@xeokit/xeokit-sdk 2.4.0-alpha-101 → 2.4.0-alpha-104

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@xeokit/xeokit-sdk",
3
- "version": "2.4.0-alpha-101",
3
+ "version": "2.4.0-alpha-104",
4
4
  "description": "Web Programming Toolkit for 3D/2D BIM and AEC Graphics",
5
5
  "module": "./dist/xeokit-sdk.es.js",
6
6
  "main": "./dist/xeokit-sdk.cjs.js",
@@ -94,7 +94,10 @@ class Bitmap extends Component {
94
94
  this._rtcPos = math.vec3();
95
95
  this._imageSize = math.vec2();
96
96
 
97
- this._texture = new Texture(this);
97
+ this._texture = new Texture(this, {
98
+ flipY: true
99
+ });
100
+
98
101
  this._image = new Image();
99
102
 
100
103
  if (this._type !== "jpg" && this._type !== "png") {
@@ -56,12 +56,13 @@ class MousePickHandler {
56
56
  }
57
57
 
58
58
  const hoverSubs = cameraControl.hasSubs("hover");
59
+ const hoverEnterSubs = cameraControl.hasSubs("hoverEnter");
59
60
  const hoverOutSubs = cameraControl.hasSubs("hoverOut");
60
61
  const hoverOffSubs = cameraControl.hasSubs("hoverOff");
61
62
  const hoverSurfaceSubs = cameraControl.hasSubs("hoverSurface");
62
63
  const hoverSnapOrSurfaceSubs = cameraControl.hasSubs("hoverSnapOrSurface");
63
64
 
64
- if (hoverSubs || hoverOutSubs || hoverOffSubs || hoverSurfaceSubs || hoverSnapOrSurfaceSubs) {
65
+ if (hoverSubs || hoverEnterSubs || hoverOutSubs || hoverOffSubs || hoverSurfaceSubs || hoverSnapOrSurfaceSubs) {
65
66
 
66
67
  pickController.pickCursorPos = states.pointerCanvasPos;
67
68
  pickController.schedulePickEntity = true;
@@ -3,6 +3,7 @@ import {Mesh} from "../mesh/Mesh.js";
3
3
  import {PhongMaterial} from "../materials/PhongMaterial.js";
4
4
  import {math} from "../math/math.js";
5
5
  import {VBOGeometry} from "../geometry/VBOGeometry.js";
6
+ import {worldToRTCPositions} from "../math";
6
7
 
7
8
  /**
8
9
  * A set of 3D line segments.
@@ -78,8 +79,10 @@ class LineSet extends Component {
78
79
  super(owner, cfg);
79
80
 
80
81
  this._positions = cfg.positions || [];
81
-
82
- this._origin = math.vec3(cfg.origin || [0, 0, 0]);
82
+ const rtcPositions = new Float32Array(this._positions.length);
83
+ const rtcCenter = math.vec3();
84
+ const cellSize = 100;
85
+ const rtcNeeded = worldToRTCPositions(this._positions, new Float32Array(this._positions.length), rtcCenter, cellSize);
83
86
 
84
87
  if (cfg.indices) {
85
88
  this._indices = cfg.indices;
@@ -97,9 +100,9 @@ class LineSet extends Component {
97
100
  collidable: cfg.collidable,
98
101
  geometry: new VBOGeometry(this, {
99
102
  primitive: "lines",
100
- positions: this._positions,
103
+ positions: rtcNeeded ? rtcPositions : this._positions,
101
104
  indices: this._indices,
102
- origin: cfg.origin
105
+ origin: rtcNeeded ? rtcCenter : null
103
106
  }),
104
107
  material: new PhongMaterial(this, {
105
108
  diffuse: cfg.color || [0, 0, 0],
@@ -0,0 +1,160 @@
1
+ import {Component} from '../Component.js';
2
+ import {math} from "../math/math.js";
3
+ import {SceneModel} from "../model";
4
+
5
+ /**
6
+ * A set of 3D line segments.
7
+ *
8
+ * * Creates a set of 3D line segments.
9
+ * * Registered by {@link LineSet#id} in {@link Scene#lineSets}.
10
+ * * Configure color using the {@link LinesMaterial} located at {@link Scene#linesMaterial}.
11
+ * * {@link BCFViewpointsPlugin} will save and load Linesets in BCF viewpoints.
12
+ *
13
+ * ## Usage
14
+ *
15
+ * In the example below, we'll load the Schependomlaan model, then use
16
+ * a ````LineSet```` to show a grid underneath the model.
17
+ *
18
+ * [<img src="http://xeokit.github.io/xeokit-sdk/assets/images/LineSet_grid.png">](/examples/#LineSet_grid)
19
+ *
20
+ * [[Run this example](/examples/#LineSet_grid)]
21
+ *
22
+ * ````javascript
23
+ * import {Viewer, XKTLoaderPlugin, LineSet, buildGridGeometry} from "https://cdn.jsdelivr.net/npm/@xeokit/xeokit-sdk/dist/xeokit-sdk.es.min.js";
24
+ *
25
+ * const viewer = new Viewer({
26
+ * canvasId: "myCanvas",
27
+ * transparent: true
28
+ * });
29
+ *
30
+ * const camera = viewer.camera;
31
+ *
32
+ * viewer.camera.eye = [-2.56, 8.38, 8.27];
33
+ * viewer.camera.look = [13.44, 3.31, -14.83];
34
+ * viewer.camera.up = [0.10, 0.98, -0.14];
35
+ *
36
+ * const xktLoader = new XKTLoaderPlugin(viewer);
37
+ *
38
+ * const model = xktLoader.load({
39
+ * id: "myModel",
40
+ * src: "../assets/models/xkt/v8/ifc/Schependomlaan.ifc.xkt",
41
+ * position: [0,1,0],
42
+ * edges: true,
43
+ * saoEnabled: true
44
+ * });
45
+ *
46
+ * const geometryArrays = buildGridGeometry({
47
+ * size: 100,
48
+ * divisions: 30
49
+ * });
50
+ *
51
+ * new LineSet(viewer.scene, {
52
+ * positions: geometryArrays.positions,
53
+ * indices: geometryArrays.indices
54
+ * });
55
+ * ````
56
+ */
57
+ class LineSet extends Component {
58
+
59
+ /**
60
+ * Creates a new LineSet.
61
+ *
62
+ * Registers the LineSet in {@link Scene#lineSets}; causes Scene to fire a "lineSetCreated" event.
63
+ *
64
+ * @constructor
65
+ * @param {Component} [owner] Owner component. When destroyed, the owner will destroy this ````LineSet```` as well.
66
+ * @param {*} [cfg] ````LineSet```` configuration
67
+ * @param {String} [cfg.id] Optional ID, unique among all components in the parent {@link Scene}, generated automatically when omitted.
68
+ * @param {Number[]} cfg.positions World-space 3D vertex positions.
69
+ * @param {Number[]} [cfg.indices] Indices to connect ````positions```` into line segments. Note that these are separate line segments, not a polyline.
70
+ * @param {Number[]} [cfg.color=[0,0,0]] The color of this ````LineSet````. This is both emissive and diffuse.
71
+ * @param {Boolean} [cfg.visible=true] Indicates whether or not this ````LineSet```` is visible.
72
+ * @param {Number} [cfg.opacity=1.0] ````LineSet````'s initial opacity factor.
73
+ */
74
+ constructor(owner, cfg = {}) {
75
+
76
+ super(owner, cfg);
77
+
78
+ this._positions = cfg.positions || [];
79
+
80
+ this._origin = math.vec3(cfg.origin || [0, 0, 0]);
81
+
82
+ if (cfg.indices) {
83
+ this._indices = cfg.indices;
84
+ } else {
85
+ this._indices = [];
86
+ for (let i = 0, len = (this._positions.length / 3) - 1; i < len; i += 2) {
87
+ this._indices.push(i);
88
+ this._indices.push(i + 1);
89
+ }
90
+ }
91
+ this._sceneModel = new SceneModel(this, { id: `${this.id}.lineset.scenemodel`});
92
+ this._sceneModel.createMesh({
93
+ id: `${this.id}.lineset.mesh`,
94
+ primitive: "lines",
95
+ positions: cfg.positions,
96
+ indices: cfg.indices,
97
+ color: cfg.color || [0, 0, 0],
98
+ clippable: false,
99
+ collidable: true
100
+ });
101
+ this._sceneModel.createEntity({
102
+ id: `${this.id}.lineset.entity`,
103
+ meshIds: [`${this.id}.lineset.mesh`]
104
+ });
105
+ this._sceneModel.finalize();
106
+ this.scene._lineSetCreated(this);
107
+ }
108
+
109
+ /**
110
+ * Sets if this ````LineSet```` is visible.
111
+ *
112
+ * Default value is ````true````.
113
+ *
114
+ * @param {Boolean} visible Set ````true```` to make this ````LineSet```` visible.
115
+ */
116
+ set visible(visible) {
117
+ this._sceneModel.visible = visible;
118
+ }
119
+
120
+ /**
121
+ * Gets if this ````LineSet```` is visible.
122
+ *
123
+ * Default value is ````true````.
124
+ *
125
+ * @returns {Boolean} Returns ````true```` if visible.
126
+ */
127
+ get visible() {
128
+ return this._sceneModel.visible;
129
+ }
130
+
131
+ /**
132
+ * Gets the 3D World-space vertex positions of the lines in this ````LineSet````.
133
+ *
134
+ * @returns {Number[]}
135
+ */
136
+ get positions() {
137
+ return this._positions;
138
+ }
139
+
140
+ /**
141
+ * Gets the vertex indices of the lines in this ````LineSet````.
142
+ *
143
+ * @returns {Number[]}
144
+ */
145
+ get indices() {
146
+ return this._indices;
147
+ }
148
+
149
+ /**
150
+ * Destroys this ````LineSet````.
151
+ *
152
+ * Removes the ```LineSet```` from {@link Scene#lineSets}; causes Scene to fire a "lineSetDestroyed" event.
153
+ */
154
+ destroy() {
155
+ super.destroy();
156
+ this.scene._lineSetDestroyed(this);
157
+ }
158
+ }
159
+
160
+ export {LineSet};
@@ -2245,7 +2245,7 @@ export class SceneModel extends Component {
2245
2245
  cfg.primitive = "triangles";
2246
2246
  }
2247
2247
  if (cfg.primitive !== "points" && cfg.primitive !== "lines" && cfg.primitive !== "triangles" && cfg.primitive !== "solid" && cfg.primitive !== "surface") {
2248
- this.error(`[createGeometry] Unsupported value for 'primitive': '${primitive}' - supported values are 'points', 'lines', 'triangles', 'solid' and 'surface'. Defaulting to 'triangles'.`);
2248
+ this.error(`[createGeometry] Unsupported value for 'primitive': '${cfg.primitive}' - supported values are 'points', 'lines', 'triangles', 'solid' and 'surface'. Defaulting to 'triangles'.`);
2249
2249
  return;
2250
2250
  }
2251
2251
  if (!cfg.positions && !cfg.positionsCompressed && !cfg.buckets) {
@@ -330,9 +330,9 @@ export class TrianglesDataTextureColorRenderer {
330
330
 
331
331
  src.push("uniform int renderPass;");
332
332
 
333
- if (scene.entityOffsetsEnabled) {
334
- src.push("in vec3 offset;");
335
- }
333
+ // if (scene.entityOffsetsEnabled) {
334
+ // src.push("in vec3 offset;");
335
+ // }
336
336
 
337
337
  src.push("uniform mat4 sceneModelWorldMatrix;");
338
338
  src.push("uniform mat4 viewMatrix;");
@@ -65,8 +65,7 @@ export class TrianglesDataTextureEdgesColorRenderer {
65
65
  if (gotOrigin || gotPosition) {
66
66
  const rtcOrigin = tempVec3a;
67
67
  if (gotOrigin) {
68
- const rotatedOrigin = tempVec3b;
69
- math.transformPoint3(rotationMatrix, origin, rotatedOrigin);
68
+ const rotatedOrigin = math.transformPoint3(rotationMatrix, origin, tempVec3b);
70
69
  rtcOrigin[0] = rotatedOrigin[0];
71
70
  rtcOrigin[1] = rotatedOrigin[1];
72
71
  rtcOrigin[2] = rotatedOrigin[2];
@@ -335,7 +334,7 @@ export class TrianglesDataTextureEdgesColorRenderer {
335
334
  // get XYZ offset
336
335
  src.push("vec4 offset = vec4(texelFetch (uTexturePerObjectIdOffsets, objectIndexCoords, 0).rgb, 0.0);");
337
336
 
338
- // src.push("worldPosition.xyz = worldPosition.xyz + offset.xyz;");
337
+ src.push("worldPosition.xyz = worldPosition.xyz + offset.xyz;");
339
338
 
340
339
  src.push(" vec4 viewPosition = viewMatrix * worldPosition; ");
341
340
 
@@ -7,7 +7,6 @@ const defaultColor = new Float32Array([0, 0, 0, 1]);
7
7
 
8
8
  const tempVec3a = math.vec3();
9
9
  const tempVec3b = math.vec3();
10
- const tempVec3c = math.vec3();
11
10
  const tempVec3d = math.vec3();
12
11
  const tempMat4a = math.mat4();
13
12
 
@@ -70,8 +69,7 @@ export class TrianglesDataTextureEdgesRenderer {
70
69
  if (gotOrigin || gotPosition) {
71
70
  const rtcOrigin = tempVec3a;
72
71
  if (gotOrigin) {
73
- const rotatedOrigin = tempVec3b;
74
- math.transformPoint3(rotationMatrix, origin, rotatedOrigin);
72
+ const rotatedOrigin = math.transformPoint3(rotationMatrix, origin, tempVec3b);
75
73
  rtcOrigin[0] = rotatedOrigin[0];
76
74
  rtcOrigin[1] = rotatedOrigin[1];
77
75
  rtcOrigin[2] = rotatedOrigin[2];
@@ -253,9 +251,9 @@ export class TrianglesDataTextureEdgesRenderer {
253
251
 
254
252
  src.push("uniform int renderPass;");
255
253
 
256
- if (scene.entityOffsetsEnabled) {
257
- src.push("in vec3 offset;");
258
- }
254
+ // if (scene.entityOffsetsEnabled) {
255
+ // src.push("in vec3 offset;");
256
+ // }
259
257
 
260
258
  src.push("uniform mat4 sceneModelWorldMatrix;");
261
259
  src.push("uniform mat4 viewMatrix;");
@@ -340,7 +338,7 @@ export class TrianglesDataTextureEdgesRenderer {
340
338
  // get XYZ offset
341
339
  src.push("vec4 offset = vec4(texelFetch (uTexturePerObjectIdOffsets, objectIndexCoords, 0).rgb, 0.0);");
342
340
 
343
- src.push("worldPosition.xyz = worldPosition.xyz + offset.xyz;");
341
+ src.push("worldPosition.xyz = worldPosition.xyz + offset.xyz + vec3(110.0,50.0, 10.0);");
344
342
 
345
343
  src.push(" vec4 viewPosition = viewMatrix * worldPosition; ");
346
344