/** * Runtime Vertex * @constructor * @param graphics * @param apiVertex */ GameLib.D3.Vertex = function Vertex( graphics, apiVertex ) { this.graphics = graphics; this.graphics.isNotThreeThrow(); GameLib.D3.API.Vertex.call( this, apiVertex.position, apiVertex.boneWeights ); this.position = new GameLib.Vector3( this.graphics, null, this.position ); //TODO: GameLib.D3.BoneWeight implementation this.instance = this.createInstance(); }; GameLib.D3.Vertex.prototype = Object.create(GameLib.D3.API.Vertex.prototype); GameLib.D3.Vertex.prototype.constructor = GameLib.D3.Vertex; /** * Creates an instance vertex * @param update boolean */ GameLib.D3.Vertex.prototype.createInstance = function(update) { var instance = null; if (update) { instance = this.instance; } else { instance = new THREE.Vector3(); } instance.x = this.position.x; instance.y = this.position.y; instance.z = this.position.z; return instance; }; /** * Updates the instance */ GameLib.D3.Vertex.prototype.updateInstance = function() { this.instance = this.createInstance(true); }; /** * Converts a GameLib.D3.Vertex to GameLib.D3.API.Vertex * @returns {GameLib.D3.API.Vertex} */ GameLib.D3.Vertex.prototype.toApiVertex = function() { return new GameLib.D3.API.Vertex( this.position.toApiVector(), this.boneWeights ); }; /** * Returns a GameLib.D3.Vertex from a vertex Object * @param graphics GameLib.D3.Graphics * @param objectVertex Object * @returns {GameLib.D3.Vertex} * @constructor */ GameLib.D3.Vertex.FromObjectVertex = function( graphics, objectVertex ) { var apiVertex = GameLib.D3.API.Vertex.FromObjectVertex(objectVertex); return new GameLib.D3.Vertex( graphics, apiVertex ); };