three.js - Drag a loaded object with threejs? -
i've been trying loaded object draggable in threejs. first block of code below (which snippet) displays cube , can rotate view, not cube itself.
the second block of code creates box draggable, want able more drag boxes. maybe drag teapot! desire drag loaded object.
why can move box when create threejs, not when load it? how fix this?
the code derived from: http://threejs.org/examples/webgl_interactive_draggablecubes.html
// var geometry = new three.boxgeometry( 40, 40, 40 ); var loader = new three.objloader(); loader.load('static/obj/cube.obj', function(object) { // var object = new three.mesh( geometry, new three.meshlambertmaterial( { color: math.random() * 0xffffff } ) ); object.position.x = math.random() * 100 - 50; object.position.y = math.random() * 60 - 30; object.position.z = math.random() * 80 - 40; scene.add( object ); objects.push( object ); });
var geometry = new three.boxgeometry( 40, 40, 40 ); // var loader = new three.objloader(); // loader.load('static/obj/cube.obj', function(object) { var object = new three.mesh( geometry, new three.meshlambertmaterial( { color: math.random() * 0xffffff } ) ); object.position.x = math.random() * 100 - 50; object.position.y = math.random() * 60 - 30; object.position.z = math.random() * 80 - 40; scene.add( object ); objects.push( object ); // });
loading obj replaces making new three.boxgeometry() part not new three.mesh(). code doesn't seem without errors.
anyway, take @ code below, notice inside loader.load changed second argument object geometry , uncommented mesh making:
var loader = new three.objloader(); loader.load('static/obj/cube.obj', function(geometry) { var object = new three.mesh( geometry, new three.meshlambertmaterial( { color: math.random() * 0xffffff } ) ); object.position.x = math.random() * 100 - 50; object.position.y = math.random() * 60 - 30; object.position.z = math.random() * 80 - 40; scene.add( object ); objects.push( object ); });
now objloader gets geometry, , uses make mesh. makes more sense doesn't it?
Comments
Post a Comment