Threejs无法拖放单个obj模型
在代码中,MTL和obj首先循环到场景中,然后是三个.objControls用鼠标拖放多个3d模型。问题是不可能拖放单个模型,只能拖放整个模型
for (let i =0;i<objUrl.length;i++){
var onProgress = function ( xhr ) {
if ( xhr.lengthComputable ) {
var percentComplete = xhr.loaded / xhr.total * 100;
console.log( Math.round( percentComplete, 2 ) + '% downloaded' );
}
};
var onError = function () { };
new THREE.MTLLoader()
.setPath( 'models/obj/female02/' )
.load( mtlUrl[i]+'.mtl', function ( materials ) {
materials.preload();
new THREE.OBJLoader()
.setMaterials( materials )
.setPath( 'models/obj/female02/' )
.load( objUrl[i]+'.obj', function ( object ) {
// object.position.y = - 95;
// scene.add( object );
object.position.x = 2+i*200;
object.position.y = 2;
object.position.z = 2;
object.castShadow = true;
object.receiveShadow = true;
//加入到场景中去
scene.add(object);
objects.push(object);
}, onProgress, onError );
} );
}
....
// 添加平移控件
controls = new THREE.TrackballControls( camera, renderer.domElement );
controls.rotateSpeed = 1.0;
controls.zoomSpeed = 1.2;
controls.panSpeed = 0.8;
controls.noZoom = false;
controls.noPan = false;
controls.staticMoving = true;
controls.dynamicDampingFactor = 0.3;
//初始化拖拽控件
var dragControls = new THREE.DragControls( objects, camera, renderer.domElement );
dragControls.addEventListener('hoveron',function (event) {
// 让变换控件对象和选中的对象绑定
transformControl.attach(event.object);
});
// 开始拖拽
dragControls.addEventListener( 'dragstart', function () {
controls.enabled = false;
} );
// 拖拽结束
dragControls.addEventListener( 'dragend', function () {
controls.enabled = true;
} );
期望场景中可以出现多个obj 3d模型,并且可以使用鼠标拖放单个3d模型 结果是场景中可以出现多个obj 3d模型,但是鼠标只能拖放整个模型(请参见整个模型)