var stlpath = '../assets/models/stl/part';
var stlformat = '.stl';
var part = new Array();
for( var i = 1; i<28; i++){
var url = stlpath + i + stlformat;
stlloader.load(url, function (geometry) {
console.log(geometry);
var mat = new THREE.MeshLambertMaterial( {color: 0xffffff} );
part = new THREE.Mesh(geometry, mat);
part.rotation.x = -0.5 * Math.PI; part.rotation.z = -0.5 * Math.PI;
part.position.set(0, -15, 0);
part.scale.set(0.3, 0.3, 0.3);
part.castShadow = true;
part.receiveShadow = true;
scene.add(part);
});
}
我已使用此代码成功加载了多个stl文件。但是这段代码只用一个变量“part”来保存stl文件,所以我无法处理每个stl文件。我想用分离的变量调整每个stl。
我尝试将数组用作变量。
var stlpath = '../assets/models/stl/part';
var stlformat = '.stl';
var part = new Array();
for( var i = 1; i<28; i++){
var url = stlpath + i + stlformat;
stlloader.load(url, function (geometry) {
console.log(geometry);
var mat = new THREE.MeshLambertMaterial( {color: 0xffffff} );
part[i] = new THREE.Mesh(geometry, mat);
part[i].rotation.x = -0.5 * Math.PI; part.rotation.z = -0.5 * Math.PI;
part[i].position.set(0, -15, 0);
part[i].scale.set(0.3, 0.3, 0.3);
part[i].castShadow = true;
part[i].receiveShadow = true;
scene.add(part[i]);
});
}
但是这段代码在没有任何错误消息的情况下无效。我不知道为什么它不起作用。你能提出任何建议,解决方案或例子吗?
谢谢