任何人都可以告诉我如何在CODE 1中返回类似于CODE 2的占位符值。 我需要返回我的(oBJ + MTL)加载的模型名称,以便我可以将它引用到我的其他执行函数。
**CODE 1:**
function makePlatform() {
var placeholder = new THREE.Object3D();
var onProgress = function(xhr) {
if (xhr.lengthComputable) {
var percentComplete = xhr.loaded / xhr.total * 100;
console.log(Math.round(percentComplete, 2) + '% downloaded');
}
};
var onError = function(xhr) {};
THREE.Loader.Handlers.add(/\.dds$/i, new THREE.DDSLoader());
var mtlLoader = new THREE.MTLLoader();
mtlLoader.setBaseUrl('myhouse/');
mtlLoader.setPath('myhouse/');
mtlLoader.load('villa.mtl', function(materials) {
materials.preload();
var objLoader = new THREE.OBJLoader();
objLoader.setMaterials(materials);
objLoader.setPath('myhouse/');
objLoader.load('villa.obj', function(object) {
object.position.y = -5.0;
object.scale.x = object.scale.y = object.scale.z = 0.05
object.castShadow = true;
object.receiveShadow = true;
object.traverse(function(node) {
if (node instanceof THREE.Mesh) {
node.castShadow = true;
node.receiveShadow = true;
}
});
scene.add(object);
object.name = "base" //unsuccessful reference
placeholder.add(object); //unsuccessful reference
}, onProgress, onError);
});
return placeholder; // nothing returned
}
referred CODE 2 :
function makePlatform(jsonUrl, textureUrl, textureQuality) {
var placeholder = new THREE.Object3D();
var texture = new THREE.TextureLoader().load(textureUrl);
texture.minFilter = THREE.LinearFilter;
texture.anisotropy = textureQuality;
var loader = new THREE.JSONLoader();
loader.load(jsonUrl, function(geometry) {
geometry.computeFaceNormals();
var platform = new THREE.Mesh(geometry, new THREE.MeshBasicMaterial({
map: texture
}));
platform.name = "platform";
placeholder.add(platform);
});
return placeholder;
}
请在引用我的代码1时告诉我出错的地方。
我使用这个fps示例作为参考 https://github.com/mrdoob/three.js/blob/master/examples/misc_fps.html