@woosh/meep-engine 2.33.58 → 2.33.62
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/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 +1 -1
- package/editor/tools/paint/TerrainPaintTool.js +1 -1
- package/editor/tools/paint/TerrainTexturePaintTool.js +1 -1
- package/editor/view/EditorView.js +1 -1
- package/editor/view/GridPickCoordinateView.js +1 -1
- 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 +1 -1
- package/engine/ecs/grid/HeightMap2NormalMap.js +1 -1
- package/engine/ecs/grid/NormalMap2AOMap.js +1 -1
- package/engine/ecs/gui/GUIElement.js +0 -106
- package/engine/ecs/gui/GUIElementSerializationAdapter.js +108 -0
- 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/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/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/TopDownCameraController.js +0 -1
- package/engine/graphics/ecs/camera/topdown/TopDownCameraController.spec.js +8 -0
- 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/ParticleVolume.d.ts +2 -0
- package/engine/graphics/particles/particular/engine/utils/volume/prototypeParticleVolume.js +2 -5
- package/engine/graphics/render/buffer/buffers/prototypeNormalFrameBuffer.js +0 -2
- package/engine/graphics/render/forward_plus/plugin/ptototypeFPPlugin.js +1 -3
- 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 +87 -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/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/view/minimap/Minimap.js +1 -1
- package/engine/ecs/sockets/AttachmentSocketsSystem.js +0 -10
|
@@ -9,13 +9,13 @@ import { Transform } from '../../transform/Transform.js';
|
|
|
9
9
|
import ClingToTerrain from './ClingToTerrain.js';
|
|
10
10
|
|
|
11
11
|
import Vector3 from '../../../../core/geom/Vector3.js';
|
|
12
|
-
import { obtainTerrain } from "../../../../../model/game/scenes/SceneUtils.js";
|
|
13
12
|
import Quaternion from "../../../../core/geom/Quaternion.js";
|
|
14
|
-
import { EPSILON} from "../../../../core/math/MathUtils.js";
|
|
13
|
+
import { EPSILON } from "../../../../core/math/MathUtils.js";
|
|
15
14
|
import { Matrix4 } from "three";
|
|
16
15
|
import { assert } from "../../../../core/assert.js";
|
|
17
16
|
import { SurfacePoint3 } from "../../../../core/geom/3d/SurfacePoint3.js";
|
|
18
17
|
import { Deque } from "../../../../core/collection/queue/Deque.js";
|
|
18
|
+
import { obtainTerrain } from "../util/obtainTerrain.js";
|
|
19
19
|
|
|
20
20
|
|
|
21
21
|
/**
|
|
@@ -909,7 +909,7 @@ class Terrain {
|
|
|
909
909
|
|
|
910
910
|
worker.setHeightSampler(s.data, s.itemSize, s.width, s.height);
|
|
911
911
|
|
|
912
|
-
|
|
912
|
+
return worker.computeHeightRange()
|
|
913
913
|
.then(({ min, max }) => {
|
|
914
914
|
this.tiles.setHeightRange(min, max);
|
|
915
915
|
});
|
|
@@ -1038,13 +1038,22 @@ class Terrain {
|
|
|
1038
1038
|
heightSampler: this.samplerHeight
|
|
1039
1039
|
});
|
|
1040
1040
|
|
|
1041
|
+
|
|
1041
1042
|
const result = promise.then(() => {
|
|
1042
1043
|
|
|
1043
|
-
|
|
1044
|
-
|
|
1044
|
+
const ref = this.__material_reference;
|
|
1045
|
+
|
|
1046
|
+
let mat = this.material;
|
|
1047
|
+
|
|
1048
|
+
if (ref !== null && ref.getValue() !== null) {
|
|
1049
|
+
mat = ref.getValue();
|
|
1050
|
+
}
|
|
1051
|
+
|
|
1052
|
+
mat.aoMap = true;
|
|
1053
|
+
mat.needsUpdate = true;
|
|
1045
1054
|
|
|
1046
|
-
|
|
1047
|
-
|
|
1055
|
+
mat.uniforms.aoMap.value = texture;
|
|
1056
|
+
mat.uniforms.aoMapIntensity.value = 0.7;
|
|
1048
1057
|
|
|
1049
1058
|
return texture;
|
|
1050
1059
|
});
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
import TopDownCameraControllerSystem from "../../../graphics/ecs/camera/topdown/TopDownCameraControllerSystem.js";
|
|
2
|
+
import { Camera } from "../../../graphics/ecs/camera/Camera.js";
|
|
3
|
+
import { obtainTerrain } from "./obtainTerrain.js";
|
|
4
|
+
import { assert } from "../../../../core/assert.js";
|
|
5
|
+
import TerrainSystem from "../ecs/TerrainSystem.js";
|
|
6
|
+
import Task from "../../../../core/process/task/Task.js";
|
|
7
|
+
import TaskSignal from "../../../../core/process/task/TaskSignal.js";
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
*
|
|
11
|
+
* @param {EntityManager} em
|
|
12
|
+
* @param {EntityComponentDataset} ecd
|
|
13
|
+
* @returns {Task}
|
|
14
|
+
*/
|
|
15
|
+
export function loadVisibleTerrainTiles(em, ecd) {
|
|
16
|
+
|
|
17
|
+
let totalTiles = 0;
|
|
18
|
+
let loadedTiles = 0;
|
|
19
|
+
let failedTiles = 0;
|
|
20
|
+
|
|
21
|
+
let attempt = 0;
|
|
22
|
+
|
|
23
|
+
let failureFlag = false;
|
|
24
|
+
|
|
25
|
+
function init() {
|
|
26
|
+
const attemptId = attempt;
|
|
27
|
+
|
|
28
|
+
//force update by camera controller, to ensure correct focus is set
|
|
29
|
+
em.getSystem(TopDownCameraControllerSystem).update(0);
|
|
30
|
+
|
|
31
|
+
ecd.traverseComponents(Camera, function (c) {
|
|
32
|
+
c.updateMatrices();
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
const tiles = [];
|
|
36
|
+
|
|
37
|
+
const terrain = obtainTerrain(ecd);
|
|
38
|
+
|
|
39
|
+
assert.notEqual(terrain, null, 'terrain not found');
|
|
40
|
+
|
|
41
|
+
TerrainSystem.traverseVisibleTiles(ecd, terrain, function (tile) {
|
|
42
|
+
tiles.push(tile);
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
totalTiles = tiles.length;
|
|
46
|
+
const tileManager = terrain.tiles;
|
|
47
|
+
|
|
48
|
+
function handleObtainedTile(t) {
|
|
49
|
+
if (attemptId !== attempt) {
|
|
50
|
+
return;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
loadedTiles++;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
function handleFailedTile(t) {
|
|
57
|
+
if (attemptId !== attempt) {
|
|
58
|
+
return;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
attempt++;
|
|
62
|
+
|
|
63
|
+
failedTiles++;
|
|
64
|
+
|
|
65
|
+
if (attempt < 10) {
|
|
66
|
+
init();
|
|
67
|
+
} else {
|
|
68
|
+
failureFlag = true;
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
if (totalTiles !== 0) {
|
|
73
|
+
tiles.forEach(function (tile) {
|
|
74
|
+
tileManager.obtain(tile.gridPosition.x, tile.gridPosition.y).then(handleObtainedTile, handleFailedTile);
|
|
75
|
+
});
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
const task = new Task({
|
|
80
|
+
name: "Building visible terrain tiles",
|
|
81
|
+
|
|
82
|
+
initializer: init,
|
|
83
|
+
|
|
84
|
+
cycleFunction() {
|
|
85
|
+
if (failureFlag) {
|
|
86
|
+
return TaskSignal.EndFailure;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
if (loadedTiles >= totalTiles) {
|
|
90
|
+
return TaskSignal.EndSuccess;
|
|
91
|
+
} else {
|
|
92
|
+
return TaskSignal.Yield;
|
|
93
|
+
}
|
|
94
|
+
},
|
|
95
|
+
|
|
96
|
+
computeProgress() {
|
|
97
|
+
if (totalTiles === 0) {
|
|
98
|
+
return 0;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
const f = loadedTiles / totalTiles;
|
|
102
|
+
|
|
103
|
+
if (f >= 1) {
|
|
104
|
+
return 1;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
return f;
|
|
108
|
+
}
|
|
109
|
+
});
|
|
110
|
+
|
|
111
|
+
return task;
|
|
112
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { assert } from "../../../../core/assert.js";
|
|
2
|
+
import Terrain from "../ecs/Terrain.js";
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
*
|
|
6
|
+
* @param {EntityComponentDataset} ecd
|
|
7
|
+
* @param {function(terrain:Terrain,entity:number)} [callback]
|
|
8
|
+
* @returns {Terrain|null}
|
|
9
|
+
*/
|
|
10
|
+
export function obtainTerrain(ecd, callback) {
|
|
11
|
+
assert.notEqual(ecd, null, 'ecd is null');
|
|
12
|
+
assert.notEqual(ecd, undefined, 'ecd is undefined');
|
|
13
|
+
|
|
14
|
+
const object = ecd.getAnyComponent(Terrain);
|
|
15
|
+
|
|
16
|
+
const terrain = object.component;
|
|
17
|
+
|
|
18
|
+
if (terrain !== null && typeof callback === "function") {
|
|
19
|
+
callback(terrain, object.entity);
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
return terrain;
|
|
23
|
+
}
|
|
@@ -10,7 +10,7 @@ export function removeComponentsExcept(ecd, entity, whitelist) {
|
|
|
10
10
|
const components = ecd.getAllComponents(entity);
|
|
11
11
|
const component_count = components.length;
|
|
12
12
|
|
|
13
|
-
for (let i = 0; i < component_count; i++) {
|
|
13
|
+
l0:for (let i = 0; i < component_count; i++) {
|
|
14
14
|
const component = components[i];
|
|
15
15
|
|
|
16
16
|
if (component === undefined) {
|
|
@@ -21,7 +21,7 @@ export function removeComponentsExcept(ecd, entity, whitelist) {
|
|
|
21
21
|
for (let i = 0; i < exception_count; i++) {
|
|
22
22
|
if (component instanceof whitelist[i]) {
|
|
23
23
|
//keep
|
|
24
|
-
continue;
|
|
24
|
+
continue l0;
|
|
25
25
|
}
|
|
26
26
|
}
|
|
27
27
|
|
|
@@ -29,4 +29,4 @@ export function removeComponentsExcept(ecd, entity, whitelist) {
|
|
|
29
29
|
ecd.removeComponentFromEntityByIndex(entity, i);
|
|
30
30
|
}
|
|
31
31
|
|
|
32
|
-
}
|
|
32
|
+
}
|
|
@@ -35,7 +35,6 @@ import { MetricsCategory } from "../metrics/MetricsCategory.js";
|
|
|
35
35
|
import Vector1 from "../../core/geom/Vector1.js";
|
|
36
36
|
import { NormalFrameBuffer } from "./render/buffer/buffers/NormalFrameBuffer.js";
|
|
37
37
|
import { MaterialManager } from "./material/manager/MaterialManager.js";
|
|
38
|
-
import { CoalesceTextures } from "./material/manager/compilers/CoalesceTextures.js";
|
|
39
38
|
import { ShadowMapRenderer } from "./shadows/ShadowMapRenderer.js";
|
|
40
39
|
import { CameraViewManager } from "./render/view/CameraViewManager.js";
|
|
41
40
|
import { StandardFrameBuffers } from "./StandardFrameBuffers.js";
|
|
@@ -91,14 +90,15 @@ function GraphicsEngine(camera, entityManger) {
|
|
|
91
90
|
*/
|
|
92
91
|
this.__material_manager = new MaterialManager();
|
|
93
92
|
|
|
94
|
-
|
|
93
|
+
// The line below would de-dupe textures, it is a rather slow process however
|
|
94
|
+
// this.__material_manager.addCompileStep(new CoalesceTextures());
|
|
95
95
|
|
|
96
96
|
this.on = {
|
|
97
97
|
preRender: new Signal(),
|
|
98
98
|
postRender: new Signal(),
|
|
99
99
|
|
|
100
100
|
preOpaquePass: new Signal(),
|
|
101
|
-
postOpaquePass
|
|
101
|
+
postOpaquePass: new Signal(),
|
|
102
102
|
|
|
103
103
|
/**
|
|
104
104
|
* @deprecated
|
|
@@ -585,6 +585,7 @@ GraphicsEngine.prototype.renderOpaque = function () {
|
|
|
585
585
|
GraphicsEngine.prototype.renderTransparent = function () {
|
|
586
586
|
const scene = this.scene;
|
|
587
587
|
|
|
588
|
+
// clear background, as transparent pass is drawn on top, the background should already be composited
|
|
588
589
|
const _background = scene.background;
|
|
589
590
|
scene.background = null;
|
|
590
591
|
|
|
@@ -596,8 +597,6 @@ GraphicsEngine.prototype.renderTransparent = function () {
|
|
|
596
597
|
|
|
597
598
|
// restore background
|
|
598
599
|
scene.background = _background;
|
|
599
|
-
|
|
600
|
-
// TODO render transparent objects into a buffer, to be able to apply post-fx
|
|
601
600
|
};
|
|
602
601
|
|
|
603
602
|
/**
|
|
@@ -8,8 +8,6 @@ import PathFollowingSystem from "../../navigation/ecs/path_following/PathFollowi
|
|
|
8
8
|
import SteeringSystem from "../../ecs/systems/SteeringSystem.js";
|
|
9
9
|
import MotionSystem from "../../ecs/systems/MotionSystem.js";
|
|
10
10
|
import TagSystem from "../../ecs/systems/TagSystem.js";
|
|
11
|
-
import { AttachmentSocketsSystem } from "../../ecs/sockets/AttachmentSocketsSystem.js";
|
|
12
|
-
import { AttachmentSystem } from "../../ecs/attachment/AttachmentSystem.js";
|
|
13
11
|
import { SoundEmitterSystem } from "../../sound/ecs/emitter/SoundEmitterSystem.js";
|
|
14
12
|
import SoundControllerSystem from "../../sound/ecs/SoundControllerSystem.js";
|
|
15
13
|
import SoundListenerSystem from "../../sound/ecs/SoundListenerSystem.js";
|
|
@@ -84,8 +82,6 @@ function makeConfig(engine) {
|
|
|
84
82
|
new SteeringSystem(),
|
|
85
83
|
new MotionSystem(),
|
|
86
84
|
new TagSystem(),
|
|
87
|
-
new AttachmentSocketsSystem(),
|
|
88
|
-
new AttachmentSystem(),
|
|
89
85
|
new SoundEmitterSystem(assetManager, sound.destination, sound.context),
|
|
90
86
|
new SoundControllerSystem(),
|
|
91
87
|
new SoundListenerSystem(sound.context),
|
|
@@ -3,6 +3,14 @@ import Vector3 from "../../../../../core/geom/Vector3.js";
|
|
|
3
3
|
import { computeTopDownTransform } from "./TopDownCameraControllerSystem.js";
|
|
4
4
|
import { Transform } from "../../../../ecs/transform/Transform.js";
|
|
5
5
|
|
|
6
|
+
test('setFromEyeAndTarget does not introduce roll when UP is aligned with +Y', () => {
|
|
7
|
+
const ut = new TopDownCameraController();
|
|
8
|
+
|
|
9
|
+
ut.setFromEyeAndTarget(new Vector3(0, 1, -1), new Vector3(0, 0, 0), new Vector3(0, 1, 0));
|
|
10
|
+
|
|
11
|
+
expect(ut.roll).toBe(0);
|
|
12
|
+
});
|
|
13
|
+
|
|
6
14
|
test('setFromEyeAndTarget results in roll respecting UP vector', () => {
|
|
7
15
|
const eye = new Vector3();
|
|
8
16
|
const target = new Vector3();
|
|
@@ -2,11 +2,11 @@ import { clamp } from "../../../../../core/math/clamp.js";
|
|
|
2
2
|
import { System } from "../../../../ecs/System.js";
|
|
3
3
|
import { TopDownCameraLander } from "./TopDownCameraLander.js";
|
|
4
4
|
import { Cache } from "../../../../../core/cache/Cache.js";
|
|
5
|
-
import { obtainTerrain } from "../../../../../../model/game/scenes/SceneUtils.js";
|
|
6
5
|
import { buildCameraTargetSampler } from "../../../../input/ecs/util/TerrainCameraTargetSampler.js";
|
|
7
6
|
import TopDownCameraController from "./TopDownCameraController.js";
|
|
8
7
|
import Vector2 from "../../../../../core/geom/Vector2.js";
|
|
9
8
|
import { SignalBinding } from "../../../../../core/events/signal/SignalBinding.js";
|
|
9
|
+
import { obtainTerrain } from "../../../../ecs/terrain/util/obtainTerrain.js";
|
|
10
10
|
|
|
11
11
|
|
|
12
12
|
/**
|
|
@@ -52,10 +52,10 @@ class Mesh {
|
|
|
52
52
|
this.mesh = null;
|
|
53
53
|
|
|
54
54
|
/**
|
|
55
|
-
* Mesh
|
|
55
|
+
* Override Mesh data, if available. Typically set via plugins
|
|
56
56
|
* @type {Object3D|null}
|
|
57
57
|
*/
|
|
58
|
-
this.
|
|
58
|
+
this.override_mesh = null;
|
|
59
59
|
|
|
60
60
|
/**
|
|
61
61
|
* @transient
|
|
@@ -128,9 +128,9 @@ class Mesh {
|
|
|
128
128
|
//set bvh
|
|
129
129
|
updateNodeByTransformAndBBB(this.bvh, this.boundingBox, _t);
|
|
130
130
|
|
|
131
|
-
//
|
|
132
|
-
if (this.
|
|
133
|
-
applyTransformToThreeObject(this.
|
|
131
|
+
// override
|
|
132
|
+
if (this.override_mesh !== null) {
|
|
133
|
+
applyTransformToThreeObject(this.override_mesh, _t);
|
|
134
134
|
}
|
|
135
135
|
}
|
|
136
136
|
|
|
@@ -18,7 +18,6 @@ import Mesh, { MeshFlags } from "./Mesh.js";
|
|
|
18
18
|
import { applyComponentPropertiesToThreeObject, setMesh } from "./setMesh.js";
|
|
19
19
|
import { GLTFAssetLoader } from "../../../asset/loaders/GLTFAssetLoader.js";
|
|
20
20
|
import { MeshEvents } from "./MeshEvents.js";
|
|
21
|
-
import { MicronRenderPlugin } from "../../micron/plugin/MicronRenderPlugin.js";
|
|
22
21
|
import { assert } from "../../../../core/assert.js";
|
|
23
22
|
|
|
24
23
|
const placeholderGeometry = new BoxBufferGeometry(1, 1, 1);
|
|
@@ -86,13 +85,6 @@ export class MeshSystem extends System {
|
|
|
86
85
|
* @type {BinaryNode}
|
|
87
86
|
*/
|
|
88
87
|
this.bvh = null;
|
|
89
|
-
|
|
90
|
-
/**
|
|
91
|
-
*
|
|
92
|
-
* @type {boolean}
|
|
93
|
-
* @private
|
|
94
|
-
*/
|
|
95
|
-
this.__use_micron = false;
|
|
96
88
|
}
|
|
97
89
|
|
|
98
90
|
/**
|
|
@@ -126,11 +118,11 @@ export class MeshSystem extends System {
|
|
|
126
118
|
|
|
127
119
|
component.setFlag(MeshFlags.Loaded);
|
|
128
120
|
|
|
129
|
-
//
|
|
130
|
-
if (asset.
|
|
131
|
-
component.
|
|
121
|
+
// override
|
|
122
|
+
if (asset.override_mesh !== undefined ) {
|
|
123
|
+
component.override_mesh = asset.override_mesh.clone();
|
|
132
124
|
|
|
133
|
-
applyComponentPropertiesToThreeObject(component, component.
|
|
125
|
+
applyComponentPropertiesToThreeObject(component, component.override_mesh, entity);
|
|
134
126
|
}
|
|
135
127
|
|
|
136
128
|
setMesh(dataset, entity, component, mesh);
|
|
@@ -141,11 +133,6 @@ export class MeshSystem extends System {
|
|
|
141
133
|
}
|
|
142
134
|
|
|
143
135
|
async startup(entityManager, readyCallback, errorCallback) {
|
|
144
|
-
const engine = this.__engine;
|
|
145
|
-
|
|
146
|
-
// is micron supported here?
|
|
147
|
-
this.__use_micron = engine.plugins.getPlugin(MicronRenderPlugin) !== undefined;
|
|
148
|
-
|
|
149
136
|
const am = this.assetManager;
|
|
150
137
|
|
|
151
138
|
this.entityManager = entityManager;
|
|
@@ -158,10 +145,15 @@ export class MeshSystem extends System {
|
|
|
158
145
|
const graphics = this.graphics;
|
|
159
146
|
this.renderLayer = graphics.layers.create("mesh-system");
|
|
160
147
|
|
|
148
|
+
/**
|
|
149
|
+
*
|
|
150
|
+
* @param {Mesh} component
|
|
151
|
+
* @return {Object3D}
|
|
152
|
+
*/
|
|
161
153
|
const extractRenderable = (component) => {
|
|
162
|
-
if (
|
|
163
|
-
// use
|
|
164
|
-
return component.
|
|
154
|
+
if (component.override_mesh !== null) {
|
|
155
|
+
// use override mesh
|
|
156
|
+
return component.override_mesh;
|
|
165
157
|
} else {
|
|
166
158
|
// use standard mesh
|
|
167
159
|
return component.mesh;
|
|
@@ -39,6 +39,35 @@ export class ShadedGeometry {
|
|
|
39
39
|
* @private
|
|
40
40
|
*/
|
|
41
41
|
this.__bvh_leaf = new LeafNode(this, 0, 0, 0, 0, 0, 0);
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* Transient, assigned in the system
|
|
45
|
+
* @type {number}
|
|
46
|
+
* @private
|
|
47
|
+
*/
|
|
48
|
+
this.__entity = -1;
|
|
49
|
+
/**
|
|
50
|
+
* Transform matrix
|
|
51
|
+
* Transient, assigned in the system
|
|
52
|
+
* @type {number[]|null}
|
|
53
|
+
* @private
|
|
54
|
+
*/
|
|
55
|
+
this.__transform = null;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* Global transform matrix
|
|
60
|
+
* 4x4 matrix
|
|
61
|
+
* @return {null|number[]}
|
|
62
|
+
*/
|
|
63
|
+
get transform() {
|
|
64
|
+
if (this.__transform !== null) {
|
|
65
|
+
return this.__transform;
|
|
66
|
+
} else if (this.__cached_object !== null) {
|
|
67
|
+
return this.__cached_object.matrix.elements;
|
|
68
|
+
} else {
|
|
69
|
+
return null;
|
|
70
|
+
}
|
|
42
71
|
}
|
|
43
72
|
|
|
44
73
|
__build_object() {
|
|
@@ -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(),
|