@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.
Files changed (122) hide show
  1. package/editor/particles/rebuildParticleEmitter.js +8 -26
  2. package/editor/process/symbolic/CameraSymbolicDisplay.js +146 -146
  3. package/editor/tools/SelectionTool.js +1 -2
  4. package/editor/tools/TransformToolV2.js +2 -3
  5. package/editor/tools/v2/BlenderCameraOrientationGizmo.js +501 -501
  6. package/editor/tools/v2/TransformControls.js +1 -1
  7. package/package.json +95 -96
  8. package/src/core/geom/3d/mat4/m4_look_at.d.ts +25 -0
  9. package/src/core/geom/3d/mat4/m4_look_at.d.ts.map +1 -0
  10. package/src/core/geom/3d/mat4/m4_look_at.js +96 -0
  11. package/src/core/geom/3d/mat4/m4_make_rotation_x.d.ts +18 -0
  12. package/src/core/geom/3d/mat4/m4_make_rotation_x.d.ts.map +1 -0
  13. package/src/core/geom/3d/mat4/m4_make_rotation_x.js +47 -0
  14. package/src/core/geom/3d/mat4/m4_make_rotation_y.d.ts +18 -0
  15. package/src/core/geom/3d/mat4/m4_make_rotation_y.d.ts.map +1 -0
  16. package/src/core/geom/3d/mat4/m4_make_rotation_y.js +47 -0
  17. package/src/core/geom/3d/mat4/m4_make_rotation_z.d.ts +18 -0
  18. package/src/core/geom/3d/mat4/m4_make_rotation_z.d.ts.map +1 -0
  19. package/src/core/geom/3d/mat4/m4_make_rotation_z.js +47 -0
  20. package/src/core/geom/3d/mat4/m4_perspective.d.ts +25 -0
  21. package/src/core/geom/3d/mat4/m4_perspective.d.ts.map +1 -0
  22. package/src/core/geom/3d/mat4/m4_perspective.js +66 -0
  23. package/src/engine/control/first-person/FirstPersonPlayerControllerSystem.d.ts.map +1 -1
  24. package/src/engine/control/first-person/FirstPersonPlayerControllerSystem.js +2045 -2052
  25. package/src/engine/ecs/gui/hud/testHudEdgeStick.js +2 -2
  26. package/src/engine/ecs/terrain/ecs/TerrainSystem.d.ts.map +1 -1
  27. package/src/engine/ecs/terrain/ecs/TerrainSystem.js +14 -27
  28. package/src/engine/ecs/terrain/util/loadVisibleTerrainTiles.d.ts.map +1 -1
  29. package/src/engine/ecs/terrain/util/loadVisibleTerrainTiles.js +129 -126
  30. package/src/engine/graphics/ecs/camera/Camera.d.ts +36 -48
  31. package/src/engine/graphics/ecs/camera/Camera.d.ts.map +1 -1
  32. package/src/engine/graphics/ecs/camera/Camera.js +165 -303
  33. package/src/engine/graphics/ecs/camera/camera_active_frustum.d.ts +14 -0
  34. package/src/engine/graphics/ecs/camera/camera_active_frustum.d.ts.map +1 -0
  35. package/src/engine/graphics/ecs/camera/camera_active_frustum.js +25 -0
  36. package/src/engine/graphics/ecs/camera/camera_find_active.d.ts +16 -0
  37. package/src/engine/graphics/ecs/camera/camera_find_active.d.ts.map +1 -0
  38. package/src/engine/graphics/ecs/camera/camera_find_active.js +28 -0
  39. package/src/engine/graphics/ecs/camera/camera_traverse_active.d.ts +12 -0
  40. package/src/engine/graphics/ecs/camera/camera_traverse_active.d.ts.map +1 -0
  41. package/src/engine/graphics/ecs/camera/camera_traverse_active.js +18 -0
  42. package/src/engine/graphics/ecs/camera/pp/PerfectPanner.js +170 -170
  43. package/src/engine/graphics/ecs/camera/topdown/TopDownCameraController.d.ts +5 -1
  44. package/src/engine/graphics/ecs/camera/topdown/TopDownCameraController.d.ts.map +1 -1
  45. package/src/engine/graphics/ecs/camera/topdown/TopDownCameraController.js +296 -281
  46. package/src/engine/graphics/ecs/render_layers_compute_depth_range.d.ts +1 -1
  47. package/src/engine/graphics/ecs/render_layers_compute_depth_range.js +1 -1
  48. package/src/engine/graphics/geometry/AttributeData.d.ts +52 -0
  49. package/src/engine/graphics/geometry/AttributeData.d.ts.map +1 -0
  50. package/src/engine/graphics/geometry/AttributeData.js +84 -0
  51. package/src/engine/graphics/particles/particular/engine/ParticularEngine.d.ts +1 -14
  52. package/src/engine/graphics/particles/particular/engine/ParticularEngine.d.ts.map +1 -1
  53. package/src/engine/graphics/particles/particular/engine/ParticularEngine.js +229 -253
  54. package/src/engine/graphics/particles/particular/engine/emitter/ParticleEmitter.d.ts +25 -12
  55. package/src/engine/graphics/particles/particular/engine/emitter/ParticleEmitter.d.ts.map +1 -1
  56. package/src/engine/graphics/particles/particular/engine/emitter/ParticleEmitter.js +1149 -1194
  57. package/src/engine/graphics/particles/particular/engine/emitter/ParticlePool.d.ts +4 -8
  58. package/src/engine/graphics/particles/particular/engine/emitter/ParticlePool.d.ts.map +1 -1
  59. package/src/engine/graphics/particles/particular/engine/emitter/ParticlePool.js +472 -540
  60. package/src/engine/graphics/particles/particular/engine/shader/ShaderManager.d.ts +19 -90
  61. package/src/engine/graphics/particles/particular/engine/shader/ShaderManager.d.ts.map +1 -1
  62. package/src/engine/graphics/particles/particular/engine/shader/ShaderManager.js +135 -514
  63. package/src/engine/graphics3/CameraSystem3.d.ts.map +1 -1
  64. package/src/engine/graphics3/CameraSystem3.js +10 -1
  65. package/src/engine/graphics3/GraphicsEngine3.d.ts +3 -3
  66. package/src/engine/graphics3/GraphicsEngine3.js +3 -3
  67. package/src/engine/graphics3/ParticleEmitterSystem3.d.ts +11 -0
  68. package/src/engine/graphics3/ParticleEmitterSystem3.d.ts.map +1 -1
  69. package/src/engine/graphics3/ParticleEmitterSystem3.js +289 -265
  70. package/src/engine/graphics3/ShadeCameraAdapter.d.ts +3 -3
  71. package/src/engine/graphics3/ShadeCameraAdapter.js +3 -3
  72. package/src/engine/graphics3/camera_sync_from_transform.d.ts +2 -2
  73. package/src/engine/graphics3/camera_sync_from_transform.js +2 -2
  74. package/src/engine/graphics3/shade_camera_projection_ray.js +2 -2
  75. package/src/engine/physics/fluid/ecs/FluidObstacleSystem.d.ts +4 -4
  76. package/src/shade/renderer/camera/Camera.d.ts +3 -5
  77. package/src/shade/renderer/camera/Camera.d.ts.map +1 -1
  78. package/src/shade/renderer/camera/Camera.js +281 -280
  79. package/src/shade/renderer/camera/GPUCameraContext.js +233 -233
  80. package/src/shade/renderer/loader/usd/parse_usda.js +1 -1
  81. package/src/shade/renderer/loader/usd/usd_build_scene.d.ts.map +1 -1
  82. package/src/shade/renderer/loader/usd/usd_build_scene.js +658 -652
  83. package/src/shade/renderer/loader/usd/usd_compose_transform.d.ts.map +1 -1
  84. package/src/shade/renderer/loader/usd/usd_compose_transform.js +58 -23
  85. package/src/shade/renderer/particles/prototypeParticleSystem.js +450 -443
  86. package/src/shade/renderer/shadow/map/DirectionalLightShadowmap.d.ts.map +1 -1
  87. package/src/shade/renderer/shadow/map/DirectionalLightShadowmap.js +7 -3
  88. package/src/view/minimap/dom/MinimapCameraView.d.ts +2 -2
  89. package/src/view/minimap/dom/MinimapCameraView.js +206 -206
  90. package/src/engine/graphics/ecs/camera/CameraSystem.d.ts +0 -74
  91. package/src/engine/graphics/ecs/camera/CameraSystem.d.ts.map +0 -1
  92. package/src/engine/graphics/ecs/camera/CameraSystem.js +0 -331
  93. package/src/engine/graphics/ecs/camera/auto_set_camera_clipping_planes.d.ts +0 -10
  94. package/src/engine/graphics/ecs/camera/auto_set_camera_clipping_planes.d.ts.map +0 -1
  95. package/src/engine/graphics/ecs/camera/auto_set_camera_clipping_planes.js +0 -105
  96. package/src/engine/graphics/ecs/camera/build_three_camera_object.d.ts +0 -7
  97. package/src/engine/graphics/ecs/camera/build_three_camera_object.d.ts.map +0 -1
  98. package/src/engine/graphics/ecs/camera/build_three_camera_object.js +0 -29
  99. package/src/engine/graphics/ecs/camera/frustum_from_camera.d.ts +0 -8
  100. package/src/engine/graphics/ecs/camera/frustum_from_camera.d.ts.map +0 -1
  101. package/src/engine/graphics/ecs/camera/frustum_from_camera.js +0 -20
  102. package/src/engine/graphics/ecs/camera/set_camera_aspect_ratio.d.ts +0 -9
  103. package/src/engine/graphics/ecs/camera/set_camera_aspect_ratio.d.ts.map +0 -1
  104. package/src/engine/graphics/ecs/camera/set_camera_aspect_ratio.js +0 -46
  105. package/src/engine/graphics/ecs/camera/unprojectPoint.d.ts +0 -9
  106. package/src/engine/graphics/ecs/camera/unprojectPoint.d.ts.map +0 -1
  107. package/src/engine/graphics/ecs/camera/unprojectPoint.js +0 -14
  108. package/src/engine/graphics/ecs/camera/update_camera_transform.d.ts +0 -6
  109. package/src/engine/graphics/ecs/camera/update_camera_transform.d.ts.map +0 -1
  110. package/src/engine/graphics/ecs/camera/update_camera_transform.js +0 -17
  111. package/src/engine/graphics/particles/ecs/ParticleEmitterSystem.d.ts +0 -67
  112. package/src/engine/graphics/particles/ecs/ParticleEmitterSystem.d.ts.map +0 -1
  113. package/src/engine/graphics/particles/ecs/ParticleEmitterSystem.js +0 -291
  114. package/src/engine/graphics/particles/particular/engine/renderers/billboard/ParticleBillboardMaterial.d.ts +0 -11
  115. package/src/engine/graphics/particles/particular/engine/renderers/billboard/ParticleBillboardMaterial.d.ts.map +0 -1
  116. package/src/engine/graphics/particles/particular/engine/renderers/billboard/ParticleBillboardMaterial.js +0 -497
  117. package/src/engine/graphics/particles/particular/engine/shader/MaterialRecord.d.ts +0 -40
  118. package/src/engine/graphics/particles/particular/engine/shader/MaterialRecord.d.ts.map +0 -1
  119. package/src/engine/graphics/particles/particular/engine/shader/MaterialRecord.js +0 -47
  120. package/src/engine/graphics/texture/sampler/writeSampler2DDataToDataTexture.d.ts +0 -7
  121. package/src/engine/graphics/texture/sampler/writeSampler2DDataToDataTexture.d.ts.map +0 -1
  122. package/src/engine/graphics/texture/sampler/writeSampler2DDataToDataTexture.js +0 -40
@@ -1,303 +1,165 @@
1
- import { Frustum } from 'three';
2
- import { assert } from "../../../../core/assert.js";
3
- import { plane3_compute_ray_intersection } from "../../../../core/geom/3d/plane/plane3_compute_ray_intersection.js";
4
- import { v3_distance_above_plane } from "../../../../core/geom/vec3/v3_distance_above_plane.js";
5
- import Vector1 from "../../../../core/geom/Vector1.js";
6
- import Vector3 from "../../../../core/geom/Vector3.js";
7
- import ObservedBoolean from "../../../../core/model/ObservedBoolean.js";
8
- import ObservedEnum from "../../../../core/model/ObservedEnum.js";
9
- import { frustum_from_camera } from "./frustum_from_camera.js";
10
- import { ProjectionType } from "./ProjectionType.js";
11
- import { quaternion_invert_orientation } from "./quaternion_invert_orientation.js";
12
- import { unprojectPoint } from "./unprojectPoint.js";
13
-
14
- /**
15
- * @class
16
- */
17
- export class Camera {
18
- /**
19
- * Whether clipping planes should be automatically calculated or not
20
- * @type {boolean}
21
- */
22
- autoClip = false;
23
-
24
- /**
25
- * Tunable parameter to prevent clipping planes from thrashing. Clipping planes must move by a certain portion of the current span before frustum gets shrunken
26
- * @type {number}
27
- */
28
- autoClipHysteresis = 0.33;
29
-
30
- object = null;
31
-
32
- /**
33
- *
34
- * @type {Vector1}
35
- */
36
- fov = new Vector1(45);
37
-
38
- /**
39
- *
40
- * @type {ObservedEnum<ProjectionType>}
41
- */
42
- projectionType = new ObservedEnum(ProjectionType.Perspective, ProjectionType);
43
-
44
- /**
45
- *
46
- * @type {ObservedBoolean}
47
- */
48
- active = new ObservedBoolean(true);
49
-
50
- /**
51
- * Near clipping plane
52
- * @type {number}
53
- * @private
54
- */
55
- __clip_far = 100;
56
-
57
- /**
58
- * Far clipping plane
59
- * @type {number}
60
- * @private
61
- */
62
- __clip_near = 0.1;
63
-
64
- /**
65
- *
66
- * @param {Quaternion} output
67
- * @param {Quaternion} input
68
- */
69
- getReciprocalRotation(output, input) {
70
- quaternion_invert_orientation(output, input);
71
- }
72
-
73
- get clip_far() {
74
- return this.__clip_far;
75
- }
76
-
77
- set clip_far(v) {
78
- this.__clip_far = v;
79
-
80
- if (this.object !== null) {
81
- this.object.far = v;
82
- }
83
- }
84
-
85
- get clip_near() {
86
- return this.__clip_near;
87
- }
88
-
89
- set clip_near(v) {
90
- this.__clip_near = v;
91
-
92
- if (this.object !== null) {
93
- this.object.near = v;
94
- }
95
- }
96
-
97
- updateMatrices() {
98
- const c = this.object;
99
-
100
- if (c === null) {
101
- return;
102
- }
103
-
104
- c.updateProjectionMatrix();
105
- c.updateMatrixWorld(true);
106
-
107
- //update world inverse matrix
108
- c.matrixWorldInverse.copy(c.matrixWorld);
109
- c.matrixWorldInverse.invert();
110
- }
111
-
112
- projectRay(x, y, source, target) {
113
- Camera.projectRay(this.object, x, y, source, target);
114
- }
115
-
116
- /**
117
- *
118
- * @param {Camera} other
119
- */
120
- copy(other) {
121
- this.active.copy(other.active);
122
- this.projectionType.copy(other.projectionType);
123
- this.autoClip = other.autoClip;
124
- this.autoClipHysteresis = other.autoClipHysteresis;
125
- this.fov.copy(other.fov);
126
- this.clip_near = other.clip_near;
127
- this.clip_far = other.clip_far;
128
- }
129
-
130
- /**
131
- *
132
- * @returns {Camera}
133
- */
134
- clone() {
135
- const clone = new Camera();
136
-
137
- clone.copy(this);
138
-
139
- return clone;
140
- }
141
-
142
- toJSON() {
143
- return {
144
- autoClip: this.autoClip,
145
- active: this.active.toJSON()
146
- };
147
- }
148
-
149
- fromJSON(json) {
150
- this.autoClip = json.autoClip;
151
-
152
- if (typeof json.active === "boolean") {
153
- this.active.fromJSON(json.active);
154
- } else {
155
- this.active.set(false);
156
- }
157
- }
158
-
159
- /**
160
- *
161
- * @param {Camera|THREE.PerspectiveCamera|THREE.OrthographicCamera} camera
162
- * @param {number} x
163
- * @param {number} y
164
- * @param {Vector3} out_source
165
- * @param {Vector3} out_direction
166
- */
167
- static projectRay(
168
- camera,
169
- x, y,
170
- out_source, out_direction
171
- ) {
172
- assert.defined(camera, "camera");
173
- assert.defined(camera.position, "Camera.position");
174
-
175
-
176
- assert.isNumber(x, 'x');
177
- assert.isNumber(y, "y");
178
-
179
- // assert.ok(x >= -1, `X(=${x}) must be greater than or equal to -1.0, not a clip-space coordinate`);
180
- // assert.ok(x <= 1, `X(=${x}) must be less than or equal to 1.0, not a clip-space coordinate`);
181
-
182
- // assert.ok(y >= -1, `Y(=${y}) must be greater than or equal to -1.0, not a clip-space coordinate`);
183
- // assert.ok(y <= 1, `Y(=${y}) must be less than or equal to 1.0, not a clip-space coordinate`);
184
-
185
- if (camera.isPerspectiveCamera || camera.isOrthographicCamera) {
186
- const m4_world = camera.matrixWorld.elements;
187
- const m4_projection_inverse = camera.projectionMatrixInverse.elements;
188
-
189
- scratch_v3_1.setFromMatrixPosition(m4_world);
190
-
191
- scratch_v3_0.set(x, y, 0.5);
192
-
193
- // NOTE: projection inverse and world matrices are used in "unproject" operation, we update those to make things work as intended. This is handled by the camera system
194
-
195
- unprojectPoint(
196
- scratch_v3_0,
197
- scratch_v3_0,
198
- m4_projection_inverse,
199
- m4_world
200
- );
201
-
202
- //get direction
203
- scratch_v3_0.sub(scratch_v3_1);
204
- scratch_v3_0.normalize();
205
-
206
- out_source.copy(scratch_v3_1);
207
- out_direction.copy(scratch_v3_0);
208
-
209
- } else {
210
- throw new Error('Unsupported camera type');
211
- }
212
- }
213
-
214
- /**
215
- *
216
- * @param {Matrix4} result
217
- */
218
- computeProjectionMatrix(result) {
219
- const camera = this.object;
220
-
221
- if (camera === null) {
222
- return false;
223
- }
224
-
225
- result.multiplyMatrices(camera.projectionMatrix, camera.matrixWorldInverse);
226
-
227
- return true;
228
- }
229
-
230
- /**
231
- *
232
- * @param {Vector3} out
233
- * @param {number} origin_x
234
- * @param {number} origin_y
235
- * @param {number} origin_z
236
- * @param {number} direction_x
237
- * @param {number} direction_y
238
- * @param {number} direction_z
239
- * @param {number} plane_index
240
- */
241
- rayPlaneIntersection(
242
- out,
243
- origin_x, origin_y, origin_z,
244
- direction_x, direction_y, direction_z,
245
- plane_index
246
- ) {
247
-
248
- assert.isNonNegativeInteger(plane_index, 'plane_index');
249
- assert.lessThanOrEqual(plane_index, 5, `plane_index must be <= 5, was ${plane_index}`)
250
-
251
- frustum_from_camera(this.object, scratch_frustum);
252
-
253
- const plane = scratch_frustum.planes[plane_index];
254
-
255
- assert.defined(plane, 'plane');
256
-
257
- plane3_compute_ray_intersection(
258
- out,
259
- origin_x, origin_y, origin_z,
260
- direction_x, direction_y, direction_z,
261
- plane.normal.x, plane.normal.y, plane.normal.z,
262
- plane.constant
263
- );
264
- }
265
-
266
- /**
267
- *
268
- * @param {number} x
269
- * @param {number} y
270
- * @param {number} z
271
- * @param {Vector3} result
272
- */
273
- projectWorldPointOntoNearPlane(x, y, z, result) {
274
-
275
- frustum_from_camera(this.object, scratch_frustum);
276
-
277
- const near = scratch_frustum.planes[0];
278
-
279
- scratch_v3_0.set(x, y, z);
280
-
281
- const normal = near.normal;
282
-
283
- const distance_to_plane = v3_distance_above_plane(x, y, z, normal.x, normal.y, normal.z, near.constant);
284
-
285
- const negative_distance_to_plane = -distance_to_plane;
286
-
287
- result.set(
288
- normal.x * negative_distance_to_plane + x,
289
- normal.y * negative_distance_to_plane + y,
290
- normal.z * negative_distance_to_plane + z,
291
- );
292
- }
293
- }
294
-
295
- Camera.typeName = "Camera";
296
-
297
- Camera.ProjectionType = ProjectionType;
298
-
299
- const scratch_v3_0 = new Vector3();
300
- const scratch_v3_1 = new Vector3();
301
- const scratch_frustum = new Frustum();
302
-
303
-
1
+ import Vector1 from "../../../../core/geom/Vector1.js";
2
+ import ObservedBoolean from "../../../../core/model/ObservedBoolean.js";
3
+ import ObservedEnum from "../../../../core/model/ObservedEnum.js";
4
+ import { ProjectionType } from "./ProjectionType.js";
5
+ import { quaternion_invert_orientation } from "./quaternion_invert_orientation.js";
6
+
7
+ /**
8
+ * @class
9
+ */
10
+ export class Camera {
11
+ /**
12
+ * Whether clipping planes should be automatically calculated or not.
13
+ *
14
+ * **Nothing reads this.** The pass that tightened the planes measured the depth range of the
15
+ * renderer's own layers, which no renderer has offered since the three path was removed; the
16
+ * field stays because it is on the wire and a level carries it.
17
+ *
18
+ * @type {boolean}
19
+ */
20
+ autoClip = false;
21
+
22
+ /**
23
+ * Tunable parameter to prevent clipping planes from thrashing. Clipping planes must move by a certain portion of the current span before frustum gets shrunken
24
+ *
25
+ * Inert for the same reason as {@link autoClip}, and kept for the same one.
26
+ *
27
+ * @type {number}
28
+ */
29
+ autoClipHysteresis = 0.33;
30
+
31
+ /**
32
+ * @type {Float32Array}
33
+ */
34
+ #frustum = new Float32Array(24);
35
+
36
+ /**
37
+ * @type {boolean}
38
+ */
39
+ #has_frustum = false;
40
+
41
+ /**
42
+ *
43
+ * @type {Vector1}
44
+ */
45
+ fov = new Vector1(45);
46
+
47
+ /**
48
+ *
49
+ * @type {ObservedEnum<ProjectionType>}
50
+ */
51
+ projectionType = new ObservedEnum(ProjectionType.Perspective, ProjectionType);
52
+
53
+ /**
54
+ *
55
+ * @type {ObservedBoolean}
56
+ */
57
+ active = new ObservedBoolean(true);
58
+
59
+ /**
60
+ * Far clipping plane
61
+ * @type {number}
62
+ */
63
+ clip_far = 100;
64
+
65
+ /**
66
+ * Near clipping plane
67
+ * @type {number}
68
+ */
69
+ clip_near = 0.1;
70
+
71
+ /**
72
+ * The planes of the frame this camera last drew — six
73
+ * `[normal_x, normal_y, normal_z, constant]` tuples, the layout every frustum query in the tree
74
+ * reads — or `null` when it has not drawn one.
75
+ *
76
+ * A method rather than a property because it is not one: the inspector draws a row for every
77
+ * readable property a component has, and this is an answer the renderer gave, not a field
78
+ * anybody authors. The planes are rewritten under the caller every tick.
79
+ *
80
+ * @returns {Float32Array|null}
81
+ */
82
+ getFrustumPlanes() {
83
+ if (!this.#has_frustum) {
84
+ return null;
85
+ }
86
+
87
+ return this.#frustum;
88
+ }
89
+
90
+ /**
91
+ * Record the planes the frame was drawn with.
92
+ *
93
+ * The renderer's camera is what computes them, because the frustum a gameplay query wants is
94
+ * the one the picture was actually drawn with; deriving a second one from the field of view
95
+ * here would need the aspect ratio, which belongs to whatever surface the frame is going out at
96
+ * and not to a camera entity.
97
+ *
98
+ * @param {Float32Array|number[]} planes six `[normal_x, normal_y, normal_z, constant]` tuples
99
+ */
100
+ publishFrustum(planes) {
101
+ this.#frustum.set(planes);
102
+
103
+ this.#has_frustum = true;
104
+ }
105
+
106
+ /**
107
+ *
108
+ * @param {Quaternion} output
109
+ * @param {Quaternion} input
110
+ */
111
+ getReciprocalRotation(output, input) {
112
+ quaternion_invert_orientation(output, input);
113
+ }
114
+
115
+ /**
116
+ *
117
+ * @param {Camera} other
118
+ */
119
+ copy(other) {
120
+ this.active.copy(other.active);
121
+ this.projectionType.copy(other.projectionType);
122
+ this.autoClip = other.autoClip;
123
+ this.autoClipHysteresis = other.autoClipHysteresis;
124
+ this.fov.copy(other.fov);
125
+ this.clip_near = other.clip_near;
126
+ this.clip_far = other.clip_far;
127
+ }
128
+
129
+ /**
130
+ *
131
+ * @returns {Camera}
132
+ */
133
+ clone() {
134
+ const clone = new Camera();
135
+
136
+ clone.copy(this);
137
+
138
+ return clone;
139
+ }
140
+
141
+ toJSON() {
142
+ return {
143
+ autoClip: this.autoClip,
144
+ active: this.active.toJSON()
145
+ };
146
+ }
147
+
148
+ fromJSON(json) {
149
+ this.autoClip = json.autoClip;
150
+
151
+ if (typeof json.active === "boolean") {
152
+ this.active.fromJSON(json.active);
153
+ } else {
154
+ this.active.set(false);
155
+ }
156
+ }
157
+
158
+ }
159
+
160
+ Camera.typeName = "Camera";
161
+
162
+ Camera.ProjectionType = ProjectionType;
163
+
164
+
165
+
@@ -0,0 +1,14 @@
1
+ /**
2
+ * The world-space frustum of the frame, or `null` when nothing is drawing one.
3
+ *
4
+ * Six `[normal_x, normal_y, normal_z, constant]` tuples, the layout every frustum query in the tree
5
+ * reads — a point is inside when `normal · p + constant` is non-negative for all six.
6
+ *
7
+ * The planes belong to the camera component and are rewritten every tick, so a caller holds the
8
+ * answer for the length of its own call and no longer.
9
+ *
10
+ * @param {EntityComponentDataset} ecd
11
+ * @returns {Float32Array|null}
12
+ */
13
+ export function camera_active_frustum(ecd: EntityComponentDataset): Float32Array | null;
14
+ //# sourceMappingURL=camera_active_frustum.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"camera_active_frustum.d.ts","sourceRoot":"","sources":["../../../../../../src/engine/graphics/ecs/camera/camera_active_frustum.js"],"names":[],"mappings":"AAEA;;;;;;;;;;;GAWG;AACH,oEAFa,YAAY,GAAC,IAAI,CAY7B"}
@@ -0,0 +1,25 @@
1
+ import { camera_find_active } from "./camera_find_active.js";
2
+
3
+ /**
4
+ * The world-space frustum of the frame, or `null` when nothing is drawing one.
5
+ *
6
+ * Six `[normal_x, normal_y, normal_z, constant]` tuples, the layout every frustum query in the tree
7
+ * reads — a point is inside when `normal · p + constant` is non-negative for all six.
8
+ *
9
+ * The planes belong to the camera component and are rewritten every tick, so a caller holds the
10
+ * answer for the length of its own call and no longer.
11
+ *
12
+ * @param {EntityComponentDataset} ecd
13
+ * @returns {Float32Array|null}
14
+ */
15
+ export function camera_active_frustum(ecd) {
16
+ const { component } = camera_find_active(ecd);
17
+
18
+ if (component === undefined) {
19
+ return null;
20
+ }
21
+
22
+ // a camera that has not driven a frame yet answers `null`; zeroed planes would say "everything
23
+ // is visible", which is an answer rather than an admission
24
+ return component.getFrustumPlanes();
25
+ }
@@ -0,0 +1,16 @@
1
+ /**
2
+ * The camera entity the frame is drawn from, or an entity of `-1` when the dataset has none.
3
+ *
4
+ * **The first active one wins**, which is the rule `CameraSystem3` settles on when it elects the
5
+ * camera it copies onto the renderer's. Two entities both claiming to be active therefore resolve
6
+ * the same way here as they do there; the predecessor of this function took the last one and could
7
+ * name a camera nothing was drawing from.
8
+ *
9
+ * @param {EntityComponentDataset} ecd
10
+ * @returns {{component: (Camera|undefined), entity: number}}
11
+ */
12
+ export function camera_find_active(ecd: EntityComponentDataset): {
13
+ component: (Camera | undefined);
14
+ entity: number;
15
+ };
16
+ //# sourceMappingURL=camera_find_active.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"camera_find_active.d.ts","sourceRoot":"","sources":["../../../../../../src/engine/graphics/ecs/camera/camera_find_active.js"],"names":[],"mappings":"AAEA;;;;;;;;;;GAUG;AACH,iEAFa;IAAC,SAAS,EAAE,CAAC,SAAO,SAAS,CAAC,CAAC;IAAC,MAAM,EAAE,MAAM,CAAA;CAAC,CAgB3D"}
@@ -0,0 +1,28 @@
1
+ import { camera_traverse_active } from "./camera_traverse_active.js";
2
+
3
+ /**
4
+ * The camera entity the frame is drawn from, or an entity of `-1` when the dataset has none.
5
+ *
6
+ * **The first active one wins**, which is the rule `CameraSystem3` settles on when it elects the
7
+ * camera it copies onto the renderer's. Two entities both claiming to be active therefore resolve
8
+ * the same way here as they do there; the predecessor of this function took the last one and could
9
+ * name a camera nothing was drawing from.
10
+ *
11
+ * @param {EntityComponentDataset} ecd
12
+ * @returns {{component: (Camera|undefined), entity: number}}
13
+ */
14
+ export function camera_find_active(ecd) {
15
+ const result = {
16
+ entity: -1,
17
+ component: undefined
18
+ };
19
+
20
+ camera_traverse_active(ecd, (camera, entity) => {
21
+ if (result.entity === -1) {
22
+ result.entity = entity;
23
+ result.component = camera;
24
+ }
25
+ });
26
+
27
+ return result;
28
+ }
@@ -0,0 +1,12 @@
1
+ /**
2
+ * Visit every camera entity that claims to be active.
3
+ *
4
+ * More than one may claim it; only one of them drives the frame, and which one that is belongs to
5
+ * {@link camera_find_active}.
6
+ *
7
+ * @param {EntityComponentDataset} ecd
8
+ * @param {(camera: Camera, entity: number) => void} visitor
9
+ */
10
+ export function camera_traverse_active(ecd: EntityComponentDataset, visitor: (camera: Camera, entity: number) => void): void;
11
+ import { Camera } from "./Camera.js";
12
+ //# sourceMappingURL=camera_traverse_active.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"camera_traverse_active.d.ts","sourceRoot":"","sources":["../../../../../../src/engine/graphics/ecs/camera/camera_traverse_active.js"],"names":[],"mappings":"AAEA;;;;;;;;GAQG;AACH,sFAFoB,MAAM,UAAU,MAAM,KAAK,IAAI,QAQlD;uBAjBsB,aAAa"}
@@ -0,0 +1,18 @@
1
+ import { Camera } from "./Camera.js";
2
+
3
+ /**
4
+ * Visit every camera entity that claims to be active.
5
+ *
6
+ * More than one may claim it; only one of them drives the frame, and which one that is belongs to
7
+ * {@link camera_find_active}.
8
+ *
9
+ * @param {EntityComponentDataset} ecd
10
+ * @param {(camera: Camera, entity: number) => void} visitor
11
+ */
12
+ export function camera_traverse_active(ecd, visitor) {
13
+ ecd.traverseComponents(Camera, function (camera, entity) {
14
+ if (camera.active.getValue()) {
15
+ visitor(camera, entity);
16
+ }
17
+ });
18
+ }