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
* @constructor
*/
GameLib.D3.BoneWeight = function(
GameLib.D3.BoneWeight = function BoneWeight(
boneIndex,
weight
) {

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -4,7 +4,7 @@
* @param apiLight GameLib.D3.Light.API
* @constructor
*/
GameLib.D3.Light = function(
GameLib.D3.Light = function Light(
graphics,
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.name = this.name;
@ -228,3 +233,7 @@ GameLib.D3.Light.prototype.createInstance = function(update) {
GameLib.D3.Light.prototype.updateInstance = function() {
this.instance = this.createInstance(true);
};
GameLib.D3.Light.prototype.clone = function() {
return _.cloneDeep(this);
};

View File

@ -6,7 +6,7 @@
* @constructor
* @returns {GameLib.D3.Material | GameLib.D3.Material.API}
*/
GameLib.D3.Material = function(
GameLib.D3.Material = function Material(
graphics,
apiMaterial
) {
@ -667,4 +667,8 @@ GameLib.D3.Material.prototype.createInstance = function(update) {
*/
GameLib.D3.Material.prototype.updateInstance = function() {
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
* @constructor
*/
GameLib.D3.Mesh = function(
GameLib.D3.Mesh = function Mesh(
graphics,
computeNormals,
apiMesh
@ -422,7 +422,7 @@ GameLib.D3.Mesh.prototype.createInstance = function(update) {
return instance;
};
GameLib.D3.Mesh.updateInstance = function() {
GameLib.D3.Mesh.prototype.updateInstance = function() {
this.instance = this.createInstance(true);
};
@ -721,4 +721,8 @@ GameLib.D3.fixPolyZPlane = function(verticesFlat, grain) {
}
return vertices;
};
GameLib.D3.Mesh.prototype.clone = function() {
return _.cloneDeep(this);
};

View File

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

View File

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

View File

@ -2,110 +2,84 @@
* We have a mapping between GameLib.D3.Texture and the Instance material map.
* Our GameLib.D3.Material.map.alpha corresponds to THREE.Material.alphaMap
* @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
*/
GameLib.D3.TextureMapTemplate = function(
GameLib.D3.TextureMapTemplate = function TextureMapTemplate(
graphics
) {
this.graphics = graphics;
this.graphics.isNotThreeThrow();
return {
alpha: {
texture : null,
instanceMapId: 'alhpaMap'
},
ao: {
texture : null,
instanceMapId: 'aoMap'
},
bump: {
texture : null,
instanceMapId: 'bumpMap'
},
diffuse: {
texture : null,
instanceMapId: 'map'
},
displacement: {
texture : null,
instanceMapId: 'displacementMap'
},
emissive: {
texture : null,
instanceMapId: 'emissiveMap'
},
environment: {
texture : null,
instanceMapId: 'envMap'
},
light: {
texture : null,
instanceMapId: 'lightMap'
},
metalness: {
texture : null,
instanceMapId: 'metalnessMap'
},
normal: {
texture : null,
instanceMapId: 'normalMap'
},
roughness: {
texture : null,
instanceMapId: 'roughnessMap'
},
specular: {
texture : null,
instanceMapId: 'specularMap'
}
};
return new GameLib.D3.TextureMaps(
new GameLib.D3.TextureMap(
null,
'alphaMap'
),
new GameLib.D3.TextureMap(
null,
'aoMap'
),
new GameLib.D3.TextureMap(
null,
'bumpMap'
),
new GameLib.D3.TextureMap(
null,
'map'
),
new GameLib.D3.TextureMap(
null,
'displacementMap'
),
new GameLib.D3.TextureMap(
null,
'emissiveMap'
),
new GameLib.D3.TextureMap(
null,
'envMap'
),
new GameLib.D3.TextureMap(
null,
'lightMap'
),
new GameLib.D3.TextureMap(
null,
'metalnessMap'
),
new GameLib.D3.TextureMap(
null,
'normalMap'
),
new GameLib.D3.TextureMap(
null,
'roughnessMap'
),
new GameLib.D3.TextureMap(
null,
'specularMap'
)
);
};
/**
* 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
*/
GameLib.D3.TextureMapTemplate.API = function() {
return {
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
}
};
return new GameLib.D3.TextureMaps(
new GameLib.D3.TextureMap(),
new GameLib.D3.TextureMap(),
new GameLib.D3.TextureMap(),
new GameLib.D3.TextureMap(),
new GameLib.D3.TextureMap(),
new GameLib.D3.TextureMap(),
new GameLib.D3.TextureMap(),
new GameLib.D3.TextureMap(),
new GameLib.D3.TextureMap(),
new GameLib.D3.TextureMap(),
new GameLib.D3.TextureMap(),
new GameLib.D3.TextureMap()
);
};

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

View File

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

View File

@ -1,4 +1,4 @@
GameLib.D3.Vector2 = function(x, y) {
GameLib.D3.Vector2 = function Vector2(x, y) {
this.x = 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.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.y = 0;

View File

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