@xeokit/xeokit-sdk 2.4.2-beta-15 → 2.4.2-beta-20
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/xeokit-sdk.cjs.js +308 -250
- package/dist/xeokit-sdk.es.js +308 -250
- package/dist/xeokit-sdk.es5.js +41 -30
- package/dist/xeokit-sdk.min.cjs.js +3 -3
- package/dist/xeokit-sdk.min.es.js +2 -2
- package/dist/xeokit-sdk.min.es5.js +2 -2
- package/package.json +1 -1
- package/src/extras/PointerLens/PointerLens.js +21 -21
- package/src/plugins/AngleMeasurementsPlugin/AngleMeasurementsMouseControl.js +10 -9
- package/src/plugins/DistanceMeasurementsPlugin/DistanceMeasurementsMouseControl.js +9 -8
- package/src/viewer/scene/CameraControl/lib/controllers/PickController.js +15 -7
- package/src/viewer/scene/scene/Scene.js +22 -3
- package/src/viewer/scene/webgl/PickResult.js +27 -2
- package/src/viewer/scene/webgl/Renderer.js +212 -207
package/dist/xeokit-sdk.es5.js
CHANGED
|
@@ -389,18 +389,18 @@ menuElement.style.display='block';var menuHeight=menuElement.offsetHeight;var me
|
|
|
389
389
|
* @param [cfg.active=true] Whether PointerLens is active. The PointerLens can only be shown when this is `true` (default).
|
|
390
390
|
*/function PointerLens(viewer){var _this6=this;var cfg=arguments.length>1&&arguments[1]!==undefined?arguments[1]:{};_classCallCheck(this,PointerLens);this.viewer=viewer;this.scene=this.viewer.scene;this._lensCursorDiv=document.createElement('div');this.viewer.scene.canvas.canvas.parentNode.insertBefore(this._lensCursorDiv,this.viewer.scene.canvas.canvas);this._lensCursorDiv.style.background="pink";this._lensCursorDiv.style.border="2px solid red";this._lensCursorDiv.style.borderRadius="20px";this._lensCursorDiv.style.width="10px";this._lensCursorDiv.style.height="10px";this._lensCursorDiv.style.margin="-200px -200px";this._lensCursorDiv.style.zIndex="100000";this._lensCursorDiv.style.position="absolute";this._lensCursorDiv.style.pointerEvents="none";this._lensContainer=document.createElement('div');this._lensContainer.style.border="1px solid black";this._lensContainer.style.background="white";// this._lensContainer.style.opacity = "0";
|
|
391
391
|
this._lensContainer.style.borderRadius="50%";this._lensContainer.style.width="300px";this._lensContainer.style.height="300px";this._lensContainer.style.marginTop="85px";this._lensContainer.style.marginLeft="25px";this._lensContainer.style.zIndex="15000";this._lensContainer.style.position="absolute";this._lensContainer.style.pointerEvents="none";this._lensContainer.style.visibility="hidden";this._lensCanvas=document.createElement('canvas');// this._lensCanvas.style.background = "darkblue";
|
|
392
|
-
this._lensCanvas.style.borderRadius="50%";this._lensCanvas.style.width="300px";this._lensCanvas.style.height="300px";this._lensCanvas.style.zIndex="15000";this._lensCanvas.style.pointerEvents="none";document.body.appendChild(this._lensContainer);this._lensContainer.appendChild(this._lensCanvas);this._lensCanvasContext=this._lensCanvas.getContext('2d');this._canvasElement=this.viewer.scene.canvas.canvas;this.
|
|
392
|
+
this._lensCanvas.style.borderRadius="50%";this._lensCanvas.style.width="300px";this._lensCanvas.style.height="300px";this._lensCanvas.style.zIndex="15000";this._lensCanvas.style.pointerEvents="none";document.body.appendChild(this._lensContainer);this._lensContainer.appendChild(this._lensCanvas);this._lensCanvasContext=this._lensCanvas.getContext('2d');this._canvasElement=this.viewer.scene.canvas.canvas;this._canvasPos=null;this._snappedCanvasPos=null;this._lensPosToggle=true;this._zoomLevel=cfg.zoomLevel||2;this._active=cfg.active!==false;this._visible=false;this._snapped=false;this._onViewerRendering=this.viewer.scene.on("rendering",function(){if(_this6._active&&_this6._visible){_this6.update();}});}/**
|
|
393
393
|
* Updates this PointerLens.
|
|
394
|
-
*/_createClass(PointerLens,[{key:"update",value:function update(){if(!this._active||!this._visible){return;}if(!this.
|
|
395
|
-
this.
|
|
396
|
-
this.
|
|
394
|
+
*/_createClass(PointerLens,[{key:"update",value:function update(){if(!this._active||!this._visible){return;}if(!this._canvasPos){return;}var lensRect=this._lensContainer.getBoundingClientRect();var canvasRect=this._canvasElement.getBoundingClientRect();var pointerOnLens=this._canvasPos[0]<lensRect.right&&this._canvasPos[0]>lensRect.left&&this._canvasPos[1]<lensRect.bottom&&this._canvasPos[1]>lensRect.top;this._lensContainer.style.marginLeft="25px";if(pointerOnLens){if(this._lensPosToggle){this._lensContainer.style.marginTop="".concat(canvasRect.bottom-canvasRect.top-this._lensCanvas.height-85,"px");}else{this._lensContainer.style.marginTop="85px";}this._lensPosToggle=!this._lensPosToggle;}this._lensCanvasContext.clearRect(0,0,this._lensCanvas.width,this._lensCanvas.height);var size=Math.max(this._lensCanvas.width,this._lensCanvas.height)/this._zoomLevel;this._lensCanvasContext.drawImage(this._canvasElement,// source canvas
|
|
395
|
+
this._canvasPos[0]-size/2,// source x (zoom center)
|
|
396
|
+
this._canvasPos[1]-size/2,// source y (zoom center)
|
|
397
397
|
size,// source width
|
|
398
398
|
size,// source height
|
|
399
399
|
0,// destination x
|
|
400
400
|
0,// destination y
|
|
401
401
|
this._lensCanvas.width,// destination width
|
|
402
402
|
this._lensCanvas.height// destination height
|
|
403
|
-
);var centerLensCanvas=[(lensRect.left+lensRect.right)/2,(lensRect.top+lensRect.bottom)/2];if(this.
|
|
403
|
+
);var centerLensCanvas=[(lensRect.left+lensRect.right)/2,(lensRect.top+lensRect.bottom)/2];if(this._snappedCanvasPos){var deltaX=this._snappedCanvasPos[0]-this._canvasPos[0];var deltaY=this._snappedCanvasPos[1]-this._canvasPos[1];this._lensCursorDiv.style.marginLeft="".concat(centerLensCanvas[0]+deltaX*this._zoomLevel-10,"px");this._lensCursorDiv.style.marginTop="".concat(centerLensCanvas[1]+deltaY*this._zoomLevel-10,"px");}else{this._lensCursorDiv.style.marginLeft="".concat(centerLensCanvas[0]-10,"px");this._lensCursorDiv.style.marginTop="".concat(centerLensCanvas[1]-10,"px");}}/**
|
|
404
404
|
* Sets the zoom factor for the lens.
|
|
405
405
|
*
|
|
406
406
|
* This is `2` by default.
|
|
@@ -414,22 +414,22 @@ this._lensCanvas.height// destination height
|
|
|
414
414
|
* @returns Number
|
|
415
415
|
*/function get(){return this._zoomFactor;}/**
|
|
416
416
|
* Sets the canvas central position of the lens.
|
|
417
|
-
* @param
|
|
418
|
-
*/,set:function set(zoomFactor){this._zoomFactor=zoomFactor;this.update();}},{key:"
|
|
417
|
+
* @param canvasPos
|
|
418
|
+
*/,set:function set(zoomFactor){this._zoomFactor=zoomFactor;this.update();}},{key:"canvasPos",get:/**
|
|
419
419
|
* Gets the canvas central position of the lens.
|
|
420
420
|
* @returns {Number[]}
|
|
421
|
-
*/function get(){return this.
|
|
421
|
+
*/function get(){return this._canvasPos;}/**
|
|
422
422
|
* Sets the canvas coordinates of the pointer.
|
|
423
|
-
* @param
|
|
424
|
-
*/,set:function set(
|
|
425
|
-
* Gets the canvas coordinates of the pointer.
|
|
423
|
+
* @param snappedCanvasPos
|
|
424
|
+
*/,set:function set(canvasPos){this._canvasPos=canvasPos;this.update();}},{key:"snappedCanvasPos",get:/**
|
|
425
|
+
* Gets the canvas coordinates of the snapped pointer.
|
|
426
426
|
* @returns {Number[]}
|
|
427
|
-
*/function get(){return this.
|
|
427
|
+
*/function get(){return this._snappedCanvasPos;}/**
|
|
428
428
|
* Sets if the cursor has snapped to anything.
|
|
429
429
|
* This is set by plugins.
|
|
430
430
|
* @param snapped
|
|
431
431
|
* @private
|
|
432
|
-
*/,set:function set(
|
|
432
|
+
*/,set:function set(snappedCanvasPos){this._snappedCanvasPos=snappedCanvasPos;this.update();}},{key:"snapped",get:/**
|
|
433
433
|
* Gets if the cursor has snapped to anything.
|
|
434
434
|
* This is called by plugins.
|
|
435
435
|
* @returns {Boolean}
|
|
@@ -2979,7 +2979,7 @@ this._originDot.setVisible(this._visible&&this._originVisible);this._cornerDot.s
|
|
|
2979
2979
|
* @returns {boolean} Whether snap-to-vertex and snap-to-edge are enabled for this AngleMeasurementsMouseControl.
|
|
2980
2980
|
*/function get(){return this._snapping;}/**
|
|
2981
2981
|
* Activates this AngleMeasurementsMouseControl, ready to respond to input.
|
|
2982
|
-
*/,set:function set(snapping){if(snapping!==this._snapping){this._snapping=snapping;this.deactivate();this.activate();}else{this._snapping=snapping;}}},{key:"activate",value:function activate(){var _this19=this;if(this._active){return;}this.angleMeasurementsPlugin;var scene=this.scene;scene.input;var canvas=scene.canvas.canvas;var clickTolerance=20;var cameraControl=this.angleMeasurementsPlugin.viewer.cameraControl;var pointerLens=this.pointerLens;var mouseHovering=false;var mouseHoverEntity=false;var lastMouseCanvasX=0;var lastMouseCanvasY=0;var mouseWorldPos=math.vec3();var mouseHoverCanvasPos=math.vec2();this._currentAngleMeasurement=null;this._onMouseHoverSurface=cameraControl.on(this._snapping?"hoverSnapOrSurface":"hoverSurface",function(event){if(event.snappedToVertex||event.snappedToEdge){if(pointerLens){pointerLens.visible=true;pointerLens.
|
|
2982
|
+
*/,set:function set(snapping){if(snapping!==this._snapping){this._snapping=snapping;this.deactivate();this.activate();}else{this._snapping=snapping;}}},{key:"activate",value:function activate(){var _this19=this;if(this._active){return;}this.angleMeasurementsPlugin;var scene=this.scene;scene.input;var canvas=scene.canvas.canvas;var clickTolerance=20;var cameraControl=this.angleMeasurementsPlugin.viewer.cameraControl;var pointerLens=this.pointerLens;var mouseHovering=false;var mouseHoverEntity=false;var lastMouseCanvasX=0;var lastMouseCanvasY=0;var mouseWorldPos=math.vec3();var mouseHoverCanvasPos=math.vec2();this._currentAngleMeasurement=null;this._onMouseHoverSurface=cameraControl.on(this._snapping?"hoverSnapOrSurface":"hoverSurface",function(event){if(event.snappedToVertex||event.snappedToEdge){if(pointerLens){pointerLens.visible=true;pointerLens.canvasPos=event.canvasPos;pointerLens.snappedCanvasPos=event.snappedCanvasPos||event.canvasPos;pointerLens.snapped=true;}_this19.markerDiv.style.background="greenyellow";_this19.markerDiv.style.border="2px solid green";}else{if(pointerLens){pointerLens.visible=true;pointerLens.canvasPos=event.canvasPos;pointerLens.snappedCanvasPos=event.canvasPos;pointerLens.snapped=false;}_this19.markerDiv.style.background="pink";_this19.markerDiv.style.border="2px solid red";}var canvasPos=event.snappedCanvasPos||event.canvasPos;mouseHovering=true;mouseHoverEntity=event.entity;mouseWorldPos.set(event.worldPos);mouseHoverCanvasPos.set(canvasPos);switch(_this19._mouseState){case MOUSE_FINDING_ORIGIN:_this19.markerDiv.style.marginLeft="".concat(canvasPos[0]-5,"px");_this19.markerDiv.style.marginTop="".concat(canvasPos[1]-5,"px");break;case MOUSE_FINDING_CORNER:if(_this19._currentAngleMeasurement){_this19._currentAngleMeasurement.originWireVisible=true;_this19._currentAngleMeasurement.targetWireVisible=false;_this19._currentAngleMeasurement.cornerVisible=true;_this19._currentAngleMeasurement.angleVisible=false;_this19._currentAngleMeasurement.corner.worldPos=event.worldPos;}_this19.markerDiv.style.marginLeft="-10000px";_this19.markerDiv.style.marginTop="-10000px";canvas.style.cursor="pointer";break;case MOUSE_FINDING_TARGET:if(_this19._currentAngleMeasurement){_this19._currentAngleMeasurement.targetWireVisible=true;_this19._currentAngleMeasurement.targetVisible=true;_this19._currentAngleMeasurement.angleVisible=true;_this19._currentAngleMeasurement.target.worldPos=event.worldPos;}_this19.markerDiv.style.marginLeft="-10000px";_this19.markerDiv.style.marginTop="-10000px";canvas.style.cursor="pointer";break;}});canvas.addEventListener('mousedown',this._onMouseDown=function(e){if(e.which!==1){return;}lastMouseCanvasX=e.clientX;lastMouseCanvasY=e.clientY;});canvas.addEventListener("mouseup",this._onMouseUp=function(e){if(e.which!==1){return;}if(e.clientX>lastMouseCanvasX+clickTolerance||e.clientX<lastMouseCanvasX-clickTolerance||e.clientY>lastMouseCanvasY+clickTolerance||e.clientY<lastMouseCanvasY-clickTolerance){return;}switch(_this19._mouseState){case MOUSE_FINDING_ORIGIN:if(mouseHovering){_this19._currentAngleMeasurement=_this19.angleMeasurementsPlugin.createMeasurement({id:math.createUUID(),origin:{entity:mouseHoverEntity,worldPos:mouseWorldPos},corner:{entity:mouseHoverEntity,worldPos:mouseWorldPos},target:{entity:mouseHoverEntity,worldPos:mouseWorldPos},approximate:true});_this19._currentAngleMeasurement.clickable=false;_this19._currentAngleMeasurement.originVisible=true;_this19._currentAngleMeasurement.originWireVisible=true;_this19._currentAngleMeasurement.cornerVisible=false;_this19._currentAngleMeasurement.targetWireVisible=false;_this19._currentAngleMeasurement.targetVisible=false;_this19._currentAngleMeasurement.angleVisible=false;_this19._mouseState=MOUSE_FINDING_CORNER;_this19.angleMeasurementsPlugin.fire("measurementStart",_this19._currentAngleMeasurement);}break;case MOUSE_FINDING_CORNER:if(mouseHovering){_this19._currentAngleMeasurement.targetWireVisible=false;_this19._currentAngleMeasurement.targetVisible=true;_this19._currentAngleMeasurement.angleVisible=true;_this19._mouseState=MOUSE_FINDING_TARGET;}else{if(_this19._currentAngleMeasurement){_this19._currentAngleMeasurement.destroy();_this19._currentAngleMeasurement=null;_this19._mouseState=MOUSE_FINDING_ORIGIN;_this19.angleMeasurementsPlugin.fire("measurementCancel",_this19._currentAngleMeasurement);}}break;case MOUSE_FINDING_TARGET:if(mouseHovering){_this19._currentAngleMeasurement.targetVisible=true;_this19._currentAngleMeasurement.angleVisible=true;_this19._currentAngleMeasurement.clickable=true;_this19.angleMeasurementsPlugin.fire("measurementEnd",_this19._currentAngleMeasurement);_this19._currentAngleMeasurement=null;_this19._mouseState=MOUSE_FINDING_ORIGIN;}else{if(_this19._currentAngleMeasurement){_this19._currentAngleMeasurement.destroy();_this19._currentAngleMeasurement=null;_this19._mouseState=MOUSE_FINDING_ORIGIN;_this19.angleMeasurementsPlugin.fire("measurementCancel",_this19._currentAngleMeasurement);}}break;}});this._onMouseHoverOff=cameraControl.on(this._snapping?"hoverSnapOrSurfaceOff":"hoverOff",function(event){mouseHovering=false;if(pointerLens){pointerLens.visible=true;pointerLens.pointerPos=event.canvasPos;pointerLens.snappedCanvasPos=event.snappedCanvasPos||event.canvasPos;pointerLens.snapped=false;}_this19.markerDiv.style.marginLeft="-100px";_this19.markerDiv.style.marginTop="-100px";if(_this19._currentAngleMeasurement){switch(_this19._mouseState){case MOUSE_FINDING_ORIGIN:_this19._currentAngleMeasurement.originVisible=false;break;case MOUSE_FINDING_CORNER:_this19._currentAngleMeasurement.cornerVisible=false;_this19._currentAngleMeasurement.originWireVisible=false;_this19._currentAngleMeasurement.targetVisible=false;_this19._currentAngleMeasurement.targetWireVisible=false;_this19._currentAngleMeasurement.angleVisible=false;break;case MOUSE_FINDING_TARGET:_this19._currentAngleMeasurement.targetVisible=false;_this19._currentAngleMeasurement.targetWireVisible=false;_this19._currentAngleMeasurement.angleVisible=false;break;}canvas.style.cursor="default";}});this._active=true;}/**
|
|
2983
2983
|
* Deactivates this AngleMeasurementsMouseControl, making it unresponsive to input.
|
|
2984
2984
|
*
|
|
2985
2985
|
* Destroys any {@link AngleMeasurement} under construction by this AngleMeasurementsMouseControl.
|
|
@@ -4381,8 +4381,8 @@ this.canvas.removeEventListener("webglcontextlost",this._webglcontextlostListene
|
|
|
4381
4381
|
*/this.snappedToEdge=false;/**
|
|
4382
4382
|
* True when snapped to nearest vertex.
|
|
4383
4383
|
* @type {boolean}
|
|
4384
|
-
*/this.snappedToVertex=false;this.
|
|
4385
|
-
* Canvas coordinates
|
|
4384
|
+
*/this.snappedToVertex=false;this._origin=new Float64Array([0,0,0]);this._direction=new Float64Array([0,0,0]);this._indices=new Int32Array(3);this._localPos=new Float64Array([0,0,0]);this._worldPos=new Float64Array([0,0,0]);this._viewPos=new Float64Array([0,0,0]);this._canvasPos=new Int16Array([0,0]);this._snappedCanvasPos=new Int16Array([0,0]);this._bary=new Float64Array([0,0,0]);this._worldNormal=new Float64Array([0,0,0]);this._uv=new Float64Array([0,0]);this.reset();}/**
|
|
4385
|
+
* Canvas pick coordinates.
|
|
4386
4386
|
* @property canvasPos
|
|
4387
4387
|
* @type {Number[]}
|
|
4388
4388
|
*/_createClass(PickResult,[{key:"canvasPos",get:function get(){return this._gotCanvasPos?this._canvasPos:null;}/**
|
|
@@ -4417,6 +4417,13 @@ this.canvas.removeEventListener("webglcontextlost",this._webglcontextlostListene
|
|
|
4417
4417
|
* @private
|
|
4418
4418
|
* @param value
|
|
4419
4419
|
*/,set:function set(value){if(value){this._localPos[0]=value[0];this._localPos[1]=value[1];this._localPos[2]=value[2];this._gotLocalPos=true;}else{this._gotLocalPos=false;}}/**
|
|
4420
|
+
* Canvas cursor coordinates, snapped when snap picking, otherwise same as {@link PickResult#pointerPos}.
|
|
4421
|
+
* @property snappedCanvasPos
|
|
4422
|
+
* @type {Number[]}
|
|
4423
|
+
*/},{key:"snappedCanvasPos",get:function get(){return this._gotSnappedCanvasPos?this._snappedCanvasPos:null;}/**
|
|
4424
|
+
* @private
|
|
4425
|
+
* @param value
|
|
4426
|
+
*/,set:function set(value){if(value){this._snappedCanvasPos[0]=value[0];this._snappedCanvasPos[1]=value[1];this._gotSnappedCanvasPos=true;}else{this._gotSnappedCanvasPos=false;}}/**
|
|
4420
4427
|
* Picked World-space point.
|
|
4421
4428
|
* @property worldPos
|
|
4422
4429
|
* @type {Number[]}
|
|
@@ -4453,7 +4460,7 @@ this.canvas.removeEventListener("webglcontextlost",this._webglcontextlostListene
|
|
|
4453
4460
|
* @param value
|
|
4454
4461
|
*/,set:function set(value){if(value){this._uv[0]=value[0];this._uv[1]=value[1];this._gotUV=true;}else{this._gotUV=false;}}/**
|
|
4455
4462
|
* @private
|
|
4456
|
-
*/},{key:"reset",value:function reset(){this.entity=null;this.primIndex=-1;this.primitive=null;this.pickSurfacePrecision=false;this._gotCanvasPos=false;this._gotOrigin=false;this._gotDirection=false;this._gotIndices=false;this._gotLocalPos=false;this._gotWorldPos=false;this._gotViewPos=false;this._gotBary=false;this._gotWorldNormal=false;this._gotUV=false;this.touchInput=false;this.snappedToEdge=false;this.snappedToVertex=false;}}]);return PickResult;}();/**
|
|
4463
|
+
*/},{key:"reset",value:function reset(){this.entity=null;this.primIndex=-1;this.primitive=null;this.pickSurfacePrecision=false;this._gotCanvasPos=false;this._gotSnappedCanvasPos=false;this._gotOrigin=false;this._gotDirection=false;this._gotIndices=false;this._gotLocalPos=false;this._gotWorldPos=false;this._gotViewPos=false;this._gotBary=false;this._gotWorldNormal=false;this._gotUV=false;this.touchInput=false;this.snappedToEdge=false;this.snappedToVertex=false;}}]);return PickResult;}();/**
|
|
4457
4464
|
* @desc Represents a vertex or fragment stage within a {@link Program}.
|
|
4458
4465
|
* @private
|
|
4459
4466
|
*/var Shader=/*#__PURE__*/function(){function Shader(gl,type,source){_classCallCheck(this,Shader);this.allocated=false;this.compiled=false;this.handle=gl.createShader(type);if(!this.handle){this.errors=["Failed to allocate"];return;}this.allocated=true;gl.shaderSource(this.handle,source);gl.compileShader(this.handle);this.compiled=gl.getShaderParameter(this.handle,gl.COMPILE_STATUS);if(!this.compiled){if(!gl.isContextLost()){// Handled explicitly elsewhere, so won't re-handle here
|
|
@@ -4657,10 +4664,10 @@ var x=(canvasPos[0]-canvas.clientWidth/2)/(canvas.clientWidth/2);var y=-(canvasP
|
|
|
4657
4664
|
* @param {number} [snapRadiusInPixels=30]
|
|
4658
4665
|
* @param {boolean} [snapToVertex=true]
|
|
4659
4666
|
* @param {boolean} [snapToEdge=true]
|
|
4660
|
-
*
|
|
4661
|
-
* @returns {
|
|
4662
|
-
*/this.snapPick=function(
|
|
4663
|
-
frameCtx.pickZNear=scene.camera.project.near;frameCtx.pickZFar=scene.camera.project.far;var vertexPickBuffer=renderBufferManager.getRenderBuffer("uniquePickColors-aabs",{depthTexture:true,size:[2*snapRadiusInPixels+1,2*snapRadiusInPixels+1]});frameCtx.snapVectorA=[getClipPosX(canvasPos[0]*resolutionScale,gl.drawingBufferWidth),getClipPosY(canvasPos[1]*resolutionScale,gl.drawingBufferHeight)];frameCtx.snapInvVectorAB=[gl.drawingBufferWidth/(2*snapRadiusInPixels),gl.drawingBufferHeight/(2*snapRadiusInPixels)];// Bind and clear the snap render target
|
|
4667
|
+
* @param pickResult
|
|
4668
|
+
* @returns {PickResult}
|
|
4669
|
+
*/this.snapPick=function(){var _pickResult=new PickResult();return function(canvasPos,snapRadiusInPixels,snapToVertex,snapToEdge){var pickResult=arguments.length>4&&arguments[4]!==undefined?arguments[4]:_pickResult;if(!snapToVertex&&!snapToEdge){return this.pick({canvasPos:canvasPos,pickSurface:true});}var resolutionScale=scene.canvas.resolutionScale;frameCtx.reset();frameCtx.backfaces=true;frameCtx.frontface=true;// "ccw"
|
|
4670
|
+
frameCtx.pickZNear=scene.camera.project.near;frameCtx.pickZFar=scene.camera.project.far;snapRadiusInPixels=snapRadiusInPixels||30;var vertexPickBuffer=renderBufferManager.getRenderBuffer("uniquePickColors-aabs",{depthTexture:true,size:[2*snapRadiusInPixels+1,2*snapRadiusInPixels+1]});frameCtx.snapVectorA=[getClipPosX(canvasPos[0]*resolutionScale,gl.drawingBufferWidth),getClipPosY(canvasPos[1]*resolutionScale,gl.drawingBufferHeight)];frameCtx.snapInvVectorAB=[gl.drawingBufferWidth/(2*snapRadiusInPixels),gl.drawingBufferHeight/(2*snapRadiusInPixels)];// Bind and clear the snap render target
|
|
4664
4671
|
vertexPickBuffer.bind(gl.RGBA32I,gl.RGBA32I,gl.RGBA8UI);gl.viewport(0,0,vertexPickBuffer.size[0],vertexPickBuffer.size[1]);gl.enable(gl.DEPTH_TEST);gl.frontFace(gl.CCW);gl.disable(gl.CULL_FACE);gl.depthMask(true);gl.disable(gl.BLEND);gl.depthFunc(gl.LEQUAL);gl.clear(gl.DEPTH_BUFFER_BIT);gl.clearBufferiv(gl.COLOR,0,new Int32Array([0,0,0,0]));gl.clearBufferiv(gl.COLOR,1,new Int32Array([0,0,0,0]));gl.clearBufferuiv(gl.COLOR,2,new Uint32Array([0,0,0,0]));//////////////////////////////////
|
|
4665
4672
|
// Set view and proj mats for VBO renderers
|
|
4666
4673
|
///////////////////////////////////////
|
|
@@ -4669,10 +4676,10 @@ drawable.setPickMatrices(pickViewMatrix,pickProjMatrix);}}}}// a) init z-buffer
|
|
|
4669
4676
|
gl.drawBuffers([gl.COLOR_ATTACHMENT0,gl.COLOR_ATTACHMENT1,gl.COLOR_ATTACHMENT2]);var layerParamsSurface=snapInitDepthBuf(frameCtx);// b) snap-pick
|
|
4670
4677
|
var layerParamsSnap=[];frameCtx.snapPickLayerParams=layerParamsSnap;gl.depthMask(false);gl.drawBuffers([gl.COLOR_ATTACHMENT0]);if(snapToVertex&&snapToEdge){frameCtx.snapMode="edge";snapPickDrawSnapDepths(frameCtx);frameCtx.snapMode="vertex";frameCtx.snapPickLayerNumber++;snapPickDrawSnapDepths(frameCtx);}else{frameCtx.snapMode=snapToVertex?"vertex":"edge";snapPickDrawSnapDepths(frameCtx);}gl.depthMask(true);// Read and decode the snapped coordinates
|
|
4671
4678
|
var snapPickResultArray=vertexPickBuffer.readArray(gl.RGBA_INTEGER,gl.INT,Int32Array,4);var snapPickNormalResultArray=vertexPickBuffer.readArray(gl.RGBA_INTEGER,gl.INT,Int32Array,4,1);var snapPickIdResultArray=vertexPickBuffer.readArray(gl.RGBA_INTEGER,gl.UNSIGNED_INT,Uint32Array,4,2);vertexPickBuffer.unbind();// result 1) regular hi-precision world position
|
|
4672
|
-
var worldPos=null;var
|
|
4679
|
+
var worldPos=null;var middleX=snapRadiusInPixels;var middleY=snapRadiusInPixels;var middleIndex=middleX*4+middleY*vertexPickBuffer.size[0]*4;var pickResultMiddleXY=snapPickResultArray.slice(middleIndex,middleIndex+4);var pickNormalResultMiddleXY=snapPickNormalResultArray.slice(middleIndex,middleIndex+4);var pickPickableResultMiddleXY=snapPickIdResultArray.slice(middleIndex,middleIndex+4);if(pickResultMiddleXY[3]!==0){var pickedLayerParmasSurface=layerParamsSurface[Math.abs(pickResultMiddleXY[3])%layerParamsSurface.length];var _origin2=pickedLayerParmasSurface.origin;var _scale=pickedLayerParmasSurface.coordinateScale;worldPos=[pickResultMiddleXY[0]*_scale[0]+_origin2[0],pickResultMiddleXY[1]*_scale[1]+_origin2[1],pickResultMiddleXY[2]*_scale[2]+_origin2[2]];math.normalizeVec3([pickNormalResultMiddleXY[0]/math.MAX_INT,pickNormalResultMiddleXY[1]/math.MAX_INT,pickNormalResultMiddleXY[2]/math.MAX_INT]);var pickID=pickPickableResultMiddleXY[0]+(pickPickableResultMiddleXY[1]<<8)+(pickPickableResultMiddleXY[2]<<16)+(pickPickableResultMiddleXY[3]<<24);pickIDs.items[pickID];}// result 2) hi-precision snapped (to vertex/edge) world position
|
|
4673
4680
|
var snapPickResult=[];for(var _i71=0;_i71<snapPickResultArray.length;_i71+=4){if(snapPickResultArray[_i71+3]>0){var pixelNumber=Math.floor(_i71/4);var w=vertexPickBuffer.size[0];var x=pixelNumber%w-Math.floor(w/2);var y=Math.floor(pixelNumber/w)-Math.floor(w/2);var dist=Math.sqrt(Math.pow(x,2)+Math.pow(y,2));snapPickResult.push({x:x,y:y,dist:dist,isVertex:snapToVertex&&snapToEdge?snapPickResultArray[_i71+3]>layerParamsSnap.length/2:snapToVertex,result:[snapPickResultArray[_i71+0],snapPickResultArray[_i71+1],snapPickResultArray[_i71+2],snapPickResultArray[_i71+3]],normal:[snapPickNormalResultArray[_i71+0],snapPickNormalResultArray[_i71+1],snapPickNormalResultArray[_i71+2],snapPickNormalResultArray[_i71+3]],id:[snapPickIdResultArray[_i71+0],snapPickIdResultArray[_i71+1],snapPickIdResultArray[_i71+2],snapPickIdResultArray[_i71+3]]});}}var snappedWorldPos=null;var snappedWorldNormal=null;var snappedPickable=null;var snapType=null;if(snapPickResult.length>0){// vertex snap first, then edge snap
|
|
4674
4681
|
snapPickResult.sort(function(a,b){if(a.isVertex!==b.isVertex){return a.isVertex?-1:1;}else{return a.dist-b.dist;}});snapType=snapPickResult[0].isVertex?"vertex":"edge";var snapPick=snapPickResult[0].result;var snapPickNormal=snapPickResult[0].normal;var snapPickId=snapPickResult[0].id;var pickedLayerParmas=layerParamsSnap[snapPick[3]];var _origin3=pickedLayerParmas.origin;var _scale2=pickedLayerParmas.coordinateScale;snappedWorldNormal=math.normalizeVec3([snapPickNormal[0]/math.MAX_INT,snapPickNormal[1]/math.MAX_INT,snapPickNormal[2]/math.MAX_INT]);snappedWorldPos=[snapPick[0]*_scale2[0]+_origin3[0],snapPick[1]*_scale2[1]+_origin3[1],snapPick[2]*_scale2[2]+_origin3[2]];snappedPickable=pickIDs.items[snapPickId[0]+(snapPickId[1]<<8)+(snapPickId[2]<<16)+(snapPickId[3]<<24)];}if(null===worldPos&&null==snappedWorldPos){// If neither regular pick or snap pick, return null
|
|
4675
|
-
return null;}var snappedCanvasPos=null;if(null!==snappedWorldPos){snappedCanvasPos=scene.camera.projectWorldPos(snappedWorldPos);}var snappedEntity=snappedPickable&&snappedPickable.delegatePickedEntity?snappedPickable.delegatePickedEntity():snappedPickable;
|
|
4682
|
+
return null;}var snappedCanvasPos=null;if(null!==snappedWorldPos){snappedCanvasPos=scene.camera.projectWorldPos(snappedWorldPos);}var snappedEntity=snappedPickable&&snappedPickable.delegatePickedEntity?snappedPickable.delegatePickedEntity():snappedPickable;pickResult.reset();pickResult.snappedToEdge=snapType==="edge";pickResult.snappedToVertex=snapType==="vertex";pickResult.worldPos=snappedWorldPos;pickResult.worldNormal=snappedWorldNormal;pickResult.entity=snappedEntity;pickResult.canvasPos=canvasPos;pickResult.snappedCanvasPos=snappedCanvasPos||canvasPos;return pickResult;};}();function unpackDepth(depthZ){var vec=[depthZ[0]/256.0,depthZ[1]/256.0,depthZ[2]/256.0,depthZ[3]/256.0];var bitShift=[1.0/(256.0*256.0*256.0),1.0/(256.0*256.0),1.0/256.0,1.0];return math.dotVec4(vec,bitShift);}function gpuPickWorldNormal(pickBuffer,pickable,canvasPos,pickViewMatrix,pickProjMatrix,pickResult){var resolutionScale=scene.canvas.resolutionScale;frameCtx.reset();frameCtx.backfaces=true;frameCtx.frontface=true;// "ccw"
|
|
4676
4683
|
frameCtx.pickOrigin=pickResult.origin;frameCtx.pickViewMatrix=pickViewMatrix;frameCtx.pickProjMatrix=pickProjMatrix;frameCtx.pickClipPos=[getClipPosX(canvasPos[0]*resolutionScale,gl.drawingBufferWidth),getClipPosY(canvasPos[1]*resolutionScale,gl.drawingBufferHeight)];var pickNormalBuffer=renderBufferManager.getRenderBuffer("pick-normal",{size:[3,3]});pickNormalBuffer.bind(gl.RGBA32I);gl.viewport(0,0,pickNormalBuffer.size[0],pickNormalBuffer.size[1]);gl.enable(gl.DEPTH_TEST);gl.disable(gl.CULL_FACE);gl.disable(gl.BLEND);gl.clear(gl.DEPTH_BUFFER_BIT);gl.clearBufferiv(gl.COLOR,0,new Int32Array([0,0,0,0]));pickable.drawPickNormals(frameCtx);// Draw color-encoded fragment World-space normals
|
|
4677
4684
|
var pix=pickNormalBuffer.read(1,1,gl.RGBA_INTEGER,gl.INT,Int32Array,4);pickNormalBuffer.unbind();var worldNormal=[pix[0]/math.MAX_INT,pix[1]/math.MAX_INT,pix[2]/math.MAX_INT];math.normalizeVec3(worldNormal);pickResult.worldNormal=worldNormal;}/**
|
|
4678
4685
|
* Adds a {@link Marker} for occlusion testing.
|
|
@@ -9430,19 +9437,23 @@ this._aabbDirty=true;this.fire("boundary");// }
|
|
|
9430
9437
|
* @param {Number[]} [params.matrix] 4x4 transformation matrix to define the World-space ray origin and direction, as an alternative to ````origin```` and ````direction````.
|
|
9431
9438
|
* @param {String[]} [params.includeEntities] IDs of {@link Entity}s to restrict picking to. When given, ignores {@link Entity}s whose IDs are not in this list.
|
|
9432
9439
|
* @param {String[]} [params.excludeEntities] IDs of {@link Entity}s to ignore. When given, will pick *through* these {@link Entity}s, as if they were not there.
|
|
9440
|
+
* @param {Number} [params.snapRadius=30] The snap radius, in canvas pixels
|
|
9441
|
+
* @param {boolean} [params.snapToVertex=true] Whether to snap to vertex.
|
|
9442
|
+
* @param {boolean} [params.snapToEdge=true] Whether to snap to edge.
|
|
9433
9443
|
* @param {PickResult} [pickResult] Holds the results of the pick attempt. Will use the Scene's singleton PickResult if you don't supply your own.
|
|
9434
9444
|
* @returns {PickResult} Holds results of the pick attempt, returned when an {@link Entity} is picked, else null. See method comments for description.
|
|
9435
9445
|
*/},{key:"pick",value:function pick(params,pickResult){if(this.canvas.boundary[2]===0||this.canvas.boundary[3]===0){this.error("Picking not allowed while canvas has zero width or height");return null;}params=params||{};params.pickSurface=params.pickSurface||params.rayPick;// Backwards compatibility
|
|
9436
9446
|
if(!params.canvasPos&&!params.matrix&&(!params.origin||!params.direction)){this.warn("picking without canvasPos, matrix, or ray origin and direction");}var includeEntities=params.includeEntities||params.include;// Backwards compat
|
|
9437
9447
|
if(includeEntities){params.includeEntityIds=getEntityIDMap(this,includeEntities);}var excludeEntities=params.excludeEntities||params.exclude;// Backwards compat
|
|
9438
|
-
if(excludeEntities){params.excludeEntityIds=getEntityIDMap(this,excludeEntities);}if(this._needRecompile){this._recompile();this._renderer.imageDirty();this._needRecompile=false;}pickResult=this._renderer.pick(params,pickResult);if(pickResult){if(pickResult.entity&&pickResult.entity.fire){pickResult.entity.fire("picked",pickResult);// TODO:
|
|
9439
|
-
}return pickResult;}
|
|
9448
|
+
if(excludeEntities){params.excludeEntityIds=getEntityIDMap(this,excludeEntities);}if(this._needRecompile){this._recompile();this._renderer.imageDirty();this._needRecompile=false;}if(params.snapToEdge||params.snapToVertex){pickResult=this._renderer.snapPick(params.canvasPos,params.snapRadius||30,params.snapToVertex,params.snapToEdge,pickResult);}else{pickResult=this._renderer.pick(params,pickResult);}if(pickResult){if(pickResult.entity&&pickResult.entity.fire){pickResult.entity.fire("picked",pickResult);// TODO: SceneModelEntity doesn't fire events
|
|
9449
|
+
}}return pickResult;}/**
|
|
9440
9450
|
* @param {Object} params Picking parameters.
|
|
9441
9451
|
* @param {Number[]} [params.canvasPos] Canvas-space coordinates. When ray-picking, this will override the **origin** and ** direction** parameters and will cause the ray to be fired through the canvas at this position, directly along the negative View-space Z-axis.
|
|
9442
9452
|
* @param {Number} [params.snapRadius=30] The snap radius, in canvas pixels
|
|
9443
9453
|
* @param {boolean} [params.snapToVertex=true] Whether to snap to vertex.
|
|
9444
9454
|
* @param {boolean} [params.snapToEdge=true] Whether to snap to edge.
|
|
9445
|
-
|
|
9455
|
+
* @deprecated
|
|
9456
|
+
*/},{key:"snapPick",value:function snapPick(params){if(undefined===this._warnSnapPickDeprecated){this._warnSnapPickDeprecated=true;this.warn("Scene.snapPick() is deprecated since v2.4.2 - use Scene.pick() instead");}return this._renderer.snapPick(params.canvasPos,params.snapRadius||30,params.snapToVertex,params.snapToEdge);}/**
|
|
9446
9457
|
* Destroys all non-default {@link Component}s in this Scene.
|
|
9447
9458
|
*/},{key:"clear",value:function clear(){var component;for(var id in this.components){if(this.components.hasOwnProperty(id)){component=this.components[id];if(!component._dontClear){// Don't destroy components like Camera, Input, Viewport etc.
|
|
9448
9459
|
component.destroy();}}}}/**
|
|
@@ -14490,7 +14501,7 @@ this._originDot.setVisible(this._visible&&this._originVisible);this._targetDot.s
|
|
|
14490
14501
|
* @returns {boolean} Whether snap-to-vertex and snap-to-edge are enabled for this DistanceMeasurementsMouseControl.
|
|
14491
14502
|
*/function get(){return this._snapping;}/**
|
|
14492
14503
|
* Activates this DistanceMeasurementsMouseControl, ready to respond to input.
|
|
14493
|
-
*/,set:function set(snapping){if(snapping!==this._snapping){this._snapping=snapping;this.deactivate();this.activate();}else{this._snapping=snapping;}}},{key:"activate",value:function activate(){var _this72=this;if(this._active){return;}this.fire("activated",true);var distanceMeasurementsPlugin=this.distanceMeasurementsPlugin;var scene=this.scene;var cameraControl=distanceMeasurementsPlugin.viewer.cameraControl;var canvas=scene.canvas.canvas;scene.input;var mouseHovering=false;var pointerWorldPos=math.vec3();var pointerCanvasPos=math.vec2();var pointerDownCanvasX;var pointerDownCanvasY;var clickTolerance=20;this._mouseState=MOUSE_FIRST_CLICK_EXPECTED;this._onCameraControlHoverSnapOrSurface=cameraControl.on(this._snapping?"hoverSnapOrSurface":"hoverSurface",function(event){mouseHovering=true;pointerWorldPos.set(event.worldPos);pointerCanvasPos.set(event.canvasPos);if(_this72._mouseState===MOUSE_FIRST_CLICK_EXPECTED){_this72._markerDiv.style.marginLeft="".concat(
|
|
14504
|
+
*/,set:function set(snapping){if(snapping!==this._snapping){this._snapping=snapping;this.deactivate();this.activate();}else{this._snapping=snapping;}}},{key:"activate",value:function activate(){var _this72=this;if(this._active){return;}this.fire("activated",true);var distanceMeasurementsPlugin=this.distanceMeasurementsPlugin;var scene=this.scene;var cameraControl=distanceMeasurementsPlugin.viewer.cameraControl;var canvas=scene.canvas.canvas;scene.input;var mouseHovering=false;var pointerWorldPos=math.vec3();var pointerCanvasPos=math.vec2();var pointerDownCanvasX;var pointerDownCanvasY;var clickTolerance=20;this._mouseState=MOUSE_FIRST_CLICK_EXPECTED;this._onCameraControlHoverSnapOrSurface=cameraControl.on(this._snapping?"hoverSnapOrSurface":"hoverSurface",function(event){var canvasPos=event.snappedCanvasPos||event.canvasPos;mouseHovering=true;pointerWorldPos.set(event.worldPos);pointerCanvasPos.set(event.canvasPos);if(_this72._mouseState===MOUSE_FIRST_CLICK_EXPECTED){_this72._markerDiv.style.marginLeft="".concat(canvasPos[0]-5,"px");_this72._markerDiv.style.marginTop="".concat(canvasPos[1]-5,"px");_this72._markerDiv.style.background="pink";if(event.snappedToVertex||event.snappedToEdge){if(_this72.pointerLens){_this72.pointerLens.visible=true;_this72.pointerLens.canvasPos=event.canvasPos;_this72.pointerLens.snappedCanvasPos=event.snappedCanvasPos||event.canvasPos;_this72.pointerLens.snapped=true;}_this72._markerDiv.style.background="greenyellow";_this72._markerDiv.style.border="2px solid green";}else{if(_this72.pointerLens){_this72.pointerLens.visible=true;_this72.pointerLens.canvasPos=event.canvasPos;_this72.pointerLens.snappedCanvasPos=event.canvasPos;_this72.pointerLens.snapped=false;}_this72._markerDiv.style.background="pink";_this72._markerDiv.style.border="2px solid red";}}else{_this72._markerDiv.style.marginLeft="-10000px";_this72._markerDiv.style.marginTop="-10000px";}canvas.style.cursor="pointer";if(_this72._currentDistanceMeasurement){_this72._currentDistanceMeasurement.wireVisible=_this72._currentDistanceMeasurementInitState.wireVisible;_this72._currentDistanceMeasurement.axisVisible=_this72._currentDistanceMeasurementInitState.axisVisible&&_this72.distanceMeasurementsPlugin.defaultAxisVisible;_this72._currentDistanceMeasurement.xAxisVisible=_this72._currentDistanceMeasurementInitState.xAxisVisible&&_this72.distanceMeasurementsPlugin.defaultXAxisVisible;_this72._currentDistanceMeasurement.yAxisVisible=_this72._currentDistanceMeasurementInitState.yAxisVisible&&_this72.distanceMeasurementsPlugin.defaultYAxisVisible;_this72._currentDistanceMeasurement.zAxisVisible=_this72._currentDistanceMeasurementInitState.zAxisVisible&&_this72.distanceMeasurementsPlugin.defaultZAxisVisible;_this72._currentDistanceMeasurement.targetVisible=_this72._currentDistanceMeasurementInitState.targetVisible;_this72._currentDistanceMeasurement.target.worldPos=pointerWorldPos.slice();_this72._markerDiv.style.marginLeft="-10000px";_this72._markerDiv.style.marginTop="-10000px";}});canvas.addEventListener('mousedown',this._onMouseDown=function(e){if(e.which!==1){return;}pointerDownCanvasX=e.clientX;pointerDownCanvasY=e.clientY;});canvas.addEventListener("mouseup",this._onMouseUp=function(e){if(e.which!==1){return;}if(e.clientX>pointerDownCanvasX+clickTolerance||e.clientX<pointerDownCanvasX-clickTolerance||e.clientY>pointerDownCanvasY+clickTolerance||e.clientY<pointerDownCanvasY-clickTolerance){return;}if(_this72._currentDistanceMeasurement){if(mouseHovering){_this72._currentDistanceMeasurement.clickable=true;_this72.distanceMeasurementsPlugin.fire("measurementEnd",_this72._currentDistanceMeasurement);_this72._currentDistanceMeasurement=null;}else{_this72._currentDistanceMeasurement.destroy();_this72.distanceMeasurementsPlugin.fire("measurementCancel",_this72._currentDistanceMeasurement);_this72._currentDistanceMeasurement=null;}}else{if(mouseHovering){_this72._currentDistanceMeasurement=distanceMeasurementsPlugin.createMeasurement({id:math.createUUID(),origin:{worldPos:pointerWorldPos.slice()},target:{worldPos:pointerWorldPos.slice()},approximate:true});_this72._currentDistanceMeasurementInitState.axisVisible=_this72._currentDistanceMeasurement.axisVisible&&_this72.distanceMeasurementsPlugin.defaultAxisVisible;_this72._currentDistanceMeasurementInitState.xAxisVisible=_this72._currentDistanceMeasurement.xAxisVisible&&_this72.distanceMeasurementsPlugin.defaultXAxisVisible;_this72._currentDistanceMeasurementInitState.yAxisVisible=_this72._currentDistanceMeasurement.yAxisVisible&&_this72.distanceMeasurementsPlugin.defaultYAxisVisible;_this72._currentDistanceMeasurementInitState.zAxisVisible=_this72._currentDistanceMeasurement.zAxisVisible&&_this72.distanceMeasurementsPlugin.defaultZAxisVisible;_this72._currentDistanceMeasurementInitState.wireVisible=_this72._currentDistanceMeasurement.wireVisible;_this72._currentDistanceMeasurementInitState.targetVisible=_this72._currentDistanceMeasurement.targetVisible;_this72._currentDistanceMeasurement.clickable=false;_this72.fire("measurementStart",_this72._currentDistanceMeasurement);}}});this._onCameraControlHoverSnapOrSurfaceOff=cameraControl.on(this._snapping?"hoverSnapOrSurfaceOff":"hoverOff",function(event){if(_this72.pointerLens){_this72.pointerLens.visible=true;_this72.pointerLens.canvasPos=event.canvasPos;_this72.pointerLens.snappedCanvasPos=event.snappedCanvasPos||event.canvasPos;}mouseHovering=false;_this72._markerDiv.style.marginLeft="-100px";_this72._markerDiv.style.marginTop="-100px";if(_this72._currentDistanceMeasurement){_this72._currentDistanceMeasurement.wireVisible=false;_this72._currentDistanceMeasurement.targetVisible=false;_this72._currentDistanceMeasurement.axisVisible=false;}canvas.style.cursor="default";});this._active=true;}/**
|
|
14494
14505
|
* Deactivates this DistanceMeasurementsMouseControl, making it unresponsive to input.
|
|
14495
14506
|
*
|
|
14496
14507
|
* Destroys any {@link DistanceMeasurement} under construction by this DistanceMeasurementsMouseControl.
|
|
@@ -21274,11 +21285,11 @@ var eyeLookLen=math.lenVec3(math.subVec3(camera.look,camera.eye,math.vec3()));va
|
|
|
21274
21285
|
*/this.pickedSurface=false;/**
|
|
21275
21286
|
* Will hold the PickResult after after picking.
|
|
21276
21287
|
* @type {PickResult}
|
|
21277
|
-
*/this.pickResult=null;this._lastPickedEntityId=null;this._needFireEvents=0;}/**
|
|
21288
|
+
*/this.pickResult=null;this._lastPickedEntityId=null;this._lastHash=null;this._needFireEvents=0;}/**
|
|
21278
21289
|
* Immediately attempts a pick, if scheduled.
|
|
21279
|
-
*/_createClass(PickController,[{key:"update",value:function update(){if(!this._configs.pointerEnabled){return;}if(!this.schedulePickEntity&&!this.schedulePickSurface){return;}this.picked=false;this.pickedSurface=false;this.snappedOrPicked=false;this.hoveredSnappedOrSurfaceOff=false;var hasHoverSurfaceSubs=this._cameraControl.hasSubs("hoverSurface");if(this.scheduleSnapOrPick){var snapPickResult=this._scene.
|
|
21290
|
+
*/_createClass(PickController,[{key:"update",value:function update(){if(!this._configs.pointerEnabled){return;}if(!this.schedulePickEntity&&!this.schedulePickSurface){return;}var hash="".concat(~~this.pickCursorPos[0],"-").concat(~~this.pickCursorPos[1],"-").concat(this.scheduleSnapOrPick,"-").concat(this.schedulePickSurface,"-").concat(this.schedulePickEntity);if(this._lastHash===hash){return;}this.picked=false;this.pickedSurface=false;this.snappedOrPicked=false;this.hoveredSnappedOrSurfaceOff=false;var hasHoverSurfaceSubs=this._cameraControl.hasSubs("hoverSurface");if(this.scheduleSnapOrPick){var snapPickResult=this._scene.pick({canvasPos:this.pickCursorPos,snapRadius:this._configs.snapRadius,snapToVertex:this._configs.snapToVertex,snapToEdge:this._configs.snapToEdge});if(snapPickResult&&(snapPickResult.snappedToEdge||snapPickResult.snappedToVertex)){this.snapPickResult=snapPickResult;this.snappedOrPicked=true;this._needFireEvents++;}else{this.schedulePickSurface=true;// Fallback
|
|
21280
21291
|
this.snapPickResult=null;}}if(this.schedulePickSurface){if(this.pickResult&&this.pickResult.worldPos){var pickResultCanvasPos=this.pickResult.canvasPos;if(pickResultCanvasPos[0]===this.pickCursorPos[0]&&pickResultCanvasPos[1]===this.pickCursorPos[1]){this.picked=true;this.pickedSurface=true;this._needFireEvents+=hasHoverSurfaceSubs?1:0;this.schedulePickEntity=false;this.schedulePickSurface=false;if(this.scheduleSnapOrPick){this.snappedOrPicked=true;}else{this.hoveredSnappedOrSurfaceOff=true;}this.scheduleSnapOrPick=false;return;}}}if(this.schedulePickEntity){if(this.pickResult&&(this.pickResult.canvasPos||this.pickResult.snappedCanvasPos)){var _pickResultCanvasPos=this.pickResult.canvasPos||this.pickResult.snappedCanvasPos;if(_pickResultCanvasPos[0]===this.pickCursorPos[0]&&_pickResultCanvasPos[1]===this.pickCursorPos[1]){this.picked=true;this.pickedSurface=false;this.schedulePickEntity=false;this.schedulePickSurface=false;return;}}}if(this.schedulePickSurface||this.scheduleSnapOrPick&&!this.snapPickResult){this.pickResult=this._scene.pick({pickSurface:true,pickSurfaceNormal:false,canvasPos:this.pickCursorPos});if(this.pickResult){this.picked=true;if(this.scheduleSnapOrPick){this.snappedOrPicked=true;}else{this.pickedSurface=true;}this._needFireEvents++;}else if(this.scheduleSnapOrPick){this.hoveredSnappedOrSurfaceOff=true;this._needFireEvents++;}}else{// schedulePickEntity == true
|
|
21281
|
-
this.pickResult=this._scene.pick({canvasPos:this.pickCursorPos});if(this.pickResult){this.picked=true;this.pickedSurface=false;this._needFireEvents++;}}this.scheduleSnapOrPick=false;this.schedulePickEntity=false;this.schedulePickSurface=false;}},{key:"fireEvents",value:function fireEvents(){if(this._needFireEvents
|
|
21292
|
+
this.pickResult=this._scene.pick({canvasPos:this.pickCursorPos});if(this.pickResult){this.picked=true;this.pickedSurface=false;this._needFireEvents++;}}this.scheduleSnapOrPick=false;this.schedulePickEntity=false;this.schedulePickSurface=false;}},{key:"fireEvents",value:function fireEvents(){if(this._needFireEvents===0){return;}if(this.hoveredSnappedOrSurfaceOff){this._cameraControl.fire("hoverSnapOrSurfaceOff",{canvasPos:this.pickCursorPos,pointerPos:this.pickCursorPos},true);}if(this.snappedOrPicked){if(this.snapPickResult){var pickResult=new PickResult();pickResult.snappedToVertex=this.snapPickResult.snappedToVertex;pickResult.snappedToEdge=this.snapPickResult.snappedToEdge;pickResult.worldPos=this.snapPickResult.worldPos;pickResult.canvasPos=this.pickCursorPos;pickResult.snappedCanvasPos=this.snapPickResult.snappedCanvasPos;this._cameraControl.fire("hoverSnapOrSurface",pickResult,true);this.snapPickResult=null;}else{this._cameraControl.fire("hoverSnapOrSurface",this.pickResult,true);}}if(this.picked&&this.pickResult&&(this.pickResult.entity||this.pickResult.worldPos)){if(this.pickResult.entity){var pickedEntityId=this.pickResult.entity.id;if(this._lastPickedEntityId!==pickedEntityId){if(this._lastPickedEntityId!==undefined){this._cameraControl.fire("hoverOut",{entity:this._scene.objects[this._lastPickedEntityId]},true);}this._cameraControl.fire("hoverEnter",this.pickResult,true);this._lastPickedEntityId=pickedEntityId;}}this._cameraControl.fire("hover",this.pickResult,true);if(this.pickResult.worldPos){this.pickedSurface=true;this._cameraControl.fire("hoverSurface",this.pickResult,true);}}else{if(this._lastPickedEntityId!==undefined){this._cameraControl.fire("hoverOut",{entity:this._scene.objects[this._lastPickedEntityId]},true);this._lastPickedEntityId=undefined;}this._cameraControl.fire("hoverOff",{canvasPos:this.pickCursorPos},true);}this.pickResult=null;this._needFireEvents=0;}}]);return PickController;}();/**
|
|
21282
21293
|
* @private
|
|
21283
21294
|
*/var canvasPos=math.vec2();var getCanvasPosFromEvent$3=function getCanvasPosFromEvent$3(event,canvasPos){if(!event){event=window.event;canvasPos[0]=event.x;canvasPos[1]=event.y;}else{var element=event.target;var totalOffsetLeft=0;var totalOffsetTop=0;var totalScrollX=0;var totalScrollY=0;while(element.offsetParent){totalOffsetLeft+=element.offsetLeft;totalOffsetTop+=element.offsetTop;totalScrollX+=element.scrollLeft;totalScrollY+=element.scrollTop;element=element.offsetParent;}canvasPos[0]=event.pageX+totalScrollX-totalOffsetLeft;canvasPos[1]=event.pageY+totalScrollY-totalOffsetTop;}return canvasPos;};/**
|
|
21284
21295
|
* @private
|