@cjcoding-git/gamelib 0.0.0-stage → 1.1.3

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 (136) hide show
  1. package/.github/ISSUE_TEMPLATE/bug_report.md +38 -0
  2. package/.github/ISSUE_TEMPLATE/feature_request.md +20 -0
  3. package/.github/dependabot.yml +6 -0
  4. package/.github/workflows/build.yml +54 -0
  5. package/.github/workflows/release.yml +79 -0
  6. package/LICENSE +21 -0
  7. package/README.md +6 -2
  8. package/assets/test-frog.gltf +1921 -0
  9. package/assets/test-frog.gml +0 -0
  10. package/buildtime.txt +1 -0
  11. package/buildversion.txt +1 -0
  12. package/dist/GameLib.js +71599 -0
  13. package/dist/GameLib.min.js +8 -0
  14. package/docs/2D/API.md +1 -0
  15. package/docs/2D/GETTING_STARTED.md +1 -0
  16. package/docs/3D/API.md +1 -0
  17. package/docs/3D/GETTING_STARTED.md +23 -0
  18. package/docs/Core/API.md +1 -0
  19. package/docs/Core/GETTING_STARTED.md +1 -0
  20. package/docs/README.md +32 -0
  21. package/package.json +21 -4
  22. package/scripts/gltf2gml.html +312 -0
  23. package/src/2D/Box.js +42 -0
  24. package/src/2D/Coord.js +17 -0
  25. package/src/2D/GameLib.js +317 -0
  26. package/src/2D/Renderable.js +31 -0
  27. package/src/2D/Rotation.js +42 -0
  28. package/src/2D/Size.js +17 -0
  29. package/src/2D/Sprite.js +56 -0
  30. package/src/2D/UI/Button.js +52 -0
  31. package/src/2D/UI/TextInput.js +77 -0
  32. package/src/2D/UI/UIElement.js +10 -0
  33. package/src/2D/UI/index.js +15 -0
  34. package/src/2D/index.js +24 -0
  35. package/src/3D/Camera.js +25 -0
  36. package/src/3D/GameLib.js +202 -0
  37. package/src/3D/Geometry/Box.js +39 -0
  38. package/src/3D/Geometry/Cone.js +45 -0
  39. package/src/3D/Geometry/ModelLoaders/GLBLoader.js +12 -0
  40. package/src/3D/Geometry/ModelLoaders/GLTFLoader.js +12 -0
  41. package/src/3D/Geometry/ModelLoaders/GMLLoader.js +114 -0
  42. package/src/3D/Geometry/ModelLoaders/OBJLoader.js +12 -0
  43. package/src/3D/Geometry/ModelLoaders/index.js +17 -0
  44. package/src/3D/Geometry/Pyramid.js +55 -0
  45. package/src/3D/Geometry/Sphere.js +37 -0
  46. package/src/3D/Geometry/index.js +19 -0
  47. package/src/3D/Lighting/AmbientLight.js +17 -0
  48. package/src/3D/Lighting/DirectionalLight.js +17 -0
  49. package/src/3D/Lighting/PointLight.js +17 -0
  50. package/src/3D/Lighting/index.js +15 -0
  51. package/src/3D/Material.js +181 -0
  52. package/src/3D/Mesh.js +142 -0
  53. package/src/3D/Object.js +13 -0
  54. package/src/3D/Position.js +15 -0
  55. package/src/3D/Rotation.js +21 -0
  56. package/src/3D/Scale.js +10 -0
  57. package/src/3D/ShaderFactory/FunctionParam.js +14 -0
  58. package/src/3D/ShaderFactory/Modifiers/Variable.js +85 -0
  59. package/src/3D/ShaderFactory/Modifiers/index.js +11 -0
  60. package/src/3D/ShaderFactory/Node.js +25 -0
  61. package/src/3D/ShaderFactory/NodeTypes/A.js +9 -0
  62. package/src/3D/ShaderFactory/NodeTypes/Add.js +13 -0
  63. package/src/3D/ShaderFactory/NodeTypes/AssignVariable.js +11 -0
  64. package/src/3D/ShaderFactory/NodeTypes/Clamp.js +14 -0
  65. package/src/3D/ShaderFactory/NodeTypes/Constant.js +9 -0
  66. package/src/3D/ShaderFactory/NodeTypes/Define.js +11 -0
  67. package/src/3D/ShaderFactory/NodeTypes/Divide.js +13 -0
  68. package/src/3D/ShaderFactory/NodeTypes/Dot.js +14 -0
  69. package/src/3D/ShaderFactory/NodeTypes/Exp2.js +9 -0
  70. package/src/3D/ShaderFactory/NodeTypes/Function.js +36 -0
  71. package/src/3D/ShaderFactory/NodeTypes/Group.js +9 -0
  72. package/src/3D/ShaderFactory/NodeTypes/Header.js +12 -0
  73. package/src/3D/ShaderFactory/NodeTypes/Length.js +9 -0
  74. package/src/3D/ShaderFactory/NodeTypes/MainFunction.js +7 -0
  75. package/src/3D/ShaderFactory/NodeTypes/Max.js +14 -0
  76. package/src/3D/ShaderFactory/NodeTypes/Mix.js +14 -0
  77. package/src/3D/ShaderFactory/NodeTypes/Multiply.js +13 -0
  78. package/src/3D/ShaderFactory/NodeTypes/Negative.js +9 -0
  79. package/src/3D/ShaderFactory/NodeTypes/NodeTypes.js +9 -0
  80. package/src/3D/ShaderFactory/NodeTypes/Normalize.js +10 -0
  81. package/src/3D/ShaderFactory/NodeTypes/Precision.js +11 -0
  82. package/src/3D/ShaderFactory/NodeTypes/RGB.js +9 -0
  83. package/src/3D/ShaderFactory/NodeTypes/Subtract.js +13 -0
  84. package/src/3D/ShaderFactory/NodeTypes/Symbol.js +9 -0
  85. package/src/3D/ShaderFactory/NodeTypes/Texture2D.js +10 -0
  86. package/src/3D/ShaderFactory/NodeTypes/Variable.js +22 -0
  87. package/src/3D/ShaderFactory/NodeTypes/Vector.js +15 -0
  88. package/src/3D/ShaderFactory/NodeTypes/XYZ.js +9 -0
  89. package/src/3D/ShaderFactory/NodeTypes/index.js +32 -0
  90. package/src/3D/ShaderFactory/PrecisionTypes.js +8 -0
  91. package/src/3D/ShaderFactory/Program.js +41 -0
  92. package/src/3D/ShaderFactory/VariableTypes.js +49 -0
  93. package/src/3D/ShaderFactory/index.js +45 -0
  94. package/src/3D/Texture.js +59 -0
  95. package/src/3D/TextureFactory.js +22 -0
  96. package/src/3D/Transform.js +35 -0
  97. package/src/3D/UI/UIImage.js +24 -0
  98. package/src/3D/UI/UILoading.js +41 -0
  99. package/src/3D/UI/UIObject.js +16 -0
  100. package/src/3D/UI/UIPath.js +25 -0
  101. package/src/3D/UI/UIRenderer.js +207 -0
  102. package/src/3D/UI/UIText.js +35 -0
  103. package/src/3D/UI/index.js +19 -0
  104. package/src/3D/Utils.js +9 -0
  105. package/src/3D/index.js +43 -0
  106. package/src/Core/AssetManager.js +116 -0
  107. package/src/Core/AudioManager.js +151 -0
  108. package/src/Core/Error.js +9 -0
  109. package/src/Core/FullscreenManager.js +49 -0
  110. package/src/Core/GameLibBase.js +29 -0
  111. package/src/Core/InputManager.js +195 -0
  112. package/src/Core/Loading.js +111 -0
  113. package/src/Core/Matrix/index.js +11 -0
  114. package/src/Core/Matrix/mat4.js +178 -0
  115. package/src/Core/Multiplayer.js +54 -0
  116. package/src/Core/Network/PeerNetwork.js +410 -0
  117. package/src/Core/Network/index.js +11 -0
  118. package/src/Core/Storage.js +45 -0
  119. package/src/Core/Store.js +45 -0
  120. package/src/Core/Utils.js +34 -0
  121. package/src/Core/index.js +30 -0
  122. package/src/Lib/Ammo.js +72 -0
  123. package/src/Lib/Matter.js +1 -0
  124. package/src/Shaders/Material/Fragment/GL1.glsl +49 -0
  125. package/src/Shaders/Material/Fragment/GL2.glsl +51 -0
  126. package/src/Shaders/Material/Vertex/GL1.glsl +19 -0
  127. package/src/Shaders/Material/Vertex/GL2.glsl +20 -0
  128. package/src/Shaders/UI/Fragment/GL1.glsl +5 -0
  129. package/src/Shaders/UI/Fragment/GL2.glsl +7 -0
  130. package/src/Shaders/UI/Vertex/GL1.glsl +10 -0
  131. package/src/Shaders/UI/Vertex/GL2.glsl +11 -0
  132. package/src/Shaders/UITexture/Fragment/GL1.glsl +6 -0
  133. package/src/Shaders/UITexture/Fragment/GL2.glsl +8 -0
  134. package/src/Shaders/UITexture/Vertex/GL1.glsl +10 -0
  135. package/src/Shaders/UITexture/Vertex/GL2.glsl +11 -0
  136. package/src/index.js +19 -0
@@ -0,0 +1,9 @@
1
+ import { NodeTypes } from "./NodeTypes.js"
2
+ import { Node } from "../Node.js"
3
+ NodeTypes.Group = class GroupNode extends Node {
4
+ constructor(value) {
5
+ super();
6
+ this._value = value;
7
+ this.text = `(${this._value.text})`;
8
+ }
9
+ };
@@ -0,0 +1,12 @@
1
+ import { NodeTypes } from "./NodeTypes.js"
2
+ import { Node } from "../Node.js"
3
+ NodeTypes.Header = class HeaderNode extends Node {
4
+ constructor(type, ...data) {
5
+ super();
6
+ this.canAddHeader = true;
7
+ this._type = type;
8
+ this._data = data;
9
+ var joinedData = this._data.join(' ');
10
+ this.text = `#${this._type} ${joinedData}`;
11
+ }
12
+ };
@@ -0,0 +1,9 @@
1
+ import { NodeTypes } from "./NodeTypes.js"
2
+ import { Node } from "../Node.js"
3
+ NodeTypes.Length = class LengthNode extends Node {
4
+ constructor(value) {
5
+ super();
6
+ this._value = value;
7
+ this.text = `length(${this._value.text})`;
8
+ }
9
+ };
@@ -0,0 +1,7 @@
1
+ import { NodeTypes } from "./NodeTypes.js"
2
+ import { VariableTypes } from "../VariableTypes.js"
3
+ NodeTypes.MainFunction = class MainFunctionNode extends NodeTypes.Function {
4
+ constructor() {
5
+ super(VariableTypes.VOID, "main", []);
6
+ }
7
+ };
@@ -0,0 +1,14 @@
1
+ import { NodeTypes } from "./NodeTypes.js"
2
+ import { Node } from "../Node.js"
3
+ NodeTypes.Max = class MaxNode extends Node {
4
+ constructor(...values) {
5
+ super();
6
+ this._values = values;
7
+ var valueTexts = [];
8
+ for(var i=0;i<this._values.length;i++) {
9
+ valueTexts.push(this._values[i].text);
10
+ }
11
+ var valuesText = valueTexts.join(', ');
12
+ this.text = `max(${valuesText})`;
13
+ }
14
+ };
@@ -0,0 +1,14 @@
1
+ import { NodeTypes } from "./NodeTypes.js"
2
+ import { Node } from "../Node.js"
3
+ NodeTypes.Mix = class MixNode extends Node {
4
+ constructor(...values) {
5
+ super();
6
+ this._values = values;
7
+ var valueTexts = [];
8
+ for(var i=0;i<this._values.length;i++) {
9
+ valueTexts.push(this._values[i].text);
10
+ }
11
+ var valuesText = valueTexts.join(', ');
12
+ this.text = `mix(${valuesText})`;
13
+ }
14
+ };
@@ -0,0 +1,13 @@
1
+ import { NodeTypes } from "./NodeTypes.js"
2
+ import { Node } from "../Node.js"
3
+ NodeTypes.Multiply = class MultiplyNode extends Node {
4
+ constructor(...values) {
5
+ super();
6
+ this._values = values;
7
+ var valueTexts = [];
8
+ for(var i=0;i<this._values.length;i++) {
9
+ valueTexts.push(this._values[i].text);
10
+ }
11
+ this.text = valueTexts.join(' * ');
12
+ }
13
+ };
@@ -0,0 +1,9 @@
1
+ import { NodeTypes } from "./NodeTypes.js"
2
+ import { Node } from "../Node.js"
3
+ NodeTypes.Negative = class NegativeNode extends Node {
4
+ constructor(value) {
5
+ super();
6
+ this._value = value;
7
+ this.text = `-${this._value.text}`;
8
+ }
9
+ };
@@ -0,0 +1,9 @@
1
+ import { GameLibCore } from "../../../Core/index.js"
2
+ class NodeTypes {
3
+ constructor() {
4
+ throw new GameLibCore.Error("Class GameLib3D.ShaderFactory.NodeTypes may not be constructed!");
5
+ }
6
+ }
7
+ export {
8
+ NodeTypes
9
+ }
@@ -0,0 +1,10 @@
1
+ import { NodeTypes } from "./NodeTypes.js"
2
+ import { Node } from "../Node.js"
3
+ NodeTypes.Normalize = class NormalizeNode extends Node {
4
+ constructor(value) {
5
+ super();
6
+ this._value = value;
7
+ var valueText = this._value.text;
8
+ this.text = `normalize(${valueText})`;
9
+ }
10
+ };
@@ -0,0 +1,11 @@
1
+ import { NodeTypes } from "./NodeTypes.js"
2
+ import { Node } from "../Node.js"
3
+ NodeTypes.Precision = class PrecisionNode extends Node {
4
+ constructor(type, precision) {
5
+ super();
6
+ this.canAddHeader = true;
7
+ this._type = type;
8
+ this._precision = precision;
9
+ this.text = `precision ${this._precision} ${this._type};`;
10
+ }
11
+ };
@@ -0,0 +1,9 @@
1
+ import { NodeTypes } from "./NodeTypes.js"
2
+ import { Node } from "../Node.js"
3
+ NodeTypes.RGB = class RGBNode extends Node {
4
+ constructor(value) {
5
+ super();
6
+ this._value = value;
7
+ this.text = `(${this._value.text}).rgb`;
8
+ }
9
+ };
@@ -0,0 +1,13 @@
1
+ import { NodeTypes } from "./NodeTypes.js"
2
+ import { Node } from "../Node.js"
3
+ NodeTypes.Subtract = class SubtractNode extends Node {
4
+ constructor(...values) {
5
+ super();
6
+ this._values = values;
7
+ var valueTexts = [];
8
+ for(var i=0;i<this._values.length;i++) {
9
+ valueTexts.push(this._values[i].text);
10
+ }
11
+ this.text = valueTexts.join(' - ');
12
+ }
13
+ };
@@ -0,0 +1,9 @@
1
+ import { NodeTypes } from "./NodeTypes.js"
2
+ import { Node } from "../Node.js"
3
+ NodeTypes.Symbol = class SymbolNode extends Node {
4
+ constructor(name) {
5
+ super();
6
+ this._name = name;
7
+ this.text = name;
8
+ }
9
+ };
@@ -0,0 +1,10 @@
1
+ import { NodeTypes } from "./NodeTypes.js"
2
+ import { Node } from "../Node.js"
3
+ NodeTypes.Texture2D = class Texture2DNode extends Node {
4
+ constructor(value1, value2) {
5
+ super();
6
+ this._value1 = value1;
7
+ this._value2 = value2;
8
+ this.text = `texture2D(${value1.text}, ${value2.text})`;
9
+ }
10
+ };
@@ -0,0 +1,22 @@
1
+ import { NodeTypes } from "./NodeTypes.js"
2
+ import { Node } from "../Node.js"
3
+ import { Modifiers } from "../Modifiers/index.js"
4
+ NodeTypes.Variable = class VariableNode extends Node {
5
+ constructor(type, name, modifiers=null, initialValue=null) {
6
+ super();
7
+ if(!modifiers || !(modifiers instanceof Modifiers.Variable)) modifiers = new Modifiers.Variable();
8
+ modifiers.update();
9
+ this.canAddNode = true;
10
+ this.canAddVar = true;
11
+ this._type = type;
12
+ this._name = name;
13
+ this._modifiers = modifiers;
14
+ this._initialValue = initialValue;
15
+ var initialValueText = "";
16
+ if(this._initialValue !== null) {
17
+ var valueString = this._initialValue.text;
18
+ initialValueText = ` = ${valueString}`;
19
+ }
20
+ this.text = `${this._modifiers.text}${this._type} ${this._name}${initialValueText};`;
21
+ }
22
+ };
@@ -0,0 +1,15 @@
1
+ import { NodeTypes } from "./NodeTypes.js"
2
+ import { Node } from "../Node.js"
3
+ NodeTypes.Vector = class VectorNode extends Node {
4
+ constructor(type, ...values) {
5
+ super();
6
+ this._type = type;
7
+ this._values = values;
8
+ var valueTexts = [];
9
+ for(var i=0;i<this._values.length;i++) {
10
+ valueTexts.push(this._values[i].text);
11
+ }
12
+ var joinedValues = valueTexts.join(', ');
13
+ this.text = `${this._type}(${joinedValues})`;
14
+ }
15
+ };
@@ -0,0 +1,9 @@
1
+ import { NodeTypes } from "./NodeTypes.js"
2
+ import { Node } from "../Node.js"
3
+ NodeTypes.XYZ = class XYZNode extends Node {
4
+ constructor(value) {
5
+ super();
6
+ this._value = value;
7
+ this.text = `(${this._value.text}).xyz`;
8
+ }
9
+ };
@@ -0,0 +1,32 @@
1
+ import { GameLibCore } from "../../../Core/index.js"
2
+ import { NodeTypes } from "./NodeTypes.js"
3
+ import "./Header.js"
4
+ import "./Variable.js"
5
+ import "./Function.js"
6
+ import "./MainFunction.js"
7
+ import "./AssignVariable.js"
8
+ import "./Constant.js"
9
+ import "./Symbol.js"
10
+ import "./Add.js"
11
+ import "./Subtract.js"
12
+ import "./Multiply.js"
13
+ import "./Divide.js"
14
+ import "./Vector.js"
15
+ import "./Normalize.js"
16
+ import "./Precision.js"
17
+ import "./Dot.js"
18
+ import "./Max.js"
19
+ import "./XYZ.js"
20
+ import "./Group.js"
21
+ import "./Texture2D.js"
22
+ import "./RGB.js"
23
+ import "./A.js"
24
+ import "./Length.js"
25
+ import "./Exp2.js"
26
+ import "./Define.js"
27
+ import "./Negative.js"
28
+ import "./Clamp.js"
29
+ import "./Mix.js"
30
+ export {
31
+ NodeTypes
32
+ }
@@ -0,0 +1,8 @@
1
+ var PrecisionTypes = {
2
+ "LOW": "lowp",
3
+ "MEDIUM": "mediump",
4
+ "HIGH": "highp"
5
+ };
6
+ export {
7
+ PrecisionTypes
8
+ }
@@ -0,0 +1,41 @@
1
+ import { GameLibCore } from "../../Core/index.js"
2
+ class Program {
3
+ constructor() {
4
+ this._header = [];
5
+ this._vars = [];
6
+ this._nodes = [];
7
+ }
8
+ get header() {
9
+ return this._header;
10
+ }
11
+ get vars() {
12
+ return this._vars;
13
+ }
14
+ get nodes() {
15
+ return this._nodes;
16
+ }
17
+ addNode(node) {
18
+ if(!node.canAddNode) {
19
+ throw new GameLibCore.Error("Cannot add a GameLib3D.ShaderFactory.Node that has canAddNode set to false!");
20
+ }
21
+ node._parent = this;
22
+ this._nodes.push(node);
23
+ }
24
+ addVar(node) {
25
+ if(!node.canAddVar) {
26
+ throw new GameLibCore.Error("Cannot add a GameLib3D.ShaderFactory.Node as a variable that has canAddVar set to false!");
27
+ }
28
+ node._parent = this;
29
+ this._vars.push(node);
30
+ }
31
+ addHeader(node) {
32
+ if(!node.canAddHeader) {
33
+ throw new GameLibCore.Error("Cannot add a GameLib3D.ShaderFactory.Node as a header that has canAddHeader set to false!");
34
+ }
35
+ node._parent = this;
36
+ this._header.push(node);
37
+ }
38
+ }
39
+ export {
40
+ Program
41
+ }
@@ -0,0 +1,49 @@
1
+ var VariableTypes = {
2
+ "VECTOR": {
3
+ "FLOAT": {
4
+ "2": "vec2",
5
+ "3": "vec3",
6
+ "4": "vec4"
7
+ },
8
+ "DOUBLE": {
9
+ "2": "dvec2",
10
+ "3": "dvec3",
11
+ "4": "dvec4"
12
+ },
13
+ "INT": {
14
+ "2": "ivec2",
15
+ "3": "ivec3",
16
+ "4": "ivec4"
17
+ },
18
+ "UINT": {
19
+ "2": "uvec2",
20
+ "3": "uvec3",
21
+ "4": "uvec4"
22
+ },
23
+ "BOOL": {
24
+ "2": "bvec2",
25
+ "3": "bvec3",
26
+ "4": "bvec4"
27
+ }
28
+ },
29
+ "MATRIX": {
30
+ "2": "mat2",
31
+ "3": "mat3",
32
+ "4": "mat4",
33
+ "custom": function(rows, cols) {
34
+ return `mat${rows}x${cols}`;
35
+ }
36
+ },
37
+ "FLOAT": "float",
38
+ "DOUBLE": "double",
39
+ "INT": "int",
40
+ "UINT": "uint",
41
+ "BOOL": "bool",
42
+ "VOID": "void",
43
+ "SAMPLER": {
44
+ "2D": "sampler2D"
45
+ }
46
+ };
47
+ export {
48
+ VariableTypes
49
+ }
@@ -0,0 +1,45 @@
1
+ import { GameLibCore } from "../../Core/index.js"
2
+ import { Node } from "./Node.js"
3
+ import { Modifiers } from "./Modifiers/index.js"
4
+ import { FunctionParam } from "./FunctionParam.js"
5
+ import { VariableTypes } from "./VariableTypes.js"
6
+ import { PrecisionTypes } from "./PrecisionTypes.js"
7
+ import { NodeTypes } from "./NodeTypes/index.js"
8
+ import { Program } from "./Program.js"
9
+ class ShaderFactory {
10
+ constructor() {
11
+ throw new GameLibCore.Error("Class GameLib3D.ShaderFactory may not be constructed!");
12
+ }
13
+ static Node = Node;
14
+ static Modifiers = Modifiers;
15
+ static FunctionParam = FunctionParam;
16
+ static VariableTypes = VariableTypes;
17
+ static PrecisionTypes = PrecisionTypes;
18
+ static NodeTypes = NodeTypes;
19
+ static Program = Program;
20
+ static compileFactory(shaderFactoryProgram) {
21
+ var headers = shaderFactoryProgram.header;
22
+ var headerTexts = [];
23
+ for(var i=0;i<headers.length;i++) {
24
+ headerTexts.push(headers[i].text);
25
+ }
26
+ var headersText = headerTexts.join("\n");
27
+ var vars = shaderFactoryProgram.vars;
28
+ var varTexts = [];
29
+ for(var i=0;i<vars.length;i++) {
30
+ varTexts.push(vars[i].text);
31
+ }
32
+ var varsText = varTexts.join("\n");
33
+ var nodes = shaderFactoryProgram.nodes;
34
+ var nodeTexts = [];
35
+ for(var i=0;i<nodes.length;i++) {
36
+ nodeTexts.push(nodes[i].text);
37
+ }
38
+ var nodesText = nodeTexts.join("\n");
39
+ var result = `${headersText}\n${varsText}\n${nodesText}`;
40
+ return result;
41
+ }
42
+ }
43
+ export {
44
+ ShaderFactory
45
+ }
@@ -0,0 +1,59 @@
1
+ import { GameLibCore } from "../Core/index.js"
2
+ class Texture {
3
+ constructor(gl, source = null, options = {}) {
4
+ this.gl = gl;
5
+ this.options = options;
6
+ this.target = options.target || gl.TEXTURE_2D;
7
+ this.texture = gl.createTexture();
8
+ gl.bindTexture(this.target, this.texture);
9
+ this.setParameters(options);
10
+ if (source !== null) {
11
+ this.update(source);
12
+ }
13
+ }
14
+ setParameters(options = {}) {
15
+ const gl = this.gl;
16
+ const target = this.target;
17
+ gl.texParameteri(target, gl.TEXTURE_WRAP_S, options.wrapS || gl.CLAMP_TO_EDGE);
18
+ gl.texParameteri(target, gl.TEXTURE_WRAP_T, options.wrapT || gl.CLAMP_TO_EDGE);
19
+ gl.texParameteri(target, gl.TEXTURE_MIN_FILTER, options.minFilter || gl.LINEAR);
20
+ gl.texParameteri(target, gl.TEXTURE_MAG_FILTER, options.magFilter || gl.LINEAR);
21
+ return this;
22
+ }
23
+ update(source) {
24
+ const gl = this.gl;
25
+ gl.bindTexture(this.target, this.texture);
26
+ if (this.options.flipY !== undefined) {
27
+ gl.pixelStorei(gl.UNPACK_FLIP_Y_WEBGL, this.options.flipY);
28
+ }
29
+ gl.texImage2D(
30
+ this.target,
31
+ 0,
32
+ this.options.internalFormat || gl.RGBA,
33
+ this.options.format || gl.RGBA,
34
+ this.options.type || gl.UNSIGNED_BYTE,
35
+ source
36
+ );
37
+ if (this.options.generateMipmaps) {
38
+ gl.generateMipmap(this.target);
39
+ }
40
+ return this;
41
+ }
42
+ bind(unit = 0) {
43
+ const gl = this.gl;
44
+ gl.activeTexture(gl.TEXTURE0 + unit);
45
+ gl.bindTexture(this.target, this.texture);
46
+ return this;
47
+ }
48
+ static fromImage(gl, image, options = {}) {
49
+ return new Texture(gl, image, options);
50
+ }
51
+ static load(gl, url, options = {}) {
52
+ return GameLibCore.AssetManager.shared
53
+ .loadImage(url, { crossOrigin: options.crossOrigin })
54
+ .then(image => Texture.fromImage(gl, image, options));
55
+ }
56
+ }
57
+ export {
58
+ Texture
59
+ }
@@ -0,0 +1,22 @@
1
+ import { GameLibCore } from "../Core/index.js"
2
+ import { Texture } from "./Texture.js"
3
+ class TextureFactory {
4
+ constructor() {
5
+ throw new GameLibCore.Error("Class TextureFactory may not be constructed!");
6
+ }
7
+ static create(gl, source, options = {}) {
8
+ if (source instanceof Texture) {
9
+ return source;
10
+ }
11
+ return new Texture(gl, source, options);
12
+ }
13
+ static fromImage(gl, image, options = {}) {
14
+ return Texture.fromImage(gl, image, options);
15
+ }
16
+ static load(gl, url, options = {}) {
17
+ return Texture.load(gl, url, options);
18
+ }
19
+ }
20
+ export {
21
+ TextureFactory
22
+ }
@@ -0,0 +1,35 @@
1
+ import { Position } from "./Position.js"
2
+ import { Rotation } from "./Rotation.js"
3
+ import { Scale } from "./Scale.js"
4
+ import { mat4 } from "../Core/Matrix/mat4.js"
5
+ class Transform {
6
+ constructor(position=new Position(), rotation=new Rotation(), scale=new Scale()) {
7
+ this.position = position;
8
+ this.rotation = rotation;
9
+ this.scale = scale;
10
+ }
11
+ translate(x, y, z) {
12
+ this.position.translate(x, y, z);
13
+ }
14
+ rotate(x, y, z) {
15
+ this.rotation.rotate(x, y, z);
16
+ }
17
+ getModelMatrix() {
18
+ var matrix = mat4.create();
19
+ mat4.translate(matrix, matrix, [this.position.x, this.position.y, this.position.z]);
20
+ mat4.rotateX(matrix, matrix, this.rotation.x);
21
+ mat4.rotateY(matrix, matrix, this.rotation.y);
22
+ mat4.rotateZ(matrix, matrix, this.rotation.z);
23
+ mat4.scale(matrix, matrix, [this.scale.x, this.scale.y, this.scale.x]);
24
+ return matrix;
25
+ }
26
+ getNormalMatrix(modelViewMatrix) {
27
+ var normalMatrix = mat4.create();
28
+ mat4.invert(normalMatrix, modelViewMatrix);
29
+ mat4.transpose(normalMatrix, normalMatrix);
30
+ return normalMatrix;
31
+ }
32
+ }
33
+ export {
34
+ Transform
35
+ }
@@ -0,0 +1,24 @@
1
+ import { UIObject } from "./UIObject.js"
2
+ class UIImage extends UIObject {
3
+ constructor(gameLib, scene, x, y, width, height, url, options={}) {
4
+ super(gameLib, scene, x, y, width, height, options.color);
5
+ this.isTexturedUI = true;
6
+ this.source = null;
7
+ this.textureDirty = true;
8
+ var image = new Image();
9
+ if(options.crossOrigin) {
10
+ image.crossOrigin = options.crossOrigin;
11
+ }
12
+ image.onload = () => {
13
+ this.source = image;
14
+ this.textureDirty = true;
15
+ };
16
+ image.onerror = () => {
17
+ console.warn(`[GameLib] Failed to load image: ${url}`);
18
+ };
19
+ image.src = url;
20
+ }
21
+ }
22
+ export {
23
+ UIImage
24
+ }
@@ -0,0 +1,41 @@
1
+ import { Loading } from "../../Core/Loading.js"
2
+ import { UIObject } from "./UIObject.js"
3
+ class UILoading extends UIObject {
4
+ constructor(gameLib) {
5
+ var x = 0;
6
+ var y = 0;
7
+ var width = gameLib._canvas.width;
8
+ var height = gameLib._canvas.height
9
+ super(gameLib, "loading", x, y, width, height, [1.0, 1.0, 1.0, 1.0]);
10
+ this.isTexturedUI = true;
11
+ this.source = document.createElement('canvas');
12
+ this.source.width = width;
13
+ this.source.height = height;
14
+ this.textureDirty = true;
15
+ this.config = {};
16
+ this.setConfig(this.config);
17
+ this.update();
18
+ }
19
+ setConfig(config) {
20
+ this.config = config;
21
+ }
22
+ update() {
23
+ Loading.render(this.source, this.source.getContext('2d'), this.config);
24
+ this.textureDirty = true;
25
+ if(this.width !== this._gameLib._canvas.width) {
26
+ this.width = this._gameLib._canvas.width;
27
+ }
28
+ if(this.height !== this._gameLib._canvas.height) {
29
+ this.height = this._gameLib._canvas.height;
30
+ }
31
+ if(this.source.width !== this.width) {
32
+ this.source.width = this.width;
33
+ }
34
+ if(this.source.height !== this.height) {
35
+ this.source.height = this.height;
36
+ }
37
+ }
38
+ }
39
+ export {
40
+ UILoading
41
+ }
@@ -0,0 +1,16 @@
1
+ class UIObject {
2
+ constructor(gameLib, scene, x, y, width, height, color) {
3
+ this._gameLib = gameLib;
4
+ this.scene = scene;
5
+ this.x = x;
6
+ this.y = y;
7
+ this.width = width;
8
+ this.height = height;
9
+ this.color = color;
10
+ this.visible = true;
11
+ }
12
+ update() {}
13
+ }
14
+ export {
15
+ UIObject
16
+ }
@@ -0,0 +1,25 @@
1
+ import { UIObject } from "./UIObject.js";
2
+ class UIPath extends UIObject {
3
+ constructor(gameLib, scene, x, y, width, height, pathData, options={}) {
4
+ super(gameLib, scene, x, y, width, height, options.color);
5
+ this.isTexturedUI = true;
6
+ this.source = document.createElement('canvas');
7
+ this.source.width = Math.max(1, Math.ceil(width));
8
+ this.source.height = Math.max(1, Math.ceil(height));
9
+ this.textureDirty = true;
10
+ var ctx = this.source.getContext('2d');
11
+ var path = new Path2D(pathData);
12
+ if(options.fillStyle) {
13
+ ctx.fillStyle = options.fillStyle;
14
+ ctx.fill(path);
15
+ }
16
+ if(options.strokeStyle) {
17
+ ctx.strokeStyle = options.strokeStyle;
18
+ ctx.lineWidth = options.lineWidth || 1;
19
+ ctx.stroke(path);
20
+ }
21
+ }
22
+ }
23
+ export {
24
+ UIPath
25
+ }