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,155 +1,155 @@
|
|
|
1
|
-
import Component from "./Component";
|
|
2
|
-
import Light, { LightType } from "../base/Light";
|
|
3
|
-
import FindNodeVisitor from "./FindNodeVisitor";
|
|
4
|
-
import Node from "./Node";
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
export default class LightComponent extends Component {
|
|
8
|
-
static GetLights(sceneRoot: Node): LightComponent[] {
|
|
9
|
-
if (sceneRoot.sceneChanged || !(sceneRoot as any).__lights) {
|
|
10
|
-
(sceneRoot as any).__lights = [];
|
|
11
|
-
let findLights = new FindNodeVisitor();
|
|
12
|
-
findLights.hasComponents(["Light"]);
|
|
13
|
-
sceneRoot.accept(findLights);
|
|
14
|
-
(sceneRoot as any).__lights = findLights.result.map(n => n.lightComponent);
|
|
15
|
-
}
|
|
16
|
-
return (sceneRoot as any).__lights;
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
static GetFirstShadowCastingLight(sceneRoot: Node): LightComponent | undefined {
|
|
20
|
-
if (sceneRoot.sceneChanged || !(sceneRoot as any).__mainDirectionalLight) {
|
|
21
|
-
(sceneRoot as any).__mainDirectionalLight = LightComponent.GetLights(sceneRoot)
|
|
22
|
-
.find(l => l.light.type === LightType.DIRECTIONAL || l.light.type === LightType.SPOT);
|
|
23
|
-
}
|
|
24
|
-
return (sceneRoot as any).__mainDirectionalLight;
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
static GetMainDirectionalLight(sceneRoot: Node): LightComponent | undefined {
|
|
28
|
-
if (sceneRoot.sceneChanged || !(sceneRoot as any).__mainDirectionalLight) {
|
|
29
|
-
(sceneRoot as any).__mainDirectionalLight = LightComponent.GetLights(sceneRoot)
|
|
30
|
-
.find(l => l.light.type === LightType.DIRECTIONAL);
|
|
31
|
-
}
|
|
32
|
-
return (sceneRoot as any).__mainDirectionalLight || LightComponent.GetFirstShadowCastingLight(sceneRoot);
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
_light: Light;
|
|
36
|
-
|
|
37
|
-
constructor(light: Light | null = null) {
|
|
38
|
-
super("Light");
|
|
39
|
-
|
|
40
|
-
this._light = light || new Light();
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
get light(): Light { return this._light; }
|
|
44
|
-
set light(l: Light) { this._light = l; }
|
|
45
|
-
|
|
46
|
-
set depthTexture(t: any) {
|
|
47
|
-
this._light.depthTexture = t;
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
get depthTexture(): any {
|
|
51
|
-
return this._light.depthTexture;
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
set viewMatrix(vm: any) {
|
|
55
|
-
this._light.viewMatrix = vm;
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
get viewMatrix(): any {
|
|
59
|
-
return this._light.viewMatrix;
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
clone(): LightComponent {
|
|
63
|
-
const result = new LightComponent();
|
|
64
|
-
result.assign(this);
|
|
65
|
-
return result;
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
assign(other: LightComponent): void {
|
|
69
|
-
this._light = other._light.clone();
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
setProperties({
|
|
73
|
-
enabled,
|
|
74
|
-
type,
|
|
75
|
-
lightType, // alias of type
|
|
76
|
-
direction,
|
|
77
|
-
position,
|
|
78
|
-
color,
|
|
79
|
-
spotCutoff,
|
|
80
|
-
spotExponent,
|
|
81
|
-
shadowStrength,
|
|
82
|
-
castShadows,
|
|
83
|
-
shadowBias,
|
|
84
|
-
intensity,
|
|
85
|
-
projection
|
|
86
|
-
}: {
|
|
87
|
-
enabled?: boolean;
|
|
88
|
-
type?: LightType;
|
|
89
|
-
lightType?: LightType;
|
|
90
|
-
direction?: any;
|
|
91
|
-
position?: any;
|
|
92
|
-
color?: any;
|
|
93
|
-
spotCutoff?: number;
|
|
94
|
-
spotExponent?: number;
|
|
95
|
-
shadowStrength?: number;
|
|
96
|
-
castShadows?: boolean;
|
|
97
|
-
shadowBias?: number;
|
|
98
|
-
intensity?: number;
|
|
99
|
-
projection?: any;
|
|
100
|
-
}): void {
|
|
101
|
-
if (enabled !== undefined) {
|
|
102
|
-
this.light.enabled = enabled;
|
|
103
|
-
}
|
|
104
|
-
if (type !== undefined) {
|
|
105
|
-
this.light.type = type;
|
|
106
|
-
}
|
|
107
|
-
if (lightType !== undefined) {
|
|
108
|
-
this.light.type = lightType;
|
|
109
|
-
}
|
|
110
|
-
if (direction !== undefined) {
|
|
111
|
-
this.light.direction = direction;
|
|
112
|
-
}
|
|
113
|
-
if (position !== undefined) {
|
|
114
|
-
this.light.position = position;
|
|
115
|
-
}
|
|
116
|
-
if (color !== undefined) {
|
|
117
|
-
this.light.color = color;
|
|
118
|
-
}
|
|
119
|
-
if (spotCutoff !== undefined) {
|
|
120
|
-
this.light.spotCutoff = spotCutoff;
|
|
121
|
-
}
|
|
122
|
-
if (spotExponent !== undefined) {
|
|
123
|
-
this.light.spotExponent = spotExponent;
|
|
124
|
-
}
|
|
125
|
-
if (shadowStrength !== undefined) {
|
|
126
|
-
this.light.shadowStrength = shadowStrength;
|
|
127
|
-
}
|
|
128
|
-
if (castShadows !== undefined) {
|
|
129
|
-
this.light.castShadows = castShadows;
|
|
130
|
-
}
|
|
131
|
-
if (shadowBias !== undefined) {
|
|
132
|
-
this.light.shadowBias = shadowBias;
|
|
133
|
-
}
|
|
134
|
-
if (intensity !== undefined) {
|
|
135
|
-
this.light.intensity = intensity;
|
|
136
|
-
}
|
|
137
|
-
if (projection !== undefined) {
|
|
138
|
-
this.light.projection = projection;
|
|
139
|
-
}
|
|
140
|
-
}
|
|
141
|
-
|
|
142
|
-
async deserialize(sceneData: any, loader: any): Promise<void> {
|
|
143
|
-
await this._light.deserialize(sceneData);
|
|
144
|
-
}
|
|
145
|
-
|
|
146
|
-
async serialize(sceneData: any, writer: any): Promise<void> {
|
|
147
|
-
await super.serialize(sceneData,writer);
|
|
148
|
-
await this._light.serialize(sceneData);
|
|
149
|
-
throw new Error("LightComponent.serialize() not implemented");
|
|
150
|
-
}
|
|
151
|
-
|
|
152
|
-
draw(renderQueue: any, modelMatrix: any): void {
|
|
153
|
-
renderQueue.addLight(this.light, modelMatrix);
|
|
154
|
-
}
|
|
1
|
+
import Component from "./Component";
|
|
2
|
+
import Light, { LightType } from "../base/Light";
|
|
3
|
+
import FindNodeVisitor from "./FindNodeVisitor";
|
|
4
|
+
import Node from "./Node";
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
export default class LightComponent extends Component {
|
|
8
|
+
static GetLights(sceneRoot: Node): LightComponent[] {
|
|
9
|
+
if (sceneRoot.sceneChanged || !(sceneRoot as any).__lights) {
|
|
10
|
+
(sceneRoot as any).__lights = [];
|
|
11
|
+
let findLights = new FindNodeVisitor();
|
|
12
|
+
findLights.hasComponents(["Light"]);
|
|
13
|
+
sceneRoot.accept(findLights);
|
|
14
|
+
(sceneRoot as any).__lights = findLights.result.map(n => n.lightComponent);
|
|
15
|
+
}
|
|
16
|
+
return (sceneRoot as any).__lights;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
static GetFirstShadowCastingLight(sceneRoot: Node): LightComponent | undefined {
|
|
20
|
+
if (sceneRoot.sceneChanged || !(sceneRoot as any).__mainDirectionalLight) {
|
|
21
|
+
(sceneRoot as any).__mainDirectionalLight = LightComponent.GetLights(sceneRoot)
|
|
22
|
+
.find(l => l.light.type === LightType.DIRECTIONAL || l.light.type === LightType.SPOT);
|
|
23
|
+
}
|
|
24
|
+
return (sceneRoot as any).__mainDirectionalLight;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
static GetMainDirectionalLight(sceneRoot: Node): LightComponent | undefined {
|
|
28
|
+
if (sceneRoot.sceneChanged || !(sceneRoot as any).__mainDirectionalLight) {
|
|
29
|
+
(sceneRoot as any).__mainDirectionalLight = LightComponent.GetLights(sceneRoot)
|
|
30
|
+
.find(l => l.light.type === LightType.DIRECTIONAL);
|
|
31
|
+
}
|
|
32
|
+
return (sceneRoot as any).__mainDirectionalLight || LightComponent.GetFirstShadowCastingLight(sceneRoot);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
_light: Light;
|
|
36
|
+
|
|
37
|
+
constructor(light: Light | null = null) {
|
|
38
|
+
super("Light");
|
|
39
|
+
|
|
40
|
+
this._light = light || new Light();
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
get light(): Light { return this._light; }
|
|
44
|
+
set light(l: Light) { this._light = l; }
|
|
45
|
+
|
|
46
|
+
set depthTexture(t: any) {
|
|
47
|
+
this._light.depthTexture = t;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
get depthTexture(): any {
|
|
51
|
+
return this._light.depthTexture;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
set viewMatrix(vm: any) {
|
|
55
|
+
this._light.viewMatrix = vm;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
get viewMatrix(): any {
|
|
59
|
+
return this._light.viewMatrix;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
clone(): LightComponent {
|
|
63
|
+
const result = new LightComponent();
|
|
64
|
+
result.assign(this);
|
|
65
|
+
return result;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
assign(other: LightComponent): void {
|
|
69
|
+
this._light = other._light.clone();
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
setProperties({
|
|
73
|
+
enabled,
|
|
74
|
+
type,
|
|
75
|
+
lightType, // alias of type
|
|
76
|
+
direction,
|
|
77
|
+
position,
|
|
78
|
+
color,
|
|
79
|
+
spotCutoff,
|
|
80
|
+
spotExponent,
|
|
81
|
+
shadowStrength,
|
|
82
|
+
castShadows,
|
|
83
|
+
shadowBias,
|
|
84
|
+
intensity,
|
|
85
|
+
projection
|
|
86
|
+
}: {
|
|
87
|
+
enabled?: boolean;
|
|
88
|
+
type?: LightType;
|
|
89
|
+
lightType?: LightType;
|
|
90
|
+
direction?: any;
|
|
91
|
+
position?: any;
|
|
92
|
+
color?: any;
|
|
93
|
+
spotCutoff?: number;
|
|
94
|
+
spotExponent?: number;
|
|
95
|
+
shadowStrength?: number;
|
|
96
|
+
castShadows?: boolean;
|
|
97
|
+
shadowBias?: number;
|
|
98
|
+
intensity?: number;
|
|
99
|
+
projection?: any;
|
|
100
|
+
}): void {
|
|
101
|
+
if (enabled !== undefined) {
|
|
102
|
+
this.light.enabled = enabled;
|
|
103
|
+
}
|
|
104
|
+
if (type !== undefined) {
|
|
105
|
+
this.light.type = type;
|
|
106
|
+
}
|
|
107
|
+
if (lightType !== undefined) {
|
|
108
|
+
this.light.type = lightType;
|
|
109
|
+
}
|
|
110
|
+
if (direction !== undefined) {
|
|
111
|
+
this.light.direction = direction;
|
|
112
|
+
}
|
|
113
|
+
if (position !== undefined) {
|
|
114
|
+
this.light.position = position;
|
|
115
|
+
}
|
|
116
|
+
if (color !== undefined) {
|
|
117
|
+
this.light.color = color;
|
|
118
|
+
}
|
|
119
|
+
if (spotCutoff !== undefined) {
|
|
120
|
+
this.light.spotCutoff = spotCutoff;
|
|
121
|
+
}
|
|
122
|
+
if (spotExponent !== undefined) {
|
|
123
|
+
this.light.spotExponent = spotExponent;
|
|
124
|
+
}
|
|
125
|
+
if (shadowStrength !== undefined) {
|
|
126
|
+
this.light.shadowStrength = shadowStrength;
|
|
127
|
+
}
|
|
128
|
+
if (castShadows !== undefined) {
|
|
129
|
+
this.light.castShadows = castShadows;
|
|
130
|
+
}
|
|
131
|
+
if (shadowBias !== undefined) {
|
|
132
|
+
this.light.shadowBias = shadowBias;
|
|
133
|
+
}
|
|
134
|
+
if (intensity !== undefined) {
|
|
135
|
+
this.light.intensity = intensity;
|
|
136
|
+
}
|
|
137
|
+
if (projection !== undefined) {
|
|
138
|
+
this.light.projection = projection;
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
async deserialize(sceneData: any, loader: any): Promise<void> {
|
|
143
|
+
await this._light.deserialize(sceneData);
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
async serialize(sceneData: any, writer: any): Promise<void> {
|
|
147
|
+
await super.serialize(sceneData,writer);
|
|
148
|
+
await this._light.serialize(sceneData);
|
|
149
|
+
throw new Error("LightComponent.serialize() not implemented");
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
draw(renderQueue: any, modelMatrix: any): void {
|
|
153
|
+
renderQueue.addLight(this.light, modelMatrix);
|
|
154
|
+
}
|
|
155
155
|
}
|
package/src/scene/MatrixState.ts
CHANGED
|
@@ -1,46 +1,46 @@
|
|
|
1
|
-
|
|
2
|
-
import Mat4 from "../math/Mat4";
|
|
3
|
-
|
|
4
|
-
const pushMatrix = function(mat: Mat4, stack: Mat4[], id: string): void {
|
|
5
|
-
stack.push(new Mat4(mat));
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
const popMatrix = function(mat: Mat4, stack: Mat4[], id: string): void {
|
|
9
|
-
if (stack.length > 0) {
|
|
10
|
-
mat.assign(stack[stack.length - 1]);
|
|
11
|
-
stack.splice(stack.length - 1, 1);
|
|
12
|
-
}
|
|
13
|
-
else {
|
|
14
|
-
throw new Error(`Matrix stack underflow detected in ${id} matrix`);
|
|
15
|
-
}
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
export default class MatrixState {
|
|
19
|
-
private _projection: Mat4;
|
|
20
|
-
private _view: Mat4;
|
|
21
|
-
private _model: Mat4;
|
|
22
|
-
private _projMatrixStack: Mat4[];
|
|
23
|
-
private _viewMatrixStack: Mat4[];
|
|
24
|
-
private _modelMatrixStack: Mat4[];
|
|
25
|
-
|
|
26
|
-
constructor() {
|
|
27
|
-
this._projection = Mat4.MakeIdentity();
|
|
28
|
-
this._view = Mat4.MakeIdentity();
|
|
29
|
-
this._model = Mat4.MakeIdentity();
|
|
30
|
-
|
|
31
|
-
this._projMatrixStack = [];
|
|
32
|
-
this._viewMatrixStack = [];
|
|
33
|
-
this._modelMatrixStack = [];
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
get projection(): Mat4 { return this._projection; }
|
|
37
|
-
get view(): Mat4 { return this._view; }
|
|
38
|
-
get model(): Mat4 { return this._model; }
|
|
39
|
-
|
|
40
|
-
pushProjection(): void { pushMatrix(this._projection, this._projMatrixStack, 'projection'); }
|
|
41
|
-
popProjection(): void { popMatrix(this._projection, this._projMatrixStack, 'projection'); }
|
|
42
|
-
pushView(): void { pushMatrix(this._view, this._viewMatrixStack, 'view'); }
|
|
43
|
-
popView(): void { popMatrix(this._view, this._viewMatrixStack, 'view'); }
|
|
44
|
-
pushModel(): void { pushMatrix(this._model, this._modelMatrixStack, 'model'); }
|
|
45
|
-
popModel(): void { popMatrix(this._model, this._modelMatrixStack, 'model'); }
|
|
46
|
-
}
|
|
1
|
+
|
|
2
|
+
import Mat4 from "../math/Mat4";
|
|
3
|
+
|
|
4
|
+
const pushMatrix = function(mat: Mat4, stack: Mat4[], id: string): void {
|
|
5
|
+
stack.push(new Mat4(mat));
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
const popMatrix = function(mat: Mat4, stack: Mat4[], id: string): void {
|
|
9
|
+
if (stack.length > 0) {
|
|
10
|
+
mat.assign(stack[stack.length - 1]);
|
|
11
|
+
stack.splice(stack.length - 1, 1);
|
|
12
|
+
}
|
|
13
|
+
else {
|
|
14
|
+
throw new Error(`Matrix stack underflow detected in ${id} matrix`);
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export default class MatrixState {
|
|
19
|
+
private _projection: Mat4;
|
|
20
|
+
private _view: Mat4;
|
|
21
|
+
private _model: Mat4;
|
|
22
|
+
private _projMatrixStack: Mat4[];
|
|
23
|
+
private _viewMatrixStack: Mat4[];
|
|
24
|
+
private _modelMatrixStack: Mat4[];
|
|
25
|
+
|
|
26
|
+
constructor() {
|
|
27
|
+
this._projection = Mat4.MakeIdentity();
|
|
28
|
+
this._view = Mat4.MakeIdentity();
|
|
29
|
+
this._model = Mat4.MakeIdentity();
|
|
30
|
+
|
|
31
|
+
this._projMatrixStack = [];
|
|
32
|
+
this._viewMatrixStack = [];
|
|
33
|
+
this._modelMatrixStack = [];
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
get projection(): Mat4 { return this._projection; }
|
|
37
|
+
get view(): Mat4 { return this._view; }
|
|
38
|
+
get model(): Mat4 { return this._model; }
|
|
39
|
+
|
|
40
|
+
pushProjection(): void { pushMatrix(this._projection, this._projMatrixStack, 'projection'); }
|
|
41
|
+
popProjection(): void { popMatrix(this._projection, this._projMatrixStack, 'projection'); }
|
|
42
|
+
pushView(): void { pushMatrix(this._view, this._viewMatrixStack, 'view'); }
|
|
43
|
+
popView(): void { popMatrix(this._view, this._viewMatrixStack, 'view'); }
|
|
44
|
+
pushModel(): void { pushMatrix(this._model, this._modelMatrixStack, 'model'); }
|
|
45
|
+
popModel(): void { popMatrix(this._model, this._modelMatrixStack, 'model'); }
|
|
46
|
+
}
|