starting to recurse through properties

beta.r3js.org
Theunis J. Botha 2016-11-21 16:08:39 +01:00
parent be64682142
commit 481cd05374
23 changed files with 272 additions and 173 deletions

View File

@ -4,7 +4,7 @@
* @param weight float * @param weight float
* @constructor * @constructor
*/ */
GameLib.D3.BoneWeight = function( GameLib.D3.BoneWeight = function BoneWeight(
boneIndex, boneIndex,
weight weight
) { ) {

View File

@ -12,7 +12,7 @@
* @param up * @param up
* @constructor * @constructor
*/ */
GameLib.D3.Bone = function( GameLib.D3.Bone = function Bone(
id, id,
boneId, boneId,
name, name,

View File

@ -6,7 +6,7 @@
* @param engine GameLib.D3.Engine * @param engine GameLib.D3.Engine
* @constructor * @constructor
*/ */
GameLib.D3.Broadphase = function( GameLib.D3.Broadphase = function Broadphase(
id, id,
name, name,
broadphaseType, broadphaseType,

View File

@ -4,7 +4,7 @@
* @param apiCamera GameLib.D3.Camera.API * @param apiCamera GameLib.D3.Camera.API
* @constructor * @constructor
*/ */
GameLib.D3.Camera = function( GameLib.D3.Camera = function Camera(
graphics, graphics,
apiCamera apiCamera
) { ) {

View File

@ -6,7 +6,7 @@
* @param a * @param a
* @constructor * @constructor
*/ */
GameLib.D3.Color = function(r, g, b, a) { GameLib.D3.Color = function Color(r, g, b, a) {
this.r = r; this.r = r;
this.g = g; this.g = g;
this.b = b; this.b = b;

View File

@ -4,7 +4,7 @@
* @param instance {CANNON | Ammo | Goblin} * @param instance {CANNON | Ammo | Goblin}
* @constructor * @constructor
*/ */
GameLib.D3.Engine = function( GameLib.D3.Engine = function Engine(
engineType, engineType,
instance instance
) { ) {

View File

@ -4,7 +4,7 @@
* @param instance {THREE} * @param instance {THREE}
* @constructor * @constructor
*/ */
GameLib.D3.Graphics = function( GameLib.D3.Graphics = function Graphics(
graphicsType, graphicsType,
instance instance
) { ) {

View File

@ -6,7 +6,7 @@
* @param heightScale Number * @param heightScale Number
* @constructor * @constructor
*/ */
GameLib.D3.Heightmap = function( GameLib.D3.Heightmap = function Heightmap(
sizeX, sizeX,
sizeY, sizeY,
matrix, matrix,

View File

@ -46,7 +46,7 @@ GameLib.D3.ImageFactory.LoadImage = function (graphics, url, defer, progressCall
loader.crossOrigin = ''; loader.crossOrigin = '';
loader.load( loader.load(
url, url + '?ts=' + Date.now(),
function (image) { function (image) {
defer.resolve(image); defer.resolve(image);
}, },

View File

@ -4,7 +4,7 @@
* @param apiLight GameLib.D3.Light.API * @param apiLight GameLib.D3.Light.API
* @constructor * @constructor
*/ */
GameLib.D3.Light = function( GameLib.D3.Light = function Light(
graphics, graphics,
apiLight apiLight
) { ) {
@ -207,6 +207,11 @@ GameLib.D3.Light.prototype.createInstance = function(update) {
} }
} }
if (!instance) {
console.warn('Do not support lights of type : ' + this.lightType + ' - is your DB out of date?');
throw new Error('Do not support lights of type : ' + this.lightType + ' - is your DB out of date?');
}
instance.gameLibObject = this; instance.gameLibObject = this;
instance.name = this.name; instance.name = this.name;
@ -228,3 +233,7 @@ GameLib.D3.Light.prototype.createInstance = function(update) {
GameLib.D3.Light.prototype.updateInstance = function() { GameLib.D3.Light.prototype.updateInstance = function() {
this.instance = this.createInstance(true); this.instance = this.createInstance(true);
}; };
GameLib.D3.Light.prototype.clone = function() {
return _.cloneDeep(this);
};

View File

@ -6,7 +6,7 @@
* @constructor * @constructor
* @returns {GameLib.D3.Material | GameLib.D3.Material.API} * @returns {GameLib.D3.Material | GameLib.D3.Material.API}
*/ */
GameLib.D3.Material = function( GameLib.D3.Material = function Material(
graphics, graphics,
apiMaterial apiMaterial
) { ) {
@ -667,4 +667,8 @@ GameLib.D3.Material.prototype.createInstance = function(update) {
*/ */
GameLib.D3.Material.prototype.updateInstance = function() { GameLib.D3.Material.prototype.updateInstance = function() {
this.instance = this.createInstance(true); this.instance = this.createInstance(true);
};
GameLib.D3.Material.prototype.clone = function() {
return _.cloneDeep(this);
}; };

View File

@ -5,7 +5,7 @@
* @param apiMesh GameLib.D3.Mesh.API * @param apiMesh GameLib.D3.Mesh.API
* @constructor * @constructor
*/ */
GameLib.D3.Mesh = function( GameLib.D3.Mesh = function Mesh(
graphics, graphics,
computeNormals, computeNormals,
apiMesh apiMesh
@ -422,7 +422,7 @@ GameLib.D3.Mesh.prototype.createInstance = function(update) {
return instance; return instance;
}; };
GameLib.D3.Mesh.updateInstance = function() { GameLib.D3.Mesh.prototype.updateInstance = function() {
this.instance = this.createInstance(true); this.instance = this.createInstance(true);
}; };
@ -721,4 +721,8 @@ GameLib.D3.fixPolyZPlane = function(verticesFlat, grain) {
} }
return vertices; return vertices;
};
GameLib.D3.Mesh.prototype.clone = function() {
return _.cloneDeep(this);
}; };

View File

@ -6,10 +6,11 @@
* @param apiScene GameLib.D3.Scene.API * @param apiScene GameLib.D3.Scene.API
* @constructor * @constructor
*/ */
GameLib.D3.Scene = function( GameLib.D3.Scene = function Scene(
graphics, graphics,
progressCallback, progressCallback,
apiScene apiScene,
imageFactory
) { ) {
for (var property in apiScene) { for (var property in apiScene) {
@ -31,7 +32,8 @@ GameLib.D3.Scene = function(
this.instance = this.createInstance(); this.instance = this.createInstance();
this.needsUpdate = false; this.imageFactory = imageFactory;
}; };
/** /**
@ -205,62 +207,67 @@ GameLib.D3.Scene.LoadScene = function(
var shapes = []; var shapes = [];
var imageFactory = GameLib.D3.ImageFactory(graphics);
if (scene.worlds && scene.worlds.length > 0) { if (scene.worlds && scene.worlds.length > 0) {
console.warn('Implement physics worlds code here'); console.warn('Implement physics worlds code here');
} }
var lights3d = []; var lights = [];
if (scene.lights && scene.lights.length > 0) { if (scene.lights && scene.lights.length > 0) {
for (var l = 0; l < scene.lights.length; l++) { for (var l = 0; l < scene.lights.length; l++) {
var light = scene.lights[l]; var apiLight = scene.lights[l];
var light3d = new GameLib.D3.Light( var light = new GameLib.D3.Light(
light.id, graphics,
light.lightType, new GameLib.D3.Light.API(
light.name, apiLight.id,
new GameLib.D3.Color( apiLight.lightType,
light.color.r, apiLight.name,
light.color.g, new GameLib.D3.Color(
light.color.b, apiLight.color.r,
light.color.a apiLight.color.g,
), apiLight.color.b,
light.intensity, apiLight.color.a
new GameLib.D3.Vector3( ),
light.position.x, apiLight.intensity,
light.position.y, new GameLib.D3.Vector3(
light.position.z apiLight.position.x,
), apiLight.position.y,
new GameLib.D3.Vector3( apiLight.position.z
light.targetPosition.x, ),
light.targetPosition.y, new GameLib.D3.Vector3(
light.targetPosition.z apiLight.targetPosition.x,
), apiLight.targetPosition.y,
new GameLib.D3.Vector4( apiLight.targetPosition.z
light.quaternion.x, ),
light.quaternion.y, new GameLib.D3.Vector4(
light.quaternion.z, apiLight.quaternion.x,
light.quaternion.w apiLight.quaternion.y,
), apiLight.quaternion.z,
new GameLib.D3.Vector3( apiLight.quaternion.w
light.rotation.x, ),
light.rotation.y, new GameLib.D3.Vector3(
light.rotation.z apiLight.rotation.x,
), apiLight.rotation.y,
new GameLib.D3.Vector3( apiLight.rotation.z
light.scale.x, ),
light.scale.y, new GameLib.D3.Vector3(
light.scale.z apiLight.scale.x,
), apiLight.scale.y,
light.distance, apiLight.scale.z
light.decay, ),
light.power, apiLight.distance,
light.angle, apiLight.decay,
light.penumbra apiLight.power,
apiLight.angle,
apiLight.penumbra
)
); );
lights3d.push(light3d); lights.push(light);
} }
} }
@ -395,7 +402,8 @@ GameLib.D3.Scene.LoadScene = function(
), ),
graphics, graphics,
gameLibMaterial, gameLibMaterial,
gameLibTextureMap[map].instanceMapId gameLibTextureMap[map].instanceMapId,
imageFactory
); );
} }
} }
@ -405,6 +413,33 @@ GameLib.D3.Scene.LoadScene = function(
gameLibMaterials.push(gameLibMaterial); gameLibMaterials.push(gameLibMaterial);
} }
var gameLibVertices = [];
for (var v = 0; v < apiMesh.vertices.length; v++) {
var boneWeights = [];
for (var bw = 0; bw < apiMesh.vertices[v].boneWeights.length; bw++) {
boneWeights.push(
new GameLib.D3.BoneWeight(
apiMesh.vertices[v].boneWeights[bw].boneIndex,
apiMesh.vertices[v].boneWeights[bw].weight
)
)
}
gameLibVertices.push(
new GameLib.D3.Vertex(
new GameLib.D3.Vector3(
apiMesh.vertices[v].position.x,
apiMesh.vertices[v].position.y,
apiMesh.vertices[v].position.z
),
boneWeights
)
)
}
var gameLibMesh = new GameLib.D3.Mesh( var gameLibMesh = new GameLib.D3.Mesh(
graphics, graphics,
computeNormals, computeNormals,
@ -412,7 +447,7 @@ GameLib.D3.Scene.LoadScene = function(
apiMesh.id, apiMesh.id,
apiMesh.meshType, apiMesh.meshType,
apiMesh.name, apiMesh.name,
apiMesh.vertices, gameLibVertices,
apiMesh.faces, apiMesh.faces,
apiMesh.faceVertexUvs, apiMesh.faceVertexUvs,
gameLibMaterials, gameLibMaterials,
@ -483,12 +518,13 @@ GameLib.D3.Scene.LoadScene = function(
scene.scale.z scene.scale.z
), ),
scene.parentSceneId, scene.parentSceneId,
lights3d, lights,
worlds, worlds,
entities, entities,
components, components,
shapes shapes
) ),
imageFactory
); );
onLoaded(scene3d); onLoaded(scene3d);

View File

@ -10,7 +10,7 @@
* @param boneTexture * @param boneTexture
* @constructor * @constructor
*/ */
GameLib.D3.Skeleton = function( GameLib.D3.Skeleton = function Skeleton(
id, id,
bones, bones,
boneInverses, boneInverses,

View File

@ -2,110 +2,84 @@
* We have a mapping between GameLib.D3.Texture and the Instance material map. * We have a mapping between GameLib.D3.Texture and the Instance material map.
* Our GameLib.D3.Material.map.alpha corresponds to THREE.Material.alphaMap * Our GameLib.D3.Material.map.alpha corresponds to THREE.Material.alphaMap
* @param graphics * @param graphics
* @returns {{alpha: {texture: null, instanceMapId: string}, ao: {texture: null, instanceMapId: string}, bump: {texture: null, instanceMapId: string}, diffuse: {texture: null, instanceMapId: string}, displacement: {texture: null, instanceMapId: string}, emissive: {texture: null, instanceMapId: string}, environment: {texture: null, instanceMapId: string}, light: {texture: null, instanceMapId: string}, metalness: {texture: null, instanceMapId: string}, normal: {texture: null, instanceMapId: string}, roughness: {texture: null, instanceMapId: string}, specular: {texture: null, instanceMapId: string}}}
* @constructor * @constructor
*/ */
GameLib.D3.TextureMapTemplate = function( GameLib.D3.TextureMapTemplate = function TextureMapTemplate(
graphics graphics
) { ) {
this.graphics = graphics; this.graphics = graphics;
this.graphics.isNotThreeThrow(); this.graphics.isNotThreeThrow();
return { return new GameLib.D3.TextureMaps(
alpha: { new GameLib.D3.TextureMap(
texture : null, null,
instanceMapId: 'alhpaMap' 'alphaMap'
}, ),
ao: { new GameLib.D3.TextureMap(
texture : null, null,
instanceMapId: 'aoMap' 'aoMap'
}, ),
bump: { new GameLib.D3.TextureMap(
texture : null, null,
instanceMapId: 'bumpMap' 'bumpMap'
}, ),
diffuse: { new GameLib.D3.TextureMap(
texture : null, null,
instanceMapId: 'map' 'map'
}, ),
displacement: { new GameLib.D3.TextureMap(
texture : null, null,
instanceMapId: 'displacementMap' 'displacementMap'
}, ),
emissive: { new GameLib.D3.TextureMap(
texture : null, null,
instanceMapId: 'emissiveMap' 'emissiveMap'
}, ),
environment: { new GameLib.D3.TextureMap(
texture : null, null,
instanceMapId: 'envMap' 'envMap'
}, ),
light: { new GameLib.D3.TextureMap(
texture : null, null,
instanceMapId: 'lightMap' 'lightMap'
}, ),
metalness: { new GameLib.D3.TextureMap(
texture : null, null,
instanceMapId: 'metalnessMap' 'metalnessMap'
}, ),
normal: { new GameLib.D3.TextureMap(
texture : null, null,
instanceMapId: 'normalMap' 'normalMap'
}, ),
roughness: { new GameLib.D3.TextureMap(
texture : null, null,
instanceMapId: 'roughnessMap' 'roughnessMap'
}, ),
specular: { new GameLib.D3.TextureMap(
texture : null, null,
instanceMapId: 'specularMap' 'specularMap'
} )
}; );
}; };
/** /**
* Raw API Texture Map Template - should match the contents of the Material Schema (maps property) * Raw API Texture Map Template - should match the contents of the Material Schema (maps property)
* @returns {{alpha: {texture: null}, ao: {texture: null}, bump: {texture: null}, diffuse: {texture: null}, displacement: {texture: null}, emissive: {texture: null}, environment: {texture: null}, light: {texture: null}, metalness: {texture: null}, normal: {texture: null}, roughness: {texture: null}, specular: {texture: null}}}
* @constructor * @constructor
*/ */
GameLib.D3.TextureMapTemplate.API = function() { GameLib.D3.TextureMapTemplate.API = function() {
return { return new GameLib.D3.TextureMaps(
alpha: { new GameLib.D3.TextureMap(),
texture : null new GameLib.D3.TextureMap(),
}, new GameLib.D3.TextureMap(),
ao: { new GameLib.D3.TextureMap(),
texture : null new GameLib.D3.TextureMap(),
}, new GameLib.D3.TextureMap(),
bump: { new GameLib.D3.TextureMap(),
texture : null new GameLib.D3.TextureMap(),
}, new GameLib.D3.TextureMap(),
diffuse: { new GameLib.D3.TextureMap(),
texture : null new GameLib.D3.TextureMap(),
}, new GameLib.D3.TextureMap()
displacement: { );
texture : null
},
emissive: {
texture : null
},
environment: {
texture : null
},
light: {
texture : null
},
metalness: {
texture : null
},
normal: {
texture : null
},
roughness: {
texture : null
},
specular: {
texture : null
}
};
}; };

View File

@ -0,0 +1,21 @@
/**
* We have a mapping between GameLib.D3.Texture and the Instance material map.
* Our GameLib.D3.Material.map.alpha corresponds to THREE.Material.alphaMap
* @constructor
* @param texture GameLib.D3.Texture
* @param instanceMapId string
*/
GameLib.D3.TextureMap = function TextureMap(
texture,
instanceMapId
) {
if (GameLib.D3.Utils.UndefinedOrNull(texture)) {
texture = null;
}
this.texture = texture;
if (GameLib.D3.Utils.UndefinedOrNull(instanceMapId)) {
instanceMapId = null;
}
this.instanceMapId = instanceMapId;
};

View File

@ -0,0 +1,45 @@
/**
* We have a mapping between GameLib.D3.Texture and the Instance material map.
* Our GameLib.D3.Material.map.alpha corresponds to THREE.Material.alphaMap
* @returns {{alpha: {texture: null, instanceMapId: string}, ao: {texture: null, instanceMapId: string}, bump: {texture: null, instanceMapId: string}, diffuse: {texture: null, instanceMapId: string}, displacement: {texture: null, instanceMapId: string}, emissive: {texture: null, instanceMapId: string}, environment: {texture: null, instanceMapId: string}, light: {texture: null, instanceMapId: string}, metalness: {texture: null, instanceMapId: string}, normal: {texture: null, instanceMapId: string}, roughness: {texture: null, instanceMapId: string}, specular: {texture: null, instanceMapId: string}}}
* @constructor
* @param alpha
* @param ao
* @param bump
* @param diffuse
* @param displacement
* @param emissive
* @param environment
* @param light
* @param metalness
* @param normal
* @param roughness
* @param specular
*/
GameLib.D3.TextureMaps = function TextureMaps(
alpha,
ao,
bump,
diffuse,
displacement,
emissive,
environment,
light,
metalness,
normal,
roughness,
specular
) {
this.alpha = alpha;
this.ao = ao;
this.bump = bump;
this.diffuse = diffuse;
this.displacement = displacement;
this.emissive = emissive;
this.environment = environment;
this.light = light;
this.metalness = metalness;
this.normal = normal;
this.roughness = roughness;
this.specular = specular;
};

View File

@ -5,13 +5,15 @@
* @param graphics GameLib.D3.Graphics * @param graphics GameLib.D3.Graphics
* @param parentMaterial GameLib.D3.Material * @param parentMaterial GameLib.D3.Material
* @param parentMaterialInstanceMapId String * @param parentMaterialInstanceMapId String
* @param imageFactory GameLib.D3.ImageFactory result
* @constructor * @constructor
*/ */
GameLib.D3.Texture = function( GameLib.D3.Texture = function Texture(
apiTexture, apiTexture,
graphics, graphics,
parentMaterial, parentMaterial,
parentMaterialInstanceMapId parentMaterialInstanceMapId,
imageFactory
) { ) {
for (var property in apiTexture) { for (var property in apiTexture) {
if (apiTexture.hasOwnProperty(property)) { if (apiTexture.hasOwnProperty(property)) {
@ -26,23 +28,23 @@ GameLib.D3.Texture = function(
this.parentMaterialInstanceMapId = parentMaterialInstanceMapId; this.parentMaterialInstanceMapId = parentMaterialInstanceMapId;
this.imageFactory = GameLib.D3.ImageFactory(graphics);
this.imageData = this.imageFactory(apiTexture.imagePath);
this.imageInstance = null; this.imageInstance = null;
this.instance = null; this.instance = null;
this.loadTexture(imageFactory);
};
GameLib.D3.Texture.prototype.loadTexture = function(imageFactory) {
this.imageData = imageFactory(this.imagePath);
this.imageData.then( this.imageData.then(
function (imageInstance){ function (imageInstance){
this.imageInstance = imageInstance; this.imageInstance = imageInstance;
this.instance = this.createInstance(); this.instance = this.createInstance();
this.parentMaterial.instance[this.parentMaterialInstanceMapId] = this.instance;
this.needsUpdate = false; this.parentMaterial.instance.needsUpdate = true;
this.parentMaterial[this.parentMaterialInstanceMapId] = this.instance;
this.parentMaterial.needsUpdate = true;
}.bind(this), }.bind(this),
function onRejected() { function onRejected() {
} }
@ -310,3 +312,7 @@ GameLib.D3.Texture.prototype.createInstance = function(update) {
GameLib.D3.Texture.prototype.updateInstance = function() { GameLib.D3.Texture.prototype.updateInstance = function() {
this.instance = this.createInstance(true); this.instance = this.createInstance(true);
}; };
GameLib.D3.Texture.prototype.clone = function() {
return _.cloneDeep(this);
};

View File

@ -13,7 +13,7 @@
* @param normal * @param normal
* @constructor * @constructor
*/ */
GameLib.D3.TriangleFace = function( GameLib.D3.TriangleFace = function TriangleFace(
v0, v0,
v1, v1,
v2, v2,

View File

@ -1,4 +1,4 @@
GameLib.D3.Vector2 = function(x, y) { GameLib.D3.Vector2 = function Vector2(x, y) {
this.x = 0; this.x = 0;
this.y = 0; this.y = 0;

View File

@ -1,4 +1,4 @@
GameLib.D3.Vector3 = function(x, y, z) { GameLib.D3.Vector3 = function Vector3(x, y, z) {
this.x = 0; this.x = 0;
this.y = 0; this.y = 0;

View File

@ -1,4 +1,4 @@
GameLib.D3.Vector4 = function(x, y, z, w) { GameLib.D3.Vector4 = function Vector4(x, y, z, w) {
this.x = 0; this.x = 0;
this.y = 0; this.y = 0;

View File

@ -4,7 +4,7 @@
* @param boneWeights GameLib.D3.BoneWeight[] * @param boneWeights GameLib.D3.BoneWeight[]
* @constructor * @constructor
*/ */
GameLib.D3.Vertex = function( GameLib.D3.Vertex = function Vertex(
position, position,
boneWeights boneWeights
) { ) {