@woosh/meep-engine 2.33.4 → 2.33.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/core/bvh2/aabb3/AABB3.js +4 -1
- package/core/collection/array/copyArray.js +2 -2
- package/core/collection/table/RowFirstTableSpec.js +8 -0
- package/core/geom/3d/aabb/aabb3_compute_projected_area.js +1 -0
- package/core/geom/3d/aabb/aabb3_estimate_projected_area2.js +59 -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/engine/graphics/GraphicsEngine.js +9 -116
- 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/format/MicronGeometryBufferAttributeSpec.js +1 -1
- package/engine/graphics/micron/prototypeVirtualGeometry.js +1 -1
- package/engine/graphics/micron/render/VirtualGeometryBuilder.js +5 -17
- package/engine/graphics/micron/render/instanced/AttributeDataTexture.js +2 -4
- package/engine/graphics/micron/render/refinement/ActivePatchList.js +33 -25
- package/engine/graphics/micron/render/refinement/ActivePatchRecord.js +4 -2
- 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/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/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 +137 -0
- package/engine/graphics/texture/sampler/convertTexture2Sampler2D.js +3 -2
- package/engine/graphics/texture/virtual/v2/ShaderUsage.js +6 -5
- package/engine/graphics/texture/virtual/v2/prototype.js +16 -6
- package/package.json +1 -1
package/core/bvh2/aabb3/AABB3.js
CHANGED
|
@@ -8,6 +8,7 @@ import { computeAABB3PlaneSide } from "../../geom/3d/aabb/computeAABB3PlaneSide.
|
|
|
8
8
|
import computeMortonCode from "../../geom/3d/morton/Morton.js";
|
|
9
9
|
import { _boxSurfaceArea2, intersectRay, intersectSegment } from "./AABB3Math.js";
|
|
10
10
|
import { aabb3_build_corners } from "../../geom/3d/aabb/aabb3_build_corners.js";
|
|
11
|
+
import { assert } from "../../assert.js";
|
|
11
12
|
|
|
12
13
|
|
|
13
14
|
/**
|
|
@@ -724,7 +725,9 @@ AABB3.prototype.getCorners = function (result) {
|
|
|
724
725
|
* @param {number} offset
|
|
725
726
|
*/
|
|
726
727
|
AABB3.prototype.writeToArray = function (result, offset) {
|
|
727
|
-
|
|
728
|
+
assert.isNonNegativeInteger(offset, 'offset');
|
|
729
|
+
|
|
730
|
+
result[offset] = this.x0;
|
|
728
731
|
result[offset + 1] = this.y0;
|
|
729
732
|
result[offset + 2] = this.z0;
|
|
730
733
|
|
|
@@ -25,9 +25,9 @@ export function copyArray(source, target) {
|
|
|
25
25
|
* Follows Java System.arraycopy interface
|
|
26
26
|
* Copy data from one array to another
|
|
27
27
|
* @template T
|
|
28
|
-
* @param {T[]|ArrayLike<T>|TypedArray} source The source array
|
|
28
|
+
* @param {T[]|ArrayLike<T>|TypedArray|Uint8ClampedArray|Uint8Array} source The source array
|
|
29
29
|
* @param {number} source_position Starting position where to copy from inside the source array
|
|
30
|
-
* @param {T[]|ArrayLike<T>|TypedArray} destination The destination array
|
|
30
|
+
* @param {T[]|ArrayLike<T>|TypedArray|Uint8ClampedArray|Uint8Array} destination The destination array
|
|
31
31
|
* @param {number} destination_position Starting position where to copy to inside the destination array
|
|
32
32
|
* @param {number} length How many elements should be copied
|
|
33
33
|
*/
|
|
@@ -234,6 +234,14 @@ export function RowFirstTableSpec(types, endianType = EndianType.BigEndian) {
|
|
|
234
234
|
}
|
|
235
235
|
}
|
|
236
236
|
|
|
237
|
+
/**
|
|
238
|
+
*
|
|
239
|
+
* @return {number}
|
|
240
|
+
*/
|
|
241
|
+
RowFirstTableSpec.prototype.getColumnCount = function () {
|
|
242
|
+
return this.types.length;
|
|
243
|
+
}
|
|
244
|
+
|
|
237
245
|
/**
|
|
238
246
|
*
|
|
239
247
|
* @param {RowFirstTableSpec} other
|
|
@@ -10,6 +10,7 @@
|
|
|
10
10
|
|
|
11
11
|
|
|
12
12
|
/**
|
|
13
|
+
* NOTE: Consider using an optimized aabb projection method based on Jim Arvo's Graphics Gems algorithm: https://stackoverflow.com/a/58630206/3973586
|
|
13
14
|
* Almost everything is inlined for speed
|
|
14
15
|
* @param {number[]} aabb_corners
|
|
15
16
|
* @param {number[]|mat4|Float32Array} projection_matrix
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
const scratch_aabb = new Float32Array(4);
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* NOTE: tends to overestimate the area
|
|
6
|
+
* @param {number[]} aabb
|
|
7
|
+
* @param {number[]} matrix
|
|
8
|
+
* @return {number}
|
|
9
|
+
*/
|
|
10
|
+
export function aabb3_estimate_projected_area2(aabb, matrix) {
|
|
11
|
+
// extract translation from matrix
|
|
12
|
+
scratch_aabb[0] = scratch_aabb[2] = matrix[12];
|
|
13
|
+
scratch_aabb[1] = scratch_aabb[3] = matrix[13];
|
|
14
|
+
|
|
15
|
+
// apply 3x3 matrix transform
|
|
16
|
+
for (let i = 0; i < 2; i++) {
|
|
17
|
+
for (let j = 0; j < 3; j++) {
|
|
18
|
+
|
|
19
|
+
const m_a = i * 4 + j;
|
|
20
|
+
const m_v = matrix[m_a];
|
|
21
|
+
|
|
22
|
+
const a = m_v * aabb[j];
|
|
23
|
+
const b = m_v * aabb[j + 3];
|
|
24
|
+
|
|
25
|
+
if (a < b) {
|
|
26
|
+
scratch_aabb[i] += a;
|
|
27
|
+
scratch_aabb[i + 2] += b;
|
|
28
|
+
} else {
|
|
29
|
+
scratch_aabb[i] += b;
|
|
30
|
+
scratch_aabb[i + 2] += a;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
const x1 = scratch_aabb[2];
|
|
37
|
+
const x0 = scratch_aabb[0];
|
|
38
|
+
|
|
39
|
+
const dx = x1 - x0;
|
|
40
|
+
|
|
41
|
+
const y1 = scratch_aabb[3];
|
|
42
|
+
const y0 = scratch_aabb[1];
|
|
43
|
+
|
|
44
|
+
const dy = y1 - y0;
|
|
45
|
+
const a = dx * dy;
|
|
46
|
+
|
|
47
|
+
const cx = (aabb[0] + aabb[3]) * 0.5;
|
|
48
|
+
const cy = (aabb[1] + aabb[4]) * 0.5;
|
|
49
|
+
const cz = (aabb[2] + aabb[5]) * 0.5;
|
|
50
|
+
|
|
51
|
+
/* compute W projection value, using conservative estimate
|
|
52
|
+
@see https://twitter.com/SebAaltonen/status/1332332808979832832
|
|
53
|
+
@see https://gist.github.com/slembcke/b2b2af4dede1d5702a635dc2d0e45d54
|
|
54
|
+
*/
|
|
55
|
+
const w = matrix[3] * cx + matrix[7] * cy + matrix[11] * cz + matrix[15];
|
|
56
|
+
const d = 0.5 / Math.abs(w);
|
|
57
|
+
|
|
58
|
+
return a * d * d;
|
|
59
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
|
|
2
|
+
/**
|
|
3
|
+
* NOTE: Based on Transforming Axis-Aligned Bounding Boxes by Jim Arvo from "Graphics Gems", Academic Press, 1990
|
|
4
|
+
* @param {number[]} result
|
|
5
|
+
* @param {number[]} aabb
|
|
6
|
+
* @param {number[]} matrix 4x4 matrix
|
|
7
|
+
*/
|
|
8
|
+
export function aabb3_matrix4_project(result, aabb, matrix) {
|
|
9
|
+
// extract translation from matrix
|
|
10
|
+
result[0] = result[3] = matrix[12];
|
|
11
|
+
result[1] = result[4] = matrix[13];
|
|
12
|
+
result[2] = result[5] = matrix[14];
|
|
13
|
+
|
|
14
|
+
// apply 3x3 matrix transform
|
|
15
|
+
for (let i = 0; i < 3; i++) {
|
|
16
|
+
for (let j = 0; j < 3; j++) {
|
|
17
|
+
|
|
18
|
+
const m_a = i * 4 + j;
|
|
19
|
+
const m_v = matrix[m_a];
|
|
20
|
+
|
|
21
|
+
const a = m_v * aabb[j];
|
|
22
|
+
const b = m_v * aabb[j + 3];
|
|
23
|
+
|
|
24
|
+
if (a < b) {
|
|
25
|
+
result[i] += a;
|
|
26
|
+
result[i + 3] += b;
|
|
27
|
+
} else {
|
|
28
|
+
result[i] += b;
|
|
29
|
+
result[i + 3] += a;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { aabb3_matrix4_project } from "./aabb3_matrix4_project.js";
|
|
2
|
+
|
|
3
|
+
test('identity', () => {
|
|
4
|
+
const r = [];
|
|
5
|
+
|
|
6
|
+
aabb3_matrix4_project(r, [1, 2, 3, 5, 7, 9], [
|
|
7
|
+
1, 0, 0, 0,
|
|
8
|
+
0, 1, 0, 0,
|
|
9
|
+
0, 0, 1, 0,
|
|
10
|
+
0, 0, 0, 1
|
|
11
|
+
]);
|
|
12
|
+
|
|
13
|
+
expect(r).toEqual([1, 2, 3, 5, 7, 9]);
|
|
14
|
+
});
|
|
15
|
+
|
|
16
|
+
test('translation case', () => {
|
|
17
|
+
const r = [];
|
|
18
|
+
|
|
19
|
+
aabb3_matrix4_project(r, [1, 2, 3, 5, 7, 9], [
|
|
20
|
+
1, 0, 0, 0,
|
|
21
|
+
0, 1, 0, 0,
|
|
22
|
+
0, 0, 1, 0,
|
|
23
|
+
13, -17, 23, 1
|
|
24
|
+
]);
|
|
25
|
+
|
|
26
|
+
expect(r).toEqual([14, -15, 26, 18, -10, 32]);
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
test('scale case', () => {
|
|
31
|
+
const r = [];
|
|
32
|
+
|
|
33
|
+
aabb3_matrix4_project(r, [1, 2, 3, 5, 7, 9], [
|
|
34
|
+
-1, 0, 0, 0,
|
|
35
|
+
0, 2, 0, 0,
|
|
36
|
+
0, 0, -3, 0,
|
|
37
|
+
0, 0, 0, 1
|
|
38
|
+
]);
|
|
39
|
+
|
|
40
|
+
expect(r).toEqual([-5, 4, -27, -1, 14, -9]);
|
|
41
|
+
});
|
|
@@ -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 () {
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @param {Uint8Array} input
|
|
3
|
+
* @param {number} width
|
|
4
|
+
* @param {number} height
|
|
5
|
+
* @param {number} channel_count
|
|
6
|
+
*/
|
|
7
|
+
export function flipArrayInPlace(input, width, height, channel_count = 4) {
|
|
8
|
+
const rowLength = width * channel_count;
|
|
9
|
+
let t, x0, x1;
|
|
10
|
+
let i = 0;
|
|
11
|
+
const l = height >> 1;
|
|
12
|
+
|
|
13
|
+
for (; i < l; i++) {
|
|
14
|
+
//swap lines
|
|
15
|
+
const k = (height - i - 1) * rowLength;
|
|
16
|
+
const m = i * rowLength;
|
|
17
|
+
for (let j = 0; j < rowLength; j++) {
|
|
18
|
+
x0 = m + j;
|
|
19
|
+
x1 = k + j;
|
|
20
|
+
t = input[x0];
|
|
21
|
+
input[x0] = input[x1];
|
|
22
|
+
input[x1] = t;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
function flipArrayViaCanvas(input, width, height) {
|
|
2
|
+
const canvas = document.createElement("canvas");
|
|
3
|
+
const c = canvas.getContext('2d');
|
|
4
|
+
const imageData = c.createImageData(width, height);
|
|
5
|
+
imageData.data.set(input);
|
|
6
|
+
c.putImageData(imageData, 0, 0);
|
|
7
|
+
c.translate(0, height);
|
|
8
|
+
c.scale(1, -1);
|
|
9
|
+
c.drawImage(canvas, 0, 0);
|
|
10
|
+
const imgd = c.getImageData(0, 0, width, height);
|
|
11
|
+
|
|
12
|
+
return imgd.data;
|
|
13
|
+
}
|
|
@@ -3,59 +3,25 @@
|
|
|
3
3
|
*/
|
|
4
4
|
|
|
5
5
|
|
|
6
|
-
import {
|
|
7
|
-
|
|
8
|
-
Mesh,
|
|
9
|
-
OrthographicCamera,
|
|
10
|
-
PlaneBufferGeometry,
|
|
11
|
-
Scene,
|
|
12
|
-
ShaderMaterial,
|
|
13
|
-
WebGLRenderTarget
|
|
14
|
-
} from 'three';
|
|
15
|
-
|
|
16
|
-
export function flipArrayInPlace(input, width, height) {
|
|
17
|
-
const rowLength = width * 4;
|
|
18
|
-
let t, x0, x1;
|
|
19
|
-
let i = 0;
|
|
20
|
-
const l = height >> 1;
|
|
21
|
-
for (; i < l; i++) {
|
|
22
|
-
//swap lines
|
|
23
|
-
const k = (height - i - 1) * rowLength;
|
|
24
|
-
const m = i * rowLength;
|
|
25
|
-
for (let j = 0; j < rowLength; j++) {
|
|
26
|
-
x0 = m + j;
|
|
27
|
-
x1 = k + j;
|
|
28
|
-
t = input[x0];
|
|
29
|
-
input[x0] = input[x1];
|
|
30
|
-
input[x1] = t;
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
function flipArrayViaCanvas(input, width, height) {
|
|
36
|
-
const canvas = document.createElement("canvas");
|
|
37
|
-
const c = canvas.getContext('2d');
|
|
38
|
-
const imageData = c.createImageData(width, height);
|
|
39
|
-
imageData.data.set(input);
|
|
40
|
-
c.putImageData(imageData, 0, 0);
|
|
41
|
-
c.translate(0, height);
|
|
42
|
-
c.scale(1, -1);
|
|
43
|
-
c.drawImage(canvas, 0, 0);
|
|
44
|
-
const imgd = c.getImageData(0, 0, width, height);
|
|
45
|
-
|
|
46
|
-
return imgd.data;
|
|
47
|
-
}
|
|
6
|
+
import { LinearFilter, Mesh, OrthographicCamera, Scene, ShaderMaterial, WebGLRenderTarget } from 'three';
|
|
7
|
+
import { FULL_SCREEN_TRIANGLE_GEOMETRY } from "../geometry/FULL_SCREEN_TRIANGLE_GEOMETRY.js";
|
|
48
8
|
|
|
49
9
|
/**
|
|
50
10
|
*
|
|
51
11
|
* @param {WebGLRenderer} renderer
|
|
52
12
|
* @param {number} width
|
|
53
13
|
* @param {number} height
|
|
54
|
-
* @param processShader
|
|
14
|
+
* @param {{vertexShader:string,fragmentShader:string, uniforms?:Object, defines?:Object}} processShader
|
|
55
15
|
* @param {Uint8Array} [destination]
|
|
56
16
|
* @return {{array: Uint8Array, renderer: WebGLRenderer}}
|
|
57
17
|
*/
|
|
58
|
-
function processTexture(
|
|
18
|
+
function processTexture(
|
|
19
|
+
renderer,
|
|
20
|
+
width,
|
|
21
|
+
height,
|
|
22
|
+
processShader,
|
|
23
|
+
destination
|
|
24
|
+
) {
|
|
59
25
|
if (destination === undefined) {
|
|
60
26
|
destination = new Uint8Array(width * height * 4);
|
|
61
27
|
}
|
|
@@ -72,9 +38,10 @@ function processTexture(renderer, width, height, processShader, destination) {
|
|
|
72
38
|
material.lights = false;
|
|
73
39
|
material.fog = false;
|
|
74
40
|
|
|
75
|
-
const quad = new Mesh(
|
|
41
|
+
const quad = new Mesh(FULL_SCREEN_TRIANGLE_GEOMETRY, material);
|
|
76
42
|
|
|
77
43
|
scene.add(quad);
|
|
44
|
+
|
|
78
45
|
//render
|
|
79
46
|
const renderTargetOptions = {
|
|
80
47
|
generateMipmaps: false,
|
|
@@ -82,28 +49,30 @@ function processTexture(renderer, width, height, processShader, destination) {
|
|
|
82
49
|
stencilBuffer: false,
|
|
83
50
|
depthBuffer: false
|
|
84
51
|
};
|
|
52
|
+
|
|
85
53
|
const renderTarget = new WebGLRenderTarget(width, height, renderTargetOptions);
|
|
86
54
|
|
|
55
|
+
const __rt = renderer.getRenderTarget(); // remember old renderer state
|
|
56
|
+
|
|
87
57
|
renderer.setRenderTarget(renderTarget);
|
|
88
58
|
|
|
89
59
|
renderer.render(scene, camera);
|
|
90
60
|
|
|
91
61
|
const gl = renderer.getContext();
|
|
62
|
+
|
|
92
63
|
//void readPixels(GLint x, GLint y, GLsizei width, GLsizei height, GLenum format, GLenum type, ArrayBufferView? pixels)
|
|
93
64
|
gl.readPixels(0, 0, width, height, gl.RGBA, gl.UNSIGNED_BYTE, destination);
|
|
94
65
|
|
|
95
|
-
renderer
|
|
66
|
+
// restore renderer state
|
|
67
|
+
renderer.setRenderTarget(__rt);
|
|
96
68
|
|
|
97
|
-
//
|
|
98
|
-
|
|
99
|
-
//uint8Array = flipArrayViaCanvas(uint8Array, width, height);
|
|
100
|
-
//
|
|
69
|
+
// cleanup resources
|
|
101
70
|
renderTarget.dispose();
|
|
102
71
|
material.dispose();
|
|
72
|
+
|
|
103
73
|
return {
|
|
104
74
|
array: destination,
|
|
105
75
|
graphics: renderer
|
|
106
|
-
//renderTarget: renderTarget
|
|
107
76
|
};
|
|
108
77
|
}
|
|
109
78
|
|
|
@@ -40,8 +40,8 @@ export class MicronGeometryBufferAttributeSpec {
|
|
|
40
40
|
equals(other) {
|
|
41
41
|
return this.type === other.type
|
|
42
42
|
&& this.itemSize === other.itemSize
|
|
43
|
-
&& this.name === other.name
|
|
44
43
|
&& this.normalized === other.normalized
|
|
44
|
+
&& this.name === other.name
|
|
45
45
|
;
|
|
46
46
|
}
|
|
47
47
|
|
|
@@ -48,10 +48,10 @@ export class VirtualGeometryBuilder {
|
|
|
48
48
|
|
|
49
49
|
/**
|
|
50
50
|
*
|
|
51
|
-
* @type {
|
|
51
|
+
* @type {ActivePatchList}
|
|
52
52
|
* @private
|
|
53
53
|
*/
|
|
54
|
-
this.
|
|
54
|
+
this.__acl = new ActivePatchList();
|
|
55
55
|
|
|
56
56
|
/**
|
|
57
57
|
* How much error to accept when deciding to subdivide a cluster
|
|
@@ -76,12 +76,8 @@ export class VirtualGeometryBuilder {
|
|
|
76
76
|
this.__flags__enforce_dependency_splits = true;
|
|
77
77
|
}
|
|
78
78
|
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
* Useful for testing and debugging
|
|
82
|
-
*/
|
|
83
|
-
dropCache() {
|
|
84
|
-
this.__acls = new WeakMap();
|
|
79
|
+
dropCache(){
|
|
80
|
+
this.__acl.clear();
|
|
85
81
|
}
|
|
86
82
|
|
|
87
83
|
/**
|
|
@@ -137,15 +133,7 @@ export class VirtualGeometryBuilder {
|
|
|
137
133
|
const micron_geometry = object.geometry;
|
|
138
134
|
if (micron_geometry !== undefined) {
|
|
139
135
|
// get acl
|
|
140
|
-
|
|
141
|
-
const acls = this.__acls;
|
|
142
|
-
|
|
143
|
-
let acl = acls.get(object);
|
|
144
|
-
|
|
145
|
-
if (acl === undefined) {
|
|
146
|
-
acl = new ActivePatchList();
|
|
147
|
-
acls.set(object, acl);
|
|
148
|
-
}
|
|
136
|
+
const acl = this.__acl;
|
|
149
137
|
|
|
150
138
|
acl.initializeFromGeometry(micron_geometry);
|
|
151
139
|
|
|
@@ -2,14 +2,12 @@ import { assert } from "../../../../../core/assert.js";
|
|
|
2
2
|
import { MICRON_PATCH_SIZE_MAX } from "../../build/MICRON_PATCH_SIZE_MAX.js";
|
|
3
3
|
import { typed_array_copy } from "../../../../../core/collection/array/typed/typed_array_copy.js";
|
|
4
4
|
import { channelCountToThreeTextureFormat } from "../../../texture/channelCountToThreeTextureFormat.js";
|
|
5
|
-
import {
|
|
6
|
-
computeThreeTextureInternalFormatFromDataType,
|
|
7
|
-
computeThreeTextureTypeFromDataType
|
|
8
|
-
} from "../../../render/forward_plus/TextureBackedMemoryRegion.js";
|
|
9
5
|
import { DataTexture, NearestFilter } from "three";
|
|
10
6
|
import { DataTypeByteSizes } from "../../../../../core/collection/table/RowFirstTableSpec.js";
|
|
11
7
|
import { DataType } from "../../../../../core/collection/table/DataType.js";
|
|
12
8
|
import { compute_micron_buffer_array_constructor } from "../../build/compute_micron_buffer_array_constructor.js";
|
|
9
|
+
import { computeThreeTextureTypeFromDataType } from "../../../render/forward_plus/data/computeThreeTextureTypeFromDataType.js";
|
|
10
|
+
import { computeThreeTextureInternalFormatFromDataType } from "../../../render/forward_plus/data/computeThreeTextureInternalFormatFromDataType.js";
|
|
13
11
|
|
|
14
12
|
/**
|
|
15
13
|
*
|