diff --git a/gz3d/build/gz3d.js b/gz3d/build/gz3d.js index e2b9a75bf46eaa1670e11ba356291c775cca4f82..c61bc4d60b2a62e6eedc845bf730eb40e09106f7 100644 --- a/gz3d/build/gz3d.js +++ b/gz3d/build/gz3d.js @@ -4846,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). @@ -4860,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(); }; @@ -4879,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) @@ -4886,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 @@ -4894,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) { @@ -4904,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 @@ -4928,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; @@ -5567,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(); diff --git a/gz3d/src/gzmultiview.js b/gz3d/src/gzmultiview.js index 12b5ea1c23d3374c9f3c77dffa018701e989ec7e..50d61d7eeae1daf11ccdcf9a96f8fd4c932c1d66 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 @@ -90,18 +117,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; } + // z-index var zIndexTop = parseInt(this.mainContainer.style.zIndex, 10) + this.views.length + 1; viewContainer.style.zIndex = angular.isDefined(displayParams.zIndex) ? displayParams.zIndex : zIndexTop; diff --git a/gz3d/src/gzscene.js b/gz3d/src/gzscene.js index c618a6eb6b0d845f79ff450cb3bd77a0fe3911e6..6188def34c19e1529d8e8828869c450086cf1d10 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();