diff --git a/src/game-lib-d3-camera.js b/src/game-lib-d3-camera.js index c87ce64..966a6f4 100644 --- a/src/game-lib-d3-camera.js +++ b/src/game-lib-d3-camera.js @@ -195,6 +195,10 @@ GameLib.D3.Camera.prototype.updateInstance = function() { this.instance.quaternion.z = this.quaternion.z; this.instance.quaternion.w = this.quaternion.w; + this.lookAt.instance.x = this.lookAt.x; + this.lookAt.instance.y = this.lookAt.y; + this.lookAt.instance.z = this.lookAt.z; + this.instance.lookAt(this.lookAt.instance); this.instance.updateProjectionMatrix(); diff --git a/src/game-lib-d3-mesh-line.js b/src/game-lib-d3-mesh-line.js new file mode 100644 index 0000000..5003629 --- /dev/null +++ b/src/game-lib-d3-mesh-line.js @@ -0,0 +1,137 @@ +/** + * Mesh Superset - The apiMesh properties get moved into the Mesh object itself, and then the instance is created + * @param graphics GameLib.D3.Graphics + * @param apiMesh GameLib.D3.API.Mesh + * @param width + * @param height + * @param depth + * @constructor + */ +GameLib.D3.Mesh.Box = function ( + graphics, + apiMesh, + width, + height, + depth +) { + this.graphics = graphics; + this.graphics.isNotThreeThrow(); + + if (GameLib.Utils.UndefinedOrNull(apiMesh)) { + apiMesh = {}; + } + + if (apiMesh instanceof GameLib.D3.Mesh.Box) { + return apiMesh; + } + + apiMesh.meshType = GameLib.D3.Mesh.MESH_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; + + GameLib.D3.Mesh.call( + this, + this.graphics, + apiMesh + ); +}; + +GameLib.D3.Mesh.Box.prototype = Object.create(GameLib.D3.Mesh.prototype); +GameLib.D3.Mesh.Box.prototype.constructor = GameLib.D3.Mesh.Box; + +GameLib.D3.Mesh.Box.prototype.createInstance = function() { + + var geometry = null; + + if (this.vertices.length === 0) { + geometry = new THREE.BoxGeometry( + this.width, + this.height, + this.depth + ); + + this.updateVerticesFromGeometryInstance(geometry); + } + + GameLib.D3.Mesh.prototype.createInstance.call(this); + + this.instance.userData.width = this.width; + this.instance.userData.height = this.height; + this.instance.userData.depth = this.depth; +}; + +GameLib.D3.Mesh.Box.prototype.updateInstance = function() { + + if ( + this.instance.userData.width !== this.width || + this.instance.userData.height !== this.height || + this.instance.userData.depth !== this.depth + ) { + this.instance.userData.width = this.width; + this.instance.userData.height = this.height; + this.instance.userData.depth = this.depth; + + var geometry = new THREE.BoxGeometry( + this.width, + this.height, + this.depth + ); + + this.updateVerticesFromGeometryInstance(geometry); + + geometry = this.createInstanceGeometry(); + + this.instance.geometry = geometry; + } + + GameLib.D3.Mesh.prototype.updateInstance.call(this); + +}; + +/** + * Converts a GameLib.D3.Mesh to a GameLib.D3.API.Mesh + * @returns {GameLib.D3.API.Mesh} + */ +GameLib.D3.Mesh.Box.prototype.toApiObject = function() { + + var apiMesh = GameLib.D3.Mesh.prototype.toApiObject.call(this); + + apiMesh.width = this.width; + apiMesh.height = this.height; + apiMesh.depth = this.depth; + + return apiMesh; +}; + +/** + * Converts a standard object mesh to a GameLib.D3.Mesh + * @param graphics GameLib.D3.Graphics + * @param objectMesh {Object} + * @constructor + */ +GameLib.D3.Mesh.Box.FromObject = function(graphics, objectMesh) { + + var apiMesh = GameLib.D3.API.Mesh.FromObject(objectMesh); + + return new GameLib.D3.Mesh.Box( + graphics, + apiMesh, + objectMesh.width, + objectMesh.height, + objectMesh.depth + ); + +};