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}")
相关推荐
aifannihao4 小时前
GitHub Actions 锁文件实测:6 个 uses 只锁住 2 个
python·ci/cd·标准库·供应链安全·github actions
2601_967980114 小时前
使用gensim处理文本(1)语料库与词向量空间
python·自然语言处理·gensim·词向量·文本分析
starzy19904 小时前
深入理解Scala隐式值:编译期自动装配
开发语言·后端·scala
布莱克6055 小时前
Swift 条件语句详解:从 if 到 switch 的完整指南
开发语言·ssh·swift·switch·条件语句·guard·if
吴可可1235 小时前
ActiveX调用WScript.Shell原理揭秘
开发语言
3095566665 小时前
股票接口返回 404 与空数组的排查笔记:证书状态与级别参数
java·笔记·python·ios·iphone·股票数据api·股票数据接口
2601_967980116 小时前
世界上最好的Python编辑器是什么?我投PyCharm一票
ide·python·pycharm·数据科学·jupyter notebook
晴天的雨.9926 小时前
【C++】继承篇
java·开发语言·c++
SomeOtherTime6 小时前
第 1 讲:内存布局与所有权解剖——栈帧、胖指针与“移动/拷贝”在汇编层面的真实面目
java·开发语言·汇编
wuyk5556 小时前
Spider-第09讲-三格式落盘CSV-Excel-JSON
爬虫·python·json·excel