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/Components/Core/X3DNode",
53
"cobweb/Rendering/X3DRenderObject",
54
"cobweb/Components/Layering/X3DViewportNode",
55
"cobweb/Execution/BindableStack",
56
"cobweb/Execution/BindableList",
57
"cobweb/Components/Navigation/NavigationInfo",
58
"cobweb/Components/EnvironmentalEffects/Fog",
59
"cobweb/Components/EnvironmentalEffects/Background",
60
"cobweb/Bits/X3DCast",
61
"cobweb/Bits/TraverseType",
62
"cobweb/Bits/X3DConstants",
63
"standard/Math/Geometry/Camera",
64
"standard/Math/Numbers/Vector3",
65
"standard/Math/Numbers/Matrix4",
85
var projectionMatrix = new Matrix4 ();
87
function X3DLayerNode (executionContext, defaultViewpoint, groupNode)
89
X3DNode .call (this, executionContext);
90
X3DRenderObject .call (this, executionContext);
92
this .addType (X3DConstants .X3DLayerNode);
94
this .groupNode = groupNode;
95
this .currentViewport = null;
97
this .defaultBackground = new Background (executionContext);
98
this .defaultFog = new Fog (executionContext);
99
this .defaultNavigationInfo = new NavigationInfo (executionContext);
100
this .defaultViewpoint = defaultViewpoint;
102
this .backgroundStack = new BindableStack (executionContext, this, this .defaultBackground);
103
this .fogStack = new BindableStack (executionContext, this, this .defaultFog);
104
this .navigationInfoStack = new BindableStack (executionContext, this, this .defaultNavigationInfo);
105
this .viewpointStack = new BindableStack (executionContext, this, this .defaultViewpoint);
107
this .backgrounds = new BindableList (executionContext, this, this .defaultBackground)
108
this .fogs = new BindableList (executionContext, this, this .defaultFog);
109
this .navigationInfos = new BindableList (executionContext, this, this .defaultNavigationInfo);
110
this .viewpoints = new BindableList (executionContext, this, this .defaultViewpoint);
112
this .defaultBackground .setHidden (true);
113
this .defaultFog .setHidden (true);
115
this .collisionTime = 0;
118
X3DLayerNode .prototype = $.extend (Object .create (X3DNode .prototype),
119
X3DRenderObject .prototype,
121
constructor: X3DLayerNode,
123
initialize: function ()
125
X3DNode .prototype .initialize .call (this);
126
X3DRenderObject .prototype .initialize .call (this);
128
this .groupNode .children_ = this .children_;
129
this .groupNode .setPrivate (true);
130
this .groupNode .setup ();
132
this .defaultNavigationInfo .setup ();
133
this .defaultBackground .setup ();
134
this .defaultFog .setup ();
135
this .defaultViewpoint .setup ();
137
this .backgroundStack .setup ();
138
this .fogStack .setup ();
139
this .navigationInfoStack .setup ();
140
this .viewpointStack .setup ();
142
this .backgrounds .setup ();
143
this .fogs .setup ();
144
this .navigationInfos .setup ();
145
this .viewpoints .setup ();
147
this .viewport_ .addInterest ("set_viewport__", this);
148
this .addChildren_ .addFieldInterest (this .groupNode .addChildren_);
149
this .removeChildren_ .addFieldInterest (this .groupNode .removeChildren_);
150
this .children_ .addFieldInterest (this .groupNode .children_);
152
this .set_viewport__ ();
154
isLayer0: function (value)
156
this .layer0 = value;
157
this .defaultBackground .setHidden (! value);
159
getLayer: function ()
163
getGroup: function ()
165
return this .groupNode;
167
getViewport: function ()
169
return this .currentViewport;
171
getBackground: function ()
173
return this .backgroundStack .top ();
177
return this .fogStack .top ();
179
getNavigationInfo: function ()
181
return this .navigationInfoStack .top ();
183
getViewpoint: function ()
185
return this .viewpointStack .top ();
187
getBackgrounds: function ()
189
return this .backgrounds;
195
getNavigationInfos: function ()
197
return this .navigationInfos;
199
getViewpoints: function ()
201
return this .viewpoints;
203
getUserViewpoints: function ()
205
var userViewpoints = [ ];
207
for (var i = 0; i < this .viewpoints .get () .length; ++ i)
209
var viewpoint = this .viewpoints .get () [i];
211
if (viewpoint .description_ .length)
212
userViewpoints .push (viewpoint);
215
return userViewpoints;
217
getBackgroundStack: function ()
219
return this .backgroundStack;
221
getFogStack: function ()
223
return this .fogStack;
225
getNavigationInfoStack: function ()
227
return this .navigationInfoStack;
229
getViewpointStack: function ()
231
return this .viewpointStack;
233
getBBox: function (bbox)
235
return this .groupNode .getBBox (bbox);
237
set_viewport__: function ()
239
this .currentViewport = X3DCast (X3DConstants .X3DViewportNode, this .viewport_);
241
if (! this .currentViewport)
242
this .currentViewport = this .getBrowser () .getDefaultViewport ();
244
bind: function (viewpointName)
246
this .traverse (TraverseType .CAMERA, this);
248
// Bind first viewpoint in viewpoint list.
251
navigationInfo = this .navigationInfos .getBound (),
252
background = this .backgrounds .getBound (),
253
fog = this .fogs .getBound (),
254
viewpoint = this .viewpoints .getBound (viewpointName);
256
this .navigationInfoStack .forcePush (navigationInfo);
257
this .backgroundStack .forcePush (background);
258
this .fogStack .forcePush (fog);
259
this .viewpointStack .forcePush (viewpoint);
261
navigationInfo .addLayer (this);
262
background .addLayer (this);
263
fog .addLayer (this);
264
viewpoint .addLayer (this);
266
viewpoint .resetUserOffsets ();
268
traverse: function (type, renderObject)
270
renderObject = renderObject || this;
272
var viewpoint = this .getViewpoint ();
274
this .getCameraSpaceMatrix () .pushMatrix (viewpoint .getCameraSpaceMatrix ());
275
this .getInverseCameraSpaceMatrix () .pushMatrix (viewpoint .getInverseCameraSpaceMatrix ());
276
this .getProjectionMatrix () .pushMatrix (viewpoint .getProjectionMatrix (this));
280
case TraverseType .POINTER:
281
this .pointer (type, renderObject);
283
case TraverseType .CAMERA:
284
this .camera (type, renderObject);
286
case TraverseType .COLLISION:
287
this .collision (type, renderObject);
289
case TraverseType .DEPTH:
290
case TraverseType .DISPLAY:
291
this .display (type, renderObject);
295
this .getProjectionMatrix () .pop ();
296
this .getInverseCameraSpaceMatrix () .pop ();
297
this .getCameraSpaceMatrix () .pop ();
299
pointer: function (type, renderObject)
301
if (this .isPickable_ .getValue ())
304
browser = this .getBrowser (),
305
viewport = this .currentViewport .getRectangle (browser);
307
if (browser .getSelectedLayer ())
309
if (browser .getSelectedLayer () !== this)
314
if (! browser .isPointerInRectangle (viewport))
318
browser .setHitRay (this .getProjectionMatrix () .get (), viewport);
319
this .getModelViewMatrix () .pushMatrix (this .getInverseCameraSpaceMatrix () .get ());
321
this .currentViewport .push (this);
322
this .groupNode .traverse (type, renderObject);
323
this .currentViewport .pop (this);
325
this .getModelViewMatrix () .pop ()
328
camera: function (type, renderObject)
330
this .getModelViewMatrix () .pushMatrix (Matrix4 .Identity);
332
this .currentViewport .push (this);
333
this .groupNode .traverse (type, renderObject);
334
this .currentViewport .pop (this);
336
this .navigationInfos .update ();
337
this .backgrounds .update ();
338
this .fogs .update ();
339
this .viewpoints .update ();
341
this .getViewpoint () .update ();
343
this .getModelViewMatrix () .pop ()
345
collision: function (type, renderObject)
347
this .collisionTime = 0;
350
navigationInfo = this .getNavigationInfo (),
351
collisionRadius = navigationInfo .getCollisionRadius (),
352
avatarHeight = navigationInfo .getAvatarHeight (),
353
size = Math .max (collisionRadius * 2, avatarHeight * 2);
355
Camera .ortho (-size, size, -size, size, -size, size, projectionMatrix);
357
this .getProjectionMatrix () .pushMatrix (projectionMatrix);
358
this .getModelViewMatrix () .pushMatrix (this .getInverseCameraSpaceMatrix () .get ());
361
this .currentViewport .push (this);
362
renderObject .render (type, this .groupNode);
363
this .currentViewport .pop (this);
365
this .getModelViewMatrix () .pop ()
366
this .getProjectionMatrix () .pop ()
368
display: function (type, renderObject)
370
this .getNavigationInfo () .enable (type, renderObject);
372
this .getModelViewMatrix () .pushMatrix (this .getInverseCameraSpaceMatrix () .get ());
374
this .currentViewport .push (this);
375
renderObject .render (type, this .groupNode);
376
this .currentViewport .pop (this);
378
this .getModelViewMatrix () .pop ()