gpt4 book ai didi

javascript - 如何将所有 STL 文件合并到一个几何体

转载 作者:行者123 更新时间:2023-12-03 02:42:17 25 4
gpt4 key购买 nike

代码如下。我觉得太麻烦了。有更好的方法吗?我这样做是为了整体导出为STL文件,或者做整体切割功能,谢谢!

var material1 = new THREE.MeshPhongMaterial( {
color:0xffffff,
} );
loader.load( 'fanban1.stl', function ( geometry ) {
stl_mesh1 = new THREE.Mesh(geometry, material1);
stl_mesh1.position.set(20, 0, 40);
stl_mesh1.rotation.set(-Math.PI / 2, 0, 0);
stl_mesh1.scale.set(0.2, 0.2, 0.2);
group.add(stl_mesh1);
arr_mesh.push(stl_mesh1);
});


var material2 = new THREE.MeshPhongMaterial( {
color:0xFFFF00,
} );
loader.load( 'fanban2.stl', function ( geometry ) {
stl_mesh2 = new THREE.Mesh(geometry, material2);
stl_mesh2.position.set(20, 0, -20);
stl_mesh2.rotation.set(-Math.PI / 2, 0, 0);
stl_mesh2.scale.set(0.3, 0.3, 0.3);
group.add(stl_mesh2);
arr_mesh.push(stl_mesh2);
});
scene.add(group);

然后,我编辑它链接:

    var allGeometry = new THREE.Geometry();
loader.load( 'fanban.stl', function ( geometry ) {
stl_mesh = new THREE.Mesh(geometry, material);
stl_mesh.position.set(20, 0, -60);
stl_mesh.rotation.set(-Math.PI / 2, 0, 0);
stl_mesh.scale.set(0.3, 0.3, 0.3);
group.add(stl_mesh);
arr_mesh.push(stl_mesh);
allGeometry.merge(geometry);
});

但是报错:THREE.Geometry.merge(): Geometry not an instance of THREE.Geometry.

最佳答案

您的意思是代码审查吗?如果是这样,那么最好转移你的问题Stack Exchange Code Review 。如果是这样,那么它们在加载网格时都会做同样的事情,所以像这样的事情将是一个好的开始:

function constructMesh(geo, mat, x, y, z, scaleX, scaleY, scaleZ) {
var mesh = new THREE.Mesh(geo, mat);
mesh.position.set(x, y, z);
mesh.rotation.set(-Math.PI / 2, 0, 0);
mesh.scale.set(scaleX, scaleY, scaleZ);
group.add(mesh);
arr_mesh.push(mesh);
}

实现如下:

var materials = [
new THREE.MeshPhongMaterial({color:0xffffff}),
new THREE.MeshPhongMaterial({color:0xffff00})
];

loader.load( 'fanban1.stl', function ( geometry ) {
constructMesh(geo, materials[0], 20, 0, 40, 0.2, 0.2, 0.2);
});
loader.load( 'fanban2.stl', function ( geometry ) {
constructMesh(geo, materials[1], 20, 0, -20, 0.3, 0.3, 0.3);
});
scene.add(group);

关于javascript - 如何将所有 STL 文件合并到一个几何体,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48277947/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com