@woosh/meep-engine 2.33.4 → 2.33.9
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/binary/BinaryBuffer.js +26 -2
- package/core/bvh2/LeafNode.js +6 -1
- package/core/bvh2/aabb3/AABB3.js +21 -1
- 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/DataType2TypedArrayConstructorMapping.js +2 -0
- package/core/collection/table/DataTypeByteSizes.js +21 -0
- package/core/collection/table/RowFirstTable.js +1 -88
- package/core/collection/table/RowFirstTable.spec.js +3 -1
- package/core/collection/table/RowFirstTableSpec.js +9 -19
- package/core/collection/table/computeDataTypeByIndex.js +21 -0
- package/core/collection/table/deserializeRowFirstTable.js +48 -0
- package/core/collection/table/serializeRowFirstTable.js +27 -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/foliage/InstancedFoliage.js +3 -5
- package/engine/ecs/fow/serialization/FogOfWarSerializationAdapter.js +2 -1
- 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/MicronGeometry.js +12 -0
- package/engine/graphics/micron/format/MicronGeometryBufferAttributeSpec.js +2 -2
- package/engine/graphics/micron/format/MicronGeometryPatch.js +17 -9
- package/engine/graphics/micron/format/MicronVertexDataSpec.js +25 -3
- package/engine/graphics/micron/format/serialization/MicronGeometryBinarySerializationAdapter.js +101 -0
- package/engine/graphics/micron/format/serialization/deserialize_attribute_spec.js +25 -0
- package/engine/graphics/micron/format/serialization/deserialize_patch.js +104 -0
- package/engine/graphics/micron/format/serialization/serialize_attribute_spec.js +18 -0
- package/engine/graphics/micron/format/serialization/serialize_patch.js +84 -0
- package/engine/graphics/micron/prototypeVirtualGeometry.js +1 -1
- package/engine/graphics/micron/render/VirtualGeometryBuilder.js +27 -23
- package/engine/graphics/micron/render/culling/{PathCullingSystem.js → PatchCullingSystem.js} +1 -1
- package/engine/graphics/micron/render/instanced/AttributeDataTexture.js +3 -5
- package/engine/graphics/micron/render/refinement/ActivePatchList.js +38 -49
- 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 +440 -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/TextureBinaryBufferSerializer.js +1 -1
- 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/network/convertPathToURL.js +6 -0
- 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 -181
|
@@ -8,13 +8,14 @@ export class Mark {
|
|
|
8
8
|
* @constructor
|
|
9
9
|
*/
|
|
10
10
|
constructor(index, description) {
|
|
11
|
-
assert.
|
|
11
|
+
assert.isNumber(index, 'index');
|
|
12
12
|
|
|
13
13
|
/**
|
|
14
14
|
*
|
|
15
15
|
* @type {number}
|
|
16
16
|
*/
|
|
17
17
|
this.index = index;
|
|
18
|
+
|
|
18
19
|
/**
|
|
19
20
|
*
|
|
20
21
|
* @type {D}
|
package/engine/Engine.d.ts
CHANGED
|
@@ -8,6 +8,7 @@ import {AssetManager} from "./asset/AssetManager";
|
|
|
8
8
|
import {EntityManager} from "./ecs/EntityManager";
|
|
9
9
|
import View from "../view/View";
|
|
10
10
|
import Ticker from "./simulation/Ticker";
|
|
11
|
+
import {EnginePluginManager} from "./plugin/EnginePluginManager";
|
|
11
12
|
|
|
12
13
|
export interface IEngineInitializationOptions {
|
|
13
14
|
entityManager?: EntityManager
|
|
@@ -25,6 +26,7 @@ export default class Engine {
|
|
|
25
26
|
public readonly devices: { keyboard: KeyboardDevice, pointer: PointerDevice }
|
|
26
27
|
public readonly assetManager: AssetManager
|
|
27
28
|
public readonly ticker: Ticker
|
|
29
|
+
public readonly plugins: EnginePluginManager
|
|
28
30
|
|
|
29
31
|
public start(): Promise<any>
|
|
30
32
|
|
package/engine/EngineHarness.js
CHANGED
|
@@ -203,10 +203,10 @@ export class EngineHarness {
|
|
|
203
203
|
*
|
|
204
204
|
* @param {Engine} engine
|
|
205
205
|
* @param {Vector3} [focus]
|
|
206
|
-
* @param heightMap
|
|
207
|
-
* @param heightRange
|
|
208
|
-
* @param pitch
|
|
209
|
-
* @param yaw
|
|
206
|
+
* @param [heightMap]
|
|
207
|
+
* @param [heightRange]
|
|
208
|
+
* @param [pitch]
|
|
209
|
+
* @param [yaw]
|
|
210
210
|
* @param {number} [distance]
|
|
211
211
|
* @param {Vector2} [terrainSize]
|
|
212
212
|
* @param {number} [terrainResolution]
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
*
|
|
3
|
+
* @param {WebGL2RenderingContext} gl
|
|
4
|
+
* @param {Sampler2D} sampler
|
|
5
|
+
* @param {ImageBitmap} bitmap
|
|
6
|
+
*/
|
|
7
|
+
export function bitmap2sampler_gl(gl, sampler, bitmap) {
|
|
8
|
+
gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, gl.RGBA, gl.UNSIGNED_BYTE, bitmap);
|
|
9
|
+
gl.drawBuffers([gl.COLOR_ATTACHMENT0]);
|
|
10
|
+
|
|
11
|
+
const w = sampler.width;
|
|
12
|
+
const h = sampler.height;
|
|
13
|
+
|
|
14
|
+
if (sampler.itemSize !== 4) {
|
|
15
|
+
throw new Error(`Expected sampler.itemSize to be 4, instead was '${sampler.itemSize}'`);
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
gl.readPixels(0, 0, w, h, gl.RGBA, gl.UNSIGNED_BYTE, sampler.data);
|
|
19
|
+
}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { Sampler2D } from "../../../graphics/texture/sampler/Sampler2D.js";
|
|
2
2
|
import { assert } from "../../../../core/assert.js";
|
|
3
3
|
import { isArrayEqualStrict } from "../../../../core/collection/array/isArrayEqualStrict.js";
|
|
4
|
+
import { bitmap2sampler_gl } from "./bitmap2sampler_gl.js";
|
|
4
5
|
|
|
5
6
|
/**
|
|
6
7
|
*
|
|
@@ -8,23 +9,6 @@ import { isArrayEqualStrict } from "../../../../core/collection/array/isArrayEqu
|
|
|
8
9
|
*/
|
|
9
10
|
const sampler_cache = new WeakMap();
|
|
10
11
|
|
|
11
|
-
/**
|
|
12
|
-
*
|
|
13
|
-
* @param {WebGL2RenderingContext} gl
|
|
14
|
-
* @param {Sampler2D} sampler
|
|
15
|
-
* @param {ImageBitmap} bitmap
|
|
16
|
-
*/
|
|
17
|
-
function bitmap2sampler_gl(gl, sampler, bitmap) {
|
|
18
|
-
gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, gl.RGBA, gl.UNSIGNED_BYTE, bitmap);
|
|
19
|
-
gl.drawBuffers([gl.COLOR_ATTACHMENT0]);
|
|
20
|
-
|
|
21
|
-
const data = new Uint8Array(sampler.width * sampler.height * 4);
|
|
22
|
-
|
|
23
|
-
gl.readPixels(0, 0, sampler.width, sampler.height, gl.RGBA, gl.UNSIGNED_BYTE, data);
|
|
24
|
-
|
|
25
|
-
sampler.data = data;
|
|
26
|
-
}
|
|
27
|
-
|
|
28
12
|
/**
|
|
29
13
|
*
|
|
30
14
|
* @param {ImageBitmap} bitmap
|
|
@@ -45,7 +29,7 @@ function obtainSampler(bitmap, ctx) {
|
|
|
45
29
|
const width = bitmap.width;
|
|
46
30
|
const height = bitmap.height;
|
|
47
31
|
|
|
48
|
-
const sampler =
|
|
32
|
+
const sampler = Sampler2D.uint8(4, width, height);
|
|
49
33
|
|
|
50
34
|
bitmap2sampler_gl(ctx, sampler, bitmap);
|
|
51
35
|
|
|
@@ -75,15 +59,19 @@ function obtainCanvasCtx(width, height) {
|
|
|
75
59
|
|
|
76
60
|
if (ctx_ref === null || (gl = ctx_ref.deref()) === undefined) {
|
|
77
61
|
const canvas = document.createElement('canvas');
|
|
62
|
+
|
|
78
63
|
gl = canvas.getContext("webgl2");
|
|
79
64
|
gl.activeTexture(gl.TEXTURE0);
|
|
65
|
+
|
|
80
66
|
const texture = gl.createTexture();
|
|
67
|
+
|
|
81
68
|
gl.bindTexture(gl.TEXTURE_2D, texture);
|
|
69
|
+
|
|
82
70
|
const framebuffer = gl.createFramebuffer();
|
|
71
|
+
|
|
83
72
|
gl.bindFramebuffer(gl.FRAMEBUFFER, framebuffer);
|
|
84
73
|
gl.framebufferTexture2D(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, gl.TEXTURE_2D, texture, 0);
|
|
85
74
|
|
|
86
|
-
|
|
87
75
|
ctx_ref = new WeakRef(gl);
|
|
88
76
|
}
|
|
89
77
|
|
|
@@ -1,9 +1,5 @@
|
|
|
1
1
|
import { BinaryNode } from "../../../core/bvh2/BinaryNode.js";
|
|
2
|
-
import {
|
|
3
|
-
deserializeRowFirstTable,
|
|
4
|
-
RowFirstTable,
|
|
5
|
-
serializeRowFirstTable
|
|
6
|
-
} from "../../../core/collection/table/RowFirstTable.js";
|
|
2
|
+
import { RowFirstTable } from "../../../core/collection/table/RowFirstTable.js";
|
|
7
3
|
import { InstancedMeshGroup } from "../../graphics/geometry/instancing/InstancedMeshGroup.js";
|
|
8
4
|
import Vector3 from "../../../core/geom/Vector3.js";
|
|
9
5
|
import { LeafNode } from "../../../core/bvh2/LeafNode.js";
|
|
@@ -19,6 +15,8 @@ import { traverseBinaryNodeUsingVisitor } from "../../../core/bvh2/traversal/tra
|
|
|
19
15
|
import { serializeBinaryNodeToBinaryBuffer } from "../../../core/bvh2/serialization/serializeBinaryNodeToBinaryBuffer.js";
|
|
20
16
|
import { deserializeBinaryNodeFromBinaryBuffer } from "../../../core/bvh2/serialization/deserializeBinaryNodeFromBinaryBuffer.js";
|
|
21
17
|
import { computeGeometryBoundingSphereMiniball } from "../../graphics/geometry/buffered/computeGeometryBoundingSphereMiniball.js";
|
|
18
|
+
import { serializeRowFirstTable } from "../../../core/collection/table/serializeRowFirstTable.js";
|
|
19
|
+
import { deserializeRowFirstTable } from "../../../core/collection/table/deserializeRowFirstTable.js";
|
|
22
20
|
|
|
23
21
|
/**
|
|
24
22
|
* @readonly
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { BinaryClassSerializationAdapter } from "../../storage/binary/BinaryClassSerializationAdapter.js";
|
|
2
|
-
import { deserializeRowFirstTable, serializeRowFirstTable } from "../../../../core/collection/table/RowFirstTable.js";
|
|
3
2
|
import { FogOfWar } from "../FogOfWar.js";
|
|
3
|
+
import { serializeRowFirstTable } from "../../../../core/collection/table/serializeRowFirstTable.js";
|
|
4
|
+
import { deserializeRowFirstTable } from "../../../../core/collection/table/deserializeRowFirstTable.js";
|
|
4
5
|
|
|
5
6
|
export class FogOfWarSerializationAdapter extends BinaryClassSerializationAdapter {
|
|
6
7
|
constructor() {
|
|
@@ -6,6 +6,7 @@ import Vector3 from "../../../core/geom/Vector3.js";
|
|
|
6
6
|
import Quaternion from "../../../core/geom/Quaternion.js";
|
|
7
7
|
import { Matrix4 } from "../../../core/geom/Matrix4.js";
|
|
8
8
|
import { Quaternion as ThreeQuaternion } from "three";
|
|
9
|
+
import { composeMatrix4 } from "../../graphics/util/composeMatrix4.js";
|
|
9
10
|
|
|
10
11
|
const delta = new Vector3();
|
|
11
12
|
|
|
@@ -175,7 +176,7 @@ export class Transform {
|
|
|
175
176
|
* @param {Matrix4} matrix
|
|
176
177
|
*/
|
|
177
178
|
toThreeMatrix(matrix) {
|
|
178
|
-
matrix
|
|
179
|
+
composeMatrix4(matrix, this.position, this.rotation, this.scale);
|
|
179
180
|
}
|
|
180
181
|
}
|
|
181
182
|
|
|
@@ -4,16 +4,11 @@
|
|
|
4
4
|
|
|
5
5
|
|
|
6
6
|
import {
|
|
7
|
-
CubeTextureLoader,
|
|
8
7
|
Group,
|
|
9
8
|
LinearEncoding,
|
|
10
9
|
NoToneMapping,
|
|
11
|
-
PMREMGenerator,
|
|
12
10
|
Raycaster as ThreeRaycaster,
|
|
13
11
|
Scene as ThreeScene,
|
|
14
|
-
sRGBEncoding,
|
|
15
|
-
TextureLoader,
|
|
16
|
-
UnsignedByteType,
|
|
17
12
|
Vector3 as ThreeVector3,
|
|
18
13
|
VSMShadowMap,
|
|
19
14
|
WebGLRenderer,
|
|
@@ -38,29 +33,13 @@ import { renderTextureToScreenQuad } from "./render/utils/renderTextureToScreenQ
|
|
|
38
33
|
import { globalMetrics } from "../metrics/GlobalMetrics.js";
|
|
39
34
|
import { MetricsCategory } from "../metrics/MetricsCategory.js";
|
|
40
35
|
import Vector1 from "../../core/geom/Vector1.js";
|
|
41
|
-
import { noop } from "../../core/function/Functions.js";
|
|
42
36
|
import { NormalFrameBuffer } from "./render/buffer/buffers/NormalFrameBuffer.js";
|
|
43
37
|
import { MaterialManager } from "./material/manager/MaterialManager.js";
|
|
44
38
|
import { CoalesceTextures } from "./material/manager/compilers/CoalesceTextures.js";
|
|
45
39
|
import { ShadowMapRenderer } from "./shadows/ShadowMapRenderer.js";
|
|
46
40
|
import { CameraViewManager } from "./render/view/CameraViewManager.js";
|
|
47
41
|
import { StandardFrameBuffers } from "./StandardFrameBuffers.js";
|
|
48
|
-
import {
|
|
49
|
-
import { EXRLoader } from "three/examples/jsm/loaders/EXRLoader.js";
|
|
50
|
-
|
|
51
|
-
/**
|
|
52
|
-
*
|
|
53
|
-
* @param {String} path
|
|
54
|
-
* @param {String} format
|
|
55
|
-
* @returns {String[]}
|
|
56
|
-
*/
|
|
57
|
-
export function buildCubeURLs(path, format) {
|
|
58
|
-
return [
|
|
59
|
-
path + "posx" + format, path + "negx" + format,
|
|
60
|
-
path + "posy" + format, path + "negy" + format,
|
|
61
|
-
path + "posz" + format, path + "negz" + format
|
|
62
|
-
];
|
|
63
|
-
}
|
|
42
|
+
import { load_environment_map } from "./texture/cubemap/load_environment_map.js";
|
|
64
43
|
|
|
65
44
|
/**
|
|
66
45
|
*
|
|
@@ -261,56 +240,6 @@ GraphicsEngine.prototype.getRenderer = function () {
|
|
|
261
240
|
return this.renderer;
|
|
262
241
|
};
|
|
263
242
|
|
|
264
|
-
/**
|
|
265
|
-
*
|
|
266
|
-
* @param {string[]|string} paths
|
|
267
|
-
* @return {Promise<THREE.CubeTexture>}
|
|
268
|
-
*/
|
|
269
|
-
function load_cube_texture(paths) {
|
|
270
|
-
// piece-wise cubemap, a collection of images for each face
|
|
271
|
-
const cubeTextureLoader = new CubeTextureLoader();
|
|
272
|
-
return new Promise((resolve, reject) => {
|
|
273
|
-
cubeTextureLoader.load(
|
|
274
|
-
paths,
|
|
275
|
-
texture => {
|
|
276
|
-
resolve(texture);
|
|
277
|
-
},
|
|
278
|
-
noop,
|
|
279
|
-
reject
|
|
280
|
-
);
|
|
281
|
-
});
|
|
282
|
-
}
|
|
283
|
-
|
|
284
|
-
/**
|
|
285
|
-
*
|
|
286
|
-
* @param {string} path
|
|
287
|
-
* @return {Promise<THREE.Texture>}
|
|
288
|
-
*/
|
|
289
|
-
function load_exr_texture(path) {
|
|
290
|
-
return new Promise((resolve, reject) => {
|
|
291
|
-
new EXRLoader()
|
|
292
|
-
.setDataType(UnsignedByteType)
|
|
293
|
-
.load(path, texture => {
|
|
294
|
-
resolve(texture);
|
|
295
|
-
}, noop, reject);
|
|
296
|
-
})
|
|
297
|
-
}
|
|
298
|
-
|
|
299
|
-
/**
|
|
300
|
-
*
|
|
301
|
-
* @param {string} path
|
|
302
|
-
* @return {Promise<THREE.Texture>}
|
|
303
|
-
*/
|
|
304
|
-
function load_standard_texture(path) {
|
|
305
|
-
return new Promise((resolve, reject) => {
|
|
306
|
-
new TextureLoader()
|
|
307
|
-
.load(path, texture => {
|
|
308
|
-
texture.encoding = sRGBEncoding;
|
|
309
|
-
resolve(texture);
|
|
310
|
-
}, noop, reject);
|
|
311
|
-
})
|
|
312
|
-
}
|
|
313
|
-
|
|
314
243
|
/**
|
|
315
244
|
*
|
|
316
245
|
* @param {string[]|string} paths URLs to faces of the cubemap
|
|
@@ -318,52 +247,16 @@ function load_standard_texture(path) {
|
|
|
318
247
|
*/
|
|
319
248
|
GraphicsEngine.prototype.loadEnvironmentMap = async function (paths) {
|
|
320
249
|
|
|
321
|
-
const
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
* @type {THREE.CubeTexture}
|
|
328
|
-
*/
|
|
329
|
-
const cube_texture = await load_cube_texture(paths);
|
|
330
|
-
|
|
331
|
-
cube_texture.encoding = sRGBEncoding;
|
|
332
|
-
|
|
333
|
-
// generate pre-filtered cubemap
|
|
334
|
-
pmremGenerator.compileCubemapShader();
|
|
335
|
-
|
|
336
|
-
cube_rt = pmremGenerator.fromCubemap(cube_texture);
|
|
337
|
-
|
|
338
|
-
// cleanup
|
|
339
|
-
cube_texture.dispose();
|
|
340
|
-
} else if (typeof paths === 'string') {
|
|
341
|
-
// single cubemap
|
|
342
|
-
const extension = computeFileExtension(paths).toLowerCase();
|
|
343
|
-
let texture;
|
|
344
|
-
if (extension === 'exr') {
|
|
345
|
-
texture = await load_exr_texture(paths);
|
|
346
|
-
} else if (extension === 'jpg') {
|
|
347
|
-
texture = await load_standard_texture(paths);
|
|
348
|
-
} else {
|
|
349
|
-
// unsupported extension
|
|
350
|
-
throw new Error(`Unsupported cube map texture extension '${extension}'`);
|
|
351
|
-
}
|
|
352
|
-
cube_rt = pmremGenerator.fromEquirectangular(texture);
|
|
353
|
-
|
|
354
|
-
texture.dispose();
|
|
355
|
-
} else {
|
|
356
|
-
throw new Error(`Unsupported parameter format: '${paths}'`);
|
|
357
|
-
}
|
|
358
|
-
|
|
359
|
-
pmremGenerator.dispose();
|
|
360
|
-
|
|
361
|
-
// assign environment
|
|
362
|
-
const t = cube_rt.texture;
|
|
363
|
-
this.scene.environment = t;
|
|
250
|
+
const { filtered } = await load_environment_map({
|
|
251
|
+
path: paths,
|
|
252
|
+
renderer: this.renderer,
|
|
253
|
+
original: false,
|
|
254
|
+
filtered: true
|
|
255
|
+
});
|
|
364
256
|
|
|
257
|
+
this.scene.environment = filtered;
|
|
365
258
|
|
|
366
|
-
return
|
|
259
|
+
return filtered;
|
|
367
260
|
}
|
|
368
261
|
|
|
369
262
|
GraphicsEngine.prototype.updateSize = function () {
|
|
@@ -1,7 +1,5 @@
|
|
|
1
|
-
import { max2 } from "../../../../core/math/max2.js";
|
|
2
|
-
import { min2 } from "../../../../core/math/min2.js";
|
|
3
|
-
import { composeMatrix4 } from "../../util/composeMatrix4.js";
|
|
4
1
|
import { Matrix4 as ThreeMatrix4 } from "three";
|
|
2
|
+
import { aabb3_matrix4_project_by_corners } from "../../../../core/geom/3d/aabb/aabb3_matrix4_project_by_corners.js";
|
|
5
3
|
|
|
6
4
|
|
|
7
5
|
const matrix4 = new ThreeMatrix4();
|
|
@@ -13,6 +11,12 @@ const matrix4 = new ThreeMatrix4();
|
|
|
13
11
|
*/
|
|
14
12
|
const corners = new Float64Array(24);
|
|
15
13
|
|
|
14
|
+
/**
|
|
15
|
+
*
|
|
16
|
+
* @type {Float32Array}
|
|
17
|
+
*/
|
|
18
|
+
const scratch_aabb = new Float32Array(6);
|
|
19
|
+
|
|
16
20
|
/**
|
|
17
21
|
*
|
|
18
22
|
* @param {LeafNode} bvh
|
|
@@ -20,20 +24,7 @@ const corners = new Float64Array(24);
|
|
|
20
24
|
* @param {Transform} transform
|
|
21
25
|
*/
|
|
22
26
|
export function updateNodeByTransformAndBBB(bvh, boundingBox, transform) {
|
|
23
|
-
|
|
24
|
-
const scale = transform.scale;
|
|
25
|
-
const rotation = transform.rotation;
|
|
26
|
-
|
|
27
|
-
composeMatrix4(matrix4, position, rotation, scale);
|
|
28
|
-
|
|
29
|
-
let x0 = Infinity,
|
|
30
|
-
y0 = Infinity,
|
|
31
|
-
z0 = Infinity,
|
|
32
|
-
x1 = -Infinity,
|
|
33
|
-
y1 = -Infinity,
|
|
34
|
-
z1 = -Infinity;
|
|
35
|
-
|
|
36
|
-
boundingBox.getCorners(corners);
|
|
27
|
+
transform.toThreeMatrix(matrix4);
|
|
37
28
|
|
|
38
29
|
/**
|
|
39
30
|
* Shortcut elements for faster access
|
|
@@ -41,29 +32,23 @@ export function updateNodeByTransformAndBBB(bvh, boundingBox, transform) {
|
|
|
41
32
|
*/
|
|
42
33
|
const e = matrix4.elements;
|
|
43
34
|
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
const y = corners[j + 1];
|
|
47
|
-
const z = corners[j + 2];
|
|
48
|
-
|
|
49
|
-
// perform matrix transform on corners
|
|
50
|
-
|
|
51
|
-
const w = 1 / (e[3] * x + e[7] * y + e[11] * z + e[15]);
|
|
35
|
+
updateNodeByMatrix4AndBBB(bvh, boundingBox, e);
|
|
36
|
+
}
|
|
52
37
|
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
38
|
+
/**
|
|
39
|
+
*
|
|
40
|
+
* @param {LeafNode} bvh
|
|
41
|
+
* @param {AABB3} boundingBox
|
|
42
|
+
* @param {number[]} matrix4
|
|
43
|
+
*/
|
|
44
|
+
export function updateNodeByMatrix4AndBBB(bvh, boundingBox, matrix4) {
|
|
45
|
+
boundingBox.getCorners(corners);
|
|
56
46
|
|
|
57
|
-
// update AABB bounds
|
|
58
47
|
|
|
59
|
-
|
|
60
|
-
y0 = min2(y0, _y);
|
|
61
|
-
z0 = min2(z0, _z);
|
|
48
|
+
aabb3_matrix4_project_by_corners(scratch_aabb, corners, matrix4);
|
|
62
49
|
|
|
63
|
-
|
|
64
|
-
y1 = max2(y1, _y);
|
|
65
|
-
z1 = max2(z1, _z);
|
|
66
|
-
}
|
|
50
|
+
bvh.readFromArray(scratch_aabb, 0);
|
|
67
51
|
|
|
68
|
-
bvh.
|
|
52
|
+
bvh.bubbleRefit();
|
|
69
53
|
}
|
|
54
|
+
|
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
import { Mesh, Quaternion } from "three";
|
|
2
|
+
import { updateNodeByMatrix4AndBBB } from "../mesh/updateNodeByTransformAndBBB.js";
|
|
3
|
+
import { LeafNode } from "../../../../core/bvh2/LeafNode.js";
|
|
4
|
+
import { AABB3 } from "../../../../core/bvh2/aabb3/AABB3.js";
|
|
5
|
+
|
|
6
|
+
const _q = new Quaternion();
|
|
7
|
+
const _aabb3 = new AABB3();
|
|
8
|
+
|
|
9
|
+
export class ShadedGeometry {
|
|
10
|
+
constructor() {
|
|
11
|
+
/**
|
|
12
|
+
*
|
|
13
|
+
* @type {THREE.BufferGeometry|null}
|
|
14
|
+
*/
|
|
15
|
+
this.geometry = null;
|
|
16
|
+
/**
|
|
17
|
+
*
|
|
18
|
+
* @type {THREE.Material|null}
|
|
19
|
+
*/
|
|
20
|
+
this.material = null;
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
*
|
|
24
|
+
* @type {THREE.Object3D|null}
|
|
25
|
+
* @private
|
|
26
|
+
*/
|
|
27
|
+
this.__cached_object = null;
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
*
|
|
31
|
+
* @type {LeafNode<ShadedGeometry>}
|
|
32
|
+
* @private
|
|
33
|
+
*/
|
|
34
|
+
this.__bvh_leaf = new LeafNode(this, 0, 0, 0, 0, 0, 0);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
get bvh() {
|
|
38
|
+
return this.__bvh_leaf;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
*
|
|
43
|
+
* @param {THREE.BufferGeometry} geometry
|
|
44
|
+
* @param {THREE.Material} material
|
|
45
|
+
*/
|
|
46
|
+
from(geometry, material) {
|
|
47
|
+
this.geometry = geometry;
|
|
48
|
+
this.material = material;
|
|
49
|
+
|
|
50
|
+
// ensure that geometry has a bounding box
|
|
51
|
+
if (geometry.boundingBox === null) {
|
|
52
|
+
geometry.computeBoundingBox();
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
if (this.__cached_object === null) {
|
|
56
|
+
this.__cached_object = new Mesh(geometry, material);
|
|
57
|
+
} else {
|
|
58
|
+
this.__cached_object.material = material;
|
|
59
|
+
this.__cached_object.geometry = geometry;
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
*
|
|
65
|
+
* @param geometry
|
|
66
|
+
* @param material
|
|
67
|
+
* @return {ShadedGeometry}
|
|
68
|
+
*/
|
|
69
|
+
static from(geometry, material) {
|
|
70
|
+
const r = new ShadedGeometry();
|
|
71
|
+
|
|
72
|
+
r.from(geometry, material);
|
|
73
|
+
|
|
74
|
+
return r;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
updateTransform() {
|
|
78
|
+
// update matrix
|
|
79
|
+
this.__cached_object.updateMatrix();
|
|
80
|
+
|
|
81
|
+
// update bounds
|
|
82
|
+
|
|
83
|
+
const gbb = this.geometry.boundingBox;
|
|
84
|
+
|
|
85
|
+
_aabb3.setBounds(
|
|
86
|
+
gbb.min.x,
|
|
87
|
+
gbb.min.y,
|
|
88
|
+
gbb.min.z,
|
|
89
|
+
gbb.max.x,
|
|
90
|
+
gbb.max.y,
|
|
91
|
+
gbb.max.z
|
|
92
|
+
);
|
|
93
|
+
|
|
94
|
+
updateNodeByMatrix4AndBBB(this.__bvh_leaf, _aabb3, this.__cached_object.matrix.elements);
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
/**
|
|
98
|
+
*
|
|
99
|
+
* @param {number} x
|
|
100
|
+
* @param {number} y
|
|
101
|
+
* @param {number} z
|
|
102
|
+
*/
|
|
103
|
+
setPositionByComponents(x, y, z) {
|
|
104
|
+
|
|
105
|
+
this.__cached_object.position.set(x, y, z);
|
|
106
|
+
|
|
107
|
+
this.updateTransform();
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
/**
|
|
111
|
+
*
|
|
112
|
+
* @param {number} x
|
|
113
|
+
* @param {number} y
|
|
114
|
+
* @param {number} z
|
|
115
|
+
* @param {number} w
|
|
116
|
+
*/
|
|
117
|
+
setRotationByComponents(x, y, z, w) {
|
|
118
|
+
|
|
119
|
+
_q.set(x, y, z, w);
|
|
120
|
+
|
|
121
|
+
this.__cached_object.rotation.setFromQuaternion(_q);
|
|
122
|
+
|
|
123
|
+
this.updateTransform();
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
/**
|
|
127
|
+
*
|
|
128
|
+
* @param {number} x
|
|
129
|
+
* @param {number} y
|
|
130
|
+
* @param {number} z
|
|
131
|
+
*/
|
|
132
|
+
setScaleByComponents(x, y, z) {
|
|
133
|
+
this.__cached_object.scale.set(x, y, z);
|
|
134
|
+
|
|
135
|
+
this.updateTransform();
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
/**
|
|
139
|
+
*
|
|
140
|
+
* @param {Transform} t
|
|
141
|
+
*/
|
|
142
|
+
applyTransform(t) {
|
|
143
|
+
// TODO this can be optimized quite a lot
|
|
144
|
+
const position = t.position;
|
|
145
|
+
this.setPositionByComponents(position.x, position.y, position.z);
|
|
146
|
+
|
|
147
|
+
const rotation = t.rotation;
|
|
148
|
+
this.setRotationByComponents(rotation.x, rotation.y, rotation.z, rotation.w);
|
|
149
|
+
|
|
150
|
+
const scale = t.scale;
|
|
151
|
+
this.setScaleByComponents(scale.x, scale.y, scale.z);
|
|
152
|
+
|
|
153
|
+
this.updateTransform();
|
|
154
|
+
}
|
|
155
|
+
}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import { ShadedGeometry } from "./ShadedGeometry.js";
|
|
2
|
+
import { Transform } from "../../../ecs/transform/Transform.js";
|
|
3
|
+
import { System } from "../../../ecs/System.js";
|
|
4
|
+
|
|
5
|
+
export class ShadedGeometrySystem extends System {
|
|
6
|
+
/**
|
|
7
|
+
*
|
|
8
|
+
* @param {Engine} engine
|
|
9
|
+
*/
|
|
10
|
+
constructor(engine) {
|
|
11
|
+
super();
|
|
12
|
+
this.dependencies = [ShadedGeometry, Transform];
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
*s
|
|
16
|
+
* @type {Engine}
|
|
17
|
+
* @private
|
|
18
|
+
*/
|
|
19
|
+
this.__engine = engine;
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
*
|
|
23
|
+
* @type {RenderLayer|null}
|
|
24
|
+
* @private
|
|
25
|
+
*/
|
|
26
|
+
this.__render_layer = null;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
async startup(entityManager, readyCallback, errorCallback) {
|
|
30
|
+
|
|
31
|
+
const engine = this.__engine;
|
|
32
|
+
|
|
33
|
+
this.__render_layer = engine.graphics.layers.create('shaded-geometry');
|
|
34
|
+
this.__render_layer.extractRenderable = (sg) => sg.__cached_object;
|
|
35
|
+
|
|
36
|
+
readyCallback();
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
*
|
|
41
|
+
* @param {ShadedGeometry} sg
|
|
42
|
+
* @param {Transform} t
|
|
43
|
+
* @param {number} entity
|
|
44
|
+
*/
|
|
45
|
+
link(sg, t, entity) {
|
|
46
|
+
t.position.onChanged.add(sg.setPositionByComponents, sg);
|
|
47
|
+
t.rotation.onChanged.add(sg.setRotationByComponents, sg);
|
|
48
|
+
t.scale.onChanged.add(sg.setScaleByComponents, sg);
|
|
49
|
+
|
|
50
|
+
sg.applyTransform(t);
|
|
51
|
+
|
|
52
|
+
this.__render_layer.bvh.insertNode(sg.bvh);
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
*
|
|
57
|
+
* @param {ShadedGeometry} sg
|
|
58
|
+
* @param {Transform} t
|
|
59
|
+
* @param {number} entity
|
|
60
|
+
*/
|
|
61
|
+
unlink(sg, t, entity) {
|
|
62
|
+
t.position.onChanged.remove(sg.setPositionByComponents, sg);
|
|
63
|
+
t.rotation.onChanged.remove(sg.setRotationByComponents, sg);
|
|
64
|
+
t.scale.onChanged.remove(sg.setScaleByComponents, sg);
|
|
65
|
+
|
|
66
|
+
sg.bvh.disconnect();
|
|
67
|
+
}
|
|
68
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { EngineHarness } from "../../../EngineHarness.js";
|
|
2
|
+
import { ShadedGeometrySystem } from "./ShadedGeometrySystem.js";
|
|
3
|
+
import EntityBuilder from "../../../ecs/EntityBuilder.js";
|
|
4
|
+
import { Transform } from "../../../ecs/transform/Transform.js";
|
|
5
|
+
import { ShadedGeometry } from "./ShadedGeometry.js";
|
|
6
|
+
import { BoxBufferGeometry, MeshBasicMaterial } from "three";
|
|
7
|
+
|
|
8
|
+
const eh = new EngineHarness();
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
*
|
|
12
|
+
* @param {Engine} engine
|
|
13
|
+
*/
|
|
14
|
+
async function main(engine) {
|
|
15
|
+
|
|
16
|
+
await engine.entityManager.addSystem(new ShadedGeometrySystem(engine));
|
|
17
|
+
|
|
18
|
+
EngineHarness.buildBasics({ engine })
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
const ecd = engine.entityManager.dataset;
|
|
22
|
+
|
|
23
|
+
new EntityBuilder()
|
|
24
|
+
.add(new Transform())
|
|
25
|
+
.add(ShadedGeometry.from(new BoxBufferGeometry(), new MeshBasicMaterial({
|
|
26
|
+
color: 0xFFFFFF
|
|
27
|
+
})))
|
|
28
|
+
.build(ecd);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
eh.initialize().then(main);
|