@woosh/meep-engine 3.0.0 → 3.0.1
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/editor/particles/rebuildParticleEmitter.js +8 -26
- package/editor/process/symbolic/CameraSymbolicDisplay.js +146 -146
- package/editor/tools/SelectionTool.js +1 -2
- package/editor/tools/TransformToolV2.js +2 -3
- package/editor/tools/v2/BlenderCameraOrientationGizmo.js +501 -501
- package/editor/tools/v2/TransformControls.js +1 -1
- package/package.json +95 -96
- package/src/core/geom/3d/mat4/m4_look_at.d.ts +25 -0
- package/src/core/geom/3d/mat4/m4_look_at.d.ts.map +1 -0
- package/src/core/geom/3d/mat4/m4_look_at.js +96 -0
- package/src/core/geom/3d/mat4/m4_make_rotation_x.d.ts +18 -0
- package/src/core/geom/3d/mat4/m4_make_rotation_x.d.ts.map +1 -0
- package/src/core/geom/3d/mat4/m4_make_rotation_x.js +47 -0
- package/src/core/geom/3d/mat4/m4_make_rotation_y.d.ts +18 -0
- package/src/core/geom/3d/mat4/m4_make_rotation_y.d.ts.map +1 -0
- package/src/core/geom/3d/mat4/m4_make_rotation_y.js +47 -0
- package/src/core/geom/3d/mat4/m4_make_rotation_z.d.ts +18 -0
- package/src/core/geom/3d/mat4/m4_make_rotation_z.d.ts.map +1 -0
- package/src/core/geom/3d/mat4/m4_make_rotation_z.js +47 -0
- package/src/core/geom/3d/mat4/m4_perspective.d.ts +25 -0
- package/src/core/geom/3d/mat4/m4_perspective.d.ts.map +1 -0
- package/src/core/geom/3d/mat4/m4_perspective.js +66 -0
- package/src/engine/control/first-person/FirstPersonPlayerControllerSystem.d.ts.map +1 -1
- package/src/engine/control/first-person/FirstPersonPlayerControllerSystem.js +2045 -2052
- package/src/engine/ecs/gui/hud/testHudEdgeStick.js +2 -2
- package/src/engine/ecs/terrain/ecs/TerrainSystem.d.ts.map +1 -1
- package/src/engine/ecs/terrain/ecs/TerrainSystem.js +14 -27
- package/src/engine/ecs/terrain/util/loadVisibleTerrainTiles.d.ts.map +1 -1
- package/src/engine/ecs/terrain/util/loadVisibleTerrainTiles.js +129 -126
- package/src/engine/graphics/ecs/camera/Camera.d.ts +36 -48
- package/src/engine/graphics/ecs/camera/Camera.d.ts.map +1 -1
- package/src/engine/graphics/ecs/camera/Camera.js +165 -303
- package/src/engine/graphics/ecs/camera/camera_active_frustum.d.ts +14 -0
- package/src/engine/graphics/ecs/camera/camera_active_frustum.d.ts.map +1 -0
- package/src/engine/graphics/ecs/camera/camera_active_frustum.js +25 -0
- package/src/engine/graphics/ecs/camera/camera_find_active.d.ts +16 -0
- package/src/engine/graphics/ecs/camera/camera_find_active.d.ts.map +1 -0
- package/src/engine/graphics/ecs/camera/camera_find_active.js +28 -0
- package/src/engine/graphics/ecs/camera/camera_traverse_active.d.ts +12 -0
- package/src/engine/graphics/ecs/camera/camera_traverse_active.d.ts.map +1 -0
- package/src/engine/graphics/ecs/camera/camera_traverse_active.js +18 -0
- package/src/engine/graphics/ecs/camera/pp/PerfectPanner.js +170 -170
- package/src/engine/graphics/ecs/camera/topdown/TopDownCameraController.d.ts +5 -1
- package/src/engine/graphics/ecs/camera/topdown/TopDownCameraController.d.ts.map +1 -1
- package/src/engine/graphics/ecs/camera/topdown/TopDownCameraController.js +296 -281
- package/src/engine/graphics/ecs/render_layers_compute_depth_range.d.ts +1 -1
- package/src/engine/graphics/ecs/render_layers_compute_depth_range.js +1 -1
- package/src/engine/graphics/geometry/AttributeData.d.ts +52 -0
- package/src/engine/graphics/geometry/AttributeData.d.ts.map +1 -0
- package/src/engine/graphics/geometry/AttributeData.js +84 -0
- package/src/engine/graphics/particles/particular/engine/ParticularEngine.d.ts +1 -14
- package/src/engine/graphics/particles/particular/engine/ParticularEngine.d.ts.map +1 -1
- package/src/engine/graphics/particles/particular/engine/ParticularEngine.js +229 -253
- package/src/engine/graphics/particles/particular/engine/emitter/ParticleEmitter.d.ts +25 -12
- package/src/engine/graphics/particles/particular/engine/emitter/ParticleEmitter.d.ts.map +1 -1
- package/src/engine/graphics/particles/particular/engine/emitter/ParticleEmitter.js +1149 -1194
- package/src/engine/graphics/particles/particular/engine/emitter/ParticlePool.d.ts +4 -8
- package/src/engine/graphics/particles/particular/engine/emitter/ParticlePool.d.ts.map +1 -1
- package/src/engine/graphics/particles/particular/engine/emitter/ParticlePool.js +472 -540
- package/src/engine/graphics/particles/particular/engine/shader/ShaderManager.d.ts +19 -90
- package/src/engine/graphics/particles/particular/engine/shader/ShaderManager.d.ts.map +1 -1
- package/src/engine/graphics/particles/particular/engine/shader/ShaderManager.js +135 -514
- package/src/engine/graphics3/CameraSystem3.d.ts.map +1 -1
- package/src/engine/graphics3/CameraSystem3.js +10 -1
- package/src/engine/graphics3/GraphicsEngine3.d.ts +3 -3
- package/src/engine/graphics3/GraphicsEngine3.js +3 -3
- package/src/engine/graphics3/ParticleEmitterSystem3.d.ts +11 -0
- package/src/engine/graphics3/ParticleEmitterSystem3.d.ts.map +1 -1
- package/src/engine/graphics3/ParticleEmitterSystem3.js +289 -265
- package/src/engine/graphics3/ShadeCameraAdapter.d.ts +3 -3
- package/src/engine/graphics3/ShadeCameraAdapter.js +3 -3
- package/src/engine/graphics3/camera_sync_from_transform.d.ts +2 -2
- package/src/engine/graphics3/camera_sync_from_transform.js +2 -2
- package/src/engine/graphics3/shade_camera_projection_ray.js +2 -2
- package/src/engine/physics/fluid/ecs/FluidObstacleSystem.d.ts +4 -4
- package/src/shade/renderer/camera/Camera.d.ts +3 -5
- package/src/shade/renderer/camera/Camera.d.ts.map +1 -1
- package/src/shade/renderer/camera/Camera.js +281 -280
- package/src/shade/renderer/camera/GPUCameraContext.js +233 -233
- package/src/shade/renderer/loader/usd/parse_usda.js +1 -1
- package/src/shade/renderer/loader/usd/usd_build_scene.d.ts.map +1 -1
- package/src/shade/renderer/loader/usd/usd_build_scene.js +658 -652
- package/src/shade/renderer/loader/usd/usd_compose_transform.d.ts.map +1 -1
- package/src/shade/renderer/loader/usd/usd_compose_transform.js +58 -23
- package/src/shade/renderer/particles/prototypeParticleSystem.js +450 -443
- package/src/shade/renderer/shadow/map/DirectionalLightShadowmap.d.ts.map +1 -1
- package/src/shade/renderer/shadow/map/DirectionalLightShadowmap.js +7 -3
- package/src/view/minimap/dom/MinimapCameraView.d.ts +2 -2
- package/src/view/minimap/dom/MinimapCameraView.js +206 -206
- package/src/engine/graphics/ecs/camera/CameraSystem.d.ts +0 -74
- package/src/engine/graphics/ecs/camera/CameraSystem.d.ts.map +0 -1
- package/src/engine/graphics/ecs/camera/CameraSystem.js +0 -331
- package/src/engine/graphics/ecs/camera/auto_set_camera_clipping_planes.d.ts +0 -10
- package/src/engine/graphics/ecs/camera/auto_set_camera_clipping_planes.d.ts.map +0 -1
- package/src/engine/graphics/ecs/camera/auto_set_camera_clipping_planes.js +0 -105
- package/src/engine/graphics/ecs/camera/build_three_camera_object.d.ts +0 -7
- package/src/engine/graphics/ecs/camera/build_three_camera_object.d.ts.map +0 -1
- package/src/engine/graphics/ecs/camera/build_three_camera_object.js +0 -29
- package/src/engine/graphics/ecs/camera/frustum_from_camera.d.ts +0 -8
- package/src/engine/graphics/ecs/camera/frustum_from_camera.d.ts.map +0 -1
- package/src/engine/graphics/ecs/camera/frustum_from_camera.js +0 -20
- package/src/engine/graphics/ecs/camera/set_camera_aspect_ratio.d.ts +0 -9
- package/src/engine/graphics/ecs/camera/set_camera_aspect_ratio.d.ts.map +0 -1
- package/src/engine/graphics/ecs/camera/set_camera_aspect_ratio.js +0 -46
- package/src/engine/graphics/ecs/camera/unprojectPoint.d.ts +0 -9
- package/src/engine/graphics/ecs/camera/unprojectPoint.d.ts.map +0 -1
- package/src/engine/graphics/ecs/camera/unprojectPoint.js +0 -14
- package/src/engine/graphics/ecs/camera/update_camera_transform.d.ts +0 -6
- package/src/engine/graphics/ecs/camera/update_camera_transform.d.ts.map +0 -1
- package/src/engine/graphics/ecs/camera/update_camera_transform.js +0 -17
- package/src/engine/graphics/particles/ecs/ParticleEmitterSystem.d.ts +0 -67
- package/src/engine/graphics/particles/ecs/ParticleEmitterSystem.d.ts.map +0 -1
- package/src/engine/graphics/particles/ecs/ParticleEmitterSystem.js +0 -291
- package/src/engine/graphics/particles/particular/engine/renderers/billboard/ParticleBillboardMaterial.d.ts +0 -11
- package/src/engine/graphics/particles/particular/engine/renderers/billboard/ParticleBillboardMaterial.d.ts.map +0 -1
- package/src/engine/graphics/particles/particular/engine/renderers/billboard/ParticleBillboardMaterial.js +0 -497
- package/src/engine/graphics/particles/particular/engine/shader/MaterialRecord.d.ts +0 -40
- package/src/engine/graphics/particles/particular/engine/shader/MaterialRecord.d.ts.map +0 -1
- package/src/engine/graphics/particles/particular/engine/shader/MaterialRecord.js +0 -47
- package/src/engine/graphics/texture/sampler/writeSampler2DDataToDataTexture.d.ts +0 -7
- package/src/engine/graphics/texture/sampler/writeSampler2DDataToDataTexture.d.ts.map +0 -1
- package/src/engine/graphics/texture/sampler/writeSampler2DDataToDataTexture.js +0 -40
|
@@ -1,234 +1,234 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import { slice_flat_array } from "../util/slice_flat_array.js";
|
|
5
|
-
import { queue_typed_buffer_update } from "../shader/type/queue_typed_buffer_update.js";
|
|
6
|
-
import { GPUTypedBuffer } from "../buffer/GPUTypedBuffer.js";
|
|
7
|
-
import { CAMERA_UNIFORM_STRUCT } from "./CAMERA_UNIFORM_STRUCT.js";
|
|
8
|
-
import { compute_device_depth_to_view_space_depth_params } from "./compute_device_depth_to_view_space_depth_params.js";
|
|
9
|
-
|
|
10
|
-
let id_counter = 0;
|
|
11
|
-
|
|
12
|
-
export class GPUCameraContext {
|
|
13
|
-
|
|
14
|
-
#id = id_counter++;
|
|
15
|
-
|
|
16
|
-
get id() {
|
|
17
|
-
return this.#id;
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
/**
|
|
21
|
-
* @returns {GPUBuffer}
|
|
22
|
-
*/
|
|
23
|
-
get gpu_buffer() {
|
|
24
|
-
return this.buffer.buffer;
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
/**
|
|
28
|
-
* @type {GPUTypedBuffer}
|
|
29
|
-
*/
|
|
30
|
-
buffer;
|
|
31
|
-
|
|
32
|
-
/**
|
|
33
|
-
* @type {GPUDevice}
|
|
34
|
-
*/
|
|
35
|
-
#device
|
|
36
|
-
|
|
37
|
-
/**
|
|
38
|
-
* @type {Camera}
|
|
39
|
-
*/
|
|
40
|
-
#camera
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
/**
|
|
44
|
-
* Final view projection matrix will be offset by this amount in NDC units
|
|
45
|
-
* @type {Float32Array}
|
|
46
|
-
*/
|
|
47
|
-
#view_offset = new Float32Array([0, 0]);
|
|
48
|
-
|
|
49
|
-
/**
|
|
50
|
-
*
|
|
51
|
-
* @type {Float32Array}
|
|
52
|
-
*/
|
|
53
|
-
#view_projection_matrix = new Float32Array(16);
|
|
54
|
-
|
|
55
|
-
get view_projection_matrix() {
|
|
56
|
-
return this.#view_projection_matrix;
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
/**
|
|
60
|
-
*
|
|
61
|
-
* @param {number} x
|
|
62
|
-
* @param {number} y
|
|
63
|
-
*/
|
|
64
|
-
setViewportOffset(x, y) {
|
|
65
|
-
this.#view_offset[0] = x;
|
|
66
|
-
this.#view_offset[1] = y;
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
/**
|
|
70
|
-
*
|
|
71
|
-
* @param {Camera} v
|
|
72
|
-
*/
|
|
73
|
-
set camera(v) {
|
|
74
|
-
this.#camera = v;
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
/**
|
|
78
|
-
*
|
|
79
|
-
* @return {Camera}
|
|
80
|
-
*/
|
|
81
|
-
get camera() {
|
|
82
|
-
return this.#camera;
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
/**
|
|
86
|
-
*
|
|
87
|
-
* @param {GPUDevice} device
|
|
88
|
-
* @param {Camera} camera
|
|
89
|
-
*/
|
|
90
|
-
constructor(device, camera) {
|
|
91
|
-
this.#device = device;
|
|
92
|
-
this.#camera = camera;
|
|
93
|
-
this.initialize();
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
clone() {
|
|
97
|
-
const r = new GPUCameraContext(this.#device, this.#camera.clone());
|
|
98
|
-
|
|
99
|
-
r.copy(this);
|
|
100
|
-
|
|
101
|
-
return r;
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
/**
|
|
105
|
-
*
|
|
106
|
-
* @param {GPUCameraContext} other
|
|
107
|
-
* @param {ShadeGPUCommandContext} [command_ctx]
|
|
108
|
-
*/
|
|
109
|
-
copy(other, command_ctx) {
|
|
110
|
-
this.#camera.copy(other.camera);
|
|
111
|
-
|
|
112
|
-
const device = this.#device;
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
const source = other.buffer.buffer;
|
|
116
|
-
const destination = this.buffer.buffer;
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
if (command_ctx === undefined) {
|
|
120
|
-
const encoder = device.createCommandEncoder();
|
|
121
|
-
|
|
122
|
-
encoder.copyBufferToBuffer(
|
|
123
|
-
source, 0,
|
|
124
|
-
destination, 0,
|
|
125
|
-
destination.size
|
|
126
|
-
);
|
|
127
|
-
|
|
128
|
-
device.queue.submit([encoder.finish()]);
|
|
129
|
-
|
|
130
|
-
} else {
|
|
131
|
-
|
|
132
|
-
command_ctx.copyBufferToBuffer(
|
|
133
|
-
source, 0,
|
|
134
|
-
destination, 0,
|
|
135
|
-
destination.size
|
|
136
|
-
);
|
|
137
|
-
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
}
|
|
141
|
-
|
|
142
|
-
initialize() {
|
|
143
|
-
|
|
144
|
-
this.buffer = GPUTypedBuffer.create({
|
|
145
|
-
device: this.#device,
|
|
146
|
-
label: `camera ${this.#id}`,
|
|
147
|
-
type: CAMERA_UNIFORM_STRUCT,
|
|
148
|
-
usage: GPUBufferUsage.STORAGE | GPUBufferUsage.UNIFORM | GPUBufferUsage.COPY_DST | GPUBufferUsage.COPY_SRC
|
|
149
|
-
});
|
|
150
|
-
}
|
|
151
|
-
|
|
152
|
-
destroy() {
|
|
153
|
-
this.buffer.destroy();
|
|
154
|
-
}
|
|
155
|
-
|
|
156
|
-
update() {
|
|
157
|
-
this.#write_update();
|
|
158
|
-
}
|
|
159
|
-
|
|
160
|
-
/**
|
|
161
|
-
*
|
|
162
|
-
*/
|
|
163
|
-
#write_update() {
|
|
164
|
-
|
|
165
|
-
const camera = this.#camera;
|
|
166
|
-
camera.update();
|
|
167
|
-
|
|
168
|
-
const projection_matrix = new Float64Array(16);
|
|
169
|
-
projection_matrix.set(camera.projection_matrix);
|
|
170
|
-
|
|
171
|
-
// Signs are chosen so a positive offset shifts rendered content in the +UV direction
|
|
172
|
-
// (right/down), which is what the temporal consumers (TAA/NSS un-jitter,
|
|
173
|
-
// chunk_unjitter_uv) assume. The perspective divide negates whatever is added here:
|
|
174
|
-
// m[11] == -1 makes clip.w = -z_view, so adding c at m[8]/m[9] shifts NDC by -c —
|
|
175
|
-
// hence "-=" for x (NDC x aligns with UV x) and "+=" for y (NDC y is UV-flipped,
|
|
176
|
-
// the two negations cancel).
|
|
177
|
-
projection_matrix[8] -= this.#view_offset[0];
|
|
178
|
-
projection_matrix[9] += this.#view_offset[1];
|
|
179
|
-
|
|
180
|
-
// build view-projection matrix
|
|
181
|
-
const view_projection_matrix = this.#view_projection_matrix;
|
|
182
|
-
m4_multiply(view_projection_matrix, projection_matrix, camera.view_matrix);
|
|
183
|
-
|
|
184
|
-
const device = this.#device;
|
|
185
|
-
const queue = device.queue;
|
|
186
|
-
|
|
187
|
-
const transform_matrix = camera.transform.matrix;
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
const transform_inverse =
|
|
191
|
-
m4_invert(transform_inverse, transform_matrix);
|
|
192
|
-
|
|
193
|
-
const projection_matrix_inverse =
|
|
194
|
-
m4_invert(projection_matrix_inverse, projection_matrix);
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
const view_projection_matrix_inverse =
|
|
198
|
-
m4_invert(view_projection_matrix_inverse, view_projection_matrix);
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
const device_depth_to_view_space = new Float32Array(4);
|
|
202
|
-
compute_device_depth_to_view_space_depth_params(
|
|
203
|
-
device_depth_to_view_space,
|
|
204
|
-
camera,
|
|
205
|
-
);
|
|
206
|
-
|
|
207
|
-
const view_matrix_inverse =
|
|
208
|
-
m4_invert(view_matrix_inverse, camera.view_matrix);
|
|
209
|
-
|
|
210
|
-
queue_typed_buffer_update(
|
|
211
|
-
queue,
|
|
212
|
-
this.buffer,
|
|
213
|
-
{
|
|
214
|
-
view_matrix: camera.view_matrix,
|
|
215
|
-
view_matrix_inverse: view_matrix_inverse,
|
|
216
|
-
transform: transform_matrix,
|
|
217
|
-
transform_inverse,
|
|
218
|
-
projection_matrix,
|
|
219
|
-
projection_matrix_inverse,
|
|
220
|
-
view_projection_matrix,
|
|
221
|
-
view_projection_matrix_inverse,
|
|
222
|
-
frustum: slice_flat_array(
|
|
223
|
-
camera.frustum,
|
|
224
|
-
0,
|
|
225
|
-
4,
|
|
226
|
-
6
|
|
227
|
-
),
|
|
228
|
-
device_depth_to_view_space,
|
|
229
|
-
clip_near_far: [camera.near, camera.far]
|
|
230
|
-
}
|
|
231
|
-
);
|
|
232
|
-
|
|
233
|
-
}
|
|
1
|
+
import { m4_allocate } from "../../../core/geom/3d/mat4/m4_allocate.js";
|
|
2
|
+
import { m4_invert } from "../../../core/geom/3d/mat4/m4_invert.js";
|
|
3
|
+
import { m4_multiply } from "../../../core/geom/3d/mat4/m4_multiply.js";
|
|
4
|
+
import { slice_flat_array } from "../util/slice_flat_array.js";
|
|
5
|
+
import { queue_typed_buffer_update } from "../shader/type/queue_typed_buffer_update.js";
|
|
6
|
+
import { GPUTypedBuffer } from "../buffer/GPUTypedBuffer.js";
|
|
7
|
+
import { CAMERA_UNIFORM_STRUCT } from "./CAMERA_UNIFORM_STRUCT.js";
|
|
8
|
+
import { compute_device_depth_to_view_space_depth_params } from "./compute_device_depth_to_view_space_depth_params.js";
|
|
9
|
+
|
|
10
|
+
let id_counter = 0;
|
|
11
|
+
|
|
12
|
+
export class GPUCameraContext {
|
|
13
|
+
|
|
14
|
+
#id = id_counter++;
|
|
15
|
+
|
|
16
|
+
get id() {
|
|
17
|
+
return this.#id;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* @returns {GPUBuffer}
|
|
22
|
+
*/
|
|
23
|
+
get gpu_buffer() {
|
|
24
|
+
return this.buffer.buffer;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* @type {GPUTypedBuffer}
|
|
29
|
+
*/
|
|
30
|
+
buffer;
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* @type {GPUDevice}
|
|
34
|
+
*/
|
|
35
|
+
#device
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* @type {Camera}
|
|
39
|
+
*/
|
|
40
|
+
#camera
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* Final view projection matrix will be offset by this amount in NDC units
|
|
45
|
+
* @type {Float32Array}
|
|
46
|
+
*/
|
|
47
|
+
#view_offset = new Float32Array([0, 0]);
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
*
|
|
51
|
+
* @type {Float32Array}
|
|
52
|
+
*/
|
|
53
|
+
#view_projection_matrix = new Float32Array(16);
|
|
54
|
+
|
|
55
|
+
get view_projection_matrix() {
|
|
56
|
+
return this.#view_projection_matrix;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
*
|
|
61
|
+
* @param {number} x
|
|
62
|
+
* @param {number} y
|
|
63
|
+
*/
|
|
64
|
+
setViewportOffset(x, y) {
|
|
65
|
+
this.#view_offset[0] = x;
|
|
66
|
+
this.#view_offset[1] = y;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
*
|
|
71
|
+
* @param {Camera} v
|
|
72
|
+
*/
|
|
73
|
+
set camera(v) {
|
|
74
|
+
this.#camera = v;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
/**
|
|
78
|
+
*
|
|
79
|
+
* @return {Camera}
|
|
80
|
+
*/
|
|
81
|
+
get camera() {
|
|
82
|
+
return this.#camera;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
/**
|
|
86
|
+
*
|
|
87
|
+
* @param {GPUDevice} device
|
|
88
|
+
* @param {Camera} camera
|
|
89
|
+
*/
|
|
90
|
+
constructor(device, camera) {
|
|
91
|
+
this.#device = device;
|
|
92
|
+
this.#camera = camera;
|
|
93
|
+
this.initialize();
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
clone() {
|
|
97
|
+
const r = new GPUCameraContext(this.#device, this.#camera.clone());
|
|
98
|
+
|
|
99
|
+
r.copy(this);
|
|
100
|
+
|
|
101
|
+
return r;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
/**
|
|
105
|
+
*
|
|
106
|
+
* @param {GPUCameraContext} other
|
|
107
|
+
* @param {ShadeGPUCommandContext} [command_ctx]
|
|
108
|
+
*/
|
|
109
|
+
copy(other, command_ctx) {
|
|
110
|
+
this.#camera.copy(other.camera);
|
|
111
|
+
|
|
112
|
+
const device = this.#device;
|
|
113
|
+
|
|
114
|
+
|
|
115
|
+
const source = other.buffer.buffer;
|
|
116
|
+
const destination = this.buffer.buffer;
|
|
117
|
+
|
|
118
|
+
|
|
119
|
+
if (command_ctx === undefined) {
|
|
120
|
+
const encoder = device.createCommandEncoder();
|
|
121
|
+
|
|
122
|
+
encoder.copyBufferToBuffer(
|
|
123
|
+
source, 0,
|
|
124
|
+
destination, 0,
|
|
125
|
+
destination.size
|
|
126
|
+
);
|
|
127
|
+
|
|
128
|
+
device.queue.submit([encoder.finish()]);
|
|
129
|
+
|
|
130
|
+
} else {
|
|
131
|
+
|
|
132
|
+
command_ctx.copyBufferToBuffer(
|
|
133
|
+
source, 0,
|
|
134
|
+
destination, 0,
|
|
135
|
+
destination.size
|
|
136
|
+
);
|
|
137
|
+
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
initialize() {
|
|
143
|
+
|
|
144
|
+
this.buffer = GPUTypedBuffer.create({
|
|
145
|
+
device: this.#device,
|
|
146
|
+
label: `camera ${this.#id}`,
|
|
147
|
+
type: CAMERA_UNIFORM_STRUCT,
|
|
148
|
+
usage: GPUBufferUsage.STORAGE | GPUBufferUsage.UNIFORM | GPUBufferUsage.COPY_DST | GPUBufferUsage.COPY_SRC
|
|
149
|
+
});
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
destroy() {
|
|
153
|
+
this.buffer.destroy();
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
update() {
|
|
157
|
+
this.#write_update();
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
/**
|
|
161
|
+
*
|
|
162
|
+
*/
|
|
163
|
+
#write_update() {
|
|
164
|
+
|
|
165
|
+
const camera = this.#camera;
|
|
166
|
+
camera.update();
|
|
167
|
+
|
|
168
|
+
const projection_matrix = new Float64Array(16);
|
|
169
|
+
projection_matrix.set(camera.projection_matrix);
|
|
170
|
+
|
|
171
|
+
// Signs are chosen so a positive offset shifts rendered content in the +UV direction
|
|
172
|
+
// (right/down), which is what the temporal consumers (TAA/NSS un-jitter,
|
|
173
|
+
// chunk_unjitter_uv) assume. The perspective divide negates whatever is added here:
|
|
174
|
+
// m[11] == -1 makes clip.w = -z_view, so adding c at m[8]/m[9] shifts NDC by -c —
|
|
175
|
+
// hence "-=" for x (NDC x aligns with UV x) and "+=" for y (NDC y is UV-flipped,
|
|
176
|
+
// the two negations cancel).
|
|
177
|
+
projection_matrix[8] -= this.#view_offset[0];
|
|
178
|
+
projection_matrix[9] += this.#view_offset[1];
|
|
179
|
+
|
|
180
|
+
// build view-projection matrix
|
|
181
|
+
const view_projection_matrix = this.#view_projection_matrix;
|
|
182
|
+
m4_multiply(view_projection_matrix, projection_matrix, camera.view_matrix);
|
|
183
|
+
|
|
184
|
+
const device = this.#device;
|
|
185
|
+
const queue = device.queue;
|
|
186
|
+
|
|
187
|
+
const transform_matrix = camera.transform.matrix;
|
|
188
|
+
|
|
189
|
+
|
|
190
|
+
const transform_inverse = m4_allocate();
|
|
191
|
+
m4_invert(transform_inverse, transform_matrix);
|
|
192
|
+
|
|
193
|
+
const projection_matrix_inverse = m4_allocate();
|
|
194
|
+
m4_invert(projection_matrix_inverse, projection_matrix);
|
|
195
|
+
|
|
196
|
+
|
|
197
|
+
const view_projection_matrix_inverse = m4_allocate();
|
|
198
|
+
m4_invert(view_projection_matrix_inverse, view_projection_matrix);
|
|
199
|
+
|
|
200
|
+
|
|
201
|
+
const device_depth_to_view_space = new Float32Array(4);
|
|
202
|
+
compute_device_depth_to_view_space_depth_params(
|
|
203
|
+
device_depth_to_view_space,
|
|
204
|
+
camera,
|
|
205
|
+
);
|
|
206
|
+
|
|
207
|
+
const view_matrix_inverse = m4_allocate();
|
|
208
|
+
m4_invert(view_matrix_inverse, camera.view_matrix);
|
|
209
|
+
|
|
210
|
+
queue_typed_buffer_update(
|
|
211
|
+
queue,
|
|
212
|
+
this.buffer,
|
|
213
|
+
{
|
|
214
|
+
view_matrix: camera.view_matrix,
|
|
215
|
+
view_matrix_inverse: view_matrix_inverse,
|
|
216
|
+
transform: transform_matrix,
|
|
217
|
+
transform_inverse,
|
|
218
|
+
projection_matrix,
|
|
219
|
+
projection_matrix_inverse,
|
|
220
|
+
view_projection_matrix,
|
|
221
|
+
view_projection_matrix_inverse,
|
|
222
|
+
frustum: slice_flat_array(
|
|
223
|
+
camera.frustum,
|
|
224
|
+
0,
|
|
225
|
+
4,
|
|
226
|
+
6
|
|
227
|
+
),
|
|
228
|
+
device_depth_to_view_space,
|
|
229
|
+
clip_near_far: [camera.near, camera.far]
|
|
230
|
+
}
|
|
231
|
+
);
|
|
232
|
+
|
|
233
|
+
}
|
|
234
234
|
}
|
|
@@ -712,7 +712,7 @@ function parse_attribute_value(value_type, raw) {
|
|
|
712
712
|
}
|
|
713
713
|
|
|
714
714
|
// Quaternion types — stored in USD's native (w, x, y, z) order.
|
|
715
|
-
// Conversion to
|
|
715
|
+
// Conversion to the engine's (x, y, z, w) is done in usd_compose_transform
|
|
716
716
|
// when the quaternion is consumed for matrix composition.
|
|
717
717
|
// @see https://openusd.org/release/api/class_gf_quatf.html — GfQuatf real-part-first layout
|
|
718
718
|
if (value_type.startsWith("quat")) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"usd_build_scene.d.ts","sourceRoot":"","sources":["../../../../../../src/shade/renderer/loader/usd/usd_build_scene.js"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"usd_build_scene.d.ts","sourceRoot":"","sources":["../../../../../../src/shade/renderer/loader/usd/usd_build_scene.js"],"names":[],"mappings":"AAkCA;;;;GAIG;AAGH;;;;;;;;;;GAUG;AACH;QAJmB,MAAM,GAAE;QAAE,QAAQ,EAAE,MAAM,CAAC;QAAC,MAAM,MAAQ;KAAE;aACpD,eAAe,GACb,MAAM,EAAE,CAqEpB;;;;;iBAnFa,IAAI,MAAM,EAAE,UAAU,CAAC;;;;iBACvB,OAAO,2BAA2B,EAAE,oBAAoB;;uBAR/C,uBAAuB"}
|