textures and materials stored to scene
parent
c3d51b5549
commit
f701370f5d
|
@ -20,6 +20,8 @@ GameLib.D3.API.Scene = function(
|
||||||
scale,
|
scale,
|
||||||
parentGameId,
|
parentGameId,
|
||||||
lights,
|
lights,
|
||||||
|
textures,
|
||||||
|
materials,
|
||||||
parentEntity
|
parentEntity
|
||||||
) {
|
) {
|
||||||
GameLib.Component.call(
|
GameLib.Component.call(
|
||||||
|
@ -28,6 +30,8 @@ GameLib.D3.API.Scene = function(
|
||||||
{
|
{
|
||||||
'meshes' : [GameLib.D3.Mesh],
|
'meshes' : [GameLib.D3.Mesh],
|
||||||
'lights' : [GameLib.D3.Light],
|
'lights' : [GameLib.D3.Light],
|
||||||
|
'textures' : [GameLib.D3.Texture],
|
||||||
|
'materials' : [GameLib.D3.Material],
|
||||||
'imageFactory' : GameLib.D3.ImageFactory
|
'imageFactory' : GameLib.D3.ImageFactory
|
||||||
},
|
},
|
||||||
false,
|
false,
|
||||||
|
@ -74,6 +78,16 @@ GameLib.D3.API.Scene = function(
|
||||||
}
|
}
|
||||||
this.lights = lights;
|
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);
|
GameLib.D3.API.Scene.prototype = Object.create(GameLib.Component.prototype);
|
||||||
|
@ -88,6 +102,8 @@ GameLib.D3.API.Scene.FromObjectScene = function(objectScene) {
|
||||||
|
|
||||||
var apiMeshes = [];
|
var apiMeshes = [];
|
||||||
var apiLights = [];
|
var apiLights = [];
|
||||||
|
var apiTextures = [];
|
||||||
|
var apiMaterials = [];
|
||||||
|
|
||||||
var apiPosition = new GameLib.API.Vector3();
|
var apiPosition = new GameLib.API.Vector3();
|
||||||
var apiQuaternion = new GameLib.API.Quaternion();
|
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) {
|
if (objectScene.position) {
|
||||||
apiPosition = GameLib.API.Vector3.FromObjectVector(objectScene.position);
|
apiPosition = GameLib.API.Vector3.FromObjectVector(objectScene.position);
|
||||||
}
|
}
|
||||||
|
@ -130,6 +162,8 @@ GameLib.D3.API.Scene.FromObjectScene = function(objectScene) {
|
||||||
apiScale,
|
apiScale,
|
||||||
objectScene.parentGameId,
|
objectScene.parentGameId,
|
||||||
apiLights,
|
apiLights,
|
||||||
|
apiTextures,
|
||||||
|
apiMaterials,
|
||||||
objectScene.parentEntity
|
objectScene.parentEntity
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
|
@ -35,8 +35,8 @@ GameLib.D3.Scene = function (
|
||||||
apiScene.scale,
|
apiScene.scale,
|
||||||
apiScene.parentGameId,
|
apiScene.parentGameId,
|
||||||
apiScene.lights,
|
apiScene.lights,
|
||||||
|
apiScene.textures,
|
||||||
apiScene.materials,
|
apiScene.materials,
|
||||||
apiScene.textures,
|
|
||||||
apiScene.parentEntity
|
apiScene.parentEntity
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -102,6 +102,42 @@ GameLib.D3.Scene = function (
|
||||||
}.bind(this)
|
}.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.buildIdToObject();
|
||||||
|
|
||||||
this.instance = this.createInstance();
|
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(
|
return new GameLib.D3.API.Scene(
|
||||||
this.id,
|
this.id,
|
||||||
this.name,
|
this.name,
|
||||||
|
@ -164,6 +212,8 @@ GameLib.D3.Scene.prototype.toApiScene = function() {
|
||||||
this.scale.toApiVector(),
|
this.scale.toApiVector(),
|
||||||
this.parentGameId,
|
this.parentGameId,
|
||||||
apiLights,
|
apiLights,
|
||||||
|
apiTextures,
|
||||||
|
apiMaterials,
|
||||||
GameLib.Utils.IdOrNull(this.parentEntity)
|
GameLib.Utils.IdOrNull(this.parentEntity)
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
@ -191,7 +241,6 @@ GameLib.D3.Scene.FromObjectScene = function(
|
||||||
imageFactory,
|
imageFactory,
|
||||||
computeNormals
|
computeNormals
|
||||||
);
|
);
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in New Issue