@xeokit/xeokit-sdk 2.5.0-beta → 2.5.1-beta
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 +136 -0
- package/dist/xeokit-sdk.es.js +136 -0
- package/dist/xeokit-sdk.es5.js +4 -4
- 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/plugins/AngleMeasurementsPlugin/AngleMeasurement.js +32 -0
- package/src/plugins/AngleMeasurementsPlugin/AngleMeasurementsPlugin.js +1 -0
- package/src/plugins/DistanceMeasurementsPlugin/DistanceMeasurement.js +44 -0
- package/src/plugins/lib/html/Dot.js +23 -0
- package/src/plugins/lib/html/Label.js +18 -0
- package/src/plugins/lib/html/Wire.js +18 -0
- package/src/plugins/LODCullingPlugin/LODCullingPlugin.js +0 -209
- package/src/plugins/LODCullingPlugin/LODManager.js +0 -82
- package/src/plugins/LODCullingPlugin/LODState.js +0 -130
- package/src/plugins/LODCullingPlugin/index.js +0 -1
- package/src/viewer/scene/model/vbo/BindableDataTexture.js +0 -31
- package/src/viewer/scene/model/vbo/DataTextureGenerator.js +0 -38
- package/src/viewer/scene/webgl/Renderer2.js +0 -1830
package/package.json
CHANGED
|
@@ -52,10 +52,12 @@ class AngleMeasurement extends Component {
|
|
|
52
52
|
|
|
53
53
|
const onMouseOver = cfg.onMouseOver ? (event) => {
|
|
54
54
|
cfg.onMouseOver(event, this);
|
|
55
|
+
this.plugin.viewer.scene.canvas.canvas.dispatchEvent(new MouseEvent('mouseover', event));
|
|
55
56
|
} : null;
|
|
56
57
|
|
|
57
58
|
const onMouseLeave = cfg.onMouseLeave ? (event) => {
|
|
58
59
|
cfg.onMouseLeave(event, this);
|
|
60
|
+
this.plugin.viewer.scene.canvas.canvas.dispatchEvent(new MouseEvent('mouseleave', event));
|
|
59
61
|
} : null;
|
|
60
62
|
|
|
61
63
|
const onContextMenu = cfg.onContextMenu ? (event) => {
|
|
@@ -66,12 +68,27 @@ class AngleMeasurement extends Component {
|
|
|
66
68
|
this.plugin.viewer.scene.canvas.canvas.dispatchEvent(new WheelEvent('wheel', event));
|
|
67
69
|
};
|
|
68
70
|
|
|
71
|
+
const onMouseDown = (event) => {
|
|
72
|
+
this.plugin.viewer.scene.canvas.canvas.dispatchEvent(new MouseEvent('mousedown', event));
|
|
73
|
+
} ;
|
|
74
|
+
|
|
75
|
+
const onMouseUp = (event) => {
|
|
76
|
+
this.plugin.viewer.scene.canvas.canvas.dispatchEvent(new MouseEvent('mouseup', event));
|
|
77
|
+
};
|
|
78
|
+
|
|
79
|
+
const onMouseMove = (event) => {
|
|
80
|
+
this.plugin.viewer.scene.canvas.canvas.dispatchEvent(new MouseEvent('mousemove', event));
|
|
81
|
+
};
|
|
82
|
+
|
|
69
83
|
this._originDot = new Dot(this._container, {
|
|
70
84
|
fillColor: this._color,
|
|
71
85
|
zIndex: plugin.zIndex !== undefined ? plugin.zIndex + 2 : undefined,
|
|
72
86
|
onMouseOver,
|
|
73
87
|
onMouseLeave,
|
|
74
88
|
onMouseWheel,
|
|
89
|
+
onMouseDown,
|
|
90
|
+
onMouseUp,
|
|
91
|
+
onMouseMove,
|
|
75
92
|
onContextMenu
|
|
76
93
|
});
|
|
77
94
|
this._cornerDot = new Dot(this._container, {
|
|
@@ -80,6 +97,9 @@ class AngleMeasurement extends Component {
|
|
|
80
97
|
onMouseOver,
|
|
81
98
|
onMouseLeave,
|
|
82
99
|
onMouseWheel,
|
|
100
|
+
onMouseDown,
|
|
101
|
+
onMouseUp,
|
|
102
|
+
onMouseMove,
|
|
83
103
|
onContextMenu
|
|
84
104
|
});
|
|
85
105
|
this._targetDot = new Dot(this._container, {
|
|
@@ -88,6 +108,9 @@ class AngleMeasurement extends Component {
|
|
|
88
108
|
onMouseOver,
|
|
89
109
|
onMouseLeave,
|
|
90
110
|
onMouseWheel,
|
|
111
|
+
onMouseDown,
|
|
112
|
+
onMouseUp,
|
|
113
|
+
onMouseMove,
|
|
91
114
|
onContextMenu
|
|
92
115
|
});
|
|
93
116
|
|
|
@@ -98,6 +121,9 @@ class AngleMeasurement extends Component {
|
|
|
98
121
|
onMouseOver,
|
|
99
122
|
onMouseLeave,
|
|
100
123
|
onMouseWheel,
|
|
124
|
+
onMouseDown,
|
|
125
|
+
onMouseUp,
|
|
126
|
+
onMouseMove,
|
|
101
127
|
onContextMenu
|
|
102
128
|
});
|
|
103
129
|
this._targetWire = new Wire(this._container, {
|
|
@@ -107,6 +133,9 @@ class AngleMeasurement extends Component {
|
|
|
107
133
|
onMouseOver,
|
|
108
134
|
onMouseLeave,
|
|
109
135
|
onMouseWheel,
|
|
136
|
+
onMouseDown,
|
|
137
|
+
onMouseUp,
|
|
138
|
+
onMouseMove,
|
|
110
139
|
onContextMenu
|
|
111
140
|
});
|
|
112
141
|
|
|
@@ -118,6 +147,9 @@ class AngleMeasurement extends Component {
|
|
|
118
147
|
onMouseOver,
|
|
119
148
|
onMouseLeave,
|
|
120
149
|
onMouseWheel,
|
|
150
|
+
onMouseDown,
|
|
151
|
+
onMouseUp,
|
|
152
|
+
onMouseMove,
|
|
121
153
|
onContextMenu
|
|
122
154
|
});
|
|
123
155
|
|
|
@@ -352,6 +352,7 @@ export class AngleMeasurementsPlugin extends Plugin {
|
|
|
352
352
|
measurement.on("destroyed", () => {
|
|
353
353
|
delete this._measurements[measurement.id];
|
|
354
354
|
});
|
|
355
|
+
measurement.clickable = true;
|
|
355
356
|
this.fire("measurementCreated", measurement);
|
|
356
357
|
return measurement;
|
|
357
358
|
}
|
|
@@ -62,12 +62,26 @@ class DistanceMeasurement extends Component {
|
|
|
62
62
|
|
|
63
63
|
const onMouseOver = cfg.onMouseOver ? (event) => {
|
|
64
64
|
cfg.onMouseOver(event, this);
|
|
65
|
+
this.plugin.viewer.scene.canvas.canvas.dispatchEvent(new MouseEvent('mouseover', event));
|
|
65
66
|
} : null;
|
|
66
67
|
|
|
67
68
|
const onMouseLeave = cfg.onMouseLeave ? (event) => {
|
|
68
69
|
cfg.onMouseLeave(event, this);
|
|
70
|
+
this.plugin.viewer.scene.canvas.canvas.dispatchEvent(new MouseEvent('mouseleave', event));
|
|
69
71
|
} : null;
|
|
70
72
|
|
|
73
|
+
const onMouseDown = (event) => {
|
|
74
|
+
this.plugin.viewer.scene.canvas.canvas.dispatchEvent(new MouseEvent('mousedown', event));
|
|
75
|
+
} ;
|
|
76
|
+
|
|
77
|
+
const onMouseUp = (event) => {
|
|
78
|
+
this.plugin.viewer.scene.canvas.canvas.dispatchEvent(new MouseEvent('mouseup', event));
|
|
79
|
+
};
|
|
80
|
+
|
|
81
|
+
const onMouseMove = (event) => {
|
|
82
|
+
this.plugin.viewer.scene.canvas.canvas.dispatchEvent(new MouseEvent('mousemove', event));
|
|
83
|
+
};
|
|
84
|
+
|
|
71
85
|
const onContextMenu = cfg.onContextMenu ? (event) => {
|
|
72
86
|
cfg.onContextMenu(event, this);
|
|
73
87
|
} : null;
|
|
@@ -82,6 +96,9 @@ class DistanceMeasurement extends Component {
|
|
|
82
96
|
onMouseOver,
|
|
83
97
|
onMouseLeave,
|
|
84
98
|
onMouseWheel,
|
|
99
|
+
onMouseDown,
|
|
100
|
+
onMouseUp,
|
|
101
|
+
onMouseMove,
|
|
85
102
|
onContextMenu
|
|
86
103
|
});
|
|
87
104
|
|
|
@@ -91,6 +108,9 @@ class DistanceMeasurement extends Component {
|
|
|
91
108
|
onMouseOver,
|
|
92
109
|
onMouseLeave,
|
|
93
110
|
onMouseWheel,
|
|
111
|
+
onMouseDown,
|
|
112
|
+
onMouseUp,
|
|
113
|
+
onMouseMove,
|
|
94
114
|
onContextMenu
|
|
95
115
|
});
|
|
96
116
|
|
|
@@ -102,6 +122,9 @@ class DistanceMeasurement extends Component {
|
|
|
102
122
|
onMouseOver,
|
|
103
123
|
onMouseLeave,
|
|
104
124
|
onMouseWheel,
|
|
125
|
+
onMouseDown,
|
|
126
|
+
onMouseUp,
|
|
127
|
+
onMouseMove,
|
|
105
128
|
onContextMenu
|
|
106
129
|
});
|
|
107
130
|
|
|
@@ -113,6 +136,9 @@ class DistanceMeasurement extends Component {
|
|
|
113
136
|
onMouseOver,
|
|
114
137
|
onMouseLeave,
|
|
115
138
|
onMouseWheel,
|
|
139
|
+
onMouseDown,
|
|
140
|
+
onMouseUp,
|
|
141
|
+
onMouseMove,
|
|
116
142
|
onContextMenu
|
|
117
143
|
});
|
|
118
144
|
|
|
@@ -124,6 +150,9 @@ class DistanceMeasurement extends Component {
|
|
|
124
150
|
onMouseOver,
|
|
125
151
|
onMouseLeave,
|
|
126
152
|
onMouseWheel,
|
|
153
|
+
onMouseDown,
|
|
154
|
+
onMouseUp,
|
|
155
|
+
onMouseMove,
|
|
127
156
|
onContextMenu
|
|
128
157
|
});
|
|
129
158
|
|
|
@@ -135,6 +164,9 @@ class DistanceMeasurement extends Component {
|
|
|
135
164
|
onMouseOver,
|
|
136
165
|
onMouseLeave,
|
|
137
166
|
onMouseWheel,
|
|
167
|
+
onMouseDown,
|
|
168
|
+
onMouseUp,
|
|
169
|
+
onMouseMove,
|
|
138
170
|
onContextMenu
|
|
139
171
|
});
|
|
140
172
|
|
|
@@ -146,6 +178,9 @@ class DistanceMeasurement extends Component {
|
|
|
146
178
|
onMouseOver,
|
|
147
179
|
onMouseLeave,
|
|
148
180
|
onMouseWheel,
|
|
181
|
+
onMouseDown,
|
|
182
|
+
onMouseUp,
|
|
183
|
+
onMouseMove,
|
|
149
184
|
onContextMenu
|
|
150
185
|
});
|
|
151
186
|
|
|
@@ -157,6 +192,9 @@ class DistanceMeasurement extends Component {
|
|
|
157
192
|
onMouseOver,
|
|
158
193
|
onMouseLeave,
|
|
159
194
|
onMouseWheel,
|
|
195
|
+
onMouseDown,
|
|
196
|
+
onMouseUp,
|
|
197
|
+
onMouseMove,
|
|
160
198
|
onContextMenu
|
|
161
199
|
});
|
|
162
200
|
|
|
@@ -168,6 +206,9 @@ class DistanceMeasurement extends Component {
|
|
|
168
206
|
onMouseOver,
|
|
169
207
|
onMouseLeave,
|
|
170
208
|
onMouseWheel,
|
|
209
|
+
onMouseDown,
|
|
210
|
+
onMouseUp,
|
|
211
|
+
onMouseMove,
|
|
171
212
|
onContextMenu
|
|
172
213
|
});
|
|
173
214
|
|
|
@@ -179,6 +220,9 @@ class DistanceMeasurement extends Component {
|
|
|
179
220
|
onMouseOver,
|
|
180
221
|
onMouseLeave,
|
|
181
222
|
onMouseWheel,
|
|
223
|
+
onMouseDown,
|
|
224
|
+
onMouseUp,
|
|
225
|
+
onMouseMove,
|
|
182
226
|
onContextMenu
|
|
183
227
|
});
|
|
184
228
|
|
|
@@ -56,9 +56,14 @@ class Dot {
|
|
|
56
56
|
}
|
|
57
57
|
parentElement.appendChild(dotClickable);
|
|
58
58
|
|
|
59
|
+
dotClickable.addEventListener('click', (event) => {
|
|
60
|
+
parentElement.dispatchEvent(new MouseEvent('mouseover', event));
|
|
61
|
+
});
|
|
62
|
+
|
|
59
63
|
if (cfg.onMouseOver) {
|
|
60
64
|
dotClickable.addEventListener('mouseover', (event) => {
|
|
61
65
|
cfg.onMouseOver(event, this);
|
|
66
|
+
parentElement.dispatchEvent(new MouseEvent('mouseover', event));
|
|
62
67
|
});
|
|
63
68
|
}
|
|
64
69
|
|
|
@@ -74,6 +79,24 @@ class Dot {
|
|
|
74
79
|
});
|
|
75
80
|
}
|
|
76
81
|
|
|
82
|
+
if (cfg.onMouseDown) {
|
|
83
|
+
dotClickable.addEventListener('mousedown', (event) => {
|
|
84
|
+
cfg.onMouseDown(event, this);
|
|
85
|
+
});
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
if (cfg.onMouseUp) {
|
|
89
|
+
dotClickable.addEventListener('mouseup', (event) => {
|
|
90
|
+
cfg.onMouseUp(event, this);
|
|
91
|
+
});
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
if (cfg.onMouseMove) {
|
|
95
|
+
dotClickable.addEventListener('mousemove', (event) => {
|
|
96
|
+
cfg.onMouseMove(event, this);
|
|
97
|
+
});
|
|
98
|
+
}
|
|
99
|
+
|
|
77
100
|
if (cfg.onContextMenu) {
|
|
78
101
|
dotClickable.addEventListener('contextmenu', (event) => {
|
|
79
102
|
cfg.onContextMenu(event, this);
|
|
@@ -63,6 +63,24 @@ class Label {
|
|
|
63
63
|
});
|
|
64
64
|
}
|
|
65
65
|
|
|
66
|
+
if (cfg.onMouseDown) {
|
|
67
|
+
label.addEventListener('mousedown', (event) => {
|
|
68
|
+
cfg.onMouseDown(event, this);
|
|
69
|
+
});
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
if (cfg.onMouseUp) {
|
|
73
|
+
label.addEventListener('mouseup', (event) => {
|
|
74
|
+
cfg.onMouseUp(event, this);
|
|
75
|
+
});
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
if (cfg.onMouseMove) {
|
|
79
|
+
label.addEventListener('mousemove', (event) => {
|
|
80
|
+
cfg.onMouseMove(event, this);
|
|
81
|
+
});
|
|
82
|
+
}
|
|
83
|
+
|
|
66
84
|
if (cfg.onContextMenu) {
|
|
67
85
|
label.addEventListener('contextmenu', (event) => {
|
|
68
86
|
cfg.onContextMenu(event, this);
|
|
@@ -95,6 +95,24 @@ class Wire {
|
|
|
95
95
|
});
|
|
96
96
|
}
|
|
97
97
|
|
|
98
|
+
if (cfg.onMouseDown) {
|
|
99
|
+
wireClickable.addEventListener('mousedown', (event) => {
|
|
100
|
+
cfg.onMouseDown(event, this);
|
|
101
|
+
});
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
if (cfg.onMouseUp) {
|
|
105
|
+
wireClickable.addEventListener('mouseup', (event) => {
|
|
106
|
+
cfg.onMouseUp(event, this);
|
|
107
|
+
});
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
if (cfg.onMouseMove) {
|
|
111
|
+
wireClickable.addEventListener('mousemove', (event) => {
|
|
112
|
+
cfg.onMouseMove(event, this);
|
|
113
|
+
});
|
|
114
|
+
}
|
|
115
|
+
|
|
98
116
|
if (cfg.onContextMenu) {
|
|
99
117
|
wireClickable.addEventListener('contextmenu', (event) => {
|
|
100
118
|
cfg.onContextMenu(event, this);
|
|
@@ -1,209 +0,0 @@
|
|
|
1
|
-
|
|
2
|
-
import {LODManager} from "./LODManager.js";
|
|
3
|
-
import {Plugin} from "../../viewer";
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* Manages LOD culling for {@link SceneModel} implementations.
|
|
7
|
-
*/
|
|
8
|
-
export class LODCullingPlugin extends Plugin {
|
|
9
|
-
|
|
10
|
-
constructor(viewer, cfg = {}) {
|
|
11
|
-
|
|
12
|
-
super("LODCulling", viewer);
|
|
13
|
-
|
|
14
|
-
this._scene = viewer.scene;
|
|
15
|
-
this._lodLevels = [2000, 600, 150, 80, 20];
|
|
16
|
-
this._neverCullTypes = [];
|
|
17
|
-
this._neverCullTypesMap = {};
|
|
18
|
-
this._lodManagers = {};
|
|
19
|
-
this._lodManagerList = [];
|
|
20
|
-
|
|
21
|
-
this.enabled = cfg.enabled;
|
|
22
|
-
this.targetFPS = cfg.targetFPS;
|
|
23
|
-
|
|
24
|
-
this._init();
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
_init() {
|
|
28
|
-
|
|
29
|
-
const MAX_NUM_TICKS = 4;
|
|
30
|
-
const tickTimeArray = new Array(MAX_NUM_TICKS);
|
|
31
|
-
|
|
32
|
-
let numTick = 0;
|
|
33
|
-
let currentFPS = -1;
|
|
34
|
-
let preRenderTime = Date.now();
|
|
35
|
-
let deltaTime = 0;
|
|
36
|
-
let sceneTick = 0;
|
|
37
|
-
let lastTickCameraMoved = sceneTick;
|
|
38
|
-
|
|
39
|
-
this._scene.on("rendering", () => { // Apply LOD-culling before rendering the scene
|
|
40
|
-
if (currentFPS === -1) {
|
|
41
|
-
return;
|
|
42
|
-
}
|
|
43
|
-
for (let i = 0, len = this._lodManagerList.length; i < len; i++) {
|
|
44
|
-
this._lodManagerList[i].applyLodCulling(currentFPS);
|
|
45
|
-
}
|
|
46
|
-
});
|
|
47
|
-
|
|
48
|
-
this._scene.on("rendered", () => {
|
|
49
|
-
preRenderTime = Date.now();
|
|
50
|
-
window.requestAnimationFrame(() => {
|
|
51
|
-
numTick++;
|
|
52
|
-
const newTime = Date.now();
|
|
53
|
-
deltaTime = newTime - preRenderTime;
|
|
54
|
-
preRenderTime = newTime;
|
|
55
|
-
tickTimeArray[numTick % MAX_NUM_TICKS] = deltaTime;
|
|
56
|
-
let sumTickTimes = 0;
|
|
57
|
-
if (numTick > MAX_NUM_TICKS) {
|
|
58
|
-
for (let i = 0; i < MAX_NUM_TICKS; i++) {
|
|
59
|
-
sumTickTimes += tickTimeArray[i];
|
|
60
|
-
}
|
|
61
|
-
currentFPS = MAX_NUM_TICKS / sumTickTimes * 1000;
|
|
62
|
-
}
|
|
63
|
-
});
|
|
64
|
-
});
|
|
65
|
-
|
|
66
|
-
this._scene.camera.on("matrix", () => {
|
|
67
|
-
lastTickCameraMoved = sceneTick;
|
|
68
|
-
});
|
|
69
|
-
|
|
70
|
-
this._scene.on("tick", () => {
|
|
71
|
-
if ((sceneTick - lastTickCameraMoved) > 3) {
|
|
72
|
-
for (let i = 0, len = this._lodManagerList.length; i < len; i++) { // Call LOD-culling tasks
|
|
73
|
-
this._lodManagerList[i].resetLodCulling();
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
sceneTick++;
|
|
77
|
-
});
|
|
78
|
-
|
|
79
|
-
this._onModelLoaded = viewer.scene.on("modelLoaded", (modelId) => {
|
|
80
|
-
const sceneModel = this.viewer.scene.models[modelId];
|
|
81
|
-
if (sceneModel) {
|
|
82
|
-
this._getLODManager(sceneModel);
|
|
83
|
-
}
|
|
84
|
-
});
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
/**
|
|
88
|
-
* Sets whether LOD is enabled for the {@link Scene}.
|
|
89
|
-
*
|
|
90
|
-
* Default value is ````false````.
|
|
91
|
-
*
|
|
92
|
-
* @type {Boolean}
|
|
93
|
-
*/
|
|
94
|
-
set enabled(value) {
|
|
95
|
-
value = !!value;
|
|
96
|
-
if (this._enabled === value) {
|
|
97
|
-
return;
|
|
98
|
-
}
|
|
99
|
-
this._enabled = value;
|
|
100
|
-
this.glRedraw();
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
/**
|
|
104
|
-
* Gets whether LOD is enabled for the {@link Scene}.
|
|
105
|
-
*
|
|
106
|
-
* Default value is ````false````.
|
|
107
|
-
*
|
|
108
|
-
* @type {Boolean}
|
|
109
|
-
*/
|
|
110
|
-
get enabled() {
|
|
111
|
-
return this._enabled;
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
/**
|
|
115
|
-
* Sets the maximum area that LOD takes into account when checking for possible occlusion for each fragment.
|
|
116
|
-
*
|
|
117
|
-
* Default value is ````30.0````.
|
|
118
|
-
*
|
|
119
|
-
* @type {Number}
|
|
120
|
-
*/
|
|
121
|
-
set targetFPS(value) {
|
|
122
|
-
if (value === undefined || value === null) {
|
|
123
|
-
value = 30.0;
|
|
124
|
-
}
|
|
125
|
-
if (this._targetFPS === value) {
|
|
126
|
-
return;
|
|
127
|
-
}
|
|
128
|
-
this._targetFPS = value;
|
|
129
|
-
this.glRedraw();
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
/**
|
|
133
|
-
* Gets the maximum area that LOD takes into account when checking for possible occlusion for each fragment.
|
|
134
|
-
*
|
|
135
|
-
* Default value is ````30.0````.
|
|
136
|
-
*
|
|
137
|
-
* @type {Number}
|
|
138
|
-
*/
|
|
139
|
-
get targetFPS() {
|
|
140
|
-
return this._targetFPS;
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
/**
|
|
144
|
-
* Sets the {@link MetaObject} types that are never culled.
|
|
145
|
-
*
|
|
146
|
-
* Default value is ````[]````.
|
|
147
|
-
*
|
|
148
|
-
* @type {string[]}
|
|
149
|
-
*/
|
|
150
|
-
set neverCullTypes(value) {
|
|
151
|
-
if (value === undefined || value === null) {
|
|
152
|
-
value = [];
|
|
153
|
-
}
|
|
154
|
-
this._neverCullTypes = value;
|
|
155
|
-
this._neverCullTypesMap = {};
|
|
156
|
-
for (let i = 0, len = this._neverCullTypes.length; i < len; i++) {
|
|
157
|
-
this._neverCullTypesMap[this._neverCullTypes[i]] = true;
|
|
158
|
-
}
|
|
159
|
-
// this.glRedraw();
|
|
160
|
-
}
|
|
161
|
-
|
|
162
|
-
/**
|
|
163
|
-
* Gets the {@link MetaObject} types that are never culled.
|
|
164
|
-
*
|
|
165
|
-
* Default value is ````[]````.
|
|
166
|
-
*
|
|
167
|
-
* @type {string[]}
|
|
168
|
-
*/
|
|
169
|
-
get neverCullTypes() {
|
|
170
|
-
return this._neverCullTypes;
|
|
171
|
-
}
|
|
172
|
-
|
|
173
|
-
/**
|
|
174
|
-
* @private
|
|
175
|
-
* @returns {*|{}}
|
|
176
|
-
*/
|
|
177
|
-
get neverCullTypesMap() {
|
|
178
|
-
return this._neverCullTypesMap;
|
|
179
|
-
}
|
|
180
|
-
|
|
181
|
-
/**
|
|
182
|
-
* Called within SceneModel constructors
|
|
183
|
-
* @private
|
|
184
|
-
*/
|
|
185
|
-
_getLODManager(sceneModel) {
|
|
186
|
-
const lodManager = new LODManager(this.scene, sceneModel, this._lodLevels, this._targetFPS);
|
|
187
|
-
this._lodManagers[lodManager.id] = lodManager;
|
|
188
|
-
this._lodManagerList = Object.values(this._lodManagers);
|
|
189
|
-
return lodManager;
|
|
190
|
-
}
|
|
191
|
-
|
|
192
|
-
/**
|
|
193
|
-
* Called within SceneModel destructors
|
|
194
|
-
* @private
|
|
195
|
-
*/
|
|
196
|
-
_putLODManager(lodManager) {
|
|
197
|
-
delete this._lodManagers[lodManager.id];
|
|
198
|
-
this._lodManagerList = Object.values(this._lodManagers);
|
|
199
|
-
}
|
|
200
|
-
|
|
201
|
-
/**
|
|
202
|
-
* Destroys this component.
|
|
203
|
-
*
|
|
204
|
-
* @private
|
|
205
|
-
*/
|
|
206
|
-
destroy() {
|
|
207
|
-
super.destroy();
|
|
208
|
-
}
|
|
209
|
-
}
|
|
@@ -1,82 +0,0 @@
|
|
|
1
|
-
import {LODState} from "./LODState.js";
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* @private
|
|
5
|
-
*/
|
|
6
|
-
export class LODManager {
|
|
7
|
-
|
|
8
|
-
constructor(scene, sceneModel, lodLevels, targetFps) {
|
|
9
|
-
this.id = sceneModel.id;
|
|
10
|
-
this.scene = scene;
|
|
11
|
-
this.sceneModel = sceneModel;
|
|
12
|
-
this.lodState = new LODState(lodLevels, targetFps);
|
|
13
|
-
this.lodState.initializeLodState(sceneModel);
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
/**
|
|
17
|
-
* Cull any objects belonging to the current `LOD` level, and increase the `LOD` level.
|
|
18
|
-
*/
|
|
19
|
-
_increaseLODLevelIndex() {
|
|
20
|
-
const lodState = this.lodState;
|
|
21
|
-
if (lodState.lodLevelIndex === lodState.primLODLevels.length) {
|
|
22
|
-
return false;
|
|
23
|
-
}
|
|
24
|
-
const entitiesInLOD = lodState.entitiesInLOD [lodState.primLODLevels[lodState.lodLevelIndex]] || [];
|
|
25
|
-
for (let i = 0, len = entitiesInLOD.length; i < len; i++) {
|
|
26
|
-
entitiesInLOD[i].culledLOD = true;
|
|
27
|
-
}
|
|
28
|
-
lodState.lodLevelIndex++;
|
|
29
|
-
return true;
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
/**
|
|
33
|
-
* Un-cull any objects belonging to the current `LOD` level, and decrease the `LOD` level.
|
|
34
|
-
*/
|
|
35
|
-
_decreaseLODLevelIndex() {
|
|
36
|
-
const lodState = this.lodState;
|
|
37
|
-
if (lodState.lodLevelIndex === 0) {
|
|
38
|
-
return false;
|
|
39
|
-
}
|
|
40
|
-
const entitiesInLOD = lodState.entitiesInLOD [lodState.primLODLevels[lodState.lodLevelIndex - 1]] || [];
|
|
41
|
-
for (let i = 0, len = entitiesInLOD.length; i < len; i++) {
|
|
42
|
-
entitiesInLOD[i].culledLOD = false;
|
|
43
|
-
}
|
|
44
|
-
lodState.lodLevelIndex--;
|
|
45
|
-
return true;
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
/**
|
|
49
|
-
* Apply LOD culling.
|
|
50
|
-
*
|
|
51
|
-
* Will update LOD level, if needed, based on current FPS and target FPS,
|
|
52
|
-
* and then will cull/uncull the needed objects according to the LOD level.
|
|
53
|
-
*
|
|
54
|
-
* @param {number} currentFPS The current FPS (frames per second)
|
|
55
|
-
* @returns {boolean} Whether the LOD level was changed. This is, if some object was culled/unculled.
|
|
56
|
-
*/
|
|
57
|
-
applyLodCulling(currentFPS) {
|
|
58
|
-
let lodState = this.lodState;
|
|
59
|
-
let retVal = false;
|
|
60
|
-
if (currentFPS < lodState.targetFps) {
|
|
61
|
-
if (++lodState.consecutiveFramesWithoutTargetFps > 2) {
|
|
62
|
-
lodState.consecutiveFramesWithoutTargetFps = 0;
|
|
63
|
-
retVal = this._increaseLODLevelIndex();
|
|
64
|
-
}
|
|
65
|
-
} else if (currentFPS > (lodState.targetFps + 4)) {
|
|
66
|
-
if (++lodState.consecutiveFramesWithTargetFps > 2) {
|
|
67
|
-
lodState.consecutiveFramesWithTargetFps = 0;
|
|
68
|
-
retVal = this._decreaseLODLevelIndex();
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
return retVal;
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
resetLodCulling() {
|
|
75
|
-
let retVal = false;
|
|
76
|
-
let decreasedLevel = false;
|
|
77
|
-
do {
|
|
78
|
-
retVal |= (decreasedLevel = this._decreaseLODLevelIndex());
|
|
79
|
-
} while (decreasedLevel);
|
|
80
|
-
return retVal;
|
|
81
|
-
}
|
|
82
|
-
}
|