@xeokit/xeokit-sdk 2.0.0-beta.25 → 2.0.0

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/README.md CHANGED
@@ -19,13 +19,14 @@ npm i @xeokit/xeokit-sdk
19
19
 
20
20
  ## Resources
21
21
 
22
- * [Website](https://xeokit.io/)
23
- * [Features](https://xeokit.io/index.html?foo=1#features)
24
- * [FAQ](https://xeokit.io/index.html?foo=1#faq)
25
- * [Blog](https://xeokit.io/blog.html)
22
+ * [xeokit.io](https://xeokit.io/)
26
23
  * [Examples](http://xeokit.github.io/xeokit-sdk/examples/)
27
- * [User Guides](https://www.notion.so/xeokit/xeokit-Documentation-4598591fcedb4889bf8896750651f74e)
24
+ * [Guides](https://www.notion.so/xeokit/xeokit-Documentation-4598591fcedb4889bf8896750651f74e)
28
25
  * [API Docs](https://xeokit.github.io/xeokit-sdk/docs/)
26
+ * [Changelog](https://xeokit.github.io/xeokit-sdk/CHANGE_LOG)
27
+ * [Features](https://xeokit.io/index.html?foo=1#features)
28
+ * [FAQ](https://xeokit.io/index.html?foo=1#faq)
29
+ * [Blog](https://xeokit.io/blog.html)
29
30
  * [License](https://xeokit.io/index.html#pricing)
30
31
 
31
32
 
@@ -15897,6 +15897,7 @@ const Renderer = function (scene, options) {
15897
15897
  const worldRayOrigin = math.vec3();
15898
15898
  const worldRayDir = math.vec3();
15899
15899
  const worldSurfacePos = math.vec3();
15900
+ const worldSurfaceNormal = math.vec3();
15900
15901
 
15901
15902
  return function (params, pickResult = _pickResult) {
15902
15903
 
@@ -15937,7 +15938,7 @@ const Renderer = function (scene, options) {
15937
15938
  // Picking with arbitrary World-space ray
15938
15939
  // Align camera along ray and fire ray through center of canvas
15939
15940
 
15940
- const pickFrustumMatrix = math.frustumMat4(-1, 1, -1, 1, scene.camera.project.near, scene.camera.project.far, tempMat4a);
15941
+ const pickFrustumMatrix = math.frustumMat4(-1, 1, -1, 1, 0.01, scene.camera.project.far, tempMat4a);
15941
15942
 
15942
15943
  if (params.matrix) {
15943
15944
 
@@ -15957,7 +15958,7 @@ const Renderer = function (scene, options) {
15957
15958
 
15958
15959
  math.normalizeVec3(randomVec3);
15959
15960
  math.cross3Vec3(worldRayDir, randomVec3, up);
15960
-
15961
+
15961
15962
  pickViewMatrix = math.lookAtMat4v(worldRayOrigin, look, up, tempMat4b);
15962
15963
  pickProjMatrix = pickFrustumMatrix;
15963
15964
 
@@ -15995,14 +15996,18 @@ const Renderer = function (scene, options) {
15995
15996
  math.canvasPosToWorldRay(scene.canvas.canvas, pickViewMatrix, pickProjMatrix, canvasPos, worldRayOrigin, worldRayDir);
15996
15997
  }
15997
15998
 
15998
- if (pickable.precisionRayPickSurface(worldRayOrigin, worldRayDir, worldSurfacePos)) {
15999
+ if (pickable.precisionRayPickSurface(worldRayOrigin, worldRayDir, worldSurfacePos, worldSurfaceNormal)) {
15999
16000
 
16000
16001
  pickResult.worldPos = worldSurfacePos;
16001
16002
 
16002
16003
  if (params.pickSurfaceNormal !== false) {
16003
- gpuPickWorldNormal(pickable, canvasPos, pickViewMatrix, pickProjMatrix, pickResult);
16004
+ pickResult.worldNormal = worldSurfaceNormal;
16004
16005
  }
16005
16006
 
16007
+ // if (params.pickSurfaceNormal !== false) {
16008
+ // gpuPickWorldNormal(pickable, canvasPos, pickViewMatrix, pickProjMatrix, pickResult);
16009
+ // }
16010
+
16006
16011
  pickResult.pickSurfacePrecision = true;
16007
16012
  }
16008
16013
 
@@ -27883,6 +27888,7 @@ function buildVertexDraw(mesh) {
27883
27888
  const lightsState = scene._lightsState;
27884
27889
  let light;
27885
27890
  const billboard = meshState.billboard;
27891
+ const background = meshState.background;
27886
27892
  const stationary = meshState.stationary;
27887
27893
  const texturing = hasTextures(mesh);
27888
27894
  const normals = hasNormals$1(mesh);
@@ -28014,6 +28020,8 @@ function buildVertexDraw(mesh) {
28014
28020
  src.push("mat4 modelMatrix2 = modelMatrix;");
28015
28021
  if (stationary) {
28016
28022
  src.push("viewMatrix2[3][0] = viewMatrix2[3][1] = viewMatrix2[3][2] = 0.0;");
28023
+ } else if (background) {
28024
+ src.push("viewMatrix2[3] = vec4(0.0, 0.0, 0.0 ,1.0);");
28017
28025
  }
28018
28026
  if (billboard === "spherical" || billboard === "cylindrical") {
28019
28027
  src.push("mat4 modelViewMatrix = viewMatrix2 * modelMatrix2;");
@@ -28092,6 +28100,9 @@ function buildVertexDraw(mesh) {
28092
28100
  }
28093
28101
  src.push("isPerspective = float (isPerspectiveMatrix(projMatrix));");
28094
28102
  }
28103
+ if (background) {
28104
+ src.push("clipPos.z = clipPos.w;");
28105
+ }
28095
28106
  src.push("gl_Position = clipPos;");
28096
28107
  if (receivesShadow) {
28097
28108
  src.push("const mat4 texUnitConverter = mat4(0.5, 0.0, 0.0, 0.0, 0.0, 0.5, 0.0, 0.0, 0.0, 0.0, 0.5, 0.0, 0.5, 0.5, 0.5, 1.0);");
@@ -29192,9 +29203,13 @@ DrawRenderer.prototype.drawMesh = function (frameCtx, mesh) {
29192
29203
  const geometryState = mesh._geometry._state;
29193
29204
  const camera = scene.camera;
29194
29205
  const rtcCenter = mesh.rtcCenter;
29206
+ const background = meshState.background;
29195
29207
 
29196
29208
  if (frameCtx.lastProgramId !== this._program.id) {
29197
29209
  frameCtx.lastProgramId = this._program.id;
29210
+ if (background) {
29211
+ gl.depthFunc(gl.LEQUAL);
29212
+ }
29198
29213
  this._bindProgram(frameCtx);
29199
29214
  }
29200
29215
 
@@ -29711,6 +29726,10 @@ DrawRenderer.prototype.drawMesh = function (frameCtx, mesh) {
29711
29726
  gl.drawArrays(gl.TRIANGLES, 0, geometryState.positions.numItems);
29712
29727
  frameCtx.drawArrays++;
29713
29728
  }
29729
+
29730
+ if (background) {
29731
+ gl.depthFunc(gl.LESS);
29732
+ }
29714
29733
  };
29715
29734
 
29716
29735
  DrawRenderer.prototype._allocate = function (mesh) {
@@ -32742,6 +32761,7 @@ class Mesh extends Component {
32742
32761
  * @param {Boolean} [cfg.highlighted=false] Indicates if the Mesh is initially highlighted.
32743
32762
  * @param {Boolean} [cfg.selected=false] Indicates if the Mesh is initially selected.
32744
32763
  * @param {Boolean} [cfg.edges=false] Indicates if the Mesh's edges are initially emphasized.
32764
+ * @param {Boolean} [cfg.background=false] Indicates if the Mesh should act as background, e.g., it can be used for a skybox.
32745
32765
  * @param {Number[]} [cfg.colorize=[1.0,1.0,1.0]] Mesh's initial RGB colorize color, multiplies by the rendered fragment colors.
32746
32766
  * @param {Number} [cfg.opacity=1.0] Mesh's initial opacity factor, multiplies by the rendered fragment alpha.
32747
32767
  * @param {String} [cfg.billboard="none"] Mesh's billboarding behaviour. Options are "none" for no billboarding, "spherical" to always directly face {@link Camera.eye}, rotating both vertically and horizontally, or "cylindrical" to face the {@link Camera#eye} while rotating only about its vertically axis (use that mode for things like trees on a landscape).
@@ -32781,6 +32801,7 @@ class Mesh extends Component {
32781
32801
  selected: false,
32782
32802
  edges: false,
32783
32803
  stationary: !!cfg.stationary,
32804
+ background: !!cfg.background,
32784
32805
  billboard: this._checkBillboard(cfg.billboard),
32785
32806
  layer: null,
32786
32807
  colorize: null,
@@ -37846,7 +37867,7 @@ class BCFViewpointsPlugin extends Plugin {
37846
37867
  * @param {Boolean} [options.updateCompositeObjects=false] When ````true````, then when visibility and selection updates refer to composite objects (eg. an IfcBuildingStorey),
37847
37868
  * then this method will apply the updates to objects within those composites.
37848
37869
  */
37849
- setViewpoint(bcfViewpoint, options = {}, done) {
37870
+ setViewpoint(bcfViewpoint, options = {}) {
37850
37871
  if (!bcfViewpoint) {
37851
37872
  return;
37852
37873
  }
@@ -38001,11 +38022,8 @@ class BCFViewpointsPlugin extends Plugin {
38001
38022
  camera.look = look;
38002
38023
  camera.up = up;
38003
38024
  camera.projection = projection;
38004
- if (done) {
38005
- done();
38006
- }
38007
38025
  } else {
38008
- viewer.cameraFlight.flyTo({eye, look, up, duration: options.duration, projection}, done);
38026
+ viewer.cameraFlight.flyTo({eye, look, up, duration: options.duration, projection});
38009
38027
  }
38010
38028
  }
38011
38029
  }
@@ -39876,8 +39894,8 @@ class PerformanceMesh {
39876
39894
  }
39877
39895
 
39878
39896
  /** @private */
39879
- precisionRayPickSurface(worldRayOrigin, worldRayDir, worldSurfacePos) {
39880
- return this._layer.precisionRayPickSurface ? this._layer.precisionRayPickSurface(this._portionId, worldRayOrigin, worldRayDir, worldSurfacePos) : false;
39897
+ precisionRayPickSurface(worldRayOrigin, worldRayDir, worldSurfacePos, worldSurfaceNormal) {
39898
+ return this._layer.precisionRayPickSurface ? this._layer.precisionRayPickSurface(this._portionId, worldRayOrigin, worldRayDir, worldSurfacePos, worldSurfaceNormal) : false;
39881
39899
  }
39882
39900
 
39883
39901
  /** @private */
@@ -46635,7 +46653,7 @@ class TrianglesBatchingLayer {
46635
46653
 
46636
46654
  //------------------------------------------------------------------------------------------------
46637
46655
 
46638
- precisionRayPickSurface(portionId, worldRayOrigin, worldRayDir, worldSurfacePos) {
46656
+ precisionRayPickSurface(portionId, worldRayOrigin, worldRayDir, worldSurfacePos, worldNormal) {
46639
46657
 
46640
46658
  if (!this.model.scene.pickSurfacePrecisionEnabled) {
46641
46659
  return false;
@@ -46713,11 +46731,19 @@ class TrianglesBatchingLayer {
46713
46731
  if (!gotIntersect || dist > closestDist) {
46714
46732
  closestDist = dist;
46715
46733
  worldSurfacePos.set(closestIntersectPos);
46734
+ if (worldNormal) { // Not that wasteful to eagerly compute - unlikely to hit >2 surfaces on most geometry
46735
+ math.triangleNormal(a, b, c, worldNormal);
46736
+ }
46716
46737
  gotIntersect = true;
46717
46738
  }
46718
46739
  }
46719
46740
  }
46720
46741
 
46742
+ if (gotIntersect && worldNormal) {
46743
+ math.transformVec3(this.model.worldNormalMatrix, worldNormal, worldNormal);
46744
+ math.normalizeVec3(worldNormal);
46745
+ }
46746
+
46721
46747
  return gotIntersect;
46722
46748
  }
46723
46749
 
@@ -53044,6 +53070,7 @@ class TrianglesInstancingLayer {
53044
53070
  if (this.model.scene.pickSurfacePrecisionEnabled) {
53045
53071
  portion.matrix = meshMatrix.slice();
53046
53072
  portion.inverseMatrix = null; // Lazy-computed in precisionRayPickSurface
53073
+ portion.normalMatrix = null; // Lazy-computed in precisionRayPickSurface
53047
53074
  }
53048
53075
 
53049
53076
  this._portions.push(portion);
@@ -53674,7 +53701,7 @@ class TrianglesInstancingLayer {
53674
53701
 
53675
53702
  //-----------------------------------------------------------------------------------------
53676
53703
 
53677
- precisionRayPickSurface(portionId, worldRayOrigin, worldRayDir, worldSurfacePos) {
53704
+ precisionRayPickSurface(portionId, worldRayOrigin, worldRayDir, worldSurfacePos, worldNormal) {
53678
53705
 
53679
53706
  if (!this.model.scene.pickSurfacePrecisionEnabled) {
53680
53707
  return false;
@@ -53692,6 +53719,10 @@ class TrianglesInstancingLayer {
53692
53719
  portion.inverseMatrix = math.inverseMat4(portion.matrix, math.mat4());
53693
53720
  }
53694
53721
 
53722
+ if (worldNormal && !portion.normalMatrix) {
53723
+ portion.normalMatrix = math.transposeMat4(portion.inverseMatrix, math.mat4());
53724
+ }
53725
+
53695
53726
  const quantizedPositions = state.quantizedPositions;
53696
53727
  const indices = state.indices;
53697
53728
  const rtcCenter = state.rtcCenter;
@@ -53760,11 +53791,20 @@ class TrianglesInstancingLayer {
53760
53791
  if (!gotIntersect || dist > closestDist) {
53761
53792
  closestDist = dist;
53762
53793
  worldSurfacePos.set(closestIntersectPos);
53794
+ if (worldNormal) { // Not that wasteful to eagerly compute - unlikely to hit >2 surfaces on most geometry
53795
+ math.triangleNormal(a, b, c, worldNormal);
53796
+ }
53763
53797
  gotIntersect = true;
53764
53798
  }
53765
53799
  }
53766
53800
  }
53767
53801
 
53802
+ if (gotIntersect && worldNormal) {
53803
+ math.transformVec3(portion.normalMatrix, worldNormal, worldNormal);
53804
+ math.transformVec3(this.model.worldNormalMatrix, worldNormal, worldNormal);
53805
+ math.normalizeVec3(worldNormal);
53806
+ }
53807
+
53768
53808
  return gotIntersect;
53769
53809
  }
53770
53810
 
@@ -69839,14 +69879,16 @@ var parseGLTF$1 = (function () {
69839
69879
  var geometry;
69840
69880
 
69841
69881
  for (var i = 0, len = primitivesInfo.length; i < len; i++) {
69842
-
69882
+ primitiveInfo = primitivesInfo[i];
69883
+ if (primitiveInfo.mode < 4 ) {
69884
+ continue;
69885
+ }
69843
69886
  geometryCfg = {
69844
69887
  primitive: "triangles",
69845
69888
  compressGeometry: true,
69846
69889
  edgeThreshold: ctx.edgeThreshold
69847
69890
  };
69848
69891
 
69849
- primitiveInfo = primitivesInfo[i];
69850
69892
  indicesIndex = primitiveInfo.indices;
69851
69893
 
69852
69894
  if (indicesIndex !== null && indicesIndex !== undefined) {
@@ -70530,11 +70572,14 @@ const parseGLTF = (function () {
70530
70572
  const meshIds = [];
70531
70573
 
70532
70574
  for (let i = 0; i < numPrimitives; i++) {
70575
+ const primitiveInfo = meshInfo.primitives[i];
70576
+ if (primitiveInfo.mode < 4 ) {
70577
+ continue;
70578
+ }
70533
70579
  const meshCfg = {
70534
70580
  id: performanceModel.id + "." + ctx.numObjects++,
70535
70581
  matrix: worldMatrix
70536
70582
  };
70537
- const primitiveInfo = meshInfo.primitives[i];
70538
70583
 
70539
70584
  const materialIndex = primitiveInfo.material;
70540
70585
  let materialInfo;
@@ -75289,6 +75334,7 @@ class Skybox extends Component {
75289
75334
  12, 13, 14, 12, 14, 15, 16, 17, 18, 16, 18, 19, 20, 21, 22, 20, 22, 23
75290
75335
  ]
75291
75336
  }),
75337
+ background: true,
75292
75338
  scale: [2000, 2000, 2000], // Overridden when we initialize the 'size' property, below
75293
75339
  rotation: [0, -90, 0],
75294
75340
  material: new PhongMaterial(this, {
@@ -75299,6 +75345,8 @@ class Skybox extends Component {
75299
75345
  emissiveMap: new Texture(this, {
75300
75346
  src: cfg.src,
75301
75347
  flipY: true,
75348
+ wrapS: "clampToEdge",
75349
+ wrapT: "clampToEdge",
75302
75350
  encoding: cfg.encoding || "sRGB"
75303
75351
  }),
75304
75352
  backfaces: true // Show interior faces of our skybox geometry
@@ -100419,13 +100467,13 @@ const tempCameraTarget = {
100419
100467
  */
100420
100468
  class KeyboardAxisViewHandler {
100421
100469
 
100422
- constructor(scene, controllers, configs, states, updates) {
100470
+ constructor(scene, controllers, configs, states) {
100423
100471
 
100424
100472
  this._scene = scene;
100425
100473
  const cameraControl = controllers.cameraControl;
100426
100474
  const camera = scene.camera;
100427
100475
 
100428
- scene.input.on("keydown", this._documentKeyDownHandler = (e) => {
100476
+ this._onSceneKeyDown = scene.input.on("keydown", () => {
100429
100477
 
100430
100478
  if (!(configs.active && configs.pointerEnabled) || (!scene.input.keyboardEnabled)) {
100431
100479
  return;
@@ -100517,7 +100565,7 @@ class KeyboardAxisViewHandler {
100517
100565
  }
100518
100566
 
100519
100567
  destroy() {
100520
- document.removeEventListener("keydown", this._documentKeyDownHandler);
100568
+ this._scene.input.off(this._onSceneKeyDown);
100521
100569
  }
100522
100570
  }
100523
100571
 
@@ -100891,22 +100939,19 @@ class KeyboardPanRotateDollyHandler {
100891
100939
 
100892
100940
  const canvas = scene.canvas.canvas;
100893
100941
 
100894
- controllers.pickController;
100895
-
100896
100942
  let mouseMovedSinceLastKeyboardDolly = true;
100897
100943
 
100898
- document.addEventListener("mousemove", this._documentMouseMoveHandler = () => {
100944
+ this._onSceneMouseMove = input.on("mousemove", () => {
100899
100945
  mouseMovedSinceLastKeyboardDolly = true;
100900
100946
  });
100901
100947
 
100902
- document.addEventListener("keydown", this._documentKeyDownHandler = (e) => {
100948
+ this._onSceneKeyDown = input.on("keydown", (keyCode) => {
100903
100949
  if (!(configs.active && configs.pointerEnabled) || (!scene.input.keyboardEnabled)) {
100904
100950
  return;
100905
100951
  }
100906
100952
  if (!states.mouseover) {
100907
100953
  return;
100908
100954
  }
100909
- const keyCode = e.keyCode;
100910
100955
  keyDownMap[keyCode] = true;
100911
100956
 
100912
100957
  if (keyCode === input.KEY_SHIFT) {
@@ -100914,14 +100959,13 @@ class KeyboardPanRotateDollyHandler {
100914
100959
  }
100915
100960
  });
100916
100961
 
100917
- document.addEventListener("keyup", this._documentKeyUpHandler = (e) => {
100962
+ this._onSceneKeyUp = input.on("keyup", (keyCode) => {
100918
100963
  if (!(configs.active && configs.pointerEnabled) || (!scene.input.keyboardEnabled)) {
100919
100964
  return;
100920
100965
  }
100921
100966
  if (!states.mouseover) {
100922
100967
  return;
100923
100968
  }
100924
- const keyCode = e.keyCode;
100925
100969
  keyDownMap[keyCode] = false;
100926
100970
 
100927
100971
  if (keyCode === input.KEY_SHIFT) {
@@ -101056,9 +101100,9 @@ class KeyboardPanRotateDollyHandler {
101056
101100
 
101057
101101
  this._scene.off(this._onTick);
101058
101102
 
101059
- document.removeEventListener("mousemove", this._documentMouseMoveHandler);
101060
- document.removeEventListener("keydown", this._documentKeyDownHandler);
101061
- document.removeEventListener("keyup", this._documentKeyUpHandler);
101103
+ this._scene.input.off(this._onSceneMouseMove);
101104
+ this._scene.input.off(this._onSceneKeyDown);
101105
+ this._scene.input.off(this._onSceneKeyUp);
101062
101106
  }
101063
101107
  }
101064
101108