diff --git a/src/game-lib-a-2-utils.js b/src/game-lib-a-2-utils.js index 3cac979..8b0b69d 100644 --- a/src/game-lib-a-2-utils.js +++ b/src/game-lib-a-2-utils.js @@ -424,8 +424,8 @@ GameLib.Utils.InvertMeshWindingOrder = function(mesh) { }.bind(this) ); - mesh.computeNormals = true; - mesh.createInstance(); + //mesh.computeNormals = true; + //mesh.createInstance(); }; /** diff --git a/src/game-lib-a-component-a.js b/src/game-lib-a-component-a.js index 705c5bb..3421f60 100644 --- a/src/game-lib-a-component-a.js +++ b/src/game-lib-a-component-a.js @@ -333,7 +333,37 @@ GameLib.Component.PASS_FXAA = 0x64; GameLib.Component.RENDER_CONFIGURATION = 0x65; GameLib.Component.MATERIAL_BASIC = 0x66; GameLib.Component.TEXTURE = 0x67; -GameLib.Component.MAX_COMPONENTS = 0x68; +GameLib.Component.MATERIAL_PHONG = 0x68; + +GameLib.Component.GEOMETRY = 0x69; +GameLib.Component.GEOMETRY_BOX = 0x6a; +GameLib.Component.GEOMETRY_CIRCLE = 0x6b; +GameLib.Component.GEOMETRY_CONE = 0x6c; +GameLib.Component.GEOMETRY_CYLINDER = 0x6d; +GameLib.Component.GEOMETRY_DODECAHEDRON = 0x6e; +GameLib.Component.GEOMETRY_EDGES = 0x6f; +GameLib.Component.GEOMETRY_EXTRUDE = 0x70; +GameLib.Component.GEOMETRY_ICOSAHEDRON = 0x71; +GameLib.Component.GEOMETRY_LATHE = 0x72; +GameLib.Component.GEOMETRY_OCTAHEDRON = 0x73; +GameLib.Component.GEOMETRY_PARAMETRIC = 0x74; +GameLib.Component.GEOMETRY_PLANE = 0x75; +GameLib.Component.GEOMETRY_POLYHEDRON = 0x76; +GameLib.Component.GEOMETRY_RING = 0x77; +GameLib.Component.GEOMETRY_SHAPE = 0x78; +GameLib.Component.GEOMETRY_SPHERE = 0x79; +GameLib.Component.GEOMETRY_TETRAHEDRON = 0x7a; +GameLib.Component.GEOMETRY_TEXT = 0x7b; +GameLib.Component.GEOMETRY_TORUS = 0x7c; +GameLib.Component.GEOMETRY_TORUS_KNOT = 0x7d; +GameLib.Component.GEOMETRY_TUBE = 0x7e; +GameLib.Component.GEOMETRY_WIREFRAME = 0x7f; +GameLib.Component.CURVE = 0x80; +GameLib.Component.CURVE_PATH = 0x81; +GameLib.Component.CURVE_PATH_D2 = 0x82; +GameLib.Component.CURVE_PATH_D2_SHAPE = 0x83; + +GameLib.Component.MAX_COMPONENTS = 0x84; GameLib.Component.GRAPHICS_RUNTIME = 0x1; GameLib.Component.PHYSICS_RUNTIME = 0x2; @@ -972,6 +1002,174 @@ GameLib.Component.GetComponentInfo = function(number) { constructor : GameLib.D3.Texture, apiConstructor : GameLib.D3.API.Texture }; + case 0x68 : return { + name : 'GameLib.D3.Material.Phong', + runtime : GameLib.Component.GRAPHICS_RUNTIME, + constructor : GameLib.D3.Material.Phong, + apiConstructor : GameLib.D3.API.Material.Phong + }; + case 0x69 : return { + name : 'GameLib.D3.Geometry', + runtime : GameLib.Component.GRAPHICS_RUNTIME, + constructor : GameLib.D3.Geometry, + apiConstructor : GameLib.D3.API.Geometry + }; + case 0x6a : return { + name : 'GameLib.D3.Geometry.Box', + runtime : GameLib.Component.GRAPHICS_RUNTIME, + constructor : GameLib.D3.Geometry.Box, + apiConstructor : GameLib.D3.API.Geometry.Box + }; + case 0x6b : return { + name : 'GameLib.D3.Geometry.Circle', + runtime : GameLib.Component.GRAPHICS_RUNTIME, + constructor : GameLib.D3.Geometry.Circle, + apiConstructor : GameLib.D3.API.Geometry.Circle + }; + case 0x6c : return { + name : 'GameLib.D3.Geometry.Cone', + runtime : GameLib.Component.GRAPHICS_RUNTIME, + constructor : GameLib.D3.Geometry.Cone, + apiConstructor : GameLib.D3.API.Geometry.Cone + }; + case 0x6d : return { + name : 'GameLib.D3.Geometry.Cylinder', + runtime : GameLib.Component.GRAPHICS_RUNTIME, + constructor : GameLib.D3.Geometry.Cylinder, + apiConstructor : GameLib.D3.API.Geometry.Cylinder + }; + case 0x6e : return { + name : 'GameLib.D3.Geometry.Dodecahedron', + runtime : GameLib.Component.GRAPHICS_RUNTIME, + constructor : GameLib.D3.Geometry.Dodecahedron, + apiConstructor : GameLib.D3.API.Geometry.Dodecahedron + }; + case 0x6f : return { + name : 'GameLib.D3.Geometry.Edges', + runtime : GameLib.Component.GRAPHICS_RUNTIME, + constructor : GameLib.D3.Geometry.Edges, + apiConstructor : GameLib.D3.API.Geometry.Edges + }; + case 0x70 : return { + name : 'GameLib.D3.Geometry.Extrude', + runtime : GameLib.Component.GRAPHICS_RUNTIME, + constructor : GameLib.D3.Geometry.Extrude, + apiConstructor : GameLib.D3.API.Geometry.Extrude + }; + case 0x71 : return { + name : 'GameLib.D3.Geometry.Icosahedron', + runtime : GameLib.Component.GRAPHICS_RUNTIME, + constructor : GameLib.D3.Geometry.Icosahedron, + apiConstructor : GameLib.D3.API.Geometry.Icosahedron + }; + case 0x72 : return { + name : 'GameLib.D3.Geometry.Lathe', + runtime : GameLib.Component.GRAPHICS_RUNTIME, + constructor : GameLib.D3.Geometry.Lathe, + apiConstructor : GameLib.D3.API.Geometry.Lathe + }; + case 0x73 : return { + name : 'GameLib.D3.Geometry.Octahedron', + runtime : GameLib.Component.GRAPHICS_RUNTIME, + constructor : GameLib.D3.Geometry.Octahedron, + apiConstructor : GameLib.D3.API.Geometry.Octahedron + }; + case 0x74 : return { + name : 'GameLib.D3.Geometry.Parametric', + runtime : GameLib.Component.GRAPHICS_RUNTIME, + constructor : GameLib.D3.Geometry.Parametric, + apiConstructor : GameLib.D3.API.Geometry.Parametric + }; + case 0x75 : return { + name : 'GameLib.D3.Geometry.Plane', + runtime : GameLib.Component.GRAPHICS_RUNTIME, + constructor : GameLib.D3.Geometry.Plane, + apiConstructor : GameLib.D3.API.Geometry.Plane + }; + case 0x76 : return { + name : 'GameLib.D3.Geometry.Polyhedron', + runtime : GameLib.Component.GRAPHICS_RUNTIME, + constructor : GameLib.D3.Geometry.Polyhedron, + apiConstructor : GameLib.D3.API.Geometry.Polyhedron + }; + case 0x77 : return { + name : 'GameLib.D3.Geometry.Ring', + runtime : GameLib.Component.GRAPHICS_RUNTIME, + constructor : GameLib.D3.Geometry.Ring, + apiConstructor : GameLib.D3.API.Geometry.Ring + }; + case 0x78 : return { + name : 'GameLib.D3.Geometry.Shape', + runtime : GameLib.Component.GRAPHICS_RUNTIME, + constructor : GameLib.D3.Geometry.Shape, + apiConstructor : GameLib.D3.API.Geometry.Shape + }; + case 0x79 : return { + name : 'GameLib.D3.Geometry.Sphere', + runtime : GameLib.Component.GRAPHICS_RUNTIME, + constructor : GameLib.D3.Geometry.Sphere, + apiConstructor : GameLib.D3.API.Geometry.Sphere + }; + case 0x7a : return { + name : 'GameLib.D3.Geometry.Tetrahedron', + runtime : GameLib.Component.GRAPHICS_RUNTIME, + constructor : GameLib.D3.Geometry.Tetrahedron, + apiConstructor : GameLib.D3.API.Geometry.Tetrahedron + }; + case 0x7b : return { + name : 'GameLib.D3.Geometry.Text', + runtime : GameLib.Component.GRAPHICS_RUNTIME, + constructor : GameLib.D3.Geometry.Text, + apiConstructor : GameLib.D3.API.Geometry.Text + }; + case 0x7c : return { + name : 'GameLib.D3.Geometry.Torus', + runtime : GameLib.Component.GRAPHICS_RUNTIME, + constructor : GameLib.D3.Geometry.Torus, + apiConstructor : GameLib.D3.API.Geometry.Torus + }; + case 0x7d : return { + name : 'GameLib.D3.Geometry.TorusKnot', + runtime : GameLib.Component.GRAPHICS_RUNTIME, + constructor : GameLib.D3.Geometry.TorusKnot, + apiConstructor : GameLib.D3.API.Geometry.TorusKnot + }; + case 0x7e : return { + name : 'GameLib.D3.Geometry.Tube', + runtime : GameLib.Component.GRAPHICS_RUNTIME, + constructor : GameLib.D3.Geometry.Tube, + apiConstructor : GameLib.D3.API.Geometry.Tube + }; + case 0x7f : return { + name : 'GameLib.D3.Geometry.Wireframe', + runtime : GameLib.Component.GRAPHICS_RUNTIME, + constructor : GameLib.D3.Geometry.Wireframe, + apiConstructor : GameLib.D3.API.Geometry.Wireframe + }; + case 0x80 : return { + name : 'GameLib.Curve', + runtime : GameLib.Component.GRAPHICS_RUNTIME, + constructor : GameLib.Curve, + apiConstructor : GameLib.API.Curve + }; + case 0x81 : return { + name : 'GameLib.Curve.Path', + runtime : GameLib.Component.GRAPHICS_RUNTIME, + constructor : GameLib.Curve.Path, + apiConstructor : GameLib.API.Curve.Path + }; + case 0x82 : return { + name : 'GameLib.Curve.Path.D2', + runtime : GameLib.Component.GRAPHICS_RUNTIME, + constructor : GameLib.Curve.Path.D2, + apiConstructor : GameLib.API.Curve.Path.D2 + }; + case 0x82 : return { + name : 'GameLib.Curve.Path.D2.Shape', + runtime : GameLib.Component.GRAPHICS_RUNTIME, + constructor : GameLib.Curve.Path.D2.Shape, + apiConstructor : GameLib.API.Curve.Path.D2.Shape + }; break; } diff --git a/src/game-lib-api-box3.js b/src/game-lib-api-box3.js new file mode 100644 index 0000000..877ac4b --- /dev/null +++ b/src/game-lib-api-box3.js @@ -0,0 +1,20 @@ +/** + * GameLib.API.Box3 + * @param min + * @param max + * @constructor + */ +GameLib.API.Box3 = function ( + min, + max +) { + if (GameLib.Utils.UndefinedOrNull(min)) { + min = new GameLib.API.Vector3(0,0,0); + } + this.min = min; + + if (GameLib.Utils.UndefinedOrNull(max)) { + max = new GameLib.API.Vector3(1,1,1); + } + this.max = max; +}; diff --git a/src/game-lib-api-curve-a.js b/src/game-lib-api-curve-a.js new file mode 100644 index 0000000..35b871c --- /dev/null +++ b/src/game-lib-api-curve-a.js @@ -0,0 +1,89 @@ +/** + * GameLib.API.Curve + * @param id + * @param name + * @param curveType + * @param parentEntity + * @param arcLenghDivisions + * @constructor + */ +GameLib.API.Curve = function ( + id, + name, + curveType, + parentEntity, + arcLenghDivisions +) { + + if (GameLib.Utils.UndefinedOrNull(id)) { + id = GameLib.Utils.RandomId(); + } + this.id = id; + + if (GameLib.Utils.UndefinedOrNull(curveType)) { + curveType = GameLib.API.Curve.CURVE_TYPE_NONE; + } + this.curveType = curveType; + + if (GameLib.Utils.UndefinedOrNull(name)) { + + switch (this.curveType) { + case GameLib.API.Curve.CURVE_TYPE_NONE : + name = 'Curve'; + break; + case GameLib.API.Curve.CURVE_TYPE_PATH : + name = 'Curve Path'; + break; + default: + console.log('no nice name for curve'); + } + + name += ' (' + this.id + ')'; + } + this.name = name; + + if (GameLib.Utils.UndefinedOrNull(arcLenghDivisions)) { + arcLenghDivisions = 200; + } + this.arcLenghDivisions = arcLenghDivisions; + + GameLib.API.Component.call( + this, + GameLib.API.Curve.GetComponentType(this.curveType), + parentEntity + ); +}; + +GameLib.API.Curve.prototype = Object.create(GameLib.API.Curve.prototype); +GameLib.API.Curve.prototype.constructor = GameLib.API.Curve; + +GameLib.API.Curve.GetComponentType = function(curveType) { + + var componentType = null; + + switch (curveType) { + case GameLib.API.Curve.CURVE_TYPE_NONE : + componentType = GameLib.Component.CURVE; + break; + case GameLib.API.Curve.CURVE_TYPE_PATH : + componentType = GameLib.Component.CURVE_PATH; + break; + case GameLib.API.Curve.CURVE_TYPE_PATH_2D : + componentType = GameLib.Component.CURVE_PATH_D2; + break; + case GameLib.API.Curve.CURVE_TYPE_PATH_2D_SHAPE : + componentType = GameLib.Component.CURVE_PATH_D2_SHAPE; + break; + default : + throw new Error('unhandled curve type'); + } + + return componentType; +}; + +GameLib.API.Curve.CURVE_TYPE_NONE = 0x0; +GameLib.API.Curve.CURVE_TYPE_PATH = 0x1; +GameLib.API.Curve.CURVE_TYPE_PATH_2D = 0x2; +GameLib.API.Curve.CURVE_TYPE_PATH_2D_SHAPE = 0x3; + + diff --git a/src/game-lib-api-curve-path-a.js b/src/game-lib-api-curve-path-a.js new file mode 100644 index 0000000..d2e0e6d --- /dev/null +++ b/src/game-lib-api-curve-path-a.js @@ -0,0 +1,44 @@ +/** + * GameLib.API.Curve.Path + * @constructor + * @param apiCurve + * @param curves + * @param autoClose + */ +GameLib.API.Curve.Path = function ( + apiCurve, + curves, + autoClose +) { + if (GameLib.Utils.UndefinedOrNull(apiCurve)) { + apiCurve = { + curveType: GameLib.API.Curve.CURVE_TYPE_PATH + }; + } + + if (GameLib.Utils.UndefinedOrNull(apiCurve.curveType)) { + apiCurve.curveType = GameLib.API.Curve.CURVE_TYPE_PATH; + } + + if (GameLib.Utils.UndefinedOrNull(curves)) { + curves = []; + } + this.curves = curves; + + if (GameLib.Utils.UndefinedOrNull(autoClose)) { + autoClose = false; + } + this.autoClose = autoClose; + + GameLib.API.Curve.call( + this, + apiCurve.id, + apiCurve.name, + apiCurve.curveType, + apiCurve.parentEntity, + apiCurve.arcLenghDivisions + ); +}; + +GameLib.API.Curve.Path.prototype = Object.create(GameLib.API.Curve.prototype); +GameLib.API.Curve.Path.prototype.constructor = GameLib.API.Curve.Path; diff --git a/src/game-lib-api-curve-path-d2-a.js b/src/game-lib-api-curve-path-d2-a.js new file mode 100644 index 0000000..fca147c --- /dev/null +++ b/src/game-lib-api-curve-path-d2-a.js @@ -0,0 +1,35 @@ +/** + * GameLib.API.Curve.Path.D2 + * @constructor + * @param apiCurvePath + * @param points + */ +GameLib.API.Curve.Path.D2 = function ( + apiCurvePath, + points +) { + if (GameLib.Utils.UndefinedOrNull(apiCurvePath)) { + apiCurvePath = { + curveType: GameLib.API.Curve.CURVE_TYPE_PATH_2D + }; + } + + if (GameLib.Utils.UndefinedOrNull(apiCurvePath.curveType)) { + apiCurvePath.curveType = GameLib.API.Curve.CURVE_TYPE_PATH_2D; + } + + if (GameLib.Utils.UndefinedOrNull(points)) { + points = []; + } + this.points = points; + + GameLib.API.Curve.Path.call( + this, + apiCurvePath, + apiCurvePath.curves, + apiCurvePath.autoClose + ); +}; + +GameLib.API.Curve.Path.D2.prototype = Object.create(GameLib.API.Curve.Path.prototype); +GameLib.API.Curve.Path.D2.prototype.constructor = GameLib.API.Curve.Path.D2; diff --git a/src/game-lib-api-curve-path-d2-shape.js b/src/game-lib-api-curve-path-d2-shape.js new file mode 100644 index 0000000..dd88a66 --- /dev/null +++ b/src/game-lib-api-curve-path-d2-shape.js @@ -0,0 +1,27 @@ +/** + * GameLib.API.Curve.Path.D2.Shape + * @constructor + * @param apiCurvePathD2 + */ +GameLib.API.Curve.Path.D2.Shape = function ( + apiCurvePathD2 +) { + if (GameLib.Utils.UndefinedOrNull(apiCurvePathD2)) { + apiCurvePathD2 = { + curveType : GameLib.API.Curve.CURVE_TYPE_PATH_2D_SHAPE + }; + } + + if (GameLib.Utils.UndefinedOrNull(apiCurvePathD2.curveType)) { + apiCurvePathD2.curveType = GameLib.API.Curve.CURVE_TYPE_PATH_2D_SHAPE ; + } + + GameLib.API.Curve.Path.call( + this, + apiCurvePathD2, + apiCurvePathD2.points + ); +}; + +GameLib.API.Curve.Path.D2.Shape.prototype = Object.create(GameLib.API.Curve.Path.D2.prototype); +GameLib.API.Curve.Path.D2.Shape.prototype.constructor = GameLib.API.Curve.Path.D2.Shape; diff --git a/src/game-lib-api-sphere.js b/src/game-lib-api-sphere.js new file mode 100644 index 0000000..0811bc4 --- /dev/null +++ b/src/game-lib-api-sphere.js @@ -0,0 +1,20 @@ +/** + * GameLib.API.Sphere + * @constructor + * @param center + * @param radius + */ +GameLib.API.Sphere = function ( + center, + radius +) { + if (GameLib.Utils.UndefinedOrNull(center)) { + center = new GameLib.API.Vector3(0,0,0); + } + this.center = center; + + if (GameLib.Utils.UndefinedOrNull(radius)) { + radius = 1; + } + this.radius = radius; +}; diff --git a/src/game-lib-box3.js b/src/game-lib-box3.js new file mode 100644 index 0000000..077b215 --- /dev/null +++ b/src/game-lib-box3.js @@ -0,0 +1,79 @@ +/** + * GameLib.Box3 + * @param implementation + * @param apiBox3 + * @param parentObject + * @constructor + */ +GameLib.Box3 = function ( + implementation, + apiBox3, + parentObject +) { + + this.implementation = implementation; + this.implementation.isNotThreeThrow(); + + if (GameLib.Utils.UndefinedOrNull(parentObject)) { + parentObject = null; + } + this.parentObject = parentObject; + + if (GameLib.Utils.UndefinedOrNull(apiBox3)) { + apiBox3 = {}; + } + + GameLib.API.Box3.call( + this, + apiBox3.min, + apiBox3.max + ); + + this.createInstance(); +}; + +GameLib.Box3.prototype = Object.create(GameLib.API.Box3.prototype); +GameLib.Box3.prototype.constructor = GameLib.Box3; + +/** + * Creates an instance GameLib.Box3 + * @returns {*} + */ +GameLib.Box3.prototype.createInstance = function() { + + this.instance = new THREE.Box3( + this.min.instance, + this.max.instance + ); + +}; + +/** + * Updates GameLib.Box3 instance + * @param property + */ +GameLib.Box3.prototype.updateInstance = function(property) { + + if (property === 'min') { + this.instance.min.x = this.min.x; + this.instance.min.y = this.min.y; + this.instance.min.z = this.min.z; + } + + if (property === 'max') { + this.instance.max.x = this.max.x; + this.instance.max.y = this.max.y; + this.instance.max.z = this.max.z; + } +}; + +/** + * GameLib.Box3 to GameLib.API.Box3 + * @returns {GameLib.API.Box3} + */ +GameLib.Box3.prototype.toApiObject = function() { + return new GameLib.API.Box3( + this.min.toApiObject(), + this.max.toApiObject() + ); +}; diff --git a/src/game-lib-curve-a.js b/src/game-lib-curve-a.js new file mode 100644 index 0000000..12444e9 --- /dev/null +++ b/src/game-lib-curve-a.js @@ -0,0 +1,87 @@ +/** + * GameLib.Curve + * @param graphics GameLib.GraphicsRuntime + * @param apiCurve GameLib.API.Curve + * @property curveType + * @constructor + */ +GameLib.Curve = function( + graphics, + apiCurve +) { + + this.graphics = graphics; + this.graphics.isNotThreeThrow(); + + if (GameLib.Utils.UndefinedOrNull(apiCurve)) { + apiCurve = {}; + } + + GameLib.API.Curve.call( + this, + apiCurve.id, + apiCurve.name, + apiCurve.curveType, + apiCurve.parentEntity, + apiCurve.arcLenghDivisions + ); + + var linkedObjects = {}; + + switch (this.curveType) { + case GameLib.API.Curve.CURVE_TYPE_PATH : + linkedObjects.curves = [GameLib.Curve]; + break; + } + + GameLib.Component.call( + this, + linkedObjects + ); +}; + +GameLib.Curve.prototype = Object.create(GameLib.Component.prototype); +GameLib.Curve.prototype.constructor = GameLib.Curve; + +/** + * Create Instance + */ +GameLib.Curve.prototype.createInstance = function() { + + if (GameLib.Utils.UndefinedOrNull(this.instance)) { + console.warn('you should not instantiate this curve object directly'); + this.instance = new THREE.Curve(); + } + + this.instance.arcLenghDivisions = this.arcLenghDivisions; + + GameLib.Component.prototype.createInstance.call(this); +}; + +/** + * Updates the instance with the current state + */ +GameLib.Curve.prototype.updateInstance = function(property) { + + if (property === 'arcLenghDivisions') { + this.instance.arcLenghDivisions = this.arcLenghDivisions; + } + + GameLib.Component.prototype.updateInstance.call(this, property); +}; + +/** + * Converts a GameLib.Curve to a new GameLib.API.Curve + * @returns {GameLib.API.Curve} + */ +GameLib.Curve.prototype.toApiObject = function() { + + return new GameLib.API.Curve( + this.id, + this.name, + this.curveType, + GameLib.Utils.IdOrNull(this.parentEntity), + this.arcLenghDivisions + ); + +}; diff --git a/src/game-lib-curve-path-d2-shape.js b/src/game-lib-curve-path-d2-shape.js new file mode 100644 index 0000000..0ea12b8 --- /dev/null +++ b/src/game-lib-curve-path-d2-shape.js @@ -0,0 +1,74 @@ +/** + * GameLib.Curve.Path.D2 + * @param graphics GameLib.GraphicsRuntime + * @param apiCurvePathD2 + * @constructor + */ +GameLib.Curve.Path.D2.Shape = function( + graphics, + apiCurvePathD2 +) { + + this.graphics = graphics; + this.graphics.isNotThreeThrow(); + + if (GameLib.Utils.UndefinedOrNull(apiCurvePathD2)) { + apiCurvePathD2 = { + curveType : GameLib.API.Curve.CURVE_TYPE_PATH_2D_SHAPE + }; + } + + GameLib.API.Curve.Path.D2.call( + this, + apiCurvePathD2, + apiCurvePathD2.points + ); + + GameLib.Curve.Path.D2.call( + this, + this.graphics, + this + ); + +}; + +GameLib.Curve.Path.D2.Shape.prototype = Object.create(GameLib.Curve.Path.D2.prototype); +GameLib.Curve.Path.D2.Shape.prototype.constructor = GameLib.Curve.Path.D2.Shape; + +/** + * Creates a camera instance + * @returns {*} + */ +GameLib.Curve.Path.D2.Shape.prototype.createInstance = function() { + + this.instance = new THREE.Shape( + this.points.map( + function(point) { + return point.instance; + } + ) + ); + + GameLib.Curve.Path.D2.prototype.createInstance.call(this); +}; + +/** + * Updates the instance with the current state + */ +GameLib.Curve.Path.D2.Shape.prototype.updateInstance = function(property) { + GameLib.Curve.Path.D2.prototype.updateInstance.call(this, property); +}; + +/** + * Converts a GameLib.Curve to a GameLib.API.Curve + * @returns {GameLib.API.Curve} + */ +GameLib.Curve.Path.D2.Shape.prototype.toApiObject = function() { + + var apiCurvePathD2 = GameLib.Curve.Path.D2.prototype.toApiObject.call(this); + + return new GameLib.API.Curve.Path.D2.Shape( + apiCurvePathD2 + ); + +}; diff --git a/src/game-lib-curve-path-d2.js b/src/game-lib-curve-path-d2.js new file mode 100644 index 0000000..0694d51 --- /dev/null +++ b/src/game-lib-curve-path-d2.js @@ -0,0 +1,101 @@ +/** + * GameLib.Curve.Path.D2 + * @param graphics GameLib.GraphicsRuntime + * @param apiCurvePath + * @constructor + */ +GameLib.Curve.Path.D2 = function( + graphics, + apiCurvePath +) { + + this.graphics = graphics; + this.graphics.isNotThreeThrow(); + + if (GameLib.Utils.UndefinedOrNull(apiCurvePath)) { + apiCurvePath = { + curveType : GameLib.API.Curve.CURVE_TYPE_PATH_2D + }; + } + + GameLib.API.Curve.Path.D2.call( + this, + apiCurvePath, + apiCurvePath.points + ); + + this.points = this.points.map( + function(point) { + return new GameLib.Vector2( + this.graphics, + point + ); + }.bind(this) + ); + + GameLib.Curve.Path.call( + this, + this.graphics, + this + ); + +}; + +GameLib.Curve.Path.D2.prototype = Object.create(GameLib.Curve.Path.prototype); +GameLib.Curve.Path.D2.prototype.constructor = GameLib.Curve.Path.D2; + +/** + * Creates a camera instance + * @returns {*} + */ +GameLib.Curve.Path.D2.prototype.createInstance = function() { + + if (GameLib.Utils.UndefinedOrNull(this.instance)) { + this.instance = new THREE.Path( + this.points.map( + function(point) { + return point.instance; + } + ) + ); + } + + GameLib.Curve.Path.prototype.createInstance.call(this); +}; + +/** + * Updates the instance with the current state + */ +GameLib.Curve.Path.D2.prototype.updateInstance = function(property) { + + if (property === 'points') { + console.warn('todo: update points (and test it)'); + this.instance.points = this.points.map( + function(point) { + return point.instance; + } + ); + return; + } + + GameLib.Curve.Path.prototype.updateInstance.call(this, property); +}; + +/** + * Converts a GameLib.Curve to a GameLib.API.Curve + * @returns {GameLib.API.Curve} + */ +GameLib.Curve.Path.D2.prototype.toApiObject = function() { + + var apiCurvePath = GameLib.Curve.Path.prototype.toApiObject.call(this); + + return new GameLib.API.Curve.Path.D2( + apiCurvePath, + this.points.map( + function(point) { + return point.toApiObject(); + } + ) + ); + +}; diff --git a/src/game-lib-curve-path.js b/src/game-lib-curve-path.js new file mode 100644 index 0000000..6b65b39 --- /dev/null +++ b/src/game-lib-curve-path.js @@ -0,0 +1,109 @@ +/** + * GameLib.Curve.Path + * @param graphics GameLib.GraphicsRuntime + * @param apiCurvePath + * @constructor + */ +GameLib.Curve.Path = function( + graphics, + apiCurvePath +) { + + this.graphics = graphics; + this.graphics.isNotThreeThrow(); + + if (GameLib.Utils.UndefinedOrNull(apiCurvePath)) { + apiCurvePath = { + curveType : GameLib.API.Curve.CURVE_TYPE_PATH + }; + } + + GameLib.API.Curve.Path.call( + this, + apiCurvePath, + apiCurvePath.curves, + apiCurvePath.autoClose + ); + + this.curves = this.curves.map( + function(curve) { + if (curve instanceof GameLib.API.Curve) { + return new GameLib.Curve( + this.graphics, + curve + ); + } + }.bind(this) + ); + + GameLib.Curve.call( + this, + this.graphics, + this + ); + +}; + +GameLib.Curve.Path.prototype = Object.create(GameLib.Curve.prototype); +GameLib.Curve.Path.prototype.constructor = GameLib.Curve.Path; + +/** + * Creates a camera instance + * @returns {*} + */ +GameLib.Curve.Path.prototype.createInstance = function() { + + if (GameLib.Utils.UndefinedOrNull(this.instance)) { + console.warn('you should not instantiate this curve object directly'); + this.instance = new THREE.CurvePath(); + } + + this.instance.curves = this.curves.map( + function(curve) { + return curve.instance; + } + ); + + this.instance.autoClose = this.autoClose; + + GameLib.Curve.prototype.createInstance.call(this); +}; + +/** + * Updates the instance with the current state + */ +GameLib.Curve.Path.prototype.updateInstance = function(property) { + + if (property === 'curves') { + console.warn('todo: update curves'); + return; + } + + if (property === 'autoClose') { + this.instance.autoClose = this.autoClose; + return; + } + + GameLib.Curve.prototype.updateInstance.call(this, property); +}; + +/** + * Converts a GameLib.Curve to a GameLib.API.Curve + * @returns {GameLib.API.Curve} + */ +GameLib.Curve.Path.prototype.toApiObject = function() { + + var apiCurve = GameLib.Curve.prototype.toApiObject.call(this); + + var apiCurvePath = new GameLib.API.Curve.Path( + apiCurve, + this.curves.map( + function(curve) { + return GameLib.Utils.IdOrNull(curve); + } + ), + this.autoClose + ); + + return apiCurvePath; +}; diff --git a/src/game-lib-d3-api-camera-a.js b/src/game-lib-d3-api-camera-a.js index e22e0be..78e39bc 100644 --- a/src/game-lib-d3-api-camera-a.js +++ b/src/game-lib-d3-api-camera-a.js @@ -5,6 +5,8 @@ * @param cameraType GameLib.D3.API.Camera.CAMERA_TYPE_* * @param aspect * @param position GameLib.API.Vector3 + * @param rotation + * @param quaternion * @param lookAt GameLib.API.Vector3 * @param parentEntity * @constructor @@ -15,6 +17,8 @@ GameLib.D3.API.Camera = function( cameraType, aspect, position, + rotation, + quaternion, lookAt, parentEntity ) { @@ -77,6 +81,16 @@ GameLib.D3.API.Camera = function( } this.lookAt = lookAt; + if (GameLib.Utils.UndefinedOrNull(rotation)) { + rotation = new GameLib.API.Vector3(); + } + this.rotation = rotation; + + if (GameLib.Utils.UndefinedOrNull(quaternion)) { + quaternion = new GameLib.API.Quaternion(); + } + this.quaternion = quaternion; + var componentType = null; switch (this.cameraType) { diff --git a/src/game-lib-d3-api-camera-cube.js b/src/game-lib-d3-api-camera-cube.js index 48255bf..b3bec61 100644 --- a/src/game-lib-d3-api-camera-cube.js +++ b/src/game-lib-d3-api-camera-cube.js @@ -55,6 +55,8 @@ GameLib.D3.API.Camera.Cube = function( apiCamera.cameraType, 1, apiCamera.position, + apiCamera.rotation, + apiCamera.quaternion, apiCamera.lookAt, apiCamera.parentEntity ); diff --git a/src/game-lib-d3-api-camera-orthographic.js b/src/game-lib-d3-api-camera-orthographic.js index a60d0fd..620d323 100644 --- a/src/game-lib-d3-api-camera-orthographic.js +++ b/src/game-lib-d3-api-camera-orthographic.js @@ -111,6 +111,8 @@ GameLib.D3.API.Camera.Orthographic = function( apiCamera.cameraType, apiCamera.aspect, apiCamera.position, + apiCamera.rotation, + apiCamera.quaternion, apiCamera.lookAt, apiCamera.parentEntity ); diff --git a/src/game-lib-d3-api-camera-perspective.js b/src/game-lib-d3-api-camera-perspective.js index b33ffe6..4a0ed4d 100644 --- a/src/game-lib-d3-api-camera-perspective.js +++ b/src/game-lib-d3-api-camera-perspective.js @@ -80,6 +80,8 @@ GameLib.D3.API.Camera.Perspective = function( apiCamera.cameraType, apiCamera.aspect, apiCamera.position, + apiCamera.rotation, + apiCamera.quaternion, apiCamera.lookAt, apiCamera.parentEntity ); diff --git a/src/game-lib-d3-api-camera-stereo-a.js b/src/game-lib-d3-api-camera-stereo-a.js index 5d38c73..53c9f73 100644 --- a/src/game-lib-d3-api-camera-stereo-a.js +++ b/src/game-lib-d3-api-camera-stereo-a.js @@ -31,6 +31,8 @@ GameLib.D3.API.Camera.Stereo = function( apiCamera.cameraType, apiCamera.aspect, apiCamera.position, + apiCamera.rotation, + apiCamera.quaternion, apiCamera.lookAt, apiCamera.parentEntity ); diff --git a/src/game-lib-d3-api-geometry-0.js b/src/game-lib-d3-api-geometry-0.js new file mode 100644 index 0000000..9d452bf --- /dev/null +++ b/src/game-lib-d3-api-geometry-0.js @@ -0,0 +1,351 @@ +/** + * GameLib.D3.API.Geometry + * @param id + * @param name + * @param geometryType + * @param isBuffer + * @param parentEntity + * @param boundingBox + * @param boundingSphere + * @param colors + * @param faces + * @param faceVertexUvs + * @param lineDistances + * @param morphTargets + * @param morphNormals + * @param skinWeights + * @param skinIndices + * @param vertices + * @param verticesNeedsUpdate + * @param elementsNeedUpdate + * @param uvsNeedUpdate + * @param normalsNeedUpdate + * @param colorsNeedUpdate + * @param groupsNeedUpdate + * @param lineDistancesNeedUpdate + * @constructor + */ +GameLib.D3.API.Geometry = function( + id, + name, + geometryType, + isBuffer, + parentEntity, + boundingBox, + boundingSphere, + colors, + faces, + faceVertexUvs, + lineDistances, + morphTargets, + morphNormals, + skinWeights, + skinIndices, + vertices, + verticesNeedsUpdate, + elementsNeedUpdate, + uvsNeedUpdate, + normalsNeedUpdate, + colorsNeedUpdate, + groupsNeedUpdate, + lineDistancesNeedUpdate +) { + if (GameLib.Utils.UndefinedOrNull(id)) { + id = GameLib.Utils.RandomId(); + } + this.id = id; + + if (GameLib.Utils.UndefinedOrNull(geometryType)) { + geometryType = GameLib.D3.API.Geometry.GEOMETRY_TYPE_NORMAL; + } + this.geometryType = geometryType; + + if (GameLib.Utils.UndefinedOrNull(name)) { + + switch (this.geometryType) { + case GameLib.D3.API.Geometry.GEOMETRY_TYPE_NORMAL : + name = 'Geometry'; + break; + case GameLib.D3.API.Geometry.GEOMETRY_TYPE_BOX : + name = 'Geometry Box'; + break; + case GameLib.D3.API.Geometry.GEOMETRY_TYPE_CIRCLE : + name = 'Geometry Circle'; + break; + case GameLib.D3.API.Geometry.GEOMETRY_TYPE_CONE : + name = 'Geometry Cone'; + break; + case GameLib.D3.API.Geometry.GEOMETRY_TYPE_CYLINDER : + name = 'Geometry Cylinder'; + break; + case GameLib.D3.API.Geometry.GEOMETRY_TYPE_DODECAHEDRON : + name = 'Geometry Dodecahedron'; + break; + case GameLib.D3.API.Geometry.GEOMETRY_TYPE_EDGES : + name = 'Geometry Edges'; + break; + case GameLib.D3.API.Geometry.GEOMETRY_TYPE_EXTRUDE : + name = 'Geometry Extrude'; + break; + case GameLib.D3.API.Geometry.GEOMETRY_TYPE_ICOSAHEDRON : + name = 'Geometry Icosahedron'; + break; + case GameLib.D3.API.Geometry.GEOMETRY_TYPE_LATHE : + name = 'Geometry Lathe'; + break; + case GameLib.D3.API.Geometry.GEOMETRY_TYPE_OCTAHEDRON : + name = 'Geometry Octahedron'; + break; + case GameLib.D3.API.Geometry.GEOMETRY_TYPE_PARAMETRIC : + name = 'Geometry Parametric'; + break; + case GameLib.D3.API.Geometry.GEOMETRY_TYPE_PLANE : + name = 'Geometry Plane'; + break; + case GameLib.D3.API.Geometry.GEOMETRY_TYPE_POLYHEDRON : + name = 'Geometry Polyhedron'; + break; + case GameLib.D3.API.Geometry.GEOMETRY_TYPE_RING : + name = 'Geometry Ring'; + break; + case GameLib.D3.API.Geometry.GEOMETRY_TYPE_SHAPE : + name = 'Geometry Shape'; + break; + case GameLib.D3.API.Geometry.GEOMETRY_TYPE_SPHERE : + name = 'Geometry Sphere'; + break; + case GameLib.D3.API.Geometry.GEOMETRY_TYPE_TETRAHEDRON : + name = 'Geometry Tetrahedron'; + break; + case GameLib.D3.API.Geometry.GEOMETRY_TYPE_TEXT : + name = 'Geometry Text'; + break; + case GameLib.D3.API.Geometry.GEOMETRY_TYPE_TORUS : + name = 'Geometry Torus'; + break; + case GameLib.D3.API.Geometry.GEOMETRY_TYPE_TORUS_KNOT : + name = 'Geometry Torus Knot'; + break; + case GameLib.D3.API.Geometry.GEOMETRY_TYPE_TUBE : + name = 'Geometry Tube'; + break; + case GameLib.D3.API.Geometry.GEOMETRY_TYPE_WIREFRAME : + name = 'Geometry Wireframe'; + break; + default : + console.warn('no nice name for geometry'); + name = 'Geometry'; + } + + name += ' (' + id + ')'; + } + this.name = name; + + if (GameLib.Utils.UndefinedOrNull(isBuffer)) { + isBuffer = false; + } + this.isBuffer = isBuffer; + + if (GameLib.Utils.UndefinedOrNull(boundingBox)) { + boundingBox = new GameLib.API.Box3(); + } + this.boundingBox = boundingBox; + + if (GameLib.Utils.UndefinedOrNull(boundingSphere)) { + boundingSphere = new GameLib.API.Sphere(); + } + this.boundingSphere = boundingSphere; + + if (GameLib.Utils.UndefinedOrNull(colors)) { + colors = []; + } + this.colors = colors; + + if (GameLib.Utils.UndefinedOrNull(faces)) { + faces = []; + } + this.faces = faces; + + if (GameLib.Utils.UndefinedOrNull(lineDistances)) { + lineDistances = []; + } + this.lineDistances = lineDistances; + + if (GameLib.Utils.UndefinedOrNull(morphTargets)) { + morphTargets = []; + } + this.morphTargets = morphTargets; + + if (GameLib.Utils.UndefinedOrNull(morphNormals)) { + morphTargets = []; + } + this.morphNormals = morphNormals; + + if (GameLib.Utils.UndefinedOrNull(skinWeights)) { + skinWeights = []; + } + this.skinWeights = skinWeights; + + if (GameLib.Utils.UndefinedOrNull(skinIndices)) { + skinIndices = []; + } + this.skinIndices = skinIndices; + + if (GameLib.Utils.UndefinedOrNull(vertices)) { + vertices = []; + } + this.vertices = vertices; + + if (GameLib.Utils.UndefinedOrNull(verticesNeedsUpdate)) { + verticesNeedsUpdate = false; + } + this.verticesNeedsUpdate = verticesNeedsUpdate; + + if (GameLib.Utils.UndefinedOrNull(elementsNeedUpdate)) { + elementsNeedUpdate = false; + } + this.elementsNeedUpdate = elementsNeedUpdate; + + if (GameLib.Utils.UndefinedOrNull(uvsNeedUpdate)) { + uvsNeedUpdate = false; + } + this.uvsNeedUpdate = uvsNeedUpdate; + + if (GameLib.Utils.UndefinedOrNull(normalsNeedUpdate)) { + normalsNeedUpdate = false; + } + this.normalsNeedUpdate = normalsNeedUpdate; + + if (GameLib.Utils.UndefinedOrNull(colorsNeedUpdate)) { + colorsNeedUpdate = false; + } + this.colorsNeedUpdate = colorsNeedUpdate; + + if (GameLib.Utils.UndefinedOrNull(groupsNeedUpdate)) { + groupsNeedUpdate = false; + } + this.groupsNeedUpdate = groupsNeedUpdate; + + if (GameLib.Utils.UndefinedOrNull(lineDistancesNeedUpdate)) { + lineDistancesNeedUpdate = false; + } + this.lineDistancesNeedUpdate = lineDistancesNeedUpdate; + + GameLib.API.Component.call( + this, + GameLib.D3.API.Geometry.GetComponentType(this.geometryType), + parentEntity + ); +}; + +GameLib.D3.API.Geometry.prototype = Object.create(GameLib.API.Component.prototype); +GameLib.D3.API.Geometry.prototype.constructor = GameLib.D3.API.Geometry; + +GameLib.D3.API.Geometry.GetComponentType = function(geometryType) { + + var componentType = null; + + switch (geometryType) { + case GameLib.D3.API.Geometry.GEOMETRY_TYPE_NORMAL : + componentType = GameLib.Component.GEOMETRY; + break; + case GameLib.D3.API.Geometry.GEOMETRY_TYPE_BOX : + componentType = GameLib.Component.GEOMETRY_BOX; + break; + case GameLib.D3.API.Geometry.GEOMETRY_TYPE_CIRCLE : + componentType = GameLib.Component.GEOMETRY_CIRCLE; + break; + case GameLib.D3.API.Geometry.GEOMETRY_TYPE_CONE : + componentType = GameLib.Component.GEOMETRY_CONE; + break; + case GameLib.D3.API.Geometry.GEOMETRY_TYPE_CYLINDER : + componentType = GameLib.Component.GEOMETRY_CYLINDER; + break; + case GameLib.D3.API.Geometry.GEOMETRY_TYPE_DODECAHEDRON : + componentType = GameLib.Component.GEOMETRY_DODECAHEDRON; + break; + case GameLib.D3.API.Geometry.GEOMETRY_TYPE_EDGES : + componentType = GameLib.Component.GEOMETRY_EDGES; + break; + case GameLib.D3.API.Geometry.GEOMETRY_TYPE_EXTRUDE : + componentType = GameLib.Component.GEOMETRY_EXTRUDE; + break; + case GameLib.D3.API.Geometry.GEOMETRY_TYPE_ICOSAHEDRON : + componentType = GameLib.Component.GEOMETRY_ICOSAHEDRON; + break; + case GameLib.D3.API.Geometry.GEOMETRY_TYPE_LATHE : + componentType = GameLib.Component.GEOMETRY_LATHE; + break; + case GameLib.D3.API.Geometry.GEOMETRY_TYPE_OCTAHEDRON : + componentType = GameLib.Component.GEOMETRY_OCTAHEDRON; + break; + case GameLib.D3.API.Geometry.GEOMETRY_TYPE_PARAMETRIC : + componentType = GameLib.Component.GEOMETRY_PARAMETRIC; + break; + case GameLib.D3.API.Geometry.GEOMETRY_TYPE_PLANE : + componentType = GameLib.Component.GEOMETRY_PLANE; + break; + case GameLib.D3.API.Geometry.GEOMETRY_TYPE_POLYHEDRON : + componentType = GameLib.Component.GEOMETRY_POLYHEDRON; + break; + case GameLib.D3.API.Geometry.GEOMETRY_TYPE_RING : + componentType = GameLib.Component.GEOMETRY_RING; + break; + case GameLib.D3.API.Geometry.GEOMETRY_TYPE_SHAPE : + componentType = GameLib.Component.GEOMETRY_SHAPE; + break; + case GameLib.D3.API.Geometry.GEOMETRY_TYPE_SPHERE : + componentType = GameLib.Component.GEOMETRY_SPHERE; + break; + case GameLib.D3.API.Geometry.GEOMETRY_TYPE_TETRAHEDRON : + componentType = GameLib.Component.GEOMETRY_TETRAHEDRON; + break; + case GameLib.D3.API.Geometry.GEOMETRY_TYPE_TEXT : + componentType = GameLib.Component.GEOMETRY_TEXT; + break; + case GameLib.D3.API.Geometry.GEOMETRY_TYPE_TORUS : + componentType = GameLib.Component.GEOMETRY_TORUS; + break; + case GameLib.D3.API.Geometry.GEOMETRY_TYPE_TORUS_KNOT : + componentType = GameLib.Component.GEOMETRY_TORUS_KNOT; + break; + case GameLib.D3.API.Geometry.GEOMETRY_TYPE_TUBE : + componentType = GameLib.Component.GEOMETRY_TUBE; + break; + case GameLib.D3.API.Geometry.GEOMETRY_TYPE_WIREFRAME : + componentType = GameLib.Component.GEOMETRY_WIREFRAME; + break; + default: + throw new Error('unhandled geometry type: ' + geometryType); + } + + return componentType; +}; + +/** + * Geometry Type + * @type {number} + */ +GameLib.D3.API.Geometry.GEOMETRY_TYPE_NORMAL = 0x0; +GameLib.D3.API.Geometry.GEOMETRY_TYPE_BOX = 0x1; +GameLib.D3.API.Geometry.GEOMETRY_TYPE_CIRCLE = 0x2; +GameLib.D3.API.Geometry.GEOMETRY_TYPE_CONE = 0x3; +GameLib.D3.API.Geometry.GEOMETRY_TYPE_CYLINDER = 0x4; +GameLib.D3.API.Geometry.GEOMETRY_TYPE_DODECAHEDRON = 0x5; +GameLib.D3.API.Geometry.GEOMETRY_TYPE_EDGES = 0x6; +GameLib.D3.API.Geometry.GEOMETRY_TYPE_EXTRUDE = 0x7; +GameLib.D3.API.Geometry.GEOMETRY_TYPE_ICOSAHEDRON = 0x8; +GameLib.D3.API.Geometry.GEOMETRY_TYPE_LATHE = 0x9; +GameLib.D3.API.Geometry.GEOMETRY_TYPE_OCTAHEDRON = 0xa; +GameLib.D3.API.Geometry.GEOMETRY_TYPE_PARAMETRIC = 0xb; +GameLib.D3.API.Geometry.GEOMETRY_TYPE_PLANE = 0xc; +GameLib.D3.API.Geometry.GEOMETRY_TYPE_POLYHEDRON = 0xd; +GameLib.D3.API.Geometry.GEOMETRY_TYPE_RING = 0xe; +GameLib.D3.API.Geometry.GEOMETRY_TYPE_SHAPE = 0xf; +GameLib.D3.API.Geometry.GEOMETRY_TYPE_SPHERE = 0x10; +GameLib.D3.API.Geometry.GEOMETRY_TYPE_TETRAHEDRON = 0x11; +GameLib.D3.API.Geometry.GEOMETRY_TYPE_TEXT = 0x12; +GameLib.D3.API.Geometry.GEOMETRY_TYPE_TORUS = 0x13; +GameLib.D3.API.Geometry.GEOMETRY_TYPE_TORUS_KNOT = 0x14; +GameLib.D3.API.Geometry.GEOMETRY_TYPE_TUBE = 0x15; +GameLib.D3.API.Geometry.GEOMETRY_TYPE_WIREFRAME = 0x16; diff --git a/src/game-lib-d3-api-geometry-box.js b/src/game-lib-d3-api-geometry-box.js new file mode 100644 index 0000000..fb6244c --- /dev/null +++ b/src/game-lib-d3-api-geometry-box.js @@ -0,0 +1,91 @@ +/** + * GameLib.D3.API.Geometry.Box + * @param apiGeometry + * @param width + * @param height + * @param depth + * @param widthSegments + * @param heightSegments + * @param depthSegments + * @constructor + */ +GameLib.D3.API.Geometry.Box = function( + apiGeometry, + width, + height, + depth, + widthSegments, + heightSegments, + depthSegments +) { + + if (GameLib.Utils.UndefinedOrNull(apiGeometry)) { + apiGeometry = { + geometryType: GameLib.D3.API.Geometry.GEOMETRY_TYPE_BOX + }; + } + + if (GameLib.Utils.UndefinedOrNull(apiGeometry.geometryType)) { + apiGeometry.geometryType = GameLib.D3.API.Geometry.GEOMETRY_TYPE_BOX; + } + + if (GameLib.Utils.UndefinedOrNull(width)) { + width = 1; + } + this.width = width; + + if (GameLib.Utils.UndefinedOrNull(height)) { + height = 1; + } + this.height = height; + + if (GameLib.Utils.UndefinedOrNull(depth)) { + depth = 1; + } + this.depth = depth; + + if (GameLib.Utils.UndefinedOrNull(widthSegments)) { + widthSegments = 1; + } + this.widthSegments = widthSegments; + + if (GameLib.Utils.UndefinedOrNull(heightSegments)) { + heightSegments = 1; + } + this.heightSegments = heightSegments; + + if (GameLib.Utils.UndefinedOrNull(depthSegments)) { + depthSegments = 1; + } + this.depthSegments = depthSegments; + + GameLib.D3.API.Geometry.call( + this, + apiGeometry.id, + apiGeometry.name, + apiGeometry.geometryType, + apiGeometry.isBuffer, + apiGeometry.parentEntity, + apiGeometry.boundingBox, + apiGeometry.boundingSphere, + apiGeometry.colors, + apiGeometry.faces, + apiGeometry.faceVertexUvs, + apiGeometry.lineDistances, + apiGeometry.morphTargets, + apiGeometry.morphNormals, + apiGeometry.skinWeights, + apiGeometry.skinIndices, + apiGeometry.vertices, + apiGeometry.verticesNeedsUpdate, + apiGeometry.elementsNeedUpdate, + apiGeometry.uvsNeedUpdate, + apiGeometry.normalsNeedUpdate, + apiGeometry.colorsNeedUpdate, + apiGeometry.groupsNeedUpdate, + apiGeometry.lineDistancesNeedUpdate + ); +}; + +GameLib.D3.API.Geometry.Box.prototype = Object.create(GameLib.D3.API.Geometry.prototype); +GameLib.D3.API.Geometry.Box.prototype.constructor = GameLib.D3.API.Geometry.Box; diff --git a/src/game-lib-d3-api-geometry-circle.js b/src/game-lib-d3-api-geometry-circle.js new file mode 100644 index 0000000..ef1a9e9 --- /dev/null +++ b/src/game-lib-d3-api-geometry-circle.js @@ -0,0 +1,77 @@ +/** + * GameLib.D3.API.Geometry.Circle + * @param apiGeometry + * @param radius + * @param segments + * @param thetaStart + * @param thetaLength + * @constructor + */ +GameLib.D3.API.Geometry.Circle = function( + apiGeometry, + radius, + segments, + thetaStart, + thetaLength +) { + + if (GameLib.Utils.UndefinedOrNull(apiGeometry)) { + apiGeometry = { + geometryType: GameLib.D3.API.Geometry.GEOMETRY_TYPE_CIRCLE + }; + } + + if (GameLib.Utils.UndefinedOrNull(apiGeometry.geometryType)) { + apiGeometry.geometryType = GameLib.D3.API.Geometry.GEOMETRY_TYPE_CIRCLE; + } + + if (GameLib.Utils.UndefinedOrNull(radius)) { + radius = 1; + } + this.radius = radius; + + if (GameLib.Utils.UndefinedOrNull(segments)) { + segments = 8; + } + this.segments = segments; + + if (GameLib.Utils.UndefinedOrNull(thetaStart)) { + thetaStart = 0; + } + this.thetaStart = thetaStart; + + if (GameLib.Utils.UndefinedOrNull(thetaLength)) { + thetaLength = Math.PI * 2; + } + this.thetaLength = thetaLength; + + GameLib.D3.API.Geometry.call( + this, + apiGeometry.id, + apiGeometry.name, + apiGeometry.geometryType, + apiGeometry.isBuffer, + apiGeometry.parentEntity, + apiGeometry.boundingBox, + apiGeometry.boundingSphere, + apiGeometry.colors, + apiGeometry.faces, + apiGeometry.faceVertexUvs, + apiGeometry.lineDistances, + apiGeometry.morphTargets, + apiGeometry.morphNormals, + apiGeometry.skinWeights, + apiGeometry.skinIndices, + apiGeometry.vertices, + apiGeometry.verticesNeedsUpdate, + apiGeometry.elementsNeedUpdate, + apiGeometry.uvsNeedUpdate, + apiGeometry.normalsNeedUpdate, + apiGeometry.colorsNeedUpdate, + apiGeometry.groupsNeedUpdate, + apiGeometry.lineDistancesNeedUpdate + ); +}; + +GameLib.D3.API.Geometry.Circle.prototype = Object.create(GameLib.D3.API.Geometry.prototype); +GameLib.D3.API.Geometry.Circle.prototype.constructor = GameLib.D3.API.Geometry.Circle; diff --git a/src/game-lib-d3-api-geometry-cone.js b/src/game-lib-d3-api-geometry-cone.js new file mode 100644 index 0000000..a4bca1d --- /dev/null +++ b/src/game-lib-d3-api-geometry-cone.js @@ -0,0 +1,98 @@ +/** + * GameLib.D3.API.Geometry.Cone + * @param apiGeometry + * @param radius + * @param height + * @param radialSegments + * @param heightSegments + * @param openEnded + * @param thetaStart + * @param thetaLength + * @constructor + */ +GameLib.D3.API.Geometry.Cone = function( + apiGeometry, + radius, + height, + radialSegments, + heightSegments, + openEnded, + thetaStart, + thetaLength +) { + + if (GameLib.Utils.UndefinedOrNull(apiGeometry)) { + apiGeometry = { + geometryType: GameLib.D3.API.Geometry.GEOMETRY_TYPE_CONE + }; + } + + if (GameLib.Utils.UndefinedOrNull(apiGeometry.geometryType)) { + apiGeometry.geometryType = GameLib.D3.API.Geometry.GEOMETRY_TYPE_CONE; + } + + if (GameLib.Utils.UndefinedOrNull(radius)) { + radius = 1; + } + this.radius = radius; + + if (GameLib.Utils.UndefinedOrNull(height)) { + height = 100; + } + this.height = height; + + if (GameLib.Utils.UndefinedOrNull(radialSegments)) { + radialSegments = 8; + } + this.radialSegments = radialSegments; + + if (GameLib.Utils.UndefinedOrNull(heightSegments)) { + heightSegments = 1; + } + this.heightSegments = heightSegments; + + if (GameLib.Utils.UndefinedOrNull(openEnded)) { + openEnded = false; + } + this.openEnded = openEnded; + + if (GameLib.Utils.UndefinedOrNull(thetaStart)) { + thetaStart = 0; + } + this.thetaStart = thetaStart; + + if (GameLib.Utils.UndefinedOrNull(thetaLength)) { + thetaLength = Math.PI * 2; + } + this.thetaLength = thetaLength; + + GameLib.D3.API.Geometry.call( + this, + apiGeometry.id, + apiGeometry.name, + apiGeometry.geometryType, + apiGeometry.isBuffer, + apiGeometry.parentEntity, + apiGeometry.boundingBox, + apiGeometry.boundingSphere, + apiGeometry.colors, + apiGeometry.faces, + apiGeometry.faceVertexUvs, + apiGeometry.lineDistances, + apiGeometry.morphTargets, + apiGeometry.morphNormals, + apiGeometry.skinWeights, + apiGeometry.skinIndices, + apiGeometry.vertices, + apiGeometry.verticesNeedsUpdate, + apiGeometry.elementsNeedUpdate, + apiGeometry.uvsNeedUpdate, + apiGeometry.normalsNeedUpdate, + apiGeometry.colorsNeedUpdate, + apiGeometry.groupsNeedUpdate, + apiGeometry.lineDistancesNeedUpdate + ); +}; + +GameLib.D3.API.Geometry.Cone.prototype = Object.create(GameLib.D3.API.Geometry.prototype); +GameLib.D3.API.Geometry.Cone.prototype.constructor = GameLib.D3.API.Geometry.Cone; diff --git a/src/game-lib-d3-api-geometry-cylinder.js b/src/game-lib-d3-api-geometry-cylinder.js new file mode 100644 index 0000000..320206a --- /dev/null +++ b/src/game-lib-d3-api-geometry-cylinder.js @@ -0,0 +1,105 @@ +/** + * GameLib.D3.API.Geometry.Cylinder + * @param apiGeometry + * @param radiusTop + * @param radiusBottom + * @param height + * @param radialSegments + * @param heightSegments + * @param openEnded + * @param thetaStart + * @param thetaLength + * @constructor + */ +GameLib.D3.API.Geometry.Cylinder = function( + apiGeometry, + radiusTop, + radiusBottom, + height, + radialSegments, + heightSegments, + openEnded, + thetaStart, + thetaLength +) { + + if (GameLib.Utils.UndefinedOrNull(apiGeometry)) { + apiGeometry = { + geometryType: GameLib.D3.API.Geometry.GEOMETRY_TYPE_CYLINDER + }; + } + + if (GameLib.Utils.UndefinedOrNull(apiGeometry.geometryType)) { + apiGeometry.geometryType = GameLib.D3.API.Geometry.GEOMETRY_TYPE_CYLINDER; + } + + if (GameLib.Utils.UndefinedOrNull(radiusTop)) { + radiusTop = 1; + } + this.radiusTop = radiusTop; + + if (GameLib.Utils.UndefinedOrNull(radiusBottom)) { + radiusBottom = 1; + } + this.radiusBottom = radiusBottom; + + if (GameLib.Utils.UndefinedOrNull(height)) { + height = 100; + } + this.height = height; + + if (GameLib.Utils.UndefinedOrNull(radialSegments)) { + radialSegments = 8; + } + this.radialSegments = radialSegments; + + if (GameLib.Utils.UndefinedOrNull(heightSegments)) { + heightSegments = 1; + } + this.heightSegments = heightSegments; + + if (GameLib.Utils.UndefinedOrNull(openEnded)) { + openEnded = false; + } + this.openEnded = openEnded; + + if (GameLib.Utils.UndefinedOrNull(thetaStart)) { + thetaStart = 0; + } + this.thetaStart = thetaStart; + + if (GameLib.Utils.UndefinedOrNull(thetaLength)) { + thetaLength = Math.PI * 2; + } + this.thetaLength = thetaLength; + + GameLib.D3.API.Geometry.call( + this, + apiGeometry.id, + apiGeometry.name, + apiGeometry.geometryType, + apiGeometry.isBuffer, + apiGeometry.parentEntity, + apiGeometry.boundingBox, + apiGeometry.boundingSphere, + apiGeometry.colors, + apiGeometry.faces, + apiGeometry.faceVertexUvs, + apiGeometry.lineDistances, + apiGeometry.morphTargets, + apiGeometry.morphNormals, + apiGeometry.skinWeights, + apiGeometry.skinIndices, + apiGeometry.vertices, + apiGeometry.verticesNeedsUpdate, + apiGeometry.elementsNeedUpdate, + apiGeometry.uvsNeedUpdate, + apiGeometry.normalsNeedUpdate, + apiGeometry.colorsNeedUpdate, + apiGeometry.groupsNeedUpdate, + apiGeometry.lineDistancesNeedUpdate + ); +}; + +GameLib.D3.API.Geometry.Cylinder.prototype = Object.create(GameLib.D3.API.Geometry.prototype); +GameLib.D3.API.Geometry.Cylinder.prototype.constructor = GameLib.D3.API.Geometry.Cylinder; diff --git a/src/game-lib-d3-api-geometry-dodecahedron.js b/src/game-lib-d3-api-geometry-dodecahedron.js new file mode 100644 index 0000000..43967b1 --- /dev/null +++ b/src/game-lib-d3-api-geometry-dodecahedron.js @@ -0,0 +1,63 @@ +/** + * GameLib.D3.API.Geometry.Dodecahedron + * @param apiGeometry + * @param radius + * @param detail + * @constructor + */ +GameLib.D3.API.Geometry.Dodecahedron = function( + apiGeometry, + radius, + detail +) { + + if (GameLib.Utils.UndefinedOrNull(apiGeometry)) { + apiGeometry = { + geometryType: GameLib.D3.API.Geometry.GEOMETRY_TYPE_DODECAHEDRON + }; + } + + if (GameLib.Utils.UndefinedOrNull(apiGeometry.geometryType)) { + apiGeometry.geometryType = GameLib.D3.API.Geometry.GEOMETRY_TYPE_DODECAHEDRON; + } + + if (GameLib.Utils.UndefinedOrNull(radius)) { + radius = 1; + } + this.radius = radius; + + if (GameLib.Utils.UndefinedOrNull(detail)) { + detail = 0; + } + this.detail = detail; + + GameLib.D3.API.Geometry.call( + this, + apiGeometry.id, + apiGeometry.name, + apiGeometry.geometryType, + apiGeometry.isBuffer, + apiGeometry.parentEntity, + apiGeometry.boundingBox, + apiGeometry.boundingSphere, + apiGeometry.colors, + apiGeometry.faces, + apiGeometry.faceVertexUvs, + apiGeometry.lineDistances, + apiGeometry.morphTargets, + apiGeometry.morphNormals, + apiGeometry.skinWeights, + apiGeometry.skinIndices, + apiGeometry.vertices, + apiGeometry.verticesNeedsUpdate, + apiGeometry.elementsNeedUpdate, + apiGeometry.uvsNeedUpdate, + apiGeometry.normalsNeedUpdate, + apiGeometry.colorsNeedUpdate, + apiGeometry.groupsNeedUpdate, + apiGeometry.lineDistancesNeedUpdate + ); +}; + +GameLib.D3.API.Geometry.Dodecahedron.prototype = Object.create(GameLib.D3.API.Geometry.prototype); +GameLib.D3.API.Geometry.Dodecahedron.prototype.constructor = GameLib.D3.API.Geometry.Dodecahedron; diff --git a/src/game-lib-d3-api-geometry-edges.js b/src/game-lib-d3-api-geometry-edges.js new file mode 100644 index 0000000..e1cea14 --- /dev/null +++ b/src/game-lib-d3-api-geometry-edges.js @@ -0,0 +1,63 @@ +/** + * GameLib.D3.API.Geometry.Edges + * @param apiGeometry + * @param geometry + * @param thresholdAngle (degrees) + * @constructor + */ +GameLib.D3.API.Geometry.Edges = function( + apiGeometry, + geometry, + thresholdAngle +) { + + if (GameLib.Utils.UndefinedOrNull(apiGeometry)) { + apiGeometry = { + geometryType: GameLib.D3.API.Geometry.GEOMETRY_TYPE_EDGES + }; + } + + if (GameLib.Utils.UndefinedOrNull(apiGeometry.geometryType)) { + apiGeometry.geometryType = GameLib.D3.API.Geometry.GEOMETRY_TYPE_EDGES; + } + + if (GameLib.Utils.UndefinedOrNull(geometry)) { + geometry = null; + } + this.geometry = geometry; + + if (GameLib.Utils.UndefinedOrNull(thresholdAngle)) { + thresholdAngle = 1; + } + this.thresholdAngle = thresholdAngle; + + GameLib.D3.API.Geometry.call( + this, + apiGeometry.id, + apiGeometry.name, + apiGeometry.geometryType, + apiGeometry.isBuffer, + apiGeometry.parentEntity, + apiGeometry.boundingBox, + apiGeometry.boundingSphere, + apiGeometry.colors, + apiGeometry.faces, + apiGeometry.faceVertexUvs, + apiGeometry.lineDistances, + apiGeometry.morphTargets, + apiGeometry.morphNormals, + apiGeometry.skinWeights, + apiGeometry.skinIndices, + apiGeometry.vertices, + apiGeometry.verticesNeedsUpdate, + apiGeometry.elementsNeedUpdate, + apiGeometry.uvsNeedUpdate, + apiGeometry.normalsNeedUpdate, + apiGeometry.colorsNeedUpdate, + apiGeometry.groupsNeedUpdate, + apiGeometry.lineDistancesNeedUpdate + ); +}; + +GameLib.D3.API.Geometry.Edges.prototype = Object.create(GameLib.D3.API.Geometry.prototype); +GameLib.D3.API.Geometry.Edges.prototype.constructor = GameLib.D3.API.Geometry.Edges; diff --git a/src/game-lib-d3-api-geometry-extrude.js b/src/game-lib-d3-api-geometry-extrude.js new file mode 100644 index 0000000..a8cd6c4 --- /dev/null +++ b/src/game-lib-d3-api-geometry-extrude.js @@ -0,0 +1,121 @@ +/** + * GameLib.D3.API.Geometry.Extrude + * @param apiGeometry + * @param shapes + * @param curveSegments + * @param steps + * @param amount + * @param bevelEnabled + * @param bevelThickness + * @param bevelSize + * @param bevelSegments + * @param extrudePath + * @param frames + * @param UVGenerator + * @constructor + */ +GameLib.D3.API.Geometry.Extrude = function( + apiGeometry, + shapes, + curveSegments, + steps, + amount, + bevelEnabled, + bevelThickness, + bevelSize, + bevelSegments, + extrudePath, + frames, + UVGenerator +) { + + if (GameLib.Utils.UndefinedOrNull(apiGeometry)) { + apiGeometry = { + geometryType: GameLib.D3.API.Geometry.GEOMETRY_TYPE_EXTRUDE + }; + } + + if (GameLib.Utils.UndefinedOrNull(apiGeometry.geometryType)) { + apiGeometry.geometryType = GameLib.D3.API.Geometry.GEOMETRY_TYPE_EXTRUDE; + } + + if (GameLib.Utils.UndefinedOrNull(shapes)) { + shapes = []; + } + this.shapes = shapes; + + if (GameLib.Utils.UndefinedOrNull(curveSegments)) { + curveSegments = 12; + } + this.curveSegments = curveSegments; + + if (GameLib.Utils.UndefinedOrNull(steps)) { + steps = 1; + } + this.steps = steps; + + if (GameLib.Utils.UndefinedOrNull(amount)) { + amount = 100; + } + this.amount = amount; + + if (GameLib.Utils.UndefinedOrNull(bevelEnabled)) { + bevelEnabled = true; + } + this.bevelEnabled = bevelEnabled; + + if (GameLib.Utils.UndefinedOrNull(bevelThickness)) { + bevelThickness = 6; + } + this.bevelThickness = bevelThickness; + + if (GameLib.Utils.UndefinedOrNull(bevelSegments)) { + bevelSegments = 3; + } + this.bevelSegments = bevelSegments; + + if (GameLib.Utils.UndefinedOrNull(extrudePath)) { + extrudePath = null; + } + this.extrudePath = extrudePath; + + if (GameLib.Utils.UndefinedOrNull(frames)) { + frames = null; + } + this.frames = frames; + + if (GameLib.Utils.UndefinedOrNull(UVGenerator)) { + UVGenerator = null; + } + this.UVGenerator = UVGenerator; + + GameLib.D3.API.Geometry.call( + this, + apiGeometry.id, + apiGeometry.name, + apiGeometry.geometryType, + apiGeometry.isBuffer, + apiGeometry.parentEntity, + apiGeometry.boundingBox, + apiGeometry.boundingSphere, + apiGeometry.colors, + apiGeometry.faces, + apiGeometry.faceVertexUvs, + apiGeometry.lineDistances, + apiGeometry.morphTargets, + apiGeometry.morphNormals, + apiGeometry.skinWeights, + apiGeometry.skinIndices, + apiGeometry.vertices, + apiGeometry.verticesNeedsUpdate, + apiGeometry.elementsNeedUpdate, + apiGeometry.uvsNeedUpdate, + apiGeometry.normalsNeedUpdate, + apiGeometry.colorsNeedUpdate, + apiGeometry.groupsNeedUpdate, + apiGeometry.lineDistancesNeedUpdate + ); +}; + +GameLib.D3.API.Geometry.Extrude.prototype = Object.create(GameLib.D3.API.Geometry.prototype); +GameLib.D3.API.Geometry.Extrude.prototype.constructor = GameLib.D3.API.Geometry.Extrude; diff --git a/src/game-lib-d3-api-geometry-icosahedron.js b/src/game-lib-d3-api-geometry-icosahedron.js new file mode 100644 index 0000000..face322 --- /dev/null +++ b/src/game-lib-d3-api-geometry-icosahedron.js @@ -0,0 +1,63 @@ +/** + * GameLib.D3.API.Geometry.Icosahedron + * @param apiGeometry + * @param radius + * @param detail + * @constructor + */ +GameLib.D3.API.Geometry.Icosahedron = function( + apiGeometry, + radius, + detail +) { + + if (GameLib.Utils.UndefinedOrNull(apiGeometry)) { + apiGeometry = { + geometryType: GameLib.D3.API.Geometry.GEOMETRY_TYPE_ICOSAHEDRON + }; + } + + if (GameLib.Utils.UndefinedOrNull(apiGeometry.geometryType)) { + apiGeometry.geometryType = GameLib.D3.API.Geometry.GEOMETRY_TYPE_ICOSAHEDRON; + } + + if (GameLib.Utils.UndefinedOrNull(radius)) { + radius = 1; + } + this.radius = radius; + + if (GameLib.Utils.UndefinedOrNull(detail)) { + detail = 0; + } + this.detail = detail; + + GameLib.D3.API.Geometry.call( + this, + apiGeometry.id, + apiGeometry.name, + apiGeometry.geometryType, + apiGeometry.isBuffer, + apiGeometry.parentEntity, + apiGeometry.boundingBox, + apiGeometry.boundingSphere, + apiGeometry.colors, + apiGeometry.faces, + apiGeometry.faceVertexUvs, + apiGeometry.lineDistances, + apiGeometry.morphTargets, + apiGeometry.morphNormals, + apiGeometry.skinWeights, + apiGeometry.skinIndices, + apiGeometry.vertices, + apiGeometry.verticesNeedsUpdate, + apiGeometry.elementsNeedUpdate, + apiGeometry.uvsNeedUpdate, + apiGeometry.normalsNeedUpdate, + apiGeometry.colorsNeedUpdate, + apiGeometry.groupsNeedUpdate, + apiGeometry.lineDistancesNeedUpdate + ); +}; + +GameLib.D3.API.Geometry.Icosahedron.prototype = Object.create(GameLib.D3.API.Geometry.prototype); +GameLib.D3.API.Geometry.Icosahedron.prototype.constructor = GameLib.D3.API.Geometry.Icosahedron; diff --git a/src/game-lib-d3-api-geometry-lathe.js b/src/game-lib-d3-api-geometry-lathe.js new file mode 100644 index 0000000..a3c0e9a --- /dev/null +++ b/src/game-lib-d3-api-geometry-lathe.js @@ -0,0 +1,77 @@ +/** + * GameLib.D3.API.Geometry.Lathe + * @param apiGeometry + * @param points [GameLib.Vector2] + * @param segments + * @param phiStart + * @param phiLength + * @constructor + */ +GameLib.D3.API.Geometry.Lathe = function( + apiGeometry, + points, + segments, + phiStart, + phiLength +) { + + if (GameLib.Utils.UndefinedOrNull(apiGeometry)) { + apiGeometry = { + geometryType: GameLib.D3.API.Geometry.GEOMETRY_TYPE_LATHE + }; + } + + if (GameLib.Utils.UndefinedOrNull(apiGeometry.geometryType)) { + apiGeometry.geometryType = GameLib.D3.API.Geometry.GEOMETRY_TYPE_LATHE; + } + + if (GameLib.Utils.UndefinedOrNull(points)) { + points = []; + } + this.points = points; + + if (GameLib.Utils.UndefinedOrNull(segments)) { + segments = 12; + } + this.segments = segments; + + if (GameLib.Utils.UndefinedOrNull(phiStart)) { + phiStart = 0; + } + this.phiStart = phiStart; + + if (GameLib.Utils.UndefinedOrNull(phiLength)) { + phiLength = Math.PI * 2; + } + this.phiLength = phiLength; + + GameLib.D3.API.Geometry.call( + this, + apiGeometry.id, + apiGeometry.name, + apiGeometry.geometryType, + apiGeometry.isBuffer, + apiGeometry.parentEntity, + apiGeometry.boundingBox, + apiGeometry.boundingSphere, + apiGeometry.colors, + apiGeometry.faces, + apiGeometry.faceVertexUvs, + apiGeometry.lineDistances, + apiGeometry.morphTargets, + apiGeometry.morphNormals, + apiGeometry.skinWeights, + apiGeometry.skinIndices, + apiGeometry.vertices, + apiGeometry.verticesNeedsUpdate, + apiGeometry.elementsNeedUpdate, + apiGeometry.uvsNeedUpdate, + apiGeometry.normalsNeedUpdate, + apiGeometry.colorsNeedUpdate, + apiGeometry.groupsNeedUpdate, + apiGeometry.lineDistancesNeedUpdate + ); +}; + +GameLib.D3.API.Geometry.Lathe.prototype = Object.create(GameLib.D3.API.Geometry.prototype); +GameLib.D3.API.Geometry.Lathe.prototype.constructor = GameLib.D3.API.Geometry.Lathe; diff --git a/src/game-lib-d3-api-geometry-octahedron.js b/src/game-lib-d3-api-geometry-octahedron.js new file mode 100644 index 0000000..2333c40 --- /dev/null +++ b/src/game-lib-d3-api-geometry-octahedron.js @@ -0,0 +1,63 @@ +/** + * GameLib.D3.API.Geometry.Octahedron + * @param apiGeometry + * @param radius + * @param detail + * @constructor + */ +GameLib.D3.API.Geometry.Octahedron = function( + apiGeometry, + radius, + detail +) { + + if (GameLib.Utils.UndefinedOrNull(apiGeometry)) { + apiGeometry = { + geometryType: GameLib.D3.API.Geometry.GEOMETRY_TYPE_OCTAHEDRON + }; + } + + if (GameLib.Utils.UndefinedOrNull(apiGeometry.geometryType)) { + apiGeometry.geometryType = GameLib.D3.API.Geometry.GEOMETRY_TYPE_OCTAHEDRON; + } + + if (GameLib.Utils.UndefinedOrNull(radius)) { + radius = 1; + } + this.radius = radius; + + if (GameLib.Utils.UndefinedOrNull(detail)) { + detail = 0; + } + this.detail = detail; + + GameLib.D3.API.Geometry.call( + this, + apiGeometry.id, + apiGeometry.name, + apiGeometry.geometryType, + apiGeometry.isBuffer, + apiGeometry.parentEntity, + apiGeometry.boundingBox, + apiGeometry.boundingSphere, + apiGeometry.colors, + apiGeometry.faces, + apiGeometry.faceVertexUvs, + apiGeometry.lineDistances, + apiGeometry.morphTargets, + apiGeometry.morphNormals, + apiGeometry.skinWeights, + apiGeometry.skinIndices, + apiGeometry.vertices, + apiGeometry.verticesNeedsUpdate, + apiGeometry.elementsNeedUpdate, + apiGeometry.uvsNeedUpdate, + apiGeometry.normalsNeedUpdate, + apiGeometry.colorsNeedUpdate, + apiGeometry.groupsNeedUpdate, + apiGeometry.lineDistancesNeedUpdate + ); +}; + +GameLib.D3.API.Geometry.Octahedron.prototype = Object.create(GameLib.D3.API.Geometry.prototype); +GameLib.D3.API.Geometry.Octahedron.prototype.constructor = GameLib.D3.API.Geometry.Octahedron; diff --git a/src/game-lib-d3-api-geometry-parametric.js b/src/game-lib-d3-api-geometry-parametric.js new file mode 100644 index 0000000..2012617 --- /dev/null +++ b/src/game-lib-d3-api-geometry-parametric.js @@ -0,0 +1,70 @@ +/** + * GameLib.D3.API.Geometry.Parametric + * @param apiGeometry + * @param generatorFn(u,v) => returns Vector3, u and v is values between 0 and 1 + * @param slices + * @param stacks + * @constructor + */ +GameLib.D3.API.Geometry.Parametric = function( + apiGeometry, + generatorFn, + slices, + stacks +) { + + if (GameLib.Utils.UndefinedOrNull(apiGeometry)) { + apiGeometry = { + geometryType: GameLib.D3.API.Geometry.GEOMETRY_TYPE_PARAMETRIC + }; + } + + if (GameLib.Utils.UndefinedOrNull(apiGeometry.geometryType)) { + apiGeometry.geometryType = GameLib.D3.API.Geometry.GEOMETRY_TYPE_PARAMETRIC; + } + + if (GameLib.Utils.UndefinedOrNull(generatorFn)) { + generatorFn = ''; + } + this.generatorFn = generatorFn; + + if (GameLib.Utils.UndefinedOrNull(slices)) { + slices = 20; + } + this.slices = slices; + + if (GameLib.Utils.UndefinedOrNull(stacks)) { + stacks = 20; + } + this.stacks = stacks; + + GameLib.D3.API.Geometry.call( + this, + apiGeometry.id, + apiGeometry.name, + apiGeometry.geometryType, + apiGeometry.isBuffer, + apiGeometry.parentEntity, + apiGeometry.boundingBox, + apiGeometry.boundingSphere, + apiGeometry.colors, + apiGeometry.faces, + apiGeometry.faceVertexUvs, + apiGeometry.lineDistances, + apiGeometry.morphTargets, + apiGeometry.morphNormals, + apiGeometry.skinWeights, + apiGeometry.skinIndices, + apiGeometry.vertices, + apiGeometry.verticesNeedsUpdate, + apiGeometry.elementsNeedUpdate, + apiGeometry.uvsNeedUpdate, + apiGeometry.normalsNeedUpdate, + apiGeometry.colorsNeedUpdate, + apiGeometry.groupsNeedUpdate, + apiGeometry.lineDistancesNeedUpdate + ); +}; + +GameLib.D3.API.Geometry.Parametric.prototype = Object.create(GameLib.D3.API.Geometry.prototype); +GameLib.D3.API.Geometry.Parametric.prototype.constructor = GameLib.D3.API.Geometry.Parametric; diff --git a/src/game-lib-d3-api-geometry-plane.js b/src/game-lib-d3-api-geometry-plane.js new file mode 100644 index 0000000..0f1d010 --- /dev/null +++ b/src/game-lib-d3-api-geometry-plane.js @@ -0,0 +1,77 @@ +/** + * GameLib.D3.API.Geometry.Plane + * @param apiGeometry + * @param width + * @param height + * @param widthSegments + * @param heightSegments + * @constructor + */ +GameLib.D3.API.Geometry.Plane = function( + apiGeometry, + width, + height, + widthSegments, + heightSegments +) { + + if (GameLib.Utils.UndefinedOrNull(apiGeometry)) { + apiGeometry = { + geometryType: GameLib.D3.API.Geometry.GEOMETRY_TYPE_PLANE + }; + } + + if (GameLib.Utils.UndefinedOrNull(apiGeometry.geometryType)) { + apiGeometry.geometryType = GameLib.D3.API.Geometry.GEOMETRY_TYPE_PLANE; + } + + if (GameLib.Utils.UndefinedOrNull(width)) { + width = 1; + } + this.width = width; + + if (GameLib.Utils.UndefinedOrNull(height)) { + height = 1; + } + this.height = height; + + if (GameLib.Utils.UndefinedOrNull(widthSegments)) { + widthSegments = 1; + } + this.widthSegments = widthSegments; + + if (GameLib.Utils.UndefinedOrNull(heightSegments)) { + heightSegments = 1; + } + this.heightSegments = heightSegments; + + GameLib.D3.API.Geometry.call( + this, + apiGeometry.id, + apiGeometry.name, + apiGeometry.geometryType, + apiGeometry.isBuffer, + apiGeometry.parentEntity, + apiGeometry.boundingBox, + apiGeometry.boundingSphere, + apiGeometry.colors, + apiGeometry.faces, + apiGeometry.faceVertexUvs, + apiGeometry.lineDistances, + apiGeometry.morphTargets, + apiGeometry.morphNormals, + apiGeometry.skinWeights, + apiGeometry.skinIndices, + apiGeometry.vertices, + apiGeometry.verticesNeedsUpdate, + apiGeometry.elementsNeedUpdate, + apiGeometry.uvsNeedUpdate, + apiGeometry.normalsNeedUpdate, + apiGeometry.colorsNeedUpdate, + apiGeometry.groupsNeedUpdate, + apiGeometry.lineDistancesNeedUpdate + ); +}; + +GameLib.D3.API.Geometry.Plane.prototype = Object.create(GameLib.D3.API.Geometry.prototype); +GameLib.D3.API.Geometry.Plane.prototype.constructor = GameLib.D3.API.Geometry.Plane; diff --git a/src/game-lib-d3-api-geometry-polyhedron.js b/src/game-lib-d3-api-geometry-polyhedron.js new file mode 100644 index 0000000..b766d0c --- /dev/null +++ b/src/game-lib-d3-api-geometry-polyhedron.js @@ -0,0 +1,77 @@ +/** + * GameLib.D3.API.Geometry.Polyhedron + * @param apiGeometry + * @param vertices + * @param indices + * @param radius + * @param detail + * @constructor + */ +GameLib.D3.API.Geometry.Polyhedron = function( + apiGeometry, + vertices, + indices, + radius, + detail +) { + + if (GameLib.Utils.UndefinedOrNull(apiGeometry)) { + apiGeometry = { + geometryType: GameLib.D3.API.Geometry.GEOMETRY_TYPE_POLYHEDRON + }; + } + + if (GameLib.Utils.UndefinedOrNull(apiGeometry.geometryType)) { + apiGeometry.geometryType = GameLib.D3.API.Geometry.GEOMETRY_TYPE_POLYHEDRON; + } + + if (GameLib.Utils.UndefinedOrNull(vertices)) { + vertices = []; + } + this.vertices = vertices; + + if (GameLib.Utils.UndefinedOrNull(indices)) { + indices = 1; + } + this.indices = indices; + + if (GameLib.Utils.UndefinedOrNull(radius)) { + radius = 5; + } + this.radius = radius; + + if (GameLib.Utils.UndefinedOrNull(detail)) { + detail = 0; + } + this.detail = detail; + + GameLib.D3.API.Geometry.call( + this, + apiGeometry.id, + apiGeometry.name, + apiGeometry.geometryType, + apiGeometry.isBuffer, + apiGeometry.parentEntity, + apiGeometry.boundingBox, + apiGeometry.boundingSphere, + apiGeometry.colors, + apiGeometry.faces, + apiGeometry.faceVertexUvs, + apiGeometry.lineDistances, + apiGeometry.morphTargets, + apiGeometry.morphNormals, + apiGeometry.skinWeights, + apiGeometry.skinIndices, + apiGeometry.vertices, + apiGeometry.verticesNeedsUpdate, + apiGeometry.elementsNeedUpdate, + apiGeometry.uvsNeedUpdate, + apiGeometry.normalsNeedUpdate, + apiGeometry.colorsNeedUpdate, + apiGeometry.groupsNeedUpdate, + apiGeometry.lineDistancesNeedUpdate + ); +}; + +GameLib.D3.API.Geometry.Polyhedron.prototype = Object.create(GameLib.D3.API.Geometry.prototype); +GameLib.D3.API.Geometry.Polyhedron.prototype.constructor = GameLib.D3.API.Geometry.Polyhedron; diff --git a/src/game-lib-d3-api-geometry-ring.js b/src/game-lib-d3-api-geometry-ring.js new file mode 100644 index 0000000..3845ef6 --- /dev/null +++ b/src/game-lib-d3-api-geometry-ring.js @@ -0,0 +1,91 @@ +/** + * GameLib.D3.API.Geometry.Ring + * @param apiGeometry + * @param innerRadius + * @param outerRadius + * @param thetaSegments + * @param phiSegments + * @param thetaStart + * @param thetaLength + * @constructor + */ +GameLib.D3.API.Geometry.Ring = function( + apiGeometry, + innerRadius, + outerRadius, + thetaSegments, + phiSegments, + thetaStart, + thetaLength +) { + + if (GameLib.Utils.UndefinedOrNull(apiGeometry)) { + apiGeometry = { + geometryType: GameLib.D3.API.Geometry.GEOMETRY_TYPE_RING + }; + } + + if (GameLib.Utils.UndefinedOrNull(apiGeometry.geometryType)) { + apiGeometry.geometryType = GameLib.D3.API.Geometry.GEOMETRY_TYPE_RING; + } + + if (GameLib.Utils.UndefinedOrNull(innerRadius)) { + innerRadius = 0.5; + } + this.innerRadius = innerRadius; + + if (GameLib.Utils.UndefinedOrNull(outerRadius)) { + outerRadius = 1; + } + this.outerRadius = outerRadius; + + if (GameLib.Utils.UndefinedOrNull(thetaSegments)) { + thetaSegments = 8; + } + this.thetaSegments = thetaSegments; + + if (GameLib.Utils.UndefinedOrNull(phiSegments)) { + phiSegments = 8; + } + this.phiSegments = phiSegments; + + if (GameLib.Utils.UndefinedOrNull(thetaStart)) { + thetaStart = 0; + } + this.thetaStart = thetaStart; + + if (GameLib.Utils.UndefinedOrNull(thetaLength)) { + thetaLength = Math.PI * 2; + } + this.thetaLength = thetaLength; + + GameLib.D3.API.Geometry.call( + this, + apiGeometry.id, + apiGeometry.name, + apiGeometry.geometryType, + apiGeometry.isBuffer, + apiGeometry.parentEntity, + apiGeometry.boundingBox, + apiGeometry.boundingSphere, + apiGeometry.colors, + apiGeometry.faces, + apiGeometry.faceVertexUvs, + apiGeometry.lineDistances, + apiGeometry.morphTargets, + apiGeometry.morphNormals, + apiGeometry.skinWeights, + apiGeometry.skinIndices, + apiGeometry.vertices, + apiGeometry.verticesNeedsUpdate, + apiGeometry.elementsNeedUpdate, + apiGeometry.uvsNeedUpdate, + apiGeometry.normalsNeedUpdate, + apiGeometry.colorsNeedUpdate, + apiGeometry.groupsNeedUpdate, + apiGeometry.lineDistancesNeedUpdate + ); +}; + +GameLib.D3.API.Geometry.Ring.prototype = Object.create(GameLib.D3.API.Geometry.prototype); +GameLib.D3.API.Geometry.Ring.prototype.constructor = GameLib.D3.API.Geometry.Ring; diff --git a/src/game-lib-d3-api-geometry-shape.js b/src/game-lib-d3-api-geometry-shape.js new file mode 100644 index 0000000..85dc1d2 --- /dev/null +++ b/src/game-lib-d3-api-geometry-shape.js @@ -0,0 +1,63 @@ +/** + * GameLib.D3.API.Geometry.Shape + * @param apiGeometry + * @param shapes + * @param curveSegments + * @constructor + */ +GameLib.D3.API.Geometry.Shape = function( + apiGeometry, + shapes, + curveSegments +) { + + if (GameLib.Utils.UndefinedOrNull(apiGeometry)) { + apiGeometry = { + geometryType: GameLib.D3.API.Geometry.GEOMETRY_TYPE_SHAPE + }; + } + + if (GameLib.Utils.UndefinedOrNull(apiGeometry.geometryType)) { + apiGeometry.geometryType = GameLib.D3.API.Geometry.GEOMETRY_TYPE_SHAPE; + } + + if (GameLib.Utils.UndefinedOrNull(shapes)) { + shapes = []; + } + this.shapes = shapes; + + if (GameLib.Utils.UndefinedOrNull(curveSegments)) { + curveSegments = 12; + } + this.curveSegments = curveSegments; + + GameLib.D3.API.Geometry.call( + this, + apiGeometry.id, + apiGeometry.name, + apiGeometry.geometryType, + apiGeometry.isBuffer, + apiGeometry.parentEntity, + apiGeometry.boundingBox, + apiGeometry.boundingSphere, + apiGeometry.colors, + apiGeometry.faces, + apiGeometry.faceVertexUvs, + apiGeometry.lineDistances, + apiGeometry.morphTargets, + apiGeometry.morphNormals, + apiGeometry.skinWeights, + apiGeometry.skinIndices, + apiGeometry.vertices, + apiGeometry.verticesNeedsUpdate, + apiGeometry.elementsNeedUpdate, + apiGeometry.uvsNeedUpdate, + apiGeometry.normalsNeedUpdate, + apiGeometry.colorsNeedUpdate, + apiGeometry.groupsNeedUpdate, + apiGeometry.lineDistancesNeedUpdate + ); +}; + +GameLib.D3.API.Geometry.Shape.prototype = Object.create(GameLib.D3.API.Geometry.prototype); +GameLib.D3.API.Geometry.Shape.prototype.constructor = GameLib.D3.API.Geometry.Shape; diff --git a/src/game-lib-d3-api-geometry-sphere.js b/src/game-lib-d3-api-geometry-sphere.js new file mode 100644 index 0000000..5626595 --- /dev/null +++ b/src/game-lib-d3-api-geometry-sphere.js @@ -0,0 +1,98 @@ +/** + * GameLib.D3.API.Geometry.Sphere + * @param apiGeometry + * @param radius + * @param widthSegments + * @param heightSegments + * @param phiStart + * @param phiLength + * @param thetaStart + * @param thetaLength + * @constructor + */ +GameLib.D3.API.Geometry.Sphere = function( + apiGeometry, + radius, + widthSegments, + heightSegments, + phiStart, + phiLength, + thetaStart, + thetaLength +) { + + if (GameLib.Utils.UndefinedOrNull(apiGeometry)) { + apiGeometry = { + geometryType: GameLib.D3.API.Geometry.GEOMETRY_TYPE_SPHERE + }; + } + + if (GameLib.Utils.UndefinedOrNull(apiGeometry.geometryType)) { + apiGeometry.geometryType = GameLib.D3.API.Geometry.GEOMETRY_TYPE_SPHERE; + } + + if (GameLib.Utils.UndefinedOrNull(radius)) { + radius = 1; + } + this.radius = radius; + + if (GameLib.Utils.UndefinedOrNull(widthSegments)) { + widthSegments = 8; + } + this.widthSegments = widthSegments; + + if (GameLib.Utils.UndefinedOrNull(heightSegments)) { + heightSegments = 6; + } + this.heightSegments = heightSegments; + + if (GameLib.Utils.UndefinedOrNull(phiStart)) { + phiStart = 0; + } + this.phiStart = phiStart; + + if (GameLib.Utils.UndefinedOrNull(phiLength)) { + phiLength = Math.PI * 2; + } + this.phiLength = phiLength; + + if (GameLib.Utils.UndefinedOrNull(thetaStart)) { + thetaStart = 0; + } + this.thetaStart = thetaStart; + + if (GameLib.Utils.UndefinedOrNull(thetaLength)) { + thetaLength = Math.PI * 2; + } + this.thetaLength = thetaLength; + + GameLib.D3.API.Geometry.call( + this, + apiGeometry.id, + apiGeometry.name, + apiGeometry.geometryType, + apiGeometry.isBuffer, + apiGeometry.parentEntity, + apiGeometry.boundingBox, + apiGeometry.boundingSphere, + apiGeometry.colors, + apiGeometry.faces, + apiGeometry.faceVertexUvs, + apiGeometry.lineDistances, + apiGeometry.morphTargets, + apiGeometry.morphNormals, + apiGeometry.skinWeights, + apiGeometry.skinIndices, + apiGeometry.vertices, + apiGeometry.verticesNeedsUpdate, + apiGeometry.elementsNeedUpdate, + apiGeometry.uvsNeedUpdate, + apiGeometry.normalsNeedUpdate, + apiGeometry.colorsNeedUpdate, + apiGeometry.groupsNeedUpdate, + apiGeometry.lineDistancesNeedUpdate + ); +}; + +GameLib.D3.API.Geometry.Sphere.prototype = Object.create(GameLib.D3.API.Geometry.prototype); +GameLib.D3.API.Geometry.Sphere.prototype.constructor = GameLib.D3.API.Geometry.Sphere; diff --git a/src/game-lib-d3-api-geometry-tetrahedron.js b/src/game-lib-d3-api-geometry-tetrahedron.js new file mode 100644 index 0000000..63cfca2 --- /dev/null +++ b/src/game-lib-d3-api-geometry-tetrahedron.js @@ -0,0 +1,63 @@ +/** + * GameLib.D3.API.Geometry.Tetrahedron + * @param apiGeometry + * @param radius + * @param detail + * @constructor + */ +GameLib.D3.API.Geometry.Tetrahedron = function( + apiGeometry, + radius, + detail +) { + + if (GameLib.Utils.UndefinedOrNull(apiGeometry)) { + apiGeometry = { + geometryType: GameLib.D3.API.Geometry.GEOMETRY_TYPE_TETRAHEDRON + }; + } + + if (GameLib.Utils.UndefinedOrNull(apiGeometry.geometryType)) { + apiGeometry.geometryType = GameLib.D3.API.Geometry.GEOMETRY_TYPE_TETRAHEDRON; + } + + if (GameLib.Utils.UndefinedOrNull(radius)) { + radius = 1; + } + this.radius = radius; + + if (GameLib.Utils.UndefinedOrNull(detail)) { + detail = 0; + } + this.detail = detail; + + GameLib.D3.API.Geometry.call( + this, + apiGeometry.id, + apiGeometry.name, + apiGeometry.geometryType, + apiGeometry.isBuffer, + apiGeometry.parentEntity, + apiGeometry.boundingBox, + apiGeometry.boundingSphere, + apiGeometry.colors, + apiGeometry.faces, + apiGeometry.faceVertexUvs, + apiGeometry.lineDistances, + apiGeometry.morphTargets, + apiGeometry.morphNormals, + apiGeometry.skinWeights, + apiGeometry.skinIndices, + apiGeometry.vertices, + apiGeometry.verticesNeedsUpdate, + apiGeometry.elementsNeedUpdate, + apiGeometry.uvsNeedUpdate, + apiGeometry.normalsNeedUpdate, + apiGeometry.colorsNeedUpdate, + apiGeometry.groupsNeedUpdate, + apiGeometry.lineDistancesNeedUpdate + ); +}; + +GameLib.D3.API.Geometry.Tetrahedron.prototype = Object.create(GameLib.D3.API.Geometry.prototype); +GameLib.D3.API.Geometry.Tetrahedron.prototype.constructor = GameLib.D3.API.Geometry.Tetrahedron; diff --git a/src/game-lib-d3-api-geometry-text.js b/src/game-lib-d3-api-geometry-text.js new file mode 100644 index 0000000..9ff2c90 --- /dev/null +++ b/src/game-lib-d3-api-geometry-text.js @@ -0,0 +1,112 @@ +/** + * GameLib.D3.API.Geometry.Text + * @param apiGeometry + * @param text + * @param font + * @param size + * @param height + * @param curveSegments + * @param bevelEnabled + * @param bevelThickness + * @param bevelSize + * @param bevelSegments + * @constructor + */ +GameLib.D3.API.Geometry.Text = function( + apiGeometry, + text, + font, + size, + height, + curveSegments, + bevelEnabled, + bevelThickness, + bevelSize, + bevelSegments +) { + + if (GameLib.Utils.UndefinedOrNull(apiGeometry)) { + apiGeometry = { + geometryType: GameLib.D3.API.Geometry.GEOMETRY_TYPE_TEXT + }; + } + + if (GameLib.Utils.UndefinedOrNull(apiGeometry.geometryType)) { + apiGeometry.geometryType = GameLib.D3.API.Geometry.GEOMETRY_TYPE_TEXT; + } + + if (GameLib.Utils.UndefinedOrNull(text)) { + text = '-=