@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,18 +1,19 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
import {
|
|
2
|
+
ParticleEmitter
|
|
3
|
+
} from "../../src/engine/graphics/particles/particular/engine/emitter/ParticleEmitter.js";
|
|
4
|
+
import { ParticleEmitterSystem3 } from "../../src/engine/graphics3/ParticleEmitterSystem3.js";
|
|
4
5
|
|
|
5
6
|
/**
|
|
6
7
|
* Rebuild a live particle emitter after structural edits (layers, sprites, parameter
|
|
7
|
-
* tracks):
|
|
8
|
-
*
|
|
8
|
+
* tracks): the system pulls it out of the particle engine, runs the full build sequence and puts
|
|
9
|
+
* it back. Sleep state is preserved.
|
|
9
10
|
*
|
|
10
11
|
* @param {EntityManager} entityManager
|
|
11
12
|
* @param {number} entity
|
|
12
13
|
* @returns {boolean} false when the entity has no emitter or no emitter system runs
|
|
13
14
|
*/
|
|
14
15
|
export function rebuildParticleEmitter(entityManager, entity) {
|
|
15
|
-
const system = entityManager.getSystem(
|
|
16
|
+
const system = entityManager.getSystem(ParticleEmitterSystem3);
|
|
16
17
|
|
|
17
18
|
if (system === null) {
|
|
18
19
|
return false;
|
|
@@ -24,26 +25,7 @@ export function rebuildParticleEmitter(entityManager, entity) {
|
|
|
24
25
|
return false;
|
|
25
26
|
}
|
|
26
27
|
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
const isSleeping = emitter.getFlag(ParticleEmitterFlag.Sleeping);
|
|
30
|
-
|
|
31
|
-
particleEngine.remove(emitter);
|
|
32
|
-
|
|
33
|
-
if (system.renderLayer.visibleSet.contains(emitter.mesh)) {
|
|
34
|
-
system.renderLayer.visibleSet.forceRemove(emitter.mesh);
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
emitter.clearFlag(ParticleEmitterFlag.Built | ParticleEmitterFlag.Initialized);
|
|
38
|
-
|
|
39
|
-
emitter.registerLayerParameters();
|
|
40
|
-
emitter.build();
|
|
41
|
-
emitter.initialize();
|
|
42
|
-
emitter.computeBoundingBox();
|
|
43
|
-
|
|
44
|
-
particleEngine.add(emitter);
|
|
45
|
-
|
|
46
|
-
emitter.writeFlag(ParticleEmitterFlag.Sleeping, isSleeping);
|
|
28
|
+
system.rebuild(emitter);
|
|
47
29
|
|
|
48
30
|
return true;
|
|
49
31
|
}
|
|
@@ -1,146 +1,146 @@
|
|
|
1
|
-
import { DEG_TO_RAD } from "../../../src/core/math/DEG_TO_RAD.js";
|
|
2
|
-
import { v3_quaternion_apply } from "../../../src/core/geom/vec3/v3_quaternion_apply.js";
|
|
3
|
-
import { Transform } from "../../../src/engine/ecs/transform/Transform.js";
|
|
4
|
-
import { Camera } from "../../../src/engine/graphics/ecs/camera/Camera.js";
|
|
5
|
-
import { Gizmo } from "../../../src/engine/graphics/render/gizmo/Gizmo.js";
|
|
6
|
-
import { entity_is_editor_owned, SymbolicDisplay } from "./SymbolicDisplay.js";
|
|
7
|
-
|
|
8
|
-
/**
|
|
9
|
-
* @type {number[]}
|
|
10
|
-
*/
|
|
11
|
-
const CAMERA_COLOR = [0.4, 0.9, 1, 1];
|
|
12
|
-
|
|
13
|
-
/**
|
|
14
|
-
* Which corners are joined: the near rectangle, the far one, and the four edges between them.
|
|
15
|
-
*
|
|
16
|
-
* @type {number[]}
|
|
17
|
-
*/
|
|
18
|
-
const EDGES = [
|
|
19
|
-
0, 1, 1, 2, 2, 3, 3, 0,
|
|
20
|
-
4, 5, 5, 6, 6, 7, 7, 4,
|
|
21
|
-
0, 4, 1, 5, 2, 6, 3, 7
|
|
22
|
-
];
|
|
23
|
-
|
|
24
|
-
/**
|
|
25
|
-
* Eight frustum corners in world space, near plane first.
|
|
26
|
-
*
|
|
27
|
-
* @type {Float32Array}
|
|
28
|
-
*/
|
|
29
|
-
const corners = new Float32Array(24);
|
|
30
|
-
|
|
31
|
-
/**
|
|
32
|
-
* @type {Float32Array}
|
|
33
|
-
*/
|
|
34
|
-
const from = new Float32Array(3);
|
|
35
|
-
|
|
36
|
-
/**
|
|
37
|
-
* @type {Float32Array}
|
|
38
|
-
*/
|
|
39
|
-
const to = new Float32Array(3);
|
|
40
|
-
|
|
41
|
-
/**
|
|
42
|
-
* The two depths the corners are taken at, near then far.
|
|
43
|
-
*
|
|
44
|
-
* @type {Float64Array}
|
|
45
|
-
*/
|
|
46
|
-
const depths = new Float64Array(2);
|
|
47
|
-
|
|
48
|
-
/**
|
|
49
|
-
* The volume a camera entity can see.
|
|
50
|
-
*
|
|
51
|
-
* **Built from the component rather than from a renderer's camera object.**
|
|
52
|
-
*
|
|
53
|
-
*
|
|
54
|
-
*
|
|
55
|
-
* The one thing that is not is the aspect ratio, which belongs to the frame rather than to the
|
|
56
|
-
* camera: it is the viewport's, exactly as the renderer's own is.
|
|
57
|
-
*
|
|
58
|
-
* **Perspective always, because that is what gets drawn.** `Camera.projectionType` carries an
|
|
59
|
-
* orthographic option and no renderer in the program reads it — `CameraSystem3` copies the field of
|
|
60
|
-
* view and the clip planes and nothing else — so a symbol that branched on it would be drawing a
|
|
61
|
-
* projection the game cannot render.
|
|
62
|
-
*
|
|
63
|
-
* The transform's scale is deliberately not applied. A camera has no size, and a scaled entity
|
|
64
|
-
* carrying one still sees exactly as far as its clip planes say.
|
|
65
|
-
*
|
|
66
|
-
* @see SymbolicDisplay
|
|
67
|
-
*/
|
|
68
|
-
export class CameraSymbolicDisplay extends SymbolicDisplay {
|
|
69
|
-
/**
|
|
70
|
-
* Record a frustum per camera entity.
|
|
71
|
-
*
|
|
72
|
-
* The engine's viewport is expected to have a size: `preRender` is dispatched from inside a
|
|
73
|
-
* frame, and a frame is not drawn into a collapsed viewport at all.
|
|
74
|
-
*
|
|
75
|
-
* @param {EntityComponentDataset} dataset
|
|
76
|
-
*/
|
|
77
|
-
record(dataset) {
|
|
78
|
-
const viewport = this.engine.graphics.viewport.size;
|
|
79
|
-
const aspect = viewport.x / viewport.y;
|
|
80
|
-
|
|
81
|
-
Gizmo.color = CAMERA_COLOR;
|
|
82
|
-
|
|
83
|
-
dataset.traverseEntities([Camera, Transform], (camera, transform, entity) => {
|
|
84
|
-
if (entity_is_editor_owned(dataset, entity)) {
|
|
85
|
-
return;
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
this.#write_corners(camera, transform, aspect);
|
|
89
|
-
|
|
90
|
-
for (let i = 0; i < 12; i++) {
|
|
91
|
-
const a = EDGES[i * 2] * 3;
|
|
92
|
-
const b = EDGES[i * 2 + 1] * 3;
|
|
93
|
-
|
|
94
|
-
from[0] = corners[a];
|
|
95
|
-
from[1] = corners[a + 1];
|
|
96
|
-
from[2] = corners[a + 2];
|
|
97
|
-
|
|
98
|
-
to[0] = corners[b];
|
|
99
|
-
to[1] = corners[b + 1];
|
|
100
|
-
to[2] = corners[b + 2];
|
|
101
|
-
|
|
102
|
-
Gizmo.draw_line(from, to);
|
|
103
|
-
}
|
|
104
|
-
});
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
/**
|
|
108
|
-
* @param {Camera} camera
|
|
109
|
-
* @param {Transform} transform
|
|
110
|
-
* @param {number} aspect
|
|
111
|
-
*/
|
|
112
|
-
#write_corners(camera, transform, aspect) {
|
|
113
|
-
const tangent = Math.tan(camera.fov.getValue() * DEG_TO_RAD / 2);
|
|
114
|
-
|
|
115
|
-
const rotation = transform.rotation;
|
|
116
|
-
const position = transform.position;
|
|
117
|
-
|
|
118
|
-
// near plane first, then far, each anticlockwise from the top right as the camera sees it
|
|
119
|
-
depths[0] = camera.clip_near;
|
|
120
|
-
depths[1] = camera.clip_far;
|
|
121
|
-
|
|
122
|
-
for (let plane = 0; plane < 2; plane++) {
|
|
123
|
-
const depth = depths[plane];
|
|
124
|
-
|
|
125
|
-
const half_height = depth * tangent;
|
|
126
|
-
const half_width = half_height * aspect;
|
|
127
|
-
|
|
128
|
-
for (let corner = 0; corner < 4; corner++) {
|
|
129
|
-
const x = (corner === 0 || corner === 3) ? half_width : -half_width;
|
|
130
|
-
const y = (corner === 0 || corner === 1) ? half_height : -half_height;
|
|
131
|
-
|
|
132
|
-
const address = (plane * 4 + corner) * 3;
|
|
133
|
-
|
|
134
|
-
v3_quaternion_apply(
|
|
135
|
-
corners, address,
|
|
136
|
-
x, y, depth,
|
|
137
|
-
rotation.x, rotation.y, rotation.z, rotation.w
|
|
138
|
-
);
|
|
139
|
-
|
|
140
|
-
corners[address] += position.x;
|
|
141
|
-
corners[address + 1] += position.y;
|
|
142
|
-
corners[address + 2] += position.z;
|
|
143
|
-
}
|
|
144
|
-
}
|
|
145
|
-
}
|
|
146
|
-
}
|
|
1
|
+
import { DEG_TO_RAD } from "../../../src/core/math/DEG_TO_RAD.js";
|
|
2
|
+
import { v3_quaternion_apply } from "../../../src/core/geom/vec3/v3_quaternion_apply.js";
|
|
3
|
+
import { Transform } from "../../../src/engine/ecs/transform/Transform.js";
|
|
4
|
+
import { Camera } from "../../../src/engine/graphics/ecs/camera/Camera.js";
|
|
5
|
+
import { Gizmo } from "../../../src/engine/graphics/render/gizmo/Gizmo.js";
|
|
6
|
+
import { entity_is_editor_owned, SymbolicDisplay } from "./SymbolicDisplay.js";
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* @type {number[]}
|
|
10
|
+
*/
|
|
11
|
+
const CAMERA_COLOR = [0.4, 0.9, 1, 1];
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Which corners are joined: the near rectangle, the far one, and the four edges between them.
|
|
15
|
+
*
|
|
16
|
+
* @type {number[]}
|
|
17
|
+
*/
|
|
18
|
+
const EDGES = [
|
|
19
|
+
0, 1, 1, 2, 2, 3, 3, 0,
|
|
20
|
+
4, 5, 5, 6, 6, 7, 7, 4,
|
|
21
|
+
0, 4, 1, 5, 2, 6, 3, 7
|
|
22
|
+
];
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Eight frustum corners in world space, near plane first.
|
|
26
|
+
*
|
|
27
|
+
* @type {Float32Array}
|
|
28
|
+
*/
|
|
29
|
+
const corners = new Float32Array(24);
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* @type {Float32Array}
|
|
33
|
+
*/
|
|
34
|
+
const from = new Float32Array(3);
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* @type {Float32Array}
|
|
38
|
+
*/
|
|
39
|
+
const to = new Float32Array(3);
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* The two depths the corners are taken at, near then far.
|
|
43
|
+
*
|
|
44
|
+
* @type {Float64Array}
|
|
45
|
+
*/
|
|
46
|
+
const depths = new Float64Array(2);
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* The volume a camera entity can see.
|
|
50
|
+
*
|
|
51
|
+
* **Built from the component rather than from a renderer's camera object.** A camera entity has no
|
|
52
|
+
* renderer object of its own, which is why the three `CameraHelper` this replaces could not survive
|
|
53
|
+
* the port; everything the frustum needs — field of view, the two clip planes — is on the component,
|
|
54
|
+
* and where the camera is and which way it faces is its `Transform`.
|
|
55
|
+
* The one thing that is not is the aspect ratio, which belongs to the frame rather than to the
|
|
56
|
+
* camera: it is the viewport's, exactly as the renderer's own is.
|
|
57
|
+
*
|
|
58
|
+
* **Perspective always, because that is what gets drawn.** `Camera.projectionType` carries an
|
|
59
|
+
* orthographic option and no renderer in the program reads it — `CameraSystem3` copies the field of
|
|
60
|
+
* view and the clip planes and nothing else — so a symbol that branched on it would be drawing a
|
|
61
|
+
* projection the game cannot render.
|
|
62
|
+
*
|
|
63
|
+
* The transform's scale is deliberately not applied. A camera has no size, and a scaled entity
|
|
64
|
+
* carrying one still sees exactly as far as its clip planes say.
|
|
65
|
+
*
|
|
66
|
+
* @see SymbolicDisplay
|
|
67
|
+
*/
|
|
68
|
+
export class CameraSymbolicDisplay extends SymbolicDisplay {
|
|
69
|
+
/**
|
|
70
|
+
* Record a frustum per camera entity.
|
|
71
|
+
*
|
|
72
|
+
* The engine's viewport is expected to have a size: `preRender` is dispatched from inside a
|
|
73
|
+
* frame, and a frame is not drawn into a collapsed viewport at all.
|
|
74
|
+
*
|
|
75
|
+
* @param {EntityComponentDataset} dataset
|
|
76
|
+
*/
|
|
77
|
+
record(dataset) {
|
|
78
|
+
const viewport = this.engine.graphics.viewport.size;
|
|
79
|
+
const aspect = viewport.x / viewport.y;
|
|
80
|
+
|
|
81
|
+
Gizmo.color = CAMERA_COLOR;
|
|
82
|
+
|
|
83
|
+
dataset.traverseEntities([Camera, Transform], (camera, transform, entity) => {
|
|
84
|
+
if (entity_is_editor_owned(dataset, entity)) {
|
|
85
|
+
return;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
this.#write_corners(camera, transform, aspect);
|
|
89
|
+
|
|
90
|
+
for (let i = 0; i < 12; i++) {
|
|
91
|
+
const a = EDGES[i * 2] * 3;
|
|
92
|
+
const b = EDGES[i * 2 + 1] * 3;
|
|
93
|
+
|
|
94
|
+
from[0] = corners[a];
|
|
95
|
+
from[1] = corners[a + 1];
|
|
96
|
+
from[2] = corners[a + 2];
|
|
97
|
+
|
|
98
|
+
to[0] = corners[b];
|
|
99
|
+
to[1] = corners[b + 1];
|
|
100
|
+
to[2] = corners[b + 2];
|
|
101
|
+
|
|
102
|
+
Gizmo.draw_line(from, to);
|
|
103
|
+
}
|
|
104
|
+
});
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
/**
|
|
108
|
+
* @param {Camera} camera
|
|
109
|
+
* @param {Transform} transform
|
|
110
|
+
* @param {number} aspect
|
|
111
|
+
*/
|
|
112
|
+
#write_corners(camera, transform, aspect) {
|
|
113
|
+
const tangent = Math.tan(camera.fov.getValue() * DEG_TO_RAD / 2);
|
|
114
|
+
|
|
115
|
+
const rotation = transform.rotation;
|
|
116
|
+
const position = transform.position;
|
|
117
|
+
|
|
118
|
+
// near plane first, then far, each anticlockwise from the top right as the camera sees it
|
|
119
|
+
depths[0] = camera.clip_near;
|
|
120
|
+
depths[1] = camera.clip_far;
|
|
121
|
+
|
|
122
|
+
for (let plane = 0; plane < 2; plane++) {
|
|
123
|
+
const depth = depths[plane];
|
|
124
|
+
|
|
125
|
+
const half_height = depth * tangent;
|
|
126
|
+
const half_width = half_height * aspect;
|
|
127
|
+
|
|
128
|
+
for (let corner = 0; corner < 4; corner++) {
|
|
129
|
+
const x = (corner === 0 || corner === 3) ? half_width : -half_width;
|
|
130
|
+
const y = (corner === 0 || corner === 1) ? half_height : -half_height;
|
|
131
|
+
|
|
132
|
+
const address = (plane * 4 + corner) * 3;
|
|
133
|
+
|
|
134
|
+
v3_quaternion_apply(
|
|
135
|
+
corners, address,
|
|
136
|
+
x, y, depth,
|
|
137
|
+
rotation.x, rotation.y, rotation.z, rotation.w
|
|
138
|
+
);
|
|
139
|
+
|
|
140
|
+
corners[address] += position.x;
|
|
141
|
+
corners[address + 1] += position.y;
|
|
142
|
+
corners[address + 2] += position.z;
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
}
|
|
@@ -108,8 +108,7 @@ class SelectionTool extends Tool {
|
|
|
108
108
|
/*
|
|
109
109
|
The active camera's own clip range, off the **component**. What a selection needs from a
|
|
110
110
|
camera is how far it can see — the projection itself comes from the facade, which is the
|
|
111
|
-
only thing that knows it
|
|
112
|
-
under Shade.
|
|
111
|
+
only thing that knows it.
|
|
113
112
|
*/
|
|
114
113
|
let near = 0.1;
|
|
115
114
|
let far = 1000;
|
|
@@ -246,9 +246,8 @@ export class TransformToolV2 extends Tool {
|
|
|
246
246
|
}
|
|
247
247
|
|
|
248
248
|
/**
|
|
249
|
-
* The gizmo asks the graphics engine for rays and nothing else, so this needs no camera
|
|
250
|
-
* own
|
|
251
|
-
* Shade.
|
|
249
|
+
* The gizmo asks the graphics engine for rays and nothing else, so this needs no camera object
|
|
250
|
+
* of its own, which is what the three version wanted.
|
|
252
251
|
*/
|
|
253
252
|
initialize() {
|
|
254
253
|
super.initialize();
|