store last render mode - use this for edit mode for renderer

beta.r3js.org
-=yb4f310 2018-01-12 10:22:14 +01:00
parent af43128b0f
commit c428e635c4
9 changed files with 103 additions and 61 deletions

View File

@ -37,7 +37,7 @@ GameLib.Canvas.prototype.createInstance = function() {
this.instance.setAttribute('id', this.id);
this.instance.setAttribute('tabindex', '1');
this.width = Math.round(this.width);
this.height = Math.round(this.height);

View File

@ -5,6 +5,7 @@
* @param width
* @param height
* @param renderMode
* @param lastRenderMode
* @param autoClear
* @param autoClearColor
* @param autoClearDepth
@ -32,6 +33,7 @@
* @param depth
* @param logarithmicDepthBuffer
* @param fullscreen
* @param windowSize
* @param offset
* @param canvas
* @param renderTarget
@ -39,6 +41,7 @@
* @param clippingPlanes
* @param clearColor
* @param camera
* @param editCamera
* @param scenes
* @param defaultScene
* @param viewports
@ -51,6 +54,7 @@ GameLib.D3.API.Renderer = function (
width,
height,
renderMode,
lastRenderMode,
autoClear,
autoClearColor,
autoClearDepth,
@ -86,6 +90,7 @@ GameLib.D3.API.Renderer = function (
clippingPlanes,
clearColor,
camera,
editCamera,
scenes,
defaultScene,
viewports,
@ -116,6 +121,11 @@ GameLib.D3.API.Renderer = function (
}
this.renderMode = renderMode;
if (GameLib.Utils.UndefinedOrNull(lastRenderMode)) {
lastRenderMode = this.renderMode;
}
this.lastRenderMode = lastRenderMode;
if (GameLib.Utils.UndefinedOrNull(autoClear)) {
autoClear = true;
}
@ -305,6 +315,17 @@ GameLib.D3.API.Renderer = function (
}
this.camera = camera;
if (GameLib.Utils.UndefinedOrNull(editCamera)) {
editCamera = new GameLib.D3.API.Camera(
null,
GameLib.D3.API.Camera.PERSPECTIVE_CAMERA,
null,
null,
this.width / this.height
);
}
this.editCamera = editCamera;
if (GameLib.Utils.UndefinedOrNull(scenes)) {
scenes = [new GameLib.D3.API.Scene()];
}
@ -341,6 +362,7 @@ GameLib.D3.API.Renderer.prototype.constructor = GameLib.D3.API.Renderer;
GameLib.D3.API.Renderer.MODE_CANVAS = 0x1;
GameLib.D3.API.Renderer.MODE_TARGET = 0x2;
GameLib.D3.API.Renderer.MODE_CANVAS_AND_TARGET = 0x3;
GameLib.D3.API.Renderer.MODE_EDIT = 0x4;
GameLib.D3.API.Renderer.SHADOW_MAP_TYPE_BASIC = 0;
GameLib.D3.API.Renderer.SHADOW_MAP_TYPE_PCF = 1;
@ -364,6 +386,7 @@ GameLib.D3.API.Renderer.FromObject = function(objectRenderer) {
objectRenderer.width,
objectRenderer.height,
objectRenderer.renderMode,
objectRenderer.lastRenderMode,
objectRenderer.autoClear,
objectRenderer.autoClearColor,
objectRenderer.autoClearDepth,
@ -399,6 +422,7 @@ GameLib.D3.API.Renderer.FromObject = function(objectRenderer) {
objectRenderer.clippingPlanes,
GameLib.API.Color.FromObject(objectRenderer.clearColor),
objectRenderer.camera,
objectRenderer.editCamera,
objectRenderer.scenes,
objectRenderer.defaultScene,
objectRenderer.viewports,

View File

@ -8,7 +8,6 @@
* @param materials [GameLib.D3.API.Material]
* @param images
* @param fog
* @param renderCamera - this is a camera which takes precedence over the renderer camera at time of render
* @param showGrid
* @param showAxis
* @param gridSize
@ -25,7 +24,6 @@ GameLib.D3.API.Scene = function(
materials,
images,
fog,
renderCamera,
showGrid,
showAxis,
gridSize,
@ -73,11 +71,6 @@ GameLib.D3.API.Scene = function(
}
this.fog = fog;
if (GameLib.Utils.UndefinedOrNull(renderCamera)) {
renderCamera = null;
}
this.renderCamera = renderCamera;
if (GameLib.Utils.UndefinedOrNull(showGrid)) {
showGrid = true;
}
@ -191,7 +184,6 @@ GameLib.D3.API.Scene.FromObject = function(objectScene) {
apiMaterials,
apiImages,
objectScene.fog,
objectScene.renderCamera,
objectScene.showGrid,
objectScene.showAxis,
objectScene.gridSize,

View File

@ -217,8 +217,8 @@ GameLib.D3.Mesh.Plane.prototype.generateDotMap = function() {
this.dots.map(
function(dot){
this.parentScene.instance.remove(dot);
dot.geometry.dispose();
// this.parentScene.instance.remove(dot);
// dot.geometry.dispose();
}.bind(this)
);
@ -233,7 +233,10 @@ GameLib.D3.Mesh.Plane.prototype.generateDotMap = function() {
for (var y = 0; y < height; y++ ) {
var geometry = new THREE.BoxBufferGeometry(0.5,0.5,0.5);
var dot = new THREE.Mesh(geometry, this.materials[0].instance);
var materialInstance = this.materials[0].instance;
var dot = new THREE.Mesh(geometry, materialInstance);
dot.position.x = x;
dot.position.y = y;
dot.position.z = data[(y * width) + x];

View File

@ -23,6 +23,7 @@ GameLib.D3.Renderer = function (
apiRenderer.width,
apiRenderer.height,
apiRenderer.renderMode,
apiRenderer.lastRenderMode,
apiRenderer.autoClear,
apiRenderer.autoClearColor,
apiRenderer.autoClearDepth,
@ -58,6 +59,7 @@ GameLib.D3.Renderer = function (
apiRenderer.clippingPlanes,
apiRenderer.clearColor,
apiRenderer.camera,
apiRenderer.editCamera,
apiRenderer.scenes,
apiRenderer.defaultScene,
apiRenderer.viewports,
@ -113,6 +115,13 @@ GameLib.D3.Renderer = function (
)
}
if (this.editCamera instanceof GameLib.D3.API.Camera) {
this.editCamera = new GameLib.D3.Camera(
this.graphics,
this.editCamera
)
}
this.scenes = this.scenes.map(function(scene){
if (scene instanceof GameLib.D3.API.Scene) {
@ -149,6 +158,7 @@ GameLib.D3.Renderer = function (
'renderTarget' : GameLib.D3.RenderTarget,
'clippingPlanes': [GameLib.Plane],
'camera' : GameLib.D3.Camera,
'editCamera' : GameLib.D3.Camera,
'scenes' : [GameLib.D3.Scene],
'defaultScene' : GameLib.D3.Scene,
'viewports' : [GameLib.D3.Viewport]
@ -301,7 +311,9 @@ GameLib.D3.Renderer.prototype.updateInstance = function(property) {
}
if (property === 'renderMode') {
console.log('todo: render mode update');
if (this.renderMode !== GameLib.D3.API.Renderer.MODE_EDIT) {
this.lastRenderMode = this.renderMode;
}
}
if (property === 'autoClear') {
@ -470,6 +482,10 @@ GameLib.D3.Renderer.prototype.updateInstance = function(property) {
console.warn('todo: camera change');
}
if (property === 'editCamera') {
console.warn('todo: edit camera change');
}
if (property === 'scenes') {
console.warn('todo: scenes change');
}
@ -493,12 +509,17 @@ GameLib.D3.Renderer.prototype.updateInstance = function(property) {
*/
GameLib.D3.Renderer.prototype.toApiObject = function() {
if (this.renderMode !== GameLib.D3.API.Renderer.MODE_EDIT) {
this.lastRenderMode = this.renderMode;
}
var apiRenderer = new GameLib.D3.API.Renderer(
this.id,
this.name,
this.width,
this.height,
this.renderMode,
this.lastRenderMode,
this.autoClear,
this.autoClearColor,
this.autoClearDepth,
@ -538,6 +559,7 @@ GameLib.D3.Renderer.prototype.toApiObject = function() {
),
this.clearColor.toApiObject(),
GameLib.Utils.IdOrNull(this.camera),
GameLib.Utils.IdOrNull(this.editCamera),
this.scenes.map(
function(scene){
return GameLib.Utils.IdOrNull(scene);

View File

@ -26,7 +26,6 @@ GameLib.D3.Scene = function (
apiScene.materials,
apiScene.images,
apiScene.fog,
apiScene.renderCamera,
apiScene.showGrid,
apiScene.showAxis,
apiScene.gridSize,
@ -132,13 +131,6 @@ GameLib.D3.Scene = function (
)
}
if (this.renderCamera instanceof GameLib.D3.API.Camera) {
this.renderCamera = new GameLib.D3.Camera(
this.graphics,
this.renderCamera
)
}
if (this.gridColor instanceof GameLib.API.Color) {
this.gridColor = new GameLib.Color(
this.graphics,
@ -169,8 +161,7 @@ GameLib.D3.Scene = function (
'textures' : [GameLib.D3.Texture],
'materials' : [GameLib.D3.Material],
'images' : [GameLib.Image],
'fog' : GameLib.D3.Fog,
'renderCamera' : GameLib.D3.Camera
'fog' : GameLib.D3.Fog
}
);
};
@ -394,7 +385,6 @@ GameLib.D3.Scene.prototype.toApiObject = function() {
apiMaterials,
apiImages,
GameLib.Utils.IdOrNull(this.fog),
GameLib.Utils.IdOrNull(this.renderCamera),
this.showGrid,
this.showAxis,
this.gridSize,

View File

@ -885,7 +885,7 @@ GameLib.System.GUI.prototype.buildControl = function(folder, componentTemplate,
}
)
);
} else if (property === 'renderMode') {
} else if (property === 'renderMode' || property === 'lastRenderMode') {
controllers.push(
folder.add(
object,
@ -893,7 +893,8 @@ GameLib.System.GUI.prototype.buildControl = function(folder, componentTemplate,
{
'canvas': GameLib.D3.API.Renderer.MODE_CANVAS,
'target': GameLib.D3.API.Renderer.MODE_TARGET,
'canvas and target': GameLib.D3.API.Renderer.MODE_CANVAS_AND_TARGET
'canvas and target': GameLib.D3.API.Renderer.MODE_CANVAS_AND_TARGET,
'edit': GameLib.D3.API.Renderer.MODE_EDIT
}
)
);

View File

@ -355,50 +355,51 @@ GameLib.System.Input.prototype.registerMouseControls = function(mouseControl) {
mouseControl.domElement.instance.addEventListener(
'mousedown',
this.mouseDown,
true
false
);
mouseControl.domElement.instance.addEventListener(
'mousemove',
this.mouseMove,
true
false
);
mouseControl.domElement.instance.addEventListener(
'wheel',
this.mouseWheel,
true
false
);
mouseControl.domElement.instance.addEventListener(
'mouseup',
this.mouseUp,
true
false
);
};
GameLib.System.Input.prototype.registerEditorControls = function(editorControl) {
/**
* If we already have mouse controls, we don't want to add another event listener onto the DOM
*/
this.mouseControls.map(
function(mouseControl) {
if (mouseControl.domElement.instance === editorControl.domElement.instance) {
this.deRegisterMouseControls(mouseControl);
}
}.bind(this)
);
/**
* If we already have keyboard controls, we don't want to add another event listener onto the DOM
*/
this.keyboardControls.map(
function(keyboardControl) {
if (keyboardControl.domElement.instance === editorControl.domElement.instance) {
this.deRegisterKeyboardControls(keyboardControl);
}
}.bind(this)
);
//
// /**
// * If we already have mouse controls, we don't want to add another event listener onto the DOM
// */
// this.mouseControls.map(
// function(mouseControl) {
// if (mouseControl.domElement.instance === editorControl.domElement.instance) {
// this.deRegisterMouseControls(mouseControl);
// }
// }.bind(this)
// );
//
// /**
// * If we already have keyboard controls, we don't want to add another event listener onto the DOM
// */
// this.keyboardControls.map(
// function(keyboardControl) {
// if (keyboardControl.domElement.instance === editorControl.domElement.instance) {
// this.deRegisterKeyboardControls(keyboardControl);
// }
// }.bind(this)
// );
editorControl.domElement.instance.addEventListener(
'mousedown',
@ -534,24 +535,25 @@ GameLib.System.Input.prototype.deRegisterMouseControls = function(mouseControl)
mouseControl.domElement.instance.removeEventListener(
'mousedown',
this.mouseDown,
true
false
);
mouseControl.domElement.instance.removeEventListener(
'mousemove',
this.mouseMove,
true
false
);
mouseControl.domElement.instance.removeEventListener(
'wheel',
this.mouseWheel,
true
false
);
mouseControl.domElement.instance.removeEventListener(
'mouseup',
this.mouseUp,
true
false
);
};

View File

@ -250,11 +250,14 @@ GameLib.System.Render.prototype.render = function(data) {
var camera = renderer.camera;
/**
* A scene's renderCamera overrides the renderer camera
*/
if (scene.renderCamera && scene.renderCamera.instance) {
camera = scene.renderCamera;
if (renderer.renderMode === GameLib.D3.API.Renderer.MODE_EDIT) {
if (!renderer.editCamera || !renderer.editCamera.instance) {
console.warn('edit camera not ready');
return;
}
camera = renderer.editCamera;
}
/**
@ -288,6 +291,11 @@ GameLib.System.Render.prototype.render = function(data) {
scene.instance,
camera.instance
);
} else if (renderer.renderMode === GameLib.D3.API.Renderer.MODE_EDIT) {
renderer.instance.render(
scene.instance,
camera.instance
)
} else {
console.warn('unknown render mode:' + renderer.renderMode);
}