@woosh/meep-engine 2.33.63 → 2.33.68
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/FilePath.js +28 -2
- package/core/binary/BinaryBuffer.js +13 -0
- package/core/geom/2d/quad-tree/QuadTreeNode.js +3 -2
- package/core/geom/3d/triangle/computeTriangleRayIntersection.js +3 -9
- package/engine/asset/AssetManager.js +1 -1
- package/engine/asset/AssetTransformer.js +2 -1
- package/engine/asset/loaders/GLTFAssetLoader.js +5 -21
- package/engine/asset/loaders/async_traverse_three_object.js +24 -0
- package/engine/ecs/attachment/AttachmentSystem.js +3 -51
- package/engine/ecs/fow/shader/screenSpaceFogOfWarShader.js +2 -10
- package/engine/ecs/grid/NormalMap2AOMap.js +10 -13
- package/engine/ecs/terrain/ecs/BuildLightTexture.js +106 -0
- package/engine/ecs/terrain/ecs/PromiseSamplerHeight.js +59 -0
- package/engine/ecs/terrain/ecs/Terrain.js +14 -153
- package/engine/graphics/FULL_SCREEN_QUAD_VERTEX_SHADER.js +10 -0
- package/engine/graphics/filter/ImageFilter.js +6 -2
- package/engine/graphics/geometry/AttributeSpec.d.ts +8 -0
- package/engine/graphics/geometry/VertexDataSpec.d.ts +15 -0
- package/engine/graphics/geometry/buffered/deinterleaveBufferAttribute.js +39 -0
- package/engine/graphics/geometry/buffered/deinterleaveBufferGeometry.js +50 -0
- package/engine/graphics/geometry/buffered/query/ClippingPlaneContainmentComputingVisitor.js +28 -27
- package/engine/graphics/geometry/buffered/query/GeometryVisitor.js +29 -2
- package/engine/graphics/geometry/buffered/query/RaycastNearestHitComputingVisitor.js +28 -27
- package/engine/graphics/micron/MICRON_GEOMETRY_FIELD.js +1 -0
- package/engine/graphics/micron/MICRON_URI_FIELD.js +1 -0
- package/engine/graphics/micron/build/buildMicronGeometryFromBufferGeometry.js +10 -7
- package/engine/graphics/micron/convert_three_object_to_micron.js +31 -5
- package/engine/graphics/micron/format/MicronGeometry.d.ts +4 -0
- package/engine/graphics/micron/format/MicronGeometry.js +6 -0
- package/engine/graphics/micron/plugin/MicronRenderPlugin.js +110 -6
- package/engine/graphics/particles/particular/engine/utils/volume/prototypeParticleVolume.js +3 -1
- package/engine/graphics/render/webgpu/sample/MeshInstance.js +9 -0
- package/engine/graphics/render/webgpu/sample/main.js +2 -2
- package/engine/graphics/shaders/AmbientOcclusionShader.js +57 -77
- package/engine/graphics/shaders/DenoiseShader.js +119 -0
- package/engine/graphics/texture/noise_octaves.js +33 -0
- package/engine/graphics/texture/sampler/Sampler2D2Texture.js +7 -18
- package/engine/graphics/texture/sampler/debug/paintSamplerOnHTML.js +8 -5
- package/engine/graphics/texture/sampler/sampler2DToFloat32Texture.js +10 -3
- package/generation/example/filters/SampleGroundMoistureFilter.js +2 -1
- package/generation/filtering/numeric/complex/CellFilterGaussianBlur.js +29 -13
- package/generation/grid/GridData.js +17 -2
- package/package.json +1 -1
- package/util/ScreenGridPicker.js +0 -3
|
@@ -14,9 +14,6 @@ import {
|
|
|
14
14
|
} from 'three';
|
|
15
15
|
import { clamp } from "../../../../core/math/clamp.js";
|
|
16
16
|
import { Sampler2D } from '../../../graphics/texture/sampler/Sampler2D.js';
|
|
17
|
-
import heightMap2NormalMap from '../../grid/HeightMap2NormalMap.js';
|
|
18
|
-
import normalMap2AOMap from '../../grid/NormalMap2AOMap.js';
|
|
19
|
-
import rgbaData2valueSampler2D from '../../../graphics/texture/sampler/rgbaData2valueSampler2D.js';
|
|
20
17
|
import { BinaryNode } from '../../../../core/bvh2/BinaryNode.js';
|
|
21
18
|
import Vector2 from '../../../../core/geom/Vector2.js';
|
|
22
19
|
import { TerrainOverlay } from '../overlay/TerrainOverlay.js';
|
|
@@ -24,13 +21,9 @@ import { TerrainOverlay } from '../overlay/TerrainOverlay.js';
|
|
|
24
21
|
import Clouds from '../TerrainClouds.js';
|
|
25
22
|
|
|
26
23
|
import TerrainTileManager from '../tiles/TerrainTileManager.js';
|
|
27
|
-
import { WebGLRendererPool } from "../../../graphics/render/RendererPool.js";
|
|
28
|
-
import { deserializeTexture } from "../../../graphics/texture/sampler/TextureBinaryBufferSerializer.js";
|
|
29
|
-
import { BinaryBuffer } from "../../../../core/binary/BinaryBuffer.js";
|
|
30
24
|
import { TerrainPreview } from "../TerrainPreview.js";
|
|
31
25
|
import { assert } from "../../../../core/assert.js";
|
|
32
26
|
import { GameAssetType } from "../../../asset/GameAssetType.js";
|
|
33
|
-
import { writeSample2DDataToDataTexture } from "../../../graphics/texture/sampler/writeSampler2DDataToDataTexture.js";
|
|
34
27
|
import { TerrainLayers } from "./layers/TerrainLayers.js";
|
|
35
28
|
import { SplatMaterial } from "../../../graphics/material/SplatMaterial.js";
|
|
36
29
|
import { loadLegacyTerrainSplats, SplatMapping } from "./splat/SplatMapping.js";
|
|
@@ -41,147 +34,8 @@ import { MeepSettings } from "../../../MeepSettings.js";
|
|
|
41
34
|
import { loadLegacyTerrainLayers } from "./layers/loadLegacyTerrainLayers.js";
|
|
42
35
|
import { TerrainFlags } from "./TerrainFlags.js";
|
|
43
36
|
import { IllegalStateException } from "../../../../core/fsm/exceptions/IllegalStateException.js";
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
*
|
|
47
|
-
* @param zRange
|
|
48
|
-
* @param heightMapURL
|
|
49
|
-
* @param {AssetManager} assetManager
|
|
50
|
-
* @returns {Promise<any>}
|
|
51
|
-
*/
|
|
52
|
-
function promiseSamplerHeight(zRange, heightMapURL, assetManager) {
|
|
53
|
-
return new Promise(function (fulfill, reject) {
|
|
54
|
-
|
|
55
|
-
function assetObtained(asset) {
|
|
56
|
-
const array = asset.create();
|
|
57
|
-
|
|
58
|
-
const binaryBuffer = new BinaryBuffer();
|
|
59
|
-
//
|
|
60
|
-
// binaryBuffer.writeUint32(2560);
|
|
61
|
-
// binaryBuffer.writeUint32(2560);
|
|
62
|
-
//
|
|
63
|
-
// binaryBuffer.writeUint8(1);
|
|
64
|
-
//
|
|
65
|
-
// binaryBuffer.writeUint8(6);
|
|
66
|
-
|
|
67
|
-
binaryBuffer.writeBytes(new Uint8Array(array), 0, array.length);
|
|
68
|
-
|
|
69
|
-
binaryBuffer.position = 0;
|
|
70
|
-
|
|
71
|
-
const sampler2D = deserializeTexture(binaryBuffer);
|
|
72
|
-
fulfill(sampler2D);
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
if (heightMapURL === undefined) {
|
|
77
|
-
console.warn('Height map is not specified');
|
|
78
|
-
const defaultSampler = new Sampler2D(new Uint8Array(1), 1, 1, 1);
|
|
79
|
-
fulfill(defaultSampler);
|
|
80
|
-
} else if (heightMapURL.endsWith('.bin')) {
|
|
81
|
-
//load texture from a binary file
|
|
82
|
-
assetManager.get(heightMapURL, GameAssetType.ArrayBuffer, assetObtained, reject);
|
|
83
|
-
} else {
|
|
84
|
-
assetManager.get(heightMapURL, GameAssetType.Image, function (asset) {
|
|
85
|
-
const image = asset.create();
|
|
86
|
-
|
|
87
|
-
// plane
|
|
88
|
-
const imgWidth = image.width;
|
|
89
|
-
const imgHeight = image.height;
|
|
90
|
-
|
|
91
|
-
const samplerHeight = rgbaData2valueSampler2D(image.data, imgWidth, imgHeight, zRange, -zRange / 2);
|
|
92
|
-
|
|
93
|
-
fulfill(samplerHeight);
|
|
94
|
-
}, reject);
|
|
95
|
-
}
|
|
96
|
-
});
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
/**
|
|
100
|
-
*
|
|
101
|
-
* @param {WebGLRenderer} renderer
|
|
102
|
-
* @param {Sampler2D} sampler
|
|
103
|
-
* @returns {Promise<Sampler2D>}
|
|
104
|
-
*/
|
|
105
|
-
function promiseSamplerNormal(renderer, sampler) {
|
|
106
|
-
|
|
107
|
-
console.time("generating normal map");
|
|
108
|
-
const normalSampler = heightMap2NormalMap(renderer, sampler);
|
|
109
|
-
console.timeEnd("generating normal map");
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
return Promise.resolve(normalSampler);
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
/**
|
|
116
|
-
*
|
|
117
|
-
* @param {WebGLRenderer} renderer
|
|
118
|
-
* @param {Promise<Sampler2D>} pSamplerNormal
|
|
119
|
-
* @param {Sampler2D} samplerHeight
|
|
120
|
-
* @param {Vector2} resolution
|
|
121
|
-
* @param {number} rayLength
|
|
122
|
-
* @returns {Promise<unknown>}
|
|
123
|
-
*/
|
|
124
|
-
function promiseSamplerAO(
|
|
125
|
-
renderer,
|
|
126
|
-
pSamplerNormal,
|
|
127
|
-
samplerHeight,
|
|
128
|
-
resolution,
|
|
129
|
-
rayLength
|
|
130
|
-
) {
|
|
131
|
-
return new Promise(function (resolve, reject) {
|
|
132
|
-
Promise.all([pSamplerNormal]).then(function (values) {
|
|
133
|
-
const samplerNormal = values[0];
|
|
134
|
-
console.time("generating AO map");
|
|
135
|
-
const occlusionSampler = normalMap2AOMap(
|
|
136
|
-
renderer,
|
|
137
|
-
samplerHeight,
|
|
138
|
-
samplerNormal,
|
|
139
|
-
resolution,
|
|
140
|
-
rayLength
|
|
141
|
-
);
|
|
142
|
-
console.timeEnd("generating AO map");
|
|
143
|
-
//console.info(occlusionSampler);
|
|
144
|
-
//
|
|
145
|
-
// paintSamplerOnHTML(samplerHeight, 0, 0, 40, 3);
|
|
146
|
-
// paintSamplerOnHTML(samplerNormal, 1, 0, 128, 1);
|
|
147
|
-
// paintSamplerOnHTML(occlusionSampler, 2, 0, 1, 0);
|
|
148
|
-
//
|
|
149
|
-
//
|
|
150
|
-
resolve(occlusionSampler);
|
|
151
|
-
}, reject);
|
|
152
|
-
});
|
|
153
|
-
}
|
|
154
|
-
|
|
155
|
-
/**
|
|
156
|
-
*
|
|
157
|
-
* @param {DataTexture} texture
|
|
158
|
-
* @param {Vector2} resolution
|
|
159
|
-
* @param {Sampler2D} heightSampler
|
|
160
|
-
* @param {number} heightRange
|
|
161
|
-
* @param {number} [rayLength]
|
|
162
|
-
* @returns {Promise}
|
|
163
|
-
*/
|
|
164
|
-
function buildLightTexture({ texture, heightSampler, resolution, rayLength = 17 }) {
|
|
165
|
-
|
|
166
|
-
const renderer = WebGLRendererPool.global.get();
|
|
167
|
-
|
|
168
|
-
if (resolution === undefined) {
|
|
169
|
-
resolution = new Vector2(texture.image.width, texture.image.height);
|
|
170
|
-
}
|
|
171
|
-
|
|
172
|
-
const normal = promiseSamplerNormal(renderer, heightSampler);
|
|
173
|
-
const ao = promiseSamplerAO(renderer, normal, heightSampler, resolution, rayLength);
|
|
174
|
-
|
|
175
|
-
const promise = ao.then(sampler => {
|
|
176
|
-
writeSample2DDataToDataTexture(sampler, texture);
|
|
177
|
-
});
|
|
178
|
-
|
|
179
|
-
Promise.all([normal, ao]).finally(() => {
|
|
180
|
-
WebGLRendererPool.global.release(renderer);
|
|
181
|
-
});
|
|
182
|
-
|
|
183
|
-
return promise;
|
|
184
|
-
}
|
|
37
|
+
import { buildLightTexture } from "./BuildLightTexture.js";
|
|
38
|
+
import { promiseSamplerHeight } from "./PromiseSamplerHeight.js";
|
|
185
39
|
|
|
186
40
|
let idCounter = 0;
|
|
187
41
|
|
|
@@ -903,13 +757,13 @@ class Terrain {
|
|
|
903
757
|
this.updateWorkerHeights();
|
|
904
758
|
}
|
|
905
759
|
|
|
906
|
-
updateWorkerHeights() {
|
|
760
|
+
async updateWorkerHeights() {
|
|
907
761
|
const s = this.samplerHeight;
|
|
908
762
|
const worker = this.buildWorker;
|
|
909
763
|
|
|
910
|
-
worker.setHeightSampler(s.data, s.itemSize, s.width, s.height);
|
|
764
|
+
await worker.setHeightSampler(s.data, s.itemSize, s.width, s.height);
|
|
911
765
|
|
|
912
|
-
|
|
766
|
+
return await worker.computeHeightRange()
|
|
913
767
|
.then(({ min, max }) => {
|
|
914
768
|
this.tiles.setHeightRange(min, max);
|
|
915
769
|
});
|
|
@@ -1012,7 +866,12 @@ class Terrain {
|
|
|
1012
866
|
this.setFlag(TerrainFlags.Built);
|
|
1013
867
|
}
|
|
1014
868
|
|
|
1015
|
-
|
|
869
|
+
/**
|
|
870
|
+
*
|
|
871
|
+
* @param {number} quality resolution in texels per grid cell (4 = 4x4 light map texels per single grid cell)
|
|
872
|
+
* @return {Promise<DataTexture>}
|
|
873
|
+
*/
|
|
874
|
+
buildLightMap(quality = 4) {
|
|
1016
875
|
|
|
1017
876
|
|
|
1018
877
|
const size_x = this.size.x;
|
|
@@ -1035,7 +894,9 @@ class Terrain {
|
|
|
1035
894
|
|
|
1036
895
|
const promise = buildLightTexture({
|
|
1037
896
|
texture,
|
|
1038
|
-
heightSampler: this.samplerHeight
|
|
897
|
+
heightSampler: this.samplerHeight,
|
|
898
|
+
worldSize: new Vector2(size_x * this.gridScale, size_y * this.gridScale),
|
|
899
|
+
resolution: new Vector2(size_x * quality, size_y *quality)
|
|
1039
900
|
});
|
|
1040
901
|
|
|
1041
902
|
|
|
@@ -5,13 +5,14 @@
|
|
|
5
5
|
|
|
6
6
|
import { LinearFilter, Mesh, OrthographicCamera, Scene, ShaderMaterial, WebGLRenderTarget } from 'three';
|
|
7
7
|
import { FULL_SCREEN_TRIANGLE_GEOMETRY } from "../geometry/FULL_SCREEN_TRIANGLE_GEOMETRY.js";
|
|
8
|
+
import { FULL_SCREEN_QUAD_VERTEX_SHADER } from "../FULL_SCREEN_QUAD_VERTEX_SHADER.js";
|
|
8
9
|
|
|
9
10
|
/**
|
|
10
11
|
*
|
|
11
12
|
* @param {WebGLRenderer} renderer
|
|
12
13
|
* @param {number} width
|
|
13
14
|
* @param {number} height
|
|
14
|
-
* @param {{vertexShader
|
|
15
|
+
* @param {{vertexShader?:string,fragmentShader:string, uniforms?:Object, defines?:Object}} processShader
|
|
15
16
|
* @param {Uint8Array} [destination]
|
|
16
17
|
* @return {{array: Uint8Array, renderer: WebGLRenderer}}
|
|
17
18
|
*/
|
|
@@ -34,9 +35,12 @@ function processTexture(
|
|
|
34
35
|
scene.add(camera);
|
|
35
36
|
|
|
36
37
|
//make a quad to render
|
|
37
|
-
const material = new ShaderMaterial(processShader);
|
|
38
|
+
const material = new ShaderMaterial(Object.assign({ vertexShader: FULL_SCREEN_QUAD_VERTEX_SHADER }, processShader));
|
|
39
|
+
|
|
38
40
|
material.lights = false;
|
|
39
41
|
material.fog = false;
|
|
42
|
+
material.uniformsNeedUpdate = true;
|
|
43
|
+
material.needsUpdate = true;
|
|
40
44
|
|
|
41
45
|
const quad = new Mesh(FULL_SCREEN_TRIANGLE_GEOMETRY, material);
|
|
42
46
|
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import {AttributeSpec} from "./AttributeSpec";
|
|
2
|
+
|
|
3
|
+
export class VertexDataSpec {
|
|
4
|
+
readonly attributes: AttributeSpec[]
|
|
5
|
+
|
|
6
|
+
getAttributeByName(name: string): AttributeSpec | undefined
|
|
7
|
+
|
|
8
|
+
add(attribute: AttributeSpec): this
|
|
9
|
+
|
|
10
|
+
setAttributes(attributes: AttributeSpec[]): void
|
|
11
|
+
|
|
12
|
+
equals(other: VertexDataSpec): boolean
|
|
13
|
+
|
|
14
|
+
hash(): number
|
|
15
|
+
}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { BufferAttribute } from "three";
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
*
|
|
6
|
+
* @param {THREE.InterleavedBufferAttribute|THREE.BufferAttribute} source_attribute
|
|
7
|
+
* @returns {THREE.BufferAttribute}
|
|
8
|
+
*/
|
|
9
|
+
export function deinterleaveBufferAttribute(source_attribute) {
|
|
10
|
+
if (source_attribute.isInterleavedBufferAttribute !== true && source_attribute.isBufferAttribute) {
|
|
11
|
+
return source_attribute;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
const source_data = source_attribute.data;
|
|
15
|
+
const source_data_array = source_data.array;
|
|
16
|
+
const stride = source_data.stride;
|
|
17
|
+
|
|
18
|
+
const item_count = source_attribute.count;
|
|
19
|
+
const itemSize = source_attribute.itemSize;
|
|
20
|
+
const array_size = item_count * itemSize;
|
|
21
|
+
|
|
22
|
+
const offset = source_attribute.offset;
|
|
23
|
+
|
|
24
|
+
const destination_array = new source_data_array.constructor(array_size);
|
|
25
|
+
|
|
26
|
+
const attribute = new BufferAttribute(destination_array, itemSize);
|
|
27
|
+
|
|
28
|
+
attribute.normalized = source_attribute.normalized;
|
|
29
|
+
attribute.name = source_attribute.name;
|
|
30
|
+
|
|
31
|
+
// copy data
|
|
32
|
+
for (let i = 0; i < item_count; i++) {
|
|
33
|
+
for (let j = 0; j < itemSize; j++) {
|
|
34
|
+
destination_array[i * itemSize + j] = source_data_array[i * stride + offset + j];
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
return attribute;
|
|
39
|
+
}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { BufferGeometry } from "three";
|
|
2
|
+
import { deinterleaveBufferAttribute } from "./deinterleaveBufferAttribute.js";
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
*
|
|
6
|
+
* @param {THREE.BufferGeometry} geometry
|
|
7
|
+
* @returns {THREE.BufferGeometry}
|
|
8
|
+
*/
|
|
9
|
+
export function deinterleaveBufferGeometry(geometry) {
|
|
10
|
+
const result = new BufferGeometry();
|
|
11
|
+
|
|
12
|
+
if (geometry.getIndex() !== null) {
|
|
13
|
+
result.setIndex(deinterleaveBufferAttribute(geometry.getIndex()));
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
for (const attribute_key in geometry.attributes) {
|
|
17
|
+
const source_attribute = geometry.attributes[attribute_key];
|
|
18
|
+
|
|
19
|
+
result.setAttribute(attribute_key, deinterleaveBufferAttribute(source_attribute));
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
// copy other bits
|
|
23
|
+
result.name = geometry.name;
|
|
24
|
+
|
|
25
|
+
result.morphTargetsRelative = geometry.morphTargetsRelative;
|
|
26
|
+
|
|
27
|
+
for (const attribute_key in geometry.morphAttributes) {
|
|
28
|
+
const source_attributes = geometry.morphAttributes[attribute_key];
|
|
29
|
+
|
|
30
|
+
const result_attributes = [];
|
|
31
|
+
|
|
32
|
+
result.morphAttributes[attribute_key] = result_attributes;
|
|
33
|
+
|
|
34
|
+
for (let i = 0; i < source_attributes.length; i++) {
|
|
35
|
+
const source_attribute = source_attributes[i];
|
|
36
|
+
result_attributes[i] = deinterleaveBufferAttribute(source_attribute);
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
result.groups = geometry.groups.slice();
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
result.boundingBox = geometry.boundingBox !== null ? geometry.boundingBox.clone() : null;
|
|
44
|
+
result.boundingSphere = geometry.boundingSphere !== null ? geometry.boundingSphere.clone() : null;
|
|
45
|
+
result.drawRange.start = geometry.drawRange.start;
|
|
46
|
+
result.drawRange.count = geometry.drawRange.count;
|
|
47
|
+
result.userData = JSON.parse(JSON.stringify(geometry.userData));
|
|
48
|
+
|
|
49
|
+
return result;
|
|
50
|
+
}
|
|
@@ -79,21 +79,32 @@ export class ClippingPlaneContainmentComputingVisitor extends GeometrySpatialAcc
|
|
|
79
79
|
|
|
80
80
|
const index3 = index * 3;
|
|
81
81
|
|
|
82
|
-
const
|
|
83
|
-
const b = this.__buffer_indices[index3 + 1] * 3;
|
|
84
|
-
const c = this.__buffer_indices[index3 + 2] * 3;
|
|
82
|
+
const indices = this.__buffer_indices;
|
|
85
83
|
|
|
86
|
-
const
|
|
87
|
-
const
|
|
88
|
-
const
|
|
84
|
+
const a = indices[index3];
|
|
85
|
+
const b = indices[index3 + 1];
|
|
86
|
+
const c = indices[index3 + 2];
|
|
89
87
|
|
|
90
|
-
const
|
|
91
|
-
const by = this.__buffer_vertices[b + 1];
|
|
92
|
-
const bz = this.__buffer_vertices[b + 2];
|
|
88
|
+
const vertices = this.__buffer_vertices;
|
|
93
89
|
|
|
94
|
-
const
|
|
95
|
-
const
|
|
96
|
-
|
|
90
|
+
const stride = this.__buffer_vertex_stride;
|
|
91
|
+
const offset = this.__buffer_position_offset;
|
|
92
|
+
|
|
93
|
+
const a_address = a * stride + offset;
|
|
94
|
+
const b_address = b * stride + offset;
|
|
95
|
+
const c_address = c * stride + offset;
|
|
96
|
+
|
|
97
|
+
const ax = vertices[a_address];
|
|
98
|
+
const ay = vertices[a_address + 1];
|
|
99
|
+
const az = vertices[a_address + 2];
|
|
100
|
+
|
|
101
|
+
const bx = vertices[b_address];
|
|
102
|
+
const by = vertices[b_address + 1];
|
|
103
|
+
const bz = vertices[b_address + 2];
|
|
104
|
+
|
|
105
|
+
const cx = vertices[c_address];
|
|
106
|
+
const cy = vertices[c_address + 1];
|
|
107
|
+
const cz = vertices[c_address + 2];
|
|
97
108
|
|
|
98
109
|
for (let i = 0; i < plane_count; i++) {
|
|
99
110
|
const plane = planes[i];
|
|
@@ -108,15 +119,9 @@ export class ClippingPlaneContainmentComputingVisitor extends GeometrySpatialAcc
|
|
|
108
119
|
plane_normal_y,
|
|
109
120
|
plane_normal_z,
|
|
110
121
|
plane_constant,
|
|
111
|
-
ax,
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
bx,
|
|
115
|
-
by,
|
|
116
|
-
bz,
|
|
117
|
-
cx,
|
|
118
|
-
cy,
|
|
119
|
-
cz
|
|
122
|
+
ax, ay, az,
|
|
123
|
+
bx, by, bz,
|
|
124
|
+
cx, cy, cz
|
|
120
125
|
);
|
|
121
126
|
|
|
122
127
|
if (side === -3) {
|
|
@@ -163,12 +168,8 @@ export class ClippingPlaneContainmentComputingVisitor extends GeometrySpatialAcc
|
|
|
163
168
|
plane_normal_z,
|
|
164
169
|
plane_constant,
|
|
165
170
|
|
|
166
|
-
x0,
|
|
167
|
-
|
|
168
|
-
z0,
|
|
169
|
-
x1,
|
|
170
|
-
y1,
|
|
171
|
-
z1
|
|
171
|
+
x0, y0, z0,
|
|
172
|
+
x1, y1, z1
|
|
172
173
|
);
|
|
173
174
|
|
|
174
175
|
if (side === -2) {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { IndexedBinaryBVHVisitor } from "../../../../../core/bvh2/binary/IndexedBinaryBVHVisitor.js";
|
|
2
2
|
|
|
3
|
-
export class GeometrySpatialAcceleratorVisitor extends IndexedBinaryBVHVisitor{
|
|
3
|
+
export class GeometrySpatialAcceleratorVisitor extends IndexedBinaryBVHVisitor {
|
|
4
4
|
constructor() {
|
|
5
5
|
super();
|
|
6
6
|
|
|
@@ -25,6 +25,20 @@ export class GeometrySpatialAcceleratorVisitor extends IndexedBinaryBVHVisitor{
|
|
|
25
25
|
*/
|
|
26
26
|
this.__buffer_vertices = null;
|
|
27
27
|
|
|
28
|
+
/**
|
|
29
|
+
*
|
|
30
|
+
* @type {number}
|
|
31
|
+
* @protected
|
|
32
|
+
*/
|
|
33
|
+
this.__buffer_vertex_stride = 3;
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
*
|
|
37
|
+
* @type {number}
|
|
38
|
+
* @protected
|
|
39
|
+
*/
|
|
40
|
+
this.__buffer_position_offset = 0;
|
|
41
|
+
|
|
28
42
|
/**
|
|
29
43
|
* @protected
|
|
30
44
|
* @type {IndexedBinaryBVH}
|
|
@@ -47,7 +61,20 @@ export class GeometrySpatialAcceleratorVisitor extends IndexedBinaryBVHVisitor{
|
|
|
47
61
|
this.geometry = geometry;
|
|
48
62
|
|
|
49
63
|
this.__buffer_indices = geometry.getIndex().array;
|
|
50
|
-
|
|
64
|
+
|
|
65
|
+
const position_attribute = geometry.getAttribute('position');
|
|
66
|
+
|
|
67
|
+
if (position_attribute.isInterleavedBufferAttribute) {
|
|
68
|
+
const data = position_attribute.data;
|
|
69
|
+
|
|
70
|
+
this.__buffer_vertices = data.array;
|
|
71
|
+
this.__buffer_vertex_stride = data.stride;
|
|
72
|
+
this.__buffer_position_offset = position_attribute.offset;
|
|
73
|
+
} else {
|
|
74
|
+
this.__buffer_vertices = position_attribute.array;
|
|
75
|
+
this.__buffer_vertex_stride = 3;
|
|
76
|
+
this.__buffer_position_offset = 0;
|
|
77
|
+
}
|
|
51
78
|
}
|
|
52
79
|
|
|
53
80
|
}
|
|
@@ -96,21 +96,32 @@ export class RaycastNearestHitComputingVisitor extends GeometrySpatialAccelerato
|
|
|
96
96
|
|
|
97
97
|
const index3 = index * 3;
|
|
98
98
|
|
|
99
|
-
const
|
|
100
|
-
const b = this.__buffer_indices[index3 + 1] * 3;
|
|
101
|
-
const c = this.__buffer_indices[index3 + 2] * 3;
|
|
99
|
+
const indices = this.__buffer_indices;
|
|
102
100
|
|
|
103
|
-
const
|
|
104
|
-
const
|
|
105
|
-
const
|
|
101
|
+
const a = indices[index3];
|
|
102
|
+
const b = indices[index3 + 1];
|
|
103
|
+
const c = indices[index3 + 2];
|
|
106
104
|
|
|
107
|
-
const
|
|
108
|
-
const by = this.__buffer_vertices[b + 1];
|
|
109
|
-
const bz = this.__buffer_vertices[b + 2];
|
|
105
|
+
const vertices = this.__buffer_vertices;
|
|
110
106
|
|
|
111
|
-
const
|
|
112
|
-
const
|
|
113
|
-
|
|
107
|
+
const stride = this.__buffer_vertex_stride;
|
|
108
|
+
const offset = this.__buffer_position_offset;
|
|
109
|
+
|
|
110
|
+
const a_address = a * stride + offset;
|
|
111
|
+
const b_address = b * stride + offset;
|
|
112
|
+
const c_address = c * stride + offset;
|
|
113
|
+
|
|
114
|
+
const ax = vertices[a_address];
|
|
115
|
+
const ay = vertices[a_address + 1];
|
|
116
|
+
const az = vertices[a_address + 2];
|
|
117
|
+
|
|
118
|
+
const bx = vertices[b_address];
|
|
119
|
+
const by = vertices[b_address + 1];
|
|
120
|
+
const bz = vertices[b_address + 2];
|
|
121
|
+
|
|
122
|
+
const cx = vertices[c_address];
|
|
123
|
+
const cy = vertices[c_address + 1];
|
|
124
|
+
const cz = vertices[c_address + 2];
|
|
114
125
|
|
|
115
126
|
if (computeTriangleRayIntersection(
|
|
116
127
|
this.__temp_hit,
|
|
@@ -120,15 +131,9 @@ export class RaycastNearestHitComputingVisitor extends GeometrySpatialAccelerato
|
|
|
120
131
|
rayDirection.x,
|
|
121
132
|
rayDirection.y,
|
|
122
133
|
rayDirection.z,
|
|
123
|
-
ax,
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
bx,
|
|
127
|
-
by,
|
|
128
|
-
bz,
|
|
129
|
-
cx,
|
|
130
|
-
cy,
|
|
131
|
-
cz
|
|
134
|
+
ax, ay, az,
|
|
135
|
+
bx, by, bz,
|
|
136
|
+
cx, cy, cz
|
|
132
137
|
)) {
|
|
133
138
|
const d = this.__temp_hit.position.distanceSqrTo(rayOrigin);
|
|
134
139
|
|
|
@@ -154,12 +159,8 @@ export class RaycastNearestHitComputingVisitor extends GeometrySpatialAccelerato
|
|
|
154
159
|
const z1 = data[address + 5];
|
|
155
160
|
|
|
156
161
|
return intersectRay(
|
|
157
|
-
x0,
|
|
158
|
-
|
|
159
|
-
z0,
|
|
160
|
-
x1,
|
|
161
|
-
y1,
|
|
162
|
-
z1,
|
|
162
|
+
x0, y0, z0,
|
|
163
|
+
x1, y1, z1,
|
|
163
164
|
|
|
164
165
|
rayOrigin.x,
|
|
165
166
|
rayOrigin.y,
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export const MICRON_GEOMETRY_FIELD = '@micron_geometry';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export const MICRON_URI_FIELD = '@micron_path';
|
|
@@ -12,6 +12,7 @@ import { expandConnectivityByLocality } from "../../../../core/geom/3d/topology/
|
|
|
12
12
|
import { build_geometry_info } from "./build_geometry_info.js";
|
|
13
13
|
import { build_leaf_patches_metis } from "./clustering/build_leaf_patches_metis.js";
|
|
14
14
|
import { compute_buffer_geometry_byte_size } from "../../geometry/buffered/compute_buffer_geometry_byte_size.js";
|
|
15
|
+
import { deinterleaveBufferGeometry } from "../../geometry/buffered/deinterleaveBufferGeometry.js";
|
|
15
16
|
|
|
16
17
|
/**
|
|
17
18
|
* Returns current time in milliseconds
|
|
@@ -105,11 +106,13 @@ const PRINT_VERBOSE_STATS = false;
|
|
|
105
106
|
* @returns {MicronGeometry}
|
|
106
107
|
*/
|
|
107
108
|
export async function buildMicronGeometryFromBufferGeometry(input) {
|
|
109
|
+
const source_geometry = deinterleaveBufferGeometry(input);
|
|
110
|
+
|
|
108
111
|
// build topology representation
|
|
109
112
|
const topoMesh = new TopoMesh();
|
|
110
113
|
|
|
111
|
-
const position_attribute =
|
|
112
|
-
const index_attribute =
|
|
114
|
+
const position_attribute = source_geometry.getAttribute("position");
|
|
115
|
+
const index_attribute = source_geometry.index;
|
|
113
116
|
|
|
114
117
|
const face_index_array = index_attribute.array;
|
|
115
118
|
const vertex_position_array = position_attribute.array;
|
|
@@ -183,18 +186,18 @@ export async function buildMicronGeometryFromBufferGeometry(input) {
|
|
|
183
186
|
|
|
184
187
|
const r = new MicronGeometry();
|
|
185
188
|
|
|
186
|
-
r.proxy =
|
|
189
|
+
r.proxy = source_geometry; // TODO use r.buildProxy(1) instead
|
|
187
190
|
|
|
188
191
|
r.source_triangle_count = index_attribute.count / 3;
|
|
189
|
-
r.source_vertex_count =
|
|
190
|
-
r.source_byte_size = compute_buffer_geometry_byte_size(
|
|
192
|
+
r.source_vertex_count = source_geometry.getAttribute('position').count;
|
|
193
|
+
r.source_byte_size = compute_buffer_geometry_byte_size(source_geometry);
|
|
191
194
|
|
|
192
195
|
// console.time('build geometry');
|
|
193
196
|
|
|
194
|
-
const vertex_attributes = attributes_from_buffer_geometry(
|
|
197
|
+
const vertex_attributes = attributes_from_buffer_geometry(source_geometry);
|
|
195
198
|
|
|
196
199
|
r.vertex_spec.setAttributes(vertex_attributes);
|
|
197
|
-
r.root = compilePatchGraph(root,
|
|
200
|
+
r.root = compilePatchGraph(root, source_geometry, r.vertex_spec);
|
|
198
201
|
|
|
199
202
|
r.initialize();
|
|
200
203
|
|