From 021bdaa895e30ab2b71fe9f74065ce2e05b88eee Mon Sep 17 00:00:00 2001 From: liteng <930372551@qq.com> Date: Wed, 27 Jun 2018 12:00:21 +0800 Subject: [PATCH] =?UTF-8?q?=E9=80=89=E4=B8=AD=E4=BA=8B=E4=BB=B6=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/editor/Viewport.js | 129 ----------------------------------------- 1 file changed, 129 deletions(-) diff --git a/src/editor/Viewport.js b/src/editor/Viewport.js index fc7b82b6..71dc234d 100644 --- a/src/editor/Viewport.js +++ b/src/editor/Viewport.js @@ -69,135 +69,6 @@ function Viewport(app) { sceneHelpers.add(transformControls); - // object picking - - var raycaster = new THREE.Raycaster(); - var mouse = new THREE.Vector2(); - - // events - - function getIntersects(point, objects) { - - mouse.set((point.x * 2) - 1, -(point.y * 2) + 1); - - raycaster.setFromCamera(mouse, camera); - - return raycaster.intersectObjects(objects); - - } - - var onDownPosition = new THREE.Vector2(); - var onUpPosition = new THREE.Vector2(); - var onDoubleClickPosition = new THREE.Vector2(); - - function getMousePosition(dom, x, y) { - - var rect = dom.getBoundingClientRect(); - return [(x - rect.left) / rect.width, (y - rect.top) / rect.height]; - - } - - function handleClick() { - - if (onDownPosition.distanceTo(onUpPosition) === 0) { - - var intersects = getIntersects(onUpPosition, objects); - - if (intersects.length > 0) { - - var object = intersects[0].object; - - if (object.userData.object !== undefined) { - - // helper - - editor.select(object.userData.object); - - } else { - - editor.select(object); - - } - - } else { - - editor.select(null); - - } - - _this.app.call('render'); - - } - - } - - function onMouseDown(event) { - - event.preventDefault(); - - var array = getMousePosition(container.dom, event.clientX, event.clientY); - onDownPosition.fromArray(array); - - document.addEventListener('mouseup', onMouseUp, false); - - } - - function onMouseUp(event) { - - var array = getMousePosition(container.dom, event.clientX, event.clientY); - onUpPosition.fromArray(array); - - handleClick(); - - document.removeEventListener('mouseup', onMouseUp, false); - - } - - function onTouchStart(event) { - - var touch = event.changedTouches[0]; - - var array = getMousePosition(container.dom, touch.clientX, touch.clientY); - onDownPosition.fromArray(array); - - document.addEventListener('touchend', onTouchEnd, false); - - } - - function onTouchEnd(event) { - - var touch = event.changedTouches[0]; - - var array = getMousePosition(container.dom, touch.clientX, touch.clientY); - onUpPosition.fromArray(array); - - handleClick(); - - document.removeEventListener('touchend', onTouchEnd, false); - - } - - function onDoubleClick(event) { - - var array = getMousePosition(container.dom, event.clientX, event.clientY); - onDoubleClickPosition.fromArray(array); - - var intersects = getIntersects(onDoubleClickPosition, objects); - - if (intersects.length > 0) { - - var intersect = intersects[0]; - - _this.app.call('objectFocused', _this, intersect.object); - - } - - } - - container.dom.addEventListener('mousedown', onMouseDown, false); - container.dom.addEventListener('touchstart', onTouchStart, false); - container.dom.addEventListener('dblclick', onDoubleClick, false); - // 编辑器控件 // controls need to be added *after* main logic,