var loader = new THREE.OBJLoader();//在init函数中,创建loader变量,用于导入模型
loader.load('0.obj', function(obj)
{//第一个表示模型路径,第二个表示完成导入后的回调函数,一般我们需要在这个回调函数中将导入的模型添加到场景中
obj.traverse(function(child)
{
if (child instanceof THREE.Mesh) {
child.material.map = THREE.ImageUtils.loadTexture( 'box9.jpg');
child.material.needsUpdate = true;
child.material.side = THREE.DoubleSide;
}
});
mesh = obj;//储存到全局变量中
obj.scale.set(2,2,2);
scene.add(obj);//将导入的模型添加到场景中
});
想要实现改变导入模型的坐标,模型也能变化:
参考 http://www.webgl3d.cn/threejs/docs/#manual/zh/introduction/How-to-update-things