@xeokit/xeokit-sdk 2.6.26 → 2.6.28

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.
@@ -6190,54 +6190,49 @@ const math = {
6190
6190
  @static
6191
6191
  @param {Number[]} viewMatrix View matrix
6192
6192
  @param {Number[]} projMatrix Projection matrix
6193
+ @param {String} projection Projection type (e.g. "ortho")
6193
6194
  @param {Number[]} canvasPos The Canvas-space position.
6194
6195
  @param {Number[]} worldRayOrigin The World-space ray origin.
6195
6196
  @param {Number[]} worldRayDir The World-space ray direction.
6196
6197
  */
6197
6198
  canvasPosToWorldRay: ((() => {
6198
6199
 
6199
- const tempMat4b = new FloatArrayType(16);
6200
- const tempMat4c = new FloatArrayType(16);
6201
- const tempVec4a = new FloatArrayType(4);
6202
- const tempVec4b = new FloatArrayType(4);
6203
- const tempVec4c = new FloatArrayType(4);
6204
- const tempVec4d = new FloatArrayType(4);
6200
+ const pvMatInv = new FloatArrayType(16);
6201
+ const vec4Near = new FloatArrayType(4);
6202
+ const vec4Far = new FloatArrayType(4);
6205
6203
 
6206
- return (canvas, viewMatrix, projMatrix, canvasPos, worldRayOrigin, worldRayDir) => {
6204
+ const clipToWorld = (clipX, clipY, clipZ, isOrtho, outVec4) => {
6205
+ outVec4[0] = clipX;
6206
+ outVec4[1] = clipY;
6207
+ outVec4[2] = clipZ;
6208
+ outVec4[3] = 1;
6207
6209
 
6208
- const pvMat = math.mulMat4(projMatrix, viewMatrix, tempMat4b);
6209
- const pvMatInverse = math.inverseMat4(pvMat, tempMat4c);
6210
-
6211
- // Calculate clip space coordinates, which will be in range
6212
- // of x=[-1..1] and y=[-1..1], with y=(+1) at top
6210
+ math.transformVec4(pvMatInv, outVec4, outVec4);
6211
+ if (! isOrtho)
6212
+ math.mulVec4Scalar(outVec4, 1 / outVec4[3]);
6213
+ };
6213
6214
 
6214
- const canvasWidth = canvas.width;
6215
- const canvasHeight = canvas.height;
6215
+ return (canvas, viewMatrix, projMatrix, projection, canvasPos, worldRayOrigin, worldRayDir) => {
6216
+ const isOrtho = projection === "ortho";
6216
6217
 
6217
- const clipX = (canvasPos[0] - canvasWidth / 2) / (canvasWidth / 2); // Calculate clip space coordinates
6218
- const clipY = -(canvasPos[1] - canvasHeight / 2) / (canvasHeight / 2);
6218
+ math.mulMat4(projMatrix, viewMatrix, pvMatInv);
6219
+ math.inverseMat4(pvMatInv, pvMatInv);
6219
6220
 
6220
- tempVec4a[0] = clipX;
6221
- tempVec4a[1] = clipY;
6222
- tempVec4a[2] = -1;
6223
- tempVec4a[3] = 1;
6221
+ // Calculate clip space coordinates, which will be in range
6222
+ // of x=[-1..1] and y=[-1..1], with y=(+1) at top
6224
6223
 
6225
- math.transformVec4(pvMatInverse, tempVec4a, tempVec4b);
6226
- math.mulVec4Scalar(tempVec4b, 1 / tempVec4b[3]);
6224
+ const clipX = 2 * canvasPos[0] / canvas.width - 1; // Calculate clip space coordinates
6225
+ const clipY = 1 - 2 * canvasPos[1] / canvas.height;
6227
6226
 
6228
- tempVec4c[0] = clipX;
6229
- tempVec4c[1] = clipY;
6230
- tempVec4c[2] = 1;
6231
- tempVec4c[3] = 1;
6227
+ clipToWorld(clipX, clipY, -1, isOrtho, vec4Near);
6232
6228
 
6233
- math.transformVec4(pvMatInverse, tempVec4c, tempVec4d);
6234
- math.mulVec4Scalar(tempVec4d, 1 / tempVec4d[3]);
6229
+ clipToWorld(clipX, clipY, 1, isOrtho, vec4Far);
6235
6230
 
6236
- worldRayOrigin[0] = tempVec4d[0];
6237
- worldRayOrigin[1] = tempVec4d[1];
6238
- worldRayOrigin[2] = tempVec4d[2];
6231
+ worldRayOrigin[0] = vec4Near[0];
6232
+ worldRayOrigin[1] = vec4Near[1];
6233
+ worldRayOrigin[2] = vec4Near[2];
6239
6234
 
6240
- math.subVec3(tempVec4d, tempVec4b, worldRayDir);
6235
+ math.subVec3(vec4Far, vec4Near, worldRayDir);
6241
6236
 
6242
6237
  math.normalizeVec3(worldRayDir);
6243
6238
  };
@@ -6261,8 +6256,8 @@ const math = {
6261
6256
  const worldRayOrigin = new FloatArrayType(3);
6262
6257
  const worldRayDir = new FloatArrayType(3);
6263
6258
 
6264
- return (canvas, viewMatrix, projMatrix, worldMatrix, canvasPos, localRayOrigin, localRayDir) => {
6265
- math.canvasPosToWorldRay(canvas, viewMatrix, projMatrix, canvasPos, worldRayOrigin, worldRayDir);
6259
+ return (canvas, viewMatrix, projMatrix, projection, worldMatrix, canvasPos, localRayOrigin, localRayDir) => {
6260
+ math.canvasPosToWorldRay(canvas, viewMatrix, projMatrix, projection, canvasPos, worldRayOrigin, worldRayDir);
6266
6261
  math.worldRayToLocalRay(worldMatrix, worldRayOrigin, worldRayDir, localRayOrigin, localRayDir);
6267
6262
  };
6268
6263
  }))(),
@@ -11117,7 +11112,7 @@ function activateDraggableDot(dot, cfg) {
11117
11112
  const pickWorldPos = canvasPos => {
11118
11113
  const origin = math.vec3();
11119
11114
  const direction = math.vec3();
11120
- math.canvasPosToWorldRay(canvas, scene.camera.viewMatrix, scene.camera.projMatrix, canvasPos, origin, direction);
11115
+ math.canvasPosToWorldRay(canvas, scene.camera.viewMatrix, scene.camera.projMatrix, scene.camera.projection, canvasPos, origin, direction);
11121
11116
  return ray2WorldPos(origin, direction, canvasPos);
11122
11117
  };
11123
11118
 
@@ -20010,6 +20005,7 @@ const Renderer$1 = function (scene, options) {
20010
20005
  let look;
20011
20006
  let pickViewMatrix = null;
20012
20007
  let pickProjMatrix = null;
20008
+ let projection = null;
20013
20009
 
20014
20010
  pickResult.pickSurface = params.pickSurface;
20015
20011
 
@@ -20020,6 +20016,7 @@ const Renderer$1 = function (scene, options) {
20020
20016
 
20021
20017
  pickViewMatrix = scene.camera.viewMatrix;
20022
20018
  pickProjMatrix = scene.camera.projMatrix;
20019
+ projection = scene.camera.projection;
20023
20020
 
20024
20021
  pickResult.canvasPos = params.canvasPos;
20025
20022
 
@@ -20032,6 +20029,7 @@ const Renderer$1 = function (scene, options) {
20032
20029
 
20033
20030
  pickViewMatrix = params.matrix;
20034
20031
  pickProjMatrix = scene.camera.projMatrix;
20032
+ projection = scene.camera.projection;
20035
20033
 
20036
20034
  } else {
20037
20035
 
@@ -20050,6 +20048,7 @@ const Renderer$1 = function (scene, options) {
20050
20048
  pickViewMatrix = math.lookAtMat4v(worldRayOrigin, look, up, tempMat4b);
20051
20049
  // pickProjMatrix = scene.camera.projMatrix;
20052
20050
  pickProjMatrix = scene.camera.ortho.matrix;
20051
+ projection = "ortho";
20053
20052
 
20054
20053
  pickResult.origin = worldRayOrigin;
20055
20054
  pickResult.direction = worldRayDir;
@@ -20097,7 +20096,7 @@ const Renderer$1 = function (scene, options) {
20097
20096
 
20098
20097
  gpuPickTriangle(pickBuffer, pickable, canvasPos, pickViewMatrix, pickProjMatrix, pickResult);
20099
20098
 
20100
- pickable.pickTriangleSurface(pickViewMatrix, pickProjMatrix, pickResult);
20099
+ pickable.pickTriangleSurface(pickViewMatrix, pickProjMatrix, projection, pickResult);
20101
20100
 
20102
20101
  pickResult.pickSurfacePrecision = false;
20103
20102
 
@@ -20370,7 +20369,9 @@ const Renderer$1 = function (scene, options) {
20370
20369
 
20371
20370
  const _pickResult = new PickResult();
20372
20371
 
20373
- return function (canvasPos, snapRadiusInPixels, snapToVertex, snapToEdge, pickResult = _pickResult) {
20372
+ return function (params, pickResult = _pickResult) {
20373
+
20374
+ const {canvasPos, origin, direction, snapRadius, snapToVertex, snapToEdge} = params;
20374
20375
 
20375
20376
  if (!snapToVertex && !snapToEdge) {
20376
20377
  return this.pick({canvasPos, pickSurface: true});
@@ -20384,7 +20385,7 @@ const Renderer$1 = function (scene, options) {
20384
20385
  frameCtx.pickZNear = scene.camera.project.near;
20385
20386
  frameCtx.pickZFar = scene.camera.project.far;
20386
20387
 
20387
- snapRadiusInPixels = snapRadiusInPixels || 30;
20388
+ const snapRadiusInPixels = snapRadius || 30;
20388
20389
 
20389
20390
  const vertexPickBuffer = renderBufferManager.getRenderBuffer("uniquePickColors-aabs", {
20390
20391
  depthTexture: true,
@@ -20395,8 +20396,8 @@ const Renderer$1 = function (scene, options) {
20395
20396
  });
20396
20397
 
20397
20398
  frameCtx.snapVectorA = [
20398
- getClipPosX(canvasPos[0] * resolutionScale, gl.drawingBufferWidth),
20399
- getClipPosY(canvasPos[1] * resolutionScale, gl.drawingBufferHeight),
20399
+ canvasPos ? getClipPosX(canvasPos[0] * resolutionScale, gl.drawingBufferWidth) : 0,
20400
+ canvasPos ? getClipPosY(canvasPos[1] * resolutionScale, gl.drawingBufferHeight) : 0,
20400
20401
  ];
20401
20402
 
20402
20403
  frameCtx.snapInvVectorAB = [
@@ -20423,7 +20424,14 @@ const Renderer$1 = function (scene, options) {
20423
20424
  // Set view and proj mats for VBO renderers
20424
20425
  ///////////////////////////////////////
20425
20426
 
20426
- const pickViewMatrix = scene.camera.viewMatrix;
20427
+ frameCtx.pickViewMatrix = (canvasPos
20428
+ ? scene.camera.viewMatrix
20429
+ : math.lookAtMat4v(
20430
+ origin,
20431
+ math.addVec3(origin, direction, math.vec3()),
20432
+ math.vec3([0, 1, 0]),
20433
+ math.mat4()));
20434
+
20427
20435
  const pickProjMatrix = scene.camera.projMatrix;
20428
20436
 
20429
20437
  for (let type in drawableTypeInfo) {
@@ -20432,7 +20440,7 @@ const Renderer$1 = function (scene, options) {
20432
20440
  for (let i = 0, len = drawableList.length; i < len; i++) {
20433
20441
  const drawable = drawableList[i];
20434
20442
  if (drawable.setPickMatrices) { // Eg. SceneModel, which needs pre-loading into texture
20435
- drawable.setPickMatrices(pickViewMatrix, pickProjMatrix);
20443
+ drawable.setPickMatrices(frameCtx.pickViewMatrix, pickProjMatrix);
20436
20444
  }
20437
20445
  }
20438
20446
  }
@@ -20609,7 +20617,7 @@ const Renderer$1 = function (scene, options) {
20609
20617
  pickResult.worldPos = snappedWorldPos;
20610
20618
  pickResult.worldNormal = snappedWorldNormal;
20611
20619
  pickResult.entity = snappedEntity;
20612
- pickResult.canvasPos = canvasPos;
20620
+ pickResult.canvasPos = canvasPos || scene.camera.projectWorldPos(worldPos || snappedWorldPos);
20613
20621
  pickResult.snappedCanvasPos = snappedCanvasPos || canvasPos;
20614
20622
 
20615
20623
  return pickResult;
@@ -32015,11 +32023,6 @@ class Scene extends Component {
32015
32023
  return null;
32016
32024
  }
32017
32025
 
32018
- if ((params.snapToVertex || params.snapToEdge) && !params.canvasPos) {
32019
- this.error("Scene.snapPick() `canvasPos` parameter expected for `snapToVertex:true` or `snapToEdge:true`");
32020
- return;
32021
- }
32022
-
32023
32026
  params = params || {};
32024
32027
 
32025
32028
  params.pickSurface = params.pickSurface || params.rayPick; // Backwards compatibility
@@ -32045,13 +32048,7 @@ class Scene extends Component {
32045
32048
  }
32046
32049
 
32047
32050
  if (params.snapToEdge || params.snapToVertex) {
32048
- pickResult = this._renderer.snapPick(
32049
- params.canvasPos,
32050
- params.snapRadius || 30,
32051
- params.snapToVertex,
32052
- params.snapToEdge,
32053
- pickResult
32054
- );
32051
+ pickResult = this._renderer.snapPick(params, pickResult);
32055
32052
  } else {
32056
32053
  pickResult = this._renderer.pick(params, pickResult);
32057
32054
  }
@@ -32082,12 +32079,7 @@ class Scene extends Component {
32082
32079
  this.error("Scene.snapPick() canvasPos parameter expected");
32083
32080
  return;
32084
32081
  }
32085
- return this._renderer.snapPick(
32086
- params.canvasPos,
32087
- params.snapRadius || 30,
32088
- params.snapToVertex,
32089
- params.snapToEdge,
32090
- );
32082
+ return this._renderer.snapPick(params);
32091
32083
  }
32092
32084
 
32093
32085
  /**
@@ -39825,8 +39817,8 @@ class Mesh extends Component {
39825
39817
  }
39826
39818
 
39827
39819
  /** @private */
39828
- pickTriangleSurface(pickViewMatrix, pickProjMatrix, pickResult) {
39829
- pickTriangleSurface(this, pickViewMatrix, pickProjMatrix, pickResult);
39820
+ pickTriangleSurface(pickViewMatrix, pickProjMatrix, projection, pickResult) {
39821
+ pickTriangleSurface(this, pickViewMatrix, pickProjMatrix, projection, pickResult);
39830
39822
  }
39831
39823
 
39832
39824
  /** @private */
@@ -39918,7 +39910,7 @@ const pickTriangleSurface = (function () {
39918
39910
  const tempVec3j = math.vec3();
39919
39911
  const tempVec3k = math.vec3();
39920
39912
 
39921
- return function (mesh, pickViewMatrix, pickProjMatrix, pickResult) {
39913
+ return function (mesh, pickViewMatrix, pickProjMatrix, projection, pickResult) {
39922
39914
 
39923
39915
  var primIndex = pickResult.primIndex;
39924
39916
 
@@ -39997,7 +39989,7 @@ const pickTriangleSurface = (function () {
39997
39989
  // Attempt to ray-pick the triangle in local space
39998
39990
 
39999
39991
  if (pickResult.canvasPos) {
40000
- math.canvasPosToLocalRay(canvas.canvas, mesh.origin ? createRTCViewMat(pickViewMatrix, mesh.origin) : pickViewMatrix, pickProjMatrix, mesh.worldMatrix, pickResult.canvasPos, localRayOrigin, localRayDir);
39992
+ math.canvasPosToLocalRay(canvas.canvas, mesh.origin ? createRTCViewMat(pickViewMatrix, mesh.origin) : pickViewMatrix, pickProjMatrix, projection, mesh.worldMatrix, pickResult.canvasPos, localRayOrigin, localRayDir);
40001
39993
 
40002
39994
  } else if (pickResult.origin && pickResult.direction) {
40003
39995
  math.worldRayToLocalRay(mesh.worldMatrix, pickResult.origin, pickResult.direction, localRayOrigin, localRayDir);
@@ -87572,7 +87564,7 @@ class DistanceMeasurement extends Component {
87572
87564
  }
87573
87565
 
87574
87566
  if (!this._zAxisLabelCulled) {
87575
- if(this._measurementOrientation === 'Vertical') {
87567
+ if(this._measurementOrientation === 'Vertical' && this.useRotationAdjustment) {
87576
87568
  this._zAxisLabel.setPrefix("");
87577
87569
  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);
87578
87570
  }
@@ -88610,27 +88602,27 @@ class DistanceMeasurementsMouseControl extends DistanceMeasurementsControl {
88610
88602
  if (!this._active) {
88611
88603
  return;
88612
88604
  }
88613
-
88605
+
88614
88606
  this.fire("activated", false);
88615
88607
 
88616
88608
  if (this.pointerLens) {
88617
88609
  this.pointerLens.visible = false;
88618
88610
  }
88619
- if (this._markerDiv) {
88620
- this._destroyMarkerDiv();
88621
- }
88622
- this.reset();
88611
+ // if (this._markerDiv) {
88612
+ // this._destroyMarkerDiv()
88613
+ // }
88614
+ // this.reset();
88623
88615
  const canvas = this.scene.canvas.canvas;
88624
88616
  canvas.removeEventListener("mousedown", this._onMouseDown);
88625
88617
  canvas.removeEventListener("mouseup", this._onMouseUp);
88626
88618
  const cameraControl = this.distanceMeasurementsPlugin.viewer.cameraControl;
88627
88619
  cameraControl.off(this._onCameraControlHoverSnapOrSurface);
88628
88620
  cameraControl.off(this._onCameraControlHoverSnapOrSurfaceOff);
88629
- if (this._currentDistanceMeasurement) {
88630
- this.distanceMeasurementsPlugin.fire("measurementCancel", this._currentDistanceMeasurement);
88631
- this._currentDistanceMeasurement.destroy();
88632
- this._currentDistanceMeasurement = null;
88633
- }
88621
+ // if (this._currentDistanceMeasurement) {
88622
+ // this.distanceMeasurementsPlugin.fire("measurementCancel", this._currentDistanceMeasurement);
88623
+ // this._currentDistanceMeasurement.destroy();
88624
+ // this._currentDistanceMeasurement = null;
88625
+ // }
88634
88626
  this._active = false;
88635
88627
  }
88636
88628
 
@@ -89165,7 +89157,7 @@ class DistanceMeasurementsPlugin extends Plugin {
89165
89157
  axisVisible: params.axisVisible !== false && this.defaultAxisVisible !== false,
89166
89158
  xAxisVisible: params.xAxisVisible !== false && this.defaultXAxisVisible !== false,
89167
89159
  yAxisVisible: params.yAxisVisible !== false && this.defaultYAxisVisible !== false,
89168
- zAxisVisibld: params.zAxisVisible !== false && this.defaultZAxisVisible !== false,
89160
+ zAxisVisible: params.zAxisVisible !== false && this.defaultZAxisVisible !== false,
89169
89161
  xLabelEnabled: params.xLabelEnabled !== false && this.defaultXLabelEnabled !== false,
89170
89162
  yLabelEnabled: params.yLabelEnabled !== false && this.defaultYLabelEnabled !== false,
89171
89163
  zLabelEnabled: params.zLabelEnabled !== false && this.defaultZLabelEnabled !== false,
@@ -96958,8 +96950,7 @@ class MousePickHandler {
96958
96950
  {
96959
96951
  const origin = math.vec3();
96960
96952
  const direction = math.vec3();
96961
- // The origin from math.canvasPosToWorldRay is incorrect for a perspective camera, should be the same as scene.camera.eye
96962
- math.canvasPosToWorldRay(scene.canvas.canvas, scene.camera.viewMatrix, scene.camera.projMatrix, states.pointerCanvasPos, origin, direction);
96953
+ math.canvasPosToWorldRay(scene.canvas.canvas, scene.camera.viewMatrix, scene.camera.projMatrix, scene.camera.projection, states.pointerCanvasPos, origin, direction);
96963
96954
  cameraControl.fire("rayMove", { canvasPos: states.pointerCanvasPos, ray: { origin: origin, direction: direction, canvasPos: states.pointerCanvasPos } }, true);
96964
96955
  }
96965
96956
 
@@ -97166,7 +97157,7 @@ class MousePickHandler {
97166
97157
 
97167
97158
  this._timeout = setTimeout(() => {
97168
97159
 
97169
- if (firstClickPickResult) {
97160
+ if (firstClickPickResult && firstClickPickResult.worldPos) {
97170
97161
 
97171
97162
  cameraControl.fire("picked", firstClickPickResult, true);
97172
97163
 
@@ -139067,7 +139058,7 @@ const mousePointSelector = function(viewer, ray2WorldPos) {
139067
139058
  const pickWorldPos = canvasPos => {
139068
139059
  const origin = math.vec3();
139069
139060
  const direction = math.vec3();
139070
- math.canvasPosToWorldRay(canvas, scene.camera.viewMatrix, scene.camera.projMatrix, canvasPos, origin, direction);
139061
+ math.canvasPosToWorldRay(canvas, scene.camera.viewMatrix, scene.camera.projMatrix, scene.camera.projection, canvasPos, origin, direction);
139071
139062
  return ray2WorldPos(origin, direction);
139072
139063
  };
139073
139064
 
@@ -139142,7 +139133,7 @@ const touchPointSelector = function(viewer, pointerCircle, ray2WorldPos) {
139142
139133
  const pickWorldPos = canvasPos => {
139143
139134
  const origin = math.vec3();
139144
139135
  const direction = math.vec3();
139145
- math.canvasPosToWorldRay(canvas, scene.camera.viewMatrix, scene.camera.projMatrix, canvasPos, origin, direction);
139136
+ math.canvasPosToWorldRay(canvas, scene.camera.viewMatrix, scene.camera.projMatrix, scene.camera.projection, canvasPos, origin, direction);
139146
139137
  return ray2WorldPos(origin, direction);
139147
139138
  };
139148
139139
 
@@ -140362,7 +140353,7 @@ class ZoneTranslateControl extends Component {
140362
140353
  const pickWorldPos = canvasPos => {
140363
140354
  const origin = math.vec3();
140364
140355
  const direction = math.vec3();
140365
- math.canvasPosToWorldRay(canvas, scene.camera.viewMatrix, scene.camera.projMatrix, canvasPos, origin, direction);
140356
+ math.canvasPosToWorldRay(canvas, scene.camera.viewMatrix, scene.camera.projMatrix, scene.camera.projection, canvasPos, origin, direction);
140366
140357
  return ray2WorldPos(origin, direction);
140367
140358
  };
140368
140359