//var 3 obj models, cushion, backrest , frame , , var chair01 group including 3 obj var cushion; var backrest; var frame; var chair01 = new three.object3d(); var loader = new three.objloader( manager ); //load obj model function loadobj("chair/obj/cushion.obj", cushion, materialcushion); loadobj("chair/obj/backrest.obj", backrest, materialbackrest); loadobj("chair/obj/frame.obj", frame, materialframe); function loadobj(path, name, material) { loader.load('model-stuff/' + path, function( object ) { object.traverse( function ( child ){ if ( child instanceof three.mesh ) { var uvs = child.geometry.attributes.uv.array; child.geometry.addattribute( 'uv2', new three.bufferattribute( uvs, 2 ) ); child.material = material; child.receiveshadow = true; child.castshadow = true; } }); name = object; name.position.y = -10; chair01.add( name ); }, onprogress, onerror); } //add chair01 scene scene.add(chair01); //remove frame chair01 manager.onload = function() { chair01.remove(frame); }
code above, loaded obj loadobj function, why cannot remove "frame" chair01?
i have tried method,if didn't load obj via loadobj funtion, can remove frame chair01
the car "frame" sent parameter loadobj, presumably undefined still. , frame never defined after that. edit: due scope closure on parameter. need object maintain persistence.
//var 3 obj models, cushion, backrest , frame , , var chair01 group including 3 obj var parts = { cushion:"cushion", backrest:"bracket", frame:"frame"; } var chair01 = new three.object3d(); var loader = new three.objloader( manager ); //load obj model function loadobj("chair/obj/cushion.obj", parts.cushion, materialcushion); loadobj("chair/obj/backrest.obj", parts.backrest, materialbackrest); loadobj("chair/obj/frame.obj", parts.frame, materialframe); function loadobj(path, name, material) { loader.load('model-stuff/' + path, function( object ) { object.traverse( function ( child ){ if ( child instanceof three.mesh ) { var uvs = child.geometry.attributes.uv.array; child.geometry.addattribute( 'uv2', new three.bufferattribute( uvs, 2 ) ); child.material = material; child.receiveshadow = true; child.castshadow = true; } }); parts[name] = object; parts[name].position.y = -10; chair01.add( parts[name]); //parts[name] = object; }, onprogress, onerror); } //add chair01 scene scene.add(chair01); //remove frame chair01 manager.onload = function() { chair01.remove(parts.frame); }
Comments
Post a Comment