@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.
Files changed (98) hide show
  1. package/core/bvh2/aabb3/AABB3.js +18 -0
  2. package/core/bvh2/aabb3/aabb3_intersects_frustum.js +38 -0
  3. package/core/collection/RingBuffer.js +40 -10
  4. package/core/collection/array/copyArray.js +2 -2
  5. package/core/collection/array/typed/typed_array_copy.js +2 -2
  6. package/core/collection/table/RowFirstTableSpec.js +8 -0
  7. package/core/geom/3d/aabb/aabb3_compute_projected_area.js +16 -14
  8. package/core/geom/3d/aabb/aabb3_estimate_projected_area2.js +59 -0
  9. package/core/geom/3d/aabb/aabb3_matrix4_project.js +33 -0
  10. package/core/geom/3d/aabb/aabb3_matrix4_project.spec.js +41 -0
  11. package/core/geom/3d/plane/plane3_lerp.js +2 -2
  12. package/core/geom/3d/topology/TopoTriangle.js +2 -2
  13. package/core/geom/AABB2.d.ts +2 -0
  14. package/core/geom/Matrix4.js +4 -4
  15. package/core/geom/Vector3.js +5 -5
  16. package/core/model/reactive/model/terminal/ReactiveReference.js +7 -1
  17. package/core/process/undo/ActionProcessor.d.ts +2 -0
  18. package/core/process/undo/ActionProcessor.js +59 -1
  19. package/core/process/undo/ActionProcessor.spec.js +59 -0
  20. package/core/process/undo/Mark.js +2 -1
  21. package/engine/asset/loaders/GLTFAssetLoader.js +3 -3
  22. package/engine/asset/loaders/material/TextureAttachmensByMaterialType.js +11 -1
  23. package/engine/asset/loaders/material/TextureAttachment.js +12 -1
  24. package/engine/asset/loaders/material/bitmap2sampler_gl.js +19 -0
  25. package/engine/asset/loaders/material/computeImageBitmapEquality.js +7 -19
  26. package/engine/asset/loaders/material/computeTextureEquality.js +1 -1
  27. package/engine/asset/loaders/material/computeTextureHash.js +16 -14
  28. package/engine/asset/loaders/material/traverseMaterialTextures.js +2 -2
  29. package/engine/ecs/animation/OneBoneSurfaceAlignmentSolver.js +2 -2
  30. package/engine/ecs/animation/TwoBoneInverseKinematicsSolver.js +4 -4
  31. package/engine/graphics/GraphicsEngine.d.ts +2 -2
  32. package/engine/graphics/GraphicsEngine.js +20 -62
  33. package/engine/graphics/filter/FlipArrayInPlace.js +25 -0
  34. package/engine/graphics/filter/FlipArrayViaCanvas.js +13 -0
  35. package/engine/graphics/filter/ImageFilter.js +20 -51
  36. package/engine/graphics/geometry/bvh/buffered/BVHGeometryRaycaster.js +2 -2
  37. package/engine/graphics/geometry/instancing/InstancedMeshGroup.js +25 -16
  38. package/engine/graphics/material/SplatMaterial.js +4 -97
  39. package/engine/graphics/material/optimization/MaterialOptimizationContext.js +598 -0
  40. package/engine/graphics/micron/build/PatchRepresentation.js +4 -43
  41. package/engine/graphics/micron/build/buildMicronGeometryFromBufferGeometry.js +4 -75
  42. package/engine/graphics/micron/build/compute_buffer_geometry_byte_size.js +16 -0
  43. package/engine/graphics/micron/build/fill_patch_geometry_data.js +2 -0
  44. package/engine/graphics/micron/format/MicronGeometryBufferAttributeSpec.js +1 -1
  45. package/engine/graphics/micron/format/MicronGeometryPatch.js +17 -5
  46. package/engine/graphics/micron/format/MicronVertexDataSpec.js +25 -3
  47. package/engine/graphics/micron/prototypeVirtualGeometry.js +19 -12
  48. package/engine/graphics/micron/render/VirtualGeometryBuilder.js +34 -27
  49. package/engine/graphics/micron/render/instanced/AttributeDataTexture.js +2 -4
  50. package/engine/graphics/micron/render/instanced/PatchDataTextures.js +1 -0
  51. package/engine/graphics/micron/render/instanced/ThreeInstancedAdapter.js +1 -29
  52. package/engine/graphics/micron/render/refinement/ActivePatchList.js +43 -159
  53. package/engine/graphics/micron/render/refinement/ActivePatchRecord.js +4 -2
  54. package/engine/graphics/micron/render/refinement/RefinementSpec.js +98 -0
  55. package/engine/graphics/micron/render/refinement/array_normalize_plane.js +25 -0
  56. package/engine/graphics/micron/render/refinement/array_setFromProjectionMatrix.js +60 -0
  57. package/engine/graphics/micron/render/refinement/is_patch_facing_back.js +43 -0
  58. package/engine/graphics/micron/render/refinement/is_patch_visible.js +37 -0
  59. package/engine/graphics/micron/render/v1/MaterialVertexSpec.js +21 -0
  60. package/engine/graphics/micron/render/v1/VGThreeRenderer.js +12 -9
  61. package/engine/graphics/micron/util/unit_hemioct.spec.js +2 -2
  62. package/engine/graphics/render/buffer/buffers/ColorAndDepthFrameBuffer.js +5 -3
  63. package/engine/graphics/render/buffer/buffers/NormalFrameBuffer.js +12 -2
  64. package/engine/graphics/render/buffer/buffers/prototypeNormalFrameBuffer.js +8 -10
  65. package/engine/graphics/render/forward_plus/LightManager.js +5 -7
  66. package/engine/graphics/render/forward_plus/data/NumericType.js +9 -0
  67. package/engine/graphics/render/forward_plus/{TextureBackedMemoryRegion.js → data/TextureBackedMemoryRegion.js} +11 -190
  68. package/engine/graphics/render/forward_plus/data/channelCountToThreIntegerTextureType.js +16 -0
  69. package/engine/graphics/render/forward_plus/data/computeDataType.js +36 -0
  70. package/engine/graphics/render/forward_plus/data/computeThreeTextureFormat.js +18 -0
  71. package/engine/graphics/render/forward_plus/data/computeThreeTextureInternalFormatFromDataType.js +63 -0
  72. package/engine/graphics/render/forward_plus/data/computeThreeTextureTypeFromDataType.js +41 -0
  73. package/engine/graphics/render/forward_plus/plugin/ptototypeFPPlugin.js +1 -1
  74. package/engine/graphics/render/forward_plus/prototypeLightManager.js +1 -1
  75. package/engine/graphics/render/utils/ThreeBypassRenderer.js +1 -3
  76. package/engine/graphics/render/visibility/hiz/buffer/HierarchicalZBuffer.js +198 -0
  77. package/engine/graphics/render/visibility/hiz/buffer/ReductionShader.js +51 -0
  78. package/engine/graphics/render/visibility/hiz/buildCanvasViewFromTexture.js +179 -0
  79. package/engine/graphics/render/visibility/hiz/prototypeHiZ.js +435 -0
  80. package/engine/graphics/render/visibility/hiz/query/BatchOcclusionQuery.js +174 -0
  81. package/engine/graphics/render/visibility/hiz/query/QueryShader.js +173 -0
  82. package/engine/graphics/shadows/ShadowMapRenderer.js +12 -2
  83. package/engine/graphics/texture/atlas/TextureAtlas.js +1 -1
  84. package/engine/graphics/texture/cubemap/buildCubeURLs.js +13 -0
  85. package/engine/graphics/texture/cubemap/load_environment_map.d.ts +8 -0
  86. package/engine/graphics/texture/cubemap/load_environment_map.js +163 -0
  87. package/engine/graphics/texture/sampler/Sampler2D.js +18 -62
  88. package/engine/graphics/texture/sampler/convertTexture2Sampler2D.js +8 -4
  89. package/engine/graphics/texture/sampler/debug/paintSamplerOnHTML.js +3 -2
  90. package/engine/graphics/texture/sampler/differenceSampler.js +31 -0
  91. package/engine/graphics/texture/sampler/typedArrayConstructorByInstance.js +25 -0
  92. package/engine/graphics/texture/sampler/util/drawSamplerHTML.js +3 -2
  93. package/engine/graphics/texture/virtual/v2/ShaderUsage.js +6 -5
  94. package/engine/graphics/texture/virtual/v2/prototype.js +16 -6
  95. package/package.json +1 -1
  96. package/view/elements/progress/segmented/SegmentedResourceBarView.js +50 -15
  97. package/view/minimap/gl/MinimapMarkersGL.js +2 -2
  98. package/engine/graphics/micron/render/RefinementSpec.js +0 -110
@@ -0,0 +1,198 @@
1
+ import { max2 } from "../../../../../../core/math/max2.js";
2
+ import { ceilPowerOfTwo } from "../../../../../../core/binary/operations/ceilPowerOfTwo.js";
3
+ import { ClampToEdgeWrapping, FloatType, NearestFilter, RedFormat, WebGLRenderTarget } from "three";
4
+ import { renderScreenSpace } from "../../../utils/renderScreenSpace.js";
5
+ import { makeReductionShader } from "./ReductionShader.js";
6
+ import Vector2 from "../../../../../../core/geom/Vector2.js";
7
+
8
+ export class HierarchicalZBuffer {
9
+ constructor() {
10
+ /**
11
+ *
12
+ * @type {THREE.Texture|null}
13
+ * @private
14
+ */
15
+ this.__input_buffer = null;
16
+
17
+ /**
18
+ *
19
+ * @type {THREE.WebGLRenderer|null}
20
+ * @private
21
+ */
22
+ this.__renderer = null;
23
+
24
+ /**
25
+ *
26
+ * @type {THREE.WebGLRenderTarget[]}
27
+ */
28
+ this.mips = [];
29
+
30
+ /**
31
+ *
32
+ * @type {ShaderMaterial}
33
+ * @private
34
+ */
35
+ this.__material = makeReductionShader();
36
+
37
+
38
+ /**
39
+ *
40
+ * @type {Vector2}
41
+ * @private
42
+ */
43
+ this.__resolution = new Vector2(0, 0);
44
+
45
+ /**
46
+ *
47
+ * @type {Vector2}
48
+ * @private
49
+ */
50
+ this.__limits = new Vector2(1, 1);
51
+ }
52
+
53
+ /**
54
+ *
55
+ * @return {Vector2}
56
+ */
57
+ get mip_limits() {
58
+ return this.__limits;
59
+ }
60
+
61
+ /**
62
+ * @param {THREE.WebGLRenderer} v
63
+ */
64
+ set renderer(v) {
65
+ this.__renderer = v;
66
+ }
67
+
68
+ /**
69
+ * @param {THREE.Texture} v
70
+ */
71
+ set input(v) {
72
+ this.__input_buffer = v;
73
+ }
74
+
75
+ build_mip_chain() {
76
+ const size_max = ceilPowerOfTwo(max2(this.__resolution.x, this.__resolution.y));
77
+ const mip_depth = Math.log2(size_max);
78
+
79
+ const mips = this.mips;
80
+ const existing_mip_depth = mips.length;
81
+
82
+ if (existing_mip_depth > mip_depth) {
83
+
84
+ for (let i = mip_depth; i < existing_mip_depth; i++) {
85
+ mips[i].dispose();
86
+ }
87
+
88
+ mips.splice(mip_depth, existing_mip_depth - mip_depth);
89
+
90
+ } else {
91
+
92
+ for (let i = existing_mip_depth; i < mip_depth; i++) {
93
+
94
+ mips[i] = new WebGLRenderTarget(1, 1, {
95
+ minFilter: NearestFilter,
96
+ magFilter: NearestFilter,
97
+ format: RedFormat,
98
+ type: FloatType,
99
+ internalFormat: 'R32F',
100
+ depthBuffer: false,
101
+ stencilBuffer: false,
102
+ wrapS: ClampToEdgeWrapping,
103
+ wrapT: ClampToEdgeWrapping,
104
+ generateMipmaps: false
105
+ });
106
+
107
+ }
108
+
109
+ }
110
+ }
111
+
112
+ /**
113
+ *
114
+ * @param {number} x
115
+ * @param {number} y
116
+ */
117
+ set_resolution(x, y) {
118
+ this.__resolution.set(x, y);
119
+
120
+ const mips = this.mips;
121
+ const mip_count = mips.length;
122
+
123
+ let _x = ceilPowerOfTwo(x);
124
+ let _y = ceilPowerOfTwo(y);
125
+
126
+ for (let i = 0; i < mip_count; i++) {
127
+ const mip = mips[i];
128
+
129
+ const _nx = max2(1, _x >> 1);
130
+ const _ny = max2(1, _y >> 1);
131
+
132
+ if (mip.width !== _nx || mip.height !== _ny) {
133
+ mip.setSize(_nx, _ny);
134
+ }
135
+
136
+ if (_nx === 1 && _x !== _nx) {
137
+ this.__limits.x = i;
138
+ }
139
+
140
+ if (_ny === 1 && _y !== _ny) {
141
+ this.__limits.y = i;
142
+ }
143
+
144
+ _x = _nx;
145
+ _y = _ny;
146
+ }
147
+ }
148
+
149
+ build_mips() {
150
+ const mips = this.mips;
151
+
152
+ let t0 = null;
153
+ let t1 = {
154
+ texture: this.__input_buffer
155
+ };
156
+
157
+ for (let i = 0; i < mips.length; i++) {
158
+ t0 = t1;
159
+ t1 = mips[i];
160
+
161
+ this.reduce_mip(t0.texture, t1);
162
+ }
163
+
164
+ this.__input_buffer.generateMipmaps = false;
165
+ this.__input_buffer.mips = mips.map(m => m.texture);
166
+ }
167
+
168
+ /**
169
+ * @private
170
+ * @param {THREE.Texture} input
171
+ * @param {THREE.WebGLRenderTarget} output
172
+ */
173
+ reduce_mip(input, output) {
174
+
175
+ const material = this.__material;
176
+ material.uniforms.source_texture.value = input;
177
+ material.uniforms.destination_resolution.value.set(output.width, output.height);
178
+ material.uniforms.source_resolution.value.set(input.image.width, input.image.height);
179
+
180
+ const renderer = this.__renderer;
181
+
182
+ const __rt = renderer.getRenderTarget();
183
+
184
+ renderer.setRenderTarget(output);
185
+
186
+ renderScreenSpace(renderer, material);
187
+
188
+ renderer.setRenderTarget(__rt);
189
+ }
190
+
191
+ /**
192
+ * Depth texture with mips
193
+ * @returns {THREE.Texture}
194
+ */
195
+ getTexture() {
196
+ return this.__input_buffer;
197
+ }
198
+ }
@@ -0,0 +1,51 @@
1
+ import { GLSL3, ShaderMaterial, Vector2 } from "three";
2
+
3
+ export function makeReductionShader() {
4
+ return new ShaderMaterial({
5
+ vertexShader: `
6
+ void main() {
7
+ gl_Position = vec4( position, 1.0 );
8
+ }
9
+ `,
10
+ fragmentShader: `
11
+ uniform sampler2D source_texture;
12
+
13
+ uniform vec2 source_resolution;
14
+ uniform vec2 destination_resolution;
15
+
16
+ out highp float out_value;
17
+
18
+ float reduce(float a, float b, float c, float d){
19
+ return max( a, max( b, max( c, d ) ) );
20
+ }
21
+
22
+ void main() {
23
+ vec2 source_uv = gl_FragCoord.xy / destination_resolution;
24
+ vec2 uv_mapping = source_resolution/destination_resolution;
25
+
26
+ ivec2 source_texel_uv_0 = ivec2( source_uv * source_resolution);
27
+
28
+ float d0 = texelFetch(source_texture, source_texel_uv_0, 0).x;
29
+ float d1 = texelFetch(source_texture, source_texel_uv_0 + ivec2( uv_mapping.x, 0 ), 0).x;
30
+ float d2 = texelFetch(source_texture, source_texel_uv_0 + ivec2( 0, uv_mapping.y ), 0).x;
31
+ float d3 = texelFetch(source_texture, source_texel_uv_0 + ivec2( uv_mapping.x, uv_mapping.y ), 0).x;
32
+
33
+ out_value = reduce(d0, d1, d2, d3);
34
+ }
35
+ `,
36
+ depthTest: false,
37
+ depthWrite: false,
38
+ uniforms: {
39
+ source_texture: {
40
+ value: null
41
+ },
42
+ destination_resolution: {
43
+ value: new Vector2()
44
+ },
45
+ source_resolution: {
46
+ value: new Vector2()
47
+ }
48
+ },
49
+ glslVersion: GLSL3
50
+ });
51
+ }
@@ -0,0 +1,179 @@
1
+ import { CanvasView } from "../../../../../view/elements/CanvasView.js";
2
+ import {
3
+ DoubleSide,
4
+ LinearFilter,
5
+ Mesh as ThreeMesh,
6
+ OrthographicCamera,
7
+ Scene,
8
+ ShaderMaterial,
9
+ UnsignedByteType,
10
+ WebGLRenderTarget
11
+ } from "three";
12
+ import CheckersTexture from "../../../texture/CheckersTexture.js";
13
+ import { FULL_SCREEN_TRIANGLE_GEOMETRY } from "../../../geometry/FULL_SCREEN_TRIANGLE_GEOMETRY.js";
14
+
15
+
16
+ /**
17
+ *
18
+ * @param {THREE.Texture} texture
19
+ * @returns {string}
20
+ */
21
+ function defineSamplerType(texture) {
22
+ switch (texture.format) {
23
+ case UnsignedByteType:
24
+ return 'usampler2D';
25
+ default:
26
+ return 'sampler2D'
27
+ }
28
+ }
29
+
30
+ /**
31
+ *
32
+ * @param {THREE.Texture} texture
33
+ * @param {string} name
34
+ * @param {string} uv
35
+ * @returns {string}
36
+ */
37
+ function sampleTexel(texture, name, uv) {
38
+ switch (texture.format) {
39
+ default:
40
+ return `texture2D(${name}, ${uv})`;
41
+ }
42
+ }
43
+
44
+ /**
45
+ *
46
+ * @param {THREE.Texture} texture
47
+ */
48
+ function makeShader(texture) {
49
+ return new ShaderMaterial({
50
+
51
+ vertexShader: /* glsl */`
52
+
53
+ varying vec2 vUv;
54
+
55
+ void main() {
56
+
57
+ vUv = uv;
58
+ gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );
59
+
60
+ }`,
61
+
62
+ fragmentShader: /* glsl */`
63
+
64
+ uniform ${defineSamplerType(texture)} tDiffuse;
65
+
66
+ varying vec2 vUv;
67
+
68
+ void main() {
69
+
70
+ vec4 texel = ${sampleTexel(texture, 'tDiffuse', 'vUv')};
71
+ gl_FragColor = texel;
72
+
73
+ gl_FragColor.a = 1.0;
74
+ // gl_FragColor.r *= 255.0;
75
+
76
+ }`,
77
+ uniforms: {
78
+
79
+ 'tDiffuse': { value: null }
80
+
81
+ }
82
+ });
83
+ }
84
+
85
+ /**
86
+ *
87
+ * @param {number} height
88
+ * @param {number} width
89
+ * @param {THREE.Texture} texture
90
+ * @param {THREE.WebGLRenderer} renderer
91
+ * @param flipY
92
+ * @return {{view: View, render: render}}
93
+ */
94
+ export function buildCanvasViewFromTexture({
95
+ height,
96
+ width,
97
+ texture = CheckersTexture.create(),
98
+ renderer,
99
+ flipY = true
100
+ }) {
101
+ const canvasView = new CanvasView();
102
+ canvasView.size.set(width, height);
103
+
104
+ const ctx = canvasView.context2d;
105
+
106
+ let copyShader = null;
107
+
108
+ const camera = new OrthographicCamera(-1, 1, 1, -1, 0, 1);
109
+ const scene = new Scene();
110
+ scene.add(camera);
111
+
112
+ const quad = new ThreeMesh(FULL_SCREEN_TRIANGLE_GEOMETRY, null);
113
+
114
+ if (flipY) {
115
+ quad.scale.y = -1;
116
+ }
117
+
118
+ scene.add(quad);
119
+
120
+ const gl = renderer.getContext();
121
+
122
+ const renderTargetOptions = {
123
+ generateMipmaps: false,
124
+ minFilter: LinearFilter,
125
+ stencilBuffer: false,
126
+ depthBuffer: false
127
+ };
128
+ const renderTarget = new WebGLRenderTarget(width, height, renderTargetOptions);
129
+
130
+ const imageData = ctx.createImageData(width, height);
131
+
132
+ let __texture_cached = texture;
133
+
134
+ /**
135
+ *
136
+ * @return {ShaderMaterial}
137
+ */
138
+ function getShader() {
139
+ if (__texture_cached !== texture || copyShader === null) {
140
+ copyShader = makeShader(texture);
141
+
142
+ copyShader.side = DoubleSide;
143
+ copyShader.uniforms.tDiffuse.value = texture;
144
+
145
+ quad.material = copyShader;
146
+
147
+ __texture_cached = texture;
148
+ }
149
+
150
+ return copyShader;
151
+ }
152
+
153
+ const render = () => {
154
+
155
+ getShader().uniforms.tDiffuse.value = texture;
156
+
157
+ renderer.setRenderTarget(renderTarget);
158
+
159
+ renderer.render(scene, camera);
160
+
161
+ gl.readPixels(0, 0, width, height, gl.RGBA, gl.UNSIGNED_BYTE, imageData.data);
162
+
163
+
164
+ ctx.putImageData(imageData, 0, 0)
165
+
166
+ renderer.setRenderTarget(null);
167
+ };
168
+
169
+ return {
170
+ view: canvasView,
171
+ render,
172
+ set texture(v) {
173
+
174
+ texture = v;
175
+
176
+ getShader().uniforms.tDiffuse.value = v;
177
+ }
178
+ }
179
+ }