three.js - Dynamically change .mtl of .obj OBJMTLLoader -


how can dynamically change material on .obj model? each of model contains .obj, .mtl , .jpg files textures. should change .mtl file somehow?

in code below center geometries of each child mesh of .obj , try give texture, neither commented code nor loader.load not giving texture.

var loader = new three.objmtlloader();             loader.addeventlistener( 'load', function ( event ) {                 object = event.content;                 (var = 0; < object.children.length; i++) {                     three.geometryutils.merge(geometry, object.children[i].geometry);                 }                 three.geometryutils.center( geometry );                 //var materials = new three.imageutils.loadtexture("/obj/stol.mtl");                 //mesh = new three.mesh( geometry, new three.meshfacematerial( material ) );                  var material = new three.meshbasicmaterial( { color: 0xff0000 } );                 mesh = new three.mesh( geometry,  material );                  mesh.scale.x = 0.25;                 mesh.scale.y = 0.25;                 mesh.scale.z = 0.25;                 mesh.castshadow = true;                  scene.add( mesh );                 animate();             });             loader.load( '/obj/stol.obj', '/obj/stol.mtl' ); 

i'd have buttons on page trigger texture changes onclick, e.g

$(function(){     $('#txt_01').click(function(){         mesh.textureload("/obj/txt_01.mtl");     } }); 

working demo: http://www.edar.com.pl/test-3d-2/

just check examples loading texture.

and how update stuff in three.js , see "material update" section. https://github.com/mrdoob/three.js/wiki/updates


Comments

Popular posts from this blog

image - ClassNotFoundException when add a prebuilt apk into system.img in android -

I need to import mysql 5.1 to 5.5? -

Java, Hibernate, MySQL - store UTC date-time -