@woosh/meep-engine 2.36.16 → 2.36.19
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/geom/3d/SurfacePoint3.js +12 -0
- package/engine/ecs/components/Renderable.js +3 -0
- package/engine/ecs/systems/RenderSystem.js +10 -7
- package/engine/graphics/ecs/highlight/renderer/OutlineRenderer.js +39 -34
- package/engine/graphics/ecs/highlight/system/ShadedGeometryHighlightSystem.js +4 -8
- package/engine/graphics/ecs/mesh-v2/ShadedGeometrySystem.d.ts +7 -0
- package/engine/graphics/ecs/mesh-v2/ShadedGeometrySystem.js +89 -0
- package/engine/graphics/ecs/mesh-v2/render/SGThreeObjectCache.js +38 -0
- package/engine/graphics/ecs/mesh-v2/render/adapters/GenericRendererAdapter.js +4 -14
- package/engine/graphics/micron/plugin/GLTFAssetTransformer.js +2 -0
- package/package.json +1 -1
|
@@ -71,4 +71,16 @@ export class SurfacePoint3 {
|
|
|
71
71
|
this.position.copy(other.position);
|
|
72
72
|
this.normal.copy(other.normal);
|
|
73
73
|
}
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
*
|
|
77
|
+
* @returns {SurfacePoint3}
|
|
78
|
+
*/
|
|
79
|
+
clone() {
|
|
80
|
+
const r = new SurfacePoint3();
|
|
81
|
+
|
|
82
|
+
r.copy(this);
|
|
83
|
+
|
|
84
|
+
return r;
|
|
85
|
+
}
|
|
74
86
|
}
|
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Created by Alex on 01/04/2014.
|
|
3
3
|
*/
|
|
4
|
-
import {System} from '../System.js';
|
|
4
|
+
import { System } from '../System.js';
|
|
5
5
|
import Renderable from '../components/Renderable.js';
|
|
6
|
-
import {Transform} from '../transform/Transform.js';
|
|
7
|
-
import {SignalBinding} from "../../../core/events/signal/SignalBinding.js";
|
|
8
|
-
import {Box3} from "three";
|
|
9
|
-
import {RenderableFlags} from "../components/RenderableFlags.js";
|
|
10
|
-
import {rootObject3DFastMatrixUpdate} from "../../graphics/ecs/mesh/rootObject3DFastMatrixUpdate.js";
|
|
11
|
-
import {updateNodeByTransformAndBBB} from "../../graphics/ecs/mesh/updateNodeByTransformAndBBB.js";
|
|
6
|
+
import { Transform } from '../transform/Transform.js';
|
|
7
|
+
import { SignalBinding } from "../../../core/events/signal/SignalBinding.js";
|
|
8
|
+
import { Box3 } from "three";
|
|
9
|
+
import { RenderableFlags } from "../components/RenderableFlags.js";
|
|
10
|
+
import { rootObject3DFastMatrixUpdate } from "../../graphics/ecs/mesh/rootObject3DFastMatrixUpdate.js";
|
|
11
|
+
import { updateNodeByTransformAndBBB } from "../../graphics/ecs/mesh/updateNodeByTransformAndBBB.js";
|
|
12
12
|
|
|
13
13
|
|
|
14
14
|
/**
|
|
@@ -43,6 +43,9 @@ export function three_computeObjectBoundingBox(object, result) {
|
|
|
43
43
|
|
|
44
44
|
}
|
|
45
45
|
|
|
46
|
+
/**
|
|
47
|
+
* @deprecated use {@link ShadedGeometry} instead
|
|
48
|
+
*/
|
|
46
49
|
class RenderSystem extends System {
|
|
47
50
|
/**
|
|
48
51
|
*
|
|
@@ -35,18 +35,49 @@ void main(){
|
|
|
35
35
|
}
|
|
36
36
|
`;
|
|
37
37
|
|
|
38
|
+
const material_id_vertex_shader_skinned = `
|
|
39
|
+
#include <common>
|
|
40
|
+
#include <uv_pars_vertex>
|
|
41
|
+
#include <displacementmap_pars_vertex>
|
|
42
|
+
#include <morphtarget_pars_vertex>
|
|
43
|
+
#include <skinning_pars_vertex>
|
|
44
|
+
#include <logdepthbuf_pars_vertex>
|
|
45
|
+
#include <clipping_planes_pars_vertex>
|
|
46
|
+
|
|
47
|
+
void main()
|
|
48
|
+
{
|
|
49
|
+
#include <uv_vertex>
|
|
50
|
+
#include <skinbase_vertex>
|
|
51
|
+
#ifdef USE_DISPLACEMENTMAP
|
|
52
|
+
#include <beginnormal_vertex>
|
|
53
|
+
#include <morphnormal_vertex>
|
|
54
|
+
#include <skinnormal_vertex>
|
|
55
|
+
#endif
|
|
56
|
+
#include <begin_vertex>
|
|
57
|
+
#include <morphtarget_vertex>
|
|
58
|
+
#include <skinning_vertex>
|
|
59
|
+
#include <displacementmap_vertex>
|
|
60
|
+
#include <project_vertex>
|
|
61
|
+
#include <logdepthbuf_vertex>
|
|
62
|
+
#include <clipping_planes_vertex>
|
|
63
|
+
}
|
|
64
|
+
`;
|
|
65
|
+
|
|
66
|
+
|
|
67
|
+
const material_id_vertex_shader_static = `
|
|
68
|
+
void main()
|
|
69
|
+
{
|
|
70
|
+
vec4 mvPosition = modelViewMatrix * vec4( position, 1.0 );
|
|
71
|
+
gl_Position = projectionMatrix * mvPosition;
|
|
72
|
+
}
|
|
73
|
+
`;
|
|
74
|
+
|
|
38
75
|
function makeIdMaterialStatic() {
|
|
39
76
|
return new ShaderMaterial({
|
|
40
77
|
uniforms: {
|
|
41
78
|
id: { value: 0 }
|
|
42
79
|
},
|
|
43
|
-
vertexShader:
|
|
44
|
-
void main()
|
|
45
|
-
{
|
|
46
|
-
vec4 mvPosition = modelViewMatrix * vec4( position, 1.0 );
|
|
47
|
-
gl_Position = projectionMatrix * mvPosition;
|
|
48
|
-
}
|
|
49
|
-
`,
|
|
80
|
+
vertexShader: material_id_vertex_shader_static,
|
|
50
81
|
fragmentShader: material_id_fragment_shader
|
|
51
82
|
});
|
|
52
83
|
}
|
|
@@ -59,33 +90,7 @@ function makeIdMaterialSkinned() {
|
|
|
59
90
|
uniforms: {
|
|
60
91
|
id: { value: 0 }
|
|
61
92
|
},
|
|
62
|
-
vertexShader:
|
|
63
|
-
#include <common>
|
|
64
|
-
#include <uv_pars_vertex>
|
|
65
|
-
#include <displacementmap_pars_vertex>
|
|
66
|
-
#include <morphtarget_pars_vertex>
|
|
67
|
-
#include <skinning_pars_vertex>
|
|
68
|
-
#include <logdepthbuf_pars_vertex>
|
|
69
|
-
#include <clipping_planes_pars_vertex>
|
|
70
|
-
|
|
71
|
-
void main()
|
|
72
|
-
{
|
|
73
|
-
#include <uv_vertex>
|
|
74
|
-
#include <skinbase_vertex>
|
|
75
|
-
#ifdef USE_DISPLACEMENTMAP
|
|
76
|
-
#include <beginnormal_vertex>
|
|
77
|
-
#include <morphnormal_vertex>
|
|
78
|
-
#include <skinnormal_vertex>
|
|
79
|
-
#endif
|
|
80
|
-
#include <begin_vertex>
|
|
81
|
-
#include <morphtarget_vertex>
|
|
82
|
-
#include <skinning_vertex>
|
|
83
|
-
#include <displacementmap_vertex>
|
|
84
|
-
#include <project_vertex>
|
|
85
|
-
#include <logdepthbuf_vertex>
|
|
86
|
-
#include <clipping_planes_vertex>
|
|
87
|
-
}
|
|
88
|
-
`,
|
|
93
|
+
vertexShader: material_id_vertex_shader_skinned,
|
|
89
94
|
fragmentShader: material_id_fragment_shader
|
|
90
95
|
});
|
|
91
96
|
}
|
|
@@ -3,7 +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 {
|
|
6
|
+
import { SGThreeObjectCache } from "../../mesh-v2/render/SGThreeObjectCache.js";
|
|
7
7
|
|
|
8
8
|
class Supplier extends HighlightRenderElementSource {
|
|
9
9
|
/**
|
|
@@ -35,10 +35,10 @@ class Supplier extends HighlightRenderElementSource {
|
|
|
35
35
|
|
|
36
36
|
/**
|
|
37
37
|
*
|
|
38
|
-
* @type {
|
|
38
|
+
* @type {SGThreeObjectCache}
|
|
39
39
|
* @private
|
|
40
40
|
*/
|
|
41
|
-
this.__object_cache =
|
|
41
|
+
this.__object_cache = SGThreeObjectCache.INSTANCE;
|
|
42
42
|
}
|
|
43
43
|
|
|
44
44
|
collect(pool, group) {
|
|
@@ -85,11 +85,7 @@ class Supplier extends HighlightRenderElementSource {
|
|
|
85
85
|
return;
|
|
86
86
|
}
|
|
87
87
|
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
if(object === undefined){
|
|
91
|
-
object = build_three_object(sg);
|
|
92
|
-
}
|
|
88
|
+
const object = this.__object_cache.get(sg);
|
|
93
89
|
|
|
94
90
|
object.matrixWorld.elements = sg.transform;
|
|
95
91
|
|
|
@@ -13,4 +13,11 @@ export class ShadedGeometrySystem extends System<ShadedGeometry> {
|
|
|
13
13
|
filter_function?: (entity: number, mesh: ShadedGeometry) => boolean,
|
|
14
14
|
filter_function_context?: any
|
|
15
15
|
): { entity: number, mesh: ShadedGeometry } | undefined
|
|
16
|
+
|
|
17
|
+
raycast(
|
|
18
|
+
origin_x: number, origin_y: number, origin_z: number,
|
|
19
|
+
direction_x: number, direction_y: number, direction_z: number,
|
|
20
|
+
filter_function?: (entity: number, mesh: ShadedGeometry) => boolean,
|
|
21
|
+
filter_function_context?: any
|
|
22
|
+
): { entity: number, mesh: ShadedGeometry, contact: SurfacePoint3 }[]
|
|
16
23
|
}
|
|
@@ -275,6 +275,91 @@ export class ShadedGeometrySystem extends System {
|
|
|
275
275
|
}
|
|
276
276
|
}
|
|
277
277
|
|
|
278
|
+
/**
|
|
279
|
+
*
|
|
280
|
+
* @param {number} origin_x
|
|
281
|
+
* @param {number} origin_y
|
|
282
|
+
* @param {number} origin_z
|
|
283
|
+
* @param {number} direction_x
|
|
284
|
+
* @param {number} direction_y
|
|
285
|
+
* @param {number} direction_z
|
|
286
|
+
* @param {function(entity:number, mesh:ShadedGeometry):boolean} [filter_function]
|
|
287
|
+
* @param {*} [filter_function_context]
|
|
288
|
+
* @returns {{entity:number, mesh:ShadedGeometry, contact: SurfacePoint3}[]}
|
|
289
|
+
*/
|
|
290
|
+
raycast(
|
|
291
|
+
origin_x, origin_y, origin_z,
|
|
292
|
+
direction_x, direction_y, direction_z,
|
|
293
|
+
filter_function = returnTrue, filter_function_context
|
|
294
|
+
) {
|
|
295
|
+
const result = [];
|
|
296
|
+
|
|
297
|
+
const hits = [];
|
|
298
|
+
|
|
299
|
+
const hit_count = bvh_query_leaves_generic(hits, 0, this.__bvh_binary, BVHQueryIntersectsRay.from([origin_x, origin_y, origin_z, direction_x, direction_y, direction_z]));
|
|
300
|
+
|
|
301
|
+
const ecd = this.entityManager.dataset;
|
|
302
|
+
|
|
303
|
+
if (ecd === null) {
|
|
304
|
+
// no ECD set
|
|
305
|
+
return result;
|
|
306
|
+
}
|
|
307
|
+
|
|
308
|
+
const sg_component_index = ecd.computeComponentTypeIndex(ShadedGeometry);
|
|
309
|
+
|
|
310
|
+
for (let i = 0; i < hit_count; i++) {
|
|
311
|
+
const node_id = hits[i];
|
|
312
|
+
|
|
313
|
+
const entity = this.__bvh_binary.node_get_user_data(node_id);
|
|
314
|
+
|
|
315
|
+
/**
|
|
316
|
+
*
|
|
317
|
+
* @type {ShadedGeometry}
|
|
318
|
+
*/
|
|
319
|
+
const sg = ecd.getComponentByIndex(entity, sg_component_index);
|
|
320
|
+
|
|
321
|
+
if (!filter_function.call(filter_function_context, entity, sg)) {
|
|
322
|
+
// filtered out
|
|
323
|
+
continue;
|
|
324
|
+
}
|
|
325
|
+
|
|
326
|
+
const m4 = sg.transform;
|
|
327
|
+
|
|
328
|
+
// get transform in local space
|
|
329
|
+
mat4.invert(scratch_m4, m4);
|
|
330
|
+
|
|
331
|
+
ray3_array_compose(
|
|
332
|
+
scratch_ray_0,
|
|
333
|
+
origin_x, origin_y, origin_z,
|
|
334
|
+
direction_x, direction_y, direction_z
|
|
335
|
+
);
|
|
336
|
+
|
|
337
|
+
// transform ray to local space
|
|
338
|
+
ray3_array_apply_matrix4(scratch_ray_0, scratch_ray_0, scratch_m4);
|
|
339
|
+
|
|
340
|
+
const geometry_hit_found = GeometrySpatialQueryAccelerator.INSTANCE.queryRaycastNearest_array(
|
|
341
|
+
scratch_point,
|
|
342
|
+
sg.geometry,
|
|
343
|
+
scratch_ray_0
|
|
344
|
+
);
|
|
345
|
+
|
|
346
|
+
if (!geometry_hit_found) {
|
|
347
|
+
continue;
|
|
348
|
+
}
|
|
349
|
+
|
|
350
|
+
// transform hit contact into global space
|
|
351
|
+
scratch_point.applyMatrix4(m4);
|
|
352
|
+
|
|
353
|
+
result.push({
|
|
354
|
+
entity,
|
|
355
|
+
mesh: sg,
|
|
356
|
+
contact: scratch_point.clone()
|
|
357
|
+
});
|
|
358
|
+
}
|
|
359
|
+
|
|
360
|
+
return result;
|
|
361
|
+
}
|
|
362
|
+
|
|
278
363
|
/**
|
|
279
364
|
*
|
|
280
365
|
* @param {SurfacePoint3} contact
|
|
@@ -327,6 +412,10 @@ export class ShadedGeometrySystem extends System {
|
|
|
327
412
|
continue;
|
|
328
413
|
}
|
|
329
414
|
|
|
415
|
+
/**
|
|
416
|
+
*
|
|
417
|
+
* @type {number[]|mat4|null}
|
|
418
|
+
*/
|
|
330
419
|
const m4 = sg.transform;
|
|
331
420
|
|
|
332
421
|
// get transform in local space
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { build_three_object } from "../build_three_object.js";
|
|
2
|
+
|
|
3
|
+
export class SGThreeObjectCache {
|
|
4
|
+
constructor() {
|
|
5
|
+
/**
|
|
6
|
+
*
|
|
7
|
+
* @type {WeakMap<ShadedGeometry, THREE.Object3D>}
|
|
8
|
+
* @private
|
|
9
|
+
*/
|
|
10
|
+
this.__object_cache = new WeakMap();
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
*
|
|
15
|
+
* @param {ShadedGeometry} sg
|
|
16
|
+
* @returns {THREE.Object3D}
|
|
17
|
+
*/
|
|
18
|
+
get(sg) {
|
|
19
|
+
|
|
20
|
+
const existing_object = this.__object_cache.get(sg);
|
|
21
|
+
|
|
22
|
+
if (existing_object !== undefined) {
|
|
23
|
+
return existing_object;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
const new_object = build_three_object(sg);
|
|
27
|
+
|
|
28
|
+
this.__object_cache.set(sg, new_object);
|
|
29
|
+
|
|
30
|
+
return new_object;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* @readonly
|
|
36
|
+
* @type {SGThreeObjectCache}
|
|
37
|
+
*/
|
|
38
|
+
SGThreeObjectCache.INSTANCE = new SGThreeObjectCache();
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { AbstractRenderAdapter } from "./AbstractRenderAdapter.js";
|
|
2
2
|
import { array_copy } from "../../../../../../core/collection/array/copyArray.js";
|
|
3
|
-
import {
|
|
3
|
+
import { SGThreeObjectCache } from "../SGThreeObjectCache.js";
|
|
4
4
|
|
|
5
5
|
export class GenericRendererAdapter extends AbstractRenderAdapter {
|
|
6
6
|
constructor() {
|
|
@@ -8,10 +8,10 @@ export class GenericRendererAdapter extends AbstractRenderAdapter {
|
|
|
8
8
|
|
|
9
9
|
/**
|
|
10
10
|
*
|
|
11
|
-
* @type {
|
|
11
|
+
* @type {SGThreeObjectCache}
|
|
12
12
|
* @private
|
|
13
13
|
*/
|
|
14
|
-
this.__cache =
|
|
14
|
+
this.__cache = SGThreeObjectCache.INSTANCE;
|
|
15
15
|
}
|
|
16
16
|
|
|
17
17
|
|
|
@@ -29,21 +29,11 @@ export class GenericRendererAdapter extends AbstractRenderAdapter {
|
|
|
29
29
|
}
|
|
30
30
|
|
|
31
31
|
add(sg) {
|
|
32
|
-
const cache = this.__cache;
|
|
33
|
-
|
|
34
32
|
/**
|
|
35
33
|
*
|
|
36
34
|
* @type {THREE.Object3D}
|
|
37
35
|
*/
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
if (object === undefined) {
|
|
41
|
-
|
|
42
|
-
object = build_three_object(sg);
|
|
43
|
-
|
|
44
|
-
cache.set(sg, object);
|
|
45
|
-
|
|
46
|
-
}
|
|
36
|
+
const object = this.__cache.get(sg);
|
|
47
37
|
|
|
48
38
|
array_copy(sg.__transform, 0, object.matrixWorld.elements, 0, 16);
|
|
49
39
|
|
|
@@ -203,6 +203,8 @@ export class GLTFAssetTransformer extends AssetTransformer {
|
|
|
203
203
|
return source;
|
|
204
204
|
}
|
|
205
205
|
|
|
206
|
+
this.__load_mesh_micron_data(source.gltf,asset_description);
|
|
207
|
+
|
|
206
208
|
// attempt to load existing micron geometries
|
|
207
209
|
await async_traverse_three_object(root, this.__visitObjectToLoadMicron, this, {
|
|
208
210
|
asset: asset_description
|
package/package.json
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
"productName": "Meep",
|
|
6
6
|
"description": "production-ready JavaScript game engine based on Entity Component System Architecture",
|
|
7
7
|
"author": "Alexander Goldring",
|
|
8
|
-
"version": "2.36.
|
|
8
|
+
"version": "2.36.19",
|
|
9
9
|
"dependencies": {
|
|
10
10
|
"gl-matrix": "3.4.3",
|
|
11
11
|
"fast-levenshtein": "2.0.6",
|