@woosh/meep-engine 2.33.24 → 2.33.28
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/BitSet.js +151 -167
- package/core/binary/BitSet.spec.js +99 -1
- package/core/binary/ValidatingBitSetWrapper.js +81 -0
- package/core/bvh2/aabb3/AABB3.js +3 -10
- package/core/bvh2/binary/IndexedBinaryBVH.js +1 -1
- package/core/bvh2/traversal/ThreeClippingPlaneComputingBVHVisitor.js +5 -1
- package/core/bvh2/traversal/__detailed_box_volume_intersection.js +22 -5
- package/core/cache/Cache.d.ts +4 -2
- package/core/cache/Cache.js +5 -2
- package/core/collection/HashMap.d.ts +9 -2
- package/core/collection/HashSet.d.ts +7 -2
- package/core/collection/HashSet.js +7 -2
- package/core/collection/array/binarySearchHighIndex.js +1 -1
- package/core/collection/array/copyArray.js +2 -2
- package/core/collection/array/typed/typed_array_copy.js +1 -1
- package/core/geom/3d/frustum/array_setFromProjectionMatrix.js +3 -3
- package/core/geom/3d/normal/hemioct/unit_hemioct.spec.js +1 -1
- package/core/geom/3d/shape/AbstractShape3D.js +37 -1
- package/core/geom/3d/shape/TransformedShape3D.js +121 -10
- package/core/geom/3d/shape/TransformedShape3D.spec.js +33 -0
- package/core/geom/3d/shape/UnionShape3D.js +255 -0
- package/core/geom/3d/shape/UnitCubeShape3D.js +88 -0
- package/core/geom/3d/shape/UnitCubeShape3D.spec.js +42 -0
- package/core/geom/3d/shape/UnitSphereShape3D.js +39 -0
- package/core/geom/3d/shape/util/compute_signed_distance_gradient_by_sampling.js +48 -0
- package/core/geom/3d/shape/util/shape_to_visual_entity.js +159 -0
- package/core/geom/random/randomPointInSphere.js +3 -2
- package/core/json/resolvePathByArray.js +2 -2
- package/core/model/ObservedBoolean.d.ts +2 -0
- package/core/parser/simple/Token.d.ts +13 -0
- package/core/parser/simple/Token.js +61 -27
- package/{engine/graphics/render/forward_plus/materials → core/primitives/strings}/insert_after.js +3 -0
- package/core/primitives/strings/insert_after_or_replace.js +27 -0
- package/editor/process/symbolic/makeHelperBoxGeometry.js +44 -0
- package/editor/tools/FoliagePaintTool.js +4 -4
- package/editor/view/ecs/EntityEditor.js +2 -2
- package/editor/view/ecs/components/particles/ParticleEmitterController.js +2 -2
- package/engine/EngineHarness.js +1 -0
- package/engine/animation/AnimationUtils.js +5 -5
- package/engine/asset/loaders/GLTFAssetLoader.js +52 -1
- package/engine/asset/loaders/image/ImageDecoderWorker.js +4 -3
- package/engine/asset/loaders/image/ImageRGBADataAsset.js +3 -2
- package/engine/asset/loaders/image/ImageRGBADataLoader.js +3 -3
- package/engine/asset/loaders/image/codec/NativeImageDecoder.js +2 -1
- package/engine/asset/loaders/image/png/PNG.js +113 -6
- package/engine/asset/loaders/image/png/PNGReader.js +5 -0
- package/engine/asset/loaders/material/bitmap2sampler_gl.js +1 -1
- package/engine/asset/loaders/material/computeImageBitmapEquality.js +6 -1
- package/engine/asset/loaders/material/computeTextureEquality.js +40 -49
- package/engine/ecs/EntityBuilder.js +25 -5
- package/engine/ecs/EntityComponentDataset.js +1 -1
- package/engine/ecs/attachment/AttachmentBinding.js +8 -0
- package/engine/ecs/attachment/AttachmentSystem.js +4 -0
- package/engine/ecs/attachment/TransformAttachmentBinding.js +14 -44
- package/engine/ecs/components/Tag.js +27 -6
- package/engine/ecs/foliage/InstancedFoliage.js +277 -266
- package/engine/ecs/foliage/ecs/Foliage2System.js +7 -7
- package/engine/ecs/foliage/ecs/InstancedMeshComponent.js +37 -0
- package/engine/ecs/foliage/ecs/{Foliage2.js → InstancedMeshLayer.js} +3 -45
- package/engine/ecs/foliage/ecs/InstancedMeshSerializationAdapter.js +6 -5
- package/engine/ecs/foliage/ecs/InstancedMeshUtils.js +7 -6
- package/engine/ecs/fow/FogOfWar.js +4 -0
- package/engine/ecs/fow/FogOfWarSystem.js +2 -0
- package/engine/ecs/gui/hud/HeadsUpDisplaySystem.js +2 -0
- package/engine/ecs/storage/binary/BinarySerializationRegistry.js +1 -1
- package/engine/ecs/system/AbstractContextSystem.js +1 -1
- package/engine/ecs/systems/TagSystem.js +17 -0
- package/engine/ecs/terrain/ecs/layers/TerrainLayer.js +12 -16
- package/engine/ecs/transform/Transform.js +19 -6
- package/engine/graphics/GraphicsEngine.js +11 -6
- package/engine/graphics/composit/CompositLayer.js +17 -4
- package/engine/graphics/composit/CompositingStages.js +8 -0
- package/engine/graphics/composit/LayerCompositer.js +35 -6
- package/engine/graphics/ecs/highlight/plugin/OutlineRenderPlugin.js +11 -7
- package/engine/graphics/ecs/light/Light.js +2 -0
- package/engine/graphics/ecs/light/binding/three/ThreeLightBinding.js +5 -1
- package/engine/graphics/ecs/mesh-v2/DrawMode.js +5 -0
- package/engine/graphics/ecs/mesh-v2/ShadedGeometry.js +32 -18
- package/engine/graphics/geometry/instancing/InstancedMeshGroup.js +14 -72
- package/engine/graphics/geometry/instancing/rewriteMaterial.js +70 -0
- package/engine/graphics/material/manager/MaterialManager.js +2 -1
- package/engine/graphics/micron/render/instanced/AttributeDataTexture.js +6 -4
- package/engine/graphics/micron/render/instanced/ThreeInstancedAdapter.js +0 -2
- package/engine/graphics/particles/ParticleEmitterLibrary.js +3 -0
- package/engine/graphics/particles/ecs/{ParticleEmitterSystem2.js → ParticleEmitterSystem.js} +17 -9
- package/engine/graphics/particles/particular/engine/ParticularEngine.js +8 -2
- package/engine/graphics/particles/particular/engine/emitter/ParticleEmitter.js +14 -25
- package/engine/graphics/particles/particular/engine/emitter/ParticleEmitterFlag.js +5 -0
- package/engine/graphics/particles/particular/engine/emitter/ParticlePool.js +90 -2
- package/engine/graphics/particles/particular/engine/emitter/ParticlePool.spec.js +7 -7
- package/engine/graphics/particles/particular/engine/renderers/billboard/BILLBOARD_PARTICLE_SPECIFICATION.js +15 -12
- package/engine/graphics/particles/particular/engine/renderers/billboard/ParticleBillboardMaterial.js +262 -51
- package/engine/graphics/particles/particular/engine/shader/ShaderManager.js +81 -48
- package/engine/graphics/particles/particular/engine/shader/debugAtlas.js +14 -0
- package/engine/graphics/particles/particular/engine/utils/volume/AttributeValue.js +141 -0
- package/engine/graphics/particles/particular/engine/utils/volume/ParticleVolume.js +148 -54
- package/engine/graphics/particles/particular/engine/utils/volume/lut_to_sampler.js +27 -0
- package/engine/graphics/particles/particular/engine/utils/volume/prototypeParticleVolume.js +544 -164
- package/engine/graphics/render/buffer/simple-fx/ao/AmbientOcclusionPostProcessEffect.js +15 -10
- package/engine/graphics/render/forward_plus/materials/FP_INJECTION_POINT_ACCUMULATION.js +1 -0
- package/engine/graphics/render/forward_plus/materials/FP_SHADER_CHUNK_ACCUMULATION.js +32 -0
- package/engine/graphics/render/forward_plus/materials/FP_SHADER_CHUNK_DECODE_PARS.js +51 -0
- package/engine/graphics/render/forward_plus/materials/FP_SHADER_CHUNK_PREAMBLE.js +25 -0
- package/engine/graphics/render/forward_plus/materials/FPlusDebugMaterial.js +3 -3
- package/engine/graphics/render/forward_plus/materials/ForwardPlusThreeMaterial.js +1 -1
- package/engine/graphics/render/forward_plus/materials/fp_build_fragment_shader.js +31 -120
- package/engine/graphics/render/forward_plus/materials/fp_build_vertex_lighting_shared.js +35 -0
- package/engine/graphics/render/forward_plus/materials/fp_build_vertex_shader.js +4 -5
- package/engine/graphics/render/forward_plus/plugin/MaterialTransformer.js +10 -3
- package/engine/graphics/render/forward_plus/plugin/ptototypeFPPlugin.js +588 -53
- package/engine/graphics/render/forward_plus/prototypeLightManager.js +31 -6
- package/engine/graphics/render/forward_plus/query/point_light_inside_volume.js +10 -9
- package/engine/graphics/shaders/TerrainShader.js +4 -5
- package/engine/graphics/shadows/ShadowMapRenderer.js +8 -2
- package/engine/graphics/texture/atlas/ManagedTextureAtlas.js +12 -1
- package/engine/graphics/texture/sampler/Sampler2D.js +3 -1
- package/engine/graphics/texture/sampler/convertTexture2Sampler2D.js +1 -1
- package/engine/graphics/texture/sampler/copy_Sampler2D_channel_data.js +66 -0
- package/engine/graphics/util/composeMatrix4.js +33 -23
- package/engine/graphics/util/decompose_matrix_4_array.js +61 -0
- package/engine/intelligence/behavior/ecs/BehaviorComponent.js +30 -14
- package/engine/knowledge/database/StaticKnowledgeDataTable.js +6 -1
- package/engine/navigation/ecs/components/Path.js +0 -5
- package/package.json +1 -1
- package/view/minimap/gl/MinimapWorldGL.js +12 -5
- package/core/geom/3d/shape/CompositeShape.js +0 -60
|
@@ -17,6 +17,7 @@ import { deserializeBinaryNodeFromBinaryBuffer } from "../../../core/bvh2/serial
|
|
|
17
17
|
import { computeGeometryBoundingSphereMiniball } from "../../graphics/geometry/buffered/computeGeometryBoundingSphereMiniball.js";
|
|
18
18
|
import { serializeRowFirstTable } from "../../../core/collection/table/serializeRowFirstTable.js";
|
|
19
19
|
import { deserializeRowFirstTable } from "../../../core/collection/table/deserializeRowFirstTable.js";
|
|
20
|
+
import { assert } from "../../../core/assert.js";
|
|
20
21
|
|
|
21
22
|
/**
|
|
22
23
|
* @readonly
|
|
@@ -28,364 +29,374 @@ const dataSpec = new RowFirstTableSpec([
|
|
|
28
29
|
DataType.Float32, DataType.Float32, DataType.Float32 //scale
|
|
29
30
|
]);
|
|
30
31
|
|
|
31
|
-
|
|
32
|
-
*
|
|
33
|
-
* @constructor
|
|
34
|
-
*/
|
|
35
|
-
function InstancedFoliage() {
|
|
36
|
-
/**
|
|
37
|
-
* Minimum area on the screen to be occupied by an instance, if instance bounding sphere occupies less than this - it will be culled
|
|
38
|
-
* Measured in pixels
|
|
39
|
-
* @type {number}
|
|
40
|
-
*/
|
|
41
|
-
this.minScreenArea = 32;
|
|
42
|
-
|
|
32
|
+
export class InstancedFoliage {
|
|
43
33
|
/**
|
|
44
34
|
*
|
|
45
|
-
* @
|
|
35
|
+
* @constructor
|
|
46
36
|
*/
|
|
47
|
-
|
|
48
|
-
|
|
37
|
+
constructor() {
|
|
38
|
+
/**
|
|
39
|
+
* Minimum area on the screen to be occupied by an instance, if instance bounding sphere occupies less than this - it will be culled
|
|
40
|
+
* Measured in pixels
|
|
41
|
+
* @type {number}
|
|
42
|
+
*/
|
|
43
|
+
this.minScreenArea = 32;
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
*
|
|
47
|
+
* @type {BinaryNode}
|
|
48
|
+
*/
|
|
49
|
+
this.bvh = new BinaryNode();
|
|
50
|
+
this.bvh.setNegativelyInfiniteBounds();
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
*
|
|
54
|
+
* @type {RowFirstTable}
|
|
55
|
+
*/
|
|
56
|
+
this.data = new RowFirstTable(dataSpec);
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
*
|
|
60
|
+
* @type {InstancedMeshGroup}
|
|
61
|
+
*/
|
|
62
|
+
this.instances = new InstancedMeshGroup();
|
|
63
|
+
|
|
64
|
+
this.geometry = null;
|
|
65
|
+
this.instanceBoundingSphere = new Vector4(0, 0, 0, 0);
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+
this.bvhVisibilityVisitor = new ThreeFrustumsIntersectionBVHVisitor();
|
|
69
|
+
|
|
70
|
+
this.visibilitySetBuilder = new FoliageVisibilitySetBuilder();
|
|
71
|
+
this.bvhVisibilityVisitor.collector = this.visibilitySetBuilder;
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
*
|
|
75
|
+
* @type {*[]}
|
|
76
|
+
* @private
|
|
77
|
+
*/
|
|
78
|
+
this.__garbage = [];
|
|
79
|
+
/**
|
|
80
|
+
*
|
|
81
|
+
* @type {number}
|
|
82
|
+
* @private
|
|
83
|
+
*/
|
|
84
|
+
this.__garbagePointer = 0;
|
|
85
|
+
}
|
|
49
86
|
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
*/
|
|
54
|
-
this.data = new RowFirstTable(dataSpec);
|
|
87
|
+
hash() {
|
|
88
|
+
return this.data.hash();
|
|
89
|
+
}
|
|
55
90
|
|
|
56
|
-
|
|
57
|
-
*
|
|
58
|
-
* @type {InstancedMeshGroup}
|
|
59
|
-
*/
|
|
60
|
-
this.instances = new InstancedMeshGroup();
|
|
91
|
+
clear() {
|
|
61
92
|
|
|
62
|
-
|
|
63
|
-
|
|
93
|
+
this.data.clear();
|
|
94
|
+
this.bvh.reset();
|
|
64
95
|
|
|
96
|
+
}
|
|
65
97
|
|
|
66
|
-
|
|
98
|
+
dispose() {
|
|
99
|
+
this.instances.dispose();
|
|
100
|
+
}
|
|
67
101
|
|
|
68
|
-
|
|
69
|
-
|
|
102
|
+
initialize() {
|
|
103
|
+
|
|
104
|
+
}
|
|
70
105
|
|
|
71
106
|
/**
|
|
72
107
|
*
|
|
73
|
-
* @
|
|
74
|
-
* @
|
|
75
|
-
|
|
76
|
-
this.__garbage = [];
|
|
77
|
-
/**
|
|
78
|
-
*
|
|
79
|
-
* @type {number}
|
|
80
|
-
* @private
|
|
108
|
+
* @param {Vector3} position
|
|
109
|
+
* @param {Quaternion} rotation
|
|
110
|
+
* @param {Vector3} scale
|
|
81
111
|
*/
|
|
82
|
-
|
|
83
|
-
|
|
112
|
+
add(position, rotation, scale) {
|
|
113
|
+
const index = this.data.length;
|
|
84
114
|
|
|
85
|
-
|
|
86
|
-
return this.data.hash();
|
|
87
|
-
};
|
|
115
|
+
const encodedRotation = rotation.encodeToUint32();
|
|
88
116
|
|
|
89
|
-
|
|
117
|
+
//update data
|
|
118
|
+
this.data.addRow([
|
|
119
|
+
position.x, position.y, position.z,
|
|
120
|
+
encodedRotation,
|
|
121
|
+
scale.x, scale.y, scale.z
|
|
122
|
+
]);
|
|
90
123
|
|
|
91
|
-
|
|
92
|
-
|
|
124
|
+
const leaf = new LeafNode(
|
|
125
|
+
index,
|
|
126
|
+
Number.POSITIVE_INFINITY, Number.POSITIVE_INFINITY, Number.POSITIVE_INFINITY,
|
|
127
|
+
Number.NEGATIVE_INFINITY, Number.NEGATIVE_INFINITY, Number.NEGATIVE_INFINITY
|
|
128
|
+
);
|
|
93
129
|
|
|
94
|
-
|
|
130
|
+
//compute bounding box for this instance
|
|
131
|
+
this.expandBoundingBoxForInstance(position, rotation, scale, leaf);
|
|
95
132
|
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
}
|
|
133
|
+
//insert bounding box into the spatial index
|
|
134
|
+
this.bvh.insertNode(leaf);
|
|
135
|
+
}
|
|
99
136
|
|
|
100
|
-
|
|
137
|
+
/**
|
|
138
|
+
*
|
|
139
|
+
* @param {int} index Instance index
|
|
140
|
+
* @param {Vector3} position Position of instance will be read into this vector
|
|
141
|
+
* @param {Quaternion} rotation Rotation of instance will be read into this quaternion
|
|
142
|
+
* @param {Vector3} scale Scale of the instance will be read into this Vector
|
|
143
|
+
*/
|
|
144
|
+
read(index, position, rotation, scale) {
|
|
145
|
+
const elementData = [];
|
|
146
|
+
//read transform data for instance
|
|
147
|
+
this.data.getRow(index, elementData);
|
|
101
148
|
|
|
102
|
-
|
|
149
|
+
const positionX = elementData[0];
|
|
150
|
+
const positionY = elementData[1];
|
|
151
|
+
const positionZ = elementData[2];
|
|
103
152
|
|
|
104
|
-
|
|
105
|
-
*
|
|
106
|
-
* @param {Vector3} position
|
|
107
|
-
* @param {Quaternion} rotation
|
|
108
|
-
* @param {Vector3} scale
|
|
109
|
-
*/
|
|
110
|
-
InstancedFoliage.prototype.add = function (position, rotation, scale) {
|
|
111
|
-
const index = this.data.length;
|
|
153
|
+
const encodedRotation = elementData[3];
|
|
112
154
|
|
|
113
|
-
|
|
155
|
+
const scaleX = elementData[4];
|
|
156
|
+
const scaleY = elementData[5];
|
|
157
|
+
const scaleZ = elementData[6];
|
|
114
158
|
|
|
115
|
-
|
|
116
|
-
this.data.addRow([
|
|
117
|
-
position.x, position.y, position.z,
|
|
118
|
-
encodedRotation,
|
|
119
|
-
scale.x, scale.y, scale.z
|
|
120
|
-
]);
|
|
159
|
+
position.set(positionX, positionY, positionZ);
|
|
121
160
|
|
|
122
|
-
|
|
123
|
-
index,
|
|
124
|
-
Number.POSITIVE_INFINITY, Number.POSITIVE_INFINITY, Number.POSITIVE_INFINITY,
|
|
125
|
-
Number.NEGATIVE_INFINITY, Number.NEGATIVE_INFINITY, Number.NEGATIVE_INFINITY
|
|
126
|
-
);
|
|
161
|
+
rotation.decodeFromUint32(encodedRotation);
|
|
127
162
|
|
|
128
|
-
|
|
129
|
-
|
|
163
|
+
scale.set(scaleX, scaleY, scaleZ);
|
|
164
|
+
}
|
|
130
165
|
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
}
|
|
166
|
+
/**
|
|
167
|
+
*
|
|
168
|
+
* @param {AABB3} result
|
|
169
|
+
* @param {Vector3} position
|
|
170
|
+
* @param {Quaternion} rotation
|
|
171
|
+
* @param {Vector3} scale
|
|
172
|
+
*/
|
|
173
|
+
expandBoundingBoxForInstance(position, rotation, scale, result) {
|
|
134
174
|
|
|
135
|
-
|
|
136
|
-
*
|
|
137
|
-
* @param {int} index Instance index
|
|
138
|
-
* @param {Vector3} position Position of instance will be read into this vector
|
|
139
|
-
* @param {Quaternion} rotation Rotation of instance will be read into this quaternion
|
|
140
|
-
* @param {Vector3} scale Scale of the instance will be read into this Vector
|
|
141
|
-
*/
|
|
142
|
-
InstancedFoliage.prototype.read = function (index, position, rotation, scale) {
|
|
143
|
-
const elementData = [];
|
|
144
|
-
//read transform data for instance
|
|
145
|
-
this.data.getRow(index, elementData);
|
|
175
|
+
const vertexData = this.geometry.attributes.position.array;
|
|
146
176
|
|
|
147
|
-
|
|
148
|
-
const positionY = elementData[1];
|
|
149
|
-
const positionZ = elementData[2];
|
|
177
|
+
const rXYZ = new Vector3(rotation.x, rotation.y, rotation.z);
|
|
150
178
|
|
|
151
|
-
|
|
179
|
+
const v = new Vector3(0, 0, 0);
|
|
152
180
|
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
181
|
+
const c0 = new Vector3(0, 0, 0);
|
|
182
|
+
const c1 = new Vector3(0, 0, 0);
|
|
183
|
+
const c2 = new Vector3(0, 0, 0);
|
|
156
184
|
|
|
157
|
-
|
|
185
|
+
for (let i = 0, l = vertexData.length; i < l; i += 3) {
|
|
186
|
+
const x = vertexData[i];
|
|
187
|
+
const y = vertexData[i + 1];
|
|
188
|
+
const z = vertexData[i + 2];
|
|
158
189
|
|
|
159
|
-
|
|
190
|
+
v.set(x, y, z);
|
|
160
191
|
|
|
161
|
-
|
|
162
|
-
};
|
|
192
|
+
//transform point
|
|
163
193
|
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
* @param {AABB3} result
|
|
167
|
-
* @param {Vector3} position
|
|
168
|
-
* @param {Quaternion} rotation
|
|
169
|
-
* @param {Vector3} scale
|
|
170
|
-
*/
|
|
171
|
-
InstancedFoliage.prototype.expandBoundingBoxForInstance = function (position, rotation, scale, result) {
|
|
194
|
+
//apply scale
|
|
195
|
+
v.multiply(scale);
|
|
172
196
|
|
|
173
|
-
|
|
197
|
+
//apply rotation
|
|
198
|
+
c1.copy(v).multiplyScalar(rotation.w);
|
|
199
|
+
c0.copy(rXYZ).cross(v).add(c1);
|
|
200
|
+
c2.copy(rXYZ).cross(c0).multiplyScalar(2);
|
|
174
201
|
|
|
175
|
-
|
|
202
|
+
v.add(c2);
|
|
176
203
|
|
|
177
|
-
|
|
204
|
+
//apply translation
|
|
205
|
+
v.add(position);
|
|
178
206
|
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
207
|
+
result._expandToFitPoint(v.x, v.y, v.z);
|
|
208
|
+
}
|
|
209
|
+
}
|
|
182
210
|
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
const z = vertexData[i + 2];
|
|
211
|
+
computeInstanceBoundingSphere() {
|
|
212
|
+
this.instanceBoundingSphere = computeGeometryBoundingSphereMiniball(this.geometry);
|
|
213
|
+
}
|
|
187
214
|
|
|
188
|
-
|
|
215
|
+
setInstance(geometry, material) {
|
|
216
|
+
if (material === undefined) {
|
|
217
|
+
throw new Error(`Material is undefined`);
|
|
218
|
+
}
|
|
189
219
|
|
|
190
|
-
|
|
220
|
+
if (geometry === undefined) {
|
|
221
|
+
throw new Error(`Geometry is undefined`);
|
|
222
|
+
}
|
|
191
223
|
|
|
192
|
-
//apply scale
|
|
193
|
-
v.multiply(scale);
|
|
194
224
|
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
225
|
+
let bufferGeometry;
|
|
226
|
+
if ((geometry instanceof BufferGeometry)) {
|
|
227
|
+
bufferGeometry = geometry;
|
|
228
|
+
} else {
|
|
229
|
+
bufferGeometry = new BufferGeometry();
|
|
230
|
+
bufferGeometry.fromGeometry(geometry);
|
|
231
|
+
}
|
|
199
232
|
|
|
200
|
-
v.add(c2);
|
|
201
233
|
|
|
202
|
-
|
|
203
|
-
v.add(position);
|
|
234
|
+
this.geometry = bufferGeometry;
|
|
204
235
|
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
};
|
|
236
|
+
this.instances.setMaterial(material);
|
|
237
|
+
this.instances.setGeometry(bufferGeometry);
|
|
208
238
|
|
|
209
|
-
|
|
210
|
-
this.instanceBoundingSphere = computeGeometryBoundingSphereMiniball(this.geometry);
|
|
211
|
-
};
|
|
239
|
+
this.computeInstanceBoundingSphere();
|
|
212
240
|
|
|
213
|
-
|
|
214
|
-
if (material === undefined) {
|
|
215
|
-
throw new Error(`Material is undefined`);
|
|
216
|
-
}
|
|
241
|
+
//TODO: compute haul for the mesh, to use for fast AABB computation
|
|
217
242
|
|
|
218
|
-
if (geometry === undefined) {
|
|
219
|
-
throw new Error(`Geometry is undefined`);
|
|
220
243
|
}
|
|
221
244
|
|
|
245
|
+
/**
|
|
246
|
+
*
|
|
247
|
+
* @param {BinaryBuffer} buffer
|
|
248
|
+
*/
|
|
249
|
+
deserialize(buffer) {
|
|
250
|
+
deserializeRowFirstTable(buffer, this.data);
|
|
222
251
|
|
|
223
|
-
|
|
224
|
-
if ((geometry instanceof BufferGeometry)) {
|
|
225
|
-
bufferGeometry = geometry;
|
|
226
|
-
} else {
|
|
227
|
-
bufferGeometry = new BufferGeometry();
|
|
228
|
-
bufferGeometry.fromGeometry(geometry);
|
|
252
|
+
deserializeBinaryNodeFromBinaryBuffer(this.bvh, buffer, deserializeLeafValueUintVar);
|
|
229
253
|
}
|
|
230
254
|
|
|
255
|
+
/**
|
|
256
|
+
*
|
|
257
|
+
* @param {BinaryBuffer} buffer
|
|
258
|
+
*/
|
|
259
|
+
serialize(buffer) {
|
|
231
260
|
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
this.instances.setMaterial(material);
|
|
235
|
-
this.instances.setGeometry(bufferGeometry);
|
|
261
|
+
//serialize data
|
|
262
|
+
serializeRowFirstTable(buffer, this.data);
|
|
236
263
|
|
|
237
|
-
|
|
264
|
+
const numRows = this.data.length;
|
|
238
265
|
|
|
239
|
-
|
|
266
|
+
if (numRows > 2147483647) {
|
|
267
|
+
throw new Error(`Data is too large to be written (length=${numRows})`);
|
|
268
|
+
}
|
|
240
269
|
|
|
241
|
-
};
|
|
242
270
|
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
* @param {BinaryBuffer} buffer
|
|
246
|
-
* @returns {number}
|
|
247
|
-
*/
|
|
248
|
-
function deserializeLeafValueUintVar(buffer) {
|
|
249
|
-
return buffer.readUintVar();
|
|
250
|
-
}
|
|
271
|
+
serializeBinaryNodeToBinaryBuffer(this.bvh, buffer, serializeLeafValueUintVar);
|
|
272
|
+
}
|
|
251
273
|
|
|
252
|
-
|
|
253
|
-
|
|
274
|
+
/**
|
|
275
|
+
*
|
|
276
|
+
* @param index
|
|
277
|
+
* @param {int} ref
|
|
278
|
+
*/
|
|
279
|
+
__updateVisibility(index, ref) {
|
|
280
|
+
assert.isNonNegativeInteger(ref, 'ref');
|
|
281
|
+
|
|
282
|
+
/**
|
|
283
|
+
*
|
|
284
|
+
* @type {FoliageVisibilitySetBuilder}
|
|
285
|
+
*/
|
|
286
|
+
const builder = this.visibilitySetBuilder;
|
|
287
|
+
|
|
288
|
+
/**
|
|
289
|
+
*
|
|
290
|
+
* @type {BitSet}
|
|
291
|
+
*/
|
|
292
|
+
const visibleElementSet = builder.visibleSet;
|
|
293
|
+
|
|
294
|
+
if (!visibleElementSet.get(ref)) {
|
|
295
|
+
//no longer visible
|
|
296
|
+
this.__garbage[this.__garbagePointer++] = ref;
|
|
297
|
+
} else {
|
|
298
|
+
//visible, and is already in the group, update the set
|
|
299
|
+
visibleElementSet.set(ref, false);
|
|
300
|
+
}
|
|
301
|
+
}
|
|
254
302
|
|
|
255
|
-
|
|
256
|
-
};
|
|
303
|
+
__removeGarbage() {
|
|
257
304
|
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
* @param {BinaryBuffer} buffer
|
|
261
|
-
* @param {number} value
|
|
262
|
-
*/
|
|
263
|
-
function serializeLeafValueUintVar(buffer, value) {
|
|
264
|
-
buffer.writeUintVar(value);
|
|
265
|
-
}
|
|
305
|
+
const garbagePointer = this.__garbagePointer;
|
|
306
|
+
const instances = this.instances;
|
|
266
307
|
|
|
267
|
-
InstancedFoliage.prototype.serialize = function (buffer) {
|
|
268
308
|
|
|
269
|
-
|
|
270
|
-
serializeRowFirstTable(buffer, this.data);
|
|
309
|
+
const garbage = this.__garbage;
|
|
271
310
|
|
|
272
|
-
|
|
311
|
+
for (let i = 0; i < garbagePointer; i++) {
|
|
312
|
+
const ref = garbage[i];
|
|
313
|
+
instances.remove(ref);
|
|
314
|
+
}
|
|
273
315
|
|
|
274
|
-
if (numRows > 2147483647) {
|
|
275
|
-
throw new Error(`Data is too large to be written (length=${numRows})`);
|
|
276
316
|
}
|
|
277
317
|
|
|
278
|
-
|
|
279
|
-
serializeBinaryNodeToBinaryBuffer(this.bvh, buffer, serializeLeafValueUintVar);
|
|
280
|
-
};
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
const tempQuaternion = new Quaternion();
|
|
284
|
-
const rowData = [];
|
|
285
|
-
|
|
286
|
-
/**
|
|
287
|
-
*
|
|
288
|
-
* @param index
|
|
289
|
-
* @param {int} ref
|
|
290
|
-
*/
|
|
291
|
-
InstancedFoliage.prototype.__updateVisibility = function (index, ref) {
|
|
292
318
|
/**
|
|
293
319
|
*
|
|
294
|
-
* @
|
|
320
|
+
* @param {Frustum[]} frustums
|
|
321
|
+
* @param {function[]} [visibilityFilters]
|
|
295
322
|
*/
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
/**
|
|
299
|
-
*
|
|
300
|
-
* @type {BitSet}
|
|
301
|
-
*/
|
|
302
|
-
const visibleElementSet = builder.visibleSet;
|
|
303
|
-
|
|
304
|
-
if (!visibleElementSet.get(ref)) {
|
|
305
|
-
//no longer visible
|
|
306
|
-
this.__garbage[this.__garbagePointer++] = ref;
|
|
307
|
-
} else {
|
|
308
|
-
//visible, and is already in the group, update the set
|
|
309
|
-
visibleElementSet.set(ref, false);
|
|
310
|
-
}
|
|
311
|
-
};
|
|
312
|
-
|
|
313
|
-
InstancedFoliage.prototype.__removeGarbage = function () {
|
|
323
|
+
update(frustums, visibilityFilters = []) {
|
|
324
|
+
const instances = this.instances;
|
|
314
325
|
|
|
315
|
-
|
|
316
|
-
const instances = this.instances;
|
|
326
|
+
this.bvhVisibilityVisitor.setFrustums(frustums);
|
|
317
327
|
|
|
328
|
+
const visibilitySetBuilder = this.visibilitySetBuilder;
|
|
329
|
+
visibilitySetBuilder.setFilters(visibilityFilters);
|
|
330
|
+
visibilitySetBuilder.initialize();
|
|
318
331
|
|
|
319
|
-
|
|
332
|
+
const visibleElementSet = visibilitySetBuilder.visibleSet;
|
|
320
333
|
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
instances.remove(ref);
|
|
324
|
-
}
|
|
325
|
-
|
|
326
|
-
};
|
|
327
|
-
|
|
328
|
-
/**
|
|
329
|
-
*
|
|
330
|
-
* @param {Frustum[]} frustums
|
|
331
|
-
* @param {function[]} [visibilityFilters]
|
|
332
|
-
*/
|
|
333
|
-
InstancedFoliage.prototype.update = function (frustums, visibilityFilters = []) {
|
|
334
|
-
const instances = this.instances;
|
|
334
|
+
//build visible set
|
|
335
|
+
traverseBinaryNodeUsingVisitor(this.bvh, this.bvhVisibilityVisitor);
|
|
335
336
|
|
|
336
|
-
|
|
337
|
+
visibilitySetBuilder.finalize();
|
|
337
338
|
|
|
338
|
-
|
|
339
|
-
visibilitySetBuilder.setFilters(visibilityFilters);
|
|
340
|
-
visibilitySetBuilder.initialize();
|
|
339
|
+
// console.log(`Visible: `, elementsToAdd.size);
|
|
341
340
|
|
|
342
|
-
|
|
341
|
+
//reset garbage pointer
|
|
342
|
+
this.__garbagePointer = 0;
|
|
343
343
|
|
|
344
|
-
|
|
345
|
-
|
|
344
|
+
//remove those that are no longer visible
|
|
345
|
+
instances.traverseReferences(this.__updateVisibility, this);
|
|
346
346
|
|
|
347
|
-
|
|
347
|
+
//cull instances that are no longer visible
|
|
348
|
+
this.__removeGarbage();
|
|
348
349
|
|
|
349
|
-
// console.log(`Visible: `, elementsToAdd.size);
|
|
350
350
|
|
|
351
|
-
|
|
352
|
-
this.__garbagePointer = 0;
|
|
351
|
+
const data = this.data;
|
|
353
352
|
|
|
354
|
-
|
|
355
|
-
|
|
353
|
+
//process entities that have become newly visible
|
|
354
|
+
for (let index = visibleElementSet.nextSetBit(0); index !== -1; index = visibleElementSet.nextSetBit(index + 1)) {
|
|
355
|
+
//read transform data for instance
|
|
356
|
+
data.getRow(index, rowData);
|
|
356
357
|
|
|
357
|
-
|
|
358
|
-
|
|
358
|
+
const positionX = rowData[0];
|
|
359
|
+
const positionY = rowData[1];
|
|
360
|
+
const positionZ = rowData[2];
|
|
359
361
|
|
|
362
|
+
const encodedRotation = rowData[3];
|
|
360
363
|
|
|
361
|
-
const data = this.data;
|
|
362
|
-
|
|
363
|
-
//process entities that have become newly visible
|
|
364
|
-
for (let index = visibleElementSet.nextSetBit(0); index !== -1; index = visibleElementSet.nextSetBit(index + 1)) {
|
|
365
|
-
//read transform data for instance
|
|
366
|
-
data.getRow(index, rowData);
|
|
367
364
|
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
365
|
+
const scaleX = rowData[4];
|
|
366
|
+
const scaleY = rowData[5];
|
|
367
|
+
const scaleZ = rowData[6];
|
|
371
368
|
|
|
372
|
-
|
|
369
|
+
const i = instances.add(index);
|
|
373
370
|
|
|
371
|
+
tempQuaternion.decodeFromUint32(encodedRotation);
|
|
374
372
|
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
373
|
+
//apply instance transforms
|
|
374
|
+
instances.setPositionAt(i, positionX, positionY, positionZ);
|
|
375
|
+
instances.setRotationAt(i, tempQuaternion.x, tempQuaternion.y, tempQuaternion.z, tempQuaternion.w);
|
|
376
|
+
instances.setScaleAt(i, scaleX, scaleY, scaleZ);
|
|
377
|
+
}
|
|
378
|
+
}
|
|
379
|
+
}
|
|
378
380
|
|
|
379
|
-
|
|
381
|
+
/**
|
|
382
|
+
*
|
|
383
|
+
* @param {BinaryBuffer} buffer
|
|
384
|
+
* @returns {number}
|
|
385
|
+
*/
|
|
386
|
+
function deserializeLeafValueUintVar(buffer) {
|
|
387
|
+
return buffer.readUintVar();
|
|
388
|
+
}
|
|
380
389
|
|
|
381
|
-
|
|
390
|
+
/**
|
|
391
|
+
*
|
|
392
|
+
* @param {BinaryBuffer} buffer
|
|
393
|
+
* @param {number} value
|
|
394
|
+
*/
|
|
395
|
+
function serializeLeafValueUintVar(buffer, value) {
|
|
396
|
+
buffer.writeUintVar(value);
|
|
397
|
+
}
|
|
382
398
|
|
|
383
|
-
//apply instance transforms
|
|
384
|
-
instances.setPositionAt(i, positionX, positionY, positionZ);
|
|
385
|
-
instances.setRotationAt(i, tempQuaternion.x, tempQuaternion.y, tempQuaternion.z, tempQuaternion.w);
|
|
386
|
-
instances.setScaleAt(i, scaleX, scaleY, scaleZ);
|
|
387
|
-
}
|
|
388
|
-
};
|
|
389
399
|
|
|
400
|
+
const tempQuaternion = new Quaternion();
|
|
401
|
+
const rowData = [];
|
|
390
402
|
|
|
391
|
-
export { InstancedFoliage };
|