javascript - THREE.js - Object Picking doesnt report parent object name on object loaded with OBJMTLLoader -
i have loaded obj file mtl file textures using objmtlloader. copied example http://threejs.org/examples/webgl_loader_obj_mtl.html.
the main object (man in business suit hair, hands , shoes) displays ok correct textures (e.g. eyes, mouth, tie, buttons).
the loaded object three.group 10 children, each child being three.object3d has further 3, 5 or 7 child three.mesh objects.
here js code loading obj , mtl...
//==================================================
function sow_f_load_objmtl_model ( givenfilespec, mtlfilespec, givenname, givenscene, givenhexcolorstr, posx, posy, posz, rotx, roty, rotz, scalex, scaley, scalez ) { three.loader.handlers.add( /\.dds$/i, new three.ddsloader() ); var objmtl_loader = new three.objmtlloader(); objmtl_loader.load( givenfilespec, mtlfilespec, sow_f_make_loadedobj_handler ( givenname, givenscene, givenhexcolorstr, posx, posy, posz, rotx, roty, rotz, scalex, scaley, scalez ) ); } } //============================================= function sow_f_make_loadedobjmtl_handler( givenname, givenscene, givenhexcolorstr, posx, posy, posz, rotx, roty, rotz, scalex, scaley, scalez ) { return function ( object ) { object.position.set( posx, posy, posz ); object.rotation.set( rotx, roty, rotz ); object.name = givenname; object.scale.set( scalex, scaley, scalez ); givenscene.add( object ); object.traverse ( function ( child ) { if ( child instanceof three.mesh ) { child.userdata.rootobject = object; //... following when material doesn't load child.geometry.computefacenormals(); child.geometry.computevertexnormals(); child.geometry.normalsneedupdate = true; } } ) object.updatematrix(); //... without next command not effective. xxx = sow_f_grob_add_to_target_set( object ); }; }
my problem object picking not report name of intersected object loaded objmtlloader. either reports name of texture material or blank.
object picking works ok on mesh objects create in three.js code.
i have tried fixes suggested in picking object3d loaded via objmtlloader including (in intersection picking code):
var intersects = ray.intersectobjects( scene.children, true );
and (in object child processing code):
child.userdata.rootobject = object;
but dont fix it.
please can suggest need make object picking report parent object object loaded objmtlloader?
ah, silly me, need name of rootobject selected intersected object!
to select referred object b ( object name reported or whatever) when object intersected:-
var intersected_object_a = intersects[ 0 ].object; //... nearest object
then if intersected object has property userdata.rootobject
can select rootobject referred object b.
if ( intersected_object.userdata.rootobject ) { var referred_object_b = intersected_object_a.userdata.rootobject }
otherwise select intersected object itself.
else { var referred_object_b = intersected_object_a } alert ("you clicked on:" + referred_object_b.name );
Comments
Post a Comment