我制作了一个平面和球体,纹理立方体和简单的立方体以及一个加载的amf,如何拖动或平移平面,并拖动所有提到的对象togethor,实际上我创建了组,我帮助了trackBallControl和OrbitControl。 这是我的代码的一部分,我不知道该怎么做。我可以单独拖动而不是作为一个群体。
var grid = new THREE.GridHelper(50, 50, 0xffffff, 0x555555);
grid.rotateOnAxis(new THREE.Vector3(1, 0, 0), 90 * (Math.PI / 180));
scene.add(grid);
var grids= [grid];
controls = new THREE.TrackballControls(camera);
controls.rotateSpeed = 1.0;
controls.zoomSpeed = 1.2;
controls.panSpeed = 10;
controls.noZoom = false;
controls.noPan = false;
controls.staticMoving = true;
controls.dynamicDampingFactor = 0.3;
var dragControls = new THREE.DragControls(grids, camera, renderer.domElement);
dragControls.addEventListener('dragstart', function (event) {
controls.enabled = false;
});
dragControls.addEventListener('dragend', function (event) {
controls.enabled = true;
});
答案 0 :(得分:1)
如果我说对了您可以添加所有内容(平面和球体,纹理立方体和简单立方体以及加载的amf )作为grid
的子项(THREE.GridHelper()
):
var objects = [];
var grid = new THREE.GridHelper(10, 10);
scene.add(grid);
objects.push(grid); // add to the array for DragControls
var sphere = new THREE.Mesh(...);
sphere.position.set(-1, 1, 0);
grid.add(sphere); // as a child of the grid
var cube = new THREE.Mesh(...);
cube.position.set(1, 1, 0);
grid.add(cube); // as a child of the grid
var dragControls = new THREE.DragControls(objects, camera, renderer.domElement);
dragControls.addEventListener('dragstart', function(event) {
controls.enabled = false;
});
dragControls.addEventListener('dragend', function(event) {
controls.enabled = true;
});
jsfiddle示例。如果我错过了你的问题,请澄清一下。