/** * Mesh Superset - The apiMesh properties get moved into the Mesh object itself, and then the instance is created * @param graphics GameLib.GraphicsRuntime * @param apiMesh GameLib.D3.API.Mesh * @param lineWidth * @constructor */ GameLib.D3.Mesh.Line = function ( graphics, apiMesh, lineWidth ) { this.graphics = graphics; this.graphics.isNotThreeThrow(); if (GameLib.Utils.UndefinedOrNull(apiMesh)) { apiMesh = { meshType: GameLib.D3.API.Mesh.MESH_TYPE_LINE }; } if (apiMesh instanceof GameLib.D3.Mesh.Line) { return apiMesh; } if (GameLib.Utils.UndefinedOrNull(lineWidth)) { lineWidth = 1; } this.lineWidth = lineWidth; GameLib.D3.Mesh.call( this, this.graphics, apiMesh ); }; GameLib.D3.Mesh.Line.prototype = Object.create(GameLib.D3.Mesh.prototype); GameLib.D3.Mesh.Line.prototype.constructor = GameLib.D3.Mesh.Line; GameLib.D3.Mesh.Line.prototype.createInstance = function() { var geometry = new THREE.Geometry(); geometry.vertices.push( this.vertices.map( function(vertex){ return vertex.instance; } ) ); this.instance = new THREE.Line(geometry); GameLib.D3.Mesh.prototype.createInstance.call(this); this.instance.userData.lineWidth = this.lineWidth; }; GameLib.D3.Mesh.Line.prototype.updateInstance = function(property) { this.instance.linewidth = this.lineWidth; GameLib.D3.Mesh.prototype.updateInstance.call(this, property); }; /** * Converts a GameLib.D3.Mesh to a GameLib.D3.API.Mesh * @returns {GameLib.D3.API.Mesh} */ GameLib.D3.Mesh.Line.prototype.toApiObject = function() { var apiMesh = GameLib.D3.Mesh.prototype.toApiObject.call(this); apiMesh.lineWidth = this.lineWidth; return apiMesh; }; /** * Converts a standard object mesh to a GameLib.D3.Mesh * @param graphics GameLib.GraphicsRuntime * @param objectMesh {Object} * @constructor */ GameLib.D3.Mesh.Line.FromObject = function(graphics, objectMesh) { var apiMesh = GameLib.D3.API.Mesh.FromObject(objectMesh); return new GameLib.D3.Mesh.Line( graphics, apiMesh, objectMesh.lineWidth ); };