How can i actually do drag and drop on a object(move with mouse) i loaded in with GLTF loader in Three.js. I couldn’t make it working with DragControls.js. If i load in basic model in three.js -
Emm, even when i load model with GLTFLoader - into example u gave me - @Mugen87 and push into Objects array…i’m getting error - object.raycast is not a function three.js:42091:3 I guess i’m missing something important about ray cast.
This results in drag enable for each individual object present in the parent GLTF object.My question is how can I combine all the child objects in a single object which as a whole can be dragged.
@Mugen87 I tried to load the gltf (object) which is made up of multiple elements,when I try to select and drag the object , I am able to drag only one element .Please help me to fix this issue.
objects.push(gltf); is not working for me.
can anyone help me…
i am facing two problems.
THREE.DragControls is not a constructor and not able to push 3d model in array
use following code to drag multi mesh GLTF. It is Work for me.
var dragobjects =[];
//add following code in init function
var gltfobject = addGLTFObjectIntoScene();
scene.add(gltfobject);
dragControls = new THREE.DragControls(dragobjects, camera, renderer.domElement);
dragControls.addEventListener('dragstart', onDragStart, false);
dragControls.addEventListener('drag', onDrag , false);
dragControls.addEventListener('dragend', onDragEnd, false);
//end init function code
//add following function after or before init function
function drawBox(objectwidth,objectheight,objectdepth){
var geometry, material, box;
geometry = new THREE.BoxGeometry(objectwidth,objectheight,objectdepth);
material = new THREE.MeshBasicMaterial({color: 0xffff00, transparent: true, opacity: 0,depthTest:false});
box = new THREE.Mesh(geometry, material);
dragobjects.push(box);
box.position.set(0, 0, 0);
return box;
};
function addGLTFObjectIntoScene(){
group = new THREE.Group();
var loader = new THREE.GLTFLoader();
loader.load( 'W1230/W1230.gltf', ( gltf ) => {
mesh = gltf.scene;
mesh.scale.set( 30, 30, 30);
var gltfbox = new THREE.Box3().setFromObject( mesh );
var objectwidth = Math.floor(gltfbox.getSize().x);
var objectheight = Math.floor(gltfbox.getSize().y);
var objectdepth = Math.floor(gltfbox.getSize().z);
objectwidth = objectwidth + parseInt(2);
objectheight = objectheight + parseInt(2);
objectdepth = objectdepth + parseInt(1);
mesh.position.set(0, -objectheight/2, 0);
box = drawBox(objectwidth,objectheight,objectdepth);
group.add(box);
group.name = "quadrant";
console.log(mesh);
box.add( mesh);
});
return group;
};
There is actually a PR that should fix this issue in a more clean way. Meaning, it’s not necessary anymore to change app level code. All you need to do is to set a flag in DragControls and you will be able to drag a 3D object with children as a group.