@woosh/meep-engine 2.33.2 → 2.33.6
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 +18 -0
- package/core/bvh2/aabb3/aabb3_intersects_frustum.js +38 -0
- 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/table/RowFirstTableSpec.js +8 -0
- package/core/geom/3d/aabb/aabb3_compute_projected_area.js +16 -14
- 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/core/geom/3d/plane/plane3_lerp.js +2 -2
- package/core/geom/3d/topology/TopoTriangle.js +2 -2
- package/core/geom/AABB2.d.ts +2 -0
- package/core/geom/Matrix4.js +4 -4
- package/core/geom/Vector3.js +5 -5
- package/core/model/reactive/model/terminal/ReactiveReference.js +7 -1
- 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/asset/loaders/GLTFAssetLoader.js +3 -3
- package/engine/asset/loaders/material/TextureAttachmensByMaterialType.js +11 -1
- package/engine/asset/loaders/material/TextureAttachment.js +12 -1
- package/engine/asset/loaders/material/bitmap2sampler_gl.js +19 -0
- package/engine/asset/loaders/material/computeImageBitmapEquality.js +7 -19
- package/engine/asset/loaders/material/computeTextureEquality.js +1 -1
- package/engine/asset/loaders/material/computeTextureHash.js +16 -14
- package/engine/asset/loaders/material/traverseMaterialTextures.js +2 -2
- package/engine/ecs/animation/OneBoneSurfaceAlignmentSolver.js +2 -2
- package/engine/ecs/animation/TwoBoneInverseKinematicsSolver.js +4 -4
- package/engine/graphics/GraphicsEngine.d.ts +2 -2
- package/engine/graphics/GraphicsEngine.js +20 -62
- 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/geometry/bvh/buffered/BVHGeometryRaycaster.js +2 -2
- package/engine/graphics/geometry/instancing/InstancedMeshGroup.js +25 -16
- package/engine/graphics/material/SplatMaterial.js +4 -97
- package/engine/graphics/material/optimization/MaterialOptimizationContext.js +598 -0
- package/engine/graphics/micron/build/PatchRepresentation.js +4 -43
- package/engine/graphics/micron/build/buildMicronGeometryFromBufferGeometry.js +4 -75
- package/engine/graphics/micron/build/compute_buffer_geometry_byte_size.js +16 -0
- package/engine/graphics/micron/build/fill_patch_geometry_data.js +2 -0
- package/engine/graphics/micron/format/MicronGeometryBufferAttributeSpec.js +1 -1
- package/engine/graphics/micron/format/MicronGeometryPatch.js +17 -5
- package/engine/graphics/micron/format/MicronVertexDataSpec.js +25 -3
- package/engine/graphics/micron/prototypeVirtualGeometry.js +19 -12
- package/engine/graphics/micron/render/VirtualGeometryBuilder.js +34 -27
- package/engine/graphics/micron/render/instanced/AttributeDataTexture.js +2 -4
- package/engine/graphics/micron/render/instanced/PatchDataTextures.js +1 -0
- package/engine/graphics/micron/render/instanced/ThreeInstancedAdapter.js +1 -29
- package/engine/graphics/micron/render/refinement/ActivePatchList.js +43 -159
- 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/refinement/array_normalize_plane.js +25 -0
- package/engine/graphics/micron/render/refinement/array_setFromProjectionMatrix.js +60 -0
- package/engine/graphics/micron/render/refinement/is_patch_facing_back.js +43 -0
- package/engine/graphics/micron/render/refinement/is_patch_visible.js +37 -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/util/unit_hemioct.spec.js +2 -2
- package/engine/graphics/render/buffer/buffers/ColorAndDepthFrameBuffer.js +5 -3
- package/engine/graphics/render/buffer/buffers/NormalFrameBuffer.js +12 -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/forward_plus/prototypeLightManager.js +1 -1
- package/engine/graphics/render/utils/ThreeBypassRenderer.js +1 -3
- package/engine/graphics/render/visibility/hiz/buffer/HierarchicalZBuffer.js +198 -0
- package/engine/graphics/render/visibility/hiz/buffer/ReductionShader.js +51 -0
- package/engine/graphics/render/visibility/hiz/buildCanvasViewFromTexture.js +179 -0
- package/engine/graphics/render/visibility/hiz/prototypeHiZ.js +435 -0
- package/engine/graphics/render/visibility/hiz/query/BatchOcclusionQuery.js +174 -0
- package/engine/graphics/render/visibility/hiz/query/QueryShader.js +173 -0
- package/engine/graphics/shadows/ShadowMapRenderer.js +12 -2
- package/engine/graphics/texture/atlas/TextureAtlas.js +1 -1
- package/engine/graphics/texture/cubemap/buildCubeURLs.js +13 -0
- package/engine/graphics/texture/cubemap/load_environment_map.d.ts +8 -0
- package/engine/graphics/texture/cubemap/load_environment_map.js +163 -0
- package/engine/graphics/texture/sampler/Sampler2D.js +18 -62
- package/engine/graphics/texture/sampler/convertTexture2Sampler2D.js +8 -4
- 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/package.json +1 -1
- package/view/elements/progress/segmented/SegmentedResourceBarView.js +50 -15
- package/view/minimap/gl/MinimapMarkersGL.js +2 -2
- package/engine/graphics/micron/render/RefinementSpec.js +0 -110
|
@@ -23,6 +23,7 @@ import { convert_three_object_to_micron } from "../../graphics/micron/convert_th
|
|
|
23
23
|
import { HashSet } from "../../../core/collection/HashSet.js";
|
|
24
24
|
import { computeGeometryHash } from "./geometry/geometry/computeGeometryHash.js";
|
|
25
25
|
import { computeGeometryEquality } from "./geometry/geometry/computeGeometryEquality.js";
|
|
26
|
+
import { traverseThreeObject } from "../../graphics/ecs/highlight/renderer/traverseThreeObject.js";
|
|
26
27
|
|
|
27
28
|
const animationOptimizer = new AnimationOptimizer();
|
|
28
29
|
const materialCache = StaticMaterialCache.Global;
|
|
@@ -287,9 +288,7 @@ export class GLTFAssetLoader extends AssetLoader {
|
|
|
287
288
|
root = meshes[0];
|
|
288
289
|
}
|
|
289
290
|
|
|
290
|
-
root.
|
|
291
|
-
this.__prepareObjectMaterial(o);
|
|
292
|
-
});
|
|
291
|
+
traverseThreeObject(root, this.__prepareObjectMaterial, this);
|
|
293
292
|
|
|
294
293
|
const root_transform = new Transform();
|
|
295
294
|
|
|
@@ -319,6 +318,7 @@ export class GLTFAssetLoader extends AssetLoader {
|
|
|
319
318
|
|
|
320
319
|
await async_traverse(root, process_object);
|
|
321
320
|
|
|
321
|
+
|
|
322
322
|
// compute object bounding sphere
|
|
323
323
|
root.boundingSphere = computeObjectBoundingSphere(root);
|
|
324
324
|
|
|
@@ -2,6 +2,7 @@ import { TextureAttachment } from "./TextureAttachment.js";
|
|
|
2
2
|
|
|
3
3
|
const taDiffuse = new TextureAttachment({
|
|
4
4
|
name: 'diffuse',
|
|
5
|
+
uv_index: 0,
|
|
5
6
|
read(m) {
|
|
6
7
|
return m.map;
|
|
7
8
|
},
|
|
@@ -12,6 +13,7 @@ const taDiffuse = new TextureAttachment({
|
|
|
12
13
|
|
|
13
14
|
const taAlphaMap = new TextureAttachment({
|
|
14
15
|
name: "alpha",
|
|
16
|
+
uv_index: 0,
|
|
15
17
|
read(m) {
|
|
16
18
|
return m.alphaMap;
|
|
17
19
|
},
|
|
@@ -22,6 +24,7 @@ const taAlphaMap = new TextureAttachment({
|
|
|
22
24
|
|
|
23
25
|
const taDisplacement = new TextureAttachment({
|
|
24
26
|
name: "displacement",
|
|
27
|
+
uv_index: 0,
|
|
25
28
|
read(m) {
|
|
26
29
|
return m.displacementMap;
|
|
27
30
|
},
|
|
@@ -45,6 +48,7 @@ export const TextureAttachmentsByMaterialType = {
|
|
|
45
48
|
taAlphaMap,
|
|
46
49
|
new TextureAttachment({
|
|
47
50
|
name: "light",
|
|
51
|
+
uv_index: 1,
|
|
48
52
|
read(m) {
|
|
49
53
|
return m.lightMap;
|
|
50
54
|
},
|
|
@@ -54,6 +58,7 @@ export const TextureAttachmentsByMaterialType = {
|
|
|
54
58
|
}),
|
|
55
59
|
new TextureAttachment({
|
|
56
60
|
name: "ao",
|
|
61
|
+
uv_index: 1,
|
|
57
62
|
read(m) {
|
|
58
63
|
return m.aoMap;
|
|
59
64
|
},
|
|
@@ -63,6 +68,7 @@ export const TextureAttachmentsByMaterialType = {
|
|
|
63
68
|
}),
|
|
64
69
|
new TextureAttachment({
|
|
65
70
|
name: "emissive",
|
|
71
|
+
uv_index: 0,
|
|
66
72
|
read(m) {
|
|
67
73
|
return m.emissiveMap;
|
|
68
74
|
},
|
|
@@ -72,6 +78,7 @@ export const TextureAttachmentsByMaterialType = {
|
|
|
72
78
|
}),
|
|
73
79
|
new TextureAttachment({
|
|
74
80
|
name: "bump",
|
|
81
|
+
uv_index: 0,
|
|
75
82
|
read(m) {
|
|
76
83
|
return m.bumpMap;
|
|
77
84
|
},
|
|
@@ -81,6 +88,7 @@ export const TextureAttachmentsByMaterialType = {
|
|
|
81
88
|
}),
|
|
82
89
|
new TextureAttachment({
|
|
83
90
|
name: "normal",
|
|
91
|
+
uv_index: 0,
|
|
84
92
|
read(m) {
|
|
85
93
|
return m.normalMap;
|
|
86
94
|
},
|
|
@@ -91,6 +99,7 @@ export const TextureAttachmentsByMaterialType = {
|
|
|
91
99
|
taDisplacement,
|
|
92
100
|
new TextureAttachment({
|
|
93
101
|
name: "roughness",
|
|
102
|
+
uv_index: 0,
|
|
94
103
|
read(m) {
|
|
95
104
|
return m.roughnessMap;
|
|
96
105
|
},
|
|
@@ -100,6 +109,7 @@ export const TextureAttachmentsByMaterialType = {
|
|
|
100
109
|
}),
|
|
101
110
|
new TextureAttachment({
|
|
102
111
|
name: "metalness",
|
|
112
|
+
uv_index: 0,
|
|
103
113
|
read(m) {
|
|
104
114
|
return m.metalnessMap;
|
|
105
115
|
},
|
|
@@ -107,9 +117,9 @@ export const TextureAttachmentsByMaterialType = {
|
|
|
107
117
|
m.metalnessMap = t;
|
|
108
118
|
}
|
|
109
119
|
}),
|
|
110
|
-
taAlphaMap,
|
|
111
120
|
new TextureAttachment({
|
|
112
121
|
name: "environment",
|
|
122
|
+
uv_index: 0,
|
|
113
123
|
read(m) {
|
|
114
124
|
return m.envMap;
|
|
115
125
|
},
|
|
@@ -4,11 +4,22 @@ export class TextureAttachment {
|
|
|
4
4
|
* @param {function(T):Texture} read
|
|
5
5
|
* @param {function(T, Texture)} write
|
|
6
6
|
* @param {string} [name]
|
|
7
|
+
* @param {number} [uv_index]
|
|
7
8
|
*/
|
|
8
|
-
constructor({ read, write, name }) {
|
|
9
|
+
constructor({ read, write, name, uv_index = 0 }) {
|
|
10
|
+
/**
|
|
11
|
+
*
|
|
12
|
+
* @type {string}
|
|
13
|
+
*/
|
|
9
14
|
this.name = name;
|
|
10
15
|
|
|
11
16
|
this.read = read;
|
|
12
17
|
this.write = write;
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
*
|
|
21
|
+
* @type {number}
|
|
22
|
+
*/
|
|
23
|
+
this.uv_index = uv_index;
|
|
13
24
|
}
|
|
14
25
|
}
|
|
@@ -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,4 +1,4 @@
|
|
|
1
|
-
import { computeHashFloat, computeHashIntegerArray} from "../../../../core/math/MathUtils.js";
|
|
1
|
+
import { computeHashFloat, computeHashIntegerArray } from "../../../../core/math/MathUtils.js";
|
|
2
2
|
import { max2 } from "../../../../core/math/max2.js";
|
|
3
3
|
import { computeImageBitmapHash } from "./computeImageBitmapHash.js";
|
|
4
4
|
|
|
@@ -19,7 +19,7 @@ function vector2Hash(v) {
|
|
|
19
19
|
*/
|
|
20
20
|
const data_cache = new WeakMap();
|
|
21
21
|
|
|
22
|
-
function computeImageDataHash(image) {
|
|
22
|
+
export function computeImageDataHash(image) {
|
|
23
23
|
const cached_value = data_cache.get(image);
|
|
24
24
|
|
|
25
25
|
if (cached_value !== undefined) {
|
|
@@ -32,6 +32,19 @@ function computeImageDataHash(image) {
|
|
|
32
32
|
result = computeImageBitmapHash(image);
|
|
33
33
|
}
|
|
34
34
|
|
|
35
|
+
let width = 0;
|
|
36
|
+
let height = 0;
|
|
37
|
+
|
|
38
|
+
if (typeof image.width === "number") {
|
|
39
|
+
width = image.width;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
if (typeof image.height === "number") {
|
|
43
|
+
height = image.height;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
result = result ^ (((width & 0xFFFF) << 16) | (height & 0xFFFF));
|
|
47
|
+
|
|
35
48
|
// cache value
|
|
36
49
|
data_cache.set(image, result);
|
|
37
50
|
|
|
@@ -44,23 +57,12 @@ function computeImageDataHash(image) {
|
|
|
44
57
|
* @return {number}
|
|
45
58
|
*/
|
|
46
59
|
function computeSpecificHash(texture) {
|
|
47
|
-
let width = 0;
|
|
48
|
-
let height = 0;
|
|
49
|
-
|
|
50
60
|
let dataHash = 0;
|
|
51
61
|
|
|
52
62
|
if (texture.image !== null && texture.image !== undefined) {
|
|
53
63
|
|
|
54
64
|
const image = texture.image;
|
|
55
65
|
|
|
56
|
-
if (typeof image.width === "number") {
|
|
57
|
-
width = image.width;
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
if (typeof image.height === "number") {
|
|
61
|
-
height = image.height;
|
|
62
|
-
}
|
|
63
|
-
|
|
64
66
|
dataHash = computeImageDataHash(image);
|
|
65
67
|
|
|
66
68
|
}
|
|
@@ -94,7 +96,7 @@ function computeSpecificHash(texture) {
|
|
|
94
96
|
|
|
95
97
|
}
|
|
96
98
|
|
|
97
|
-
return
|
|
99
|
+
return dataHash;
|
|
98
100
|
}
|
|
99
101
|
|
|
100
102
|
/**
|
|
@@ -3,7 +3,7 @@ import { TextureAttachmentsByMaterialType } from "./TextureAttachmensByMaterialT
|
|
|
3
3
|
/**
|
|
4
4
|
*
|
|
5
5
|
* @param {Material} material
|
|
6
|
-
* @param {function(Texture)} callback
|
|
6
|
+
* @param {function(THREE.Texture, TextureAttachment)} callback
|
|
7
7
|
* @param {*} [thisArg]
|
|
8
8
|
*/
|
|
9
9
|
export function traverseMaterialTextures(material, callback, thisArg) {
|
|
@@ -30,7 +30,7 @@ export function traverseMaterialTextures(material, callback, thisArg) {
|
|
|
30
30
|
continue;
|
|
31
31
|
}
|
|
32
32
|
|
|
33
|
-
callback.call(thisArg, texture);
|
|
33
|
+
callback.call(thisArg, texture, attachment);
|
|
34
34
|
|
|
35
35
|
}
|
|
36
36
|
}
|
|
@@ -3,7 +3,7 @@ import { inverseLerp } from "../../../core/math/inverseLerp.js";
|
|
|
3
3
|
import { IKSolver } from "./IKSolver.js";
|
|
4
4
|
import { findSkeletonBoneByType } from "../../graphics/ecs/mesh/SkeletonUtils.js";
|
|
5
5
|
import Quaternion from "../../../core/geom/Quaternion.js";
|
|
6
|
-
import Vector3, { v3_dot,
|
|
6
|
+
import Vector3, { v3_dot, v3_length } from "../../../core/geom/Vector3.js";
|
|
7
7
|
import { SurfacePoint3 } from "../../../core/geom/3d/SurfacePoint3.js";
|
|
8
8
|
import { v3_computeOffsetVector } from "./IKMath.js";
|
|
9
9
|
|
|
@@ -127,7 +127,7 @@ export class OneBoneSurfaceAlignmentSolver extends IKSolver {
|
|
|
127
127
|
//check if current effector position is above the contact point
|
|
128
128
|
const dot_contact_side = v3_dot(directionX, directionY, directionZ, delta_contact_c_x, delta_contact_c_y, delta_contact_c_z);
|
|
129
129
|
|
|
130
|
-
const delta_contact_c_length =
|
|
130
|
+
const delta_contact_c_length = v3_length(delta_contact_c_x, delta_contact_c_y, delta_contact_c_z);
|
|
131
131
|
|
|
132
132
|
let influence;
|
|
133
133
|
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { assert } from "../../../core/assert.js";
|
|
2
|
-
import Vector3, { v3_dot,
|
|
2
|
+
import Vector3, { v3_dot, v3_length } from "../../../core/geom/Vector3.js";
|
|
3
3
|
import { clamp } from "../../../core/math/clamp.js";
|
|
4
4
|
import { inverseLerp } from "../../../core/math/inverseLerp.js";
|
|
5
5
|
import Quaternion from "../../../core/geom/Quaternion.js";
|
|
@@ -41,7 +41,7 @@ function computeInteriorAngle(a, b, c) {
|
|
|
41
41
|
const d_ab_z = a.z - b.z;
|
|
42
42
|
|
|
43
43
|
//normalize AB delta vector
|
|
44
|
-
const d_ab_length =
|
|
44
|
+
const d_ab_length = v3_length(d_ab_x, d_ab_y, d_ab_z);
|
|
45
45
|
|
|
46
46
|
const nd_ab_x = d_ab_x / d_ab_length;
|
|
47
47
|
const nd_ab_y = d_ab_y / d_ab_length;
|
|
@@ -53,7 +53,7 @@ function computeInteriorAngle(a, b, c) {
|
|
|
53
53
|
const d_cb_z = c.z - b.z;
|
|
54
54
|
|
|
55
55
|
//normalize CB delta vector
|
|
56
|
-
const d_cb_length =
|
|
56
|
+
const d_cb_length = v3_length(d_cb_x, d_cb_y, d_cb_z);
|
|
57
57
|
|
|
58
58
|
const nd_cb_x = d_cb_x / d_cb_length;
|
|
59
59
|
const nd_cb_y = d_cb_y / d_cb_length;
|
|
@@ -266,7 +266,7 @@ export class TwoBoneInverseKinematicsSolver extends IKSolver {
|
|
|
266
266
|
//check if current effector position is above the contact point
|
|
267
267
|
const dot_contact_side = v3_dot(directionX, directionY, directionZ, delta_contact_c_x, delta_contact_c_y, delta_contact_c_z);
|
|
268
268
|
|
|
269
|
-
const delta_contact_c_length =
|
|
269
|
+
const delta_contact_c_length = v3_length(delta_contact_c_x, delta_contact_c_y, delta_contact_c_z);
|
|
270
270
|
|
|
271
271
|
let influence;
|
|
272
272
|
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {PerspectiveCamera,
|
|
1
|
+
import {PerspectiveCamera, Scene, WebGLRenderer, WebGLRenderTarget} from "three";
|
|
2
2
|
import {RenderLayerManager} from "./render/layers/RenderLayerManager";
|
|
3
3
|
import Vector3 from "../../core/geom/Vector3";
|
|
4
4
|
import Vector2 from "../../core/geom/Vector2";
|
|
@@ -17,7 +17,7 @@ export class GraphicsEngine {
|
|
|
17
17
|
public needDraw: boolean
|
|
18
18
|
public autoDraw: boolean
|
|
19
19
|
|
|
20
|
-
render(renderTarget?:
|
|
20
|
+
render(renderTarget?: WebGLRenderTarget): void
|
|
21
21
|
|
|
22
22
|
normalizeViewportPoint(input: Vector3 | Vector2, result: Vector2 | Vector3): void
|
|
23
23
|
|
|
@@ -4,14 +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
12
|
Vector3 as ThreeVector3,
|
|
16
13
|
VSMShadowMap,
|
|
17
14
|
WebGLRenderer,
|
|
@@ -36,27 +33,13 @@ import { renderTextureToScreenQuad } from "./render/utils/renderTextureToScreenQ
|
|
|
36
33
|
import { globalMetrics } from "../metrics/GlobalMetrics.js";
|
|
37
34
|
import { MetricsCategory } from "../metrics/MetricsCategory.js";
|
|
38
35
|
import Vector1 from "../../core/geom/Vector1.js";
|
|
39
|
-
import { noop } from "../../core/function/Functions.js";
|
|
40
36
|
import { NormalFrameBuffer } from "./render/buffer/buffers/NormalFrameBuffer.js";
|
|
41
37
|
import { MaterialManager } from "./material/manager/MaterialManager.js";
|
|
42
38
|
import { CoalesceTextures } from "./material/manager/compilers/CoalesceTextures.js";
|
|
43
39
|
import { ShadowMapRenderer } from "./shadows/ShadowMapRenderer.js";
|
|
44
40
|
import { CameraViewManager } from "./render/view/CameraViewManager.js";
|
|
45
41
|
import { StandardFrameBuffers } from "./StandardFrameBuffers.js";
|
|
46
|
-
|
|
47
|
-
/**
|
|
48
|
-
*
|
|
49
|
-
* @param {String} path
|
|
50
|
-
* @param {String} format
|
|
51
|
-
* @returns {String[]}
|
|
52
|
-
*/
|
|
53
|
-
export function buildCubeURLs(path, format) {
|
|
54
|
-
return [
|
|
55
|
-
path + "posx" + format, path + "negx" + format,
|
|
56
|
-
path + "posy" + format, path + "negy" + format,
|
|
57
|
-
path + "posz" + format, path + "negz" + format
|
|
58
|
-
];
|
|
59
|
-
}
|
|
42
|
+
import { load_environment_map } from "./texture/cubemap/load_environment_map.js";
|
|
60
43
|
|
|
61
44
|
/**
|
|
62
45
|
*
|
|
@@ -259,54 +242,21 @@ GraphicsEngine.prototype.getRenderer = function () {
|
|
|
259
242
|
|
|
260
243
|
/**
|
|
261
244
|
*
|
|
262
|
-
* @param {string[]} paths
|
|
263
|
-
* @
|
|
264
|
-
*/
|
|
265
|
-
function load_cube_texture(paths) {
|
|
266
|
-
const cubeTextureLoader = new CubeTextureLoader();
|
|
267
|
-
return new Promise((resolve, reject) => {
|
|
268
|
-
|
|
269
|
-
cubeTextureLoader.load(
|
|
270
|
-
paths,
|
|
271
|
-
texture => {
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
resolve(texture);
|
|
275
|
-
},
|
|
276
|
-
noop,
|
|
277
|
-
reject
|
|
278
|
-
);
|
|
279
|
-
});
|
|
280
|
-
}
|
|
281
|
-
|
|
282
|
-
/**
|
|
283
|
-
*
|
|
284
|
-
* @param {string[]} paths URLs to faces of the cubemap
|
|
285
|
-
* @returns {Promise<void>}
|
|
245
|
+
* @param {string[]|string} paths URLs to faces of the cubemap
|
|
246
|
+
* @returns {Promise<Texture>}
|
|
286
247
|
*/
|
|
287
248
|
GraphicsEngine.prototype.loadEnvironmentMap = async function (paths) {
|
|
288
249
|
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
cube_texture.encoding = sRGBEncoding;
|
|
296
|
-
|
|
297
|
-
// generate pre-filtered cubemap
|
|
298
|
-
const pmremGenerator = new PMREMGenerator(this.renderer);
|
|
299
|
-
pmremGenerator.compileCubemapShader();
|
|
300
|
-
|
|
301
|
-
const cube_rt = pmremGenerator.fromCubemap(cube_texture);
|
|
302
|
-
|
|
303
|
-
// cleanup
|
|
304
|
-
cube_texture.dispose();
|
|
305
|
-
pmremGenerator.dispose();
|
|
250
|
+
const { filtered } = await load_environment_map({
|
|
251
|
+
path: paths,
|
|
252
|
+
renderer: this.renderer,
|
|
253
|
+
original: false,
|
|
254
|
+
filtered: true
|
|
255
|
+
});
|
|
306
256
|
|
|
307
|
-
|
|
308
|
-
this.scene.environment = cube_rt.texture;
|
|
257
|
+
this.scene.environment = filtered;
|
|
309
258
|
|
|
259
|
+
return filtered;
|
|
310
260
|
}
|
|
311
261
|
|
|
312
262
|
GraphicsEngine.prototype.updateSize = function () {
|
|
@@ -618,11 +568,19 @@ GraphicsEngine.prototype.renderOpaque = function () {
|
|
|
618
568
|
* Renders assets that (may) contain transparent fragments
|
|
619
569
|
*/
|
|
620
570
|
GraphicsEngine.prototype.renderTransparent = function () {
|
|
571
|
+
const scene = this.scene;
|
|
572
|
+
|
|
573
|
+
const _background = scene.background;
|
|
574
|
+
scene.background = null;
|
|
575
|
+
|
|
621
576
|
this.prepareRenderPass(RenderPassType.Transparent);
|
|
622
577
|
|
|
623
578
|
const renderer = this.renderer;
|
|
624
579
|
|
|
625
|
-
renderer.render(
|
|
580
|
+
renderer.render(scene, this.camera);
|
|
581
|
+
|
|
582
|
+
// restore background
|
|
583
|
+
scene.background = _background;
|
|
626
584
|
|
|
627
585
|
// TODO render transparent objects into a buffer, to be able to apply post-fx
|
|
628
586
|
};
|
|
@@ -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
|
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import Vector3, {
|
|
1
|
+
import Vector3, { v3_length } from "../../../../../core/geom/Vector3.js";
|
|
2
2
|
|
|
3
3
|
import { Vector3 as ThreeVector3 } from 'three';
|
|
4
4
|
import { rayTriangleIntersection } from "../../../../../core/geom/GeometryMath.js";
|
|
@@ -60,7 +60,7 @@ function bindGeometryFaceNormal(indices, normals, index) {
|
|
|
60
60
|
const nsZ = (naZ + nbZ + ncZ);
|
|
61
61
|
|
|
62
62
|
//normalize
|
|
63
|
-
const l =
|
|
63
|
+
const l = v3_length(nsX, nsY, nsZ);
|
|
64
64
|
const m = 1 / l;
|
|
65
65
|
|
|
66
66
|
const nx = nsX * m;
|