diff --git a/src/game-lib-a-component-a.js b/src/game-lib-a-component-a.js index 3421f60..5a79c3a 100644 --- a/src/game-lib-a-component-a.js +++ b/src/game-lib-a-component-a.js @@ -358,12 +358,38 @@ 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.BUFFER_GEOMETRY = 0x80; +GameLib.Component.BUFFER_GEOMETRY_BOX = 0x81; +GameLib.Component.BUFFER_GEOMETRY_CIRCLE = 0x82; +GameLib.Component.BUFFER_GEOMETRY_CONE = 0x83; +GameLib.Component.BUFFER_GEOMETRY_CYLINDER = 0x84; +GameLib.Component.BUFFER_GEOMETRY_DODECAHEDRON = 0x85; +GameLib.Component.BUFFER_GEOMETRY_EXTRUDE = 0x86; +GameLib.Component.BUFFER_GEOMETRY_ICOSAHEDRON = 0x87; +GameLib.Component.BUFFER_GEOMETRY_LATHE = 0x88; +GameLib.Component.BUFFER_GEOMETRY_OCTAHEDRON = 0x89; +GameLib.Component.BUFFER_GEOMETRY_PARAMETRIC = 0x8a; +GameLib.Component.BUFFER_GEOMETRY_PLANE = 0x8b; +GameLib.Component.BUFFER_GEOMETRY_POLYHEDRON = 0x8c; +GameLib.Component.BUFFER_GEOMETRY_RING = 0x8d; +GameLib.Component.BUFFER_GEOMETRY_SHAPE = 0x8e; +GameLib.Component.BUFFER_GEOMETRY_SPHERE = 0x8f; +GameLib.Component.BUFFER_GEOMETRY_TETRAHEDRON = 0x90; +GameLib.Component.BUFFER_GEOMETRY_TEXT = 0x91; +GameLib.Component.BUFFER_GEOMETRY_TORUS = 0x92; +GameLib.Component.BUFFER_GEOMETRY_TORUS_KNOT = 0x93; +GameLib.Component.BUFFER_GEOMETRY_TUBE = 0x94; + +GameLib.Component.CURVE = 0x95; +GameLib.Component.CURVE_PATH = 0x96; +GameLib.Component.CURVE_PATH_D2 = 0x97; +GameLib.Component.CURVE_PATH_D2_SHAPE = 0x98; +GameLib.Component.BOX3 = 0x99; +GameLib.Component.DRAW_RANGE = 0x9a; +GameLib.Component.GROUP = 0x9b; + +GameLib.Component.MAX_COMPONENTS = 0x9c; GameLib.Component.GRAPHICS_RUNTIME = 0x1; GameLib.Component.PHYSICS_RUNTIME = 0x2; @@ -1147,29 +1173,173 @@ GameLib.Component.GetComponentInfo = function(number) { apiConstructor : GameLib.D3.API.Geometry.Wireframe }; case 0x80 : return { + name : 'GameLib.D3.BufferGeometry', + runtime : GameLib.Component.GRAPHICS_RUNTIME, + constructor : GameLib.D3.BufferGeometry, + apiConstructor : GameLib.D3.API.BufferGeometry + }; + case 0x81 : return { + name : 'GameLib.D3.BufferGeometry.Box', + runtime : GameLib.Component.GRAPHICS_RUNTIME, + constructor : GameLib.D3.BufferGeometry.Box, + apiConstructor : GameLib.D3.API.BufferGeometry.Box + }; + case 0x82 : return { + name : 'GameLib.D3.BufferGeometry.Circle', + runtime : GameLib.Component.GRAPHICS_RUNTIME, + constructor : GameLib.D3.BufferGeometry.Circle, + apiConstructor : GameLib.D3.API.BufferGeometry.Circle + }; + case 0x83 : return { + name : 'GameLib.D3.BufferGeometry.Cone', + runtime : GameLib.Component.GRAPHICS_RUNTIME, + constructor : GameLib.D3.BufferGeometry.Cone, + apiConstructor : GameLib.D3.API.BufferGeometry.Cone + }; + case 0x84 : return { + name : 'GameLib.D3.BufferGeometry.Cylinder', + runtime : GameLib.Component.GRAPHICS_RUNTIME, + constructor : GameLib.D3.BufferGeometry.Cylinder, + apiConstructor : GameLib.D3.API.BufferGeometry.Cylinder + }; + case 0x85 : return { + name : 'GameLib.D3.BufferGeometry.Dodecahedron', + runtime : GameLib.Component.GRAPHICS_RUNTIME, + constructor : GameLib.D3.BufferGeometry.Dodecahedron, + apiConstructor : GameLib.D3.API.BufferGeometry.Dodecahedron + }; + case 0x86 : return { + name : 'GameLib.D3.BufferGeometry.Extrude', + runtime : GameLib.Component.GRAPHICS_RUNTIME, + constructor : GameLib.D3.BufferGeometry.Extrude, + apiConstructor : GameLib.D3.API.BufferGeometry.Extrude + }; + case 0x87 : return { + name : 'GameLib.D3.BufferGeometry.Icosahedron', + runtime : GameLib.Component.GRAPHICS_RUNTIME, + constructor : GameLib.D3.BufferGeometry.Icosahedron, + apiConstructor : GameLib.D3.API.BufferGeometry.Icosahedron + }; + case 0x88 : return { + name : 'GameLib.D3.BufferGeometry.Lathe', + runtime : GameLib.Component.GRAPHICS_RUNTIME, + constructor : GameLib.D3.BufferGeometry.Lathe, + apiConstructor : GameLib.D3.API.BufferGeometry.Lathe + }; + case 0x89 : return { + name : 'GameLib.D3.BufferGeometry.Octahedron', + runtime : GameLib.Component.GRAPHICS_RUNTIME, + constructor : GameLib.D3.BufferGeometry.Octahedron, + apiConstructor : GameLib.D3.API.BufferGeometry.Octahedron + }; + case 0x8a : return { + name : 'GameLib.D3.BufferGeometry.Parametric', + runtime : GameLib.Component.GRAPHICS_RUNTIME, + constructor : GameLib.D3.BufferGeometry.Parametric, + apiConstructor : GameLib.D3.API.BufferGeometry.Parametric + }; + case 0x8b : return { + name : 'GameLib.D3.BufferGeometry.Plane', + runtime : GameLib.Component.GRAPHICS_RUNTIME, + constructor : GameLib.D3.BufferGeometry.Plane, + apiConstructor : GameLib.D3.API.BufferGeometry.Plane + }; + case 0x8c : return { + name : 'GameLib.D3.BufferGeometry.Polyhedron', + runtime : GameLib.Component.GRAPHICS_RUNTIME, + constructor : GameLib.D3.BufferGeometry.Polyhedron, + apiConstructor : GameLib.D3.API.BufferGeometry.Polyhedron + }; + case 0x8d : return { + name : 'GameLib.D3.BufferGeometry.Ring', + runtime : GameLib.Component.GRAPHICS_RUNTIME, + constructor : GameLib.D3.BufferGeometry.Ring, + apiConstructor : GameLib.D3.API.BufferGeometry.Ring + }; + case 0x8e : return { + name : 'GameLib.D3.BufferGeometry.Shape', + runtime : GameLib.Component.GRAPHICS_RUNTIME, + constructor : GameLib.D3.BufferGeometry.Shape, + apiConstructor : GameLib.D3.API.BufferGeometry.Shape + }; + case 0x8f : return { + name : 'GameLib.D3.BufferGeometry.Sphere', + runtime : GameLib.Component.GRAPHICS_RUNTIME, + constructor : GameLib.D3.BufferGeometry.Sphere, + apiConstructor : GameLib.D3.API.BufferGeometry.Sphere + }; + case 0x90 : return { + name : 'GameLib.D3.BufferGeometry.Tetrahedron', + runtime : GameLib.Component.GRAPHICS_RUNTIME, + constructor : GameLib.D3.BufferGeometry.Tetrahedron, + apiConstructor : GameLib.D3.API.BufferGeometry.Tetrahedron + }; + case 0x91 : return { + name : 'GameLib.D3.BufferGeometry.Text', + runtime : GameLib.Component.GRAPHICS_RUNTIME, + constructor : GameLib.D3.BufferGeometry.Text, + apiConstructor : GameLib.D3.API.BufferGeometry.Text + }; + case 0x92 : return { + name : 'GameLib.D3.BufferGeometry.Torus', + runtime : GameLib.Component.GRAPHICS_RUNTIME, + constructor : GameLib.D3.BufferGeometry.Torus, + apiConstructor : GameLib.D3.API.BufferGeometry.Torus + }; + case 0x93 : return { + name : 'GameLib.D3.BufferGeometry.TorusKnot', + runtime : GameLib.Component.GRAPHICS_RUNTIME, + constructor : GameLib.D3.BufferGeometry.TorusKnot, + apiConstructor : GameLib.D3.API.BufferGeometry.TorusKnot + }; + case 0x94 : return { + name : 'GameLib.D3.BufferGeometry.Tube', + runtime : GameLib.Component.GRAPHICS_RUNTIME, + constructor : GameLib.D3.BufferGeometry.Tube, + apiConstructor : GameLib.D3.API.BufferGeometry.Tube + }; + case 0x95 : return { name : 'GameLib.Curve', runtime : GameLib.Component.GRAPHICS_RUNTIME, constructor : GameLib.Curve, apiConstructor : GameLib.API.Curve }; - case 0x81 : return { + case 0x96 : return { name : 'GameLib.Curve.Path', runtime : GameLib.Component.GRAPHICS_RUNTIME, constructor : GameLib.Curve.Path, apiConstructor : GameLib.API.Curve.Path }; - case 0x82 : return { + case 0x97 : 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 { + case 0x98 : 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 }; + case 0x99 : return { + name : 'GameLib.Box3', + runtime : GameLib.Component.GRAPHICS_RUNTIME, + constructor : GameLib.Box3, + apiConstructor : GameLib.API.Box3 + }; + case 0x9a : return { + name : 'GameLib.DrawRange', + runtime : GameLib.Component.GRAPHICS_RUNTIME, + constructor : GameLib.DrawRange, + apiConstructor : GameLib.API.DrawRange + }; + case 0x9b : return { + name : 'GameLib.Group', + runtime : GameLib.Component.GRAPHICS_RUNTIME, + constructor : GameLib.Group, + apiConstructor : GameLib.API.Group + }; break; } diff --git a/src/game-lib-api-box3.js b/src/game-lib-api-box3.js index 877ac4b..e19ec17 100644 --- a/src/game-lib-api-box3.js +++ b/src/game-lib-api-box3.js @@ -1,13 +1,29 @@ /** * GameLib.API.Box3 + * @param id + * @param name + * @param parentEntity * @param min * @param max * @constructor */ GameLib.API.Box3 = function ( + id, + name, + parentEntity, min, max ) { + if (GameLib.Utils.UndefinedOrNull(id)) { + id = GameLib.Utils.RandomId(); + } + this.id = id; + + if (GameLib.Utils.UndefinedOrNull(name)) { + name = 'Box (' + id + ')'; + } + this.name = name; + if (GameLib.Utils.UndefinedOrNull(min)) { min = new GameLib.API.Vector3(0,0,0); } @@ -17,4 +33,13 @@ GameLib.API.Box3 = function ( max = new GameLib.API.Vector3(1,1,1); } this.max = max; + + GameLib.API.Component.call( + this, + GameLib.Component.BOX3, + parentEntity + ) }; + +GameLib.API.Box3.prototype = Object.create(GameLib.API.Component.prototype); +GameLib.API.Box3.prototype.constructor = GameLib.API.Box3; diff --git a/src/game-lib-api-draw-range.js b/src/game-lib-api-draw-range.js new file mode 100644 index 0000000..a829787 --- /dev/null +++ b/src/game-lib-api-draw-range.js @@ -0,0 +1,45 @@ +/** + * GameLib.API.Box3 + * @constructor + * @param id + * @param name + * @param parentEntity + * @param start + * @param count + */ +GameLib.API.DrawRange = function ( + id, + name, + parentEntity, + start, + count +) { + if (GameLib.Utils.UndefinedOrNull(id)) { + id = GameLib.Utils.RandomId(); + } + this.id = id; + + if (GameLib.Utils.UndefinedOrNull(name)) { + name = 'DrawRange (' + id + ')'; + } + this.name = name; + + if (GameLib.Utils.UndefinedOrNull(start)) { + start = 0; + } + this.start = start; + + if (GameLib.Utils.UndefinedOrNull(count)) { + count = Infinity; + } + this.count = count; + + GameLib.API.Component.call( + this, + GameLib.Component.DRAW_RANGE, + parentEntity + ) +}; + +GameLib.API.DrawRange.prototype = Object.create(GameLib.API.Component.prototype); +GameLib.API.DrawRange.prototype.constructor = GameLib.API.DrawRange; diff --git a/src/game-lib-api-group.js b/src/game-lib-api-group.js new file mode 100644 index 0000000..2406cf2 --- /dev/null +++ b/src/game-lib-api-group.js @@ -0,0 +1,52 @@ +/** + * GameLib.API.Group + * @constructor + * @param id + * @param name + * @param parentEntity + * @param start + * @param count + * @param materialIndex + */ +GameLib.API.Group = function ( + id, + name, + parentEntity, + start, + count, + materialIndex +) { + if (GameLib.Utils.UndefinedOrNull(id)) { + id = GameLib.Utils.RandomId(); + } + this.id = id; + + if (GameLib.Utils.UndefinedOrNull(name)) { + name = 'Group (' + id + ')'; + } + this.name = name; + + if (GameLib.Utils.UndefinedOrNull(start)) { + start = 0; + } + this.start = start; + + if (GameLib.Utils.UndefinedOrNull(count)) { + count = 0; + } + this.count = count; + + if (GameLib.Utils.UndefinedOrNull(materialIndex)) { + materialIndex = 0; + } + this.materialIndex = materialIndex; + + GameLib.API.Component.call( + this, + GameLib.Component.GROUP, + parentEntity + ) +}; + +GameLib.API.Group.prototype = Object.create(GameLib.API.Component.prototype); +GameLib.API.Group.prototype.constructor = GameLib.API.Group; diff --git a/src/game-lib-box3.js b/src/game-lib-box3.js index 077b215..9f22b95 100644 --- a/src/game-lib-box3.js +++ b/src/game-lib-box3.js @@ -25,6 +25,9 @@ GameLib.Box3 = function ( GameLib.API.Box3.call( this, + apiBox3.id, + apiBox3.name, + apiBox3.parentEntity, apiBox3.min, apiBox3.max ); @@ -32,7 +35,7 @@ GameLib.Box3 = function ( this.createInstance(); }; -GameLib.Box3.prototype = Object.create(GameLib.API.Box3.prototype); +GameLib.Box3.prototype = Object.create(GameLib.Component.prototype); GameLib.Box3.prototype.constructor = GameLib.Box3; /** @@ -73,6 +76,9 @@ GameLib.Box3.prototype.updateInstance = function(property) { */ GameLib.Box3.prototype.toApiObject = function() { return new GameLib.API.Box3( + this.id, + this.name, + GameLib.Utils.IdOrNull(this.parentEntity), this.min.toApiObject(), this.max.toApiObject() ); diff --git a/src/game-lib-d3-api-buffer-geometry-0.js b/src/game-lib-d3-api-buffer-geometry-0.js new file mode 100644 index 0000000..7f4220e --- /dev/null +++ b/src/game-lib-d3-api-buffer-geometry-0.js @@ -0,0 +1,267 @@ +/** + * GameLib.D3.API.BufferGeometry + * @param id + * @param name + * @param bufferGeometryType + * @param parentEntity + * @param faces + * @param vertices + * @param attributes + * @param boundingBox + * @param boundingSphere + * @param drawRange + * @param groups + * @param index + * @param morphAttributes + * @constructor + */ +GameLib.D3.API.BufferGeometry = function( + id, + name, + bufferGeometryType, + parentEntity, + faces, + vertices, + attributes, + boundingBox, + boundingSphere, + drawRange, + groups, + index, + morphAttributes +) { + if (GameLib.Utils.UndefinedOrNull(id)) { + id = GameLib.Utils.RandomId(); + } + this.id = id; + + if (GameLib.Utils.UndefinedOrNull(bufferGeometryType)) { + bufferGeometryType = GameLib.D3.API.BufferGeometry.BUFFER_GEOMETRY_TYPE_NONE; + } + this.bufferGeometryType = bufferGeometryType; + + if (GameLib.Utils.UndefinedOrNull(name)) { + + switch (this.bufferGeometryType) { + case GameLib.D3.API.BufferGeometry.BUFFER_GEOMETRY_TYPE_NONE : + name = 'BufferGeometry'; + break; + case GameLib.D3.API.BufferGeometry.BUFFER_GEOMETRY_TYPE_BOX : + name = 'BufferGeometry Box'; + break; + case GameLib.D3.API.BufferGeometry.BUFFER_GEOMETRY_TYPE_CIRCLE : + name = 'BufferGeometry Circle'; + break; + case GameLib.D3.API.BufferGeometry.BUFFER_GEOMETRY_TYPE_CONE : + name = 'BufferGeometry Cone'; + break; + case GameLib.D3.API.BufferGeometry.BUFFER_GEOMETRY_TYPE_CYLINDER : + name = 'BufferGeometry Cylinder'; + break; + case GameLib.D3.API.BufferGeometry.BUFFER_GEOMETRY_TYPE_DODECAHEDRON : + name = 'BufferGeometry Dodecahedron'; + break; + case GameLib.D3.API.BufferGeometry.BUFFER_GEOMETRY_TYPE_EXTRUDE : + name = 'BufferGeometry Extrude'; + break; + case GameLib.D3.API.BufferGeometry.BUFFER_GEOMETRY_TYPE_ICOSAHEDRON : + name = 'BufferGeometry Icosahedron'; + break; + case GameLib.D3.API.BufferGeometry.BUFFER_GEOMETRY_TYPE_LATHE : + name = 'BufferGeometry Lathe'; + break; + case GameLib.D3.API.BufferGeometry.BUFFER_GEOMETRY_TYPE_OCTAHEDRON : + name = 'BufferGeometry Octahedron'; + break; + case GameLib.D3.API.BufferGeometry.BUFFER_GEOMETRY_TYPE_PARAMETRIC : + name = 'BufferGeometry Parametric'; + break; + case GameLib.D3.API.BufferGeometry.BUFFER_GEOMETRY_TYPE_PLANE : + name = 'BufferGeometry Plane'; + break; + case GameLib.D3.API.BufferGeometry.BUFFER_GEOMETRY_TYPE_POLYHEDRON : + name = 'BufferGeometry Polyhedron'; + break; + case GameLib.D3.API.BufferGeometry.BUFFER_GEOMETRY_TYPE_RING : + name = 'BufferGeometry Ring'; + break; + case GameLib.D3.API.BufferGeometry.BUFFER_GEOMETRY_TYPE_SHAPE : + name = 'BufferGeometry Shape'; + break; + case GameLib.D3.API.BufferGeometry.BUFFER_GEOMETRY_TYPE_SPHERE : + name = 'BufferGeometry Sphere'; + break; + case GameLib.D3.API.BufferGeometry.BUFFER_GEOMETRY_TYPE_TETRAHEDRON : + name = 'BufferGeometry Tetrahedron'; + break; + case GameLib.D3.API.BufferGeometry.BUFFER_GEOMETRY_TYPE_TEXT : + name = 'BufferGeometry Text'; + break; + case GameLib.D3.API.BufferGeometry.BUFFER_GEOMETRY_TYPE_TORUS : + name = 'BufferGeometry Torus'; + break; + case GameLib.D3.API.BufferGeometry.BUFFER_GEOMETRY_TYPE_TORUS_KNOT : + name = 'BufferGeometry Torus Knot'; + break; + case GameLib.D3.API.BufferGeometry.BUFFER_GEOMETRY_TYPE_TUBE : + name = 'BufferGeometry Tube'; + break; + default : + console.warn('no nice name for geometry'); + name = 'BufferGeometry'; + } + + name += ' (' + id + ')'; + } + this.name = name; + + if (GameLib.Utils.UndefinedOrNull(attributes)) { + attributes = []; + } + this.attributes = attributes; + + 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(groups)) { + groups = []; + } + this.groups = groups; + + if (GameLib.Utils.UndefinedOrNull(index)) { + index = null; + } + this.index = index; + + if (GameLib.Utils.UndefinedOrNull(morphAttributes)) { + morphAttributes = null; + } + this.morphAttributes = morphAttributes; + + if (GameLib.Utils.UndefinedOrNull(faces)) { + faces = []; + } + this.faces = faces; + + if (GameLib.Utils.UndefinedOrNull(vertices)) { + vertices = []; + } + this.vertices = vertices; + + GameLib.API.Component.call( + this, + GameLib.D3.API.BufferGeometry.GetComponentType(this.bufferGeometryType), + parentEntity + ); +}; + +GameLib.D3.API.BufferGeometry.prototype = Object.create(GameLib.API.Component.prototype); +GameLib.D3.API.BufferGeometry.prototype.constructor = GameLib.D3.API.BufferGeometry; + +GameLib.D3.API.BufferGeometry.GetComponentType = function(bufferGeometryType) { + + var componentType = null; + + switch (bufferGeometryType) { + case GameLib.D3.API.BufferGeometry.BUFFER_GEOMETRY_TYPE_NONE : + componentType = GameLib.Component.BUFFER_GEOMETRY; + break; + case GameLib.D3.API.BufferGeometry.BUFFER_GEOMETRY_TYPE_BOX : + componentType = GameLib.Component.BUFFER_GEOMETRY_BOX; + break; + case GameLib.D3.API.BufferGeometry.BUFFER_GEOMETRY_TYPE_CIRCLE : + componentType = GameLib.Component.BUFFER_GEOMETRY_CIRCLE; + break; + case GameLib.D3.API.BufferGeometry.BUFFER_GEOMETRY_TYPE_CONE : + componentType = GameLib.Component.BUFFER_GEOMETRY_CONE; + break; + case GameLib.D3.API.BufferGeometry.BUFFER_GEOMETRY_TYPE_CYLINDER : + componentType = GameLib.Component.BUFFER_GEOMETRY_CYLINDER; + break; + case GameLib.D3.API.BufferGeometry.BUFFER_GEOMETRY_TYPE_DODECAHEDRON : + componentType = GameLib.Component.BUFFER_GEOMETRY_DODECAHEDRON; + break; + case GameLib.D3.API.BufferGeometry.BUFFER_GEOMETRY_TYPE_EXTRUDE : + componentType = GameLib.Component.BUFFER_GEOMETRY_EXTRUDE; + break; + case GameLib.D3.API.BufferGeometry.BUFFER_GEOMETRY_TYPE_ICOSAHEDRON : + componentType = GameLib.Component.BUFFER_GEOMETRY_ICOSAHEDRON; + break; + case GameLib.D3.API.BufferGeometry.BUFFER_GEOMETRY_TYPE_LATHE : + componentType = GameLib.Component.BUFFER_GEOMETRY_LATHE; + break; + case GameLib.D3.API.BufferGeometry.BUFFER_GEOMETRY_TYPE_OCTAHEDRON : + componentType = GameLib.Component.BUFFER_GEOMETRY_OCTAHEDRON; + break; + case GameLib.D3.API.BufferGeometry.BUFFER_GEOMETRY_TYPE_PARAMETRIC: + componentType = GameLib.Component.BUFFER_GEOMETRY_PARAMETRIC; + break; + case GameLib.D3.API.BufferGeometry.BUFFER_GEOMETRY_TYPE_PLANE : + componentType = GameLib.Component.BUFFER_GEOMETRY_PLANE; + break; + case GameLib.D3.API.BufferGeometry.BUFFER_GEOMETRY_TYPE_POLYHEDRON : + componentType = GameLib.Component.BUFFER_GEOMETRY_POLYHEDRON; + break; + case GameLib.D3.API.BufferGeometry.BUFFER_GEOMETRY_TYPE_RING: + componentType = GameLib.Component.BUFFER_GEOMETRY_RING; + break; + case GameLib.D3.API.BufferGeometry.BUFFER_GEOMETRY_TYPE_SHAPE : + componentType = GameLib.Component.BUFFER_GEOMETRY_SHAPE; + break; + case GameLib.D3.API.BufferGeometry.BUFFER_GEOMETRY_TYPE_SPHERE : + componentType = GameLib.Component.BUFFER_GEOMETRY_SPHERE; + break; + case GameLib.D3.API.BufferGeometry.BUFFER_GEOMETRY_TYPE_TETRAHEDRON : + componentType = GameLib.Component.BUFFER_GEOMETRY_TETRAHEDRON; + break; + case GameLib.D3.API.BufferGeometry.BUFFER_GEOMETRY_TYPE_TEXT : + componentType = GameLib.Component.BUFFER_GEOMETRY_TEXT; + break; + case GameLib.D3.API.BufferGeometry.BUFFER_GEOMETRY_TYPE_TORUS : + componentType = GameLib.Component.BUFFER_GEOMETRY_TORUS; + break; + case GameLib.D3.API.BufferGeometry.BUFFER_GEOMETRY_TYPE_TORUS_KNOT : + componentType = GameLib.Component.BUFFER_GEOMETRY_TORUS_KNOT; + break; + case GameLib.D3.API.BufferGeometry.BUFFER_GEOMETRY_TYPE_TUBE : + componentType = GameLib.Component.BUFFER_GEOMETRY_TUBE; + break; + default: + throw new Error('unhandled geometry type: ' + bufferGeometryType); + } + + return componentType; +}; + +/** + * BufferGeometry Type + * @type {number} + */ +GameLib.D3.API.BufferGeometry.BUFFER_GEOMETRY_TYPE_NONE = 0x1; +GameLib.D3.API.BufferGeometry.BUFFER_GEOMETRY_TYPE_BOX = 0x2; +GameLib.D3.API.BufferGeometry.BUFFER_GEOMETRY_TYPE_CIRCLE = 0x3; +GameLib.D3.API.BufferGeometry.BUFFER_GEOMETRY_TYPE_CONE = 0x4; +GameLib.D3.API.BufferGeometry.BUFFER_GEOMETRY_TYPE_CYLINDER = 0x5; +GameLib.D3.API.BufferGeometry.BUFFER_GEOMETRY_TYPE_DODECAHEDRON = 0x6; +GameLib.D3.API.BufferGeometry.BUFFER_GEOMETRY_TYPE_EXTRUDE = 0x7; +GameLib.D3.API.BufferGeometry.BUFFER_GEOMETRY_TYPE_ICOSAHEDRON = 0x8; +GameLib.D3.API.BufferGeometry.BUFFER_GEOMETRY_TYPE_LATHE = 0x9; +GameLib.D3.API.BufferGeometry.BUFFER_GEOMETRY_TYPE_OCTAHEDRON = 0xa; +GameLib.D3.API.BufferGeometry.BUFFER_GEOMETRY_TYPE_PARAMETRIC = 0xb; +GameLib.D3.API.BufferGeometry.BUFFER_GEOMETRY_TYPE_PLANE = 0xc; +GameLib.D3.API.BufferGeometry.BUFFER_GEOMETRY_TYPE_POLYHEDRON = 0xd; +GameLib.D3.API.BufferGeometry.BUFFER_GEOMETRY_TYPE_RING = 0xe; +GameLib.D3.API.BufferGeometry.BUFFER_GEOMETRY_TYPE_SHAPE = 0xf; +GameLib.D3.API.BufferGeometry.BUFFER_GEOMETRY_TYPE_SPHERE = 0x10; +GameLib.D3.API.BufferGeometry.BUFFER_GEOMETRY_TYPE_TETRAHEDRON = 0x11; +GameLib.D3.API.BufferGeometry.BUFFER_GEOMETRY_TYPE_TEXT = 0x12; +GameLib.D3.API.BufferGeometry.BUFFER_GEOMETRY_TYPE_TORUS = 0x13; +GameLib.D3.API.BufferGeometry.BUFFER_GEOMETRY_TYPE_TORUS_KNOT = 0x14; +GameLib.D3.API.BufferGeometry.BUFFER_GEOMETRY_TYPE_TUBE = 0x15; diff --git a/src/game-lib-d3-api-buffer-geometry-box.js b/src/game-lib-d3-api-buffer-geometry-box.js new file mode 100644 index 0000000..2cd72b5 --- /dev/null +++ b/src/game-lib-d3-api-buffer-geometry-box.js @@ -0,0 +1,81 @@ +/** + * GameLib.D3.API.BufferGeometry.Box + * @param apiBufferGeometry + * @param width + * @param height + * @param depth + * @param widthSegments + * @param heightSegments + * @param depthSegments + * @constructor + */ +GameLib.D3.API.BufferGeometry.Box = function( + apiBufferGeometry, + width, + height, + depth, + widthSegments, + heightSegments, + depthSegments +) { + + if (GameLib.Utils.UndefinedOrNull(apiBufferGeometry)) { + apiBufferGeometry = { + bufferGeometryType: GameLib.D3.API.BufferGeometry.BUFFER_GEOMETRY_TYPE_BOX + }; + } + + if (GameLib.Utils.UndefinedOrNull(apiBufferGeometry.bufferGeometryType)) { + apiBufferGeometry.bufferGeometryType = GameLib.D3.API.BufferGeometry.BUFFER_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.BufferGeometry.call( + this, + apiBufferGeometry.id, + apiBufferGeometry.name, + apiBufferGeometry.bufferGeometryType, + apiBufferGeometry.parentEntity, + apiBufferGeometry.faces, + apiBufferGeometry.vertices, + apiBufferGeometry.attributes, + apiBufferGeometry.boundingBox, + apiBufferGeometry.boundingSphere, + apiBufferGeometry.drawRange, + apiBufferGeometry.groups, + apiBufferGeometry.index, + apiBufferGeometry.morphAttributes + ); +}; + +GameLib.D3.API.BufferGeometry.Box.prototype = Object.create(GameLib.D3.API.BufferGeometry.prototype); +GameLib.D3.API.BufferGeometry.Box.prototype.constructor = GameLib.D3.API.BufferGeometry.Box; diff --git a/src/game-lib-d3-api-buffer-geometry-circle.js b/src/game-lib-d3-api-buffer-geometry-circle.js new file mode 100644 index 0000000..810f89e --- /dev/null +++ b/src/game-lib-d3-api-buffer-geometry-circle.js @@ -0,0 +1,67 @@ +/** + * GameLib.D3.API.BufferGeometry.Circle + * @param apiBufferGeometry + * @param radius + * @param segments + * @param thetaStart + * @param thetaLength + * @constructor + */ +GameLib.D3.API.BufferGeometry.Circle = function( + apiBufferGeometry, + radius, + segments, + thetaStart, + thetaLength +) { + + if (GameLib.Utils.UndefinedOrNull(apiBufferGeometry)) { + apiBufferGeometry = { + bufferGeometryType: GameLib.D3.API.BufferGeometry.BUFFER_GEOMETRY_TYPE_CIRCLE + }; + } + + if (GameLib.Utils.UndefinedOrNull(apiBufferGeometry.bufferGeometryType)) { + apiBufferGeometry.bufferGeometryType = GameLib.D3.API.BufferGeometry.BUFFER_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.BufferGeometry.call( + this, + apiBufferGeometry.id, + apiBufferGeometry.name, + apiBufferGeometry.bufferGeometryType, + apiBufferGeometry.parentEntity, + apiBufferGeometry.faces, + apiBufferGeometry.vertices, + apiBufferGeometry.attributes, + apiBufferGeometry.boundingBox, + apiBufferGeometry.boundingSphere, + apiBufferGeometry.drawRange, + apiBufferGeometry.groups, + apiBufferGeometry.index, + apiBufferGeometry.morphAttributes + ); +}; + +GameLib.D3.API.BufferGeometry.Circle.prototype = Object.create(GameLib.D3.API.BufferGeometry.prototype); +GameLib.D3.API.BufferGeometry.Circle.prototype.constructor = GameLib.D3.API.BufferGeometry.Circle; diff --git a/src/game-lib-d3-api-buffer-geometry-cone.js b/src/game-lib-d3-api-buffer-geometry-cone.js new file mode 100644 index 0000000..52491c2 --- /dev/null +++ b/src/game-lib-d3-api-buffer-geometry-cone.js @@ -0,0 +1,88 @@ +/** + * GameLib.D3.API.BufferGeometry.Cone + * @param apiBufferGeometry + * @param radius + * @param height + * @param radialSegments + * @param heightSegments + * @param openEnded + * @param thetaStart + * @param thetaLength + * @constructor + */ +GameLib.D3.API.BufferGeometry.Cone = function( + apiBufferGeometry, + radius, + height, + radialSegments, + heightSegments, + openEnded, + thetaStart, + thetaLength +) { + + if (GameLib.Utils.UndefinedOrNull(apiBufferGeometry)) { + apiBufferGeometry = { + bufferGeometryType: GameLib.D3.API.BufferGeometry.BUFFER_GEOMETRY_TYPE_CONE + }; + } + + if (GameLib.Utils.UndefinedOrNull(apiBufferGeometry.bufferGeometryType)) { + apiBufferGeometry.bufferGeometryType = GameLib.D3.API.BufferGeometry.BUFFER_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.BufferGeometry.call( + this, + apiBufferGeometry.id, + apiBufferGeometry.name, + apiBufferGeometry.bufferGeometryType, + apiBufferGeometry.parentEntity, + apiBufferGeometry.faces, + apiBufferGeometry.vertices, + apiBufferGeometry.attributes, + apiBufferGeometry.boundingBox, + apiBufferGeometry.boundingSphere, + apiBufferGeometry.drawRange, + apiBufferGeometry.groups, + apiBufferGeometry.index, + apiBufferGeometry.morphAttributes + ); +}; + +GameLib.D3.API.BufferGeometry.Cone.prototype = Object.create(GameLib.D3.API.BufferGeometry.prototype); +GameLib.D3.API.BufferGeometry.Cone.prototype.constructor = GameLib.D3.API.BufferGeometry.Cone; diff --git a/src/game-lib-d3-api-buffer-geometry-cylinder.js b/src/game-lib-d3-api-buffer-geometry-cylinder.js new file mode 100644 index 0000000..5ceec66 --- /dev/null +++ b/src/game-lib-d3-api-buffer-geometry-cylinder.js @@ -0,0 +1,95 @@ +/** + * GameLib.D3.API.BufferGeometry.Cylinder + * @param apiBufferGeometry + * @param radiusTop + * @param radiusBottom + * @param height + * @param radialSegments + * @param heightSegments + * @param openEnded + * @param thetaStart + * @param thetaLength + * @constructor + */ +GameLib.D3.API.BufferGeometry.Cylinder = function( + apiBufferGeometry, + radiusTop, + radiusBottom, + height, + radialSegments, + heightSegments, + openEnded, + thetaStart, + thetaLength +) { + + if (GameLib.Utils.UndefinedOrNull(apiBufferGeometry)) { + apiBufferGeometry = { + bufferGeometryType: GameLib.D3.API.BufferGeometry.BUFFER_GEOMETRY_TYPE_CYLINDER + }; + } + + if (GameLib.Utils.UndefinedOrNull(apiBufferGeometry.bufferGeometryType)) { + apiBufferGeometry.bufferGeometryType = GameLib.D3.API.BufferGeometry.BUFFER_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.BufferGeometry.call( + this, + apiBufferGeometry.id, + apiBufferGeometry.name, + apiBufferGeometry.bufferGeometryType, + apiBufferGeometry.parentEntity, + apiBufferGeometry.faces, + apiBufferGeometry.vertices, + apiBufferGeometry.attributes, + apiBufferGeometry.boundingBox, + apiBufferGeometry.boundingSphere, + apiBufferGeometry.drawRange, + apiBufferGeometry.groups, + apiBufferGeometry.index, + apiBufferGeometry.morphAttributes + ); +}; + +GameLib.D3.API.BufferGeometry.Cylinder.prototype = Object.create(GameLib.D3.API.BufferGeometry.prototype); +GameLib.D3.API.BufferGeometry.Cylinder.prototype.constructor = GameLib.D3.API.BufferGeometry.Cylinder; diff --git a/src/game-lib-d3-api-buffer-geometry-dodecahedron.js b/src/game-lib-d3-api-buffer-geometry-dodecahedron.js new file mode 100644 index 0000000..3a2f1ae --- /dev/null +++ b/src/game-lib-d3-api-buffer-geometry-dodecahedron.js @@ -0,0 +1,53 @@ +/** + * GameLib.D3.API.BufferGeometry.Dodecahedron + * @param apiBufferGeometry + * @param radius + * @param detail + * @constructor + */ +GameLib.D3.API.BufferGeometry.Dodecahedron = function( + apiBufferGeometry, + radius, + detail +) { + + if (GameLib.Utils.UndefinedOrNull(apiBufferGeometry)) { + apiBufferGeometry = { + bufferGeometryType: GameLib.D3.API.BufferGeometry.BUFFER_GEOMETRY_TYPE_DODECAHEDRON + }; + } + + if (GameLib.Utils.UndefinedOrNull(apiBufferGeometry.bufferGeometryType)) { + apiBufferGeometry.bufferGeometryType = GameLib.D3.API.BufferGeometry.BUFFER_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.BufferGeometry.call( + this, + apiBufferGeometry.id, + apiBufferGeometry.name, + apiBufferGeometry.bufferGeometryType, + apiBufferGeometry.parentEntity, + apiBufferGeometry.faces, + apiBufferGeometry.vertices, + apiBufferGeometry.attributes, + apiBufferGeometry.boundingBox, + apiBufferGeometry.boundingSphere, + apiBufferGeometry.drawRange, + apiBufferGeometry.groups, + apiBufferGeometry.index, + apiBufferGeometry.morphAttributes + ); +}; + +GameLib.D3.API.BufferGeometry.Dodecahedron.prototype = Object.create(GameLib.D3.API.BufferGeometry.prototype); +GameLib.D3.API.BufferGeometry.Dodecahedron.prototype.constructor = GameLib.D3.API.BufferGeometry.Dodecahedron; diff --git a/src/game-lib-d3-api-buffer-geometry-extrude.js b/src/game-lib-d3-api-buffer-geometry-extrude.js new file mode 100644 index 0000000..b011f04 --- /dev/null +++ b/src/game-lib-d3-api-buffer-geometry-extrude.js @@ -0,0 +1,111 @@ +/** + * GameLib.D3.API.BufferGeometry.Extrude + * @param apiBufferGeometry + * @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.BufferGeometry.Extrude = function( + apiBufferGeometry, + shapes, + curveSegments, + steps, + amount, + bevelEnabled, + bevelThickness, + bevelSize, + bevelSegments, + extrudePath, + frames, + UVGenerator +) { + + if (GameLib.Utils.UndefinedOrNull(apiBufferGeometry)) { + apiBufferGeometry = { + bufferGeometryType: GameLib.D3.API.BufferGeometry.BUFFER_GEOMETRY_TYPE_EXTRUDE + }; + } + + if (GameLib.Utils.UndefinedOrNull(apiBufferGeometry.bufferGeometryType)) { + apiBufferGeometry.bufferGeometryType = GameLib.D3.API.BufferGeometry.BUFFER_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.BufferGeometry.call( + this, + apiBufferGeometry.id, + apiBufferGeometry.name, + apiBufferGeometry.bufferGeometryType, + apiBufferGeometry.parentEntity, + apiBufferGeometry.faces, + apiBufferGeometry.vertices, + apiBufferGeometry.attributes, + apiBufferGeometry.boundingBox, + apiBufferGeometry.boundingSphere, + apiBufferGeometry.drawRange, + apiBufferGeometry.groups, + apiBufferGeometry.index, + apiBufferGeometry.morphAttributes + ); +}; + +GameLib.D3.API.BufferGeometry.Extrude.prototype = Object.create(GameLib.D3.API.BufferGeometry.prototype); +GameLib.D3.API.BufferGeometry.Extrude.prototype.constructor = GameLib.D3.API.BufferGeometry.Extrude; diff --git a/src/game-lib-d3-api-buffer-geometry-icosahedron.js b/src/game-lib-d3-api-buffer-geometry-icosahedron.js new file mode 100644 index 0000000..e6bda3b --- /dev/null +++ b/src/game-lib-d3-api-buffer-geometry-icosahedron.js @@ -0,0 +1,53 @@ +/** + * GameLib.D3.API.BufferGeometry.Icosahedron + * @param apiBufferGeometry + * @param radius + * @param detail + * @constructor + */ +GameLib.D3.API.BufferGeometry.Icosahedron = function( + apiBufferGeometry, + radius, + detail +) { + + if (GameLib.Utils.UndefinedOrNull(apiBufferGeometry)) { + apiBufferGeometry = { + bufferGeometryType: GameLib.D3.API.BufferGeometry.BUFFER_GEOMETRY_TYPE_ICOSAHEDRON + }; + } + + if (GameLib.Utils.UndefinedOrNull(apiBufferGeometry.bufferGeometryType)) { + apiBufferGeometry.bufferGeometryType = GameLib.D3.API.BufferGeometry.BUFFER_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.BufferGeometry.call( + this, + apiBufferGeometry.id, + apiBufferGeometry.name, + apiBufferGeometry.bufferGeometryType, + apiBufferGeometry.parentEntity, + apiBufferGeometry.faces, + apiBufferGeometry.vertices, + apiBufferGeometry.attributes, + apiBufferGeometry.boundingBox, + apiBufferGeometry.boundingSphere, + apiBufferGeometry.drawRange, + apiBufferGeometry.groups, + apiBufferGeometry.index, + apiBufferGeometry.morphAttributes + ); +}; + +GameLib.D3.API.BufferGeometry.Icosahedron.prototype = Object.create(GameLib.D3.API.BufferGeometry.prototype); +GameLib.D3.API.BufferGeometry.Icosahedron.prototype.constructor = GameLib.D3.API.BufferGeometry.Icosahedron; diff --git a/src/game-lib-d3-api-buffer-geometry-lathe.js b/src/game-lib-d3-api-buffer-geometry-lathe.js new file mode 100644 index 0000000..4c87412 --- /dev/null +++ b/src/game-lib-d3-api-buffer-geometry-lathe.js @@ -0,0 +1,67 @@ +/** + * GameLib.D3.API.BufferGeometry.Lathe + * @param apiBufferGeometry + * @param points [GameLib.Vector2] + * @param segments + * @param phiStart + * @param phiLength + * @constructor + */ +GameLib.D3.API.BufferGeometry.Lathe = function( + apiBufferGeometry, + points, + segments, + phiStart, + phiLength +) { + + if (GameLib.Utils.UndefinedOrNull(apiBufferGeometry)) { + apiBufferGeometry = { + bufferGeometryType: GameLib.D3.API.BufferGeometry.BUFFER_GEOMETRY_TYPE_LATHE + }; + } + + if (GameLib.Utils.UndefinedOrNull(apiBufferGeometry.bufferGeometryType)) { + apiBufferGeometry.bufferGeometryType = GameLib.D3.API.BufferGeometry.BUFFER_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.BufferGeometry.call( + this, + apiBufferGeometry.id, + apiBufferGeometry.name, + apiBufferGeometry.bufferGeometryType, + apiBufferGeometry.parentEntity, + apiBufferGeometry.faces, + apiBufferGeometry.vertices, + apiBufferGeometry.attributes, + apiBufferGeometry.boundingBox, + apiBufferGeometry.boundingSphere, + apiBufferGeometry.drawRange, + apiBufferGeometry.groups, + apiBufferGeometry.index, + apiBufferGeometry.morphAttributes + ); +}; + +GameLib.D3.API.BufferGeometry.Lathe.prototype = Object.create(GameLib.D3.API.BufferGeometry.prototype); +GameLib.D3.API.BufferGeometry.Lathe.prototype.constructor = GameLib.D3.API.BufferGeometry.Lathe; diff --git a/src/game-lib-d3-api-buffer-geometry-octahedron.js b/src/game-lib-d3-api-buffer-geometry-octahedron.js new file mode 100644 index 0000000..e1ed3f2 --- /dev/null +++ b/src/game-lib-d3-api-buffer-geometry-octahedron.js @@ -0,0 +1,53 @@ +/** + * GameLib.D3.API.BufferGeometry.Octahedron + * @param apiBufferGeometry + * @param radius + * @param detail + * @constructor + */ +GameLib.D3.API.BufferGeometry.Octahedron = function( + apiBufferGeometry, + radius, + detail +) { + + if (GameLib.Utils.UndefinedOrNull(apiBufferGeometry)) { + apiBufferGeometry = { + bufferGeometryType: GameLib.D3.API.BufferGeometry.BUFFER_GEOMETRY_TYPE_OCTAHEDRON + }; + } + + if (GameLib.Utils.UndefinedOrNull(apiBufferGeometry.bufferGeometryType)) { + apiBufferGeometry.bufferGeometryType = GameLib.D3.API.BufferGeometry.BUFFER_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.BufferGeometry.call( + this, + apiBufferGeometry.id, + apiBufferGeometry.name, + apiBufferGeometry.bufferGeometryType, + apiBufferGeometry.parentEntity, + apiBufferGeometry.faces, + apiBufferGeometry.vertices, + apiBufferGeometry.attributes, + apiBufferGeometry.boundingBox, + apiBufferGeometry.boundingSphere, + apiBufferGeometry.drawRange, + apiBufferGeometry.groups, + apiBufferGeometry.index, + apiBufferGeometry.morphAttributes + ); +}; + +GameLib.D3.API.BufferGeometry.Octahedron.prototype = Object.create(GameLib.D3.API.BufferGeometry.prototype); +GameLib.D3.API.BufferGeometry.Octahedron.prototype.constructor = GameLib.D3.API.BufferGeometry.Octahedron; diff --git a/src/game-lib-d3-api-buffer-geometry-parametric.js b/src/game-lib-d3-api-buffer-geometry-parametric.js new file mode 100644 index 0000000..82adb9d --- /dev/null +++ b/src/game-lib-d3-api-buffer-geometry-parametric.js @@ -0,0 +1,60 @@ +/** + * GameLib.D3.API.BufferGeometry.Parametric + * @param apiBufferGeometry + * @param generatorFn(u,v) => returns Vector3, u and v is values between 0 and 1 + * @param slices + * @param stacks + * @constructor + */ +GameLib.D3.API.BufferGeometry.Parametric = function( + apiBufferGeometry, + generatorFn, + slices, + stacks +) { + + if (GameLib.Utils.UndefinedOrNull(apiBufferGeometry)) { + apiBufferGeometry = { + bufferGeometryType: GameLib.D3.API.BufferGeometry.BUFFER_GEOMETRY_TYPE_PARAMETRIC + }; + } + + if (GameLib.Utils.UndefinedOrNull(apiBufferGeometry.bufferGeometryType)) { + apiBufferGeometry.bufferGeometryType = GameLib.D3.API.BufferGeometry.BUFFER_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.BufferGeometry.call( + this, + apiBufferGeometry.id, + apiBufferGeometry.name, + apiBufferGeometry.bufferGeometryType, + apiBufferGeometry.parentEntity, + apiBufferGeometry.faces, + apiBufferGeometry.vertices, + apiBufferGeometry.attributes, + apiBufferGeometry.boundingBox, + apiBufferGeometry.boundingSphere, + apiBufferGeometry.drawRange, + apiBufferGeometry.groups, + apiBufferGeometry.index, + apiBufferGeometry.morphAttributes + ); +}; + +GameLib.D3.API.BufferGeometry.Parametric.prototype = Object.create(GameLib.D3.API.BufferGeometry.prototype); +GameLib.D3.API.BufferGeometry.Parametric.prototype.constructor = GameLib.D3.API.BufferGeometry.Parametric; diff --git a/src/game-lib-d3-api-buffer-geometry-plane.js b/src/game-lib-d3-api-buffer-geometry-plane.js new file mode 100644 index 0000000..eddc2c1 --- /dev/null +++ b/src/game-lib-d3-api-buffer-geometry-plane.js @@ -0,0 +1,67 @@ +/** + * GameLib.D3.API.BufferGeometry.Plane + * @param apiBufferGeometry + * @param width + * @param height + * @param widthSegments + * @param heightSegments + * @constructor + */ +GameLib.D3.API.BufferGeometry.Plane = function( + apiBufferGeometry, + width, + height, + widthSegments, + heightSegments +) { + + if (GameLib.Utils.UndefinedOrNull(apiBufferGeometry)) { + apiBufferGeometry = { + bufferGeometryType: GameLib.D3.API.BufferGeometry.BUFFER_GEOMETRY_TYPE_PLANE + }; + } + + if (GameLib.Utils.UndefinedOrNull(apiBufferGeometry.bufferGeometryType)) { + apiBufferGeometry.bufferGeometryType = GameLib.D3.API.BufferGeometry.BUFFER_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.BufferGeometry.call( + this, + apiBufferGeometry.id, + apiBufferGeometry.name, + apiBufferGeometry.bufferGeometryType, + apiBufferGeometry.parentEntity, + apiBufferGeometry.faces, + apiBufferGeometry.vertices, + apiBufferGeometry.attributes, + apiBufferGeometry.boundingBox, + apiBufferGeometry.boundingSphere, + apiBufferGeometry.drawRange, + apiBufferGeometry.groups, + apiBufferGeometry.index, + apiBufferGeometry.morphAttributes + ); +}; + +GameLib.D3.API.BufferGeometry.Plane.prototype = Object.create(GameLib.D3.API.BufferGeometry.prototype); +GameLib.D3.API.BufferGeometry.Plane.prototype.constructor = GameLib.D3.API.BufferGeometry.Plane; diff --git a/src/game-lib-d3-api-buffer-geometry-polyhedron.js b/src/game-lib-d3-api-buffer-geometry-polyhedron.js new file mode 100644 index 0000000..a624e15 --- /dev/null +++ b/src/game-lib-d3-api-buffer-geometry-polyhedron.js @@ -0,0 +1,67 @@ +/** + * GameLib.D3.API.BufferGeometry.Polyhedron + * @param apiBufferGeometry + * @param vertices + * @param indices + * @param radius + * @param detail + * @constructor + */ +GameLib.D3.API.BufferGeometry.Polyhedron = function( + apiBufferGeometry, + vertices, + indices, + radius, + detail +) { + + if (GameLib.Utils.UndefinedOrNull(apiBufferGeometry)) { + apiBufferGeometry = { + bufferGeometryType: GameLib.D3.API.BufferGeometry.BUFFER_GEOMETRY_TYPE_POLYHEDRON + }; + } + + if (GameLib.Utils.UndefinedOrNull(apiBufferGeometry.bufferGeometryType)) { + apiBufferGeometry.bufferGeometryType = GameLib.D3.API.BufferGeometry.BUFFER_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.BufferGeometry.call( + this, + apiBufferGeometry.id, + apiBufferGeometry.name, + apiBufferGeometry.bufferGeometryType, + apiBufferGeometry.parentEntity, + apiBufferGeometry.faces, + apiBufferGeometry.vertices, + apiBufferGeometry.attributes, + apiBufferGeometry.boundingBox, + apiBufferGeometry.boundingSphere, + apiBufferGeometry.drawRange, + apiBufferGeometry.groups, + apiBufferGeometry.index, + apiBufferGeometry.morphAttributes + ); +}; + +GameLib.D3.API.BufferGeometry.Polyhedron.prototype = Object.create(GameLib.D3.API.BufferGeometry.prototype); +GameLib.D3.API.BufferGeometry.Polyhedron.prototype.constructor = GameLib.D3.API.BufferGeometry.Polyhedron; diff --git a/src/game-lib-d3-api-buffer-geometry-ring.js b/src/game-lib-d3-api-buffer-geometry-ring.js new file mode 100644 index 0000000..a09004d --- /dev/null +++ b/src/game-lib-d3-api-buffer-geometry-ring.js @@ -0,0 +1,81 @@ +/** + * GameLib.D3.API.BufferGeometry.Ring + * @param apiBufferGeometry + * @param innerRadius + * @param outerRadius + * @param thetaSegments + * @param phiSegments + * @param thetaStart + * @param thetaLength + * @constructor + */ +GameLib.D3.API.BufferGeometry.Ring = function( + apiBufferGeometry, + innerRadius, + outerRadius, + thetaSegments, + phiSegments, + thetaStart, + thetaLength +) { + + if (GameLib.Utils.UndefinedOrNull(apiBufferGeometry)) { + apiBufferGeometry = { + bufferGeometryType: GameLib.D3.API.BufferGeometry.BUFFER_GEOMETRY_TYPE_RING + }; + } + + if (GameLib.Utils.UndefinedOrNull(apiBufferGeometry.bufferGeometryType)) { + apiBufferGeometry.bufferGeometryType = GameLib.D3.API.BufferGeometry.BUFFER_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.BufferGeometry.call( + this, + apiBufferGeometry.id, + apiBufferGeometry.name, + apiBufferGeometry.bufferGeometryType, + apiBufferGeometry.parentEntity, + apiBufferGeometry.faces, + apiBufferGeometry.vertices, + apiBufferGeometry.attributes, + apiBufferGeometry.boundingBox, + apiBufferGeometry.boundingSphere, + apiBufferGeometry.drawRange, + apiBufferGeometry.groups, + apiBufferGeometry.index, + apiBufferGeometry.morphAttributes + ); +}; + +GameLib.D3.API.BufferGeometry.Ring.prototype = Object.create(GameLib.D3.API.BufferGeometry.prototype); +GameLib.D3.API.BufferGeometry.Ring.prototype.constructor = GameLib.D3.API.BufferGeometry.Ring; diff --git a/src/game-lib-d3-api-buffer-geometry-shape.js b/src/game-lib-d3-api-buffer-geometry-shape.js new file mode 100644 index 0000000..7484d2f --- /dev/null +++ b/src/game-lib-d3-api-buffer-geometry-shape.js @@ -0,0 +1,53 @@ +/** + * GameLib.D3.API.BufferGeometry.Shape + * @param apiBufferGeometry + * @param shapes + * @param curveSegments + * @constructor + */ +GameLib.D3.API.BufferGeometry.Shape = function( + apiBufferGeometry, + shapes, + curveSegments +) { + + if (GameLib.Utils.UndefinedOrNull(apiBufferGeometry)) { + apiBufferGeometry = { + bufferGeometryType: GameLib.D3.API.BufferGeometry.BUFFER_GEOMETRY_TYPE_SHAPE + }; + } + + if (GameLib.Utils.UndefinedOrNull(apiBufferGeometry.bufferGeometryType)) { + apiBufferGeometry.bufferGeometryType = GameLib.D3.API.BufferGeometry.BUFFER_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.BufferGeometry.call( + this, + apiBufferGeometry.id, + apiBufferGeometry.name, + apiBufferGeometry.bufferGeometryType, + apiBufferGeometry.parentEntity, + apiBufferGeometry.faces, + apiBufferGeometry.vertices, + apiBufferGeometry.attributes, + apiBufferGeometry.boundingBox, + apiBufferGeometry.boundingSphere, + apiBufferGeometry.drawRange, + apiBufferGeometry.groups, + apiBufferGeometry.index, + apiBufferGeometry.morphAttributes + ); +}; + +GameLib.D3.API.BufferGeometry.Shape.prototype = Object.create(GameLib.D3.API.BufferGeometry.prototype); +GameLib.D3.API.BufferGeometry.Shape.prototype.constructor = GameLib.D3.API.BufferGeometry.Shape; diff --git a/src/game-lib-d3-api-buffer-geometry-sphere.js b/src/game-lib-d3-api-buffer-geometry-sphere.js new file mode 100644 index 0000000..0f8ea64 --- /dev/null +++ b/src/game-lib-d3-api-buffer-geometry-sphere.js @@ -0,0 +1,88 @@ +/** + * GameLib.D3.API.BufferGeometry.Sphere + * @param apiBufferGeometry + * @param radius + * @param widthSegments + * @param heightSegments + * @param phiStart + * @param phiLength + * @param thetaStart + * @param thetaLength + * @constructor + */ +GameLib.D3.API.BufferGeometry.Sphere = function( + apiBufferGeometry, + radius, + widthSegments, + heightSegments, + phiStart, + phiLength, + thetaStart, + thetaLength +) { + + if (GameLib.Utils.UndefinedOrNull(apiBufferGeometry)) { + apiBufferGeometry = { + bufferGeometryType: GameLib.D3.API.BufferGeometry.BUFFER_GEOMETRY_TYPE_SPHERE + }; + } + + if (GameLib.Utils.UndefinedOrNull(apiBufferGeometry.bufferGeometryType)) { + apiBufferGeometry.bufferGeometryType = GameLib.D3.API.BufferGeometry.BUFFER_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.BufferGeometry.call( + this, + apiBufferGeometry.id, + apiBufferGeometry.name, + apiBufferGeometry.bufferGeometryType, + apiBufferGeometry.parentEntity, + apiBufferGeometry.faces, + apiBufferGeometry.vertices, + apiBufferGeometry.attributes, + apiBufferGeometry.boundingBox, + apiBufferGeometry.boundingSphere, + apiBufferGeometry.drawRange, + apiBufferGeometry.groups, + apiBufferGeometry.index, + apiBufferGeometry.morphAttributes + ); +}; + +GameLib.D3.API.BufferGeometry.Sphere.prototype = Object.create(GameLib.D3.API.BufferGeometry.prototype); +GameLib.D3.API.BufferGeometry.Sphere.prototype.constructor = GameLib.D3.API.BufferGeometry.Sphere; diff --git a/src/game-lib-d3-api-buffer-geometry-tetrahedron.js b/src/game-lib-d3-api-buffer-geometry-tetrahedron.js new file mode 100644 index 0000000..ba76bf4 --- /dev/null +++ b/src/game-lib-d3-api-buffer-geometry-tetrahedron.js @@ -0,0 +1,53 @@ +/** + * GameLib.D3.API.BufferGeometry.Tetrahedron + * @param apiBufferGeometry + * @param radius + * @param detail + * @constructor + */ +GameLib.D3.API.BufferGeometry.Tetrahedron = function( + apiBufferGeometry, + radius, + detail +) { + + if (GameLib.Utils.UndefinedOrNull(apiBufferGeometry)) { + apiBufferGeometry = { + bufferGeometryType: GameLib.D3.API.BufferGeometry.BUFFER_GEOMETRY_TYPE_TETRAHEDRON + }; + } + + if (GameLib.Utils.UndefinedOrNull(apiBufferGeometry.bufferGeometryType)) { + apiBufferGeometry.bufferGeometryType = GameLib.D3.API.BufferGeometry.BUFFER_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.BufferGeometry.call( + this, + apiBufferGeometry.id, + apiBufferGeometry.name, + apiBufferGeometry.bufferGeometryType, + apiBufferGeometry.parentEntity, + apiBufferGeometry.faces, + apiBufferGeometry.vertices, + apiBufferGeometry.attributes, + apiBufferGeometry.boundingBox, + apiBufferGeometry.boundingSphere, + apiBufferGeometry.drawRange, + apiBufferGeometry.groups, + apiBufferGeometry.index, + apiBufferGeometry.morphAttributes + ); +}; + +GameLib.D3.API.BufferGeometry.Tetrahedron.prototype = Object.create(GameLib.D3.API.BufferGeometry.prototype); +GameLib.D3.API.BufferGeometry.Tetrahedron.prototype.constructor = GameLib.D3.API.BufferGeometry.Tetrahedron; diff --git a/src/game-lib-d3-api-buffer-geometry-text.js b/src/game-lib-d3-api-buffer-geometry-text.js new file mode 100644 index 0000000..bb3fa12 --- /dev/null +++ b/src/game-lib-d3-api-buffer-geometry-text.js @@ -0,0 +1,102 @@ +/** + * GameLib.D3.API.BufferGeometry.Text + * @param apiBufferGeometry + * @param text + * @param font + * @param size + * @param height + * @param curveSegments + * @param bevelEnabled + * @param bevelThickness + * @param bevelSize + * @param bevelSegments + * @constructor + */ +GameLib.D3.API.BufferGeometry.Text = function( + apiBufferGeometry, + text, + font, + size, + height, + curveSegments, + bevelEnabled, + bevelThickness, + bevelSize, + bevelSegments +) { + + if (GameLib.Utils.UndefinedOrNull(apiBufferGeometry)) { + apiBufferGeometry = { + bufferGeometryType: GameLib.D3.API.BufferGeometry.BUFFER_GEOMETRY_TYPE_TEXT + }; + } + + if (GameLib.Utils.UndefinedOrNull(apiBufferGeometry.bufferGeometryType)) { + apiBufferGeometry.bufferGeometryType = GameLib.D3.API.BufferGeometry.BUFFER_GEOMETRY_TYPE_TEXT; + } + + if (GameLib.Utils.UndefinedOrNull(text)) { + text = '-= b.materialIndex) { + return 1; + } + + return 0; + }); +}; + +GameLib.D3.Geometry.prototype.applyToInstance = function(property) { + + if (property === 'faces') { + + this.sortFaces(); + + var standardUvs = []; + + /** + * Now setup each face and collect UV information during this process + */ + this.instance.faces = this.faces.map( + function (face) { + + if (face.uvs[0].length > 0) { + standardUvs.push( + face.uvs[0].map( + function (uv) { + return uv.instance; + } + ) + ); + } + + if (!face.instance) { + face.createInstance(this); + } + + return face.instance; + }.bind(this) + ); + + /** + * UV data - but only if it exists + */ + if (standardUvs.length > 0) { + this.instance.faceVertexUvs = [standardUvs]; + } + return; } - this.instance.alphaTest = this.alphaTest; - this.instance.blendDst = this.blendDst; - this.instance.blendDstAlpha = this.blendDstAlpha; - this.instance.blendEquation = this.blendEquation; - this.instance.blendEquationAlpha = this.blendEquationAlpha; - this.instance.blending = this.blending; - this.instance.blendSrc = this.blendSrc; - this.instance.blendSrcAlpha = this.blendSrcAlpha; - this.instance.clipIntersection = this.clipIntersection; - this.instance.clippingPlanes = this.clippingPlanes; - this.instance.clipShadows = this.clipShadows; - this.instance.colorWrite = this.colorWrite; - this.instance.customDepthGeometry = this.customDepthGeometry; - this.instance.customDistanceGeometry = this.customDistanceGeometry; - this.instance.defines = this.defines; - this.instance.depthFunc = this.depthFunc; - this.instance.depthTest = this.depthTest; - this.instance.depthWrite = this.depthWrite; - this.instance.fog = this.fog; - this.instance.lights = this.lights; - this.instance.opacity = this.opacity; - this.instance.overdraw = this.overdraw; - this.instance.polygonOffset = this.polygonOffset; - this.instance.polygonOffsetFactor = this.polygonOffsetFactor; - this.instance.polygonOffsetUnits = this.polygonOffsetUnits; - this.instance.precision = this.precision; - this.instance.premultipliedAlpha = this.premultipliedAlpha; - this.instance.dithering = this.dithering; - this.instance.flatShading = this.flatShading; - this.instance.side = this.side; - this.instance.transparent = this.transparent; - this.instance.vertexColors = this.vertexColors; - this.instance.visible = this.visible; + if (property === 'vertices') { + this.instance.vertices = this.vertices.map( + function (vertex) { + return vertex.position.instance; + } + ); + } +}; +GameLib.D3.Geometry.prototype.createInstance = function() { + + if (GameLib.Utils.UndefinedOrNull(this.instance)) { + this.instance = new THREE.Geometry(); + } + + this.instance.name = this.name; + + /** + * We calculate the bounding box new and copy the information for ourselves + */ + this.instance.computeBoundingBox(); + + this.boundingBox.min.x = this.instance.boundingBox.min.x; + this.boundingBox.min.y = this.instance.boundingBox.min.y; + this.boundingBox.min.z = this.instance.boundingBox.min.z; + + this.boundingBox.max.x = this.instance.boundingBox.max.x; + this.boundingBox.max.y = this.instance.boundingBox.max.y; + this.boundingBox.max.z = this.instance.boundingBox.max.z; + + /** + * Same with the bounding sphere + */ + this.instance.computeBoundingSphere(); + + this.boundingSphere.center.x = this.instance.boundingSphere.center.x; + this.boundingSphere.center.y = this.instance.boundingSphere.center.y; + this.boundingSphere.center.z = this.instance.boundingSphere.center.z; + this.boundingSphere.radius = this.instance.boundingSphere.radius; + + /** + * Setup colors + */ + this.instance.colors = this.colors.map( + function(color) { + return color.instance; + } + ); + + /** + * Setup faces + */ + this.applyToInstance('faces'); + + /** + * Setup line distances - we let three calculate it and then update our information + */ + this.instance.computeLineDistances(); + this.lineDistances = this.instance.lineDistances; + + /** + * Some more stuff + */ + if (this.morphTargets && this.morphTargets.length > 0) { + this.instance.morphTargets = this.morphTargets; + } + + if (this.morphNormals && this.morphNormals.length > 0) { + this.instance.morphNormals = this.morphNormals; + } + + if (this.skinWeights && this.skinWeights.length > 0) { + this.instance.skinWeights = this.skinWeights.map( + function(skinWeight) { + return skinWeight.instance; + } + ); + } + + if (this.skinIndices && this.skinIndices.length > 0) { + this.instance.skinIndices = this.skinIndices.map( + function(skinIndex) { + return skinIndex.instance; + } + ); + } + + /** + * Setup vertices + */ + this.applyToInstance('vertices'); + + this.instance.computeFaceNormals(); + this.instance.computeVertexNormals(); + + // this.instance.verticesNeedUpdate = true; + // this.instance.elementsNeedUpdate = true; + // this.instance.uvsNeedUpdate = true; + // this.instance.normalsNeedUpdate = true; + // this.instance.colorsNeedUpdate = true; + // this.instance.groupsNeedUpdate = true; + // this.instance.lineDistancesNeedUpdate = true; + + // /** + // * Re-compute normals - we don't do this for buffer geometry because it assigns to every vertex normal the face + // * normal - essentially disabling 'smooth shading' + // */ + // geometry.computeFaceNormals(); + // // geometry.computeBoundingBox(); + // geometry.computeVertexNormals(); + GameLib.Component.prototype.createInstance.call(this); }; @@ -158,202 +297,133 @@ GameLib.D3.Geometry.prototype.createInstance = function() { GameLib.D3.Geometry.prototype.updateInstance = function(property) { if (GameLib.Utils.UndefinedOrNull(this.instance)) { - console.warn('no material instance'); - return; - } - - if (property === 'materialType') { - - var componentType = GameLib.D3.API.Geometry.GetComponentType(this.materialType); - - this.replace(componentType); - - return; - } - - if (property === 'parentEntity') { - console.warn('todo: parent entity update'); - return; - } - - if (property === 'parentMeshes') { - console.warn('parent meshes are read-only'); - return; - } - - if (property === 'alphaTest') { - this.instance.alphaTest = this.alphaTest; - this.instance.needsUpdate = true; - return; - } - - if (property === 'blendDst') { - this.instance.blendDst = this.blendDst; - return; - } - - if (property === 'blendDstAlpha') { - this.instance.blendDstAlpha = this.blendDstAlpha; - return; - } - - if (property === 'blendEquation') { - this.instance.blendEquation = this.blendEquation; - return; - } - - if (property === 'blendEquationAlpha') { - this.instance.blendEquationAlpha = this.blendEquationAlpha; + console.warn('no geometry instance'); return; } - if (property === 'blending') { - this.instance.blending = this.blending; + if (property === 'name') { + this.instance.name = this.name; + return; + } + + if (property === 'boundingBox') { + console.log('bounding box is read only'); + return; + } + + if (property === 'boundingSphere') { + console.log('bounding sphere is read only'); return; + } + + if (property === 'colors') { + this.instance.colors = this.colors.map( + function(color) { + return color.instance; + } + ); + this.instance.colorsNeedUpdate = true; + return; + } + + if (property === 'faces') { + this.applyToInstance(property); + this.instance.elementsNeedUpdate = true; + this.instance.groupsNeedUpdate = true; + return; } - if (property === 'blendSrc') { - this.instance.blendSrc = this.blendSrc; + if (property === 'lineDistances') { + this.instance.lineDistances = this.lineDistances; + this.instance.lineDistancesNeedUpdate = true; + return; + } + + if (property === 'morphTargets') { + this.instance.morphTargets = this.morphTargets; + return; + } + + if (property === 'morphNormals') { + this.instance.morphNormals = this.morphNormals; return; - } + } + + if (property === 'skinWeights') { + + if (this.skinWeights) { + this.instance.skinWeights = this.skinWeights.map( + function(skinWeight) { + return skinWeight.instance; + } + ) + } else { + console.warn('todo : check deleting skinweights'); + delete this.instance.skinWeights; + } - if (property === 'blendSrcAlpha') { - this.instance.blendSrcAlpha = this.blendSrcAlpha; return; - } + } + + if (property === 'skinIndices') { + + if (this.skinIndices) { + this.instance.skinIndices = this.skinIndices.map( + function(skinIndex) { + return skinIndex.instance; + } + ) + } else { + console.warn('todo : check deleting skinIndices'); + delete this.instance.skinIndices; + } - if (property === 'clipIntersection') { - this.instance.clipIntersection = this.clipIntersection; return; - } + } - if (property === 'clippingPlanes') { - console.warn('todo: implement clipping planes update'); + if (property === 'vertices') { + this.applyToInstance(property); + this.instance.verticesNeedUpdate = true; return; - } + } - if (property === 'clipShadows') { - this.instance.clipShadows = this.clipShadows; - return; - } + /** + * Manually trigger updates (and ignore our setting) + */ + if (property === 'verticesNeedsUpdate') { + this.instance.verticesNeedsUpdate = true; + this.verticesNeedUpdate = false; + } - if (property === 'colorWrite') { - this.instance.colorWrite = this.colorWrite; - return; - } + if (property === 'elementsNeedUpdate') { + this.instance.elementsNeedUpdate = true; + this.elementsNeedUpdate = false; + } - if (property === 'customDepthGeometry') { - console.warn('todo: implement custom depth material update'); - return; - } + if (property === 'uvsNeedUpdate') { + this.instance.uvsNeedUpdate = true; + this.uvsNeedUpdate = false; + } - if (property === 'customDistanceGeometry') { - console.warn('todo: implement custom distance material update'); - return; - } + if (property === 'normalsNeedUpdate') { + this.instance.normalsNeedUpdate = true; + this.normalsNeedUpdate = false; + } - if (property === 'defines') { - this.instance.defines = this.defines; - this.instance.needsUpdate = true; - return; - } + if (property === 'colorsNeedUpdate') { + this.instance.colorsNeedUpdate = true; + this.colorsNeedUpdate = false; + } - if (property === 'depthFunc') { - this.instance.depthFunc = this.depthFunc; - return; - } + if (property === 'groupsNeedUpdate') { + this.instance.groupsNeedUpdate = true; + this.groupsNeedUpdate = false; + } - if (property === 'depthTest') { - this.instance.depthTest = this.depthTest; - return; - } - - if (property === 'depthWrite') { - this.instance.depthWrite = this.depthWrite; - return; - } - - if (property === 'fog') { - this.instance.fog = this.fog; - return; - } - - if (property === 'lights') { - this.instance.lights = this.lights; - } - - if (property === 'opacity') { - this.instance.opacity = this.opacity; - return; - } - - if (property === 'overdraw') { - this.instance.overdraw = this.overdraw; - return; - } - - if (property === 'polygonOffset') { - this.instance.polygonOffset = this.polygonOffset; - return; - } - - if (property === 'polygonOffsetFactor') { - this.instance.polygonOffsetFactor = this.polygonOffsetFactor; - return; - } - - if (property === 'polygonOffsetUnits') { - this.instance.polygonOffsetUnits = this.polygonOffsetUnits; - return; - } - - if (property === 'precision') { - this.instance.precision = this.precision; - return; - } - - if (property === 'premultipliedAlpha') { - this.instance.premultipliedAlpha = this.premultipliedAlpha; - return; - } - - if (property === 'dithering') { - this.instance.dithering = this.dithering; - console.log('not sure about needsupdate - cannot detect any changes until now'); - } - - if (property === 'flatShading') { - this.instance.flatShading = this.flatShading; - } - - if (property === 'side') { - this.instance.side = this.side; - return; - } - - if (property === 'transparent') { - this.instance.transparent = this.transparent; - return; - } - - if (property === 'vertexColors') { - this.instance.vertexColors = this.vertexColors; - return; - } - - if (property === 'visible') { - this.instance.visible = this.visible; - return; - } - - if (property === 'needsUpdate') { - /** - * update follows - */ - } - - this.instance.needsUpdate = true; - this.needsUpdate = false; + if (property === 'lineDistancesNeedUpdate') { + this.instance.lineDistancesNeedUpdate = true; + this.lineDistancesNeedUpdate = false; + } GameLib.Component.prototype.updateInstance.call(this, property); }; @@ -365,698 +435,43 @@ GameLib.D3.Geometry.prototype.updateInstance = function(property) { GameLib.D3.Geometry.prototype.toApiObject = function() { var apiGeometry = new GameLib.D3.API.Geometry( - this.id, - this.name, - this.materialType, - GameLib.Utils.IdOrNull(this.parentEntity), - this.parentMeshes.map( - function(mesh) { - return GameLib.Utils.IdOrNull(mesh); + this.id, + this.name, + this.geometryType, + this.isBufferGeometry, + GameLib.Utils.IdOrNull(this.parentEntity), + this.boundingBox.toApiObject(), + this.boundingSphere.toApiObject(), + this.colors.map( + function(color) { + return color.toApiObject(); } ), - this.alphaTest, - this.blendDst, - this.blendDstAlpha, - this.blendEquation, - this.blendEquationAlpha, - this.blending, - this.blendSrc, - this.blendSrcAlpha, - this.clipIntersection, - this.clippingPlanes, - this.clipShadows, - this.colorWrite, - this.customDepthGeometry, - this.customDistanceGeometry, - this.defines, - this.depthFunc, - this.depthTest, - this.depthWrite, - this.fog, - this.lights, - this.opacity, - this.overdraw, - this.polygonOffset, - this.polygonOffsetFactor, - this.polygonOffsetUnits, - this.precision, - this.premultipliedAlpha, - this.dithering, - this.flatShading, - this.side, - this.transparent, - this.vertexColors, - this.visible + this.faces.map( + function(face) { + return face.toApiObject(); + } + ), + this.lineDistances, + this.morphTargets, + this.morphNormals, + this.skinWeights.map( + function(skinWeight) { + return skinWeight.toApiObject(); + } + ), + this.skinIndices.map( + function(skinIndex) { + return skinIndex.toApiObject(); + } + ), + this.vertices.map( + function (vertex) { + return vertex.toApiObject(); + } + ) ); return apiGeometry; }; - -GameLib.D3.Geometry.prototype.assignTexture = function(instanceProperty, property) { - if (this[property] && this[property].instance) { - this.instance[instanceProperty] = this[property].instance; - } else { - this.instance[instanceProperty] = null; - } - this.instance.needsUpdate = true; -}; - -GameLib.D3.Geometry.prototype.getTextures = function() { - - var textures = []; - - Object.keys(this.linkedObjects).map( - function(property) { - if (this[property] instanceof GameLib.D3.Texture) { - textures.push( - { - property: property, - texture: this[property] - } - ); - } - }.bind(this) - ); - - return textures; -}; - - -// -// -// -// GameLib.D3.Geometry.prototype.createToonGeometryInstance = function() { -// return new THREE.MeshToonGeometry({ -// name: this.name, -// opacity: this.opacity, -// transparent: this.transparent, -// blending: this.blending, -// blendSrc: this.blendSrc, -// blendDst: this.blendDst, -// blendEquation: this.blendEquation, -// depthTest: this.depthTest, -// depthFunc: this.depthFunc, -// depthWrite: this.depthWrite, -// polygonOffset: this.polygonOffset, -// polygonOffsetFactor: this.polygonOffsetFactor, -// polygonOffsetUnits: this.polygonOffsetUnits, -// alphaTest: this.alphaTest, -// clippingPlanes: this.clippingPlanes, -// clipShadows: this.clipShadows, -// overdraw: this.overdraw, -// visible: this.visible, -// side: this.side, -// color: this.color.instance, -// roughness: this.roughness, -// metalness: this.metalness, -// lightMapIntensity: this.lightMapIntensity, -// aoMapIntensity: this.aoMapIntensity, -// emissive: this.emissive.instance, -// emissiveIntensity: this.emissiveIntensity, -// bumpScale: this.bumpScale, -// normalScale: this.normalScale, -// displacementScale: this.displacementScale, -// refractionRatio: this.refractionRatio, -// fog: this.fog, -// flatShading: this.flatShading, -// wireframe: this.wireframe, -// wireframeLinewidth: this.wireframeLineWidth, -// wireframeLinecap: this.wireframeLineCap, -// wireframeLinejoin: this.wireframeLineJoin, -// vertexColors: this.vertexColors, -// skinning: this.skinning, -// morphTargets: this.morphTargets, -// morphNormals: this.morphNormals -// }); -// }; - - -// GameLib.D3.Geometry.prototype.createStandardGeometryInstance = function() { -// return new THREE.MeshStandardGeometry({ -// name: this.name, -// opacity: this.opacity, -// transparent: this.transparent, -// blending: this.blending, -// blendSrc: this.blendSrc, -// blendDst: this.blendDst, -// blendEquation: this.blendEquation, -// depthTest: this.depthTest, -// depthFunc: this.depthFunc, -// depthWrite: this.depthWrite, -// polygonOffset: this.polygonOffset, -// polygonOffsetFactor: this.polygonOffsetFactor, -// polygonOffsetUnits: this.polygonOffsetUnits, -// alphaTest: this.alphaTest, -// clippingPlanes: this.clippingPlanes, -// clipShadows: this.clipShadows, -// overdraw: this.overdraw, -// visible: this.visible, -// side: this.side, -// color: this.color.instance, -// roughness: this.roughness, -// metalness: this.metalness, -// lightMapIntensity: this.lightMapIntensity, -// aoMapIntensity: this.aoMapIntensity, -// emissive: this.emissive.instance, -// emissiveIntensity: this.emissiveIntensity, -// bumpScale: this.bumpScale, -// normalScale: this.normalScale, -// displacementScale: this.displacementScale, -// refractionRatio: this.refractionRatio, -// fog: this.fog, -// flatShading: this.flatShading, -// wireframe: this.wireframe, -// wireframeLinewidth: this.wireframeLineWidth, -// wireframeLinecap: this.wireframeLineCap, -// wireframeLinejoin: this.wireframeLineJoin, -// vertexColors: this.vertexColors, -// skinning: this.skinning, -// morphTargets: this.morphTargets, -// morphNormals: this.morphNormals -// }); -// }; - -// GameLib.D3.Geometry.prototype.createPointsGeometryInstance = function() { -// return new THREE.PointsGeometry({ -// name: this.name, -// opacity: this.opacity, -// transparent: this.transparent, -// // blending: this.blending, -// // blendSrc: this.blendSrc, -// // blendDst: this.blendDst, -// // blendEquation: this.blendEquation, -// depthTest: this.depthTest, -// depthFunc: this.depthFunc, -// depthWrite: this.depthWrite, -// // polygonOffset: this.polygonOffset, -// // polygonOffsetFactor: this.polygonOffsetFactor, -// // polygonOffsetUnits: this.polygonOffsetUnits, -// // alphaTest: this.alphaTest, -// // clippingPlanes: this.clippingPlanes, -// // clipShadows: this.clipShadows, -// // overdraw: this.overdraw, -// visible: this.visible, -// side: this.side, -// color: this.color.instance, -// size: this.pointSize, -// sizeAttenuation: this.pointSizeAttenuation -// // vertexColors: GameLib.D3.API.Geometry.TYPE_VERTEX_COLORS, -// // fog: this.fog -// }); -// }; -// -// GameLib.D3.Geometry.prototype.createLineBasicGeometryInstance = function() { -// -// var linecap = 'round'; -// -// if (this.lineCap === GameLib.D3.API.Geometry.LINE_CAP_BUTT) { -// linecap = 'butt'; -// } -// -// if (this.lineCap === GameLib.D3.API.Geometry.LINE_CAP_SQUARE) { -// linecap = 'square'; -// } -// -// var linejoin = 'round'; -// -// if (this.lineJoin === GameLib.D3.API.Geometry.LINE_JOIN_BEVEL) { -// linejoin = 'bevel'; -// } -// -// if (this.lineJoin === GameLib.D3.API.Geometry.LINE_JOIN_MITER) { -// linejoin = 'miter'; -// } -// -// return new THREE.LineBasicGeometry({ -// name: this.name, -// opacity: this.opacity, -// transparent: this.transparent, -// // blending: this.blending, -// // blendSrc: this.blendSrc, -// // blendDst: this.blendDst, -// // blendEquation: this.blendEquation, -// depthTest: this.depthTest, -// depthFunc: this.depthFunc, -// depthWrite: this.depthWrite, -// // polygonOffset: this.polygonOffset, -// // polygonOffsetFactor: this.polygonOffsetFactor, -// // polygonOffsetUnits: this.polygonOffsetUnits, -// // alphaTest: this.alphaTest, -// // clippingPlanes: this.clippingPlanes, -// // clipShadows: this.clipShadows, -// // overdraw: this.overdraw, -// visible: this.visible, -// side: this.side, -// color: this.color.instance, -// linewidth: this.lineWidth, -// linecap: linecap, -// linejoin: linejoin -// // vertexColors: GameLib.D3.API.Geometry.TYPE_VERTEX_COLORS, -// // fog: this.fog -// }); -// }; -// -// GameLib.D3.Geometry.prototype.createPhongGeometryInstance = function() { -// return new THREE.MeshPhongGeometry({ -// name: this.name, -// opacity: this.opacity, -// transparent: this.transparent, -// blending: this.blending, -// blendSrc: this.blendSrc, -// blendDst: this.blendDst, -// blendEquation: this.blendEquation, -// depthTest: this.depthTest, -// depthFunc: this.depthFunc, -// depthWrite: this.depthWrite, -// polygonOffset: this.polygonOffset, -// polygonOffsetFactor: this.polygonOffsetFactor, -// polygonOffsetUnits: this.polygonOffsetUnits, -// alphaTest: this.alphaTest, -// clippingPlanes: this.clippingPlanes, -// clipShadows: this.clipShadows, -// overdraw: this.overdraw, -// visible: this.visible, -// side: this.side, -// color: this.color.instance, -// specular: this.specular.instance, -// shininess: this.shininess, -// lightMapIntensity: this.lightMapIntensity, -// aoMapIntensity: this.aoMapIntensity, -// emissive: this.emissive.instance, -// emissiveIntensity: this.emissiveIntensity, -// bumpScale: this.bumpScale, -// normalScale: this.normalScale, -// displacementScale: this.displacementScale, -// combine: this.combine, -// refractionRatio: this.refractionRatio, -// fog: this.fog, -// flatShading: this.flatShading, -// wireframe: this.wireframe, -// wireframeLinewidth: this.wireframeLineWidth, -// wireframeLinecap: this.wireframeLineCap, -// wireframeLinejoin: this.wireframeLineJoin, -// vertexColors: this.vertexColors, -// skinning: this.skinning, -// morphTargets: this.morphTargets, -// morphNormals: this.morphNormals -// }); -// }; -// -// GameLib.D3.Geometry.prototype.createMeshBasicGeometryInstance = function() { -// return new THREE.MeshBasicGeometry({ -// name: this.name, -// opacity: this.opacity, -// transparent: this.transparent, -// blending: this.blending, -// blendSrc: this.blendSrc, -// blendDst: this.blendDst, -// blendEquation: this.blendEquation, -// depthTest: this.depthTest, -// depthFunc: this.depthFunc, -// depthWrite: this.depthWrite, -// polygonOffset: this.polygonOffset, -// polygonOffsetFactor: this.polygonOffsetFactor, -// polygonOffsetUnits: this.polygonOffsetUnits, -// alphaTest: this.alphaTest, -// clippingPlanes: this.clippingPlanes, -// clipShadows: this.clipShadows, -// overdraw: this.overdraw, -// visible: this.visible, -// side: this.side, -// color: this.color.instance, -// vertexColors: this.vertexColors, -// fog: this.fog -// }); -// }; - -// GameLib.D3.Geometry.prototype.checkTexture = function(runtimeMap, instanceMap) { -// -// var textureChanged = false; -// -// if (this[runtimeMap] && this[runtimeMap].instance) { -// if (this.instance[instanceMap] !== this[runtimeMap].instance) { -// this.instance[instanceMap] = this[runtimeMap].instance; -// textureChanged = true; -// } -// } else { -// if (this.instance[instanceMap] !== null) { -// this.instance[instanceMap] = null; -// textureChanged = true; -// } -// } -// -// return textureChanged; -// }; -// -// /** -// * updates textures -// */ -// GameLib.D3.Geometry.prototype.updateTextures = function() { -// -// var textureChanged = false; -// -// if (this.checkTexture('alphaMap', 'alphaMap')) { -// textureChanged = true; -// } -// -// if (this.checkTexture('aoMap', 'aoMap')) { -// textureChanged = true; -// } -// -// if (this.checkTexture('bumpMap', 'bumpMap')) { -// textureChanged = true; -// } -// -// if (this.checkTexture('diffuseMap', 'map')) { -// textureChanged = true; -// } -// -// if (this.checkTexture('displacementMap', 'displacementMap')) { -// textureChanged = true; -// } -// -// if (this.checkTexture('emissiveMap', 'emissiveMap')) { -// textureChanged = true; -// } -// -// if (this.checkTexture('environmentMap', 'envMap')) { -// textureChanged = true; -// } -// -// if (this.checkTexture('lightMap', 'lightMap')) { -// textureChanged = true; -// } -// -// if (this.checkTexture('metalnessMap', 'metalnessMap')) { -// textureChanged = true; -// } -// -// if (this.checkTexture('normalMap', 'normalMap')) { -// textureChanged = true; -// } -// -// if (this.checkTexture('roughnessMap', 'roughnessMap')) { -// textureChanged = true; -// } -// -// if (this.checkTexture('specularMap', 'specularMap')) { -// textureChanged = true; -// } -// -// if (textureChanged) { -// this.publish( -// GameLib.Event.MATERIAL_TEXTURES_UPDATED, -// { -// material : this -// } -// ); -// } -// -// return textureChanged; -// }; -// -// -// GameLib.D3.Geometry.prototype.updateToonGeometryInstance = function(property) { -// this.instance.name = this.name; -// this.instance.opacity = this.opacity; -// this.instance.transparent = this.transparent; -// this.instance.blending = this.blending; -// this.instance.blendSrc = this.blendSrc; -// this.instance.blendDst = this.blendDst; -// this.instance.blendEquation = this.blendEquation; -// this.instance.depthTest = this.depthTest; -// this.instance.depthFunc = this.depthFunc; -// this.instance.depthWrite = this.depthWrite; -// this.instance.polygonOffset = this.polygonOffset; -// this.instance.polygonOffsetFactor = this.polygonOffsetFactor; -// this.instance.polygonOffsetUnits = this.polygonOffsetUnits; -// this.instance.alphaTest = this.alphaTest; -// this.instance.clippingPlanes = this.clippingPlanes; -// this.instance.clipShadows = this.clipShadows; -// this.instance.overdraw = this.overdraw; -// this.instance.visible = this.visible; -// this.instance.side = this.side; -// this.instance.color = this.color.instance; -// this.instance.envMapIntensity = this.envMapIntensity; //standard material doesnt have specular color -// this.instance.roughness = this.roughness; -// this.instance.metalness = this.metalness; -// this.instance.lightMapIntensity = this.lightMapIntensity; -// this.instance.aoMapIntensity = this.aoMapIntensity; -// this.instance.emissive = this.emissive.instance; -// this.instance.emissiveIntensity = this.emissiveIntensity; -// this.instance.bumpScale = this.bumpScale; -// this.instance.normalScale = this.normalScale; -// this.instance.displacementScale = this.displacementScale; -// this.instance.refractionRatio = this.refractionRatio; -// this.instance.fog = this.fog; -// this.instance.flatShading = this.flatShading; -// this.instance.wireframe = this.wireframe; -// this.instance.wireframeLinewidth = this.wireframeLineWidth; -// this.instance.wireframeLinecap = this.wireframeLineCap; -// this.instance.wireframeLinejoin = this.wireframeLineJoin; -// this.instance.vertexColors = this.vertexColors; -// this.instance.skinning = this.skinning; -// this.instance.morphTargets = this.morphTargets; -// this.instance.morphNormals = this.morphNormals; -// }; -// -// GameLib.D3.Geometry.prototype.updateStandardGeometryInstance = function(property) { -// this.instance.name = this.name; -// this.instance.opacity = this.opacity; -// this.instance.transparent = this.transparent; -// this.instance.blending = this.blending; -// this.instance.blendSrc = this.blendSrc; -// this.instance.blendDst = this.blendDst; -// this.instance.blendEquation = this.blendEquation; -// this.instance.depthTest = this.depthTest; -// this.instance.depthFunc = this.depthFunc; -// this.instance.depthWrite = this.depthWrite; -// this.instance.polygonOffset = this.polygonOffset; -// this.instance.polygonOffsetFactor = this.polygonOffsetFactor; -// this.instance.polygonOffsetUnits = this.polygonOffsetUnits; -// this.instance.alphaTest = this.alphaTest; -// this.instance.clippingPlanes = this.clippingPlanes; -// this.instance.clipShadows = this.clipShadows; -// this.instance.overdraw = this.overdraw; -// this.instance.visible = this.visible; -// this.instance.side = this.side; -// this.instance.color = this.color.instance; -// this.instance.envMapIntensity = this.envMapIntensity; //standard material doesnt have specular color -// this.instance.roughness = this.roughness; -// this.instance.metalness = this.metalness; -// this.instance.lightMapIntensity = this.lightMapIntensity; -// this.instance.aoMapIntensity = this.aoMapIntensity; -// this.instance.emissive = this.emissive.instance; -// this.instance.emissiveIntensity = this.emissiveIntensity; -// this.instance.bumpScale = this.bumpScale; -// this.instance.normalScale = this.normalScale; -// this.instance.displacementScale = this.displacementScale; -// this.instance.refractionRatio = this.refractionRatio; -// this.instance.fog = this.fog; -// this.instance.flatShading = this.flatShading; -// this.instance.wireframe = this.wireframe; -// this.instance.wireframeLinewidth = this.wireframeLineWidth; -// this.instance.wireframeLinecap = this.wireframeLineCap; -// this.instance.wireframeLinejoin = this.wireframeLineJoin; -// this.instance.vertexColors = this.vertexColors; -// this.instance.skinning = this.skinning; -// this.instance.morphTargets = this.morphTargets; -// this.instance.morphNormals = this.morphNormals; -// }; -// -// GameLib.D3.Geometry.prototype.updatePointsGeometryInstance = function(property) { -// this.instance.name = this.name; -// this.instance.opacity = this.opacity; -// this.instance.transparent = this.transparent; -// // this.instance.blending = this.blending; -// // this.instance.blendSrc = this.blendSrc; -// // this.instance.blendDst = this.blendDst; -// // this.instance.blendEquation = this.blendEquation; -// // this.instance.depthTest = this.depthTest; -// this.instance.depthFunc = this.depthFunc; -// this.instance.depthWrite = this.depthWrite; -// // this.instance.polygonOffset = this.polygonOffset; -// // this.instance.polygonOffsetFactor = this.polygonOffsetFactor; -// // this.instance.polygonOffsetUnits = this.polygonOffsetUnits; -// // this.instance.alphaTest = this.alphaTest; -// // this.instance.clippingPlanes = this.clippingPlanes; -// // this.instance.clipShadows = this.clipShadows; -// // this.instance.overdraw = this.overdraw; -// this.instance.visible = this.visible; -// this.instance.side = this.side; -// this.instance.color = this.color.instance; -// this.instance.size = this.pointSize; -// this.instance.sizeAttenuation = this.pointSizeAttenuation; -// //this.instance.vertexColors = this.vertexColors; -// //this.instance.fog = this.fog; -// }; -// -// GameLib.D3.Geometry.prototype.updateLineBasicGeometryInstance = function(property) { -// -// var linecap = 'round'; -// -// if (this.lineCap === GameLib.D3.API.Geometry.LINE_CAP_BUTT) { -// linecap = 'butt'; -// } -// -// if (this.lineCap === GameLib.D3.API.Geometry.LINE_CAP_SQUARE) { -// linecap = 'square'; -// } -// -// var linejoin = 'round'; -// -// if (this.lineJoin === GameLib.D3.API.Geometry.LINE_JOIN_BEVEL) { -// linejoin = 'bevel'; -// } -// -// if (this.lineJoin === GameLib.D3.API.Geometry.LINE_JOIN_MITER) { -// linejoin = 'miter'; -// } -// -// this.instance.name = this.name; -// this.instance.opacity = this.opacity; -// this.instance.transparent = this.transparent; -// // this.instance.blending = this.blending; -// // this.instance.blendSrc = this.blendSrc; -// // this.instance.blendDst = this.blendDst; -// // this.instance.blendEquation = this.blendEquation; -// // this.instance.depthTest = this.depthTest; -// this.instance.depthFunc = this.depthFunc; -// this.instance.depthWrite = this.depthWrite; -// // this.instance.polygonOffset = this.polygonOffset; -// // this.instance.polygonOffsetFactor = this.polygonOffsetFactor; -// // this.instance.polygonOffsetUnits = this.polygonOffsetUnits; -// // this.instance.alphaTest = this.alphaTest; -// // this.instance.clippingPlanes = this.clippingPlanes; -// // this.instance.clipShadows = this.clipShadows; -// // this.instance.overdraw = this.overdraw; -// this.instance.visible = this.visible; -// this.instance.side = this.side; -// this.instance.color = this.color.instance; -// -// this.instance.linewidth = this.lineWidth; -// this.instance.linecap = linecap; -// this.instance.linejoin = linejoin; -// -// //this.instance.vertexColors = this.vertexColors; -// //this.instance.fog = this.fog; -// }; -// -// -// GameLib.D3.Geometry.prototype.updatePhongGeometryInstance = function(property) { -// this.instance.name = this.name; -// this.instance.opacity = this.opacity; -// this.instance.transparent = this.transparent; -// this.instance.blending = this.blending; -// this.instance.blendSrc = this.blendSrc; -// this.instance.blendDst = this.blendDst; -// this.instance.blendEquation = this.blendEquation; -// this.instance.depthTest = this.depthTest; -// this.instance.depthFunc = this.depthFunc; -// this.instance.depthWrite = this.depthWrite; -// this.instance.polygonOffset = this.polygonOffset; -// this.instance.polygonOffsetFactor = this.polygonOffsetFactor; -// this.instance.polygonOffsetUnits = this.polygonOffsetUnits; -// this.instance.alphaTest = this.alphaTest; -// this.instance.clippingPlanes = this.clippingPlanes; -// this.instance.clipShadows = this.clipShadows; -// this.instance.overdraw = this.overdraw; -// this.instance.visible = this.visible; -// this.instance.side = this.side; -// this.instance.color = this.color.instance; -// this.instance.specular = this.specular.instance; -// this.instance.shininess = this.shininess; -// this.instance.lightMapIntensity = this.lightMapIntensity; -// this.instance.aoMapIntensity = this.aoMapIntensity; -// this.instance.emissive = this.emissive.instance; -// this.instance.emissiveIntensity = this.emissiveIntensity; -// this.instance.envMapIntensity = this.envMapIntensity; -// this.instance.bumpScale = this.bumpScale; -// this.instance.normalScale = this.normalScale; -// this.instance.displacementScale = this.displacementScale; -// this.instance.combine = this.combine; -// this.instance.refractionRatio = this.refractionRatio; -// this.instance.fog = this.fog; -// this.instance.flatShading = this.flatShading; -// this.instance.wireframe = this.wireframe; -// this.instance.wireframeLinewidth = this.wireframeLineWidth; -// this.instance.wireframeLinecap = this.wireframeLineCap; -// this.instance.wireframeLinejoin = this.wireframeLineJoin; -// this.instance.vertexColors = this.vertexColors; -// this.instance.skinning = this.skinning; -// this.instance.morphTargets = this.morphTargets; -// this.instance.morphNormals = this.morphNormals; -// }; -// -// GameLib.D3.Geometry.prototype.updateMeshBasicGeometryInstance = function(property) { -// this.instance.name = this.name; -// this.instance.opacity = this.opacity; -// this.instance.transparent = this.transparent; -// this.instance.blending = this.blending; -// this.instance.blendSrc = this.blendSrc; -// this.instance.blendDst = this.blendDst; -// this.instance.blendEquation = this.blendEquation; -// this.instance.depthTest = this.depthTest; -// this.instance.depthFunc = this.depthFunc; -// this.instance.depthWrite = this.depthWrite; -// this.instance.polygonOffset = this.polygonOffset; -// this.instance.polygonOffsetFactor = this.polygonOffsetFactor; -// this.instance.polygonOffsetUnits = this.polygonOffsetUnits; -// this.instance.alphaTest = this.alphaTest; -// this.instance.clippingPlanes = this.clippingPlanes; -// this.instance.clipShadows = this.clipShadows; -// this.instance.overdraw = this.overdraw; -// this.instance.visible = this.visible; -// this.instance.side = this.side; -// this.instance.color = this.color.instance; -// this.instance.vertexColors = this.vertexColors; -// this.instance.fog = this.fog; -// }; -// -// /** -// * Geometry instance -// * @returns {*} -// */ -// GameLib.D3.Geometry.prototype.createInstance = function() { -// -// if (this.materialType === GameLib.D3.API.Geometry.MATERIAL_TYPE_STANDARD) { -// -// this.instance = this.createStandardGeometryInstance(); -// -// } else if (this.materialType === GameLib.D3.API.Geometry.MATERIAL_TYPE_POINTS) { -// -// this.instance = this.createPointsGeometryInstance(); -// -// } else if (this.materialType === GameLib.D3.API.Geometry.MATERIAL_TYPE_PHONG) { -// -// this.instance = this.createPhongGeometryInstance(); -// -// } else if (this.materialType === GameLib.D3.API.Geometry.MATERIAL_TYPE_BASIC) { -// -// this.instance = this.createMeshBasicGeometryInstance(); -// -// } else if (this.materialType === GameLib.D3.API.Geometry.MATERIAL_TYPE_LINE_BASIC) { -// -// this.instance = this.createLineBasicGeometryInstance(); -// -// } else if (this.materialType === GameLib.D3.API.Geometry.MATERIAL_TYPE_TOON) { -// -// this.instance = this.createToonGeometryInstance(); -// -// } else { -// console.warn("material type is not implemented yet: " + this.materialType); -// } -// -// this.instance.needsUpdate = true; -// -// this.updateTextures(); -// -// GameLib.Component.prototype.createInstance.call(this); -// }; - -/** - * Updates the instance with the current state - */ - - diff --git a/src/game-lib-d3-geometry-buffer-a.js b/src/game-lib-d3-geometry-buffer-a.js new file mode 100644 index 0000000..8ae19d4 --- /dev/null +++ b/src/game-lib-d3-geometry-buffer-a.js @@ -0,0 +1,258 @@ +/** + * GameLib.D3.Geometry.Buffer + * @param graphics + * @param apiGeometry + * @property geometryType + * @constructor + */ +GameLib.D3.BufferGeometry = function( + graphics, + apiGeometry +) { + + this.graphics = graphics; + this.graphics.isNotThreeThrow(); + + if (GameLib.Utils.UndefinedOrNull(apiGeometry)) { + apiGeometry = { + geometryType : GameLib.D3.API.Geometry.GEOMETRY_TYPE_BUFFER + }; + } + + GameLib.D3.Geometry.call( + this, + apiGeometry + ); +}; + +GameLib.D3.Geometry.Buffer.prototype = Object.create(GameLib.D3.Geometry.prototype); +GameLib.D3.Geometry.Buffer.prototype.constructor = GameLib.D3.Geometry.Buffer; + +GameLib.D3.Geometry.Buffer.prototype.createInstance = function() { + + /** + * First we try it this way - we setup things the old-school way + */ + GameLib.D3.Geometry.prototype.createInstance.call(this); + + /** + * Then we convert to the new BufferGeometry type + */ + this.instance = new THREE.BufferGeometry().fromGeometry(this.instance); + + // /** + // * Setup mesh vertices positions + // * @type {Float32Array} + // */ + // var vertices = new Float32Array( + // + // this.faces.reduce( + // function(result, face){ + // result.push(this.vertices[face.v0index].position.x); + // result.push(this.vertices[face.v0index].position.y); + // result.push(this.vertices[face.v0index].position.z); + // result.push(this.vertices[face.v1index].position.x); + // result.push(this.vertices[face.v1index].position.y); + // result.push(this.vertices[face.v1index].position.z); + // result.push(this.vertices[face.v2index].position.x); + // result.push(this.vertices[face.v2index].position.y); + // result.push(this.vertices[face.v2index].position.z); + // return result; + // }.bind(this), + // [] + // ) + // + // ); + // + // this.instance.addAttribute('position', new THREE.BufferAttribute(vertices, 3)); + // + // /** + // * Setyp mesh vertices colors + // */ + // var colors = new Float32Array( + // this.faces.reduce( + // function(result, face){ + // result.push(1,1,1,1,1,1,1,1,1); + // // result.push(face.color.r); + // // result.push(face.color.g); + // // result.push(face.color.b); + // // result.push(face.color.r); + // // result.push(face.color.g); + // // result.push(face.color.b); + // // result.push(face.color.r); + // // result.push(face.color.g); + // // result.push(face.color.b); + // return result; + // }.bind(this), + // [] + // ) + // ); + // geometry.addAttribute('color', new THREE.BufferAttribute(colors, 3, true)); + // + // /** + // * Setup face UVs + // */ + // var uvs = new Float32Array( + // this.faces.reduce( + // function(result, face) { + // + // face.uvs[0].map( + // function(uv) { + // result.push(uv.x); + // result.push(uv.y); + // } + // ); + // + // return result; + // }, + // [] + // ) + // ); + // geometry.addAttribute('uv', new THREE.BufferAttribute(uvs, 2)); + // + // var normals = new Float32Array( + // this.faces.reduce( + // function(result, face) { + // + // result.push( + // face.normal.x, + // face.normal.y, + // face.normal.z + // ); + // result.push( + // face.normal.x, + // face.normal.y, + // face.normal.z + // ); + // result.push( + // face.normal.x, + // face.normal.y, + // face.normal.z + // ); + // return result; + // }, + // [] + // ) + // ); + // geometry.addAttribute('normal', new THREE.BufferAttribute( normals, 3 )); + // + // geometry.computeVertexNormals(); + // + // + // /** + // * Setup material groups - this means creating a new group for each material index change + // * We know faces are sorted according to material index + // */ + // var groupIndexCounts = this.faces.reduce( + // function(result, face) { + // + // var currentGroup = result.pop(); + // + // if (currentGroup.index !== face.materialIndex) { + // /** + // * We have a new group + // */ + // result.push(currentGroup); + // result.push({ + // index: face.materialIndex, + // count: 3 + // }) + // } else { + // currentGroup.count += 3; + // result.push(currentGroup); + // } + // + // return result; + // }, + // [ + // { + // index : 0, + // count : 0 + // } + // ] + // ); + // + // groupIndexCounts.reduce( + // function(start, group) { + // geometry.addGroup(start, group.count, group.index); + // return start + group.count; + // }, + // 0 + // ); + // + // + // } else { + // + // + // } + + + +}; + +GameLib.D3.Geometry.Buffer.prototype.updateInstance = function(property) { + + if (GameLib.Utils.UndefinedOrNull(this.instance)) { + console.warn('no geometry instance'); + return; + } + + + + GameLib.D3.Geometry.prototype.updateInstance.call(this, property); +}; + +/** + * Converts a GameLib.D3.Geometry to a GameLib.D3.API.Geometry + * @returns {GameLib.D3.API.Geometry} + */ +GameLib.D3.Geometry.Buffer.prototype.toApiObject = function() { + + var apiGeometry = new GameLib.D3.API.Geometry( + this.id, + this.name, + this.geometryType, + this.isBufferGeometry, + GameLib.Utils.IdOrNull(this.parentEntity), + this.boundingBox.toApiObject(), + this.boundingSphere.toApiObject(), + this.colors.map( + function(color) { + return color.toApiObject(); + } + ), + this.faces.map( + function(face) { + return face.toApiObject(); + } + ), + this.lineDistances, + this.morphTargets, + this.morphNormals, + this.skinWeights.map( + function(skinWeight) { + return skinWeight.toApiObject(); + } + ), + this.skinIndices.map( + function(skinIndex) { + return skinIndex.toApiObject(); + } + ), + this.vertices.map( + function (vertex) { + return vertex.toApiObject(); + } + ), + this.verticesNeedsUpdate, + this.elementsNeedUpdate, + this.uvsNeedUpdate, + this.normalsNeedUpdate, + this.colorsNeedUpdate, + this.groupsNeedUpdate, + this.lineDistancesNeedUpdate + ); + + return apiGeometry; + +}; diff --git a/src/game-lib-d3-mesh-0.js b/src/game-lib-d3-mesh-0.js index d37f485..08ca7be 100644 --- a/src/game-lib-d3-mesh-0.js +++ b/src/game-lib-d3-mesh-0.js @@ -187,255 +187,13 @@ GameLib.D3.Mesh.prototype.createInstanceGeometry = function(instanceGeometry) { if (instanceGeometry instanceof THREE.Geometry) { - this.computeBoundingBox(instanceGeometry); - if (this.isBufferMesh) { return new THREE.BufferGeometry().fromGeometry(instanceGeometry); } } - /** - * Setup face indexes - first we sort according to the material index, because later we will create - * groups for each vertice group - */ - this.faces.sort(function(a, b){ - - if (a.materialIndex < b.materialIndex) { - return -1; - } - - if (a.materialIndex > b.materialIndex) { - return 1; - } - - return 0; - }); - - /** - * Setup mesh vertices positions - * @type {Float32Array} - */ - var vertices = new Float32Array( - - this.faces.reduce( - function(result, face){ - result.push(this.vertices[face.v0index].position.x); - result.push(this.vertices[face.v0index].position.y); - result.push(this.vertices[face.v0index].position.z); - result.push(this.vertices[face.v1index].position.x); - result.push(this.vertices[face.v1index].position.y); - result.push(this.vertices[face.v1index].position.z); - result.push(this.vertices[face.v2index].position.x); - result.push(this.vertices[face.v2index].position.y); - result.push(this.vertices[face.v2index].position.z); - return result; - }.bind(this), - [] - ) - - ); - - var geometry = null; - if (this.isBufferMesh) { - - geometry = new THREE.BufferGeometry(); - - geometry.addAttribute('position', new THREE.BufferAttribute(vertices, 3)); - - /** - * Setyp mesh vertices colors - */ - var colors = new Float32Array( - this.faces.reduce( - function(result, face){ - result.push(1,1,1,1,1,1,1,1,1); - // result.push(face.color.r); - // result.push(face.color.g); - // result.push(face.color.b); - // result.push(face.color.r); - // result.push(face.color.g); - // result.push(face.color.b); - // result.push(face.color.r); - // result.push(face.color.g); - // result.push(face.color.b); - return result; - }.bind(this), - [] - ) - ); - geometry.addAttribute('color', new THREE.BufferAttribute(colors, 3, true)); - - /** - * Setup face UVs - */ - var uvs = new Float32Array( - this.faces.reduce( - function(result, face) { - - face.uvs[0].map( - function(uv) { - result.push(uv.x); - result.push(uv.y); - } - ); - - return result; - }, - [] - ) - ); - geometry.addAttribute('uv', new THREE.BufferAttribute(uvs, 2)); - - var normals = new Float32Array( - this.faces.reduce( - function(result, face) { - - result.push( - face.normal.x, - face.normal.y, - face.normal.z - ); - result.push( - face.normal.x, - face.normal.y, - face.normal.z - ); - result.push( - face.normal.x, - face.normal.y, - face.normal.z - ); - return result; - }, - [] - ) - ); - geometry.addAttribute('normal', new THREE.BufferAttribute( normals, 3 )); - - geometry.computeVertexNormals(); - - - /** - * Setup material groups - this means creating a new group for each material index change - * We know faces are sorted according to material index - */ - var groupIndexCounts = this.faces.reduce( - function(result, face) { - - var currentGroup = result.pop(); - - if (currentGroup.index !== face.materialIndex) { - /** - * We have a new group - */ - result.push(currentGroup); - result.push({ - index: face.materialIndex, - count: 3 - }) - } else { - currentGroup.count += 3; - result.push(currentGroup); - } - - return result; - }, - [ - { - index : 0, - count : 0 - } - ] - ); - - groupIndexCounts.reduce( - function(start, group) { - geometry.addGroup(start, group.count, group.index); - return start + group.count; - }, - 0 - ); - - - } else { - - geometry = new THREE.Geometry(); - - var standardUvs = []; - - /** - * Face data - * @type {Array} - */ - geometry.faces = this.faces.map( - function (face) { - - if (face.uvs[0].length > 0) { - standardUvs.push( - face.uvs[0].map( - function(uv) { - return uv.instance; - } - ) - ); - } - - if (!face.instance) { - face.createInstance(this); - } - - return face.instance; - }.bind(this) - ); - - /** - * Vertex data - * @type {Array} - */ - geometry.vertices = this.vertices.map( - function (vertex) { - return new THREE.Vector3( - vertex.position.x, - vertex.position.y, - vertex.position.z - ) - } - ); - geometry.verticesNeedUpdate = true; - - - /** - * UV data - but only if it exists - */ - if (standardUvs.length > 0) { - geometry.faceVertexUvs = [standardUvs]; - } - - /** - * Re-compute normals - we don't do this for buffer geometry because it assigns to every vertex normal the face - * normal - essentially disabling 'smooth shading' - */ - geometry.computeFaceNormals(); - // geometry.computeBoundingBox(); - geometry.computeVertexNormals(); - - // geometry.verticesNeedUpdate = true; - // geometry.elementsNeedUpdate = true; - // geometry.morphTargetsNeedUpdate = true; - // geometry.uvsNeedUpdate = true; - // geometry.normalsNeedUpdate = true; - // geometry.colorsNeedUpdate = true; - // geometry.tangentsNeedUpdate = true; - } - - /** - * Apply skin indices - */ - // this.applyBones(geometry); - - this.computeBoundingBox(geometry); return geometry; }; @@ -1050,26 +808,6 @@ GameLib.D3.Mesh.prototype.getBoundingBox = function() { */ GameLib.D3.Mesh.prototype.toApiObject = function() { - var apiSkeleton = null; - if (this.skeleton) { - apiSkeleton = this.skeleton.id; - } - - var apiMaterials = null; - if (this.materials) { - apiMaterials = this.materials.map( - function(material) { - return material.id; - } - ) - } - - var apiFaces = this.faces.map( - function(face){ - return face.toApiObject(); - } - ); - var apiMesh = new GameLib.D3.API.Mesh( this.id, this.name, @@ -1080,11 +818,19 @@ GameLib.D3.Mesh.prototype.toApiObject = function() { return vertex.toApiObject(); } ), - apiFaces, - apiMaterials, + this.faces.map( + function(face){ + return face.toApiObject(); + } + ), + this.materials.map( + function(material) { + return GameLib.Utils.IdOrNull(material); + } + ), GameLib.Utils.IdOrNull(this.parentMesh), GameLib.Utils.IdOrNull(this.parentScene), - apiSkeleton, + GameLib.Utils.IdOrNull(this.skeleton), this.skinIndices, this.skinWeights, this.position.toApiObject(), @@ -1496,20 +1242,3 @@ GameLib.D3.Mesh.prototype.removeHelper = function() { this.helper = null; }; - -GameLib.D3.Mesh.prototype.computeBoundingBox = function(geometry) { - - if (GameLib.Utils.UndefinedOrNull(geometry)) { - - if (this.instance && this.instance.geometry) { - geometry = this.instance.geometry; - } else { - console.log('no instance geometry to compute bounding box'); - } - } - - geometry.computeBoundingBox(); - this.dimensions.x = geometry.boundingBox.getSize().x; - this.dimensions.y = geometry.boundingBox.getSize().y; - this.dimensions.z = geometry.boundingBox.getSize().z; -}; diff --git a/src/game-lib-d3-vertex.js b/src/game-lib-d3-vertex.js index 195a5b6..d4b3be5 100644 --- a/src/game-lib-d3-vertex.js +++ b/src/game-lib-d3-vertex.js @@ -1,21 +1,15 @@ /** - * Runtime Vertex - * @constructor + * GameLib.D3.Vertex * @param implementation * @param apiVertex + * @constructor */ GameLib.D3.Vertex = function Vertex( implementation, apiVertex ) { this.implementation = implementation; - if (implementation instanceof GameLib.GraphicsRuntime) { - this.implementation.isNotThreeThrow(); - } else if (implementation instanceof GameLib.PhysicsRuntime) { - this.implementation.isNotCannonThrow(); - } else { - throw new Error('Unhandled implementation : ' + implementation); - } + this.implementation.isNotThreeThrow(); if (GameLib.Utils.UndefinedOrNull(apiVertex)) { apiVertex = {}; @@ -30,19 +24,18 @@ GameLib.D3.Vertex = function Vertex( this.position = new GameLib.Vector3( this.implementation, this.position, - null + this + ); + + this.boneWeights = this.boneWeights.map( + function(boneWeight) { + return new GameLib.Vector4( + this.graphics, + boneWeight + ) + } ); - if (implementation instanceof GameLib.GraphicsRuntime) { - this.boneWeights = this.boneWeights.map( - function(apiBoneWeight) { - return new GameLib.D3.BoneWeight( - this.implementation, - apiBoneWeight - ) - }.bind(this) - ) - } }; GameLib.D3.Vertex.prototype = Object.create(GameLib.Component.prototype); @@ -56,28 +49,11 @@ GameLib.D3.Vertex.prototype.toApiObject = function() { return new GameLib.D3.API.Vertex( this.position.toApiObject(), - this.boneWeights.map(function(boneWeight){ - return boneWeight.toApiObject(); - }) + this.boneWeights.map( + function(boneWeight){ + return boneWeight.toApiObject(); + } + ) ); }; - -/** - * Returns a GameLib.D3.Vertex from a vertex Object - * @param implementation (graphics or physics object) - * @param objectVertex Object - * @returns {GameLib.D3.Vertex} - * @constructor - */ -GameLib.D3.Vertex.FromObject = function( - implementation, - objectVertex -) { - var apiVertex = GameLib.D3.API.Vertex.FromObject(objectVertex); - - return new GameLib.D3.Vertex( - implementation, - apiVertex - ); -}; diff --git a/src/game-lib-draw-range.js b/src/game-lib-draw-range.js new file mode 100644 index 0000000..d007857 --- /dev/null +++ b/src/game-lib-draw-range.js @@ -0,0 +1,82 @@ +/** + * GameLib.DrawRange + * @param implementation + * @param apiDrawRange + * @param parentGeometry + * @constructor + */ +GameLib.DrawRange = function ( + implementation, + apiDrawRange, + parentGeometry +) { + + this.implementation = implementation; + this.implementation.isNotThreeThrow(); + + if (GameLib.Utils.UndefinedOrNull(apiDrawRange)) { + apiDrawRange = {}; + } + + if (GameLib.Utils.UndefinedOrNull(parentGeometry)) { + parentGeometry = null; + } + this.parentGeometry = parentGeometry; + + GameLib.API.DrawRange.call( + this, + apiDrawRange.id, + apiDrawRange.name, + apiDrawRange.parentEntity, + apiDrawRange.start, + apiDrawRange.count + ); + + this.createInstance(); +}; + +GameLib.DrawRange.prototype = Object.create(GameLib.Component.prototype); +GameLib.DrawRange.prototype.constructor = GameLib.DrawRange; + +/** + * Creates an instance GameLib.DrawRange + * @returns {*} + */ +GameLib.DrawRange.prototype.createInstance = function() { + + this.instance = { + start : this.start, + count : this.count + } + +}; + +/** + * Updates GameLib.DrawRange instance + * @param property + */ +GameLib.DrawRange.prototype.updateInstance = function(property) { + + console.warn('update the geometry instead'); + + if (property === 'start') { + } + + if (property === 'count') { + } + +}; + +/** + * GameLib.DrawRange to GameLib.API.DrawRange + * @returns {GameLib.API.DrawRange} + */ +GameLib.DrawRange.prototype.toApiObject = function() { + return new GameLib.API.DrawRange( + this.id, + this.name, + GameLib.Utils.IdOrNull(this.parentEntity), + this.start, + this.count + ); +}; diff --git a/src/game-lib-group.js b/src/game-lib-group.js new file mode 100644 index 0000000..eecbed5 --- /dev/null +++ b/src/game-lib-group.js @@ -0,0 +1,88 @@ +/** + * GameLib.Group + * @param implementation + * @param apiGroup + * @param parentGeometry + * @constructor + */ +GameLib.Group = function ( + implementation, + apiGroup, + parentGeometry +) { + + this.implementation = implementation; + this.implementation.isNotThreeThrow(); + + if (GameLib.Utils.UndefinedOrNull(parentGeometry)) { + parentGeometry = null; + } + this.parentGeometry = parentGeometry; + + if (GameLib.Utils.UndefinedOrNull(apiGroup)) { + apiGroup = {}; + } + + GameLib.API.Group.call( + this, + apiGroup.id, + apiGroup.name, + apiGroup.parentEntity, + apiGroup.start, + apiGroup.count, + apiGroup.materialIndex + ); + + this.createInstance(); +}; + +GameLib.Group.prototype = Object.create(GameLib.Component.prototype); +GameLib.Group.prototype.constructor = GameLib.Group; + +/** + * Creates an instance GameLib.Group + * @returns {*} + */ +GameLib.Group.prototype.createInstance = function() { + + this.instance = { + start : this.start, + count : this.count, + materialIndex : this.materialIndex + } + +}; + +/** + * Updates GameLib.Group instance + * @param property + */ +GameLib.Group.prototype.updateInstance = function(property) { + + console.warn('update the geometry instead'); + + if (property === 'start') { + } + + if (property === 'count') { + } + + if (property === 'materialIndex') { + } + +}; + +/** + * GameLib.Group to GameLib.API.Group + * @returns {GameLib.API.Group} + */ +GameLib.Group.prototype.toApiObject = function() { + return new GameLib.API.Group( + this.id, + this.name, + GameLib.Utils.IdOrNull(this.parentEntity), + this.start, + this.count, + this.materialIndex + ); +};