|
@@ -1,1107 +1,974 @@
|
|
/**
|
|
/**
|
|
* @author arodic / https://github.com/arodic
|
|
* @author arodic / https://github.com/arodic
|
|
*/
|
|
*/
|
|
|
|
+ /*jshint sub:true*/
|
|
|
|
|
|
- "use strict";
|
|
|
|
|
|
+(function () {
|
|
|
|
|
|
-THREE.TransformGizmoMaterial = function ( parameters ) {
|
|
|
|
|
|
+ 'use strict';
|
|
|
|
|
|
- THREE.MeshBasicMaterial.call( this );
|
|
|
|
|
|
+ var GizmoMaterial = function ( parameters ) {
|
|
|
|
|
|
- this.depthTest = false;
|
|
|
|
- this.depthWrite = false;
|
|
|
|
- this.side = THREE.FrontSide;
|
|
|
|
- this.transparent = true;
|
|
|
|
|
|
+ THREE.MeshBasicMaterial.call( this );
|
|
|
|
|
|
- this.setValues( parameters );
|
|
|
|
|
|
+ this.depthTest = false;
|
|
|
|
+ this.depthWrite = false;
|
|
|
|
+ this.side = THREE.FrontSide;
|
|
|
|
+ this.transparent = true;
|
|
|
|
|
|
-}
|
|
|
|
|
|
+ this.setValues( parameters );
|
|
|
|
|
|
-THREE.TransformGizmoMaterial.prototype = Object.create( THREE.MeshBasicMaterial.prototype );
|
|
|
|
|
|
+ this.oldColor = this.color.clone();
|
|
|
|
+ this.oldOpacity = this.opacity;
|
|
|
|
|
|
-THREE.TransformGizmoLineMaterial = function ( parameters ) {
|
|
|
|
|
|
+ this.highlight = function( highlighted ) {
|
|
|
|
|
|
- THREE.LineBasicMaterial.call( this );
|
|
|
|
|
|
+ if ( highlighted ) {
|
|
|
|
|
|
- this.depthTest = false;
|
|
|
|
- this.depthWrite = false;
|
|
|
|
- this.transparent = true;
|
|
|
|
- this.linewidth = 1;
|
|
|
|
|
|
+ this.color.setRGB( 1, 1, 0 );
|
|
|
|
+ this.opacity = 1;
|
|
|
|
|
|
- this.setValues( parameters );
|
|
|
|
-
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
-THREE.TransformGizmoLineMaterial.prototype = Object.create( THREE.LineBasicMaterial.prototype );
|
|
|
|
-
|
|
|
|
-THREE.TransformGizmo = function () {
|
|
|
|
-
|
|
|
|
- this.handleGizmos = {
|
|
|
|
- X: [
|
|
|
|
- new THREE.Mesh( new THREE.CylinderGeometry( 0.005, 0.005, 1, 4, 1, false ), new THREE.TransformGizmoMaterial( { color: 0xff0000 } ) ),
|
|
|
|
- new THREE.Vector3( 0.5, 0, 0 ),
|
|
|
|
- new THREE.Vector3( 0, 0, -Math.PI/2 )
|
|
|
|
- ],
|
|
|
|
- Y: [
|
|
|
|
- new THREE.Mesh( new THREE.CylinderGeometry( 0.005, 0.005, 1, 4, 1, false ), new THREE.TransformGizmoMaterial( { color: 0x00ff00 } ) ),
|
|
|
|
- new THREE.Vector3( 0, 0.5, 0 )
|
|
|
|
- ],
|
|
|
|
- Z: [
|
|
|
|
- new THREE.Mesh( new THREE.CylinderGeometry( 0.005, 0.005, 1, 4, 1, false ), new THREE.TransformGizmoMaterial( { color: 0x0000ff } ) ),
|
|
|
|
- new THREE.Vector3( 0, 0, 0.5 ),
|
|
|
|
- new THREE.Vector3( Math.PI/2, 0, 0 )
|
|
|
|
- ]
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- var showPickers = false; //debug
|
|
|
|
- var showActivePlane = false; //debug
|
|
|
|
- this.activePlane = undefined;
|
|
|
|
-
|
|
|
|
- this.init = function () {
|
|
|
|
-
|
|
|
|
- THREE.Object3D.call( this );
|
|
|
|
-
|
|
|
|
- this.handles = new THREE.Object3D();
|
|
|
|
- this.lines = new THREE.Object3D();
|
|
|
|
- this.pickers = new THREE.Object3D();
|
|
|
|
- this.planes = new THREE.Object3D();
|
|
|
|
-
|
|
|
|
- this.add(this.handles);
|
|
|
|
- this.add(this.lines);
|
|
|
|
- this.add(this.pickers);
|
|
|
|
- this.add(this.planes);
|
|
|
|
-
|
|
|
|
- //// PLANES
|
|
|
|
-
|
|
|
|
- var planeGeometry = new THREE.PlaneGeometry( 50, 50, 2, 2 );
|
|
|
|
- var planeMaterial = new THREE.MeshBasicMaterial( { wireframe: true } );
|
|
|
|
- planeMaterial.side = THREE.DoubleSide;
|
|
|
|
-
|
|
|
|
- var planes = {
|
|
|
|
- "XY": new THREE.Mesh( planeGeometry, planeMaterial ),
|
|
|
|
- "YZ": new THREE.Mesh( planeGeometry, planeMaterial ),
|
|
|
|
- "XZ": new THREE.Mesh( planeGeometry, planeMaterial ),
|
|
|
|
- "XYZE": new THREE.Mesh( planeGeometry, planeMaterial )
|
|
|
|
- };
|
|
|
|
-
|
|
|
|
- planes["YZ"].rotation.set( 0, Math.PI/2, 0 );
|
|
|
|
- planes["XZ"].rotation.set( -Math.PI/2, 0, 0 );
|
|
|
|
-
|
|
|
|
- for (var i in planes) {
|
|
|
|
- planes[i].name = i;
|
|
|
|
- this.planes.add(planes[i]);
|
|
|
|
- this.planes[i] = planes[i];
|
|
|
|
- planes[i].visible = false;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- //// HANDLES AND PICKERS
|
|
|
|
-
|
|
|
|
- for ( var i in this.handleGizmos ) {
|
|
|
|
-
|
|
|
|
- var handle = this.handleGizmos[i][0];
|
|
|
|
- handle.name = i;
|
|
|
|
- if ( this.handleGizmos[i][1] ) handle.position.set( this.handleGizmos[i][1].x, this.handleGizmos[i][1].y, this.handleGizmos[i][1].z );
|
|
|
|
- if ( this.handleGizmos[i][2] ) handle.rotation.set( this.handleGizmos[i][2].x, this.handleGizmos[i][2].y, this.handleGizmos[i][2].z );
|
|
|
|
-
|
|
|
|
- this.handles.add( handle );
|
|
|
|
-
|
|
|
|
- if ( this.pickerGizmos && this.pickerGizmos[i] ) {
|
|
|
|
-
|
|
|
|
- var picker = this.pickerGizmos[i][0];
|
|
|
|
- if ( this.pickerGizmos[i][1] ) picker.position.set( this.pickerGizmos[i][1].x, this.pickerGizmos[i][1].y, this.pickerGizmos[i][1].z );
|
|
|
|
- if ( this.pickerGizmos[i][2] ) picker.rotation.set( this.pickerGizmos[i][2].x, this.pickerGizmos[i][2].y, this.pickerGizmos[i][2].z );
|
|
|
|
-
|
|
|
|
} else {
|
|
} else {
|
|
|
|
|
|
- var picker = handle.clone();
|
|
|
|
|
|
+ this.color.copy( this.oldColor );
|
|
|
|
+ this.opacity = this.oldOpacity;
|
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
- picker.name = i;
|
|
|
|
- this.pickers.add( picker );
|
|
|
|
|
|
+ };
|
|
|
|
|
|
- }
|
|
|
|
|
|
+ };
|
|
|
|
|
|
- if ( this.lineGizmos ) {
|
|
|
|
|
|
+ GizmoMaterial.prototype = Object.create( THREE.MeshBasicMaterial.prototype );
|
|
|
|
|
|
- for ( var i in this.lineGizmos ) {
|
|
|
|
|
|
+ var GizmoLineMaterial = function ( parameters ) {
|
|
|
|
|
|
- var line = this.lineGizmos[i][0];
|
|
|
|
- line.name = i;
|
|
|
|
- this.lines.add( line );
|
|
|
|
|
|
+ THREE.LineBasicMaterial.call( this );
|
|
|
|
|
|
- }
|
|
|
|
|
|
+ this.depthTest = false;
|
|
|
|
+ this.depthWrite = false;
|
|
|
|
+ this.transparent = true;
|
|
|
|
+ this.linewidth = 1;
|
|
|
|
|
|
- }
|
|
|
|
|
|
+ this.setValues( parameters );
|
|
|
|
|
|
- // reset Transformations
|
|
|
|
|
|
+ this.oldColor = this.color.clone();
|
|
|
|
+ this.oldOpacity = this.opacity;
|
|
|
|
|
|
- this.traverse(function (child) {
|
|
|
|
- if (child instanceof THREE.Mesh) {
|
|
|
|
- var tempGeometry = new THREE.Geometry();
|
|
|
|
- THREE.GeometryUtils.merge( tempGeometry, child );
|
|
|
|
- child.geometry = tempGeometry;
|
|
|
|
- child.position.set( 0, 0, 0 );
|
|
|
|
- child.rotation.set( 0, 0, 0 );
|
|
|
|
- child.scale.set( 1, 1, 1 );
|
|
|
|
|
|
+ this.highlight = function( highlighted ) {
|
|
|
|
|
|
- }
|
|
|
|
- });
|
|
|
|
|
|
+ if ( highlighted ) {
|
|
|
|
|
|
- }
|
|
|
|
|
|
+ this.color.setRGB( 1, 1, 0 );
|
|
|
|
+ this.opacity = 1;
|
|
|
|
|
|
- this.hide = function () {
|
|
|
|
-
|
|
|
|
- for ( var j in this.handles.children ) this.handles.children[j].visible = false;
|
|
|
|
|
|
+ } else {
|
|
|
|
|
|
- for ( var j in this.lines.children ) this.lines.children[j].visible = false;
|
|
|
|
|
|
+ this.color.copy( this.oldColor );
|
|
|
|
+ this.opacity = this.oldOpacity;
|
|
|
|
|
|
- for ( var j in this.pickers.children ) this.pickers.children[j].visible = false;
|
|
|
|
|
|
+ }
|
|
|
|
|
|
- for ( var j in this.planes.children ) this.planes.children[j].visible = false;
|
|
|
|
|
|
+ };
|
|
|
|
|
|
- }
|
|
|
|
|
|
+ };
|
|
|
|
|
|
- this.show = function () {
|
|
|
|
|
|
+ GizmoLineMaterial.prototype = Object.create( THREE.LineBasicMaterial.prototype );
|
|
|
|
|
|
- for ( var i in this.handles.children ) this.handles.children[i].visible = true;
|
|
|
|
|
|
+ THREE.TransformGizmo = function () {
|
|
|
|
|
|
- for ( var i in this.lines.children ) this.lines.children[i].visible = true;
|
|
|
|
|
|
+ var scope = this;
|
|
|
|
+ var showPickers = false; //debug
|
|
|
|
+ var showActivePlane = false; //debug
|
|
|
|
|
|
- for ( var i in this.pickers.children ) this.pickers.children[i].visible = showPickers;
|
|
|
|
|
|
+ this.init = function () {
|
|
|
|
|
|
- if ( this.activePlane !== undefined ) this.activePlane.visible = showActivePlane;
|
|
|
|
|
|
+ THREE.Object3D.call( this );
|
|
|
|
|
|
- }
|
|
|
|
|
|
+ this.handles = new THREE.Object3D();
|
|
|
|
+ this.pickers = new THREE.Object3D();
|
|
|
|
+ this.planes = new THREE.Object3D();
|
|
|
|
|
|
- this.highlight = function ( axis ) {
|
|
|
|
|
|
+ this.add(this.handles);
|
|
|
|
+ this.add(this.pickers);
|
|
|
|
+ this.add(this.planes);
|
|
|
|
|
|
- var handle;
|
|
|
|
- var line;
|
|
|
|
|
|
+ //// PLANES
|
|
|
|
|
|
- for ( var i in this.handleGizmos ) {
|
|
|
|
|
|
+ var planeGeometry = new THREE.PlaneGeometry( 50, 50, 2, 2 );
|
|
|
|
+ var planeMaterial = new THREE.MeshBasicMaterial( { wireframe: true } );
|
|
|
|
+ planeMaterial.side = THREE.DoubleSide;
|
|
|
|
|
|
- handle = this.handleGizmos[ i ][0];
|
|
|
|
|
|
+ var planes = {
|
|
|
|
+ "XY": new THREE.Mesh( planeGeometry, planeMaterial ),
|
|
|
|
+ "YZ": new THREE.Mesh( planeGeometry, planeMaterial ),
|
|
|
|
+ "XZ": new THREE.Mesh( planeGeometry, planeMaterial ),
|
|
|
|
+ "XYZE": new THREE.Mesh( planeGeometry, planeMaterial )
|
|
|
|
+ };
|
|
|
|
|
|
- if ( handle.material.oldColor !== undefined ) {
|
|
|
|
|
|
+ this.activePlane = planes["XYZE"];
|
|
|
|
|
|
- handle.material.color.copy( handle.material.oldColor );
|
|
|
|
- handle.material.opacity = handle.material.oldOpacity;
|
|
|
|
|
|
+ planes["YZ"].rotation.set( 0, Math.PI/2, 0 );
|
|
|
|
+ planes["XZ"].rotation.set( -Math.PI/2, 0, 0 );
|
|
|
|
|
|
|
|
+ for (var i in planes) {
|
|
|
|
+ planes[i].name = i;
|
|
|
|
+ this.planes.add(planes[i]);
|
|
|
|
+ this.planes[i] = planes[i];
|
|
|
|
+ planes[i].visible = false;
|
|
}
|
|
}
|
|
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- if ( this.handleGizmos[ axis ] !== undefined ) {
|
|
|
|
-
|
|
|
|
- handle = this.handleGizmos[ axis ][0];
|
|
|
|
-
|
|
|
|
- handle.material.oldColor = handle.material.color.clone();
|
|
|
|
- handle.material.oldOpacity = handle.material.opacity;
|
|
|
|
-
|
|
|
|
- handle.material.color.setRGB( 1, 1, 0 );
|
|
|
|
- handle.material.opacity = 1;
|
|
|
|
-
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- for ( var i in this.lineGizmos ) {
|
|
|
|
-
|
|
|
|
- line = this.lineGizmos[ i ][0];
|
|
|
|
|
|
+ //// HANDLES AND PICKERS
|
|
|
|
|
|
- if ( line.material.oldColor !== undefined ) {
|
|
|
|
|
|
+ var setupGizmos = function( gizmoMap, parent ) {
|
|
|
|
|
|
- line.material.color.copy( line.material.oldColor );
|
|
|
|
- line.material.opacity = line.material.oldOpacity;
|
|
|
|
|
|
+ for ( var name in gizmoMap ) {
|
|
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- }
|
|
|
|
|
|
+ for ( i = gizmoMap[name].length; i--;) {
|
|
|
|
+
|
|
|
|
+ var object = gizmoMap[name][i][0];
|
|
|
|
+ var position = gizmoMap[name][i][1];
|
|
|
|
+ var rotation = gizmoMap[name][i][2];
|
|
|
|
|
|
- if ( this.lineGizmos[ axis ] !== undefined ) {
|
|
|
|
-
|
|
|
|
- line = this.lineGizmos[ axis ][0];
|
|
|
|
|
|
+ object.name = name;
|
|
|
|
|
|
- line.material.oldColor = line.material.color.clone();
|
|
|
|
- line.material.oldOpacity = line.material.opacity;
|
|
|
|
-
|
|
|
|
- line.material.color.setRGB( 1, 1, 0 );
|
|
|
|
- line.material.opacity = 1;
|
|
|
|
|
|
+ if ( position ) object.position.set( position[0], position[1], position[2] );
|
|
|
|
+ if ( rotation ) object.rotation.set( rotation[0], rotation[1], rotation[2] );
|
|
|
|
+
|
|
|
|
+ parent.add( object );
|
|
|
|
|
|
- }
|
|
|
|
|
|
+ }
|
|
|
|
|
|
- }
|
|
|
|
|
|
+ }
|
|
|
|
|
|
- this.init();
|
|
|
|
|
|
+ };
|
|
|
|
|
|
-}
|
|
|
|
|
|
+ setupGizmos(this.handleGizmos, this.handles);
|
|
|
|
+ setupGizmos(this.pickerGizmos, this.pickers);
|
|
|
|
|
|
-THREE.TransformGizmo.prototype = Object.create( THREE.Object3D.prototype );
|
|
|
|
|
|
+ // reset Transformations
|
|
|
|
|
|
-THREE.TransformGizmo.prototype.update = function ( rotation, eye ) {
|
|
|
|
|
|
+ this.traverse(function ( child ) {
|
|
|
|
+ if (child instanceof THREE.Mesh) {
|
|
|
|
+ var tempGeometry = new THREE.Geometry();
|
|
|
|
+ THREE.GeometryUtils.merge( tempGeometry, child );
|
|
|
|
+ child.geometry = tempGeometry;
|
|
|
|
+ child.position.set( 0, 0, 0 );
|
|
|
|
+ child.rotation.set( 0, 0, 0 );
|
|
|
|
+ child.scale.set( 1, 1, 1 );
|
|
|
|
+ }
|
|
|
|
+ });
|
|
|
|
|
|
- var vec1 = new THREE.Vector3( 0, 0, 0 );
|
|
|
|
- var vec2 = new THREE.Vector3( 0, 1, 0 );
|
|
|
|
- var lookAtMatrix = new THREE.Matrix4();
|
|
|
|
|
|
+ };
|
|
|
|
|
|
- for ( var i in this.children ) {
|
|
|
|
|
|
+ this.hide = function () {
|
|
|
|
+ this.traverse(function( child ) {
|
|
|
|
+ child.visible = false;
|
|
|
|
+ });
|
|
|
|
+ };
|
|
|
|
|
|
- for ( var j in this.children[i].children ) {
|
|
|
|
|
|
+ this.show = function () {
|
|
|
|
+ this.traverse(function( child ) {
|
|
|
|
+ child.visible = true;
|
|
|
|
+ if (child.parent == scope.pickers ) child.visible = showPickers;
|
|
|
|
+ if (child.parent == scope.planes ) child.visible = false;
|
|
|
|
+ });
|
|
|
|
+ this.activePlane.visible = showActivePlane;
|
|
|
|
+ };
|
|
|
|
|
|
- var object = this.children[i].children[j];
|
|
|
|
|
|
+ this.highlight = function ( axis ) {
|
|
|
|
+ this.traverse(function( child ) {
|
|
|
|
+ if ( child.material && child.material.highlight ){
|
|
|
|
+ if ( child.name == axis ) {
|
|
|
|
+ child.material.highlight( true );
|
|
|
|
+ } else {
|
|
|
|
+ child.material.highlight( false );
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ });
|
|
|
|
+ };
|
|
|
|
|
|
- if ( object.name.search("E") != -1 ) {
|
|
|
|
|
|
+ };
|
|
|
|
|
|
- object.quaternion.setFromRotationMatrix( lookAtMatrix.lookAt( eye, vec1, vec2 ) );
|
|
|
|
|
|
+ THREE.TransformGizmo.prototype = Object.create( THREE.Object3D.prototype );
|
|
|
|
|
|
- } else {
|
|
|
|
|
|
+ THREE.TransformGizmo.prototype.update = function ( rotation, eye ) {
|
|
|
|
|
|
- object.quaternion.setFromEuler( rotation );
|
|
|
|
|
|
+ var vec1 = new THREE.Vector3( 0, 0, 0 );
|
|
|
|
+ var vec2 = new THREE.Vector3( 0, 1, 0 );
|
|
|
|
+ var lookAtMatrix = new THREE.Matrix4();
|
|
|
|
|
|
|
|
+ this.traverse(function(child) {
|
|
|
|
+ if ( child.name.search("E") != -1 ) {
|
|
|
|
+ child.quaternion.setFromRotationMatrix( lookAtMatrix.lookAt( eye, vec1, vec2 ) );
|
|
|
|
+ } else if ( child.name.search("X") != -1 || child.name.search("Y") != -1 || child.name.search("Z") != -1 ) {
|
|
|
|
+ child.quaternion.setFromEuler( rotation );
|
|
}
|
|
}
|
|
|
|
+ });
|
|
|
|
|
|
- }
|
|
|
|
|
|
+ };
|
|
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
-THREE.TransformGizmoTranslate = function () {
|
|
|
|
-
|
|
|
|
- THREE.TransformGizmo.call( this );
|
|
|
|
-
|
|
|
|
- var arrowGeometry = new THREE.Geometry();
|
|
|
|
- var mesh = new THREE.Mesh( new THREE.CylinderGeometry( 0, 0.05, 0.2, 12, 1, false ) );
|
|
|
|
- mesh.position.y = 0.5;
|
|
|
|
- THREE.GeometryUtils.merge( arrowGeometry, mesh );
|
|
|
|
-
|
|
|
|
- var lineXGeometry = new THREE.Geometry();
|
|
|
|
- lineXGeometry.vertices.push( new THREE.Vector3( 0, 0, 0 ), new THREE.Vector3( 1, 0, 0 ) );
|
|
|
|
-
|
|
|
|
- var lineYGeometry = new THREE.Geometry();
|
|
|
|
- lineYGeometry.vertices.push( new THREE.Vector3( 0, 0, 0 ), new THREE.Vector3( 0, 1, 0 ) );
|
|
|
|
-
|
|
|
|
- var lineZGeometry = new THREE.Geometry();
|
|
|
|
- lineZGeometry.vertices.push( new THREE.Vector3( 0, 0, 0 ), new THREE.Vector3( 0, 0, 1 ) );
|
|
|
|
-
|
|
|
|
- this.handleGizmos = {
|
|
|
|
-
|
|
|
|
- X: [
|
|
|
|
- new THREE.Mesh( arrowGeometry, new THREE.TransformGizmoMaterial( { color: 0xff0000 } ) ),
|
|
|
|
- new THREE.Vector3( 0.5, 0, 0 ),
|
|
|
|
- new THREE.Vector3( 0, 0, -Math.PI/2 )
|
|
|
|
- ],
|
|
|
|
- Y: [
|
|
|
|
- new THREE.Mesh( arrowGeometry, new THREE.TransformGizmoMaterial( { color: 0x00ff00 } ) ),
|
|
|
|
- new THREE.Vector3( 0, 0.5, 0 )
|
|
|
|
- ],
|
|
|
|
- Z: [
|
|
|
|
- new THREE.Mesh( arrowGeometry, new THREE.TransformGizmoMaterial( { color: 0x0000ff } ) ),
|
|
|
|
- new THREE.Vector3( 0, 0, 0.5 ),
|
|
|
|
- new THREE.Vector3( Math.PI/2, 0, 0 )
|
|
|
|
- ],
|
|
|
|
- XYZ: [
|
|
|
|
- new THREE.Mesh( new THREE.OctahedronGeometry( 0.1, 0 ), new THREE.TransformGizmoMaterial( { color: 0xffffff, opacity: 0.25 } ) ),
|
|
|
|
- new THREE.Vector3( 0, 0, 0 ),
|
|
|
|
- new THREE.Vector3( 0, 0, 0 )
|
|
|
|
- ],
|
|
|
|
- XY: [
|
|
|
|
- new THREE.Mesh( new THREE.PlaneGeometry( 0.29, 0.29 ), new THREE.TransformGizmoMaterial( { color: 0xffff00, opacity: 0.25 } ) ),
|
|
|
|
- new THREE.Vector3( 0.15, 0.15, 0 )
|
|
|
|
- ],
|
|
|
|
- YZ: [
|
|
|
|
- new THREE.Mesh( new THREE.PlaneGeometry( 0.29, 0.29 ), new THREE.TransformGizmoMaterial( { color: 0x00ffff, opacity: 0.25 } ) ),
|
|
|
|
- new THREE.Vector3( 0, 0.15, 0.15 ),
|
|
|
|
- new THREE.Vector3( 0, Math.PI/2, 0 )
|
|
|
|
- ],
|
|
|
|
- XZ: [
|
|
|
|
- new THREE.Mesh( new THREE.PlaneGeometry( 0.29, 0.29 ), new THREE.TransformGizmoMaterial( { color: 0xff00ff, opacity: 0.25 } ) ),
|
|
|
|
- new THREE.Vector3( 0.15, 0, 0.15 ),
|
|
|
|
- new THREE.Vector3( -Math.PI/2, 0, 0 )
|
|
|
|
- ]
|
|
|
|
-
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- this.lineGizmos = {
|
|
|
|
-
|
|
|
|
- X: [
|
|
|
|
- new THREE.Line( lineXGeometry, new THREE.TransformGizmoLineMaterial( { color: 0xff0000 } ) ),
|
|
|
|
- ],
|
|
|
|
- Y: [
|
|
|
|
- new THREE.Line( lineYGeometry, new THREE.TransformGizmoLineMaterial( { color: 0x00ff00 } ) ),
|
|
|
|
- ],
|
|
|
|
- Z: [
|
|
|
|
- new THREE.Line( lineZGeometry, new THREE.TransformGizmoLineMaterial( { color: 0x0000ff } ) ),
|
|
|
|
- ]
|
|
|
|
-
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- this.pickerGizmos = {
|
|
|
|
-
|
|
|
|
- X: [
|
|
|
|
- new THREE.Mesh( new THREE.CylinderGeometry( 0.2, 0, 1, 4, 1, false ), new THREE.TransformGizmoMaterial( { color: 0xff0000, opacity: 0.25 } ) ),
|
|
|
|
- new THREE.Vector3( 0.6, 0, 0 ),
|
|
|
|
- new THREE.Vector3( 0, 0, -Math.PI/2 )
|
|
|
|
- ],
|
|
|
|
- Y: [
|
|
|
|
- new THREE.Mesh( new THREE.CylinderGeometry( 0.2, 0, 1, 4, 1, false ), new THREE.TransformGizmoMaterial( { color: 0x00ff00, opacity: 0.25 } ) ),
|
|
|
|
- new THREE.Vector3( 0, 0.6, 0 )
|
|
|
|
- ],
|
|
|
|
- Z: [
|
|
|
|
- new THREE.Mesh( new THREE.CylinderGeometry( 0.2, 0, 1, 4, 1, false ), new THREE.TransformGizmoMaterial( { color: 0x0000ff, opacity: 0.25 } ) ),
|
|
|
|
- new THREE.Vector3( 0, 0, 0.6 ),
|
|
|
|
- new THREE.Vector3( Math.PI/2, 0, 0 )
|
|
|
|
- ],
|
|
|
|
- XYZ: [
|
|
|
|
- new THREE.Mesh( new THREE.OctahedronGeometry( 0.2, 0 ), new THREE.TransformGizmoMaterial( { color: 0xffffff, opacity: 0.25 } ) )
|
|
|
|
- ],
|
|
|
|
- XY: [
|
|
|
|
- new THREE.Mesh( new THREE.PlaneGeometry( 0.4, 0.4 ), new THREE.TransformGizmoMaterial( { color: 0xffff00, opacity: 0.25 } ) ),
|
|
|
|
- new THREE.Vector3( 0.2, 0.2, 0 )
|
|
|
|
- ],
|
|
|
|
- YZ: [
|
|
|
|
- new THREE.Mesh( new THREE.PlaneGeometry( 0.4, 0.4 ), new THREE.TransformGizmoMaterial( { color: 0x00ffff, opacity: 0.25 } ) ),
|
|
|
|
- new THREE.Vector3( 0, 0.2, 0.2 ),
|
|
|
|
- new THREE.Vector3( 0, Math.PI/2, 0 )
|
|
|
|
- ],
|
|
|
|
- XZ: [
|
|
|
|
- new THREE.Mesh( new THREE.PlaneGeometry( 0.4, 0.4 ), new THREE.TransformGizmoMaterial( { color: 0xff00ff, opacity: 0.25 } ) ),
|
|
|
|
- new THREE.Vector3( 0.2, 0, 0.2 ),
|
|
|
|
- new THREE.Vector3( -Math.PI/2, 0, 0 )
|
|
|
|
- ]
|
|
|
|
-
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- this.setActivePlane = function ( axis, eye ) {
|
|
|
|
|
|
+ THREE.TransformGizmoTranslate = function () {
|
|
|
|
|
|
- var tempMatrix = new THREE.Matrix4();
|
|
|
|
- eye.applyProjection( tempMatrix.getInverse( tempMatrix.extractRotation( this.planes[ "XY" ].matrixWorld ) ) );
|
|
|
|
|
|
+ THREE.TransformGizmo.call( this );
|
|
|
|
|
|
- if ( axis == "X" ) {
|
|
|
|
- this.activePlane = this.planes[ "XY" ];
|
|
|
|
- if ( Math.abs(eye.y) > Math.abs(eye.z) ) this.activePlane = this.planes[ "XZ" ];
|
|
|
|
- }
|
|
|
|
|
|
+ var arrowGeometry = new THREE.Geometry();
|
|
|
|
+ var mesh = new THREE.Mesh( new THREE.CylinderGeometry( 0, 0.05, 0.2, 12, 1, false ) );
|
|
|
|
+ mesh.position.y = 0.5;
|
|
|
|
+ THREE.GeometryUtils.merge( arrowGeometry, mesh );
|
|
|
|
+
|
|
|
|
+ var lineXGeometry = new THREE.Geometry();
|
|
|
|
+ lineXGeometry.vertices.push( new THREE.Vector3( 0, 0, 0 ), new THREE.Vector3( 1, 0, 0 ) );
|
|
|
|
+
|
|
|
|
+ var lineYGeometry = new THREE.Geometry();
|
|
|
|
+ lineYGeometry.vertices.push( new THREE.Vector3( 0, 0, 0 ), new THREE.Vector3( 0, 1, 0 ) );
|
|
|
|
+
|
|
|
|
+ var lineZGeometry = new THREE.Geometry();
|
|
|
|
+ lineZGeometry.vertices.push( new THREE.Vector3( 0, 0, 0 ), new THREE.Vector3( 0, 0, 1 ) );
|
|
|
|
+
|
|
|
|
+ this.handleGizmos = {
|
|
|
|
+ X: [
|
|
|
|
+ [ new THREE.Mesh( arrowGeometry, new GizmoMaterial( { color: 0xff0000 } ) ), [ 0.5, 0, 0 ], [ 0, 0, -Math.PI/2 ] ],
|
|
|
|
+ [ new THREE.Line( lineXGeometry, new GizmoLineMaterial( { color: 0xff0000 } ) ) ]
|
|
|
|
+ ],
|
|
|
|
+ Y: [
|
|
|
|
+ [ new THREE.Mesh( arrowGeometry, new GizmoMaterial( { color: 0x00ff00 } ) ), [ 0, 0.5, 0 ] ],
|
|
|
|
+ [ new THREE.Line( lineYGeometry, new GizmoLineMaterial( { color: 0x00ff00 } ) ) ]
|
|
|
|
+ ],
|
|
|
|
+ Z: [
|
|
|
|
+ [ new THREE.Mesh( arrowGeometry, new GizmoMaterial( { color: 0x0000ff } ) ), [ 0, 0, 0.5 ], [ Math.PI/2, 0, 0 ] ],
|
|
|
|
+ [ new THREE.Line( lineZGeometry, new GizmoLineMaterial( { color: 0x0000ff } ) ) ]
|
|
|
|
+ ],
|
|
|
|
+ XYZ: [
|
|
|
|
+ [ new THREE.Mesh( new THREE.OctahedronGeometry( 0.1, 0 ), new GizmoMaterial( { color: 0xffffff, opacity: 0.25 } ) ), [ 0, 0, 0 ], [ 0, 0, 0 ] ]
|
|
|
|
+ ],
|
|
|
|
+ XY: [
|
|
|
|
+ [ new THREE.Mesh( new THREE.PlaneGeometry( 0.29, 0.29 ), new GizmoMaterial( { color: 0xffff00, opacity: 0.25 } ) ), [ 0.15, 0.15, 0 ] ]
|
|
|
|
+ ],
|
|
|
|
+ YZ: [
|
|
|
|
+ [ new THREE.Mesh( new THREE.PlaneGeometry( 0.29, 0.29 ), new GizmoMaterial( { color: 0x00ffff, opacity: 0.25 } ) ), [ 0, 0.15, 0.15 ], [ 0, Math.PI/2, 0 ] ]
|
|
|
|
+ ],
|
|
|
|
+ XZ: [
|
|
|
|
+ [ new THREE.Mesh( new THREE.PlaneGeometry( 0.29, 0.29 ), new GizmoMaterial( { color: 0xff00ff, opacity: 0.25 } ) ), [ 0.15, 0, 0.15 ], [ -Math.PI/2, 0, 0 ] ]
|
|
|
|
+ ]
|
|
|
|
+ };
|
|
|
|
|
|
- if ( axis == "Y" ){
|
|
|
|
- this.activePlane = this.planes[ "XY" ];
|
|
|
|
- if ( Math.abs(eye.x) > Math.abs(eye.z) ) this.activePlane = this.planes[ "YZ" ];
|
|
|
|
- }
|
|
|
|
|
|
+ this.pickerGizmos = {
|
|
|
|
+ X: [
|
|
|
|
+ [ new THREE.Mesh( new THREE.CylinderGeometry( 0.2, 0, 1, 4, 1, false ), new GizmoMaterial( { color: 0xff0000, opacity: 0.25 } ) ), [ 0.6, 0, 0 ], [ 0, 0, -Math.PI/2 ] ]
|
|
|
|
+ ],
|
|
|
|
+ Y: [
|
|
|
|
+ [ new THREE.Mesh( new THREE.CylinderGeometry( 0.2, 0, 1, 4, 1, false ), new GizmoMaterial( { color: 0x00ff00, opacity: 0.25 } ) ), [ 0, 0.6, 0 ] ]
|
|
|
|
+ ],
|
|
|
|
+ Z: [
|
|
|
|
+ [ new THREE.Mesh( new THREE.CylinderGeometry( 0.2, 0, 1, 4, 1, false ), new GizmoMaterial( { color: 0x0000ff, opacity: 0.25 } ) ), [ 0, 0, 0.6 ], [ Math.PI/2, 0, 0 ] ]
|
|
|
|
+ ],
|
|
|
|
+ XYZ: [
|
|
|
|
+ [ new THREE.Mesh( new THREE.OctahedronGeometry( 0.2, 0 ), new GizmoMaterial( { color: 0xffffff, opacity: 0.25 } ) ) ]
|
|
|
|
+ ],
|
|
|
|
+ XY: [
|
|
|
|
+ [ new THREE.Mesh( new THREE.PlaneGeometry( 0.4, 0.4 ), new GizmoMaterial( { color: 0xffff00, opacity: 0.25 } ) ), [ 0.2, 0.2, 0 ] ]
|
|
|
|
+ ],
|
|
|
|
+ YZ: [
|
|
|
|
+ [ new THREE.Mesh( new THREE.PlaneGeometry( 0.4, 0.4 ), new GizmoMaterial( { color: 0x00ffff, opacity: 0.25 } ) ), [ 0, 0.2, 0.2 ], [ 0, Math.PI/2, 0 ] ]
|
|
|
|
+ ],
|
|
|
|
+ XZ: [
|
|
|
|
+ [ new THREE.Mesh( new THREE.PlaneGeometry( 0.4, 0.4 ), new GizmoMaterial( { color: 0xff00ff, opacity: 0.25 } ) ), [ 0.2, 0, 0.2 ], [ -Math.PI/2, 0, 0 ] ]
|
|
|
|
+ ]
|
|
|
|
+ };
|
|
|
|
|
|
- if ( axis == "Z" ){
|
|
|
|
- this.activePlane = this.planes[ "XZ" ];
|
|
|
|
- if ( Math.abs(eye.x) > Math.abs(eye.y) ) this.activePlane = this.planes[ "YZ" ];
|
|
|
|
- }
|
|
|
|
|
|
+ this.setActivePlane = function ( axis, eye ) {
|
|
|
|
|
|
- if ( axis == "XYZ" ) this.activePlane = this.planes[ "XYZE" ];
|
|
|
|
|
|
+ var tempMatrix = new THREE.Matrix4();
|
|
|
|
+ eye.applyProjection( tempMatrix.getInverse( tempMatrix.extractRotation( this.planes[ "XY" ].matrixWorld ) ) );
|
|
|
|
|
|
- if ( axis == "XY" ) this.activePlane = this.planes[ "XY" ];
|
|
|
|
|
|
+ if ( axis == "X" ) {
|
|
|
|
+ this.activePlane = this.planes[ "XY" ];
|
|
|
|
+ if ( Math.abs(eye.y) > Math.abs(eye.z) ) this.activePlane = this.planes[ "XZ" ];
|
|
|
|
+ }
|
|
|
|
|
|
- if ( axis == "YZ" ) this.activePlane = this.planes[ "YZ" ];
|
|
|
|
|
|
+ if ( axis == "Y" ){
|
|
|
|
+ this.activePlane = this.planes[ "XY" ];
|
|
|
|
+ if ( Math.abs(eye.x) > Math.abs(eye.z) ) this.activePlane = this.planes[ "YZ" ];
|
|
|
|
+ }
|
|
|
|
|
|
- if ( axis == "XZ" ) this.activePlane = this.planes[ "XZ" ];
|
|
|
|
|
|
+ if ( axis == "Z" ){
|
|
|
|
+ this.activePlane = this.planes[ "XZ" ];
|
|
|
|
+ if ( Math.abs(eye.x) > Math.abs(eye.y) ) this.activePlane = this.planes[ "YZ" ];
|
|
|
|
+ }
|
|
|
|
|
|
- this.hide();
|
|
|
|
- this.show();
|
|
|
|
|
|
+ if ( axis == "XYZ" ) this.activePlane = this.planes[ "XYZE" ];
|
|
|
|
|
|
- }
|
|
|
|
|
|
+ if ( axis == "XY" ) this.activePlane = this.planes[ "XY" ];
|
|
|
|
|
|
- this.init();
|
|
|
|
|
|
+ if ( axis == "YZ" ) this.activePlane = this.planes[ "YZ" ];
|
|
|
|
|
|
-}
|
|
|
|
|
|
+ if ( axis == "XZ" ) this.activePlane = this.planes[ "XZ" ];
|
|
|
|
|
|
-THREE.TransformGizmoTranslate.prototype = Object.create( THREE.TransformGizmo.prototype );
|
|
|
|
|
|
+ this.hide();
|
|
|
|
+ this.show();
|
|
|
|
|
|
-THREE.TransformGizmoRotate = function () {
|
|
|
|
|
|
+ };
|
|
|
|
|
|
- THREE.TransformGizmo.call( this );
|
|
|
|
|
|
+ this.init();
|
|
|
|
|
|
- var CircleGeometry = function ( radius, facing, arc ) {
|
|
|
|
|
|
+ };
|
|
|
|
|
|
- var geometry = new THREE.Geometry();
|
|
|
|
- arc = arc ? arc : 1;
|
|
|
|
- for ( var i = 0; i <= 64 * arc; ++i ) {
|
|
|
|
- if ( facing == 'x' ) geometry.vertices.push( new THREE.Vector3( 0, Math.cos( i / 32 * Math.PI ), Math.sin( i / 32 * Math.PI ) ).multiplyScalar(radius) );
|
|
|
|
- if ( facing == 'y' ) geometry.vertices.push( new THREE.Vector3( Math.cos( i / 32 * Math.PI ), 0, Math.sin( i / 32 * Math.PI ) ).multiplyScalar(radius) );
|
|
|
|
- if ( facing == 'z' ) geometry.vertices.push( new THREE.Vector3( Math.sin( i / 32 * Math.PI ), Math.cos( i / 32 * Math.PI ), 0 ).multiplyScalar(radius) );
|
|
|
|
- }
|
|
|
|
|
|
+ THREE.TransformGizmoTranslate.prototype = Object.create( THREE.TransformGizmo.prototype );
|
|
|
|
|
|
- return geometry;
|
|
|
|
- }
|
|
|
|
|
|
+ THREE.TransformGizmoRotate = function () {
|
|
|
|
|
|
- this.handleGizmos = {
|
|
|
|
|
|
+ THREE.TransformGizmo.call( this );
|
|
|
|
|
|
- X: [
|
|
|
|
- new THREE.Line( CircleGeometry(1,'x',0.5), new THREE.TransformGizmoLineMaterial( { color: 0xff0000 } ) ),
|
|
|
|
- ],
|
|
|
|
- Y: [
|
|
|
|
- new THREE.Line( CircleGeometry(1,'y',0.5), new THREE.TransformGizmoLineMaterial( { color: 0x00ff00 } ) ),
|
|
|
|
- ],
|
|
|
|
- Z: [
|
|
|
|
- new THREE.Line( CircleGeometry(1,'z',0.5), new THREE.TransformGizmoLineMaterial( { color: 0x0000ff } ) ),
|
|
|
|
- ],
|
|
|
|
- E: [
|
|
|
|
- new THREE.Line( CircleGeometry(1.25,'z',1), new THREE.TransformGizmoLineMaterial( { color: 0xcccc00 } ) ),
|
|
|
|
- ],
|
|
|
|
- XYZE: [
|
|
|
|
- new THREE.Line( CircleGeometry(1,'z',1), new THREE.TransformGizmoLineMaterial( { color: 0x787878 } ) ),
|
|
|
|
- ]
|
|
|
|
|
|
+ var CircleGeometry = function ( radius, facing, arc ) {
|
|
|
|
|
|
- }
|
|
|
|
|
|
+ var geometry = new THREE.Geometry();
|
|
|
|
+ arc = arc ? arc : 1;
|
|
|
|
+ for ( var i = 0; i <= 64 * arc; ++i ) {
|
|
|
|
+ if ( facing == 'x' ) geometry.vertices.push( new THREE.Vector3( 0, Math.cos( i / 32 * Math.PI ), Math.sin( i / 32 * Math.PI ) ).multiplyScalar(radius) );
|
|
|
|
+ if ( facing == 'y' ) geometry.vertices.push( new THREE.Vector3( Math.cos( i / 32 * Math.PI ), 0, Math.sin( i / 32 * Math.PI ) ).multiplyScalar(radius) );
|
|
|
|
+ if ( facing == 'z' ) geometry.vertices.push( new THREE.Vector3( Math.sin( i / 32 * Math.PI ), Math.cos( i / 32 * Math.PI ), 0 ).multiplyScalar(radius) );
|
|
|
|
+ }
|
|
|
|
|
|
- this.lineGizmos = {}
|
|
|
|
|
|
+ return geometry;
|
|
|
|
+ };
|
|
|
|
|
|
- this.pickerGizmos = {
|
|
|
|
|
|
+ this.handleGizmos = {
|
|
|
|
+ X: [
|
|
|
|
+ [ new THREE.Line( new CircleGeometry(1,'x',0.5), new GizmoLineMaterial( { color: 0xff0000 } ) ) ]
|
|
|
|
+ ],
|
|
|
|
+ Y: [
|
|
|
|
+ [ new THREE.Line( new CircleGeometry(1,'y',0.5), new GizmoLineMaterial( { color: 0x00ff00 } ) ) ]
|
|
|
|
+ ],
|
|
|
|
+ Z: [
|
|
|
|
+ [ new THREE.Line( new CircleGeometry(1,'z',0.5), new GizmoLineMaterial( { color: 0x0000ff } ) ) ]
|
|
|
|
+ ],
|
|
|
|
+ E: [
|
|
|
|
+ [ new THREE.Line( new CircleGeometry(1.25,'z',1), new GizmoLineMaterial( { color: 0xcccc00 } ) ) ]
|
|
|
|
+ ],
|
|
|
|
+ XYZE: [
|
|
|
|
+ [ new THREE.Line( new CircleGeometry(1,'z',1), new GizmoLineMaterial( { color: 0x787878 } ) ) ]
|
|
|
|
+ ]
|
|
|
|
+ };
|
|
|
|
|
|
- X: [
|
|
|
|
- new THREE.Mesh( new THREE.TorusGeometry( 1, 0.12, 4, 12, Math.PI ), new THREE.TransformGizmoMaterial( { color: 0xff0000, opacity: 0.25 } ) ),
|
|
|
|
- new THREE.Vector3( 0, 0, 0 ),
|
|
|
|
- new THREE.Vector3( 0, -Math.PI/2, -Math.PI/2 )
|
|
|
|
- ],
|
|
|
|
- Y: [
|
|
|
|
- new THREE.Mesh( new THREE.TorusGeometry( 1, 0.12, 4, 12, Math.PI ), new THREE.TransformGizmoMaterial( { color: 0x00ff00, opacity: 0.25 } ) ),
|
|
|
|
- new THREE.Vector3( 0, 0, 0 ),
|
|
|
|
- new THREE.Vector3( Math.PI/2, 0, 0 )
|
|
|
|
- ],
|
|
|
|
- Z: [
|
|
|
|
- new THREE.Mesh( new THREE.TorusGeometry( 1, 0.12, 4, 12, Math.PI ), new THREE.TransformGizmoMaterial( { color: 0x0000ff, opacity: 0.25 } ) ),
|
|
|
|
- new THREE.Vector3( 0, 0, 0 ),
|
|
|
|
- new THREE.Vector3( 0, 0, -Math.PI/2 )
|
|
|
|
- ],
|
|
|
|
- E: [
|
|
|
|
- new THREE.Mesh( new THREE.TorusGeometry( 1.25, 0.12, 2, 24 ), new THREE.TransformGizmoMaterial( { color: 0xffff00, opacity: 0.25 } ) )
|
|
|
|
- ],
|
|
|
|
- XYZE: [
|
|
|
|
- new THREE.Mesh( new THREE.Geometry() ) // TODO
|
|
|
|
- ]
|
|
|
|
|
|
+ this.pickerGizmos = {
|
|
|
|
+ X: [
|
|
|
|
+ [ new THREE.Mesh( new THREE.TorusGeometry( 1, 0.12, 4, 12, Math.PI ), new GizmoMaterial( { color: 0xff0000, opacity: 0.25 } ) ), [ 0, 0, 0 ], [ 0, -Math.PI/2, -Math.PI/2 ] ]
|
|
|
|
+ ],
|
|
|
|
+ Y: [
|
|
|
|
+ [ new THREE.Mesh( new THREE.TorusGeometry( 1, 0.12, 4, 12, Math.PI ), new GizmoMaterial( { color: 0x00ff00, opacity: 0.25 } ) ), [ 0, 0, 0 ], [ Math.PI/2, 0, 0 ] ]
|
|
|
|
+ ],
|
|
|
|
+ Z: [
|
|
|
|
+ [ new THREE.Mesh( new THREE.TorusGeometry( 1, 0.12, 4, 12, Math.PI ), new GizmoMaterial( { color: 0x0000ff, opacity: 0.25 } ) ), [ 0, 0, 0 ], [ 0, 0, -Math.PI/2 ] ]
|
|
|
|
+ ],
|
|
|
|
+ E: [
|
|
|
|
+ [ new THREE.Mesh( new THREE.TorusGeometry( 1.25, 0.12, 2, 24 ), new GizmoMaterial( { color: 0xffff00, opacity: 0.25 } ) ) ]
|
|
|
|
+ ],
|
|
|
|
+ XYZE: [
|
|
|
|
+ [ new THREE.Mesh( new THREE.Geometry() ) ]// TODO
|
|
|
|
+ ]
|
|
|
|
+ };
|
|
|
|
|
|
- }
|
|
|
|
|
|
+ this.setActivePlane = function ( axis ) {
|
|
|
|
|
|
- this.setActivePlane = function ( axis ) {
|
|
|
|
|
|
+ if ( axis == "E" ) this.activePlane = this.planes[ "XYZE" ];
|
|
|
|
|
|
- if ( axis == "E" ) this.activePlane = this.planes[ "XYZE" ];
|
|
|
|
|
|
+ if ( axis == "X" ) this.activePlane = this.planes[ "YZ" ];
|
|
|
|
|
|
- if ( axis == "X" ) this.activePlane = this.planes[ "YZ" ];
|
|
|
|
|
|
+ if ( axis == "Y" ) this.activePlane = this.planes[ "XZ" ];
|
|
|
|
|
|
- if ( axis == "Y" ) this.activePlane = this.planes[ "XZ" ];
|
|
|
|
|
|
+ if ( axis == "Z" ) this.activePlane = this.planes[ "XY" ];
|
|
|
|
|
|
- if ( axis == "Z" ) this.activePlane = this.planes[ "XY" ];
|
|
|
|
|
|
+ this.hide();
|
|
|
|
+ this.show();
|
|
|
|
|
|
- this.hide();
|
|
|
|
- this.show();
|
|
|
|
|
|
+ };
|
|
|
|
|
|
- }
|
|
|
|
|
|
+ this.update = function ( rotation, eye2 ) {
|
|
|
|
|
|
- this.update = function ( rotation, eye2 ) {
|
|
|
|
|
|
+ THREE.TransformGizmo.prototype.update.apply( this, arguments );
|
|
|
|
|
|
- THREE.TransformGizmo.prototype.update.apply( this, arguments );
|
|
|
|
|
|
+ var group = {
|
|
|
|
+ handles: this["handles"],
|
|
|
|
+ pickers: this["pickers"],
|
|
|
|
+ };
|
|
|
|
|
|
- var group = {
|
|
|
|
- handles: this["handles"],
|
|
|
|
- pickers: this["pickers"],
|
|
|
|
- }
|
|
|
|
|
|
+ var tempMatrix = new THREE.Matrix4();
|
|
|
|
+ var worldRotation = new THREE.Euler( 0, 0, 1 );
|
|
|
|
+ var tempQuaternion = new THREE.Quaternion();
|
|
|
|
+ var unitX = new THREE.Vector3( 1, 0, 0 );
|
|
|
|
+ var unitY = new THREE.Vector3( 0, 1, 0 );
|
|
|
|
+ var unitZ = new THREE.Vector3( 0, 0, 1 );
|
|
|
|
+ var quaternionX = new THREE.Quaternion();
|
|
|
|
+ var quaternionY = new THREE.Quaternion();
|
|
|
|
+ var quaternionZ = new THREE.Quaternion();
|
|
|
|
+ var eye = eye2.clone();
|
|
|
|
|
|
- var tempMatrix = new THREE.Matrix4();
|
|
|
|
- var worldRotation = new THREE.Euler( 0, 0, 1 );
|
|
|
|
- var tempQuaternion = new THREE.Quaternion();
|
|
|
|
- var unitX = new THREE.Vector3( 1, 0, 0 );
|
|
|
|
- var unitY = new THREE.Vector3( 0, 1, 0 );
|
|
|
|
- var unitZ = new THREE.Vector3( 0, 0, 1 );
|
|
|
|
- var quaternionX = new THREE.Quaternion();
|
|
|
|
- var quaternionY = new THREE.Quaternion();
|
|
|
|
- var quaternionZ = new THREE.Quaternion();
|
|
|
|
- var eye = eye2.clone();
|
|
|
|
|
|
+ worldRotation.copy( this.planes["XY"].rotation );
|
|
|
|
+ tempQuaternion.setFromEuler( worldRotation );
|
|
|
|
|
|
- worldRotation.copy( this.planes["XY"].rotation );
|
|
|
|
- tempQuaternion.setFromEuler( worldRotation );
|
|
|
|
|
|
+ tempMatrix.makeRotationFromQuaternion( tempQuaternion ).getInverse( tempMatrix );
|
|
|
|
+ eye.applyProjection( tempMatrix );
|
|
|
|
|
|
- tempMatrix.makeRotationFromQuaternion( tempQuaternion ).getInverse( tempMatrix );
|
|
|
|
- eye.applyProjection( tempMatrix );
|
|
|
|
-
|
|
|
|
- for ( var i in group ) {
|
|
|
|
-
|
|
|
|
- for ( var j in group[i].children ) {
|
|
|
|
-
|
|
|
|
- var object = group[i].children[j];
|
|
|
|
|
|
+ this.traverse(function(child) {
|
|
|
|
|
|
tempQuaternion.setFromEuler( worldRotation );
|
|
tempQuaternion.setFromEuler( worldRotation );
|
|
|
|
|
|
- if ( object.name == "X" ) {
|
|
|
|
|
|
+ if ( child.name == "X" ) {
|
|
quaternionX.setFromAxisAngle( unitX, Math.atan2( -eye.y, eye.z ) );
|
|
quaternionX.setFromAxisAngle( unitX, Math.atan2( -eye.y, eye.z ) );
|
|
tempQuaternion.multiplyQuaternions( tempQuaternion, quaternionX );
|
|
tempQuaternion.multiplyQuaternions( tempQuaternion, quaternionX );
|
|
- object.quaternion.copy( tempQuaternion );
|
|
|
|
|
|
+ child.quaternion.copy( tempQuaternion );
|
|
}
|
|
}
|
|
|
|
|
|
- if ( object.name == "Y" ) {
|
|
|
|
|
|
+ if ( child.name == "Y" ) {
|
|
quaternionY.setFromAxisAngle( unitY, Math.atan2( eye.x, eye.z ) );
|
|
quaternionY.setFromAxisAngle( unitY, Math.atan2( eye.x, eye.z ) );
|
|
tempQuaternion.multiplyQuaternions( tempQuaternion, quaternionY );
|
|
tempQuaternion.multiplyQuaternions( tempQuaternion, quaternionY );
|
|
- object.quaternion.copy( tempQuaternion );
|
|
|
|
|
|
+ child.quaternion.copy( tempQuaternion );
|
|
}
|
|
}
|
|
|
|
|
|
- if ( object.name == "Z" ) {
|
|
|
|
|
|
+ if ( child.name == "Z" ) {
|
|
quaternionZ.setFromAxisAngle( unitZ, Math.atan2( eye.y, eye.x ) );
|
|
quaternionZ.setFromAxisAngle( unitZ, Math.atan2( eye.y, eye.x ) );
|
|
tempQuaternion.multiplyQuaternions( tempQuaternion, quaternionZ );
|
|
tempQuaternion.multiplyQuaternions( tempQuaternion, quaternionZ );
|
|
- object.quaternion.copy( tempQuaternion );
|
|
|
|
|
|
+ child.quaternion.copy( tempQuaternion );
|
|
}
|
|
}
|
|
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
|
|
+ });
|
|
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- this.init();
|
|
|
|
-
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
-THREE.TransformGizmoRotate.prototype = Object.create( THREE.TransformGizmo.prototype );
|
|
|
|
-
|
|
|
|
-THREE.TransformGizmoScale = function () {
|
|
|
|
-
|
|
|
|
- THREE.TransformGizmo.call( this );
|
|
|
|
-
|
|
|
|
- var arrowGeometry = new THREE.Geometry();
|
|
|
|
- var mesh = new THREE.Mesh( new THREE.BoxGeometry( 0.125, 0.125, 0.125 ) );
|
|
|
|
- mesh.position.y = 0.5;
|
|
|
|
- THREE.GeometryUtils.merge( arrowGeometry, mesh );
|
|
|
|
-
|
|
|
|
- var lineXGeometry = new THREE.Geometry();
|
|
|
|
- lineXGeometry.vertices.push( new THREE.Vector3( 0, 0, 0 ), new THREE.Vector3( 1, 0, 0 ) );
|
|
|
|
-
|
|
|
|
- var lineYGeometry = new THREE.Geometry();
|
|
|
|
- lineYGeometry.vertices.push( new THREE.Vector3( 0, 0, 0 ), new THREE.Vector3( 0, 1, 0 ) );
|
|
|
|
-
|
|
|
|
- var lineZGeometry = new THREE.Geometry();
|
|
|
|
- lineZGeometry.vertices.push( new THREE.Vector3( 0, 0, 0 ), new THREE.Vector3( 0, 0, 1 ) );
|
|
|
|
-
|
|
|
|
- this.handleGizmos = {
|
|
|
|
-
|
|
|
|
- X: [
|
|
|
|
- new THREE.Mesh( arrowGeometry, new THREE.TransformGizmoMaterial( { color: 0xff0000 } ) ),
|
|
|
|
- new THREE.Vector3( 0.5, 0, 0 ),
|
|
|
|
- new THREE.Vector3( 0, 0, -Math.PI/2 )
|
|
|
|
- ],
|
|
|
|
- Y: [
|
|
|
|
- new THREE.Mesh( arrowGeometry, new THREE.TransformGizmoMaterial( { color: 0x00ff00 } ) ),
|
|
|
|
- new THREE.Vector3( 0, 0.5, 0 )
|
|
|
|
- ],
|
|
|
|
- Z: [
|
|
|
|
- new THREE.Mesh( arrowGeometry, new THREE.TransformGizmoMaterial( { color: 0x0000ff } ) ),
|
|
|
|
- new THREE.Vector3( 0, 0, 0.5 ),
|
|
|
|
- new THREE.Vector3( Math.PI/2, 0, 0 )
|
|
|
|
- ],
|
|
|
|
- XYZ: [
|
|
|
|
- new THREE.Mesh( new THREE.BoxGeometry( 0.125, 0.125, 0.125 ), new THREE.TransformGizmoMaterial( { color: 0xffffff, opacity: 0.25 } ) )
|
|
|
|
- ]
|
|
|
|
-
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- this.lineGizmos = {
|
|
|
|
-
|
|
|
|
- X: [
|
|
|
|
- new THREE.Line( lineXGeometry, new THREE.TransformGizmoLineMaterial( { color: 0xff0000 } ) ),
|
|
|
|
- ],
|
|
|
|
- Y: [
|
|
|
|
- new THREE.Line( lineYGeometry, new THREE.TransformGizmoLineMaterial( { color: 0x00ff00 } ) ),
|
|
|
|
- ],
|
|
|
|
- Z: [
|
|
|
|
- new THREE.Line( lineZGeometry, new THREE.TransformGizmoLineMaterial( { color: 0x0000ff } ) ),
|
|
|
|
- ]
|
|
|
|
-
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- this.pickerGizmos = {
|
|
|
|
-
|
|
|
|
- X: [
|
|
|
|
- new THREE.Mesh( new THREE.CylinderGeometry( 0.2, 0, 1, 4, 1, false ), new THREE.TransformGizmoMaterial( { color: 0xff0000, opacity: 0.25 } ) ),
|
|
|
|
- new THREE.Vector3( 0.6, 0, 0 ),
|
|
|
|
- new THREE.Vector3( 0, 0, -Math.PI/2 )
|
|
|
|
- ],
|
|
|
|
- Y: [
|
|
|
|
- new THREE.Mesh( new THREE.CylinderGeometry( 0.2, 0, 1, 4, 1, false ), new THREE.TransformGizmoMaterial( { color: 0x00ff00, opacity: 0.25 } ) ),
|
|
|
|
- new THREE.Vector3( 0, 0.6, 0 )
|
|
|
|
- ],
|
|
|
|
- Z: [
|
|
|
|
- new THREE.Mesh( new THREE.CylinderGeometry( 0.2, 0, 1, 4, 1, false ), new THREE.TransformGizmoMaterial( { color: 0x0000ff, opacity: 0.25 } ) ),
|
|
|
|
- new THREE.Vector3( 0, 0, 0.6 ),
|
|
|
|
- new THREE.Vector3( Math.PI/2, 0, 0 )
|
|
|
|
- ],
|
|
|
|
- XYZ: [
|
|
|
|
- new THREE.Mesh( new THREE.BoxGeometry( 0.4, 0.4, 0.4 ), new THREE.TransformGizmoMaterial( { color: 0xffffff, opacity: 0.25 } ) )
|
|
|
|
- ]
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- this.setActivePlane = function ( axis, eye ) {
|
|
|
|
|
|
+ };
|
|
|
|
|
|
- var tempMatrix = new THREE.Matrix4();
|
|
|
|
- eye.applyProjection( tempMatrix.getInverse( tempMatrix.extractRotation( this.planes[ "XY" ].matrixWorld ) ) );
|
|
|
|
|
|
+ this.init();
|
|
|
|
|
|
- if ( axis == "X" ) {
|
|
|
|
- this.activePlane = this.planes[ "XY" ];
|
|
|
|
- if ( Math.abs(eye.y) > Math.abs(eye.z) ) this.activePlane = this.planes[ "XZ" ];
|
|
|
|
- }
|
|
|
|
|
|
+ };
|
|
|
|
|
|
- if ( axis == "Y" ){
|
|
|
|
- this.activePlane = this.planes[ "XY" ];
|
|
|
|
- if ( Math.abs(eye.x) > Math.abs(eye.z) ) this.activePlane = this.planes[ "YZ" ];
|
|
|
|
- }
|
|
|
|
|
|
+ THREE.TransformGizmoRotate.prototype = Object.create( THREE.TransformGizmo.prototype );
|
|
|
|
+
|
|
|
|
+ THREE.TransformGizmoScale = function () {
|
|
|
|
+
|
|
|
|
+ THREE.TransformGizmo.call( this );
|
|
|
|
+
|
|
|
|
+ var arrowGeometry = new THREE.Geometry();
|
|
|
|
+ var mesh = new THREE.Mesh( new THREE.BoxGeometry( 0.125, 0.125, 0.125 ) );
|
|
|
|
+ mesh.position.y = 0.5;
|
|
|
|
+ THREE.GeometryUtils.merge( arrowGeometry, mesh );
|
|
|
|
+
|
|
|
|
+ var lineXGeometry = new THREE.Geometry();
|
|
|
|
+ lineXGeometry.vertices.push( new THREE.Vector3( 0, 0, 0 ), new THREE.Vector3( 1, 0, 0 ) );
|
|
|
|
+
|
|
|
|
+ var lineYGeometry = new THREE.Geometry();
|
|
|
|
+ lineYGeometry.vertices.push( new THREE.Vector3( 0, 0, 0 ), new THREE.Vector3( 0, 1, 0 ) );
|
|
|
|
+
|
|
|
|
+ var lineZGeometry = new THREE.Geometry();
|
|
|
|
+ lineZGeometry.vertices.push( new THREE.Vector3( 0, 0, 0 ), new THREE.Vector3( 0, 0, 1 ) );
|
|
|
|
+
|
|
|
|
+ this.handleGizmos = {
|
|
|
|
+ X: [
|
|
|
|
+ [ new THREE.Mesh( arrowGeometry, new GizmoMaterial( { color: 0xff0000 } ) ), [ 0.5, 0, 0 ], [ 0, 0, -Math.PI/2 ] ],
|
|
|
|
+ [ new THREE.Line( lineXGeometry, new GizmoLineMaterial( { color: 0xff0000 } ) ) ]
|
|
|
|
+ ],
|
|
|
|
+ Y: [
|
|
|
|
+ [ new THREE.Mesh( arrowGeometry, new GizmoMaterial( { color: 0x00ff00 } ) ), [ 0, 0.5, 0 ] ],
|
|
|
|
+ [ new THREE.Line( lineYGeometry, new GizmoLineMaterial( { color: 0x00ff00 } ) ) ]
|
|
|
|
+ ],
|
|
|
|
+ Z: [
|
|
|
|
+ [ new THREE.Mesh( arrowGeometry, new GizmoMaterial( { color: 0x0000ff } ) ), [ 0, 0, 0.5 ], [ Math.PI/2, 0, 0 ] ],
|
|
|
|
+ [ new THREE.Line( lineZGeometry, new GizmoLineMaterial( { color: 0x0000ff } ) ) ]
|
|
|
|
+ ],
|
|
|
|
+ XYZ: [
|
|
|
|
+ [ new THREE.Mesh( new THREE.BoxGeometry( 0.125, 0.125, 0.125 ), new GizmoMaterial( { color: 0xffffff, opacity: 0.25 } ) ) ]
|
|
|
|
+ ]
|
|
|
|
+ };
|
|
|
|
|
|
- if ( axis == "Z" ){
|
|
|
|
- this.activePlane = this.planes[ "XZ" ];
|
|
|
|
- if ( Math.abs(eye.x) > Math.abs(eye.y) ) this.activePlane = this.planes[ "YZ" ];
|
|
|
|
- }
|
|
|
|
|
|
+ this.pickerGizmos = {
|
|
|
|
+ X: [
|
|
|
|
+ [ new THREE.Mesh( new THREE.CylinderGeometry( 0.2, 0, 1, 4, 1, false ), new GizmoMaterial( { color: 0xff0000, opacity: 0.25 } ) ), [ 0.6, 0, 0 ], [ 0, 0, -Math.PI/2 ] ]
|
|
|
|
+ ],
|
|
|
|
+ Y: [
|
|
|
|
+ [ new THREE.Mesh( new THREE.CylinderGeometry( 0.2, 0, 1, 4, 1, false ), new GizmoMaterial( { color: 0x00ff00, opacity: 0.25 } ) ), [ 0, 0.6, 0 ] ]
|
|
|
|
+ ],
|
|
|
|
+ Z: [
|
|
|
|
+ [ new THREE.Mesh( new THREE.CylinderGeometry( 0.2, 0, 1, 4, 1, false ), new GizmoMaterial( { color: 0x0000ff, opacity: 0.25 } ) ), [ 0, 0, 0.6 ], [ Math.PI/2, 0, 0 ] ]
|
|
|
|
+ ],
|
|
|
|
+ XYZ: [
|
|
|
|
+ [ new THREE.Mesh( new THREE.BoxGeometry( 0.4, 0.4, 0.4 ), new GizmoMaterial( { color: 0xffffff, opacity: 0.25 } ) ) ]
|
|
|
|
+ ]
|
|
|
|
+ };
|
|
|
|
|
|
- if ( axis == "XYZ" ) this.activePlane = this.planes[ "XYZE" ];
|
|
|
|
|
|
+ this.setActivePlane = function ( axis, eye ) {
|
|
|
|
|
|
- this.hide();
|
|
|
|
- this.show();
|
|
|
|
|
|
+ var tempMatrix = new THREE.Matrix4();
|
|
|
|
+ eye.applyProjection( tempMatrix.getInverse( tempMatrix.extractRotation( this.planes[ "XY" ].matrixWorld ) ) );
|
|
|
|
|
|
- }
|
|
|
|
|
|
+ if ( axis == "X" ) {
|
|
|
|
+ this.activePlane = this.planes[ "XY" ];
|
|
|
|
+ if ( Math.abs(eye.y) > Math.abs(eye.z) ) this.activePlane = this.planes[ "XZ" ];
|
|
|
|
+ }
|
|
|
|
|
|
- this.init();
|
|
|
|
|
|
+ if ( axis == "Y" ){
|
|
|
|
+ this.activePlane = this.planes[ "XY" ];
|
|
|
|
+ if ( Math.abs(eye.x) > Math.abs(eye.z) ) this.activePlane = this.planes[ "YZ" ];
|
|
|
|
+ }
|
|
|
|
|
|
-}
|
|
|
|
|
|
+ if ( axis == "Z" ){
|
|
|
|
+ this.activePlane = this.planes[ "XZ" ];
|
|
|
|
+ if ( Math.abs(eye.x) > Math.abs(eye.y) ) this.activePlane = this.planes[ "YZ" ];
|
|
|
|
+ }
|
|
|
|
|
|
-THREE.TransformGizmoScale.prototype = Object.create( THREE.TransformGizmo.prototype );
|
|
|
|
|
|
+ if ( axis == "XYZ" ) this.activePlane = this.planes[ "XYZE" ];
|
|
|
|
|
|
-THREE.TransformControls = function ( camera, domElement ) {
|
|
|
|
|
|
+ this.hide();
|
|
|
|
+ this.show();
|
|
|
|
|
|
- // TODO: Make non-uniform scale and rotate play nice in hierarchies
|
|
|
|
- // TODO: ADD RXYZ contol
|
|
|
|
|
|
+ };
|
|
|
|
|
|
- THREE.Object3D.call( this );
|
|
|
|
|
|
+ this.init();
|
|
|
|
|
|
- domElement = ( domElement !== undefined ) ? domElement : document;
|
|
|
|
|
|
+ };
|
|
|
|
|
|
- this.gizmo = {}
|
|
|
|
- this.gizmo["translate"] = new THREE.TransformGizmoTranslate();
|
|
|
|
- this.gizmo["rotate"] = new THREE.TransformGizmoRotate();
|
|
|
|
- this.gizmo["scale"] = new THREE.TransformGizmoScale();
|
|
|
|
|
|
+ THREE.TransformGizmoScale.prototype = Object.create( THREE.TransformGizmo.prototype );
|
|
|
|
|
|
- this.add(this.gizmo["translate"]);
|
|
|
|
- this.add(this.gizmo["rotate"]);
|
|
|
|
- this.add(this.gizmo["scale"]);
|
|
|
|
|
|
+ THREE.TransformControls = function ( camera, domElement ) {
|
|
|
|
|
|
- this.gizmo["translate"].hide();
|
|
|
|
- this.gizmo["rotate"].hide();
|
|
|
|
- this.gizmo["scale"].hide();
|
|
|
|
|
|
+ // TODO: Make non-uniform scale and rotate play nice in hierarchies
|
|
|
|
+ // TODO: ADD RXYZ contol
|
|
|
|
|
|
- this.object = undefined;
|
|
|
|
- this.snap = undefined;
|
|
|
|
- this.space = "world";
|
|
|
|
- this.size = 1;
|
|
|
|
- this.axis = undefined;
|
|
|
|
|
|
+ THREE.Object3D.call( this );
|
|
|
|
|
|
- var scope = this;
|
|
|
|
-
|
|
|
|
- var _dragging = false;
|
|
|
|
- var _mode = "translate";
|
|
|
|
- var _plane = "XY";
|
|
|
|
|
|
+ domElement = ( domElement !== undefined ) ? domElement : document;
|
|
|
|
|
|
- var changeEvent = { type: "change" };
|
|
|
|
|
|
+ this.gizmo = {};
|
|
|
|
+ this.gizmo["translate"] = new THREE.TransformGizmoTranslate();
|
|
|
|
+ this.gizmo["rotate"] = new THREE.TransformGizmoRotate();
|
|
|
|
+ this.gizmo["scale"] = new THREE.TransformGizmoScale();
|
|
|
|
|
|
- var ray = new THREE.Raycaster();
|
|
|
|
- var projector = new THREE.Projector();
|
|
|
|
- var pointerVector = new THREE.Vector3();
|
|
|
|
|
|
+ this.add(this.gizmo["translate"]);
|
|
|
|
+ this.add(this.gizmo["rotate"]);
|
|
|
|
+ this.add(this.gizmo["scale"]);
|
|
|
|
|
|
- var point = new THREE.Vector3();
|
|
|
|
- var offset = new THREE.Vector3();
|
|
|
|
|
|
+ this.gizmo["translate"].hide();
|
|
|
|
+ this.gizmo["rotate"].hide();
|
|
|
|
+ this.gizmo["scale"].hide();
|
|
|
|
|
|
- var rotation = new THREE.Vector3();
|
|
|
|
- var offsetRotation = new THREE.Vector3();
|
|
|
|
- var scale = 1;
|
|
|
|
|
|
+ this.object = undefined;
|
|
|
|
+ this.snap = undefined;
|
|
|
|
+ this.space = "world";
|
|
|
|
+ this.size = 1;
|
|
|
|
+ this.axis = undefined;
|
|
|
|
|
|
- var lookAtMatrix = new THREE.Matrix4();
|
|
|
|
- var eye = new THREE.Vector3()
|
|
|
|
|
|
+ var scope = this;
|
|
|
|
+
|
|
|
|
+ var _dragging = false;
|
|
|
|
+ var _mode = "translate";
|
|
|
|
+ var _plane = "XY";
|
|
|
|
|
|
- var tempMatrix = new THREE.Matrix4();
|
|
|
|
- var tempVector = new THREE.Vector3();
|
|
|
|
- var tempQuaternion = new THREE.Quaternion();
|
|
|
|
- var unitX = new THREE.Vector3( 1, 0, 0 );
|
|
|
|
- var unitY = new THREE.Vector3( 0, 1, 0 );
|
|
|
|
- var unitZ = new THREE.Vector3( 0, 0, 1 );
|
|
|
|
|
|
+ var changeEvent = { type: "change" };
|
|
|
|
|
|
- var quaternionXYZ = new THREE.Quaternion();
|
|
|
|
- var quaternionX = new THREE.Quaternion();
|
|
|
|
- var quaternionY = new THREE.Quaternion();
|
|
|
|
- var quaternionZ = new THREE.Quaternion();
|
|
|
|
- var quaternionE = new THREE.Quaternion();
|
|
|
|
|
|
+ var ray = new THREE.Raycaster();
|
|
|
|
+ var projector = new THREE.Projector();
|
|
|
|
+ var pointerVector = new THREE.Vector3();
|
|
|
|
|
|
- var oldPosition = new THREE.Vector3();
|
|
|
|
- var oldScale = new THREE.Vector3();
|
|
|
|
- var oldRotationMatrix = new THREE.Matrix4();
|
|
|
|
|
|
+ var point = new THREE.Vector3();
|
|
|
|
+ var offset = new THREE.Vector3();
|
|
|
|
|
|
- var parentRotationMatrix = new THREE.Matrix4();
|
|
|
|
- var parentScale = new THREE.Vector3();
|
|
|
|
|
|
+ var rotation = new THREE.Vector3();
|
|
|
|
+ var offsetRotation = new THREE.Vector3();
|
|
|
|
+ var scale = 1;
|
|
|
|
|
|
- var worldPosition = new THREE.Vector3();
|
|
|
|
- var worldRotation = new THREE.Euler();
|
|
|
|
- var worldRotationMatrix = new THREE.Matrix4();
|
|
|
|
- var camPosition = new THREE.Vector3();
|
|
|
|
- var camRotation = new THREE.Euler();
|
|
|
|
|
|
+ var lookAtMatrix = new THREE.Matrix4();
|
|
|
|
+ var eye = new THREE.Vector3();
|
|
|
|
|
|
- domElement.addEventListener( "mousedown", onPointerDown, false );
|
|
|
|
- domElement.addEventListener( "touchstart", onPointerDown, false );
|
|
|
|
|
|
+ var tempMatrix = new THREE.Matrix4();
|
|
|
|
+ var tempVector = new THREE.Vector3();
|
|
|
|
+ var tempQuaternion = new THREE.Quaternion();
|
|
|
|
+ var unitX = new THREE.Vector3( 1, 0, 0 );
|
|
|
|
+ var unitY = new THREE.Vector3( 0, 1, 0 );
|
|
|
|
+ var unitZ = new THREE.Vector3( 0, 0, 1 );
|
|
|
|
|
|
- domElement.addEventListener( "mousemove", onPointerHover, false );
|
|
|
|
- domElement.addEventListener( "touchmove", onPointerHover, false );
|
|
|
|
|
|
+ var quaternionXYZ = new THREE.Quaternion();
|
|
|
|
+ var quaternionX = new THREE.Quaternion();
|
|
|
|
+ var quaternionY = new THREE.Quaternion();
|
|
|
|
+ var quaternionZ = new THREE.Quaternion();
|
|
|
|
+ var quaternionE = new THREE.Quaternion();
|
|
|
|
|
|
- domElement.addEventListener( "mousemove", onPointerMove, false );
|
|
|
|
- domElement.addEventListener( "touchmove", onPointerMove, false );
|
|
|
|
|
|
+ var oldPosition = new THREE.Vector3();
|
|
|
|
+ var oldScale = new THREE.Vector3();
|
|
|
|
+ var oldRotationMatrix = new THREE.Matrix4();
|
|
|
|
|
|
- domElement.addEventListener( "mouseup", onPointerUp, false );
|
|
|
|
- domElement.addEventListener( "mouseout", onPointerUp, false );
|
|
|
|
- domElement.addEventListener( "touchend", onPointerUp, false );
|
|
|
|
- domElement.addEventListener( "touchcancel", onPointerUp, false );
|
|
|
|
- domElement.addEventListener( "touchleave", onPointerUp, false );
|
|
|
|
|
|
+ var parentRotationMatrix = new THREE.Matrix4();
|
|
|
|
+ var parentScale = new THREE.Vector3();
|
|
|
|
|
|
- this.attach = function ( object ) {
|
|
|
|
|
|
+ var worldPosition = new THREE.Vector3();
|
|
|
|
+ var worldRotation = new THREE.Euler();
|
|
|
|
+ var worldRotationMatrix = new THREE.Matrix4();
|
|
|
|
+ var camPosition = new THREE.Vector3();
|
|
|
|
+ var camRotation = new THREE.Euler();
|
|
|
|
|
|
- scope.object = object;
|
|
|
|
|
|
+ domElement.addEventListener( "mousedown", onPointerDown, false );
|
|
|
|
+ domElement.addEventListener( "touchstart", onPointerDown, false );
|
|
|
|
|
|
- this.gizmo["translate"].hide();
|
|
|
|
- this.gizmo["rotate"].hide();
|
|
|
|
- this.gizmo["scale"].hide();
|
|
|
|
- this.gizmo[_mode].show();
|
|
|
|
|
|
+ domElement.addEventListener( "mousemove", onPointerHover, false );
|
|
|
|
+ domElement.addEventListener( "touchmove", onPointerHover, false );
|
|
|
|
|
|
- scope.update();
|
|
|
|
|
|
+ domElement.addEventListener( "mousemove", onPointerMove, false );
|
|
|
|
+ domElement.addEventListener( "touchmove", onPointerMove, false );
|
|
|
|
|
|
- }
|
|
|
|
|
|
+ domElement.addEventListener( "mouseup", onPointerUp, false );
|
|
|
|
+ domElement.addEventListener( "mouseout", onPointerUp, false );
|
|
|
|
+ domElement.addEventListener( "touchend", onPointerUp, false );
|
|
|
|
+ domElement.addEventListener( "touchcancel", onPointerUp, false );
|
|
|
|
+ domElement.addEventListener( "touchleave", onPointerUp, false );
|
|
|
|
|
|
- this.detach = function ( object ) {
|
|
|
|
|
|
+ this.attach = function ( object ) {
|
|
|
|
|
|
- scope.object = undefined;
|
|
|
|
- this.axis = undefined;
|
|
|
|
|
|
+ scope.object = object;
|
|
|
|
|
|
- this.gizmo["translate"].hide();
|
|
|
|
- this.gizmo["rotate"].hide();
|
|
|
|
- this.gizmo["scale"].hide();
|
|
|
|
|
|
+ this.gizmo["translate"].hide();
|
|
|
|
+ this.gizmo["rotate"].hide();
|
|
|
|
+ this.gizmo["scale"].hide();
|
|
|
|
+ this.gizmo[_mode].show();
|
|
|
|
|
|
- }
|
|
|
|
|
|
+ scope.update();
|
|
|
|
|
|
- this.setMode = function ( mode ) {
|
|
|
|
|
|
+ };
|
|
|
|
|
|
- _mode = mode ? mode : _mode;
|
|
|
|
|
|
+ this.detach = function ( object ) {
|
|
|
|
|
|
- if ( _mode == "scale" ) scope.space = "local";
|
|
|
|
|
|
+ scope.object = undefined;
|
|
|
|
+ this.axis = undefined;
|
|
|
|
|
|
- this.gizmo["translate"].hide();
|
|
|
|
- this.gizmo["rotate"].hide();
|
|
|
|
- this.gizmo["scale"].hide();
|
|
|
|
- this.gizmo[_mode].show();
|
|
|
|
|
|
+ this.gizmo["translate"].hide();
|
|
|
|
+ this.gizmo["rotate"].hide();
|
|
|
|
+ this.gizmo["scale"].hide();
|
|
|
|
|
|
- this.update();
|
|
|
|
- scope.dispatchEvent( changeEvent );
|
|
|
|
|
|
+ };
|
|
|
|
|
|
- }
|
|
|
|
|
|
+ this.setMode = function ( mode ) {
|
|
|
|
|
|
- this.setSnap = function ( snap ) {
|
|
|
|
|
|
+ _mode = mode ? mode : _mode;
|
|
|
|
|
|
- scope.snap = snap;
|
|
|
|
|
|
+ if ( _mode == "scale" ) scope.space = "local";
|
|
|
|
|
|
- }
|
|
|
|
|
|
+ this.gizmo["translate"].hide();
|
|
|
|
+ this.gizmo["rotate"].hide();
|
|
|
|
+ this.gizmo["scale"].hide();
|
|
|
|
+ this.gizmo[_mode].show();
|
|
|
|
|
|
- this.setSize = function ( size ) {
|
|
|
|
|
|
+ this.update();
|
|
|
|
+ scope.dispatchEvent( changeEvent );
|
|
|
|
|
|
- scope.size = size;
|
|
|
|
- this.update();
|
|
|
|
- scope.dispatchEvent( changeEvent );
|
|
|
|
-
|
|
|
|
- }
|
|
|
|
|
|
+ };
|
|
|
|
|
|
- this.setSpace = function ( space ) {
|
|
|
|
|
|
+ this.setSnap = function ( snap ) {
|
|
|
|
|
|
- scope.space = space;
|
|
|
|
- this.update();
|
|
|
|
- scope.dispatchEvent( changeEvent );
|
|
|
|
|
|
+ scope.snap = snap;
|
|
|
|
|
|
- }
|
|
|
|
|
|
+ };
|
|
|
|
|
|
- this.update = function () {
|
|
|
|
|
|
+ this.setSize = function ( size ) {
|
|
|
|
|
|
- if ( scope.object === undefined ) return;
|
|
|
|
|
|
+ scope.size = size;
|
|
|
|
+ this.update();
|
|
|
|
+ scope.dispatchEvent( changeEvent );
|
|
|
|
+
|
|
|
|
+ };
|
|
|
|
|
|
- scope.object.updateMatrixWorld();
|
|
|
|
- worldPosition.setFromMatrixPosition( scope.object.matrixWorld );
|
|
|
|
- worldRotation.setFromRotationMatrix( tempMatrix.extractRotation( scope.object.matrixWorld ) );
|
|
|
|
|
|
+ this.setSpace = function ( space ) {
|
|
|
|
|
|
- camera.updateMatrixWorld();
|
|
|
|
- camPosition.setFromMatrixPosition( camera.matrixWorld );
|
|
|
|
- camRotation.setFromRotationMatrix( tempMatrix.extractRotation( camera.matrixWorld ) );
|
|
|
|
|
|
+ scope.space = space;
|
|
|
|
+ this.update();
|
|
|
|
+ scope.dispatchEvent( changeEvent );
|
|
|
|
|
|
- scale = worldPosition.distanceTo( camPosition ) / 6 * scope.size;
|
|
|
|
- this.position.copy( worldPosition )
|
|
|
|
- this.scale.set( scale, scale, scale );
|
|
|
|
|
|
+ };
|
|
|
|
|
|
- eye.copy( camPosition ).sub( worldPosition ).normalize();
|
|
|
|
|
|
+ this.update = function () {
|
|
|
|
|
|
- if ( scope.space == "local" )
|
|
|
|
- this.gizmo[_mode].update( worldRotation, eye );
|
|
|
|
|
|
+ if ( scope.object === undefined ) return;
|
|
|
|
|
|
- else if ( scope.space == "world" )
|
|
|
|
- this.gizmo[_mode].update( new THREE.Euler(), eye );
|
|
|
|
|
|
+ scope.object.updateMatrixWorld();
|
|
|
|
+ worldPosition.setFromMatrixPosition( scope.object.matrixWorld );
|
|
|
|
+ worldRotation.setFromRotationMatrix( tempMatrix.extractRotation( scope.object.matrixWorld ) );
|
|
|
|
|
|
- this.gizmo[_mode].highlight( scope.axis );
|
|
|
|
|
|
+ camera.updateMatrixWorld();
|
|
|
|
+ camPosition.setFromMatrixPosition( camera.matrixWorld );
|
|
|
|
+ camRotation.setFromRotationMatrix( tempMatrix.extractRotation( camera.matrixWorld ) );
|
|
|
|
|
|
- }
|
|
|
|
|
|
+ scale = worldPosition.distanceTo( camPosition ) / 6 * scope.size;
|
|
|
|
+ this.position.copy( worldPosition );
|
|
|
|
+ this.scale.set( scale, scale, scale );
|
|
|
|
|
|
- function onPointerHover( event ) {
|
|
|
|
|
|
+ eye.copy( camPosition ).sub( worldPosition ).normalize();
|
|
|
|
|
|
- if ( scope.object === undefined || _dragging == true ) return;
|
|
|
|
|
|
+ if ( scope.space == "local" )
|
|
|
|
+ this.gizmo[_mode].update( worldRotation, eye );
|
|
|
|
|
|
- event.preventDefault();
|
|
|
|
|
|
+ else if ( scope.space == "world" )
|
|
|
|
+ this.gizmo[_mode].update( new THREE.Euler(), eye );
|
|
|
|
|
|
- var pointer = event.touches ? event.touches[ 0 ] : event;
|
|
|
|
|
|
+ this.gizmo[_mode].highlight( scope.axis );
|
|
|
|
|
|
- var intersect = intersectObjects( pointer, scope.gizmo[_mode].pickers.children );
|
|
|
|
|
|
+ };
|
|
|
|
|
|
- if ( intersect ) {
|
|
|
|
|
|
+ function onPointerHover( event ) {
|
|
|
|
|
|
- scope.axis = intersect.object.name;
|
|
|
|
- scope.update();
|
|
|
|
- scope.dispatchEvent( changeEvent );
|
|
|
|
|
|
+ if ( scope.object === undefined || _dragging === true ) return;
|
|
|
|
|
|
- } else if ( scope.axis !== undefined ) {
|
|
|
|
|
|
+ event.preventDefault();
|
|
|
|
|
|
- scope.axis = undefined;
|
|
|
|
- scope.update();
|
|
|
|
- scope.dispatchEvent( changeEvent );
|
|
|
|
|
|
+ var pointer = event.touches ? event.touches[ 0 ] : event;
|
|
|
|
+
|
|
|
|
+ var intersect = intersectObjects( pointer, scope.gizmo[_mode].pickers.children );
|
|
|
|
+
|
|
|
|
+ if ( intersect ) {
|
|
|
|
+
|
|
|
|
+ scope.axis = intersect.object.name;
|
|
|
|
+ scope.update();
|
|
|
|
+ scope.dispatchEvent( changeEvent );
|
|
|
|
+
|
|
|
|
+ } else if ( scope.axis !== undefined ) {
|
|
|
|
+
|
|
|
|
+ scope.axis = undefined;
|
|
|
|
+ scope.update();
|
|
|
|
+ scope.dispatchEvent( changeEvent );
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
- };
|
|
|
|
|
|
+ function onPointerDown( event ) {
|
|
|
|
|
|
- function onPointerDown( event ) {
|
|
|
|
|
|
+ if ( scope.object === undefined || _dragging === true ) return;
|
|
|
|
|
|
- if ( scope.object === undefined || _dragging == true ) return;
|
|
|
|
|
|
+ event.preventDefault();
|
|
|
|
+ event.stopPropagation();
|
|
|
|
|
|
- event.preventDefault();
|
|
|
|
- event.stopPropagation();
|
|
|
|
|
|
+ var pointer = event.touches ? event.touches[ 0 ] : event;
|
|
|
|
|
|
- var pointer = event.touches ? event.touches[ 0 ] : event;
|
|
|
|
|
|
+ if ( pointer.button === 0 || pointer.button === undefined ) {
|
|
|
|
|
|
- if ( pointer.button === 0 || pointer.button === undefined ) {
|
|
|
|
|
|
+ var intersect = intersectObjects( pointer, scope.gizmo[_mode].pickers.children );
|
|
|
|
|
|
- var intersect = intersectObjects( pointer, scope.gizmo[_mode].pickers.children );
|
|
|
|
|
|
+ if ( intersect ) {
|
|
|
|
|
|
- if ( intersect ) {
|
|
|
|
|
|
+ scope.axis = intersect.object.name;
|
|
|
|
|
|
- scope.axis = intersect.object.name;
|
|
|
|
|
|
+ scope.update();
|
|
|
|
|
|
- scope.update();
|
|
|
|
|
|
+ eye.copy( camPosition ).sub( worldPosition ).normalize();
|
|
|
|
|
|
- eye.copy( camPosition ).sub( worldPosition ).normalize();
|
|
|
|
|
|
+ scope.gizmo[_mode].setActivePlane( scope.axis, eye );
|
|
|
|
|
|
- scope.gizmo[_mode].setActivePlane( scope.axis, eye );
|
|
|
|
|
|
+ var planeIntersect = intersectObjects( pointer, [scope.gizmo[_mode].activePlane] );
|
|
|
|
|
|
- var planeIntersect = intersectObjects( pointer, [scope.gizmo[_mode].activePlane] );
|
|
|
|
|
|
+ oldPosition.copy( scope.object.position );
|
|
|
|
+ oldScale.copy( scope.object.scale );
|
|
|
|
|
|
- oldPosition.copy( scope.object.position );
|
|
|
|
- oldScale.copy( scope.object.scale );
|
|
|
|
|
|
+ oldRotationMatrix.extractRotation( scope.object.matrix );
|
|
|
|
+ worldRotationMatrix.extractRotation( scope.object.matrixWorld );
|
|
|
|
|
|
- oldRotationMatrix.extractRotation( scope.object.matrix );
|
|
|
|
- worldRotationMatrix.extractRotation( scope.object.matrixWorld );
|
|
|
|
|
|
+ parentRotationMatrix.extractRotation( scope.object.parent.matrixWorld );
|
|
|
|
+ parentScale.setFromMatrixScale( tempMatrix.getInverse( scope.object.parent.matrixWorld ) );
|
|
|
|
|
|
- parentRotationMatrix.extractRotation( scope.object.parent.matrixWorld );
|
|
|
|
- parentScale.setFromMatrixScale( tempMatrix.getInverse( scope.object.parent.matrixWorld ) );
|
|
|
|
|
|
+ offset.copy( planeIntersect.point );
|
|
|
|
|
|
- offset.copy( planeIntersect.point );
|
|
|
|
|
|
+ }
|
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ _dragging = true;
|
|
|
|
+
|
|
}
|
|
}
|
|
|
|
|
|
- _dragging = true;
|
|
|
|
|
|
+ function onPointerMove( event ) {
|
|
|
|
|
|
- };
|
|
|
|
|
|
+ if ( scope.object === undefined || scope.axis === undefined || _dragging === false ) return;
|
|
|
|
|
|
- function onPointerMove( event ) {
|
|
|
|
|
|
+ event.preventDefault();
|
|
|
|
+ event.stopPropagation();
|
|
|
|
|
|
- if ( scope.object === undefined || scope.axis === undefined || _dragging == false ) return;
|
|
|
|
|
|
+ var pointer = event.touches? event.touches[0] : event;
|
|
|
|
|
|
- event.preventDefault();
|
|
|
|
- event.stopPropagation();
|
|
|
|
|
|
+ var planeIntersect = intersectObjects( pointer, [scope.gizmo[_mode].activePlane] );
|
|
|
|
|
|
- var pointer = event.touches? event.touches[0] : event;
|
|
|
|
|
|
+ point.copy( planeIntersect.point );
|
|
|
|
|
|
- var planeIntersect = intersectObjects( pointer, [scope.gizmo[_mode].activePlane] );
|
|
|
|
|
|
+ if ( _mode == "translate" ) {
|
|
|
|
|
|
- point.copy( planeIntersect.point );
|
|
|
|
|
|
+ point.sub( offset );
|
|
|
|
+ point.multiply(parentScale);
|
|
|
|
|
|
- if ( _mode == "translate" ) {
|
|
|
|
|
|
+ if ( scope.space == "local" ) {
|
|
|
|
|
|
- point.sub( offset );
|
|
|
|
- point.multiply(parentScale);
|
|
|
|
|
|
+ point.applyMatrix4( tempMatrix.getInverse( worldRotationMatrix ) );
|
|
|
|
|
|
- if ( scope.space == "local" ) {
|
|
|
|
|
|
+ if ( scope.axis.search("X") == -1 ) point.x = 0;
|
|
|
|
+ if ( scope.axis.search("Y") == -1 ) point.y = 0;
|
|
|
|
+ if ( scope.axis.search("Z") == -1 ) point.z = 0;
|
|
|
|
|
|
- point.applyMatrix4( tempMatrix.getInverse( worldRotationMatrix ) );
|
|
|
|
|
|
+ point.applyMatrix4( oldRotationMatrix );
|
|
|
|
|
|
- if ( scope.axis.search("X") == -1 ) point.x = 0;
|
|
|
|
- if ( scope.axis.search("Y") == -1 ) point.y = 0;
|
|
|
|
- if ( scope.axis.search("Z") == -1 ) point.z = 0;
|
|
|
|
|
|
+ scope.object.position.copy( oldPosition );
|
|
|
|
+ scope.object.position.add( point );
|
|
|
|
|
|
- point.applyMatrix4( oldRotationMatrix );
|
|
|
|
|
|
+ }
|
|
|
|
|
|
- scope.object.position.copy( oldPosition );
|
|
|
|
- scope.object.position.add( point );
|
|
|
|
|
|
+ if ( scope.space == "world" || scope.axis.search("XYZ") != -1 ) {
|
|
|
|
|
|
- }
|
|
|
|
|
|
+ if ( scope.axis.search("X") == -1 ) point.x = 0;
|
|
|
|
+ if ( scope.axis.search("Y") == -1 ) point.y = 0;
|
|
|
|
+ if ( scope.axis.search("Z") == -1 ) point.z = 0;
|
|
|
|
|
|
- if ( scope.space == "world" || scope.axis.search("XYZ") != -1 ) {
|
|
|
|
|
|
+ point.applyMatrix4( tempMatrix.getInverse( parentRotationMatrix ) );
|
|
|
|
|
|
- if ( scope.axis.search("X") == -1 ) point.x = 0;
|
|
|
|
- if ( scope.axis.search("Y") == -1 ) point.y = 0;
|
|
|
|
- if ( scope.axis.search("Z") == -1 ) point.z = 0;
|
|
|
|
|
|
+ scope.object.position.copy( oldPosition );
|
|
|
|
+ scope.object.position.add( point );
|
|
|
|
|
|
- point.applyMatrix4( tempMatrix.getInverse( parentRotationMatrix ) );
|
|
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if ( scope.snap !== undefined ) {
|
|
|
|
+
|
|
|
|
+ if ( scope.axis.search("X") != -1 ) scope.object.position.x = Math.round( scope.object.position.x / scope.snap ) * scope.snap;
|
|
|
|
+ if ( scope.axis.search("Y") != -1 ) scope.object.position.y = Math.round( scope.object.position.y / scope.snap ) * scope.snap;
|
|
|
|
+ if ( scope.axis.search("Z") != -1 ) scope.object.position.z = Math.round( scope.object.position.z / scope.snap ) * scope.snap;
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
|
|
- scope.object.position.copy( oldPosition );
|
|
|
|
- scope.object.position.add( point );
|
|
|
|
|
|
+ } else if ( _mode == "scale" ) {
|
|
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- if ( scope.snap != undefined ) {
|
|
|
|
-
|
|
|
|
- if ( scope.axis.search("X") != -1 ) scope.object.position.x = Math.round( scope.object.position.x / scope.snap ) * scope.snap;
|
|
|
|
- if ( scope.axis.search("Y") != -1 ) scope.object.position.y = Math.round( scope.object.position.y / scope.snap ) * scope.snap;
|
|
|
|
- if ( scope.axis.search("Z") != -1 ) scope.object.position.z = Math.round( scope.object.position.z / scope.snap ) * scope.snap;
|
|
|
|
-
|
|
|
|
- }
|
|
|
|
|
|
+ point.sub( offset );
|
|
|
|
+ point.multiply(parentScale);
|
|
|
|
|
|
- } else if ( _mode == "scale" ) {
|
|
|
|
|
|
+ if ( scope.space == "local" ) {
|
|
|
|
|
|
- point.sub( offset );
|
|
|
|
- point.multiply(parentScale);
|
|
|
|
|
|
+ if ( scope.axis == "XYZ") {
|
|
|
|
|
|
- if ( scope.space == "local" ) {
|
|
|
|
|
|
+ scale = 1 + ( ( point.y ) / 50 );
|
|
|
|
|
|
- if ( scope.axis == "XYZ") {
|
|
|
|
|
|
+ scope.object.scale.x = oldScale.x * scale;
|
|
|
|
+ scope.object.scale.y = oldScale.y * scale;
|
|
|
|
+ scope.object.scale.z = oldScale.z * scale;
|
|
|
|
|
|
- scale = 1 + ( ( point.y ) / 50 );
|
|
|
|
|
|
+ } else {
|
|
|
|
|
|
- scope.object.scale.x = oldScale.x * scale;
|
|
|
|
- scope.object.scale.y = oldScale.y * scale;
|
|
|
|
- scope.object.scale.z = oldScale.z * scale;
|
|
|
|
|
|
+ point.applyMatrix4( tempMatrix.getInverse( worldRotationMatrix ) );
|
|
|
|
|
|
- } else {
|
|
|
|
|
|
+ if ( scope.axis == "X" ) scope.object.scale.x = oldScale.x * ( 1 + point.x / 50 );
|
|
|
|
+ if ( scope.axis == "Y" ) scope.object.scale.y = oldScale.y * ( 1 + point.y / 50 );
|
|
|
|
+ if ( scope.axis == "Z" ) scope.object.scale.z = oldScale.z * ( 1 + point.z / 50 );
|
|
|
|
|
|
- point.applyMatrix4( tempMatrix.getInverse( worldRotationMatrix ) );
|
|
|
|
-
|
|
|
|
- if ( scope.axis == "X" ) scope.object.scale.x = oldScale.x * ( 1 + point.x / 50 );
|
|
|
|
- if ( scope.axis == "Y" ) scope.object.scale.y = oldScale.y * ( 1 + point.y / 50 );
|
|
|
|
- if ( scope.axis == "Z" ) scope.object.scale.z = oldScale.z * ( 1 + point.z / 50 );
|
|
|
|
|
|
+ }
|
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
- }
|
|
|
|
|
|
+ } else if ( _mode == "rotate" ) {
|
|
|
|
|
|
- } else if ( _mode == "rotate" ) {
|
|
|
|
|
|
+ point.sub( worldPosition );
|
|
|
|
+ point.multiply(parentScale);
|
|
|
|
+ tempVector.copy(offset).sub( worldPosition );
|
|
|
|
+ tempVector.multiply(parentScale);
|
|
|
|
|
|
- point.sub( worldPosition );
|
|
|
|
- point.multiply(parentScale);
|
|
|
|
- tempVector.copy(offset).sub( worldPosition );
|
|
|
|
- tempVector.multiply(parentScale);
|
|
|
|
|
|
+ if ( scope.axis == "E" ) {
|
|
|
|
|
|
- if ( scope.axis == "E" ) {
|
|
|
|
|
|
+ point.applyMatrix4( tempMatrix.getInverse( lookAtMatrix ) );
|
|
|
|
+ tempVector.applyMatrix4( tempMatrix.getInverse( lookAtMatrix ) );
|
|
|
|
|
|
- point.applyMatrix4( tempMatrix.getInverse( lookAtMatrix ) );
|
|
|
|
- tempVector.applyMatrix4( tempMatrix.getInverse( lookAtMatrix ) );
|
|
|
|
|
|
+ rotation.set( Math.atan2( point.z, point.y ), Math.atan2( point.x, point.z ), Math.atan2( point.y, point.x ) );
|
|
|
|
+ offsetRotation.set( Math.atan2( tempVector.z, tempVector.y ), Math.atan2( tempVector.x, tempVector.z ), Math.atan2( tempVector.y, tempVector.x ) );
|
|
|
|
|
|
- rotation.set( Math.atan2( point.z, point.y ), Math.atan2( point.x, point.z ), Math.atan2( point.y, point.x ) );
|
|
|
|
- offsetRotation.set( Math.atan2( tempVector.z, tempVector.y ), Math.atan2( tempVector.x, tempVector.z ), Math.atan2( tempVector.y, tempVector.x ) );
|
|
|
|
|
|
+ tempQuaternion.setFromRotationMatrix( tempMatrix.getInverse( parentRotationMatrix ) );
|
|
|
|
|
|
- tempQuaternion.setFromRotationMatrix( tempMatrix.getInverse( parentRotationMatrix ) );
|
|
|
|
|
|
+ quaternionE.setFromAxisAngle( eye, rotation.z - offsetRotation.z );
|
|
|
|
+ quaternionXYZ.setFromRotationMatrix( worldRotationMatrix );
|
|
|
|
|
|
- quaternionE.setFromAxisAngle( eye, rotation.z - offsetRotation.z );
|
|
|
|
- quaternionXYZ.setFromRotationMatrix( worldRotationMatrix );
|
|
|
|
|
|
+ tempQuaternion.multiplyQuaternions( tempQuaternion, quaternionE );
|
|
|
|
+ tempQuaternion.multiplyQuaternions( tempQuaternion, quaternionXYZ );
|
|
|
|
|
|
- tempQuaternion.multiplyQuaternions( tempQuaternion, quaternionE );
|
|
|
|
- tempQuaternion.multiplyQuaternions( tempQuaternion, quaternionXYZ );
|
|
|
|
|
|
+ scope.object.quaternion.copy( tempQuaternion );
|
|
|
|
|
|
- scope.object.quaternion.copy( tempQuaternion );
|
|
|
|
|
|
+ } else if ( scope.axis == "XYZE" ) {
|
|
|
|
|
|
- } else if ( scope.axis == "XYZE" ) {
|
|
|
|
|
|
+ quaternionE.setFromEuler( point.clone().cross(tempVector).normalize() ); // rotation axis
|
|
|
|
|
|
- quaternionE.setFromEuler( point.clone().cross(tempVector).normalize() ); // rotation axis
|
|
|
|
|
|
+ tempQuaternion.setFromRotationMatrix( tempMatrix.getInverse( parentRotationMatrix ) );
|
|
|
|
+ quaternionX.setFromAxisAngle( quaternionE, - point.clone().angleTo(tempVector) );
|
|
|
|
+ quaternionXYZ.setFromRotationMatrix( worldRotationMatrix );
|
|
|
|
|
|
- tempQuaternion.setFromRotationMatrix( tempMatrix.getInverse( parentRotationMatrix ) );
|
|
|
|
- quaternionX.setFromAxisAngle( quaternionE, - point.clone().angleTo(tempVector) );
|
|
|
|
- quaternionXYZ.setFromRotationMatrix( worldRotationMatrix );
|
|
|
|
|
|
+ tempQuaternion.multiplyQuaternions( tempQuaternion, quaternionX );
|
|
|
|
+ tempQuaternion.multiplyQuaternions( tempQuaternion, quaternionXYZ );
|
|
|
|
|
|
- tempQuaternion.multiplyQuaternions( tempQuaternion, quaternionX );
|
|
|
|
- tempQuaternion.multiplyQuaternions( tempQuaternion, quaternionXYZ );
|
|
|
|
|
|
+ scope.object.quaternion.copy( tempQuaternion );
|
|
|
|
|
|
- scope.object.quaternion.copy( tempQuaternion );
|
|
|
|
|
|
+ } else if ( scope.space == "local" ) {
|
|
|
|
|
|
- } else if ( scope.space == "local" ) {
|
|
|
|
|
|
+ point.applyMatrix4( tempMatrix.getInverse( worldRotationMatrix ) );
|
|
|
|
|
|
- point.applyMatrix4( tempMatrix.getInverse( worldRotationMatrix ) );
|
|
|
|
|
|
+ tempVector.applyMatrix4( tempMatrix.getInverse( worldRotationMatrix ) );
|
|
|
|
|
|
- tempVector.applyMatrix4( tempMatrix.getInverse( worldRotationMatrix ) );
|
|
|
|
|
|
+ rotation.set( Math.atan2( point.z, point.y ), Math.atan2( point.x, point.z ), Math.atan2( point.y, point.x ) );
|
|
|
|
+ offsetRotation.set( Math.atan2( tempVector.z, tempVector.y ), Math.atan2( tempVector.x, tempVector.z ), Math.atan2( tempVector.y, tempVector.x ) );
|
|
|
|
|
|
- rotation.set( Math.atan2( point.z, point.y ), Math.atan2( point.x, point.z ), Math.atan2( point.y, point.x ) );
|
|
|
|
- offsetRotation.set( Math.atan2( tempVector.z, tempVector.y ), Math.atan2( tempVector.x, tempVector.z ), Math.atan2( tempVector.y, tempVector.x ) );
|
|
|
|
|
|
+ quaternionXYZ.setFromRotationMatrix( oldRotationMatrix );
|
|
|
|
+ quaternionX.setFromAxisAngle( unitX, rotation.x - offsetRotation.x );
|
|
|
|
+ quaternionY.setFromAxisAngle( unitY, rotation.y - offsetRotation.y );
|
|
|
|
+ quaternionZ.setFromAxisAngle( unitZ, rotation.z - offsetRotation.z );
|
|
|
|
|
|
- quaternionXYZ.setFromRotationMatrix( oldRotationMatrix );
|
|
|
|
- quaternionX.setFromAxisAngle( unitX, rotation.x - offsetRotation.x );
|
|
|
|
- quaternionY.setFromAxisAngle( unitY, rotation.y - offsetRotation.y );
|
|
|
|
- quaternionZ.setFromAxisAngle( unitZ, rotation.z - offsetRotation.z );
|
|
|
|
|
|
+ if ( scope.axis == "X" ) quaternionXYZ.multiplyQuaternions( quaternionXYZ, quaternionX );
|
|
|
|
+ if ( scope.axis == "Y" ) quaternionXYZ.multiplyQuaternions( quaternionXYZ, quaternionY );
|
|
|
|
+ if ( scope.axis == "Z" ) quaternionXYZ.multiplyQuaternions( quaternionXYZ, quaternionZ );
|
|
|
|
|
|
- if ( scope.axis == "X" ) quaternionXYZ.multiplyQuaternions( quaternionXYZ, quaternionX );
|
|
|
|
- if ( scope.axis == "Y" ) quaternionXYZ.multiplyQuaternions( quaternionXYZ, quaternionY );
|
|
|
|
- if ( scope.axis == "Z" ) quaternionXYZ.multiplyQuaternions( quaternionXYZ, quaternionZ );
|
|
|
|
|
|
+ scope.object.quaternion.copy( quaternionXYZ );
|
|
|
|
|
|
- scope.object.quaternion.copy( quaternionXYZ );
|
|
|
|
|
|
+ } else if ( scope.space == "world" ) {
|
|
|
|
|
|
- } else if ( scope.space == "world" ) {
|
|
|
|
|
|
+ rotation.set( Math.atan2( point.z, point.y ), Math.atan2( point.x, point.z ), Math.atan2( point.y, point.x ) );
|
|
|
|
+ offsetRotation.set( Math.atan2( tempVector.z, tempVector.y ), Math.atan2( tempVector.x, tempVector.z ), Math.atan2( tempVector.y, tempVector.x ) );
|
|
|
|
|
|
- rotation.set( Math.atan2( point.z, point.y ), Math.atan2( point.x, point.z ), Math.atan2( point.y, point.x ) );
|
|
|
|
- offsetRotation.set( Math.atan2( tempVector.z, tempVector.y ), Math.atan2( tempVector.x, tempVector.z ), Math.atan2( tempVector.y, tempVector.x ) );
|
|
|
|
|
|
+ tempQuaternion.setFromRotationMatrix( tempMatrix.getInverse( parentRotationMatrix ) );
|
|
|
|
|
|
- tempQuaternion.setFromRotationMatrix( tempMatrix.getInverse( parentRotationMatrix ) );
|
|
|
|
|
|
+ quaternionX.setFromAxisAngle( unitX, rotation.x - offsetRotation.x );
|
|
|
|
+ quaternionY.setFromAxisAngle( unitY, rotation.y - offsetRotation.y );
|
|
|
|
+ quaternionZ.setFromAxisAngle( unitZ, rotation.z - offsetRotation.z );
|
|
|
|
+ quaternionXYZ.setFromRotationMatrix( worldRotationMatrix );
|
|
|
|
|
|
- quaternionX.setFromAxisAngle( unitX, rotation.x - offsetRotation.x );
|
|
|
|
- quaternionY.setFromAxisAngle( unitY, rotation.y - offsetRotation.y );
|
|
|
|
- quaternionZ.setFromAxisAngle( unitZ, rotation.z - offsetRotation.z );
|
|
|
|
- quaternionXYZ.setFromRotationMatrix( worldRotationMatrix );
|
|
|
|
|
|
+ if ( scope.axis == "X" ) tempQuaternion.multiplyQuaternions( tempQuaternion, quaternionX );
|
|
|
|
+ if ( scope.axis == "Y" ) tempQuaternion.multiplyQuaternions( tempQuaternion, quaternionY );
|
|
|
|
+ if ( scope.axis == "Z" ) tempQuaternion.multiplyQuaternions( tempQuaternion, quaternionZ );
|
|
|
|
|
|
- if ( scope.axis == "X" ) tempQuaternion.multiplyQuaternions( tempQuaternion, quaternionX );
|
|
|
|
- if ( scope.axis == "Y" ) tempQuaternion.multiplyQuaternions( tempQuaternion, quaternionY );
|
|
|
|
- if ( scope.axis == "Z" ) tempQuaternion.multiplyQuaternions( tempQuaternion, quaternionZ );
|
|
|
|
|
|
+ tempQuaternion.multiplyQuaternions( tempQuaternion, quaternionXYZ );
|
|
|
|
|
|
- tempQuaternion.multiplyQuaternions( tempQuaternion, quaternionXYZ );
|
|
|
|
|
|
+ scope.object.quaternion.copy( tempQuaternion );
|
|
|
|
|
|
- scope.object.quaternion.copy( tempQuaternion );
|
|
|
|
|
|
+ }
|
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
- }
|
|
|
|
|
|
+ scope.update();
|
|
|
|
+ scope.dispatchEvent( changeEvent );
|
|
|
|
|
|
- scope.update();
|
|
|
|
- scope.dispatchEvent( changeEvent );
|
|
|
|
|
|
+ }
|
|
|
|
|
|
- }
|
|
|
|
|
|
+ function onPointerUp( event ) {
|
|
|
|
|
|
- function onPointerUp( event ) {
|
|
|
|
|
|
+ _dragging = false;
|
|
|
|
+ onPointerHover( event );
|
|
|
|
|
|
- _dragging = false;
|
|
|
|
- onPointerHover( event );
|
|
|
|
|
|
+ }
|
|
|
|
|
|
- }
|
|
|
|
|
|
+ function intersectObjects( pointer, objects ) {
|
|
|
|
|
|
- function intersectObjects( pointer, objects ) {
|
|
|
|
|
|
+ var rect = domElement.getBoundingClientRect();
|
|
|
|
+ var x = (pointer.clientX - rect.left) / rect.width;
|
|
|
|
+ var y = (pointer.clientY - rect.top) / rect.height;
|
|
|
|
+ pointerVector.set( ( x ) * 2 - 1, - ( y ) * 2 + 1, 0.5 );
|
|
|
|
|
|
- var rect = domElement.getBoundingClientRect();
|
|
|
|
- var x = (pointer.clientX - rect.left) / rect.width;
|
|
|
|
- var y = (pointer.clientY - rect.top) / rect.height;
|
|
|
|
- pointerVector.set( ( x ) * 2 - 1, - ( y ) * 2 + 1, 0.5 );
|
|
|
|
|
|
+ projector.unprojectVector( pointerVector, camera );
|
|
|
|
+ ray.set( camPosition, pointerVector.sub( camPosition ).normalize() );
|
|
|
|
|
|
- projector.unprojectVector( pointerVector, camera );
|
|
|
|
- ray.set( camPosition, pointerVector.sub( camPosition ).normalize() );
|
|
|
|
|
|
+ var intersections = ray.intersectObjects( objects, true );
|
|
|
|
+ return intersections[0] ? intersections[0] : false;
|
|
|
|
|
|
- var intersections = ray.intersectObjects( objects, true );
|
|
|
|
- return intersections[0] ? intersections[0] : false;
|
|
|
|
|
|
+ }
|
|
|
|
|
|
- }
|
|
|
|
|
|
+ };
|
|
|
|
|
|
-};
|
|
|
|
|
|
+ THREE.TransformControls.prototype = Object.create( THREE.Object3D.prototype );
|
|
|
|
|
|
-THREE.TransformControls.prototype = Object.create( THREE.Object3D.prototype );
|
|
|
|
|
|
+}());
|