textures and materials stored to scene

beta.r3js.org
Theunis J. Botha 2017-01-31 11:37:55 +01:00
parent c3d51b5549
commit f701370f5d
2 changed files with 85 additions and 2 deletions

View File

@ -20,6 +20,8 @@ GameLib.D3.API.Scene = function(
scale,
parentGameId,
lights,
textures,
materials,
parentEntity
) {
GameLib.Component.call(
@ -28,6 +30,8 @@ GameLib.D3.API.Scene = function(
{
'meshes' : [GameLib.D3.Mesh],
'lights' : [GameLib.D3.Light],
'textures' : [GameLib.D3.Texture],
'materials' : [GameLib.D3.Material],
'imageFactory' : GameLib.D3.ImageFactory
},
false,
@ -74,6 +78,16 @@ GameLib.D3.API.Scene = function(
}
this.lights = lights;
if (GameLib.Utils.UndefinedOrNull(textures)) {
textures = [];
}
this.textures = textures;
if (GameLib.Utils.UndefinedOrNull(materials)) {
materials = [];
}
this.materials = materials;
};
GameLib.D3.API.Scene.prototype = Object.create(GameLib.Component.prototype);
@ -88,6 +102,8 @@ GameLib.D3.API.Scene.FromObjectScene = function(objectScene) {
var apiMeshes = [];
var apiLights = [];
var apiTextures = [];
var apiMaterials = [];
var apiPosition = new GameLib.API.Vector3();
var apiQuaternion = new GameLib.API.Quaternion();
@ -109,6 +125,22 @@ GameLib.D3.API.Scene.FromObjectScene = function(objectScene) {
)
}
if (objectScene.textures) {
apiTextures = objectScene.textures.map(
function(objectTexture) {
return GameLib.D3.API.Texture.FromObjectTexture(objectTexture)
}
)
}
if (objectScene.materials) {
apiMaterials = objectScene.materials.map(
function(objectMaterial) {
return GameLib.D3.API.Material.FromObjectMaterial(objectMaterial)
}
)
}
if (objectScene.position) {
apiPosition = GameLib.API.Vector3.FromObjectVector(objectScene.position);
}
@ -130,6 +162,8 @@ GameLib.D3.API.Scene.FromObjectScene = function(objectScene) {
apiScale,
objectScene.parentGameId,
apiLights,
apiTextures,
apiMaterials,
objectScene.parentEntity
);

View File

@ -35,8 +35,8 @@ GameLib.D3.Scene = function (
apiScene.scale,
apiScene.parentGameId,
apiScene.lights,
apiScene.textures,
apiScene.materials,
apiScene.textures,
apiScene.parentEntity
);
@ -102,6 +102,42 @@ GameLib.D3.Scene = function (
}.bind(this)
);
this.textures = this.textures.map(
function(apiTexture) {
if (apiTexture instanceof GameLib.D3.API.Texture) {
return new GameLib.D3.Texture(
this.graphics,
apiTexture,
null,
null,
this.imageFactory
);
} else {
console.warn('apiTexture not an instance of API.Texture');
throw new Error('apiTexture not an instance of API.Texture');
}
}.bind(this)
);
this.materials = this.materials.map(
function(apiMaterial) {
if (apiMaterial instanceof GameLib.D3.API.Material) {
return new GameLib.D3.Material(
this.graphics,
apiMaterial,
this.imageFactory
);
} else {
console.warn('apiMaterial not an instance of API.Material');
throw new Error('apiMaterial not an instance of API.Material');
}
}.bind(this)
);
this.buildIdToObject();
this.instance = this.createInstance();
@ -155,6 +191,18 @@ GameLib.D3.Scene.prototype.toApiScene = function() {
}
);
var apiTextures = this.textures.map(
function(texture) {
return texture.toApiTexture();
}
);
var apiMaterials = this.materials.map(
function(material) {
return material.toApiMaterial();
}
);
return new GameLib.D3.API.Scene(
this.id,
this.name,
@ -164,6 +212,8 @@ GameLib.D3.Scene.prototype.toApiScene = function() {
this.scale.toApiVector(),
this.parentGameId,
apiLights,
apiTextures,
apiMaterials,
GameLib.Utils.IdOrNull(this.parentEntity)
);
};
@ -191,7 +241,6 @@ GameLib.D3.Scene.FromObjectScene = function(
imageFactory,
computeNormals
);
};
/**