@woosh/meep-engine 2.75.2 → 2.75.4
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/build/meep.cjs +56 -60
- package/build/meep.min.js +1 -1
- package/build/meep.module.js +56 -60
- package/package.json +1 -1
- package/src/core/geom/3d/ray/ray_computeNearestPointToPoint.js +7 -1
- package/src/core/geom/3d/topology/simplify/compute_face_normal_change_dot_product.js +19 -39
- package/src/core/geom/3d/v3_compute_triangle_normal.js +1 -1
- package/src/core/geom/Quaternion.js +0 -59
- package/src/engine/asset/loaders/image/ImageRGBADataLoader.js +2 -1
- package/src/engine/graphics/ecs/mesh-v2/aggregate/SGMeshHighlightSystem.js +7 -1
- package/src/engine/graphics/geometry/VertexDataSpec.d.ts +10 -0
- package/src/engine/graphics/geometry/VertexDataSpec.js +20 -21
- package/src/engine/graphics/render/visibility/hiz/buildCanvasViewFromTexture.js +41 -10
- package/src/engine/graphics/texture/formatToChannelCount.js +2 -1
- package/src/engine/graphics/texture/sampler/filter/sampler2d_scale_down_generic.js +2 -2
- package/src/engine/graphics/texture/sampler/prototypeSamplerFiltering.js +20 -19
- package/src/engine/graphics/texture/virtual/v2/NOTES.md +93 -1
- package/src/engine/graphics/texture/virtual/v2/VirtualTextureMaterial.js +193 -0
- package/src/engine/graphics/texture/virtual/v2/VirtualTextureMemoryMapping.js +203 -0
- package/src/engine/graphics/texture/virtual/v2/{PageTexture.js → VirtualTexturePage.js} +151 -22
- package/src/engine/graphics/texture/virtual/v2/VirtualTextureTileLoader.js +10 -1
- package/src/engine/graphics/texture/virtual/v2/VirtualTextureUsage.js +43 -10
- package/src/engine/graphics/texture/virtual/v2/VirtualTextureUsageShader.js +3 -3
- package/src/engine/graphics/texture/virtual/v2/VirtualTextureUsageUpdater.js +39 -11
- package/src/engine/graphics/texture/virtual/v2/debug/ResidencyDebugView.js +20 -5
- package/src/engine/graphics/texture/virtual/v2/prototype.js +148 -62
- package/src/engine/graphics/texture/virtual/v2/tile/VirtualTextureTile.js +4 -0
- package/src/core/bvh2/sah/surfaceAreaHeuristic.js +0 -15
- package/src/core/bvh2/sah/surfaceAreaHeuristicFull.js +0 -14
- package/src/core/geom/3d/aabb/computeBoundingBoxFromVertexData.js +0 -12
- package/src/core/geom/3d/frustum/array_normalize_plane.js +0 -25
- package/src/core/geom/3d/plane/lerp_planes_to_array.js +0 -53
- package/src/core/geom/3d/plane/planeRayIntersection.js +0 -14
- package/src/core/geom/3d/voxel/DenseBitVolume3D.js +0 -87
- package/src/core/geom/3d/voxel/buildVolumeFromProjectedGeometry.js +0 -23
- package/src/engine/graphics/texture/virtual/v2/ResidentTileTexture.js +0 -46
- /package/src/core/math/{bessel_i0.spec.js → bessel_j0.spec.js} +0 -0
|
@@ -1,29 +1,26 @@
|
|
|
1
|
-
import { GUI } from "dat.gui";
|
|
2
1
|
import {
|
|
3
2
|
AmbientLight,
|
|
4
3
|
Clock,
|
|
5
4
|
DirectionalLight,
|
|
6
|
-
DoubleSide,
|
|
7
5
|
Matrix4,
|
|
8
6
|
Mesh,
|
|
9
|
-
MeshBasicMaterial,
|
|
10
7
|
PerspectiveCamera,
|
|
11
8
|
PlaneBufferGeometry,
|
|
12
9
|
Scene,
|
|
13
|
-
TextureLoader,
|
|
14
10
|
Vector2,
|
|
15
11
|
WebGLRenderer
|
|
16
12
|
} from "three";
|
|
17
13
|
import { OrbitControls } from "three/examples/jsm/controls/OrbitControls.js";
|
|
18
|
-
import
|
|
14
|
+
import Signal from "../../../../../core/events/signal/Signal.js";
|
|
15
|
+
import { CSS_ABSOLUTE_POSITIONING } from "../../../../../view/CSS_ABSOLUTE_POSITIONING.js";
|
|
19
16
|
import EmptyView from "../../../../../view/elements/EmptyView.js";
|
|
20
17
|
import { AssetManager } from "../../../../asset/AssetManager.js";
|
|
21
18
|
import { GameAssetType } from "../../../../asset/GameAssetType.js";
|
|
22
19
|
import { ImageRGBADataLoader } from "../../../../asset/loaders/image/ImageRGBADataLoader.js";
|
|
23
|
-
import {
|
|
24
|
-
import {
|
|
25
|
-
import {
|
|
26
|
-
import {
|
|
20
|
+
import { buildCanvasViewFromTexture } from "../../../render/visibility/hiz/buildCanvasViewFromTexture.js";
|
|
21
|
+
import { VirtualTextureMaterial } from "./VirtualTextureMaterial.js";
|
|
22
|
+
import { VirtualTextureMemoryMapping } from "./VirtualTextureMemoryMapping.js";
|
|
23
|
+
import { VirtualTexturePage } from "./VirtualTexturePage.js";
|
|
27
24
|
import { VirtualTextureUsageUpdater } from "./VirtualTextureUsageUpdater.js";
|
|
28
25
|
|
|
29
26
|
let camera,
|
|
@@ -37,40 +34,53 @@ let camera,
|
|
|
37
34
|
*/
|
|
38
35
|
scene;
|
|
39
36
|
|
|
40
|
-
let mesh;
|
|
37
|
+
// let mesh;
|
|
41
38
|
|
|
42
|
-
const
|
|
39
|
+
const signal_render = new Signal();
|
|
40
|
+
|
|
41
|
+
// const TEXTURE_URL = "data/textures/utility/uv_map_reference.png";
|
|
42
|
+
// const TEXTURE_URL = "data/textures/utility/maurus_uv_checker_8k/UV-CheckerMap_Maurus_01_8K.png";
|
|
43
43
|
// const TEXTURE_URL = "data/textures/utility/4096x4096TexelDensityTexture1.png";
|
|
44
44
|
// const TEXTURE_URL = "data/textures/utility/Lenna.png";
|
|
45
45
|
// const TEXTURE_URL = "data/textures/utility/TESTIMAGES/SAMPLING/8BIT/RGB/2448x2448/SRC/img_2448x2448_3x8bit_SRC_RGB_cards_a.png";
|
|
46
46
|
// const TEXTURE_URL = "data/models/LowPolyTownshipSet/Town_Hall//diffuse_2048.png";
|
|
47
47
|
|
|
48
48
|
const virtualTextureManager = new VirtualTextureUsageUpdater();
|
|
49
|
-
const
|
|
50
|
-
const residencyDebugView = new ResidencyDebugView();
|
|
49
|
+
const virtualTexturePage = new VirtualTexturePage();
|
|
50
|
+
// const residencyDebugView = new ResidencyDebugView({ scale: 1 });
|
|
51
|
+
const memoryMapping = new VirtualTextureMemoryMapping();
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
// const usageDebugView = new UsageDebugView();
|
|
55
|
+
// usageDebugView.position.set(0,256);
|
|
56
|
+
|
|
57
|
+
window.page = virtualTexturePage;
|
|
58
|
+
window.mapping = memoryMapping;
|
|
59
|
+
window.usage = virtualTextureManager.usage_metadata;
|
|
51
60
|
|
|
52
61
|
const container_view = new EmptyView();
|
|
53
62
|
|
|
54
63
|
const options = {
|
|
55
|
-
spin: false
|
|
64
|
+
spin: false,
|
|
65
|
+
get jitter_samples() {
|
|
66
|
+
return virtualTextureManager.frame_jitter_enabled
|
|
67
|
+
},
|
|
68
|
+
set jitter_samples(v) {
|
|
69
|
+
virtualTextureManager.frame_jitter_enabled = v;
|
|
70
|
+
}
|
|
56
71
|
};
|
|
57
72
|
|
|
58
73
|
init();
|
|
59
74
|
|
|
60
|
-
function makeMesh() {
|
|
61
|
-
const size =
|
|
75
|
+
function makeMesh(mat) {
|
|
76
|
+
const size = 10;
|
|
62
77
|
|
|
63
|
-
const map = new TextureLoader().load(TEXTURE_URL);
|
|
64
|
-
map.flipY = false;
|
|
65
78
|
|
|
66
79
|
// const geo = new TetrahedronBufferGeometry(size,30);
|
|
67
80
|
// const geo = new TorusGeometry(size, 0.3, 30, 30);
|
|
68
81
|
const geo = new PlaneBufferGeometry(size, size);
|
|
69
82
|
|
|
70
|
-
mesh = new Mesh(geo,
|
|
71
|
-
map,
|
|
72
|
-
side: DoubleSide
|
|
73
|
-
}));
|
|
83
|
+
const mesh = new Mesh(geo, mat);
|
|
74
84
|
const m4 = new Matrix4();
|
|
75
85
|
|
|
76
86
|
// m4.makeRotationZ(-Math.PI/2);
|
|
@@ -81,16 +91,8 @@ function makeMesh() {
|
|
|
81
91
|
// mesh.rotation.x = 0.3;
|
|
82
92
|
|
|
83
93
|
scene.add(mesh);
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
function makeGLTF(path) {
|
|
87
|
-
|
|
88
|
-
new GLTFLoader().load(path, (gltf) => {
|
|
89
|
-
|
|
90
|
-
mesh = gltf.scene;
|
|
91
|
-
scene.add(mesh);
|
|
92
94
|
|
|
93
|
-
|
|
95
|
+
return mesh;
|
|
94
96
|
}
|
|
95
97
|
|
|
96
98
|
async function init() {
|
|
@@ -100,39 +102,60 @@ async function init() {
|
|
|
100
102
|
am.startup();
|
|
101
103
|
|
|
102
104
|
virtualTextureManager.setTextureParameters(
|
|
103
|
-
|
|
105
|
+
// 32768,
|
|
106
|
+
// 16384,
|
|
107
|
+
// 8192,
|
|
108
|
+
// 2048,
|
|
104
109
|
// 16384,
|
|
110
|
+
512,
|
|
105
111
|
32,
|
|
112
|
+
// 128,
|
|
106
113
|
3
|
|
107
114
|
);
|
|
108
115
|
|
|
109
|
-
|
|
110
|
-
|
|
116
|
+
virtualTexturePage.tile_resolution = virtualTextureManager.tile_resolution;
|
|
117
|
+
|
|
118
|
+
// virtualTexturePage.path = "data/textures/utility/maurus_uv_checker_8k/vt-01-32";
|
|
119
|
+
// virtualTexturePage.path = "data/textures/utility/maurus_uv_checker_8k/vt-01-128";
|
|
120
|
+
// virtualTexturePage.path = "data/textures/utility/azeroth/vt-01-128";
|
|
121
|
+
// virtualTexturePage.path = "data/textures/utility/aco-greece/vt-01-128";
|
|
122
|
+
// sparseTexture.path = "data/textures/utility/vt/uv_map_reference";
|
|
123
|
+
// virtualTexturePage.path = "data/textures/utility/vt/Lenna";
|
|
124
|
+
virtualTexturePage.path = "data/textures/utility/Lenna/vt-01-32";
|
|
111
125
|
// sparseTexture.path = "data/textures/utility/vt/TexelDensity1";
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
126
|
+
// virtualTexturePage.page_texture_size = [32, 64];
|
|
127
|
+
// virtualTexturePage.page_texture_size = [256, 256];
|
|
128
|
+
// virtualTexturePage.page_texture_size = [280, 280];
|
|
129
|
+
// virtualTexturePage.page_texture_size = [256,512];
|
|
130
|
+
virtualTexturePage.page_texture_size = [512, 512];
|
|
131
|
+
// virtualTexturePage.page_texture_size = [480, 480];
|
|
132
|
+
// virtualTexturePage.page_texture_size = [384, 1280];
|
|
133
|
+
// virtualTexturePage.page_texture_size = [1024, 1024];
|
|
134
|
+
// virtualTexturePage.page_texture_size = [2048, 2048];
|
|
135
|
+
// virtualTexturePage.page_texture_size = [4096, 4096];
|
|
136
|
+
virtualTexturePage.asset_manager = am;
|
|
115
137
|
|
|
138
|
+
memoryMapping.resolution = virtualTextureManager.texture_resolution / virtualTextureManager.tile_resolution;
|
|
116
139
|
|
|
117
|
-
|
|
140
|
+
|
|
141
|
+
console.log(virtualTexturePage);
|
|
118
142
|
|
|
119
143
|
|
|
120
144
|
//
|
|
121
|
-
|
|
122
|
-
usageDebugView.mip_levels = virtualTextureManager.max_mip_level;
|
|
145
|
+
// usageDebugView.mip_levels = virtualTextureManager.max_mip_level;
|
|
123
146
|
// container_view.addChild(usageDebugView);
|
|
124
147
|
|
|
125
148
|
|
|
126
|
-
const usagePyramidDebugView = new UsagePyramidDebugView();
|
|
127
|
-
usagePyramidDebugView.setImageURL(TEXTURE_URL);
|
|
128
|
-
container_view.addChild(usagePyramidDebugView);
|
|
149
|
+
// const usagePyramidDebugView = new UsagePyramidDebugView();
|
|
150
|
+
// usagePyramidDebugView.setImageURL(TEXTURE_URL);
|
|
151
|
+
// container_view.addChild(usagePyramidDebugView);
|
|
129
152
|
|
|
130
|
-
residencyDebugView.texture =
|
|
131
|
-
residencyDebugView.css({
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
});
|
|
135
|
-
container_view.addChild(residencyDebugView);
|
|
153
|
+
// residencyDebugView.texture = virtualTexturePage;
|
|
154
|
+
// residencyDebugView.css({
|
|
155
|
+
// bottom: 0,
|
|
156
|
+
// right: 0
|
|
157
|
+
// });
|
|
158
|
+
// container_view.addChild(residencyDebugView);
|
|
136
159
|
|
|
137
160
|
// ===================
|
|
138
161
|
|
|
@@ -144,14 +167,45 @@ async function init() {
|
|
|
144
167
|
container_view.link();
|
|
145
168
|
|
|
146
169
|
camera = new PerspectiveCamera(35, window.innerWidth / window.innerHeight, 0.1, 100);
|
|
147
|
-
camera.position.z =
|
|
170
|
+
camera.position.z = 30;
|
|
148
171
|
|
|
149
172
|
scene = new Scene();
|
|
173
|
+
// scene.background = new Color("#002D62");
|
|
150
174
|
|
|
151
175
|
clock = new Clock();
|
|
152
176
|
|
|
177
|
+
//
|
|
178
|
+
// const map = new TextureLoader().load(TEXTURE_URL);
|
|
179
|
+
// map.flipY = false;
|
|
180
|
+
//
|
|
181
|
+
// const material = new MeshBasicMaterial({
|
|
182
|
+
// map,
|
|
183
|
+
// side: DoubleSide
|
|
184
|
+
// });
|
|
185
|
+
|
|
186
|
+
const material = new VirtualTextureMaterial({
|
|
187
|
+
page: virtualTexturePage,
|
|
188
|
+
mapping: memoryMapping
|
|
189
|
+
})
|
|
190
|
+
|
|
191
|
+
console.log(material.uniforms);
|
|
192
|
+
|
|
153
193
|
// makeTorus();
|
|
154
|
-
makeMesh();
|
|
194
|
+
const virt = makeMesh(material);
|
|
195
|
+
// virt.position.x = -0.4
|
|
196
|
+
|
|
197
|
+
// const original_texture = new TextureLoader().load("data/textures/utility/maurus_uv_checker_8k/UV-CheckerMap_Maurus_01_8K.png");
|
|
198
|
+
// original_texture.flipY = false;
|
|
199
|
+
// original_texture.generateMipmaps = true;
|
|
200
|
+
// original_texture.anisotropy = 4;
|
|
201
|
+
|
|
202
|
+
// const ref = makeMesh(new MeshBasicMaterial({
|
|
203
|
+
// // map: original_texture,
|
|
204
|
+
// color: 0xFFFFFF,
|
|
205
|
+
// side: DoubleSide
|
|
206
|
+
// }));
|
|
207
|
+
//
|
|
208
|
+
// ref.position.x = 0.4;
|
|
155
209
|
|
|
156
210
|
// makeGLTF("data/models/LowPolyTownshipSet/Town_Hall/model.gltf");
|
|
157
211
|
|
|
@@ -162,10 +216,13 @@ async function init() {
|
|
|
162
216
|
//
|
|
163
217
|
|
|
164
218
|
renderer = new WebGLRenderer({ antialias: true });
|
|
219
|
+
renderer.setClearColor("#002D62",1);
|
|
220
|
+
|
|
165
221
|
renderer.setPixelRatio(window.devicePixelRatio);
|
|
166
222
|
container.appendChild(renderer.domElement);
|
|
167
223
|
renderer.autoClear = false;
|
|
168
224
|
|
|
225
|
+
window.renderer = renderer;
|
|
169
226
|
|
|
170
227
|
//
|
|
171
228
|
|
|
@@ -179,13 +236,38 @@ async function init() {
|
|
|
179
236
|
new OrbitControls(camera, renderer.domElement);
|
|
180
237
|
|
|
181
238
|
|
|
182
|
-
const gui = new GUI();
|
|
239
|
+
// const gui = new GUI();
|
|
240
|
+
//
|
|
241
|
+
// Object.keys(options).forEach(key => {
|
|
242
|
+
// gui.add(options, key);
|
|
243
|
+
// });
|
|
244
|
+
|
|
245
|
+
virtualTexturePage.renderer = renderer;
|
|
183
246
|
|
|
184
|
-
Object.keys(options).forEach(key => {
|
|
185
|
-
gui.add(options, key);
|
|
186
|
-
});
|
|
187
247
|
|
|
188
248
|
animate();
|
|
249
|
+
|
|
250
|
+
const mappingPreview = buildCanvasViewFromTexture({
|
|
251
|
+
texture: virtualTexturePage.texture,
|
|
252
|
+
renderer,
|
|
253
|
+
swizzle: ['r', 'g', 'b', 1],
|
|
254
|
+
width: 256,
|
|
255
|
+
height: 256,
|
|
256
|
+
flipY: false
|
|
257
|
+
});
|
|
258
|
+
|
|
259
|
+
mappingPreview.view.css(CSS_ABSOLUTE_POSITIONING);
|
|
260
|
+
mappingPreview.view.css({
|
|
261
|
+
// border: "1px solid red"
|
|
262
|
+
boxShadow: "0 0 8px rgba(0,0,0,0.4)"
|
|
263
|
+
});
|
|
264
|
+
mappingPreview.view.position.set(0, 0);
|
|
265
|
+
|
|
266
|
+
signal_render.add(() => {
|
|
267
|
+
mappingPreview.render();
|
|
268
|
+
});
|
|
269
|
+
|
|
270
|
+
container_view.addChild(mappingPreview.view);
|
|
189
271
|
}
|
|
190
272
|
|
|
191
273
|
function onWindowResize() {
|
|
@@ -210,11 +292,11 @@ function animate() {
|
|
|
210
292
|
function render() {
|
|
211
293
|
|
|
212
294
|
const delta = 5 * clock.getDelta();
|
|
213
|
-
|
|
214
|
-
if (options.spin && mesh !== undefined) {
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
}
|
|
295
|
+
//
|
|
296
|
+
// if (options.spin && mesh !== undefined) {
|
|
297
|
+
// mesh.rotation.y += 0.0125 * delta;
|
|
298
|
+
// mesh.rotation.x += 0.05 * delta;
|
|
299
|
+
// }
|
|
218
300
|
|
|
219
301
|
const view_port_size = renderer.getSize(new Vector2());
|
|
220
302
|
view_port_size.multiplyScalar(renderer.getPixelRatio());
|
|
@@ -222,8 +304,10 @@ function render() {
|
|
|
222
304
|
|
|
223
305
|
virtualTextureManager.setViewportResolution(view_port_size.x, view_port_size.y);
|
|
224
306
|
virtualTextureManager.updateUsage(renderer, scene, camera);
|
|
225
|
-
|
|
307
|
+
virtualTexturePage.update_usage(virtualTextureManager.usage_metadata);
|
|
308
|
+
memoryMapping.residency = virtualTexturePage;
|
|
226
309
|
|
|
310
|
+
// renderer.setViewport(0, 0, view_port_size.x, view_port_size.y);
|
|
227
311
|
renderer.clear();
|
|
228
312
|
renderer.render(scene, camera)
|
|
229
313
|
|
|
@@ -232,5 +316,7 @@ function render() {
|
|
|
232
316
|
// usagePyramidDebugView.setTextureParameters(virtualTextureManager.texture_resolution, virtualTextureManager.tile_resolution);
|
|
233
317
|
// usagePyramidDebugView.usage = virtualTextureManager.usage_metadata;
|
|
234
318
|
|
|
235
|
-
residencyDebugView.update();
|
|
319
|
+
// residencyDebugView.update();
|
|
320
|
+
|
|
321
|
+
signal_render.send0();
|
|
236
322
|
}
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import { surfaceAreaHeuristicFull } from "./surfaceAreaHeuristicFull.js";
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Surface Area Heuristic
|
|
5
|
-
* @param {number} saV Surface Area of the volume being split
|
|
6
|
-
* @param {number} saVL Surface Area of Left Volume
|
|
7
|
-
* @param {number} saVR Surface Area of Right Volume
|
|
8
|
-
* @param {number|int} nL Number of leaf nodes in Left Volume
|
|
9
|
-
* @param {number|int} nR Number of leaf nodes in Right Volume
|
|
10
|
-
* @returns {number}
|
|
11
|
-
*/
|
|
12
|
-
export function surfaceAreaHeuristic(saV, saVL, saVR, nL, nR) {
|
|
13
|
-
return surfaceAreaHeuristicFull(saV, saVL, saVR, nL, nR, 1, 1);
|
|
14
|
-
}
|
|
15
|
-
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Surface Area Heuristic
|
|
3
|
-
* @param {number} saV Surface Area of the volume being split
|
|
4
|
-
* @param {number} saVL Surface Area of Left Volume
|
|
5
|
-
* @param {number} saVR Surface Area of Right Volume
|
|
6
|
-
* @param {number|int} nL Number of leaf nodes in Left Volume
|
|
7
|
-
* @param {number|int} nR Number of leaf nodes in Right Volume
|
|
8
|
-
* @param {number} kT constant for the estimated cost of a traversal step
|
|
9
|
-
* @param {number} kI constant for the estimated cost of a intersection
|
|
10
|
-
* @returns {number}
|
|
11
|
-
*/
|
|
12
|
-
export function surfaceAreaHeuristicFull(saV, saVL, saVR, nL, nR, kT, kI) {
|
|
13
|
-
return kT + kI * (saVL * nL / saV + saVR * nR / saV);
|
|
14
|
-
}
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import { aabb3_from_v3_array } from "./aabb3_from_v3_array.js";
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* @deprecated use {@link aabb3_from_v3_array} instead
|
|
5
|
-
* @param {Float32Array} data must be x,y,z sequence
|
|
6
|
-
* @param {AABB3} aabb
|
|
7
|
-
*/
|
|
8
|
-
export function computeBoundingBoxFromVertexData(data, aabb) {
|
|
9
|
-
|
|
10
|
-
aabb3_from_v3_array(aabb, data, data.length);
|
|
11
|
-
|
|
12
|
-
}
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
import { v3_length } from "../../Vector3.js";
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Normalize a plane in-place
|
|
5
|
-
* @param {number[]} source
|
|
6
|
-
* @param {number} source_offset
|
|
7
|
-
*/
|
|
8
|
-
function array_normalize_plane(source, source_offset) {
|
|
9
|
-
const _x = source[source_offset];
|
|
10
|
-
const _y = source[source_offset + 1];
|
|
11
|
-
const _z = source[source_offset + 2];
|
|
12
|
-
|
|
13
|
-
const length = v3_length(_x, _y, _z);
|
|
14
|
-
|
|
15
|
-
const inverseNormalLength = 1.0 / length;
|
|
16
|
-
|
|
17
|
-
/*
|
|
18
|
-
By re-using values already in the registers instead of using *= we save a few extra READ ops
|
|
19
|
-
*/
|
|
20
|
-
source[source_offset] = _x * inverseNormalLength;
|
|
21
|
-
source[source_offset + 1] = _y * inverseNormalLength;
|
|
22
|
-
source[source_offset + 2] = _z * inverseNormalLength;
|
|
23
|
-
|
|
24
|
-
source[source_offset + 3] *= inverseNormalLength;
|
|
25
|
-
}
|
|
@@ -1,53 +0,0 @@
|
|
|
1
|
-
import { v3_dot } from "../../vec3/v3_dot.js";
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Calculate a plane that is a linear interpolation between two other planes A and B with interpolation factor between 0 and 1
|
|
5
|
-
* Result is places into destination array at the given array index offset
|
|
6
|
-
* NOTE: Based on https://stackoverflow.com/a/57824137/3973586
|
|
7
|
-
*
|
|
8
|
-
* @param {number[]|Float32Array|Float64Array} destination
|
|
9
|
-
* @param {number} destination_offset
|
|
10
|
-
* @param {number} fraction
|
|
11
|
-
* @param {number} a_normal_x
|
|
12
|
-
* @param {number} a_normal_y
|
|
13
|
-
* @param {number} a_normal_z
|
|
14
|
-
* @param {number} a_distance
|
|
15
|
-
* @param {number} b_normal_x
|
|
16
|
-
* @param {number} b_normal_y
|
|
17
|
-
* @param {number} b_normal_z
|
|
18
|
-
* @param {number} b_distance
|
|
19
|
-
*/
|
|
20
|
-
function lerp_planes_to_array(
|
|
21
|
-
destination,
|
|
22
|
-
destination_offset,
|
|
23
|
-
fraction,
|
|
24
|
-
a_normal_x, a_normal_y, a_normal_z, a_distance,
|
|
25
|
-
b_normal_x, b_normal_y, b_normal_z, b_distance
|
|
26
|
-
) {
|
|
27
|
-
|
|
28
|
-
// e = cross(a.normal, b.normal)
|
|
29
|
-
const e_x = a_normal_y * b_normal_z - a_normal_z * b_normal_y;
|
|
30
|
-
const e_y = a_normal_z * b_normal_x - a_normal_x * b_normal_z;
|
|
31
|
-
const e_z = a_normal_x * b_normal_y - a_normal_y * b_normal_x;
|
|
32
|
-
|
|
33
|
-
// n = slerp( a.normal, b.normal, fraction)
|
|
34
|
-
const dot = v3_dot(
|
|
35
|
-
a_normal_x, a_normal_y, a_normal_z,
|
|
36
|
-
b_normal_x, b_normal_y, b_normal_z
|
|
37
|
-
);
|
|
38
|
-
|
|
39
|
-
const theta = Math.acos(dot);
|
|
40
|
-
|
|
41
|
-
const sin_theta = Math.sin(theta);
|
|
42
|
-
|
|
43
|
-
const scale_0 = Math.sin((1 - fraction) * theta) / sin_theta;
|
|
44
|
-
const scale_1 = Math.sin((fraction) * theta) / sin_theta;
|
|
45
|
-
|
|
46
|
-
const n_x = a_normal_x * scale_0 + b_normal_x * scale_1;
|
|
47
|
-
const n_y = a_normal_y * scale_0 + b_normal_y * scale_1;
|
|
48
|
-
const n_z = a_normal_z * scale_0 + b_normal_z * scale_1;
|
|
49
|
-
|
|
50
|
-
//compute R
|
|
51
|
-
|
|
52
|
-
throw new Error("Not Implemented");
|
|
53
|
-
}
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import { plane3_compute_ray_intersection } from "./plane3_compute_ray_intersection.js";
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
*
|
|
5
|
-
* @param {Vector3} out Result will be written here
|
|
6
|
-
* @param {Vector3} origin Ray origin
|
|
7
|
-
* @param {Vector3} direction Ray direction
|
|
8
|
-
* @param {Vector3} normal Plane normal
|
|
9
|
-
* @param {number} dist Plane distance
|
|
10
|
-
* @returns {boolean} true if intersection is found, false otherwise
|
|
11
|
-
*/
|
|
12
|
-
export function planeRayIntersection(out, origin, direction, normal, dist) {
|
|
13
|
-
return plane3_compute_ray_intersection(out, origin.x, origin.y, origin.z, direction.x, direction.y, direction.z, normal.x, normal.y, normal.z, dist)
|
|
14
|
-
}
|
|
@@ -1,87 +0,0 @@
|
|
|
1
|
-
import Vector3 from "../../Vector3.js";
|
|
2
|
-
import { BitSet } from "../../../binary/BitSet.js";
|
|
3
|
-
|
|
4
|
-
export class DenseBitVolume3D {
|
|
5
|
-
constructor() {
|
|
6
|
-
this.size = new Vector3(1, 1, 1);
|
|
7
|
-
|
|
8
|
-
this.__data = new BitSet();
|
|
9
|
-
this.__data.preventShrink();
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
clear() {
|
|
13
|
-
this.__data.reset();
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
resize(x, y, z) {
|
|
17
|
-
// TODO consider how we can resize while keeping the data
|
|
18
|
-
this.clear();
|
|
19
|
-
|
|
20
|
-
this.size.set(x, y, z);
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
/**
|
|
24
|
-
*
|
|
25
|
-
* @param {number} x
|
|
26
|
-
* @param {number} y
|
|
27
|
-
* @param {number} z
|
|
28
|
-
* @return {number}
|
|
29
|
-
* @private
|
|
30
|
-
*/
|
|
31
|
-
__compute_address(x, y, z) {
|
|
32
|
-
|
|
33
|
-
const size = this.size;
|
|
34
|
-
|
|
35
|
-
const dx = size.x;
|
|
36
|
-
const dy = size.y;
|
|
37
|
-
|
|
38
|
-
return y * dx + z * dx * dy + x;
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
/**
|
|
42
|
-
*
|
|
43
|
-
* @param {number} x
|
|
44
|
-
* @param {number} y
|
|
45
|
-
* @param {number} z
|
|
46
|
-
* @return {boolean}
|
|
47
|
-
*/
|
|
48
|
-
get(x, y, z) {
|
|
49
|
-
const address = this.__compute_address(x, y, z);
|
|
50
|
-
|
|
51
|
-
return this.__data.get(address)
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
/**
|
|
55
|
-
*
|
|
56
|
-
* @param {boolean} value
|
|
57
|
-
* @param {number} x
|
|
58
|
-
* @param {number} y
|
|
59
|
-
* @param {number} z
|
|
60
|
-
*/
|
|
61
|
-
set(value, x, y, z) {
|
|
62
|
-
const address = this.__compute_address(x, y, z);
|
|
63
|
-
|
|
64
|
-
this.__data.set(address, value);
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
/**
|
|
68
|
-
*
|
|
69
|
-
* @param {number} u x-coordinate, normalized to [0,1] range
|
|
70
|
-
* @param {number} v y-coordinate, normalized to [0,1] range
|
|
71
|
-
* @param {number} w z-coordinate, normalized to [0,1] range
|
|
72
|
-
* @returns {boolean}
|
|
73
|
-
*/
|
|
74
|
-
sampleNearest(u, v, w) {
|
|
75
|
-
const s = this.size;
|
|
76
|
-
|
|
77
|
-
const dx = s.x;
|
|
78
|
-
const dy = s.y;
|
|
79
|
-
const dz = s.z;
|
|
80
|
-
|
|
81
|
-
const x = Math.round(dx * u) % dx
|
|
82
|
-
const y = Math.round(dy * v) % dy
|
|
83
|
-
const z = Math.round(dz * w) % dz
|
|
84
|
-
|
|
85
|
-
return this.get(x, y, z);
|
|
86
|
-
}
|
|
87
|
-
}
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Build a world-space oriented volume
|
|
3
|
-
* @param {DenseBitVolume3D} volume
|
|
4
|
-
* @param {AABB3} bounds
|
|
5
|
-
* @param {{raycast:function(source_x:number, source_y:number, source_z:number, direction_x:number, direction_y:number, direction_z:number):number}} sampler
|
|
6
|
-
* @param {number[]} frustum 3d frustum, defined as series of 6 planes in order: normal_x, normal_y, normal_z, plane_offset
|
|
7
|
-
*/
|
|
8
|
-
export function buildVolumeFromProjectedGeometry({ volume, sampler, frustum }) {
|
|
9
|
-
// get frustum corners
|
|
10
|
-
|
|
11
|
-
// get first hits from "front" plane to seed the volume
|
|
12
|
-
for (let x = 0; x < 64; x++) {
|
|
13
|
-
for (let y = 0; y < 64; y++) {
|
|
14
|
-
|
|
15
|
-
}
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
// fit volume to the frustum
|
|
19
|
-
|
|
20
|
-
// create a connectivity graph to identify disconnected regions
|
|
21
|
-
|
|
22
|
-
// clear out disconnected regions starting from smallest until only one is left
|
|
23
|
-
}
|
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
import { compose_tile_address } from "./tile/compose_tile_address.js";
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Represents entire mip pyramid of tiles, where each tile slot points to an actual resident tile
|
|
5
|
-
*/
|
|
6
|
-
export class ResidentTileTexture {
|
|
7
|
-
#resolution = 0;
|
|
8
|
-
#pyramid = new Uint32Array(0);
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
/**
|
|
12
|
-
*
|
|
13
|
-
* @param {number} resolution
|
|
14
|
-
*/
|
|
15
|
-
set resolution(resolution) {
|
|
16
|
-
this.#resolution = resolution;
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
//max mip
|
|
20
|
-
const mip_level = Math.log2(resolution);
|
|
21
|
-
|
|
22
|
-
compose_tile_address(mip_level, 0, 0);
|
|
23
|
-
|
|
24
|
-
this.#pyramid = new Uint32Array(mip_level);
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
get resolution() {
|
|
28
|
-
return this.#resolution;
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
/**
|
|
32
|
-
*
|
|
33
|
-
* @param {PageTexture} page
|
|
34
|
-
*/
|
|
35
|
-
set residency(page) {
|
|
36
|
-
|
|
37
|
-
const tiles = page.resident_tiles;
|
|
38
|
-
const tile_count = tiles.length;
|
|
39
|
-
|
|
40
|
-
for (let i = 0; i < tile_count; i++) {
|
|
41
|
-
const tile = tiles[i];
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
}
|
|
File without changes
|