.obj - THREE.js OBJMTLLoader - Request for simple example files -


as detailed in previous question have learned how use three.js objmtlloader using same objects & materials used in official example.

that example uses (for me) complex model ddsloader.

i load simpler obj+mtl models , have been trying several free models obtained web. have managed load obj files ok (by applying further three.js code such defining normals) there problem loading material textures mtl files.

here simple example of code.

//...dolphinb var posx = -3445; var posy = 750; var posz = -100;  var common_scale = 100;  var loader = new three.objmtlloader(); loader.load(    'tri_vp_files/models/dolphin/dolphin_b.obj',     'tri_vp_files/models/dolphin/dolphin_b.mtl',      function(object)      {     object.position.set( posx, posy, posz );     scene222.add( object );     object.scale.set(common_scale, common_scale, common_scale);      } ); 

here mtl code

# wavefront material library # tue aug 03 07:47:56 1999 # created viewpoint interchange www.viewpoint.com  newmtl dl_body   ka 0 0 0   kd 0 0.8 0.9   ks 0 0 0   illum 1   map_kd dolphin2.jpg 

my question

please point me simple obj + mtl files known load ok objmtlloader.

you can use following free-for-private-use fileset hand created mohammad alizadeh (nice work thankyou mohammad).

it uses single .jpg image file source material texture.

it uses single material.

here .mtl file contents...

# blender mtl file: 'hand.blend' # material count: 1     newmtl defaultmat ns 96.078431 ka 0.000000 0.000000 0.000000 kd 0.640000 0.640000 0.640000 ks 0.500000 0.500000 0.500000 ni 1.000000 d 1.000000 illum 2 map_kd hand_mapnew.jpg 

you need change top few lines of .obj file from...

# blender v2.74 (sub 0) obj file: 'hand.blend' # www.blender.org mtllib hand.mtl o zbrushpolymesh3d v 0.614360 0.281365 -0.675872 v 0.684894 0.445729 -0.634615 

to

# blender v2.74 (sub 0) obj file: 'hand.blend' # www.blender.org ## mtllib hand.mtl    <===== commented out usemtl defaultmat ##  <===== added usemtl command,note proper name of material ## o zbrushpolymesh3d <===== commented out v 0.614360 0.281365 -0.675872 v 0.684894 0.445729 -0.634615 

note many free 3d object filesets use .tif image files. .tif's cannot display in browsers (or three.js). converting them .jpg format possible uv mapping not preserved.

also note free 3d object filesets need edited material names in .obj file match names given in .mtl file.

also note .obj files (like hand example above) need editted material indicated usemtl command e.g.:-

usemtl defaultmat 

child processing

for hand fileset there are vertex normals (vn) in .obj file. reason smoothing not applied. applying following code produce smoothing (and adjust shininess , set rootobject references object picking):-

object.traverse (  function (child) {     if (child instanceof three.mesh)      {                    child.material.shininess = 10;//range 0.1 30 (default) 1000 or more, applies phong materials.             //child.userdata.rootobject = object; //... see west langley answer @ http://stackoverflow.com/questions/22228203/picking-object3d-loaded-via-objmtlloader         //... used object picking that, further operations, can select picked child object or child's rootobject.         child.rootobject = object; //... avoids infinite loop if cloning 3d objects.             child.geometry.computefacenormals();          child.geometry.computevertexnormals();            //child.geometry.normalsneedupdate = true; //... required if object has been rendered.     } }; ) 

disclaimer

these tricks got things working me particular scenario. don't best way of doing things.


Comments

Popular posts from this blog

html - Outlook 2010 Anchor (url/address/link) -

javascript - Why does running this loop 9 times take 100x longer than running it 8 times? -

Getting gateway time-out Rails app with Nginx + Puma running on Digital Ocean -