make faces and vertexes implementation independent
parent
69a0556424
commit
c5bb684272
|
@ -11,7 +11,6 @@
|
||||||
* @param vertexColors
|
* @param vertexColors
|
||||||
* @param vertexNormals
|
* @param vertexNormals
|
||||||
* @param normal
|
* @param normal
|
||||||
* @param parentEntity GameLib.Entity
|
|
||||||
* @constructor
|
* @constructor
|
||||||
*/
|
*/
|
||||||
GameLib.D3.API.Face = function(
|
GameLib.D3.API.Face = function(
|
||||||
|
@ -84,6 +83,10 @@ GameLib.D3.API.Face = function(
|
||||||
this.normal = normal;
|
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 = Object.create(GameLib.Component.prototype);
|
||||||
// GameLib.D3.API.Face.prototype.constructor = GameLib.D3.API.Face;
|
// GameLib.D3.API.Face.prototype.constructor = GameLib.D3.API.Face;
|
||||||
|
|
||||||
|
|
|
@ -1,15 +1,22 @@
|
||||||
/**
|
/**
|
||||||
* Face
|
* Face
|
||||||
* @constructor
|
* @constructor
|
||||||
* @param graphics
|
* @param implementation
|
||||||
* @param apiFace
|
* @param apiFace
|
||||||
*/
|
*/
|
||||||
GameLib.D3.Face = function Face(
|
GameLib.D3.Face = function Face(
|
||||||
graphics,
|
implementation,
|
||||||
apiFace
|
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)) {
|
if (GameLib.Utils.UndefinedOrNull(apiFace)) {
|
||||||
apiFace = {};
|
apiFace = {};
|
||||||
|
@ -34,8 +41,12 @@ GameLib.D3.Face = function Face(
|
||||||
apiFace.normal
|
apiFace.normal
|
||||||
);
|
);
|
||||||
|
|
||||||
|
if (this.implementation instanceof GameLib.D3.Graphics) {
|
||||||
|
/**
|
||||||
|
* physics faces have no color... a little sad right?
|
||||||
|
*/
|
||||||
this.color = new GameLib.Color(
|
this.color = new GameLib.Color(
|
||||||
this.graphics,
|
this.implementation,
|
||||||
this.color,
|
this.color,
|
||||||
this
|
this
|
||||||
);
|
);
|
||||||
|
@ -47,7 +58,7 @@ GameLib.D3.Face = function Face(
|
||||||
|
|
||||||
if (vertexColor instanceof GameLib.API.Color) {
|
if (vertexColor instanceof GameLib.API.Color) {
|
||||||
return new GameLib.Color(
|
return new GameLib.Color(
|
||||||
this.graphics,
|
this.implementation,
|
||||||
vertexColor,
|
vertexColor,
|
||||||
this
|
this
|
||||||
)
|
)
|
||||||
|
@ -56,6 +67,8 @@ GameLib.D3.Face = function Face(
|
||||||
console.warn('unknown vertex color type', vertexColor);
|
console.warn('unknown vertex color type', vertexColor);
|
||||||
}.bind(this));
|
}.bind(this));
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
this.vertexNormals = this.vertexNormals.map(function(vertexNormal){
|
this.vertexNormals = this.vertexNormals.map(function(vertexNormal){
|
||||||
if (vertexNormal instanceof GameLib.Vector3) {
|
if (vertexNormal instanceof GameLib.Vector3) {
|
||||||
return vertexNormal;
|
return vertexNormal;
|
||||||
|
@ -73,7 +86,7 @@ GameLib.D3.Face = function Face(
|
||||||
}.bind(this));
|
}.bind(this));
|
||||||
|
|
||||||
this.normal = new GameLib.Vector3(
|
this.normal = new GameLib.Vector3(
|
||||||
this.graphics,
|
this.implementation,
|
||||||
this.normal,
|
this.normal,
|
||||||
this
|
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(
|
return new GameLib.D3.Face(
|
||||||
graphics,
|
implementation,
|
||||||
GameLib.D3.API.Face.FromObject(objectFace)
|
GameLib.D3.API.Face.FromObject(objectFace)
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
|
@ -1,15 +1,21 @@
|
||||||
/**
|
/**
|
||||||
* Runtime Vertex
|
* Runtime Vertex
|
||||||
* @constructor
|
* @constructor
|
||||||
* @param graphics
|
* @param implementation
|
||||||
* @param apiVertex
|
* @param apiVertex
|
||||||
*/
|
*/
|
||||||
GameLib.D3.Vertex = function Vertex(
|
GameLib.D3.Vertex = function Vertex(
|
||||||
graphics,
|
implementation,
|
||||||
apiVertex
|
apiVertex
|
||||||
) {
|
) {
|
||||||
this.graphics = graphics;
|
this.implementation = implementation;
|
||||||
this.graphics.isNotThreeThrow();
|
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)) {
|
if (GameLib.Utils.UndefinedOrNull(apiVertex)) {
|
||||||
apiVertex = {};
|
apiVertex = {};
|
||||||
|
@ -26,19 +32,21 @@ GameLib.D3.Vertex = function Vertex(
|
||||||
);
|
);
|
||||||
|
|
||||||
this.position = new GameLib.Vector3(
|
this.position = new GameLib.Vector3(
|
||||||
this.graphics,
|
this.implementation,
|
||||||
this.position,
|
this.position,
|
||||||
null
|
null
|
||||||
);
|
);
|
||||||
|
|
||||||
|
if (implementation instanceof GameLib.D3.Graphics) {
|
||||||
this.boneWeights = this.boneWeights.map(
|
this.boneWeights = this.boneWeights.map(
|
||||||
function(apiBoneWeight) {
|
function(apiBoneWeight) {
|
||||||
return new GameLib.D3.BoneWeight(
|
return new GameLib.D3.BoneWeight(
|
||||||
this.graphics,
|
this.implementation,
|
||||||
apiBoneWeight
|
apiBoneWeight
|
||||||
)
|
)
|
||||||
}.bind(this)
|
}.bind(this)
|
||||||
)
|
)
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
GameLib.D3.Vertex.prototype = Object.create(GameLib.D3.API.Vertex.prototype);
|
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
|
* Returns a GameLib.D3.Vertex from a vertex Object
|
||||||
* @param graphics GameLib.D3.Graphics
|
* @param implementation (graphics or physics object)
|
||||||
* @param objectVertex Object
|
* @param objectVertex Object
|
||||||
* @returns {GameLib.D3.Vertex}
|
* @returns {GameLib.D3.Vertex}
|
||||||
* @constructor
|
* @constructor
|
||||||
*/
|
*/
|
||||||
GameLib.D3.Vertex.FromObject = function(
|
GameLib.D3.Vertex.FromObject = function(
|
||||||
graphics,
|
implementation,
|
||||||
objectVertex
|
objectVertex
|
||||||
) {
|
) {
|
||||||
var apiVertex = GameLib.D3.API.Vertex.FromObject(objectVertex);
|
var apiVertex = GameLib.D3.API.Vertex.FromObject(objectVertex);
|
||||||
|
|
||||||
return new GameLib.D3.Vertex(
|
return new GameLib.D3.Vertex(
|
||||||
graphics,
|
implementation,
|
||||||
apiVertex
|
apiVertex
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in New Issue