From 314a9037a3588beaf2012eb4256b645a57d16426 Mon Sep 17 00:00:00 2001
From: sweber <webers@in.tum.de>
Date: Wed, 28 Oct 2015 19:11:22 +0100
Subject: [PATCH] a small refactoring in the in the course of [NRRPLT-2785]
Change-Id: If2620d0e8dbbd6d300170b31e71158b4adb796b7
---
gz3d/build/gz3d.js | 84 ++++++++++++++++++++++++-----------------
gz3d/src/gziface.js | 1 -
gz3d/src/gzmultiview.js | 55 +++++++++++++++++++++------
gz3d/src/gzscene.js | 27 +++----------
4 files changed, 99 insertions(+), 68 deletions(-)
diff --git a/gz3d/build/gz3d.js b/gz3d/build/gz3d.js
index 48e52a7..8b1351d 100644
--- a/gz3d/build/gz3d.js
+++ b/gz3d/build/gz3d.js
@@ -3013,7 +3013,6 @@ GZ3D.GZIface.prototype.createSensorFromMsg = function(sensor)
// view.camera.add( cameraHelper );
view.type = sensor.type;
- console.log('view type: ' + view.type);
sensorObj.add(view.camera);
}
@@ -4847,6 +4846,7 @@ GZ3D.Manipulator.prototype = Object.create(THREE.EventDispatcher.prototype);
*/
GZ3D.MULTIVIEW_MAX_VIEW_COUNT = 10;
+GZ3D.MULTIVIEW_MAINVIEW_NAME = 'main_view';
/**
* GZ3D.MULTIVIEW_RENDER_VIEWPORTS uses view containers as transparent references to determine viewports for rendering (one single canvas).
@@ -4861,11 +4861,10 @@ GZ3D.MULTIVIEW_RENDER_VIEWPORTS = 1;
*/
GZ3D.MULTIVIEW_RENDER_COPY2CANVAS = 2;
-GZ3D.MultiView = function(gz3dScene, mainContainer, callbackCreateRenderContainer)
+GZ3D.MultiView = function(gz3dScene, mainContainer)
{
this.gz3dScene = gz3dScene;
this.mainContainer = mainContainer;
- this.createRenderContainerCallback = callbackCreateRenderContainer;
this.init();
};
@@ -4880,6 +4879,8 @@ GZ3D.MultiView.prototype.init = function()
if (this.renderMethod === GZ3D.MULTIVIEW_RENDER_VIEWPORTS) {
this.mainContainer.appendChild(this.gz3dScene.getDomElement());
}
+
+ this.createMainUserView();
};
GZ3D.MultiView.prototype.setCallbackCreateRenderContainer = function(callback)
@@ -4887,6 +4888,31 @@ GZ3D.MultiView.prototype.setCallbackCreateRenderContainer = function(callback)
this.createRenderContainerCallback = callback;
};
+/**
+ * This creates the main view the user will interact with and should always be there.
+ */
+GZ3D.MultiView.prototype.createMainUserView = function()
+{
+ var displayParams = {
+ left: '0px',
+ top: '0px',
+ width: '100%',
+ height: '100%',
+ adjustable: false
+ };
+ var cameraParams = {
+ width: 960,
+ height: 600,
+ fov: 60,
+ near: 0.1,
+ far: 100
+ };
+
+ this.mainUserView = this.createView(GZ3D.MULTIVIEW_MAINVIEW_NAME, displayParams, cameraParams);
+
+ return this.mainUserView;
+};
+
/**
*
* @param name
@@ -4895,9 +4921,9 @@ GZ3D.MultiView.prototype.setCallbackCreateRenderContainer = function(callback)
*/
GZ3D.MultiView.prototype.createView = function(name, displayParams, cameraParams)
{
- if (this.getViewByName(name) !== undefined) {
+ if (angular.isDefined(this.getViewByName(name))) {
console.error('GZ3D.MultiView.createView() - a view of that name already exists (' + name + ')');
- return null;
+ return undefined;
}
if (this.views.length >= this.MULTIVIEW_MAX_VIEW_COUNT) {
@@ -4905,8 +4931,8 @@ GZ3D.MultiView.prototype.createView = function(name, displayParams, cameraParams
}
var container = this.createViewContainer(displayParams, name);
- if (container === null) {
- return;
+ if (!angular.isDefined(container)) {
+ return undefined;
}
// camera
@@ -4929,18 +4955,24 @@ GZ3D.MultiView.prototype.createView = function(name, displayParams, cameraParams
GZ3D.MultiView.prototype.createViewContainer = function(displayParams, name)
{
- if (this.createRenderContainerCallback === undefined) {
+ if (!angular.isDefined(this.createRenderContainerCallback)) {
console.error('GZ3D.MultiView.createViewContainer() - no callback for creating view reference container defined');
- return null;
+ return undefined;
}
// container div
- var viewContainer = this.createRenderContainerCallback(displayParams.adjustable, name);
- if (!viewContainer) {
+ var viewContainer;
+ if (name === GZ3D.MULTIVIEW_MAINVIEW_NAME) {
+ viewContainer = document.createElement('div');
+ } else {
+ viewContainer = this.createRenderContainerCallback(displayParams.adjustable, name);
+ }
+ if (!angular.isDefined(viewContainer)) {
console.error('GZ3D.MultiView.createViewContainer() - could not create view container via callback');
- return null;
+ return undefined;
}
+
// positioning
viewContainer.style.position = 'absolute';
viewContainer.style.left = displayParams.left;
@@ -5568,32 +5600,14 @@ GZ3D.Scene.prototype.init = function()
this.container = document.getElementById( 'container' );
// create views manager
- this.viewManager = new GZ3D.MultiView(this, this.container, function(adjustable, name){
- return document.createElement('div');
- });
- // create main view
- var displayParams = {
- left: '0px',
- top: '0px',
- width: '100%',
- height: '100%',
- adjustable: false
- };
- var cameraParams = {
- width: 960,
- height: 600,
- fov: 60,
- near: 0.1,
- far: 100
- };
- this.viewManager.createView('main_view', displayParams, cameraParams);
+ this.viewManager = new GZ3D.MultiView(this, this.container);
// lights
this.ambient = new THREE.AmbientLight( 0x666666 );
this.scene.add(this.ambient);
// camera
- this.camera = this.viewManager.getViewByName('main_view').camera;
+ this.camera = this.viewManager.mainUserView.camera;
this.defaultCameraPosition = new THREE.Vector3(5, 0, 1);
this.resetView();
@@ -6606,10 +6620,12 @@ GZ3D.Scene.prototype.createPointLight = function(obj, color, intensity,
{
lightObj.distance = distance;
}
- if (cast_shadows)
+
+ // point light shadow maps not supported yet, disable for now
+ /*if (cast_shadows)
{
lightObj.castShadow = cast_shadows;
- }
+ }*/
var helperGeometry = new THREE.OctahedronGeometry(0.25, 0);
helperGeometry.applyMatrix(new THREE.Matrix4().makeRotationX(Math.PI/2));
diff --git a/gz3d/src/gziface.js b/gz3d/src/gziface.js
index 5e28028..530da13 100644
--- a/gz3d/src/gziface.js
+++ b/gz3d/src/gziface.js
@@ -992,7 +992,6 @@ GZ3D.GZIface.prototype.createSensorFromMsg = function(sensor)
// view.camera.add( cameraHelper );
view.type = sensor.type;
- console.log('view type: ' + view.type);
sensorObj.add(view.camera);
}
diff --git a/gz3d/src/gzmultiview.js b/gz3d/src/gzmultiview.js
index 16aaa50..b874ac4 100644
--- a/gz3d/src/gzmultiview.js
+++ b/gz3d/src/gzmultiview.js
@@ -3,6 +3,7 @@
*/
GZ3D.MULTIVIEW_MAX_VIEW_COUNT = 10;
+GZ3D.MULTIVIEW_MAINVIEW_NAME = 'main_view';
/**
* GZ3D.MULTIVIEW_RENDER_VIEWPORTS uses view containers as transparent references to determine viewports for rendering (one single canvas).
@@ -17,11 +18,10 @@ GZ3D.MULTIVIEW_RENDER_VIEWPORTS = 1;
*/
GZ3D.MULTIVIEW_RENDER_COPY2CANVAS = 2;
-GZ3D.MultiView = function(gz3dScene, mainContainer, callbackCreateRenderContainer)
+GZ3D.MultiView = function(gz3dScene, mainContainer)
{
this.gz3dScene = gz3dScene;
this.mainContainer = mainContainer;
- this.createRenderContainerCallback = callbackCreateRenderContainer;
this.init();
};
@@ -36,6 +36,8 @@ GZ3D.MultiView.prototype.init = function()
if (this.renderMethod === GZ3D.MULTIVIEW_RENDER_VIEWPORTS) {
this.mainContainer.appendChild(this.gz3dScene.getDomElement());
}
+
+ this.createMainUserView();
};
GZ3D.MultiView.prototype.setCallbackCreateRenderContainer = function(callback)
@@ -43,6 +45,31 @@ GZ3D.MultiView.prototype.setCallbackCreateRenderContainer = function(callback)
this.createRenderContainerCallback = callback;
};
+/**
+ * This creates the main view the user will interact with and should always be there.
+ */
+GZ3D.MultiView.prototype.createMainUserView = function()
+{
+ var displayParams = {
+ left: '0px',
+ top: '0px',
+ width: '100%',
+ height: '100%',
+ adjustable: false
+ };
+ var cameraParams = {
+ width: 960,
+ height: 600,
+ fov: 60,
+ near: 0.1,
+ far: 100
+ };
+
+ this.mainUserView = this.createView(GZ3D.MULTIVIEW_MAINVIEW_NAME, displayParams, cameraParams);
+
+ return this.mainUserView;
+};
+
/**
*
* @param name
@@ -51,9 +78,9 @@ GZ3D.MultiView.prototype.setCallbackCreateRenderContainer = function(callback)
*/
GZ3D.MultiView.prototype.createView = function(name, displayParams, cameraParams)
{
- if (this.getViewByName(name) !== undefined) {
+ if (angular.isDefined(this.getViewByName(name))) {
console.error('GZ3D.MultiView.createView() - a view of that name already exists (' + name + ')');
- return null;
+ return undefined;
}
if (this.views.length >= this.MULTIVIEW_MAX_VIEW_COUNT) {
@@ -61,8 +88,8 @@ GZ3D.MultiView.prototype.createView = function(name, displayParams, cameraParams
}
var container = this.createViewContainer(displayParams, name);
- if (container === null) {
- return;
+ if (!angular.isDefined(container)) {
+ return undefined;
}
// camera
@@ -85,18 +112,24 @@ GZ3D.MultiView.prototype.createView = function(name, displayParams, cameraParams
GZ3D.MultiView.prototype.createViewContainer = function(displayParams, name)
{
- if (this.createRenderContainerCallback === undefined) {
+ if (!angular.isDefined(this.createRenderContainerCallback)) {
console.error('GZ3D.MultiView.createViewContainer() - no callback for creating view reference container defined');
- return null;
+ return undefined;
}
// container div
- var viewContainer = this.createRenderContainerCallback(displayParams.adjustable, name);
- if (!viewContainer) {
+ var viewContainer;
+ if (name === GZ3D.MULTIVIEW_MAINVIEW_NAME) {
+ viewContainer = document.createElement('div');
+ } else {
+ viewContainer = this.createRenderContainerCallback(displayParams.adjustable, name);
+ }
+ if (!angular.isDefined(viewContainer)) {
console.error('GZ3D.MultiView.createViewContainer() - could not create view container via callback');
- return null;
+ return undefined;
}
+
// positioning
viewContainer.style.position = 'absolute';
viewContainer.style.left = displayParams.left;
diff --git a/gz3d/src/gzscene.js b/gz3d/src/gzscene.js
index ebac0df..6188def 100644
--- a/gz3d/src/gzscene.js
+++ b/gz3d/src/gzscene.js
@@ -41,32 +41,14 @@ GZ3D.Scene.prototype.init = function()
this.container = document.getElementById( 'container' );
// create views manager
- this.viewManager = new GZ3D.MultiView(this, this.container, function(adjustable, name){
- return document.createElement('div');
- });
- // create main view
- var displayParams = {
- left: '0px',
- top: '0px',
- width: '100%',
- height: '100%',
- adjustable: false
- };
- var cameraParams = {
- width: 960,
- height: 600,
- fov: 60,
- near: 0.1,
- far: 100
- };
- this.viewManager.createView('main_view', displayParams, cameraParams);
+ this.viewManager = new GZ3D.MultiView(this, this.container);
// lights
this.ambient = new THREE.AmbientLight( 0x666666 );
this.scene.add(this.ambient);
// camera
- this.camera = this.viewManager.getViewByName('main_view').camera;
+ this.camera = this.viewManager.mainUserView.camera;
this.defaultCameraPosition = new THREE.Vector3(5, 0, 1);
this.resetView();
@@ -1080,10 +1062,11 @@ GZ3D.Scene.prototype.createPointLight = function(obj, color, intensity,
lightObj.distance = distance;
}
- if (cast_shadows)
+ // point light shadow maps not supported yet, disable for now
+ /*if (cast_shadows)
{
lightObj.castShadow = cast_shadows;
- }
+ }*/
var helperGeometry = new THREE.OctahedronGeometry(0.25, 0);
helperGeometry.applyMatrix(new THREE.Matrix4().makeRotationX(Math.PI/2));
--
GitLab