r3-legacy/src/game-lib-d3-vertex.js

80 lines
1.7 KiB
JavaScript

/**
* Runtime Vertex
* @constructor
* @param graphics
* @param apiVertex
*/
GameLib.D3.Vertex = function Vertex(
graphics,
apiVertex
) {
this.graphics = graphics;
this.graphics.isNotThreeThrow();
if (GameLib.Utils.UndefinedOrNull(apiVertex)) {
apiVertex = {};
}
if (apiVertex instanceof GameLib.D3.Vertex) {
return apiVertex;
}
GameLib.D3.API.Vertex.call(
this,
apiVertex.position,
apiVertex.boneWeights
);
this.position = new GameLib.Vector3(
this.graphics,
this.position,
null
);
this.boneWeights = this.boneWeights.map(
function(apiBoneWeight) {
return new GameLib.D3.BoneWeight(
this.graphics,
apiBoneWeight
)
}.bind(this)
)
};
GameLib.D3.Vertex.prototype = Object.create(GameLib.D3.API.Vertex.prototype);
GameLib.D3.Vertex.prototype.constructor = GameLib.D3.Vertex;
/**
* Converts a GameLib.D3.Vertex to GameLib.D3.API.Vertex
* @returns {GameLib.D3.API.Vertex}
*/
GameLib.D3.Vertex.prototype.toApiObject = function() {
return new GameLib.D3.API.Vertex(
this.position.toApiObject(),
this.boneWeights.map(function(boneWeight){
return boneWeight.toApiObject();
})
);
};
/**
* 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.FromObject = function(
graphics,
objectVertex
) {
var apiVertex = GameLib.D3.API.Vertex.FromObject(objectVertex);
return new GameLib.D3.Vertex(
graphics,
apiVertex
);
};