@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 +1 @@
1
- {"version":3,"file":"DirectionalLightShadowmap.d.ts","sourceRoot":"","sources":["../../../../../../src/shade/renderer/shadow/map/DirectionalLightShadowmap.js"],"names":[],"mappings":"AAkGA;IACI;;;OAGG;IACH,cAFU,MAAM,CAEC;IAEjB;;;OAGG;IACH,cAFU,MAAM,CAEC;IAEjB,qBAAuD;IAEvD,+CA2PC;IAED,qBAYC;CAEJ;0BAjWyB,gBAAgB"}
1
+ {"version":3,"file":"DirectionalLightShadowmap.d.ts","sourceRoot":"","sources":["../../../../../../src/shade/renderer/shadow/map/DirectionalLightShadowmap.js"],"names":[],"mappings":"AAkGA;IACI;;;OAGG;IACH,cAFU,MAAM,CAEC;IAEjB;;;OAGG;IACH,cAFU,MAAM,CAEC;IAEjB,qBAAuD;IAEvD,+CA+PC;IAED,qBAYC;CAEJ;0BArWyB,gBAAgB"}
@@ -14,6 +14,7 @@ import { frustum_slice } from "../../../../core/geom/3d/frustum/frustum_slice.js
14
14
  import { compose_matrix4_array } from "../../../../core/geom/3d/mat4/compose_matrix4_array.js";
15
15
  import { m4_invert } from "../../../../core/geom/3d/mat4/m4_invert.js";
16
16
  import { m4_multiply } from "../../../../core/geom/3d/mat4/m4_multiply.js";
17
+ import { m4_orthographic_off_center_z0 } from "../../../../core/geom/3d/mat4/m4_orthographic_off_center_z0.js";
17
18
  import Quaternion from "../../../../core/geom/Quaternion.js";
18
19
  import { v3_array_centroid } from "../../../../core/geom/vec3/v3_array_centroid.js";
19
20
  import Vector3 from "../../../../core/geom/Vector3.js";
@@ -22,7 +23,6 @@ import { inverseLerp } from "../../../../core/math/inverseLerp.js";
22
23
  import {
23
24
  quaternion_invert_orientation
24
25
  } from "../../../../engine/graphics/ecs/camera/quaternion_invert_orientation.js";
25
- import { mat4 } from "gl-matrix";
26
26
  import { SHADOWMAP_CSM_CASCADE_BLEND_FRACTION } from "./csm/SHADOWMAP_CSM_CASCADE_BLEND_FRACTION.js";
27
27
  import { SHADOWMAP_CSM_CASCADE_COUNT } from "./csm/SHADOWMAP_CSM_CASCADE_COUNT.js";
28
28
  import { Shadowmap } from "./Shadowmap.js";
@@ -271,8 +271,12 @@ export class DirectionalLightShadowmap extends Shadowmap {
271
271
 
272
272
  const shadow_proj = new Float32Array(16);
273
273
 
274
- // the z range here is irrelevant: planes 4/5 are relaxed by the query
275
- mat4.orthoZO(
274
+ // The z range here is irrelevant: planes 4/5 are relaxed by the query, which
275
+ // keeps their normals and recomputes only their offsets. This projection looks
276
+ // down +z where the light's view space looks down -z, which swaps those two
277
+ // planes over — and the loop below reads both and takes the nearer, so the swap
278
+ // does not reach the result.
279
+ m4_orthographic_off_center_z0(
276
280
  shadow_proj,
277
281
  extents.x0, extents.x1,
278
282
  extents.y0, extents.y1,
@@ -23,8 +23,8 @@ export class MinimapCameraView extends View {
23
23
  camera: Camera;
24
24
  /**
25
25
  * **The frame is traced with the renderer's own ray, not the camera component's.**
26
- * `Camera.projectRay` goes through `camera.object`, a three.js camera that only the legacy
27
- * `CameraSystem` builds — under Shade it is never built, so every update warned and drew
26
+ * `Camera.projectRay` went through a three camera object that only the legacy camera
27
+ * system built — under Shade it was never built, so every update warned and drew
28
28
  * nothing. `viewportProjectionRay` is the one picking primitive both engines answer with the
29
29
  * same meaning, and it reports the camera that actually drew.
30
30
  *
@@ -1,206 +1,206 @@
1
- import View from "../../View.js";
2
- import Vector3 from "../../../core/geom/Vector3.js";
3
- import ObservedValue from "../../../core/model/ObservedValue.js";
4
- import { SurfacePoint3 } from "../../../core/geom/3d/SurfacePoint3.js";
5
- import SVG from "../../SVG.js";
6
- import { plane3_compute_ray_intersection } from "../../../core/geom/3d/plane/plane3_compute_ray_intersection.js";
7
-
8
-
9
- const rayContact = new SurfacePoint3();
10
-
11
- export class MinimapCameraView extends View {
12
- /**
13
- * @param {Camera} camera
14
- * @param {Transform} transform
15
- * @param entity
16
- * @param {Rectangle} world
17
- * @param {Vector2} worldScale
18
- * @param {GraphicsEngine|GraphicsEngine3} graphics asked for the ray the frame is traced with
19
- * @constructor
20
- */
21
- constructor({ camera, transform, entity, world, worldScale, graphics }) {
22
- super();
23
-
24
- this.el = SVG.createElement('svg');
25
-
26
- this.addClass('ui-camera-view');
27
-
28
- /**
29
- *
30
- * @type {Element}
31
- * @private
32
- */
33
- this.__el_polygon = SVG.createElement('polygon');
34
-
35
- this.el.appendChild(this.__el_polygon);
36
-
37
- /**
38
- *
39
- * @type {Camera}
40
- */
41
- this.camera = camera;
42
-
43
- /**
44
- * **The frame is traced with the renderer's own ray, not the camera component's.**
45
- * `Camera.projectRay` goes through `camera.object`, a three.js camera that only the legacy
46
- * `CameraSystem` builds — under Shade it is never built, so every update warned and drew
47
- * nothing. `viewportProjectionRay` is the one picking primitive both engines answer with the
48
- * same meaning, and it reports the camera that actually drew.
49
- *
50
- * It therefore traces the view the player has rather than this entity's camera. The two are
51
- * the same wherever the game has one camera, which is everywhere it has a minimap.
52
- *
53
- * @type {GraphicsEngine|GraphicsEngine3}
54
- */
55
- this.graphics = graphics;
56
- /**
57
- *
58
- * @type {Transform}
59
- */
60
- this.transform = transform;
61
-
62
- this.entity = entity;
63
-
64
- /**
65
- *
66
- * @type {Rectangle}
67
- * @private
68
- */
69
- this.__world = world;
70
-
71
- /**
72
- *
73
- * @type {Vector2}
74
- * @private
75
- */
76
- this.__world_scale = worldScale;
77
-
78
- /**
79
- *
80
- * @type {ObservedValue<Terrain>}
81
- */
82
- this.terrain = new ObservedValue(null);
83
-
84
-
85
- this
86
- .bindSignal(this.camera.projectionType.onChanged, this.__update, this)
87
- .bindSignal(this.transform.position.onChanged, this.__update, this)
88
- .bindSignal(worldScale.onChanged, this.__update, this)
89
- .bindSignal(world.position.onChanged, this.__update, this)
90
- .bindSignal(this.transform.rotation.onChanged, this.__update, this);
91
-
92
- }
93
-
94
- /**
95
- *
96
- * @param {Vector3} result
97
- * @param {number} originX
98
- * @param {number} originY
99
- * @param {number} originZ
100
- * @param {number} directionX
101
- * @param {number} directionY
102
- * @param {number} directionZ
103
- */
104
- castTerrainRay(result, originX, originY, originZ, directionX, directionY, directionZ) {
105
- const terrain = this.terrain.getValue();
106
-
107
- const JITTER = 0.00001;
108
-
109
- if (terrain === null) {
110
- plane3_compute_ray_intersection(result, originX, originY, originZ, directionX, directionY, directionZ, 0, 1, 0, 0);
111
- } else {
112
-
113
- let oX = originX;
114
- let oY = originY;
115
- let oZ = originZ;
116
-
117
- let foundHit = false;
118
-
119
- for (let i = 0; i < 10 && !foundHit; i++) {
120
- foundHit = terrain.raycastFirstSync(rayContact, originX, originY, originZ, directionX, directionY, directionZ);
121
-
122
- if (!foundHit) {
123
- //no hit found, try to jitter origin in case of mathematical error at polygon edges
124
- oX += (Math.random() - 0.5) * JITTER;
125
- oY += (Math.random() - 0.5) * JITTER;
126
- oZ += (Math.random() - 0.5) * JITTER;
127
- } else {
128
- result.copy(rayContact.position);
129
- }
130
-
131
- }
132
-
133
- if (!foundHit) {
134
- //no hit found, fall back to planar test
135
- plane3_compute_ray_intersection(result, originX, originY, originZ, directionX, directionY, directionZ, 0, 1, 0, 0);
136
- }
137
-
138
- }
139
-
140
- }
141
-
142
- /**
143
- *
144
- * @param {number} x
145
- * @param {number} y
146
- * @returns {Vector3}
147
- */
148
- getPoint(x, y) {
149
- /**
150
- *
151
- * @type {Rectangle}
152
- */
153
- const world = this.__world;
154
-
155
- /**
156
- *
157
- * @type {Vector2}
158
- */
159
- const worldScale = this.__world_scale;
160
-
161
- const vOrigin = new Vector3(-1, 1, 0.5);
162
- const vDirection = new Vector3(1, -1, 0.5);
163
-
164
- this.graphics.viewportProjectionRay(x, y, vOrigin, vDirection);
165
-
166
- const vResult = new Vector3(0, 0, 0);
167
-
168
- this.castTerrainRay(vResult, vOrigin.x, vOrigin.y, vOrigin.z, vDirection.x, vDirection.y, vDirection.z);
169
-
170
- vResult.x -= world.position.x;
171
- vResult.x *= worldScale.x;
172
-
173
- vResult.z -= world.position.y;
174
- vResult.z *= worldScale.y;
175
-
176
- return vResult;
177
- }
178
-
179
- __update() {
180
- const v_tl = this.getPoint(-1, 1);
181
- const v_tr = this.getPoint(1, 1);
182
- const v_br = this.getPoint(1, -1);
183
- const v_bl = this.getPoint(-1, -1);
184
-
185
-
186
- this.__el_polygon.setAttribute('points', `${v_tl.x},${v_tl.z} ${v_tr.x},${v_tr.z} ${v_br.x},${v_br.z} ${v_bl.x},${v_bl.z}`);
187
- };
188
-
189
-
190
- link() {
191
- super.link();
192
- try {
193
- this.__update();
194
- } catch (e) {
195
- console.error('Failed to execute update', e);
196
- }
197
- }
198
-
199
- unlink() {
200
- super.unlink();
201
-
202
- }
203
- }
204
-
205
-
206
-
1
+ import View from "../../View.js";
2
+ import Vector3 from "../../../core/geom/Vector3.js";
3
+ import ObservedValue from "../../../core/model/ObservedValue.js";
4
+ import { SurfacePoint3 } from "../../../core/geom/3d/SurfacePoint3.js";
5
+ import SVG from "../../SVG.js";
6
+ import { plane3_compute_ray_intersection } from "../../../core/geom/3d/plane/plane3_compute_ray_intersection.js";
7
+
8
+
9
+ const rayContact = new SurfacePoint3();
10
+
11
+ export class MinimapCameraView extends View {
12
+ /**
13
+ * @param {Camera} camera
14
+ * @param {Transform} transform
15
+ * @param entity
16
+ * @param {Rectangle} world
17
+ * @param {Vector2} worldScale
18
+ * @param {GraphicsEngine|GraphicsEngine3} graphics asked for the ray the frame is traced with
19
+ * @constructor
20
+ */
21
+ constructor({ camera, transform, entity, world, worldScale, graphics }) {
22
+ super();
23
+
24
+ this.el = SVG.createElement('svg');
25
+
26
+ this.addClass('ui-camera-view');
27
+
28
+ /**
29
+ *
30
+ * @type {Element}
31
+ * @private
32
+ */
33
+ this.__el_polygon = SVG.createElement('polygon');
34
+
35
+ this.el.appendChild(this.__el_polygon);
36
+
37
+ /**
38
+ *
39
+ * @type {Camera}
40
+ */
41
+ this.camera = camera;
42
+
43
+ /**
44
+ * **The frame is traced with the renderer's own ray, not the camera component's.**
45
+ * `Camera.projectRay` went through a three camera object that only the legacy camera
46
+ * system built — under Shade it was never built, so every update warned and drew
47
+ * nothing. `viewportProjectionRay` is the one picking primitive both engines answer with the
48
+ * same meaning, and it reports the camera that actually drew.
49
+ *
50
+ * It therefore traces the view the player has rather than this entity's camera. The two are
51
+ * the same wherever the game has one camera, which is everywhere it has a minimap.
52
+ *
53
+ * @type {GraphicsEngine|GraphicsEngine3}
54
+ */
55
+ this.graphics = graphics;
56
+ /**
57
+ *
58
+ * @type {Transform}
59
+ */
60
+ this.transform = transform;
61
+
62
+ this.entity = entity;
63
+
64
+ /**
65
+ *
66
+ * @type {Rectangle}
67
+ * @private
68
+ */
69
+ this.__world = world;
70
+
71
+ /**
72
+ *
73
+ * @type {Vector2}
74
+ * @private
75
+ */
76
+ this.__world_scale = worldScale;
77
+
78
+ /**
79
+ *
80
+ * @type {ObservedValue<Terrain>}
81
+ */
82
+ this.terrain = new ObservedValue(null);
83
+
84
+
85
+ this
86
+ .bindSignal(this.camera.projectionType.onChanged, this.__update, this)
87
+ .bindSignal(this.transform.position.onChanged, this.__update, this)
88
+ .bindSignal(worldScale.onChanged, this.__update, this)
89
+ .bindSignal(world.position.onChanged, this.__update, this)
90
+ .bindSignal(this.transform.rotation.onChanged, this.__update, this);
91
+
92
+ }
93
+
94
+ /**
95
+ *
96
+ * @param {Vector3} result
97
+ * @param {number} originX
98
+ * @param {number} originY
99
+ * @param {number} originZ
100
+ * @param {number} directionX
101
+ * @param {number} directionY
102
+ * @param {number} directionZ
103
+ */
104
+ castTerrainRay(result, originX, originY, originZ, directionX, directionY, directionZ) {
105
+ const terrain = this.terrain.getValue();
106
+
107
+ const JITTER = 0.00001;
108
+
109
+ if (terrain === null) {
110
+ plane3_compute_ray_intersection(result, originX, originY, originZ, directionX, directionY, directionZ, 0, 1, 0, 0);
111
+ } else {
112
+
113
+ let oX = originX;
114
+ let oY = originY;
115
+ let oZ = originZ;
116
+
117
+ let foundHit = false;
118
+
119
+ for (let i = 0; i < 10 && !foundHit; i++) {
120
+ foundHit = terrain.raycastFirstSync(rayContact, originX, originY, originZ, directionX, directionY, directionZ);
121
+
122
+ if (!foundHit) {
123
+ //no hit found, try to jitter origin in case of mathematical error at polygon edges
124
+ oX += (Math.random() - 0.5) * JITTER;
125
+ oY += (Math.random() - 0.5) * JITTER;
126
+ oZ += (Math.random() - 0.5) * JITTER;
127
+ } else {
128
+ result.copy(rayContact.position);
129
+ }
130
+
131
+ }
132
+
133
+ if (!foundHit) {
134
+ //no hit found, fall back to planar test
135
+ plane3_compute_ray_intersection(result, originX, originY, originZ, directionX, directionY, directionZ, 0, 1, 0, 0);
136
+ }
137
+
138
+ }
139
+
140
+ }
141
+
142
+ /**
143
+ *
144
+ * @param {number} x
145
+ * @param {number} y
146
+ * @returns {Vector3}
147
+ */
148
+ getPoint(x, y) {
149
+ /**
150
+ *
151
+ * @type {Rectangle}
152
+ */
153
+ const world = this.__world;
154
+
155
+ /**
156
+ *
157
+ * @type {Vector2}
158
+ */
159
+ const worldScale = this.__world_scale;
160
+
161
+ const vOrigin = new Vector3(-1, 1, 0.5);
162
+ const vDirection = new Vector3(1, -1, 0.5);
163
+
164
+ this.graphics.viewportProjectionRay(x, y, vOrigin, vDirection);
165
+
166
+ const vResult = new Vector3(0, 0, 0);
167
+
168
+ this.castTerrainRay(vResult, vOrigin.x, vOrigin.y, vOrigin.z, vDirection.x, vDirection.y, vDirection.z);
169
+
170
+ vResult.x -= world.position.x;
171
+ vResult.x *= worldScale.x;
172
+
173
+ vResult.z -= world.position.y;
174
+ vResult.z *= worldScale.y;
175
+
176
+ return vResult;
177
+ }
178
+
179
+ __update() {
180
+ const v_tl = this.getPoint(-1, 1);
181
+ const v_tr = this.getPoint(1, 1);
182
+ const v_br = this.getPoint(1, -1);
183
+ const v_bl = this.getPoint(-1, -1);
184
+
185
+
186
+ this.__el_polygon.setAttribute('points', `${v_tl.x},${v_tl.z} ${v_tr.x},${v_tr.z} ${v_br.x},${v_br.z} ${v_bl.x},${v_bl.z}`);
187
+ };
188
+
189
+
190
+ link() {
191
+ super.link();
192
+ try {
193
+ this.__update();
194
+ } catch (e) {
195
+ console.error('Failed to execute update', e);
196
+ }
197
+ }
198
+
199
+ unlink() {
200
+ super.unlink();
201
+
202
+ }
203
+ }
204
+
205
+
206
+
@@ -1,74 +0,0 @@
1
- /**
2
- *
3
- * @param {THREE.Camera} object
4
- * @param {Quaternion} rotation
5
- */
6
- export function three_camera_set_transform_rotation(object: THREE.Camera, rotation: Quaternion): void;
7
- export class CameraSystem extends System<any> {
8
- /**
9
- *
10
- * @param {EntityComponentDataset} ecd
11
- * @param {(camera: Camera, entity: number) => void} visitor
12
- */
13
- static traverseActiveCameras(ecd: EntityComponentDataset, visitor: (camera: Camera, entity: number) => void): void;
14
- /**
15
- *
16
- * @param {EntityComponentDataset} ecd
17
- * @returns {{component:(Camera|undefined), entity: number}}
18
- */
19
- static getFirstActiveCamera(ecd: EntityComponentDataset): {
20
- component: (Camera | undefined);
21
- entity: number;
22
- };
23
- /**
24
- *
25
- * @param {EntityComponentDataset} ecd
26
- * @param {function(ThreeFrustum[])} callback
27
- */
28
- static getActiveFrustums(ecd: EntityComponentDataset, callback: (arg0: ThreeFrustum[]) => any): void;
29
- /**
30
- *
31
- * @param {GraphicsEngine} graphics
32
- * @constructor
33
- */
34
- constructor(graphics: GraphicsEngine);
35
- entityData: any[];
36
- scene: any;
37
- dependencies: (typeof Transform | typeof Camera)[];
38
- components_used: ResourceAccessSpecification<typeof Camera>[];
39
- /**
40
- * @type {GraphicsEngine}
41
- */
42
- graphics: GraphicsEngine;
43
- /**
44
- *
45
- * @param {number} x
46
- * @param {number} y
47
- * @private
48
- */
49
- private __handleViewportResize;
50
- signalBindings: any[];
51
- /**
52
- *
53
- * @param {Transform} transform
54
- * @param {Camera} camera
55
- * @param entityId
56
- */
57
- link(camera: Camera, transform: Transform, entityId: any): void;
58
- /**
59
- *
60
- * @param {Transform} transform
61
- * @param {Camera} camera
62
- * @param entityId
63
- */
64
- unlink(camera: Camera, transform: Transform, entityId: any): void;
65
- startup(entityManager: any): Promise<void>;
66
- shutdown(entityManager: any): Promise<void>;
67
- }
68
- import { Camera } from './Camera.js';
69
- import Quaternion from "../../../../core/geom/Quaternion.js";
70
- import { System } from '../../../ecs/System.js';
71
- import { Transform } from '../../../ecs/transform/Transform.js';
72
- import { ResourceAccessSpecification } from "../../../../core/model/ResourceAccessSpecification.js";
73
- import { Frustum as ThreeFrustum } from 'three';
74
- //# sourceMappingURL=CameraSystem.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"CameraSystem.d.ts","sourceRoot":"","sources":["../../../../../../src/engine/graphics/ecs/camera/CameraSystem.js"],"names":[],"mappings":"AAoBA;;;;GAIG;AACH,4DAHW,YAAY,YACZ,UAAU,QAsBpB;AAED;IA+NI;;;;OAIG;IACH,4EAFoB,MAAM,UAAU,MAAM,KAAK,IAAI,QASlD;IAED;;;;OAIG;IACH,0DAFa;QAAC,SAAS,EAAC,CAAC,MAAM,GAAC,SAAS,CAAC,CAAC;QAAC,MAAM,EAAE,MAAM,CAAA;KAAC,CAc1D;IAED;;;;OAIG;IACH,uEAFoB,YAAY,EAAE,gBAqBjC;IA/QD;;;;OAIG;IACH,sCA8CC;IArDD,kBAAgB;IAcZ,WAA2B;IAE3B,mDAAuC;IAEvC,8DAEC;IAED;;OAEG;IACH,yBAAwB;IAIxB;;;;;OAKG;IACH,+BAeC;IAED,sBAAwB;IAI5B;;;;;OAKG;IACH,aAHW,MAAM,aADN,SAAS,uBAyEnB;IAED;;;;;OAKG;IACH,eAHW,MAAM,aADN,SAAS,uBAiBnB;IAED,2CAoDC;IAED,4CAMC;CA4DJ;uBA7TsB,aAAa;uBARb,qCAAqC;uBAGrC,wBAAwB;0BACrB,qCAAqC;4CAFnB,uDAAuD;wCAL1D,OAAO"}