Materials in exported Blender model for Three.js not working

不羁岁月 提交于 2020-03-21 19:06:52

问题


I am trying to use a model created with Blender with Three.js The model is very basic, two cubes on top of each other. One cube is red and the other is green.

I have exported the model using the Blender exporter plugin of Three.js When I assign a material manually to the object like:

loader.load("model.js", function ( geometry, material ) {

    material = new THREE.MeshBasicMaterial( { color: 0xFF0000 } );

    mesh = new THREE.Mesh( geometry, material);

    scene.add(mesh);

    animate();

});

there is no problem as shown at https://googledrive.com/host/0B9t0vRo6sUnzWndDTGxicENIdDg/index.html

However when I remove the line:

material = new THREE.MeshBasicMaterial( { color: 0xFF0000 } );

the material of the model is used. Which produces an error of Three.js:

TypeError: program is undefined [Break On This Error]

p_uniforms = program.uniforms,

You can see this for yourself at https://googledrive.com/host/0B9t0vRo6sUnzWndDTGxicENIdDg/index2.html

Does anyone have an idea what could cause this problem? You can download the Blender file at https://googledrive.com/host/0B9t0vRo6sUnzWndDTGxicENIdDg/model.blend


回答1:


Easy. The materials is an array. You need to do the following:

loader.load( "model.js", function ( geometry, materials ) {

    mesh = new THREE.Mesh( geometry, materials );

    scene.add( mesh );

    animate();

} );

three.js r.88



来源:https://stackoverflow.com/questions/14732253/materials-in-exported-blender-model-for-three-js-not-working

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!