make faces and vertexes implementation independent
parent
69a0556424
commit
c5bb684272
|
@ -11,7 +11,6 @@
|
|||
* @param vertexColors
|
||||
* @param vertexNormals
|
||||
* @param normal
|
||||
* @param parentEntity GameLib.Entity
|
||||
* @constructor
|
||||
*/
|
||||
GameLib.D3.API.Face = function(
|
||||
|
@ -84,6 +83,10 @@ GameLib.D3.API.Face = function(
|
|||
this.normal = normal;
|
||||
};
|
||||
|
||||
/**
|
||||
* We don't inherit from component - it makes the entitymanager too heavy - all faces end up in the register etc..
|
||||
*/
|
||||
|
||||
// GameLib.D3.API.Face.prototype = Object.create(GameLib.Component.prototype);
|
||||
// GameLib.D3.API.Face.prototype.constructor = GameLib.D3.API.Face;
|
||||
|
||||
|
|
|
@ -1,15 +1,22 @@
|
|||
/**
|
||||
* Face
|
||||
* @constructor
|
||||
* @param graphics
|
||||
* @param implementation
|
||||
* @param apiFace
|
||||
*/
|
||||
GameLib.D3.Face = function Face(
|
||||
graphics,
|
||||
implementation,
|
||||
apiFace
|
||||
) {
|
||||
this.graphics = graphics;
|
||||
this.graphics.isNotThreeThrow();
|
||||
|
||||
this.implementation = implementation;
|
||||
if (implementation instanceof GameLib.D3.Graphics) {
|
||||
this.implementation.isNotThreeThrow();
|
||||
} else if (implementation instanceof GameLib.D3.Physics) {
|
||||
this.implementation.isNotCannonThrow();
|
||||
} else {
|
||||
throw new Error('Unhandled implementation : ' + implementation);
|
||||
}
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(apiFace)) {
|
||||
apiFace = {};
|
||||
|
@ -34,27 +41,33 @@ GameLib.D3.Face = function Face(
|
|||
apiFace.normal
|
||||
);
|
||||
|
||||
this.color = new GameLib.Color(
|
||||
this.graphics,
|
||||
this.color,
|
||||
this
|
||||
);
|
||||
if (this.implementation instanceof GameLib.D3.Graphics) {
|
||||
/**
|
||||
* physics faces have no color... a little sad right?
|
||||
*/
|
||||
this.color = new GameLib.Color(
|
||||
this.implementation,
|
||||
this.color,
|
||||
this
|
||||
);
|
||||
|
||||
this.vertexColors = this.vertexColors.map(function(vertexColor){
|
||||
if (vertexColor instanceof GameLib.Color) {
|
||||
return vertexColor;
|
||||
}
|
||||
this.vertexColors = this.vertexColors.map(function(vertexColor){
|
||||
if (vertexColor instanceof GameLib.Color) {
|
||||
return vertexColor;
|
||||
}
|
||||
|
||||
if (vertexColor instanceof GameLib.API.Color) {
|
||||
return new GameLib.Color(
|
||||
this.graphics,
|
||||
vertexColor,
|
||||
this
|
||||
)
|
||||
}
|
||||
if (vertexColor instanceof GameLib.API.Color) {
|
||||
return new GameLib.Color(
|
||||
this.implementation,
|
||||
vertexColor,
|
||||
this
|
||||
)
|
||||
}
|
||||
|
||||
console.warn('unknown vertex color type', vertexColor);
|
||||
}.bind(this));
|
||||
console.warn('unknown vertex color type', vertexColor);
|
||||
}.bind(this));
|
||||
|
||||
}
|
||||
|
||||
this.vertexNormals = this.vertexNormals.map(function(vertexNormal){
|
||||
if (vertexNormal instanceof GameLib.Vector3) {
|
||||
|
@ -73,7 +86,7 @@ GameLib.D3.Face = function Face(
|
|||
}.bind(this));
|
||||
|
||||
this.normal = new GameLib.Vector3(
|
||||
this.graphics,
|
||||
this.implementation,
|
||||
this.normal,
|
||||
this
|
||||
);
|
||||
|
@ -111,9 +124,15 @@ GameLib.D3.Face.prototype.toApiObject = function() {
|
|||
);
|
||||
};
|
||||
|
||||
GameLib.D3.Face.FromObject = function(graphics, objectFace) {
|
||||
/**
|
||||
* @param implementation
|
||||
* @param objectFace
|
||||
* @returns {GameLib.D3.Face}
|
||||
* @constructor
|
||||
*/
|
||||
GameLib.D3.Face.FromObject = function(implementation, objectFace) {
|
||||
return new GameLib.D3.Face(
|
||||
graphics,
|
||||
implementation,
|
||||
GameLib.D3.API.Face.FromObject(objectFace)
|
||||
);
|
||||
};
|
||||
|
|
|
@ -1,15 +1,21 @@
|
|||
/**
|
||||
* Runtime Vertex
|
||||
* @constructor
|
||||
* @param graphics
|
||||
* @param implementation
|
||||
* @param apiVertex
|
||||
*/
|
||||
GameLib.D3.Vertex = function Vertex(
|
||||
graphics,
|
||||
implementation,
|
||||
apiVertex
|
||||
) {
|
||||
this.graphics = graphics;
|
||||
this.graphics.isNotThreeThrow();
|
||||
this.implementation = implementation;
|
||||
if (implementation instanceof GameLib.D3.Graphics) {
|
||||
this.implementation.isNotThreeThrow();
|
||||
} else if (implementation instanceof GameLib.D3.Physics) {
|
||||
this.implementation.isNotCannonThrow();
|
||||
} else {
|
||||
throw new Error('Unhandled implementation : ' + implementation);
|
||||
}
|
||||
|
||||
if (GameLib.Utils.UndefinedOrNull(apiVertex)) {
|
||||
apiVertex = {};
|
||||
|
@ -26,19 +32,21 @@ GameLib.D3.Vertex = function Vertex(
|
|||
);
|
||||
|
||||
this.position = new GameLib.Vector3(
|
||||
this.graphics,
|
||||
this.implementation,
|
||||
this.position,
|
||||
null
|
||||
);
|
||||
|
||||
this.boneWeights = this.boneWeights.map(
|
||||
function(apiBoneWeight) {
|
||||
return new GameLib.D3.BoneWeight(
|
||||
this.graphics,
|
||||
apiBoneWeight
|
||||
)
|
||||
}.bind(this)
|
||||
)
|
||||
if (implementation instanceof GameLib.D3.Graphics) {
|
||||
this.boneWeights = this.boneWeights.map(
|
||||
function(apiBoneWeight) {
|
||||
return new GameLib.D3.BoneWeight(
|
||||
this.implementation,
|
||||
apiBoneWeight
|
||||
)
|
||||
}.bind(this)
|
||||
)
|
||||
}
|
||||
};
|
||||
|
||||
GameLib.D3.Vertex.prototype = Object.create(GameLib.D3.API.Vertex.prototype);
|
||||
|
@ -61,19 +69,19 @@ GameLib.D3.Vertex.prototype.toApiObject = function() {
|
|||
|
||||
/**
|
||||
* Returns a GameLib.D3.Vertex from a vertex Object
|
||||
* @param graphics GameLib.D3.Graphics
|
||||
* @param implementation (graphics or physics object)
|
||||
* @param objectVertex Object
|
||||
* @returns {GameLib.D3.Vertex}
|
||||
* @constructor
|
||||
*/
|
||||
GameLib.D3.Vertex.FromObject = function(
|
||||
graphics,
|
||||
implementation,
|
||||
objectVertex
|
||||
) {
|
||||
var apiVertex = GameLib.D3.API.Vertex.FromObject(objectVertex);
|
||||
|
||||
return new GameLib.D3.Vertex(
|
||||
graphics,
|
||||
implementation,
|
||||
apiVertex
|
||||
);
|
||||
};
|
||||
|
|
Loading…
Reference in New Issue