如何在ThreeJs中使用Blender(使用colladaLoader - > .dae)渲染导出的场景(具有许多对象,每个对象具有不同的颜色和不同的属性,例如在场景中旋转一个轴)?
答案 0 :(得分:3)
因此,第一步是学习如何在threeJ中创建场景并使用Blender学习一些功能。准备就绪后,创建第一个模型,在导出之前请记住这一点:
现在,关于threeJs的部分:
请务必使用以下内容导入colladaLoader:
<script src="jsLib/ColladaLoader.js"></script>
将此代码插入到init()函数中,以便加载器将加载.dae模型:
var loader = new THREE.ColladaLoader();
loader.options.convertUpAxis = true;
loader.load( 'model.dae', function ( collada ) {
// with this you can get the objects of the scene; the [0] is not the first object
// you display in blender in case of many objects (which means you didn't join them)
var obj1 = collada.scene.children[0];
// you can name the object so you can use it even out of the function, if you want
// animate it for example obj1.name = "daeObj1";
// you can set here some material properties as trasparency
obj1.material.needsUpdate = true;
obj1.material.transparent = true;
obj1.material.opacity = 0.5;
obj1.hearth.material.wireframe = false;
// and now some position and rotation for good visualization
obj1.position.set(0, -5, -0.6); //x,z,y
obj1.rotation.set(0, 45, 0);
// and add the obj to the threeJs scene
scene.add(obj1);
});
和animate()函数的一些代码,如果你想更新你的一些对象,例如旋转
scene.traverse (function (object) {
if (object.name === 'daeObj1') {
object.rotation.z -= 0.01;
}
});
我希望有人能从这篇文章中受益