| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038 |
-
- import * as THREE from "../../../../libs/three.js/build/three.module.js";
- import math from "../../utils/math.js";
-
-
- let lastUseCamera
- var TransformControls = function ( camera, domElement, options ) {
- if ( domElement === undefined ) {
- console.warn( 'THREE.TransformControls: The second parameter "domElement" is now mandatory.' );
- domElement = document;
- }
- THREE.Object3D.call( this );
-
- Potree.Utils.updateVisible(this, 'attach', false)
- this.domElement = domElement;
-
- var _gizmo = new TransformControlsGizmo(options);
- this.add( _gizmo );
- this._gizmo = _gizmo
- var _plane = new TransformControlsPlane(options);
- this.add( _plane );
- /* this.linesAssistance = new TransformControlsLines(options); //水平 垂直 辅助
- this.add( this.linesAssistance ); */
- 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 THREE.Raycaster();
- var _tempVector = new THREE.Vector3();
- var _tempVector2 = new THREE.Vector3();
- var _tempQuaternion = new THREE.Quaternion();
- var _unit = {
- X: new THREE.Vector3( 1, 0, 0 ),
- Y: new THREE.Vector3( 0, 1, 0 ),
- Z: new THREE.Vector3( 0, 0, 1 )
- };
- var pointStart = new THREE.Vector3();
- var pointEnd = new THREE.Vector3();
- var offset = new THREE.Vector3();
- var rotationAxis = new THREE.Vector3();
- var startNorm = new THREE.Vector3();
- var endNorm = new THREE.Vector3();
- var rotationAngle = 0;
- var cameraPosition = new THREE.Vector3();
- var cameraQuaternion = new THREE.Quaternion();
- var cameraScale = new THREE.Vector3();
- var parentPosition = new THREE.Vector3();
- var parentQuaternion = new THREE.Quaternion();
- var parentQuaternionInv = new THREE.Quaternion();
- var parentScale = new THREE.Vector3();
- var worldPositionStart = new THREE.Vector3();
- var worldQuaternionStart = new THREE.Quaternion();
- var worldScaleStart = new THREE.Vector3();
- var worldPosition = new THREE.Vector3();
- var worldQuaternion = new THREE.Quaternion();
- var worldQuaternionInv = new THREE.Quaternion();
- var worldScale = new THREE.Vector3();
- var eye = new THREE.Vector3(); //整体共用
- var positionStart = new THREE.Vector3();
- var quaternionStart = new THREE.Quaternion();
- var scaleStart = new THREE.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 );
- let drag = (e)=>{
- if(this.dragging && e.button == 0){
- this.pointerMove()
- return {stopContinue:true}
- }
- }
- this.addEventListener('dragging',drag,{importance:10})
- viewer.addEventListener('global_drag',drag,{importance:10})
-
- }
-
-
-
- this.setRotateMethod = function(number){//add 注意为2时 旋转期间不能改变位置 space可能不能为local ._gizmo.hideAxis = { rotate:[这里必须包含'e' ] }
- this.rotateMethod = number
-
- }
- 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, clickPos ) {
- this.object = object;
- Potree.Utils.updateVisible(this, 'attach', true)
- //Config.keyCon = false;//add
- //this.linesAssistance.setVisible(true)
- this.clickPos = clickPos?.isVector3 ? clickPos : null
- viewer.dispatchEvent('content_changed')
- return this;
- };
- // Detatch from object
- this.detach = function () {
- this.object = undefined;
- this.axis = null;
- //Config.keyCon = true;//add
- Potree.Utils.updateVisible(this, 'attach', false)
- //this.linesAssistance.setVisible(false)
- viewer.dispatchEvent('content_changed')
- return this;
- };
- //this.space = 'local'
-
- /* this.hideAxis = function ( mode, axis=[] ) {//xzw add 设置不可见的axis
- var handles = [];
- handles = handles.concat( this._gizmo.picker[ mode ].children );
- handles = handles.concat( this._gizmo.gizmo[ mode ].children );
- handles = handles.concat( this._gizmo.helper[ mode ].children );
- handles.forEach(e=>e.visible = false)
- axis.forEach(name=>{
- handles.filter(handle =>!handle.name.includes(name))
- })
- handles.forEach(e=>e.visible = true)
- }; */
- // 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.updateEye = function(camera){
- if(camera.type == "OrthographicCamera"){//xzw add
- eye.set(0,0,-1).applyQuaternion(camera.quaternion) // this.view.direction
- }else{
- eye.copy( cameraPosition ).sub( worldPosition ).normalize();
- }
-
- }
-
- this.updateMatrixWorld = function () {//TransformControls
- if(!this.visible)return//add
- let camera = arguments[1]?.isCamera ? arguments[1] : (Potree.currentRender?.camera || this.camera)
- lastUseCamera = camera //add 使用父级使用的camera
- if ( this.object !== undefined ) {
-
- this.object.updateMatrixWorld();
- this.object.parent.matrixWorld.decompose( parentPosition, parentQuaternion, parentScale );
- this.object.matrixWorld.decompose( worldPosition, worldQuaternion, worldScale );
-
-
- if(Potree.settings.mergeTransCtlOnClick && this.mode == 'translate' && this.clickPos ){//允许位移控件出现在点击的位置
- let pos = this.clickPos.clone().applyMatrix4(this.object.matrixWorld)
- worldPosition.copy(pos)
- }else if(this.object.boundingBox){
- let boundingBox = this.object.boundingBox.clone().applyMatrix4(this.object.matrixWorld)
- boundingBox.getCenter(worldPosition) //bound中心
- if(this.pivotOnBottom){
- worldPosition.setZ(boundingBox.min.z) //中心点居于模型bound底部,因固定离地高度,旋转时旋转中心在地面上就不会变位置
- }
- }
-
- parentQuaternionInv.copy( parentQuaternion ).invert();
- worldQuaternionInv.copy( worldQuaternion ).invert();
- }
- camera.updateMatrixWorld();
- camera.matrixWorld.decompose( cameraPosition, cameraQuaternion, cameraScale );
- this.updateEye(camera)
-
-
-
- THREE.Object3D.prototype.updateMatrixWorld.call( this );
- };
- this.pointerHover = function () {
- let pointer = viewer.inputHandler.pointer
- if ( this.object === undefined)return
- let camera = viewer.inputHandler.hoverViewport?.camera
- //if(this.dragging === true /* || ( pointer.button !== undefined && pointer.button !== 0 ) */) return;
-
- if(!this.dragging){
- let oldAxis = this.axis
- //ray.setFromCamera( pointer, this.camera ); //这句会在floorplan模式get不到intersect
- let {origin, direction} = viewer.inputHandler.getMouseDirection()
- ray.set(origin, direction);
-
- Potree.Utils.setCameraLayers(ray, //设置能识别到的layers
- ['sceneObjects','mapObjects',/* 'measure', */ 'transformationTool', 'model'],
- viewer.inputHandler.hoverViewport && viewer.inputHandler.hoverViewport.extraEnableLayers
- )
-
- camera && camera!=lastUseCamera && this.updateMatrixWorld(null, camera) //add 多viewport时重新根据hover的camera更新下
-
- var intersect = ray.intersectObjects( _gizmo.picker[ this.mode ].children.filter(e=>e.visible), true )[ 0 ] || false;
- if ( intersect ) {
-
- this.axis = intersect.object.name;
- } else {
- this.axis = null;
- }
-
- //console.log('hover', !!intersect)
-
-
- if(oldAxis != this.axis){
- this.dispatchEvent({type:'axisHoveredChange',axis:this.axis, mode:this.mode})
- viewer.dispatchEvent('content_changed')
- }
- }else{
- //this.pointerMove()
-
- }
- };
- this.pointerDown = function ( /* pointer */ ) {
- let pointer = viewer.inputHandler.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, camera ); //这句会在floorplan模式get不到intersect
- let {origin, direction} = viewer.inputHandler.getMouseDirection()
- ray.set(origin, direction);
-
- Potree.Utils.setCameraLayers(ray, //设置能识别到的layers
- ['sceneObjects','mapObjects',/* 'measure', */ 'transformationTool', 'model'],
- viewer.inputHandler.hoverViewport && viewer.inputHandler.hoverViewport.extraEnableLayers
- )
-
-
-
- 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 );
- //add: 使坐标轴在boundingBox中心
- this.object.boundingBox && this.object.boundingBox.getCenter(worldPositionStart).applyMatrix4(this.object.matrixWorld);
- 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;
- //console.log('this.dragging = true;')
- mouseDownEvent.mode = this.mode;
- this.dispatchEvent( mouseDownEvent );
- }
- };
- this.pointerMove = function ( /* pointer */ ) {
- //console.log('pointerMove')
- let pointer = viewer.inputHandler.pointer
- var axis = this.axis;
- var mode = this.mode;
- var object = this.object;
- var space = this.space;
- let camera = viewer.inputHandler.hoverViewport?.camera
- 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, camera ); //这句会在floorplan模式get不到intersect
- let {origin, direction} = viewer.inputHandler.getMouseDirection()
- ray.set(origin, direction);
- Potree.Utils.setCameraLayers(ray, //设置能识别到的layers
- ['sceneObjects','mapObjects',/* 'measure', */'transformationTool', 'model'],
- viewer.inputHandler.hoverViewport && viewer.inputHandler.hoverViewport.extraEnableLayers
- )
-
- camera && camera!=lastUseCamera && this.updateMatrixWorld(null, camera) //add 多viewport时重新根据hover的camera更新下
-
- 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' ) {
- //xzw 加,否则会反向---------------
- object.scale.x < 0 && (offset.x *= -1)
- object.scale.y < 0 && (offset.y *= -1)
- object.scale.z < 0 && (offset.z *= -1)
- //---------------------------------
- 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 ).invert() );
- 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:
-
- object.dispatchEvent({
- type: "position_changed"
- });
- } 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 if ( axis.search( 'XY' ) !== - 1 ) { //add 等比例for plane
- var d = pointEnd.length() / pointStart.length();
- if ( pointEnd.dot( pointStart ) < 0 ) d *= - 1;
-
-
- _tempVector2.set( d, d, 1 );
-
-
- }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:
-
-
-
- object.dispatchEvent({
- type: "scale_changed"
- });
-
- } else if ( mode === 'rotate' ) {
- if(this.rotateMethod == 2){//新版参照transfromTool的写法,更跟手,但是有bug,在同时移动位置时或e轴上有问题
- 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' ) {//像滚球一样拨动,鼠标滑动方向为拨动方向,在plane面上滚动
- offset.copy( pointEnd ).sub( pointStart );
- rotationAxis.copy( offset ).cross( eye ).normalize();
- }else{
- rotationAxis.copy( _unit[ axis ] );
- }
- let center = new THREE.Vector3//坐标轴位置
-
-
- /* if(this.object.boundingBox){
- center.copy(worldPosition) //center设置为boundingbox的中心。但center一直更改会导致虽然在按某个时针旋转,但v2相对v1可能会时不时逆向,导致闪烁。所以固定住center,虽然这样计算的角度和绕模型中心的感觉偏颇
- }else{ */
- center.copy(worldPositionStart)
- //}
-
-
- let rotationAxis_ = space === 'local' ? rotationAxis.clone().applyQuaternion(worldQuaternion) : rotationAxis
- let plane = new THREE.Plane().setFromNormalAndCoplanarPoint(rotationAxis_, center);//旋转过程中rotationAxis不会变化,但center可能会
-
-
- let {origin, direction} = viewer.inputHandler.getMouseDirection()
- ray.set(origin, direction);
- let I = ray.ray.intersectPlane(plane, new THREE.Vector3());
-
- if (I) {
-
- let v2 = I.clone().sub(center)//.normalize();
-
- if(!this.rotateStart){
- this.rotateStart = {
- v1: v2
- }
- return
-
- }
- let v1 = this.rotateStart.v1
-
- rotationAngle = math.getAngle( v1, v2, rotationAxis_)
- //console.log('rot', rotationAngle, /* center.toArray(), */ v1, v2)
-
- if (Number.isNaN(rotationAngle)) {
- return;
- }
-
- this.rotateStart.v1 = v2
- }else{
- rotationAngle = 0
- //console.log('!I', rotationAngle)
- }
- }
-
- }else{
- //pointStart 是起始intersect - object中心的向量
- //pointEnd 是当前intersect - object中心的向量
- 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' ) {//像滚球一样拨动,鼠标滑动方向为拨动方向,在plane面上滚动
- 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.scale[axis.toLowerCase()] < 0 && (rotationAngle *= -1) //xzw 加,否则会反向
- 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();
- }
-
-
- if ( this.rotateMethod == 2 && axis != 'E' ) {
- quaternionStart.copy(object.quaternion)
- }
-
- //add:
-
- object.dispatchEvent({
- type: "rotation_changed"
- });
-
-
- }
- this.dispatchEvent( changeEvent );
- this.dispatchEvent( objectChangeEvent );
- viewer.dispatchEvent('content_changed')
- };
- 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 );
- /* 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
- } */
- this.rotateStart = null//add
-
-
- }
- 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( );
- }
- function onPointerDown( event ) {
- if ( ! scope.enabled ) return;
- //document.addEventListener( "mousemove", onPointerMove, false );
- /* scope.pointerHover( getPointer( event ) );
- scope.pointerDown( getPointer( event ) ); */
- scope.pointerHover( );
- scope.pointerDown();
- }
- this.onPointerDown = onPointerDown;
- function onPointerMove( event ) {
-
- if ( ! scope.enabled || !this.dragging) return; //xzw change
- //scope.pointerMove( getPointer( event ) );
- scope.pointerMove( );
- }
- this.onPointerMove = onPointerMove;
-
-
- function onPointerUp( event ) {
-
- if ( ! scope.enabled ) return;
- //document.removeEventListener( "mousemove", onPointerMove, false );
- //scope.pointerUp( getPointer( event ) );
- scope.pointerUp( );
- }
- 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.setCamera = function ( camera ){//add
- scope.camera = camera;
- };
-
-
-
- this.update = function () {
- console.warn( 'THREE.TransformControls: update function has no more functionality and therefore has been deprecated.' );
- };
- };
- var TransformControlsGizmo = function (options) {
- 'use strict';
- THREE.Object3D.call( this );
- this.type = 'TransformControlsGizmo';
- // shared materials
- this.hideAxis = {}, this.showAxis = {}
-
-
- var gizmoMaterial = new THREE.MeshBasicMaterial( {
- depthTest: false,
- depthWrite: false,
- transparent: true,
- side: THREE.DoubleSide,
- fog: false
- } );
- var gizmoLineMaterial = new THREE.LineBasicMaterial( {
- depthTest: false,
- depthWrite: false,
- transparent: true,
- fog: false
- } );
- // Make unique material for each axis/color
- var matInvisible = gizmoMaterial.clone();
- matInvisible.opacity = 0.15;
-
- var matHelper = gizmoMaterial.clone();
- matHelper.opacity = 0.1;
- 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( 0x999999 );
- var matLineYellowTransparent = matLineYellow.clone();
- matLineYellowTransparent.opacity = 0.25;
- // reusable geometry
- var arrowGeometry = new THREE.CylinderBufferGeometry( 0, 0.05, 0.2, 12, 1, false );
- var scaleHandleGeometry = new THREE.BoxBufferGeometry( 0.125, 0.125, 0.125 );
- var lineGeometry = new THREE.BufferGeometry( );
- //lineGeometry.setAttribute( 'position', new THREE.Float32BufferAttribute( [ 0, 0, 0, 1, 0, 0 ], 3 ) );
- lineGeometry.setAttribute("position", new THREE.BufferAttribute(new Float32Array([ 0, 0, 0, 1, 0, 0]), 3 ))
-
-
- var CircleGeometry = function ( radius, arc ) {
- var geometry = new THREE.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.setAttribute( 'position', new THREE.Float32BufferAttribute( vertices, 3 ) );
- geometry.setAttribute("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 THREE.BufferGeometry();
- //geometry.setAttribute( 'position', new THREE.Float32BufferAttribute( [ 0, 0, 0, 1, 1, 1 ], 3 ) );
- geometry.setAttribute("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 THREE.Mesh( arrowGeometry, matRed ), [ 1, 0, 0 ], [ 0, 0, - Math.PI / 2 ], null, 'fwd' ],
- //[ new THREE.Mesh( arrowGeometry, matRed ), [ 1, 0, 0 ], [ 0, 0, Math.PI / 2 ], null, 'bwd' ],
- [ new THREE.Line( lineGeometry, matLineRed ) ]
- ],
- Y: [
- [ new THREE.Mesh( arrowGeometry, matGreen ), [ 0, 1, 0 ], null, null, 'fwd' ],
- //[ new THREE.Mesh( arrowGeometry, matGreen ), [ 0, 1, 0 ], [ Math.PI, 0, 0 ], null, 'bwd' ],
- [ new THREE.Line( lineGeometry, matLineGreen ), null, [ 0, 0, Math.PI / 2 ]]
- ],
- Z: [
- [ new THREE.Mesh( arrowGeometry, matBlue ), [ 0, 0, 1 ], [ Math.PI / 2, 0, 0 ], null, 'fwd' ],
- //[ new THREE.Mesh( arrowGeometry, matBlue ), [ 0, 0, 1 ], [ - Math.PI / 2, 0, 0 ], null, 'bwd' ],
- [ new THREE.Line( lineGeometry, matLineBlue ), null, [ 0, - Math.PI / 2, 0 ]]
- ],
- /* XYZ: [
- [ new THREE.Mesh( new THREE.OctahedronBufferGeometry( 0.1, 0 ), matWhiteTransparent.clone() ), [ 0, 0, 0 ], [ 0, 0, 0 ]]
- ], */
- XY: [
- [ new THREE.Mesh( new THREE.PlaneBufferGeometry( 0.295, 0.295 ), matYellowTransparent.clone() ), [ 0.15, 0.15, 0 ]],
- [ new THREE.Line( lineGeometry, matLineYellow ), [ 0.18, 0.3, 0 ], null, [ 0.125, 1, 1 ]],
- [ new THREE.Line( lineGeometry, matLineYellow ), [ 0.3, 0.18, 0 ], [ 0, 0, Math.PI / 2 ], [ 0.125, 1, 1 ]]
- ],
- YZ: [
- [ new THREE.Mesh( new THREE.PlaneBufferGeometry( 0.295, 0.295 ), matCyanTransparent.clone() ), [ 0, 0.15, 0.15 ], [ 0, Math.PI / 2, 0 ]],
- [ new THREE.Line( lineGeometry, matLineCyan ), [ 0, 0.18, 0.3 ], [ 0, 0, Math.PI / 2 ], [ 0.125, 1, 1 ]],
- [ new THREE.Line( lineGeometry, matLineCyan ), [ 0, 0.3, 0.18 ], [ 0, - Math.PI / 2, 0 ], [ 0.125, 1, 1 ]]
- ],
- XZ: [
- [ new THREE.Mesh( new THREE.PlaneBufferGeometry( 0.295, 0.295 ), matMagentaTransparent.clone() ), [ 0.15, 0, 0.15 ], [ - Math.PI / 2, 0, 0 ]],
- [ new THREE.Line( lineGeometry, matLineMagenta ), [ 0.18, 0, 0.3 ], null, [ 0.125, 1, 1 ]],
- [ new THREE.Line( lineGeometry, matLineMagenta ), [ 0.3, 0, 0.18 ], [ 0, - Math.PI / 2, 0 ], [ 0.125, 1, 1 ]]
- ]
- };
- var pickerTranslate = {
- X: [
- [ new THREE.Mesh( new THREE.CylinderBufferGeometry( 0.2, 0, 1, 4, 1, false ), matInvisible ), [ 0.6, 0, 0 ], [ 0, 0, - Math.PI / 2 ]]
- ],
- Y: [
- [ new THREE.Mesh( new THREE.CylinderBufferGeometry( 0.2, 0, 1, 4, 1, false ), matInvisible ), [ 0, 0.6, 0 ]]
- ],
- Z: [
- [ new THREE.Mesh( new THREE.CylinderBufferGeometry( 0.2, 0, 1, 4, 1, false ), matInvisible ), [ 0, 0, 0.6 ], [ Math.PI / 2, 0, 0 ]]
- ],
- /* XYZ: [
- [ new THREE.Mesh( new THREE.OctahedronBufferGeometry( 0.2, 0 ), matInvisible ) ]
- ], */
- XY: [
- [ new THREE.Mesh( new THREE.PlaneBufferGeometry( 0.4, 0.4 ), matInvisible ), [ 0.2, 0.2, 0 ]]
- ],
- YZ: [
- [ new THREE.Mesh( new THREE.PlaneBufferGeometry( 0.4, 0.4 ), matInvisible ), [ 0, 0.2, 0.2 ], [ 0, Math.PI / 2, 0 ]]
- ],
- XZ: [
- [ new THREE.Mesh( new THREE.PlaneBufferGeometry( 0.4, 0.4 ), matInvisible ), [ 0.2, 0, 0.2 ], [ - Math.PI / 2, 0, 0 ]]
- ]
- };
- var helperTranslate = {
- START: [
- [ new THREE.Mesh( new THREE.OctahedronBufferGeometry( 0.01, 2 ), matHelper ), null, null, null, 'helper' ]
- ],
- END: [
- [ new THREE.Mesh( new THREE.OctahedronBufferGeometry( 0.01, 2 ), matHelper ), null, null, null, 'helper' ]
- ],
- DELTA: [
- [ new THREE.Line( TranslateHelperGeometry(), matHelper ), null, null, null, 'helper' ]
- ],
- X: [
- [ new THREE.Line( lineGeometry, matHelper.clone() ), [ - 1e3, 0, 0 ], null, [ 1e6, 1, 1 ], 'helper' ]
- ],
- Y: [
- [ new THREE.Line( lineGeometry, matHelper.clone() ), [ 0, - 1e3, 0 ], [ 0, 0, Math.PI / 2 ], [ 1e6, 1, 1 ], 'helper' ]
- ],
- Z: [
- [ new THREE.Line( lineGeometry, matHelper.clone() ), [ 0, 0, - 1e3 ], [ 0, - Math.PI / 2, 0 ], [ 1e6, 1, 1 ], 'helper' ]
- ]
- };
- let arc = options.rotFullCircle ? 1 : 0.5//add
- var gizmoRotate = {
-
- X: [
- [ new THREE.Line( CircleGeometry( 1, arc ), matLineRed ) ],
- [ new THREE.Mesh( new THREE.OctahedronBufferGeometry( 0.04, 0 ), matRed ), [ 0, 0, 0.99 ], null, [ 1, 3, 1 ]],
- ],
- Y: [
- [ new THREE.Line( CircleGeometry( 1, arc ), matLineGreen ), null, [ 0, 0, - Math.PI / 2 ]],
- [ new THREE.Mesh( new THREE.OctahedronBufferGeometry( 0.04, 0 ), matGreen ), [ 0, 0, 0.99 ], null, [ 3, 1, 1 ]],
- ],
- Z: [
- [ new THREE.Line( CircleGeometry( 1, arc ), matLineBlue ), null, [ 0, Math.PI / 2, 0 ]],
- [ new THREE.Mesh( new THREE.OctahedronBufferGeometry( 0.04, 0 ), matBlue ), [ 0.99, 0, 0 ], null, [ 1, 3, 1 ]],
- ],
- E: [
- [ new THREE.Line( CircleGeometry( 1.25, 1 ), matLineYellowTransparent ), null, [ 0, Math.PI / 2, 0 ]],
- [ new THREE.Mesh( new THREE.CylinderBufferGeometry( 0.03, 0, 0.15, 4, 1, false ), matLineYellowTransparent ), [ 1.17, 0, 0 ], [ 0, 0, - Math.PI / 2 ], [ 1, 1, 0.001 ]],
- [ new THREE.Mesh( new THREE.CylinderBufferGeometry( 0.03, 0, 0.15, 4, 1, false ), matLineYellowTransparent ), [ - 1.17, 0, 0 ], [ 0, 0, Math.PI / 2 ], [ 1, 1, 0.001 ]],
- [ new THREE.Mesh( new THREE.CylinderBufferGeometry( 0.03, 0, 0.15, 4, 1, false ), matLineYellowTransparent ), [ 0, - 1.17, 0 ], [ Math.PI, 0, 0 ], [ 1, 1, 0.001 ]],
- [ new THREE.Mesh( new THREE.CylinderBufferGeometry( 0.03, 0, 0.15, 4, 1, false ), matLineYellowTransparent ), [ 0, 1.17, 0 ], [ 0, 0, 0 ], [ 1, 1, 0.001 ]],
- ],
- XYZE: [
- [ new THREE.Line( CircleGeometry( 1, 1 ), matLineGray ), null, [ 0, Math.PI / 2, 0 ]]
- ]
- };
-
- var helperRotate = {
- AXIS: [
- [ new THREE.Line( lineGeometry, matHelper.clone() ), [ - 1e3, 0, 0 ], null, [ 1e6, 1, 1 ], 'helper' ]
- ]
- };
- var pickerRotate = {
- X: [ //xzw 由原先全弧度改为一半弧度(Math.PI),否则在背面也会hover到
- [ new THREE.Mesh( new THREE.TorusBufferGeometry( 1, 0.06, 4, 24, options.rotFullCircle ? Math.PI*2 : Math.PI ), matInvisible ), [ 0, 0, 0 ], [ 0, - Math.PI / 2, - Math.PI / 2 ]],
- ],
- Y: [
- [ new THREE.Mesh( new THREE.TorusBufferGeometry( 1, 0.06, 4, 24, options.rotFullCircle ? Math.PI*2 : Math.PI ), matInvisible ), [ 0, 0, 0 ], [ Math.PI / 2, 0, 0 ]],
- ],
- Z: [
- [ new THREE.Mesh( new THREE.TorusBufferGeometry( 1, 0.06, 4, 24, options.rotFullCircle ? Math.PI*2 : Math.PI ), matInvisible ), [ 0, 0, 0 ], [ 0, 0, - Math.PI / 2 ]],
- ],
- E: [
- [ new THREE.Mesh( new THREE.TorusBufferGeometry( 1.25, 0.06, 2, 24 ), matInvisible ) ]
- ],
- XYZE: [
- [ new THREE.Mesh( new THREE.SphereBufferGeometry( 0.7, 10, 8 ), matInvisible ) ]
- ]
- };
- var gizmoScale = {
- X: [
- [ new THREE.Mesh( scaleHandleGeometry, matRed ), [ 0.8, 0, 0 ], [ 0, 0, - Math.PI / 2 ]],
- [ new THREE.Line( lineGeometry, matLineRed ), null, null, [ 0.8, 1, 1 ]]
- ],
- Y: [
- [ new THREE.Mesh( scaleHandleGeometry, matGreen ), [ 0, 0.8, 0 ]],
- [ new THREE.Line( lineGeometry, matLineGreen ), null, [ 0, 0, Math.PI / 2 ], [ 0.8, 1, 1 ]]
- ],
- Z: [
- [ new THREE.Mesh( scaleHandleGeometry, matBlue ), [ 0, 0, 0.8 ], [ Math.PI / 2, 0, 0 ]],
- [ new THREE.Line( lineGeometry, matLineBlue ), null, [ 0, - Math.PI / 2, 0 ], [ 0.8, 1, 1 ]]
- ],
- XY: [
- [ new THREE.Mesh( scaleHandleGeometry, matYellowTransparent ), [ 0.85, 0.85, 0 ], null, [ 2, 2, 0.2 ]],
- [ new THREE.Line( lineGeometry, matLineYellow ), [ 0.855, 0.98, 0 ], null, [ 0.125, 1, 1 ]],
- [ new THREE.Line( lineGeometry, matLineYellow ), [ 0.98, 0.855, 0 ], [ 0, 0, Math.PI / 2 ], [ 0.125, 1, 1 ]]
- ],
- /* YZ: [
- [ new THREE.Mesh( scaleHandleGeometry, matCyanTransparent ), [ 0, 0.85, 0.85 ], null, [ 0.2, 2, 2 ]],
- [ new THREE.Line( lineGeometry, matLineCyan ), [ 0, 0.855, 0.98 ], [ 0, 0, Math.PI / 2 ], [ 0.125, 1, 1 ]],
- [ new THREE.Line( lineGeometry, matLineCyan ), [ 0, 0.98, 0.855 ], [ 0, - Math.PI / 2, 0 ], [ 0.125, 1, 1 ]]
- ],
- XZ: [
- [ new THREE.Mesh( scaleHandleGeometry, matMagentaTransparent ), [ 0.85, 0, 0.85 ], null, [ 2, 0.2, 2 ]],
- [ new THREE.Line( lineGeometry, matLineMagenta ), [ 0.855, 0, 0.98 ], null, [ 0.125, 1, 1 ]],
- [ new THREE.Line( lineGeometry, matLineMagenta ), [ 0.98, 0, 0.855 ], [ 0, - Math.PI / 2, 0 ], [ 0.125, 1, 1 ]]
- ],
- XYZX: [
- [ new THREE.Mesh( new THREE.BoxBufferGeometry( 0.125, 0.125, 0.125 ), matWhiteTransparent.clone() ), [ 1.1, 0, 0 ]],
- ],*/
- XYZY: [
- [ new THREE.Mesh( new THREE.BoxBufferGeometry( 0.125, 0.125, 0.125 ), matWhiteTransparent.clone() ), [ 0, 1.1, 0 ]],
- ]/* ,
- XYZZ: [
- [ new THREE.Mesh( new THREE.BoxBufferGeometry( 0.125, 0.125, 0.125 ), matWhiteTransparent.clone() ), [ 0, 0, 1.1 ]],
- ] */
- };
-
-
-
- var pickerScale = {
- X: [
- [ new THREE.Mesh( new THREE.CylinderBufferGeometry( 0.2, 0, 0.8, 4, 1, false ), matInvisible ), [ 0.5, 0, 0 ], [ 0, 0, - Math.PI / 2 ]]
- ],
- Y: [
- [ new THREE.Mesh( new THREE.CylinderBufferGeometry( 0.2, 0, 0.8, 4, 1, false ), matInvisible ), [ 0, 0.5, 0 ]]
- ],
- Z: [
- [ new THREE.Mesh( new THREE.CylinderBufferGeometry( 0.2, 0, 0.8, 4, 1, false ), matInvisible ), [ 0, 0, 0.5 ], [ Math.PI / 2, 0, 0 ]]
- ],
- XY: [
- [ new THREE.Mesh( scaleHandleGeometry, matInvisible ), [ 0.85, 0.85, 0 ], null, [ 3, 3, 0.2 ]],
- ],
- /*YZ: [
- [ new THREE.Mesh( scaleHandleGeometry, matInvisible ), [ 0, 0.85, 0.85 ], null, [ 0.2, 3, 3 ]],
- ],
- XZ: [
- [ new THREE.Mesh( scaleHandleGeometry, matInvisible ), [ 0.85, 0, 0.85 ], null, [ 3, 0.2, 3 ]],
- ],
- XYZX: [
- [ new THREE.Mesh( new THREE.BoxBufferGeometry( 0.2, 0.2, 0.2 ), matInvisible ), [ 1.1, 0, 0 ]],
- ],*/
- XYZY: [
- [ new THREE.Mesh( new THREE.BoxBufferGeometry( 0.2, 0.2, 0.2 ), matInvisible ), [ 0, 1.1, 0 ]],
- ]/* ,
- XYZZ: [
- [ new THREE.Mesh( new THREE.BoxBufferGeometry( 0.2, 0.2, 0.2 ), matInvisible ), [ 0, 0, 1.1 ]],
- ] */
- };
- var helperScale = {
- X: [
- [ new THREE.Line( lineGeometry, matHelper.clone() ), [ - 1e3, 0, 0 ], null, [ 1e6, 1, 1 ], 'helper' ]
- ],
- Y: [
- [ new THREE.Line( lineGeometry, matHelper.clone() ), [ 0, - 1e3, 0 ], [ 0, 0, Math.PI / 2 ], [ 1e6, 1, 1 ], 'helper' ]
- ],
- Z: [
- [ new THREE.Line( lineGeometry, matHelper.clone() ), [ 0, 0, - 1e3 ], [ 0, - Math.PI / 2, 0 ], [ 1e6, 1, 1 ], 'helper' ]
- ]
- };
- // Creates an THREE.Object3D with gizmos described in custom hierarchy definition.
- var setupGizmo = function ( gizmoMap ) {
- var gizmo = new THREE.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.applyMatrix4( 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 THREE.Vector3( 0, 0, 0 );
- var tempEuler = new THREE.Euler();
- var alignVector = new THREE.Vector3( 0, 1, 0 );
- var zeroVector = new THREE.Vector3( 0, 0, 0 );
- var lookAtMatrix = new THREE.Matrix4();
- var tempQuaternion = new THREE.Quaternion();
- var tempQuaternion2 = new THREE.Quaternion();
- var identityQuaternion = 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 );
- // 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 () { //TransformControlsGizmo
- if(!this.parent.visible)return //add
- var space = this.space;
- let camera = lastUseCamera || Potree.currentRender?.camera || this.camera
- 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 );
-
- Potree.Utils.updateVisible(this.gizmo[ "rotate" ].children.find(e=>e.name == 'XYZE'), 'decorateCircle', options.showRotXYZE, 1, this.showRotXYZE ? 'add' : 'cancel')//xzw add 没有环的话不好看。但不要picker
-
- for ( var i = 0; i < handles.length; i ++ ) {
- var handle = handles[ i ];
- //add
- if(this.hideAxis[this.mode]?.some(e=>handle.name.includes(e.toUpperCase())) && !this.showAxis[this.mode]?.some(e=>handle.name == e.toUpperCase() )){
- Potree.Utils.updateVisible(handle, 'hidden', false)
- if(!handle.visible) continue //XYZE还是要作为装饰显示
- }
-
- let visible = true
- // hide aligned to camera
-
-
- handle.rotation.set( 0, 0, 0 );
- handle.position.copy( this.worldPosition );
- if(camera.type == "OrthographicCamera"){
- var eyeDistance = 800 / camera.zoom
- }else{
- var eyeDistance = this.worldPosition.distanceTo( this.cameraPosition );
- }
-
-
- handle.scale.set( 1, 1, 1 ).multiplyScalar( eyeDistance * this.size / 7 );
- // TODO: simplify helpers and consider decoupling from gizmo
- if ( handle.tag === 'helper' ) {
- visible = false;
- if ( handle.name === 'AXIS' ) {
- handle.position.copy( this.worldPositionStart );
- 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 ) {
- 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 ) {
- 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 ) {
-
- 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 );
-
- visible = this.dragging;
- }
- if ( this.axis === 'E' ) {
- visible = false;
- }
- } else if ( handle.name === 'START' ) {
- handle.position.copy( this.worldPositionStart );
- visible = this.dragging;
- } else if ( handle.name === 'END' ) {
- handle.position.copy( this.worldPosition );
- 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().invert() );
- handle.scale.copy( tempVector );
- 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 ) {
- visible = this.axis.search( handle.name ) !== - 1;
-
- }
- }
- // If updating helper, skip rest of the loop
- Potree.Utils.updateVisible(handle, 'hidden', !!visible)
- 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 );
- 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 );
- 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 );
- 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 );
- 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 );
- 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 );
- 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 ).invert() );
- 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
- visible = visible && ( handle.name.indexOf( "X" ) === - 1 || this.showX );
- visible = visible && ( handle.name.indexOf( "Y" ) === - 1 || this.showY );
- visible = visible && ( handle.name.indexOf( "Z" ) === - 1 || this.showZ );
- visible = visible && ( handle.name.indexOf( "E" ) === - 1 || ( this.showX && this.showY && this.showZ ) );
-
- Potree.Utils.updateVisible(handle, 'hidden', !!visible)
-
-
-
- // 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 THREE.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 THREE.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 THREE.Color( 1, 1, 1 ), 0.5 );
- } else {
- handle.material.opacity *= 0.25;
- handle.material.color.lerp( new THREE.Color( 1, 1, 1 ), 0.5 );
- }
- }
- }
- THREE.Object3D.prototype.updateMatrixWorld.call( this );
- };
- };
-
-
-
- /* var TransformControlsLines = function (options) {
-
- THREE.Object3D.call( this)
-
- let label1 = new Label2D({ innerHTML:`<div>与相机水平距离</div>` , domElement:$("#otherLabels")[0] ,autoUpdate:true })
- let label2 = new Label2D({ innerHTML:`<div>与相机高度差</div>` , domElement:$("#otherLabels")[0] ,autoUpdate:true })
-
- let css = {'opacity': 0.7, 'color': '#07fceb', transform:'translate(-50%, -50%)'}
- label1.elem.css(css);
- label2.elem.css(css)
-
-
- //for(let i=0;i<2;i++){
- // let line = LineDraw.createLine([new THREE.THREE.Vector3, new THREE.THREE.Vector3],{color:'#07fceb', opacity:0.7 })
- // this.add(line)
- //}
-
-
- this.updateTransform = function(object){
-
- object = object || this.parent.object;
-
- let A = player.position.clone(); //当前相机位置
- let B = object.position //物体位置
- let C = B.clone().setY(A.y); //物体在相机的高度的位置
- let D = A.clone().setY(B.y); //相机在物体的高度的位置
-
- //LineDraw.moveLine(this.children[0], [B, C]) // 垂直线
- //LineDraw.moveLine(this.children[1], [D, B]) // 水平线
-
-
- let dis1 = toPrecision(D.distanceTo(B),1)
- let dis2 = C.y - B.y
- label1.elem.text('与相机水平距离: '+dis1+'米')
- label2.elem.text('在相机之'+ (dis2>0?'下' : '上') +' :'+ toPrecision(dis2 , 1) +'米')
-
- label1.setPos(new THREE.THREE.Vector3().addVectors(D,B).multiplyScalar(0.5))
- label2.setPos(new THREE.THREE.Vector3().addVectors(B,C).multiplyScalar(0.5))
-
- }
-
- this.setVisible = (v,reason)=>{
- label1.setVisible(v, reason || 'unvisi')
- label2.setVisible(v, reason || 'unvisi')
- this.visible = label1.visible
- if(this.visible){
- this.updateTransform()
- }
- }
-
-
-
- this.setVisible(false)
-
-
- player.on("mode.changing",(currentMode, mode, pano, duration)=>{
- if(mode != 'panorama'){
- this.setVisible(false, 'isPanorama')
- }else{
- this.setVisible(true, 'isPanorama')
- }
- })
-
-
- player.on("flying.started",( )=>{
- this.setVisible(false, 'flying')
- })
-
- player.on("flying.ended",( )=>{
- this.setVisible(true, 'flying')
- })
-
- }
- */
-
- var TransformControlsPlane = function (options) {
- 'use strict';
- THREE.Mesh.call( this,
- new THREE.PlaneBufferGeometry( 100000, 100000, 2, 2 ),
- new THREE.MeshBasicMaterial( { color: "#ff0000", visible: false, wireframe: false, side: THREE.DoubleSide, transparent: true, opacity: 0.2 } )
- );
- this.type = 'TransformControlsPlane';
- 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 tempVector = new THREE.Vector3();
- var dirVector = new THREE.Vector3();
- var alignVector = new THREE.Vector3();
- var tempMatrix = new THREE.Matrix4();
- var identityQuaternion = new THREE.Quaternion();
- this.updateMatrixWorld = function () {//TransformControlsPlane
- if(!this.visible)return//add
- 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 );
- }
- THREE.Object3D.prototype.updateMatrixWorld.call( this );
-
-
- };
- };
-
- TransformControls.prototype = Object.assign( Object.create( THREE.Object3D.prototype ), {
- constructor: TransformControls,
- isTransformControls: true
- } );
- TransformControlsGizmo.prototype = Object.assign( Object.create( THREE.Object3D.prototype ), {
- constructor: TransformControlsGizmo,
- isTransformControlsGizmo: true
- } );
- TransformControlsPlane.prototype = Object.assign( Object.create( THREE.Mesh.prototype ), {
- constructor: TransformControlsPlane,
- isTransformControlsPlane: true
- } );
-
-
- export { TransformControls, TransformControlsGizmo, TransformControlsPlane };
- /*
- 备注:
-
-
-
- //这里虽然 使坐标轴在boundingBox中心
- boundingBox && this.object.boundingBox.getCenter(worldPosition).applyMatrix4(this.object.matrixWorld);
- 但是旋转中心并不是这个坐标轴显示的位置,需要再执行 MergeEditor.maintainBoundXY()才能维持在这个中心
-
-
-
-
-
-
- */
|