texture and material loading revamped
parent
9a12e4e3c3
commit
14da18f2e8
|
@ -17,7 +17,10 @@ GameLib.Event.Subscriptions = {};
|
||||||
GameLib.Event.WINDOW_RESIZE = 0x1;
|
GameLib.Event.WINDOW_RESIZE = 0x1;
|
||||||
GameLib.Event.PARENT_SCENE_CHANGE = 0x2;
|
GameLib.Event.PARENT_SCENE_CHANGE = 0x2;
|
||||||
GameLib.Event.PARENT_ENTITY_CHANGE = 0x3;
|
GameLib.Event.PARENT_ENTITY_CHANGE = 0x3;
|
||||||
GameLib.Event.TEXTURE_LOADED = 0x4;
|
GameLib.Event.IMAGE_LOADED = 0x5;
|
||||||
|
GameLib.Event.TEXTURE_LOADED = 0x6;
|
||||||
|
GameLib.Event.LOAD_IMAGE = 0x7;
|
||||||
|
GameLib.Event.MATERIAL_LOADED = 0x8;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Subscribe to some events
|
* Subscribe to some events
|
||||||
|
|
|
@ -539,51 +539,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(
|
||||||
|
|
|
@ -10,6 +10,7 @@
|
||||||
* @param lights [GameLib.D3.API.Light]
|
* @param lights [GameLib.D3.API.Light]
|
||||||
* @param textures [GameLib.D3.API.Texture]
|
* @param textures [GameLib.D3.API.Texture]
|
||||||
* @param materials [GameLib.D3.API.Material]
|
* @param materials [GameLib.D3.API.Material]
|
||||||
|
* @param images
|
||||||
* @param activeCamera [GameLib.D3.Camera]
|
* @param activeCamera [GameLib.D3.Camera]
|
||||||
* @param parentEntity
|
* @param parentEntity
|
||||||
* @constructor
|
* @constructor
|
||||||
|
@ -25,6 +26,7 @@ GameLib.D3.API.Scene = function(
|
||||||
lights,
|
lights,
|
||||||
textures,
|
textures,
|
||||||
materials,
|
materials,
|
||||||
|
images,
|
||||||
activeCamera,
|
activeCamera,
|
||||||
parentEntity
|
parentEntity
|
||||||
) {
|
) {
|
||||||
|
@ -36,6 +38,7 @@ GameLib.D3.API.Scene = function(
|
||||||
'lights' : [GameLib.D3.Light],
|
'lights' : [GameLib.D3.Light],
|
||||||
'textures' : [GameLib.D3.Texture],
|
'textures' : [GameLib.D3.Texture],
|
||||||
'materials' : [GameLib.D3.Material],
|
'materials' : [GameLib.D3.Material],
|
||||||
|
'images' : [GameLib.D3.Image],
|
||||||
'activeCamera' : GameLib.D3.Camera
|
'activeCamera' : GameLib.D3.Camera
|
||||||
},
|
},
|
||||||
false,
|
false,
|
||||||
|
@ -92,6 +95,11 @@ GameLib.D3.API.Scene = function(
|
||||||
}
|
}
|
||||||
this.materials = materials;
|
this.materials = materials;
|
||||||
|
|
||||||
|
if (GameLib.Utils.UndefinedOrNull(images)) {
|
||||||
|
images = [];
|
||||||
|
}
|
||||||
|
this.images = images;
|
||||||
|
|
||||||
if (GameLib.Utils.UndefinedOrNull(activeCamera)) {
|
if (GameLib.Utils.UndefinedOrNull(activeCamera)) {
|
||||||
activeCamera = null;
|
activeCamera = null;
|
||||||
}
|
}
|
||||||
|
@ -113,6 +121,7 @@ GameLib.D3.API.Scene.FromObjectScene = function(objectScene) {
|
||||||
var apiLights = [];
|
var apiLights = [];
|
||||||
var apiTextures = [];
|
var apiTextures = [];
|
||||||
var apiMaterials = [];
|
var apiMaterials = [];
|
||||||
|
var apiImages = [];
|
||||||
|
|
||||||
var apiPosition = new GameLib.API.Vector3();
|
var apiPosition = new GameLib.API.Vector3();
|
||||||
var apiQuaternion = new GameLib.API.Quaternion();
|
var apiQuaternion = new GameLib.API.Quaternion();
|
||||||
|
@ -152,6 +161,14 @@ GameLib.D3.API.Scene.FromObjectScene = function(objectScene) {
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (objectScene.images) {
|
||||||
|
apiImages = objectScene.images.map(
|
||||||
|
function(objectImage) {
|
||||||
|
return GameLib.D3.API.Image.FromObject(objectImage)
|
||||||
|
}
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
if (objectScene.position) {
|
if (objectScene.position) {
|
||||||
apiPosition = GameLib.API.Vector3.FromObjectVector(objectScene.position);
|
apiPosition = GameLib.API.Vector3.FromObjectVector(objectScene.position);
|
||||||
}
|
}
|
||||||
|
@ -179,6 +196,7 @@ GameLib.D3.API.Scene.FromObjectScene = function(objectScene) {
|
||||||
apiLights,
|
apiLights,
|
||||||
apiTextures,
|
apiTextures,
|
||||||
apiMaterials,
|
apiMaterials,
|
||||||
|
apiImages,
|
||||||
apiActiveCamera,
|
apiActiveCamera,
|
||||||
objectScene.parentEntity
|
objectScene.parentEntity
|
||||||
);
|
);
|
||||||
|
|
|
@ -56,7 +56,9 @@ GameLib.D3.API.Texture = function(
|
||||||
GameLib.Component.call(
|
GameLib.Component.call(
|
||||||
this,
|
this,
|
||||||
GameLib.Component.COMPONENT_TEXTURE,
|
GameLib.Component.COMPONENT_TEXTURE,
|
||||||
null,
|
{
|
||||||
|
'image' : GameLib.D3.Image
|
||||||
|
},
|
||||||
null,
|
null,
|
||||||
parentEntity
|
parentEntity
|
||||||
);
|
);
|
||||||
|
|
|
@ -99,7 +99,7 @@ GameLib.D3.ImageFactory.prototype.loadImage = function(
|
||||||
function (image) {
|
function (image) {
|
||||||
|
|
||||||
GameLib.Event.Emit(
|
GameLib.Event.Emit(
|
||||||
GameLib.Event.TEXTURE_LOADED,
|
GameLib.Event.IMAGE_LOADED,
|
||||||
{
|
{
|
||||||
imagePath : imagePath,
|
imagePath : imagePath,
|
||||||
imageInstance : image
|
imageInstance : image
|
||||||
|
|
|
@ -39,16 +39,54 @@ GameLib.D3.Image.prototype.createInstance = function(update) {
|
||||||
|
|
||||||
if (update) {
|
if (update) {
|
||||||
console.log('why the fuck are you updating an image instance?');
|
console.log('why the fuck are you updating an image instance?');
|
||||||
|
if (!this.instance) {
|
||||||
|
console.warn('no image instance');
|
||||||
|
return;
|
||||||
|
}
|
||||||
this.instance.id = this.id;
|
this.instance.id = this.id;
|
||||||
this.instance.name = this.name;
|
this.instance.name = this.name;
|
||||||
this.instance.path = this.path;
|
this.instance.path = this.path;
|
||||||
this.instance.contentType = this.contentType;
|
this.instance.contentType = this.contentType;
|
||||||
} else {
|
} else {
|
||||||
var instance = new THREE.TextureLoader().load(this.path);
|
|
||||||
return instance;
|
|
||||||
}
|
|
||||||
|
|
||||||
return instance;
|
this.subscribe(
|
||||||
|
GameLib.Event.LOAD_IMAGE,
|
||||||
|
function(data) {
|
||||||
|
if (
|
||||||
|
data.id === this.id ||
|
||||||
|
data.path === this.path
|
||||||
|
) {
|
||||||
|
var loader = new THREE.ImageLoader();
|
||||||
|
|
||||||
|
loader.crossOrigin = true;
|
||||||
|
|
||||||
|
loader.path = data.baseUrl;
|
||||||
|
|
||||||
|
loader.load(
|
||||||
|
this.path,
|
||||||
|
function ( image ) {
|
||||||
|
this.instance = image;
|
||||||
|
this.publish(
|
||||||
|
GameLib.Event.IMAGE_LOADED,
|
||||||
|
{
|
||||||
|
imagePath : this.path,
|
||||||
|
imageInstance : this.instance
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}.bind(this),
|
||||||
|
function ( xhr ) {
|
||||||
|
console.log( (xhr.loaded / xhr.total * 100) + '% loaded' );
|
||||||
|
},
|
||||||
|
function () {
|
||||||
|
console.log('An image load error happened');
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -24,7 +24,7 @@ GameLib.D3.Material = function(
|
||||||
|
|
||||||
GameLib.D3.API.Material.call(
|
GameLib.D3.API.Material.call(
|
||||||
this,
|
this,
|
||||||
apiMaterial.id,
|
apiMaterial.id,
|
||||||
apiMaterial.materialType,
|
apiMaterial.materialType,
|
||||||
apiMaterial.name,
|
apiMaterial.name,
|
||||||
apiMaterial.opacity,
|
apiMaterial.opacity,
|
||||||
|
@ -225,6 +225,7 @@ GameLib.D3.Material = function(
|
||||||
|
|
||||||
this.instance = this.createInstance();
|
this.instance = this.createInstance();
|
||||||
|
|
||||||
|
this.updateTextures();
|
||||||
};
|
};
|
||||||
|
|
||||||
GameLib.D3.Material.prototype = Object.create(GameLib.D3.API.Material.prototype);
|
GameLib.D3.Material.prototype = Object.create(GameLib.D3.API.Material.prototype);
|
||||||
|
@ -477,62 +478,62 @@ GameLib.D3.Material.prototype.createMeshBasicMaterialInstance = function() {
|
||||||
* updates textures
|
* updates textures
|
||||||
*/
|
*/
|
||||||
GameLib.D3.Material.prototype.updateTextures = function() {
|
GameLib.D3.Material.prototype.updateTextures = function() {
|
||||||
if (this.alphaMap) {
|
if (this.alphaMap && this.alphaMap.instance) {
|
||||||
this.instance.alphaMap = this.alphaMap.instance;
|
this.instance.alphaMap = this.alphaMap.instance;
|
||||||
} else {
|
} else {
|
||||||
this.instance.alphaMap = null;
|
this.instance.alphaMap = null;
|
||||||
}
|
}
|
||||||
if (this.aoMap) {
|
if (this.aoMap && this.aoMap.instance) {
|
||||||
this.instance.aoMap = this.aoMap.instance;
|
this.instance.aoMap = this.aoMap.instance;
|
||||||
} else {
|
} else {
|
||||||
this.instance.aoMap = null;
|
this.instance.aoMap = null;
|
||||||
}
|
}
|
||||||
if (this.bumpMap) {
|
if (this.bumpMap && this.bumpMap.instance) {
|
||||||
this.instance.bumpMap = this.bumpMap.instance;
|
this.instance.bumpMap = this.bumpMap.instance;
|
||||||
} else {
|
} else {
|
||||||
this.instance.bumpMap = null;
|
this.instance.bumpMap = null;
|
||||||
}
|
}
|
||||||
if (this.diffuseMap) {
|
if (this.diffuseMap && this.diffuseMap.instance) {
|
||||||
this.instance.map = this.diffuseMap.instance;
|
this.instance.map = this.diffuseMap.instance;
|
||||||
} else {
|
} else {
|
||||||
this.instance.map = null;
|
this.instance.map = null;
|
||||||
}
|
}
|
||||||
if (this.displacementMap) {
|
if (this.displacementMap && this.displacementMap.instance) {
|
||||||
this.instance.displacementMap = this.displacementMap.instance;
|
this.instance.displacementMap = this.displacementMap.instance;
|
||||||
} else {
|
} else {
|
||||||
this.instance.displacementMap = null;
|
this.instance.displacementMap = null;
|
||||||
}
|
}
|
||||||
if (this.emissiveMap) {
|
if (this.emissiveMap && this.emissiveMap.instance) {
|
||||||
this.instance.emissiveMap = this.emissiveMap.instance;
|
this.instance.emissiveMap = this.emissiveMap.instance;
|
||||||
} else {
|
} else {
|
||||||
this.instance.emissiveMap = null;
|
this.instance.emissiveMap = null;
|
||||||
}
|
}
|
||||||
if (this.environmentMap) {
|
if (this.environmentMap && this.environmentMap.instance) {
|
||||||
this.instance.envMap = this.environmentMap.instance;
|
this.instance.envMap = this.environmentMap.instance;
|
||||||
} else {
|
} else {
|
||||||
this.instance.envMap = null;
|
this.instance.envMap = null;
|
||||||
}
|
}
|
||||||
if (this.lightMap) {
|
if (this.lightMap && this.lightMap.instance) {
|
||||||
this.instance.lightMap = this.lightMap.instance;
|
this.instance.lightMap = this.lightMap.instance;
|
||||||
} else {
|
} else {
|
||||||
this.instance.lightMap = null;
|
this.instance.lightMap = null;
|
||||||
}
|
}
|
||||||
if (this.metalnessMap) {
|
if (this.metalnessMap && this.metalnessMap.instance) {
|
||||||
this.instance.metalnessMap = this.metalnessMap.instance;
|
this.instance.metalnessMap = this.metalnessMap.instance;
|
||||||
} else {
|
} else {
|
||||||
this.instance.metalnessMap = null;
|
this.instance.metalnessMap = null;
|
||||||
}
|
}
|
||||||
if (this.normalMap) {
|
if (this.normalMap && this.normalMap.instance) {
|
||||||
this.instance.normalMap = this.normalMap.instance;
|
this.instance.normalMap = this.normalMap.instance;
|
||||||
} else {
|
} else {
|
||||||
this.instance.normalMap = null;
|
this.instance.normalMap = null;
|
||||||
}
|
}
|
||||||
if (this.roughnessMap) {
|
if (this.roughnessMap && this.roughnessMap.instance) {
|
||||||
this.instance.roughnessMap = this.roughnessMap.instance;
|
this.instance.roughnessMap = this.roughnessMap.instance;
|
||||||
} else {
|
} else {
|
||||||
this.instance.roughnessMap = null;
|
this.instance.roughnessMap = null;
|
||||||
}
|
}
|
||||||
if (this.specularMap) {
|
if (this.specularMap && this.specularMap.instance) {
|
||||||
this.instance.specularMap = this.specularMap.instance;
|
this.instance.specularMap = this.specularMap.instance;
|
||||||
} else {
|
} else {
|
||||||
this.instance.specularMap = null;
|
this.instance.specularMap = null;
|
||||||
|
@ -581,7 +582,6 @@ GameLib.D3.Material.prototype.updateStandardMaterialInstance = function() {
|
||||||
this.instance.skinning = this.skinning;
|
this.instance.skinning = this.skinning;
|
||||||
this.instance.morphTargets = this.morphTargets;
|
this.instance.morphTargets = this.morphTargets;
|
||||||
this.instance.morphNormals = this.morphNormals;
|
this.instance.morphNormals = this.morphNormals;
|
||||||
this.updateTextures();
|
|
||||||
};
|
};
|
||||||
|
|
||||||
GameLib.D3.Material.prototype.updatePointsMaterialInstance = function() {
|
GameLib.D3.Material.prototype.updatePointsMaterialInstance = function() {
|
||||||
|
@ -609,7 +609,6 @@ GameLib.D3.Material.prototype.updatePointsMaterialInstance = function() {
|
||||||
this.instance.sizeAttenuation = this.pointSizeAttenuation;
|
this.instance.sizeAttenuation = this.pointSizeAttenuation;
|
||||||
this.instance.vertexColors = GameLib.D3.Material.TYPE_NO_COLORS;
|
this.instance.vertexColors = GameLib.D3.Material.TYPE_NO_COLORS;
|
||||||
this.instance.fog = this.fog;
|
this.instance.fog = this.fog;
|
||||||
this.updateTextures();
|
|
||||||
};
|
};
|
||||||
|
|
||||||
GameLib.D3.Material.prototype.updatePhongMaterialInstance = function() {
|
GameLib.D3.Material.prototype.updatePhongMaterialInstance = function() {
|
||||||
|
@ -654,7 +653,6 @@ GameLib.D3.Material.prototype.updatePhongMaterialInstance = function() {
|
||||||
this.instance.skinning = this.skinning;
|
this.instance.skinning = this.skinning;
|
||||||
this.instance.morphTargets = this.morphTargets;
|
this.instance.morphTargets = this.morphTargets;
|
||||||
this.instance.morphNormals = this.morphNormals;
|
this.instance.morphNormals = this.morphNormals;
|
||||||
this.updateTextures();
|
|
||||||
};
|
};
|
||||||
|
|
||||||
GameLib.D3.Material.prototype.updateMeshBasicMaterialInstance = function() {
|
GameLib.D3.Material.prototype.updateMeshBasicMaterialInstance = function() {
|
||||||
|
@ -680,7 +678,6 @@ GameLib.D3.Material.prototype.updateMeshBasicMaterialInstance = function() {
|
||||||
this.instance.color = this.color.instance;
|
this.instance.color = this.color.instance;
|
||||||
this.instance.vertexColors = GameLib.D3.Material.TYPE_NO_COLORS;
|
this.instance.vertexColors = GameLib.D3.Material.TYPE_NO_COLORS;
|
||||||
this.instance.fog = this.fog;
|
this.instance.fog = this.fog;
|
||||||
this.updateTextures();
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -719,6 +716,8 @@ GameLib.D3.Material.prototype.createInstance = function(update) {
|
||||||
console.warn('not yet implemented (material type = ' + this.materialType + ')');
|
console.warn('not yet implemented (material type = ' + this.materialType + ')');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
this.updateTextures();
|
||||||
|
|
||||||
this.instance.needsUpdate = true;
|
this.instance.needsUpdate = true;
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
|
@ -747,6 +746,78 @@ GameLib.D3.Material.prototype.createInstance = function(update) {
|
||||||
|
|
||||||
instance.needsUpdate = true;
|
instance.needsUpdate = true;
|
||||||
|
|
||||||
|
this.subscribe(
|
||||||
|
GameLib.Event.TEXTURE_LOADED,
|
||||||
|
function (data) {
|
||||||
|
|
||||||
|
var modified = false;
|
||||||
|
|
||||||
|
if (this.alphaMap === data.texture) {
|
||||||
|
this.instance.alphaMap = data.texture.instance;
|
||||||
|
modified = true;
|
||||||
|
}
|
||||||
|
if (this.aoMap === data.texture) {
|
||||||
|
this.instance.aoMap = data.texture.instance;
|
||||||
|
modified = true;
|
||||||
|
}
|
||||||
|
if (this.bumpMap === data.texture) {
|
||||||
|
this.instance.bumpMap = data.texture.instance;
|
||||||
|
modified = true;
|
||||||
|
}
|
||||||
|
if (this.diffuseMap === data.texture) {
|
||||||
|
this.instance.map = data.texture.instance;
|
||||||
|
modified = true;
|
||||||
|
}
|
||||||
|
if (this.displacementMap === data.texture) {
|
||||||
|
this.instance.displacementMap = data.texture.instance;
|
||||||
|
modified = true;
|
||||||
|
}
|
||||||
|
if (this.emissiveMap === data.texture) {
|
||||||
|
this.instance.emissiveMap = data.texture.instance;
|
||||||
|
modified = true;
|
||||||
|
}
|
||||||
|
if (this.environmentMap === data.texture) {
|
||||||
|
this.instance.envMap = data.texture.instance;
|
||||||
|
modified = true;
|
||||||
|
}
|
||||||
|
if (this.lightMap === data.texture) {
|
||||||
|
this.instance.lightMap = data.texture.instance;
|
||||||
|
modified = true;
|
||||||
|
}
|
||||||
|
if (this.metalnessMap === data.texture) {
|
||||||
|
this.instance.metalnessMap = data.texture.instance;
|
||||||
|
modified = true;
|
||||||
|
}
|
||||||
|
if (this.normalMap === data.texture) {
|
||||||
|
this.instance.normalMap = data.texture.instance;
|
||||||
|
modified = true;
|
||||||
|
}
|
||||||
|
if (this.roughnessMap === data.texture) {
|
||||||
|
this.instance.roughnessMap = data.texture.instance;
|
||||||
|
modified = true;
|
||||||
|
}
|
||||||
|
if (this.specularMap === data.texture) {
|
||||||
|
this.instance.specularMap = data.texture.instance;
|
||||||
|
modified = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (modified) {
|
||||||
|
|
||||||
|
data.texture.instance.needsUpdate = true;
|
||||||
|
|
||||||
|
this.publish(
|
||||||
|
GameLib.Event.MATERIAL_LOADED,
|
||||||
|
{
|
||||||
|
material: this
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
this.instance.needsUpdate = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
return instance;
|
return instance;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -45,27 +45,18 @@ GameLib.D3.Mesh = function (
|
||||||
apiMesh.renderOrder
|
apiMesh.renderOrder
|
||||||
);
|
);
|
||||||
|
|
||||||
apiMesh.materials = apiMesh.materials.map(function(apiMaterial) {
|
this.materials = this.materials.map(
|
||||||
if (apiMaterial instanceof GameLib.D3.API.Material) {
|
function(material) {
|
||||||
/**
|
if (material instanceof GameLib.D3.API.Material) {
|
||||||
* Do Nothing
|
|
||||||
*/
|
|
||||||
if (apiMaterial instanceof GameLib.D3.Material) {
|
|
||||||
return apiMaterial;
|
|
||||||
} else {
|
|
||||||
return new GameLib.D3.Material(
|
return new GameLib.D3.Material(
|
||||||
this.graphics,
|
this.graphics,
|
||||||
apiMaterial
|
material
|
||||||
);
|
)
|
||||||
|
} else {
|
||||||
|
return material;
|
||||||
}
|
}
|
||||||
} else {
|
}.bind(this)
|
||||||
/**
|
);
|
||||||
* Do Nothing
|
|
||||||
*/
|
|
||||||
}
|
|
||||||
}.bind(this));
|
|
||||||
|
|
||||||
this.materials = apiMesh.materials;
|
|
||||||
|
|
||||||
if (this.skeleton) {
|
if (this.skeleton) {
|
||||||
this.skeleton = new GameLib.D3.Skeleton(
|
this.skeleton = new GameLib.D3.Skeleton(
|
||||||
|
@ -133,7 +124,7 @@ GameLib.D3.Mesh = function (
|
||||||
|
|
||||||
this.buildIdToObject();
|
this.buildIdToObject();
|
||||||
|
|
||||||
this.instance = this.createInstance(false);
|
this.instance = this.createInstance();
|
||||||
|
|
||||||
this.instance.geometry.computeBoundingBox();
|
this.instance.geometry.computeBoundingBox();
|
||||||
|
|
||||||
|
@ -288,14 +279,58 @@ GameLib.D3.Mesh.prototype.customGeometry = function(){
|
||||||
*/
|
*/
|
||||||
GameLib.D3.Mesh.prototype.createInstance = function(update) {
|
GameLib.D3.Mesh.prototype.createInstance = function(update) {
|
||||||
|
|
||||||
var instance = null;
|
|
||||||
|
|
||||||
if (update) {
|
if (update) {
|
||||||
instance = this.instance;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!update) {
|
if (this.parentMesh && this.parentMesh.loaded) {
|
||||||
|
|
||||||
|
this.instance.parent = this.parentMesh.instance;
|
||||||
|
|
||||||
|
this.instance.position.x = this.localPosition.x;
|
||||||
|
this.instance.position.y = this.localPosition.y;
|
||||||
|
this.instance.position.z = this.localPosition.z;
|
||||||
|
|
||||||
|
this.instance.rotation.x = this.localRotation.x;
|
||||||
|
this.instance.rotation.y = this.localRotation.y;
|
||||||
|
this.instance.rotation.z = this.localRotation.z;
|
||||||
|
|
||||||
|
this.instance.scale.x = this.localScale.x;
|
||||||
|
this.instance.scale.y = this.localScale.y;
|
||||||
|
this.instance.scale.z = this.localScale.z;
|
||||||
|
|
||||||
|
} else {
|
||||||
|
this.instance.quaternion.x = this.quaternion.x;
|
||||||
|
this.instance.quaternion.y = this.quaternion.y;
|
||||||
|
this.instance.quaternion.z = this.quaternion.z;
|
||||||
|
this.instance.quaternion.w = this.quaternion.w;
|
||||||
|
|
||||||
|
this.instance.position.x = this.position.x + this.localPosition.x;
|
||||||
|
this.instance.position.y = this.position.y + this.localPosition.y;
|
||||||
|
this.instance.position.z = this.position.z + this.localPosition.z;
|
||||||
|
|
||||||
|
this.instance.scale.x = this.scale.x * this.localScale.x;
|
||||||
|
this.instance.scale.y = this.scale.y * this.localScale.y;
|
||||||
|
this.instance.scale.z = this.scale.z * this.localScale.z;
|
||||||
|
|
||||||
|
this.instance.up.x = this.up.x;
|
||||||
|
this.instance.up.y = this.up.y;
|
||||||
|
this.instance.up.z = this.up.z;
|
||||||
|
|
||||||
|
this.instance.rotateX(this.localRotation.x);
|
||||||
|
this.instance.rotateY(this.localRotation.y);
|
||||||
|
this.instance.rotateZ(this.localRotation.z);
|
||||||
|
}
|
||||||
|
|
||||||
|
this.instance.name = this.name;
|
||||||
|
|
||||||
|
if (this.materials.length === 1 && this.materials[0].instance) {
|
||||||
|
this.instance.material = this.materials[0].instance;
|
||||||
|
}
|
||||||
|
|
||||||
|
this.instance.renderOrder = this.renderOrder;
|
||||||
|
|
||||||
|
} else {
|
||||||
|
|
||||||
|
var instance = null;
|
||||||
var geometry = null;
|
var geometry = null;
|
||||||
|
|
||||||
if (this instanceof GameLib.D3.Mesh.Sphere) {
|
if (this instanceof GameLib.D3.Mesh.Sphere) {
|
||||||
|
@ -309,13 +344,9 @@ GameLib.D3.Mesh.prototype.createInstance = function(update) {
|
||||||
|
|
||||||
if (this.meshType === GameLib.D3.Mesh.TYPE_NORMAL) {
|
if (this.meshType === GameLib.D3.Mesh.TYPE_NORMAL) {
|
||||||
instance = new THREE.Mesh(geometry);
|
instance = new THREE.Mesh(geometry);
|
||||||
}
|
} else if (this.meshType === GameLib.D3.Mesh.TYPE_CURVE) {
|
||||||
|
|
||||||
if (this.meshType === GameLib.D3.Mesh.TYPE_CURVE) {
|
|
||||||
instance = new THREE.Points(geometry);
|
instance = new THREE.Points(geometry);
|
||||||
}
|
} else if (this.meshType === GameLib.D3.Mesh.TYPE_SKINNED) {
|
||||||
|
|
||||||
if (this.meshType === GameLib.D3.Mesh.TYPE_SKINNED) {
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Setup bones (indexes)
|
* Setup bones (indexes)
|
||||||
|
@ -350,84 +381,81 @@ GameLib.D3.Mesh.prototype.createInstance = function(update) {
|
||||||
instance.add(this.skeleton.rootBoneInstance);
|
instance.add(this.skeleton.rootBoneInstance);
|
||||||
|
|
||||||
instance.bind(this.skeleton.instance);
|
instance.bind(this.skeleton.instance);
|
||||||
}
|
} else {
|
||||||
|
|
||||||
if (instance === null) {
|
|
||||||
console.log('cannot handle meshes of type ' + this.meshType + ' yet.');
|
console.log('cannot handle meshes of type ' + this.meshType + ' yet.');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
instance.name = this.name;
|
||||||
|
|
||||||
|
if (this.parentMesh && this.parentMesh.loaded) {
|
||||||
|
|
||||||
|
instance.parent = this.parentMesh.instance;
|
||||||
|
|
||||||
|
instance.position.x = this.localPosition.x;
|
||||||
|
instance.position.y = this.localPosition.y;
|
||||||
|
instance.position.z = this.localPosition.z;
|
||||||
|
|
||||||
|
instance.rotation.x = this.localRotation.x;
|
||||||
|
instance.rotation.y = this.localRotation.y;
|
||||||
|
instance.rotation.z = this.localRotation.z;
|
||||||
|
|
||||||
|
instance.scale.x = this.localScale.x;
|
||||||
|
instance.scale.y = this.localScale.y;
|
||||||
|
instance.scale.z = this.localScale.z;
|
||||||
|
|
||||||
|
} else {
|
||||||
|
instance.quaternion.x = this.quaternion.x;
|
||||||
|
instance.quaternion.y = this.quaternion.y;
|
||||||
|
instance.quaternion.z = this.quaternion.z;
|
||||||
|
instance.quaternion.w = this.quaternion.w;
|
||||||
|
|
||||||
|
instance.position.x = this.position.x + this.localPosition.x;
|
||||||
|
instance.position.y = this.position.y + this.localPosition.y;
|
||||||
|
instance.position.z = this.position.z + this.localPosition.z;
|
||||||
|
|
||||||
|
instance.scale.x = this.scale.x * this.localScale.x;
|
||||||
|
instance.scale.y = this.scale.y * this.localScale.y;
|
||||||
|
instance.scale.z = this.scale.z * this.localScale.z;
|
||||||
|
|
||||||
|
instance.up.x = this.up.x;
|
||||||
|
instance.up.y = this.up.y;
|
||||||
|
instance.up.z = this.up.z;
|
||||||
|
|
||||||
|
instance.rotateX(this.localRotation.x);
|
||||||
|
instance.rotateY(this.localRotation.y);
|
||||||
|
instance.rotateZ(this.localRotation.z);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (this.materials.length === 1 && this.materials[0].instance) {
|
||||||
|
instance.material = this.materials[0].instance;
|
||||||
|
}
|
||||||
|
|
||||||
|
instance.renderOrder = this.renderOrder;
|
||||||
|
|
||||||
|
this.subscribe(
|
||||||
|
GameLib.Event.MATERIAL_LOADED,
|
||||||
|
function(data) {
|
||||||
|
|
||||||
|
if (this.instance.material === data.material.instance) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (this.materials[0] === data.material) {
|
||||||
|
this.instance.material = data.material.instance;
|
||||||
|
this.instance.geometry.uvsNeedUpdate = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
return instance;
|
||||||
}
|
}
|
||||||
|
|
||||||
instance.name = this.name;
|
|
||||||
|
|
||||||
instance.gameLibObject = this;
|
|
||||||
|
|
||||||
if (this.parentMesh && this.parentMesh.loaded) {
|
|
||||||
|
|
||||||
instance.parent = this.parentMesh.instance;
|
|
||||||
|
|
||||||
instance.position.x = this.localPosition.x;
|
|
||||||
instance.position.y = this.localPosition.y;
|
|
||||||
instance.position.z = this.localPosition.z;
|
|
||||||
|
|
||||||
instance.rotation.x = this.localRotation.x;
|
|
||||||
instance.rotation.y = this.localRotation.y;
|
|
||||||
instance.rotation.z = this.localRotation.z;
|
|
||||||
|
|
||||||
instance.scale.x = this.localScale.x;
|
|
||||||
instance.scale.y = this.localScale.y;
|
|
||||||
instance.scale.z = this.localScale.z;
|
|
||||||
|
|
||||||
// this.position.x = this.parentMesh.position.x;
|
|
||||||
// this.position.y = this.parentMesh.position.y;
|
|
||||||
// this.position.z = this.parentMesh.position.z;
|
|
||||||
|
|
||||||
// var euler = new THREE.Euler();
|
|
||||||
//
|
|
||||||
// var worldRotation = this.parentMesh.instance.getWorldRotation();
|
|
||||||
//
|
|
||||||
// this.instance.setRotationFromEuler(euler);
|
|
||||||
|
|
||||||
// this.quaternion.x = this.parentMesh.quaternion.x;
|
|
||||||
// this.quaternion.y = this.parentMesh.quaternion.y;
|
|
||||||
// this.quaternion.z = this.parentMesh.quaternion.z;
|
|
||||||
// this.quaternion.w = this.parentMesh.quaternion.w;
|
|
||||||
} else {
|
|
||||||
instance.quaternion.x = this.quaternion.x;
|
|
||||||
instance.quaternion.y = this.quaternion.y;
|
|
||||||
instance.quaternion.z = this.quaternion.z;
|
|
||||||
instance.quaternion.w = this.quaternion.w;
|
|
||||||
|
|
||||||
instance.position.x = this.position.x + this.localPosition.x;
|
|
||||||
instance.position.y = this.position.y + this.localPosition.y;
|
|
||||||
instance.position.z = this.position.z + this.localPosition.z;
|
|
||||||
|
|
||||||
instance.scale.x = this.scale.x * this.localScale.x;
|
|
||||||
instance.scale.y = this.scale.y * this.localScale.y;
|
|
||||||
instance.scale.z = this.scale.z * this.localScale.z;
|
|
||||||
|
|
||||||
instance.up.x = this.up.x;
|
|
||||||
instance.up.y = this.up.y;
|
|
||||||
instance.up.z = this.up.z;
|
|
||||||
|
|
||||||
instance.rotateX(this.localRotation.x);
|
|
||||||
instance.rotateY(this.localRotation.y);
|
|
||||||
instance.rotateZ(this.localRotation.z);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (this.materials.length === 1 && this.materials[0].instance) {
|
|
||||||
instance.material = this.materials[0].instance;
|
|
||||||
}
|
|
||||||
|
|
||||||
instance.renderOrder = this.renderOrder;
|
|
||||||
|
|
||||||
return instance;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Updates the mesh instance
|
* Updates the mesh instance
|
||||||
*/
|
*/
|
||||||
GameLib.D3.Mesh.prototype.updateInstance = function() {
|
GameLib.D3.Mesh.prototype.updateInstance = function() {
|
||||||
this.instance = this.createInstance(true);
|
this.createInstance(true);
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -32,6 +32,7 @@ GameLib.D3.Scene = function (
|
||||||
apiScene.lights,
|
apiScene.lights,
|
||||||
apiScene.textures,
|
apiScene.textures,
|
||||||
apiScene.materials,
|
apiScene.materials,
|
||||||
|
apiScene.images,
|
||||||
apiScene.activeCamera,
|
apiScene.activeCamera,
|
||||||
apiScene.parentEntity
|
apiScene.parentEntity
|
||||||
);
|
);
|
||||||
|
@ -90,49 +91,69 @@ GameLib.D3.Scene = function (
|
||||||
}.bind(this)
|
}.bind(this)
|
||||||
);
|
);
|
||||||
|
|
||||||
// this.textures = this.textures.map(
|
this.textures = this.textures.map(
|
||||||
// function(apiTexture) {
|
function(apiTexture) {
|
||||||
//
|
|
||||||
// if (apiTexture instanceof GameLib.D3.API.Texture) {
|
if (apiTexture instanceof GameLib.D3.API.Texture) {
|
||||||
// var texture = new GameLib.D3.Texture(
|
var texture = new GameLib.D3.Texture(
|
||||||
// this.graphics,
|
this.graphics,
|
||||||
// apiTexture,
|
apiTexture
|
||||||
// this.imageFactory
|
);
|
||||||
// );
|
|
||||||
//
|
this.idToObject[texture.id] = texture;
|
||||||
// this.idToObject[texture.id] = texture;
|
|
||||||
//
|
return texture;
|
||||||
// return texture;
|
} else {
|
||||||
// } else {
|
console.warn('apiTexture not an instance of API.Texture');
|
||||||
// console.warn('apiTexture not an instance of API.Texture');
|
throw new Error('apiTexture not an instance of API.Texture');
|
||||||
// throw new Error('apiTexture not an instance of API.Texture');
|
}
|
||||||
// }
|
|
||||||
//
|
}.bind(this)
|
||||||
// }.bind(this)
|
);
|
||||||
// );
|
|
||||||
//
|
this.materials = this.materials.map(
|
||||||
// this.materials = this.materials.map(
|
function(apiMaterial) {
|
||||||
// function(apiMaterial) {
|
|
||||||
//
|
if (apiMaterial instanceof GameLib.D3.API.Material) {
|
||||||
// if (apiMaterial instanceof GameLib.D3.API.Material) {
|
|
||||||
//
|
var material = new GameLib.D3.Material(
|
||||||
// var material = new GameLib.D3.Material(
|
this.graphics,
|
||||||
// this.graphics,
|
apiMaterial
|
||||||
// apiMaterial,
|
);
|
||||||
// this.imageFactory
|
|
||||||
// );
|
this.idToObject[material.id] = material;
|
||||||
//
|
|
||||||
// this.idToObject[material.id] = material;
|
return material;
|
||||||
//
|
|
||||||
// return material;
|
} else {
|
||||||
//
|
console.warn('apiMaterial not an instance of API.Material');
|
||||||
// } else {
|
throw new Error('apiMaterial not an instance of API.Material');
|
||||||
// console.warn('apiMaterial not an instance of API.Material');
|
}
|
||||||
// throw new Error('apiMaterial not an instance of API.Material');
|
|
||||||
// }
|
}.bind(this)
|
||||||
//
|
);
|
||||||
// }.bind(this)
|
|
||||||
// );
|
this.images = this.images.map(
|
||||||
|
function(apiImage) {
|
||||||
|
|
||||||
|
if (apiImage instanceof GameLib.D3.API.Image) {
|
||||||
|
|
||||||
|
var image = new GameLib.D3.Image(
|
||||||
|
this.graphics,
|
||||||
|
apiImage
|
||||||
|
);
|
||||||
|
|
||||||
|
this.idToObject[image.id] = image;
|
||||||
|
|
||||||
|
return image;
|
||||||
|
|
||||||
|
} else {
|
||||||
|
console.warn('apiImage not an instance of API.Image');
|
||||||
|
throw new Error('apiImage not an instance of API.Image');
|
||||||
|
}
|
||||||
|
|
||||||
|
}.bind(this)
|
||||||
|
);
|
||||||
|
|
||||||
if (this.activeCamera instanceof GameLib.D3.API.Camera) {
|
if (this.activeCamera instanceof GameLib.D3.API.Camera) {
|
||||||
this.activeCamera = new GameLib.D3.Camera(
|
this.activeCamera = new GameLib.D3.Camera(
|
||||||
|
@ -258,7 +279,8 @@ GameLib.D3.Scene.prototype.addMesh = function(mesh) {
|
||||||
mesh = new GameLib.D3.Mesh(
|
mesh = new GameLib.D3.Mesh(
|
||||||
this.graphics,
|
this.graphics,
|
||||||
mesh
|
mesh
|
||||||
)
|
);
|
||||||
|
this.meshes.push(mesh);
|
||||||
}
|
}
|
||||||
|
|
||||||
mesh.parentScene = this;
|
mesh.parentScene = this;
|
||||||
|
|
|
@ -58,10 +58,12 @@ GameLib.D3.Texture = function(
|
||||||
this
|
this
|
||||||
);
|
);
|
||||||
|
|
||||||
this.image = new GameLib.D3.Image(
|
if (this.image instanceof GameLib.D3.API.Image) {
|
||||||
this.graphics,
|
this.image = new GameLib.D3.Image(
|
||||||
this.image
|
this.graphics,
|
||||||
);
|
this.image
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
this.instance = this.createInstance();
|
this.instance = this.createInstance();
|
||||||
};
|
};
|
||||||
|
@ -157,7 +159,13 @@ GameLib.D3.Texture.TEXTURE_TYPE_SPECULAR = 'specular';
|
||||||
* @returns {*}
|
* @returns {*}
|
||||||
*/
|
*/
|
||||||
GameLib.D3.Texture.prototype.createInstance = function(update) {
|
GameLib.D3.Texture.prototype.createInstance = function(update) {
|
||||||
|
|
||||||
if (update) {
|
if (update) {
|
||||||
|
|
||||||
|
if (!this.instance) {
|
||||||
|
console.warn('trying to update a non-existent texture instance');
|
||||||
|
return;
|
||||||
|
}
|
||||||
this.instance.name = this.name;
|
this.instance.name = this.name;
|
||||||
this.instance.flipY = this.flipY;
|
this.instance.flipY = this.flipY;
|
||||||
this.instance.encoding = this.encoding;
|
this.instance.encoding = this.encoding;
|
||||||
|
@ -165,18 +173,68 @@ GameLib.D3.Texture.prototype.createInstance = function(update) {
|
||||||
this.instance.offset.y = this.offset.y;
|
this.instance.offset.y = this.offset.y;
|
||||||
this.instance.repeat.x = this.repeat.x;
|
this.instance.repeat.x = this.repeat.x;
|
||||||
this.instance.repeat.y = this.repeat.y;
|
this.instance.repeat.y = this.repeat.y;
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
var instance = new THREE.Texture(
|
|
||||||
this.image.instance
|
if (this.image instanceof GameLib.D3.Image) {
|
||||||
|
|
||||||
|
if (this.image.instance) {
|
||||||
|
|
||||||
|
var instance = new THREE.Texture(
|
||||||
|
this.image.instance
|
||||||
|
);
|
||||||
|
instance.name = this.name;
|
||||||
|
instance.flipY = this.flipY;
|
||||||
|
instance.encoding = this.encoding;
|
||||||
|
instance.offset.x = this.offset.x;
|
||||||
|
instance.offset.y = this.offset.y;
|
||||||
|
instance.repeat.x = this.repeat.x;
|
||||||
|
instance.repeat.y = this.repeat.y;
|
||||||
|
|
||||||
|
return instance;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
this.subscribe(
|
||||||
|
GameLib.Event.IMAGE_LOADED,
|
||||||
|
function (data) {
|
||||||
|
|
||||||
|
if (!(this.image instanceof GameLib.D3.Image)) {
|
||||||
|
console.warn('The image associated with this texture has not been setup properly - did you link the objects?')
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (this.instance) {
|
||||||
|
/**
|
||||||
|
* The texture has already been loaded
|
||||||
|
*/
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (data.imagePath === this.image.path) {
|
||||||
|
var instance = new THREE.Texture(
|
||||||
|
data.imageInstance
|
||||||
|
);
|
||||||
|
instance.name = this.name;
|
||||||
|
instance.flipY = this.flipY;
|
||||||
|
instance.encoding = this.encoding;
|
||||||
|
instance.offset.x = this.offset.x;
|
||||||
|
instance.offset.y = this.offset.y;
|
||||||
|
instance.repeat.x = this.repeat.x;
|
||||||
|
instance.repeat.y = this.repeat.y;
|
||||||
|
this.instance = instance;
|
||||||
|
|
||||||
|
this.publish(
|
||||||
|
GameLib.Event.TEXTURE_LOADED,
|
||||||
|
{
|
||||||
|
texture : this
|
||||||
|
}
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
);
|
);
|
||||||
instance.name = this.name;
|
|
||||||
instance.flipY = this.flipY;
|
return null;
|
||||||
instance.encoding = this.encoding;
|
|
||||||
instance.offset.x = this.offset.x;
|
|
||||||
instance.offset.y = this.offset.y;
|
|
||||||
instance.repeat.x = this.repeat.x;
|
|
||||||
instance.repeat.y = this.repeat.y;
|
|
||||||
return instance;
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -193,16 +251,11 @@ GameLib.D3.Texture.prototype.updateInstance = function() {
|
||||||
*/
|
*/
|
||||||
GameLib.D3.Texture.prototype.toApiObject = function() {
|
GameLib.D3.Texture.prototype.toApiObject = function() {
|
||||||
|
|
||||||
var apiImage = null;
|
|
||||||
if (this.image) {
|
|
||||||
apiImage = this.image.toApiObject();
|
|
||||||
}
|
|
||||||
|
|
||||||
return new GameLib.D3.API.Texture(
|
return new GameLib.D3.API.Texture(
|
||||||
this.id,
|
this.id,
|
||||||
this.typeId,
|
this.typeId,
|
||||||
this.name,
|
this.name,
|
||||||
apiImage,
|
this.image.id,
|
||||||
this.wrapS,
|
this.wrapS,
|
||||||
this.wrapT,
|
this.wrapT,
|
||||||
this.repeat.toApiObject(),
|
this.repeat.toApiObject(),
|
||||||
|
|
|
@ -394,74 +394,6 @@ GameLib.EntityManager.prototype.onParentEntityChange = function(data) {
|
||||||
data.newEntity.addComponent(data.object);
|
data.newEntity.addComponent(data.object);
|
||||||
};
|
};
|
||||||
|
|
||||||
GameLib.EntityManager.prototype.onTextureLoaded = function(data) {
|
|
||||||
|
|
||||||
var allGuis = [];
|
|
||||||
|
|
||||||
this.entities.map(
|
|
||||||
|
|
||||||
function(entity) {
|
|
||||||
|
|
||||||
var materials = entity.getComponents(GameLib.D3.Material);
|
|
||||||
|
|
||||||
materials.map(
|
|
||||||
|
|
||||||
function(material) {
|
|
||||||
|
|
||||||
for (var property in material.linkedObjects) {
|
|
||||||
if (
|
|
||||||
material.linkedObjects.hasOwnProperty(property) &&
|
|
||||||
material.linkedObjects[property] === GameLib.D3.Texture &&
|
|
||||||
material[property]
|
|
||||||
) {
|
|
||||||
var texture = material[property];
|
|
||||||
|
|
||||||
var dataImagePath = GameLib.Utils.StripImageExtension(data.imagePath);
|
|
||||||
var textureImagePath = GameLib.Utils.StripImageExtension(texture.imagePath);
|
|
||||||
|
|
||||||
if (dataImagePath === textureImagePath) {
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Update the image path in case the file extension changed
|
|
||||||
* @type {*}
|
|
||||||
*/
|
|
||||||
texture.imagePath = data.imagePath;
|
|
||||||
|
|
||||||
texture.imageInstance = data.imageInstance;
|
|
||||||
|
|
||||||
if (texture.instance) {
|
|
||||||
texture.updateInstance();
|
|
||||||
} else {
|
|
||||||
texture.instance = texture.createInstance();
|
|
||||||
}
|
|
||||||
|
|
||||||
texture.instance.needsUpdate = true;
|
|
||||||
|
|
||||||
material.updateInstance();
|
|
||||||
|
|
||||||
material.instance.needsUpdate = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
);
|
|
||||||
|
|
||||||
var guis = entity.getComponents(GameLib.GUI);
|
|
||||||
|
|
||||||
guis.map(function(gui) {
|
|
||||||
allGuis.push(gui);
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
);
|
|
||||||
|
|
||||||
allGuis.map(function(gui){
|
|
||||||
gui.build(this);
|
|
||||||
}.bind(this))
|
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
@ -477,11 +409,6 @@ GameLib.EntityManager.prototype.registerCallbacks = function() {
|
||||||
this.onParentEntityChange
|
this.onParentEntityChange
|
||||||
);
|
);
|
||||||
|
|
||||||
this.subscribe(
|
|
||||||
GameLib.Event.TEXTURE_LOADED,
|
|
||||||
this.onTextureLoaded
|
|
||||||
)
|
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in New Issue