scene render camera back

beta.r3js.org
-=yb4f310 2018-01-15 18:37:59 +01:00
parent a09db70d07
commit 40d66dd5db
5 changed files with 78 additions and 163 deletions

View File

@ -12,6 +12,7 @@
* @param showAxis
* @param gridSize
* @param gridColor
* @param camera - this overrides the renderer camera
* @param parentEntity
* @constructor
*/
@ -28,6 +29,7 @@ GameLib.D3.API.Scene = function(
showAxis,
gridSize,
gridColor,
camera,
parentEntity
) {
@ -91,6 +93,11 @@ GameLib.D3.API.Scene = function(
}
this.gridColor = gridColor;
if (GameLib.Utils.UndefinedOrNull(camera)) {
camera = null;
}
this.camera = camera;
GameLib.API.Component.call(
this,
GameLib.Component.SCENE,
@ -100,95 +107,4 @@ GameLib.D3.API.Scene = function(
};
GameLib.D3.API.Scene.prototype = Object.create(GameLib.API.Component.prototype);
GameLib.D3.API.Scene.prototype.constructor = GameLib.D3.API.Scene;
/**
* Returns an API scene from an Object scene
* @param objectScene
* @constructor
*/
GameLib.D3.API.Scene.FromObject = function(objectScene) {
var apiMeshes = [];
var apiLights = [];
var apiTextures = [];
var apiMaterials = [];
var apiImages = [];
if (objectScene.meshes) {
apiMeshes = objectScene.meshes.map(
function(objectMesh) {
if (objectMesh instanceof Object){
return GameLib.D3.API.Mesh.FromObject(objectMesh);
} else {
return objectMesh;
}
}
)
}
if (objectScene.lights) {
apiLights = objectScene.lights.map(
function(objectLight) {
if (objectLight instanceof Object) {
return GameLib.D3.API.Light.FromObject(objectLight);
} else {
return objectLight;
}
}
)
}
if (objectScene.textures) {
apiTextures = objectScene.textures.map(
function(objectTexture) {
if (objectTexture instanceof Object) {
return GameLib.D3.API.Texture.FromObject(objectTexture)
} else {
return objectTexture;
}
}
)
}
if (objectScene.materials) {
apiMaterials = objectScene.materials.map(
function(objectMaterial) {
if (objectMaterial instanceof Object) {
return GameLib.D3.API.Material.FromObject(objectMaterial)
} else {
return objectMaterial;
}
}
)
}
if (objectScene.images) {
apiImages = objectScene.images.map(
function(objectImage) {
if (objectImage instanceof Object) {
return GameLib.API.Image.FromObject(objectImage)
} else {
return objectImage;
}
}
)
}
return new GameLib.D3.API.Scene(
objectScene.id,
objectScene.name,
apiMeshes,
apiLights,
apiTextures,
apiMaterials,
apiImages,
objectScene.fog,
objectScene.showGrid,
objectScene.showAxis,
objectScene.gridSize,
GameLib.API.Color.FromObject(objectScene.gridColor),
objectScene.parentEntity
);
};
GameLib.D3.API.Scene.prototype.constructor = GameLib.D3.API.Scene;

View File

@ -30,6 +30,7 @@ GameLib.D3.Scene = function (
apiScene.showAxis,
apiScene.gridSize,
apiScene.gridColor,
apiScene.camera,
apiScene.parentEntity
);
@ -124,6 +125,13 @@ GameLib.D3.Scene = function (
this
);
if (this.camera instanceof GameLib.D3.API.Camera) {
this.camera = new GameLib.D3.Camera(
this.graphics,
this.camera
)
}
/**
* Runtime scenes have helpers (just used to store which helper belongs to which scene)
* @type {Array}
@ -146,7 +154,8 @@ GameLib.D3.Scene = function (
'textures' : [GameLib.D3.Texture],
'materials' : [GameLib.D3.Material],
'images' : [GameLib.Image],
'fog' : GameLib.D3.Fog
'fog' : GameLib.D3.Fog,
'camera' : GameLib.D3.Camera
}
);
};
@ -302,7 +311,6 @@ GameLib.D3.Scene.prototype.updateInstance = function(property) {
} else {
this.removeAxis();
}
}
};
@ -374,30 +382,11 @@ GameLib.D3.Scene.prototype.toApiObject = function() {
this.showAxis,
this.gridSize,
this.gridColor.toApiObject(),
GameLib.Utils.IdOrNull(this.camera),
GameLib.Utils.IdOrNull(this.parentEntity)
);
};
/**
* Converts a scene Object to a GameLib.D3.Scene object
* @param graphics GameLib.GraphicsRuntime
* @param objectScene Object
* @returns {GameLib.D3.Scene}
* @constructor
*/
GameLib.D3.Scene.FromObject = function(
graphics,
objectScene
) {
var apiScene = GameLib.D3.API.Scene.FromObject(objectScene);
return new GameLib.D3.Scene(
graphics,
apiScene
);
};
/**
* Adds a mesh to the scene
* @param object GameLib.D3.Mesh

View File

@ -211,55 +211,61 @@ GameLib.D3.Texture.prototype.updateInstance = function(property) {
throw new Error('need to specify a property');
}
if (property === 'image') {
if (
property === 'textureType' ||
property === 'image'
) {
this.createInstance();
// }
//
// if (property === 'image') {
if (this.textureType === GameLib.D3.API.Texture.TEXTURE_TYPE_NORMAL) {
if (
GameLib.Utils.UndefinedOrNull(this.image) &&
this.instance.image
) {
try {
this.createInstance();
} catch (error) {
console.error(error);
}
}
if (this.image && this.image.instance && this.instance.image !== this.image.instance) {
try {
this.createInstance();
} catch (error) {
console.error(error);
}
}
} else if (this.textureType === GameLib.D3.API.Texture.TEXTURE_TYPE_CANVAS) {
if (
GameLib.Utils.UndefinedOrNull(this.canvas) &&
this.instance.canvas
) {
try {
this.createInstance();
} catch (error) {
console.error(error);
}
}
if (this.canvas && this.canvas.instance && this.instance.image !== this.canvas.instance) {
try {
this.createInstance();
} catch (error) {
console.error(error);
}
}
} else if (this.textureType === GameLib.D3.API.Texture.TEXTURE_TYPE_CUBE) {
console.log('todo : cube images change check here');
}
// if (this.textureType === GameLib.D3.API.Texture.TEXTURE_TYPE_NORMAL) {
//
// if (
// GameLib.Utils.UndefinedOrNull(this.image) &&
// this.instance.image
// ) {
// try {
// this.createInstance();
// } catch (error) {
// console.error(error);
// }
// }
//
// if (this.image && this.image.instance && this.instance.image !== this.image.instance) {
// try {
// this.createInstance();
// } catch (error) {
// console.error(error);
// }
// }
//
// } else if (this.textureType === GameLib.D3.API.Texture.TEXTURE_TYPE_CANVAS) {
//
// if (
// GameLib.Utils.UndefinedOrNull(this.canvas) &&
// this.instance.canvas
// ) {
// try {
// this.createInstance();
// } catch (error) {
// console.error(error);
// }
// }
//
// if (this.canvas && this.canvas.instance && this.instance.image !== this.canvas.instance) {
// try {
// this.createInstance();
// } catch (error) {
// console.error(error);
// }
// }
//
// } else if (this.textureType === GameLib.D3.API.Texture.TEXTURE_TYPE_CUBE) {
//
// console.log('todo : cube images change check here');
// }
this.publish(
GameLib.Event.IMAGE_CHANGED,

View File

@ -1422,7 +1422,7 @@ GameLib.System.GUI.prototype.buildControl = function(folder, componentTemplate,
property === 'width' ||
property === 'height'
) {
controllers.push(folder.add(object, property, 0, 1, 0.001));
controllers.push(folder.add(object, property, 0, 1000, 0.001));
} else if (
property === 'depth' ||
property === 'radius'

View File

@ -250,6 +250,10 @@ GameLib.System.Render.prototype.render = function(data) {
var camera = renderer.camera;
if (scene.camera && scene.camera.instance) {
camera = scene.camera;
}
if (renderer.renderMode === GameLib.D3.API.Renderer.MODE_EDIT) {
if (!renderer.editCamera || !renderer.editCamera.instance) {