1
/* -*- Mode: JavaScript; coding: utf-8; tab-width: 3; indent-tabs-mode: tab; c-basic-offset: 3 -*-
2
*******************************************************************************
4
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6
* Copyright create3000, Scheffelstraße 31a, Leipzig, Germany 2011.
8
* All rights reserved. Holger Seelig <holger.seelig@yahoo.de>.
10
* The copyright notice above does not evidence any actual of intended
11
* publication of such source code, and is an unpublished work by create3000.
12
* This material contains CONFIDENTIAL INFORMATION that is the property of
15
* No permission is granted to copy, distribute, or create derivative works from
16
* the contents of this software, in whole or in part, without the prior written
17
* permission of create3000.
19
* NON-MILITARY USE ONLY
21
* All create3000 software are effectively free software with a non-military use
22
* restriction. It is free. Well commented source is provided. You may reuse the
23
* source in any way you please with the exception anything that uses it must be
24
* marked to indicate is contains 'non-military use only' components.
26
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
28
* Copyright 2015, 2016 Holger Seelig <holger.seelig@yahoo.de>.
30
* This file is part of the Cobweb Project.
32
* Cobweb is free software: you can redistribute it and/or modify it under the
33
* terms of the GNU General Public License version 3 only, as published by the
34
* Free Software Foundation.
36
* Cobweb is distributed in the hope that it will be useful, but WITHOUT ANY
37
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
38
* A PARTICULAR PURPOSE. See the GNU General Public License version 3 for more
39
* details (a copy is included in the LICENSE file that accompanied this code).
41
* You should have received a copy of the GNU General Public License version 3
42
* along with Cobweb. If not, see <http://www.gnu.org/licenses/gpl.html> for a
43
* copy of the GPLv3 License.
45
* For Silvio, Joy and Adi.
47
******************************************************************************/
52
"cobweb/Browser/Core/BrowserOptions",
53
"cobweb/Browser/Core/BrowserProperties",
54
"cobweb/Browser/Core/RenderingProperties",
55
"cobweb/Browser/Core/Notification",
56
"cobweb/Browser/Core/BrowserTimings",
57
"cobweb/Browser/Core/ContextMenu",
58
"cobweb/Execution/Scene",
59
"cobweb/Parser/Parser",
75
var browserNumber = 0;
77
function getContext (canvas)
79
var gl = canvas .getContext ("webgl") ||
80
canvas .getContext ("experimental-webgl");
83
throw new Error ("Couldn't create WebGL context.");
87
// If the aliased linewidth ranges are both 1, gl.lineWidth is probably not possible,
88
// thus we disable it completely to prevent webgl errors.
90
var aliasedLineWidthRange = gl .getParameter (gl .ALIASED_LINE_WIDTH_RANGE);
92
if (aliasedLineWidthRange [0] === 1 && aliasedLineWidthRange [1] === 1)
94
gl .lineWidth = Function .prototype;
102
function X3DCoreContext (element)
104
this .number = ++ browserNumber;
105
this .element = element;
107
// Get canvas & context.
109
var browser = $("<div></div>") .addClass ("cobweb-browser") .prependTo (this .element);
110
var splashScreen = $("<div></div>") .addClass ("cobweb-splash-screen") .appendTo (browser);
111
var spinner = $("<div></div>") .addClass ("cobweb-spinner") .appendTo (splashScreen);
112
var progress = $("<div></div>") .addClass ("cobweb-progress") .appendTo (splashScreen);
113
var surface = $("<div></div>") .addClass ("cobweb-surface cobweb-surface-" + this .getId ()) .appendTo (browser);
115
$("<div></div>") .addClass ("cobweb-spinner-one") .appendTo (spinner);
116
$("<div></div>") .addClass ("cobweb-spinner-two") .appendTo (spinner);
117
$("<div></div>") .addClass ("cobweb-spinner-three") .appendTo (spinner);
118
$("<div></div>") .addClass ("cobweb-spinner-text") .appendTo (progress) .text ("Lade 0 Dateien");
119
$("<div></div>") .addClass ("cobweb-progressbar") .appendTo (progress) .append ($("<div></div>"));
121
this .splashScreen = splashScreen;
122
this .canvas = $("<canvas></canvas>") .prependTo (surface);
123
this .context = getContext (this .canvas [0]);
125
this .privateScene = new Scene (this); // Scene for default nodes.
127
this .browserOptions = new BrowserOptions (this .getPrivateScene ());
128
this .browserProperties = new BrowserProperties (this .getPrivateScene ());
129
this .renderingProperties = new RenderingProperties (this .getPrivateScene ());
130
this .notification = new Notification (this .getPrivateScene ());
131
this .browserTimings = new BrowserTimings (this .getPrivateScene ());
132
this .contextMenu = new ContextMenu (this .getPrivateScene ());
134
this .dataStorage = new DataStorage ("X3DBrowser(" + this .number + ").");
135
this .mobile = /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i .test (navigator .userAgent);
137
this .getCanvas () .fadeOut (0);
139
if (this .getBrowserOptions () .getSplashScreen ())
140
this .getSplashScreen () .fadeIn (0);
142
$(".cobweb-console") .empty ();
145
X3DCoreContext .prototype =
147
initialize: function ()
149
// Scene for default nodes.
151
this .privateScene .setPrivate (true);
152
this .privateScene .setLive (true);
153
this .privateScene .setup ();
155
// Setup browser nodes.
157
this .browserOptions .setup ()
158
this .browserProperties .setup ()
159
this .renderingProperties .setup ();
160
this .notification .setup ();
161
this .browserTimings .setup ();
162
this .contextMenu .setup ();
164
// Observe Element's attributes.
166
this .observer = new MutationObserver (this .processMutations .bind (this));
168
this .observer .observe (this .element [0], { attributes: true, childList: false, characterData: false, subtree: false });
170
getNumber: function ()
174
isStrict: function ()
178
getElement: function ()
180
return this .element;
182
getSplashScreen: function ()
184
return this .splashScreen;
186
getCanvas: function ()
190
getContext: function ()
192
return this .context;
194
getBrowserOptions: function ()
196
return this .browserOptions;
198
getBrowserProperties: function ()
200
return this .browserProperties;
202
getRenderingProperties: function ()
204
return this .renderingProperties;
206
getNotification: function ()
208
return this .notification;
210
getBrowserTimings: function ()
212
return this .browserTimings;
214
getDataStorage: function ()
216
return this .dataStorage;
218
getMobile: function ()
222
processMutations: function (mutations)
224
mutations .forEach (function (mutation)
226
this .processMutation (mutation);
230
processMutation: function (mutation)
232
var element = mutation .target;
234
switch (mutation .type)
238
this .processAttribute (mutation, element);
243
processAttribute: function (mutation, element)
245
var attributeName = mutation .attributeName;
247
switch (attributeName .toLowerCase())
250
var urlCharacters = this .getElement () .attr ("src");
253
this .load ('"' + urlCharacters + '"');
257
this .load (this .getElement () .attr ("url"));
260
this .getBrowserOptions () .setAttributeSplashScreen ();
264
load: function (urlCharacters)
269
parser = new Parser (this .getExecutionContext (), true),
270
url = new Fields .MFString (),
271
parameter = new Fields .MFString ();
273
parser .setInput (urlCharacters);
274
parser .sfstringValues (url);
277
this .loadURL (url, parameter);
281
if (! this .getLoading ())
282
this .getCanvas () .fadeIn (0);
285
getPrivateScene: function ()
287
return this .privateScene;
291
return X3DCoreContext;