@zephyr3d/scene 0.1.0
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/dist/animation/animation.js +173 -0
- package/dist/animation/animation.js.map +1 -0
- package/dist/animation/animationset.js +95 -0
- package/dist/animation/animationset.js.map +1 -0
- package/dist/animation/animationtrack.js +38 -0
- package/dist/animation/animationtrack.js.map +1 -0
- package/dist/animation/eulerrotationtrack.js +33 -0
- package/dist/animation/eulerrotationtrack.js.map +1 -0
- package/dist/animation/rotationtrack.js +37 -0
- package/dist/animation/rotationtrack.js.map +1 -0
- package/dist/animation/scaletrack.js +36 -0
- package/dist/animation/scaletrack.js.map +1 -0
- package/dist/animation/skeleton.js +97 -0
- package/dist/animation/skeleton.js.map +1 -0
- package/dist/animation/translationtrack.js +36 -0
- package/dist/animation/translationtrack.js.map +1 -0
- package/dist/animation/usertrack.js +47 -0
- package/dist/animation/usertrack.js.map +1 -0
- package/dist/app.js +173 -0
- package/dist/app.js.map +1 -0
- package/dist/asset/assetmanager.js +476 -0
- package/dist/asset/assetmanager.js.map +1 -0
- package/dist/asset/builtin.js +373 -0
- package/dist/asset/builtin.js.map +1 -0
- package/dist/asset/loaders/dds/dds.js +472 -0
- package/dist/asset/loaders/dds/dds.js.map +1 -0
- package/dist/asset/loaders/dds/dds_loader.js +38 -0
- package/dist/asset/loaders/dds/dds_loader.js.map +1 -0
- package/dist/asset/loaders/gltf/gltf_loader.js +981 -0
- package/dist/asset/loaders/gltf/gltf_loader.js.map +1 -0
- package/dist/asset/loaders/gltf/helpers.js +314 -0
- package/dist/asset/loaders/gltf/helpers.js.map +1 -0
- package/dist/asset/loaders/hdr/hdr.js +175 -0
- package/dist/asset/loaders/hdr/hdr.js.map +1 -0
- package/dist/asset/loaders/image/tga_Loader.js +117 -0
- package/dist/asset/loaders/image/tga_Loader.js.map +1 -0
- package/dist/asset/loaders/image/webimage_loader.js +50 -0
- package/dist/asset/loaders/image/webimage_loader.js.map +1 -0
- package/dist/asset/loaders/loader.js +45 -0
- package/dist/asset/loaders/loader.js.map +1 -0
- package/dist/asset/model.js +264 -0
- package/dist/asset/model.js.map +1 -0
- package/dist/blitter/blitter.js +389 -0
- package/dist/blitter/blitter.js.map +1 -0
- package/dist/blitter/box.js +118 -0
- package/dist/blitter/box.js.map +1 -0
- package/dist/blitter/copy.js +22 -0
- package/dist/blitter/copy.js.map +1 -0
- package/dist/blitter/depthlimitedgaussion.js +166 -0
- package/dist/blitter/depthlimitedgaussion.js.map +1 -0
- package/dist/blitter/gaussianblur.js +229 -0
- package/dist/blitter/gaussianblur.js.map +1 -0
- package/dist/camera/base.js +90 -0
- package/dist/camera/base.js.map +1 -0
- package/dist/camera/camera.js +358 -0
- package/dist/camera/camera.js.map +1 -0
- package/dist/camera/fps.js +246 -0
- package/dist/camera/fps.js.map +1 -0
- package/dist/camera/orbit.js +157 -0
- package/dist/camera/orbit.js.map +1 -0
- package/dist/camera/orthocamera.js +126 -0
- package/dist/camera/orthocamera.js.map +1 -0
- package/dist/camera/perspectivecamera.js +133 -0
- package/dist/camera/perspectivecamera.js.map +1 -0
- package/dist/index.d.ts +8402 -0
- package/dist/index.js +87 -0
- package/dist/index.js.map +1 -0
- package/dist/input/inputmgr.js +242 -0
- package/dist/input/inputmgr.js.map +1 -0
- package/dist/material/blinn.js +75 -0
- package/dist/material/blinn.js.map +1 -0
- package/dist/material/grassmaterial.js +221 -0
- package/dist/material/grassmaterial.js.map +1 -0
- package/dist/material/lambert.js +52 -0
- package/dist/material/lambert.js.map +1 -0
- package/dist/material/lightmodel.js +2074 -0
- package/dist/material/lightmodel.js.map +1 -0
- package/dist/material/lit.js +578 -0
- package/dist/material/lit.js.map +1 -0
- package/dist/material/material.js +458 -0
- package/dist/material/material.js.map +1 -0
- package/dist/material/meshmaterial.js +311 -0
- package/dist/material/meshmaterial.js.map +1 -0
- package/dist/material/mixins/albedocolor.js +130 -0
- package/dist/material/mixins/albedocolor.js.map +1 -0
- package/dist/material/mixins/texture.js +110 -0
- package/dist/material/mixins/texture.js.map +1 -0
- package/dist/material/mixins/vertexcolor.js +45 -0
- package/dist/material/mixins/vertexcolor.js.map +1 -0
- package/dist/material/pbr.js +27 -0
- package/dist/material/pbr.js.map +1 -0
- package/dist/material/standard.js +282 -0
- package/dist/material/standard.js.map +1 -0
- package/dist/material/terrainlightmodel.js +259 -0
- package/dist/material/terrainlightmodel.js.map +1 -0
- package/dist/material/terrainmaterial.js +139 -0
- package/dist/material/terrainmaterial.js.map +1 -0
- package/dist/material/unlit.js +29 -0
- package/dist/material/unlit.js.map +1 -0
- package/dist/posteffect/bloom.js +398 -0
- package/dist/posteffect/bloom.js.map +1 -0
- package/dist/posteffect/compositor.js +264 -0
- package/dist/posteffect/compositor.js.map +1 -0
- package/dist/posteffect/fxaa.js +291 -0
- package/dist/posteffect/fxaa.js.map +1 -0
- package/dist/posteffect/grayscale.js +87 -0
- package/dist/posteffect/grayscale.js.map +1 -0
- package/dist/posteffect/posteffect.js +165 -0
- package/dist/posteffect/posteffect.js.map +1 -0
- package/dist/posteffect/sao.js +327 -0
- package/dist/posteffect/sao.js.map +1 -0
- package/dist/posteffect/tonemap.js +112 -0
- package/dist/posteffect/tonemap.js.map +1 -0
- package/dist/posteffect/water.js +535 -0
- package/dist/posteffect/water.js.map +1 -0
- package/dist/render/clipmap.js +462 -0
- package/dist/render/clipmap.js.map +1 -0
- package/dist/render/cluster_light.js +329 -0
- package/dist/render/cluster_light.js.map +1 -0
- package/dist/render/cull_visitor.js +124 -0
- package/dist/render/cull_visitor.js.map +1 -0
- package/dist/render/depth_pass.js +47 -0
- package/dist/render/depth_pass.js.map +1 -0
- package/dist/render/envlight.js +282 -0
- package/dist/render/envlight.js.map +1 -0
- package/dist/render/forward.js +186 -0
- package/dist/render/forward.js.map +1 -0
- package/dist/render/forward_pass.js +137 -0
- package/dist/render/forward_pass.js.map +1 -0
- package/dist/render/helper.js +38 -0
- package/dist/render/helper.js.map +1 -0
- package/dist/render/primitive.js +246 -0
- package/dist/render/primitive.js.map +1 -0
- package/dist/render/render_queue.js +163 -0
- package/dist/render/render_queue.js.map +1 -0
- package/dist/render/renderpass.js +151 -0
- package/dist/render/renderpass.js.map +1 -0
- package/dist/render/renderscheme.js +61 -0
- package/dist/render/renderscheme.js.map +1 -0
- package/dist/render/scatteringlut.js +634 -0
- package/dist/render/scatteringlut.js.map +1 -0
- package/dist/render/shadowmap_pass.js +70 -0
- package/dist/render/shadowmap_pass.js.map +1 -0
- package/dist/render/sky.js +881 -0
- package/dist/render/sky.js.map +1 -0
- package/dist/render/temporalcache.js +222 -0
- package/dist/render/temporalcache.js.map +1 -0
- package/dist/render/watermesh.js +835 -0
- package/dist/render/watermesh.js.map +1 -0
- package/dist/scene/environment.js +146 -0
- package/dist/scene/environment.js.map +1 -0
- package/dist/scene/graph_node.js +69 -0
- package/dist/scene/graph_node.js.map +1 -0
- package/dist/scene/light.js +436 -0
- package/dist/scene/light.js.map +1 -0
- package/dist/scene/mesh.js +215 -0
- package/dist/scene/mesh.js.map +1 -0
- package/dist/scene/model.js +111 -0
- package/dist/scene/model.js.map +1 -0
- package/dist/scene/octree.js +651 -0
- package/dist/scene/octree.js.map +1 -0
- package/dist/scene/octree_update_visitor.js +16 -0
- package/dist/scene/octree_update_visitor.js.map +1 -0
- package/dist/scene/raycast_visitor.js +72 -0
- package/dist/scene/raycast_visitor.js.map +1 -0
- package/dist/scene/scene.js +225 -0
- package/dist/scene/scene.js.map +1 -0
- package/dist/scene/scene_node.js +299 -0
- package/dist/scene/scene_node.js.map +1 -0
- package/dist/scene/terrain/grass.js +277 -0
- package/dist/scene/terrain/grass.js.map +1 -0
- package/dist/scene/terrain/heightfield.js +391 -0
- package/dist/scene/terrain/heightfield.js.map +1 -0
- package/dist/scene/terrain/patch.js +530 -0
- package/dist/scene/terrain/patch.js.map +1 -0
- package/dist/scene/terrain/quadtree.js +430 -0
- package/dist/scene/terrain/quadtree.js.map +1 -0
- package/dist/scene/terrain/terrain.js +258 -0
- package/dist/scene/terrain/terrain.js.map +1 -0
- package/dist/scene/xform.js +224 -0
- package/dist/scene/xform.js.map +1 -0
- package/dist/shaders/builtins.js +110 -0
- package/dist/shaders/builtins.js.map +1 -0
- package/dist/shaders/framework.js +709 -0
- package/dist/shaders/framework.js.map +1 -0
- package/dist/shaders/lighting.js +335 -0
- package/dist/shaders/lighting.js.map +1 -0
- package/dist/shaders/misc.js +405 -0
- package/dist/shaders/misc.js.map +1 -0
- package/dist/shaders/noise.js +157 -0
- package/dist/shaders/noise.js.map +1 -0
- package/dist/shaders/pbr.js +132 -0
- package/dist/shaders/pbr.js.map +1 -0
- package/dist/shaders/shadow.js +642 -0
- package/dist/shaders/shadow.js.map +1 -0
- package/dist/shaders/water.js +630 -0
- package/dist/shaders/water.js.map +1 -0
- package/dist/shadow/esm.js +235 -0
- package/dist/shadow/esm.js.map +1 -0
- package/dist/shadow/pcf_opt.js +182 -0
- package/dist/shadow/pcf_opt.js.map +1 -0
- package/dist/shadow/pcf_pd.js +190 -0
- package/dist/shadow/pcf_pd.js.map +1 -0
- package/dist/shadow/shadow_impl.js +15 -0
- package/dist/shadow/shadow_impl.js.map +1 -0
- package/dist/shadow/shadowmapper.js +709 -0
- package/dist/shadow/shadowmapper.js.map +1 -0
- package/dist/shadow/ssm.js +194 -0
- package/dist/shadow/ssm.js.map +1 -0
- package/dist/shadow/vsm.js +298 -0
- package/dist/shadow/vsm.js.map +1 -0
- package/dist/shapes/box.js +313 -0
- package/dist/shapes/box.js.map +1 -0
- package/dist/shapes/cylinder.js +74 -0
- package/dist/shapes/cylinder.js.map +1 -0
- package/dist/shapes/plane.js +48 -0
- package/dist/shapes/plane.js.map +1 -0
- package/dist/shapes/shape.js +33 -0
- package/dist/shapes/shape.js.map +1 -0
- package/dist/shapes/sphere.js +91 -0
- package/dist/shapes/sphere.js.map +1 -0
- package/dist/shapes/torus.js +100 -0
- package/dist/shapes/torus.js.map +1 -0
- package/dist/utility/aabbtree.js +390 -0
- package/dist/utility/aabbtree.js.map +1 -0
- package/dist/utility/bounding_volume.js +78 -0
- package/dist/utility/bounding_volume.js.map +1 -0
- package/dist/utility/panorama.js +163 -0
- package/dist/utility/panorama.js.map +1 -0
- package/dist/utility/pmrem.js +345 -0
- package/dist/utility/pmrem.js.map +1 -0
- package/dist/utility/shprojection.js +448 -0
- package/dist/utility/shprojection.js.map +1 -0
- package/dist/values.js +48 -0
- package/dist/values.js.map +1 -0
- package/package.json +70 -0
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
import { Vector3, Quaternion } from '@zephyr3d/base';
|
|
2
|
+
import { BaseCameraController } from './base.js';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Orbit camera controller
|
|
6
|
+
* @public
|
|
7
|
+
*/ class OrbitCameraController extends BaseCameraController {
|
|
8
|
+
/** @internal */ options;
|
|
9
|
+
/** @internal */ mouseDown;
|
|
10
|
+
/** @internal */ lastMouseX;
|
|
11
|
+
/** @internal */ lastMouseY;
|
|
12
|
+
/** @internal */ rotateX;
|
|
13
|
+
/** @internal */ rotateY;
|
|
14
|
+
/** @internal */ eyePos;
|
|
15
|
+
/** @internal */ upVector;
|
|
16
|
+
/** @internal */ xVector;
|
|
17
|
+
/** @internal */ target;
|
|
18
|
+
/** @internal */ direction;
|
|
19
|
+
/** @internal */ quat;
|
|
20
|
+
/** @internal */ scale;
|
|
21
|
+
/**
|
|
22
|
+
* Creates an instance of OrbitCameraController
|
|
23
|
+
* @param options - The creation options
|
|
24
|
+
*/ constructor(options){
|
|
25
|
+
super();
|
|
26
|
+
this.options = Object.assign({
|
|
27
|
+
distance: 1,
|
|
28
|
+
damping: 0.1,
|
|
29
|
+
moveSpeed: 0.2,
|
|
30
|
+
rotateSpeed: 0.01,
|
|
31
|
+
zoomSpeed: 1
|
|
32
|
+
}, options || {});
|
|
33
|
+
this.rotateX = 0;
|
|
34
|
+
this.rotateY = 0;
|
|
35
|
+
this.eyePos = new Vector3();
|
|
36
|
+
this.upVector = Vector3.axisPY();
|
|
37
|
+
this.xVector = new Vector3();
|
|
38
|
+
this.target = new Vector3();
|
|
39
|
+
this.direction = new Vector3();
|
|
40
|
+
this.quat = new Quaternion();
|
|
41
|
+
this.scale = 1;
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* {@inheritDoc BaseCameraController.reset}
|
|
45
|
+
* @override
|
|
46
|
+
*/ reset() {
|
|
47
|
+
this.mouseDown = false;
|
|
48
|
+
this.lastMouseX = 0;
|
|
49
|
+
this.lastMouseY = 0;
|
|
50
|
+
this.rotateX = 0;
|
|
51
|
+
this.rotateY = 0;
|
|
52
|
+
this.scale = 1;
|
|
53
|
+
this._loadCameraParams();
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* {@inheritDoc BaseCameraController._onMouseDown}
|
|
57
|
+
* @override
|
|
58
|
+
*/ _onMouseDown(evt) {
|
|
59
|
+
if (evt.button === 0) {
|
|
60
|
+
this.mouseDown = true;
|
|
61
|
+
this.lastMouseX = evt.offsetX;
|
|
62
|
+
this.lastMouseY = evt.offsetY;
|
|
63
|
+
this.rotateX = 0;
|
|
64
|
+
this.rotateY = 0;
|
|
65
|
+
return true;
|
|
66
|
+
}
|
|
67
|
+
return false;
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* {@inheritDoc BaseCameraController._onMouseUp}
|
|
71
|
+
* @override
|
|
72
|
+
*/ _onMouseUp(evt) {
|
|
73
|
+
if (evt.button === 0 && this.mouseDown) {
|
|
74
|
+
this.mouseDown = false;
|
|
75
|
+
return true;
|
|
76
|
+
}
|
|
77
|
+
return false;
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* {@inheritDoc BaseCameraController._onMouseWheel}
|
|
81
|
+
* @override
|
|
82
|
+
*/ _onMouseWheel(evt) {
|
|
83
|
+
console.log(`wheel deltaX: ${evt.deltaX}`);
|
|
84
|
+
console.log(`wheel deltaY: ${evt.deltaY}`);
|
|
85
|
+
const factor = Math.pow(0.9, Math.abs(this.options.zoomSpeed));
|
|
86
|
+
if (evt.deltaY > 0) {
|
|
87
|
+
this.scale /= factor;
|
|
88
|
+
} else {
|
|
89
|
+
this.scale *= factor;
|
|
90
|
+
}
|
|
91
|
+
return true;
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* {@inheritDoc BaseCameraController._onMouseMove}
|
|
95
|
+
* @override
|
|
96
|
+
*/ _onMouseMove(evt) {
|
|
97
|
+
if (this.mouseDown) {
|
|
98
|
+
const dx = evt.offsetX - this.lastMouseX;
|
|
99
|
+
const dy = evt.offsetY - this.lastMouseY;
|
|
100
|
+
this.lastMouseX = evt.offsetX;
|
|
101
|
+
this.lastMouseY = evt.offsetY;
|
|
102
|
+
this.rotateX -= dy * this.options.rotateSpeed;
|
|
103
|
+
this.rotateY -= dx * this.options.rotateSpeed;
|
|
104
|
+
return true;
|
|
105
|
+
}
|
|
106
|
+
return false;
|
|
107
|
+
}
|
|
108
|
+
/** @internal */ _loadCameraParams() {
|
|
109
|
+
if (this._getCamera()) {
|
|
110
|
+
const mat = this._getCamera().worldMatrix;
|
|
111
|
+
mat.decomposeLookAt(this.eyePos, this.target);
|
|
112
|
+
Vector3.normalize(Vector3.sub(this.eyePos, this.target), this.direction);
|
|
113
|
+
Vector3.sub(this.eyePos, Vector3.scale(this.direction, this.options.distance), this.target);
|
|
114
|
+
this.xVector.setXYZ(mat[0], mat[1], mat[2]);
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
/**
|
|
118
|
+
* Set options
|
|
119
|
+
* @param opt - options
|
|
120
|
+
*/ setOptions(opt) {
|
|
121
|
+
opt && Object.assign(this.options, opt);
|
|
122
|
+
this.reset();
|
|
123
|
+
}
|
|
124
|
+
/**
|
|
125
|
+
* {@inheritDoc BaseCameraController.update}
|
|
126
|
+
* @override
|
|
127
|
+
*/ update() {
|
|
128
|
+
if (this._getCamera()) {
|
|
129
|
+
Quaternion.fromAxisAngle(this.xVector, this.rotateX, this.quat);
|
|
130
|
+
this.quat.transform(this.eyePos.subBy(this.target), this.eyePos);
|
|
131
|
+
Quaternion.fromEulerAngle(0, this.rotateY, 0, 'XYZ', this.quat);
|
|
132
|
+
this.quat.transform(this.eyePos, this.eyePos);
|
|
133
|
+
this.quat.transform(this.xVector, this.xVector).inplaceNormalize();
|
|
134
|
+
Vector3.normalize(this.eyePos, this.direction).inplaceNormalize();
|
|
135
|
+
Vector3.cross(this.direction, this.xVector, this.upVector).inplaceNormalize();
|
|
136
|
+
Vector3.add(this.target, Vector3.scale(this.direction, this.options.distance * this.scale), this.eyePos);
|
|
137
|
+
this._getCamera().lookAt(this.eyePos, this.target, this.upVector);
|
|
138
|
+
// this._loadCameraParams();
|
|
139
|
+
if (this.mouseDown) {
|
|
140
|
+
this.rotateX = 0;
|
|
141
|
+
this.rotateY = 0;
|
|
142
|
+
} else {
|
|
143
|
+
this.rotateX *= 1 - this.options.damping;
|
|
144
|
+
this.rotateY *= 1 - this.options.damping;
|
|
145
|
+
if (Math.abs(this.rotateX) < 0.0001) {
|
|
146
|
+
this.rotateX = 0;
|
|
147
|
+
}
|
|
148
|
+
if (Math.abs(this.rotateY) < 0.0001) {
|
|
149
|
+
this.rotateY = 0;
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
export { OrbitCameraController };
|
|
157
|
+
//# sourceMappingURL=orbit.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"orbit.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
import { Camera } from './camera.js';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Orthogonal camera class
|
|
5
|
+
* @public
|
|
6
|
+
*/ class OrthoCamera extends Camera {
|
|
7
|
+
/** @internal */ _left;
|
|
8
|
+
_right;
|
|
9
|
+
_top;
|
|
10
|
+
_bottom;
|
|
11
|
+
_near;
|
|
12
|
+
_far;
|
|
13
|
+
/**
|
|
14
|
+
* Creates an instance of PerspectiveCamera
|
|
15
|
+
* @param scene - The scene that the camera belongs to.
|
|
16
|
+
* @param fovY - A radian value indicates the field of view in Y axis
|
|
17
|
+
* @param aspect - Aspect ratio of the perspective transform
|
|
18
|
+
* @param nearPlane - The near clip plane
|
|
19
|
+
* @param farPlane - The far clip plane
|
|
20
|
+
*/ constructor(scene, left, right, bottom, top, near, far){
|
|
21
|
+
super(scene);
|
|
22
|
+
this._left = left;
|
|
23
|
+
this._right = right;
|
|
24
|
+
this._bottom = bottom;
|
|
25
|
+
this._top = top;
|
|
26
|
+
this._near = near;
|
|
27
|
+
this._far = far;
|
|
28
|
+
this._invalidate(true);
|
|
29
|
+
}
|
|
30
|
+
/** The near clip plane */ get near() {
|
|
31
|
+
return this._near;
|
|
32
|
+
}
|
|
33
|
+
set near(val) {
|
|
34
|
+
if (val !== this._near) {
|
|
35
|
+
this._near = val;
|
|
36
|
+
this._invalidate(true);
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
/** The far clip plane */ get far() {
|
|
40
|
+
return this._far;
|
|
41
|
+
}
|
|
42
|
+
set far(val) {
|
|
43
|
+
if (val !== this._far) {
|
|
44
|
+
this._far = val;
|
|
45
|
+
this._invalidate(true);
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
/** The left clip plane */ get left() {
|
|
49
|
+
return this._left;
|
|
50
|
+
}
|
|
51
|
+
set left(val) {
|
|
52
|
+
if (val !== this._left) {
|
|
53
|
+
this._left = val;
|
|
54
|
+
this._invalidate(true);
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
/** The right clip plane */ get right() {
|
|
58
|
+
return this._right;
|
|
59
|
+
}
|
|
60
|
+
set right(val) {
|
|
61
|
+
if (val !== this._right) {
|
|
62
|
+
this._right = val;
|
|
63
|
+
this._invalidate(true);
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
/** The top clip plane */ get top() {
|
|
67
|
+
return this._top;
|
|
68
|
+
}
|
|
69
|
+
set top(val) {
|
|
70
|
+
if (val !== this._top) {
|
|
71
|
+
this._top = val;
|
|
72
|
+
this._invalidate(true);
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
/** The bottom clip plane */ get bottom() {
|
|
76
|
+
return this._bottom;
|
|
77
|
+
}
|
|
78
|
+
set bottom(val) {
|
|
79
|
+
if (val !== this._bottom) {
|
|
80
|
+
this._bottom = val;
|
|
81
|
+
this._invalidate(true);
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* Not valid for OrthoCamera
|
|
86
|
+
*
|
|
87
|
+
* @remarks
|
|
88
|
+
* This method is only valid for {@link Camera} class or {@link PerspectiveCamera} class.
|
|
89
|
+
*/ setPerspective() {
|
|
90
|
+
throw new Error(`setPerspective() not allowed on OrthoCamera`);
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* {@inheritDoc Camera.setOrtho}
|
|
94
|
+
*/ setOrtho(left, right, bottom, top, near, far) {
|
|
95
|
+
this._left = left;
|
|
96
|
+
this._right = right;
|
|
97
|
+
this._bottom = bottom;
|
|
98
|
+
this._top = top;
|
|
99
|
+
this._near = near;
|
|
100
|
+
this._far = far;
|
|
101
|
+
this._invalidate(true);
|
|
102
|
+
return this;
|
|
103
|
+
}
|
|
104
|
+
/**
|
|
105
|
+
* Setup a projection matrix for the camera
|
|
106
|
+
* @param matrix - The projection matrix
|
|
107
|
+
*/ setProjectionMatrix(matrix) {
|
|
108
|
+
if (matrix && matrix !== this._projMatrix && matrix.isOrtho()) {
|
|
109
|
+
this._left = matrix.getLeftPlane();
|
|
110
|
+
this._right = matrix.getRightPlane();
|
|
111
|
+
this._near = matrix.getNearPlane();
|
|
112
|
+
this._far = matrix.getFarPlane();
|
|
113
|
+
this._top = matrix.getTopPlane();
|
|
114
|
+
this._bottom = matrix.getBottomPlane();
|
|
115
|
+
this._invalidate(true);
|
|
116
|
+
} else {
|
|
117
|
+
throw new Error(`OrthoCamera.setProjectionMatrix(): param is not an orthogonal projection matrix`);
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
/** @internal */ _computeProj() {
|
|
121
|
+
this._projMatrix.ortho(this._left, this._right, this._bottom, this._top, this._near, this._far);
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
export { OrthoCamera };
|
|
126
|
+
//# sourceMappingURL=orthocamera.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"orthocamera.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
|
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
import { Camera } from './camera.js';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Perspective camera class
|
|
5
|
+
* @public
|
|
6
|
+
*/ class PerspectiveCamera extends Camera {
|
|
7
|
+
/** @internal */ _near;
|
|
8
|
+
_far;
|
|
9
|
+
_fovY;
|
|
10
|
+
_aspect;
|
|
11
|
+
_window;
|
|
12
|
+
/**
|
|
13
|
+
* Creates an instance of PerspectiveCamera
|
|
14
|
+
* @param scene - The scene that the camera belongs to.
|
|
15
|
+
* @param fovY - A radian value indicates the field of view in Y axis
|
|
16
|
+
* @param aspect - Aspect ratio of the perspective transform
|
|
17
|
+
* @param near - The near clip plane
|
|
18
|
+
* @param far - The far clip plane
|
|
19
|
+
*/ constructor(scene, fovY, aspect, near, far){
|
|
20
|
+
super(scene);
|
|
21
|
+
this._fovY = fovY;
|
|
22
|
+
this._aspect = aspect;
|
|
23
|
+
this._near = near;
|
|
24
|
+
this._far = far;
|
|
25
|
+
this._window = null;
|
|
26
|
+
this._invalidate(true);
|
|
27
|
+
}
|
|
28
|
+
/** Sub-window of the frustum */ get window() {
|
|
29
|
+
return this._window;
|
|
30
|
+
}
|
|
31
|
+
set window(val) {
|
|
32
|
+
this._window = val ?? null;
|
|
33
|
+
this._invalidate(true);
|
|
34
|
+
}
|
|
35
|
+
/** The near clip plane */ get near() {
|
|
36
|
+
return this._near;
|
|
37
|
+
}
|
|
38
|
+
set near(val) {
|
|
39
|
+
if (val !== this._near) {
|
|
40
|
+
this._near = val;
|
|
41
|
+
this._invalidate(true);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
/** The far clip plane */ get far() {
|
|
45
|
+
return this._far;
|
|
46
|
+
}
|
|
47
|
+
set far(val) {
|
|
48
|
+
if (val !== this._far) {
|
|
49
|
+
this._far = val;
|
|
50
|
+
this._invalidate(true);
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
/** Radian value indicates the field of view in Y axis */ get fovY() {
|
|
54
|
+
return this._fovY;
|
|
55
|
+
}
|
|
56
|
+
set fovY(val) {
|
|
57
|
+
if (val === 0) {
|
|
58
|
+
debugger;
|
|
59
|
+
}
|
|
60
|
+
if (val !== this._fovY) {
|
|
61
|
+
this._fovY = val;
|
|
62
|
+
this._invalidate(true);
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
/** Aspect ratio of the perspective transform */ get aspect() {
|
|
66
|
+
return this._aspect;
|
|
67
|
+
}
|
|
68
|
+
set aspect(val) {
|
|
69
|
+
if (val !== this._aspect) {
|
|
70
|
+
this._aspect = val;
|
|
71
|
+
this._invalidate(true);
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* {@inheritDoc Camera.setPerspective}
|
|
76
|
+
*/ setPerspective(fovY, aspect, zNear, zFar) {
|
|
77
|
+
if (fovY === 0) {
|
|
78
|
+
debugger;
|
|
79
|
+
}
|
|
80
|
+
this._aspect = aspect;
|
|
81
|
+
this._fovY = fovY;
|
|
82
|
+
this._near = zNear;
|
|
83
|
+
this._far = zFar;
|
|
84
|
+
this._invalidate(true);
|
|
85
|
+
return this;
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* Not valid for PerspectiveCamera
|
|
89
|
+
*
|
|
90
|
+
* @remarks
|
|
91
|
+
* This method is only valid for {@link Camera} class or {@link OrthoCamera} class.
|
|
92
|
+
*/ setOrtho(left, right, bottom, top, near, far) {
|
|
93
|
+
throw new Error(`setOrtho() not allowed on PerspectiveCamera`);
|
|
94
|
+
}
|
|
95
|
+
/**
|
|
96
|
+
* Setup a projection matrix for the camera
|
|
97
|
+
* @param matrix - The projection matrix
|
|
98
|
+
*/ setProjectionMatrix(matrix) {
|
|
99
|
+
if (matrix && matrix !== this._projMatrix && matrix.isPerspective()) {
|
|
100
|
+
if (matrix.getFov() === 0) {
|
|
101
|
+
debugger;
|
|
102
|
+
}
|
|
103
|
+
this._aspect = matrix.getAspect();
|
|
104
|
+
this._fovY = matrix.getFov();
|
|
105
|
+
this._near = matrix.getNearPlane();
|
|
106
|
+
this._far = matrix.getFarPlane();
|
|
107
|
+
this._invalidate(true);
|
|
108
|
+
} else {
|
|
109
|
+
throw new Error(`PerspectiveCamera.setProjectionMatrix(): param is not a perspective projection matrix`);
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
/** @internal */ _computeProj() {
|
|
113
|
+
const h = this._near * Math.tan(this._fovY * 0.5);
|
|
114
|
+
const w = h * this._aspect;
|
|
115
|
+
let left = -w;
|
|
116
|
+
let right = w;
|
|
117
|
+
let top = h;
|
|
118
|
+
let bottom = -h;
|
|
119
|
+
if (this._window) {
|
|
120
|
+
const width = right - left;
|
|
121
|
+
const height = top - bottom;
|
|
122
|
+
left += width * this._window[0];
|
|
123
|
+
bottom += height * this._window[1];
|
|
124
|
+
right = left + width * this._window[2];
|
|
125
|
+
top = bottom + height * this._window[3];
|
|
126
|
+
}
|
|
127
|
+
this._projMatrix.frustum(left, right, bottom, top, this._near, this._far);
|
|
128
|
+
//this._projMatrix.perspective(this._fovY, this._aspect, this._near, this._far);
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
export { PerspectiveCamera };
|
|
133
|
+
//# sourceMappingURL=perspectivecamera.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"perspectivecamera.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
|