@woosh/meep-engine 2.33.59 → 2.33.63
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/aabb3/AABB3.js +4 -1
- package/core/bvh2/traversal/traverseBinaryNodeUsingVisitor.js +6 -6
- package/core/cache/Cache.js +7 -0
- package/core/collection/array/fastArrayEquals.js +17 -0
- package/core/collection/array/typed/is_typed_array_equals.js +58 -0
- package/core/collection/map/AbstractAsyncMap.js +30 -0
- package/core/collection/map/AsyncMapWrapper.js +16 -0
- package/core/collection/map/AsyncRemoteHashMap.js +358 -0
- package/core/collection/map/CachedAsyncMap.js +34 -0
- package/core/geom/3d/SurfacePoint3.js +44 -5
- package/core/geom/Vector2.d.ts +2 -0
- package/core/geom/Vector4.js +5 -5
- package/core/geom/packing/MaxRectangles.js +13 -4
- package/core/math/hash/murmur3_32.js +3 -3
- package/ecs/grid/pick.js +44 -0
- package/editor/actions/concrete/PaintTerrainOverlayAction.js +1 -1
- package/editor/process/ObstacleGridDisplayProcess.js +1 -1
- package/editor/process/symbolic/makeGridPositionSymbolDisplay.js +1 -1
- package/editor/tools/FoliagePaintTool.js +1 -1
- package/editor/tools/GridPaintTool.js +2 -2
- package/editor/tools/paint/TerrainPaintTool.js +2 -2
- package/editor/tools/paint/TerrainTexturePaintTool.js +1 -1
- package/editor/view/EditorView.js +1 -1
- package/editor/view/GridPickCoordinateView.js +2 -2
- package/engine/animation/removeEntityGenericEffect.js +22 -31
- package/engine/asset/Asset.js +0 -45
- package/engine/asset/AssetDescription.js +51 -0
- package/engine/asset/AssetManager.d.ts +7 -0
- package/engine/asset/AssetManager.js +98 -2
- package/engine/asset/AssetTransformer.d.ts +5 -0
- package/engine/asset/AssetTransformer.js +15 -0
- package/engine/asset/loaders/GLTFAssetLoader.js +27 -25
- package/engine/asset/loaders/material/computeImageBitmapEquality.js +2 -2
- package/engine/asset/loaders/material/computeTextureEquality.js +2 -2
- package/engine/asset/loaders/material/computeTextureHash.js +7 -13
- package/engine/ecs/animation/InverseKinematicsSystem.js +1 -1
- package/engine/ecs/attachment/AttachmentSystem.js +18 -17
- package/engine/ecs/evaluation/world/ReadTerrainLayerWeightPointFitness.js +1 -1
- package/engine/ecs/fow/FogOfWarRevealerSystem.js +2 -2
- package/engine/ecs/grid/HeightMap2NormalMap.js +1 -1
- package/engine/ecs/grid/NormalMap2AOMap.js +1 -1
- package/engine/ecs/gui/hud/HeadsUpDisplaySystem.js +60 -45
- package/engine/ecs/gui/position/ViewportPositionSystem.js +5 -5
- package/engine/ecs/parent/EntityNode.d.ts +20 -0
- package/engine/ecs/parent/EntityNode.js +284 -0
- package/engine/ecs/parent/FaceEditor.js +137 -0
- package/engine/ecs/parent/testCompositionEntityNode.js +153 -0
- package/engine/ecs/parent/testHuDPerf.js +123 -0
- package/engine/ecs/storage/binary/BinaryClassUpgrader.js +1 -0
- package/engine/ecs/team/Team.js +82 -0
- package/engine/ecs/terrain/ecs/ClingToTerrainSystem.js +2 -2
- package/engine/ecs/terrain/ecs/Terrain.js +14 -5
- package/engine/ecs/terrain/util/loadVisibleTerrainTiles.js +112 -0
- package/engine/ecs/terrain/util/obtainTerrain.js +23 -0
- package/engine/ecs/tooltip/TooltipComponentSystem.js +1 -1
- package/engine/ecs/util/removeComponentsExcept.js +3 -3
- package/engine/graphics/GraphicsEngine.js +4 -5
- package/engine/graphics/camera/testClippingPlaneComputation.js +0 -4
- package/engine/graphics/ecs/camera/topdown/TopDownCameraLanderSystem.js +1 -1
- package/engine/graphics/ecs/light/LightSystem.js +1 -1
- package/engine/graphics/ecs/mesh/Mesh.js +5 -5
- package/engine/graphics/ecs/mesh/MeshSystem.js +12 -20
- package/engine/graphics/ecs/mesh-v2/ShadedGeometry.js +29 -0
- package/engine/graphics/ecs/mesh-v2/ShadedGeometrySystem.js +158 -1
- package/engine/graphics/ecs/path/testPathDisplaySystem.js +0 -2
- package/engine/graphics/ecs/trail2d/Trail2D.js +35 -1
- package/engine/graphics/ecs/trail2d/Trail2DSystem.js +26 -19
- package/engine/graphics/ecs/trail2d/makeGradientTrail.js +68 -0
- package/engine/graphics/ecs/water/WaterSystem.js +1 -1
- package/engine/graphics/ecs/water2/shader/testWaterShader.js +1 -1
- package/engine/graphics/geometry/buffered/query/GeometrySpatialQueryAccelerator.js +55 -11
- package/engine/graphics/micron/convert_three_object_to_micron.js +24 -7
- package/engine/graphics/micron/plugin/MicronRenderPlugin.js +107 -4
- package/engine/graphics/micron/plugin/serialization/BufferGeometrySerializationAdapter.js +176 -0
- package/engine/graphics/micron/render/v1/MaterialContext.js +1 -0
- package/engine/graphics/particles/particular/engine/simulator/SimulationStepFixedPhysics.js +19 -3
- package/engine/graphics/particles/particular/engine/utils/volume/prototypeParticleVolume.js +3 -6
- package/engine/graphics/render/buffer/buffers/prototypeNormalFrameBuffer.js +0 -2
- package/engine/graphics/render/forward_plus/plugin/ptototypeFPPlugin.js +2 -4
- package/engine/graphics/render/forward_plus/query/query_bvh_frustum_from_texture.js +3 -1
- package/engine/graphics/render/frame_graph/FrameGraphBuilder.js +36 -0
- package/engine/graphics/render/frame_graph/IRenderContext.js +8 -0
- package/engine/graphics/render/frame_graph/RenderPass.js +32 -0
- package/engine/graphics/render/frame_graph/RenderPassFlags.js +6 -0
- package/engine/graphics/render/frame_graph/RenderPassResources.js +15 -0
- package/engine/graphics/render/frame_graph/Resource.js +21 -0
- package/engine/graphics/render/frame_graph/ResourceReference.js +14 -0
- package/engine/graphics/render/frame_graph/TextureDescriptor.js +30 -0
- package/engine/graphics/render/frame_graph/UsageModeType.js +5 -0
- package/engine/graphics/render/frame_graph/sample/deferred/GBufferDrawPass.js +27 -0
- package/engine/graphics/render/frame_graph/sample/deferred/PresentPass.js +17 -0
- package/engine/graphics/render/visibility/hiz/prototypeHiZ.js +0 -2
- package/engine/graphics/render/webgpu/sample/MeshInstance.js +99 -0
- package/engine/graphics/render/webgpu/sample/fragmentDeferredRendering.wgsl +71 -0
- package/engine/graphics/render/webgpu/sample/fragmentGBuffersDebugView.wgsl +39 -0
- package/engine/graphics/render/webgpu/sample/fragmentWriteGBuffers.wgsl +21 -0
- package/engine/graphics/render/webgpu/sample/lightUpdate.wgsl +41 -0
- package/engine/graphics/render/webgpu/sample/main.js +604 -0
- package/engine/graphics/render/webgpu/sample/vertexTextureQuad.wgsl +9 -0
- package/engine/graphics/render/webgpu/sample/vertexWriteGBuffers.wgsl +30 -0
- package/engine/graphics/shadows/ShadowMapRenderer.js +10 -4
- package/engine/graphics/shadows/testShadowMapRendering.js +0 -2
- package/engine/graphics/texture/sampler/Sampler2D.js +24 -45
- package/engine/{ecs/grid → graphics/texture/sampler}/sampler2DToFloat32Texture.js +1 -1
- package/engine/graphics/util/modelHitTest.js +63 -0
- package/engine/grid/systems/GridPosition2TransformSystem.js +1 -1
- package/engine/grid/systems/ViewportGridProjectionSystem.js +1 -1
- package/engine/grid/transform2grid/Transform2GridPositionSystem.js +1 -1
- package/engine/intelligence/behavior/ecs/WaitForEventBehavior.js +3 -0
- package/engine/save/storage/IndexedDBStorage.js +8 -1
- package/engine/scene/transitionToScene.js +1 -1
- package/generation/grid/actions/ContinuousGridCellActionSetTerrainHeight.js +1 -1
- package/generation/markers/actions/placement/MarkerNodeEntityProcessorClingToTerrain.js +1 -1
- package/generation/markers/debug/visualizeMarkers.js +1 -1
- package/generation/theme/ThemeEngine.js +1 -1
- package/package.json +1 -1
- package/samples/terrain/main.js +117 -0
- package/util/ScreenGridPicker.js +3 -0
- package/view/minimap/Minimap.js +1 -1
- package/engine/ecs/sockets/AttachmentSocketsSystem.js +0 -10
|
@@ -1,6 +1,27 @@
|
|
|
1
1
|
import { ShadedGeometry } from "./ShadedGeometry.js";
|
|
2
2
|
import { Transform } from "../../../ecs/transform/Transform.js";
|
|
3
3
|
import { System } from "../../../ecs/System.js";
|
|
4
|
+
import { intersectRay } from "../../../../core/bvh2/aabb3/AABB3Math.js";
|
|
5
|
+
import { GeometrySpatialQueryAccelerator } from "../../geometry/buffered/query/GeometrySpatialQueryAccelerator.js";
|
|
6
|
+
import { SurfacePoint3 } from "../../../../core/geom/3d/SurfacePoint3.js";
|
|
7
|
+
import { v3_distance_sqr } from "../../../../core/geom/v3_distance_sqr.js";
|
|
8
|
+
import { mat4 } from "gl-matrix";
|
|
9
|
+
import { returnTrue } from "../../../../core/function/Functions.js";
|
|
10
|
+
|
|
11
|
+
const traversal_stack = [];
|
|
12
|
+
let traversal_cursor = 0;
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
*
|
|
16
|
+
* @type {SurfacePoint3}
|
|
17
|
+
*/
|
|
18
|
+
const scratch_point = new SurfacePoint3();
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
*
|
|
22
|
+
* @type {Float32Array|mat4}
|
|
23
|
+
*/
|
|
24
|
+
const scratch_m4 = new Float32Array(16);
|
|
4
25
|
|
|
5
26
|
export class ShadedGeometrySystem extends System {
|
|
6
27
|
/**
|
|
@@ -49,7 +70,12 @@ export class ShadedGeometrySystem extends System {
|
|
|
49
70
|
|
|
50
71
|
sg.applyTransform(t);
|
|
51
72
|
|
|
52
|
-
|
|
73
|
+
const leaf_node = sg.bvh;
|
|
74
|
+
|
|
75
|
+
// remember entity for lookups
|
|
76
|
+
sg.__entity = entity;
|
|
77
|
+
|
|
78
|
+
this.__render_layer.bvh.insertNode(leaf_node);
|
|
53
79
|
}
|
|
54
80
|
|
|
55
81
|
/**
|
|
@@ -65,4 +91,135 @@ export class ShadedGeometrySystem extends System {
|
|
|
65
91
|
|
|
66
92
|
sg.bvh.disconnect();
|
|
67
93
|
}
|
|
94
|
+
|
|
95
|
+
/**
|
|
96
|
+
*
|
|
97
|
+
* @param {SurfacePoint3} contact
|
|
98
|
+
* @param {number} origin_x
|
|
99
|
+
* @param {number} origin_y
|
|
100
|
+
* @param {number} origin_z
|
|
101
|
+
* @param {number} direction_x
|
|
102
|
+
* @param {number} direction_y
|
|
103
|
+
* @param {number} direction_z
|
|
104
|
+
* @param {function(entity:number, mesh:ShadedGeometry)} [filter_function]
|
|
105
|
+
* @param {*} [filter_function_context]
|
|
106
|
+
* @returns {{entity:number, mesh:ShadedGeometry}|undefined}
|
|
107
|
+
*/
|
|
108
|
+
raycastNearest(
|
|
109
|
+
contact,
|
|
110
|
+
origin_x, origin_y, origin_z,
|
|
111
|
+
direction_x, direction_y, direction_z,
|
|
112
|
+
filter_function = returnTrue, filter_function_context
|
|
113
|
+
) {
|
|
114
|
+
const root_bvh = this.__render_layer.bvh;
|
|
115
|
+
const stack_frame_address = traversal_cursor;
|
|
116
|
+
|
|
117
|
+
traversal_stack[traversal_cursor++] = root_bvh;
|
|
118
|
+
|
|
119
|
+
let best_distance = Infinity;
|
|
120
|
+
let found_hit = false;
|
|
121
|
+
let best_result = null;
|
|
122
|
+
|
|
123
|
+
while (traversal_cursor > stack_frame_address) {
|
|
124
|
+
traversal_cursor--;
|
|
125
|
+
|
|
126
|
+
/**
|
|
127
|
+
*
|
|
128
|
+
* @type {BinaryNode|LeafNode<ShadedGeometry>}
|
|
129
|
+
*/
|
|
130
|
+
const node = traversal_stack[traversal_cursor];
|
|
131
|
+
|
|
132
|
+
// test node against the ray
|
|
133
|
+
const intersects = intersectRay(
|
|
134
|
+
node.x0, node.y0, node.z0,
|
|
135
|
+
node.x1, node.y1, node.z1,
|
|
136
|
+
origin_x, origin_y, origin_z,
|
|
137
|
+
direction_x, direction_y, direction_z
|
|
138
|
+
);
|
|
139
|
+
|
|
140
|
+
if (!intersects) {
|
|
141
|
+
continue;
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
if (node.isBinaryNode) {
|
|
145
|
+
if (node.right !== null) {
|
|
146
|
+
traversal_stack[traversal_cursor++] = node.right;
|
|
147
|
+
}
|
|
148
|
+
if (node.left !== null) {
|
|
149
|
+
traversal_stack[traversal_cursor++] = node.left;
|
|
150
|
+
}
|
|
151
|
+
} else {
|
|
152
|
+
// leaf node
|
|
153
|
+
|
|
154
|
+
/**
|
|
155
|
+
*
|
|
156
|
+
* @type {ShadedGeometry}
|
|
157
|
+
*/
|
|
158
|
+
const sg = node.object;
|
|
159
|
+
|
|
160
|
+
const entity = sg.__entity;
|
|
161
|
+
|
|
162
|
+
if (!filter_function.call(filter_function_context, entity, sg)) {
|
|
163
|
+
// filtered out
|
|
164
|
+
continue;
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
const m4 = sg.transform;
|
|
168
|
+
|
|
169
|
+
// get transform in local space
|
|
170
|
+
mat4.invert(scratch_m4, m4);
|
|
171
|
+
|
|
172
|
+
// transform ray to local space
|
|
173
|
+
const local_origin_x = scratch_m4[0] * origin_x + scratch_m4[4] * origin_y + scratch_m4[8] * origin_z + scratch_m4[12];
|
|
174
|
+
const local_origin_y = scratch_m4[1] * origin_x + scratch_m4[5] * origin_y + scratch_m4[9] * origin_z + scratch_m4[13];
|
|
175
|
+
const local_origin_z = scratch_m4[2] * origin_x + scratch_m4[6] * origin_y + scratch_m4[10] * origin_z + scratch_m4[14];
|
|
176
|
+
|
|
177
|
+
const local_direction_x = scratch_m4[0] * direction_x + scratch_m4[4] * direction_y + scratch_m4[8] * direction_z;
|
|
178
|
+
const local_direction_y = scratch_m4[1] * direction_x + scratch_m4[5] * direction_y + scratch_m4[9] * direction_z;
|
|
179
|
+
const local_direction_z = scratch_m4[2] * direction_x + scratch_m4[6] * direction_y + scratch_m4[10] * direction_z;
|
|
180
|
+
// NOTE: direction is not normalized
|
|
181
|
+
|
|
182
|
+
const geometry_hit_found = GeometrySpatialQueryAccelerator.INSTANCE.queryRaycastNearest_primitive(
|
|
183
|
+
scratch_point,
|
|
184
|
+
sg.geometry,
|
|
185
|
+
local_origin_x, local_origin_y, local_origin_z,
|
|
186
|
+
local_direction_x, local_direction_y, local_direction_z
|
|
187
|
+
);
|
|
188
|
+
|
|
189
|
+
if (!geometry_hit_found) {
|
|
190
|
+
continue;
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
// transform hit contact into global space
|
|
194
|
+
scratch_point.applyMatrix4(m4);
|
|
195
|
+
|
|
196
|
+
found_hit = true;
|
|
197
|
+
|
|
198
|
+
const hit_position = scratch_point.position;
|
|
199
|
+
|
|
200
|
+
const distance_sqr = v3_distance_sqr(
|
|
201
|
+
hit_position.x, hit_position.y, hit_position.z,
|
|
202
|
+
origin_x, origin_y, origin_z
|
|
203
|
+
);
|
|
204
|
+
|
|
205
|
+
if (distance_sqr >= best_distance) {
|
|
206
|
+
// further than best found
|
|
207
|
+
continue;
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
contact.copy(scratch_point);
|
|
211
|
+
best_result = sg;
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
// drop stack frame
|
|
216
|
+
traversal_cursor = stack_frame_address;
|
|
217
|
+
|
|
218
|
+
if (found_hit) {
|
|
219
|
+
return {
|
|
220
|
+
entity: best_result.__entity,
|
|
221
|
+
mesh: best_result
|
|
222
|
+
};
|
|
223
|
+
}
|
|
224
|
+
}
|
|
68
225
|
}
|
|
@@ -19,7 +19,6 @@ import PathFollowingSystem from "../../../navigation/ecs/path_following/PathFoll
|
|
|
19
19
|
import SteeringSystem from "../../../ecs/systems/SteeringSystem.js";
|
|
20
20
|
import MotionSystem from "../../../ecs/systems/MotionSystem.js";
|
|
21
21
|
import TagSystem from "../../../ecs/systems/TagSystem.js";
|
|
22
|
-
import { AttachmentSocketsSystem } from "../../../ecs/sockets/AttachmentSocketsSystem.js";
|
|
23
22
|
import { AttachmentSystem } from "../../../ecs/attachment/AttachmentSystem.js";
|
|
24
23
|
import { SoundEmitterSystem } from "../../../sound/ecs/emitter/SoundEmitterSystem.js";
|
|
25
24
|
import SoundControllerSystem from "../../../sound/ecs/SoundControllerSystem.js";
|
|
@@ -95,7 +94,6 @@ function makeConfig(engine) {
|
|
|
95
94
|
new SteeringSystem(),
|
|
96
95
|
new MotionSystem(),
|
|
97
96
|
new TagSystem(),
|
|
98
|
-
new AttachmentSocketsSystem(),
|
|
99
97
|
new AttachmentSystem(),
|
|
100
98
|
new SoundEmitterSystem(assetManager, sound.destination, sound.context),
|
|
101
99
|
new SoundControllerSystem(),
|
|
@@ -6,6 +6,10 @@
|
|
|
6
6
|
import Vector3 from "../../../../core/geom/Vector3.js";
|
|
7
7
|
import Vector4 from "../../../../core/geom/Vector4.js";
|
|
8
8
|
import { RibbonXMaterialSpec } from "../../trail/x/RibbonXMaterialSpec.js";
|
|
9
|
+
import { LeafNode } from "../../../../core/bvh2/LeafNode.js";
|
|
10
|
+
import { makeGradientTrail } from "./makeGradientTrail.js";
|
|
11
|
+
import { RibbonX } from "../../trail/x/RibbonX.js";
|
|
12
|
+
import ThreeFactory from "../../three/ThreeFactory.js";
|
|
9
13
|
|
|
10
14
|
/**
|
|
11
15
|
* @readonly
|
|
@@ -14,6 +18,7 @@ import { RibbonXMaterialSpec } from "../../trail/x/RibbonXMaterialSpec.js";
|
|
|
14
18
|
export const Trail2DFlags = {
|
|
15
19
|
Spawning: 1,
|
|
16
20
|
Aging: 2,
|
|
21
|
+
Built: 4,
|
|
17
22
|
};
|
|
18
23
|
|
|
19
24
|
class Trail2D {
|
|
@@ -37,6 +42,12 @@ class Trail2D {
|
|
|
37
42
|
*/
|
|
38
43
|
this.time = 0;
|
|
39
44
|
|
|
45
|
+
/**
|
|
46
|
+
*
|
|
47
|
+
* @type {number}
|
|
48
|
+
*/
|
|
49
|
+
this.trailingIndex = 0;
|
|
50
|
+
|
|
40
51
|
/**
|
|
41
52
|
* Time elapsed since last update
|
|
42
53
|
* @type {number}
|
|
@@ -72,7 +83,11 @@ class Trail2D {
|
|
|
72
83
|
* transient
|
|
73
84
|
* @type {LeafNode|null}
|
|
74
85
|
*/
|
|
75
|
-
this.bvhLeaf =
|
|
86
|
+
this.bvhLeaf = new LeafNode(
|
|
87
|
+
this,
|
|
88
|
+
0, 0, 0,
|
|
89
|
+
0, 0, 0
|
|
90
|
+
);
|
|
76
91
|
|
|
77
92
|
/**
|
|
78
93
|
* @private
|
|
@@ -165,6 +180,21 @@ class Trail2D {
|
|
|
165
180
|
}
|
|
166
181
|
}
|
|
167
182
|
|
|
183
|
+
build(segment_count) {
|
|
184
|
+
|
|
185
|
+
const ribbon = new RibbonX();
|
|
186
|
+
|
|
187
|
+
ribbon.buildGeometry();
|
|
188
|
+
ribbon.setCount(segment_count);
|
|
189
|
+
|
|
190
|
+
const geometry = ribbon.getGeometry();
|
|
191
|
+
|
|
192
|
+
const mesh = ThreeFactory.createMesh(geometry, null);
|
|
193
|
+
|
|
194
|
+
this.ribbon = ribbon;
|
|
195
|
+
this.mesh = mesh;
|
|
196
|
+
}
|
|
197
|
+
|
|
168
198
|
toJSON() {
|
|
169
199
|
return {
|
|
170
200
|
maxAge: this.maxAge,
|
|
@@ -187,10 +217,14 @@ class Trail2D {
|
|
|
187
217
|
&& this.offset.equals(other.offset)
|
|
188
218
|
;
|
|
189
219
|
}
|
|
220
|
+
|
|
221
|
+
|
|
190
222
|
}
|
|
191
223
|
|
|
192
224
|
Trail2D.typeName = "Trail2D";
|
|
193
225
|
|
|
194
226
|
Trail2D.serializable = false;
|
|
195
227
|
|
|
228
|
+
Trail2D.makeGradientTrail = makeGradientTrail;
|
|
229
|
+
|
|
196
230
|
export default Trail2D;
|
|
@@ -10,9 +10,6 @@ import { Transform } from '../../../ecs/transform/Transform.js';
|
|
|
10
10
|
import Vector3 from '../../../../core/geom/Vector3.js';
|
|
11
11
|
|
|
12
12
|
import Trail2D, { Trail2DFlags } from './Trail2D.js';
|
|
13
|
-
|
|
14
|
-
import { LeafNode } from '../../../../core/bvh2/LeafNode.js';
|
|
15
|
-
import ThreeFactory from '../../three/ThreeFactory.js';
|
|
16
13
|
import { GraphicsEngine } from "../../GraphicsEngine.js";
|
|
17
14
|
import { RibbonXFixedPhysicsSimulator } from "../../trail/x/simulator/RibbonXFixedPhysicsSimulator.js";
|
|
18
15
|
import { RibbonX } from "../../trail/x/RibbonX.js";
|
|
@@ -118,11 +115,11 @@ class Trail2DSystem extends System {
|
|
|
118
115
|
|
|
119
116
|
/**
|
|
120
117
|
*
|
|
121
|
-
* @param {Transform} transform
|
|
122
118
|
* @param {Trail2D} trail
|
|
123
|
-
* @param {
|
|
119
|
+
* @param {Transform} transform
|
|
120
|
+
* @private
|
|
124
121
|
*/
|
|
125
|
-
|
|
122
|
+
__build_trail(trail, transform) {
|
|
126
123
|
const segmentsPerSecond = 60;
|
|
127
124
|
const maxSegments = 1000;
|
|
128
125
|
//instantiation
|
|
@@ -130,24 +127,19 @@ class Trail2DSystem extends System {
|
|
|
130
127
|
//make a mesh
|
|
131
128
|
const segment_count = Math.ceil(clamp(trail.maxAge * segmentsPerSecond, 2, maxSegments));
|
|
132
129
|
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
ribbon.buildGeometry();
|
|
136
|
-
ribbon.setCount(segment_count);
|
|
130
|
+
trail.build(segment_count);
|
|
137
131
|
|
|
138
|
-
|
|
139
|
-
const geometry = ribbon.getGeometry();
|
|
132
|
+
const ribbon = trail.ribbon;
|
|
140
133
|
|
|
141
134
|
const ribbons = this.__ribbon_plugin.getValue();
|
|
142
135
|
|
|
143
136
|
const material = ribbons.obtain_material_x(trail.material);
|
|
144
137
|
|
|
145
|
-
|
|
138
|
+
trail.mesh.material = material;
|
|
146
139
|
|
|
147
140
|
trail.time = 0;
|
|
148
141
|
trail.trailingIndex = 0;
|
|
149
142
|
trail.ribbon = ribbon;
|
|
150
|
-
trail.mesh = mesh;
|
|
151
143
|
trail.timeSinceLastUpdate = 0;
|
|
152
144
|
|
|
153
145
|
|
|
@@ -173,16 +165,31 @@ class Trail2DSystem extends System {
|
|
|
173
165
|
|
|
174
166
|
}
|
|
175
167
|
|
|
176
|
-
|
|
177
|
-
trail,
|
|
178
|
-
|
|
168
|
+
trail.bvhLeaf.resize(
|
|
179
169
|
position_x, position_y, position_z,
|
|
180
170
|
position_x, position_y, position_z
|
|
181
171
|
);
|
|
182
172
|
|
|
183
|
-
trail.
|
|
173
|
+
trail.setFlag(Trail2DFlags.Built);
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
/**
|
|
177
|
+
*
|
|
178
|
+
* @param {Transform} transform
|
|
179
|
+
* @param {Trail2D} trail
|
|
180
|
+
* @param {number} entityId
|
|
181
|
+
*/
|
|
182
|
+
link(trail, transform, entityId) {
|
|
183
|
+
if (!trail.getFlag(Trail2DFlags.Built)) {
|
|
184
|
+
this.__build_trail(trail, transform);
|
|
185
|
+
} else {
|
|
186
|
+
|
|
187
|
+
const material = this.__ribbon_plugin.getValue().obtain_material_x(trail.material);
|
|
188
|
+
trail.mesh.material = material;
|
|
189
|
+
}
|
|
190
|
+
|
|
184
191
|
|
|
185
|
-
this.bvh.insertNode(
|
|
192
|
+
this.bvh.insertNode(trail.bvhLeaf);
|
|
186
193
|
}
|
|
187
194
|
|
|
188
195
|
/**
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import Trail2D, { Trail2DFlags } from "./Trail2D.js";
|
|
2
|
+
import {
|
|
3
|
+
RIBBON_ATTRIBUTE_ADDRESS_AGE,
|
|
4
|
+
RIBBON_ATTRIBUTE_ADDRESS_COLOR,
|
|
5
|
+
RIBBON_ATTRIBUTE_ADDRESS_THICKNESS,
|
|
6
|
+
RIBBON_ATTRIBUTE_ADDRESS_UV_OFFSET
|
|
7
|
+
} from "../../trail/x/ribbon_attributes_spec.js";
|
|
8
|
+
import { assert } from "../../../../core/assert.js";
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
*
|
|
12
|
+
* @param {number[]} color
|
|
13
|
+
* @param {number[]} thickness
|
|
14
|
+
* @param {number} [duration]
|
|
15
|
+
* @param {number} [scale]
|
|
16
|
+
* @param {number[]} position
|
|
17
|
+
* @param {number[]} ages
|
|
18
|
+
* @param {string} texture
|
|
19
|
+
* @returns {Trail2D}
|
|
20
|
+
*/
|
|
21
|
+
export function makeGradientTrail({
|
|
22
|
+
color,
|
|
23
|
+
thickness,
|
|
24
|
+
position,
|
|
25
|
+
duration = 1,
|
|
26
|
+
scale = 1,
|
|
27
|
+
ages,
|
|
28
|
+
texture
|
|
29
|
+
}) {
|
|
30
|
+
|
|
31
|
+
const trail2D = new Trail2D();
|
|
32
|
+
trail2D.maxAge = duration;
|
|
33
|
+
trail2D.width = 1;
|
|
34
|
+
trail2D.textureURL = texture;
|
|
35
|
+
|
|
36
|
+
const point_count = thickness.length;
|
|
37
|
+
|
|
38
|
+
trail2D.build(point_count);
|
|
39
|
+
|
|
40
|
+
const ribbon = trail2D.ribbon;
|
|
41
|
+
|
|
42
|
+
for (let i = 0; i < point_count; i++) {
|
|
43
|
+
|
|
44
|
+
const f = i / (point_count - 1);
|
|
45
|
+
const i3 = i * 3;
|
|
46
|
+
|
|
47
|
+
ribbon.setPointAlpha(i, 0);
|
|
48
|
+
ribbon.setPointPosition(i, position[i3], position[i3 + 1], position[i3 + 2]);
|
|
49
|
+
|
|
50
|
+
ribbon.setPointAttribute_Scalar(i, RIBBON_ATTRIBUTE_ADDRESS_AGE, ages[i] * duration);
|
|
51
|
+
ribbon.setPointAttribute_Scalar(i, RIBBON_ATTRIBUTE_ADDRESS_UV_OFFSET, f);
|
|
52
|
+
ribbon.setPointAttribute_Scalar(i, RIBBON_ATTRIBUTE_ADDRESS_THICKNESS, thickness[i]);
|
|
53
|
+
|
|
54
|
+
const c_0 = color[i];
|
|
55
|
+
|
|
56
|
+
assert.isNumber(c_0, `color[i]`);
|
|
57
|
+
|
|
58
|
+
ribbon.setPointAttribute_Vector3(i, RIBBON_ATTRIBUTE_ADDRESS_COLOR, c_0 >> 16, c_0 >> 8, c_0);
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
// don't spawn more trail segments
|
|
62
|
+
trail2D.clearFlag(Trail2DFlags.Spawning);
|
|
63
|
+
trail2D.setFlag(Trail2DFlags.Built);
|
|
64
|
+
|
|
65
|
+
ribbon.computeBoundingBox(trail2D.bvhLeaf);
|
|
66
|
+
|
|
67
|
+
return trail2D;
|
|
68
|
+
}
|
|
@@ -8,10 +8,10 @@ import { LeafNode } from '../../../../core/bvh2/LeafNode.js';
|
|
|
8
8
|
import { buildPlanarRenderLayerClipPlaneComputationMethod } from "../../render/layers/RenderLayerUtils.js";
|
|
9
9
|
import ThreeFactory from "../../three/ThreeFactory.js";
|
|
10
10
|
import { RenderPassType } from "../../render/RenderPassType.js";
|
|
11
|
-
import { obtainTerrain } from "../../../../../model/game/scenes/SceneUtils.js";
|
|
12
11
|
import { makeAlexWaterMaterial } from "../water2/shader/AlexWaterShader.js";
|
|
13
12
|
import { threeUpdateTransform } from "../../util/threeUpdateTransform.js";
|
|
14
13
|
import { StandardFrameBuffers } from "../../StandardFrameBuffers.js";
|
|
14
|
+
import { obtainTerrain } from "../../../ecs/terrain/util/obtainTerrain.js";
|
|
15
15
|
|
|
16
16
|
const WATER_SIZE = 800;
|
|
17
17
|
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { obtainTerrain } from "../../../../../../model/game/scenes/SceneUtils.js";
|
|
2
1
|
import { seededRandom } from "../../../../../core/math/random/seededRandom.js";
|
|
3
2
|
import { EngineConfiguration } from "../../../../EngineConfiguration.js";
|
|
4
3
|
import ScriptSystem from "../../../../ecs/systems/ScriptSystem.js";
|
|
@@ -28,6 +27,7 @@ import { EngineHarness } from "../../../../EngineHarness.js";
|
|
|
28
27
|
import Vector2 from "../../../../../core/geom/Vector2.js";
|
|
29
28
|
import Vector3 from "../../../../../core/geom/Vector3.js";
|
|
30
29
|
import SimplexNoise from 'simplex-noise';
|
|
30
|
+
import { obtainTerrain } from "../../../../ecs/terrain/util/obtainTerrain.js";
|
|
31
31
|
|
|
32
32
|
const engineHarness = new EngineHarness();
|
|
33
33
|
|
|
@@ -2,6 +2,7 @@ import { Cache } from "../../../../../core/cache/Cache.js";
|
|
|
2
2
|
import { buildUnsorted } from "../../bvh/buffered/BinaryBVHFromBufferGeometry.js";
|
|
3
3
|
import { ClippingPlaneContainmentComputingVisitor } from "./ClippingPlaneContainmentComputingVisitor.js";
|
|
4
4
|
import { RaycastNearestHitComputingVisitor } from "./RaycastNearestHitComputingVisitor.js";
|
|
5
|
+
import { assert } from "../../../../../core/assert.js";
|
|
5
6
|
|
|
6
7
|
export class GeometrySpatialQueryAccelerator {
|
|
7
8
|
constructor(cache_size = 100 * 1024 * 1024) {
|
|
@@ -38,6 +39,8 @@ export class GeometrySpatialQueryAccelerator {
|
|
|
38
39
|
* @returns {number} -1,0,1. -1 means fully outside, 0 means partially inside, 1 means fully inside
|
|
39
40
|
*/
|
|
40
41
|
queryContainmentViaClippingPlanes(geometry, planes) {
|
|
42
|
+
assert.notNull(geometry, 'geometry');
|
|
43
|
+
assert.defined(geometry, 'geometry');
|
|
41
44
|
|
|
42
45
|
const bvh = this.__acquireBVH(geometry);
|
|
43
46
|
|
|
@@ -53,14 +56,25 @@ export class GeometrySpatialQueryAccelerator {
|
|
|
53
56
|
}
|
|
54
57
|
|
|
55
58
|
/**
|
|
56
|
-
*
|
|
59
|
+
*
|
|
57
60
|
* @param {SurfacePoint3} destination
|
|
58
61
|
* @param {THREE.BufferGeometry} geometry
|
|
59
|
-
* @param {
|
|
60
|
-
* @param {
|
|
61
|
-
* @
|
|
62
|
+
* @param {number} ray_origin_x
|
|
63
|
+
* @param {number} ray_origin_y
|
|
64
|
+
* @param {number} ray_origin_z
|
|
65
|
+
* @param {number} ray_direction_x
|
|
66
|
+
* @param {number} ray_direction_y
|
|
67
|
+
* @param {number} ray_direction_z
|
|
68
|
+
* @return {boolean}
|
|
62
69
|
*/
|
|
63
|
-
|
|
70
|
+
queryRaycastNearest_primitive(
|
|
71
|
+
destination,
|
|
72
|
+
geometry,
|
|
73
|
+
ray_origin_x, ray_origin_y, ray_origin_z,
|
|
74
|
+
ray_direction_x, ray_direction_y, ray_direction_z
|
|
75
|
+
) {
|
|
76
|
+
assert.notNull(geometry, 'geometry');
|
|
77
|
+
assert.defined(geometry, 'geometry');
|
|
64
78
|
|
|
65
79
|
const bvh = this.__acquireBVH(geometry);
|
|
66
80
|
|
|
@@ -69,12 +83,12 @@ export class GeometrySpatialQueryAccelerator {
|
|
|
69
83
|
this.__visitor_raycast.setGeometry(geometry);
|
|
70
84
|
this.__visitor_raycast.setRoot(bvh);
|
|
71
85
|
this.__visitor_raycast.setRay(
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
86
|
+
ray_origin_x,
|
|
87
|
+
ray_origin_y,
|
|
88
|
+
ray_origin_z,
|
|
89
|
+
ray_direction_x,
|
|
90
|
+
ray_direction_y,
|
|
91
|
+
ray_direction_z
|
|
78
92
|
);
|
|
79
93
|
|
|
80
94
|
bvh.traversePreOrderStack(this.__visitor_raycast, 0);
|
|
@@ -87,6 +101,27 @@ export class GeometrySpatialQueryAccelerator {
|
|
|
87
101
|
} else {
|
|
88
102
|
return false;
|
|
89
103
|
}
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
/**
|
|
107
|
+
* Get the nearest ray intersection
|
|
108
|
+
* @param {SurfacePoint3} destination
|
|
109
|
+
* @param {THREE.BufferGeometry} geometry
|
|
110
|
+
* @param {Vector3} ray_origin
|
|
111
|
+
* @param {Vector3} ray_direction
|
|
112
|
+
* @returns {boolean} true if hit detected, false otherwise
|
|
113
|
+
*/
|
|
114
|
+
queryRaycastNearest(destination, geometry, ray_origin, ray_direction) {
|
|
115
|
+
|
|
116
|
+
return this.queryRaycastNearest_primitive(
|
|
117
|
+
destination, geometry,
|
|
118
|
+
ray_origin.x,
|
|
119
|
+
ray_origin.y,
|
|
120
|
+
ray_origin.z,
|
|
121
|
+
ray_direction.x,
|
|
122
|
+
ray_direction.y,
|
|
123
|
+
ray_direction.z
|
|
124
|
+
);
|
|
90
125
|
|
|
91
126
|
}
|
|
92
127
|
|
|
@@ -96,6 +131,9 @@ export class GeometrySpatialQueryAccelerator {
|
|
|
96
131
|
* @returns {IndexedBinaryBVH}
|
|
97
132
|
*/
|
|
98
133
|
__acquireBVH(geometry) {
|
|
134
|
+
assert.notNull(geometry, 'geometry');
|
|
135
|
+
assert.defined(geometry, 'geometry');
|
|
136
|
+
|
|
99
137
|
const existing = this.cache.get(geometry);
|
|
100
138
|
|
|
101
139
|
if (existing !== null) {
|
|
@@ -122,3 +160,9 @@ export class GeometrySpatialQueryAccelerator {
|
|
|
122
160
|
}
|
|
123
161
|
|
|
124
162
|
}
|
|
163
|
+
|
|
164
|
+
/**
|
|
165
|
+
* @readonly
|
|
166
|
+
* @type {GeometrySpatialQueryAccelerator}
|
|
167
|
+
*/
|
|
168
|
+
GeometrySpatialQueryAccelerator.INSTANCE = new GeometrySpatialQueryAccelerator();
|
|
@@ -3,12 +3,18 @@ import { computeGeometryHash } from "../../asset/loaders/geometry/geometry/compu
|
|
|
3
3
|
import { computeGeometryEquality } from "../../asset/loaders/geometry/geometry/computeGeometryEquality.js";
|
|
4
4
|
import { buildMicronGeometryFromBufferGeometry } from "./build/buildMicronGeometryFromBufferGeometry.js";
|
|
5
5
|
import { ThreeMicronMesh } from "./format/ThreeMicronMesh.js";
|
|
6
|
+
import { AsyncMapWrapper } from "../../../core/collection/map/AsyncMapWrapper.js";
|
|
6
7
|
|
|
7
8
|
/**
|
|
8
9
|
*
|
|
9
10
|
* @type {HashMap<THREE.BufferGeometry, MicronGeometry>}
|
|
10
11
|
*/
|
|
11
|
-
const
|
|
12
|
+
const default_micron_cache = new AsyncMapWrapper(new HashMap({
|
|
13
|
+
keyHashFunction: computeGeometryHash,
|
|
14
|
+
keyEqualityFunction: computeGeometryEquality
|
|
15
|
+
}));
|
|
16
|
+
|
|
17
|
+
const pending_cache = new HashMap({
|
|
12
18
|
keyHashFunction: computeGeometryHash,
|
|
13
19
|
keyEqualityFunction: computeGeometryEquality
|
|
14
20
|
});
|
|
@@ -17,9 +23,10 @@ const micron_cache = new HashMap({
|
|
|
17
23
|
/**
|
|
18
24
|
*
|
|
19
25
|
* @param {THREE.Object3D} object
|
|
26
|
+
* @param {AbstractAsyncMap<THREE.BufferGeometry, MicronGeometry>} micron_cache
|
|
20
27
|
* @returns {THREE.Object3D}
|
|
21
28
|
*/
|
|
22
|
-
export async function convert_three_object_to_micron(object) {
|
|
29
|
+
export async function convert_three_object_to_micron(object, micron_cache = default_micron_cache) {
|
|
23
30
|
|
|
24
31
|
const promises = [];
|
|
25
32
|
|
|
@@ -29,19 +36,29 @@ export async function convert_three_object_to_micron(object) {
|
|
|
29
36
|
* @returns {MicronGeometry}
|
|
30
37
|
*/
|
|
31
38
|
async function obtain_geometry(g) {
|
|
32
|
-
const existing = micron_cache.get(g);
|
|
39
|
+
const existing = await micron_cache.get(g);
|
|
40
|
+
|
|
41
|
+
if (existing !== undefined && existing !== null) {
|
|
42
|
+
return existing;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
const pending = pending_cache.get(g);
|
|
33
46
|
|
|
34
|
-
if (
|
|
35
|
-
return await
|
|
47
|
+
if (pending !== undefined) {
|
|
48
|
+
return await pending;
|
|
36
49
|
}
|
|
37
50
|
|
|
38
51
|
const micron_geometry_promise = buildMicronGeometryFromBufferGeometry(g);
|
|
39
52
|
|
|
40
|
-
|
|
53
|
+
pending_cache.set(g, micron_geometry_promise);
|
|
41
54
|
|
|
42
55
|
promises.push(micron_geometry_promise);
|
|
43
56
|
|
|
44
|
-
|
|
57
|
+
const micron_geometry = await micron_geometry_promise;
|
|
58
|
+
|
|
59
|
+
await micron_cache.set(g, micron_geometry);
|
|
60
|
+
|
|
61
|
+
return micron_geometry;
|
|
45
62
|
}
|
|
46
63
|
|
|
47
64
|
|