@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,281 +1,296 @@
1
- import { Matrix4 } from "three";
2
- import { assert } from "../../../../../core/assert.js";
3
- import { m4_euler_angles } from "../../../../../core/geom/3d/mat4/m4_euler_angles.js";
4
- import { normalize_angle_rad } from "../../../../../core/geom/normalize_angle_rad.js";
5
- import Quaternion from "../../../../../core/geom/Quaternion.js";
6
- import Vector3 from '../../../../../core/geom/Vector3.js';
7
- import { lerp } from "../../../../../core/math/lerp.js";
8
- import { max2 } from "../../../../../core/math/max2.js";
9
- import { sign_not_zero } from "../../../../../core/math/sign_not_zero.js";
10
-
11
- const m4 = new Matrix4();
12
- const angles = [];
13
-
14
- const q_view = new Quaternion();
15
-
16
- const v3_view_right = new Vector3();
17
- const v3_view_up = new Vector3();
18
-
19
-
20
- /**
21
- *
22
- * @param {number} displacement_x
23
- * @param {number} displacement_y
24
- * @param {TopDownCameraController} input source thing being rotated
25
- * @param {TopDownCameraController} output target thing where the result is written to
26
- */
27
- export function rotate_from_view(displacement_x, displacement_y, input, output) {
28
- // crop yaw and pitch to safe range of -PI to PI
29
- const i_pitch = normalize_angle_rad(input.pitch);
30
- const i_yaw = normalize_angle_rad(input.yaw);
31
- const i_roll = normalize_angle_rad(input.roll);
32
-
33
- const quaternion = Quaternion.fromEulerAngles(i_pitch, i_yaw, i_roll);
34
- const forward = Vector3.up.clone();
35
- forward.applyQuaternion(quaternion);
36
-
37
- // flip rotation axis when pitch is over 90deg in either direction, that is UP vector is pointing down
38
- const d_yaw = sign_not_zero(forward.y) * displacement_x;
39
-
40
- output.yaw = i_yaw + d_yaw;
41
- output.pitch = i_pitch - displacement_y;
42
- }
43
-
44
- /**
45
- * The orientation a controller looks along. The camera's transform is built from this and the
46
- * distance, so anything that needs the view's own axes takes them from here rather than from
47
- * whatever object a renderer happens to keep.
48
- *
49
- * @param {Quaternion} result
50
- * @param {TopDownCameraController} controller
51
- */
52
- export function top_down_view_rotation(result, controller) {
53
- result.fromEulerAnglesZYX(controller.pitch, controller.yaw, controller.roll);
54
- }
55
-
56
- /**
57
- * @param {Vector3} result
58
- * @param {Vector3} direction unit length
59
- * @param {number} distance world units
60
- * @param {Vector3} multiplier
61
- */
62
- function move_along(result, direction, distance, multiplier) {
63
- result._add(
64
- direction.x * distance * multiplier.x,
65
- direction.y * distance * multiplier.y,
66
- direction.z * distance * multiplier.z
67
- );
68
- }
69
-
70
- const deg2_in_rad = Math.PI / 360;
71
-
72
- /**
73
- * Move a controller's target across the view plane it is looking at, by a displacement given in
74
- * viewport pixels; right and down are positive.
75
- *
76
- * Handlers pass where the pointer *was* less where it *is*, so the target travels against the drag
77
- * and the world under the pointer comes with it.
78
- *
79
- * **The viewer's right is the negated X axis of the view rotation**, which is the one thing here
80
- * that is easy to invert silently: meep's forward is +Z with up +Y, so a viewer facing along
81
- * forward has world −X on their right. Both renderers read it that way Shade builds its view
82
- * matrix from `[−right, up, −forward]`, and the three camera the legacy path drives carries the
83
- * object orientation with its forward negated, which flips the same axis.
84
- *
85
- * @param {Vector2} delta viewport pixels
86
- * @param {TopDownCameraController} controller its {@link TopDownCameraController#target} is moved
87
- * @param {number} viewport_height_px the perspective camera is fitted to height alone, so width
88
- * plays no part
89
- * @param {number} fov vertical field of view, in degrees
90
- * @param {Vector3} [multiplier] per-axis scale on the world displacement; the strategy map zeroes Y
91
- * to keep its target on the ground
92
- */
93
- function pan(delta, controller, viewport_height_px, fov, multiplier = Vector3.one) {
94
- assert.isNumber(viewport_height_px, 'viewport_height_px');
95
- assert.isNumber(fov, 'fov');
96
-
97
- // half of the fov is center to top of screen
98
- const d = controller.distance * Math.tan(fov * deg2_in_rad);
99
-
100
- const m = 2 * d / viewport_height_px;
101
-
102
- top_down_view_rotation(q_view, controller);
103
-
104
- v3_view_right.copy(Vector3.right);
105
- v3_view_right.applyQuaternion(q_view);
106
- v3_view_right.negate();
107
-
108
- v3_view_up.copy(Vector3.up);
109
- v3_view_up.applyQuaternion(q_view);
110
-
111
- const target = controller.target;
112
-
113
- move_along(target, v3_view_right, delta.x * m, multiplier);
114
-
115
- // screen Y runs down the viewport and the view's up runs the other way
116
- move_along(target, v3_view_up, -delta.y * m, multiplier);
117
- }
118
-
119
-
120
- class TopDownCameraController {
121
- target = new Vector3();
122
- pitch = 0;
123
- yaw = 0;
124
- roll = 0;
125
- distance = 0;
126
- distanceMin = 1;
127
- distanceMax = 200;
128
-
129
- constructor(options) {
130
- //
131
- if (options !== void 0) {
132
- this.fromJSON(options);
133
- }
134
- }
135
-
136
- /**
137
- * Set target, rotation and distance from 2 vectors
138
- * @param {Vector3} eye
139
- * @param {Vector3} target
140
- * @param {Vector3} [up]
141
- */
142
- setFromEyeAndTarget(eye, target, up = Vector3.up) {
143
-
144
- /*
145
- NOTE: I'm not sure why, but three.js camera points in the opposite direction to normal objects
146
- See: https://github.com/mrdoob/three.js/blob/412b99a7f26e117ea97f40eb53d010ab81aa3279/src/core/Object3D.js#L282
147
- */
148
- m4.lookAt(target, eye, up);
149
-
150
- m4_euler_angles(angles, m4.elements, 2, 1, 0)
151
-
152
- this.pitch = angles[2];
153
- this.yaw = angles[1];
154
- this.roll = angles[0];
155
-
156
- this.distance = eye.distanceTo(target);
157
-
158
- // ensure we can maintain this distance
159
- this.distanceMax = max2(this.distance, this.distanceMax);
160
-
161
- this.target.copy(target);
162
- }
163
-
164
- /**
165
- *
166
- * @param {TopDownCameraController} other
167
- * @returns {boolean}
168
- */
169
- equals(other) {
170
- return this.target.equals(other.target)
171
- && this.pitch === other.pitch
172
- && this.yaw === other.yaw
173
- && this.roll === other.roll
174
- && this.distance === other.distance
175
- && this.distanceMin === other.distanceMin
176
- && this.distanceMax === other.distanceMax
177
- ;
178
- }
179
-
180
- /**
181
- *
182
- * @param {TopDownCameraController} other
183
- */
184
- copy(other) {
185
- this.target.copy(other.target);
186
-
187
- this.pitch = other.pitch;
188
- this.yaw = other.yaw;
189
- this.roll = other.roll;
190
-
191
- this.distance = other.distance;
192
- this.distanceMax = other.distanceMax;
193
- this.distanceMin = other.distanceMin;
194
- }
195
-
196
- /**
197
- *
198
- * @returns {TopDownCameraController}
199
- */
200
- clone() {
201
- const r = new TopDownCameraController();
202
-
203
- r.copy(this);
204
-
205
- return r;
206
- }
207
-
208
- /**
209
- *
210
- * @param {TopDownCameraController} a
211
- * @param {TopDownCameraController} b
212
- * @param {number} t
213
- */
214
- lerp(a, b, t) {
215
- this.target.lerpVectors(a.target, b.target, t);
216
-
217
- this.pitch = lerp(a.pitch, b.pitch, t);
218
- this.yaw = lerp(a.yaw, b.yaw, t);
219
- this.roll = lerp(a.roll, b.roll, t);
220
-
221
- this.distance = lerp(a.distance, b.distance, t);
222
-
223
- this.distanceMin = lerp(a.distanceMin, b.distanceMin, t);
224
- this.distanceMax = lerp(a.distanceMax, b.distanceMax, t);
225
- }
226
-
227
- toJSON() {
228
- return {
229
- target: this.target.toJSON(),
230
-
231
- pitch: this.pitch,
232
- yaw: this.yaw,
233
- roll: this.roll,
234
-
235
- distance: this.distance,
236
- distanceMin: this.distanceMin,
237
- distanceMax: this.distanceMax
238
- };
239
- }
240
-
241
- fromJSON(
242
- {
243
- distance = 0,
244
- distanceMin = 0,
245
- distanceMax = 0,
246
- pitch = 0,
247
- yaw = 0,
248
- roll = 0,
249
- target = Vector3.zero,
250
- }
251
- ) {
252
-
253
- this.distance = distance;
254
- this.distanceMin = distanceMin;
255
- this.distanceMax = distanceMax;
256
-
257
- this.pitch = pitch;
258
- this.roll = roll;
259
- this.yaw = yaw;
260
-
261
- this.target.fromJSON(target);
262
-
263
- }
264
-
265
- static fromJSON(j) {
266
- const r = new TopDownCameraController();
267
-
268
- r.fromJSON(j);
269
-
270
- return r;
271
- }
272
- }
273
-
274
- TopDownCameraController.typeName = "TopDownCameraController";
275
-
276
- TopDownCameraController.pan = pan;
277
- TopDownCameraController.rotate = rotate_from_view;
278
-
279
- export default TopDownCameraController;
280
-
281
-
1
+ import { assert } from "../../../../../core/assert.js";
2
+ import { m4_euler_angles } from "../../../../../core/geom/3d/mat4/m4_euler_angles.js";
3
+ import {
4
+ m4_from_rotation_translation_scale_scalar
5
+ } from "../../../../../core/geom/3d/mat4/m4_from_rotation_translation_scale_scalar.js";
6
+ import { normalize_angle_rad } from "../../../../../core/geom/normalize_angle_rad.js";
7
+ import Quaternion from "../../../../../core/geom/Quaternion.js";
8
+ import Vector3 from '../../../../../core/geom/Vector3.js';
9
+ import { lerp } from "../../../../../core/math/lerp.js";
10
+ import { max2 } from "../../../../../core/math/max2.js";
11
+ import { sign_not_zero } from "../../../../../core/math/sign_not_zero.js";
12
+
13
+ const m4 = [];
14
+ const angles = [];
15
+
16
+ const q_look = new Quaternion();
17
+ const v3_forward = new Vector3();
18
+
19
+ const q_view = new Quaternion();
20
+
21
+ const v3_view_right = new Vector3();
22
+ const v3_view_up = new Vector3();
23
+
24
+
25
+ /**
26
+ *
27
+ * @param {number} displacement_x
28
+ * @param {number} displacement_y
29
+ * @param {TopDownCameraController} input source thing being rotated
30
+ * @param {TopDownCameraController} output target thing where the result is written to
31
+ */
32
+ export function rotate_from_view(displacement_x, displacement_y, input, output) {
33
+ // crop yaw and pitch to safe range of -PI to PI
34
+ const i_pitch = normalize_angle_rad(input.pitch);
35
+ const i_yaw = normalize_angle_rad(input.yaw);
36
+ const i_roll = normalize_angle_rad(input.roll);
37
+
38
+ const quaternion = Quaternion.fromEulerAngles(i_pitch, i_yaw, i_roll);
39
+ const forward = Vector3.up.clone();
40
+ forward.applyQuaternion(quaternion);
41
+
42
+ // flip rotation axis when pitch is over 90deg in either direction, that is UP vector is pointing down
43
+ const d_yaw = sign_not_zero(forward.y) * displacement_x;
44
+
45
+ output.yaw = i_yaw + d_yaw;
46
+ output.pitch = i_pitch - displacement_y;
47
+ }
48
+
49
+ /**
50
+ * The orientation a controller looks along. The camera's transform is built from this and the
51
+ * distance, so anything that needs the view's own axes takes them from here rather than from
52
+ * whatever object a renderer happens to keep.
53
+ *
54
+ * @param {Quaternion} result
55
+ * @param {TopDownCameraController} controller
56
+ */
57
+ export function top_down_view_rotation(result, controller) {
58
+ result.fromEulerAnglesZYX(controller.pitch, controller.yaw, controller.roll);
59
+ }
60
+
61
+ /**
62
+ * @param {Vector3} result
63
+ * @param {Vector3} direction unit length
64
+ * @param {number} distance world units
65
+ * @param {Vector3} multiplier
66
+ */
67
+ function move_along(result, direction, distance, multiplier) {
68
+ result._add(
69
+ direction.x * distance * multiplier.x,
70
+ direction.y * distance * multiplier.y,
71
+ direction.z * distance * multiplier.z
72
+ );
73
+ }
74
+
75
+ const deg2_in_rad = Math.PI / 360;
76
+
77
+ /**
78
+ * Move a controller's target across the view plane it is looking at, by a displacement given in
79
+ * viewport pixels; right and down are positive.
80
+ *
81
+ * Handlers pass where the pointer *was* less where it *is*, so the target travels against the drag
82
+ * and the world under the pointer comes with it.
83
+ *
84
+ * **The viewer's right is the negated X axis of the view rotation**, which is the one thing here
85
+ * that is easy to invert silently: meep's forward is +Z with up +Y, so a viewer facing along
86
+ * forward has world −X on their right. Both renderers read it that way — Shade builds its view
87
+ * matrix from `[−right, up, −forward]`, and the three camera the legacy path drives carries the
88
+ * object orientation with its forward negated, which flips the same axis.
89
+ *
90
+ * @param {Vector2} delta viewport pixels
91
+ * @param {TopDownCameraController} controller its {@link TopDownCameraController#target} is moved
92
+ * @param {number} viewport_height_px the perspective camera is fitted to height alone, so width
93
+ * plays no part
94
+ * @param {number} fov vertical field of view, in degrees
95
+ * @param {Vector3} [multiplier] per-axis scale on the world displacement; the strategy map zeroes Y
96
+ * to keep its target on the ground
97
+ */
98
+ function pan(delta, controller, viewport_height_px, fov, multiplier = Vector3.one) {
99
+ assert.isNumber(viewport_height_px, 'viewport_height_px');
100
+ assert.isNumber(fov, 'fov');
101
+
102
+ // half of the fov is center to top of screen
103
+ const d = controller.distance * Math.tan(fov * deg2_in_rad);
104
+
105
+ const m = 2 * d / viewport_height_px;
106
+
107
+ top_down_view_rotation(q_view, controller);
108
+
109
+ v3_view_right.copy(Vector3.right);
110
+ v3_view_right.applyQuaternion(q_view);
111
+ v3_view_right.negate();
112
+
113
+ v3_view_up.copy(Vector3.up);
114
+ v3_view_up.applyQuaternion(q_view);
115
+
116
+ const target = controller.target;
117
+
118
+ move_along(target, v3_view_right, delta.x * m, multiplier);
119
+
120
+ // screen Y runs down the viewport and the view's up runs the other way
121
+ move_along(target, v3_view_up, -delta.y * m, multiplier);
122
+ }
123
+
124
+
125
+ class TopDownCameraController {
126
+ target = new Vector3();
127
+ pitch = 0;
128
+ yaw = 0;
129
+ roll = 0;
130
+ distance = 0;
131
+ distanceMin = 1;
132
+ distanceMax = 200;
133
+
134
+ constructor(options) {
135
+ //
136
+ if (options !== void 0) {
137
+ this.fromJSON(options);
138
+ }
139
+ }
140
+
141
+ /**
142
+ * Set target, rotation and distance from 2 vectors.
143
+ *
144
+ * `eye` must not coincide with `target`, and `up` must not be parallel to the direction between
145
+ * them a degenerate basis has no angles to report and the caller gets an arbitrary one.
146
+ *
147
+ * @param {Vector3} eye
148
+ * @param {Vector3} target
149
+ * @param {Vector3} [up]
150
+ */
151
+ setFromEyeAndTarget(eye, target, up = Vector3.up) {
152
+
153
+ v3_forward.copy(target);
154
+ v3_forward.sub(eye);
155
+
156
+ q_look.lookRotation(v3_forward, up);
157
+
158
+ m4_from_rotation_translation_scale_scalar(
159
+ m4,
160
+ q_look.x, q_look.y, q_look.z, q_look.w,
161
+ 0, 0, 0,
162
+ 1, 1, 1
163
+ );
164
+
165
+ m4_euler_angles(angles, m4, 2, 1, 0)
166
+
167
+ this.pitch = angles[2];
168
+ this.yaw = angles[1];
169
+ this.roll = angles[0];
170
+
171
+ this.distance = eye.distanceTo(target);
172
+
173
+ // ensure we can maintain this distance
174
+ this.distanceMax = max2(this.distance, this.distanceMax);
175
+
176
+ this.target.copy(target);
177
+ }
178
+
179
+ /**
180
+ *
181
+ * @param {TopDownCameraController} other
182
+ * @returns {boolean}
183
+ */
184
+ equals(other) {
185
+ return this.target.equals(other.target)
186
+ && this.pitch === other.pitch
187
+ && this.yaw === other.yaw
188
+ && this.roll === other.roll
189
+ && this.distance === other.distance
190
+ && this.distanceMin === other.distanceMin
191
+ && this.distanceMax === other.distanceMax
192
+ ;
193
+ }
194
+
195
+ /**
196
+ *
197
+ * @param {TopDownCameraController} other
198
+ */
199
+ copy(other) {
200
+ this.target.copy(other.target);
201
+
202
+ this.pitch = other.pitch;
203
+ this.yaw = other.yaw;
204
+ this.roll = other.roll;
205
+
206
+ this.distance = other.distance;
207
+ this.distanceMax = other.distanceMax;
208
+ this.distanceMin = other.distanceMin;
209
+ }
210
+
211
+ /**
212
+ *
213
+ * @returns {TopDownCameraController}
214
+ */
215
+ clone() {
216
+ const r = new TopDownCameraController();
217
+
218
+ r.copy(this);
219
+
220
+ return r;
221
+ }
222
+
223
+ /**
224
+ *
225
+ * @param {TopDownCameraController} a
226
+ * @param {TopDownCameraController} b
227
+ * @param {number} t
228
+ */
229
+ lerp(a, b, t) {
230
+ this.target.lerpVectors(a.target, b.target, t);
231
+
232
+ this.pitch = lerp(a.pitch, b.pitch, t);
233
+ this.yaw = lerp(a.yaw, b.yaw, t);
234
+ this.roll = lerp(a.roll, b.roll, t);
235
+
236
+ this.distance = lerp(a.distance, b.distance, t);
237
+
238
+ this.distanceMin = lerp(a.distanceMin, b.distanceMin, t);
239
+ this.distanceMax = lerp(a.distanceMax, b.distanceMax, t);
240
+ }
241
+
242
+ toJSON() {
243
+ return {
244
+ target: this.target.toJSON(),
245
+
246
+ pitch: this.pitch,
247
+ yaw: this.yaw,
248
+ roll: this.roll,
249
+
250
+ distance: this.distance,
251
+ distanceMin: this.distanceMin,
252
+ distanceMax: this.distanceMax
253
+ };
254
+ }
255
+
256
+ fromJSON(
257
+ {
258
+ distance = 0,
259
+ distanceMin = 0,
260
+ distanceMax = 0,
261
+ pitch = 0,
262
+ yaw = 0,
263
+ roll = 0,
264
+ target = Vector3.zero,
265
+ }
266
+ ) {
267
+
268
+ this.distance = distance;
269
+ this.distanceMin = distanceMin;
270
+ this.distanceMax = distanceMax;
271
+
272
+ this.pitch = pitch;
273
+ this.roll = roll;
274
+ this.yaw = yaw;
275
+
276
+ this.target.fromJSON(target);
277
+
278
+ }
279
+
280
+ static fromJSON(j) {
281
+ const r = new TopDownCameraController();
282
+
283
+ r.fromJSON(j);
284
+
285
+ return r;
286
+ }
287
+ }
288
+
289
+ TopDownCameraController.typeName = "TopDownCameraController";
290
+
291
+ TopDownCameraController.pan = pan;
292
+ TopDownCameraController.rotate = rotate_from_view;
293
+
294
+ export default TopDownCameraController;
295
+
296
+
@@ -5,7 +5,7 @@
5
5
  *
6
6
  * WHY THIS EXISTS
7
7
  *
8
- * `auto_set_camera_clipping_planes` and `extend_shadow_camera_near_for_casters`
8
+ * `extend_shadow_camera_near_for_casters` and the camera auto-clipping pass that has since gone
9
9
  * each restated two things verbatim:
10
10
  *
11
11
  * - the three.js matrix-layout invariant that a camera's view direction is the
@@ -5,7 +5,7 @@
5
5
  *
6
6
  * WHY THIS EXISTS
7
7
  *
8
- * `auto_set_camera_clipping_planes` and `extend_shadow_camera_near_for_casters`
8
+ * `extend_shadow_camera_near_for_casters` and the camera auto-clipping pass that has since gone
9
9
  * each restated two things verbatim:
10
10
  *
11
11
  * - the three.js matrix-layout invariant that a camera's view direction is the
@@ -0,0 +1,52 @@
1
+ /**
2
+ * An {@link AttributeSpec} and the elements stored under it.
3
+ *
4
+ * The spec says what one item is — how many components, in what type, whether integer values are
5
+ * read back normalized — and the array holds `count` of them end to end. Nothing here knows about a
6
+ * renderer: uploading is the business of whoever is drawing, and a consumer that re-reads the array
7
+ * every frame has nothing to be told.
8
+ */
9
+ export class AttributeData {
10
+ /**
11
+ * Allocate storage for `count` items of `spec`.
12
+ *
13
+ * @param {AttributeSpec} spec
14
+ * @param {number} count
15
+ * @returns {AttributeData}
16
+ */
17
+ static allocate(spec: AttributeSpec, count: number): AttributeData;
18
+ /**
19
+ * @param {AttributeSpec} spec
20
+ * @param {Float32Array|Float64Array|Uint8Array|Uint16Array|Uint32Array|Int8Array|Int16Array|Int32Array} array
21
+ */
22
+ constructor(spec: AttributeSpec, array: Float32Array | Float64Array | Uint8Array | Uint16Array | Uint32Array | Int8Array | Int16Array | Int32Array);
23
+ /**
24
+ * @type {AttributeSpec}
25
+ */
26
+ spec: AttributeSpec;
27
+ /**
28
+ * `count * spec.itemSize` elements, item-major.
29
+ *
30
+ * @type {Float32Array|Float64Array|Uint8Array|Uint16Array|Uint32Array|Int8Array|Int16Array|Int32Array}
31
+ */
32
+ array: Float32Array | Float64Array | Uint8Array | Uint16Array | Uint32Array | Int8Array | Int16Array | Int32Array;
33
+ /**
34
+ * @returns {string}
35
+ */
36
+ get name(): string;
37
+ /**
38
+ * @returns {number}
39
+ */
40
+ get itemSize(): number;
41
+ /**
42
+ * @returns {boolean}
43
+ */
44
+ get normalized(): boolean;
45
+ /**
46
+ * How many items the array has room for.
47
+ *
48
+ * @returns {number}
49
+ */
50
+ get count(): number;
51
+ }
52
+ //# sourceMappingURL=AttributeData.d.ts.map