glb读取颜色

顶点颜色:

python 复制代码
import trimesh
import numpy as np
from PIL import Image
import os

scene = trimesh.load(r"E:\pro_math\math_image\3d_print\chaijian\baozha.glb", force='scene')

print(f"📦 找到 {len(scene.geometry)} 个部件")

all_colors = []
color_map = {}

for name, mesh in scene.geometry.items():
    if not isinstance(mesh, trimesh.Trimesh):
        continue

    # 提取顶点颜色
    if hasattr(mesh.visual, 'vertex_colors') and mesh.visual.vertex_colors is not None:
        colors = mesh.visual.vertex_colors
        # 取最常见的颜色(众数)
        unique_colors, counts = np.unique(colors, axis=0, return_counts=True)
        dominant = unique_colors[np.argmax(counts)]
        hex_color = f"#{dominant[0]:02x}{dominant[1]:02x}{dominant[2]:02x}"
        color_map[name] = hex_color
        all_colors.append(hex_color)
        print(f"  {name}: {hex_color}")

# 去重颜色
unique_colors = list(set(all_colors))
print(f"\n🎨 共检测到 {len(unique_colors)} 种颜色:")
for c in unique_colors:
    print(f"  {c}")
相关推荐
半兽先生1 小时前
2026年RAG系统主流开源文档解析工具选型指南:PaddleOCR、MinerU、LiteParse、HunyuanOCR、Apache Tika 全面对比
人工智能·python·机器学习·ai·开源
程序员-Benothing2 小时前
如何实现高并发系统订单30分钟自动关闭?
开发语言·c#·wpf
郝学胜-神的一滴3 小时前
Python 高级编程 026:内置数据结构之骈文纵论
开发语言·数据结构·python·程序人生·软件工程
DLYSB_10 小时前
存储运维实战:基于 Ceph Event 监听与 Python 适配器的分布式存储健康度物理声光响应架构
运维·ceph·python·报警灯
阿童木写作10 小时前
跨境图片翻译工具多合一,批量图片视频字幕翻译加智能抠图
人工智能·python·音视频·语音识别
隐积11 小时前
3.1.7.Qt容器大家族(3):QVariant——万能盒子
开发语言·qt
阿童木写作12 小时前
Python实现Temu图片批量翻译自动化教程
运维·人工智能·python·自动化
就是一只白13 小时前
复制地理信息python版本
python
看浪的路人13 小时前
第1讲:Agent 到底是什么?和 Chatbot 有什么区别
python·ai