@woosh/meep-engine 2.33.3 → 2.33.8
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/LeafNode.js +6 -1
- package/core/bvh2/aabb3/AABB3.js +21 -1
- package/core/bvh2/aabb3/aabb3_intersects_frustum.js +10 -2
- package/core/collection/RingBuffer.js +40 -10
- package/core/collection/array/copyArray.js +2 -2
- package/core/collection/array/typed/typed_array_copy.js +2 -2
- package/core/collection/set/compute_set_difference.js +32 -0
- package/core/collection/set/compute_set_intersection.js +22 -0
- package/core/collection/set/set_remove.js +15 -0
- package/core/collection/table/RowFirstTableSpec.js +8 -0
- package/core/color/Color.js +1 -0
- package/core/color/ColorUtils.js +12 -3
- package/core/geom/3d/aabb/aabb3_compute_projected_area.js +6 -4
- package/core/geom/3d/aabb/aabb3_estimate_projected_area2.js +59 -0
- package/core/geom/3d/aabb/aabb3_from_min_max.js +15 -0
- package/core/geom/3d/aabb/aabb3_matrix4_project.js +33 -0
- package/core/geom/3d/aabb/aabb3_matrix4_project.spec.js +41 -0
- package/core/geom/3d/aabb/aabb3_matrix4_project_by_corners.js +96 -0
- package/{engine/graphics/micron/render/v1 → core/geom/3d}/apply_mat4_transform_to_v3_array.js +0 -0
- package/{engine/graphics/micron/build/bounds → core/geom/3d}/compute_bounding_cone_of_2_cones.js +3 -3
- package/{engine/graphics/micron/build/bounds → core/geom/3d}/compute_bounding_cone_of_2_cones.spec.js +1 -1
- package/{engine/graphics/micron/build/bounds → core/geom/3d}/compute_bounding_sphere_of_2_spheres.js +3 -3
- package/{engine/graphics/micron/util → core/geom/3d}/encode_unit3_hemioct.js +0 -0
- package/core/geom/3d/frustum/array_normalize_plane.js +25 -0
- package/core/geom/3d/frustum/array_setFromProjectionMatrix.js +60 -0
- package/{engine/graphics/micron/util → core/geom/3d}/unit_hemioct.spec.js +1 -1
- package/{engine/graphics/micron/build → core}/graph/MultiNode.js +0 -0
- package/{engine/graphics/micron/build → core}/graph/SquareMatrix.js +2 -2
- package/{engine/graphics/micron/build → core}/graph/SquareMatrix.spec.js +1 -1
- package/{engine/graphics/micron/build → core}/graph/WeightedEdge.js +1 -1
- package/{engine/graphics/micron/build → core}/graph/build_face_graph_from_mesh.js +2 -2
- package/{engine/graphics/micron/build/clustering → core/graph}/cluster_mesh_metis.js +2 -6
- package/{engine/graphics/micron/build → core}/graph/coarsen_graph.js +1 -1
- package/{engine/graphics/micron/build → core}/graph/coarsen_graph.spec.js +1 -1
- package/{engine/graphics/micron/build → core}/graph/eigen/eigen.js +0 -0
- package/{engine/graphics/micron/build → core}/graph/eigen/eigen.spec.js +1 -1
- package/{engine/graphics/micron/build/hierarchy → core/graph/eigen}/eigen_values_find_spectral_gap.js +0 -0
- package/{engine/graphics/micron/build → core}/graph/graph_adjacency_matrix.js +0 -0
- package/{engine/graphics/micron/build → core}/graph/graph_compute_disconnected_clusters.js +0 -0
- package/{engine/graphics/micron/build → core}/graph/graph_degree_matrix.js +0 -0
- package/{engine/graphics/micron/build → core}/graph/graph_k_means_cluster.js +5 -5
- package/{engine/graphics/micron/build → core}/graph/graph_laplacian_matrix.js +1 -1
- package/{engine/graphics/micron/build → core}/graph/metis/metis.js +2 -2
- package/{engine/graphics/micron/build → core}/graph/metis/metis_options.js +0 -0
- package/{engine/graphics/micron/build → core}/graph/mn_graph_collapse_weighted_edge.js +0 -0
- package/core/process/undo/ActionProcessor.d.ts +2 -0
- package/core/process/undo/ActionProcessor.js +59 -1
- package/core/process/undo/ActionProcessor.spec.js +59 -0
- package/core/process/undo/Mark.js +2 -1
- package/engine/Engine.d.ts +2 -0
- package/engine/EngineHarness.js +4 -4
- package/engine/asset/loaders/material/bitmap2sampler_gl.js +19 -0
- package/engine/asset/loaders/material/computeImageBitmapEquality.js +7 -19
- package/engine/ecs/transform/Transform.js +2 -1
- package/engine/graphics/GraphicsEngine.js +9 -116
- package/engine/graphics/ecs/mesh/updateNodeByTransformAndBBB.js +22 -37
- package/engine/graphics/ecs/mesh-v2/ShadedGeometry.js +155 -0
- package/engine/graphics/ecs/mesh-v2/ShadedGeometrySystem.js +68 -0
- package/engine/graphics/ecs/mesh-v2/prototypeShadedGeometry.js +31 -0
- package/engine/graphics/filter/FlipArrayInPlace.js +25 -0
- package/engine/graphics/filter/FlipArrayViaCanvas.js +13 -0
- package/engine/graphics/filter/ImageFilter.js +20 -51
- package/engine/graphics/{micron → geometry}/aabb3_to_buffer_geometry.js +0 -0
- package/engine/graphics/{micron/build → geometry/buffered}/compute_buffer_geometry_byte_size.js +0 -0
- package/engine/graphics/geometry/instancing/InstancedMeshGroup.js +25 -16
- package/engine/graphics/material/SplatMaterial.js +4 -97
- package/engine/graphics/micron/build/buildMicronGeometryFromBufferGeometry.js +2 -6
- package/engine/graphics/micron/build/clustering/build_clustering_2.js +2 -2
- package/engine/graphics/micron/build/clustering/build_leaf_patches_metis.js +1 -1
- package/engine/graphics/micron/build/fill_patch_geometry_data.js +2 -0
- package/engine/graphics/micron/build/hierarchy/buildAbstractPatchHierarchy.js +3 -3
- package/engine/graphics/micron/build/hierarchy/build_intermediate_patch_topology.js +0 -72
- package/engine/graphics/micron/build/hierarchy/build_merge_graph.js +2 -2
- package/engine/graphics/micron/build/hierarchy/computePatchMergeScore.js +3 -3
- package/engine/graphics/micron/build/hierarchy/merge_patches.js +6 -3
- package/engine/graphics/micron/build/hierarchy/metis_cluster_clusters.js +1 -1
- package/engine/graphics/micron/build/hierarchy/optimize_graph_partitioning_balance.js +1 -1
- package/engine/graphics/micron/build/hierarchy/patch_combine.js +2 -2
- package/engine/graphics/micron/build/hierarchy/qvdr_build_simplified_clusters.js +2 -1
- package/engine/graphics/micron/format/MicronGeometryBufferAttributeSpec.js +1 -1
- package/engine/graphics/micron/format/MicronGeometryPatch.js +11 -3
- package/engine/graphics/micron/format/MicronVertexDataSpec.js +25 -3
- package/engine/graphics/micron/prototypeVirtualGeometry.js +4 -4
- package/engine/graphics/micron/render/VirtualGeometryBuilder.js +28 -26
- package/engine/graphics/micron/render/culling/{PathCullingSystem.js → PatchCullingSystem.js} +1 -1
- package/engine/graphics/micron/render/instanced/AttributeDataTexture.js +2 -4
- package/engine/graphics/micron/render/refinement/ActivePatchList.js +40 -80
- package/engine/graphics/micron/render/refinement/ActivePatchRecord.js +4 -2
- package/engine/graphics/micron/render/refinement/RefinementSpec.js +98 -0
- package/engine/graphics/micron/render/v1/MaterialVertexSpec.js +21 -0
- package/engine/graphics/micron/render/v1/VGThreeRenderer.js +12 -9
- package/engine/graphics/micron/render/v1/getTransformedPositionsCached.js +1 -1
- package/engine/graphics/render/buffer/buffers/ColorAndDepthFrameBuffer.js +5 -3
- package/engine/graphics/render/buffer/buffers/prototypeNormalFrameBuffer.js +8 -10
- package/engine/graphics/render/forward_plus/LightManager.js +5 -7
- package/engine/graphics/render/forward_plus/data/NumericType.js +9 -0
- package/engine/graphics/render/forward_plus/{TextureBackedMemoryRegion.js → data/TextureBackedMemoryRegion.js} +11 -190
- package/engine/graphics/render/forward_plus/data/channelCountToThreIntegerTextureType.js +16 -0
- package/engine/graphics/render/forward_plus/data/computeDataType.js +36 -0
- package/engine/graphics/render/forward_plus/data/computeThreeTextureFormat.js +18 -0
- package/engine/graphics/render/forward_plus/data/computeThreeTextureInternalFormatFromDataType.js +63 -0
- package/engine/graphics/render/forward_plus/data/computeThreeTextureTypeFromDataType.js +41 -0
- package/engine/graphics/render/forward_plus/plugin/ptototypeFPPlugin.js +1 -1
- package/engine/graphics/render/forward_plus/prototypeLightManager.js +1 -1
- package/engine/graphics/render/visibility/hiz/buffer/HierarchicalZBuffer.js +198 -0
- package/engine/graphics/render/visibility/hiz/buffer/ReductionShader.js +51 -0
- package/engine/graphics/render/visibility/hiz/buildCanvasViewFromTexture.js +179 -0
- package/engine/graphics/render/visibility/hiz/prototypeHiZ.js +435 -0
- package/engine/graphics/render/visibility/hiz/query/BatchOcclusionQuery.js +174 -0
- package/engine/graphics/render/visibility/hiz/query/QueryShader.js +173 -0
- package/engine/graphics/shadows/ShadowMapRenderer.js +12 -2
- package/engine/graphics/texture/cubemap/buildCubeURLs.js +13 -0
- package/engine/graphics/texture/cubemap/load_environment_map.d.ts +8 -0
- package/engine/graphics/texture/cubemap/load_environment_map.js +163 -0
- package/engine/graphics/texture/sampler/Sampler2D.js +18 -62
- package/engine/graphics/texture/sampler/convertTexture2Sampler2D.js +3 -2
- package/engine/graphics/texture/sampler/debug/paintSamplerOnHTML.js +3 -2
- package/engine/graphics/texture/sampler/differenceSampler.js +31 -0
- package/engine/graphics/texture/sampler/typedArrayConstructorByInstance.js +25 -0
- package/engine/graphics/texture/sampler/util/drawSamplerHTML.js +3 -2
- package/engine/graphics/texture/virtual/v2/ShaderUsage.js +6 -5
- package/engine/graphics/texture/virtual/v2/prototype.js +16 -6
- package/engine/plugin/EnginePluginManager.d.ts +9 -0
- package/engine/reference/v2/Reference.d.ts +7 -0
- package/package.json +1 -1
- package/view/minimap/gl/MinimapMarkersGL.js +2 -2
- package/engine/graphics/micron/build/clustering/cluster_mesh_vertices.js +0 -3
- package/engine/graphics/micron/render/RefinementSpec.js +0 -159
|
@@ -0,0 +1,179 @@
|
|
|
1
|
+
import { CanvasView } from "../../../../../view/elements/CanvasView.js";
|
|
2
|
+
import {
|
|
3
|
+
DoubleSide,
|
|
4
|
+
LinearFilter,
|
|
5
|
+
Mesh as ThreeMesh,
|
|
6
|
+
OrthographicCamera,
|
|
7
|
+
Scene,
|
|
8
|
+
ShaderMaterial,
|
|
9
|
+
UnsignedByteType,
|
|
10
|
+
WebGLRenderTarget
|
|
11
|
+
} from "three";
|
|
12
|
+
import CheckersTexture from "../../../texture/CheckersTexture.js";
|
|
13
|
+
import { FULL_SCREEN_TRIANGLE_GEOMETRY } from "../../../geometry/FULL_SCREEN_TRIANGLE_GEOMETRY.js";
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
*
|
|
18
|
+
* @param {THREE.Texture} texture
|
|
19
|
+
* @returns {string}
|
|
20
|
+
*/
|
|
21
|
+
function defineSamplerType(texture) {
|
|
22
|
+
switch (texture.format) {
|
|
23
|
+
case UnsignedByteType:
|
|
24
|
+
return 'usampler2D';
|
|
25
|
+
default:
|
|
26
|
+
return 'sampler2D'
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
*
|
|
32
|
+
* @param {THREE.Texture} texture
|
|
33
|
+
* @param {string} name
|
|
34
|
+
* @param {string} uv
|
|
35
|
+
* @returns {string}
|
|
36
|
+
*/
|
|
37
|
+
function sampleTexel(texture, name, uv) {
|
|
38
|
+
switch (texture.format) {
|
|
39
|
+
default:
|
|
40
|
+
return `texture2D(${name}, ${uv})`;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
*
|
|
46
|
+
* @param {THREE.Texture} texture
|
|
47
|
+
*/
|
|
48
|
+
function makeShader(texture) {
|
|
49
|
+
return new ShaderMaterial({
|
|
50
|
+
|
|
51
|
+
vertexShader: /* glsl */`
|
|
52
|
+
|
|
53
|
+
varying vec2 vUv;
|
|
54
|
+
|
|
55
|
+
void main() {
|
|
56
|
+
|
|
57
|
+
vUv = uv;
|
|
58
|
+
gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );
|
|
59
|
+
|
|
60
|
+
}`,
|
|
61
|
+
|
|
62
|
+
fragmentShader: /* glsl */`
|
|
63
|
+
|
|
64
|
+
uniform ${defineSamplerType(texture)} tDiffuse;
|
|
65
|
+
|
|
66
|
+
varying vec2 vUv;
|
|
67
|
+
|
|
68
|
+
void main() {
|
|
69
|
+
|
|
70
|
+
vec4 texel = ${sampleTexel(texture, 'tDiffuse', 'vUv')};
|
|
71
|
+
gl_FragColor = texel;
|
|
72
|
+
|
|
73
|
+
gl_FragColor.a = 1.0;
|
|
74
|
+
// gl_FragColor.r *= 255.0;
|
|
75
|
+
|
|
76
|
+
}`,
|
|
77
|
+
uniforms: {
|
|
78
|
+
|
|
79
|
+
'tDiffuse': { value: null }
|
|
80
|
+
|
|
81
|
+
}
|
|
82
|
+
});
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
/**
|
|
86
|
+
*
|
|
87
|
+
* @param {number} height
|
|
88
|
+
* @param {number} width
|
|
89
|
+
* @param {THREE.Texture} texture
|
|
90
|
+
* @param {THREE.WebGLRenderer} renderer
|
|
91
|
+
* @param flipY
|
|
92
|
+
* @return {{view: View, render: render}}
|
|
93
|
+
*/
|
|
94
|
+
export function buildCanvasViewFromTexture({
|
|
95
|
+
height,
|
|
96
|
+
width,
|
|
97
|
+
texture = CheckersTexture.create(),
|
|
98
|
+
renderer,
|
|
99
|
+
flipY = true
|
|
100
|
+
}) {
|
|
101
|
+
const canvasView = new CanvasView();
|
|
102
|
+
canvasView.size.set(width, height);
|
|
103
|
+
|
|
104
|
+
const ctx = canvasView.context2d;
|
|
105
|
+
|
|
106
|
+
let copyShader = null;
|
|
107
|
+
|
|
108
|
+
const camera = new OrthographicCamera(-1, 1, 1, -1, 0, 1);
|
|
109
|
+
const scene = new Scene();
|
|
110
|
+
scene.add(camera);
|
|
111
|
+
|
|
112
|
+
const quad = new ThreeMesh(FULL_SCREEN_TRIANGLE_GEOMETRY, null);
|
|
113
|
+
|
|
114
|
+
if (flipY) {
|
|
115
|
+
quad.scale.y = -1;
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
scene.add(quad);
|
|
119
|
+
|
|
120
|
+
const gl = renderer.getContext();
|
|
121
|
+
|
|
122
|
+
const renderTargetOptions = {
|
|
123
|
+
generateMipmaps: false,
|
|
124
|
+
minFilter: LinearFilter,
|
|
125
|
+
stencilBuffer: false,
|
|
126
|
+
depthBuffer: false
|
|
127
|
+
};
|
|
128
|
+
const renderTarget = new WebGLRenderTarget(width, height, renderTargetOptions);
|
|
129
|
+
|
|
130
|
+
const imageData = ctx.createImageData(width, height);
|
|
131
|
+
|
|
132
|
+
let __texture_cached = texture;
|
|
133
|
+
|
|
134
|
+
/**
|
|
135
|
+
*
|
|
136
|
+
* @return {ShaderMaterial}
|
|
137
|
+
*/
|
|
138
|
+
function getShader() {
|
|
139
|
+
if (__texture_cached !== texture || copyShader === null) {
|
|
140
|
+
copyShader = makeShader(texture);
|
|
141
|
+
|
|
142
|
+
copyShader.side = DoubleSide;
|
|
143
|
+
copyShader.uniforms.tDiffuse.value = texture;
|
|
144
|
+
|
|
145
|
+
quad.material = copyShader;
|
|
146
|
+
|
|
147
|
+
__texture_cached = texture;
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
return copyShader;
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
const render = () => {
|
|
154
|
+
|
|
155
|
+
getShader().uniforms.tDiffuse.value = texture;
|
|
156
|
+
|
|
157
|
+
renderer.setRenderTarget(renderTarget);
|
|
158
|
+
|
|
159
|
+
renderer.render(scene, camera);
|
|
160
|
+
|
|
161
|
+
gl.readPixels(0, 0, width, height, gl.RGBA, gl.UNSIGNED_BYTE, imageData.data);
|
|
162
|
+
|
|
163
|
+
|
|
164
|
+
ctx.putImageData(imageData, 0, 0)
|
|
165
|
+
|
|
166
|
+
renderer.setRenderTarget(null);
|
|
167
|
+
};
|
|
168
|
+
|
|
169
|
+
return {
|
|
170
|
+
view: canvasView,
|
|
171
|
+
render,
|
|
172
|
+
set texture(v) {
|
|
173
|
+
|
|
174
|
+
texture = v;
|
|
175
|
+
|
|
176
|
+
getShader().uniforms.tDiffuse.value = v;
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
}
|
|
@@ -0,0 +1,435 @@
|
|
|
1
|
+
import { EngineHarness } from "../../../../EngineHarness.js";
|
|
2
|
+
import { EngineConfiguration } from "../../../../EngineConfiguration.js";
|
|
3
|
+
import GUIElementSystem from "../../../../ecs/gui/GUIElementSystem.js";
|
|
4
|
+
import HeadsUpDisplaySystem from "../../../../ecs/gui/hud/HeadsUpDisplaySystem.js";
|
|
5
|
+
import ScriptSystem from "../../../../ecs/systems/ScriptSystem.js";
|
|
6
|
+
import FacingDirectionSystem from "../../../../../../model/game/ecs/system/FacingDirectionSystem.js";
|
|
7
|
+
import PathFollowingSystem from "../../../../navigation/ecs/path_following/PathFollowingSystem.js";
|
|
8
|
+
import SteeringSystem from "../../../../ecs/systems/SteeringSystem.js";
|
|
9
|
+
import MotionSystem from "../../../../ecs/systems/MotionSystem.js";
|
|
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
|
+
import { SoundEmitterSystem } from "../../../../sound/ecs/emitter/SoundEmitterSystem.js";
|
|
14
|
+
import SoundControllerSystem from "../../../../sound/ecs/SoundControllerSystem.js";
|
|
15
|
+
import SoundListenerSystem from "../../../../sound/ecs/SoundListenerSystem.js";
|
|
16
|
+
import TimerSystem from "../../../../ecs/systems/TimerSystem.js";
|
|
17
|
+
import AnimationSystem from "../../../../ecs/systems/AnimationSystem.js";
|
|
18
|
+
import TopDownCameraControllerSystem from "../../../ecs/camera/topdown/TopDownCameraControllerSystem.js";
|
|
19
|
+
import { TopDownCameraLanderSystem } from "../../../ecs/camera/topdown/TopDownCameraLanderSystem.js";
|
|
20
|
+
import { CameraSystem } from "../../../ecs/camera/CameraSystem.js";
|
|
21
|
+
import { MeshSystem } from "../../../ecs/mesh/MeshSystem.js";
|
|
22
|
+
import ClingToTerrainSystem from "../../../../ecs/terrain/ecs/ClingToTerrainSystem.js";
|
|
23
|
+
import TerrainSystem from "../../../../ecs/terrain/ecs/TerrainSystem.js";
|
|
24
|
+
import WaterSystem from "../../../ecs/water/WaterSystem.js";
|
|
25
|
+
import Trail2DSystem from "../../../ecs/trail2d/Trail2DSystem.js";
|
|
26
|
+
import { Foliage2System } from "../../../../ecs/foliage/ecs/Foliage2System.js";
|
|
27
|
+
import ViewportPositionSystem from "../../../../ecs/gui/position/ViewportPositionSystem.js";
|
|
28
|
+
import { GridPosition2TransformSystem } from "../../../../grid/systems/GridPosition2TransformSystem.js";
|
|
29
|
+
import { Transform2GridPositionSystem } from "../../../../grid/transform2grid/Transform2GridPositionSystem.js";
|
|
30
|
+
import SynchronizePositionSystem from "../../../../ecs/systems/SynchronizePositionSystem.js";
|
|
31
|
+
import GridObstacleSystem from "../../../../grid/systems/GridObstacleSystem.js";
|
|
32
|
+
import GridPositionSystem from "../../../../grid/systems/GridPositionSystem.js";
|
|
33
|
+
import InputControllerSystem from "../../../../input/ecs/systems/InputControllerSystem.js";
|
|
34
|
+
import { InputSystem } from "../../../../input/ecs/systems/InputSystem.js";
|
|
35
|
+
import MeshHighlightSystem from "../../../ecs/highlight/system/MeshHighlightSystem.js";
|
|
36
|
+
import LightSystem from "../../../ecs/light/LightSystem.js";
|
|
37
|
+
import AnimationControllerSystem from "../../../ecs/animation/AnimationControllerSystem.js";
|
|
38
|
+
import { AnimationGraphSystem } from "../../../ecs/animation/animator/AnimationGraphSystem.js";
|
|
39
|
+
import { FogOfWarSystem } from "../../../../ecs/fow/FogOfWarSystem.js";
|
|
40
|
+
import { FogOfWarRevealerSystem } from "../../../../ecs/fow/FogOfWarRevealerSystem.js";
|
|
41
|
+
import { BehaviorSystem } from "../../../../intelligence/behavior/ecs/BehaviorSystem.js";
|
|
42
|
+
import { SerializationMetadataSystem } from "../../../../ecs/systems/SerializationMetadataSystem.js";
|
|
43
|
+
import { InverseKinematicsSystem } from "../../../../ecs/animation/InverseKinematicsSystem.js";
|
|
44
|
+
import Vector3 from "../../../../../core/geom/Vector3.js";
|
|
45
|
+
import Vector2 from "../../../../../core/geom/Vector2.js";
|
|
46
|
+
import RenderSystem from "../../../../ecs/systems/RenderSystem.js";
|
|
47
|
+
import { makeEngineOptionsModel } from "../../../../../../model/game/options/makeEngineOptionsModel.js";
|
|
48
|
+
import { enableEditor } from "../../../../../editor/enableEditor.js";
|
|
49
|
+
import EntityBuilder from "../../../../ecs/EntityBuilder.js";
|
|
50
|
+
import { Transform } from "../../../../ecs/transform/Transform.js";
|
|
51
|
+
import Mesh from "../../../ecs/mesh/Mesh.js";
|
|
52
|
+
import { PathDisplaySystem } from "../../../ecs/path/PathDisplaySystem.js";
|
|
53
|
+
import { MicronRenderPlugin } from "../../../micron/plugin/MicronRenderPlugin.js";
|
|
54
|
+
import { StandardFrameBuffers } from "../../../StandardFrameBuffers.js";
|
|
55
|
+
import { HierarchicalZBuffer } from "./buffer/HierarchicalZBuffer.js";
|
|
56
|
+
import ViewportPosition from "../../../../ecs/gui/position/ViewportPosition.js";
|
|
57
|
+
import GUIElement from "../../../../ecs/gui/GUIElement.js";
|
|
58
|
+
import { MetricCollection } from "../../../../development/performance/MetricCollection.js";
|
|
59
|
+
import { MetricStatistics } from "../../../../development/performance/MetricStatistics.js";
|
|
60
|
+
import { prettyPrint } from "../../../../../core/NumberFormat.js";
|
|
61
|
+
import { buildCanvasViewFromTexture } from "./buildCanvasViewFromTexture.js";
|
|
62
|
+
import { BatchOcclusionQuery } from "./query/BatchOcclusionQuery.js";
|
|
63
|
+
import HeadsUpDisplay from "../../../../ecs/gui/hud/HeadsUpDisplay.js";
|
|
64
|
+
import LabelView from "../../../../../view/common/LabelView.js";
|
|
65
|
+
import { randomFloatBetween } from "../../../../../core/math/MathUtils.js";
|
|
66
|
+
import { seededRandom } from "../../../../../core/math/random/seededRandom.js";
|
|
67
|
+
import { Sampler2D } from "../../../texture/sampler/Sampler2D.js";
|
|
68
|
+
import { RefinementSpec } from "../../../micron/render/refinement/RefinementSpec.js";
|
|
69
|
+
import { Matrix4 } from "three";
|
|
70
|
+
import { inverseLerp } from "../../../../../core/math/inverseLerp.js";
|
|
71
|
+
import { clamp } from "../../../../../core/math/clamp.js";
|
|
72
|
+
import { max2 } from "../../../../../core/math/max2.js";
|
|
73
|
+
import { min2 } from "../../../../../core/math/min2.js";
|
|
74
|
+
import { buildCubeURLs } from "../../../texture/cubemap/buildCubeURLs.js";
|
|
75
|
+
|
|
76
|
+
const engineHarness = new EngineHarness();
|
|
77
|
+
|
|
78
|
+
function makeConfig(engine) {
|
|
79
|
+
|
|
80
|
+
const config = new EngineConfiguration();
|
|
81
|
+
|
|
82
|
+
/**
|
|
83
|
+
*
|
|
84
|
+
* @type {SoundEngine}
|
|
85
|
+
*/
|
|
86
|
+
const sound = engine.sound;
|
|
87
|
+
const graphics = engine.graphics;
|
|
88
|
+
const assetManager = engine.assetManager;
|
|
89
|
+
const devices = engine.devices;
|
|
90
|
+
|
|
91
|
+
const guiSystem = new GUIElementSystem(engine.gui.view, engine);
|
|
92
|
+
const headsUpDisplaySystem = new HeadsUpDisplaySystem(graphics);
|
|
93
|
+
|
|
94
|
+
config.systems.push(
|
|
95
|
+
new ScriptSystem(),
|
|
96
|
+
new FacingDirectionSystem(),
|
|
97
|
+
new PathFollowingSystem(),
|
|
98
|
+
new SteeringSystem(),
|
|
99
|
+
new MotionSystem(),
|
|
100
|
+
new TagSystem(),
|
|
101
|
+
new AttachmentSocketsSystem(),
|
|
102
|
+
new AttachmentSystem(),
|
|
103
|
+
new SoundEmitterSystem(assetManager, sound.destination, sound.context),
|
|
104
|
+
new SoundControllerSystem(),
|
|
105
|
+
new SoundListenerSystem(sound.context),
|
|
106
|
+
new TimerSystem(),
|
|
107
|
+
guiSystem,
|
|
108
|
+
new AnimationSystem(graphics.viewport.size),
|
|
109
|
+
new TopDownCameraControllerSystem(graphics),
|
|
110
|
+
new TopDownCameraLanderSystem(),
|
|
111
|
+
new CameraSystem(graphics.scene, graphics),
|
|
112
|
+
new MeshSystem(engine),
|
|
113
|
+
new ClingToTerrainSystem(),
|
|
114
|
+
new TerrainSystem(graphics, assetManager),
|
|
115
|
+
new WaterSystem(graphics),
|
|
116
|
+
new Trail2DSystem(graphics, assetManager),
|
|
117
|
+
new Foliage2System(assetManager, graphics),
|
|
118
|
+
new ViewportPositionSystem(graphics.viewport.size),
|
|
119
|
+
new GridPosition2TransformSystem(),
|
|
120
|
+
new Transform2GridPositionSystem(),
|
|
121
|
+
new SynchronizePositionSystem(),
|
|
122
|
+
new GridObstacleSystem(),
|
|
123
|
+
new GridPositionSystem(),
|
|
124
|
+
new InputControllerSystem(devices),
|
|
125
|
+
new InputSystem(devices),
|
|
126
|
+
new MeshHighlightSystem(engine),
|
|
127
|
+
new LightSystem(engine, {
|
|
128
|
+
shadowResolution: 1024
|
|
129
|
+
}),
|
|
130
|
+
new AnimationControllerSystem(),
|
|
131
|
+
new AnimationGraphSystem(graphics.viewport.size),
|
|
132
|
+
headsUpDisplaySystem,
|
|
133
|
+
new FogOfWarSystem(graphics),
|
|
134
|
+
new FogOfWarRevealerSystem(0),
|
|
135
|
+
new BehaviorSystem(engine),
|
|
136
|
+
new SerializationMetadataSystem(),
|
|
137
|
+
new InverseKinematicsSystem(),
|
|
138
|
+
new PathDisplaySystem(engine),
|
|
139
|
+
);
|
|
140
|
+
|
|
141
|
+
|
|
142
|
+
// Plugins
|
|
143
|
+
config.addPlugin(MicronRenderPlugin);
|
|
144
|
+
|
|
145
|
+
|
|
146
|
+
// Knowledge
|
|
147
|
+
|
|
148
|
+
return config;
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
|
|
152
|
+
/**
|
|
153
|
+
*
|
|
154
|
+
* @param {EngineHarness} harness
|
|
155
|
+
* @return {Promise<void>}
|
|
156
|
+
*/
|
|
157
|
+
async function init(harness) {
|
|
158
|
+
const engine = harness.engine;
|
|
159
|
+
|
|
160
|
+
engine.entityManager.addSystem(new RenderSystem(engine.graphics));
|
|
161
|
+
|
|
162
|
+
makeEngineOptionsModel(engine.options, engine);
|
|
163
|
+
|
|
164
|
+
await makeConfig(engine).apply(engine);
|
|
165
|
+
|
|
166
|
+
enableEditor(engine);
|
|
167
|
+
|
|
168
|
+
await engine.graphics.loadEnvironmentMap(buildCubeURLs('data/textures/cubemaps/hip_miramar/32/', '.png'));
|
|
169
|
+
|
|
170
|
+
await harness.initialize();
|
|
171
|
+
|
|
172
|
+
main(engine);
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
const metrics = new MetricCollection();
|
|
176
|
+
|
|
177
|
+
metrics.create({
|
|
178
|
+
name: 'hiz_build', buffer_size: 1000
|
|
179
|
+
});
|
|
180
|
+
metrics.create({
|
|
181
|
+
name: 'hiz_query', buffer_size: 1000
|
|
182
|
+
});
|
|
183
|
+
|
|
184
|
+
function print_perf_stats() {
|
|
185
|
+
|
|
186
|
+
const values = [];
|
|
187
|
+
|
|
188
|
+
const stats = new MetricStatistics();
|
|
189
|
+
metrics.list().forEach(m => {
|
|
190
|
+
const metric = metrics.get(m);
|
|
191
|
+
|
|
192
|
+
metric.computeStats(stats);
|
|
193
|
+
|
|
194
|
+
values.push(`${m}: ${prettyPrint(stats.mean)}`);
|
|
195
|
+
});
|
|
196
|
+
|
|
197
|
+
console.log(values.join(", "));
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
/**
|
|
201
|
+
*
|
|
202
|
+
* @param {HierarchicalZBuffer} hiz
|
|
203
|
+
* @param {GraphicsEngine} graphics
|
|
204
|
+
* @param {EntityComponentDataset} ecd
|
|
205
|
+
*/
|
|
206
|
+
function prepare_query_test(hiz, graphics, ecd) {
|
|
207
|
+
|
|
208
|
+
const query = new BatchOcclusionQuery();
|
|
209
|
+
query.setSize(64);
|
|
210
|
+
|
|
211
|
+
|
|
212
|
+
const random = seededRandom(42);
|
|
213
|
+
|
|
214
|
+
const row_count = 8;
|
|
215
|
+
|
|
216
|
+
const entities = [];
|
|
217
|
+
const labels = [];
|
|
218
|
+
|
|
219
|
+
|
|
220
|
+
function prepare_query() {
|
|
221
|
+
|
|
222
|
+
const spec = new RefinementSpec();
|
|
223
|
+
spec.build(new Matrix4(), graphics.camera.matrixWorldInverse, graphics.camera.projectionMatrix);
|
|
224
|
+
|
|
225
|
+
for (let i = 0; i < query.getSize(); i++) {
|
|
226
|
+
const entity = entities[i];
|
|
227
|
+
|
|
228
|
+
if (entity === undefined) {
|
|
229
|
+
continue;
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
/**
|
|
233
|
+
* @type {Mesh}
|
|
234
|
+
*/
|
|
235
|
+
const mesh = entity.getComponent(Mesh);
|
|
236
|
+
const aabb = new Float32Array(6);
|
|
237
|
+
|
|
238
|
+
mesh.bvh.writeToArray(aabb, 0);
|
|
239
|
+
|
|
240
|
+
query.setElement(i, aabb, spec.projection_matrix);
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
const ENTITY_COUNT = min2(query.getSize(), 100);
|
|
246
|
+
for (let i = 0; i < ENTITY_COUNT; i++) {
|
|
247
|
+
|
|
248
|
+
const ix = i % row_count;
|
|
249
|
+
const iy = Math.floor(i / row_count);
|
|
250
|
+
|
|
251
|
+
const v = new LabelView('a', { classList: ['__debug-plaque'] });
|
|
252
|
+
v.css({
|
|
253
|
+
position: 'absolute',
|
|
254
|
+
whiteSpace: 'pre',
|
|
255
|
+
left: 0,
|
|
256
|
+
top: 0
|
|
257
|
+
});
|
|
258
|
+
|
|
259
|
+
labels[i] = v;
|
|
260
|
+
|
|
261
|
+
const entityBuilder = new EntityBuilder();
|
|
262
|
+
|
|
263
|
+
entities[i] = entityBuilder;
|
|
264
|
+
|
|
265
|
+
const scale = randomFloatBetween(random, 0.1, 1);
|
|
266
|
+
|
|
267
|
+
entityBuilder
|
|
268
|
+
.add(Mesh.fromJSON({
|
|
269
|
+
url: 'data/models/snaps/cube_blue.gltf'
|
|
270
|
+
}))
|
|
271
|
+
.add(Transform.fromJSON({
|
|
272
|
+
position: new Vector3(102 + ix * 5, randomFloatBetween(random, -4, 3), 60 + iy * 5),
|
|
273
|
+
scale: scale
|
|
274
|
+
}))
|
|
275
|
+
.add(new HeadsUpDisplay())
|
|
276
|
+
.add(new ViewportPosition())
|
|
277
|
+
.add(GUIElement.fromView(v))
|
|
278
|
+
.build(ecd);
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
const rt = query.getResultTexture();
|
|
282
|
+
const result_sampler = Sampler2D.uint8(4, rt.image.width, rt.image.height);
|
|
283
|
+
|
|
284
|
+
function process_query_results() {
|
|
285
|
+
|
|
286
|
+
query.readResultTexture(renderer, result_sampler.data);
|
|
287
|
+
|
|
288
|
+
|
|
289
|
+
for (let i = 0; i < ENTITY_COUNT; i++) {
|
|
290
|
+
const value = result_sampler.readChannel(i, 0, 0);
|
|
291
|
+
|
|
292
|
+
labels[i].updateText(value);
|
|
293
|
+
}
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
const renderer = graphics.getRenderer();
|
|
297
|
+
|
|
298
|
+
function compute_rt_scale(v) {
|
|
299
|
+
return Math.ceil(max2(1, clamp(inverseLerp(256, 32, v), 0, 1) * 8));
|
|
300
|
+
}
|
|
301
|
+
|
|
302
|
+
const preview_query = buildCanvasViewFromTexture({
|
|
303
|
+
width: rt.image.width * compute_rt_scale(rt.image.width),
|
|
304
|
+
height: rt.image.height * compute_rt_scale(rt.image.height),
|
|
305
|
+
renderer: renderer,
|
|
306
|
+
texture: null,
|
|
307
|
+
flipY: false
|
|
308
|
+
});
|
|
309
|
+
|
|
310
|
+
graphics.on.postRender.add(() => {
|
|
311
|
+
prepare_query();
|
|
312
|
+
|
|
313
|
+
const t0 = performance.now();
|
|
314
|
+
query.execute(renderer, hiz);
|
|
315
|
+
const t1 = performance.now();
|
|
316
|
+
|
|
317
|
+
metrics.get('hiz_query').record(t1 - t0);
|
|
318
|
+
|
|
319
|
+
preview_query.texture = query.getResultTexture();
|
|
320
|
+
preview_query.render();
|
|
321
|
+
|
|
322
|
+
process_query_results();
|
|
323
|
+
});
|
|
324
|
+
|
|
325
|
+
|
|
326
|
+
new EntityBuilder()
|
|
327
|
+
.add(ViewportPosition.fromJSON({
|
|
328
|
+
offset: new Vector2(10, 276)
|
|
329
|
+
}))
|
|
330
|
+
.add(GUIElement.fromView(preview_query.view))
|
|
331
|
+
.build(ecd);
|
|
332
|
+
}
|
|
333
|
+
|
|
334
|
+
setInterval(print_perf_stats, 2000);
|
|
335
|
+
|
|
336
|
+
/**
|
|
337
|
+
*
|
|
338
|
+
* @param {Engine} engine
|
|
339
|
+
*/
|
|
340
|
+
function main(engine) {
|
|
341
|
+
EngineHarness.buildBasics({
|
|
342
|
+
engine,
|
|
343
|
+
enableWater: false,
|
|
344
|
+
// enableTerrain: false,
|
|
345
|
+
enableTerrain: true,
|
|
346
|
+
terrainSize: new Vector2(100, 100),
|
|
347
|
+
focus: new Vector3(102, 0, 61),
|
|
348
|
+
// pitch: -0.5,
|
|
349
|
+
// yaw: 2.2,
|
|
350
|
+
// distance: 3
|
|
351
|
+
pitch: 0.9,
|
|
352
|
+
yaw: 3.1,
|
|
353
|
+
distance: 20
|
|
354
|
+
});
|
|
355
|
+
|
|
356
|
+
|
|
357
|
+
const graphics = engine.graphics;
|
|
358
|
+
|
|
359
|
+
graphics.renderer.setClearColor('rgba(99,99,99,1)');
|
|
360
|
+
|
|
361
|
+
const ecd = engine.entityManager.dataset;
|
|
362
|
+
//
|
|
363
|
+
// for (let i = 0; i < 10; i++) {
|
|
364
|
+
// for (let j = 0; j < 10; j++) {
|
|
365
|
+
//
|
|
366
|
+
// new EntityBuilder()
|
|
367
|
+
// .add(Transform.fromJSON({
|
|
368
|
+
// position: {
|
|
369
|
+
// x: 60 + i * 10,
|
|
370
|
+
// y: 0,
|
|
371
|
+
// z: 30 + j * 10
|
|
372
|
+
// },
|
|
373
|
+
// scale: {
|
|
374
|
+
// x: 1,
|
|
375
|
+
// y: 1,
|
|
376
|
+
// z: 1
|
|
377
|
+
// }
|
|
378
|
+
// }))
|
|
379
|
+
// .add(Mesh.fromJSON({
|
|
380
|
+
// url: 'data/models/RTS_Buildings_Humans/18/Building_R_18_out/Building_R_18.gltf',
|
|
381
|
+
// castShadow: true,
|
|
382
|
+
// receiveShadow: true
|
|
383
|
+
// }))
|
|
384
|
+
// .build(ecd);
|
|
385
|
+
// }
|
|
386
|
+
// }
|
|
387
|
+
|
|
388
|
+
const hiz = new HierarchicalZBuffer();
|
|
389
|
+
const depthTexture = graphics.frameBuffers.getById(StandardFrameBuffers.ColorAndDepth).getRenderTarget().depthTexture;
|
|
390
|
+
hiz.input = depthTexture;
|
|
391
|
+
hiz.renderer = graphics.renderer;
|
|
392
|
+
|
|
393
|
+
|
|
394
|
+
const renderer = graphics.getRenderer();
|
|
395
|
+
|
|
396
|
+
const preview = buildCanvasViewFromTexture({
|
|
397
|
+
width: 512,
|
|
398
|
+
height: 256,
|
|
399
|
+
renderer: renderer,
|
|
400
|
+
texture: null
|
|
401
|
+
});
|
|
402
|
+
|
|
403
|
+
|
|
404
|
+
graphics.on.postRender.add(() => {
|
|
405
|
+
hiz.set_resolution(depthTexture.image.width, depthTexture.image.height);
|
|
406
|
+
hiz.build_mip_chain();
|
|
407
|
+
|
|
408
|
+
const t0 = performance.now();
|
|
409
|
+
hiz.build_mips();
|
|
410
|
+
const t1 = performance.now();
|
|
411
|
+
|
|
412
|
+
metrics.get('hiz_build').record(t1 - t0);
|
|
413
|
+
|
|
414
|
+
|
|
415
|
+
preview.texture = hiz.mips[0].texture;
|
|
416
|
+
|
|
417
|
+
preview.render();
|
|
418
|
+
|
|
419
|
+
});
|
|
420
|
+
|
|
421
|
+
console.log(hiz);
|
|
422
|
+
|
|
423
|
+
prepare_query_test(hiz, graphics, ecd);
|
|
424
|
+
|
|
425
|
+
new EntityBuilder()
|
|
426
|
+
.add(ViewportPosition.fromJSON({
|
|
427
|
+
offset: new Vector2(10, 10)
|
|
428
|
+
}))
|
|
429
|
+
.add(GUIElement.fromView(preview.view))
|
|
430
|
+
.build(ecd);
|
|
431
|
+
|
|
432
|
+
|
|
433
|
+
}
|
|
434
|
+
|
|
435
|
+
init(engineHarness);
|