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

100 lines
2.0 KiB
JavaScript
Raw Normal View History

2016-10-14 12:32:53 +02:00
/**
2016-12-22 17:22:19 +01:00
* Runtime Vertex
2016-10-14 12:32:53 +02:00
* @constructor
2016-12-22 17:22:19 +01:00
* @param graphics
* @param apiVertex
2016-10-14 12:32:53 +02:00
*/
2016-11-21 16:08:39 +01:00
GameLib.D3.Vertex = function Vertex(
2016-12-22 17:22:19 +01:00
graphics,
apiVertex
2016-10-14 12:32:53 +02:00
) {
2016-12-22 17:22:19 +01:00
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 = new GameLib.D3.API.Vertex(
new GameLib.API.Vector3(
objectVertex.position.x,
objectVertex.position.y,
objectVertex.position.z
),
objectVertex.boneWeights
);
return new GameLib.D3.Vertex(
graphics,
apiVertex
);
};