TransformControls.js 55 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120
  1. !function(){
  2. var BoxBufferGeometry,
  3. BufferGeometry,
  4. Color,
  5. CylinderBufferGeometry,
  6. DoubleSide,
  7. Euler,
  8. Float32BufferAttribute ,
  9. Line ,
  10. LineBasicMaterial ,
  11. Matrix4 ,
  12. Mesh ,
  13. MeshBasicMaterial ,
  14. Object3D ,
  15. OctahedronBufferGeometry ,
  16. PlaneBufferGeometry ,
  17. Quaternion ,
  18. Raycaster ,
  19. SphereBufferGeometry ,
  20. TorusBufferGeometry ,
  21. Vector2,
  22. Vector3 ;
  23. var TransformControls = function ( camera, domElement, options ) {
  24. if ( domElement === undefined ) {
  25. console.warn( 'THREE.TransformControls: The second parameter "domElement" is now mandatory.' );
  26. domElement = document;
  27. }
  28. Object3D.call( this );
  29. this.visible = false;
  30. this.domElement = domElement;
  31. var _gizmo = new TransformControlsGizmo(options);
  32. this.add( _gizmo );
  33. var _plane = new TransformControlsPlane(options);
  34. this.add( _plane );
  35. var scope = this;
  36. this.player = options.player;//xzw add
  37. this.options = options//xzw add
  38. // Define properties with getters/setter
  39. // Setting the defined property will automatically trigger change event
  40. // Defined properties are passed down to gizmo and plane
  41. defineProperty( "camera", camera );
  42. defineProperty( "object", undefined );
  43. defineProperty( "enabled", true );
  44. defineProperty( "axis", null );
  45. defineProperty( "mode", "translate" );
  46. defineProperty( "translationSnap", null );
  47. defineProperty( "rotationSnap", null );
  48. defineProperty( "scaleSnap", null );
  49. defineProperty( "space", "world" );
  50. defineProperty( "size", 1 );
  51. defineProperty( "dragging", false );
  52. defineProperty( "showX", true );
  53. defineProperty( "showY", true );
  54. defineProperty( "showZ", true );
  55. var changeEvent = { type: "change" };
  56. var mouseDownEvent = { type: "mouseDown" };
  57. var mouseUpEvent = { type: "mouseUp", mode: scope.mode };
  58. var objectChangeEvent = { type: "objectChange" };
  59. // Reusable utility variables
  60. var ray = new Raycaster();
  61. var _tempVector = new Vector3();
  62. var _tempVector2 = new Vector3();
  63. var _tempQuaternion = new Quaternion();
  64. var _unit = {
  65. X: new Vector3( 1, 0, 0 ),
  66. Y: new Vector3( 0, 1, 0 ),
  67. Z: new Vector3( 0, 0, 1 )
  68. };
  69. var pointStart = new Vector3();
  70. var pointEnd = new Vector3();
  71. var offset = new Vector3();
  72. var rotationAxis = new Vector3();
  73. var startNorm = new Vector3();
  74. var endNorm = new Vector3();
  75. var rotationAngle = 0;
  76. var cameraPosition = new Vector3();
  77. var cameraQuaternion = new Quaternion();
  78. var cameraScale = new Vector3();
  79. var parentPosition = new Vector3();
  80. var parentQuaternion = new Quaternion();
  81. var parentQuaternionInv = new Quaternion();
  82. var parentScale = new Vector3();
  83. var worldPositionStart = new Vector3();
  84. var worldQuaternionStart = new Quaternion();
  85. var worldScaleStart = new Vector3();
  86. var worldPosition = new Vector3();
  87. var worldQuaternion = new Quaternion();
  88. var worldQuaternionInv = new Quaternion();
  89. var worldScale = new Vector3();
  90. var eye = new Vector3();
  91. var positionStart = new Vector3();
  92. var quaternionStart = new Quaternion();
  93. var scaleStart = new Vector3();
  94. // TODO: remove properties unused in plane and gizmo
  95. defineProperty( "worldPosition", worldPosition );
  96. defineProperty( "worldPositionStart", worldPositionStart );
  97. defineProperty( "worldQuaternion", worldQuaternion );
  98. defineProperty( "worldQuaternionStart", worldQuaternionStart );
  99. defineProperty( "cameraPosition", cameraPosition );
  100. defineProperty( "cameraQuaternion", cameraQuaternion );
  101. defineProperty( "pointStart", pointStart );
  102. defineProperty( "pointEnd", pointEnd );
  103. defineProperty( "rotationAxis", rotationAxis );
  104. defineProperty( "rotationAngle", rotationAngle );
  105. defineProperty( "eye", eye );
  106. {
  107. domElement.addEventListener( "mousedown", onPointerDown, false );
  108. domElement.addEventListener( "touchstart", onPointerDown, false );
  109. domElement.addEventListener( "mousemove", onPointerHover, false );
  110. domElement.addEventListener( "touchmove", onPointerHover, false );
  111. domElement.addEventListener( "touchmove", onPointerMove, false );
  112. document.addEventListener( "mouseup", onPointerUp, false );
  113. domElement.addEventListener( "touchend", onPointerUp, false );
  114. domElement.addEventListener( "touchcancel", onPointerUp, false );
  115. domElement.addEventListener( "touchleave", onPointerUp, false );
  116. }
  117. this.dispose = function () {
  118. domElement.removeEventListener( "mousedown", onPointerDown );
  119. domElement.removeEventListener( "touchstart", onPointerDown );
  120. domElement.removeEventListener( "mousemove", onPointerHover );
  121. domElement.removeEventListener( "mousemove", onPointerMove );
  122. domElement.removeEventListener( "touchmove", onPointerHover );
  123. domElement.removeEventListener( "touchmove", onPointerMove );
  124. document.removeEventListener( "mouseup", onPointerUp );
  125. domElement.removeEventListener( "touchend", onPointerUp );
  126. domElement.removeEventListener( "touchcancel", onPointerUp );
  127. domElement.removeEventListener( "touchleave", onPointerUp );
  128. this.traverse( function ( child ) {
  129. if ( child.geometry ) child.geometry.dispose();
  130. if ( child.material ) child.material.dispose();
  131. } );
  132. };
  133. // Set current object
  134. this.attach = function ( object ) {
  135. this.object = object;
  136. this.visible = true;
  137. //Config.keyCon = false;//add
  138. return this;
  139. };
  140. // Detatch from object
  141. this.detach = function () {
  142. this.object = undefined;
  143. this.visible = false;
  144. this.axis = null;
  145. //Config.keyCon = true;//add
  146. return this;
  147. };
  148. // Defined getter, setter and store for a property
  149. function defineProperty( propName, defaultValue ) {
  150. var propValue = defaultValue;
  151. Object.defineProperty( scope, propName, {
  152. get: function () {
  153. return propValue !== undefined ? propValue : defaultValue;
  154. },
  155. set: function ( value ) {
  156. if ( propValue !== value ) {
  157. propValue = value;
  158. _plane[ propName ] = value;
  159. _gizmo[ propName ] = value;
  160. scope.dispatchEvent( { type: propName + "-changed", value: value } );
  161. scope.dispatchEvent( changeEvent );
  162. }
  163. }
  164. } );
  165. scope[ propName ] = defaultValue;
  166. _plane[ propName ] = defaultValue;
  167. _gizmo[ propName ] = defaultValue;
  168. }
  169. // updateMatrixWorld updates key transformation variables
  170. this.updateMatrixWorld = function () {
  171. if ( this.object !== undefined ) {
  172. this.object.updateMatrixWorld();
  173. this.object.parent.matrixWorld.decompose( parentPosition, parentQuaternion, parentScale );
  174. this.object.matrixWorld.decompose( worldPosition, worldQuaternion, worldScale );
  175. parentQuaternionInv.copy( parentQuaternion ).inverse();
  176. worldQuaternionInv.copy( worldQuaternion ).inverse();
  177. }
  178. this.camera.updateMatrixWorld();
  179. this.camera.matrixWorld.decompose( cameraPosition, cameraQuaternion, cameraScale );
  180. eye.copy( cameraPosition ).sub( worldPosition ).normalize();
  181. Object3D.prototype.updateMatrixWorld.call( this );
  182. };
  183. this.pointerHover = function ( pointer ) {
  184. if ( this.object === undefined || this.dragging === true || ( pointer.button !== undefined && pointer.button !== 0 ) ) return;
  185. //ray.setFromCamera( pointer, this.camera ); //这句会在floorplan模式get不到intersect
  186. var origin = new Vector3(pointer.x, pointer.y, -1).unproject(this.camera);
  187. ray.set(origin, player.getMouseDirection(pointer));
  188. var intersect = ray.intersectObjects( _gizmo.picker[ this.mode ].children, true )[ 0 ] || false;
  189. if ( intersect ) {
  190. this.axis = intersect.object.name;
  191. } else {
  192. this.axis = null;
  193. }
  194. };
  195. this.pointerDown = function ( pointer ) {
  196. if ( this.object === undefined || this.dragging === true || ( pointer.button !== undefined && pointer.button !== 0 ) ) return;
  197. if ( ( pointer.button === 0 || pointer.button === undefined ) && this.axis !== null ) {
  198. //ray.setFromCamera( pointer, this.camera ); //这句会在floorplan模式get不到intersect
  199. var origin = new Vector3(pointer.x, pointer.y, -1).unproject(this.camera);
  200. ray.set(origin, player.getMouseDirection(pointer));
  201. var planeIntersect = ray.intersectObjects( [ _plane ], true )[ 0 ] || false;
  202. if ( planeIntersect ) {
  203. var space = this.space;
  204. if ( this.mode === 'scale' ) {
  205. space = 'local';
  206. } else if ( this.axis === 'E' || this.axis === 'XYZE' || this.axis === 'XYZ' ) {
  207. space = 'world';
  208. }
  209. if ( space === 'local' && this.mode === 'rotate' ) {
  210. var snap = this.rotationSnap;
  211. if ( this.axis === 'X' && snap ) this.object.rotation.x = Math.round( this.object.rotation.x / snap ) * snap;
  212. if ( this.axis === 'Y' && snap ) this.object.rotation.y = Math.round( this.object.rotation.y / snap ) * snap;
  213. if ( this.axis === 'Z' && snap ) this.object.rotation.z = Math.round( this.object.rotation.z / snap ) * snap;
  214. }
  215. this.object.updateMatrixWorld();
  216. this.object.parent.updateMatrixWorld();
  217. positionStart.copy( this.object.position );
  218. quaternionStart.copy( this.object.quaternion );
  219. scaleStart.copy( this.object.scale );
  220. this.object.matrixWorld.decompose( worldPositionStart, worldQuaternionStart, worldScaleStart );
  221. pointStart.copy( planeIntersect.point ).sub( worldPositionStart );
  222. if(this.player.cameraControls.activeControl){
  223. //this.player.cameraControls.activeControl.locked = true; //add
  224. this.player.cameraControls.activeControl.enabled = false; //add
  225. }
  226. }
  227. this.dragging = true;
  228. mouseDownEvent.mode = this.mode;
  229. this.dispatchEvent( mouseDownEvent );
  230. }
  231. };
  232. this.pointerMove = function ( pointer ) {
  233. var axis = this.axis;
  234. var mode = this.mode;
  235. var object = this.object;
  236. var space = this.space;
  237. if ( mode === 'scale' ) {
  238. space = 'local';
  239. } else if ( axis === 'E' || axis === 'XYZE' || axis === 'XYZ' ) {
  240. space = 'world';
  241. }
  242. if ( object === undefined || axis === null || this.dragging === false || ( pointer.button !== undefined && pointer.button !== 0 ) ) return;
  243. //ray.setFromCamera( pointer, this.camera ); //这句会在floorplan模式get不到intersect
  244. var origin = new Vector3(pointer.x, pointer.y, -1).unproject(this.camera);
  245. ray.set(origin, player.getMouseDirection(pointer));
  246. var planeIntersect = ray.intersectObjects( [ _plane ], true )[ 0 ] || false;
  247. if ( planeIntersect === false ) return;
  248. pointEnd.copy( planeIntersect.point ).sub( worldPositionStart );
  249. if ( mode === 'translate' ) {
  250. // Apply translate
  251. offset.copy( pointEnd ).sub( pointStart );
  252. if ( space === 'local' && axis !== 'XYZ' ) {
  253. offset.applyQuaternion( worldQuaternionInv );
  254. }
  255. if ( axis.indexOf( 'X' ) === - 1 ) offset.x = 0;
  256. if ( axis.indexOf( 'Y' ) === - 1 ) offset.y = 0;
  257. if ( axis.indexOf( 'Z' ) === - 1 ) offset.z = 0;
  258. if ( space === 'local' && axis !== 'XYZ' ) {
  259. offset.applyQuaternion( quaternionStart ).divide( parentScale );
  260. } else {
  261. offset.applyQuaternion( parentQuaternionInv ).divide( parentScale );
  262. }
  263. object.position.copy( offset ).add( positionStart );
  264. // Apply translation snap
  265. if ( this.translationSnap ) {
  266. if ( space === 'local' ) {
  267. object.position.applyQuaternion( _tempQuaternion.copy( quaternionStart ).inverse() );
  268. if ( axis.search( 'X' ) !== - 1 ) {
  269. object.position.x = Math.round( object.position.x / this.translationSnap ) * this.translationSnap;
  270. }
  271. if ( axis.search( 'Y' ) !== - 1 ) {
  272. object.position.y = Math.round( object.position.y / this.translationSnap ) * this.translationSnap;
  273. }
  274. if ( axis.search( 'Z' ) !== - 1 ) {
  275. object.position.z = Math.round( object.position.z / this.translationSnap ) * this.translationSnap;
  276. }
  277. object.position.applyQuaternion( quaternionStart );
  278. }
  279. if ( space === 'world' ) {
  280. if ( object.parent ) {
  281. object.position.add( _tempVector.setFromMatrixPosition( object.parent.matrixWorld ) );
  282. }
  283. if ( axis.search( 'X' ) !== - 1 ) {
  284. object.position.x = Math.round( object.position.x / this.translationSnap ) * this.translationSnap;
  285. }
  286. if ( axis.search( 'Y' ) !== - 1 ) {
  287. object.position.y = Math.round( object.position.y / this.translationSnap ) * this.translationSnap;
  288. }
  289. if ( axis.search( 'Z' ) !== - 1 ) {
  290. object.position.z = Math.round( object.position.z / this.translationSnap ) * this.translationSnap;
  291. }
  292. if ( object.parent ) {
  293. object.position.sub( _tempVector.setFromMatrixPosition( object.parent.matrixWorld ) );
  294. }
  295. }
  296. }
  297. //add:
  298. /* if(EditOverlay.editing){
  299. EditOverlay.updatePosition();
  300. }else */ if(editTool.hotpoint.editSpot){
  301. editTool.hotpoint.updateTransform('position');
  302. }
  303. } else if ( mode === 'scale' ) {
  304. if ( axis.search( 'XYZ' ) !== - 1 ) {
  305. var d = pointEnd.length() / pointStart.length();
  306. if ( pointEnd.dot( pointStart ) < 0 ) d *= - 1;
  307. if(options.NoScaleZ){//xzw add
  308. _tempVector2.set( d, d, 1 );
  309. }else{
  310. _tempVector2.set( d, d, d );
  311. }
  312. }else if ( axis.search( 'XY' ) !== - 1 ) { //add 等比例for plane
  313. var d = pointEnd.length() / pointStart.length();
  314. if ( pointEnd.dot( pointStart ) < 0 ) d *= - 1;
  315. _tempVector2.set( d, d, 1 );
  316. }else {
  317. _tempVector.copy( pointStart );
  318. _tempVector2.copy( pointEnd );
  319. _tempVector.applyQuaternion( worldQuaternionInv );
  320. _tempVector2.applyQuaternion( worldQuaternionInv );
  321. _tempVector2.divide( _tempVector );
  322. if ( axis.search( 'X' ) === - 1 ) {
  323. _tempVector2.x = 1;
  324. }
  325. if ( axis.search( 'Y' ) === - 1 ) {
  326. _tempVector2.y = 1;
  327. }
  328. if ( axis.search( 'Z' ) === - 1 ) {
  329. _tempVector2.z = 1;
  330. }
  331. }
  332. // Apply scale
  333. object.scale.copy( scaleStart ).multiply( _tempVector2 );
  334. if ( this.scaleSnap ) {
  335. if ( axis.search( 'X' ) !== - 1 ) {
  336. object.scale.x = Math.round( object.scale.x / this.scaleSnap ) * this.scaleSnap || this.scaleSnap;
  337. }
  338. if ( axis.search( 'Y' ) !== - 1 ) {
  339. object.scale.y = Math.round( object.scale.y / this.scaleSnap ) * this.scaleSnap || this.scaleSnap;
  340. }
  341. if ( axis.search( 'Z' ) !== - 1 ) {
  342. object.scale.z = Math.round( object.scale.z / this.scaleSnap ) * this.scaleSnap || this.scaleSnap;
  343. }
  344. }
  345. //add:
  346. /* if(EditOverlay.editing){
  347. EditOverlay.updateScale();
  348. } */
  349. if(editTool.hotpoint.editSpot){
  350. editTool.hotpoint.updateTransform('scale');
  351. }
  352. } else if ( mode === 'rotate' ) {
  353. offset.copy( pointEnd ).sub( pointStart );
  354. var ROTATION_SPEED = 2 / worldPosition.distanceTo( _tempVector.setFromMatrixPosition( this.camera.matrixWorld ) );
  355. if ( axis === 'E' ) {
  356. rotationAxis.copy( eye );
  357. rotationAngle = pointEnd.angleTo( pointStart );
  358. startNorm.copy( pointStart ).normalize();
  359. endNorm.copy( pointEnd ).normalize();
  360. rotationAngle *= ( endNorm.cross( startNorm ).dot( eye ) < 0 ? 1 : - 1 );
  361. } else if ( axis === 'XYZE' ) {
  362. rotationAxis.copy( offset ).cross( eye ).normalize();
  363. rotationAngle = offset.dot( _tempVector.copy( rotationAxis ).cross( this.eye ) ) * ROTATION_SPEED;
  364. } else if ( axis === 'X' || axis === 'Y' || axis === 'Z' ) {
  365. rotationAxis.copy( _unit[ axis ] );
  366. _tempVector.copy( _unit[ axis ] );
  367. if ( space === 'local' ) {
  368. _tempVector.applyQuaternion( worldQuaternion );
  369. }
  370. rotationAngle = offset.dot( _tempVector.cross( eye ).normalize() ) * ROTATION_SPEED;
  371. }
  372. // Apply rotation snap
  373. if ( this.rotationSnap ) rotationAngle = Math.round( rotationAngle / this.rotationSnap ) * this.rotationSnap;
  374. this.rotationAngle = rotationAngle;
  375. // Apply rotate
  376. if ( space === 'local' && axis !== 'E' && axis !== 'XYZE' ) {
  377. object.quaternion.copy( quaternionStart );
  378. object.quaternion.multiply( _tempQuaternion.setFromAxisAngle( rotationAxis, rotationAngle ) ).normalize();
  379. } else {
  380. rotationAxis.applyQuaternion( parentQuaternionInv );
  381. object.quaternion.copy( _tempQuaternion.setFromAxisAngle( rotationAxis, rotationAngle ) );
  382. object.quaternion.multiply( quaternionStart ).normalize();
  383. }
  384. //add:
  385. /*
  386. if(EditOverlay.editing){
  387. EditOverlay.updateQua();
  388. } */
  389. if(editTool.hotpoint.editSpot){
  390. editTool.hotpoint.updateTransform('quaternion');
  391. }
  392. }
  393. this.dispatchEvent( changeEvent );
  394. this.dispatchEvent( objectChangeEvent );
  395. };
  396. this.pointerUp = function ( pointer ) {
  397. //if ( pointer.button !== undefined && pointer.button !== 0 ) return;
  398. if ( this.dragging && ( this.axis !== null ) ) {
  399. mouseUpEvent.mode = this.mode;
  400. this.dispatchEvent( mouseUpEvent );
  401. if(this.player.cameraControls.activeControl){
  402. //this.player.cameraControls.activeControl.locked = false; //add
  403. this.player.cameraControls.activeControl.pointerDragOn = false //add
  404. this.player.cameraControls.activeControl.enabled = true
  405. }
  406. }
  407. this.dragging = false;
  408. if ( pointer.button === undefined ) this.axis = null;
  409. /* if(this.player.cameraControls.activeControl){
  410. //this.player.cameraControls.activeControl.locked = false; //add
  411. this.player.cameraControls.activeControl.pointerDragOn = false //add
  412. this.player.cameraControls.activeControl.enabled = true
  413. } */
  414. };
  415. // normalize mouse / touch pointer and remap {x,y} to view space.
  416. function getPointer( event ) {
  417. if(!event){
  418. console.log('hhahhhahah')
  419. return;
  420. }
  421. if ( document.pointerLockElement ) {
  422. return {
  423. x: 0,
  424. y: 0,
  425. button: event.button
  426. };
  427. } else {
  428. var pointer = event.changedTouches ? event.changedTouches[ 0 ] : event;
  429. var rect = domElement.getBoundingClientRect();
  430. return {
  431. x: ( pointer.clientX - rect.left ) / rect.width * 2 - 1,
  432. y: - ( pointer.clientY - rect.top ) / rect.height * 2 + 1,
  433. button: event.button
  434. };
  435. }
  436. }
  437. // mouse / touch event handlers
  438. function onPointerHover( event ) {
  439. if ( ! scope.enabled ) return;
  440. //scope.pointerHover( getPointer( event ) );
  441. scope.pointerHover( scope.player.mouse );
  442. }
  443. function onPointerDown( event ) {
  444. if ( ! scope.enabled ) return;
  445. //document.addEventListener( "mousemove", onPointerMove, false );
  446. /* scope.pointerHover( getPointer( event ) );
  447. scope.pointerDown( getPointer( event ) ); */
  448. scope.pointerHover( scope.player.mouse );
  449. scope.pointerDown( scope.player.mouse );
  450. }
  451. this.onPointerDown = onPointerDown;
  452. function onPointerMove( event ) {
  453. if ( ! scope.enabled || !this.dragging) return; //xzw change
  454. //scope.pointerMove( getPointer( event ) );
  455. scope.pointerMove( scope.player.mouse );
  456. }
  457. this.onPointerMove = onPointerMove;
  458. function onPointerUp( event ) {
  459. if ( ! scope.enabled ) return;
  460. //document.removeEventListener( "mousemove", onPointerMove, false );
  461. //scope.pointerUp( getPointer( event ) );
  462. scope.pointerUp( scope.player.mouse );
  463. }
  464. this.onPointerUp = onPointerUp;
  465. // TODO: deprecate
  466. this.getMode = function () {
  467. return scope.mode;
  468. };
  469. this.setMode = function ( mode ) {
  470. scope.mode = mode;
  471. };
  472. this.setTranslationSnap = function ( translationSnap ) {
  473. scope.translationSnap = translationSnap;
  474. };
  475. this.setRotationSnap = function ( rotationSnap ) {
  476. scope.rotationSnap = rotationSnap;
  477. };
  478. this.setScaleSnap = function ( scaleSnap ) {
  479. scope.scaleSnap = scaleSnap;
  480. };
  481. this.setSize = function ( size ) {
  482. scope.size = size;
  483. };
  484. this.setSpace = function ( space ) {
  485. scope.space = space;
  486. };
  487. this.update = function () {
  488. console.warn( 'THREE.TransformControls: update function has no more functionality and therefore has been deprecated.' );
  489. };
  490. };
  491. var TransformControlsGizmo = function (options) {
  492. 'use strict';
  493. Object3D.call( this );
  494. this.type = 'TransformControlsGizmo';
  495. // shared materials
  496. var gizmoMaterial = new MeshBasicMaterial( {
  497. depthTest: false,
  498. depthWrite: false,
  499. transparent: true,
  500. side: DoubleSide,
  501. fog: false
  502. } );
  503. var gizmoLineMaterial = new LineBasicMaterial( {
  504. depthTest: false,
  505. depthWrite: false,
  506. transparent: true,
  507. linewidth: 1,
  508. fog: false
  509. } );
  510. // Make unique material for each axis/color
  511. var matInvisible = gizmoMaterial.clone();
  512. matInvisible.opacity = 0.15;
  513. var matHelper = gizmoMaterial.clone();
  514. matHelper.opacity = 0.33;
  515. var matRed = gizmoMaterial.clone();
  516. matRed.color.set( 0xff0000 );
  517. var matGreen = gizmoMaterial.clone();
  518. matGreen.color.set( 0x00ff00 );
  519. var matBlue = gizmoMaterial.clone();
  520. matBlue.color.set( 0x0000ff );
  521. var matWhiteTransparent = gizmoMaterial.clone();
  522. matWhiteTransparent.opacity = 0.35;
  523. matWhiteTransparent.color.set( 0x00d0fd );//xzw add
  524. var matYellowTransparent = matWhiteTransparent.clone();
  525. matYellowTransparent.color.set( 0xffff00 );
  526. var matCyanTransparent = matWhiteTransparent.clone();
  527. matCyanTransparent.color.set( 0x00ffff );
  528. var matMagentaTransparent = matWhiteTransparent.clone();
  529. matMagentaTransparent.color.set( 0xff00ff );
  530. var matYellow = gizmoMaterial.clone();
  531. matYellow.color.set( 0xffff00 );
  532. var matLineRed = gizmoLineMaterial.clone();
  533. matLineRed.color.set( 0xff0000 );
  534. var matLineGreen = gizmoLineMaterial.clone();
  535. matLineGreen.color.set( 0x00ff00 );
  536. var matLineBlue = gizmoLineMaterial.clone();
  537. matLineBlue.color.set( 0x0000ff );
  538. var matLineCyan = gizmoLineMaterial.clone();
  539. matLineCyan.color.set( 0x00ffff );
  540. var matLineMagenta = gizmoLineMaterial.clone();
  541. matLineMagenta.color.set( 0xff00ff );
  542. var matLineYellow = gizmoLineMaterial.clone();
  543. matLineYellow.color.set( 0xffff00 );
  544. var matLineGray = gizmoLineMaterial.clone();
  545. matLineGray.color.set( 0x787878 );
  546. var matLineYellowTransparent = matLineYellow.clone();
  547. matLineYellowTransparent.opacity = 0.25;
  548. // reusable geometry
  549. var arrowGeometry = new CylinderBufferGeometry( 0, 0.05, 0.2, 12, 1, false );
  550. var scaleHandleGeometry = new BoxBufferGeometry( 0.125, 0.125, 0.125 );
  551. var lineGeometry = new BufferGeometry( );
  552. //lineGeometry.addAttribute( 'position', new Float32BufferAttribute( [ 0, 0, 0, 1, 0, 0 ], 3 ) );
  553. lineGeometry.addAttribute("position", new THREE.BufferAttribute(new Float32Array([ 0, 0, 0, 1, 0, 0]), 3 ))
  554. var CircleGeometry = function ( radius, arc ) {
  555. var geometry = new BufferGeometry( );
  556. var vertices = [];
  557. for ( var i = 0; i <= 64 * arc; ++ i ) {
  558. vertices.push( 0, Math.cos( i / 32 * Math.PI ) * radius, Math.sin( i / 32 * Math.PI ) * radius );
  559. }
  560. //geometry.addAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  561. geometry.addAttribute("position", new THREE.BufferAttribute(new Float32Array(vertices), 3 ))
  562. return geometry;
  563. };
  564. // Special geometry for transform helper. If scaled with position vector it spans from [0,0,0] to position
  565. var TranslateHelperGeometry = function () {
  566. var geometry = new BufferGeometry();
  567. //geometry.addAttribute( 'position', new Float32BufferAttribute( [ 0, 0, 0, 1, 1, 1 ], 3 ) );
  568. geometry.addAttribute("position", new THREE.BufferAttribute(new Float32Array([ 0, 0, 0, 1, 1, 1 ]), 3 ))
  569. return geometry;
  570. };
  571. // Gizmo definitions - custom hierarchy definitions for setupGizmo() function
  572. var gizmoTranslate = {
  573. X: [
  574. [ new Mesh( arrowGeometry, matRed ), [ 1, 0, 0 ], [ 0, 0, - Math.PI / 2 ], null, 'fwd' ],
  575. //[ new Mesh( arrowGeometry, matRed ), [ 1, 0, 0 ], [ 0, 0, Math.PI / 2 ], null, 'bwd' ],
  576. [ new Line( lineGeometry, matLineRed ) ]
  577. ],
  578. Y: [
  579. [ new Mesh( arrowGeometry, matGreen ), [ 0, 1, 0 ], null, null, 'fwd' ],
  580. //[ new Mesh( arrowGeometry, matGreen ), [ 0, 1, 0 ], [ Math.PI, 0, 0 ], null, 'bwd' ],
  581. [ new Line( lineGeometry, matLineGreen ), null, [ 0, 0, Math.PI / 2 ]]
  582. ],
  583. Z: [
  584. [ new Mesh( arrowGeometry, matBlue ), [ 0, 0, 1 ], [ Math.PI / 2, 0, 0 ], null, 'fwd' ],
  585. //[ new Mesh( arrowGeometry, matBlue ), [ 0, 0, 1 ], [ - Math.PI / 2, 0, 0 ], null, 'bwd' ],
  586. [ new Line( lineGeometry, matLineBlue ), null, [ 0, - Math.PI / 2, 0 ]]
  587. ],
  588. /* XYZ: [
  589. [ new Mesh( new OctahedronBufferGeometry( 0.1, 0 ), matWhiteTransparent.clone() ), [ 0, 0, 0 ], [ 0, 0, 0 ]]
  590. ], */
  591. XY: [
  592. [ new Mesh( new PlaneBufferGeometry( 0.295, 0.295 ), matYellowTransparent.clone() ), [ 0.15, 0.15, 0 ]],
  593. [ new Line( lineGeometry, matLineYellow ), [ 0.18, 0.3, 0 ], null, [ 0.125, 1, 1 ]],
  594. [ new Line( lineGeometry, matLineYellow ), [ 0.3, 0.18, 0 ], [ 0, 0, Math.PI / 2 ], [ 0.125, 1, 1 ]]
  595. ],
  596. YZ: [
  597. [ new Mesh( new PlaneBufferGeometry( 0.295, 0.295 ), matCyanTransparent.clone() ), [ 0, 0.15, 0.15 ], [ 0, Math.PI / 2, 0 ]],
  598. [ new Line( lineGeometry, matLineCyan ), [ 0, 0.18, 0.3 ], [ 0, 0, Math.PI / 2 ], [ 0.125, 1, 1 ]],
  599. [ new Line( lineGeometry, matLineCyan ), [ 0, 0.3, 0.18 ], [ 0, - Math.PI / 2, 0 ], [ 0.125, 1, 1 ]]
  600. ],
  601. XZ: [
  602. [ new Mesh( new PlaneBufferGeometry( 0.295, 0.295 ), matMagentaTransparent.clone() ), [ 0.15, 0, 0.15 ], [ - Math.PI / 2, 0, 0 ]],
  603. [ new Line( lineGeometry, matLineMagenta ), [ 0.18, 0, 0.3 ], null, [ 0.125, 1, 1 ]],
  604. [ new Line( lineGeometry, matLineMagenta ), [ 0.3, 0, 0.18 ], [ 0, - Math.PI / 2, 0 ], [ 0.125, 1, 1 ]]
  605. ]
  606. };
  607. var pickerTranslate = {
  608. X: [
  609. [ new Mesh( new CylinderBufferGeometry( 0.2, 0, 1, 4, 1, false ), matInvisible ), [ 0.6, 0, 0 ], [ 0, 0, - Math.PI / 2 ]]
  610. ],
  611. Y: [
  612. [ new Mesh( new CylinderBufferGeometry( 0.2, 0, 1, 4, 1, false ), matInvisible ), [ 0, 0.6, 0 ]]
  613. ],
  614. Z: [
  615. [ new Mesh( new CylinderBufferGeometry( 0.2, 0, 1, 4, 1, false ), matInvisible ), [ 0, 0, 0.6 ], [ Math.PI / 2, 0, 0 ]]
  616. ],
  617. /* XYZ: [
  618. [ new Mesh( new OctahedronBufferGeometry( 0.2, 0 ), matInvisible ) ]
  619. ], */
  620. XY: [
  621. [ new Mesh( new PlaneBufferGeometry( 0.4, 0.4 ), matInvisible ), [ 0.2, 0.2, 0 ]]
  622. ],
  623. YZ: [
  624. [ new Mesh( new PlaneBufferGeometry( 0.4, 0.4 ), matInvisible ), [ 0, 0.2, 0.2 ], [ 0, Math.PI / 2, 0 ]]
  625. ],
  626. XZ: [
  627. [ new Mesh( new PlaneBufferGeometry( 0.4, 0.4 ), matInvisible ), [ 0.2, 0, 0.2 ], [ - Math.PI / 2, 0, 0 ]]
  628. ]
  629. };
  630. var helperTranslate = {
  631. START: [
  632. [ new Mesh( new OctahedronBufferGeometry( 0.01, 2 ), matHelper ), null, null, null, 'helper' ]
  633. ],
  634. END: [
  635. [ new Mesh( new OctahedronBufferGeometry( 0.01, 2 ), matHelper ), null, null, null, 'helper' ]
  636. ],
  637. DELTA: [
  638. [ new Line( TranslateHelperGeometry(), matHelper ), null, null, null, 'helper' ]
  639. ],
  640. X: [
  641. [ new Line( lineGeometry, matHelper.clone() ), [ - 1e3, 0, 0 ], null, [ 1e6, 1, 1 ], 'helper' ]
  642. ],
  643. Y: [
  644. [ new Line( lineGeometry, matHelper.clone() ), [ 0, - 1e3, 0 ], [ 0, 0, Math.PI / 2 ], [ 1e6, 1, 1 ], 'helper' ]
  645. ],
  646. Z: [
  647. [ new Line( lineGeometry, matHelper.clone() ), [ 0, 0, - 1e3 ], [ 0, - Math.PI / 2, 0 ], [ 1e6, 1, 1 ], 'helper' ]
  648. ]
  649. };
  650. var gizmoRotate = {
  651. X: [
  652. [ new Line( CircleGeometry( 1, 0.5 ), matLineRed ) ],
  653. [ new Mesh( new OctahedronBufferGeometry( 0.04, 0 ), matRed ), [ 0, 0, 0.99 ], null, [ 1, 3, 1 ]],
  654. ],
  655. Y: [
  656. [ new Line( CircleGeometry( 1, 0.5 ), matLineGreen ), null, [ 0, 0, - Math.PI / 2 ]],
  657. [ new Mesh( new OctahedronBufferGeometry( 0.04, 0 ), matGreen ), [ 0, 0, 0.99 ], null, [ 3, 1, 1 ]],
  658. ],
  659. Z: [
  660. [ new Line( CircleGeometry( 1, 0.5 ), matLineBlue ), null, [ 0, Math.PI / 2, 0 ]],
  661. [ new Mesh( new OctahedronBufferGeometry( 0.04, 0 ), matBlue ), [ 0.99, 0, 0 ], null, [ 1, 3, 1 ]],
  662. ],
  663. E: [
  664. [ new Line( CircleGeometry( 1.25, 1 ), matLineYellowTransparent ), null, [ 0, Math.PI / 2, 0 ]],
  665. [ 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 ]],
  666. [ 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 ]],
  667. [ 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 ]],
  668. [ new Mesh( new CylinderBufferGeometry( 0.03, 0, 0.15, 4, 1, false ), matLineYellowTransparent ), [ 0, 1.17, 0 ], [ 0, 0, 0 ], [ 1, 1, 0.001 ]],
  669. ],
  670. XYZE: [
  671. [ new Line( CircleGeometry( 1, 1 ), matLineGray ), null, [ 0, Math.PI / 2, 0 ]]
  672. ]
  673. };
  674. var helperRotate = {
  675. AXIS: [
  676. [ new Line( lineGeometry, matHelper.clone() ), [ - 1e3, 0, 0 ], null, [ 1e6, 1, 1 ], 'helper' ]
  677. ]
  678. };
  679. var pickerRotate = {
  680. X: [
  681. [ new Mesh( new TorusBufferGeometry( 1, 0.1, 4, 24 ), matInvisible ), [ 0, 0, 0 ], [ 0, - Math.PI / 2, - Math.PI / 2 ]],
  682. ],
  683. Y: [
  684. [ new Mesh( new TorusBufferGeometry( 1, 0.1, 4, 24 ), matInvisible ), [ 0, 0, 0 ], [ Math.PI / 2, 0, 0 ]],
  685. ],
  686. Z: [
  687. [ new Mesh( new TorusBufferGeometry( 1, 0.1, 4, 24 ), matInvisible ), [ 0, 0, 0 ], [ 0, 0, - Math.PI / 2 ]],
  688. ],
  689. E: [
  690. [ new Mesh( new TorusBufferGeometry( 1.25, 0.1, 2, 24 ), matInvisible ) ]
  691. ],
  692. XYZE: [
  693. [ new Mesh( new SphereBufferGeometry( 0.7, 10, 8 ), matInvisible ) ]
  694. ]
  695. };
  696. var gizmoScale = {
  697. X: [
  698. [ new Mesh( scaleHandleGeometry, matRed ), [ 0.8, 0, 0 ], [ 0, 0, - Math.PI / 2 ]],
  699. [ new Line( lineGeometry, matLineRed ), null, null, [ 0.8, 1, 1 ]]
  700. ],
  701. Y: [
  702. [ new Mesh( scaleHandleGeometry, matGreen ), [ 0, 0.8, 0 ]],
  703. [ new Line( lineGeometry, matLineGreen ), null, [ 0, 0, Math.PI / 2 ], [ 0.8, 1, 1 ]]
  704. ],
  705. Z: [
  706. [ new Mesh( scaleHandleGeometry, matBlue ), [ 0, 0, 0.8 ], [ Math.PI / 2, 0, 0 ]],
  707. [ new Line( lineGeometry, matLineBlue ), null, [ 0, - Math.PI / 2, 0 ], [ 0.8, 1, 1 ]]
  708. ],
  709. XY: [
  710. [ new Mesh( scaleHandleGeometry, matYellowTransparent ), [ 0.85, 0.85, 0 ], null, [ 2, 2, 0.2 ]],
  711. [ new Line( lineGeometry, matLineYellow ), [ 0.855, 0.98, 0 ], null, [ 0.125, 1, 1 ]],
  712. [ new Line( lineGeometry, matLineYellow ), [ 0.98, 0.855, 0 ], [ 0, 0, Math.PI / 2 ], [ 0.125, 1, 1 ]]
  713. ],
  714. /* YZ: [
  715. [ new Mesh( scaleHandleGeometry, matCyanTransparent ), [ 0, 0.85, 0.85 ], null, [ 0.2, 2, 2 ]],
  716. [ new Line( lineGeometry, matLineCyan ), [ 0, 0.855, 0.98 ], [ 0, 0, Math.PI / 2 ], [ 0.125, 1, 1 ]],
  717. [ new Line( lineGeometry, matLineCyan ), [ 0, 0.98, 0.855 ], [ 0, - Math.PI / 2, 0 ], [ 0.125, 1, 1 ]]
  718. ],
  719. XZ: [
  720. [ new Mesh( scaleHandleGeometry, matMagentaTransparent ), [ 0.85, 0, 0.85 ], null, [ 2, 0.2, 2 ]],
  721. [ new Line( lineGeometry, matLineMagenta ), [ 0.855, 0, 0.98 ], null, [ 0.125, 1, 1 ]],
  722. [ new Line( lineGeometry, matLineMagenta ), [ 0.98, 0, 0.855 ], [ 0, - Math.PI / 2, 0 ], [ 0.125, 1, 1 ]]
  723. ],
  724. XYZX: [
  725. [ new Mesh( new BoxBufferGeometry( 0.125, 0.125, 0.125 ), matWhiteTransparent.clone() ), [ 1.1, 0, 0 ]],
  726. ],*/
  727. XYZY: [
  728. [ new Mesh( new BoxBufferGeometry( 0.125, 0.125, 0.125 ), matWhiteTransparent.clone() ), [ 0, 1.1, 0 ]],
  729. ]/* ,
  730. XYZZ: [
  731. [ new Mesh( new BoxBufferGeometry( 0.125, 0.125, 0.125 ), matWhiteTransparent.clone() ), [ 0, 0, 1.1 ]],
  732. ] */
  733. };
  734. var pickerScale = {
  735. X: [
  736. [ new Mesh( new CylinderBufferGeometry( 0.2, 0, 0.8, 4, 1, false ), matInvisible ), [ 0.5, 0, 0 ], [ 0, 0, - Math.PI / 2 ]]
  737. ],
  738. Y: [
  739. [ new Mesh( new CylinderBufferGeometry( 0.2, 0, 0.8, 4, 1, false ), matInvisible ), [ 0, 0.5, 0 ]]
  740. ],
  741. Z: [
  742. [ new Mesh( new CylinderBufferGeometry( 0.2, 0, 0.8, 4, 1, false ), matInvisible ), [ 0, 0, 0.5 ], [ Math.PI / 2, 0, 0 ]]
  743. ],
  744. XY: [
  745. [ new Mesh( scaleHandleGeometry, matInvisible ), [ 0.85, 0.85, 0 ], null, [ 3, 3, 0.2 ]],
  746. ],
  747. /*YZ: [
  748. [ new Mesh( scaleHandleGeometry, matInvisible ), [ 0, 0.85, 0.85 ], null, [ 0.2, 3, 3 ]],
  749. ],
  750. XZ: [
  751. [ new Mesh( scaleHandleGeometry, matInvisible ), [ 0.85, 0, 0.85 ], null, [ 3, 0.2, 3 ]],
  752. ],
  753. XYZX: [
  754. [ new Mesh( new BoxBufferGeometry( 0.2, 0.2, 0.2 ), matInvisible ), [ 1.1, 0, 0 ]],
  755. ],*/
  756. XYZY: [
  757. [ new Mesh( new BoxBufferGeometry( 0.2, 0.2, 0.2 ), matInvisible ), [ 0, 1.1, 0 ]],
  758. ]/* ,
  759. XYZZ: [
  760. [ new Mesh( new BoxBufferGeometry( 0.2, 0.2, 0.2 ), matInvisible ), [ 0, 0, 1.1 ]],
  761. ] */
  762. };
  763. var helperScale = {
  764. X: [
  765. [ new Line( lineGeometry, matHelper.clone() ), [ - 1e3, 0, 0 ], null, [ 1e6, 1, 1 ], 'helper' ]
  766. ],
  767. Y: [
  768. [ new Line( lineGeometry, matHelper.clone() ), [ 0, - 1e3, 0 ], [ 0, 0, Math.PI / 2 ], [ 1e6, 1, 1 ], 'helper' ]
  769. ],
  770. Z: [
  771. [ new Line( lineGeometry, matHelper.clone() ), [ 0, 0, - 1e3 ], [ 0, - Math.PI / 2, 0 ], [ 1e6, 1, 1 ], 'helper' ]
  772. ]
  773. };
  774. // Creates an Object3D with gizmos described in custom hierarchy definition.
  775. var setupGizmo = function ( gizmoMap ) {
  776. var gizmo = new Object3D();
  777. for ( var name in gizmoMap ) {
  778. for ( var i = gizmoMap[ name ].length; i --; ) {
  779. var object = gizmoMap[ name ][ i ][ 0 ].clone();
  780. var position = gizmoMap[ name ][ i ][ 1 ];
  781. var rotation = gizmoMap[ name ][ i ][ 2 ];
  782. var scale = gizmoMap[ name ][ i ][ 3 ];
  783. var tag = gizmoMap[ name ][ i ][ 4 ];
  784. // name and tag properties are essential for picking and updating logic.
  785. object.name = name;
  786. object.tag = tag;
  787. if ( position ) {
  788. object.position.set( position[ 0 ], position[ 1 ], position[ 2 ] );
  789. }
  790. if ( rotation ) {
  791. object.rotation.set( rotation[ 0 ], rotation[ 1 ], rotation[ 2 ] );
  792. }
  793. if ( scale ) {
  794. object.scale.set( scale[ 0 ], scale[ 1 ], scale[ 2 ] );
  795. }
  796. object.updateMatrix();
  797. var tempGeometry = object.geometry.clone();
  798. tempGeometry.applyMatrix( object.matrix );
  799. object.geometry = tempGeometry;
  800. object.renderOrder = Infinity;
  801. object.position.set( 0, 0, 0 );
  802. object.rotation.set( 0, 0, 0 );
  803. object.scale.set( 1, 1, 1 );
  804. gizmo.add( object );
  805. }
  806. }
  807. return gizmo;
  808. };
  809. // Reusable utility variables
  810. var tempVector = new Vector3( 0, 0, 0 );
  811. var tempEuler = new Euler();
  812. var alignVector = new Vector3( 0, 1, 0 );
  813. var zeroVector = new Vector3( 0, 0, 0 );
  814. var lookAtMatrix = new Matrix4();
  815. var tempQuaternion = new Quaternion();
  816. var tempQuaternion2 = new Quaternion();
  817. var identityQuaternion = new Quaternion();
  818. var unitX = new Vector3( 1, 0, 0 );
  819. var unitY = new Vector3( 0, 1, 0 );
  820. var unitZ = new Vector3( 0, 0, 1 );
  821. // Gizmo creation
  822. this.gizmo = {};
  823. this.picker = {};
  824. this.helper = {};
  825. this.add( this.gizmo[ "translate" ] = setupGizmo( gizmoTranslate ) );
  826. this.add( this.gizmo[ "rotate" ] = setupGizmo( gizmoRotate ) );
  827. this.add( this.gizmo[ "scale" ] = setupGizmo( gizmoScale ) );
  828. this.add( this.picker[ "translate" ] = setupGizmo( pickerTranslate ) );
  829. this.add( this.picker[ "rotate" ] = setupGizmo( pickerRotate ) );
  830. this.add( this.picker[ "scale" ] = setupGizmo( pickerScale ) );
  831. this.add( this.helper[ "translate" ] = setupGizmo( helperTranslate ) );
  832. this.add( this.helper[ "rotate" ] = setupGizmo( helperRotate ) );
  833. this.add( this.helper[ "scale" ] = setupGizmo( helperScale ) );
  834. // Pickers should be hidden always
  835. this.picker[ "translate" ].visible = false;
  836. this.picker[ "rotate" ].visible = false;
  837. this.picker[ "scale" ].visible = false;
  838. // updateMatrixWorld will update transformations and appearance of individual handles
  839. this.updateMatrixWorld = function () {
  840. var space = this.space;
  841. if ( this.mode === 'scale' ) space = 'local'; // scale always oriented to local rotation
  842. var quaternion = space === "local" ? this.worldQuaternion : identityQuaternion;
  843. // Show only gizmos for current transform mode
  844. this.gizmo[ "translate" ].visible = this.mode === "translate";
  845. this.gizmo[ "rotate" ].visible = this.mode === "rotate";
  846. this.gizmo[ "scale" ].visible = this.mode === "scale";
  847. this.helper[ "translate" ].visible = this.mode === "translate";
  848. this.helper[ "rotate" ].visible = this.mode === "rotate";
  849. this.helper[ "scale" ].visible = this.mode === "scale";
  850. var handles = [];
  851. handles = handles.concat( this.picker[ this.mode ].children );
  852. handles = handles.concat( this.gizmo[ this.mode ].children );
  853. handles = handles.concat( this.helper[ this.mode ].children );
  854. for ( var i = 0; i < handles.length; i ++ ) {
  855. var handle = handles[ i ];
  856. // hide aligned to camera
  857. handle.visible = true;
  858. handle.rotation.set( 0, 0, 0 );
  859. handle.position.copy( this.worldPosition );
  860. var eyeDistance = this.worldPosition.distanceTo( this.cameraPosition );
  861. //俯视图的透视和距离无关,因此在两种相机切换切换时大小过渡比较困难
  862. if(player.mode == "transitioning" && (player.modeTran.split('-')[0] == "floorplan" || player.modeTran.split('-')[1] == "floorplan")){
  863. eyeDistance = Math.min(eyeDistance, 6.5)//从一开始很小的距离过渡到俯视图50的高度,会变得很大。
  864. }else if(player.mode == "floorplan"){
  865. var flcamera = player.cameraControls.cameras.floorplan;
  866. eyeDistance = (flcamera.right - flcamera.left ) / flcamera.aspect ;
  867. }
  868. handle.scale.set( 1, 1, 1 ).multiplyScalar( eyeDistance * this.size / 7 );
  869. // TODO: simplify helpers and consider decoupling from gizmo
  870. if ( handle.tag === 'helper' ) {
  871. handle.visible = false;
  872. if ( handle.name === 'AXIS' ) {
  873. handle.position.copy( this.worldPositionStart );
  874. handle.visible = !! this.axis;
  875. if ( this.axis === 'X' ) {
  876. tempQuaternion.setFromEuler( tempEuler.set( 0, 0, 0 ) );
  877. handle.quaternion.copy( quaternion ).multiply( tempQuaternion );
  878. if ( Math.abs( alignVector.copy( unitX ).applyQuaternion( quaternion ).dot( this.eye ) ) > 0.9 ) {
  879. handle.visible = false;
  880. }
  881. }
  882. if ( this.axis === 'Y' ) {
  883. tempQuaternion.setFromEuler( tempEuler.set( 0, 0, Math.PI / 2 ) );
  884. handle.quaternion.copy( quaternion ).multiply( tempQuaternion );
  885. if ( Math.abs( alignVector.copy( unitY ).applyQuaternion( quaternion ).dot( this.eye ) ) > 0.9 ) {
  886. handle.visible = false;
  887. }
  888. }
  889. if ( this.axis === 'Z' ) {
  890. tempQuaternion.setFromEuler( tempEuler.set( 0, Math.PI / 2, 0 ) );
  891. handle.quaternion.copy( quaternion ).multiply( tempQuaternion );
  892. if ( Math.abs( alignVector.copy( unitZ ).applyQuaternion( quaternion ).dot( this.eye ) ) > 0.9 ) {
  893. handle.visible = false;
  894. }
  895. }
  896. if ( this.axis === 'XYZE' ) {
  897. tempQuaternion.setFromEuler( tempEuler.set( 0, Math.PI / 2, 0 ) );
  898. alignVector.copy( this.rotationAxis );
  899. handle.quaternion.setFromRotationMatrix( lookAtMatrix.lookAt( zeroVector, alignVector, unitY ) );
  900. handle.quaternion.multiply( tempQuaternion );
  901. handle.visible = this.dragging;
  902. }
  903. if ( this.axis === 'E' ) {
  904. handle.visible = false;
  905. }
  906. } else if ( handle.name === 'START' ) {
  907. handle.position.copy( this.worldPositionStart );
  908. handle.visible = this.dragging;
  909. } else if ( handle.name === 'END' ) {
  910. handle.position.copy( this.worldPosition );
  911. handle.visible = this.dragging;
  912. } else if ( handle.name === 'DELTA' ) {
  913. handle.position.copy( this.worldPositionStart );
  914. handle.quaternion.copy( this.worldQuaternionStart );
  915. tempVector.set( 1e-10, 1e-10, 1e-10 ).add( this.worldPositionStart ).sub( this.worldPosition ).multiplyScalar( - 1 );
  916. tempVector.applyQuaternion( this.worldQuaternionStart.clone().inverse() );
  917. handle.scale.copy( tempVector );
  918. handle.visible = this.dragging;
  919. } else {
  920. handle.quaternion.copy( quaternion );
  921. if ( this.dragging ) {
  922. handle.position.copy( this.worldPositionStart );
  923. } else {
  924. handle.position.copy( this.worldPosition );
  925. }
  926. if ( this.axis ) {
  927. handle.visible = this.axis.search( handle.name ) !== - 1;
  928. }
  929. }
  930. // If updating helper, skip rest of the loop
  931. continue;
  932. }
  933. // Align handles to current local or world rotation
  934. handle.quaternion.copy( quaternion );
  935. if ( this.mode === 'translate' || this.mode === 'scale' ) {
  936. // Hide translate and scale axis facing the camera
  937. var AXIS_HIDE_TRESHOLD = 0.99;
  938. var PLANE_HIDE_TRESHOLD = 0.2;
  939. var AXIS_FLIP_TRESHOLD = 0.0;
  940. if(options.dontHideWhenFaceCamera){//xzw add
  941. //正对镜头时不隐藏箭头
  942. }else{
  943. if ( handle.name === 'X' || handle.name === 'XYZX' ) {
  944. if ( Math.abs( alignVector.copy( unitX ).applyQuaternion( quaternion ).dot( this.eye ) ) > AXIS_HIDE_TRESHOLD ) {
  945. handle.scale.set( 1e-10, 1e-10, 1e-10 );
  946. handle.visible = false;
  947. }
  948. }
  949. if ( handle.name === 'Y' || handle.name === 'XYZY' ) {
  950. if ( Math.abs( alignVector.copy( unitY ).applyQuaternion( quaternion ).dot( this.eye ) ) > AXIS_HIDE_TRESHOLD ) {
  951. handle.scale.set( 1e-10, 1e-10, 1e-10 );
  952. handle.visible = false;
  953. }
  954. }
  955. if ( handle.name === 'Z' || handle.name === 'XYZZ' ) {
  956. if ( Math.abs( alignVector.copy( unitZ ).applyQuaternion( quaternion ).dot( this.eye ) ) > AXIS_HIDE_TRESHOLD ) {
  957. handle.scale.set( 1e-10, 1e-10, 1e-10 );
  958. handle.visible = false;
  959. }
  960. }
  961. if ( handle.name === 'XY' ) {
  962. if ( Math.abs( alignVector.copy( unitZ ).applyQuaternion( quaternion ).dot( this.eye ) ) < PLANE_HIDE_TRESHOLD ) {
  963. handle.scale.set( 1e-10, 1e-10, 1e-10 );
  964. handle.visible = false;
  965. }
  966. }
  967. if ( handle.name === 'YZ' ) {
  968. if ( Math.abs( alignVector.copy( unitX ).applyQuaternion( quaternion ).dot( this.eye ) ) < PLANE_HIDE_TRESHOLD ) {
  969. handle.scale.set( 1e-10, 1e-10, 1e-10 );
  970. handle.visible = false;
  971. }
  972. }
  973. if ( handle.name === 'XZ' ) {
  974. if ( Math.abs( alignVector.copy( unitY ).applyQuaternion( quaternion ).dot( this.eye ) ) < PLANE_HIDE_TRESHOLD ) {
  975. handle.scale.set( 1e-10, 1e-10, 1e-10 );
  976. handle.visible = false;
  977. }
  978. }
  979. }
  980. // Flip translate and scale axis ocluded behind another axis
  981. //xzw 改 去掉反向箭头
  982. if ( handle.name.search( 'X' ) !== - 1 ) {
  983. if ( alignVector.copy( unitX ).applyQuaternion( quaternion ).dot( this.eye ) < AXIS_FLIP_TRESHOLD ) {
  984. /* if ( handle.tag === 'fwd' ) {
  985. handle.visible = false;
  986. } else {
  987. handle.scale.x *= - 1;
  988. }
  989. } else if ( handle.tag === 'bwd' ) {
  990. handle.visible = false;*/
  991. handle.scale.x *= - 1;
  992. }
  993. }
  994. if ( handle.name.search( 'Y' ) !== - 1 ) {
  995. if ( alignVector.copy( unitY ).applyQuaternion( quaternion ).dot( this.eye ) < AXIS_FLIP_TRESHOLD ) {
  996. /* if ( handle.tag === 'fwd' ) {
  997. handle.visible = false;
  998. } else {
  999. handle.scale.y *= - 1;
  1000. }
  1001. } else if ( handle.tag === 'bwd' ) {
  1002. handle.visible = false;
  1003. */
  1004. handle.scale.y *= - 1;
  1005. }
  1006. }
  1007. if ( handle.name.search( 'Z' ) !== - 1 ) {
  1008. if ( alignVector.copy( unitZ ).applyQuaternion( quaternion ).dot( this.eye ) < AXIS_FLIP_TRESHOLD ) {
  1009. /* if ( handle.tag === 'fwd' ) {
  1010. handle.visible = false;
  1011. } else {
  1012. handle.scale.z *= - 1;
  1013. }
  1014. } else if ( handle.tag === 'bwd' ) {
  1015. handle.visible = false; */
  1016. handle.scale.z *= - 1;
  1017. }
  1018. }
  1019. } else if ( this.mode === 'rotate' ) {
  1020. // Align handles to current local or world rotation
  1021. tempQuaternion2.copy( quaternion );
  1022. alignVector.copy( this.eye ).applyQuaternion( tempQuaternion.copy( quaternion ).inverse() );
  1023. if ( handle.name.search( "E" ) !== - 1 ) {
  1024. handle.quaternion.setFromRotationMatrix( lookAtMatrix.lookAt( this.eye, zeroVector, unitY ) );
  1025. }
  1026. if ( handle.name === 'X' ) {
  1027. tempQuaternion.setFromAxisAngle( unitX, Math.atan2( - alignVector.y, alignVector.z ) );
  1028. tempQuaternion.multiplyQuaternions( tempQuaternion2, tempQuaternion );
  1029. handle.quaternion.copy( tempQuaternion );
  1030. }
  1031. if ( handle.name === 'Y' ) {
  1032. tempQuaternion.setFromAxisAngle( unitY, Math.atan2( alignVector.x, alignVector.z ) );
  1033. tempQuaternion.multiplyQuaternions( tempQuaternion2, tempQuaternion );
  1034. handle.quaternion.copy( tempQuaternion );
  1035. }
  1036. if ( handle.name === 'Z' ) {
  1037. tempQuaternion.setFromAxisAngle( unitZ, Math.atan2( alignVector.y, alignVector.x ) );
  1038. tempQuaternion.multiplyQuaternions( tempQuaternion2, tempQuaternion );
  1039. handle.quaternion.copy( tempQuaternion );
  1040. }
  1041. }
  1042. // Hide disabled axes
  1043. handle.visible = handle.visible && ( handle.name.indexOf( "X" ) === - 1 || this.showX );
  1044. handle.visible = handle.visible && ( handle.name.indexOf( "Y" ) === - 1 || this.showY );
  1045. handle.visible = handle.visible && ( handle.name.indexOf( "Z" ) === - 1 || this.showZ );
  1046. handle.visible = handle.visible && ( handle.name.indexOf( "E" ) === - 1 || ( this.showX && this.showY && this.showZ ) );
  1047. // highlight selected axis
  1048. handle.material._opacity = handle.material._opacity || handle.material.opacity;
  1049. handle.material._color = handle.material._color || handle.material.color.clone();
  1050. handle.material.color.copy( handle.material._color );
  1051. handle.material.opacity = handle.material._opacity;
  1052. if ( ! this.enabled ) {
  1053. handle.material.opacity *= 0.5;
  1054. handle.material.color.lerp( new Color( 1, 1, 1 ), 0.5 );
  1055. } else if ( this.axis ) {
  1056. if ( handle.name === this.axis ) {
  1057. handle.material.opacity = 1.0;
  1058. handle.material.color.lerp( new Color( 1, 1, 1 ), 0.5 );
  1059. } else if ( this.axis.split( '' ).some( function ( a ) {
  1060. return handle.name === a;
  1061. } ) ) {
  1062. handle.material.opacity = 1.0;
  1063. handle.material.color.lerp( new Color( 1, 1, 1 ), 0.5 );
  1064. } else {
  1065. handle.material.opacity *= 0.25;
  1066. handle.material.color.lerp( new Color( 1, 1, 1 ), 0.5 );
  1067. }
  1068. }
  1069. }
  1070. Object3D.prototype.updateMatrixWorld.call( this );
  1071. };
  1072. };
  1073. var TransformControlsPlane = function (options) {
  1074. 'use strict';
  1075. Mesh.call( this,
  1076. new PlaneBufferGeometry( 100000, 100000, 2, 2 ),
  1077. new MeshBasicMaterial( { color: "#ff0000", visible: false, wireframe: false, side: DoubleSide, transparent: true, opacity: 0.2 } )
  1078. );
  1079. this.type = 'TransformControlsPlane';
  1080. var unitX = new Vector3( 1, 0, 0 );
  1081. var unitY = new Vector3( 0, 1, 0 );
  1082. var unitZ = new Vector3( 0, 0, 1 );
  1083. var tempVector = new Vector3();
  1084. var dirVector = new Vector3();
  1085. var alignVector = new Vector3();
  1086. var tempMatrix = new Matrix4();
  1087. var identityQuaternion = new Quaternion();
  1088. this.updateMatrixWorld = function () {
  1089. var space = this.space;
  1090. this.position.copy( this.worldPosition );
  1091. if ( this.mode === 'scale' ) space = 'local'; // scale always oriented to local rotation
  1092. unitX.set( 1, 0, 0 ).applyQuaternion( space === "local" ? this.worldQuaternion : identityQuaternion );
  1093. unitY.set( 0, 1, 0 ).applyQuaternion( space === "local" ? this.worldQuaternion : identityQuaternion );
  1094. unitZ.set( 0, 0, 1 ).applyQuaternion( space === "local" ? this.worldQuaternion : identityQuaternion );
  1095. // Align the plane for current transform mode, axis and space.
  1096. alignVector.copy( unitY );
  1097. switch ( this.mode ) {
  1098. case 'translate':
  1099. case 'scale':
  1100. switch ( this.axis ) {
  1101. case 'X':
  1102. alignVector.copy( this.eye ).cross( unitX );
  1103. dirVector.copy( unitX ).cross( alignVector );
  1104. break;
  1105. case 'Y':
  1106. alignVector.copy( this.eye ).cross( unitY );
  1107. dirVector.copy( unitY ).cross( alignVector );
  1108. break;
  1109. case 'Z':
  1110. alignVector.copy( this.eye ).cross( unitZ );
  1111. dirVector.copy( unitZ ).cross( alignVector );
  1112. break;
  1113. case 'XY':
  1114. dirVector.copy( unitZ );
  1115. break;
  1116. case 'YZ':
  1117. dirVector.copy( unitX );
  1118. break;
  1119. case 'XZ':
  1120. alignVector.copy( unitZ );
  1121. dirVector.copy( unitY );
  1122. break;
  1123. case 'XYZ':
  1124. case 'E':
  1125. default: //xzw add for scale xyzz
  1126. dirVector.set( 0, 0, 0 );
  1127. break;
  1128. }
  1129. break;
  1130. case 'rotate':
  1131. default:
  1132. // special case for rotate
  1133. dirVector.set( 0, 0, 0 );
  1134. }
  1135. if ( dirVector.length() === 0 ) {
  1136. // If in rotate mode, make the plane parallel to camera
  1137. this.quaternion.copy( this.cameraQuaternion );
  1138. } else {
  1139. tempMatrix.lookAt( tempVector.set( 0, 0, 0 ), dirVector, alignVector );
  1140. this.quaternion.setFromRotationMatrix( tempMatrix );
  1141. }
  1142. Object3D.prototype.updateMatrixWorld.call( this );
  1143. };
  1144. };
  1145. //export { TransformControls, TransformControlsGizmo, TransformControlsPlane };
  1146. TransformControls.init = function(THREE){
  1147. BoxBufferGeometry = THREE.BoxBufferGeometry,
  1148. BufferGeometry = THREE.BufferGeometry,
  1149. Color = THREE.Color,
  1150. CylinderBufferGeometry = THREE.CylinderBufferGeometry,
  1151. DoubleSide = THREE.DoubleSide,
  1152. Euler = THREE.Euler,
  1153. Float32BufferAttribute = THREE.Float32BufferAttribute,
  1154. Line = THREE.Line,
  1155. LineBasicMaterial = THREE.LineBasicMaterial,
  1156. Matrix4 = THREE.Matrix4,
  1157. Mesh = THREE.Mesh,
  1158. MeshBasicMaterial = THREE.MeshBasicMaterial,
  1159. Object3D = THREE.Object3D,
  1160. //OctahedronBufferGeometry = THREE.OctahedronBufferGeometry,
  1161. PlaneBufferGeometry = THREE.PlaneBufferGeometry,
  1162. Quaternion = THREE.Quaternion,
  1163. Raycaster = THREE.Raycaster,
  1164. SphereBufferGeometry = THREE.SphereBufferGeometry,
  1165. TorusBufferGeometry = THREE.TorusBufferGeometry,
  1166. Vector3 = THREE.Vector3;
  1167. Vector2 = THREE.Vector2;
  1168. TransformControls.prototype = Object.assign( Object.create( Object3D.prototype ), {
  1169. constructor: TransformControls,
  1170. isTransformControls: true
  1171. } );
  1172. TransformControlsGizmo.prototype = Object.assign( Object.create( Object3D.prototype ), {
  1173. constructor: TransformControlsGizmo,
  1174. isTransformControlsGizmo: true
  1175. } );
  1176. TransformControlsPlane.prototype = Object.assign( Object.create( Mesh.prototype ), {
  1177. constructor: TransformControlsPlane,
  1178. isTransformControlsPlane: true
  1179. } );
  1180. //----------
  1181. function PolyhedronBufferGeometry( vertices, indices, radius, detail ) {
  1182. BufferGeometry.call( this );
  1183. this.type = 'PolyhedronBufferGeometry';
  1184. this.parameters = {
  1185. vertices: vertices,
  1186. indices: indices,
  1187. radius: radius,
  1188. detail: detail
  1189. };
  1190. radius = radius || 1;
  1191. detail = detail || 0;
  1192. // default buffer data
  1193. var vertexBuffer = [];
  1194. var uvBuffer = [];
  1195. // the subdivision creates the vertex buffer data
  1196. subdivide( detail );
  1197. // all vertices should lie on a conceptual sphere with a given radius
  1198. appplyRadius( radius );
  1199. // finally, create the uv data
  1200. generateUVs();
  1201. // build non-indexed geometry
  1202. this.addAttribute("position", new THREE.BufferAttribute(new Float32Array(vertexBuffer), 3 ))
  1203. this.addAttribute( 'normal', new THREE.BufferAttribute( new Float32Array(vertexBuffer), 3 ) );
  1204. this.addAttribute( 'uv', new THREE.BufferAttribute( new Float32Array(uvBuffer), 2 ) );
  1205. if ( detail === 0 ) {
  1206. this.computeVertexNormals(); // flat normals
  1207. } else {
  1208. this.normalizeNormals(); // smooth normals
  1209. }
  1210. // helper functions
  1211. function subdivide( detail ) {
  1212. var a = new Vector3();
  1213. var b = new Vector3();
  1214. var c = new Vector3();
  1215. // iterate over all faces and apply a subdivison with the given detail value
  1216. for ( var i = 0; i < indices.length; i += 3 ) {
  1217. // get the vertices of the face
  1218. getVertexByIndex( indices[ i + 0 ], a );
  1219. getVertexByIndex( indices[ i + 1 ], b );
  1220. getVertexByIndex( indices[ i + 2 ], c );
  1221. // perform subdivision
  1222. subdivideFace( a, b, c, detail );
  1223. }
  1224. }
  1225. function subdivideFace( a, b, c, detail ) {
  1226. var cols = Math.pow( 2, detail );
  1227. // we use this multidimensional array as a data structure for creating the subdivision
  1228. var v = [];
  1229. var i, j;
  1230. // construct all of the vertices for this subdivision
  1231. for ( i = 0; i <= cols; i ++ ) {
  1232. v[ i ] = [];
  1233. var aj = a.clone().lerp( c, i / cols );
  1234. var bj = b.clone().lerp( c, i / cols );
  1235. var rows = cols - i;
  1236. for ( j = 0; j <= rows; j ++ ) {
  1237. if ( j === 0 && i === cols ) {
  1238. v[ i ][ j ] = aj;
  1239. } else {
  1240. v[ i ][ j ] = aj.clone().lerp( bj, j / rows );
  1241. }
  1242. }
  1243. }
  1244. // construct all of the faces
  1245. for ( i = 0; i < cols; i ++ ) {
  1246. for ( j = 0; j < 2 * ( cols - i ) - 1; j ++ ) {
  1247. var k = Math.floor( j / 2 );
  1248. if ( j % 2 === 0 ) {
  1249. pushVertex( v[ i ][ k + 1 ] );
  1250. pushVertex( v[ i + 1 ][ k ] );
  1251. pushVertex( v[ i ][ k ] );
  1252. } else {
  1253. pushVertex( v[ i ][ k + 1 ] );
  1254. pushVertex( v[ i + 1 ][ k + 1 ] );
  1255. pushVertex( v[ i + 1 ][ k ] );
  1256. }
  1257. }
  1258. }
  1259. }
  1260. function appplyRadius( radius ) {
  1261. var vertex = new Vector3();
  1262. // iterate over the entire buffer and apply the radius to each vertex
  1263. for ( var i = 0; i < vertexBuffer.length; i += 3 ) {
  1264. vertex.x = vertexBuffer[ i + 0 ];
  1265. vertex.y = vertexBuffer[ i + 1 ];
  1266. vertex.z = vertexBuffer[ i + 2 ];
  1267. vertex.normalize().multiplyScalar( radius );
  1268. vertexBuffer[ i + 0 ] = vertex.x;
  1269. vertexBuffer[ i + 1 ] = vertex.y;
  1270. vertexBuffer[ i + 2 ] = vertex.z;
  1271. }
  1272. }
  1273. function generateUVs() {
  1274. var vertex = new Vector3();
  1275. for ( var i = 0; i < vertexBuffer.length; i += 3 ) {
  1276. vertex.x = vertexBuffer[ i + 0 ];
  1277. vertex.y = vertexBuffer[ i + 1 ];
  1278. vertex.z = vertexBuffer[ i + 2 ];
  1279. var u = azimuth( vertex ) / 2 / Math.PI + 0.5;
  1280. var v = inclination( vertex ) / Math.PI + 0.5;
  1281. uvBuffer.push( u, 1 - v );
  1282. }
  1283. correctUVs();
  1284. correctSeam();
  1285. }
  1286. function correctSeam() {
  1287. // handle case when face straddles the seam, see #3269
  1288. for ( var i = 0; i < uvBuffer.length; i += 6 ) {
  1289. // uv data of a single face
  1290. var x0 = uvBuffer[ i + 0 ];
  1291. var x1 = uvBuffer[ i + 2 ];
  1292. var x2 = uvBuffer[ i + 4 ];
  1293. var max = Math.max( x0, x1, x2 );
  1294. var min = Math.min( x0, x1, x2 );
  1295. // 0.9 is somewhat arbitrary
  1296. if ( max > 0.9 && min < 0.1 ) {
  1297. if ( x0 < 0.2 ) uvBuffer[ i + 0 ] += 1;
  1298. if ( x1 < 0.2 ) uvBuffer[ i + 2 ] += 1;
  1299. if ( x2 < 0.2 ) uvBuffer[ i + 4 ] += 1;
  1300. }
  1301. }
  1302. }
  1303. function pushVertex( vertex ) {
  1304. vertexBuffer.push( vertex.x, vertex.y, vertex.z );
  1305. }
  1306. function getVertexByIndex( index, vertex ) {
  1307. var stride = index * 3;
  1308. vertex.x = vertices[ stride + 0 ];
  1309. vertex.y = vertices[ stride + 1 ];
  1310. vertex.z = vertices[ stride + 2 ];
  1311. }
  1312. function correctUVs() {
  1313. var a = new Vector3();
  1314. var b = new Vector3();
  1315. var c = new Vector3();
  1316. var centroid = new Vector3();
  1317. var uvA = new Vector2();
  1318. var uvB = new Vector2();
  1319. var uvC = new Vector2();
  1320. for ( var i = 0, j = 0; i < vertexBuffer.length; i += 9, j += 6 ) {
  1321. a.set( vertexBuffer[ i + 0 ], vertexBuffer[ i + 1 ], vertexBuffer[ i + 2 ] );
  1322. b.set( vertexBuffer[ i + 3 ], vertexBuffer[ i + 4 ], vertexBuffer[ i + 5 ] );
  1323. c.set( vertexBuffer[ i + 6 ], vertexBuffer[ i + 7 ], vertexBuffer[ i + 8 ] );
  1324. uvA.set( uvBuffer[ j + 0 ], uvBuffer[ j + 1 ] );
  1325. uvB.set( uvBuffer[ j + 2 ], uvBuffer[ j + 3 ] );
  1326. uvC.set( uvBuffer[ j + 4 ], uvBuffer[ j + 5 ] );
  1327. centroid.copy( a ).add( b ).add( c ).divideScalar( 3 );
  1328. var azi = azimuth( centroid );
  1329. correctUV( uvA, j + 0, a, azi );
  1330. correctUV( uvB, j + 2, b, azi );
  1331. correctUV( uvC, j + 4, c, azi );
  1332. }
  1333. }
  1334. function correctUV( uv, stride, vector, azimuth ) {
  1335. if ( ( azimuth < 0 ) && ( uv.x === 1 ) ) {
  1336. uvBuffer[ stride ] = uv.x - 1;
  1337. }
  1338. if ( ( vector.x === 0 ) && ( vector.z === 0 ) ) {
  1339. uvBuffer[ stride ] = azimuth / 2 / Math.PI + 0.5;
  1340. }
  1341. }
  1342. // Angle around the Y axis, counter-clockwise when looking from above.
  1343. function azimuth( vector ) {
  1344. return Math.atan2( vector.z, - vector.x );
  1345. }
  1346. // Angle above the XZ plane.
  1347. function inclination( vector ) {
  1348. return Math.atan2( - vector.y, Math.sqrt( ( vector.x * vector.x ) + ( vector.z * vector.z ) ) );
  1349. }
  1350. }
  1351. PolyhedronBufferGeometry.prototype = Object.create( BufferGeometry.prototype );
  1352. PolyhedronBufferGeometry.prototype.constructor = PolyhedronBufferGeometry;
  1353. OctahedronBufferGeometry = function( radius, detail ) {
  1354. var vertices = [
  1355. 1, 0, 0, - 1, 0, 0, 0, 1, 0,
  1356. 0, - 1, 0, 0, 0, 1, 0, 0, - 1
  1357. ];
  1358. var indices = [
  1359. 0, 2, 4, 0, 4, 3, 0, 3, 5,
  1360. 0, 5, 2, 1, 2, 5, 1, 5, 3,
  1361. 1, 3, 4, 1, 4, 2
  1362. ];
  1363. PolyhedronBufferGeometry.call( this, vertices, indices, radius, detail );
  1364. this.type = 'OctahedronBufferGeometry';
  1365. this.parameters = {
  1366. radius: radius,
  1367. detail: detail
  1368. };
  1369. }
  1370. OctahedronBufferGeometry.prototype = Object.create( PolyhedronBufferGeometry.prototype );
  1371. OctahedronBufferGeometry.prototype.constructor = OctahedronBufferGeometry;
  1372. }
  1373. window.TransformControls = TransformControls;
  1374. }()