提交 459769d0 编写于 作者: A Aleksandar Rodic 提交者: Aleksandar Rodic

added transform controls

replaced axis geometry with code
added rotation and scale controls
refactored
added local modes
changed default settings
added todo list

optimized and bug fixes

changed default settings

typo

hide intersection planes

refactored transformControls
added half-rings to rotation handles
上级 411c4488
...@@ -77,6 +77,7 @@ ...@@ -77,6 +77,7 @@
<script src="../examples/js/libs/system.min.js"></script> <script src="../examples/js/libs/system.min.js"></script>
<script src="../examples/js/controls/EditorControls.js"></script> <script src="../examples/js/controls/EditorControls.js"></script>
<script src="../examples/js/controls/TransformControls.js"></script>
<script src="../examples/js/loaders/BinaryLoader.js"></script> <script src="../examples/js/loaders/BinaryLoader.js"></script>
<script src="../examples/js/loaders/ColladaLoader.js"></script> <script src="../examples/js/loaders/ColladaLoader.js"></script>
<script src="../examples/js/loaders/OBJLoader.js"></script> <script src="../examples/js/loaders/OBJLoader.js"></script>
......
...@@ -25,8 +25,15 @@ var Viewport = function ( signals ) { ...@@ -25,8 +25,15 @@ var Viewport = function ( signals ) {
var grid = new THREE.GridHelper( 500, 25 ); var grid = new THREE.GridHelper( 500, 25 );
sceneHelpers.add( grid ); sceneHelpers.add( grid );
var modifierAxis = new THREE.Vector3( 1, 1, 1 ); //
var snapDist = null;
var scene = new THREE.Scene();
var camera = new THREE.PerspectiveCamera( 50, container.dom.offsetWidth / container.dom.offsetHeight, 1, 5000 );
camera.position.set( 500, 250, 500 );
camera.lookAt( scene.position );
//
var selectionBox = new THREE.BoxHelper(); var selectionBox = new THREE.BoxHelper();
selectionBox.material.color.setHex( 0xffff00 ); selectionBox.material.color.setHex( 0xffff00 );
...@@ -35,20 +42,9 @@ var Viewport = function ( signals ) { ...@@ -35,20 +42,9 @@ var Viewport = function ( signals ) {
selectionBox.visible = false; selectionBox.visible = false;
sceneHelpers.add( selectionBox ); sceneHelpers.add( selectionBox );
var selectionAxis = new THREE.AxisHelper( 100 ); var transformControls = new THREE.TransformControls( camera, container.dom );
selectionAxis.material.depthTest = false; sceneHelpers.add( transformControls.gizmo );
selectionAxis.material.transparent = true; transformControls.hide();
selectionAxis.matrixAutoUpdate = false;
selectionAxis.visible = false;
sceneHelpers.add( selectionAxis );
//
var scene = new THREE.Scene();
var camera = new THREE.PerspectiveCamera( 50, container.dom.offsetWidth / container.dom.offsetHeight, 1, 5000 );
camera.position.set( 500, 250, 500 );
camera.lookAt( scene.position );
// fog // fog
...@@ -60,13 +56,8 @@ var Viewport = function ( signals ) { ...@@ -60,13 +56,8 @@ var Viewport = function ( signals ) {
// object picking // object picking
var intersectionPlane = new THREE.Mesh( new THREE.PlaneGeometry( 5000, 5000 ) );
intersectionPlane.visible = false;
sceneHelpers.add( intersectionPlane );
var ray = new THREE.Raycaster(); var ray = new THREE.Raycaster();
var projector = new THREE.Projector(); var projector = new THREE.Projector();
var offset = new THREE.Vector3();
var selected = camera; var selected = camera;
...@@ -106,72 +97,21 @@ var Viewport = function ( signals ) { ...@@ -106,72 +97,21 @@ var Viewport = function ( signals ) {
onMouseDownPosition.set( event.layerX, event.layerY ); onMouseDownPosition.set( event.layerX, event.layerY );
if ( event.button === 0 ) { setTimeout( function(){
if ( transformControls.active ) controls.enabled = false;
var intersects = getIntersects( event, objects ); else controls.enabled = true;
}, 10 );
if ( intersects.length > 0 ) {
var object = intersects[ 0 ].object;
if ( selected === object || selected === helpersToObjects[ object.id ] ) {
intersectionPlane.position.copy( selected.position );
intersectionPlane.lookAt( camera.position );
intersectionPlane.updateMatrixWorld();
var intersects = ray.intersectObject( intersectionPlane );
offset.copy( intersects[ 0 ].point ).sub( intersectionPlane.position );
document.addEventListener( 'mousemove', onMouseMove, false );
controls.enabled = false;
}
} else {
controls.enabled = true;
}
document.addEventListener( 'mouseup', onMouseUp, false ); document.addEventListener( 'mousemove', onMouseMove, false );
document.addEventListener( 'mouseup', onMouseUp, false );
} render();
}; };
var onMouseMove = function ( event ) { var onMouseMove = function ( event ) {
onMouseMovePosition.set( event.layerX, event.layerY ); signals.objectChanged.dispatch( selected );
if ( onMouseDownPosition.distanceTo( onMouseUpPosition ) > 1 ) {
var intersects = getIntersects( event, intersectionPlane );
if ( intersects.length > 0 ) {
var point = intersects[ 0 ].point.sub( offset );
if (snapDist) {
point.x = Math.round( point.x / snapDist ) * snapDist;
point.y = Math.round( point.y / snapDist ) * snapDist;
point.z = Math.round( point.z / snapDist ) * snapDist;
}
selected.position.x = modifierAxis.x === 1 ? point.x : intersectionPlane.position.x;
selected.position.y = modifierAxis.y === 1 ? point.y : intersectionPlane.position.y;
selected.position.z = modifierAxis.z === 1 ? point.z : intersectionPlane.position.z;
signals.objectChanged.dispatch( selected );
render();
}
}
}; };
...@@ -205,6 +145,8 @@ var Viewport = function ( signals ) { ...@@ -205,6 +145,8 @@ var Viewport = function ( signals ) {
} }
controls.enabled = false;
render(); render();
} }
...@@ -244,7 +186,13 @@ var Viewport = function ( signals ) { ...@@ -244,7 +186,13 @@ var Viewport = function ( signals ) {
signals.modifierAxisChanged.add( function ( axis ) { signals.modifierAxisChanged.add( function ( axis ) {
modifierAxis.copy( axis ); transformControls.modifierAxis.copy( axis );
} );
signals.snapChanged.add( function ( dist ) {
transformControls.snapDist = dist;
} ); } );
...@@ -348,7 +296,7 @@ var Viewport = function ( signals ) { ...@@ -348,7 +296,7 @@ var Viewport = function ( signals ) {
signals.objectSelected.add( function ( object ) { signals.objectSelected.add( function ( object ) {
selectionBox.visible = false; selectionBox.visible = false;
selectionAxis.visible = false; transformControls.detatch();
if ( object !== null ) { if ( object !== null ) {
...@@ -359,11 +307,10 @@ var Viewport = function ( signals ) { ...@@ -359,11 +307,10 @@ var Viewport = function ( signals ) {
} }
selectionAxis.matrixWorld = object.matrixWorld;
selectionAxis.visible = true;
selected = object; selected = object;
if ( !(selected instanceof THREE.PerspectiveCamera) ) transformControls.attatch(object);
} }
render(); render();
...@@ -636,4 +583,4 @@ var Viewport = function ( signals ) { ...@@ -636,4 +583,4 @@ var Viewport = function ( signals ) {
return container; return container;
} }
\ No newline at end of file
此差异已折叠。
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册