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

Popular posts from this blog

c++ - Difference between pre and post decrement in recursive function argument -

php - Nothing but 'run(); ' when browsing to my local project, how do I fix this? -

php - How can I echo out this array? -