How to add shader to THREE.Object3D loaded from OBJMTLLoader
javascript, shader, three.js, webgl
Solution
In addition to Gero3's answer, this would ensure that all the meshes in the content will get the right material:
var material = new THREE.ShaderMaterial( {
uniforms: shader.uniforms,
fragmentShader: shader.fragmentShader,
vertexShader: shader.vertexShader
} );
var object = event.content;
object.traverse( function ( child ) {
if ( child instanceof THREE.Mesh ) {
child.material = material;
}
} );
scene.add( object );
Problem
I have a model loaded using `THREE.OBJMTLLoader`. ``` var loader = new THREE.OBJMTLLoader(); loader.addEventListener('load', function(event) { var mesh = event.content; scene.add(mesh); }); loader.load('model/machine.obj', 'model/machine.mtl'); ``` I need to apply a vertex and fragment shader to this model. How to do this?