本文介绍了加载 Collada (dae) 模型时如何在 THREE.js 中设置材料?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
加载 Collada (dae) 模型时如何在 THREE.js 中设置材质?
How do I setup materials in THREE.js when loading Collada (dae) models?
我有以下代码:
new THREE.ColladaLoader().load('models/cylinder.dae',
function(collada) {
var model = collada.scene;
model.scale.set(10.0, 10.0, 10.0);
// attempt to set a material - doesn't work...
collada.dae.materials[0] = new THREE.MeshBasicMaterial( { color: 0xff0000, wireframe: true } );
scene.add(model);
});
感谢您的帮助.
推荐答案
var loader = new THREE.ColladaLoader();
loader.options.convertUpAxis = true;
loader.load( './models/cylinder.dae',function colladaReady( collada ) {
model = collada.scene;
model_geometry = collada.scene.children[ 0 ].geometry;
model_material = collada.scene.children[ 0 ].material;
model.scale.set(10.0, 10.0, 10.0);
model.updateMatrix();
});
如果您将 model_material 设为未定义",请查看 collada 对象
if you are getting model_material as 'undefined', then take a look at collada object
console.log(collada);
有时孩子里面有孩子,所以你可能不得不这样做:
sometimes there are children inside children, so you might have to do this:
model_material = collada.scene.children[ 0 ].children[ 0 ].material;
查看 collada 模型,然后进行相应修改.
Take a look at collada model and then modify accordingly.
这篇关于加载 Collada (dae) 模型时如何在 THREE.js 中设置材料?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!