materials and textures stuff needs updates
parent
6e3270508e
commit
4071abc0c6
|
@ -202,16 +202,18 @@ GameLib.API.Quaternion.prototype.slerp = function (quaternion, t) {
|
||||||
* @constructor
|
* @constructor
|
||||||
*/
|
*/
|
||||||
GameLib.API.Quaternion.FromObjectQuaternion = function (objectQuaternion) {
|
GameLib.API.Quaternion.FromObjectQuaternion = function (objectQuaternion) {
|
||||||
|
|
||||||
|
var apiAxis = null;
|
||||||
|
if (objectQuaternion.axis) {
|
||||||
|
apiAxis = GameLib.API.Vector3.FromObjectVector(objectQuaternion.axis);
|
||||||
|
}
|
||||||
|
|
||||||
return new GameLib.API.Quaternion(
|
return new GameLib.API.Quaternion(
|
||||||
objectQuaternion.x,
|
objectQuaternion.x,
|
||||||
objectQuaternion.y,
|
objectQuaternion.y,
|
||||||
objectQuaternion.z,
|
objectQuaternion.z,
|
||||||
objectQuaternion.w,
|
objectQuaternion.w,
|
||||||
new GameLib.API.Vector3(
|
apiAxis,
|
||||||
objectQuaternion.axis.x,
|
|
||||||
objectQuaternion.axis.y,
|
|
||||||
objectQuaternion.axis.z
|
|
||||||
),
|
|
||||||
objectQuaternion.angle
|
objectQuaternion.angle
|
||||||
)
|
)
|
||||||
};
|
};
|
|
@ -528,51 +528,51 @@ GameLib.D3.API.Material.FromObjectMaterial = function(objectMaterial) {
|
||||||
var apiSpecularMap = null;
|
var apiSpecularMap = null;
|
||||||
|
|
||||||
if (objectMaterial.alphaMap) {
|
if (objectMaterial.alphaMap) {
|
||||||
apiAlphaMap = GameLib.D3.API.Texture.FromObjectTexture(objectMaterial.alphaMap);
|
apiAlphaMap = objectMaterial.alphaMap;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (objectMaterial.aoMap) {
|
if (objectMaterial.aoMap) {
|
||||||
apiAoMap = GameLib.D3.API.Texture.FromObjectTexture(objectMaterial.aoMap);
|
apiAoMap = objectMaterial.aoMap;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (objectMaterial.bumpMap) {
|
if (objectMaterial.bumpMap) {
|
||||||
apiBumpMap = GameLib.D3.API.Texture.FromObjectTexture(objectMaterial.bumpMap);
|
apiBumpMap = objectMaterial.bumpMap;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (objectMaterial.diffuseMap) {
|
if (objectMaterial.diffuseMap) {
|
||||||
apiDiffuseMap = GameLib.D3.API.Texture.FromObjectTexture(objectMaterial.diffuseMap);
|
apiDiffuseMap = objectMaterial.diffuseMap;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (objectMaterial.displacementMap) {
|
if (objectMaterial.displacementMap) {
|
||||||
apiDisplacementMap = GameLib.D3.API.Texture.FromObjectTexture(objectMaterial.displacementMap);
|
apiDisplacementMap = objectMaterial.displacementMap;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (objectMaterial.emissiveMap) {
|
if (objectMaterial.emissiveMap) {
|
||||||
apiEmissiveMap = GameLib.D3.API.Texture.FromObjectTexture(objectMaterial.emissiveMap);
|
apiEmissiveMap = objectMaterial.emissiveMap;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (objectMaterial.environmentMap) {
|
if (objectMaterial.environmentMap) {
|
||||||
apiEnvironmentMap = GameLib.D3.API.Texture.FromObjectTexture(objectMaterial.environmentMap);
|
apiEnvironmentMap = objectMaterial.environmentMap;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (objectMaterial.lightMap) {
|
if (objectMaterial.lightMap) {
|
||||||
apiLightMap = GameLib.D3.API.Texture.FromObjectTexture(objectMaterial.lightMap);
|
apiLightMap = objectMaterial.lightMap;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (objectMaterial.metalnessMap) {
|
if (objectMaterial.metalnessMap) {
|
||||||
apiMetalnessMap = GameLib.D3.API.Texture.FromObjectTexture(objectMaterial.metalnessMap);
|
apiMetalnessMap = objectMaterial.metalnessMap;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (objectMaterial.normalMap) {
|
if (objectMaterial.normalMap) {
|
||||||
apiNormalMap = GameLib.D3.API.Texture.FromObjectTexture(objectMaterial.normalMap);
|
apiNormalMap = objectMaterial.normalMap;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (objectMaterial.roughnessMap) {
|
if (objectMaterial.roughnessMap) {
|
||||||
apiRoughnessMap = GameLib.D3.API.Texture.FromObjectTexture(objectMaterial.roughnessMap);
|
apiRoughnessMap = objectMaterial.roughnessMap;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (objectMaterial.specularMap) {
|
if (objectMaterial.specularMap) {
|
||||||
apiSpecularMap = GameLib.D3.API.Texture.FromObjectTexture(objectMaterial.specularMap);
|
apiSpecularMap = objectMaterial.specularMap;
|
||||||
}
|
}
|
||||||
|
|
||||||
return new GameLib.D3.API.Material(
|
return new GameLib.D3.API.Material(
|
||||||
|
|
|
@ -53,7 +53,8 @@ GameLib.D3.API.Mesh = function(
|
||||||
GameLib.Component.COMPONENT_MESH,
|
GameLib.Component.COMPONENT_MESH,
|
||||||
{
|
{
|
||||||
'parentMesh' : GameLib.D3.Mesh,
|
'parentMesh' : GameLib.D3.Mesh,
|
||||||
'parentScene' : GameLib.D3.Scene
|
'parentScene' : GameLib.D3.Scene,
|
||||||
|
'materials' : [GameLib.D3.Material]
|
||||||
},
|
},
|
||||||
null,
|
null,
|
||||||
parentEntity
|
parentEntity
|
||||||
|
@ -176,11 +177,51 @@ GameLib.D3.API.Mesh.prototype.constructor = GameLib.D3.API.Mesh;
|
||||||
GameLib.D3.API.Mesh.FromObjectMesh = function (objectMesh){
|
GameLib.D3.API.Mesh.FromObjectMesh = function (objectMesh){
|
||||||
|
|
||||||
var apiSkeleton = null;
|
var apiSkeleton = null;
|
||||||
|
var apiPosition = null;
|
||||||
|
var apiQuaternion = null;
|
||||||
|
var apiScale = null;
|
||||||
|
var apiLocalPosition = null;
|
||||||
|
var apiLocalRotation = null;
|
||||||
|
var apiLocalScale = null;
|
||||||
|
var apiUp = null;
|
||||||
|
var apiModelMatrix = null;
|
||||||
|
|
||||||
if (objectMesh.skeleton) {
|
if (objectMesh.skeleton) {
|
||||||
apiSkeleton = GameLib.D3.API.Skeleton.FromObjectSkeleton(objectMesh.skeleton);
|
apiSkeleton = GameLib.D3.API.Skeleton.FromObjectSkeleton(objectMesh.skeleton);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (objectMesh.position) {
|
||||||
|
apiPosition = GameLib.API.Vector3.FromObjectVector(objectMesh.position);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (objectMesh.quaternion) {
|
||||||
|
apiQuaternion = GameLib.API.Quaternion.FromObjectQuaternion(objectMesh.quaternion);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (objectMesh.scale) {
|
||||||
|
apiScale = GameLib.API.Vector3.FromObjectVector(objectMesh.scale);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (objectMesh.localPosition) {
|
||||||
|
apiLocalPosition = GameLib.API.Vector3.FromObjectVector(objectMesh.localPosition);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (objectMesh.localRotation) {
|
||||||
|
apiLocalRotation = GameLib.API.Vector3.FromObjectVector(objectMesh.localRotation);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (objectMesh.localScale) {
|
||||||
|
apiLocalScale = GameLib.API.Vector3.FromObjectVector(objectMesh.localScale);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (objectMesh.up) {
|
||||||
|
apiUp = GameLib.API.Vector3.FromObjectVector(objectMesh.up);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (objectMesh.modelMatrix) {
|
||||||
|
apiModelMatrix = GameLib.API.Matrix4.FromObjectMatrix(objectMesh.modelMatrix);
|
||||||
|
}
|
||||||
|
|
||||||
return new GameLib.D3.API.Mesh(
|
return new GameLib.D3.API.Mesh(
|
||||||
objectMesh.id,
|
objectMesh.id,
|
||||||
objectMesh.meshType,
|
objectMesh.meshType,
|
||||||
|
@ -192,24 +233,20 @@ GameLib.D3.API.Mesh.FromObjectMesh = function (objectMesh){
|
||||||
),
|
),
|
||||||
objectMesh.faces,
|
objectMesh.faces,
|
||||||
objectMesh.faceVertexUvs,
|
objectMesh.faceVertexUvs,
|
||||||
objectMesh.materials.map(
|
objectMesh.materials,
|
||||||
function (objectMaterial) {
|
|
||||||
return GameLib.D3.API.Material.FromObjectMaterial(objectMaterial);
|
|
||||||
}
|
|
||||||
),
|
|
||||||
objectMesh.parentMesh,
|
objectMesh.parentMesh,
|
||||||
objectMesh.parentScene,
|
objectMesh.parentScene,
|
||||||
apiSkeleton,
|
apiSkeleton,
|
||||||
objectMesh.skinIndices,
|
objectMesh.skinIndices,
|
||||||
objectMesh.skinWeights,
|
objectMesh.skinWeights,
|
||||||
GameLib.API.Vector3.FromObjectVector(objectMesh.position),
|
apiPosition,
|
||||||
GameLib.API.Quaternion.FromObjectQuaternion(objectMesh.quaternion),
|
apiQuaternion,
|
||||||
GameLib.API.Vector3.FromObjectVector(objectMesh.scale),
|
apiScale,
|
||||||
GameLib.API.Vector3.FromObjectVector(objectMesh.localPosition),
|
apiLocalPosition,
|
||||||
GameLib.API.Vector3.FromObjectVector(objectMesh.localRotation),
|
apiLocalRotation,
|
||||||
GameLib.API.Vector3.FromObjectVector(objectMesh.localScale),
|
apiLocalScale,
|
||||||
GameLib.API.Vector3.FromObjectVector(objectMesh.up),
|
apiUp,
|
||||||
GameLib.API.Matrix4.FromObjectMatrix(objectMesh.modelMatrix),
|
apiModelMatrix,
|
||||||
objectMesh.parentEntity,
|
objectMesh.parentEntity,
|
||||||
objectMesh.renderOrder
|
objectMesh.renderOrder
|
||||||
);
|
);
|
||||||
|
|
|
@ -32,7 +32,8 @@ GameLib.D3.API.Scene = function(
|
||||||
shapes,
|
shapes,
|
||||||
cameras,
|
cameras,
|
||||||
activeCameraIndex,
|
activeCameraIndex,
|
||||||
textures
|
textures,
|
||||||
|
materials
|
||||||
) {
|
) {
|
||||||
if (GameLib.Utils.UndefinedOrNull(id)) {
|
if (GameLib.Utils.UndefinedOrNull(id)) {
|
||||||
id = GameLib.Utils.RandomId();
|
id = GameLib.Utils.RandomId();
|
||||||
|
@ -108,6 +109,11 @@ GameLib.D3.API.Scene = function(
|
||||||
textures = [];
|
textures = [];
|
||||||
}
|
}
|
||||||
this.textures = textures;
|
this.textures = textures;
|
||||||
|
|
||||||
|
if (GameLib.Utils.UndefinedOrNull(materials)) {
|
||||||
|
materials = [];
|
||||||
|
}
|
||||||
|
this.materials = materials;
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -118,8 +124,15 @@ GameLib.D3.API.Scene = function(
|
||||||
GameLib.D3.API.Scene.FromObjectScene = function(objectScene) {
|
GameLib.D3.API.Scene.FromObjectScene = function(objectScene) {
|
||||||
|
|
||||||
var apiEntityManager = null;
|
var apiEntityManager = null;
|
||||||
|
var apiPosition = null;
|
||||||
|
var apiQuaternion = null;
|
||||||
|
var apiScale = null;
|
||||||
|
|
||||||
var apiTextures = null;
|
var apiTextures = [];
|
||||||
|
var apiMaterials = [];
|
||||||
|
var apiMeshes = [];
|
||||||
|
var apiLights = [];
|
||||||
|
var apiCameras = [];
|
||||||
|
|
||||||
if (objectScene.entityManager) {
|
if (objectScene.entityManager) {
|
||||||
apiEntityManager = GameLib.API.EntityManager.FromObjectEntityManager(objectScene.entityManager);
|
apiEntityManager = GameLib.API.EntityManager.FromObjectEntityManager(objectScene.entityManager);
|
||||||
|
@ -133,34 +146,67 @@ GameLib.D3.API.Scene.FromObjectScene = function(objectScene) {
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (objectScene.materials) {
|
||||||
|
apiMaterials = objectScene.materials.map(
|
||||||
|
function(objectMaterial) {
|
||||||
|
return GameLib.D3.API.Material.FromObjectMaterial(objectMaterial)
|
||||||
|
}
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
if (objectScene.meshes) {
|
||||||
|
apiMeshes = objectScene.meshes.map(
|
||||||
|
function(objectMesh) {
|
||||||
|
return GameLib.D3.API.Mesh.FromObjectMesh(objectMesh);
|
||||||
|
}
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
if (objectScene.lights) {
|
||||||
|
apiLights = objectScene.lights.map(
|
||||||
|
function(objectLight) {
|
||||||
|
return GameLib.D3.API.Light.FromObjectLight(objectLight);
|
||||||
|
}
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
if (objectScene.cameras) {
|
||||||
|
apiCameras = objectScene.cameras.map(
|
||||||
|
function(objectCamera) {
|
||||||
|
return GameLib.D3.API.Camera.FromObjectCamera(objectCamera);
|
||||||
|
}
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
if (objectScene.position) {
|
||||||
|
apiPosition = GameLib.API.Vector3.FromObjectVector(objectScene.position);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (objectScene.quaternion) {
|
||||||
|
apiQuaternion = GameLib.API.Quaternion.FromObjectQuaternion(objectScene.quaternion);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (objectScene.scale) {
|
||||||
|
apiScale = GameLib.API.Vector3.FromObjectVector(objectScene.scale);
|
||||||
|
}
|
||||||
|
|
||||||
return new GameLib.D3.API.Scene(
|
return new GameLib.D3.API.Scene(
|
||||||
objectScene.id,
|
objectScene.id,
|
||||||
objectScene.path,
|
objectScene.path,
|
||||||
objectScene.name,
|
objectScene.name,
|
||||||
objectScene.meshes.map(
|
apiMeshes,
|
||||||
function (objectMesh) {
|
apiPosition,
|
||||||
return GameLib.D3.API.Mesh.FromObjectMesh(objectMesh)
|
apiQuaternion,
|
||||||
}
|
apiScale,
|
||||||
),
|
|
||||||
GameLib.API.Vector3.FromObjectVector(objectScene.position),
|
|
||||||
GameLib.API.Quaternion.FromObjectQuaternion(objectScene.quaternion),
|
|
||||||
GameLib.API.Vector3.FromObjectVector(objectScene.scale),
|
|
||||||
objectScene.parentSceneId,
|
objectScene.parentSceneId,
|
||||||
objectScene.lights.map(
|
apiLights,
|
||||||
function (objectLight) {
|
|
||||||
return GameLib.D3.API.Light.FromObjectLight(objectLight)
|
|
||||||
}
|
|
||||||
),
|
|
||||||
[], //TODO : implement worlds here
|
[], //TODO : implement worlds here
|
||||||
apiEntityManager,
|
apiEntityManager,
|
||||||
[], //TODO : implement shapes here
|
[], //TODO : implement shapes here
|
||||||
objectScene.cameras.map(
|
apiCameras,
|
||||||
function (objectCamera) {
|
|
||||||
return GameLib.D3.API.Camera.FromObjectCamera(objectCamera);
|
|
||||||
}
|
|
||||||
),
|
|
||||||
objectScene.activeCameraIndex,
|
objectScene.activeCameraIndex,
|
||||||
apiTextures
|
apiTextures,
|
||||||
|
apiMaterials
|
||||||
);
|
);
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
|
@ -83,6 +83,7 @@ GameLib.D3.Light.LIGHT_TYPE_SPOT = 0x4;
|
||||||
*/
|
*/
|
||||||
GameLib.D3.Light.prototype.createInstance = function(update) {
|
GameLib.D3.Light.prototype.createInstance = function(update) {
|
||||||
|
|
||||||
|
|
||||||
var instance = null;
|
var instance = null;
|
||||||
|
|
||||||
if (update) {
|
if (update) {
|
||||||
|
@ -91,22 +92,31 @@ GameLib.D3.Light.prototype.createInstance = function(update) {
|
||||||
|
|
||||||
if (!instance) {
|
if (!instance) {
|
||||||
|
|
||||||
if (this.lightType == GameLib.D3.Light.LIGHT_TYPE_AMBIENT) {
|
if (
|
||||||
instance = new this.graphics.instance.AmbientLight(
|
this.lightType == GameLib.D3.Light.LIGHT_TYPE_AMBIENT ||
|
||||||
|
this.lightType == 'AmbientLight'
|
||||||
|
) {
|
||||||
|
instance = new THREE.AmbientLight(
|
||||||
this.color.instance,
|
this.color.instance,
|
||||||
this.intensity
|
this.intensity
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.lightType == GameLib.D3.Light.LIGHT_TYPE_DIRECTIONAL) {
|
if (
|
||||||
instance = new this.graphics.instance.DirectionalLight(
|
this.lightType == GameLib.D3.Light.LIGHT_TYPE_DIRECTIONAL ||
|
||||||
|
this.lightType == 'DirectionalLight'
|
||||||
|
) {
|
||||||
|
instance = new THREE.DirectionalLight(
|
||||||
this.color.instance,
|
this.color.instance,
|
||||||
this.intensity
|
this.intensity
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.lightType == GameLib.D3.Light.LIGHT_TYPE_POINT) {
|
if (
|
||||||
instance = new this.graphics.instance.PointLight(
|
this.lightType == GameLib.D3.Light.LIGHT_TYPE_POINT ||
|
||||||
|
this.lightType == 'PointLight'
|
||||||
|
) {
|
||||||
|
instance = new THREE.PointLight(
|
||||||
this.color.instance,
|
this.color.instance,
|
||||||
this.intensity
|
this.intensity
|
||||||
);
|
);
|
||||||
|
@ -114,8 +124,11 @@ GameLib.D3.Light.prototype.createInstance = function(update) {
|
||||||
instance.decay = this.decay;
|
instance.decay = this.decay;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.lightType == GameLib.D3.Light.LIGHT_TYPE_SPOT ) {
|
if (
|
||||||
instance = new this.graphics.instance.SpotLight(
|
this.lightType == GameLib.D3.Light.LIGHT_TYPE_SPOT ||
|
||||||
|
this.lightType == 'SpotLight'
|
||||||
|
) {
|
||||||
|
instance = new THREE.SpotLight(
|
||||||
this.color.instance,
|
this.color.instance,
|
||||||
this.intensity
|
this.intensity
|
||||||
);
|
);
|
||||||
|
@ -143,11 +156,11 @@ GameLib.D3.Light.prototype.createInstance = function(update) {
|
||||||
instance.scale.y = this.scale.y;
|
instance.scale.y = this.scale.y;
|
||||||
instance.scale.z = this.scale.z;
|
instance.scale.z = this.scale.z;
|
||||||
|
|
||||||
if (instance.target) {
|
if (instance.target) {
|
||||||
instance.target.position.x = this.targetPosition.x;
|
instance.target.position.x = this.targetPosition.x;
|
||||||
instance.target.position.y = this.targetPosition.y;
|
instance.target.position.y = this.targetPosition.y;
|
||||||
instance.target.position.z = this.targetPosition.z;
|
instance.target.position.z = this.targetPosition.z;
|
||||||
}
|
}
|
||||||
|
|
||||||
instance.quaternion.x = this.quaternion.x;
|
instance.quaternion.x = this.quaternion.x;
|
||||||
instance.quaternion.y = this.quaternion.y;
|
instance.quaternion.y = this.quaternion.y;
|
||||||
|
|
|
@ -108,123 +108,159 @@ GameLib.D3.Material = function Material(
|
||||||
);
|
);
|
||||||
|
|
||||||
if (this.alphaMap) {
|
if (this.alphaMap) {
|
||||||
this.alphaMap = new GameLib.D3.Texture(
|
if (this.alphaMap instanceof GameLib.D3.API.Texture) {
|
||||||
this.graphics,
|
this.alphaMap = new GameLib.D3.Texture(
|
||||||
this.alphaMap,
|
this.graphics,
|
||||||
this,
|
this.alphaMap,
|
||||||
'alphaMap',
|
this.imageFactory
|
||||||
imageFactory
|
);
|
||||||
);
|
} else {
|
||||||
|
console.warn('this.alphaMap is not an instance of API.Texture');
|
||||||
|
// throw new Error('this.alphaMap is not an instance of API.Texture');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.aoMap) {
|
if (this.aoMap) {
|
||||||
this.aoMap = new GameLib.D3.Texture(
|
if (this.aoMap instanceof GameLib.D3.API.Texture) {
|
||||||
this.graphics,
|
this.aoMap = new GameLib.D3.Texture(
|
||||||
this.aoMap,
|
this.graphics,
|
||||||
this,
|
this.aoMap,
|
||||||
'aoMap',
|
this.imageFactory
|
||||||
imageFactory
|
);
|
||||||
);
|
} else {
|
||||||
|
console.warn('this.aoMap is not an instance of API.Texture');
|
||||||
|
// throw new Error('this.aoMap is not an instance of API.Texture');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.bumpMap) {
|
if (this.bumpMap) {
|
||||||
this.bumpMap = new GameLib.D3.Texture(
|
if (this.bumpMap instanceof GameLib.D3.API.Texture) {
|
||||||
this.graphics,
|
this.bumpMap = new GameLib.D3.Texture(
|
||||||
this.bumpMap,
|
this.graphics,
|
||||||
this,
|
this.bumpMap,
|
||||||
'bumpMap',
|
this.imageFactory
|
||||||
imageFactory
|
);
|
||||||
);
|
} else {
|
||||||
|
console.warn('this.bumpMap is not an instance of API.Texture');
|
||||||
|
// throw new Error('this.bumpMap is not an instance of API.Texture');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.diffuseMap) {
|
if (this.diffuseMap) {
|
||||||
this.diffuseMap = new GameLib.D3.Texture(
|
if (this.diffuseMap instanceof GameLib.D3.API.Texture) {
|
||||||
this.graphics,
|
this.diffuseMap = new GameLib.D3.Texture(
|
||||||
this.diffuseMap,
|
this.graphics,
|
||||||
this,
|
this.diffuseMap,
|
||||||
'map',
|
this.imageFactory
|
||||||
imageFactory
|
);
|
||||||
);
|
} else {
|
||||||
|
console.warn('this.diffuseMap is not an instance of API.Texture');
|
||||||
|
// throw new Error('this.diffuseMap is not an instance of API.Texture');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.displacementMap) {
|
if (this.displacementMap) {
|
||||||
this.displacementMap = new GameLib.D3.Texture(
|
if (this.displacementMap instanceof GameLib.D3.API.Texture) {
|
||||||
this.graphics,
|
this.displacementMap = new GameLib.D3.Texture(
|
||||||
this.displacementMap,
|
this.graphics,
|
||||||
this,
|
this.displacementMap,
|
||||||
'displacementMap',
|
this.imageFactory
|
||||||
imageFactory
|
);
|
||||||
);
|
} else {
|
||||||
|
console.warn('this.displacementMap is not an instance of API.Texture');
|
||||||
|
// throw new Error('this.displacementMap is not an instance of API.Texture');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.emissiveMap) {
|
if (this.emissiveMap) {
|
||||||
this.emissiveMap = new GameLib.D3.Texture(
|
if (this.emissiveMap instanceof GameLib.D3.API.Texture) {
|
||||||
this.graphics,
|
this.emissiveMap = new GameLib.D3.Texture(
|
||||||
this.emissiveMap,
|
this.graphics,
|
||||||
this,
|
this.emissiveMap,
|
||||||
'emissiveMap',
|
this.imageFactory
|
||||||
imageFactory
|
);
|
||||||
);
|
} else {
|
||||||
|
console.warn('this.emissiveMap is not an instance of API.Texture');
|
||||||
|
// throw new Error('this.emissiveMap is not an instance of API.Texture');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.environmentMap) {
|
if (this.environmentMap) {
|
||||||
this.environmentMap = new GameLib.D3.Texture(
|
if (this.environmentMap instanceof GameLib.D3.API.Texture) {
|
||||||
this.graphics,
|
this.environmentMap = new GameLib.D3.Texture(
|
||||||
this.environmentMap,
|
this.graphics,
|
||||||
this,
|
this.environmentMap,
|
||||||
'envMap',
|
this.imageFactory
|
||||||
imageFactory
|
);
|
||||||
);
|
} else {
|
||||||
|
console.warn('this.environmentMap is not an instance of API.Texture');
|
||||||
|
// throw new Error('this.environmentMap is not an instance of API.Texture');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.lightMap) {
|
if (this.lightMap) {
|
||||||
this.lightMap = new GameLib.D3.Texture(
|
if (this.lightMap instanceof GameLib.D3.API.Texture) {
|
||||||
this.graphics,
|
this.lightMap = new GameLib.D3.Texture(
|
||||||
this.lightMap,
|
this.graphics,
|
||||||
this,
|
this.lightMap,
|
||||||
'lightMap',
|
this.imageFactory
|
||||||
imageFactory
|
);
|
||||||
);
|
} else {
|
||||||
|
console.warn('this.lightMap is not an instance of API.Texture');
|
||||||
|
// throw new Error('this.lightMap is not an instance of API.Texture');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.metalnessMap) {
|
if (this.metalnessMap) {
|
||||||
this.metalnessMap = new GameLib.D3.Texture(
|
if (this.metalnessMap instanceof GameLib.D3.API.Texture) {
|
||||||
this.graphics,
|
this.metalnessMap = new GameLib.D3.Texture(
|
||||||
this.metalnessMap,
|
this.graphics,
|
||||||
this,
|
this.metalnessMap,
|
||||||
'metalnessMap',
|
this.imageFactory
|
||||||
imageFactory
|
);
|
||||||
);
|
} else {
|
||||||
|
console.warn('this.metalnessMap is not an instance of API.Texture');
|
||||||
|
// throw new Error('this.metalnessMap is not an instance of API.Texture');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.normalMap) {
|
if (this.normalMap) {
|
||||||
this.normalMap = new GameLib.D3.Texture(
|
if (this.normalMap instanceof GameLib.D3.API.Texture) {
|
||||||
this.graphics,
|
this.normalMap = new GameLib.D3.Texture(
|
||||||
this.normalMap,
|
this.graphics,
|
||||||
this,
|
this.normalMap,
|
||||||
'normalMap',
|
this.imageFactory
|
||||||
imageFactory
|
);
|
||||||
);
|
} else {
|
||||||
|
console.warn('this.normalMap is not an instance of API.Texture');
|
||||||
|
// throw new Error('this.normalMap is not an instance of API.Texture');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.roughnessMap) {
|
if (this.roughnessMap) {
|
||||||
this.roughnessMap = new GameLib.D3.Texture(
|
if (this.roughnessMap instanceof GameLib.D3.API.Texture) {
|
||||||
this.graphics,
|
this.roughnessMap = new GameLib.D3.Texture(
|
||||||
this.roughnessMap,
|
this.graphics,
|
||||||
this,
|
this.roughnessMap,
|
||||||
'roughnessMap',
|
this.imageFactory
|
||||||
imageFactory
|
);
|
||||||
);
|
} else {
|
||||||
|
console.warn('this.roughnessMap is not an instance of API.Texture');
|
||||||
|
// throw new Error('this.roughnessMap is not an instance of API.Texture');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.specularMap) {
|
if (this.specularMap) {
|
||||||
this.specularMap = new GameLib.D3.Texture(
|
if (this.specularMap instanceof GameLib.D3.API.Texture) {
|
||||||
this.graphics,
|
this.specularMap = new GameLib.D3.Texture(
|
||||||
this.specularMap,
|
this.graphics,
|
||||||
this,
|
this.specularMap,
|
||||||
'specularMap',
|
this.imageFactory
|
||||||
imageFactory
|
);
|
||||||
);
|
} else {
|
||||||
|
console.warn('this.specularMap is not an instance of API.Texture');
|
||||||
|
// throw new Error('this.specularMap is not an instance of API.Texture');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
this.instance = this.createInstance();
|
this.instance = this.createInstance();
|
||||||
|
|
|
@ -41,15 +41,15 @@ GameLib.D3.Mesh = function (
|
||||||
apiMesh.renderOrder
|
apiMesh.renderOrder
|
||||||
);
|
);
|
||||||
|
|
||||||
this.materials = this.materials.map(
|
// this.materials = this.materials.map(
|
||||||
function (apiMaterial) {
|
// function (apiMaterial) {
|
||||||
return new GameLib.D3.Material(
|
// return new GameLib.D3.Material(
|
||||||
this.graphics,
|
// this.graphics,
|
||||||
apiMaterial,
|
// apiMaterial,
|
||||||
imageFactory
|
// imageFactory
|
||||||
)
|
// )
|
||||||
}.bind(this)
|
// }.bind(this)
|
||||||
);
|
// );
|
||||||
|
|
||||||
if (this.skeleton) {
|
if (this.skeleton) {
|
||||||
this.skeleton = new GameLib.D3.Skeleton(
|
this.skeleton = new GameLib.D3.Skeleton(
|
||||||
|
@ -426,7 +426,7 @@ GameLib.D3.Mesh.prototype.toApiMesh = function() {
|
||||||
),
|
),
|
||||||
this.faces,
|
this.faces,
|
||||||
this.faceVertexUvs,
|
this.faceVertexUvs,
|
||||||
this.materials.map(function(material){return material.toApiMaterial()}),
|
this.materials.map(function(material){return material.id}),
|
||||||
GameLib.Utils.IdOrNull(this.parentMesh),
|
GameLib.Utils.IdOrNull(this.parentMesh),
|
||||||
GameLib.Utils.IdOrNull(this.parentScene),
|
GameLib.Utils.IdOrNull(this.parentScene),
|
||||||
apiSkeleton,
|
apiSkeleton,
|
||||||
|
|
|
@ -36,7 +36,8 @@ GameLib.D3.Scene = function Scene(
|
||||||
apiScene.shapes,
|
apiScene.shapes,
|
||||||
apiScene.cameras,
|
apiScene.cameras,
|
||||||
apiScene.activeCameraIndex,
|
apiScene.activeCameraIndex,
|
||||||
apiScene.textures
|
apiScene.textures,
|
||||||
|
apiScene.materials
|
||||||
);
|
);
|
||||||
|
|
||||||
this.meshes = this.meshes.map(
|
this.meshes = this.meshes.map(
|
||||||
|
@ -87,6 +88,16 @@ GameLib.D3.Scene = function Scene(
|
||||||
}.bind(this)
|
}.bind(this)
|
||||||
);
|
);
|
||||||
|
|
||||||
|
this.materials = this.materials.map(
|
||||||
|
function(apiMaterial) {
|
||||||
|
return new GameLib.D3.Material(
|
||||||
|
this.graphics,
|
||||||
|
apiMaterial,
|
||||||
|
this.imageFactory
|
||||||
|
)
|
||||||
|
}.bind(this)
|
||||||
|
);
|
||||||
|
|
||||||
this.position = new GameLib.Vector3(
|
this.position = new GameLib.Vector3(
|
||||||
graphics,
|
graphics,
|
||||||
this,
|
this,
|
||||||
|
@ -113,14 +124,15 @@ GameLib.D3.Scene = function Scene(
|
||||||
"cameras",
|
"cameras",
|
||||||
"meshes",
|
"meshes",
|
||||||
"lights",
|
"lights",
|
||||||
"textures"
|
"textures",
|
||||||
|
"materials"
|
||||||
];
|
];
|
||||||
|
|
||||||
this.idToObject = {};
|
this.idToObject = {};
|
||||||
|
|
||||||
this.idToObject[this.id] = this;
|
this.idToObject[this.id] = this;
|
||||||
|
|
||||||
var material = null;
|
// var material = null;
|
||||||
|
|
||||||
for (var p = 0; p < this.interestingProperties.length; p++) {
|
for (var p = 0; p < this.interestingProperties.length; p++) {
|
||||||
property = this.interestingProperties[p];
|
property = this.interestingProperties[p];
|
||||||
|
@ -144,14 +156,8 @@ GameLib.D3.Scene = function Scene(
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.meshes[m].materials[0]) {
|
if (this.meshes[m].materials[0]) {
|
||||||
|
this.meshes[m].materials[0] = this.idToObject[this.meshes[m].materials[0]];
|
||||||
material = this.meshes[m].materials[0];
|
this.meshes[m].materials[0].diffuseMap = this.idToObject[this.meshes[m].materials[0].diffuseMap];
|
||||||
|
|
||||||
for (var property in material) {
|
|
||||||
if (material.hasOwnProperty(property) && material[property] instanceof GameLib.D3.Texture) {
|
|
||||||
this.idToObject[material[property].id] = material[property];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -10,6 +10,32 @@ GameLib.Utils.Extend = function(
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns id of object with the name if it exists in the array, otherwise null
|
||||||
|
* @param name
|
||||||
|
* @param array
|
||||||
|
* @returns {*}
|
||||||
|
* @constructor
|
||||||
|
*/
|
||||||
|
GameLib.Utils.ObjectIdWithNameInArray = function(name, array) {
|
||||||
|
|
||||||
|
return array.reduce(
|
||||||
|
function(result, object) {
|
||||||
|
|
||||||
|
if (result) {
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (name == object.name) {
|
||||||
|
return object.id;
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
},
|
||||||
|
null
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
// GameLib.Utils.ObjectFactory = function() {
|
// GameLib.Utils.ObjectFactory = function() {
|
||||||
//
|
//
|
||||||
// var promiseList = {};
|
// var promiseList = {};
|
||||||
|
|
Loading…
Reference in New Issue