bg2e-js 2.3.11 → 2.3.13
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/bg2e-js.js +356 -326
- package/dist/bg2e-js.js.map +1 -1
- package/package.json +56 -56
- package/src/app/AppController.ts +39 -39
- package/src/app/Bg2KeyboardEvent.ts +54 -54
- package/src/app/Bg2MouseEvent.ts +82 -82
- package/src/app/Bg2TouchEvent.ts +18 -18
- package/src/app/Canvas.ts +108 -108
- package/src/app/EventBase.ts +10 -10
- package/src/app/MainLoop.ts +273 -273
- package/src/app/index.ts +24 -24
- package/src/base/Color.ts +134 -134
- package/src/base/Environment.ts +183 -183
- package/src/base/Light.ts +192 -192
- package/src/base/Material.ts +620 -620
- package/src/base/PolyList.ts +365 -365
- package/src/base/Texture.ts +620 -620
- package/src/base/index.ts +81 -81
- package/src/db/Bg2LoaderPlugin.ts +143 -143
- package/src/db/DBPluginApi.ts +48 -48
- package/src/db/Loader.ts +116 -116
- package/src/db/LoaderPlugin.ts +34 -34
- package/src/db/MtlParser.ts +7 -7
- package/src/db/ObjLoaderPlugin.ts +54 -54
- package/src/db/ObjParser.ts +252 -252
- package/src/db/ObjWriterPlugin.ts +18 -18
- package/src/db/VitscnjLoaderPlugin.ts +112 -112
- package/src/db/Writer.ts +52 -52
- package/src/db/WriterPlugin.ts +22 -22
- package/src/db/index.ts +44 -44
- package/src/debug/DebugRenderer.ts +173 -173
- package/src/debug/WebGLTextureViewer.ts +75 -75
- package/src/debug/index.ts +6 -6
- package/src/index.html +11 -11
- package/src/index.ts +33 -33
- package/src/manipulation/SelectionBuffer.ts +81 -81
- package/src/manipulation/SelectionHighlight.ts +105 -84
- package/src/manipulation/SelectionIdAssignVisitor.ts +96 -96
- package/src/manipulation/SelectionManager.ts +196 -188
- package/src/manipulation/SelectionMode.ts +6 -6
- package/src/math/Mat3.ts +259 -259
- package/src/math/Mat4.ts +710 -710
- package/src/math/MatrixStrategy.ts +25 -25
- package/src/math/Quat.ts +65 -65
- package/src/math/Vec.ts +753 -753
- package/src/math/constants.ts +46 -46
- package/src/math/functions.ts +103 -103
- package/src/math/index.ts +74 -74
- package/src/phsics/joint.ts +137 -137
- package/src/primitives/arrow.ts +57 -57
- package/src/primitives/cone.ts +138 -138
- package/src/primitives/cube.ts +60 -60
- package/src/primitives/cylinder.ts +216 -216
- package/src/primitives/index.ts +13 -13
- package/src/primitives/plane.ts +31 -31
- package/src/primitives/sphere.ts +809 -809
- package/src/react/useBg2e.ts +69 -69
- package/src/render/BRDFIntegrationMap.ts +4 -4
- package/src/render/Environment.ts +135 -135
- package/src/render/FrameBuffer.ts +35 -35
- package/src/render/MaterialRenderer.ts +34 -34
- package/src/render/Pipeline.ts +108 -108
- package/src/render/PolyListRenderer.ts +47 -47
- package/src/render/RenderBuffer.ts +197 -197
- package/src/render/RenderQueue.ts +198 -198
- package/src/render/RenderState.ts +116 -116
- package/src/render/Renderer.ts +248 -248
- package/src/render/SceneAppController.ts +250 -250
- package/src/render/SceneRenderer.ts +387 -387
- package/src/render/Shader.ts +32 -32
- package/src/render/ShadowRenderer.ts +176 -176
- package/src/render/SkyCube.ts +105 -105
- package/src/render/SkySphere.ts +117 -117
- package/src/render/TextureMergerRenderer.ts +70 -70
- package/src/render/TextureRenderer.ts +34 -34
- package/src/render/index.ts +67 -67
- package/src/render/webgl/FrameBuffer.ts +9 -9
- package/src/render/webgl/MaterialRenderer.ts +112 -112
- package/src/render/webgl/Pipeline.ts +88 -88
- package/src/render/webgl/PolyListRenderer.ts +260 -260
- package/src/render/webgl/RenderBuffer.ts +226 -226
- package/src/render/webgl/Renderer.ts +262 -262
- package/src/render/webgl/SceneRenderer.ts +67 -67
- package/src/render/webgl/ShaderProgram.ts +424 -424
- package/src/render/webgl/ShadowRenderer.ts +6 -6
- package/src/render/webgl/SkyCube.ts +15 -15
- package/src/render/webgl/SkySphere.ts +15 -15
- package/src/render/webgl/State.ts +152 -152
- package/src/render/webgl/TextureRenderer.ts +167 -167
- package/src/render/webgl/VertexBuffer.ts +137 -137
- package/src/render/webgl/index.ts +35 -35
- package/src/scene/Camera.ts +458 -458
- package/src/scene/Chain.ts +44 -44
- package/src/scene/ChainJoint.ts +58 -58
- package/src/scene/Component.ts +177 -177
- package/src/scene/ComponentMap.ts +106 -106
- package/src/scene/Drawable.ts +154 -154
- package/src/scene/EnvironmentComponent.ts +141 -141
- package/src/scene/FindNodeVisitor.ts +59 -59
- package/src/scene/LightComponent.ts +154 -154
- package/src/scene/MatrixState.ts +46 -46
- package/src/scene/Node.ts +328 -328
- package/src/scene/NodeVisitor.ts +15 -15
- package/src/scene/OrbitCameraController.ts +450 -450
- package/src/scene/SmoothOrbitCameraController.ts +99 -99
- package/src/scene/Transform.ts +73 -73
- package/src/scene/index.ts +60 -60
- package/src/shaders/BasicDiffuseColorShader.ts +111 -111
- package/src/shaders/BasicPBRLightShader.ts +276 -276
- package/src/shaders/DebugRenderShader.ts +97 -97
- package/src/shaders/DepthRenderShader.ts +127 -127
- package/src/shaders/IrradianceMapCubeShader.ts +115 -115
- package/src/shaders/PBRLightIBLShader.ts +486 -486
- package/src/shaders/PickSelectionShader.ts +101 -101
- package/src/shaders/PresentDebugFramebufferShader.ts +118 -118
- package/src/shaders/PresentTextureShader.ts +99 -99
- package/src/shaders/SelectionHighlightShader.ts +143 -127
- package/src/shaders/ShaderFunction.ts +318 -318
- package/src/shaders/SkyCubeShader.ts +93 -93
- package/src/shaders/SkySphereShader.ts +102 -102
- package/src/shaders/SpecularMapCubeShader.ts +164 -164
- package/src/shaders/TextureMergerShader.ts +171 -171
- package/src/shaders/index.ts +36 -36
- package/src/shaders/webgl/color_correction.glsl +47 -47
- package/src/shaders/webgl/constants.glsl +6 -6
- package/src/shaders/webgl/index.ts +70 -70
- package/src/shaders/webgl/normal_map.glsl +9 -9
- package/src/shaders/webgl/pbr.glsl +173 -173
- package/src/shaders/webgl/uniforms.glsl +91 -91
- package/src/shaders/webgl_shader_lib.ts +213 -213
- package/src/tools/BinaryResourceProvider.ts +14 -14
- package/src/tools/ImageResourceProvider.ts +66 -66
- package/src/tools/MaterialModifier.ts +446 -446
- package/src/tools/Resource.ts +203 -203
- package/src/tools/ResourceProvider.ts +69 -69
- package/src/tools/TextResourceProvider.ts +24 -24
- package/src/tools/TextureCache.ts +51 -51
- package/src/tools/TextureResourceDatabase.ts +100 -100
- package/src/tools/UserAgent.ts +362 -362
- package/src/tools/VideoResourceProvider.ts +50 -50
- package/src/tools/WriteStrategy.ts +22 -22
- package/src/tools/base64.ts +11 -11
- package/src/tools/crypto.ts +19 -19
- package/src/tools/endiantess.ts +13 -13
- package/src/tools/image.ts +18 -18
- package/src/tools/index.ts +41 -41
- package/src/tools/processType.ts +39 -39
- package/src/vite-env.d.ts +12 -12
|
@@ -1,99 +1,99 @@
|
|
|
1
|
-
import Component from './Component';
|
|
2
|
-
import OrbitCameraController, { Action, getOrbitAction } from './OrbitCameraController';
|
|
3
|
-
import MouseEvent, {
|
|
4
|
-
leftMouseButton,
|
|
5
|
-
middleMouseButton,
|
|
6
|
-
rightMouseButton
|
|
7
|
-
} from '../app/Bg2MouseEvent';
|
|
8
|
-
import { SpecialKey } from '../app/Bg2KeyboardEvent';
|
|
9
|
-
import { degreesToRadians, lerp, clamp } from '../math/functions';
|
|
10
|
-
import Vec from '../math/Vec';
|
|
11
|
-
import { OrthographicProjectionStrategy } from './Camera';
|
|
12
|
-
import Mat4 from '../math/Mat4';
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
export default class SmoothOrbitCameraController extends OrbitCameraController {
|
|
16
|
-
_smoothFactor: number;
|
|
17
|
-
_action: number;
|
|
18
|
-
_center0?: Vec;
|
|
19
|
-
_distance0?: number;
|
|
20
|
-
_pitch0?: number;
|
|
21
|
-
_yaw0?: number;
|
|
22
|
-
|
|
23
|
-
constructor() {
|
|
24
|
-
super("SmoothOrbitCameraController");
|
|
25
|
-
this._smoothFactor = 0.009;
|
|
26
|
-
this._action = Action.NONE;
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
clone(): SmoothOrbitCameraController {
|
|
30
|
-
const result = new SmoothOrbitCameraController();
|
|
31
|
-
result.assign(this);
|
|
32
|
-
return result;
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
assign(other: SmoothOrbitCameraController): void {
|
|
36
|
-
super.assign(other);
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
willUpdate(delta: number): void {
|
|
40
|
-
if (this.transform && this.enabled) {
|
|
41
|
-
const orthoStrategy = this.camera && this.camera.projectionStrategy instanceof OrthographicProjectionStrategy ?
|
|
42
|
-
this.camera.projectionStrategy : null;
|
|
43
|
-
|
|
44
|
-
if (this._mouseButtonPressed) {
|
|
45
|
-
let displacement = new Vec([0, 0, 0]);
|
|
46
|
-
if (this._keys[SpecialKey.UP_ARROW]) {
|
|
47
|
-
displacement = Vec.Add(displacement, this.transform.matrix.backwardVector);
|
|
48
|
-
}
|
|
49
|
-
if (this._keys[SpecialKey.DOWN_ARROW]) {
|
|
50
|
-
displacement = Vec.Add(displacement, this.transform.matrix.forwardVector);
|
|
51
|
-
}
|
|
52
|
-
if (this._keys[SpecialKey.LEFT_ARROW]) {
|
|
53
|
-
displacement = Vec.Add(displacement, this.transform.matrix.leftVector);
|
|
54
|
-
}
|
|
55
|
-
if (this._keys[SpecialKey.RIGHT_ARROW]) {
|
|
56
|
-
displacement = Vec.Add(displacement, this.transform.matrix.rightVector);
|
|
57
|
-
}
|
|
58
|
-
displacement.scale(this._displacementSpeed);
|
|
59
|
-
this._center = Vec.Add(this._center, displacement);
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
this._center0 = this._center0 ?? Mat4.GetPosition(this.transform.matrix);
|
|
63
|
-
this._distance0 = this._distance0 ?? Vec.Distance(this._center0, this._center);
|
|
64
|
-
this._center0 = Vec.Lerp(this._center0, this._center, delta * this._smoothFactor);
|
|
65
|
-
this._distance0 = lerp(this._distance0, this._distance, delta * this._smoothFactor * 2);
|
|
66
|
-
this._pitch0 = this._pitch0 ?? this._rotation.x;
|
|
67
|
-
this._yaw0 = this._yaw0 ?? this._rotation.y;
|
|
68
|
-
|
|
69
|
-
this._pitch0 = lerp(this._pitch0, this._rotation.x, delta * this._smoothFactor);
|
|
70
|
-
this._yaw0 = lerp(this._yaw0, this._rotation.y, delta * this._smoothFactor);
|
|
71
|
-
|
|
72
|
-
// Clamp values
|
|
73
|
-
this._distance = clamp(this._distance, this.minDistance, this.maxDistance);
|
|
74
|
-
this._distance0 = clamp(this._distance0, this.minDistance, this.maxDistance);
|
|
75
|
-
this._pitch0 = clamp(this._pitch0, this.minPitch, this.maxPitch);
|
|
76
|
-
this._rotation.x = clamp(this._rotation.x, this.minPitch, this.maxPitch);
|
|
77
|
-
const minDisp = new Vec(this.minX, this.minY, this.minZ);
|
|
78
|
-
const maxDisp = new Vec(this.maxX, this.maxY, this.maxZ);
|
|
79
|
-
this._center0 = Vec.Clamp(this._center0, minDisp, maxDisp);
|
|
80
|
-
this._center = Vec.Clamp(this._center, minDisp, maxDisp);
|
|
81
|
-
|
|
82
|
-
this.transform.matrix.identity();
|
|
83
|
-
if (orthoStrategy) {
|
|
84
|
-
orthoStrategy.viewWidth = this._viewWidth!;
|
|
85
|
-
}
|
|
86
|
-
else {
|
|
87
|
-
this.transform.matrix.translate(0, 0, this._distance0);
|
|
88
|
-
if (this.camera) {
|
|
89
|
-
// Update the camera focus distance to optimize the shadow map rendering
|
|
90
|
-
this.camera.focusDistance = this._distance0;
|
|
91
|
-
}
|
|
92
|
-
}
|
|
93
|
-
this.transform.matrix.rotate(degreesToRadians(-this._pitch0), 1, 0, 0)
|
|
94
|
-
.rotate(degreesToRadians(this._yaw0), 0, 1, 0)
|
|
95
|
-
.translate(this._center0);
|
|
96
|
-
|
|
97
|
-
}
|
|
98
|
-
}
|
|
99
|
-
}
|
|
1
|
+
import Component from './Component';
|
|
2
|
+
import OrbitCameraController, { Action, getOrbitAction } from './OrbitCameraController';
|
|
3
|
+
import MouseEvent, {
|
|
4
|
+
leftMouseButton,
|
|
5
|
+
middleMouseButton,
|
|
6
|
+
rightMouseButton
|
|
7
|
+
} from '../app/Bg2MouseEvent';
|
|
8
|
+
import { SpecialKey } from '../app/Bg2KeyboardEvent';
|
|
9
|
+
import { degreesToRadians, lerp, clamp } from '../math/functions';
|
|
10
|
+
import Vec from '../math/Vec';
|
|
11
|
+
import { OrthographicProjectionStrategy } from './Camera';
|
|
12
|
+
import Mat4 from '../math/Mat4';
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
export default class SmoothOrbitCameraController extends OrbitCameraController {
|
|
16
|
+
_smoothFactor: number;
|
|
17
|
+
_action: number;
|
|
18
|
+
_center0?: Vec;
|
|
19
|
+
_distance0?: number;
|
|
20
|
+
_pitch0?: number;
|
|
21
|
+
_yaw0?: number;
|
|
22
|
+
|
|
23
|
+
constructor() {
|
|
24
|
+
super("SmoothOrbitCameraController");
|
|
25
|
+
this._smoothFactor = 0.009;
|
|
26
|
+
this._action = Action.NONE;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
clone(): SmoothOrbitCameraController {
|
|
30
|
+
const result = new SmoothOrbitCameraController();
|
|
31
|
+
result.assign(this);
|
|
32
|
+
return result;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
assign(other: SmoothOrbitCameraController): void {
|
|
36
|
+
super.assign(other);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
willUpdate(delta: number): void {
|
|
40
|
+
if (this.transform && this.enabled) {
|
|
41
|
+
const orthoStrategy = this.camera && this.camera.projectionStrategy instanceof OrthographicProjectionStrategy ?
|
|
42
|
+
this.camera.projectionStrategy : null;
|
|
43
|
+
|
|
44
|
+
if (this._mouseButtonPressed) {
|
|
45
|
+
let displacement = new Vec([0, 0, 0]);
|
|
46
|
+
if (this._keys[SpecialKey.UP_ARROW]) {
|
|
47
|
+
displacement = Vec.Add(displacement, this.transform.matrix.backwardVector);
|
|
48
|
+
}
|
|
49
|
+
if (this._keys[SpecialKey.DOWN_ARROW]) {
|
|
50
|
+
displacement = Vec.Add(displacement, this.transform.matrix.forwardVector);
|
|
51
|
+
}
|
|
52
|
+
if (this._keys[SpecialKey.LEFT_ARROW]) {
|
|
53
|
+
displacement = Vec.Add(displacement, this.transform.matrix.leftVector);
|
|
54
|
+
}
|
|
55
|
+
if (this._keys[SpecialKey.RIGHT_ARROW]) {
|
|
56
|
+
displacement = Vec.Add(displacement, this.transform.matrix.rightVector);
|
|
57
|
+
}
|
|
58
|
+
displacement.scale(this._displacementSpeed);
|
|
59
|
+
this._center = Vec.Add(this._center, displacement);
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
this._center0 = this._center0 ?? Mat4.GetPosition(this.transform.matrix);
|
|
63
|
+
this._distance0 = this._distance0 ?? Vec.Distance(this._center0, this._center);
|
|
64
|
+
this._center0 = Vec.Lerp(this._center0, this._center, delta * this._smoothFactor);
|
|
65
|
+
this._distance0 = lerp(this._distance0, this._distance, delta * this._smoothFactor * 2);
|
|
66
|
+
this._pitch0 = this._pitch0 ?? this._rotation.x;
|
|
67
|
+
this._yaw0 = this._yaw0 ?? this._rotation.y;
|
|
68
|
+
|
|
69
|
+
this._pitch0 = lerp(this._pitch0, this._rotation.x, delta * this._smoothFactor);
|
|
70
|
+
this._yaw0 = lerp(this._yaw0, this._rotation.y, delta * this._smoothFactor);
|
|
71
|
+
|
|
72
|
+
// Clamp values
|
|
73
|
+
this._distance = clamp(this._distance, this.minDistance, this.maxDistance);
|
|
74
|
+
this._distance0 = clamp(this._distance0, this.minDistance, this.maxDistance);
|
|
75
|
+
this._pitch0 = clamp(this._pitch0, this.minPitch, this.maxPitch);
|
|
76
|
+
this._rotation.x = clamp(this._rotation.x, this.minPitch, this.maxPitch);
|
|
77
|
+
const minDisp = new Vec(this.minX, this.minY, this.minZ);
|
|
78
|
+
const maxDisp = new Vec(this.maxX, this.maxY, this.maxZ);
|
|
79
|
+
this._center0 = Vec.Clamp(this._center0, minDisp, maxDisp);
|
|
80
|
+
this._center = Vec.Clamp(this._center, minDisp, maxDisp);
|
|
81
|
+
|
|
82
|
+
this.transform.matrix.identity();
|
|
83
|
+
if (orthoStrategy) {
|
|
84
|
+
orthoStrategy.viewWidth = this._viewWidth!;
|
|
85
|
+
}
|
|
86
|
+
else {
|
|
87
|
+
this.transform.matrix.translate(0, 0, this._distance0);
|
|
88
|
+
if (this.camera) {
|
|
89
|
+
// Update the camera focus distance to optimize the shadow map rendering
|
|
90
|
+
this.camera.focusDistance = this._distance0;
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
this.transform.matrix.rotate(degreesToRadians(-this._pitch0), 1, 0, 0)
|
|
94
|
+
.rotate(degreesToRadians(this._yaw0), 0, 1, 0)
|
|
95
|
+
.translate(this._center0);
|
|
96
|
+
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
}
|
package/src/scene/Transform.ts
CHANGED
|
@@ -1,73 +1,73 @@
|
|
|
1
|
-
import Component from './Component';
|
|
2
|
-
import Node from './Node';
|
|
3
|
-
import Mat4 from "../math/Mat4";
|
|
4
|
-
import NodeVisitor from './NodeVisitor';
|
|
5
|
-
|
|
6
|
-
export class TransformVisitor extends NodeVisitor {
|
|
7
|
-
_matrix: Mat4;
|
|
8
|
-
|
|
9
|
-
constructor() {
|
|
10
|
-
super();
|
|
11
|
-
this._matrix = Mat4.MakeIdentity();
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
get matrix(): Mat4 {
|
|
15
|
-
return this._matrix;
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
visit(node: any): void {
|
|
19
|
-
if (node.transform) {
|
|
20
|
-
this._matrix = Mat4.Mult(this._matrix, node.transform.matrix);
|
|
21
|
-
}
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
export default class Transform extends Component {
|
|
26
|
-
static GetWorldMatrix(node: Node | Component): Mat4 {
|
|
27
|
-
if (node instanceof Component) {
|
|
28
|
-
node = node.node;
|
|
29
|
-
}
|
|
30
|
-
const visitor = new TransformVisitor();
|
|
31
|
-
node.acceptReverse(visitor);
|
|
32
|
-
return visitor.matrix;
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
_matrix: Mat4;
|
|
36
|
-
|
|
37
|
-
constructor(mat: Mat4 = Mat4.MakeIdentity()) {
|
|
38
|
-
super("Transform");
|
|
39
|
-
this._matrix = mat;
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
get matrix(): Mat4 { return this._matrix; }
|
|
43
|
-
set matrix(m: Mat4) { this._matrix = m; }
|
|
44
|
-
|
|
45
|
-
clone(): Transform {
|
|
46
|
-
const result = new Transform();
|
|
47
|
-
result.assign(this);
|
|
48
|
-
return result;
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
assign(other: Transform): void {
|
|
52
|
-
this._matrix = new Mat4(other.matrix);
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
async deserialize(sceneData: any, loader: any): Promise<void> {
|
|
56
|
-
if (Array.isArray(sceneData.transformMatrix) && sceneData.transformMatrix.length === 16) {
|
|
57
|
-
this._matrix.assign(sceneData.transformMatrix);
|
|
58
|
-
}
|
|
59
|
-
else {
|
|
60
|
-
console.warn("Transform.deserialize(): invalid transformMatrix attribute found in scene data");
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
async serialize(sceneData: any, writer: any): Promise<void> {
|
|
65
|
-
await super.serialize(sceneData,writer);
|
|
66
|
-
throw new Error("Transform.serialice() not implemented");
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
update(delta: number, modelMatrix: Mat4): void {
|
|
70
|
-
//modelMatrix.mult(this._matrix);
|
|
71
|
-
modelMatrix.assign(Mat4.Mult(modelMatrix, this._matrix));
|
|
72
|
-
}
|
|
73
|
-
}
|
|
1
|
+
import Component from './Component';
|
|
2
|
+
import Node from './Node';
|
|
3
|
+
import Mat4 from "../math/Mat4";
|
|
4
|
+
import NodeVisitor from './NodeVisitor';
|
|
5
|
+
|
|
6
|
+
export class TransformVisitor extends NodeVisitor {
|
|
7
|
+
_matrix: Mat4;
|
|
8
|
+
|
|
9
|
+
constructor() {
|
|
10
|
+
super();
|
|
11
|
+
this._matrix = Mat4.MakeIdentity();
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
get matrix(): Mat4 {
|
|
15
|
+
return this._matrix;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
visit(node: any): void {
|
|
19
|
+
if (node.transform) {
|
|
20
|
+
this._matrix = Mat4.Mult(this._matrix, node.transform.matrix);
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export default class Transform extends Component {
|
|
26
|
+
static GetWorldMatrix(node: Node | Component): Mat4 {
|
|
27
|
+
if (node instanceof Component) {
|
|
28
|
+
node = node.node;
|
|
29
|
+
}
|
|
30
|
+
const visitor = new TransformVisitor();
|
|
31
|
+
node.acceptReverse(visitor);
|
|
32
|
+
return visitor.matrix;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
_matrix: Mat4;
|
|
36
|
+
|
|
37
|
+
constructor(mat: Mat4 = Mat4.MakeIdentity()) {
|
|
38
|
+
super("Transform");
|
|
39
|
+
this._matrix = mat;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
get matrix(): Mat4 { return this._matrix; }
|
|
43
|
+
set matrix(m: Mat4) { this._matrix = m; }
|
|
44
|
+
|
|
45
|
+
clone(): Transform {
|
|
46
|
+
const result = new Transform();
|
|
47
|
+
result.assign(this);
|
|
48
|
+
return result;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
assign(other: Transform): void {
|
|
52
|
+
this._matrix = new Mat4(other.matrix);
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
async deserialize(sceneData: any, loader: any): Promise<void> {
|
|
56
|
+
if (Array.isArray(sceneData.transformMatrix) && sceneData.transformMatrix.length === 16) {
|
|
57
|
+
this._matrix.assign(sceneData.transformMatrix);
|
|
58
|
+
}
|
|
59
|
+
else {
|
|
60
|
+
console.warn("Transform.deserialize(): invalid transformMatrix attribute found in scene data");
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
async serialize(sceneData: any, writer: any): Promise<void> {
|
|
65
|
+
await super.serialize(sceneData,writer);
|
|
66
|
+
throw new Error("Transform.serialice() not implemented");
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
update(delta: number, modelMatrix: Mat4): void {
|
|
70
|
+
//modelMatrix.mult(this._matrix);
|
|
71
|
+
modelMatrix.assign(Mat4.Mult(modelMatrix, this._matrix));
|
|
72
|
+
}
|
|
73
|
+
}
|
package/src/scene/index.ts
CHANGED
|
@@ -1,61 +1,61 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
import DrawableComponent from "./Drawable";
|
|
4
|
-
import TransformComponent from "./Transform";
|
|
5
|
-
import ChainComponent from "./Chain";
|
|
6
|
-
import {
|
|
7
|
-
InputChainJoint as InputChainJointComponent,
|
|
8
|
-
OutputChainJoint as OutputChainJointComponent } from "./ChainJoint";
|
|
9
|
-
import LightComponent from "./LightComponent";
|
|
10
|
-
import CameraComponent, {
|
|
11
|
-
OpticalProjectionStrategy,
|
|
12
|
-
PerspectiveProjectionStrategy,
|
|
13
|
-
ProjectionStrategy
|
|
14
|
-
} from "./Camera";
|
|
15
|
-
import OrbitCameraControllerComponent from "./OrbitCameraController";
|
|
16
|
-
import SmoothOrbitCameraControllerComponent from "./SmoothOrbitCameraController";
|
|
17
|
-
import EnvironmentComponent from "./EnvironmentComponent";
|
|
18
|
-
import Component, { registerComponent } from "./Component";
|
|
19
|
-
import Node from "./Node";
|
|
20
|
-
import NodeVisitor from "./NodeVisitor";
|
|
21
|
-
import FindNodeVisitor from "./FindNodeVisitor";
|
|
22
|
-
|
|
23
|
-
export const registerComponents = () => {
|
|
24
|
-
registerComponent("Drawable", DrawableComponent);
|
|
25
|
-
registerComponent("Transform", TransformComponent);
|
|
26
|
-
|
|
27
|
-
// Retrocompatibility: the light is registered with both "Light" and "LightComponent" names, but only "LightComponent" should be used in the future
|
|
28
|
-
registerComponent("Light", LightComponent);
|
|
29
|
-
registerComponent("LightComponent", LightComponent);
|
|
30
|
-
|
|
31
|
-
registerComponent("Chain", ChainComponent);
|
|
32
|
-
registerComponent("InputChainJoint", InputChainJointComponent);
|
|
33
|
-
registerComponent("OutputChainJoint", OutputChainJointComponent);
|
|
34
|
-
registerComponent("Camera", CameraComponent);
|
|
35
|
-
registerComponent("OrbitCameraController", OrbitCameraControllerComponent);
|
|
36
|
-
registerComponent("SmoothOrbitCameraController", SmoothOrbitCameraControllerComponent);
|
|
37
|
-
registerComponent("Environment", EnvironmentComponent);
|
|
38
|
-
// TODO: Register more components
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
export default {
|
|
42
|
-
Component,
|
|
43
|
-
DrawableComponent,
|
|
44
|
-
TransformComponent,
|
|
45
|
-
ChainComponent,
|
|
46
|
-
InputChainJointComponent,
|
|
47
|
-
OutputChainJointComponent,
|
|
48
|
-
LightComponent,
|
|
49
|
-
CameraComponent,
|
|
50
|
-
OpticalProjectionStrategy,
|
|
51
|
-
PerspectiveProjectionStrategy,
|
|
52
|
-
ProjectionStrategy,
|
|
53
|
-
OrbitCameraControllerComponent,
|
|
54
|
-
SmoothOrbitCameraControllerComponent,
|
|
55
|
-
EnvironmentComponent,
|
|
56
|
-
registerComponents,
|
|
57
|
-
registerComponent,
|
|
58
|
-
Node,
|
|
59
|
-
NodeVisitor,
|
|
60
|
-
FindNodeVisitor
|
|
1
|
+
|
|
2
|
+
|
|
3
|
+
import DrawableComponent from "./Drawable";
|
|
4
|
+
import TransformComponent from "./Transform";
|
|
5
|
+
import ChainComponent from "./Chain";
|
|
6
|
+
import {
|
|
7
|
+
InputChainJoint as InputChainJointComponent,
|
|
8
|
+
OutputChainJoint as OutputChainJointComponent } from "./ChainJoint";
|
|
9
|
+
import LightComponent from "./LightComponent";
|
|
10
|
+
import CameraComponent, {
|
|
11
|
+
OpticalProjectionStrategy,
|
|
12
|
+
PerspectiveProjectionStrategy,
|
|
13
|
+
ProjectionStrategy
|
|
14
|
+
} from "./Camera";
|
|
15
|
+
import OrbitCameraControllerComponent from "./OrbitCameraController";
|
|
16
|
+
import SmoothOrbitCameraControllerComponent from "./SmoothOrbitCameraController";
|
|
17
|
+
import EnvironmentComponent from "./EnvironmentComponent";
|
|
18
|
+
import Component, { registerComponent } from "./Component";
|
|
19
|
+
import Node from "./Node";
|
|
20
|
+
import NodeVisitor from "./NodeVisitor";
|
|
21
|
+
import FindNodeVisitor from "./FindNodeVisitor";
|
|
22
|
+
|
|
23
|
+
export const registerComponents = () => {
|
|
24
|
+
registerComponent("Drawable", DrawableComponent);
|
|
25
|
+
registerComponent("Transform", TransformComponent);
|
|
26
|
+
|
|
27
|
+
// Retrocompatibility: the light is registered with both "Light" and "LightComponent" names, but only "LightComponent" should be used in the future
|
|
28
|
+
registerComponent("Light", LightComponent);
|
|
29
|
+
registerComponent("LightComponent", LightComponent);
|
|
30
|
+
|
|
31
|
+
registerComponent("Chain", ChainComponent);
|
|
32
|
+
registerComponent("InputChainJoint", InputChainJointComponent);
|
|
33
|
+
registerComponent("OutputChainJoint", OutputChainJointComponent);
|
|
34
|
+
registerComponent("Camera", CameraComponent);
|
|
35
|
+
registerComponent("OrbitCameraController", OrbitCameraControllerComponent);
|
|
36
|
+
registerComponent("SmoothOrbitCameraController", SmoothOrbitCameraControllerComponent);
|
|
37
|
+
registerComponent("Environment", EnvironmentComponent);
|
|
38
|
+
// TODO: Register more components
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export default {
|
|
42
|
+
Component,
|
|
43
|
+
DrawableComponent,
|
|
44
|
+
TransformComponent,
|
|
45
|
+
ChainComponent,
|
|
46
|
+
InputChainJointComponent,
|
|
47
|
+
OutputChainJointComponent,
|
|
48
|
+
LightComponent,
|
|
49
|
+
CameraComponent,
|
|
50
|
+
OpticalProjectionStrategy,
|
|
51
|
+
PerspectiveProjectionStrategy,
|
|
52
|
+
ProjectionStrategy,
|
|
53
|
+
OrbitCameraControllerComponent,
|
|
54
|
+
SmoothOrbitCameraControllerComponent,
|
|
55
|
+
EnvironmentComponent,
|
|
56
|
+
registerComponents,
|
|
57
|
+
registerComponent,
|
|
58
|
+
Node,
|
|
59
|
+
NodeVisitor,
|
|
60
|
+
FindNodeVisitor
|
|
61
61
|
}
|