fix: display
This commit is contained in:
parent
2476659fc6
commit
940caaf8e4
|
|
@ -52,22 +52,28 @@ export default function MdTokenViewer(props: TokenViewerProps) {
|
||||||
// 3MF 文件可能返回一个 Group,包含多个 Mesh
|
// 3MF 文件可能返回一个 Group,包含多个 Mesh
|
||||||
group = object instanceof THREE.Group ? object : new THREE.Group().add(object);
|
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);
|
group.rotateX(Math.PI);
|
||||||
|
|
||||||
// 为每个 mesh 启用原始颜色
|
// 为每个 mesh 启用原始颜色
|
||||||
group.traverse((child) => {
|
group.traverse((child) => {
|
||||||
if ((child as THREE.Mesh).isMesh) {
|
if ((child as THREE.Mesh).isMesh) {
|
||||||
const childMesh = child as THREE.Mesh;
|
const childMesh = child as THREE.Mesh;
|
||||||
|
const material = childMesh.material as THREE.MeshStandardMaterial;
|
||||||
// 保留原始顶点颜色或材质颜色
|
// 保留原始顶点颜色或材质颜色
|
||||||
if (childMesh.geometry.attributes.color) {
|
if (childMesh.geometry.attributes.color) {
|
||||||
childMesh.material.vertexColors = true;
|
material.vertexColors = true;
|
||||||
}
|
}
|
||||||
// 确保材质是标准材质以支持光照
|
// 确保材质是标准材质以支持光照
|
||||||
if (!(childMesh.material instanceof THREE.MeshStandardMaterial)) {
|
if (!(childMesh.material instanceof THREE.MeshStandardMaterial)) {
|
||||||
childMesh.material = new THREE.MeshStandardMaterial({
|
childMesh.material = new THREE.MeshStandardMaterial({
|
||||||
color: childMesh.material.color,
|
color: material.color,
|
||||||
metalness: 0.3,
|
metalness: 0.3,
|
||||||
roughness: 0.7,
|
roughness: 0.7,
|
||||||
});
|
});
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue