123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094 |
- !function(){
-
-
-
- var BoxBufferGeometry,
- BufferGeometry,
- Color,
- CylinderBufferGeometry,
- DoubleSide,
- Euler,
- Float32BufferAttribute ,
- Line ,
- LineBasicMaterial ,
- Matrix4 ,
- Mesh ,
- MeshBasicMaterial ,
- Object3D ,
- OctahedronBufferGeometry ,
- PlaneBufferGeometry ,
- Quaternion ,
- Raycaster ,
- SphereBufferGeometry ,
- TorusBufferGeometry ,
- Vector2,
- Vector3 ;
-
- var TransformControls = function ( camera, domElement, options ) {
- if ( domElement === undefined ) {
- console.warn( 'THREE.TransformControls: The second parameter "domElement" is now mandatory.' );
- domElement = document;
- }
- Object3D.call( this );
- this.visible = false;
- this.domElement = domElement;
- var _gizmo = new TransformControlsGizmo(options);
- this.add( _gizmo );
- var _plane = new TransformControlsPlane(options);
- this.add( _plane );
- var scope = this;
- this.player = options.player;//xzw add
- this.options = options//xzw add
-
- // Define properties with getters/setter
- // Setting the defined property will automatically trigger change event
- // Defined properties are passed down to gizmo and plane
- defineProperty( "camera", camera );
- defineProperty( "object", undefined );
- defineProperty( "enabled", true );
- defineProperty( "axis", null );
- defineProperty( "mode", "translate" );
- defineProperty( "translationSnap", null );
- defineProperty( "rotationSnap", null );
- defineProperty( "scaleSnap", null );
- defineProperty( "space", "world" );
- defineProperty( "size", 1 );
- defineProperty( "dragging", false );
- defineProperty( "showX", true );
- defineProperty( "showY", true );
- defineProperty( "showZ", true );
- var changeEvent = { type: "change" };
- var mouseDownEvent = { type: "mouseDown" };
- var mouseUpEvent = { type: "mouseUp", mode: scope.mode };
- var objectChangeEvent = { type: "objectChange" };
- // Reusable utility variables
- var ray = new Raycaster();
- var _tempVector = new Vector3();
- var _tempVector2 = new Vector3();
- var _tempQuaternion = new Quaternion();
- var _unit = {
- X: new Vector3( 1, 0, 0 ),
- Y: new Vector3( 0, 1, 0 ),
- Z: new Vector3( 0, 0, 1 )
- };
- var pointStart = new Vector3();
- var pointEnd = new Vector3();
- var offset = new Vector3();
- var rotationAxis = new Vector3();
- var startNorm = new Vector3();
- var endNorm = new Vector3();
- var rotationAngle = 0;
- var cameraPosition = new Vector3();
- var cameraQuaternion = new Quaternion();
- var cameraScale = new Vector3();
- var parentPosition = new Vector3();
- var parentQuaternion = new Quaternion();
- var parentQuaternionInv = new Quaternion();
- var parentScale = new Vector3();
- var worldPositionStart = new Vector3();
- var worldQuaternionStart = new Quaternion();
- var worldScaleStart = new Vector3();
- var worldPosition = new Vector3();
- var worldQuaternion = new Quaternion();
- var worldQuaternionInv = new Quaternion();
- var worldScale = new Vector3();
- var eye = new Vector3();
- var positionStart = new Vector3();
- var quaternionStart = new Quaternion();
- var scaleStart = new Vector3();
-
- // TODO: remove properties unused in plane and gizmo
- defineProperty( "worldPosition", worldPosition );
- defineProperty( "worldPositionStart", worldPositionStart );
- defineProperty( "worldQuaternion", worldQuaternion );
- defineProperty( "worldQuaternionStart", worldQuaternionStart );
- defineProperty( "cameraPosition", cameraPosition );
- defineProperty( "cameraQuaternion", cameraQuaternion );
- defineProperty( "pointStart", pointStart );
- defineProperty( "pointEnd", pointEnd );
- defineProperty( "rotationAxis", rotationAxis );
- defineProperty( "rotationAngle", rotationAngle );
- defineProperty( "eye", eye );
- {
- domElement.addEventListener( "mousedown", onPointerDown, false );
- domElement.addEventListener( "touchstart", onPointerDown, false );
- domElement.addEventListener( "mousemove", onPointerHover, false );
- domElement.addEventListener( "touchmove", onPointerHover, false );
- domElement.addEventListener( "touchmove", onPointerMove, false );
- document.addEventListener( "mouseup", onPointerUp, false );
- domElement.addEventListener( "touchend", onPointerUp, false );
- domElement.addEventListener( "touchcancel", onPointerUp, false );
- domElement.addEventListener( "touchleave", onPointerUp, false );
- }
- this.dispose = function () {
- domElement.removeEventListener( "mousedown", onPointerDown );
- domElement.removeEventListener( "touchstart", onPointerDown );
- domElement.removeEventListener( "mousemove", onPointerHover );
- domElement.removeEventListener( "mousemove", onPointerMove );
- domElement.removeEventListener( "touchmove", onPointerHover );
- domElement.removeEventListener( "touchmove", onPointerMove );
- document.removeEventListener( "mouseup", onPointerUp );
- domElement.removeEventListener( "touchend", onPointerUp );
- domElement.removeEventListener( "touchcancel", onPointerUp );
- domElement.removeEventListener( "touchleave", onPointerUp );
- this.traverse( function ( child ) {
- if ( child.geometry ) child.geometry.dispose();
- if ( child.material ) child.material.dispose();
- } );
- };
- // Set current object
- this.attach = function ( object ) {
- this.object = object;
- this.visible = true;
- //Config.keyCon = false;//add
- return this;
- };
- // Detatch from object
- this.detach = function () {
- this.object = undefined;
- this.visible = false;
- this.axis = null;
- //Config.keyCon = true;//add
- return this;
- };
- // Defined getter, setter and store for a property
- function defineProperty( propName, defaultValue ) {
- var propValue = defaultValue;
- Object.defineProperty( scope, propName, {
- get: function () {
- return propValue !== undefined ? propValue : defaultValue;
- },
- set: function ( value ) {
- if ( propValue !== value ) {
- propValue = value;
- _plane[ propName ] = value;
- _gizmo[ propName ] = value;
- scope.dispatchEvent( { type: propName + "-changed", value: value } );
- scope.dispatchEvent( changeEvent );
- }
- }
- } );
- scope[ propName ] = defaultValue;
- _plane[ propName ] = defaultValue;
- _gizmo[ propName ] = defaultValue;
- }
- // updateMatrixWorld updates key transformation variables
- this.updateMatrixWorld = function () {
- if ( this.object !== undefined ) {
- this.object.updateMatrixWorld();
- this.object.parent.matrixWorld.decompose( parentPosition, parentQuaternion, parentScale );
- this.object.matrixWorld.decompose( worldPosition, worldQuaternion, worldScale );
- parentQuaternionInv.copy( parentQuaternion ).inverse();
- worldQuaternionInv.copy( worldQuaternion ).inverse();
- }
- this.camera.updateMatrixWorld();
- this.camera.matrixWorld.decompose( cameraPosition, cameraQuaternion, cameraScale );
- eye.copy( cameraPosition ).sub( worldPosition ).normalize();
- Object3D.prototype.updateMatrixWorld.call( this );
- };
- this.pointerHover = function ( pointer ) {
- if ( this.object === undefined || this.dragging === true || ( pointer.button !== undefined && pointer.button !== 0 ) ) return;
- //ray.setFromCamera( pointer, this.camera ); //这句会在floorplan模式get不到intersect
- var origin = new Vector3(pointer.x, pointer.y, -1).unproject(this.camera);
- ray.set(origin, player.getMouseDirection(pointer));
- var intersect = ray.intersectObjects( _gizmo.picker[ this.mode ].children, true )[ 0 ] || false;
- if ( intersect ) {
- this.axis = intersect.object.name;
- } else {
- this.axis = null;
- }
- };
- this.pointerDown = function ( pointer ) {
- if ( this.object === undefined || this.dragging === true || ( pointer.button !== undefined && pointer.button !== 0 ) ) return;
- if ( ( pointer.button === 0 || pointer.button === undefined ) && this.axis !== null ) {
- //ray.setFromCamera( pointer, this.camera ); //这句会在floorplan模式get不到intersect
- var origin = new Vector3(pointer.x, pointer.y, -1).unproject(this.camera);
- ray.set(origin, player.getMouseDirection(pointer));
- var planeIntersect = ray.intersectObjects( [ _plane ], true )[ 0 ] || false;
- if ( planeIntersect ) {
- var space = this.space;
- if ( this.mode === 'scale' ) {
- space = 'local';
- } else if ( this.axis === 'E' || this.axis === 'XYZE' || this.axis === 'XYZ' ) {
- space = 'world';
- }
- if ( space === 'local' && this.mode === 'rotate' ) {
- var snap = this.rotationSnap;
- if ( this.axis === 'X' && snap ) this.object.rotation.x = Math.round( this.object.rotation.x / snap ) * snap;
- if ( this.axis === 'Y' && snap ) this.object.rotation.y = Math.round( this.object.rotation.y / snap ) * snap;
- if ( this.axis === 'Z' && snap ) this.object.rotation.z = Math.round( this.object.rotation.z / snap ) * snap;
- }
- this.object.updateMatrixWorld();
- this.object.parent.updateMatrixWorld();
- positionStart.copy( this.object.position );
- quaternionStart.copy( this.object.quaternion );
- scaleStart.copy( this.object.scale );
- this.object.matrixWorld.decompose( worldPositionStart, worldQuaternionStart, worldScaleStart );
- pointStart.copy( planeIntersect.point ).sub( worldPositionStart );
-
- if(this.player.cameraControls.activeControl){
- //this.player.cameraControls.activeControl.locked = true; //add
- this.player.cameraControls.activeControl.enabled = false; //add
- }
-
- }
- this.dragging = true;
- mouseDownEvent.mode = this.mode;
- this.dispatchEvent( mouseDownEvent );
- }
- };
- this.pointerMove = function ( pointer ) {
- var axis = this.axis;
- var mode = this.mode;
- var object = this.object;
- var space = this.space;
- if ( mode === 'scale' ) {
- space = 'local';
- } else if ( axis === 'E' || axis === 'XYZE' || axis === 'XYZ' ) {
- space = 'world';
- }
-
- if ( object === undefined || axis === null || this.dragging === false || ( pointer.button !== undefined && pointer.button !== 0 ) ) return;
- //ray.setFromCamera( pointer, this.camera ); //这句会在floorplan模式get不到intersect
- var origin = new Vector3(pointer.x, pointer.y, -1).unproject(this.camera);
- ray.set(origin, player.getMouseDirection(pointer));
- var planeIntersect = ray.intersectObjects( [ _plane ], true )[ 0 ] || false;
- if ( planeIntersect === false ) return;
- pointEnd.copy( planeIntersect.point ).sub( worldPositionStart );
- if ( mode === 'translate' ) {
- // Apply translate
- offset.copy( pointEnd ).sub( pointStart );
- if ( space === 'local' && axis !== 'XYZ' ) {
- offset.applyQuaternion( worldQuaternionInv );
- }
- if ( axis.indexOf( 'X' ) === - 1 ) offset.x = 0;
- if ( axis.indexOf( 'Y' ) === - 1 ) offset.y = 0;
- if ( axis.indexOf( 'Z' ) === - 1 ) offset.z = 0;
- if ( space === 'local' && axis !== 'XYZ' ) {
- offset.applyQuaternion( quaternionStart ).divide( parentScale );
- } else {
- offset.applyQuaternion( parentQuaternionInv ).divide( parentScale );
- }
- object.position.copy( offset ).add( positionStart );
- // Apply translation snap
- if ( this.translationSnap ) {
- if ( space === 'local' ) {
- object.position.applyQuaternion( _tempQuaternion.copy( quaternionStart ).inverse() );
- if ( axis.search( 'X' ) !== - 1 ) {
- object.position.x = Math.round( object.position.x / this.translationSnap ) * this.translationSnap;
- }
- if ( axis.search( 'Y' ) !== - 1 ) {
- object.position.y = Math.round( object.position.y / this.translationSnap ) * this.translationSnap;
- }
- if ( axis.search( 'Z' ) !== - 1 ) {
- object.position.z = Math.round( object.position.z / this.translationSnap ) * this.translationSnap;
- }
- object.position.applyQuaternion( quaternionStart );
- }
- if ( space === 'world' ) {
- if ( object.parent ) {
- object.position.add( _tempVector.setFromMatrixPosition( object.parent.matrixWorld ) );
- }
- if ( axis.search( 'X' ) !== - 1 ) {
- object.position.x = Math.round( object.position.x / this.translationSnap ) * this.translationSnap;
- }
- if ( axis.search( 'Y' ) !== - 1 ) {
- object.position.y = Math.round( object.position.y / this.translationSnap ) * this.translationSnap;
- }
- if ( axis.search( 'Z' ) !== - 1 ) {
- object.position.z = Math.round( object.position.z / this.translationSnap ) * this.translationSnap;
- }
- if ( object.parent ) {
- object.position.sub( _tempVector.setFromMatrixPosition( object.parent.matrixWorld ) );
- }
- }
- }
- //add:
-
- if(EditOverlay.editing){
- EditOverlay.updatePosition();
- }
- } else if ( mode === 'scale' ) {
- if ( axis.search( 'XYZ' ) !== - 1 ) {
- var d = pointEnd.length() / pointStart.length();
- if ( pointEnd.dot( pointStart ) < 0 ) d *= - 1;
-
- if(options.NoScaleZ){//xzw add
- _tempVector2.set( d, d, 1 );
- }else{
- _tempVector2.set( d, d, d );
- }
- } else {
- _tempVector.copy( pointStart );
- _tempVector2.copy( pointEnd );
- _tempVector.applyQuaternion( worldQuaternionInv );
- _tempVector2.applyQuaternion( worldQuaternionInv );
- _tempVector2.divide( _tempVector );
- if ( axis.search( 'X' ) === - 1 ) {
- _tempVector2.x = 1;
- }
- if ( axis.search( 'Y' ) === - 1 ) {
- _tempVector2.y = 1;
- }
- if ( axis.search( 'Z' ) === - 1 ) {
- _tempVector2.z = 1;
- }
- }
- // Apply scale
- object.scale.copy( scaleStart ).multiply( _tempVector2 );
- if ( this.scaleSnap ) {
- if ( axis.search( 'X' ) !== - 1 ) {
- object.scale.x = Math.round( object.scale.x / this.scaleSnap ) * this.scaleSnap || this.scaleSnap;
- }
- if ( axis.search( 'Y' ) !== - 1 ) {
- object.scale.y = Math.round( object.scale.y / this.scaleSnap ) * this.scaleSnap || this.scaleSnap;
- }
- if ( axis.search( 'Z' ) !== - 1 ) {
- object.scale.z = Math.round( object.scale.z / this.scaleSnap ) * this.scaleSnap || this.scaleSnap;
- }
- }
- //add:
-
-
-
- if(EditOverlay.editing){
- EditOverlay.updateScale();
- }
- } else if ( mode === 'rotate' ) {
- offset.copy( pointEnd ).sub( pointStart );
- var ROTATION_SPEED = 2 / worldPosition.distanceTo( _tempVector.setFromMatrixPosition( this.camera.matrixWorld ) );
- if ( axis === 'E' ) {
- rotationAxis.copy( eye );
- rotationAngle = pointEnd.angleTo( pointStart );
- startNorm.copy( pointStart ).normalize();
- endNorm.copy( pointEnd ).normalize();
- rotationAngle *= ( endNorm.cross( startNorm ).dot( eye ) < 0 ? 1 : - 1 );
- } else if ( axis === 'XYZE' ) {
- rotationAxis.copy( offset ).cross( eye ).normalize();
- rotationAngle = offset.dot( _tempVector.copy( rotationAxis ).cross( this.eye ) ) * ROTATION_SPEED;
- } else if ( axis === 'X' || axis === 'Y' || axis === 'Z' ) {
- rotationAxis.copy( _unit[ axis ] );
- _tempVector.copy( _unit[ axis ] );
- if ( space === 'local' ) {
- _tempVector.applyQuaternion( worldQuaternion );
- }
- rotationAngle = offset.dot( _tempVector.cross( eye ).normalize() ) * ROTATION_SPEED;
- }
- // Apply rotation snap
- if ( this.rotationSnap ) rotationAngle = Math.round( rotationAngle / this.rotationSnap ) * this.rotationSnap;
- this.rotationAngle = rotationAngle;
- // Apply rotate
- if ( space === 'local' && axis !== 'E' && axis !== 'XYZE' ) {
- object.quaternion.copy( quaternionStart );
- object.quaternion.multiply( _tempQuaternion.setFromAxisAngle( rotationAxis, rotationAngle ) ).normalize();
- } else {
- rotationAxis.applyQuaternion( parentQuaternionInv );
- object.quaternion.copy( _tempQuaternion.setFromAxisAngle( rotationAxis, rotationAngle ) );
- object.quaternion.multiply( quaternionStart ).normalize();
- }
-
- //add:
-
-
-
- if(EditOverlay.editing){
- EditOverlay.updateQua();
- }
- }
- this.dispatchEvent( changeEvent );
- this.dispatchEvent( objectChangeEvent );
- };
- this.pointerUp = function ( pointer ) {
- //if ( pointer.button !== undefined && pointer.button !== 0 ) return;
- if ( this.dragging && ( this.axis !== null ) ) {
- mouseUpEvent.mode = this.mode;
- this.dispatchEvent( mouseUpEvent );
- }
- this.dragging = false;
- if ( pointer.button === undefined ) this.axis = null;
-
- if(this.player.cameraControls.activeControl){
- //this.player.cameraControls.activeControl.locked = false; //add
- this.player.cameraControls.activeControl.pointerDragOn = false //add
- this.player.cameraControls.activeControl.enabled = true
- }
-
- };
- // normalize mouse / touch pointer and remap {x,y} to view space.
- function getPointer( event ) {
- if(!event){
- console.log('hhahhhahah')
- return;
- }
- if ( document.pointerLockElement ) {
- return {
- x: 0,
- y: 0,
- button: event.button
- };
- } else {
- var pointer = event.changedTouches ? event.changedTouches[ 0 ] : event;
- var rect = domElement.getBoundingClientRect();
- return {
- x: ( pointer.clientX - rect.left ) / rect.width * 2 - 1,
- y: - ( pointer.clientY - rect.top ) / rect.height * 2 + 1,
- button: event.button
- };
- }
- }
- // mouse / touch event handlers
- function onPointerHover( event ) {
- if ( ! scope.enabled ) return;
- //scope.pointerHover( getPointer( event ) );
- scope.pointerHover( scope.player.mouse );
- }
- function onPointerDown( event ) {
- if ( ! scope.enabled ) return;
- //document.addEventListener( "mousemove", onPointerMove, false );
- /* scope.pointerHover( getPointer( event ) );
- scope.pointerDown( getPointer( event ) ); */
- scope.pointerHover( scope.player.mouse );
- scope.pointerDown( scope.player.mouse );
- }
- this.onPointerDown = onPointerDown;
- function onPointerMove( event ) {
-
- if ( ! scope.enabled || !this.dragging) return; //xzw change
- //scope.pointerMove( getPointer( event ) );
- scope.pointerMove( scope.player.mouse );
- }
- this.onPointerMove = onPointerMove;
-
-
- function onPointerUp( event ) {
-
- if ( ! scope.enabled ) return;
- //document.removeEventListener( "mousemove", onPointerMove, false );
- //scope.pointerUp( getPointer( event ) );
- scope.pointerUp( scope.player.mouse );
- }
- this.onPointerUp = onPointerUp;
- // TODO: deprecate
- this.getMode = function () {
- return scope.mode;
- };
- this.setMode = function ( mode ) {
- scope.mode = mode;
- };
- this.setTranslationSnap = function ( translationSnap ) {
- scope.translationSnap = translationSnap;
- };
- this.setRotationSnap = function ( rotationSnap ) {
- scope.rotationSnap = rotationSnap;
- };
- this.setScaleSnap = function ( scaleSnap ) {
- scope.scaleSnap = scaleSnap;
- };
- this.setSize = function ( size ) {
- scope.size = size;
- };
- this.setSpace = function ( space ) {
- scope.space = space;
- };
- this.update = function () {
- console.warn( 'THREE.TransformControls: update function has no more functionality and therefore has been deprecated.' );
- };
- };
- var TransformControlsGizmo = function (options) {
- 'use strict';
- Object3D.call( this );
- this.type = 'TransformControlsGizmo';
- // shared materials
- var gizmoMaterial = new MeshBasicMaterial( {
- depthTest: false,
- depthWrite: false,
- transparent: true,
- side: DoubleSide,
- fog: false
- } );
- var gizmoLineMaterial = new LineBasicMaterial( {
- depthTest: false,
- depthWrite: false,
- transparent: true,
- linewidth: 1,
- fog: false
- } );
- // Make unique material for each axis/color
- var matInvisible = gizmoMaterial.clone();
- matInvisible.opacity = 0.15;
- var matHelper = gizmoMaterial.clone();
- matHelper.opacity = 0.33;
- var matRed = gizmoMaterial.clone();
- matRed.color.set( 0xff0000 );
- var matGreen = gizmoMaterial.clone();
- matGreen.color.set( 0x00ff00 );
- var matBlue = gizmoMaterial.clone();
- matBlue.color.set( 0x0000ff );
- var matWhiteTransparent = gizmoMaterial.clone();
- matWhiteTransparent.opacity = 0.35;
- matWhiteTransparent.color.set( 0x00d0fd );//xzw add
- var matYellowTransparent = matWhiteTransparent.clone();
- matYellowTransparent.color.set( 0xffff00 );
- var matCyanTransparent = matWhiteTransparent.clone();
- matCyanTransparent.color.set( 0x00ffff );
- var matMagentaTransparent = matWhiteTransparent.clone();
- matMagentaTransparent.color.set( 0xff00ff );
- var matYellow = gizmoMaterial.clone();
- matYellow.color.set( 0xffff00 );
- var matLineRed = gizmoLineMaterial.clone();
- matLineRed.color.set( 0xff0000 );
- var matLineGreen = gizmoLineMaterial.clone();
- matLineGreen.color.set( 0x00ff00 );
- var matLineBlue = gizmoLineMaterial.clone();
- matLineBlue.color.set( 0x0000ff );
- var matLineCyan = gizmoLineMaterial.clone();
- matLineCyan.color.set( 0x00ffff );
- var matLineMagenta = gizmoLineMaterial.clone();
- matLineMagenta.color.set( 0xff00ff );
- var matLineYellow = gizmoLineMaterial.clone();
- matLineYellow.color.set( 0xffff00 );
- var matLineGray = gizmoLineMaterial.clone();
- matLineGray.color.set( 0x787878 );
- var matLineYellowTransparent = matLineYellow.clone();
- matLineYellowTransparent.opacity = 0.25;
- // reusable geometry
- var arrowGeometry = new CylinderBufferGeometry( 0, 0.05, 0.2, 12, 1, false );
- var scaleHandleGeometry = new BoxBufferGeometry( 0.125, 0.125, 0.125 );
- var lineGeometry = new BufferGeometry( );
- //lineGeometry.addAttribute( 'position', new Float32BufferAttribute( [ 0, 0, 0, 1, 0, 0 ], 3 ) );
- lineGeometry.addAttribute("position", new THREE.BufferAttribute(new Float32Array([ 0, 0, 0, 1, 0, 0]), 3 ))
-
-
- var CircleGeometry = function ( radius, arc ) {
- var geometry = new BufferGeometry( );
- var vertices = [];
- for ( var i = 0; i <= 64 * arc; ++ i ) {
- vertices.push( 0, Math.cos( i / 32 * Math.PI ) * radius, Math.sin( i / 32 * Math.PI ) * radius );
- }
- //geometry.addAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
- geometry.addAttribute("position", new THREE.BufferAttribute(new Float32Array(vertices), 3 ))
- return geometry;
- };
- // Special geometry for transform helper. If scaled with position vector it spans from [0,0,0] to position
- var TranslateHelperGeometry = function () {
- var geometry = new BufferGeometry();
- //geometry.addAttribute( 'position', new Float32BufferAttribute( [ 0, 0, 0, 1, 1, 1 ], 3 ) );
- geometry.addAttribute("position", new THREE.BufferAttribute(new Float32Array([ 0, 0, 0, 1, 1, 1 ]), 3 ))
- return geometry;
- };
- // Gizmo definitions - custom hierarchy definitions for setupGizmo() function
- var gizmoTranslate = {
- X: [
- [ new Mesh( arrowGeometry, matRed ), [ 1, 0, 0 ], [ 0, 0, - Math.PI / 2 ], null, 'fwd' ],
- //[ new Mesh( arrowGeometry, matRed ), [ 1, 0, 0 ], [ 0, 0, Math.PI / 2 ], null, 'bwd' ],
- [ new Line( lineGeometry, matLineRed ) ]
- ],
- Y: [
- [ new Mesh( arrowGeometry, matGreen ), [ 0, 1, 0 ], null, null, 'fwd' ],
- //[ new Mesh( arrowGeometry, matGreen ), [ 0, 1, 0 ], [ Math.PI, 0, 0 ], null, 'bwd' ],
- [ new Line( lineGeometry, matLineGreen ), null, [ 0, 0, Math.PI / 2 ]]
- ],
- Z: [
- [ new Mesh( arrowGeometry, matBlue ), [ 0, 0, 1 ], [ Math.PI / 2, 0, 0 ], null, 'fwd' ],
- //[ new Mesh( arrowGeometry, matBlue ), [ 0, 0, 1 ], [ - Math.PI / 2, 0, 0 ], null, 'bwd' ],
- [ new Line( lineGeometry, matLineBlue ), null, [ 0, - Math.PI / 2, 0 ]]
- ],
- /* XYZ: [
- [ new Mesh( new OctahedronBufferGeometry( 0.1, 0 ), matWhiteTransparent.clone() ), [ 0, 0, 0 ], [ 0, 0, 0 ]]
- ], */
- XY: [
- [ new Mesh( new PlaneBufferGeometry( 0.295, 0.295 ), matYellowTransparent.clone() ), [ 0.15, 0.15, 0 ]],
- [ new Line( lineGeometry, matLineYellow ), [ 0.18, 0.3, 0 ], null, [ 0.125, 1, 1 ]],
- [ new Line( lineGeometry, matLineYellow ), [ 0.3, 0.18, 0 ], [ 0, 0, Math.PI / 2 ], [ 0.125, 1, 1 ]]
- ],
- YZ: [
- [ new Mesh( new PlaneBufferGeometry( 0.295, 0.295 ), matCyanTransparent.clone() ), [ 0, 0.15, 0.15 ], [ 0, Math.PI / 2, 0 ]],
- [ new Line( lineGeometry, matLineCyan ), [ 0, 0.18, 0.3 ], [ 0, 0, Math.PI / 2 ], [ 0.125, 1, 1 ]],
- [ new Line( lineGeometry, matLineCyan ), [ 0, 0.3, 0.18 ], [ 0, - Math.PI / 2, 0 ], [ 0.125, 1, 1 ]]
- ],
- XZ: [
- [ new Mesh( new PlaneBufferGeometry( 0.295, 0.295 ), matMagentaTransparent.clone() ), [ 0.15, 0, 0.15 ], [ - Math.PI / 2, 0, 0 ]],
- [ new Line( lineGeometry, matLineMagenta ), [ 0.18, 0, 0.3 ], null, [ 0.125, 1, 1 ]],
- [ new Line( lineGeometry, matLineMagenta ), [ 0.3, 0, 0.18 ], [ 0, - Math.PI / 2, 0 ], [ 0.125, 1, 1 ]]
- ]
- };
- var pickerTranslate = {
- X: [
- [ new Mesh( new CylinderBufferGeometry( 0.2, 0, 1, 4, 1, false ), matInvisible ), [ 0.6, 0, 0 ], [ 0, 0, - Math.PI / 2 ]]
- ],
- Y: [
- [ new Mesh( new CylinderBufferGeometry( 0.2, 0, 1, 4, 1, false ), matInvisible ), [ 0, 0.6, 0 ]]
- ],
- Z: [
- [ new Mesh( new CylinderBufferGeometry( 0.2, 0, 1, 4, 1, false ), matInvisible ), [ 0, 0, 0.6 ], [ Math.PI / 2, 0, 0 ]]
- ],
- /* XYZ: [
- [ new Mesh( new OctahedronBufferGeometry( 0.2, 0 ), matInvisible ) ]
- ], */
- XY: [
- [ new Mesh( new PlaneBufferGeometry( 0.4, 0.4 ), matInvisible ), [ 0.2, 0.2, 0 ]]
- ],
- YZ: [
- [ new Mesh( new PlaneBufferGeometry( 0.4, 0.4 ), matInvisible ), [ 0, 0.2, 0.2 ], [ 0, Math.PI / 2, 0 ]]
- ],
- XZ: [
- [ new Mesh( new PlaneBufferGeometry( 0.4, 0.4 ), matInvisible ), [ 0.2, 0, 0.2 ], [ - Math.PI / 2, 0, 0 ]]
- ]
- };
- var helperTranslate = {
- START: [
- [ new Mesh( new OctahedronBufferGeometry( 0.01, 2 ), matHelper ), null, null, null, 'helper' ]
- ],
- END: [
- [ new Mesh( new OctahedronBufferGeometry( 0.01, 2 ), matHelper ), null, null, null, 'helper' ]
- ],
- DELTA: [
- [ new Line( TranslateHelperGeometry(), matHelper ), null, null, null, 'helper' ]
- ],
- X: [
- [ new Line( lineGeometry, matHelper.clone() ), [ - 1e3, 0, 0 ], null, [ 1e6, 1, 1 ], 'helper' ]
- ],
- Y: [
- [ new Line( lineGeometry, matHelper.clone() ), [ 0, - 1e3, 0 ], [ 0, 0, Math.PI / 2 ], [ 1e6, 1, 1 ], 'helper' ]
- ],
- Z: [
- [ new Line( lineGeometry, matHelper.clone() ), [ 0, 0, - 1e3 ], [ 0, - Math.PI / 2, 0 ], [ 1e6, 1, 1 ], 'helper' ]
- ]
- };
- var gizmoRotate = {
- X: [
- [ new Line( CircleGeometry( 1, 0.5 ), matLineRed ) ],
- [ new Mesh( new OctahedronBufferGeometry( 0.04, 0 ), matRed ), [ 0, 0, 0.99 ], null, [ 1, 3, 1 ]],
- ],
- Y: [
- [ new Line( CircleGeometry( 1, 0.5 ), matLineGreen ), null, [ 0, 0, - Math.PI / 2 ]],
- [ new Mesh( new OctahedronBufferGeometry( 0.04, 0 ), matGreen ), [ 0, 0, 0.99 ], null, [ 3, 1, 1 ]],
- ],
- Z: [
- [ new Line( CircleGeometry( 1, 0.5 ), matLineBlue ), null, [ 0, Math.PI / 2, 0 ]],
- [ new Mesh( new OctahedronBufferGeometry( 0.04, 0 ), matBlue ), [ 0.99, 0, 0 ], null, [ 1, 3, 1 ]],
- ],
- E: [
- [ new Line( CircleGeometry( 1.25, 1 ), matLineYellowTransparent ), null, [ 0, Math.PI / 2, 0 ]],
- [ new Mesh( new CylinderBufferGeometry( 0.03, 0, 0.15, 4, 1, false ), matLineYellowTransparent ), [ 1.17, 0, 0 ], [ 0, 0, - Math.PI / 2 ], [ 1, 1, 0.001 ]],
- [ new Mesh( new CylinderBufferGeometry( 0.03, 0, 0.15, 4, 1, false ), matLineYellowTransparent ), [ - 1.17, 0, 0 ], [ 0, 0, Math.PI / 2 ], [ 1, 1, 0.001 ]],
- [ new Mesh( new CylinderBufferGeometry( 0.03, 0, 0.15, 4, 1, false ), matLineYellowTransparent ), [ 0, - 1.17, 0 ], [ Math.PI, 0, 0 ], [ 1, 1, 0.001 ]],
- [ new Mesh( new CylinderBufferGeometry( 0.03, 0, 0.15, 4, 1, false ), matLineYellowTransparent ), [ 0, 1.17, 0 ], [ 0, 0, 0 ], [ 1, 1, 0.001 ]],
- ],
- XYZE: [
- [ new Line( CircleGeometry( 1, 1 ), matLineGray ), null, [ 0, Math.PI / 2, 0 ]]
- ]
- };
- var helperRotate = {
- AXIS: [
- [ new Line( lineGeometry, matHelper.clone() ), [ - 1e3, 0, 0 ], null, [ 1e6, 1, 1 ], 'helper' ]
- ]
- };
- var pickerRotate = {
- X: [
- [ new Mesh( new TorusBufferGeometry( 1, 0.1, 4, 24 ), matInvisible ), [ 0, 0, 0 ], [ 0, - Math.PI / 2, - Math.PI / 2 ]],
- ],
- Y: [
- [ new Mesh( new TorusBufferGeometry( 1, 0.1, 4, 24 ), matInvisible ), [ 0, 0, 0 ], [ Math.PI / 2, 0, 0 ]],
- ],
- Z: [
- [ new Mesh( new TorusBufferGeometry( 1, 0.1, 4, 24 ), matInvisible ), [ 0, 0, 0 ], [ 0, 0, - Math.PI / 2 ]],
- ],
- E: [
- [ new Mesh( new TorusBufferGeometry( 1.25, 0.1, 2, 24 ), matInvisible ) ]
- ],
- XYZE: [
- [ new Mesh( new SphereBufferGeometry( 0.7, 10, 8 ), matInvisible ) ]
- ]
- };
- var gizmoScale = {
- X: [
- [ new Mesh( scaleHandleGeometry, matRed ), [ 0.8, 0, 0 ], [ 0, 0, - Math.PI / 2 ]],
- [ new Line( lineGeometry, matLineRed ), null, null, [ 0.8, 1, 1 ]]
- ],
- Y: [
- [ new Mesh( scaleHandleGeometry, matGreen ), [ 0, 0.8, 0 ]],
- [ new Line( lineGeometry, matLineGreen ), null, [ 0, 0, Math.PI / 2 ], [ 0.8, 1, 1 ]]
- ],
- /*Z: [
- [ new Mesh( scaleHandleGeometry, matBlue ), [ 0, 0, 0.8 ], [ Math.PI / 2, 0, 0 ]],
- [ new Line( lineGeometry, matLineBlue ), null, [ 0, - Math.PI / 2, 0 ], [ 0.8, 1, 1 ]]
- ],
- XY: [
- [ new Mesh( scaleHandleGeometry, matYellowTransparent ), [ 0.85, 0.85, 0 ], null, [ 2, 2, 0.2 ]],
- [ new Line( lineGeometry, matLineYellow ), [ 0.855, 0.98, 0 ], null, [ 0.125, 1, 1 ]],
- [ new Line( lineGeometry, matLineYellow ), [ 0.98, 0.855, 0 ], [ 0, 0, Math.PI / 2 ], [ 0.125, 1, 1 ]]
- ],
- YZ: [
- [ new Mesh( scaleHandleGeometry, matCyanTransparent ), [ 0, 0.85, 0.85 ], null, [ 0.2, 2, 2 ]],
- [ new Line( lineGeometry, matLineCyan ), [ 0, 0.855, 0.98 ], [ 0, 0, Math.PI / 2 ], [ 0.125, 1, 1 ]],
- [ new Line( lineGeometry, matLineCyan ), [ 0, 0.98, 0.855 ], [ 0, - Math.PI / 2, 0 ], [ 0.125, 1, 1 ]]
- ],
- XZ: [
- [ new Mesh( scaleHandleGeometry, matMagentaTransparent ), [ 0.85, 0, 0.85 ], null, [ 2, 0.2, 2 ]],
- [ new Line( lineGeometry, matLineMagenta ), [ 0.855, 0, 0.98 ], null, [ 0.125, 1, 1 ]],
- [ new Line( lineGeometry, matLineMagenta ), [ 0.98, 0, 0.855 ], [ 0, - Math.PI / 2, 0 ], [ 0.125, 1, 1 ]]
- ], */
- XYZX: [
- [ new Mesh( new BoxBufferGeometry( 0.125, 0.125, 0.125 ), matWhiteTransparent.clone() ), [ 1.1, 0, 0 ]],
- ],
- XYZY: [
- [ new Mesh( new BoxBufferGeometry( 0.125, 0.125, 0.125 ), matWhiteTransparent.clone() ), [ 0, 1.1, 0 ]],
- ]/* ,
- XYZZ: [
- [ new Mesh( new BoxBufferGeometry( 0.125, 0.125, 0.125 ), matWhiteTransparent.clone() ), [ 0, 0, 1.1 ]],
- ] */
- };
-
-
-
- var pickerScale = {
- X: [
- [ new Mesh( new CylinderBufferGeometry( 0.2, 0, 0.8, 4, 1, false ), matInvisible ), [ 0.5, 0, 0 ], [ 0, 0, - Math.PI / 2 ]]
- ],
- Y: [
- [ new Mesh( new CylinderBufferGeometry( 0.2, 0, 0.8, 4, 1, false ), matInvisible ), [ 0, 0.5, 0 ]]
- ],
- /* Z: [
- [ new Mesh( new CylinderBufferGeometry( 0.2, 0, 0.8, 4, 1, false ), matInvisible ), [ 0, 0, 0.5 ], [ Math.PI / 2, 0, 0 ]]
- ],
- XY: [
- [ new Mesh( scaleHandleGeometry, matInvisible ), [ 0.85, 0.85, 0 ], null, [ 3, 3, 0.2 ]],
- ],
- YZ: [
- [ new Mesh( scaleHandleGeometry, matInvisible ), [ 0, 0.85, 0.85 ], null, [ 0.2, 3, 3 ]],
- ],
- XZ: [
- [ new Mesh( scaleHandleGeometry, matInvisible ), [ 0.85, 0, 0.85 ], null, [ 3, 0.2, 3 ]],
- ], */
- XYZX: [
- [ new Mesh( new BoxBufferGeometry( 0.2, 0.2, 0.2 ), matInvisible ), [ 1.1, 0, 0 ]],
- ],
- XYZY: [
- [ new Mesh( new BoxBufferGeometry( 0.2, 0.2, 0.2 ), matInvisible ), [ 0, 1.1, 0 ]],
- ]/* ,
- XYZZ: [
- [ new Mesh( new BoxBufferGeometry( 0.2, 0.2, 0.2 ), matInvisible ), [ 0, 0, 1.1 ]],
- ] */
- };
- var helperScale = {
- X: [
- [ new Line( lineGeometry, matHelper.clone() ), [ - 1e3, 0, 0 ], null, [ 1e6, 1, 1 ], 'helper' ]
- ],
- Y: [
- [ new Line( lineGeometry, matHelper.clone() ), [ 0, - 1e3, 0 ], [ 0, 0, Math.PI / 2 ], [ 1e6, 1, 1 ], 'helper' ]
- ],
- Z: [
- [ new Line( lineGeometry, matHelper.clone() ), [ 0, 0, - 1e3 ], [ 0, - Math.PI / 2, 0 ], [ 1e6, 1, 1 ], 'helper' ]
- ]
- };
- // Creates an Object3D with gizmos described in custom hierarchy definition.
- var setupGizmo = function ( gizmoMap ) {
- var gizmo = new Object3D();
- for ( var name in gizmoMap ) {
- for ( var i = gizmoMap[ name ].length; i --; ) {
- var object = gizmoMap[ name ][ i ][ 0 ].clone();
- var position = gizmoMap[ name ][ i ][ 1 ];
- var rotation = gizmoMap[ name ][ i ][ 2 ];
- var scale = gizmoMap[ name ][ i ][ 3 ];
- var tag = gizmoMap[ name ][ i ][ 4 ];
- // name and tag properties are essential for picking and updating logic.
- object.name = name;
- object.tag = tag;
- if ( position ) {
- object.position.set( position[ 0 ], position[ 1 ], position[ 2 ] );
- }
- if ( rotation ) {
- object.rotation.set( rotation[ 0 ], rotation[ 1 ], rotation[ 2 ] );
- }
- if ( scale ) {
- object.scale.set( scale[ 0 ], scale[ 1 ], scale[ 2 ] );
- }
- object.updateMatrix();
- var tempGeometry = object.geometry.clone();
- tempGeometry.applyMatrix( object.matrix );
- object.geometry = tempGeometry;
- object.renderOrder = Infinity;
- object.position.set( 0, 0, 0 );
- object.rotation.set( 0, 0, 0 );
- object.scale.set( 1, 1, 1 );
- gizmo.add( object );
- }
- }
- return gizmo;
- };
- // Reusable utility variables
- var tempVector = new Vector3( 0, 0, 0 );
- var tempEuler = new Euler();
- var alignVector = new Vector3( 0, 1, 0 );
- var zeroVector = new Vector3( 0, 0, 0 );
- var lookAtMatrix = new Matrix4();
- var tempQuaternion = new Quaternion();
- var tempQuaternion2 = new Quaternion();
- var identityQuaternion = new Quaternion();
- var unitX = new Vector3( 1, 0, 0 );
- var unitY = new Vector3( 0, 1, 0 );
- var unitZ = new Vector3( 0, 0, 1 );
- // Gizmo creation
- this.gizmo = {};
- this.picker = {};
- this.helper = {};
- this.add( this.gizmo[ "translate" ] = setupGizmo( gizmoTranslate ) );
- this.add( this.gizmo[ "rotate" ] = setupGizmo( gizmoRotate ) );
- this.add( this.gizmo[ "scale" ] = setupGizmo( gizmoScale ) );
- this.add( this.picker[ "translate" ] = setupGizmo( pickerTranslate ) );
- this.add( this.picker[ "rotate" ] = setupGizmo( pickerRotate ) );
- this.add( this.picker[ "scale" ] = setupGizmo( pickerScale ) );
- this.add( this.helper[ "translate" ] = setupGizmo( helperTranslate ) );
- this.add( this.helper[ "rotate" ] = setupGizmo( helperRotate ) );
- this.add( this.helper[ "scale" ] = setupGizmo( helperScale ) );
- // Pickers should be hidden always
- this.picker[ "translate" ].visible = false;
- this.picker[ "rotate" ].visible = false;
- this.picker[ "scale" ].visible = false;
- // updateMatrixWorld will update transformations and appearance of individual handles
- this.updateMatrixWorld = function () {
- var space = this.space;
- if ( this.mode === 'scale' ) space = 'local'; // scale always oriented to local rotation
- var quaternion = space === "local" ? this.worldQuaternion : identityQuaternion;
- // Show only gizmos for current transform mode
- this.gizmo[ "translate" ].visible = this.mode === "translate";
- this.gizmo[ "rotate" ].visible = this.mode === "rotate";
- this.gizmo[ "scale" ].visible = this.mode === "scale";
- this.helper[ "translate" ].visible = this.mode === "translate";
- this.helper[ "rotate" ].visible = this.mode === "rotate";
- this.helper[ "scale" ].visible = this.mode === "scale";
- var handles = [];
- handles = handles.concat( this.picker[ this.mode ].children );
- handles = handles.concat( this.gizmo[ this.mode ].children );
- handles = handles.concat( this.helper[ this.mode ].children );
- for ( var i = 0; i < handles.length; i ++ ) {
- var handle = handles[ i ];
- // hide aligned to camera
- handle.visible = true;
- handle.rotation.set( 0, 0, 0 );
- handle.position.copy( this.worldPosition );
- var eyeDistance = this.worldPosition.distanceTo( this.cameraPosition );
-
- //俯视图的透视和距离无关,因此在两种相机切换切换时大小过渡比较困难
- if(player.mode == "transitioning" && (player.modeTran.split('-')[0] == "floorplan" || player.modeTran.split('-')[1] == "floorplan")){
- eyeDistance = Math.min(eyeDistance, 6.5)//从一开始很小的距离过渡到俯视图50的高度,会变得很大。
- }else if(player.mode == "floorplan"){
- var flcamera = player.cameraControls.cameras.floorplan;
- eyeDistance = (flcamera.right - flcamera.left ) / flcamera.aspect ;
- }
-
-
- handle.scale.set( 1, 1, 1 ).multiplyScalar( eyeDistance * this.size / 7 );
- // TODO: simplify helpers and consider decoupling from gizmo
- if ( handle.tag === 'helper' ) {
- handle.visible = false;
- if ( handle.name === 'AXIS' ) {
- handle.position.copy( this.worldPositionStart );
- handle.visible = !! this.axis;
- if ( this.axis === 'X' ) {
- tempQuaternion.setFromEuler( tempEuler.set( 0, 0, 0 ) );
- handle.quaternion.copy( quaternion ).multiply( tempQuaternion );
- if ( Math.abs( alignVector.copy( unitX ).applyQuaternion( quaternion ).dot( this.eye ) ) > 0.9 ) {
- handle.visible = false;
- }
- }
- if ( this.axis === 'Y' ) {
- tempQuaternion.setFromEuler( tempEuler.set( 0, 0, Math.PI / 2 ) );
- handle.quaternion.copy( quaternion ).multiply( tempQuaternion );
- if ( Math.abs( alignVector.copy( unitY ).applyQuaternion( quaternion ).dot( this.eye ) ) > 0.9 ) {
- handle.visible = false;
- }
- }
- if ( this.axis === 'Z' ) {
- tempQuaternion.setFromEuler( tempEuler.set( 0, Math.PI / 2, 0 ) );
- handle.quaternion.copy( quaternion ).multiply( tempQuaternion );
- if ( Math.abs( alignVector.copy( unitZ ).applyQuaternion( quaternion ).dot( this.eye ) ) > 0.9 ) {
- handle.visible = false;
- }
- }
- if ( this.axis === 'XYZE' ) {
- tempQuaternion.setFromEuler( tempEuler.set( 0, Math.PI / 2, 0 ) );
- alignVector.copy( this.rotationAxis );
- handle.quaternion.setFromRotationMatrix( lookAtMatrix.lookAt( zeroVector, alignVector, unitY ) );
- handle.quaternion.multiply( tempQuaternion );
- handle.visible = this.dragging;
- }
- if ( this.axis === 'E' ) {
- handle.visible = false;
- }
- } else if ( handle.name === 'START' ) {
- handle.position.copy( this.worldPositionStart );
- handle.visible = this.dragging;
- } else if ( handle.name === 'END' ) {
- handle.position.copy( this.worldPosition );
- handle.visible = this.dragging;
- } else if ( handle.name === 'DELTA' ) {
- handle.position.copy( this.worldPositionStart );
- handle.quaternion.copy( this.worldQuaternionStart );
- tempVector.set( 1e-10, 1e-10, 1e-10 ).add( this.worldPositionStart ).sub( this.worldPosition ).multiplyScalar( - 1 );
- tempVector.applyQuaternion( this.worldQuaternionStart.clone().inverse() );
- handle.scale.copy( tempVector );
- handle.visible = this.dragging;
- } else {
- handle.quaternion.copy( quaternion );
- if ( this.dragging ) {
- handle.position.copy( this.worldPositionStart );
- } else {
- handle.position.copy( this.worldPosition );
- }
- if ( this.axis ) {
- handle.visible = this.axis.search( handle.name ) !== - 1;
- }
- }
- // If updating helper, skip rest of the loop
- continue;
- }
- // Align handles to current local or world rotation
- handle.quaternion.copy( quaternion );
- if ( this.mode === 'translate' || this.mode === 'scale' ) {
- // Hide translate and scale axis facing the camera
- var AXIS_HIDE_TRESHOLD = 0.99;
- var PLANE_HIDE_TRESHOLD = 0.2;
- var AXIS_FLIP_TRESHOLD = 0.0;
- if(options.dontHideWhenFaceCamera){//xzw add
- //正对镜头时不隐藏箭头
- }else{
-
- if ( handle.name === 'X' || handle.name === 'XYZX' ) {
- if ( Math.abs( alignVector.copy( unitX ).applyQuaternion( quaternion ).dot( this.eye ) ) > AXIS_HIDE_TRESHOLD ) {
- handle.scale.set( 1e-10, 1e-10, 1e-10 );
- handle.visible = false;
- }
- }
- if ( handle.name === 'Y' || handle.name === 'XYZY' ) {
- if ( Math.abs( alignVector.copy( unitY ).applyQuaternion( quaternion ).dot( this.eye ) ) > AXIS_HIDE_TRESHOLD ) {
- handle.scale.set( 1e-10, 1e-10, 1e-10 );
- handle.visible = false;
- }
- }
- if ( handle.name === 'Z' || handle.name === 'XYZZ' ) {
- if ( Math.abs( alignVector.copy( unitZ ).applyQuaternion( quaternion ).dot( this.eye ) ) > AXIS_HIDE_TRESHOLD ) {
- handle.scale.set( 1e-10, 1e-10, 1e-10 );
- handle.visible = false;
- }
- }
- if ( handle.name === 'XY' ) {
- if ( Math.abs( alignVector.copy( unitZ ).applyQuaternion( quaternion ).dot( this.eye ) ) < PLANE_HIDE_TRESHOLD ) {
- handle.scale.set( 1e-10, 1e-10, 1e-10 );
- handle.visible = false;
- }
- }
- if ( handle.name === 'YZ' ) {
- if ( Math.abs( alignVector.copy( unitX ).applyQuaternion( quaternion ).dot( this.eye ) ) < PLANE_HIDE_TRESHOLD ) {
- handle.scale.set( 1e-10, 1e-10, 1e-10 );
- handle.visible = false;
- }
- }
- if ( handle.name === 'XZ' ) {
- if ( Math.abs( alignVector.copy( unitY ).applyQuaternion( quaternion ).dot( this.eye ) ) < PLANE_HIDE_TRESHOLD ) {
- handle.scale.set( 1e-10, 1e-10, 1e-10 );
- handle.visible = false;
- }
- }
- }
- // Flip translate and scale axis ocluded behind another axis
- //xzw 改 去掉反向箭头
- if ( handle.name.search( 'X' ) !== - 1 ) {
- if ( alignVector.copy( unitX ).applyQuaternion( quaternion ).dot( this.eye ) < AXIS_FLIP_TRESHOLD ) {
- /* if ( handle.tag === 'fwd' ) {
- handle.visible = false;
- } else {
- handle.scale.x *= - 1;
- }
- } else if ( handle.tag === 'bwd' ) {
- handle.visible = false;*/
- handle.scale.x *= - 1;
- }
-
- }
- if ( handle.name.search( 'Y' ) !== - 1 ) {
- if ( alignVector.copy( unitY ).applyQuaternion( quaternion ).dot( this.eye ) < AXIS_FLIP_TRESHOLD ) {
- /* if ( handle.tag === 'fwd' ) {
- handle.visible = false;
- } else {
- handle.scale.y *= - 1;
- }
-
- } else if ( handle.tag === 'bwd' ) {
- handle.visible = false;
- */
- handle.scale.y *= - 1;
- }
- }
- if ( handle.name.search( 'Z' ) !== - 1 ) {
- if ( alignVector.copy( unitZ ).applyQuaternion( quaternion ).dot( this.eye ) < AXIS_FLIP_TRESHOLD ) {
- /* if ( handle.tag === 'fwd' ) {
- handle.visible = false;
- } else {
- handle.scale.z *= - 1;
- }
- } else if ( handle.tag === 'bwd' ) {
- handle.visible = false; */
- handle.scale.z *= - 1;
- }
- }
- } else if ( this.mode === 'rotate' ) {
- // Align handles to current local or world rotation
- tempQuaternion2.copy( quaternion );
- alignVector.copy( this.eye ).applyQuaternion( tempQuaternion.copy( quaternion ).inverse() );
- if ( handle.name.search( "E" ) !== - 1 ) {
- handle.quaternion.setFromRotationMatrix( lookAtMatrix.lookAt( this.eye, zeroVector, unitY ) );
- }
- if ( handle.name === 'X' ) {
- tempQuaternion.setFromAxisAngle( unitX, Math.atan2( - alignVector.y, alignVector.z ) );
- tempQuaternion.multiplyQuaternions( tempQuaternion2, tempQuaternion );
- handle.quaternion.copy( tempQuaternion );
- }
- if ( handle.name === 'Y' ) {
- tempQuaternion.setFromAxisAngle( unitY, Math.atan2( alignVector.x, alignVector.z ) );
- tempQuaternion.multiplyQuaternions( tempQuaternion2, tempQuaternion );
- handle.quaternion.copy( tempQuaternion );
- }
- if ( handle.name === 'Z' ) {
- tempQuaternion.setFromAxisAngle( unitZ, Math.atan2( alignVector.y, alignVector.x ) );
- tempQuaternion.multiplyQuaternions( tempQuaternion2, tempQuaternion );
- handle.quaternion.copy( tempQuaternion );
- }
- }
- // Hide disabled axes
- handle.visible = handle.visible && ( handle.name.indexOf( "X" ) === - 1 || this.showX );
- handle.visible = handle.visible && ( handle.name.indexOf( "Y" ) === - 1 || this.showY );
- handle.visible = handle.visible && ( handle.name.indexOf( "Z" ) === - 1 || this.showZ );
- handle.visible = handle.visible && ( handle.name.indexOf( "E" ) === - 1 || ( this.showX && this.showY && this.showZ ) );
- // highlight selected axis
- handle.material._opacity = handle.material._opacity || handle.material.opacity;
- handle.material._color = handle.material._color || handle.material.color.clone();
- handle.material.color.copy( handle.material._color );
- handle.material.opacity = handle.material._opacity;
- if ( ! this.enabled ) {
- handle.material.opacity *= 0.5;
- handle.material.color.lerp( new Color( 1, 1, 1 ), 0.5 );
- } else if ( this.axis ) {
- if ( handle.name === this.axis ) {
- handle.material.opacity = 1.0;
- handle.material.color.lerp( new Color( 1, 1, 1 ), 0.5 );
- } else if ( this.axis.split( '' ).some( function ( a ) {
- return handle.name === a;
- } ) ) {
- handle.material.opacity = 1.0;
- handle.material.color.lerp( new Color( 1, 1, 1 ), 0.5 );
- } else {
- handle.material.opacity *= 0.25;
- handle.material.color.lerp( new Color( 1, 1, 1 ), 0.5 );
- }
- }
- }
- Object3D.prototype.updateMatrixWorld.call( this );
- };
- };
- var TransformControlsPlane = function (options) {
- 'use strict';
- Mesh.call( this,
- new PlaneBufferGeometry( 100000, 100000, 2, 2 ),
- new MeshBasicMaterial( { color: "#ff0000", visible: false, wireframe: false, side: DoubleSide, transparent: true, opacity: 0.2 } )
- );
- this.type = 'TransformControlsPlane';
- var unitX = new Vector3( 1, 0, 0 );
- var unitY = new Vector3( 0, 1, 0 );
- var unitZ = new Vector3( 0, 0, 1 );
- var tempVector = new Vector3();
- var dirVector = new Vector3();
- var alignVector = new Vector3();
- var tempMatrix = new Matrix4();
- var identityQuaternion = new Quaternion();
- this.updateMatrixWorld = function () {
- var space = this.space;
- this.position.copy( this.worldPosition );
- if ( this.mode === 'scale' ) space = 'local'; // scale always oriented to local rotation
- unitX.set( 1, 0, 0 ).applyQuaternion( space === "local" ? this.worldQuaternion : identityQuaternion );
- unitY.set( 0, 1, 0 ).applyQuaternion( space === "local" ? this.worldQuaternion : identityQuaternion );
- unitZ.set( 0, 0, 1 ).applyQuaternion( space === "local" ? this.worldQuaternion : identityQuaternion );
- // Align the plane for current transform mode, axis and space.
- alignVector.copy( unitY );
- switch ( this.mode ) {
- case 'translate':
- case 'scale':
- switch ( this.axis ) {
- case 'X':
- alignVector.copy( this.eye ).cross( unitX );
- dirVector.copy( unitX ).cross( alignVector );
- break;
- case 'Y':
- alignVector.copy( this.eye ).cross( unitY );
- dirVector.copy( unitY ).cross( alignVector );
- break;
- case 'Z':
- alignVector.copy( this.eye ).cross( unitZ );
- dirVector.copy( unitZ ).cross( alignVector );
- break;
- case 'XY':
- dirVector.copy( unitZ );
- break;
- case 'YZ':
- dirVector.copy( unitX );
- break;
- case 'XZ':
- alignVector.copy( unitZ );
- dirVector.copy( unitY );
- break;
- case 'XYZ':
- case 'E':
- default: //xzw add for scale xyzz
- dirVector.set( 0, 0, 0 );
- break;
-
- }
- break;
- case 'rotate':
- default:
- // special case for rotate
- dirVector.set( 0, 0, 0 );
- }
- if ( dirVector.length() === 0 ) {
- // If in rotate mode, make the plane parallel to camera
- this.quaternion.copy( this.cameraQuaternion );
- } else {
- tempMatrix.lookAt( tempVector.set( 0, 0, 0 ), dirVector, alignVector );
- this.quaternion.setFromRotationMatrix( tempMatrix );
- }
- Object3D.prototype.updateMatrixWorld.call( this );
-
-
- };
- };
- //export { TransformControls, TransformControlsGizmo, TransformControlsPlane };
- TransformControls.init = function(THREE){
-
- BoxBufferGeometry = THREE.BoxBufferGeometry,
- BufferGeometry = THREE.BufferGeometry,
- Color = THREE.Color,
- CylinderBufferGeometry = THREE.CylinderBufferGeometry,
- DoubleSide = THREE.DoubleSide,
- Euler = THREE.Euler,
- Float32BufferAttribute = THREE.Float32BufferAttribute,
- Line = THREE.Line,
- LineBasicMaterial = THREE.LineBasicMaterial,
- Matrix4 = THREE.Matrix4,
- Mesh = THREE.Mesh,
- MeshBasicMaterial = THREE.MeshBasicMaterial,
- Object3D = THREE.Object3D,
- //OctahedronBufferGeometry = THREE.OctahedronBufferGeometry,
- PlaneBufferGeometry = THREE.PlaneBufferGeometry,
- Quaternion = THREE.Quaternion,
- Raycaster = THREE.Raycaster,
- SphereBufferGeometry = THREE.SphereBufferGeometry,
- TorusBufferGeometry = THREE.TorusBufferGeometry,
- Vector3 = THREE.Vector3;
- Vector2 = THREE.Vector2;
- TransformControls.prototype = Object.assign( Object.create( Object3D.prototype ), {
- constructor: TransformControls,
- isTransformControls: true
- } );
- TransformControlsGizmo.prototype = Object.assign( Object.create( Object3D.prototype ), {
- constructor: TransformControlsGizmo,
- isTransformControlsGizmo: true
- } );
- TransformControlsPlane.prototype = Object.assign( Object.create( Mesh.prototype ), {
- constructor: TransformControlsPlane,
- isTransformControlsPlane: true
- } );
- //----------
-
- function PolyhedronBufferGeometry( vertices, indices, radius, detail ) {
- BufferGeometry.call( this );
- this.type = 'PolyhedronBufferGeometry';
- this.parameters = {
- vertices: vertices,
- indices: indices,
- radius: radius,
- detail: detail
- };
- radius = radius || 1;
- detail = detail || 0;
- // default buffer data
- var vertexBuffer = [];
- var uvBuffer = [];
- // the subdivision creates the vertex buffer data
- subdivide( detail );
- // all vertices should lie on a conceptual sphere with a given radius
- appplyRadius( radius );
- // finally, create the uv data
- generateUVs();
- // build non-indexed geometry
-
- this.addAttribute("position", new THREE.BufferAttribute(new Float32Array(vertexBuffer), 3 ))
- this.addAttribute( 'normal', new THREE.BufferAttribute( new Float32Array(vertexBuffer), 3 ) );
- this.addAttribute( 'uv', new THREE.BufferAttribute( new Float32Array(uvBuffer), 2 ) );
-
-
-
- if ( detail === 0 ) {
- this.computeVertexNormals(); // flat normals
- } else {
- this.normalizeNormals(); // smooth normals
- }
- // helper functions
- function subdivide( detail ) {
- var a = new Vector3();
- var b = new Vector3();
- var c = new Vector3();
- // iterate over all faces and apply a subdivison with the given detail value
- for ( var i = 0; i < indices.length; i += 3 ) {
- // get the vertices of the face
- getVertexByIndex( indices[ i + 0 ], a );
- getVertexByIndex( indices[ i + 1 ], b );
- getVertexByIndex( indices[ i + 2 ], c );
- // perform subdivision
- subdivideFace( a, b, c, detail );
- }
- }
- function subdivideFace( a, b, c, detail ) {
- var cols = Math.pow( 2, detail );
- // we use this multidimensional array as a data structure for creating the subdivision
- var v = [];
- var i, j;
- // construct all of the vertices for this subdivision
- for ( i = 0; i <= cols; i ++ ) {
- v[ i ] = [];
- var aj = a.clone().lerp( c, i / cols );
- var bj = b.clone().lerp( c, i / cols );
- var rows = cols - i;
- for ( j = 0; j <= rows; j ++ ) {
- if ( j === 0 && i === cols ) {
- v[ i ][ j ] = aj;
- } else {
- v[ i ][ j ] = aj.clone().lerp( bj, j / rows );
- }
- }
- }
- // construct all of the faces
- for ( i = 0; i < cols; i ++ ) {
- for ( j = 0; j < 2 * ( cols - i ) - 1; j ++ ) {
- var k = Math.floor( j / 2 );
- if ( j % 2 === 0 ) {
- pushVertex( v[ i ][ k + 1 ] );
- pushVertex( v[ i + 1 ][ k ] );
- pushVertex( v[ i ][ k ] );
- } else {
- pushVertex( v[ i ][ k + 1 ] );
- pushVertex( v[ i + 1 ][ k + 1 ] );
- pushVertex( v[ i + 1 ][ k ] );
- }
- }
- }
- }
- function appplyRadius( radius ) {
- var vertex = new Vector3();
- // iterate over the entire buffer and apply the radius to each vertex
- for ( var i = 0; i < vertexBuffer.length; i += 3 ) {
- vertex.x = vertexBuffer[ i + 0 ];
- vertex.y = vertexBuffer[ i + 1 ];
- vertex.z = vertexBuffer[ i + 2 ];
- vertex.normalize().multiplyScalar( radius );
- vertexBuffer[ i + 0 ] = vertex.x;
- vertexBuffer[ i + 1 ] = vertex.y;
- vertexBuffer[ i + 2 ] = vertex.z;
- }
- }
- function generateUVs() {
- var vertex = new Vector3();
- for ( var i = 0; i < vertexBuffer.length; i += 3 ) {
- vertex.x = vertexBuffer[ i + 0 ];
- vertex.y = vertexBuffer[ i + 1 ];
- vertex.z = vertexBuffer[ i + 2 ];
- var u = azimuth( vertex ) / 2 / Math.PI + 0.5;
- var v = inclination( vertex ) / Math.PI + 0.5;
- uvBuffer.push( u, 1 - v );
- }
- correctUVs();
- correctSeam();
- }
- function correctSeam() {
- // handle case when face straddles the seam, see #3269
- for ( var i = 0; i < uvBuffer.length; i += 6 ) {
- // uv data of a single face
- var x0 = uvBuffer[ i + 0 ];
- var x1 = uvBuffer[ i + 2 ];
- var x2 = uvBuffer[ i + 4 ];
- var max = Math.max( x0, x1, x2 );
- var min = Math.min( x0, x1, x2 );
- // 0.9 is somewhat arbitrary
- if ( max > 0.9 && min < 0.1 ) {
- if ( x0 < 0.2 ) uvBuffer[ i + 0 ] += 1;
- if ( x1 < 0.2 ) uvBuffer[ i + 2 ] += 1;
- if ( x2 < 0.2 ) uvBuffer[ i + 4 ] += 1;
- }
- }
- }
- function pushVertex( vertex ) {
- vertexBuffer.push( vertex.x, vertex.y, vertex.z );
- }
- function getVertexByIndex( index, vertex ) {
- var stride = index * 3;
- vertex.x = vertices[ stride + 0 ];
- vertex.y = vertices[ stride + 1 ];
- vertex.z = vertices[ stride + 2 ];
- }
- function correctUVs() {
- var a = new Vector3();
- var b = new Vector3();
- var c = new Vector3();
- var centroid = new Vector3();
- var uvA = new Vector2();
- var uvB = new Vector2();
- var uvC = new Vector2();
- for ( var i = 0, j = 0; i < vertexBuffer.length; i += 9, j += 6 ) {
- a.set( vertexBuffer[ i + 0 ], vertexBuffer[ i + 1 ], vertexBuffer[ i + 2 ] );
- b.set( vertexBuffer[ i + 3 ], vertexBuffer[ i + 4 ], vertexBuffer[ i + 5 ] );
- c.set( vertexBuffer[ i + 6 ], vertexBuffer[ i + 7 ], vertexBuffer[ i + 8 ] );
- uvA.set( uvBuffer[ j + 0 ], uvBuffer[ j + 1 ] );
- uvB.set( uvBuffer[ j + 2 ], uvBuffer[ j + 3 ] );
- uvC.set( uvBuffer[ j + 4 ], uvBuffer[ j + 5 ] );
- centroid.copy( a ).add( b ).add( c ).divideScalar( 3 );
- var azi = azimuth( centroid );
- correctUV( uvA, j + 0, a, azi );
- correctUV( uvB, j + 2, b, azi );
- correctUV( uvC, j + 4, c, azi );
- }
- }
- function correctUV( uv, stride, vector, azimuth ) {
- if ( ( azimuth < 0 ) && ( uv.x === 1 ) ) {
- uvBuffer[ stride ] = uv.x - 1;
- }
- if ( ( vector.x === 0 ) && ( vector.z === 0 ) ) {
- uvBuffer[ stride ] = azimuth / 2 / Math.PI + 0.5;
- }
- }
- // Angle around the Y axis, counter-clockwise when looking from above.
- function azimuth( vector ) {
- return Math.atan2( vector.z, - vector.x );
- }
- // Angle above the XZ plane.
- function inclination( vector ) {
- return Math.atan2( - vector.y, Math.sqrt( ( vector.x * vector.x ) + ( vector.z * vector.z ) ) );
- }
- }
- PolyhedronBufferGeometry.prototype = Object.create( BufferGeometry.prototype );
- PolyhedronBufferGeometry.prototype.constructor = PolyhedronBufferGeometry;
-
-
-
-
-
- OctahedronBufferGeometry = function( radius, detail ) {
- var vertices = [
- 1, 0, 0, - 1, 0, 0, 0, 1, 0,
- 0, - 1, 0, 0, 0, 1, 0, 0, - 1
- ];
- var indices = [
- 0, 2, 4, 0, 4, 3, 0, 3, 5,
- 0, 5, 2, 1, 2, 5, 1, 5, 3,
- 1, 3, 4, 1, 4, 2
- ];
- PolyhedronBufferGeometry.call( this, vertices, indices, radius, detail );
- this.type = 'OctahedronBufferGeometry';
- this.parameters = {
- radius: radius,
- detail: detail
- };
- }
- OctahedronBufferGeometry.prototype = Object.create( PolyhedronBufferGeometry.prototype );
- OctahedronBufferGeometry.prototype.constructor = OctahedronBufferGeometry;
-
-
-
-
- }
- window.TransformControls = TransformControls;
- }()
|