@woosh/meep-engine 2.34.49 → 2.35.2
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/core/bvh2/BinaryNode.js +19 -35
- package/core/bvh2/aabb3/aabb3_intersects_frustum_array.js +5 -5
- package/core/bvh2/aabb3/aabb3_intersects_frustum_degree.js +6 -6
- package/core/bvh2/aabb3_combined_surface_area.js +21 -0
- package/core/bvh2/traversal/queryBinaryNode_CollectData.js +1 -2
- package/core/bvh2/traversal/queryBinaryNode_FrustumIntersections.js +42 -17
- package/core/cache/Cache.d.ts +2 -0
- package/core/cache/Cache.js +27 -23
- package/core/collection/HashMap.js +1 -1
- package/core/geom/3d/frustum/frustum_from_projection_matrix_array.js +2 -0
- package/core/math/max2.js +2 -6
- package/core/math/min2.js +2 -6
- package/engine/asset/loaders/geometry/geometry/computeGeometryEquality.js +1 -1
- package/engine/asset/loaders/geometry/geometry/computeGeometryHash.js +9 -1
- package/engine/ecs/EntityComponentDataset.js +7 -2
- package/engine/ecs/foliage/ViewState.js +13 -3
- package/engine/ecs/parent/EntityNode.js +23 -11
- package/engine/ecs/transform/Transform.js +15 -13
- package/engine/graphics/ecs/highlight/system/ShadedGeometryHighlightSystem.js +13 -4
- package/engine/graphics/ecs/mesh-v2/ShadedGeometry.js +46 -108
- package/engine/graphics/ecs/mesh-v2/ShadedGeometrySystem.js +72 -10
- package/engine/graphics/ecs/mesh-v2/build_three_object.js +39 -0
- package/engine/graphics/ecs/mesh-v2/render/AbstractRenderAdapter.js +67 -0
- package/engine/graphics/ecs/mesh-v2/render/GenericRendererAdapter.js +48 -0
- package/engine/graphics/ecs/mesh-v2/render/InstancedRendererAdapter.js +158 -0
- package/engine/graphics/ecs/mesh-v2/render/ShadedGeometryRendererContext.js +98 -0
- package/engine/graphics/ecs/mesh-v2/sample/load_gltf.js +5 -0
- package/engine/graphics/ecs/mesh-v2/sample/prototypeShadedGeometry.js +37 -10
- package/engine/graphics/ecs/mesh-v2/three_object_to_entity_composition.js +8 -3
- package/engine/graphics/geometry/instancing/InstancedMeshGroup.js +29 -82
- package/engine/graphics/geometry/instancing/rewriteMaterial.js +9 -45
- package/engine/graphics/material/optimization/BUFFER_GEOMETRY_UVS.js +10 -0
- package/engine/graphics/material/optimization/MaterialDescriptor.js +46 -0
- package/engine/graphics/material/optimization/MaterialOptimizationContext.js +470 -201
- package/engine/graphics/material/optimization/UvContext.js +18 -0
- package/engine/graphics/material/optimization/is_compliant_mesh.js +71 -0
- package/engine/graphics/material/optimization/prepare_atlas_texture.js +23 -0
- package/engine/graphics/material/optimization/prototypeMaterialOptimizer.js +127 -0
- package/engine/graphics/micron/format/MicronGeometryPatch.js +1 -1
- package/engine/graphics/micron/format/VirtualGeometry.js +47 -11
- package/engine/graphics/micron/format/serialization/MicronGeometryBinarySerializationAdapter.js +16 -0
- package/engine/graphics/micron/prototypeVirtualGeometry.js +3 -2
- package/engine/graphics/micron/render/VirtualGeometryBuilder.js +5 -7
- package/engine/graphics/micron/render/instanced/AttributeDataTexture.js +1 -45
- package/engine/graphics/micron/render/instanced/ThreeInstancedAdapter.js +18 -7
- package/engine/graphics/micron/render/refinement/RefinementSpec.js +0 -1
- package/engine/graphics/micron/render/refinement/get_geometry_patch_cut.js +17 -24
- package/engine/graphics/micron/render/v1/MaterialContext.js +3 -2
- package/engine/graphics/micron/render/v1/VGThreeRenderer.js +20 -4
- package/engine/graphics/render/utils/ThreeBypassRenderer.js +3 -2
- package/engine/graphics/render/visibility/IncrementalDeltaSet.js +1 -0
- package/engine/graphics/texture/normalized_internal_format.js +48 -0
- package/engine/graphics/texture/sampler/Sampler2D.js +6 -0
- package/engine/graphics/texture/sampler/sampler2d_copy_channel_data.js +25 -0
- package/engine/graphics/texture/sampler/scaleSampler2D.js +3 -0
- package/engine/graphics/texture/sampler/util/drawSamplerHTML.js +14 -1
- package/package.json +1 -1
|
@@ -4,14 +4,16 @@
|
|
|
4
4
|
|
|
5
5
|
import Vector3 from "../../../core/geom/Vector3.js";
|
|
6
6
|
import Quaternion from "../../../core/geom/Quaternion.js";
|
|
7
|
-
import { Matrix4 } from "../../../core/geom/Matrix4.js";
|
|
8
7
|
import { compose_matrix4_array } from "../../graphics/util/composeMatrix4.js";
|
|
9
8
|
import { decompose_matrix_4_array } from "../../graphics/util/decompose_matrix_4_array.js";
|
|
9
|
+
import { mat4 } from "gl-matrix";
|
|
10
10
|
|
|
11
11
|
const delta = new Vector3();
|
|
12
12
|
|
|
13
|
-
const
|
|
14
|
-
|
|
13
|
+
const scratch_buffer = new ArrayBuffer(32 * 4);
|
|
14
|
+
|
|
15
|
+
const m4_0 = new Float32Array(scratch_buffer, 0, 16);
|
|
16
|
+
const m4_1 = new Float32Array(scratch_buffer, 64, 16)
|
|
15
17
|
|
|
16
18
|
export class Transform {
|
|
17
19
|
/**
|
|
@@ -152,12 +154,12 @@ export class Transform {
|
|
|
152
154
|
* @param {Transform} b
|
|
153
155
|
*/
|
|
154
156
|
multiplyTransforms(a, b) {
|
|
155
|
-
m4_0
|
|
156
|
-
m4_1
|
|
157
|
+
compose_matrix4_array(m4_0, a.position, a.rotation, a.scale);
|
|
158
|
+
compose_matrix4_array(m4_1, b.position, b.rotation, b.scale);
|
|
157
159
|
|
|
158
|
-
|
|
160
|
+
mat4.multiply(m4_0, m4_0, m4_1);
|
|
159
161
|
|
|
160
|
-
|
|
162
|
+
this.fromMatrix4(m4_0);
|
|
161
163
|
}
|
|
162
164
|
|
|
163
165
|
/**
|
|
@@ -170,18 +172,18 @@ export class Transform {
|
|
|
170
172
|
|
|
171
173
|
/**
|
|
172
174
|
*
|
|
173
|
-
* @param {
|
|
175
|
+
* @param {Matrix4} matrix
|
|
174
176
|
*/
|
|
175
|
-
|
|
176
|
-
|
|
177
|
+
toThreeMatrix(matrix) {
|
|
178
|
+
this.toMatrix4(matrix.elements);
|
|
177
179
|
}
|
|
178
180
|
|
|
179
181
|
/**
|
|
180
182
|
*
|
|
181
|
-
* @param {
|
|
183
|
+
* @param {mat4|number[]|Float32Array} m
|
|
182
184
|
*/
|
|
183
|
-
|
|
184
|
-
this.
|
|
185
|
+
fromMatrix4(m) {
|
|
186
|
+
decompose_matrix_4_array(m, this.position, this.rotation, this.scale);
|
|
185
187
|
}
|
|
186
188
|
|
|
187
189
|
/**
|
|
@@ -3,6 +3,7 @@ import { HighlightRenderElementSource } from "../plugin/HighlightRenderElementSo
|
|
|
3
3
|
import Highlight from "../Highlight.js";
|
|
4
4
|
import { OutlineRenderPlugin } from "../plugin/OutlineRenderPlugin.js";
|
|
5
5
|
import { ShadedGeometry } from "../../mesh-v2/ShadedGeometry.js";
|
|
6
|
+
import { build_three_object } from "../../mesh-v2/build_three_object.js";
|
|
6
7
|
|
|
7
8
|
class Supplier extends HighlightRenderElementSource {
|
|
8
9
|
/**
|
|
@@ -31,6 +32,13 @@ class Supplier extends HighlightRenderElementSource {
|
|
|
31
32
|
* @private
|
|
32
33
|
*/
|
|
33
34
|
this.__group = null;
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
*
|
|
38
|
+
* @type {WeakMap<ShadedGeometry, THREE.Object3D>}
|
|
39
|
+
* @private
|
|
40
|
+
*/
|
|
41
|
+
this.__object_cache = new WeakMap();
|
|
34
42
|
}
|
|
35
43
|
|
|
36
44
|
collect(pool, group) {
|
|
@@ -77,13 +85,14 @@ class Supplier extends HighlightRenderElementSource {
|
|
|
77
85
|
return;
|
|
78
86
|
}
|
|
79
87
|
|
|
80
|
-
|
|
88
|
+
let object = this.__object_cache.get(sg);
|
|
81
89
|
|
|
82
|
-
if
|
|
83
|
-
|
|
84
|
-
return;
|
|
90
|
+
if(object === undefined){
|
|
91
|
+
object = build_three_object(sg);
|
|
85
92
|
}
|
|
86
93
|
|
|
94
|
+
object.matrixWorld.elements = sg.transform;
|
|
95
|
+
|
|
87
96
|
const renderElement = this.__pool.create();
|
|
88
97
|
|
|
89
98
|
renderElement.definitions = elements.asArray();
|
|
@@ -1,9 +1,7 @@
|
|
|
1
|
-
import { Line, LineSegments, Mesh } from "three";
|
|
2
1
|
import { updateNodeByMatrix4AndBBB } from "../mesh/updateNodeByTransformAndBBB.js";
|
|
3
2
|
import { LeafNode } from "../../../../core/bvh2/LeafNode.js";
|
|
4
3
|
import { AABB3 } from "../../../../core/bvh2/aabb3/AABB3.js";
|
|
5
4
|
import { DrawMode } from "./DrawMode.js";
|
|
6
|
-
import { applyTransformToThreeObject } from "../mesh/applyTransformToThreeObject.js";
|
|
7
5
|
import { ShadedGeometryFlags } from "./ShadedGeometryFlags.js";
|
|
8
6
|
|
|
9
7
|
const _aabb3 = new AABB3();
|
|
@@ -31,13 +29,6 @@ export class ShadedGeometry {
|
|
|
31
29
|
*/
|
|
32
30
|
this.mode = DrawMode.Triangles;
|
|
33
31
|
|
|
34
|
-
/**
|
|
35
|
-
*
|
|
36
|
-
* @type {THREE.Object3D|null}
|
|
37
|
-
* @private
|
|
38
|
-
*/
|
|
39
|
-
this.__cached_object = null;
|
|
40
|
-
|
|
41
32
|
/**
|
|
42
33
|
*
|
|
43
34
|
* @type {LeafNode<ShadedGeometry>}
|
|
@@ -51,13 +42,27 @@ export class ShadedGeometry {
|
|
|
51
42
|
* @private
|
|
52
43
|
*/
|
|
53
44
|
this.__entity = -1;
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
*
|
|
48
|
+
* @type {Transform|null}
|
|
49
|
+
* @private
|
|
50
|
+
*/
|
|
51
|
+
this.__c_transform = null;
|
|
52
|
+
|
|
54
53
|
/**
|
|
55
54
|
* Transform matrix
|
|
56
55
|
* Transient, assigned in the system
|
|
57
56
|
* @type {number[]|null}
|
|
58
57
|
* @private
|
|
59
58
|
*/
|
|
60
|
-
this.__transform =
|
|
59
|
+
this.__transform = new Float32Array(16);
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* Transient property signifying how to render object
|
|
63
|
+
* @type {number}
|
|
64
|
+
*/
|
|
65
|
+
this.draw_method = 0;
|
|
61
66
|
|
|
62
67
|
/**
|
|
63
68
|
*
|
|
@@ -66,6 +71,14 @@ export class ShadedGeometry {
|
|
|
66
71
|
this.flags = DEFAULT_FLAGS;
|
|
67
72
|
}
|
|
68
73
|
|
|
74
|
+
/**
|
|
75
|
+
* @deprecated
|
|
76
|
+
* @private
|
|
77
|
+
*/
|
|
78
|
+
get __cached_object(){
|
|
79
|
+
throw new Error('Deprecated');
|
|
80
|
+
}
|
|
81
|
+
|
|
69
82
|
/**
|
|
70
83
|
*
|
|
71
84
|
* @param {number|ShadedGeometryFlags} flag
|
|
@@ -106,6 +119,25 @@ export class ShadedGeometry {
|
|
|
106
119
|
return (this.flags & flag) === flag;
|
|
107
120
|
}
|
|
108
121
|
|
|
122
|
+
/**
|
|
123
|
+
*
|
|
124
|
+
* @return {number}
|
|
125
|
+
*/
|
|
126
|
+
hash() {
|
|
127
|
+
return this.geometry.id ^ this.material.id;
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
/**
|
|
131
|
+
*
|
|
132
|
+
* @param {ShadedGeometry} other
|
|
133
|
+
* @returns {boolean}
|
|
134
|
+
*/
|
|
135
|
+
equals(other) {
|
|
136
|
+
return this.geometry.id === other.geometry.id
|
|
137
|
+
&& this.material.id === other.material.id
|
|
138
|
+
;
|
|
139
|
+
}
|
|
140
|
+
|
|
109
141
|
/**
|
|
110
142
|
* Current cached entity that this component is attached to
|
|
111
143
|
* @return {number}
|
|
@@ -120,42 +152,7 @@ export class ShadedGeometry {
|
|
|
120
152
|
* @return {null|number[]}
|
|
121
153
|
*/
|
|
122
154
|
get transform() {
|
|
123
|
-
|
|
124
|
-
return this.__transform;
|
|
125
|
-
} else if (this.__cached_object !== null) {
|
|
126
|
-
return this.__cached_object.matrix.elements;
|
|
127
|
-
} else {
|
|
128
|
-
return null;
|
|
129
|
-
}
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
__build_object() {
|
|
133
|
-
/**
|
|
134
|
-
* @type {THREE.Object3D}
|
|
135
|
-
*/
|
|
136
|
-
let object;
|
|
137
|
-
|
|
138
|
-
const mode = this.mode;
|
|
139
|
-
const shader = this.material;
|
|
140
|
-
const geo = this.geometry;
|
|
141
|
-
|
|
142
|
-
if (mode === DrawMode.Triangles) {
|
|
143
|
-
object = new Mesh(geo, shader);
|
|
144
|
-
} else if (mode === DrawMode.Lines) {
|
|
145
|
-
object = new Line(geo, shader);
|
|
146
|
-
} else if (mode === DrawMode.LineSegments) {
|
|
147
|
-
object = new LineSegments(geo, shader);
|
|
148
|
-
} else {
|
|
149
|
-
throw new Error(`Unsupported draw mode '${mode}'`);
|
|
150
|
-
}
|
|
151
|
-
|
|
152
|
-
object.matrixAutoUpdate = false;
|
|
153
|
-
object.frustumCulled = false;
|
|
154
|
-
|
|
155
|
-
object.castShadow = this.getFlag(ShadedGeometryFlags.CastShadow);
|
|
156
|
-
object.receiveShadow = this.getFlag(ShadedGeometryFlags.ReceiveShadow);
|
|
157
|
-
|
|
158
|
-
this.__cached_object = object;
|
|
155
|
+
return this.__transform;
|
|
159
156
|
}
|
|
160
157
|
|
|
161
158
|
get bvh() {
|
|
@@ -177,13 +174,6 @@ export class ShadedGeometry {
|
|
|
177
174
|
if (geometry.boundingBox === null) {
|
|
178
175
|
geometry.computeBoundingBox();
|
|
179
176
|
}
|
|
180
|
-
|
|
181
|
-
if (this.__cached_object === null) {
|
|
182
|
-
this.__build_object();
|
|
183
|
-
} else {
|
|
184
|
-
this.__cached_object.material = material;
|
|
185
|
-
this.__cached_object.geometry = geometry;
|
|
186
|
-
}
|
|
187
177
|
}
|
|
188
178
|
|
|
189
179
|
/**
|
|
@@ -202,11 +192,8 @@ export class ShadedGeometry {
|
|
|
202
192
|
}
|
|
203
193
|
|
|
204
194
|
updateTransform() {
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
// update matrix
|
|
208
|
-
object_3d.updateMatrix();
|
|
209
|
-
object_3d.updateMatrixWorld();
|
|
195
|
+
//
|
|
196
|
+
this.__c_transform.toMatrix4(this.__transform);
|
|
210
197
|
|
|
211
198
|
// update bounds
|
|
212
199
|
const gbb = this.geometry.boundingBox;
|
|
@@ -223,56 +210,7 @@ export class ShadedGeometry {
|
|
|
223
210
|
max.z
|
|
224
211
|
);
|
|
225
212
|
|
|
226
|
-
updateNodeByMatrix4AndBBB(this.__bvh_leaf, _aabb3,
|
|
227
|
-
}
|
|
228
|
-
|
|
229
|
-
/**
|
|
230
|
-
*
|
|
231
|
-
* @param {number} x
|
|
232
|
-
* @param {number} y
|
|
233
|
-
* @param {number} z
|
|
234
|
-
*/
|
|
235
|
-
setPositionByComponents(x, y, z) {
|
|
236
|
-
|
|
237
|
-
this.__cached_object.position.set(x, y, z);
|
|
238
|
-
|
|
239
|
-
this.updateTransform();
|
|
240
|
-
}
|
|
241
|
-
|
|
242
|
-
/**
|
|
243
|
-
*
|
|
244
|
-
* @param {number} x
|
|
245
|
-
* @param {number} y
|
|
246
|
-
* @param {number} z
|
|
247
|
-
* @param {number} w
|
|
248
|
-
*/
|
|
249
|
-
setRotationByComponents(x, y, z, w) {
|
|
250
|
-
|
|
251
|
-
this.__cached_object.quaternion.set(x, y, z, w);
|
|
252
|
-
|
|
253
|
-
this.updateTransform();
|
|
254
|
-
}
|
|
255
|
-
|
|
256
|
-
/**
|
|
257
|
-
*
|
|
258
|
-
* @param {number} x
|
|
259
|
-
* @param {number} y
|
|
260
|
-
* @param {number} z
|
|
261
|
-
*/
|
|
262
|
-
setScaleByComponents(x, y, z) {
|
|
263
|
-
this.__cached_object.scale.set(x, y, z);
|
|
264
|
-
|
|
265
|
-
this.updateTransform();
|
|
266
|
-
}
|
|
267
|
-
|
|
268
|
-
/**
|
|
269
|
-
*
|
|
270
|
-
* @param {Transform} t
|
|
271
|
-
*/
|
|
272
|
-
applyTransform(t) {
|
|
273
|
-
applyTransformToThreeObject(this.__cached_object, t);
|
|
274
|
-
|
|
275
|
-
this.updateTransform();
|
|
213
|
+
updateNodeByMatrix4AndBBB(this.__bvh_leaf, _aabb3, this.__transform);
|
|
276
214
|
}
|
|
277
215
|
}
|
|
278
216
|
|
|
@@ -7,6 +7,8 @@ import { v3_distance_sqr } from "../../../../core/geom/v3_distance_sqr.js";
|
|
|
7
7
|
import { mat4 } from "gl-matrix";
|
|
8
8
|
import { returnTrue } from "../../../../core/function/Functions.js";
|
|
9
9
|
import { aabb3_intersects_ray } from "../../../../core/bvh2/aabb3/aabb3_intersects_ray.js";
|
|
10
|
+
import { ShadedGeometryRendererContext } from "./render/ShadedGeometryRendererContext.js";
|
|
11
|
+
import { BinaryNode } from "../../../../core/bvh2/BinaryNode.js";
|
|
10
12
|
|
|
11
13
|
/**
|
|
12
14
|
*
|
|
@@ -54,14 +56,72 @@ export class ShadedGeometrySystem extends System {
|
|
|
54
56
|
* @private
|
|
55
57
|
*/
|
|
56
58
|
this.__render_layer = null;
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
*
|
|
62
|
+
* @type {Map<CameraView, ShadedGeometryRendererContext>}
|
|
63
|
+
* @private
|
|
64
|
+
*/
|
|
65
|
+
this.__view_contexts = new Map();
|
|
66
|
+
|
|
67
|
+
this.__bvh = new BinaryNode();
|
|
68
|
+
this.__bvh.setNegativelyInfiniteBounds();
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
*
|
|
73
|
+
* @param {CameraView} view
|
|
74
|
+
* @private
|
|
75
|
+
*/
|
|
76
|
+
__handle_view_added(view) {
|
|
77
|
+
this.__view_contexts.set(view, new ShadedGeometryRendererContext());
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
/**
|
|
81
|
+
*
|
|
82
|
+
* @param {CameraView} view
|
|
83
|
+
* @private
|
|
84
|
+
*/
|
|
85
|
+
__handle_view_removed(view) {
|
|
86
|
+
const ctx = this.__view_contexts.get(view);
|
|
87
|
+
|
|
88
|
+
this.__view_contexts.delete(view);
|
|
89
|
+
|
|
90
|
+
ctx.dispose();
|
|
57
91
|
}
|
|
58
92
|
|
|
59
93
|
async startup(entityManager, readyCallback, errorCallback) {
|
|
60
94
|
|
|
61
95
|
const engine = this.__engine;
|
|
96
|
+
const graphics = engine.graphics;
|
|
97
|
+
|
|
98
|
+
const view_list = graphics.views.elements;
|
|
99
|
+
|
|
100
|
+
view_list.forEach(this.__handle_view_added, this);
|
|
101
|
+
view_list.on.added.add(this.__handle_view_added, this);
|
|
102
|
+
view_list.on.removed.add(this.__handle_view_removed, this);
|
|
62
103
|
|
|
63
|
-
this.__render_layer =
|
|
64
|
-
|
|
104
|
+
this.__render_layer = graphics.layers.create('shaded-geometry');
|
|
105
|
+
|
|
106
|
+
this.__render_layer.buildVisibleSet = ((destination, destination_offset, view) => {
|
|
107
|
+
const ctx = this.__view_contexts.get(view);
|
|
108
|
+
|
|
109
|
+
return ctx.collect(destination, destination_offset, view, this.__bvh);
|
|
110
|
+
});
|
|
111
|
+
|
|
112
|
+
readyCallback();
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
async shutdown(entityManager, readyCallback, errorCallback) {
|
|
116
|
+
|
|
117
|
+
const engine = this.__engine;
|
|
118
|
+
const graphics = engine.graphics;
|
|
119
|
+
|
|
120
|
+
const view_list = graphics.views.elements;
|
|
121
|
+
|
|
122
|
+
view_list.forEach(this.__handle_view_removed, this);
|
|
123
|
+
view_list.on.added.remove(this.__handle_view_added, this);
|
|
124
|
+
view_list.on.removed.remove(this.__handle_view_removed, this);
|
|
65
125
|
|
|
66
126
|
readyCallback();
|
|
67
127
|
}
|
|
@@ -73,11 +133,13 @@ export class ShadedGeometrySystem extends System {
|
|
|
73
133
|
* @param {number} entity
|
|
74
134
|
*/
|
|
75
135
|
link(sg, t, entity) {
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
t.
|
|
136
|
+
sg.__c_transform = t;
|
|
137
|
+
|
|
138
|
+
t.position.onChanged.add(sg.updateTransform, sg);
|
|
139
|
+
t.rotation.onChanged.add(sg.updateTransform, sg);
|
|
140
|
+
t.scale.onChanged.add(sg.updateTransform, sg);
|
|
79
141
|
|
|
80
|
-
sg.
|
|
142
|
+
sg.updateTransform();
|
|
81
143
|
|
|
82
144
|
const leaf_node = sg.bvh;
|
|
83
145
|
|
|
@@ -87,7 +149,7 @@ export class ShadedGeometrySystem extends System {
|
|
|
87
149
|
// remember entity for lookups
|
|
88
150
|
sg.__entity = entity;
|
|
89
151
|
|
|
90
|
-
this.
|
|
152
|
+
this.__bvh.insertNode(leaf_node);
|
|
91
153
|
}
|
|
92
154
|
|
|
93
155
|
/**
|
|
@@ -97,9 +159,9 @@ export class ShadedGeometrySystem extends System {
|
|
|
97
159
|
* @param {number} entity
|
|
98
160
|
*/
|
|
99
161
|
unlink(sg, t, entity) {
|
|
100
|
-
t.position.onChanged.remove(sg.
|
|
101
|
-
t.rotation.onChanged.remove(sg.
|
|
102
|
-
t.scale.onChanged.remove(sg.
|
|
162
|
+
t.position.onChanged.remove(sg.updateTransform, sg);
|
|
163
|
+
t.rotation.onChanged.remove(sg.updateTransform, sg);
|
|
164
|
+
t.scale.onChanged.remove(sg.updateTransform, sg);
|
|
103
165
|
|
|
104
166
|
sg.bvh.disconnect();
|
|
105
167
|
}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { DrawMode } from "./DrawMode.js";
|
|
2
|
+
import { Line, LineSegments, Mesh } from "three";
|
|
3
|
+
import { ShadedGeometryFlags } from "./ShadedGeometryFlags.js";
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
*
|
|
7
|
+
* @param {ShadedGeometry} sg
|
|
8
|
+
* @returns {THREE.Object3D}
|
|
9
|
+
*/
|
|
10
|
+
export function build_three_object(sg) {
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* @type {THREE.Object3D}
|
|
14
|
+
*/
|
|
15
|
+
let object;
|
|
16
|
+
|
|
17
|
+
const mode = sg.mode;
|
|
18
|
+
const shader = sg.material;
|
|
19
|
+
const geo = sg.geometry;
|
|
20
|
+
|
|
21
|
+
if (mode === DrawMode.Triangles) {
|
|
22
|
+
object = new Mesh(geo, shader);
|
|
23
|
+
} else if (mode === DrawMode.Lines) {
|
|
24
|
+
object = new Line(geo, shader);
|
|
25
|
+
} else if (mode === DrawMode.LineSegments) {
|
|
26
|
+
object = new LineSegments(geo, shader);
|
|
27
|
+
} else {
|
|
28
|
+
throw new Error(`Unsupported draw mode '${mode}'`);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
object.matrixAutoUpdate = false;
|
|
32
|
+
object.frustumCulled = false;
|
|
33
|
+
object.matrixWorldNeedsUpdate = false;
|
|
34
|
+
|
|
35
|
+
object.castShadow = sg.getFlag(ShadedGeometryFlags.CastShadow);
|
|
36
|
+
object.receiveShadow = sg.getFlag(ShadedGeometryFlags.ReceiveShadow);
|
|
37
|
+
|
|
38
|
+
return object;
|
|
39
|
+
}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
export class AbstractRenderAdapter {
|
|
2
|
+
constructor() {
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
*
|
|
6
|
+
* @type {number}
|
|
7
|
+
* @protected
|
|
8
|
+
*/
|
|
9
|
+
this.__object_count = 0;
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
*
|
|
13
|
+
* @type {THREE.Object3D[]}
|
|
14
|
+
* @protected
|
|
15
|
+
*/
|
|
16
|
+
this.__objects = [];
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
*
|
|
21
|
+
* @param {THREE.BufferGeometry} geometry
|
|
22
|
+
* @param {THREE.Material} material
|
|
23
|
+
* @returns {number}
|
|
24
|
+
*/
|
|
25
|
+
score(geometry, material) {
|
|
26
|
+
return 0;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
*
|
|
31
|
+
* @param {ShadedGeometry} sg
|
|
32
|
+
* @returns {void}
|
|
33
|
+
*/
|
|
34
|
+
add(sg) {
|
|
35
|
+
throw new Error('Not Implemented');
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
build_start() {
|
|
39
|
+
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
build_end() {
|
|
43
|
+
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
clear() {
|
|
47
|
+
this.__object_count = 0;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* @returns {THREE.Object3D[]}
|
|
52
|
+
*/
|
|
53
|
+
get objects() {
|
|
54
|
+
return this.__objects;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* @returns {number}
|
|
59
|
+
*/
|
|
60
|
+
get object_count() {
|
|
61
|
+
return this.__object_count;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
dispose() {
|
|
65
|
+
|
|
66
|
+
}
|
|
67
|
+
}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { AbstractRenderAdapter } from "./AbstractRenderAdapter.js";
|
|
2
|
+
import { array_copy } from "../../../../../core/collection/array/copyArray.js";
|
|
3
|
+
import { build_three_object } from "../build_three_object.js";
|
|
4
|
+
|
|
5
|
+
export class GenericRendererAdapter extends AbstractRenderAdapter {
|
|
6
|
+
constructor() {
|
|
7
|
+
super();
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
*
|
|
11
|
+
* @type {Cache<ShadedGeometry, THREE.Object3D>}
|
|
12
|
+
* @private
|
|
13
|
+
*/
|
|
14
|
+
this.__cache = new WeakMap();
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
score(geometry, material) {
|
|
19
|
+
return 0;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
build_start() {
|
|
23
|
+
this.clear();
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
add(sg) {
|
|
27
|
+
const cache = this.__cache;
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
*
|
|
31
|
+
* @type {THREE.Object3D}
|
|
32
|
+
*/
|
|
33
|
+
let object = cache.get(sg);
|
|
34
|
+
|
|
35
|
+
if (object === undefined) {
|
|
36
|
+
|
|
37
|
+
object = build_three_object(sg);
|
|
38
|
+
|
|
39
|
+
cache.set(sg, object);
|
|
40
|
+
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
array_copy(sg.__transform, 0, object.matrixWorld.elements, 0, 16);
|
|
44
|
+
|
|
45
|
+
this.__objects[this.__object_count++] = object;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
}
|