0
votes

I would like to move the container (which contains my 3d objects)

Could you tell me how? I am using Three JS

THREE.DragControls = function(camera, scene, domElement) {

this.childs = [];
this.childOffsets = [];
if (scene instanceof THREE.Scene) {
    childs = scene.children;
    scene = scene.children;
}
var _projector = new THREE.Projector();

var mouse = new THREE.Vector3();
var offset = new THREE.Vector3();
var selected;

domElement.addEventListener('mousemove', onDocumentMouseMove, false);
domElement.addEventListener('mousedown', onDocumentMouseDown, false);
domElement.addEventListener('mouseup', onDocumentMouseUp, false);

function onDocumentMouseMove(event) {

    event.preventDefault();

    mouse.x = (event.clientX / domElement.width) * 2 - 1;
    mouse.y = -(event.clientY / domElement.height) * 2 + 1;

    var ray = _projector.pickingRay(mouse, camera);

    if (selected) {
        var targetPos = ray.ray.direction.clone().multiplyScalar(selected.distance).add(ray.ray.origin);
        selected.object.position.copy(targetPos.sub(offset));

        return;

    }

    var intersects = ray.intersectObjects(scene);

    if (intersects.length > 0) {

        domElement.style.cursor = 'pointer';

    } else {

        domElement.style.cursor = 'auto';

    }

}

function onDocumentMouseDown(event) {

    event.preventDefault();

    mouse.x = (event.clientX / domElement.width) * 2 - 1;
    mouse.y = -(event.clientY / domElement.height) * 2 + 1;

    var ray = _projector.pickingRay(mouse, camera);
    var intersects = ray.intersectObjects(scene);

    if (intersects.length > 0) {
        selected = intersects[0];

        offset.copy(selected.point).sub(selected.object.position);

        domElement.style.cursor = 'move';

    }
}

function onDocumentMouseUp(event) {

    event.preventDefault();

    if (selected) {
        selected = null;
    }

    domElement.style.cursor = 'auto';

}

}

1
Please be more specific with what you mean by "move". Have you checked the threejs examples?2pha
Yes, I tried some example. And I can move 3D object. And I can move many object but I moved array object. :( It's not good. I think so. I would like to move container (May be It's "FLY"), I don't know.Luc

1 Answers

1
votes

If I understand correctly you would like to MOVE all 3D Objects within a scene?

The way I did that is to create a THREE.Group(). E.g.

var holder = new THREE.Group();

Then add all models/lights/etc to that holder group. Then add the holder to the scene.

var scene = new THREE.Scene();
holder.add(model);
scene.add(holder);

Then moving the holder would move all objects added to it.