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,42 +0,0 @@
|
|
|
1
|
-
|
|
2
|
-
export default class PolyListRenderer {
|
|
3
|
-
constructor(renderer,polyList) {
|
|
4
|
-
if (polyList.renderer) {
|
|
5
|
-
throw new Error("Invalid initialization of polyList renderer: the polyList is already controlled by another polyList renderer.")
|
|
6
|
-
}
|
|
7
|
-
this._renderer = renderer;
|
|
8
|
-
this._polyList = polyList;
|
|
9
|
-
this._polyList._renderer = this;
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
get polyList() {
|
|
13
|
-
return this._polyList;
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
get renderer() {
|
|
17
|
-
return this._renderer;
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
init() {
|
|
21
|
-
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
// Updates the internal state of the renderer. It is necessary to call this
|
|
25
|
-
// function if the polyList has been modified, so that the internal objects
|
|
26
|
-
// of the specific rendering API are updated.
|
|
27
|
-
refresh() {
|
|
28
|
-
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
bindBuffers() {
|
|
32
|
-
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
draw() {
|
|
36
|
-
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
destroy() {
|
|
40
|
-
|
|
41
|
-
}
|
|
42
|
-
}
|
package/render/RenderBuffer.js
DELETED
|
@@ -1,189 +0,0 @@
|
|
|
1
|
-
import Texture, { TextureDataType, TextureTarget, TextureRenderTargetAttachmentNames } from "../base/Texture";
|
|
2
|
-
import Vec from "../math/Vec";
|
|
3
|
-
import Mat4 from "../math/Mat4";
|
|
4
|
-
|
|
5
|
-
export const RenderBufferType = {
|
|
6
|
-
UNINITIALIZED: 0,
|
|
7
|
-
TEXTURE: 1,
|
|
8
|
-
CUBE_MAP: 2
|
|
9
|
-
};
|
|
10
|
-
|
|
11
|
-
export const RenderBufferTypeName = {
|
|
12
|
-
0: 'UNINITIALIZED',
|
|
13
|
-
1: 'TEXTURE',
|
|
14
|
-
2: 'CUBE_MAP'
|
|
15
|
-
};
|
|
16
|
-
|
|
17
|
-
export const CubeMapFace = {
|
|
18
|
-
NONE: 0,
|
|
19
|
-
POSITIVE_X: 1,
|
|
20
|
-
NEGATIVE_X: 2,
|
|
21
|
-
POSITIVE_Y: 3,
|
|
22
|
-
NEGATIVE_Y: 4,
|
|
23
|
-
POSITIVE_Z: 5,
|
|
24
|
-
NEGATIVE_Z: 6
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
function getTargetType(texture) {
|
|
28
|
-
if (texture.target === TextureTarget.TEXTURE_2D) {
|
|
29
|
-
return RenderBufferType.TEXTURE;
|
|
30
|
-
}
|
|
31
|
-
else if (texture.target === TextureTarget.CUBE_MAP) {
|
|
32
|
-
return RenderBufferType.CUBE_MAP;
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
function getRenderBufferTypeName(type) {
|
|
37
|
-
return RenderBufferTypeName[type];
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
export default class RenderBuffer {
|
|
42
|
-
constructor(renderer, size = new Vec([512,512])) {
|
|
43
|
-
this._renderer = renderer;
|
|
44
|
-
this._attachments = {};
|
|
45
|
-
this._size = size;
|
|
46
|
-
this._dirty = true;
|
|
47
|
-
this._type = RenderBufferType.UNINITIALIZED;
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
get renderer() { return this._renderer; }
|
|
51
|
-
|
|
52
|
-
get type() { return this._type; }
|
|
53
|
-
|
|
54
|
-
get size() { return this._size; }
|
|
55
|
-
|
|
56
|
-
set size(s) {
|
|
57
|
-
this._size = new Vec(s);
|
|
58
|
-
for (const att in this.attachments) {
|
|
59
|
-
const textureRenderer = this.attachments[att];
|
|
60
|
-
const texture = textureRenderer.texture;
|
|
61
|
-
if (!Vec.Equals(texture.size, this.size)) {
|
|
62
|
-
texture.size = this.size;
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
this._dirty = true;
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
// This is an object of type { TextureRenderTargetAttachmentName: TextureRenderer }
|
|
69
|
-
get attachments() { return this._attachments; }
|
|
70
|
-
|
|
71
|
-
getTextureRenderer(attachment) {
|
|
72
|
-
return this._attachments[attachment];
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
getTexture(attachment) {
|
|
76
|
-
return this.getAttachment(attachment)?.texture;
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
get dirty() { return this._dirty; }
|
|
80
|
-
|
|
81
|
-
setUpdated(updated = true) { this._dirty = !updated; }
|
|
82
|
-
|
|
83
|
-
async attachTexture(texture) {
|
|
84
|
-
if (this._attachments[texture.renderTargetAttachment]) {
|
|
85
|
-
throw new Error(`RenderBuffer.attachTexture(): The attachment is occupied by another texture ${TextureRenderTargetAttachmentNames[texture.renderTargetAttachment]}`);
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
if (this.type !== RenderBufferType.UNINITIALIZED) {
|
|
89
|
-
const type = getTargetType(texture);
|
|
90
|
-
if (this.type !== type) {
|
|
91
|
-
throw new Error(`Invalid texture attachment. RenderBuffer is ${ getRenderBufferTypeName(this.type) }, but the new attachment is ${ getRenderBufferTypeName(type) }`);
|
|
92
|
-
}
|
|
93
|
-
}
|
|
94
|
-
else {
|
|
95
|
-
this._type = getTargetType(texture);
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
texture.dataType = TextureDataType.RENDER_TARGET;
|
|
99
|
-
texture.size = this.size;
|
|
100
|
-
await texture.loadImageData();
|
|
101
|
-
const textureRenderer = this.renderer.factory.texture(texture);
|
|
102
|
-
this._attachments[texture.renderTargetAttachment] = textureRenderer;
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
detachTexture(texture) {
|
|
106
|
-
const textureRenderer = this._attachments[texture.renderTargetAttachment];
|
|
107
|
-
if (!textureRenderer) {
|
|
108
|
-
throw new Error(`RenderBuffer.detachTexture(): no texture attached to ${TextureRenderTargetAttachmentNames[texture.renderTargetAttachment]}`);
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
if (textureRenderer.texture !== texture) {
|
|
112
|
-
throw new Error(`RenderBuffer.detachTexture(): the texture is not attached to ${TextureRenderTargetAttachmentNames[texture.renderTargetAttachment]}`);
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
this._attachments[texture.renderTargetAttachment] = null;
|
|
116
|
-
textureRenderer.deleteTexture();
|
|
117
|
-
this._dirty = true;
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
beginUpdate(textureFace = CubeMapFace.NONE) {
|
|
121
|
-
throw new Error("RenderBuffer.beginUpdate(): calling base implementation.");
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
endUpdate(textureFace = CubeMapFace.NONE) {
|
|
125
|
-
throw new Error("RenderBuffer.endUpdate(): calling base implementation.");
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
destroy() {
|
|
129
|
-
throw new Error("RenderBuffer.destory(): calling base implementation.");
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
get frameBuffer() {
|
|
133
|
-
throw new Error("RenderBuffer.frameBuffer: calling base implementation");
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
// Save and restore buffer states must save the currently binded array buffer and restore it
|
|
137
|
-
saveVertexBufferState() {
|
|
138
|
-
throw new Error("RenderBuffer.saveVertexBufferState: callig base implementation");
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
restoreVertexBufferState() {
|
|
142
|
-
throw new Error("RenderBuffer.restoreVertexBufferState: calling base implementation");
|
|
143
|
-
}
|
|
144
|
-
|
|
145
|
-
update(drawFunc) {
|
|
146
|
-
this.saveVertexBufferState();
|
|
147
|
-
if (this.type === RenderBufferType.TEXTURE) {
|
|
148
|
-
this.beginUpdate();
|
|
149
|
-
drawFunc();
|
|
150
|
-
this.endUpdate();
|
|
151
|
-
}
|
|
152
|
-
else if (this.type === RenderBufferType.CUBE_MAP) {
|
|
153
|
-
const viewMatrix = Mat4.MakeIdentity();
|
|
154
|
-
const projectionMatrix = Mat4.MakePerspective(90, 1, 0.1, 100000);
|
|
155
|
-
for (let i = 0; i<6; ++i) {
|
|
156
|
-
const face = CubeMapFace.POSITIVE_X + i;
|
|
157
|
-
switch (face) {
|
|
158
|
-
case CubeMapFace.POSITIVE_X:
|
|
159
|
-
viewMatrix.lookAt([-1, 0, 0], [0, 0, 0], [0,-1, 0]);
|
|
160
|
-
break;
|
|
161
|
-
case CubeMapFace.NEGATIVE_X:
|
|
162
|
-
viewMatrix.lookAt([ 1, 0, 0], [0, 0, 0], [0,-1, 0]);
|
|
163
|
-
break;
|
|
164
|
-
case CubeMapFace.POSITIVE_Y:
|
|
165
|
-
viewMatrix.lookAt([ 0,-1, 0], [0, 0, 0], [0, 0, 1]);
|
|
166
|
-
break;
|
|
167
|
-
case CubeMapFace.NEGATIVE_Y:
|
|
168
|
-
viewMatrix.lookAt([ 0, 1, 0], [0, 0, 0], [0, 0,-1]);
|
|
169
|
-
break;
|
|
170
|
-
case CubeMapFace.POSITIVE_Z:
|
|
171
|
-
viewMatrix.lookAt([ 0, 0,-1], [0, 0, 0], [0,-1, 0]);
|
|
172
|
-
break;
|
|
173
|
-
case CubeMapFace.NEGATIVE_Z:
|
|
174
|
-
viewMatrix.lookAt([ 0, 0, 1], [0, 0, 0], [0,-1, 0]);
|
|
175
|
-
break;
|
|
176
|
-
}
|
|
177
|
-
|
|
178
|
-
this.beginUpdate(face);
|
|
179
|
-
drawFunc(face,viewMatrix,projectionMatrix);
|
|
180
|
-
this.endUpdate(face);
|
|
181
|
-
}
|
|
182
|
-
}
|
|
183
|
-
this.restoreVertexBufferState();
|
|
184
|
-
}
|
|
185
|
-
|
|
186
|
-
readPixels(x, y, width, height, format, type) {
|
|
187
|
-
|
|
188
|
-
}
|
|
189
|
-
}
|
package/render/RenderQueue.js
DELETED
|
@@ -1,162 +0,0 @@
|
|
|
1
|
-
|
|
2
|
-
import { getLayers, RenderLayer } from "../base/PolyList";
|
|
3
|
-
import Mat4 from "../math/Mat4";
|
|
4
|
-
import { BlendFunction } from "./Pipeline";
|
|
5
|
-
import RenderState from "./RenderState";
|
|
6
|
-
|
|
7
|
-
export default class RenderQueue {
|
|
8
|
-
constructor(renderer) {
|
|
9
|
-
this._renderer = renderer;
|
|
10
|
-
|
|
11
|
-
this._queues = [];
|
|
12
|
-
|
|
13
|
-
this._viewMatrix = Mat4.MakeIdentity();
|
|
14
|
-
this._projectionMatrix = Mat4.MakeIdentity();
|
|
15
|
-
|
|
16
|
-
this._lights = [];
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
get renderer() {
|
|
20
|
-
return this._renderer;
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
get queues() {
|
|
24
|
-
return this._queues;
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
get viewMatrix() {
|
|
28
|
-
return this._viewMatrix;
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
set viewMatrix(m) {
|
|
32
|
-
this._viewMatrix.assign(m);
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
get projectionMatrix() {
|
|
36
|
-
return this._projectionMatrix;
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
set projectionMatrix(m) {
|
|
40
|
-
this._projectionMatrix.assign(m);
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
get lights() {
|
|
44
|
-
return this._lights;
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
getQueue(layer) {
|
|
48
|
-
return this._queues.find(l => l.layer === layer);
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
enableQueue(layer, shader, { beginOperation = null, endOperation = null, enabled = true } = {}) {
|
|
52
|
-
// TODO: Create pipelines for different render states (cull face, front face etc.)
|
|
53
|
-
const cullBackFace = this.renderer.factory.pipeline();
|
|
54
|
-
const cullFaceDisabled = this.renderer.factory.pipeline();
|
|
55
|
-
if (layer === RenderLayer.TRANSPARENT_DEFAULT) {
|
|
56
|
-
const blendState = {
|
|
57
|
-
enabled: true,
|
|
58
|
-
blendFuncSrc: BlendFunction.SRC_ALPHA,
|
|
59
|
-
blendFuncDst: BlendFunction.ONE_MINUS_SRC_ALPHA,
|
|
60
|
-
blendFuncSrcAlpha: BlendFunction.ONE,
|
|
61
|
-
blendFuncDstAlpha: BlendFunction.ONE_MINUS_SRC_ALPHA
|
|
62
|
-
};
|
|
63
|
-
cullBackFace.setBlendState(blendState);
|
|
64
|
-
cullFaceDisabled.setBlendState(blendState);
|
|
65
|
-
}
|
|
66
|
-
cullBackFace.create();
|
|
67
|
-
cullFaceDisabled.cullFace = false;
|
|
68
|
-
cullFaceDisabled.create();
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
const queue = this.getQueue(layer);
|
|
74
|
-
if (!queue) {
|
|
75
|
-
this._queues.push({
|
|
76
|
-
layer,
|
|
77
|
-
shader,
|
|
78
|
-
beginOperation,
|
|
79
|
-
endOperation,
|
|
80
|
-
enabled,
|
|
81
|
-
pipelines: {
|
|
82
|
-
cullBackFace,
|
|
83
|
-
cullFaceDisabled
|
|
84
|
-
},
|
|
85
|
-
queue: []
|
|
86
|
-
});
|
|
87
|
-
}
|
|
88
|
-
else {
|
|
89
|
-
queue.enabled = true;
|
|
90
|
-
}
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
disableQueue(layer) {
|
|
94
|
-
const queue = this.getQueue(layer);
|
|
95
|
-
if (queue) {
|
|
96
|
-
queue.enabled = true;
|
|
97
|
-
}
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
isQueueEnabled(layer) {
|
|
101
|
-
return this.getQueue(layer)?.enabled || false;
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
newFrame() {
|
|
105
|
-
this._queues.forEach(q => q.queue = []);
|
|
106
|
-
this._lights = [];
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
addPolyList(polyListRenderer, materialRenderer, modelMatrix) {
|
|
110
|
-
const plistLayers = getLayers(polyListRenderer.polyList, materialRenderer.material);
|
|
111
|
-
this._queues.forEach(({ layer, shader, queue, pipelines }) => {
|
|
112
|
-
if (plistLayers & layer) {
|
|
113
|
-
const { polyList } = polyListRenderer;
|
|
114
|
-
let pipeline = null;
|
|
115
|
-
// TODO: Select pipeline based on material and polyList properties
|
|
116
|
-
if (polyList.enableCullFace) {
|
|
117
|
-
pipeline = pipelines.cullBackFace;
|
|
118
|
-
}
|
|
119
|
-
else {
|
|
120
|
-
pipeline = pipelines.cullFaceDisabled;
|
|
121
|
-
}
|
|
122
|
-
queue.push(new RenderState({
|
|
123
|
-
shader,
|
|
124
|
-
polyListRenderer,
|
|
125
|
-
materialRenderer,
|
|
126
|
-
modelMatrix,
|
|
127
|
-
viewMatrix: this.viewMatrix,
|
|
128
|
-
projectionMatrix: this.projectionMatrix,
|
|
129
|
-
pipeline
|
|
130
|
-
}))
|
|
131
|
-
}
|
|
132
|
-
});
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
addLight(light, transform) {
|
|
136
|
-
// Clear the depth texture, because this parameter
|
|
137
|
-
// is set each frame by the ShadowRenderer
|
|
138
|
-
light.depthTexture = null;
|
|
139
|
-
light.mvpMatrix = null;
|
|
140
|
-
this._lights.push({ light, transform });
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
draw(layer) {
|
|
144
|
-
const queue = this.getQueue(layer);
|
|
145
|
-
if (queue) {
|
|
146
|
-
if (typeof(queue.beginOperation) === "function") {
|
|
147
|
-
queue.beginOperation(layer);
|
|
148
|
-
}
|
|
149
|
-
|
|
150
|
-
//queue.pipeline.activate();
|
|
151
|
-
queue.queue.forEach(rs => {
|
|
152
|
-
rs.draw();
|
|
153
|
-
});
|
|
154
|
-
if (typeof(queue.endOperation) === "function") {
|
|
155
|
-
queue.endOperation(layer);
|
|
156
|
-
}
|
|
157
|
-
}
|
|
158
|
-
else {
|
|
159
|
-
console.warn(`No render queue found for layer ${layer}`);
|
|
160
|
-
}
|
|
161
|
-
}
|
|
162
|
-
}
|
package/render/RenderState.js
DELETED
|
@@ -1,82 +0,0 @@
|
|
|
1
|
-
|
|
2
|
-
import { RenderLayer } from "../base/PolyList";
|
|
3
|
-
import Mat4 from "../math/Mat4";
|
|
4
|
-
|
|
5
|
-
export default class RenderState {
|
|
6
|
-
constructor({
|
|
7
|
-
shader = null,
|
|
8
|
-
polyListRenderer = null,
|
|
9
|
-
materialRenderer = null,
|
|
10
|
-
modelMatrix = Mat4.MakeIdentity(),
|
|
11
|
-
viewMatrix = Mat4.MakeIdentity(),
|
|
12
|
-
projectionMatrix = Mat4.MakeIdentity(),
|
|
13
|
-
pipeline = null
|
|
14
|
-
}) {
|
|
15
|
-
this._shader = shader;
|
|
16
|
-
this._polyListRenderer = polyListRenderer;
|
|
17
|
-
this._materialRenderer = materialRenderer;
|
|
18
|
-
this._modelMatrix = modelMatrix;
|
|
19
|
-
this._viewMatrix = viewMatrix;
|
|
20
|
-
this._projectionMatrix = projectionMatrix;
|
|
21
|
-
this._pipeline = pipeline;
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
get valid() {
|
|
25
|
-
return this._shader && this._plistRenderer && this._materialRenderer;
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
get renderer() { return this._polyListRenderer?.renderer; }
|
|
29
|
-
|
|
30
|
-
set shader(shader) { this._shader = shader; }
|
|
31
|
-
get shader() { return this._shader; }
|
|
32
|
-
set polyListRenderer(polyListRenderer) { this._polyListRenderer = polyListRenderer; }
|
|
33
|
-
get polyListRenderer() { return this._polyListRenderer; }
|
|
34
|
-
set materialRenderer(materialRenderer) { this._materialRenderer = materialRenderer; }
|
|
35
|
-
get materialRenderer() { return this._materialRenderer; }
|
|
36
|
-
set modelMatrix(model) { this._modelMatrix = model; }
|
|
37
|
-
get modelMatrix() { return this._modelMatrix; }
|
|
38
|
-
set viewMatrix(view) { this._viewMatrix = view; }
|
|
39
|
-
get viewMatrix() { return this._viewMatrix; }
|
|
40
|
-
set projectionMatrix(projection) { this._projectionMatrix = projection; }
|
|
41
|
-
get projectionMatrix() { return this._projectionMatrix; }
|
|
42
|
-
get pipeline() { return this._pipeline; }
|
|
43
|
-
set pipeline(pl) { this._pipeline = pl; }
|
|
44
|
-
|
|
45
|
-
isLayerEnabled(layer) {
|
|
46
|
-
const { polyList } = this._polyListRenderer;
|
|
47
|
-
const { material } = this._materialRenderer;
|
|
48
|
-
const renderLayers = polyList.renderLayers === RenderLayer.AUTO ?
|
|
49
|
-
(material.isTransparent ? RenderLayer.TRANSPARENT_DEFAULT : RenderLayer.OPAQUE_DEFAULT) :
|
|
50
|
-
(polyList.renderLayers);
|
|
51
|
-
|
|
52
|
-
return renderLayers & layer;
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
draw({ overrideShader = null, overrideViewMatrix = null, overrideProjectionMatrix = null} = {}) {
|
|
56
|
-
if (!this.polyListRenderer.polyList.visible) {
|
|
57
|
-
return;
|
|
58
|
-
}
|
|
59
|
-
if (this.renderer.debugMode) {
|
|
60
|
-
console.log(`======= Begin render polyList "${this.polyListRenderer.polyList.name}" ==============`);
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
if (this.pipeline) {
|
|
64
|
-
this.pipeline.activate();
|
|
65
|
-
}
|
|
66
|
-
this.polyListRenderer.bindBuffers();
|
|
67
|
-
const shader = overrideShader || this.shader;
|
|
68
|
-
const viewMatrix = overrideViewMatrix || this.viewMatrix;
|
|
69
|
-
const projectionMatrix = overrideProjectionMatrix || this.projectionMatrix;
|
|
70
|
-
shader.setup(
|
|
71
|
-
this.polyListRenderer,
|
|
72
|
-
this.materialRenderer,
|
|
73
|
-
this.modelMatrix,
|
|
74
|
-
viewMatrix,
|
|
75
|
-
projectionMatrix
|
|
76
|
-
);
|
|
77
|
-
this.polyListRenderer.draw();
|
|
78
|
-
if (this.renderer.debugMode) {
|
|
79
|
-
console.log(`======= End render polyList "${this.polyListRenderer.polyList.name}" ==============`);
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
}
|
package/render/Renderer.js
DELETED
|
@@ -1,202 +0,0 @@
|
|
|
1
|
-
|
|
2
|
-
import PresentTextureShader from "../shaders/PresentTextureShader";
|
|
3
|
-
import Material from "../base/Material";
|
|
4
|
-
import PolyList from "../base/PolyList";
|
|
5
|
-
import Environment from "./Environment";
|
|
6
|
-
import TextureMergerRenderer from "./TextureMergerRenderer";
|
|
7
|
-
|
|
8
|
-
export const EngineFeatures = {
|
|
9
|
-
RENDER_TARGET_TEXTURES: 0x1 << 0,
|
|
10
|
-
RENDER_TARGET_FLOAT: 0x1 << 1,
|
|
11
|
-
RENDER_TARGET_DEPTH: 0x1 << 2
|
|
12
|
-
};
|
|
13
|
-
|
|
14
|
-
export default class Renderer {
|
|
15
|
-
constructor(identifier) {
|
|
16
|
-
this._identifier = identifier;
|
|
17
|
-
this._frameBuffer = null;
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
get uniqueId() {
|
|
21
|
-
throw new Error("Calling Renderer.uniqueId base implementation.");
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
get typeId() {
|
|
25
|
-
throw new Error("Calling Renderer.typeId base implementation");
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
async init(canvas) {
|
|
29
|
-
this._canvas = canvas;
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
get canvas() {
|
|
33
|
-
return this._canvas;
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
get frameBuffer() {
|
|
37
|
-
throw new Error("Calling Renderer.frameBuffer base implementation.");
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
set viewport(vp) {
|
|
41
|
-
throw new Error("Calling Renderer.viewport setter base implementation.");
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
get viewport() {
|
|
45
|
-
throw new Error("Calling Renderer.viewport getter base implementation.");
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
get presentTextureSurfaceRenderer() {
|
|
49
|
-
if (!this._presentTextureSurface) {
|
|
50
|
-
const plist = new PolyList();
|
|
51
|
-
plist.vertex = [
|
|
52
|
-
-1, -1, 0,
|
|
53
|
-
1, -1, 0,
|
|
54
|
-
1, 1, 0,
|
|
55
|
-
-1, 1, 0
|
|
56
|
-
];
|
|
57
|
-
plist.texCoord0 = [
|
|
58
|
-
0, 0,
|
|
59
|
-
1, 0,
|
|
60
|
-
1, 1,
|
|
61
|
-
0, 1
|
|
62
|
-
];
|
|
63
|
-
plist.index = [
|
|
64
|
-
0, 1, 2,
|
|
65
|
-
2, 3, 0
|
|
66
|
-
];
|
|
67
|
-
this._presentTextureSurface = this.factory.polyList(plist);
|
|
68
|
-
}
|
|
69
|
-
return this._presentTextureSurface;
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
async initPresentTextureShader() {
|
|
73
|
-
if (!this._presentTextureShader) {
|
|
74
|
-
this._presentTextureShader = new PresentTextureShader(this);
|
|
75
|
-
this._presentTextureShader.load();
|
|
76
|
-
}
|
|
77
|
-
return this._presentTextureShader;
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
get presentTextureShader() {
|
|
81
|
-
return this._presentTextureShader;
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
get presentTextureMaterialRenderer() {
|
|
85
|
-
if (!this._presentTextureMaterial) {
|
|
86
|
-
this._presentTextureMaterial = this.factory.material(new Material());
|
|
87
|
-
}
|
|
88
|
-
return this._presentTextureMaterial;
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
postReshape(width,height) {
|
|
92
|
-
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
postRedisplay() {
|
|
96
|
-
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
polyListFactory(plist) {
|
|
100
|
-
throw new Error("Calling base implementation of Renderer.polyListFactory()");
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
materialFactory(material) {
|
|
104
|
-
throw new Error("Calling base implementation of Renderer.materialFactory()");
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
textureFactory(texture) {
|
|
108
|
-
throw new Error("Calling base implementation of Renderer.textureFactory()");
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
renderBufferFactory() {
|
|
112
|
-
throw new Error("Calling base implementation of Renderer.renderBufferFactory()");
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
skySphereFactory() {
|
|
116
|
-
throw new Error("Calling base implementation of Renderer.skySphereFactory()");
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
skyCubeFactory() {
|
|
120
|
-
throw new Error("Calling base implementation of Renderer.skyCubeFactory()");
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
environmentFactory() {
|
|
124
|
-
return new Environment(this);
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
textureMergerFactory() {
|
|
128
|
-
return new TextureMergerRenderer(this);
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
pipelineFactory() {
|
|
132
|
-
throw new Error("Calling base implementation of Renderer.pipelineFactory()");
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
sceneRendererFactory() {
|
|
136
|
-
throw new Error("Calling base implementation of Renderer.sceneRendererFactory()");
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
shadowRendererFactory() {
|
|
140
|
-
throw new Error("Calling base implementation of Renderer.shadowRendererFactory()");
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
get clearColor() {
|
|
144
|
-
throw new Error("Calling base implementation of Renderer.clearColor getter.");
|
|
145
|
-
}
|
|
146
|
-
|
|
147
|
-
set clearColor(c) {
|
|
148
|
-
throw new Error("Calling base implementation of Renderer.clearColor setter.");
|
|
149
|
-
}
|
|
150
|
-
|
|
151
|
-
get factory() {
|
|
152
|
-
const renderer = this;
|
|
153
|
-
return {
|
|
154
|
-
polyList(plist) {
|
|
155
|
-
return renderer.polyListFactory(plist);
|
|
156
|
-
},
|
|
157
|
-
material(material) {
|
|
158
|
-
return renderer.materialFactory(material);
|
|
159
|
-
},
|
|
160
|
-
texture(texture) {
|
|
161
|
-
return renderer.textureFactory(texture);
|
|
162
|
-
},
|
|
163
|
-
renderBuffer() {
|
|
164
|
-
return renderer.renderBufferFactory();
|
|
165
|
-
},
|
|
166
|
-
skySphere() {
|
|
167
|
-
return renderer.skySphereFactory();
|
|
168
|
-
},
|
|
169
|
-
skyCube() {
|
|
170
|
-
return renderer.skyCubeFactory();
|
|
171
|
-
},
|
|
172
|
-
environment() {
|
|
173
|
-
return renderer.environmentFactory();
|
|
174
|
-
},
|
|
175
|
-
textureMerger() {
|
|
176
|
-
return renderer.textureMergerFactory();
|
|
177
|
-
},
|
|
178
|
-
pipeline() {
|
|
179
|
-
return renderer.pipelineFactory();
|
|
180
|
-
},
|
|
181
|
-
scene() {
|
|
182
|
-
return renderer.sceneRendererFactory();
|
|
183
|
-
},
|
|
184
|
-
shadowRenderer() {
|
|
185
|
-
return renderer.shadowRendererFactory();
|
|
186
|
-
}
|
|
187
|
-
}
|
|
188
|
-
}
|
|
189
|
-
|
|
190
|
-
presentTexture(texture, { clearBuffers = true, shader = null, viewport = null } = {}) {
|
|
191
|
-
|
|
192
|
-
}
|
|
193
|
-
|
|
194
|
-
// Compatibility function
|
|
195
|
-
supportsFeatures(feature) {
|
|
196
|
-
return false;
|
|
197
|
-
}
|
|
198
|
-
|
|
199
|
-
getMaximumRenderTargets() {
|
|
200
|
-
return 1;
|
|
201
|
-
}
|
|
202
|
-
}
|