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
******************************************************************************/
53
"cobweb/Basic/X3DBaseNode",
54
"cobweb/Components/Geometry3D/IndexedFaceSet",
55
"cobweb/Components/Rendering/Coordinate",
56
"cobweb/Components/Texturing/TextureCoordinate",
57
"standard/Math/Numbers/Complex",
58
"standard/Math/Numbers/Vector2",
59
"standard/Math/Numbers/Vector3",
73
function QuadSphereOptions (executionContext)
75
X3DBaseNode .call (this, executionContext);
77
this .addChildObjects ("xDimension", new Fields .SFInt32 (32),
78
"yDimension", new Fields .SFInt32 (15))
81
QuadSphereOptions .prototype = $.extend (Object .create (X3DBaseNode .prototype),
83
constructor: QuadSphereOptions,
84
getTypeName: function ()
86
return "QuadSphereOptions";
88
getComponentName: function ()
92
getContainerField: function ()
94
return "quadSphereOptions";
96
initialize: function ()
98
X3DBaseNode .prototype .initialize .call (this);
100
this .addInterest ("eventsProcessed", this);
102
getGeometry: function ()
104
if (! this .geometry)
105
this .eventsProcessed ();
107
return this .geometry;
109
createTexCoordIndex: function ()
112
xDimension = this .xDimension_ .getValue () + 1,
113
yDimension = this .yDimension_ .getValue (),
114
texCoordIndex = this .geometry .texCoordIndex_;
118
for (var u = 0, uLength = xDimension - 1; u < uLength; ++ u)
120
texCoordIndex .push (u);
121
texCoordIndex .push (u + xDimension - 1);
122
texCoordIndex .push (u + xDimension);
123
texCoordIndex .push (-1);
128
for (var p = xDimension - 1, v = 0, vLength = yDimension - 3; v < vLength; ++ v, ++ p)
130
for (var u = 0, uLength = xDimension - 1; u < uLength; ++ u, ++ p)
132
texCoordIndex .push (p);
133
texCoordIndex .push (p + xDimension);
134
texCoordIndex .push (p + xDimension + 1);
135
texCoordIndex .push (p + 1);
136
texCoordIndex .push (-1);
142
var p = (yDimension - 2) * xDimension - 1;
144
for (var u = 0, uLength = xDimension - 1; u < uLength; ++ u, ++ p)
146
texCoordIndex .push (p + xDimension);
147
texCoordIndex .push (p + 1);
148
texCoordIndex .push (p);
149
texCoordIndex .push (-1)
152
createTexCoord: function ()
155
xDimension = this .xDimension_ .getValue () + 1,
156
yDimension = this .yDimension_ .getValue (),
157
point = this .geometry .texCoord_ .getValue () .point_;
159
var poleOffset = -0.5 / (xDimension - 1);
163
for (var u = 1; u < xDimension; ++ u)
165
var x = u / (xDimension - 1) + poleOffset;
167
point .push (new Vector2 (x, 1));
172
for (var v = 1, vLength = yDimension - 1; v < vLength; ++ v)
174
var y = 1 - v / (yDimension - 1);
176
for (var u = 0; u < xDimension; ++ u)
178
var x = u / (xDimension - 1);
180
point .push (new Vector2 (x, y));
186
for (var u = 1; u < xDimension; ++ u)
188
var x = u / (xDimension - 1) + poleOffset;
190
point .push (new Vector2 (x, 0));
193
createCoordIndex: function ()
196
xDimension = this .xDimension_ .getValue () + 1,
197
yDimension = this .yDimension_ .getValue (),
198
coordIndex = this .geometry .coordIndex_;
202
for (var u = 1, uLength = xDimension - 1; u < uLength; ++ u)
204
coordIndex .push (0);
205
coordIndex .push (u);
206
coordIndex .push (u + 1);
207
coordIndex .push (-1);
210
coordIndex .push (0);
211
coordIndex .push (u);
212
coordIndex .push (1);
213
coordIndex .push (-1);
219
for (var v = 0, vLength = yDimension - 3; v < vLength; ++ v, ++ p)
221
for (var u = 0, uLength = xDimension - 2; u < uLength; ++ u, ++ p)
223
coordIndex .push (p);
224
coordIndex .push (p + xDimension - 1);
225
coordIndex .push (p + xDimension);
226
coordIndex .push (p + 1);
227
coordIndex .push (-1);
230
coordIndex .push (p);
231
coordIndex .push (p + xDimension - 1);
232
coordIndex .push (p + 1);
233
coordIndex .push (p - xDimension + 2);
234
coordIndex .push (-1);
239
var last = p + xDimension - 1;
241
for (var u = 0, uLength = xDimension - 2; u < uLength; ++ u, ++ p)
243
coordIndex .push (last);
244
coordIndex .push (p + 1);
245
coordIndex .push (p);
246
coordIndex .push (-1);
249
coordIndex .push (last);
250
coordIndex .push (last - xDimension + 1);
251
coordIndex .push (p);
252
coordIndex .push (-1);
254
createPoints: function ()
257
xDimension = this .xDimension_ .getValue () + 1,
258
yDimension = this .yDimension_ .getValue (),
259
point = this .geometry .coord_ .getValue () .point_;
262
point .push (new Vector3 (0, 1, 0));
265
for (var v = 1, vLength = yDimension - 1; v < vLength; ++ v)
267
var zPlane = Complex .Polar (1, -Math .PI * v / vLength);
269
for (var u = 0, uLength = xDimension - 1; u < uLength; ++ u)
271
var yPlane = Complex .Polar (zPlane .imag, 2 * Math .PI * u / uLength);
273
point .push (new Vector3 (yPlane .imag, zPlane .real, yPlane .real));
278
point .push (new Vector3 (0, -1, 0));
280
eventsProcessed: function ()
282
this .geometry = new IndexedFaceSet (this .getExecutionContext ());
283
this .geometry .texCoord_ = new TextureCoordinate (this .getExecutionContext ());
284
this .geometry .coord_ = new Coordinate (this .getExecutionContext ());
286
this .createTexCoordIndex ();
287
this .createTexCoord ();
288
this .createCoordIndex ();
289
this .createPoints ();
292
geometry = this .geometry,
293
texCoord = this .geometry .texCoord_ .getValue (),
294
coord = this .geometry .coord_ .getValue ();
296
geometry .creaseAngle_ = Math .PI;
304
return QuadSphereOptions;