原文地址:http://blog.csdn.net/zhengxiaotaozz/article/details/68927099dom
添加引用spa
<script src="TrackballControls.js"></script> <script src="DragControls.js"></script>
var controls; controls = new THREE.TrackballControls( camera ); 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 objects = [];//將須要拖拽的元素放進這個集合中
objects.push(元素);
建立拖拽控制並添加事件監聽.net
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; } );
渲染code
function render() { controls.update(); renderer.render( scene, camera ); }