bg2e-js 2.0.1 → 2.0.2
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 +11001 -0
- package/dist/bg2e-js.js.map +1 -0
- package/package.json +17 -6
- package/app/AppController.d.ts +0 -37
- package/app/AppController.js +0 -32
- package/app/Canvas.d.ts +0 -42
- package/app/Canvas.js +0 -98
- package/app/EventBase.js +0 -8
- package/app/KeyboardEvent.js +0 -51
- package/app/MainLoop.d.ts +0 -245
- package/app/MainLoop.js +0 -251
- package/app/MouseEvent.js +0 -77
- package/app/TouchEvent.js +0 -15
- package/base/Color.js +0 -131
- package/base/Environment.js +0 -78
- package/base/Light.js +0 -176
- package/base/Material.js +0 -619
- package/base/PolyList.js +0 -336
- package/base/Texture.js +0 -545
- package/db/Bg2LoaderPlugin.js +0 -113
- package/db/DBPluginApi.js +0 -40
- package/db/Loader.js +0 -91
- package/db/LoaderPlugin.js +0 -26
- package/db/MtlParser.js +0 -7
- package/db/ObjLoaderPlugin.js +0 -51
- package/db/ObjParser.js +0 -233
- package/db/ObjWriterPlugin.js +0 -18
- package/db/VitscnjLoaderPlugin.js +0 -87
- package/db/Writer.js +0 -49
- package/db/WriterPlugin.js +0 -20
- package/debug/DebugRenderer.js +0 -138
- package/debug/WebGLTextureViewer.js +0 -67
- package/manipulation/SelectionBuffer.js +0 -65
- package/manipulation/SelectionHighlight.js +0 -69
- package/manipulation/SelectionIdAssignVisitor.js +0 -86
- package/manipulation/SelectionManager.js +0 -134
- package/manipulation/SelectionMode.js +0 -6
- package/math/Mat3.js +0 -248
- package/math/Mat4.js +0 -694
- package/math/MatrixStrategy.js +0 -23
- package/math/Quat.js +0 -60
- package/math/Vec.js +0 -728
- package/math/constants.js +0 -44
- package/math/functions.js +0 -104
- package/math/index.js +0 -74
- package/phsics/joint.js +0 -124
- package/primitives/arrow.js +0 -58
- package/primitives/cone.js +0 -137
- package/primitives/cube.js +0 -59
- package/primitives/cylinder.js +0 -215
- package/primitives/index.js +0 -13
- package/primitives/plane.js +0 -31
- package/primitives/sphere.js +0 -808
- package/render/BRDFIntegrationMap.js +0 -4
- package/render/Environment.js +0 -105
- package/render/EnvironmentRenderer.js +0 -12
- package/render/FrameBuffer.js +0 -26
- package/render/MaterialRenderer.js +0 -28
- package/render/Pipeline.js +0 -83
- package/render/PolyListRenderer.js +0 -42
- package/render/RenderBuffer.js +0 -189
- package/render/RenderQueue.js +0 -162
- package/render/RenderState.js +0 -82
- package/render/Renderer.js +0 -202
- package/render/SceneAppController.js +0 -208
- package/render/SceneRenderer.js +0 -310
- package/render/Shader.js +0 -21
- package/render/ShadowRenderer.js +0 -159
- package/render/SkyCube.js +0 -77
- package/render/SkySphere.js +0 -94
- package/render/TextureMergerRenderer.js +0 -58
- package/render/TextureRenderer.js +0 -29
- package/render/webgl/FrameBuffer.js +0 -9
- package/render/webgl/MaterialRenderer.js +0 -99
- package/render/webgl/Pipeline.js +0 -82
- package/render/webgl/PolyListRenderer.js +0 -224
- package/render/webgl/RenderBuffer.js +0 -244
- package/render/webgl/Renderer.js +0 -239
- package/render/webgl/SceneRenderer.js +0 -43
- package/render/webgl/ShaderProgram.js +0 -350
- package/render/webgl/ShadowRenderer.js +0 -6
- package/render/webgl/SkyCube.js +0 -15
- package/render/webgl/SkySphere.js +0 -14
- package/render/webgl/State.js +0 -149
- package/render/webgl/TextureRenderer.js +0 -167
- package/render/webgl/VertexBuffer.js +0 -128
- package/scene/Camera.js +0 -378
- package/scene/Chain.js +0 -43
- package/scene/ChainJoint.js +0 -55
- package/scene/Component.js +0 -146
- package/scene/ComponentMap.js +0 -99
- package/scene/Drawable.js +0 -130
- package/scene/EnvironmentComponent.js +0 -123
- package/scene/FindNodeVisitor.js +0 -55
- package/scene/LightComponent.js +0 -146
- package/scene/MatrixState.js +0 -39
- package/scene/Node.js +0 -300
- package/scene/NodeVisitor.js +0 -12
- package/scene/OrbitCameraController.js +0 -407
- package/scene/SmoothOrbitCameraController.js +0 -92
- package/scene/Transform.js +0 -74
- package/scene/index.js +0 -24
- package/shaders/BasicDiffuseColorShader.js +0 -91
- package/shaders/BasicPBRLightShader.js +0 -238
- package/shaders/DebugRenderShader.js +0 -79
- package/shaders/DepthRenderShader.js +0 -69
- package/shaders/IrradianceMapCubeShader.js +0 -99
- package/shaders/PBRLightIBLShader.js +0 -380
- package/shaders/PickSelectionShader.js +0 -75
- package/shaders/PresentDebugFramebufferShader.js +0 -90
- package/shaders/PresentTextureShader.js +0 -73
- package/shaders/SelectionHighlightShader.js +0 -98
- package/shaders/ShaderFunction.js +0 -72
- package/shaders/SkyCubeShader.js +0 -78
- package/shaders/SkySphereShader.js +0 -77
- package/shaders/SpecularMapCubeShader.js +0 -145
- package/shaders/TextureMergerShader.js +0 -127
- package/shaders/webgl_shader_lib.js +0 -187
- package/tools/BinaryResourceProvider.js +0 -15
- package/tools/ImageResourceProvider.js +0 -65
- package/tools/MaterialModifier.js +0 -228
- package/tools/Resource.js +0 -177
- package/tools/ResourceProvider.js +0 -56
- package/tools/TextResourceProvider.js +0 -24
- package/tools/TextureCache.js +0 -44
- package/tools/TextureResourceDatabase.js +0 -87
- package/tools/UserAgent.js +0 -294
- package/tools/VideoResourceProvider.js +0 -51
- package/tools/WriteStrategy.js +0 -22
- package/tools/base64.js +0 -15
- package/tools/crypto.js +0 -15
- package/tools/endiantess.js +0 -15
- package/tools/image.js +0 -15
- package/tools/index.js +0 -33
- package/tools/processType.js +0 -56
|
@@ -1,208 +0,0 @@
|
|
|
1
|
-
import AppController from "../app/AppController";
|
|
2
|
-
import SelectionHighlight from "../manipulation/SelectionHighlight";
|
|
3
|
-
import SelectionManager from "../manipulation/SelectionManager";
|
|
4
|
-
import { registerComponents } from "../scene";
|
|
5
|
-
import Camera from "../scene/Camera";
|
|
6
|
-
import DebugRenderer from "../debug/DebugRenderer";
|
|
7
|
-
import Vec from "../math/Vec";
|
|
8
|
-
|
|
9
|
-
export default class SceneAppController extends AppController {
|
|
10
|
-
get sceneRoot() {
|
|
11
|
-
return this._sceneRoot;
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
get sceneRenderer() {
|
|
15
|
-
return this._sceneRenderer;
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
get environment() {
|
|
19
|
-
return this._environment;
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
get selectionManager() {
|
|
23
|
-
return this._selectionManager;
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
get selectionHighlight() {
|
|
27
|
-
return this._selectionHighlight;
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
get selectionManagerEnabled() {
|
|
31
|
-
return true;
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
get selectionHighlightEnabled() {
|
|
35
|
-
return true;
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
get updateOnInputEvents() {
|
|
39
|
-
return this._updateOnInputEvents ?? true;
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
set updateOnInputEvents(update) {
|
|
43
|
-
this._updateOnInputEvents = update;
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
async loadScene() {
|
|
47
|
-
return new Node("Scene Root");
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
async loadEnvironment() {
|
|
51
|
-
return null;
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
async registerLoaders() {
|
|
55
|
-
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
async loadDone() {
|
|
59
|
-
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
async init() {
|
|
63
|
-
registerComponents();
|
|
64
|
-
|
|
65
|
-
await this.registerLoaders();
|
|
66
|
-
|
|
67
|
-
this._sceneRoot = await this.loadScene();
|
|
68
|
-
|
|
69
|
-
this._environment = await this.loadEnvironment();
|
|
70
|
-
|
|
71
|
-
if (!this._environment) {
|
|
72
|
-
this._environment = this.renderer.factory.environment();
|
|
73
|
-
await this._environment.load(); // Load black environment
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
this._sceneRenderer = this.renderer.factory.scene();
|
|
77
|
-
await this.sceneRenderer.init({ shadowMapSize: new Vec(4096, 4096) });
|
|
78
|
-
if (this.environment) {
|
|
79
|
-
await this.sceneRenderer.setEnvironment(this.environment);
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
await this.sceneRenderer.bindRenderer(this.sceneRoot);
|
|
83
|
-
|
|
84
|
-
if (this.selectionManagerEnabled) {
|
|
85
|
-
this._selectionManager = new SelectionManager(this.renderer);
|
|
86
|
-
await this._selectionManager.init();
|
|
87
|
-
this._selectionManager.sceneRoot = this.sceneRoot;
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
if (this.selectionHighlightEnabled) {
|
|
91
|
-
this._selectionHighlight = new SelectionHighlight(this.renderer);
|
|
92
|
-
await this._selectionHighlight.init();
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
this._debugRenderer = DebugRenderer.Get(this.renderer);
|
|
96
|
-
await this._debugRenderer.init();
|
|
97
|
-
|
|
98
|
-
await this.loadDone();
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
reshape(width,height) {
|
|
102
|
-
this.sceneRenderer.resize(this.sceneRoot,width,height);
|
|
103
|
-
this.selectionManager?.setViewportSize(width,height);
|
|
104
|
-
this.selectionHighlight?.setViewportSize(width,height);
|
|
105
|
-
this._debugRenderer.setViewportSize(width,height);
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
async frame(delta) {
|
|
109
|
-
this._debugRenderer.beginFrame();
|
|
110
|
-
|
|
111
|
-
await this.sceneRenderer.frame(this.sceneRoot, delta);
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
display() {
|
|
115
|
-
this.sceneRenderer.draw();
|
|
116
|
-
const camera = Camera.GetMain(this.sceneRoot);
|
|
117
|
-
this.selectionHighlight && this.selectionHighlight.draw(this.sceneRoot, camera);
|
|
118
|
-
this._debugRenderer.draw(camera);
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
destroy() {
|
|
122
|
-
this.sceneRenderer.destroy();
|
|
123
|
-
if (this.selectionManagerEnabled) {
|
|
124
|
-
this.selectionManager.destroy();
|
|
125
|
-
}
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
keyDown(evt) {
|
|
129
|
-
this.sceneRenderer.keyDown(this.sceneRoot,evt);
|
|
130
|
-
if (this.updateOnInputEvents) {
|
|
131
|
-
this.mainLoop.postRedisplay();
|
|
132
|
-
}
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
keyUp(evt) {
|
|
136
|
-
this.sceneRenderer.keyUp(this.sceneRoot,evt);
|
|
137
|
-
if (this.updateOnInputEvents) {
|
|
138
|
-
this.mainLoop.postRedisplay();
|
|
139
|
-
}
|
|
140
|
-
}
|
|
141
|
-
|
|
142
|
-
mouseUp(evt) {
|
|
143
|
-
this.sceneRenderer.mouseUp(this.sceneRoot,evt);
|
|
144
|
-
this.selectionManager?.mouseUp(evt);
|
|
145
|
-
if (this.updateOnInputEvents) {
|
|
146
|
-
this.mainLoop.postRedisplay();
|
|
147
|
-
}
|
|
148
|
-
}
|
|
149
|
-
|
|
150
|
-
mouseDown(evt) {
|
|
151
|
-
this.sceneRenderer.mouseDown(this.sceneRoot,evt);
|
|
152
|
-
this.selectionManager?.mouseDown(evt);
|
|
153
|
-
if (this.updateOnInputEvents) {
|
|
154
|
-
this.mainLoop.postRedisplay();
|
|
155
|
-
}
|
|
156
|
-
}
|
|
157
|
-
|
|
158
|
-
mouseMove(evt) {
|
|
159
|
-
this.sceneRenderer.mouseMove(this.sceneRoot,evt);
|
|
160
|
-
if (this.updateOnInputEvents) {
|
|
161
|
-
this.mainLoop.postRedisplay();
|
|
162
|
-
}
|
|
163
|
-
}
|
|
164
|
-
|
|
165
|
-
mouseOut(evt) {
|
|
166
|
-
this.sceneRenderer.mouseOut(this.sceneRoot,evt);
|
|
167
|
-
if (this.updateOnInputEvents) {
|
|
168
|
-
this.mainLoop.postRedisplay();
|
|
169
|
-
}
|
|
170
|
-
}
|
|
171
|
-
|
|
172
|
-
mouseDrag(evt) {
|
|
173
|
-
this.sceneRenderer.mouseDrag(this.sceneRoot,evt);
|
|
174
|
-
if (this.updateOnInputEvents) {
|
|
175
|
-
this.mainLoop.postRedisplay();
|
|
176
|
-
}
|
|
177
|
-
}
|
|
178
|
-
|
|
179
|
-
mouseWheel(evt) {
|
|
180
|
-
this.sceneRenderer.mouseWheel(this.sceneRoot,evt);
|
|
181
|
-
if (this.updateOnInputEvents) {
|
|
182
|
-
this.mainLoop.postRedisplay();
|
|
183
|
-
}
|
|
184
|
-
}
|
|
185
|
-
|
|
186
|
-
touchStart(evt) {
|
|
187
|
-
this.sceneRenderer.touchStart(this.sceneRoot,evt);
|
|
188
|
-
this.selectionManager?.touchStart(evt);
|
|
189
|
-
if (this.updateOnInputEvents) {
|
|
190
|
-
this.mainLoop.postRedisplay();
|
|
191
|
-
}
|
|
192
|
-
}
|
|
193
|
-
|
|
194
|
-
touchMove(evt) {
|
|
195
|
-
this.sceneRenderer.touchMove(this.sceneRoot,evt);
|
|
196
|
-
if (this.updateOnInputEvents) {
|
|
197
|
-
this.mainLoop.postRedisplay();
|
|
198
|
-
}
|
|
199
|
-
}
|
|
200
|
-
|
|
201
|
-
touchEnd(evt) {
|
|
202
|
-
this.sceneRenderer.touchEnd(this.sceneRoot,evt);
|
|
203
|
-
this.selectionManager?.touchEnd(evt);
|
|
204
|
-
if (this.updateOnInputEvents) {
|
|
205
|
-
this.mainLoop.postRedisplay();
|
|
206
|
-
}
|
|
207
|
-
}
|
|
208
|
-
}
|
package/render/SceneRenderer.js
DELETED
|
@@ -1,310 +0,0 @@
|
|
|
1
|
-
import { RenderLayer } from "../base/PolyList";
|
|
2
|
-
import { BlendFunction } from "./Pipeline";
|
|
3
|
-
import RenderQueue from "./RenderQueue";
|
|
4
|
-
import NodeVisitor from "../scene/NodeVisitor";
|
|
5
|
-
import Mat4 from "../math/Mat4";
|
|
6
|
-
import Vec from "../math/Vec";
|
|
7
|
-
import Camera from "../scene/Camera";
|
|
8
|
-
import FindNodeVisitor from "../scene/FindNodeVisitor";
|
|
9
|
-
import Transform from "../scene/Transform";
|
|
10
|
-
import { bindRenderer, init } from "../scene/Node";
|
|
11
|
-
import LightComponent from "../scene/LightComponent";
|
|
12
|
-
|
|
13
|
-
export class FrameVisitor extends NodeVisitor {
|
|
14
|
-
constructor(renderQueue) {
|
|
15
|
-
super();
|
|
16
|
-
this._renderQueue = renderQueue;
|
|
17
|
-
this._delta = 0;
|
|
18
|
-
this._modelMatrix = Mat4.MakeIdentity();
|
|
19
|
-
this._matrixStack = [];
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
get delta() { return this._delta; }
|
|
23
|
-
set delta(d) { this._delta = d; }
|
|
24
|
-
|
|
25
|
-
get modelMatrix() { return this._modelMatrix; }
|
|
26
|
-
|
|
27
|
-
visit(node) {
|
|
28
|
-
this._matrixStack.push(new Mat4(this._modelMatrix));
|
|
29
|
-
node.frame(this._delta, this._modelMatrix, this._renderQueue);
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
didVisit(node) {
|
|
33
|
-
this._modelMatrix = this._matrixStack[this._matrixStack.length - 1] || Mat4.MakeIdentity();
|
|
34
|
-
this._matrixStack.pop();
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
export class BindRendererVisitor extends NodeVisitor {
|
|
39
|
-
constructor(renderer) {
|
|
40
|
-
super(renderer);
|
|
41
|
-
this._renderer = renderer;
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
visit(node) {
|
|
45
|
-
bindRenderer(node, this._renderer);
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
export class InitVisitor extends NodeVisitor {
|
|
50
|
-
constructor() {
|
|
51
|
-
super();
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
async asyncVisit(node) {
|
|
55
|
-
await init(node);
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
export class EventCallbackVisitor extends NodeVisitor {
|
|
60
|
-
constructor(callbackName) {
|
|
61
|
-
super();
|
|
62
|
-
this._callbackName = callbackName;
|
|
63
|
-
this._event = null;
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
set event(evt) {
|
|
67
|
-
this._event = evt;
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
get event() {
|
|
71
|
-
return this._event;
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
visit(node) {
|
|
75
|
-
node[this._callbackName](this._event);
|
|
76
|
-
}
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
export default class SceneRenderer {
|
|
80
|
-
constructor(renderer) {
|
|
81
|
-
this._renderer = renderer;
|
|
82
|
-
this._keyDownVisitor = new EventCallbackVisitor('keyDown');
|
|
83
|
-
this._keyUpVisitor = new EventCallbackVisitor('keyUp');
|
|
84
|
-
this._mouseUpVisitor = new EventCallbackVisitor('mouseUp');
|
|
85
|
-
this._mouseDownVisitor = new EventCallbackVisitor('mouseDown');
|
|
86
|
-
this._mouseMoveVisitor = new EventCallbackVisitor('mouseMove');
|
|
87
|
-
this._mouseOutVisitor = new EventCallbackVisitor('mouseOut');
|
|
88
|
-
this._mouseDragVisitor = new EventCallbackVisitor('mouseDrag');
|
|
89
|
-
this._mouseWheelVisitor = new EventCallbackVisitor('mouseWheel');
|
|
90
|
-
this._touchStartVisitor = new EventCallbackVisitor('touchStart');
|
|
91
|
-
this._touchMoveVisitor = new EventCallbackVisitor('touchMove');
|
|
92
|
-
this._touchEndVisitor = new EventCallbackVisitor('touchEnd');
|
|
93
|
-
|
|
94
|
-
// This will be the EnvironmentComponent component, if one is defined in the scene.
|
|
95
|
-
this._sceneEnvironment = null;
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
get renderer() {
|
|
99
|
-
return this._renderer;
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
get renderQueue() {
|
|
103
|
-
return this._renderQueue;
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
async init({ shadowMapSize = new Vec(1024, 1024) } = {}) {
|
|
107
|
-
if (typeof(shadowMapSize) === "number") {
|
|
108
|
-
shadowMapSize = new Vec(shadowMapSize, shadowMapSize);
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
// TODO: Create function to resize shadow map
|
|
112
|
-
this._shadowMapSize = shadowMapSize;
|
|
113
|
-
|
|
114
|
-
this._mainDirectionalLight = null;
|
|
115
|
-
|
|
116
|
-
this._opaquePipeline = this.renderer.factory.pipeline();
|
|
117
|
-
this._opaquePipeline.setBlendState({ enabled: false });
|
|
118
|
-
this._opaquePipeline.create();
|
|
119
|
-
|
|
120
|
-
this._transparentPipeline = this.renderer.factory.pipeline();
|
|
121
|
-
this._transparentPipeline.setBlendState({
|
|
122
|
-
enabled: true,
|
|
123
|
-
blendFuncSrc: BlendFunction.SRC_ALPHA,
|
|
124
|
-
blendFuncDst: BlendFunction.ONE_MINUS_SRC_ALPHA,
|
|
125
|
-
blendFuncSrcAlpha: BlendFunction.ONE,
|
|
126
|
-
blendFuncDstAlpha: BlendFunction.ONE_MINUS_SRC_ALPHA
|
|
127
|
-
});
|
|
128
|
-
this._transparentPipeline.create();
|
|
129
|
-
|
|
130
|
-
this._renderQueue = new RenderQueue(this.renderer);
|
|
131
|
-
this._initVisitor = new InitVisitor();
|
|
132
|
-
this._frameVisitor = new FrameVisitor(this._renderQueue);
|
|
133
|
-
|
|
134
|
-
this._skyCube = this.renderer.factory.skyCube();
|
|
135
|
-
|
|
136
|
-
this._shadowRenderer = this.renderer.factory.shadowRenderer();
|
|
137
|
-
await this._shadowRenderer.create(this._shadowMapSize);
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
async setEnvironment(env) {
|
|
141
|
-
this._environment = env;
|
|
142
|
-
this._skyCube.load(this._environment.environmentMap);
|
|
143
|
-
}
|
|
144
|
-
|
|
145
|
-
get environment() {
|
|
146
|
-
return this._environment;
|
|
147
|
-
}
|
|
148
|
-
|
|
149
|
-
get defaultViewMatrix() {
|
|
150
|
-
return this._defaultViewMatrix || Mat4.MakeIdentity();
|
|
151
|
-
}
|
|
152
|
-
|
|
153
|
-
set defaultViewMatrix(mat) {
|
|
154
|
-
this._defaultViewMatrix = mat;
|
|
155
|
-
}
|
|
156
|
-
|
|
157
|
-
get defaultProjectionMatrix() {
|
|
158
|
-
return this._defaultProjectionMatrix || Mat4.MakePerspective(55,this.renderer.viewport.aspectRatio, 0.2, 100.0);
|
|
159
|
-
}
|
|
160
|
-
|
|
161
|
-
set defaultProjectionMatrix(mat) {
|
|
162
|
-
this._defaultProjectionMatrix = mat;
|
|
163
|
-
}
|
|
164
|
-
|
|
165
|
-
async bindRenderer(sceneRoot) {
|
|
166
|
-
const bindRendererVisitor = new BindRendererVisitor(this.renderer);
|
|
167
|
-
sceneRoot.accept(bindRendererVisitor);
|
|
168
|
-
|
|
169
|
-
await sceneRoot.asyncAccept(this._initVisitor);
|
|
170
|
-
|
|
171
|
-
const findVisitor = new FindNodeVisitor();
|
|
172
|
-
findVisitor.hasComponents("Environment");
|
|
173
|
-
sceneRoot.accept(findVisitor);
|
|
174
|
-
if (findVisitor.result.length) {
|
|
175
|
-
const comp = findVisitor.result[0].component("Environment");
|
|
176
|
-
this.setEnvironment(comp.environment);
|
|
177
|
-
this._sceneEnvironment = comp;
|
|
178
|
-
}
|
|
179
|
-
}
|
|
180
|
-
|
|
181
|
-
resize(sceneRoot, width,height) {
|
|
182
|
-
this.renderer.viewport = new Vec([0, 0, width, height]);
|
|
183
|
-
this.renderer.canvas.updateViewportSize();
|
|
184
|
-
const mainCamera = Camera.GetMain(sceneRoot);
|
|
185
|
-
if (mainCamera) {
|
|
186
|
-
mainCamera.resize(width,height);
|
|
187
|
-
}
|
|
188
|
-
}
|
|
189
|
-
|
|
190
|
-
async frame(sceneRoot,delta) {
|
|
191
|
-
if (sceneRoot.sceneChanged) {
|
|
192
|
-
await sceneRoot.asyncAccept(this._initVisitor);
|
|
193
|
-
}
|
|
194
|
-
this._sceneRoot = sceneRoot;
|
|
195
|
-
|
|
196
|
-
this._renderQueue.newFrame();
|
|
197
|
-
this._frameVisitor.delta = delta;
|
|
198
|
-
this._frameVisitor.modelMatrix.identity();
|
|
199
|
-
|
|
200
|
-
const mainCamera = Camera.GetMain(sceneRoot);
|
|
201
|
-
|
|
202
|
-
let viewMatrix = this.defaultViewMatrix;
|
|
203
|
-
let projectionMatrix = this.defaultProjectionMatrix;
|
|
204
|
-
if (mainCamera) {
|
|
205
|
-
projectionMatrix = mainCamera.projectionMatrix;
|
|
206
|
-
viewMatrix = Mat4.GetInverted(Transform.GetWorldMatrix(mainCamera.node));
|
|
207
|
-
}
|
|
208
|
-
|
|
209
|
-
this._renderQueue.viewMatrix = viewMatrix;
|
|
210
|
-
this._renderQueue.projectionMatrix = projectionMatrix;
|
|
211
|
-
|
|
212
|
-
sceneRoot.accept(this._frameVisitor);
|
|
213
|
-
|
|
214
|
-
this._skyCube.updateRenderState({
|
|
215
|
-
viewMatrix: viewMatrix,
|
|
216
|
-
projectionMatrix: projectionMatrix
|
|
217
|
-
});
|
|
218
|
-
}
|
|
219
|
-
|
|
220
|
-
draw({ clearBuffers = true, drawSky = true } = {}) {
|
|
221
|
-
const mainLight = LightComponent.GetMainDirectionalLight(this._sceneRoot);
|
|
222
|
-
const camera = Camera.GetMain(this._sceneRoot);
|
|
223
|
-
|
|
224
|
-
// Update the light projection based on the camera focus distance, to optimize
|
|
225
|
-
// the shadow map size
|
|
226
|
-
if (mainLight && camera) {
|
|
227
|
-
const focus = camera.focusDistance;
|
|
228
|
-
const lightProjection = Mat4.MakeOrtho(-focus,focus,-focus,focus,0.1,500.0);
|
|
229
|
-
mainLight.light.projection = lightProjection;
|
|
230
|
-
}
|
|
231
|
-
if (mainLight) {
|
|
232
|
-
this._shadowRenderer.update(camera, mainLight, this._renderQueue);
|
|
233
|
-
}
|
|
234
|
-
|
|
235
|
-
if (clearBuffers) {
|
|
236
|
-
this.renderer.frameBuffer.clear();
|
|
237
|
-
}
|
|
238
|
-
|
|
239
|
-
if (this.environment && !this.environment.updated) {
|
|
240
|
-
this.environment.updateMaps();
|
|
241
|
-
}
|
|
242
|
-
|
|
243
|
-
if (drawSky && (!this._sceneEnvironment || this._sceneEnvironment.showSkybox)) {
|
|
244
|
-
this._skyCube.draw();
|
|
245
|
-
}
|
|
246
|
-
|
|
247
|
-
this._renderQueue.draw(RenderLayer.OPAQUE_DEFAULT);
|
|
248
|
-
this._renderQueue.draw(RenderLayer.TRANSPARENT_DEFAULT);
|
|
249
|
-
}
|
|
250
|
-
|
|
251
|
-
destroy() {
|
|
252
|
-
|
|
253
|
-
}
|
|
254
|
-
|
|
255
|
-
keyDown(sceneRoot, evt) {
|
|
256
|
-
this._keyDownVisitor.event = evt;
|
|
257
|
-
sceneRoot.accept(this._keyDownVisitor);
|
|
258
|
-
}
|
|
259
|
-
|
|
260
|
-
keyUp(sceneRoot, evt) {
|
|
261
|
-
this._keyUpVisitor.event = evt;
|
|
262
|
-
sceneRoot.accept(this._keyUpVisitor);
|
|
263
|
-
}
|
|
264
|
-
|
|
265
|
-
mouseUp(sceneRoot, evt) {
|
|
266
|
-
this._mouseUpVisitor.event = evt;
|
|
267
|
-
sceneRoot.accept(this._mouseUpVisitor);
|
|
268
|
-
}
|
|
269
|
-
|
|
270
|
-
mouseDown(sceneRoot, evt) {
|
|
271
|
-
this._mouseDownVisitor.event = evt;
|
|
272
|
-
sceneRoot.accept(this._mouseDownVisitor);
|
|
273
|
-
}
|
|
274
|
-
|
|
275
|
-
mouseMove(sceneRoot, evt) {
|
|
276
|
-
this._mouseMoveVisitor.event = evt;
|
|
277
|
-
sceneRoot.accept(this._mouseMoveVisitor);
|
|
278
|
-
}
|
|
279
|
-
|
|
280
|
-
mouseOut(sceneRoot, evt) {
|
|
281
|
-
this._mouseOutVisitor.event = evt;
|
|
282
|
-
sceneRoot.accept(this._mouseOutVisitor);
|
|
283
|
-
}
|
|
284
|
-
|
|
285
|
-
mouseDrag(sceneRoot, evt) {
|
|
286
|
-
this._mouseDragVisitor.event = evt;
|
|
287
|
-
sceneRoot.accept(this._mouseDragVisitor);
|
|
288
|
-
}
|
|
289
|
-
|
|
290
|
-
mouseWheel(sceneRoot, evt) {
|
|
291
|
-
this._mouseWheelVisitor.event = evt;
|
|
292
|
-
sceneRoot.accept(this._mouseWheelVisitor);
|
|
293
|
-
}
|
|
294
|
-
|
|
295
|
-
touchStart(sceneRoot, evt) {
|
|
296
|
-
this._touchStartVisitor.event = evt;
|
|
297
|
-
sceneRoot.accept(this._touchStartVisitor);
|
|
298
|
-
}
|
|
299
|
-
|
|
300
|
-
touchMove(sceneRoot, evt) {
|
|
301
|
-
this._touchMoveVisitor.event = evt;
|
|
302
|
-
sceneRoot.accept(this._touchMoveVisitor);
|
|
303
|
-
}
|
|
304
|
-
|
|
305
|
-
touchEnd(sceneRoot, evt) {
|
|
306
|
-
this._touchEndVisitor.event = evt;
|
|
307
|
-
sceneRoot.accept(this._touchEndVisitor);
|
|
308
|
-
}
|
|
309
|
-
|
|
310
|
-
}
|
package/render/Shader.js
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import Material from "../base/Material";
|
|
2
|
-
|
|
3
|
-
export default class Shader {
|
|
4
|
-
constructor(renderer) {
|
|
5
|
-
this._renderer = renderer;
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
get renderer() { return this._renderer; }
|
|
9
|
-
|
|
10
|
-
async load() {
|
|
11
|
-
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
setup(plistRenderer, materialRenderer, modelMatrix, viewMatrix, projectionMatrix) {
|
|
15
|
-
throw new Error("Error: using an abstract implementation of render.Shader.");
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
destroy() {
|
|
19
|
-
throw new Error("Error: using an abstract implementation of render.Shader.destroy()");
|
|
20
|
-
}
|
|
21
|
-
}
|
package/render/ShadowRenderer.js
DELETED
|
@@ -1,159 +0,0 @@
|
|
|
1
|
-
import { RenderLayer } from "../base/PolyList";
|
|
2
|
-
import Texture, {
|
|
3
|
-
TextureComponentFormat,
|
|
4
|
-
TextureRenderTargetAttachment,
|
|
5
|
-
TextureWrap
|
|
6
|
-
} from "../base/Texture";
|
|
7
|
-
import Mat4 from "../math/Mat4";
|
|
8
|
-
import Vec from "../math/Vec";
|
|
9
|
-
import Color from "../base/Color";
|
|
10
|
-
import Camera from "../scene/Camera";
|
|
11
|
-
import LightComponent from "../scene/LightComponent";
|
|
12
|
-
import Transform from "../scene/Transform";
|
|
13
|
-
import DebugRenderer from "../debug/DebugRenderer";
|
|
14
|
-
import DepthRenderShader from "../shaders/DepthRenderShader";
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
export default class ShadowRenderer {
|
|
18
|
-
constructor(renderer) {
|
|
19
|
-
this._renderer = renderer;
|
|
20
|
-
this._shadowMapRenderDistance = 100;
|
|
21
|
-
this._debug = false;
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
get renderer() { return this._renderer; }
|
|
25
|
-
|
|
26
|
-
get size() {
|
|
27
|
-
return this._size;
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
get shadowMapRenderDistance() {
|
|
31
|
-
return this._shadowMapRenderDistance;
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
get debug() {
|
|
35
|
-
return this._debug;
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
set debug(d) {
|
|
39
|
-
this._debug = d;
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
set shadowMapRenderDistance(d) {
|
|
43
|
-
this._shadowMapRenderDistance = d;
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
// TODO: set size. Update the shadow map size
|
|
47
|
-
|
|
48
|
-
get depthTexture() {
|
|
49
|
-
return this._depthTexture;
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
async create(size = new Vec(1024, 1024)) {
|
|
53
|
-
this._size = size;
|
|
54
|
-
|
|
55
|
-
this._texture = new Texture();
|
|
56
|
-
this._texture.name = `ShadowMap_${ size.width }x${ size.height }`;
|
|
57
|
-
this._texture.renderTargetAttachment = TextureRenderTargetAttachment.COLOR_ATTACHMENT_0;
|
|
58
|
-
this._texture.componentFormat = TextureComponentFormat.UNSIGNED_BYTE;
|
|
59
|
-
this._texture.wrapModeXY = TextureWrap.CLAMP;
|
|
60
|
-
|
|
61
|
-
this._renderBuffer = this.renderer.factory.renderBuffer();
|
|
62
|
-
|
|
63
|
-
await this._renderBuffer.attachTexture(this._texture);
|
|
64
|
-
|
|
65
|
-
this._depthTexture = new Texture();
|
|
66
|
-
this._depthTexture.name = `ShadowMapDepth_${ size.width }x${ size.height }`;
|
|
67
|
-
this._depthTexture.renderTargetAttachment = TextureRenderTargetAttachment.DEPTH_ATTACHMENT;
|
|
68
|
-
this._depthTexture.componentFormat = TextureComponentFormat.UNSIGNED_BYTE;
|
|
69
|
-
this._depthTexture.wrapModeXY = TextureWrap.CLAMP;
|
|
70
|
-
await this._renderBuffer.attachTexture(this._depthTexture);
|
|
71
|
-
|
|
72
|
-
this._renderBuffer.size = this._size;
|
|
73
|
-
|
|
74
|
-
this._shader = new DepthRenderShader(this.renderer);
|
|
75
|
-
await this._shader.load();
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
getLightTransform(camera, light) {
|
|
79
|
-
let cameraNode = null;
|
|
80
|
-
if (camera instanceof Camera) {
|
|
81
|
-
cameraNode = camera.node;
|
|
82
|
-
}
|
|
83
|
-
else if (camera instanceof Node) {
|
|
84
|
-
cameraNode = camera;
|
|
85
|
-
camera = cameraNode.camera;
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
if (!cameraNode || !camera) {
|
|
89
|
-
throw Error(`ShadowRenderer.getLightPosition(): invalid camera parameter. Camera must be a Node or a Camera component, and the camera must be added to the scene.`);
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
let lightNode = null;
|
|
93
|
-
if (light instanceof LightComponent) {
|
|
94
|
-
lightNode = light.node;
|
|
95
|
-
}
|
|
96
|
-
else if (light instanceof Node) {
|
|
97
|
-
lightNode = light;
|
|
98
|
-
light = light.lightComponent;
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
if (!lightNode || !light) {
|
|
102
|
-
throw Error(`ShadowRenderer.getLightPosition(): invalid light. Light must be a Node or a LightComponent`);
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
// Get the camera focus point
|
|
106
|
-
const focus = camera.focusDistance;
|
|
107
|
-
const cameraTransform = Transform.GetWorldMatrix(cameraNode);
|
|
108
|
-
const cameraPos = Vec.Add(Mat4.GetPosition(cameraTransform), Vec.Mult(cameraTransform.forwardVector, -focus));
|
|
109
|
-
|
|
110
|
-
// Get the light rotation vector and scale it to the light shadow map render distance
|
|
111
|
-
const lightTransform = Transform.GetWorldMatrix(lightNode);
|
|
112
|
-
const lightVector = Mat4.GetRotation(lightTransform).forwardVector;
|
|
113
|
-
lightVector.scale(this._shadowMapRenderDistance);
|
|
114
|
-
|
|
115
|
-
// Get the light render position, adding the camera focus point to the light vector
|
|
116
|
-
const lightPos = Vec.Add(cameraPos, lightVector);
|
|
117
|
-
|
|
118
|
-
// Set the light render position to the light transform matrix
|
|
119
|
-
lightTransform.setPosition(lightPos);
|
|
120
|
-
|
|
121
|
-
if (this._debug) {
|
|
122
|
-
DebugRenderer.Get(this._renderer).drawSphere({ radius: 0.1, color: Color.Red(), position: cameraPos });
|
|
123
|
-
DebugRenderer.Get(this.renderer).drawSphere({ radius: 0.1, color: Color.Blue(), position: lightPos });
|
|
124
|
-
DebugRenderer.Get(this.renderer).drawArrow({ length: 0.8, color: Color.Green(), transformMatrix: lightTransform });
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
return lightTransform;
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
update(camera, lightComponent, renderQueue) {
|
|
131
|
-
const viewMatrix = Mat4.GetInverted(this.getLightTransform(camera, lightComponent));
|
|
132
|
-
|
|
133
|
-
this._renderBuffer.update(() => {
|
|
134
|
-
this._renderBuffer.renderer.state.clear();
|
|
135
|
-
const layer = RenderLayer.OPAQUE_DEFAULT;
|
|
136
|
-
const queue = renderQueue.getQueue(layer);
|
|
137
|
-
if (queue) {
|
|
138
|
-
|
|
139
|
-
if (typeof(queue.beginOperation) === "function") {
|
|
140
|
-
queue.beginOperation(layer);
|
|
141
|
-
}
|
|
142
|
-
queue.queue.forEach(rs => {
|
|
143
|
-
rs.draw({
|
|
144
|
-
overrideShader: this._shader,
|
|
145
|
-
overrideViewMatrix: viewMatrix,
|
|
146
|
-
overrideProjectionMatrix: lightComponent.light.projection
|
|
147
|
-
});
|
|
148
|
-
});
|
|
149
|
-
if (typeof(queue.endOperation) === "function") {
|
|
150
|
-
queue.endOperation(layer);
|
|
151
|
-
}
|
|
152
|
-
}
|
|
153
|
-
});
|
|
154
|
-
|
|
155
|
-
// Set the depthTexture to the light component. If the shader needs the depth texture, it will use it
|
|
156
|
-
lightComponent.depthTexture = this._depthTexture;
|
|
157
|
-
lightComponent.viewMatrix = viewMatrix;
|
|
158
|
-
}
|
|
159
|
-
}
|