fix: display

This commit is contained in:
hyper 2026-03-15 23:17:59 +08:00
parent 2476659fc6
commit 940caaf8e4
1 changed files with 10 additions and 4 deletions

View File

@ -52,22 +52,28 @@ export default function MdTokenViewer(props: TokenViewerProps) {
// 3MF 文件可能返回一个 Group包含多个 Mesh
group = object instanceof THREE.Group ? object : new THREE.Group().add(object);
// 居中并调整方向
group.center();
// 计算边界框并居中
const box = new THREE.Box3().setFromObject(group);
const center = box.getCenter(new THREE.Vector3());
group.position.x = -center.x;
group.position.y = -center.y;
group.position.z = -center.z;
group.rotateX(Math.PI);
// 为每个 mesh 启用原始颜色
group.traverse((child) => {
if ((child as THREE.Mesh).isMesh) {
const childMesh = child as THREE.Mesh;
const material = childMesh.material as THREE.MeshStandardMaterial;
// 保留原始顶点颜色或材质颜色
if (childMesh.geometry.attributes.color) {
childMesh.material.vertexColors = true;
material.vertexColors = true;
}
// 确保材质是标准材质以支持光照
if (!(childMesh.material instanceof THREE.MeshStandardMaterial)) {
childMesh.material = new THREE.MeshStandardMaterial({
color: childMesh.material.color,
color: material.color,
metalness: 0.3,
roughness: 0.7,
});