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.
Files changed (135) hide show
  1. package/dist/bg2e-js.js +11001 -0
  2. package/dist/bg2e-js.js.map +1 -0
  3. package/package.json +17 -6
  4. package/app/AppController.d.ts +0 -37
  5. package/app/AppController.js +0 -32
  6. package/app/Canvas.d.ts +0 -42
  7. package/app/Canvas.js +0 -98
  8. package/app/EventBase.js +0 -8
  9. package/app/KeyboardEvent.js +0 -51
  10. package/app/MainLoop.d.ts +0 -245
  11. package/app/MainLoop.js +0 -251
  12. package/app/MouseEvent.js +0 -77
  13. package/app/TouchEvent.js +0 -15
  14. package/base/Color.js +0 -131
  15. package/base/Environment.js +0 -78
  16. package/base/Light.js +0 -176
  17. package/base/Material.js +0 -619
  18. package/base/PolyList.js +0 -336
  19. package/base/Texture.js +0 -545
  20. package/db/Bg2LoaderPlugin.js +0 -113
  21. package/db/DBPluginApi.js +0 -40
  22. package/db/Loader.js +0 -91
  23. package/db/LoaderPlugin.js +0 -26
  24. package/db/MtlParser.js +0 -7
  25. package/db/ObjLoaderPlugin.js +0 -51
  26. package/db/ObjParser.js +0 -233
  27. package/db/ObjWriterPlugin.js +0 -18
  28. package/db/VitscnjLoaderPlugin.js +0 -87
  29. package/db/Writer.js +0 -49
  30. package/db/WriterPlugin.js +0 -20
  31. package/debug/DebugRenderer.js +0 -138
  32. package/debug/WebGLTextureViewer.js +0 -67
  33. package/manipulation/SelectionBuffer.js +0 -65
  34. package/manipulation/SelectionHighlight.js +0 -69
  35. package/manipulation/SelectionIdAssignVisitor.js +0 -86
  36. package/manipulation/SelectionManager.js +0 -134
  37. package/manipulation/SelectionMode.js +0 -6
  38. package/math/Mat3.js +0 -248
  39. package/math/Mat4.js +0 -694
  40. package/math/MatrixStrategy.js +0 -23
  41. package/math/Quat.js +0 -60
  42. package/math/Vec.js +0 -728
  43. package/math/constants.js +0 -44
  44. package/math/functions.js +0 -104
  45. package/math/index.js +0 -74
  46. package/phsics/joint.js +0 -124
  47. package/primitives/arrow.js +0 -58
  48. package/primitives/cone.js +0 -137
  49. package/primitives/cube.js +0 -59
  50. package/primitives/cylinder.js +0 -215
  51. package/primitives/index.js +0 -13
  52. package/primitives/plane.js +0 -31
  53. package/primitives/sphere.js +0 -808
  54. package/render/BRDFIntegrationMap.js +0 -4
  55. package/render/Environment.js +0 -105
  56. package/render/EnvironmentRenderer.js +0 -12
  57. package/render/FrameBuffer.js +0 -26
  58. package/render/MaterialRenderer.js +0 -28
  59. package/render/Pipeline.js +0 -83
  60. package/render/PolyListRenderer.js +0 -42
  61. package/render/RenderBuffer.js +0 -189
  62. package/render/RenderQueue.js +0 -162
  63. package/render/RenderState.js +0 -82
  64. package/render/Renderer.js +0 -202
  65. package/render/SceneAppController.js +0 -208
  66. package/render/SceneRenderer.js +0 -310
  67. package/render/Shader.js +0 -21
  68. package/render/ShadowRenderer.js +0 -159
  69. package/render/SkyCube.js +0 -77
  70. package/render/SkySphere.js +0 -94
  71. package/render/TextureMergerRenderer.js +0 -58
  72. package/render/TextureRenderer.js +0 -29
  73. package/render/webgl/FrameBuffer.js +0 -9
  74. package/render/webgl/MaterialRenderer.js +0 -99
  75. package/render/webgl/Pipeline.js +0 -82
  76. package/render/webgl/PolyListRenderer.js +0 -224
  77. package/render/webgl/RenderBuffer.js +0 -244
  78. package/render/webgl/Renderer.js +0 -239
  79. package/render/webgl/SceneRenderer.js +0 -43
  80. package/render/webgl/ShaderProgram.js +0 -350
  81. package/render/webgl/ShadowRenderer.js +0 -6
  82. package/render/webgl/SkyCube.js +0 -15
  83. package/render/webgl/SkySphere.js +0 -14
  84. package/render/webgl/State.js +0 -149
  85. package/render/webgl/TextureRenderer.js +0 -167
  86. package/render/webgl/VertexBuffer.js +0 -128
  87. package/scene/Camera.js +0 -378
  88. package/scene/Chain.js +0 -43
  89. package/scene/ChainJoint.js +0 -55
  90. package/scene/Component.js +0 -146
  91. package/scene/ComponentMap.js +0 -99
  92. package/scene/Drawable.js +0 -130
  93. package/scene/EnvironmentComponent.js +0 -123
  94. package/scene/FindNodeVisitor.js +0 -55
  95. package/scene/LightComponent.js +0 -146
  96. package/scene/MatrixState.js +0 -39
  97. package/scene/Node.js +0 -300
  98. package/scene/NodeVisitor.js +0 -12
  99. package/scene/OrbitCameraController.js +0 -407
  100. package/scene/SmoothOrbitCameraController.js +0 -92
  101. package/scene/Transform.js +0 -74
  102. package/scene/index.js +0 -24
  103. package/shaders/BasicDiffuseColorShader.js +0 -91
  104. package/shaders/BasicPBRLightShader.js +0 -238
  105. package/shaders/DebugRenderShader.js +0 -79
  106. package/shaders/DepthRenderShader.js +0 -69
  107. package/shaders/IrradianceMapCubeShader.js +0 -99
  108. package/shaders/PBRLightIBLShader.js +0 -380
  109. package/shaders/PickSelectionShader.js +0 -75
  110. package/shaders/PresentDebugFramebufferShader.js +0 -90
  111. package/shaders/PresentTextureShader.js +0 -73
  112. package/shaders/SelectionHighlightShader.js +0 -98
  113. package/shaders/ShaderFunction.js +0 -72
  114. package/shaders/SkyCubeShader.js +0 -78
  115. package/shaders/SkySphereShader.js +0 -77
  116. package/shaders/SpecularMapCubeShader.js +0 -145
  117. package/shaders/TextureMergerShader.js +0 -127
  118. package/shaders/webgl_shader_lib.js +0 -187
  119. package/tools/BinaryResourceProvider.js +0 -15
  120. package/tools/ImageResourceProvider.js +0 -65
  121. package/tools/MaterialModifier.js +0 -228
  122. package/tools/Resource.js +0 -177
  123. package/tools/ResourceProvider.js +0 -56
  124. package/tools/TextResourceProvider.js +0 -24
  125. package/tools/TextureCache.js +0 -44
  126. package/tools/TextureResourceDatabase.js +0 -87
  127. package/tools/UserAgent.js +0 -294
  128. package/tools/VideoResourceProvider.js +0 -51
  129. package/tools/WriteStrategy.js +0 -22
  130. package/tools/base64.js +0 -15
  131. package/tools/crypto.js +0 -15
  132. package/tools/endiantess.js +0 -15
  133. package/tools/image.js +0 -15
  134. package/tools/index.js +0 -33
  135. package/tools/processType.js +0 -56
package/render/SkyCube.js DELETED
@@ -1,77 +0,0 @@
1
- import Material from "../base/Material";
2
- import { createCube } from "../primitives";
3
- import RenderState from "./RenderState";
4
- import SkyCubeShader from "../shaders/SkyCubeShader";
5
- import Mat4 from "../math/Mat4";
6
- import { PolyListCullFace } from "../base/PolyList";
7
-
8
- export default class SkyCube {
9
- constructor(renderer) {
10
- this._renderer = renderer;
11
- }
12
-
13
- get renderer() { return this._renderer; }
14
-
15
- set texture(texture) {
16
- if (!this._texture) {
17
- throw new Error("SkyCube: setting texture to an uninitialized sky cube. The texture setter is used to change the skyCube texture once created. Use the load() method instead.");
18
- }
19
- this._texture = texture;
20
- this._material.diffuse = this._texture;
21
- }
22
-
23
- async load(cubemapTexture, Shader = null, shaderParams = []) {
24
- this._texture = cubemapTexture;
25
-
26
- this._material = new Material();
27
- this._material.diffuse = this._texture;
28
-
29
- this._shader = Shader ? new Shader(this.renderer) : new SkyCubeShader(this.renderer);
30
- await this._shader.load.apply(this._shader,shaderParams);
31
- }
32
-
33
- updateRenderState({ viewMatrix, projectionMatrix = null }) {
34
- const rotationMatrix = Mat4.GetRotation(viewMatrix);
35
- if (!this._renderState) {
36
- this._renderState = new RenderState({
37
- shader: this._shader,
38
- polyListRenderer: this.polyListRenderer,
39
- materialRenderer: this.renderer.factory.material(this._material),
40
- viewMatrix: rotationMatrix,
41
- projectionMatrix
42
- });
43
- }
44
- else {
45
- this._renderState.viewMatrix = rotationMatrix;
46
- if (projectionMatrix) {
47
- this._renderState.projectionMatrix = projectionMatrix;
48
- }
49
- }
50
- return this._renderState;
51
- }
52
-
53
- draw() {
54
- throw new Error("SkyCube.draw(): Calling base implementation of SkyCube");
55
- }
56
-
57
- get polyListRenderer() {
58
- if (!this._plistRenderer) {
59
- const cube = createCube(1,1,1);
60
- cube.cullFace = PolyListCullFace.FRONT; // Draw back face
61
- this._plistRenderer = this.renderer.factory.polyList(cube);
62
- }
63
- return this._plistRenderer;
64
- }
65
-
66
- destroy() {
67
- this._shader.destroy();
68
- this._texture.destroy();
69
- this._plistRenderer.destroy();
70
- this._material.destroy();
71
- this._shader = null;
72
- this._texture = null;
73
- this._material = null;
74
- this._plistRenderer = null;
75
- this._renderState = null;
76
- }
77
- }
@@ -1,94 +0,0 @@
1
- import { createSphere } from "../primitives";
2
- import SkySphereShader from "../shaders/SkySphereShader";
3
- import RenderState from "./RenderState";
4
- import Material from "../base/Material";
5
- import Texture, { ProceduralTextureFunction, TextureFilter, TextureWrap } from "../base/Texture";
6
- import Mat4 from "../math/Mat4";
7
- import { PolyListCullFace, PolyListFrontFace } from "../base/PolyList";
8
- import Color from "../base/Color";
9
-
10
- export default class SkySphere {
11
- constructor(renderer) {
12
- this._renderer = renderer;
13
- }
14
-
15
- get renderer() { return this._renderer; }
16
-
17
- async load(equirectangularTextureUrl, Shader = null) {
18
- this._texture = new Texture();
19
- if (equirectangularTextureUrl) {
20
- this._texture.fileName = equirectangularTextureUrl;
21
- }
22
- else {
23
- // Load black texture
24
- this._texture.magFilter = TextureFilter.NEAREST;
25
- this._texture.minFilter = TextureFilter.NEAREST;
26
- this._texture.wrapModeXY = TextureWrap.REPEAT;
27
- this._texture.proceduralFunction = ProceduralTextureFunction.PLAIN_COLOR;
28
- this._texture.proceduralParameters = Color.Black();
29
- this._texture.size = [2, 2];
30
- }
31
- await this._texture.loadImageData();
32
-
33
- this._material = new Material();
34
- this._material.diffuse = this._texture;
35
-
36
- this._shader = Shader ? new Shader(this.renderer) : new SkySphereShader(this.renderer);
37
- await this._shader.load();
38
- }
39
-
40
- async setTexture(equirectangularTextureUrl) {
41
- if (this._texture) {
42
- this._texture.destroy();
43
- }
44
- this._texture.fileName = equirectangularTextureUrl;
45
- await this._texture.loadImageData();
46
-
47
- this._material.diffuse = this._texture;
48
- }
49
-
50
- updateRenderState({ viewMatrix, projectionMatrix = null }) {
51
- const rotationMatrix = Mat4.GetRotation(viewMatrix);
52
- if (!this._renderState) {
53
- this._renderState = new RenderState({
54
- shader: this._shader,
55
- polyListRenderer: this.polyListRenderer,
56
- materialRenderer: this.renderer.factory.material(this._material),
57
- viewMatrix: rotationMatrix,
58
- projectionMatrix
59
- });
60
- }
61
- else {
62
- this._renderState.viewMatrix = rotationMatrix;
63
- if (projectionMatrix) {
64
- this._renderState.projectionMatrix = projectionMatrix;
65
- }
66
- }
67
- return this._renderState;
68
- }
69
-
70
- draw() {
71
- throw new Error("SkySphere.draw(): Calling base implementation of SkySphere");
72
- }
73
-
74
- get polyListRenderer() {
75
- if (!this._plistRenderer) {
76
- const sphere = createSphere(3.5);
77
- sphere.cullFace = PolyListCullFace.FRONT; // Draw back face
78
- this._plistRenderer = this.renderer.factory.polyList(sphere);
79
- }
80
- return this._plistRenderer;
81
- }
82
-
83
- destroy() {
84
- this._shader.destroy();
85
- this._texture.destroy();
86
- this._plistRenderer.destroy();
87
- this._shader = null;
88
- this._texture = null;
89
- this._material.destroy();
90
- this._material = null;
91
- this._plistRenderer = null;
92
- this._renderState = null;
93
- }
94
- }
@@ -1,58 +0,0 @@
1
-
2
- import Texture, { TextureChannel, TextureComponentFormat, TextureRenderTargetAttachment, TextureWrap } from "../base/Texture";
3
- import TextureMergerShader from "../shaders/TextureMergerShader";
4
- export default class TextureMergerRenderer {
5
- constructor(renderer) {
6
- this._renderer = renderer;
7
-
8
- this._shader = TextureMergerShader.GetUnique(this.renderer);
9
-
10
- this._dirty = true;
11
-
12
- this._mergedTexture = new Texture();
13
- this._mergedTexture.renderTargetAttachment = TextureRenderTargetAttachment.COLOR_ATTACHMENT_0;
14
- this._mergedTexture.componentFormat = TextureComponentFormat.UNSIGNED_BYTE;
15
- this._mergedTexture.wrapModeXY = TextureWrap.REPEAT;
16
-
17
- this._renderBuffer = this.renderer.factory.renderBuffer();
18
- this._renderBuffer.attachTexture(this._mergedTexture);
19
-
20
- this._shader.load();
21
- }
22
-
23
- get renderer() {
24
- return this._renderer;
25
- }
26
-
27
- get dirty() {
28
- return this._dirty;
29
- }
30
-
31
- set dirty(d) {
32
- this._dirty = d;
33
- }
34
-
35
- setTexture(tex,channel,dstChannel = TextureChannel.R) {
36
- this._shader.setTexture(tex,channel,dstChannel);
37
- this._dirty = true;
38
- }
39
-
40
- get mergedTexture() {
41
- return this._mergedTexture;
42
- }
43
-
44
- get isComplete() {
45
- return this._shader.isComplete;
46
- }
47
-
48
- update() {
49
- if (this._dirty) {
50
- this._renderBuffer.update(() => {
51
- // DEBUG: check why it's neccesary to present texture twice
52
- this.renderer.presentTexture(null, { clear: true, shader: this._shader });
53
- this.renderer.presentTexture(null, { shader: this._shader });
54
- });
55
- this._dirty = false;
56
- }
57
- }
58
- }
@@ -1,29 +0,0 @@
1
- import { TextureTarget } from "../base/Texture";
2
- export default class TextureRenderer {
3
- constructor(renderer, texture) {
4
- if (texture.renderer) {
5
- throw new Error("Invalid initialization of texture renderer: The texture object is already controlled by another texture renderer.");
6
- }
7
-
8
- this._renderer = renderer;
9
- this._texture = texture;
10
- this._texture._renderer = this;
11
- }
12
-
13
- get renderer() {
14
- return this._renderer;
15
- }
16
-
17
- get texture() {
18
- return this._texture;
19
- }
20
-
21
- getApiObject(texture) {
22
- // Return the specific texture identifier for renderer type
23
- throw new Error("TextureRenderer: getApiObject() invalid usage of generic implementation of TextureRenderer");
24
- }
25
-
26
- destroy() {
27
- throw new Error("TextureRenderer: destroy() invalid usage of generic implementation of TextureRenderer");
28
- }
29
- }
@@ -1,9 +0,0 @@
1
-
2
- import FrameBuffer from "../FrameBuffer";
3
-
4
- export default class WebGLFrameBuffer extends FrameBuffer {
5
- clear({ color = true, depth = true, stencil = false } = {}) {
6
- const { state } = this.renderer;
7
- state.clear({ color, depth, stencil });
8
- }
9
- }
@@ -1,99 +0,0 @@
1
- import Texture, { TextureChannel, TextureTargetName } from "../../base/Texture";
2
- import MaterialRenderer from "../MaterialRenderer";
3
- import { whiteTexture, createWhiteTexture, blackTexture, createBlackTexture } from "../../tools/TextureResourceDatabase";
4
-
5
- export default class WebGLMaterialRenderer extends MaterialRenderer {
6
- static async InitResources(renderer) {
7
- await createWhiteTexture(renderer);
8
- await createBlackTexture(renderer);
9
- }
10
-
11
- constructor(renderer, material) {
12
- super(renderer, material);
13
- if (material.renderer) {
14
- throw new Error("Duplicate material renderer set to material. Please, use the Renderer factory to get material renderer instance.");
15
- }
16
- material._renderer = this;
17
-
18
- this._whiteTexture = renderer.factory.texture(whiteTexture(renderer));
19
- this._blackTexture = renderer.factory.texture(blackTexture(renderer));
20
- this._textureMerger = renderer.factory.textureMerger();
21
- }
22
-
23
- mergeTextures() {
24
- if (this.material.dirty) {
25
- const getTexture = (att, fallbackTexture = this._whiteTexture) => {
26
- if (this.material[att] instanceof Texture) {
27
- return this.material[att];
28
- }
29
- else {
30
- return fallbackTexture.texture;
31
- }
32
- }
33
-
34
- this._textureMerger.setTexture(getTexture('metallic'), TextureChannel.R, TextureChannel.R + this.material.metallicChannel);
35
- this._textureMerger.setTexture(getTexture('roughness'), TextureChannel.G, TextureChannel.R + this.material.roughnessChannel);
36
- this._textureMerger.setTexture(getTexture('lightEmission', this._blackTexture), TextureChannel.B, TextureChannel.R + this.material.lightEmissionChannel);
37
- this._textureMerger.setTexture(getTexture('ambientOcclussion'), TextureChannel.A, TextureChannel.R + this.material.ambientOcclussionChannel);
38
- this._textureMerger.update();
39
- this.material.dirty = false;
40
- }
41
- }
42
-
43
- get metallicRoughnessHeightAOTexture() {
44
- return this._textureMerger.mergedTexture;
45
- }
46
-
47
- destroy() {
48
- console.log("Destroy material renderer");
49
- if (this.material) {
50
- this.material._renderer = null;
51
- }
52
- }
53
-
54
- // Bind the metallic, roughness, height and ambient occlussion combined texture
55
- bindMetallicRoughnessHeightAOTexture(shaderProgram, uniformName, textureUnit) {
56
- shaderProgram.bindTexture(uniformName, this.renderer.factory.texture(this.metallicRoughnessHeightAOTexture), textureUnit);
57
- return true;
58
- }
59
-
60
- // Binds the property to the uniformName uniform of the shader program, if the
61
- // material property ies a texture. If not, it binds the fallbackTexture. If the fallbackTexture
62
- // value is null, it binds a 2x2 px white texture
63
- bindTexture(shaderProgram, property, uniformName, textureUnit, fallbackTexture = null) {
64
- if (this.material[property] instanceof Texture) {
65
- shaderProgram.bindTexture(uniformName, this.getTextureRenderer(property), textureUnit);
66
- return true;
67
- }
68
- else if (fallbackTexture instanceof Texture) {
69
- shaderProgram.bindTexture(uniformName, this.renderer.factory.texture(fallbackTexture), textureUnit);
70
- return false;
71
- }
72
- else {
73
- shaderProgram.bindTexture(uniformName, this._whiteTexture, textureUnit);
74
- return false;
75
- }
76
- }
77
-
78
- // Bind the property to the uniformName uniform of the shader program, if the
79
- // material property is a color. If not, it binds the fallbackColor vector
80
- bindColor(shaderProgram, property, uniformName, fallbackColor = [1, 1, 1, 1]) {
81
- if (this.material[property].length>=4) {
82
- shaderProgram.uniform4fv(uniformName, this.material[property]);
83
- }
84
- else {
85
- shaderProgram.uniform4fv(uniformName, fallbackColor);
86
- }
87
- }
88
-
89
- // Bind the property to the uniformName uniform of the shader program, if the
90
- // material property is a number. If not, it binds the fallbackValue value
91
- bindValue(shaderProgram, property, uniformName, fallbackValue = 1) {
92
- if (typeof(this.material[property]) === "number") {
93
- shaderProgram.uniform1f(uniformName, this.material[property]);
94
- }
95
- else {
96
- shaderProgram.uniform1f(uniformName, fallbackValue);
97
- }
98
- }
99
- }
@@ -1,82 +0,0 @@
1
-
2
- import Pipeline, { BlendEquation, BlendFunction } from "../Pipeline";
3
-
4
- const getBlendEquation = (gl, blendEquation) => {
5
- switch (blendEquation) {
6
- case BlendEquation.ADD:
7
- return gl.FUNC_ADD;
8
- case BlendEquation.FUNC_SUBTRACT:
9
- return gl.SUBTRACT;
10
- case BlendEquation.REVERSE_SUBTRACT:
11
- return gl.FUNC_REVERSE_SUBTRACT;
12
- }
13
- throw new Error(`Invalid blend equation specified in WebGLPipeline: ${ blendEquation }`);
14
- }
15
-
16
- const getBlendFunc = (gl, blendFunc) => {
17
- switch (blendFunc) {
18
- case BlendFunction.NULL:
19
- return null;
20
- case BlendFunction.ZERO:
21
- return gl.ZERO;
22
- case BlendFunction.ONE:
23
- return gl.ONE;
24
- case BlendFunction.SRC_COLOR:
25
- return gl.SRC_COLOR;
26
- case BlendFunction.ONE_MINUS_SRC_COLOR:
27
- return gl.ONE_MINUS_SRC_COLOR;
28
- case BlendFunction.DST_COLOR:
29
- return gl.DST_COLOR;
30
- case BlendFunction.ONE_MINUS_DST_COLOR:
31
- return gl.ONE_MINUS_DST_COLOR;
32
- case BlendFunction.SRC_ALPHA:
33
- return gl.SRC_ALPHA;
34
- case BlendFunction.ONE_MINUS_SRC_ALPHA:
35
- return gl.ONE_MINUS_SRC_ALPHA;
36
- case BlendFunction.DST_ALPHA:
37
- return gl.DST_ALPHA;
38
- case BlendFunction.ONE_MINUS_DST_ALPHA:
39
- return gl.ONE_MINUS_DST_ALPHA;
40
- }
41
- throw new Error(`Invalid blend function specified in WebGLPipeline: ${ blendFunc }`);
42
- }
43
-
44
- export default class WebGLPipeline extends Pipeline {
45
- create() {
46
- const { gl } = this.renderer;
47
-
48
- // Set the webgl equivalent values
49
- this._blendEquation = getBlendEquation(gl, this.blendState.blendEquation);
50
- this._blendFuncSrcColor = getBlendFunc(gl, this.blendState.blendFuncSrc);
51
- this._blendFuncSrcAlpha = getBlendFunc(gl, this.blendState.blendFuncSrcAlpha);
52
- this._blendFuncDstColor = getBlendFunc(gl, this.blendState.blendFuncDst);
53
- this._blendFuncDstAlpha = getBlendFunc(gl, this.blendState.blendFuncDstAlpha);
54
- if ((this._blendFuncDstAlpha === null && this._blendFuncSrcAlpha !== null) ||
55
- (this._blendFuncDstAlpha !== null && this._blendFuncSrcAlpha === null))
56
- {
57
- throw new Error("WebGLPipeline.create(): Invalid values of blendFuncDstAlpha and blendFuncSrcAlpha");
58
- }
59
- this._blendFunc = this._blendFuncDstAlpha !== null ? (a,b) => gl.blendFunc(a,b) : (a,b,c,d) => gl.blendFuncSeparate(a,b,c,d);
60
- }
61
-
62
- activate() {
63
- const { gl, state } = this.renderer;
64
- this.blendState.enabled ? gl.enable(gl.BLEND) : gl.disable(gl.BLEND);
65
- gl.blendEquation(this._blendEquation);
66
- this._blendFunc(
67
- this._blendFuncSrcColor,
68
- this._blendFuncDstColor,
69
- this._blendFuncSrcAlpha,
70
- this._blendFuncDstAlpha
71
- );
72
-
73
- state.depthTestEnabled = this.depthTest;
74
-
75
- if (this.cullFace) {
76
- gl.enable(gl.CULL_FACE);
77
- }
78
- else {
79
- gl.disable(gl.CULL_FACE);
80
- }
81
- }
82
- }
@@ -1,224 +0,0 @@
1
-
2
- import { DrawMode, PolyListCullFace, PolyListFrontFace } from "../../base/PolyList";
3
- import PolyListRenderer from "../PolyListRenderer";
4
- import VertexBuffer, { BufferTarget } from "./VertexBuffer";
5
-
6
- export default class WebGLPolyListRenderer extends PolyListRenderer {
7
- constructor(renderer,polyList) {
8
- super(renderer,polyList);
9
- }
10
-
11
- init() {
12
- this._vertexBuffer = null;
13
- this._indexBuffer = null;
14
- this._indexArrayFormat = null;
15
- }
16
-
17
- get valid() {
18
- return this._vertexBuffer !== null && this._indexArrayFormat !== null && this._indexBuffer !== null;
19
- }
20
-
21
- refresh() {
22
- const getVector = (items, current, stride) => items.length && (stride === 3 ?
23
- [items[current * stride], items[current * stride + 1], items[current * stride + 2]] :
24
- stride === 2 ? [items[current * stride], items[current * stride + 1]] || null :
25
- [items[current * stride], items[current * stride + 1], items[current * stride + 2], items[current * stride + 3]])
26
-
27
- const numElements = this.polyList.vertex.length / 3;
28
- const result = [];
29
- for (let i = 0; i < numElements; ++i) {
30
- const v = getVector(this.polyList.vertex, i, 3);
31
- const n = getVector(this.polyList.normal, i, 3);
32
- const t0 = getVector(this.polyList.texCoord0, i, 2);
33
- const t1 = getVector(this.polyList.texCoord1, i, 2);
34
- const t2 = getVector(this.polyList.texCoord2, i, 2);
35
- const c = getVector(this.polyList.color, i, 4);
36
- const t = getVector(this.polyList.tangent, i, 3);
37
-
38
- result.push(...v);
39
- if (n) {
40
- result.push(...n);
41
- }
42
- if (t0) {
43
- result.push(...t0);
44
- }
45
- if (t1) {
46
- result.push(...t1);
47
- }
48
- if (t2) {
49
- result.push(...t2);
50
- }
51
- if (c) {
52
- result.push(...c);
53
- }
54
- if (t) {
55
- result.push(...t);
56
- }
57
- }
58
-
59
- this._stride = 3;
60
- const vertex = 0;
61
- const normal = 3;
62
- let texCoord0 = 3;
63
- let texCoord1 = 3;
64
- let texCoord2 = 3;
65
- let color = 3;
66
- let tangent = 3;
67
- if (this.hasNormal) {
68
- this._stride += 3;
69
- texCoord0 += 3;
70
- texCoord1 += 3;
71
- texCoord2 += 3;
72
- color += 3;
73
- tangent += 3;
74
- }
75
- if (this.hasTexCoord0) {
76
- this._stride += 2;
77
- texCoord1 += 2;
78
- texCoord2 += 2;
79
- color += 2;
80
- tangent += 2;
81
- }
82
- if (this.hasTexCoord1) {
83
- this._stride += 2;
84
- texCoord2 += 2;
85
- color += 2;
86
- tangent += 2;
87
- }
88
- if (this.hasTexCoord2) {
89
- this._stride += 2;
90
- color += 2;
91
- tangent += 2;
92
- }
93
- if (this.hasColor) {
94
- this._stride += 4;
95
- tangent += 4;
96
- }
97
- if (this.hasTangent) {
98
- this._stride += 3;
99
- }
100
-
101
- this._offsets = { vertex, normal, texCoord0, texCoord1, texCoord2, color, tangent };
102
- this._vertexBuffer = VertexBuffer.CreateArrayBuffer(this.renderer.gl, new Float32Array(result));
103
- const indexArray = this.polyList.index.length < 65535 ? new Uint16Array(this.polyList.index) : new Uint32Array(this.polyList.index);
104
- this._indexBuffer = VertexBuffer.CreateElementArrayBuffer(this.renderer.gl, indexArray);
105
- this._indexArrayFormat = indexArray instanceof Uint16Array ? this.renderer.gl.UNSIGNED_SHORT : this.renderer.gl.UNSIGNED_INT;
106
- }
107
-
108
- get hasNormal() {
109
- return this._polyList.normal.length > 0;
110
- }
111
-
112
- get hasTexCoord0() {
113
- return this._polyList.texCoord0.length > 0;
114
- }
115
-
116
- get hasTexCoord1() {
117
- return this._polyList.texCoord1.length > 0;
118
- }
119
-
120
- get hasTexCoord2() {
121
- return this._polyList.texCoord2.length > 0;
122
- }
123
-
124
- get hasColor() {
125
- return this._polyList.color.length > 0;
126
- }
127
-
128
- get hasTangent() {
129
- return this._polyList.tangent.length > 0;
130
- }
131
-
132
- positionAttribParams(name) {
133
- return { name, stride: this._stride, size: 3, offset: 0, enable: true }
134
- }
135
-
136
- normalAttribParams(name) {
137
- return { name, stride: this._stride, size: 3, offset: this._offsets.normal, enable: true }
138
- }
139
-
140
- texCoord0AttribParams(name) {
141
- return { name, stride: this._stride, size: 2, offset: this._offsets.texCoord0, enable: true }
142
- }
143
-
144
- texCoord1AttribParams(name) {
145
- return { name, stride: this._stride, size: 2, offset: this._offsets.texCoord1, enable: true }
146
- }
147
-
148
- texCoord2AttribParams(name) {
149
- return { name, stride: this._stride, size: 2, offset: this._offsets.texCoord2, enable: true }
150
- }
151
-
152
- colorAttribParams(name) {
153
- return { name, stride: this._stride, size: 4, offset: this._offsets.color, enable: true }
154
- }
155
-
156
- tangentAttribParams(name) {
157
- return { name, stride: this._stride, size: 3, offset: this._offsets.tangent, enable: true }
158
- }
159
-
160
- bindBuffers() {
161
- this._vertexBuffer.bind(BufferTarget.ARRAY_BUFFER);
162
- this._indexBuffer.bind(BufferTarget.ELEMENT_ARRAY_BUFFER);
163
- }
164
-
165
- draw() {
166
- const { gl, state } = this.renderer;
167
-
168
- state.cullFaceEnabled = this.polyList.enableCullFace;
169
-
170
- switch (this.polyList.frontFace) {
171
- case PolyListFrontFace.CCW:
172
- state.frontFace = state.CCW;
173
- break;
174
- case PolyListFrontFace.CW:
175
- state.frontFace = state.CW;
176
- break;
177
- }
178
-
179
- switch (this.polyList.cullFace) {
180
- case PolyListCullFace.BACK:
181
- state.cullFace = state.BACK;
182
- break;
183
- case PolyListCullFace.FRONT:
184
- state.cullFace = state.FRONT;
185
- break;
186
- case PolyListCullFace.FRONT_AND_BACK:
187
- state.cullFace = state.FRONT_AND_BACK;
188
- break;
189
- }
190
-
191
-
192
-
193
- let mode = 0;
194
- switch (this._polyList.drawMode) {
195
- case DrawMode.POINTS:
196
- mode = gl.POINTS;
197
- break;
198
- case DrawMode.TRIANGLES:
199
- mode = gl.TRIANGLES;
200
- break;
201
- case DrawMode.TRIANGLE_FAN:
202
- mode = gl.TRIANGLE_FAN
203
- break;
204
- case DrawMode.TRIANGLE_STRIP:
205
- mode = gl.TRIANGLE_STRIP;
206
- break;
207
- case DrawMode.LINES:
208
- mode = gl.LINES;
209
- break;
210
- case DrawMode.LINE_STRIP:
211
- mode = gl.LINE_STRIP;
212
- break;
213
- }
214
-
215
- gl.lineWidth(this.polyList.lineWidth);
216
-
217
- gl.drawElements(mode, this.polyList.index.length, this._indexArrayFormat, 0);
218
- }
219
-
220
- destroy() {
221
- VertexBuffer.Delete(this._vertexBuffer);
222
- VertexBuffer.Delete(this._indexBuffer);
223
- }
224
- }