Skip to content
Browse files

Merge pull request #1 from OpenWebGlobe/master

Updating my fork
  • Loading branch information...
2 parents e997b3c + 2d88ed9 commit a225ac482cf4fd60d4221db47c10dbbc1e393575 @nbmont nbmont committed Aug 15, 2012
Showing with 7,708 additions and 582 deletions.
  1. +0 −7 .gitignore
  2. +6 −1 source/core/earthpolyline.js
  3. +567 −415 source/core/engine3d.js
  4. +57 −0 source/core/globerenderer.js
  5. +2 −2 source/core/layer/imagelayer_osm.js
  6. +190 −0 source/core/layer/imagelayer_wms.js
  7. +31 −0 source/core/mat4.js
  8. +45 −3 source/core/mercatorquadtree.js
  9. +5 −2 source/core/node.js
  10. +6 −1 source/core/nodes/camera.js
  11. +703 −0 source/core/nodes/constrainednavigation.js
  12. +1,046 −0 source/core/nodes/dynamicnavigation.js
  13. +84 −13 source/core/nodes/globenavigation.js
  14. +15 −4 source/core/nodes/logos.js
  15. +43 −7 source/core/nodes/navigation.js
  16. +69 −14 source/core/nodes/renderobject.js
  17. +299 −26 source/core/og.js
  18. +17 −0 source/core/og/ObjectDefs.js
  19. +15 −0 source/core/og/ogCamera.js
  20. +14 −5 source/core/og/ogContext.js
  21. +176 −6 source/core/og/ogGeometry.js
  22. +50 −0 source/core/og/ogMeshObject.js
  23. +40 −5 source/core/og/ogScene.js
  24. +61 −8 source/core/og/ogSurface.js
  25. +52 −4 source/core/og/ogVector.js
  26. +13 −0 source/core/og/ogWorld.js
  27. +66 −8 source/core/scenegraph.js
  28. +124 −18 source/core/shaders.js
  29. +256 −3 source/core/surface.js
  30. +4 −0 source/core/terrainblock.js
  31. +2 −2 source/core/texture.js
  32. +8 −0 source/core/vectorrenderer.js
  33. +1 −1 source/demos/04_SwisstopoDemo/index.html
  34. +44 −0 source/demos/08_WMS/debug.html
  35. +41 −0 source/demos/08_WMS/index.html
  36. +4 −0 source/externs/webgl_fixes.js
  37. +103 −0 source/tests/03_ContextLost/debug.html
  38. +100 −0 source/tests/03_ContextLost/release.html
  39. +33 −7 source/tutorials/04_Picking/picking.html
  40. +0 −5 source/tutorials/05_POI/POI_00_Basic_Style.html
  41. +3 −0 source/tutorials/06_3D-Geometry/3DGeometry_01_PickGeometry.html
  42. +121 −0 source/tutorials/06_3D-Geometry/3DGeometry_02_CreateModel.html
  43. +154 −0 source/tutorials/06_3D-Geometry/3DGeometry_03_ChangeSizePosOri.html
  44. +158 −0 source/tutorials/06_3D-Geometry/3DGeometry_Highlight.html
  45. +1 −0 source/tutorials/06_3D-Geometry/torus.json
  46. +10 −14 source/tutorials/10_PointSprites/PointSprites.html
  47. +2,191 −0 source/tutorials/10_PointSprites/points.xyz
  48. +77 −0 source/tutorials/12_GeoJSON/dynamic.html
  49. +1 −1 source/tutorials/{06_3D-Geometry → 13_CustomWorld}/cubepc.json
  50. +98 −0 source/tutorials/13_CustomWorld/custom_globe.html
  51. +109 −0 source/tutorials/14_ResetScene/globe.html
  52. +143 −0 source/tutorials/15_Navigation/debug.html
  53. +137 −0 source/tutorials/18_GetElevation/debug.html
  54. +113 −0 source/tutorials/19_Fullscreen/debug.html
View
7 .gitignore
@@ -8,13 +8,6 @@
/.komodotools
/.idea
-# build server:
-/cloc.exe
-/code_stats.bat
-
-# internal tests
-/source/tests
-
# MacOS
.DS_Store
View
7 source/core/earthpolyline.js
@@ -62,6 +62,10 @@ function EarthPolyline(engine,options)
this.options = options;
+ /** @type {vec4} */
+ this.highlightcolor = new vec4();
+ this.highlightcolor.Set(1, 1, 1, 1);
+
}
@@ -211,7 +215,8 @@ EarthPolyline.prototype.Draw = function()
this.gl.enableVertexAttribArray(1);
this.gl.vertexAttribPointer(0, 3, this.gl.FLOAT, false, 7*4, 0*4); // position
this.gl.vertexAttribPointer(1, 4, this.gl.FLOAT, false, 7*4, 3*4); // color
- this.engine.shadermanager.UseShader_PC(this.engine.matModelViewProjection);
+
+ this.engine.shadermanager.UseShader_PC(this.engine.matModelViewProjection,this.highlightcolor);
this.gl.lineWidth(this.options["linewidth"]);
View
982 source/core/engine3d.js
@@ -1,25 +1,25 @@
/*******************************************************************************
-# ____ __ __ _ _____ _ _ #
-# / __ \ \ \ / / | | / ____| | | | #
-# | | | |_ __ ___ _ __ \ /\ / /__| |__ | | __| | ___ | |__ ___ #
-# | | | | '_ \ / _ \ '_ \ \/ \/ / _ \ '_ \| | |_ | |/ _ \| '_ \ / _ \ #
-# | |__| | |_) | __/ | | \ /\ / __/ |_) | |__| | | (_) | |_) | __/ #
-# \____/| .__/ \___|_| |_|\/ \/ \___|_.__/ \_____|_|\___/|_.__/ \___| #
-# | | #
-# |_| _____ _____ _ __ #
-# / ____| __ \| |/ / #
-# | (___ | | | | ' / #
-# \___ \| | | | < #
-# ____) | |__| | . \ #
-# |_____/|_____/|_|\_\ #
-# #
-# (c) 2010-2012 by #
-# University of Applied Sciences Northwestern Switzerland #
-# Institute of Geomatics Engineering #
-# martin.christen@fhnw.ch #
-********************************************************************************
-* Licensed under MIT License. Read the file LICENSE for more information *
-*******************************************************************************/
+ # ____ __ __ _ _____ _ _ #
+ # / __ \ \ \ / / | | / ____| | | | #
+ # | | | |_ __ ___ _ __ \ /\ / /__| |__ | | __| | ___ | |__ ___ #
+ # | | | | '_ \ / _ \ '_ \ \/ \/ / _ \ '_ \| | |_ | |/ _ \| '_ \ / _ \ #
+ # | |__| | |_) | __/ | | \ /\ / __/ |_) | |__| | | (_) | |_) | __/ #
+ # \____/| .__/ \___|_| |_|\/ \/ \___|_.__/ \_____|_|\___/|_.__/ \___| #
+ # | | #
+ # |_| _____ _____ _ __ #
+ # / ____| __ \| |/ / #
+ # | (___ | | | | ' / #
+ # \___ \| | | | < #
+ # ____) | |__| | . \ #
+ # |_____/|_____/|_|\_\ #
+ # #
+ # (c) 2010-2012 by #
+ # University of Applied Sciences Northwestern Switzerland #
+ # Institute of Geomatics Engineering #
+ # martin.christen@fhnw.ch #
+ ********************************************************************************
+ * Licensed under MIT License. Read the file LICENSE for more information *
+ *******************************************************************************/
goog.provide('owg.engine3d');
@@ -40,13 +40,13 @@ goog.require('owg.TextureManager');
goog.require('owg.GeoCoord');
goog.require('owg.PointSprite');
-/**
- *
+/**
+ *
* @class engine3d
- * The actual 3d engine with all functions.
+ * The actual 3d engine with all functions.
* Based on "ALGOS 3D Engine" created by Martin Christen
*
- * @author Martin Christen martin.christen@fhnw.ch
+ * @author Martin Christen martin.christen@fhnw.ch
*/
//------------------------------------------------------------------------------
@@ -58,16 +58,16 @@ var dtEnd = new Date();
var dtStart = new Date();
/** @type {Array.<engine3d>} */
-var _g_vInstances = new Array(); // array of all current instances
+var _g_vInstances = new Array(); // array of all current instances
/** @type {number} */
-var _g_nInstanceCnt = 0; // total number of engine instances
+var _g_nInstanceCnt = 0; // total number of engine instances
/** @type {?number} */
-var _gcbfKeyDown = null; // global key down event
+var _gcbfKeyDown = null; // global key down event
/** @type {?number} */
-var _gcbfKeyUp = null; // global key up event
+var _gcbfKeyUp = null; // global key up event
//------------------------------------------------------------------------------
@@ -80,17 +80,17 @@ var _gcbfKeyUp = null; // global key up event
*/
function _fncMouseMove(evt)
{
- for (var i=0;i<_g_vInstances.length;i++)
+ for (var i = 0; i < _g_vInstances.length; i++)
{
var engine = _g_vInstances[i];
if (evt.currentTarget == engine.context)
{
- var x = evt.clientX-engine.xoffset/2;
- var y = evt.clientY-engine.yoffset/2;
-
- if (engine.cbfMouseMove)
+ var x = evt.clientX - engine.xoffset / 2;
+ var y = evt.clientY - engine.yoffset / 2;
+
+ if (engine.cbfMouseMove && !engine.gl.isContextLost())
{
- engine.cbfMouseMove(x,y, engine); // call mouse up callback function
+ engine.cbfMouseMove(x, y, engine); // call mouse up callback function
}
return;
}
@@ -104,33 +104,52 @@ function _fncMouseMove(evt)
*/
function _fncResize(evt)
{
- for (var i=0;i<_g_vInstances.length;i++)
+ for (var i = 0; i < _g_vInstances.length; i++)
{
var engine = _g_vInstances[i];
if (engine.bFullscreen)
{
- if(engine.widthOffset > 0 && engine.heightOffset > 0)
- {
- engine.context.width = window.innerWidth-engine.widthOffset;
- engine.context.height = window.innerHeight-engine.heightOffset;
- }
- else
- {
- engine.context.width = window.innerWidth;
- engine.context.height = window.innerHeight;
- }
+ if (engine.widthOffset > 0 && engine.heightOffset > 0)
+ {
+ engine.context.width = window.innerWidth - engine.widthOffset;
+ engine.context.height = window.innerHeight - engine.heightOffset;
+ }
+ else
+ {
+ engine.context.width = window.innerWidth;
+ engine.context.height = window.innerHeight;
+ }
}
-
-
- engine._resize(engine.context.width, engine.context.height);
+
+ if (!engine.gl.isContextLost())
+ {
+ engine._resize(engine.context.width, engine.context.height);
+ }
}
}
-
+
+//------------------------------------------------------------------------------
+/**
+ * @param {engine3d} engine
+ */
+function OnLostContext(engine)
+{
+ engine.ContextLost();
+}
+//------------------------------------------------------------------------------
+/**
+ * @param {engine3d} engine
+ */
+function OnRestoreContext(engine)
+{
+ engine.RestoreContext();
+}
+
//------------------------------------------------------------------------------
/**
* @description Create a new engine3d object
- * @class
+ * @class
* @constructor
*/
function engine3d()
@@ -156,30 +175,29 @@ function engine3d()
this.cbfKeyReleased = null;
/** @type {?function(number,number,engine3d)} */
this.cbfResize = null;
-
+
// flags
/** @type {boolean} */
this.init = false;
/** @type {string} */
this.canvasid = "";
-
// width / height
/** @type {number} */
this.width = 0;
/** @type {number} */
this.height = 0;
-
+
this.bFullscreen = false;
/** @type {WebGLRenderingContext} */
this.gl = null; // opengl context
-
+
this.context = null;
-
+
/** @type {ShaderManager} */
this.shadermanager = null;
-
+
// Default Background color
/** @type {number} */
this.bg_r = 0.670588;
@@ -189,8 +207,7 @@ function engine3d()
this.bg_b = 1;
/** @type {number} */
this.bg_a = 1;
-
-
+
// Viewport
/** @type {number} */
this.vp_x = 0;
@@ -200,11 +217,11 @@ function engine3d()
this.vp_w = 0;
/** @type {number} */
this.vp_h = 0;
-
+
// Special Offset for Fullscreen mode
this.xoffset = 20;
this.yoffset = 20;
-
+
// Model, View and Projection Matrices
/** @type {mat4} */
this.matModel = new mat4();
@@ -221,90 +238,88 @@ function engine3d()
/** @type {Array.<Texture>} */
this.RenderTargetStack = new Array();
-
+
// Engine Traversal State
/** @type {TraversalState} */
this.TravState = new TraversalState();
-
+
// Content Arrays
/** @type {Array.<Surface>} */
this.vecMeshes = new Array();
/** @type {Array.<Texture>} */
this.vecTextures = new Array();
-
+
// engine instance voodoo
/** @type {engine3d} */
_g_vInstances[_g_nInstanceCnt] = this;
/** @type {number} */
_g_nInstanceCnt++;
-
+
// system font (for ASCII Text only)
/** @type {Font} */
this.systemfont = null;
-
+
// the scene
/** @type {SceneGraph} */
this.scene = null;
-
+
// an empty texture for "failed" downloads
/** @type {Texture} */
this.nodata = null;
-
+
/** @type {number} */
this.worldtype = 1; // 0: custom, 1: wgs84, 2: flat, 3: 2D
-
+
// POI Manager
/** @type {PoiManager} */
this.poimanager = null;
-
+
/** @type {TextureManager} */
this.texturemanager = null;
-
+
/** @type {FlyToAnimation} */
this.flyto = null;
- /** @type {number} */
- this.widthOffset = 0;
-
- /** @type {number} */
- this.heightOffset = 0;
-
+ /** @type {number} */
+ this.widthOffset = 0;
-}
+ /** @type {number} */
+ this.heightOffset = 0;
+}
//------------------------------------------------------------------------------
/**
* Creates the HTLM for a failure message
* @param {string} msg
* @return {string} The html.
*/
-var makeFailHTML = function(msg)
+var makeFailHTML = function (msg)
{
return '' +
- '<table style="background-color: #8CE; width: 100%; height: 100%;"><tr>' +
- '<td align="center">' +
- '<div style="display: table-cell; vertical-align: middle;">' +
- '<div style="">' + msg + '</div>' +
- '</div>' +
- '</td></tr></table>';
+ '<table style="background-color: #8CE; width: 100%; height: 100%;"><tr>' +
+ '<td align="center">' +
+ '<div style="display: table-cell; vertical-align: middle;">' +
+ '<div style="">' + msg + '</div>' +
+ '</div>' +
+ '</td></tr></table>';
};
-
+//------------------------------------------------------------------------------
/**
* Message: getting a webgl browser
* @type {string}
*/
var GET_A_WEBGL_BROWSER = '' +
- 'This page requires a browser that supports WebGL.<br/>' +
- '<a href="http://get.webgl.org">Click here to upgrade your browser.</a>';
-
+ 'This page requires a browser that supports WebGL.<br/>' +
+ '<a href="http://get.webgl.org">Click here to upgrade your browser.</a>';
+//------------------------------------------------------------------------------
/**
* Message: need better hardware
* @type {string}
*/
var OTHER_PROBLEM = '' +
- "It doesn't appear your browser supports WebGL.<br/>" +
- '<a href="http://get.webgl.org/troubleshooting/">Click here for more information.</a>';
-
+ "It doesn't appear your browser supports WebGL.<br/>" +
+ '<a href="http://get.webgl.org/troubleshooting/">Click here for more information.</a>';
+//------------------------------------------------------------------------------
/**
* Creates a webgl context. If creation fails it will
* change the contents of the container of the <canvas>
@@ -313,193 +328,239 @@ var OTHER_PROBLEM = '' +
* context from.
* @return {WebGLRenderingContext} The created context.
*/
-var setupWebGL = function(canvas)
-{
- function showLink(str)
- {
- var container = canvas.parentNode;
- if (container)
- {
- container["innerHTML"] = makeFailHTML(str);
- }
- };
-
- if (!window["WebGLRenderingContext"])
- {
- showLink(GET_A_WEBGL_BROWSER);
- return null;
- }
-
- var context = create3DContext(canvas);
- if (goog.isNull(context))
- {
- showLink(OTHER_PROBLEM);
- }
- return context;
-};
+var setupWebGL = function (canvas)
+{
+ function showLink(str)
+ {
+ var container = canvas.parentNode;
+ if (container)
+ {
+ container["innerHTML"] = makeFailHTML(str);
+ }
+ }
+
+ if (!window["WebGLRenderingContext"])
+ {
+ showLink(GET_A_WEBGL_BROWSER);
+ return null;
+ }
+ var context = create3DContext(canvas);
+ if (goog.isNull(context))
+ {
+ showLink(OTHER_PROBLEM);
+ return null;
+ }
+
+ return context;
+};
+//------------------------------------------------------------------------------
/**
* Creates a webgl context.
* @param {!Element} canvas The canvas tag to get context
* from. If one is not passed in one will be created.
* @return {!WebGLRenderingContext} The created context.
*/
-var create3DContext = function(canvas)
+var create3DContext = function (canvas)
{
- var names = ["webgl", "experimental-webgl", "webkit-3d", "moz-webgl"];
- var context = null;
- for (var ii = 0; ii < names.length; ++ii)
- {
- try
+ var names = ["webgl", "experimental-webgl", "webkit-3d", "moz-webgl"];
+ var context = null;
+ for (var ii = 0; ii < names.length; ++ii)
+ {
+ try
+ {
+ context = canvas.getContext(names[ii], { antialias:false });
+ }
+ catch (e)
{
- context = canvas.getContext(names[ii], { antialias: false });
}
- catch(e) {}
if (context)
{
break;
}
- }
- return context;
+ }
+ return context;
}
-
//------------------------------------------------------------------------------
/**
- * @description Initialize Engine
+ * @description Initialize Engine
* @param {string} canvasid The id of the webgl canvas
* @param {boolean} bFullscreen True if the canvas should autofit the browser window
*/
-engine3d.prototype.InitEngine = function(canvasid, bFullscreen)
+engine3d.prototype.InitEngine = function (canvasid, bFullscreen)
{
var canvas = document.getElementById(canvasid);
-
+
this.gl = setupWebGL(canvas);
if (!this.gl)
{
-
return;
}
-
+
this.context = canvas;
-
+
+ // Handling losing/restoring context:
+ var evt_engine = this;
+ canvas.addEventListener("webglcontextlost", function(event) { OnLostContext(evt_engine); event.preventDefault(); }, false);
+ canvas.addEventListener("webglcontextrestored", function(event) { OnRestoreContext(evt_engine); }, false);
+
if (bFullscreen)
{
- this.xoffset = 0; //document.body.scrollLeft - document.body.clientLeft;
- this.yoffset = 0; //document.body.scrollTop - document.body.clientTop;
- canvas.width = window.innerWidth-this.xoffset;
- canvas.height = window.innerHeight-this.yoffset;
- this.bFullscreen = true;
+ this.xoffset = 0; //document.body.scrollLeft - document.body.clientLeft;
+ this.yoffset = 0; //document.body.scrollTop - document.body.clientTop;
+ canvas.width = window.innerWidth - this.xoffset;
+ canvas.height = window.innerHeight - this.yoffset;
+ this.bFullscreen = true;
}
-
+
var names = [ "webgl", "experimental-webgl", "moz-webgl", "webkit-3d" ];
- for (var i=0; names.length>i; i++)
+ for (var i = 0; names.length > i; i++)
{
- try
- {
+ try
+ {
this.gl = canvas.getContext(names[i]);
- if (this.gl)
- {
- break;
+ if (this.gl)
+ {
+ break;
}
- }
- catch (e)
+ }
+ catch (e)
{
}
}
- if (!this.gl)
+ if (!this.gl)
{
alert("Can't find webgl context. It seems your browser is not compatible! For example, you can get the latest Firefox or Chrome");
return;
}
-
+
+ this.InitGL();
+
+ //disable context menu on canvas
+ this.context.oncontextmenu = function (event)
+ {
+ event.preventDefault();
+ event.stopPropagation();
+ return false;
+ };
+
+ goog.events.listen(window, goog.events.EventType.RESIZE, _fncResize, false, this);
+ goog.events.listen(window, goog.events.EventType.UNLOAD, this.OnDestroy, false, this);
+
+}
+//------------------------------------------------------------------------------
+/**
+ * Initialize Graphics Subsystem
+ */
+engine3d.prototype.InitGL = function()
+{
// Call OnResize(canvas.width, canvas.height)
this._resize(this.context.width, this.context.height);
-
+
// basic settings
this.gl.clearColor(0, 0, 0, 1);
this.gl.enable(this.gl.DEPTH_TEST);
-
+
this.gl.frontFace(this.gl.CCW);
//this.gl.cullFace(this.gl.FRONT_AND_BACK);
this.gl.cullFace(this.gl.BACK);
-
- // Create Default Shaders
- //this.CreateDefaultShaders();
- //this.UseShaderDefault();
-
+
//Init Shaders
this.shadermanager = new ShaderManager(this.gl);
this.shadermanager.InitShaders();
-
+
// Create Font
this.systemfont = new Font(this);
-
+
// Create Nodata texture
this.nodata = new Texture(this);
this.nodata.LoadNoDataTexture();
-
+
// Create Poi Manager
this.poimanager = new PoiManager(this);
-
+
//Create TextureManager
this.texturemanager = new TextureManager(this);
-
+
//Create FlyToAnimation
this.flyto = new FlyToAnimation(this);
-
+
// call init callback
- if (this.cbfInit)
+ if (this.cbfInit)
{
- var engine = this;
- this.cbfInit(engine);
- }
-
- goog.events.listen(window, goog.events.EventType.RESIZE, _fncResize, false, this);
-
-
+ var engine = this;
+ this.cbfInit(engine);
+ }
+
dtStart = new Date(); // setup main timer...
- if(typeof(window)!="undefined")//if owg runs in a webworker "window" is not available!
+ if (typeof(window) != "undefined") // if owg runs in a webworker "window" is not available!
{
window.requestAnimFrame(fncTimer, this.context); // request first frame
}
-
- //disable context menu on canvas
- this.context.oncontextmenu = function(event)
- {
- event.preventDefault();
- event.stopPropagation();
- return false;
- };
-
-
- goog.events.listen(window, goog.events.EventType.UNLOAD, this.OnDestroy, false, this);
}
//------------------------------------------------------------------------------
/**
* @description Called when engine is destroyed
*/
//------------------------------------------------------------------------------
-engine3d.prototype.OnDestroy = function()
+engine3d.prototype.OnDestroy = function ()
{
- this.cbfInit = null;
- this.cbfTimer = null;
- this.cbfRender = null;
- this.cbfMouseClicked = null;
- this.cbfMouseReleased = null;
- this.cbfMouseMoved = null;
- this.cbfMouseWheel = null;
- this.cbfKeyPressed = null;
- this.cbfKeyReleased = null;
- this.cbfResize = null;
+ if (this.cbfInit)
+ {
+ this.cbfInit = null;
+ }
+
+ if (this.cbfMouseDown)
+ {
+ goog.events.unlistenByKey(this.cbfMouseDown);
+ this.cbfMouseDown = null;
+ }
+ if (this.cbfMouseUp)
+ {
+ goog.events.unlistenByKey(this.cbfMouseUp);
+ this.cbfMouseUp = null;
+ }
+ if (this.cbfMouseWheel)
+ {
+ goog.events.unlistenByKey(this.cbfMouseWheel);
+ this.cbfMouseWheel = null;
+ }
+
+ if (this.cbfTimer)
+ {
+ this.cbfTimer = null;
+ }
+ if (this.cbfRender)
+ {
+ this.cbfRender = null;
+ }
+
+ if (_gcbfKeyDown)
+ {
+ goog.events.unlistenByKey(_gcbfKeyDown);
+ _gcbfKeyUp = null;
+ }
+ if (_gcbfKeyUp)
+ {
+ goog.events.unlistenByKey(_gcbfKeyUp);
+ _gcbfKeyUp = null;
+ }
+
+ //if (this.cbfMouseMoved) { goog.events.unlistenByKey(this.cbfMouseMoved); this.cbfMouseMoved = null;}
+
+ //if (this.cbfResize) { goog.events.unlistenByKey(this.cbfResize); this.cbfResize = null;}
if (this.scene)
{
this.scene.Destroy();
this.scene = null;
}
- this.gl = null;
+ this.gl.clearColor(0, 0, 0, 0);
+ this.gl.clear(this.gl.COLOR_BUFFER_BIT | this.gl.DEPTH_BUFFER_BIT);
+
+ this.gl = null;
this.context = null;
this.shadermanager = null;
this.vecMeshes = [];
@@ -508,7 +569,27 @@ engine3d.prototype.OnDestroy = function()
this.scene = null;
this.poimanager = null;
this.texturemanager = null;
- goog.events.listen(window, goog.events.EventType.RESIZE, null, false, this);
+ goog.events.unlisten(window, goog.events.EventType.RESIZE, null, false, this);
+
+ _g_nInstanceCnt = 0;
+ _g_vInstances = [];
+}
+//------------------------------------------------------------------------------
+/**
+ * Called when context is lost
+ */
+engine3d.prototype.ContextLost = function()
+{
+}
+//------------------------------------------------------------------------------
+/*
+ * Called when context is restored
+ */
+engine3d.prototype.RestoreContext = function()
+{
+ // This is a temporary fix
+ // in future all WebGL resources must be regenerated
+ window.location.reload();
}
//------------------------------------------------------------------------------
/**
@@ -518,9 +599,9 @@ engine3d.prototype.OnDestroy = function()
* @param {number} b blue component, range [0,1]
* @param {number} a alpha component, range [0,1]
*/
-engine3d.prototype.SetClearColor = function(r,g,b,a)
+engine3d.prototype.SetClearColor = function (r, g, b, a)
{
- if (r>=0 && r<=1 && g>=0 && g<=1 && b>=0 && b<=1 && a>=0 && a<=1)
+ if (r >= 0 && r <= 1 && g >= 0 && g <= 1 && b >= 0 && b <= 1 && a >= 0 && a <= 1)
{
this.bg_r = r;
this.bg_g = g;
@@ -533,26 +614,34 @@ engine3d.prototype.SetClearColor = function(r,g,b,a)
* @description Gets the clear color
* returns an array A. You can access components using A.r, A.g, A.b, A.a
*/
-engine3d.prototype.GetClearColor = function(color)
+engine3d.prototype.GetClearColor = function (color)
{
- return {r: this.bg_r, g: this.bg_g, b: this.bg_b, a: this.bg_a};
+ return {r:this.bg_r, g:this.bg_g, b:this.bg_b, a:this.bg_a};
}
//------------------------------------------------------------------------------
/**
* @description Clear color and depth buffer (using current clear color)
*/
-engine3d.prototype.Clear = function()
+engine3d.prototype.Clear = function ()
{
/** @type {WebGLRenderingContext} */
var gl = this.gl;
- gl.clearColor(this.bg_r, this.bg_g, this.bg_b, this.bg_a);
- gl.clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT);
+
+ if (gl)
+ {
+ gl.clearColor(this.bg_r, this.bg_g, this.bg_b, this.bg_a);
+ gl.clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT);
+ }
+ else
+ {
+ ogLog("Warning: no gl context!!")
+ }
}
//------------------------------------------------------------------------------
/**
* @description Initialize Render-Target
*/
-engine3d.prototype.SetupDepthTextureTarget = function()
+engine3d.prototype.SetupDepthTextureTarget = function ()
{
/** @type {WebGLRenderingContext} */
var gl = this.gl;
@@ -573,7 +662,7 @@ engine3d.prototype.SetupDepthTextureTarget = function()
* @param {Array.<Surface>} bboxarray
* @param {boolean=} opt_bBlend
*/
-engine3d.prototype.VectorRender = function(geometryarray, bboxarray, opt_bBlend)
+engine3d.prototype.VectorRender = function (geometryarray, bboxarray, opt_bBlend)
{
/** @type {WebGLRenderingContext} */
var gl = this.gl;
@@ -593,7 +682,7 @@ engine3d.prototype.VectorRender = function(geometryarray, bboxarray, opt_bBlend)
gl.stencilOp(gl.KEEP, gl.KEEP, gl.INCR);
gl.cullFace(gl.FRONT);
// First Pass:
- for (var i=0;i<geometryarray.length;i++)
+ for (var i = 0; i < geometryarray.length; i++)
{
geometryarray[i].Draw();
}
@@ -602,7 +691,7 @@ engine3d.prototype.VectorRender = function(geometryarray, bboxarray, opt_bBlend)
gl.cullFace(gl.BACK);
// Second Pass:
- for (var i=0;i<geometryarray.length;i++)
+ for (var i = 0; i < geometryarray.length; i++)
{
geometryarray[i].Draw();
}
@@ -613,22 +702,28 @@ engine3d.prototype.VectorRender = function(geometryarray, bboxarray, opt_bBlend)
gl.stencilFunc(gl.NOTEQUAL, 0, 1);
gl.stencilOp(gl.KEEP, gl.KEEP, gl.KEEP);
- if (bBlend) { gl.enable(gl.BLEND); }
+ if (bBlend)
+ {
+ gl.enable(gl.BLEND);
+ }
//gl.disable(gl.DEPTH_TEST);
gl.depthMask(true);
- for (var i=0;i<bboxarray.length;i++)
+ for (var i = 0; i < bboxarray.length; i++)
{
bboxarray[i].Draw();
}
gl.stencilFunc(gl.NOTEQUAL, 0, 2);
- for (var i=0;i<bboxarray.length;i++)
+ for (var i = 0; i < bboxarray.length; i++)
{
bboxarray[i].Draw();
}
- if (bBlend) { gl.disable(gl.BLEND); }
+ if (bBlend)
+ {
+ gl.disable(gl.BLEND);
+ }
gl.enable(gl.DEPTH_TEST);
gl.enable(gl.CULL_FACE);
@@ -644,60 +739,81 @@ engine3d.prototype.VectorRender = function(geometryarray, bboxarray, opt_bBlend)
* @param {number} w Screen width
* @param {number} h Screen height
*/
-engine3d.prototype.SetViewport = function(x,y,w,h)
+engine3d.prototype.SetViewport = function (x, y, w, h)
{
- this.vp_x = x; this.vp_y = y; this.vp_w = w; this.vp_h = h;
- this.gl.viewport(x, y, w, h);
+ if (this.gl)
+ {
+ this.vp_x = x;
+ this.vp_y = y;
+ this.vp_w = w;
+ this.vp_h = h;
+ this.gl.viewport(x, y, w, h);
+ }
}
//------------------------------------------------------------------------------
/**
* @description Retrieve current Viewport
* returns an array A. You can access components using A.x, A.y, A.w, A.h
*/
-engine3d.prototype.GetViewport = function()
+engine3d.prototype.GetViewport = function ()
{
- return {x: this.vp_x, y: this.vp_y, w: this.vp_w, h: this.vp_h};
+ return {x:this.vp_x, y:this.vp_y, w:this.vp_w, h:this.vp_h};
+}
+//------------------------------------------------------------------------------
+/**
+ * Enable Depth Test
+ */
+engine3d.prototype.EnableDepthTest = function ()
+{
+ this.gl.enable(this.gl.DEPTH_TEST);
+}
+//------------------------------------------------------------------------------
+/**
+ * Disable Depth Test
+ */
+engine3d.prototype.DisableDepthTest = function ()
+{
+ this.gl.disable(this.gl.DEPTH_TEST);
}
-
//------------------------------------------------------------------------------
/**
* @description Set projection matrix
* @param{mat4} projmat The projection matrix to copy from.
*/
-engine3d.prototype.SetProjectionMatrix = function(projmat)
+engine3d.prototype.SetProjectionMatrix = function (projmat)
{
this.matProjection.CopyFrom(projmat);
this._UpdateMatrices();
-}
+}
//------------------------------------------------------------------------------
/**
* @description set view matrix
* @param{mat4} viewmat The view matrix to copy from.
*/
-engine3d.prototype.SetViewMatrix = function(viewmat)
+engine3d.prototype.SetViewMatrix = function (viewmat)
{
this.matView.CopyFrom(viewmat);
this._UpdateMatrices();
-}
+}
//------------------------------------------------------------------------------
/**
* @description Set model matrix
* @param{mat4} modelmat The model matrix to copy from.
*/
-engine3d.prototype.SetModelMatrix = function(modelmat)
+engine3d.prototype.SetModelMatrix = function (modelmat)
{
this.matModel.CopyFrom(modelmat);
this._UpdateMatrices();
-}
+}
//------------------------------------------------------------------------------
/**
* @description Update matrices: calc ModelView, ModelViewProjection
* @ignore
*/
-engine3d.prototype._UpdateMatrices = function()
+engine3d.prototype._UpdateMatrices = function ()
{
this.matModelView.Multiply(this.matView, this.matModel);
this.matModelViewProjection.Multiply(this.matProjection, this.matModelView);
@@ -711,12 +827,12 @@ engine3d.prototype._UpdateMatrices = function()
* @param {string} url The URL to the texture
* @return {Texture} the texture
*/
-engine3d.prototype.LoadTexture = function(url)
+engine3d.prototype.LoadTexture = function (url)
{
var tex = new Texture(this);
tex.loadTexture(url);
this.vecTextures.push(tex);
-
+
return tex;
}
@@ -725,21 +841,20 @@ engine3d.prototype.LoadTexture = function(url)
* @description Load Mesh from url (async)
* @param{string} url The URL to the mesh (JSON)
*/
-engine3d.prototype.LoadMesh = function(url)
+engine3d.prototype.LoadMesh = function (url)
{
var m = new Surface(this);
m.loadFromJSON(url);
this.vecMeshes.push(m);
-
+
return m;
}
-
//------------------------------------------------------------------------------
/**
- * @description Push all matrices (model, view, projectoin) to matrix stack
+ * @description Push all matrices (model, view, projectoin) to matrix stack
*/
-engine3d.prototype.PushMatrices = function()
+engine3d.prototype.PushMatrices = function ()
{
this.TravState.PushView(this.matView);
this.TravState.PushModel(this.matModel);
@@ -750,14 +865,14 @@ engine3d.prototype.PushMatrices = function()
/**
* @description Pop all matrices from matrix stack
*/
-engine3d.prototype.PopMatrices = function()
+engine3d.prototype.PopMatrices = function ()
{
var model = this.TravState.PopModel()
this.matModel.CopyFrom(model);
-
+
var view = this.TravState.PopView();
this.matView.CopyFrom(view);
-
+
var proj = this.TravState.PopProjection();
this.matProjection.CopyFrom(proj);
// update matrices again:
@@ -768,43 +883,50 @@ engine3d.prototype.PopMatrices = function()
/**
* @description Set Matrices to 2D projection, so you can draw directly on 2D screen.
*/
-engine3d.prototype.SetOrtho2D = function()
+engine3d.prototype.SetOrtho2D = function ()
{
var vp = this.gl.getParameter(this.gl.VIEWPORT);
- var w = vp[2]-vp[0];
- var h = vp[3]-vp[1];
+ var w = vp[2] - vp[0];
+ var h = vp[3] - vp[1];
this.matModel.Identity();
this.matView.Identity();
- this.matProjection.Ortho2D(0,w,0,h);
+ this.matProjection.Ortho2D(0, w, 0, h);
this._UpdateMatrices();
}
//------------------------------------------------------------------------------
/**
* @description Create Scene
*/
-engine3d.prototype.CreateScene = function()
+engine3d.prototype.CreateScene = function ()
{
if (this.worldtype == 0) // custom scene
{
- goog.debug.Logger.getLogger('owg.engine3d').warning("** WARNING: not implemented");
+ var options = {
+ "type":"custom"
+ };
+ this.scene = new SceneGraph(this, options);
+ this.scene.nodeRenderObject.DoResize(this.width, this.height);
}
else if (this.worldtype == 1) // wgs84
{
- this.scene = new SceneGraph(this);
- // call resize here to initialize the scenegraph: todo: move to scenegraph (don't call renderobject direcly)
- this.scene.nodeRenderObject.DoResize(this.width,this.height);
+ var options = {
+ "type":"ellipsoid"
+ };
+
+ this.scene = new SceneGraph(this, options);
+ this.scene.nodeRenderObject.DoResize(this.width, this.height);
+
}
else if (this.worldtype == 2)
{
goog.debug.Logger.getLogger('owg.engine3d').warning("** WARNING: not implemented");
}
else if (this.worldtype == 3)
{
- goog.debug.Logger.getLogger('owg.engine3d').warning("** WARNING: not implemented");
+ goog.debug.Logger.getLogger('owg.engine3d').warning("** WARNING: not implemented");
}
-
-
+
}
//------------------------------------------------------------------------------
@@ -816,11 +938,11 @@ engine3d.prototype.CreateScene = function()
* @param {number=} scale a scale for the font size
* @param {vec4=} fontcolor the color
*/
-engine3d.prototype.DrawText = function(txt,x,y,scale,fontcolor)
+engine3d.prototype.DrawText = function (txt, x, y, scale, fontcolor)
{
if (this.systemfont)
{
- this.systemfont.DrawText(txt,x,y,scale,fontcolor);
+ this.systemfont.DrawText(txt, x, y, scale, fontcolor);
}
}
//------------------------------------------------------------------------------
@@ -829,18 +951,19 @@ engine3d.prototype.DrawText = function(txt,x,y,scale,fontcolor)
* @param {string} txt the text
* @returns {Array} array with width, height
*/
-engine3d.prototype.GetTextSize = function(txt)
+engine3d.prototype.GetTextSize = function (txt)
{
- var ret = new Array(2);
- ret[0] = 0; ret[1] = 0;
+ var ret = new Array(2);
+ ret[0] = 0;
+ ret[1] = 0;
if (this.systemfont)
{
var w = this.systemfont.GetStringWidth(txt);
- var h = this.systemfont.GetStringHeight();
- ret[0] = w;
- ret[1] = h;
+ var h = this.systemfont.GetStringHeight();
+ ret[0] = w;
+ ret[1] = h;
}
- return ret;
+ return ret;
}
//------------------------------------------------------------------------------
/**
@@ -850,56 +973,56 @@ engine3d.prototype.GetTextSize = function(txt)
* @param {mat4} mvp the model-view-projection matrix.
* @param {boolean} normalize_dir true if direction should be normalized
*/
-engine3d.prototype.GetDirectionMousePos = function(x, y, mvp, normalize_dir)
+engine3d.prototype.GetDirectionMousePos = function (x, y, mvp, normalize_dir)
{
var mvpInv = new mat4();
mvpInv.Inverse(mvp);
var winx = x;
- var winy = this.height-y-1;
+ var winy = this.height - y - 1;
var winz = 0;
-
- var mx = (winx-0)*2/this.width - 1;
- var my = (winy-0)*2/this.height - 1;
+
+ var mx = (winx - 0) * 2 / this.width - 1;
+ var my = (winy - 0) * 2 / this.height - 1;
var mz = -1; //cordinates on nearplane
-
- var fx = (winx-0)*2/this.width - 1;
- var fy = (winy-0)*2/this.height - 1;
+
+ var fx = (winx - 0) * 2 / this.width - 1;
+ var fy = (winy - 0) * 2 / this.height - 1;
var fz = 1; //coordinates on farplane
- var CoorOnNearPlane = new vec3();
- CoorOnNearPlane.Set(mx,my,mz);
+ var CoorOnNearPlane = new vec3();
+ CoorOnNearPlane.Set(mx, my, mz);
var CoorOnNearPlaneWorld = mvpInv.MultiplyVec3(CoorOnNearPlane);
- var CoorOnFarPlane = new vec3();
- CoorOnFarPlane.Set(fx,fy,fz);
+ var CoorOnFarPlane = new vec3();
+ CoorOnFarPlane.Set(fx, fy, fz);
var CoorOnFarPlaneWorld = mvpInv.MultiplyVec3(CoorOnFarPlane);
-
+
//direction
var dirx = CoorOnFarPlaneWorld.Get()[0] - CoorOnNearPlaneWorld.Get()[0];
var diry = CoorOnFarPlaneWorld.Get()[1] - CoorOnNearPlaneWorld.Get()[1];
var dirz = CoorOnFarPlaneWorld.Get()[2] - CoorOnNearPlaneWorld.Get()[2];
-
+
//normalize direction
-
+
if (normalize_dir)
{
- var a = Math.sqrt(dirx*dirx+diry*diry+dirz*dirz);
- dirx/=a;
- diry/=a;
- dirz/=a;
+ var a = Math.sqrt(dirx * dirx + diry * diry + dirz * dirz);
+ dirx /= a;
+ diry /= a;
+ dirz /= a;
}
-
+
var res = CoorOnNearPlaneWorld.Get();
var pointAndDir = {};
- pointAndDir.x = res[0];
- pointAndDir.y = res[1];
- pointAndDir.z = res[2];
+ pointAndDir.x = res[0];
+ pointAndDir.y = res[1];
+ pointAndDir.z = res[2];
pointAndDir.dirx = dirx;
pointAndDir.diry = diry;
pointAndDir.dirz = dirz;
-
- return pointAndDir;
+
+ return pointAndDir;
}
//------------------------------------------------------------------------------
/**
@@ -908,24 +1031,24 @@ engine3d.prototype.GetDirectionMousePos = function(x, y, mvp, normalize_dir)
* @param {number} y the world y coordinate
* @param {number} z the world z coordinate
*/
-engine3d.prototype.WorldToWindow = function(x,y,z)
+engine3d.prototype.WorldToWindow = function (x, y, z)
{
var matViewProjection = new mat4();
matViewProjection.Multiply(this.matProjection, this.matModelView);
- var v = new vec3(x,y,z);
+ var v = new vec3(x, y, z);
var res = matViewProjection.MultiplyVec3(v); // (-1,-1)-(+1,+1)
var xw = res._values[0];
var yw = -res._values[1];
var zw = res._values[2];
- xw = (xw + 1)*0.5;
- yw = (yw + 1)*0.5;
- zw = (zw + 1)*0.5;
+ xw = (xw + 1) * 0.5;
+ yw = (yw + 1) * 0.5;
+ zw = (zw + 1) * 0.5;
- xw = Math.floor(xw*this.width + 0.5);
- yw = Math.floor(yw*this.height-1 + 0.5);
+ xw = Math.floor(xw * this.width + 0.5);
+ yw = Math.floor(yw * this.height - 1 + 0.5);
return [xw, yw, zw];
}
//------------------------------------------------------------------------------
@@ -935,17 +1058,19 @@ engine3d.prototype.WorldToWindow = function(x,y,z)
* @param {function()} callback
* @param {Element=} opt_element
*/
-if(typeof(window)!="undefined")//if owg runs in a webworker "window" is not available!
+if (typeof(window) != "undefined") //if owg runs in a webworker "window" is not available!
{
- window.requestAnimFrame = (function() {
+ window.requestAnimFrame = (function ()
+ {
return window.requestAnimationFrame ||
- window.webkitRequestAnimationFrame ||
- window.mozRequestAnimationFrame ||
- window.oRequestAnimationFrame ||
- window.msRequestAnimationFrame ||
- function(callback, element) {
- window.setTimeout(callback, 30);
- };
+ window.webkitRequestAnimationFrame ||
+ window.mozRequestAnimationFrame ||
+ window.oRequestAnimationFrame ||
+ window.msRequestAnimationFrame ||
+ function (callback, element)
+ {
+ window.setTimeout(callback, 30);
+ };
})();
}
@@ -962,45 +1087,51 @@ function fncTimer()
dtEnd = new Date();
var nMSeconds = dtEnd.valueOf() - dtStart.valueOf();
dtStart = dtEnd;
-
- for (var i=0;i<_g_vInstances.length;i++)
+
+ for (var i = 0; i < _g_vInstances.length; i++)
{
var engine = _g_vInstances[i];
// (1) Call Timer Event
-
- if (engine.scene)
- {
- engine.scene.Tick(nMSeconds);
- }
-
- if (engine.cbfTimer)
- {
- engine.cbfTimer(nMSeconds, engine);
- }
-
- // (2) Set Current Viewport and clear
- engine.SetViewport(0, 0, engine.width, engine.height);
- engine.Clear();
-
-
- // (3) Draw Scenegraph
- if (engine.scene)
- {
- engine.scene.Traverse();
- engine.scene.Render();
- }
-
- // (4) Call Render Callback (-> integrate in Scenegraph)
- if (engine.cbfRender)
- {
- engine.cbfRender(engine); // call draw callback function
- }
- if(typeof(window)!="undefined") //if owg runs in a webworker "window" is not available!
+
+ if (!engine.gl.isContextLost())
{
- window.requestAnimFrame(fncTimer, engine.context);
- }
-
+ if (engine.scene)
+ {
+ engine.scene.Tick(nMSeconds);
+ }
+
+ if (engine.cbfTimer)
+ {
+ engine.cbfTimer(nMSeconds, engine);
+ }
+
+ // (2) Set Current Viewport and clear
+ engine.SetViewport(0, 0, engine.width, engine.height);
+ engine.Clear();
+
+ // (3) Draw Scenegraph
+ if (engine.scene)
+ {
+ engine.scene.Traverse();
+ engine.scene.Render();
+ }
+
+ var error = engine.gl.getError();
+ if (error != engine.gl.NO_ERROR && error != engine.gl.CONTEXT_LOST_WEBGL)
+ {
+ ogLog("WebGL Error: " + error);
+ }
+ // (4) Call Render Callback (-> integrate in Scenegraph)
+ if (engine.cbfRender)
+ {
+ engine.cbfRender(engine); // call draw callback function
+ }
+ if (typeof(window) != "undefined") //if owg runs in a webworker "window" is not available!
+ {
+ window.requestAnimFrame(fncTimer, engine.context);
+ }
+ }
}
}
@@ -1014,20 +1145,20 @@ function fncTimer()
* @param {number} h height
* @ignore
*/
-engine3d.prototype._resize = function(w,h)
+engine3d.prototype._resize = function (w, h)
{
this.width = w;
this.height = h;
// called on resize...
if (this.cbfResize)
{
- var engine = this;
+ var engine = this;
this.cbfResize(w, h, engine);
}
if (this.scene)
{
- this.scene.nodeRenderObject.DoResize(w,h); // todo: move to scenegraph
+ this.scene.nodeRenderObject.DoResize(w, h); // todo: move to scenegraph
}
}
@@ -1036,7 +1167,7 @@ engine3d.prototype._resize = function(w,h)
* @description sets the init callback function
* @param {function(engine3d)} f init callback handler.
*/
-engine3d.prototype.SetInitCallback = function(f)
+engine3d.prototype.SetInitCallback = function (f)
{
this.cbfInit = f;
}
@@ -1046,7 +1177,7 @@ engine3d.prototype.SetInitCallback = function(f)
* @description sets the timer callback function
* @param {?function(number, engine3d)} f timer callback handler.
*/
-engine3d.prototype.SetTimerCallback = function(f)
+engine3d.prototype.SetTimerCallback = function (f)
{
this.cbfTimer = f;
}
@@ -1057,7 +1188,7 @@ engine3d.prototype.SetTimerCallback = function(f)
*
* @param {function(engine3d)} f render callback handler.
*/
-engine3d.prototype.SetRenderCallback = function(f)
+engine3d.prototype.SetRenderCallback = function (f)
{
this.cbfRender = f;
}
@@ -1068,7 +1199,7 @@ engine3d.prototype.SetRenderCallback = function(f)
*
* @param {?function(number, number, number, engine3d)} opt_f mousedown callback handler.
*/
-engine3d.prototype.SetMouseDownCallback = function(opt_f)
+engine3d.prototype.SetMouseDownCallback = function (opt_f)
{
if (this.cbfMouseDown)
{
@@ -1077,11 +1208,12 @@ engine3d.prototype.SetMouseDownCallback = function(opt_f)
}
if (opt_f)
{
- this.cbfMouseDown = goog.events.listen(this.context, goog.events.EventType.MOUSEDOWN, function(e) {
- var x = e.clientX - this.xoffset / 2;
- var y = e.clientY - this.yoffset / 2;
- opt_f(e.button, x, y, this);
- }, false, this);
+ this.cbfMouseDown = goog.events.listen(this.context, goog.events.EventType.MOUSEDOWN, function (e)
+ {
+ var x = e.clientX - this.xoffset / 2;
+ var y = e.clientY - this.yoffset / 2;
+ opt_f(e.button, x, y, this);
+ }, false, this);
}
};
@@ -1091,7 +1223,7 @@ engine3d.prototype.SetMouseDownCallback = function(opt_f)
*
* @param {?function(number, number, number, engine3d)} opt_f mouseup callback handler.
*/
-engine3d.prototype.SetMouseUpCallback = function(opt_f)
+engine3d.prototype.SetMouseUpCallback = function (opt_f)
{
if (this.cbfMouseUp)
{
@@ -1100,11 +1232,12 @@ engine3d.prototype.SetMouseUpCallback = function(opt_f)
}
if (opt_f)
{
- this.cbfMouseUp = goog.events.listen(this.context, goog.events.EventType.MOUSEUP, function(e) {
- var x = e.clientX - this.xoffset / 2;
- var y = e.clientY - this.yoffset / 2;
- opt_f(e.button, x, y, this);
- }, false, this);
+ this.cbfMouseUp = goog.events.listen(this.context, goog.events.EventType.MOUSEUP, function (e)
+ {
+ var x = e.clientX - this.xoffset / 2;
+ var y = e.clientY - this.yoffset / 2;
+ opt_f(e.button, x, y, this);
+ }, false, this);
}
};
@@ -1114,7 +1247,7 @@ engine3d.prototype.SetMouseUpCallback = function(opt_f)
*
* @param {?function(number, number, engine3d)} opt_f mousemove callback handler.
*/
-engine3d.prototype.SetMouseMoveCallback = function(opt_f)
+engine3d.prototype.SetMouseMoveCallback = function (opt_f)
{
if (this.cbfMouseMove)
{
@@ -1123,11 +1256,12 @@ engine3d.prototype.SetMouseMoveCallback = function(opt_f)
}
if (opt_f)
{
- this.cbfMouseMove = goog.events.listen(this.context, goog.events.EventType.MOUSEMOVE, function(e) {
- var x = e.clientX - this.xoffset / 2;
- var y = e.clientY - this.yoffset / 2;
- opt_f(x, y, this);
- }, false, this);
+ this.cbfMouseMove = goog.events.listen(this.context, goog.events.EventType.MOUSEMOVE, function (e)
+ {
+ var x = e.clientX - this.xoffset / 2;
+ var y = e.clientY - this.yoffset / 2;
+ opt_f(x, y, this);
+ }, false, this);
}
};
@@ -1137,7 +1271,7 @@ engine3d.prototype.SetMouseMoveCallback = function(opt_f)
*
* @param {?function(number, engine3d)} opt_f mousewhell callback handler.
*/
-engine3d.prototype.SetMouseWheelCallback = function(opt_f)
+engine3d.prototype.SetMouseWheelCallback = function (opt_f)
{
if (this.cbfMouseWheel)
{
@@ -1147,10 +1281,11 @@ engine3d.prototype.SetMouseWheelCallback = function(opt_f)
if (opt_f)
{
var mouseWheelHandler = new goog.events.MouseWheelHandler(this.context);
- this.cbfMouseWheel = goog.events.listen(mouseWheelHandler, goog.events.EventType.MOUSEMOVE, function(e) {
- e.preventDefault();
- opt_f(e.deltaY, this);
- }, false, this);
+ this.cbfMouseWheel = goog.events.listen(mouseWheelHandler, goog.events.EventType.MOUSEMOVE, function (e)
+ {
+ e.preventDefault();
+ opt_f(e.deltaY, this);
+ }, false, this);
}
};
@@ -1160,7 +1295,7 @@ engine3d.prototype.SetMouseWheelCallback = function(opt_f)
*
* @param {function(number, number, engine3d)} f resize callback handler.
*/
-engine3d.prototype.SetResizeCallback = function(f)
+engine3d.prototype.SetResizeCallback = function (f)
{
this.cbfResize = f;
}
@@ -1171,7 +1306,7 @@ engine3d.prototype.SetResizeCallback = function(f)
*
* @param {?function(number, engine3d)} opt_f keydown callback handler.
*/
-engine3d.prototype.SetKeyDownCallback = function(opt_f)
+engine3d.prototype.SetKeyDownCallback = function (opt_f)
{
if (_gcbfKeyDown)
{
@@ -1180,7 +1315,10 @@ engine3d.prototype.SetKeyDownCallback = function(opt_f)
}
if (opt_f)
{
- _gcbfKeyDown = goog.events.listen(window, goog.events.EventType.KEYDOWN, function(e) { opt_f(e.keyCode, this); },false,this);
+ _gcbfKeyDown = goog.events.listen(window, goog.events.EventType.KEYDOWN, function (e)
+ {
+ opt_f(e.keyCode, this);
+ }, false, this);
}
};
//------------------------------------------------------------------------------
@@ -1189,7 +1327,7 @@ engine3d.prototype.SetKeyDownCallback = function(opt_f)
*
* @param {?function(number, engine3d)} opt_f keyup callback handler.
*/
-engine3d.prototype.SetKeyUpCallback = function(opt_f)
+engine3d.prototype.SetKeyUpCallback = function (opt_f)
{
if (_gcbfKeyUp)
{
@@ -1198,7 +1336,10 @@ engine3d.prototype.SetKeyUpCallback = function(opt_f)
}
if (opt_f)
{
- _gcbfKeyUp = goog.events.listen(window, goog.events.EventType.KEYUP, function(e) { opt_f(e.keyCode, this); },false,this);
+ _gcbfKeyUp = goog.events.listen(window, goog.events.EventType.KEYUP, function (e)
+ {
+ opt_f(e.keyCode, this);
+ }, false, this);
}
};
@@ -1217,11 +1358,11 @@ engine3d.prototype.SetKeyUpCallback = function(opt_f)
* pickresult["y"]: geocentric cartesian y-coordinate at mouse position
* pickresult["z"]: geocentric cartesian z-coordinate at mouse position
*/
-engine3d.prototype.PickGlobe = function(mx, my, pickresult)
+engine3d.prototype.PickGlobe = function (mx, my, pickresult)
{
- if (this.scene)
+ if (this.scene && this.scene.nodeRenderObject && this.scene.nodeRenderObject.globerenderer)
{
- this.scene.nodeRenderObject.globerenderer.PickGlobe(mx,my,pickresult);
+ this.scene.nodeRenderObject.globerenderer.PickGlobe(mx, my, pickresult);
}
}
@@ -1230,9 +1371,9 @@ engine3d.prototype.PickGlobe = function(mx, my, pickresult)
* @description UpdatePickMatrix: Updates the pick matrix
* @param {mat4} matView
*/
-engine3d.prototype.UpdatePickMatrix = function(matView)
+engine3d.prototype.UpdatePickMatrix = function (matView)
{
- if (this.scene)
+ if (this.scene && this.scene.nodeRenderObject && this.scene.nodeRenderObject.globerenderer)
{
var pickmatrix = new mat4();
pickmatrix.Multiply(this.matProjection, matView);
@@ -1253,11 +1394,11 @@ engine3d.prototype.UpdatePickMatrix = function(matView)
* pickresult["y"]: geocentric cartesian y-coordinate at mouse position
* pickresult["z"]: geocentric cartesian z-coordinate at mouse position
*/
-engine3d.prototype.PickEllipsoid = function(mx, my, pickresult, initialize)
+engine3d.prototype.PickEllipsoid = function (mx, my, pickresult, initialize)
{
- if (this.scene)
+ if (this.scene && this.scene.nodeRenderObject && this.scene.nodeRenderObject.globerenderer)
{
- this.scene.nodeRenderObject.globerenderer.PickEllipsoid(mx,my,pickresult,initialize);
+ this.scene.nodeRenderObject.globerenderer.PickEllipsoid(mx, my, pickresult, initialize);
}
}
@@ -1267,11 +1408,11 @@ engine3d.prototype.PickEllipsoid = function(mx, my, pickresult, initialize)
* @param {number} mx
* @param {number} my
*/
-engine3d.prototype.PickPOI = function(mx, my)
+engine3d.prototype.PickPOI = function (mx, my)
{
- if (this.scene)
+ if (this.scene && this.scene.nodeRenderObject && this.scene.nodeRenderObject.poirenderer)
{
- return this.scene.nodeRenderObject.poirenderer.PickPOI(mx,my);
+ return this.scene.nodeRenderObject.poirenderer.PickPOI(mx, my);
}
return null;
}
@@ -1282,11 +1423,11 @@ engine3d.prototype.PickPOI = function(mx, my)
* @param {number} mx
* @param {number} my
*/
-engine3d.prototype.PickSurface = function(mx, my)
+engine3d.prototype.PickSurface = function (mx, my)
{
- if (this.scene)
+ if (this.scene && this.scene.nodeRenderObject && this.scene.nodeRenderObject.geometryrenderer)
{
- return this.scene.nodeRenderObject.geometryrenderer.PickSurface(mx,my);
+ return this.scene.nodeRenderObject.geometryrenderer.PickSurface(mx, my);
}
return -1;
}
@@ -1297,57 +1438,69 @@ engine3d.prototype.PickSurface = function(mx, my)
* @param {number} mx
* @param {number} my
*/
-engine3d.prototype.PickBillboard = function(mx, my)
+engine3d.prototype.PickBillboard = function (mx, my)
{
- if (this.scene)
+ if (this.scene && this.scene.nodeRenderObject && this.scene.nodeRenderObject.billboardrenderer)
{
- return this.scene.nodeRenderObject.billboardrenderer.PickBillboard(mx,my);
+ return this.scene.nodeRenderObject.billboardrenderer.PickBillboard(mx, my);
}
return -1;
}
- //-----------------------------------------------------------------------------
- /**
+//-----------------------------------------------------------------------------
+/**
* @description Returns the altitude above ground [m]
*/
-engine3d.prototype.AltitudeAboveGround = function()
+engine3d.prototype.AltitudeAboveGround = function ()
{
- if (this.scene)
+ if (this.scene && this.scene.nodeRenderObject && this.scene.nodeRenderObject.globerenderer)
{
return this.scene.nodeRenderObject.globerenderer.AltitudeAboveGround();
- }
-
- return 0;
+ }
+
+ return 0;
}
- //-----------------------------------------------------------------------------
- /**
+//-----------------------------------------------------------------------------
+/**
* @description Returns the altitude above ellipsoid [m]
*/
-engine3d.prototype.AltitudeAboveEllipsoid = function()
+engine3d.prototype.AltitudeAboveEllipsoid = function ()
{
if (this.scene)
{
return this.scene.nodeNavigation.GetPosition().elevation;
- }
-
+ }
+
return 0;
}
- //-----------------------------------------------------------------------------
- /**
+//-----------------------------------------------------------------------------
+/**
* @description Returns the elevation at specified position.
* @param {number} lng
* @param {number} lat
* @return {Object}
* return["hasvalue"] true, if there is a valid value
* return["elevation"] : elevation at specified position
- * return["lod"] : level of detail at position
+ * return["lod"] : level of detail at position
*/
-engine3d.prototype.GetElevationAt = function(lng, lat)
+engine3d.prototype.GetElevationAt = function (lng, lat)
{
- if (this.scene)
+ if (this.scene && this.scene.nodeRenderObject && this.scene.nodeRenderObject.globerenderer)
{
return this.scene.nodeRenderObject.globerenderer.GetElevationAt(lng, lat);
}
+
+ // Special case: There is no globe. GetElevationAt always returns 0 in this case.
+ if (!this.scene.nodeRenderObject.globerenderer)
+ {
+
+ var oReturn = { "hasvalue":true,
+ "elevation":0,
+ "lod":0
+ };
+ return oReturn;
+ }
+
var oFailed = {};
oFailed["hasvalue"] = false;
oFailed["elevation"] = 0;
@@ -1360,7 +1513,7 @@ engine3d.prototype.GetElevationAt = function(lng, lat)
* @ignore
* @param {number} worldtype
*/
-engine3d.prototype.SetWorldType = function(worldtype)
+engine3d.prototype.SetWorldType = function (worldtype)
{
this.worldtype = worldtype;
}
@@ -1369,7 +1522,7 @@ engine3d.prototype.SetWorldType = function(worldtype)
// ** FlyTo Functions **
//##############################################################################
//------------------------------------------------------------------------------
-/**
+/**
* @description flies the camera to a specific position. yaw,pitch and roll are
* optional if they are defined, there will be an interpolation between the current
* angles and the target angles otherwise the angles will not be changed.
@@ -1380,14 +1533,13 @@ engine3d.prototype.SetWorldType = function(worldtype)
* @param {number} pitch target pitch
* @param {number} roll target roll
*/
-engine3d.prototype.FlyTo = function(lng,lat,elv,yaw,pitch,roll)
+engine3d.prototype.FlyTo = function (lng, lat, elv, yaw, pitch, roll)
{
- this.flyto.StartFlyTo(lng,lat,elv,yaw,pitch,roll);
+ this.flyto.StartFlyTo(lng, lat, elv, yaw, pitch, roll);
}
-
//------------------------------------------------------------------------------
-/**
+/**
* @description The camera moves to a LookAt Position "distance" away from the
* point defined by lng,lat,elv. The camera orientation will not changed.
* @param {number} lng target longitude
@@ -1398,35 +1550,35 @@ engine3d.prototype.FlyTo = function(lng,lat,elv,yaw,pitch,roll)
* @param {number} opt_pitch in [degrees]
* @param {number} opt_roll in [degrees]
*/
-engine3d.prototype.FlyToLookAtPosition = function(lng,lat,elv,distance,opt_yaw,opt_pitch,opt_roll)
+engine3d.prototype.FlyToLookAtPosition = function (lng, lat, elv, distance, opt_yaw, opt_pitch, opt_roll)
{
- this.flyto.FlyToLookAtPosition(lng,lat,elv,distance,opt_yaw,opt_pitch,opt_roll);
+ this.flyto.FlyToLookAtPosition(lng, lat, elv, distance, opt_yaw, opt_pitch, opt_roll);
}
//------------------------------------------------------------------------------
-/**
+/**
* @description Set the duration of the FlyTo-animation in [ms].
* @param {number} timespan duration in [ms]
*/
-engine3d.prototype.SetFlightDuration = function(timespan)
+engine3d.prototype.SetFlightDuration = function (timespan)
{
- this.flyto.SetFlightDuration(timespan);
+ this.flyto.SetFlightDuration(timespan);
}
//------------------------------------------------------------------------------
/**
* @description Break fly to animation cycle
*/
-engine3d.prototype.StopFlyTo = function()
+engine3d.prototype.StopFlyTo = function ()
{
- this.flyto.StopFlyTo();
+ this.flyto.StopFlyTo();
}
//------------------------------------------------------------------------------
/**
* @description Set Current Render Target (must be texture)
* @param {Texture} texture
-*/
-engine3d.prototype.PushRenderTarget = function(texture)
+ */
+engine3d.prototype.PushRenderTarget = function (texture)
{
this.RenderTargetStack.push(texture);
texture._EnableRenderToTexture();
@@ -1436,7 +1588,7 @@ engine3d.prototype.PushRenderTarget = function(texture)
/**
* @description Reset Render Target
*/
-engine3d.prototype.PopRenderTarget = function()
+engine3d.prototype.PopRenderTarget = function ()
{
if (this.RenderTargetStack.length < 1)
{
@@ -1449,10 +1601,10 @@ engine3d.prototype.PopRenderTarget = function()
var l = this.RenderTargetStack.length;
- if (l>0)
+ if (l > 0)
{
/** @type {Texture} */
- var activetarget = this.RenderTargetStack[l-1];
+ var activetarget = this.RenderTargetStack[l - 1];
activetarget._EnableRenderToTexture();
}
else
View
57 source/core/globerenderer.js
@@ -35,6 +35,8 @@ goog.require('owg.i3dElevationLayer');
goog.require('owg.owgElevationLayer');
goog.require('owg.GoogleImageLayer');
goog.require('owg.OYMImageLayer');
+goog.require('owg.TMSImageLayer');
+goog.require('owg.WMSImageLayer');
//------------------------------------------------------------------------------
/**
* @typedef {{
@@ -150,6 +152,7 @@ GlobeRenderer.prototype.Destroy = function()
* service: i3d for i3d tile layout (deprecated)
* osm for OpenStreetMap tile layout
* owg for OpenWebGlobe tile layout (default)
+ * tms for TMS tile layout
*
* Example:
* var imglayer =
@@ -222,6 +225,45 @@ GlobeRenderer.prototype.AddImageLayer = function(options)
this._UpdateLayers();
}
}
+ // TMS service
+ else if (options["service"] == "tms")
+ {
+ if (goog.isDef(options["url"]) && options["url"].length>0)
+ {
+ var imgLayer = new TMSImageLayer();
+ if (goog.isDef(options["minlod"]))
+ {
+ imgLayer.userminlod = options["minlod"];
+ }
+ if (goog.isDef(options["maxlod"]))
+ {
+ imgLayer.usermaxlod = options["maxlod"];
+ }
+ imgLayer.Setup(options["url"]);
+ index = this.imagelayerlist.length;
+ this.imagelayerlist.push(imgLayer);
+ this._UpdateLayers();
+ }
+ }
+ // TMS service
+ else if (options["service"] == "wms")
+ {
+ if (goog.isDef(options["url"]) && options["url"].length>0
+ && goog.isDef(options["layer"]) && options["layer"].length>0)
+ {
+ var imgLayer = new WMSImageLayer();
+ if (goog.isDef(options["format"]))
+ {imgLayer.format = options["format"];}
+ if (goog.isDef(options["style"]))
+ {imgLayer.style = options["style"];}
+ if (goog.isDef(options["version"]))
+ {imgLayer.version = options["version"];}
+ imgLayer.Setup(options["url"],options["layer"],options["SRS"],options["format"],options["style"],options["version"],options["transparency"]);
+ index = this.imagelayerlist.length;
+ this.imagelayerlist.push(imgLayer);
+ this._UpdateLayers();
+ }
+ }
// OpenWebGlobe tile layout
else if (options["service"] == "owg")
{
@@ -706,6 +748,7 @@ GlobeRenderer.prototype.PickGlobe = function(mx, my, pickresult)
{
var pointDir = this.engine.GetDirectionMousePos(mx, my, this.matPick, true);
var candidates = new Array();
+ var meshmode = 0;
for (var i=0;i<this.lstFrustum.length;i++)
{
@@ -735,6 +778,15 @@ GlobeRenderer.prototype.PickGlobe = function(mx, my, pickresult)
{
pickresult["hit"] = true;
tmin = r.t;
+
+ if (!candidates[i].haselevation)
+ {
+ meshmode = 1;
+ }
+ else
+ {
+ meshmode = 0;
+ }
}
}
}
@@ -752,6 +804,11 @@ GlobeRenderer.prototype.PickGlobe = function(mx, my, pickresult)
pickresult["lng"] = gc._wgscoords[0];
pickresult["lat"] = gc._wgscoords[1];
pickresult["elv"] = gc._wgscoords[2];
+
+ if (meshmode == 1)
+ {
+ pickresult["elv"] = 0;
+ }
}
}
//-----------------------------------------------------------------------------