@xeokit/xeokit-sdk 2.6.26 → 2.6.27

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.
@@ -6194,54 +6194,49 @@ const math = {
6194
6194
  @static
6195
6195
  @param {Number[]} viewMatrix View matrix
6196
6196
  @param {Number[]} projMatrix Projection matrix
6197
+ @param {String} projection Projection type (e.g. "ortho")
6197
6198
  @param {Number[]} canvasPos The Canvas-space position.
6198
6199
  @param {Number[]} worldRayOrigin The World-space ray origin.
6199
6200
  @param {Number[]} worldRayDir The World-space ray direction.
6200
6201
  */
6201
6202
  canvasPosToWorldRay: ((() => {
6202
6203
 
6203
- const tempMat4b = new FloatArrayType(16);
6204
- const tempMat4c = new FloatArrayType(16);
6205
- const tempVec4a = new FloatArrayType(4);
6206
- const tempVec4b = new FloatArrayType(4);
6207
- const tempVec4c = new FloatArrayType(4);
6208
- const tempVec4d = new FloatArrayType(4);
6204
+ const pvMatInv = new FloatArrayType(16);
6205
+ const vec4Near = new FloatArrayType(4);
6206
+ const vec4Far = new FloatArrayType(4);
6209
6207
 
6210
- return (canvas, viewMatrix, projMatrix, canvasPos, worldRayOrigin, worldRayDir) => {
6208
+ const clipToWorld = (clipX, clipY, clipZ, isOrtho, outVec4) => {
6209
+ outVec4[0] = clipX;
6210
+ outVec4[1] = clipY;
6211
+ outVec4[2] = clipZ;
6212
+ outVec4[3] = 1;
6211
6213
 
6212
- const pvMat = math.mulMat4(projMatrix, viewMatrix, tempMat4b);
6213
- const pvMatInverse = math.inverseMat4(pvMat, tempMat4c);
6214
-
6215
- // Calculate clip space coordinates, which will be in range
6216
- // of x=[-1..1] and y=[-1..1], with y=(+1) at top
6214
+ math.transformVec4(pvMatInv, outVec4, outVec4);
6215
+ if (! isOrtho)
6216
+ math.mulVec4Scalar(outVec4, 1 / outVec4[3]);
6217
+ };
6217
6218
 
6218
- const canvasWidth = canvas.width;
6219
- const canvasHeight = canvas.height;
6219
+ return (canvas, viewMatrix, projMatrix, projection, canvasPos, worldRayOrigin, worldRayDir) => {
6220
+ const isOrtho = projection === "ortho";
6220
6221
 
6221
- const clipX = (canvasPos[0] - canvasWidth / 2) / (canvasWidth / 2); // Calculate clip space coordinates
6222
- const clipY = -(canvasPos[1] - canvasHeight / 2) / (canvasHeight / 2);
6222
+ math.mulMat4(projMatrix, viewMatrix, pvMatInv);
6223
+ math.inverseMat4(pvMatInv, pvMatInv);
6223
6224
 
6224
- tempVec4a[0] = clipX;
6225
- tempVec4a[1] = clipY;
6226
- tempVec4a[2] = -1;
6227
- tempVec4a[3] = 1;
6225
+ // Calculate clip space coordinates, which will be in range
6226
+ // of x=[-1..1] and y=[-1..1], with y=(+1) at top
6228
6227
 
6229
- math.transformVec4(pvMatInverse, tempVec4a, tempVec4b);
6230
- math.mulVec4Scalar(tempVec4b, 1 / tempVec4b[3]);
6228
+ const clipX = 2 * canvasPos[0] / canvas.width - 1; // Calculate clip space coordinates
6229
+ const clipY = 1 - 2 * canvasPos[1] / canvas.height;
6231
6230
 
6232
- tempVec4c[0] = clipX;
6233
- tempVec4c[1] = clipY;
6234
- tempVec4c[2] = 1;
6235
- tempVec4c[3] = 1;
6231
+ clipToWorld(clipX, clipY, -1, isOrtho, vec4Near);
6236
6232
 
6237
- math.transformVec4(pvMatInverse, tempVec4c, tempVec4d);
6238
- math.mulVec4Scalar(tempVec4d, 1 / tempVec4d[3]);
6233
+ clipToWorld(clipX, clipY, 1, isOrtho, vec4Far);
6239
6234
 
6240
- worldRayOrigin[0] = tempVec4d[0];
6241
- worldRayOrigin[1] = tempVec4d[1];
6242
- worldRayOrigin[2] = tempVec4d[2];
6235
+ worldRayOrigin[0] = vec4Near[0];
6236
+ worldRayOrigin[1] = vec4Near[1];
6237
+ worldRayOrigin[2] = vec4Near[2];
6243
6238
 
6244
- math.subVec3(tempVec4d, tempVec4b, worldRayDir);
6239
+ math.subVec3(vec4Far, vec4Near, worldRayDir);
6245
6240
 
6246
6241
  math.normalizeVec3(worldRayDir);
6247
6242
  };
@@ -6265,8 +6260,8 @@ const math = {
6265
6260
  const worldRayOrigin = new FloatArrayType(3);
6266
6261
  const worldRayDir = new FloatArrayType(3);
6267
6262
 
6268
- return (canvas, viewMatrix, projMatrix, worldMatrix, canvasPos, localRayOrigin, localRayDir) => {
6269
- math.canvasPosToWorldRay(canvas, viewMatrix, projMatrix, canvasPos, worldRayOrigin, worldRayDir);
6263
+ return (canvas, viewMatrix, projMatrix, projection, worldMatrix, canvasPos, localRayOrigin, localRayDir) => {
6264
+ math.canvasPosToWorldRay(canvas, viewMatrix, projMatrix, projection, canvasPos, worldRayOrigin, worldRayDir);
6270
6265
  math.worldRayToLocalRay(worldMatrix, worldRayOrigin, worldRayDir, localRayOrigin, localRayDir);
6271
6266
  };
6272
6267
  }))(),
@@ -11121,7 +11116,7 @@ function activateDraggableDot(dot, cfg) {
11121
11116
  const pickWorldPos = canvasPos => {
11122
11117
  const origin = math.vec3();
11123
11118
  const direction = math.vec3();
11124
- math.canvasPosToWorldRay(canvas, scene.camera.viewMatrix, scene.camera.projMatrix, canvasPos, origin, direction);
11119
+ math.canvasPosToWorldRay(canvas, scene.camera.viewMatrix, scene.camera.projMatrix, scene.camera.projection, canvasPos, origin, direction);
11125
11120
  return ray2WorldPos(origin, direction, canvasPos);
11126
11121
  };
11127
11122
 
@@ -20014,6 +20009,7 @@ const Renderer$1 = function (scene, options) {
20014
20009
  let look;
20015
20010
  let pickViewMatrix = null;
20016
20011
  let pickProjMatrix = null;
20012
+ let projection = null;
20017
20013
 
20018
20014
  pickResult.pickSurface = params.pickSurface;
20019
20015
 
@@ -20024,6 +20020,7 @@ const Renderer$1 = function (scene, options) {
20024
20020
 
20025
20021
  pickViewMatrix = scene.camera.viewMatrix;
20026
20022
  pickProjMatrix = scene.camera.projMatrix;
20023
+ projection = scene.camera.projection;
20027
20024
 
20028
20025
  pickResult.canvasPos = params.canvasPos;
20029
20026
 
@@ -20036,6 +20033,7 @@ const Renderer$1 = function (scene, options) {
20036
20033
 
20037
20034
  pickViewMatrix = params.matrix;
20038
20035
  pickProjMatrix = scene.camera.projMatrix;
20036
+ projection = scene.camera.projection;
20039
20037
 
20040
20038
  } else {
20041
20039
 
@@ -20054,6 +20052,7 @@ const Renderer$1 = function (scene, options) {
20054
20052
  pickViewMatrix = math.lookAtMat4v(worldRayOrigin, look, up, tempMat4b);
20055
20053
  // pickProjMatrix = scene.camera.projMatrix;
20056
20054
  pickProjMatrix = scene.camera.ortho.matrix;
20055
+ projection = "ortho";
20057
20056
 
20058
20057
  pickResult.origin = worldRayOrigin;
20059
20058
  pickResult.direction = worldRayDir;
@@ -20101,7 +20100,7 @@ const Renderer$1 = function (scene, options) {
20101
20100
 
20102
20101
  gpuPickTriangle(pickBuffer, pickable, canvasPos, pickViewMatrix, pickProjMatrix, pickResult);
20103
20102
 
20104
- pickable.pickTriangleSurface(pickViewMatrix, pickProjMatrix, pickResult);
20103
+ pickable.pickTriangleSurface(pickViewMatrix, pickProjMatrix, projection, pickResult);
20105
20104
 
20106
20105
  pickResult.pickSurfacePrecision = false;
20107
20106
 
@@ -20374,7 +20373,9 @@ const Renderer$1 = function (scene, options) {
20374
20373
 
20375
20374
  const _pickResult = new PickResult();
20376
20375
 
20377
- return function (canvasPos, snapRadiusInPixels, snapToVertex, snapToEdge, pickResult = _pickResult) {
20376
+ return function (params, pickResult = _pickResult) {
20377
+
20378
+ const {canvasPos, origin, direction, snapRadius, snapToVertex, snapToEdge} = params;
20378
20379
 
20379
20380
  if (!snapToVertex && !snapToEdge) {
20380
20381
  return this.pick({canvasPos, pickSurface: true});
@@ -20388,7 +20389,7 @@ const Renderer$1 = function (scene, options) {
20388
20389
  frameCtx.pickZNear = scene.camera.project.near;
20389
20390
  frameCtx.pickZFar = scene.camera.project.far;
20390
20391
 
20391
- snapRadiusInPixels = snapRadiusInPixels || 30;
20392
+ const snapRadiusInPixels = snapRadius || 30;
20392
20393
 
20393
20394
  const vertexPickBuffer = renderBufferManager.getRenderBuffer("uniquePickColors-aabs", {
20394
20395
  depthTexture: true,
@@ -20399,8 +20400,8 @@ const Renderer$1 = function (scene, options) {
20399
20400
  });
20400
20401
 
20401
20402
  frameCtx.snapVectorA = [
20402
- getClipPosX(canvasPos[0] * resolutionScale, gl.drawingBufferWidth),
20403
- getClipPosY(canvasPos[1] * resolutionScale, gl.drawingBufferHeight),
20403
+ canvasPos ? getClipPosX(canvasPos[0] * resolutionScale, gl.drawingBufferWidth) : 0,
20404
+ canvasPos ? getClipPosY(canvasPos[1] * resolutionScale, gl.drawingBufferHeight) : 0,
20404
20405
  ];
20405
20406
 
20406
20407
  frameCtx.snapInvVectorAB = [
@@ -20427,7 +20428,14 @@ const Renderer$1 = function (scene, options) {
20427
20428
  // Set view and proj mats for VBO renderers
20428
20429
  ///////////////////////////////////////
20429
20430
 
20430
- const pickViewMatrix = scene.camera.viewMatrix;
20431
+ frameCtx.pickViewMatrix = (canvasPos
20432
+ ? scene.camera.viewMatrix
20433
+ : math.lookAtMat4v(
20434
+ origin,
20435
+ math.addVec3(origin, direction, math.vec3()),
20436
+ math.vec3([0, 1, 0]),
20437
+ math.mat4()));
20438
+
20431
20439
  const pickProjMatrix = scene.camera.projMatrix;
20432
20440
 
20433
20441
  for (let type in drawableTypeInfo) {
@@ -20436,7 +20444,7 @@ const Renderer$1 = function (scene, options) {
20436
20444
  for (let i = 0, len = drawableList.length; i < len; i++) {
20437
20445
  const drawable = drawableList[i];
20438
20446
  if (drawable.setPickMatrices) { // Eg. SceneModel, which needs pre-loading into texture
20439
- drawable.setPickMatrices(pickViewMatrix, pickProjMatrix);
20447
+ drawable.setPickMatrices(frameCtx.pickViewMatrix, pickProjMatrix);
20440
20448
  }
20441
20449
  }
20442
20450
  }
@@ -20613,7 +20621,7 @@ const Renderer$1 = function (scene, options) {
20613
20621
  pickResult.worldPos = snappedWorldPos;
20614
20622
  pickResult.worldNormal = snappedWorldNormal;
20615
20623
  pickResult.entity = snappedEntity;
20616
- pickResult.canvasPos = canvasPos;
20624
+ pickResult.canvasPos = canvasPos || scene.camera.projectWorldPos(worldPos || snappedWorldPos);
20617
20625
  pickResult.snappedCanvasPos = snappedCanvasPos || canvasPos;
20618
20626
 
20619
20627
  return pickResult;
@@ -32019,11 +32027,6 @@ class Scene extends Component {
32019
32027
  return null;
32020
32028
  }
32021
32029
 
32022
- if ((params.snapToVertex || params.snapToEdge) && !params.canvasPos) {
32023
- this.error("Scene.snapPick() `canvasPos` parameter expected for `snapToVertex:true` or `snapToEdge:true`");
32024
- return;
32025
- }
32026
-
32027
32030
  params = params || {};
32028
32031
 
32029
32032
  params.pickSurface = params.pickSurface || params.rayPick; // Backwards compatibility
@@ -32049,13 +32052,7 @@ class Scene extends Component {
32049
32052
  }
32050
32053
 
32051
32054
  if (params.snapToEdge || params.snapToVertex) {
32052
- pickResult = this._renderer.snapPick(
32053
- params.canvasPos,
32054
- params.snapRadius || 30,
32055
- params.snapToVertex,
32056
- params.snapToEdge,
32057
- pickResult
32058
- );
32055
+ pickResult = this._renderer.snapPick(params, pickResult);
32059
32056
  } else {
32060
32057
  pickResult = this._renderer.pick(params, pickResult);
32061
32058
  }
@@ -32086,12 +32083,7 @@ class Scene extends Component {
32086
32083
  this.error("Scene.snapPick() canvasPos parameter expected");
32087
32084
  return;
32088
32085
  }
32089
- return this._renderer.snapPick(
32090
- params.canvasPos,
32091
- params.snapRadius || 30,
32092
- params.snapToVertex,
32093
- params.snapToEdge,
32094
- );
32086
+ return this._renderer.snapPick(params);
32095
32087
  }
32096
32088
 
32097
32089
  /**
@@ -39829,8 +39821,8 @@ class Mesh extends Component {
39829
39821
  }
39830
39822
 
39831
39823
  /** @private */
39832
- pickTriangleSurface(pickViewMatrix, pickProjMatrix, pickResult) {
39833
- pickTriangleSurface(this, pickViewMatrix, pickProjMatrix, pickResult);
39824
+ pickTriangleSurface(pickViewMatrix, pickProjMatrix, projection, pickResult) {
39825
+ pickTriangleSurface(this, pickViewMatrix, pickProjMatrix, projection, pickResult);
39834
39826
  }
39835
39827
 
39836
39828
  /** @private */
@@ -39922,7 +39914,7 @@ const pickTriangleSurface = (function () {
39922
39914
  const tempVec3j = math.vec3();
39923
39915
  const tempVec3k = math.vec3();
39924
39916
 
39925
- return function (mesh, pickViewMatrix, pickProjMatrix, pickResult) {
39917
+ return function (mesh, pickViewMatrix, pickProjMatrix, projection, pickResult) {
39926
39918
 
39927
39919
  var primIndex = pickResult.primIndex;
39928
39920
 
@@ -40001,7 +39993,7 @@ const pickTriangleSurface = (function () {
40001
39993
  // Attempt to ray-pick the triangle in local space
40002
39994
 
40003
39995
  if (pickResult.canvasPos) {
40004
- math.canvasPosToLocalRay(canvas.canvas, mesh.origin ? createRTCViewMat(pickViewMatrix, mesh.origin) : pickViewMatrix, pickProjMatrix, mesh.worldMatrix, pickResult.canvasPos, localRayOrigin, localRayDir);
39996
+ math.canvasPosToLocalRay(canvas.canvas, mesh.origin ? createRTCViewMat(pickViewMatrix, mesh.origin) : pickViewMatrix, pickProjMatrix, projection, mesh.worldMatrix, pickResult.canvasPos, localRayOrigin, localRayDir);
40005
39997
 
40006
39998
  } else if (pickResult.origin && pickResult.direction) {
40007
39999
  math.worldRayToLocalRay(mesh.worldMatrix, pickResult.origin, pickResult.direction, localRayOrigin, localRayDir);
@@ -87576,7 +87568,7 @@ class DistanceMeasurement extends Component {
87576
87568
  }
87577
87569
 
87578
87570
  if (!this._zAxisLabelCulled) {
87579
- if(this._measurementOrientation === 'Vertical') {
87571
+ if(this._measurementOrientation === 'Vertical' && this.useRotationAdjustment) {
87580
87572
  this._zAxisLabel.setPrefix("");
87581
87573
  this._zAxisLabel.setText(tilde + Math.abs(math.lenVec3(math.subVec3(this._targetWorld, [this._originWorld[0], this._targetWorld[1], this._originWorld[2]], distVec3)) * scale).toFixed(2) + unitAbbrev);
87582
87574
  }
@@ -88614,27 +88606,27 @@ class DistanceMeasurementsMouseControl extends DistanceMeasurementsControl {
88614
88606
  if (!this._active) {
88615
88607
  return;
88616
88608
  }
88617
-
88609
+
88618
88610
  this.fire("activated", false);
88619
88611
 
88620
88612
  if (this.pointerLens) {
88621
88613
  this.pointerLens.visible = false;
88622
88614
  }
88623
- if (this._markerDiv) {
88624
- this._destroyMarkerDiv();
88625
- }
88626
- this.reset();
88615
+ // if (this._markerDiv) {
88616
+ // this._destroyMarkerDiv()
88617
+ // }
88618
+ // this.reset();
88627
88619
  const canvas = this.scene.canvas.canvas;
88628
88620
  canvas.removeEventListener("mousedown", this._onMouseDown);
88629
88621
  canvas.removeEventListener("mouseup", this._onMouseUp);
88630
88622
  const cameraControl = this.distanceMeasurementsPlugin.viewer.cameraControl;
88631
88623
  cameraControl.off(this._onCameraControlHoverSnapOrSurface);
88632
88624
  cameraControl.off(this._onCameraControlHoverSnapOrSurfaceOff);
88633
- if (this._currentDistanceMeasurement) {
88634
- this.distanceMeasurementsPlugin.fire("measurementCancel", this._currentDistanceMeasurement);
88635
- this._currentDistanceMeasurement.destroy();
88636
- this._currentDistanceMeasurement = null;
88637
- }
88625
+ // if (this._currentDistanceMeasurement) {
88626
+ // this.distanceMeasurementsPlugin.fire("measurementCancel", this._currentDistanceMeasurement);
88627
+ // this._currentDistanceMeasurement.destroy();
88628
+ // this._currentDistanceMeasurement = null;
88629
+ // }
88638
88630
  this._active = false;
88639
88631
  }
88640
88632
 
@@ -89169,7 +89161,7 @@ class DistanceMeasurementsPlugin extends Plugin {
89169
89161
  axisVisible: params.axisVisible !== false && this.defaultAxisVisible !== false,
89170
89162
  xAxisVisible: params.xAxisVisible !== false && this.defaultXAxisVisible !== false,
89171
89163
  yAxisVisible: params.yAxisVisible !== false && this.defaultYAxisVisible !== false,
89172
- zAxisVisibld: params.zAxisVisible !== false && this.defaultZAxisVisible !== false,
89164
+ zAxisVisible: params.zAxisVisible !== false && this.defaultZAxisVisible !== false,
89173
89165
  xLabelEnabled: params.xLabelEnabled !== false && this.defaultXLabelEnabled !== false,
89174
89166
  yLabelEnabled: params.yLabelEnabled !== false && this.defaultYLabelEnabled !== false,
89175
89167
  zLabelEnabled: params.zLabelEnabled !== false && this.defaultZLabelEnabled !== false,
@@ -96962,8 +96954,7 @@ class MousePickHandler {
96962
96954
  {
96963
96955
  const origin = math.vec3();
96964
96956
  const direction = math.vec3();
96965
- // The origin from math.canvasPosToWorldRay is incorrect for a perspective camera, should be the same as scene.camera.eye
96966
- math.canvasPosToWorldRay(scene.canvas.canvas, scene.camera.viewMatrix, scene.camera.projMatrix, states.pointerCanvasPos, origin, direction);
96957
+ math.canvasPosToWorldRay(scene.canvas.canvas, scene.camera.viewMatrix, scene.camera.projMatrix, scene.camera.projection, states.pointerCanvasPos, origin, direction);
96967
96958
  cameraControl.fire("rayMove", { canvasPos: states.pointerCanvasPos, ray: { origin: origin, direction: direction, canvasPos: states.pointerCanvasPos } }, true);
96968
96959
  }
96969
96960
 
@@ -139071,7 +139062,7 @@ const mousePointSelector = function(viewer, ray2WorldPos) {
139071
139062
  const pickWorldPos = canvasPos => {
139072
139063
  const origin = math.vec3();
139073
139064
  const direction = math.vec3();
139074
- math.canvasPosToWorldRay(canvas, scene.camera.viewMatrix, scene.camera.projMatrix, canvasPos, origin, direction);
139065
+ math.canvasPosToWorldRay(canvas, scene.camera.viewMatrix, scene.camera.projMatrix, scene.camera.projection, canvasPos, origin, direction);
139075
139066
  return ray2WorldPos(origin, direction);
139076
139067
  };
139077
139068
 
@@ -139146,7 +139137,7 @@ const touchPointSelector = function(viewer, pointerCircle, ray2WorldPos) {
139146
139137
  const pickWorldPos = canvasPos => {
139147
139138
  const origin = math.vec3();
139148
139139
  const direction = math.vec3();
139149
- math.canvasPosToWorldRay(canvas, scene.camera.viewMatrix, scene.camera.projMatrix, canvasPos, origin, direction);
139140
+ math.canvasPosToWorldRay(canvas, scene.camera.viewMatrix, scene.camera.projMatrix, scene.camera.projection, canvasPos, origin, direction);
139150
139141
  return ray2WorldPos(origin, direction);
139151
139142
  };
139152
139143
 
@@ -140366,7 +140357,7 @@ class ZoneTranslateControl extends Component {
140366
140357
  const pickWorldPos = canvasPos => {
140367
140358
  const origin = math.vec3();
140368
140359
  const direction = math.vec3();
140369
- math.canvasPosToWorldRay(canvas, scene.camera.viewMatrix, scene.camera.projMatrix, canvasPos, origin, direction);
140360
+ math.canvasPosToWorldRay(canvas, scene.camera.viewMatrix, scene.camera.projMatrix, scene.camera.projection, canvasPos, origin, direction);
140370
140361
  return ray2WorldPos(origin, direction);
140371
140362
  };
140372
140363