@woosh/meep-engine 2.33.4 → 2.33.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/core/binary/BinaryBuffer.js +26 -2
- package/core/bvh2/LeafNode.js +6 -1
- package/core/bvh2/aabb3/AABB3.js +21 -1
- 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/set/compute_set_difference.js +32 -0
- package/core/collection/set/compute_set_intersection.js +22 -0
- package/core/collection/set/set_remove.js +15 -0
- package/core/collection/table/DataType2TypedArrayConstructorMapping.js +2 -0
- package/core/collection/table/DataTypeByteSizes.js +21 -0
- package/core/collection/table/RowFirstTable.js +1 -88
- package/core/collection/table/RowFirstTable.spec.js +3 -1
- package/core/collection/table/RowFirstTableSpec.js +9 -19
- package/core/collection/table/computeDataTypeByIndex.js +21 -0
- package/core/collection/table/deserializeRowFirstTable.js +48 -0
- package/core/collection/table/serializeRowFirstTable.js +27 -0
- package/core/color/Color.js +1 -0
- package/core/color/ColorUtils.js +12 -3
- package/core/geom/3d/aabb/aabb3_compute_projected_area.js +6 -4
- package/core/geom/3d/aabb/aabb3_estimate_projected_area2.js +59 -0
- package/core/geom/3d/aabb/aabb3_from_min_max.js +15 -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/aabb/aabb3_matrix4_project_by_corners.js +96 -0
- package/{engine/graphics/micron/render/v1 → core/geom/3d}/apply_mat4_transform_to_v3_array.js +0 -0
- package/{engine/graphics/micron/build/bounds → core/geom/3d}/compute_bounding_cone_of_2_cones.js +3 -3
- package/{engine/graphics/micron/build/bounds → core/geom/3d}/compute_bounding_cone_of_2_cones.spec.js +1 -1
- package/{engine/graphics/micron/build/bounds → core/geom/3d}/compute_bounding_sphere_of_2_spheres.js +3 -3
- package/{engine/graphics/micron/util → core/geom/3d}/encode_unit3_hemioct.js +0 -0
- package/core/geom/3d/frustum/array_normalize_plane.js +25 -0
- package/core/geom/3d/frustum/array_setFromProjectionMatrix.js +60 -0
- package/{engine/graphics/micron/util → core/geom/3d}/unit_hemioct.spec.js +1 -1
- package/{engine/graphics/micron/build → core}/graph/MultiNode.js +0 -0
- package/{engine/graphics/micron/build → core}/graph/SquareMatrix.js +2 -2
- package/{engine/graphics/micron/build → core}/graph/SquareMatrix.spec.js +1 -1
- package/{engine/graphics/micron/build → core}/graph/WeightedEdge.js +1 -1
- package/{engine/graphics/micron/build → core}/graph/build_face_graph_from_mesh.js +2 -2
- package/{engine/graphics/micron/build/clustering → core/graph}/cluster_mesh_metis.js +2 -6
- package/{engine/graphics/micron/build → core}/graph/coarsen_graph.js +1 -1
- package/{engine/graphics/micron/build → core}/graph/coarsen_graph.spec.js +1 -1
- package/{engine/graphics/micron/build → core}/graph/eigen/eigen.js +0 -0
- package/{engine/graphics/micron/build → core}/graph/eigen/eigen.spec.js +1 -1
- package/{engine/graphics/micron/build/hierarchy → core/graph/eigen}/eigen_values_find_spectral_gap.js +0 -0
- package/{engine/graphics/micron/build → core}/graph/graph_adjacency_matrix.js +0 -0
- package/{engine/graphics/micron/build → core}/graph/graph_compute_disconnected_clusters.js +0 -0
- package/{engine/graphics/micron/build → core}/graph/graph_degree_matrix.js +0 -0
- package/{engine/graphics/micron/build → core}/graph/graph_k_means_cluster.js +5 -5
- package/{engine/graphics/micron/build → core}/graph/graph_laplacian_matrix.js +1 -1
- package/{engine/graphics/micron/build → core}/graph/metis/metis.js +2 -2
- package/{engine/graphics/micron/build → core}/graph/metis/metis_options.js +0 -0
- package/{engine/graphics/micron/build → core}/graph/mn_graph_collapse_weighted_edge.js +0 -0
- 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/Engine.d.ts +2 -0
- package/engine/EngineHarness.js +4 -4
- package/engine/asset/loaders/material/bitmap2sampler_gl.js +19 -0
- package/engine/asset/loaders/material/computeImageBitmapEquality.js +7 -19
- package/engine/ecs/foliage/InstancedFoliage.js +3 -5
- package/engine/ecs/fow/serialization/FogOfWarSerializationAdapter.js +2 -1
- package/engine/ecs/transform/Transform.js +2 -1
- package/engine/graphics/GraphicsEngine.js +9 -116
- package/engine/graphics/ecs/mesh/updateNodeByTransformAndBBB.js +22 -37
- package/engine/graphics/ecs/mesh-v2/ShadedGeometry.js +155 -0
- package/engine/graphics/ecs/mesh-v2/ShadedGeometrySystem.js +68 -0
- package/engine/graphics/ecs/mesh-v2/prototypeShadedGeometry.js +31 -0
- 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 → geometry}/aabb3_to_buffer_geometry.js +0 -0
- package/engine/graphics/{micron/build → geometry/buffered}/compute_buffer_geometry_byte_size.js +0 -0
- package/engine/graphics/geometry/instancing/InstancedMeshGroup.js +25 -16
- package/engine/graphics/material/SplatMaterial.js +4 -97
- package/engine/graphics/micron/build/buildMicronGeometryFromBufferGeometry.js +2 -6
- package/engine/graphics/micron/build/clustering/build_clustering_2.js +2 -2
- package/engine/graphics/micron/build/clustering/build_leaf_patches_metis.js +1 -1
- package/engine/graphics/micron/build/fill_patch_geometry_data.js +2 -0
- package/engine/graphics/micron/build/hierarchy/buildAbstractPatchHierarchy.js +3 -3
- package/engine/graphics/micron/build/hierarchy/build_intermediate_patch_topology.js +0 -72
- package/engine/graphics/micron/build/hierarchy/build_merge_graph.js +2 -2
- package/engine/graphics/micron/build/hierarchy/computePatchMergeScore.js +3 -3
- package/engine/graphics/micron/build/hierarchy/merge_patches.js +6 -3
- package/engine/graphics/micron/build/hierarchy/metis_cluster_clusters.js +1 -1
- package/engine/graphics/micron/build/hierarchy/optimize_graph_partitioning_balance.js +1 -1
- package/engine/graphics/micron/build/hierarchy/patch_combine.js +2 -2
- package/engine/graphics/micron/build/hierarchy/qvdr_build_simplified_clusters.js +2 -1
- package/engine/graphics/micron/format/MicronGeometry.js +12 -0
- package/engine/graphics/micron/format/MicronGeometryBufferAttributeSpec.js +2 -2
- package/engine/graphics/micron/format/MicronGeometryPatch.js +17 -9
- package/engine/graphics/micron/format/MicronVertexDataSpec.js +25 -3
- package/engine/graphics/micron/format/serialization/MicronGeometryBinarySerializationAdapter.js +101 -0
- package/engine/graphics/micron/format/serialization/deserialize_attribute_spec.js +25 -0
- package/engine/graphics/micron/format/serialization/deserialize_patch.js +104 -0
- package/engine/graphics/micron/format/serialization/serialize_attribute_spec.js +18 -0
- package/engine/graphics/micron/format/serialization/serialize_patch.js +84 -0
- package/engine/graphics/micron/prototypeVirtualGeometry.js +1 -1
- package/engine/graphics/micron/render/VirtualGeometryBuilder.js +27 -23
- package/engine/graphics/micron/render/culling/{PathCullingSystem.js → PatchCullingSystem.js} +1 -1
- package/engine/graphics/micron/render/instanced/AttributeDataTexture.js +3 -5
- package/engine/graphics/micron/render/refinement/ActivePatchList.js +38 -49
- 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/v1/MaterialVertexSpec.js +21 -0
- package/engine/graphics/micron/render/v1/VGThreeRenderer.js +12 -9
- package/engine/graphics/micron/render/v1/getTransformedPositionsCached.js +1 -1
- package/engine/graphics/render/buffer/buffers/ColorAndDepthFrameBuffer.js +5 -3
- 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/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 +440 -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/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/TextureBinaryBufferSerializer.js +1 -1
- package/engine/graphics/texture/sampler/convertTexture2Sampler2D.js +3 -2
- 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/engine/network/convertPathToURL.js +6 -0
- package/engine/plugin/EnginePluginManager.d.ts +9 -0
- package/engine/reference/v2/Reference.d.ts +7 -0
- package/package.json +1 -1
- package/view/minimap/gl/MinimapMarkersGL.js +2 -2
- package/engine/graphics/micron/build/clustering/cluster_mesh_vertices.js +0 -3
- package/engine/graphics/micron/render/RefinementSpec.js +0 -181
|
@@ -0,0 +1,173 @@
|
|
|
1
|
+
import { GLSL3, ShaderMaterial, Vector2 } from "three";
|
|
2
|
+
|
|
3
|
+
export function makeQueryShader() {
|
|
4
|
+
return new ShaderMaterial({
|
|
5
|
+
vertexShader: `
|
|
6
|
+
void main() {
|
|
7
|
+
gl_Position = vec4( position, 1.0 );
|
|
8
|
+
}
|
|
9
|
+
`,
|
|
10
|
+
fragmentShader: `
|
|
11
|
+
uniform sampler2D utDepth;
|
|
12
|
+
uniform sampler2D utInput;
|
|
13
|
+
|
|
14
|
+
uniform vec2 uDepthMipLimits;
|
|
15
|
+
|
|
16
|
+
out highp vec4 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
|
+
vec3 read_input_v3(ivec2 start){
|
|
23
|
+
float x = texelFetch(utInput, start, 0).x;
|
|
24
|
+
float y = texelFetch(utInput, start + ivec2(1,0), 0).x;
|
|
25
|
+
float z = texelFetch(utInput, start + ivec2(2,0), 0).x;
|
|
26
|
+
|
|
27
|
+
return vec3(x,y,z);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
vec4 read_input_v4(ivec2 start){
|
|
31
|
+
return vec4(
|
|
32
|
+
read_input_v3(start),
|
|
33
|
+
texelFetch(utInput, start + ivec2(3,0) , 0).x
|
|
34
|
+
);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
mat4 read_input_m4(ivec2 start){
|
|
38
|
+
return mat4(
|
|
39
|
+
read_input_v4(start),
|
|
40
|
+
read_input_v4(start + ivec2(4,0)),
|
|
41
|
+
read_input_v4(start + ivec2(8,0)),
|
|
42
|
+
read_input_v4(start + ivec2(12,0))
|
|
43
|
+
);
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
vec3 project_vec3(vec3 value, mat4 transform){
|
|
47
|
+
vec4 v1 = transform * vec4( value, 1.0 );
|
|
48
|
+
v1.xyz /= abs(v1.w);
|
|
49
|
+
|
|
50
|
+
return v1.xyz;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
void project_aabb(out vec3 pb_min, out vec3 pb_max, in vec3 bb_min, in vec3 bb_max, in mat4 transform){
|
|
54
|
+
vec3 p0 = project_vec3( bb_min, transform );
|
|
55
|
+
vec3 p1 = project_vec3( vec3(bb_min.xy, bb_max.z), transform );
|
|
56
|
+
|
|
57
|
+
pb_min = min( p0, p1 );
|
|
58
|
+
pb_max = max( p0, p1 );
|
|
59
|
+
|
|
60
|
+
vec3 p2 = project_vec3( vec3(bb_min.x, bb_max.y, bb_min.z), transform );
|
|
61
|
+
|
|
62
|
+
pb_min = min( pb_min, p2 );
|
|
63
|
+
pb_max = max( pb_max, p2 );
|
|
64
|
+
|
|
65
|
+
vec3 p3 = project_vec3( vec3( bb_min.x, bb_max.y, bb_max.z ), transform );
|
|
66
|
+
|
|
67
|
+
pb_min = min( pb_min, p3 );
|
|
68
|
+
pb_max = max( pb_max, p3 );
|
|
69
|
+
|
|
70
|
+
vec3 p4 = project_vec3( vec3( bb_max.x, bb_min.y, bb_min.z), transform );
|
|
71
|
+
|
|
72
|
+
pb_min = min( pb_min, p4 );
|
|
73
|
+
pb_max = max( pb_max, p4 );
|
|
74
|
+
|
|
75
|
+
vec3 p5 = project_vec3( vec3( bb_max.x, bb_min.y, bb_max.z ), transform );
|
|
76
|
+
|
|
77
|
+
pb_min = min( pb_min, p5 );
|
|
78
|
+
pb_max = max( pb_max, p5 );
|
|
79
|
+
|
|
80
|
+
vec3 p6 = project_vec3( vec3( bb_max.x, bb_max.y, bb_min.z ), transform );
|
|
81
|
+
|
|
82
|
+
pb_min = min( pb_min, p6 );
|
|
83
|
+
pb_max = max( pb_max, p6 );
|
|
84
|
+
|
|
85
|
+
vec3 p7 = project_vec3( vec3( bb_max.x, bb_max.y, bb_max.z ), transform );
|
|
86
|
+
|
|
87
|
+
pb_min = min( pb_min, p7 );
|
|
88
|
+
pb_max = max( pb_max, p7 );
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
int compute_mip_level_for_dimension(float mip_limit, float ndc_extents){
|
|
92
|
+
return max(0, int( floor( mip_limit - log2( 1.0 / ndc_extents) ) ) );
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
float query_depth_from_screen_space_bb(in vec3 pb_min, in vec3 pb_max){
|
|
96
|
+
vec3 n_min = clamp( (pb_min+1.0)*0.5, 0.0, 1.0);
|
|
97
|
+
vec3 n_max = clamp( (pb_max+1.0)*0.5, 0.0, 1.0);
|
|
98
|
+
|
|
99
|
+
float bb_width = ( n_max.x - n_min.x ) * 0.5;
|
|
100
|
+
float bb_height = ( n_max.y - n_min.y ) * 0.5 ;
|
|
101
|
+
|
|
102
|
+
// pick coarsest z-buffer mip to test 4x4 pixels of the bounding box against
|
|
103
|
+
int mip_level_x = compute_mip_level_for_dimension( uDepthMipLimits.x, bb_width );
|
|
104
|
+
int mip_level_y = compute_mip_level_for_dimension( uDepthMipLimits.y, bb_height );
|
|
105
|
+
|
|
106
|
+
// figure out which mip level to use
|
|
107
|
+
int mip_to_use = max(mip_level_x, mip_level_y);
|
|
108
|
+
|
|
109
|
+
// sample 4 pixels that cover AABB
|
|
110
|
+
float n0 = textureLod(utDepth, n_min.xy, float(mip_to_use)).x;
|
|
111
|
+
float n1 = textureLod(utDepth, vec2(n_min.x, n_max.y), float(mip_to_use)).x;
|
|
112
|
+
float n2 = textureLod(utDepth, vec2(n_max.y, n_min.y), float(mip_to_use)).x;
|
|
113
|
+
float n3 = textureLod(utDepth, n_max.xy, float(mip_to_use)).x;
|
|
114
|
+
|
|
115
|
+
float n = max(n0, max(n1, max(n2,n3)));
|
|
116
|
+
|
|
117
|
+
float depth_delta = n - n_min.z;
|
|
118
|
+
|
|
119
|
+
return depth_delta;
|
|
120
|
+
// return float( uDepthMipLimits.x );
|
|
121
|
+
// return float( depth_delta*255.0 );
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
uint query_bounds(vec3 bb_min, vec3 bb_max, mat4 transform){
|
|
125
|
+
vec3 pb_min;
|
|
126
|
+
vec3 pb_max;
|
|
127
|
+
|
|
128
|
+
// project bounds to screen space
|
|
129
|
+
project_aabb(pb_min, pb_max, bb_min, bb_max, transform);
|
|
130
|
+
|
|
131
|
+
if(
|
|
132
|
+
pb_max.x < -1.0 || pb_max.y < -1.0 || pb_max.z < -1.0
|
|
133
|
+
|| pb_min.x > 1.0 || pb_min.y > 1.0 || pb_min.z > 1.0
|
|
134
|
+
){
|
|
135
|
+
// outside of view frustum
|
|
136
|
+
return 0u;
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
float n = query_depth_from_screen_space_bb( pb_min, pb_max );
|
|
140
|
+
|
|
141
|
+
if(n < 0.0){
|
|
142
|
+
return 0u;
|
|
143
|
+
}else{
|
|
144
|
+
return 255u;
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
void main() {
|
|
149
|
+
ivec2 input_offset = ivec2( int(gl_FragCoord.x) * ITEM_SIZE, int(gl_FragCoord.y) );
|
|
150
|
+
|
|
151
|
+
vec3 bb_min = read_input_v3(input_offset);
|
|
152
|
+
vec3 bb_max = read_input_v3(input_offset + ivec2(3,0));
|
|
153
|
+
mat4 transform = read_input_m4(input_offset + ivec2(6,0));
|
|
154
|
+
|
|
155
|
+
out_value = vec4( float( query_bounds(bb_min, bb_max, transform) ) / 255.0, 0.0, 0.0, 1.0 );
|
|
156
|
+
}
|
|
157
|
+
`,
|
|
158
|
+
depthTest: false,
|
|
159
|
+
depthWrite: false,
|
|
160
|
+
uniforms: {
|
|
161
|
+
utDepth: {
|
|
162
|
+
value: null
|
|
163
|
+
},
|
|
164
|
+
utInput: {
|
|
165
|
+
value: null
|
|
166
|
+
},
|
|
167
|
+
uDepthMipLimits: {
|
|
168
|
+
value: new Vector2(1, 1)
|
|
169
|
+
}
|
|
170
|
+
},
|
|
171
|
+
glslVersion: GLSL3
|
|
172
|
+
});
|
|
173
|
+
}
|
|
@@ -64,7 +64,6 @@ export class ShadowMapRenderer {
|
|
|
64
64
|
this.__renderer = renderer;
|
|
65
65
|
|
|
66
66
|
this.__ensure_map(shadow, renderer);
|
|
67
|
-
shadow_camera.updateProjectionMatrix();
|
|
68
67
|
|
|
69
68
|
// draw scene from perspective of shadow camera into the render texture
|
|
70
69
|
|
|
@@ -92,7 +91,7 @@ export class ShadowMapRenderer {
|
|
|
92
91
|
|
|
93
92
|
renderer.clear(true, true, false);
|
|
94
93
|
|
|
95
|
-
shadow.updateMatrices(light);
|
|
94
|
+
shadow.updateMatrices(light, 0);
|
|
96
95
|
|
|
97
96
|
this.onBeforeRender.send3(renderer, shadow_camera, scene);
|
|
98
97
|
|
|
@@ -123,6 +122,16 @@ export class ShadowMapRenderer {
|
|
|
123
122
|
__do_vsm_pass(shadow) {
|
|
124
123
|
const _renderer = this.__renderer;
|
|
125
124
|
|
|
125
|
+
if (shadowMaterialVertical.defines.VSM_SAMPLES !== shadow.blurSamples) {
|
|
126
|
+
|
|
127
|
+
shadowMaterialVertical.defines.VSM_SAMPLES = shadow.blurSamples;
|
|
128
|
+
shadowMaterialHorizontal.defines.VSM_SAMPLES = shadow.blurSamples;
|
|
129
|
+
|
|
130
|
+
shadowMaterialVertical.needsUpdate = true;
|
|
131
|
+
shadowMaterialHorizontal.needsUpdate = true;
|
|
132
|
+
|
|
133
|
+
}
|
|
134
|
+
|
|
126
135
|
// vertical pass
|
|
127
136
|
|
|
128
137
|
const vertical = shadowMaterialVertical.uniforms;
|
|
@@ -181,6 +190,7 @@ export class ShadowMapRenderer {
|
|
|
181
190
|
shadow.map = new WebGLRenderTarget(_shadowMapSize.x, _shadowMapSize.y, pars);
|
|
182
191
|
shadow.map.texture.name = '.shadowMap';
|
|
183
192
|
|
|
193
|
+
shadow.camera.updateProjectionMatrix();
|
|
184
194
|
}
|
|
185
195
|
}
|
|
186
196
|
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
*
|
|
3
|
+
* @param {String} path
|
|
4
|
+
* @param {String} format
|
|
5
|
+
* @returns {String[]}
|
|
6
|
+
*/
|
|
7
|
+
export function buildCubeURLs(path, format) {
|
|
8
|
+
return [
|
|
9
|
+
path + "posx" + format, path + "negx" + format,
|
|
10
|
+
path + "posy" + format, path + "negy" + format,
|
|
11
|
+
path + "posz" + format, path + "negz" + format
|
|
12
|
+
];
|
|
13
|
+
}
|
|
@@ -0,0 +1,163 @@
|
|
|
1
|
+
import { EXRLoader } from "three/examples/jsm/loaders/EXRLoader.js";
|
|
2
|
+
import { CubeTextureLoader, LinearFilter, PMREMGenerator, sRGBEncoding, TextureLoader, UnsignedByteType } from "three";
|
|
3
|
+
import { noop } from "../../../../core/function/Functions.js";
|
|
4
|
+
import { computeFileExtension } from "../../../../core/FilePath.js";
|
|
5
|
+
import { HDRCubeTextureLoader } from "three/examples/jsm/loaders/HDRCubeTextureLoader.js";
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
*
|
|
9
|
+
* @param {string[]|string} paths
|
|
10
|
+
* @return {Promise<THREE.CubeTexture>}
|
|
11
|
+
*/
|
|
12
|
+
function load_cube_texture(paths) {
|
|
13
|
+
// piece-wise cubemap, a collection of images for each face
|
|
14
|
+
const cubeTextureLoader = new CubeTextureLoader();
|
|
15
|
+
return new Promise((resolve, reject) => {
|
|
16
|
+
cubeTextureLoader.load(
|
|
17
|
+
paths,
|
|
18
|
+
texture => {
|
|
19
|
+
texture.magFilter = LinearFilter;
|
|
20
|
+
texture.encoding = sRGBEncoding;
|
|
21
|
+
resolve(texture);
|
|
22
|
+
},
|
|
23
|
+
noop,
|
|
24
|
+
reject
|
|
25
|
+
);
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
*
|
|
31
|
+
* @param {string[]|string} paths
|
|
32
|
+
* @return {Promise<THREE.CubeTexture>}
|
|
33
|
+
*/
|
|
34
|
+
function load_hdr_cube_texture(paths) {
|
|
35
|
+
// piece-wise cubemap, a collection of images for each face
|
|
36
|
+
const cubeTextureLoader = new HDRCubeTextureLoader();
|
|
37
|
+
return new Promise((resolve, reject) => {
|
|
38
|
+
cubeTextureLoader.load(
|
|
39
|
+
paths,
|
|
40
|
+
texture => {
|
|
41
|
+
resolve(texture);
|
|
42
|
+
},
|
|
43
|
+
noop,
|
|
44
|
+
reject
|
|
45
|
+
);
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
*
|
|
51
|
+
* @param {string} path
|
|
52
|
+
* @return {Promise<THREE.Texture>}
|
|
53
|
+
*/
|
|
54
|
+
function load_exr_texture(path) {
|
|
55
|
+
return new Promise((resolve, reject) => {
|
|
56
|
+
new EXRLoader()
|
|
57
|
+
.setDataType(UnsignedByteType)
|
|
58
|
+
.load(path, texture => {
|
|
59
|
+
resolve(texture);
|
|
60
|
+
}, noop, reject);
|
|
61
|
+
})
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
*
|
|
66
|
+
* @param {string} path
|
|
67
|
+
* @return {Promise<THREE.Texture>}
|
|
68
|
+
*/
|
|
69
|
+
function load_standard_texture(path) {
|
|
70
|
+
return new Promise((resolve, reject) => {
|
|
71
|
+
new TextureLoader()
|
|
72
|
+
.load(path, texture => {
|
|
73
|
+
texture.encoding = sRGBEncoding;
|
|
74
|
+
resolve(texture);
|
|
75
|
+
}, noop, reject);
|
|
76
|
+
})
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
/**
|
|
80
|
+
*
|
|
81
|
+
* @param {string|string[]} path
|
|
82
|
+
* @param {THREE.WebGLRenderer} [renderer]
|
|
83
|
+
* @param {boolean} [original]
|
|
84
|
+
* @param {boolean} [filtered]
|
|
85
|
+
* @returns {{original?:THREE.CubeTexture, filtered?: THREE.CubeTexture}}
|
|
86
|
+
*/
|
|
87
|
+
export async function load_environment_map({ path, renderer, original = false, filtered = true }) {
|
|
88
|
+
/**
|
|
89
|
+
* @type {string} 'e' or 'c'
|
|
90
|
+
*/
|
|
91
|
+
let type;
|
|
92
|
+
|
|
93
|
+
/**
|
|
94
|
+
* @type {THREE.WebGLCubeRenderTarget}
|
|
95
|
+
*/
|
|
96
|
+
let cube_rt;
|
|
97
|
+
|
|
98
|
+
/**
|
|
99
|
+
* @type {THREE.Texture|THREE.CubeTexture}
|
|
100
|
+
*/
|
|
101
|
+
let texture;
|
|
102
|
+
|
|
103
|
+
if (Array.isArray(path)) {
|
|
104
|
+
const ext = computeFileExtension(path[0]);
|
|
105
|
+
|
|
106
|
+
if (ext === 'hdr') {
|
|
107
|
+
texture = await load_hdr_cube_texture(path);
|
|
108
|
+
} else {
|
|
109
|
+
texture = await load_cube_texture(path);
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
type = 'c';
|
|
113
|
+
|
|
114
|
+
} else if (typeof path === 'string') {
|
|
115
|
+
// single cubemap
|
|
116
|
+
const extension = computeFileExtension(path).toLowerCase();
|
|
117
|
+
if (extension === 'exr') {
|
|
118
|
+
texture = await load_exr_texture(path);
|
|
119
|
+
} else if (extension === 'jpg') {
|
|
120
|
+
texture = await load_standard_texture(path);
|
|
121
|
+
} else {
|
|
122
|
+
// unsupported extension
|
|
123
|
+
throw new Error(`Unsupported cube map texture extension '${extension}'`);
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
type = 'e';
|
|
127
|
+
|
|
128
|
+
} else {
|
|
129
|
+
throw new Error(`Unsupported parameter format: '${path}'`);
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
const result = {};
|
|
133
|
+
|
|
134
|
+
if (filtered) {
|
|
135
|
+
|
|
136
|
+
if (renderer === undefined) {
|
|
137
|
+
throw new Error('renderer argument not supplied, expected a WebGLRenderer');
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
const pmremGenerator = new PMREMGenerator(renderer);
|
|
141
|
+
|
|
142
|
+
if (type === 'c') {
|
|
143
|
+
cube_rt = pmremGenerator.fromCubemap(texture);
|
|
144
|
+
} else if (type === 'e') {
|
|
145
|
+
cube_rt = pmremGenerator.fromEquirectangular(texture);
|
|
146
|
+
} else {
|
|
147
|
+
throw new Error(`Unsupported cubemap type '${type}'`);
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
pmremGenerator.dispose();
|
|
151
|
+
|
|
152
|
+
result.filtered = cube_rt.texture;
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
if (original) {
|
|
156
|
+
result.original = texture;
|
|
157
|
+
} else {
|
|
158
|
+
// cleanup
|
|
159
|
+
texture.dispose();
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
return result;
|
|
163
|
+
}
|
|
@@ -3,13 +3,13 @@
|
|
|
3
3
|
*/
|
|
4
4
|
|
|
5
5
|
|
|
6
|
-
import Vector4 from "../../../../core/geom/Vector4.js";
|
|
7
6
|
import { clamp } from "../../../../core/math/clamp.js";
|
|
8
7
|
import { max2 } from "../../../../core/math/max2.js";
|
|
9
8
|
import { min2 } from "../../../../core/math/min2.js";
|
|
10
9
|
import { mix } from "../../../../core/math/mix.js";
|
|
11
10
|
import { BlendingType } from "./BlendingType.js";
|
|
12
11
|
import { assert } from "../../../../core/assert.js";
|
|
12
|
+
import { typedArrayConstructorByInstance } from "./typedArrayConstructorByInstance.js";
|
|
13
13
|
|
|
14
14
|
function v2CrossMag(ax, ay, bx, by) {
|
|
15
15
|
return ax * by - ay * bx;
|
|
@@ -1319,8 +1319,8 @@ Sampler2D.prototype.fill = function (x, y, width, height, value) {
|
|
|
1319
1319
|
* @param {number} value
|
|
1320
1320
|
*/
|
|
1321
1321
|
Sampler2D.prototype.writeChannel = function (x, y, channel, value) {
|
|
1322
|
-
assert.
|
|
1323
|
-
assert.
|
|
1322
|
+
assert.isNumber(x, "x");
|
|
1323
|
+
assert.isNumber(y, "y");
|
|
1324
1324
|
|
|
1325
1325
|
assert.greaterThanOrEqual(x, 0);
|
|
1326
1326
|
assert.greaterThanOrEqual(y, 0);
|
|
@@ -1385,32 +1385,6 @@ Sampler2D.prototype.traverseCircle = function (centerX, centerY, radius, visitor
|
|
|
1385
1385
|
}
|
|
1386
1386
|
};
|
|
1387
1387
|
|
|
1388
|
-
export function arrayConstructorByInstance(a) {
|
|
1389
|
-
if (a instanceof Int8Array) {
|
|
1390
|
-
return Int8Array;
|
|
1391
|
-
} else if (a instanceof Int16Array) {
|
|
1392
|
-
return Int16Array;
|
|
1393
|
-
} else if (a instanceof Int32Array) {
|
|
1394
|
-
return Int32Array;
|
|
1395
|
-
} else if (a instanceof Uint8Array) {
|
|
1396
|
-
return Uint8Array;
|
|
1397
|
-
} else if (a instanceof Uint8ClampedArray) {
|
|
1398
|
-
return Uint8ClampedArray;
|
|
1399
|
-
} else if (a instanceof Uint16Array) {
|
|
1400
|
-
return Uint16Array;
|
|
1401
|
-
} else if (a instanceof Uint32Array) {
|
|
1402
|
-
return Uint32Array;
|
|
1403
|
-
} else if (a instanceof Float32Array) {
|
|
1404
|
-
return Float32Array;
|
|
1405
|
-
} else if (a instanceof Float64Array) {
|
|
1406
|
-
return Float64Array;
|
|
1407
|
-
} else if (Array.isArray(a)) {
|
|
1408
|
-
return Array;
|
|
1409
|
-
} else {
|
|
1410
|
-
throw new TypeError(`Unsupported array type`);
|
|
1411
|
-
}
|
|
1412
|
-
}
|
|
1413
|
-
|
|
1414
1388
|
/**
|
|
1415
1389
|
*
|
|
1416
1390
|
* @param {number} x
|
|
@@ -1419,31 +1393,40 @@ export function arrayConstructorByInstance(a) {
|
|
|
1419
1393
|
*/
|
|
1420
1394
|
Sampler2D.prototype.resize = function (x, y, preserveData = true) {
|
|
1421
1395
|
|
|
1396
|
+
const _w = this.width;
|
|
1397
|
+
const _h = this.height;
|
|
1398
|
+
|
|
1399
|
+
if (_w === x && _h === y) {
|
|
1400
|
+
// size didn't change
|
|
1401
|
+
return;
|
|
1402
|
+
}
|
|
1403
|
+
|
|
1422
1404
|
const itemSize = this.itemSize;
|
|
1405
|
+
|
|
1423
1406
|
const length = x * y * itemSize;
|
|
1424
1407
|
|
|
1425
1408
|
const oldData = this.data;
|
|
1426
1409
|
|
|
1427
|
-
const Constructor =
|
|
1410
|
+
const Constructor = typedArrayConstructorByInstance(oldData);
|
|
1428
1411
|
|
|
1429
1412
|
const newData = new Constructor(length);
|
|
1430
1413
|
|
|
1431
1414
|
if (preserveData) {
|
|
1432
1415
|
//copy old data
|
|
1433
|
-
if (x ===
|
|
1416
|
+
if (x === _w) {
|
|
1434
1417
|
// number of columns is preserved, we can just copy the old data across
|
|
1435
1418
|
newData.set(oldData.subarray(0, Math.min(oldData.length, length)));
|
|
1436
1419
|
} else {
|
|
1437
1420
|
//we need to copy new data row-by-row
|
|
1438
|
-
const rowCount = min2(y,
|
|
1421
|
+
const rowCount = min2(y, _h);
|
|
1439
1422
|
|
|
1440
|
-
const columnCount = min2(x,
|
|
1423
|
+
const columnCount = min2(x, _w);
|
|
1441
1424
|
|
|
1442
1425
|
for (let i = 0; i < rowCount; i++) {
|
|
1443
1426
|
for (let j = 0; j < columnCount; j++) {
|
|
1444
1427
|
|
|
1445
1428
|
const targetItemAddress = (i * x + j) * itemSize;
|
|
1446
|
-
const sourceItemAddress = (i *
|
|
1429
|
+
const sourceItemAddress = (i * _w + j) * itemSize;
|
|
1447
1430
|
|
|
1448
1431
|
for (let k = 0; k < itemSize; k++) {
|
|
1449
1432
|
|
|
@@ -1457,6 +1440,7 @@ Sampler2D.prototype.resize = function (x, y, preserveData = true) {
|
|
|
1457
1440
|
|
|
1458
1441
|
this.width = x;
|
|
1459
1442
|
this.height = y;
|
|
1443
|
+
|
|
1460
1444
|
this.data = newData;
|
|
1461
1445
|
};
|
|
1462
1446
|
|
|
@@ -1563,31 +1547,3 @@ Sampler2D.prototype.traverseOrthogonalNeighbours = function (x, y, visitor, this
|
|
|
1563
1547
|
}
|
|
1564
1548
|
};
|
|
1565
1549
|
|
|
1566
|
-
/**
|
|
1567
|
-
*
|
|
1568
|
-
* @param {Sampler2D} sampler0
|
|
1569
|
-
* @param {Sampler2D} sampler1
|
|
1570
|
-
* @returns {Sampler2D}
|
|
1571
|
-
*/
|
|
1572
|
-
export function differenceSampler(sampler0, sampler1) {
|
|
1573
|
-
let v0 = new Vector4();
|
|
1574
|
-
let v1 = new Vector4();
|
|
1575
|
-
//
|
|
1576
|
-
const width = sampler0.width;
|
|
1577
|
-
const height = sampler0.height;
|
|
1578
|
-
//
|
|
1579
|
-
const difference = new Float32Array(width * height);
|
|
1580
|
-
for (let y = 0; y < height; y++) {
|
|
1581
|
-
for (let x = 0; x < width; x++) {
|
|
1582
|
-
v0 = sampler0.get(x, y, v0);
|
|
1583
|
-
v1 = sampler1.get(x, y, v1);
|
|
1584
|
-
v0.normalize();
|
|
1585
|
-
v1.normalize();
|
|
1586
|
-
//check distance
|
|
1587
|
-
difference[x + y * width] = 1 - v0.dot(v1);
|
|
1588
|
-
}
|
|
1589
|
-
}
|
|
1590
|
-
//
|
|
1591
|
-
const sampleD = new Sampler2D(difference, 1, width, height);
|
|
1592
|
-
return sampleD;
|
|
1593
|
-
}
|
|
@@ -2,8 +2,8 @@ import { DataTypeIndices } from "../../../../core/collection/table/DataTypeIndic
|
|
|
2
2
|
import { Sampler2D } from "./Sampler2D.js";
|
|
3
3
|
import { EndianType } from "../../../../core/binary/BinaryBuffer.js";
|
|
4
4
|
import { DataType } from "../../../../core/collection/table/DataType.js";
|
|
5
|
-
import { DataTypeByteSizes } from "../../../../core/collection/table/RowFirstTableSpec.js";
|
|
6
5
|
import { assert } from "../../../../core/assert.js";
|
|
6
|
+
import { DataTypeByteSizes } from "../../../../core/collection/table/DataTypeByteSizes.js";
|
|
7
7
|
|
|
8
8
|
|
|
9
9
|
/**
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { WebGLRendererPool } from "../../render/RendererPool.js";
|
|
2
|
-
import ImageFilter
|
|
2
|
+
import ImageFilter from "../../filter/ImageFilter.js";
|
|
3
3
|
import { Sampler2D } from "./Sampler2D.js";
|
|
4
4
|
import CopyShader from "../../postprocess/threejs/shaders/CopyShader.js";
|
|
5
|
+
import { flipArrayInPlace } from "../../filter/FlipArrayInPlace.js";
|
|
5
6
|
|
|
6
7
|
|
|
7
8
|
const DEFAULT_TEXTURE_WIDTH = 512;
|
|
@@ -65,7 +66,7 @@ export function convertTexture2Sampler2D(texture, width, height, flipY = true) {
|
|
|
65
66
|
value: texture,
|
|
66
67
|
type: 't'
|
|
67
68
|
},
|
|
68
|
-
|
|
69
|
+
opacity: { value: 1.0 }
|
|
69
70
|
}
|
|
70
71
|
});
|
|
71
72
|
|
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Sampler2D } from "../Sampler2D.js";
|
|
2
2
|
import { scaleSampler2D } from "../scaleSampler2D.js";
|
|
3
3
|
import convertSampler2D2Canvas from "../Sampler2D2Canvas.js";
|
|
4
|
+
import { typedArrayConstructorByInstance } from "../typedArrayConstructorByInstance.js";
|
|
4
5
|
|
|
5
6
|
/**
|
|
6
7
|
*
|
|
@@ -14,7 +15,7 @@ export function paintSamplerOnHTML(s, x, y, scale, offset) {
|
|
|
14
15
|
|
|
15
16
|
const d = 180;
|
|
16
17
|
|
|
17
|
-
const target = new Sampler2D(
|
|
18
|
+
const target = new Sampler2D(typedArrayConstructorByInstance(s.data), s.itemSize, d, d);
|
|
18
19
|
|
|
19
20
|
scaleSampler2D(s, target);
|
|
20
21
|
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import Vector4 from "../../../../core/geom/Vector4.js";
|
|
2
|
+
import { Sampler2D } from "./Sampler2D.js";
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
*
|
|
6
|
+
* @param {Sampler2D} sampler0
|
|
7
|
+
* @param {Sampler2D} sampler1
|
|
8
|
+
* @returns {Sampler2D}
|
|
9
|
+
*/
|
|
10
|
+
export function differenceSampler(sampler0, sampler1) {
|
|
11
|
+
let v0 = new Vector4();
|
|
12
|
+
let v1 = new Vector4();
|
|
13
|
+
//
|
|
14
|
+
const width = sampler0.width;
|
|
15
|
+
const height = sampler0.height;
|
|
16
|
+
//
|
|
17
|
+
const difference = new Float32Array(width * height);
|
|
18
|
+
for (let y = 0; y < height; y++) {
|
|
19
|
+
for (let x = 0; x < width; x++) {
|
|
20
|
+
v0 = sampler0.get(x, y, v0);
|
|
21
|
+
v1 = sampler1.get(x, y, v1);
|
|
22
|
+
v0.normalize();
|
|
23
|
+
v1.normalize();
|
|
24
|
+
//check distance
|
|
25
|
+
difference[x + y * width] = 1 - v0.dot(v1);
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
//
|
|
29
|
+
const sampleD = new Sampler2D(difference, 1, width, height);
|
|
30
|
+
return sampleD;
|
|
31
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
export function typedArrayConstructorByInstance(a) {
|
|
2
|
+
if (a instanceof Int8Array) {
|
|
3
|
+
return Int8Array;
|
|
4
|
+
} else if (a instanceof Int16Array) {
|
|
5
|
+
return Int16Array;
|
|
6
|
+
} else if (a instanceof Int32Array) {
|
|
7
|
+
return Int32Array;
|
|
8
|
+
} else if (a instanceof Uint8Array) {
|
|
9
|
+
return Uint8Array;
|
|
10
|
+
} else if (a instanceof Uint8ClampedArray) {
|
|
11
|
+
return Uint8ClampedArray;
|
|
12
|
+
} else if (a instanceof Uint16Array) {
|
|
13
|
+
return Uint16Array;
|
|
14
|
+
} else if (a instanceof Uint32Array) {
|
|
15
|
+
return Uint32Array;
|
|
16
|
+
} else if (a instanceof Float32Array) {
|
|
17
|
+
return Float32Array;
|
|
18
|
+
} else if (a instanceof Float64Array) {
|
|
19
|
+
return Float64Array;
|
|
20
|
+
} else if (Array.isArray(a)) {
|
|
21
|
+
return Array;
|
|
22
|
+
} else {
|
|
23
|
+
throw new TypeError(`Unsupported array type`);
|
|
24
|
+
}
|
|
25
|
+
}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Sampler2D } from "../Sampler2D.js";
|
|
2
2
|
import { scaleSampler2D } from "../scaleSampler2D.js";
|
|
3
3
|
import convertSampler2D2Canvas from "../Sampler2D2Canvas.js";
|
|
4
|
+
import { typedArrayConstructorByInstance } from "../typedArrayConstructorByInstance.js";
|
|
4
5
|
|
|
5
6
|
/**
|
|
6
7
|
*
|
|
@@ -15,7 +16,7 @@ import convertSampler2D2Canvas from "../Sampler2D2Canvas.js";
|
|
|
15
16
|
export function drawSamplerHTML(parentNode, sampler, x, y, scale, offset, size) {
|
|
16
17
|
|
|
17
18
|
|
|
18
|
-
const target = new Sampler2D(
|
|
19
|
+
const target = new Sampler2D(typedArrayConstructorByInstance(sampler.data), sampler.itemSize, size, size);
|
|
19
20
|
|
|
20
21
|
scaleSampler2D(sampler, target);
|
|
21
22
|
|