scenejs_on_rails 1.0.0 → 1.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +5 -5
- data/app/controllers/scenejs_controller.rb +53 -0
- data/app/views/scenejs/get_scenejs_data.html.erb +3 -0
- data/lib/scenejs_on_rails.rb +1 -1
- data/lib/scenejs_on_rails/rails.rb +5 -0
- data/lib/scenejs_on_rails/version.rb +1 -1
- data/vendor/assets/javascripts/scenejs.js +17307 -0
- data/vendor/assets/javascripts/scenejs_extras/gui.js +478 -0
- data/vendor/assets/javascripts/scenejs_extras/gui/README.md +4 -0
- data/vendor/assets/javascripts/scenejs_extras/gui/dat.gui.min.js +94 -0
- data/vendor/assets/javascripts/scenejs_extras/gui/gui.js +385 -0
- data/vendor/assets/javascripts/scenejs_lib/cityBuilder.js +457 -0
- data/vendor/assets/javascripts/scenejs_lib/dat.gui.min.js +94 -0
- data/vendor/assets/javascripts/scenejs_lib/gl-matrix-min.js +28 -0
- data/vendor/assets/javascripts/scenejs_lib/gl-matrix.js +4078 -0
- data/vendor/assets/javascripts/scenejs_lib/require.js +36 -0
- data/vendor/assets/javascripts/scenejs_lib/requireConfig.js +18 -0
- data/vendor/assets/javascripts/scenejs_lib/requireWrapperEnd.js +1 -0
- data/vendor/assets/javascripts/scenejs_lib/requireWrapperStart.js +2 -0
- data/vendor/assets/javascripts/scenejs_lib/stats.min.js +6 -0
- data/vendor/assets/javascripts/scenejs_lib/sylvester.js +1 -0
- data/vendor/assets/javascripts/scenejs_lib/webgl-debug-utils.js +839 -0
- data/vendor/assets/javascripts/scenejs_plugins/geometry/boundary.js +59 -0
- data/vendor/assets/javascripts/scenejs_plugins/geometry/box.js +72 -0
- data/vendor/assets/javascripts/scenejs_plugins/geometry/plane.js +126 -0
- data/vendor/assets/javascripts/scenejs_plugins/geometry/quad.js +37 -0
- data/vendor/assets/javascripts/scenejs_plugins/geometry/skybox.js +86 -0
- data/vendor/assets/javascripts/scenejs_plugins/geometry/sphere.js +82 -0
- data/vendor/assets/javascripts/scenejs_plugins/geometry/teapot.js +5853 -0
- data/vendor/assets/javascripts/scenejs_plugins/geometry/torus.js +139 -0
- data/vendor/assets/javascripts/scenejs_plugins/geometry/vectorText.js +1499 -0
- data/vendor/assets/javascripts/scenejs_plugins/geometry/wobblyBox.js +44 -0
- data/vendor/assets/javascripts/scenejs_plugins/lib/canvas2image.js +198 -0
- data/vendor/assets/javascripts/scenejs_plugins/lib/frustum/frustumCullEngine.js +810 -0
- data/vendor/assets/javascripts/scenejs_plugins/lib/frustum/frustumCullSystem.js +185 -0
- data/vendor/assets/javascripts/scenejs_plugins/lib/frustum/frustumCullSystemPool.js +174 -0
- data/vendor/assets/javascripts/scenejs_plugins/lib/frustum/frustumCullWorker.js +142 -0
- data/vendor/assets/javascripts/scenejs_plugins/lib/gl-matrix-min.js +28 -0
- data/vendor/assets/javascripts/scenejs_plugins/lib/jquery-1.8.3.min.js +2 -0
- data/vendor/assets/javascripts/scenejs_plugins/lib/k3d.js +1029 -0
- data/vendor/assets/javascripts/scenejs_plugins/lib/physics/jiglib.all.min.js +3 -0
- data/vendor/assets/javascripts/scenejs_plugins/lib/physics/physics.js +223 -0
- data/vendor/assets/javascripts/scenejs_plugins/lib/physics/worker.js +330 -0
- data/vendor/assets/javascripts/scenejs_plugins/node/alpha/orbitTracking.js +295 -0
- data/vendor/assets/javascripts/scenejs_plugins/node/alpha/orbitTrackingTarget.js +43 -0
- data/vendor/assets/javascripts/scenejs_plugins/node/backgrounds/gradient.js +148 -0
- data/vendor/assets/javascripts/scenejs_plugins/node/cameras/orbit.js +172 -0
- data/vendor/assets/javascripts/scenejs_plugins/node/cameras/pickFlyOrbit.js +409 -0
- data/vendor/assets/javascripts/scenejs_plugins/node/canvas/capture.js +107 -0
- data/vendor/assets/javascripts/scenejs_plugins/node/demos/color.js +30 -0
- data/vendor/assets/javascripts/scenejs_plugins/node/demos/redTeapot.js +52 -0
- data/vendor/assets/javascripts/scenejs_plugins/node/demos/spinningTeapot.js +43 -0
- data/vendor/assets/javascripts/scenejs_plugins/node/effects/crt.js +36 -0
- data/vendor/assets/javascripts/scenejs_plugins/node/effects/fog.js +159 -0
- data/vendor/assets/javascripts/scenejs_plugins/node/effects/snowyPeaks.js +50 -0
- data/vendor/assets/javascripts/scenejs_plugins/node/effects/wobble.js +42 -0
- data/vendor/assets/javascripts/scenejs_plugins/node/effects/xray.js +126 -0
- data/vendor/assets/javascripts/scenejs_plugins/node/frustum/body.js +112 -0
- data/vendor/assets/javascripts/scenejs_plugins/node/frustum/cull.js +42 -0
- data/vendor/assets/javascripts/scenejs_plugins/node/frustum/lod.js +125 -0
- data/vendor/assets/javascripts/scenejs_plugins/node/heightmaps/custom.js +185 -0
- data/vendor/assets/javascripts/scenejs_plugins/node/import/3ds.js +91 -0
- data/vendor/assets/javascripts/scenejs_plugins/node/import/md2.js +139 -0
- data/vendor/assets/javascripts/scenejs_plugins/node/import/obj.js +100 -0
- data/vendor/assets/javascripts/scenejs_plugins/node/objects/buildings/building.js +352 -0
- data/vendor/assets/javascripts/scenejs_plugins/node/objects/buildings/building/HighRiseGlass.jpg +0 -0
- data/vendor/assets/javascripts/scenejs_plugins/node/objects/buildings/building/HighRiseGlassSpecular.jpg +0 -0
- data/vendor/assets/javascripts/scenejs_plugins/node/objects/buildings/building/highrise-windows.jpg +0 -0
- data/vendor/assets/javascripts/scenejs_plugins/node/objects/buildings/building/pixelcity_windows7.jpg +0 -0
- data/vendor/assets/javascripts/scenejs_plugins/node/objects/buildings/city.js +26 -0
- data/vendor/assets/javascripts/scenejs_plugins/node/objects/plants/ghostTree.js +387 -0
- data/vendor/assets/javascripts/scenejs_plugins/node/objects/space/planets/earth.js +168 -0
- data/vendor/assets/javascripts/scenejs_plugins/node/objects/space/planets/earth/earth-lights.gif +0 -0
- data/vendor/assets/javascripts/scenejs_plugins/node/objects/space/planets/earth/earth-specular.gif +0 -0
- data/vendor/assets/javascripts/scenejs_plugins/node/objects/space/planets/earth/earth-specular.jpg +0 -0
- data/vendor/assets/javascripts/scenejs_plugins/node/objects/space/planets/earth/earth.jpg +0 -0
- data/vendor/assets/javascripts/scenejs_plugins/node/objects/space/planets/earth/earthbump.jpg +0 -0
- data/vendor/assets/javascripts/scenejs_plugins/node/objects/space/planets/earth/earthclouds.jpg +0 -0
- data/vendor/assets/javascripts/scenejs_plugins/node/objects/toys/drinkingBird.js +632 -0
- data/vendor/assets/javascripts/scenejs_plugins/node/objects/vehicles/tank.js +77670 -0
- data/vendor/assets/javascripts/scenejs_plugins/node/objects/vehicles/tank.js~ +77636 -0
- data/vendor/assets/javascripts/scenejs_plugins/node/physics/body.js +85 -0
- data/vendor/assets/javascripts/scenejs_plugins/node/physics/box.js +30 -0
- data/vendor/assets/javascripts/scenejs_plugins/node/physics/material.js +35 -0
- data/vendor/assets/javascripts/scenejs_plugins/node/physics/plane.js +47 -0
- data/vendor/assets/javascripts/scenejs_plugins/node/physics/sphere.js +32 -0
- data/vendor/assets/javascripts/scenejs_plugins/node/physics/system.js +44 -0
- data/vendor/assets/javascripts/scenejs_plugins/node/physics/teapot.js +29 -0
- data/vendor/assets/javascripts/scenejs_plugins/node/prims/boundary.js +73 -0
- data/vendor/assets/javascripts/scenejs_plugins/node/prims/box.js +87 -0
- data/vendor/assets/javascripts/scenejs_plugins/node/prims/cylinder.js +186 -0
- data/vendor/assets/javascripts/scenejs_plugins/node/prims/grid.js +47 -0
- data/vendor/assets/javascripts/scenejs_plugins/node/prims/plane.js +137 -0
- data/vendor/assets/javascripts/scenejs_plugins/node/prims/quad.js +43 -0
- data/vendor/assets/javascripts/scenejs_plugins/node/prims/sphere.js +107 -0
- data/vendor/assets/javascripts/scenejs_plugins/node/prims/teapot.js +5846 -0
- data/vendor/assets/javascripts/scenejs_plugins/node/prims/torus.js +149 -0
- data/vendor/assets/javascripts/scenejs_plugins/node/prims/vectorText.js +1508 -0
- data/vendor/assets/javascripts/scenejs_plugins/node/skyboxes/clouds.js +19 -0
- data/vendor/assets/javascripts/scenejs_plugins/node/skyboxes/cloudySea.js +19 -0
- data/vendor/assets/javascripts/scenejs_plugins/node/skyboxes/custom.js +150 -0
- data/vendor/assets/javascripts/scenejs_plugins/node/skyboxes/grimmNight.js +19 -0
- data/vendor/assets/javascripts/scenejs_plugins/node/skyboxes/interstellarClouds.js +19 -0
- data/vendor/assets/javascripts/scenejs_plugins/node/skyboxes/miramarClouds.js +19 -0
- data/vendor/assets/javascripts/scenejs_plugins/node/skyboxes/stormyDays.js +19 -0
- data/vendor/assets/javascripts/scenejs_plugins/node/skyboxes/textures/clouds.jpg +0 -0
- data/vendor/assets/javascripts/scenejs_plugins/node/skyboxes/textures/cloudySea.jpg +0 -0
- data/vendor/assets/javascripts/scenejs_plugins/node/skyboxes/textures/grimmNight.jpg +0 -0
- data/vendor/assets/javascripts/scenejs_plugins/node/skyboxes/textures/interstellarClouds.jpg +0 -0
- data/vendor/assets/javascripts/scenejs_plugins/node/skyboxes/textures/miramarClouds.jpg +0 -0
- data/vendor/assets/javascripts/scenejs_plugins/node/skyboxes/textures/stormyDays.jpg +0 -0
- data/vendor/assets/javascripts/scenejs_plugins/node/skyboxes/textures/violentDays.jpg +0 -0
- data/vendor/assets/javascripts/scenejs_plugins/node/skyboxes/violentDays.js +19 -0
- data/vendor/assets/javascripts/scenejs_plugins/texture/image.js +67 -0
- data/vendor/assets/javascripts/scenejs_plugins/texture/video.js +105 -0
- metadata +113 -1
@@ -0,0 +1,186 @@
|
|
1
|
+
/**
|
2
|
+
* Sphere geometry node type
|
3
|
+
*
|
4
|
+
* @author Moritz Kornher
|
5
|
+
*
|
6
|
+
* Usage example:
|
7
|
+
*
|
8
|
+
* someNode.addNode({
|
9
|
+
* type: "prims/cylinder",
|
10
|
+
* radiusTop: 20, // Default
|
11
|
+
* radiusBottom: 20, // Default
|
12
|
+
* height: 100, // Default
|
13
|
+
* radialSegments: 8, // Default
|
14
|
+
* heightSegments: 1, // Default
|
15
|
+
* openEnded: false // Default
|
16
|
+
* });
|
17
|
+
*/
|
18
|
+
|
19
|
+
(function () {
|
20
|
+
|
21
|
+
SceneJS.Types.addType("prims/cylinder", {
|
22
|
+
|
23
|
+
init:function (params) {
|
24
|
+
this.addNode(build.call(this, params));
|
25
|
+
}
|
26
|
+
});
|
27
|
+
|
28
|
+
function build(params) {
|
29
|
+
|
30
|
+
// Thanks awfully to: http://www.e-reading-lib.com/bookreader.php/143437/Pike_-_DirectX_8_Programming_Tutorial.html
|
31
|
+
|
32
|
+
/* config */
|
33
|
+
var radiusTop = params.radiusTop !== undefined ? params.radiusTop : 20;
|
34
|
+
var radiusBottom = params.radiusBottom !== undefined ? params.radiusBottom : 20;
|
35
|
+
var height = params.height !== undefined ? params.height : 100;
|
36
|
+
|
37
|
+
var radialSegments = params.radialSegments || 8;
|
38
|
+
var heightSegments = params.heightSegments || 1;
|
39
|
+
|
40
|
+
var openEnded = params.openEnded || false;
|
41
|
+
/* config end */
|
42
|
+
|
43
|
+
var heightHalf = height / 2;
|
44
|
+
var heightLength = height / heightSegments;
|
45
|
+
|
46
|
+
var radialAngle = (2.0 * Math.PI / radialSegments);
|
47
|
+
var radialLength = 1.0 / radialSegments;
|
48
|
+
|
49
|
+
var nextRadius = this.radiusBottom;
|
50
|
+
var radiusChange = (radiusTop-radiusBottom)/heightSegments;
|
51
|
+
|
52
|
+
var positions = [];
|
53
|
+
var normals = [];
|
54
|
+
var uvs = [];
|
55
|
+
var indices = [];
|
56
|
+
|
57
|
+
// create vertices
|
58
|
+
var normalY = (90.0 - (Math.atan(height / (radiusBottom - radiusTop))) * 180/Math.PI) / 90.0;
|
59
|
+
|
60
|
+
for (var h = 0; h <= heightSegments; h++) {
|
61
|
+
var currentRadius = radiusTop - h*radiusChange;
|
62
|
+
var currentHeight = heightHalf - h*heightLength
|
63
|
+
|
64
|
+
for (var i=0; i <= radialSegments; i++) {
|
65
|
+
var x = Math.sin(i * radialAngle);
|
66
|
+
var z = Math.cos(i * radialAngle);
|
67
|
+
|
68
|
+
normals.push(currentRadius * x);
|
69
|
+
normals.push(normalY); //todo
|
70
|
+
normals.push(currentRadius * z);
|
71
|
+
uvs.push(1 - (i*radialLength));
|
72
|
+
uvs.push(0 + h*1/heightSegments);
|
73
|
+
positions.push(currentRadius * x);
|
74
|
+
positions.push(currentHeight);
|
75
|
+
positions.push(currentRadius * z);
|
76
|
+
}
|
77
|
+
}
|
78
|
+
|
79
|
+
// create faces
|
80
|
+
for (var h = 0; h < heightSegments; h++) {
|
81
|
+
for (var i=0; i <= radialSegments; i++) {
|
82
|
+
var first = h * (radialSegments + 1) + i;
|
83
|
+
var second = first + radialSegments;
|
84
|
+
indices.push(first);
|
85
|
+
indices.push(second);
|
86
|
+
indices.push(second + 1);
|
87
|
+
|
88
|
+
indices.push(first);
|
89
|
+
indices.push(second + 1);
|
90
|
+
indices.push(first + 1);
|
91
|
+
}
|
92
|
+
}
|
93
|
+
|
94
|
+
// create top cap
|
95
|
+
if (!openEnded && radiusTop > 0) {
|
96
|
+
var startIndex = (positions.length/3);
|
97
|
+
|
98
|
+
// top center
|
99
|
+
normals.push(0.0);
|
100
|
+
normals.push(1.0);
|
101
|
+
normals.push(0.0);
|
102
|
+
uvs.push(0.5);
|
103
|
+
uvs.push(0.5);
|
104
|
+
positions.push(0);
|
105
|
+
positions.push(heightHalf);
|
106
|
+
positions.push(0);
|
107
|
+
|
108
|
+
// top triangle fan
|
109
|
+
for (var i=0; i <= radialSegments; i++) {
|
110
|
+
var x = Math.sin(i * radialAngle);
|
111
|
+
var z = Math.cos(i * radialAngle);
|
112
|
+
var tu = (0.5 * Math.sin(i * radialAngle)) + 0.5;
|
113
|
+
var tv = (0.5 * Math.cos(i * radialAngle)) + 0.5;
|
114
|
+
|
115
|
+
normals.push(radiusTop * x);
|
116
|
+
normals.push(1.0);
|
117
|
+
normals.push(radiusTop * z);
|
118
|
+
uvs.push(tu);
|
119
|
+
uvs.push(tv);
|
120
|
+
positions.push(radiusTop * x);
|
121
|
+
positions.push(heightHalf);
|
122
|
+
positions.push(radiusTop * z);
|
123
|
+
}
|
124
|
+
|
125
|
+
for (var i=0; i < radialSegments; i++) {
|
126
|
+
var center = startIndex;
|
127
|
+
var first = startIndex + 1 + i;
|
128
|
+
indices.push(first);
|
129
|
+
indices.push(first + 1);
|
130
|
+
indices.push(center);
|
131
|
+
}
|
132
|
+
}
|
133
|
+
|
134
|
+
// create bottom cap
|
135
|
+
if (!openEnded && radiusBottom > 0) {
|
136
|
+
var startIndex = (positions.length/3);
|
137
|
+
|
138
|
+
// top center
|
139
|
+
normals.push(0.0);
|
140
|
+
normals.push(-1.0);
|
141
|
+
normals.push(0.0);
|
142
|
+
uvs.push(0.5);
|
143
|
+
uvs.push(0.5);
|
144
|
+
positions.push(0);
|
145
|
+
positions.push(0-heightHalf);
|
146
|
+
positions.push(0);
|
147
|
+
|
148
|
+
// top triangle fan
|
149
|
+
for (var i=0; i <= radialSegments; i++) {
|
150
|
+
var x = Math.sin(i * radialAngle);
|
151
|
+
var z = Math.cos(i * radialAngle);
|
152
|
+
var tu = (0.5 * Math.sin(i * radialAngle)) + 0.5;
|
153
|
+
var tv = (0.5 * Math.cos(i * radialAngle)) + 0.5;
|
154
|
+
|
155
|
+
normals.push(radiusBottom * x);
|
156
|
+
normals.push(-1.0);
|
157
|
+
normals.push(radiusBottom * z);
|
158
|
+
uvs.push(tu);
|
159
|
+
uvs.push(tv);
|
160
|
+
positions.push(radiusBottom * x);
|
161
|
+
positions.push(0-heightHalf);
|
162
|
+
positions.push(radiusBottom * z);
|
163
|
+
}
|
164
|
+
|
165
|
+
for (var i=0; i < radialSegments; i++) {
|
166
|
+
var center = startIndex;
|
167
|
+
var first = startIndex + 1 + i;
|
168
|
+
indices.push(first);
|
169
|
+
indices.push(first + 1);
|
170
|
+
indices.push(center);
|
171
|
+
}
|
172
|
+
}
|
173
|
+
|
174
|
+
return {
|
175
|
+
type: "geometry",
|
176
|
+
primitive:params.wire ? "lines" : "triangles",
|
177
|
+
coreId : "cylinder_" + (params.wire ? "wire" : "solid") + "_" + (params.openEnded ? "open" : "closed") + "_"
|
178
|
+
+ radiusTop + "_" + radiusBottom + "_" + radialSegments + "_"
|
179
|
+
+ height + "_" + heightSegments,
|
180
|
+
positions : new Float32Array(positions),
|
181
|
+
normals: new Float32Array(normals),
|
182
|
+
uv : new Float32Array(uvs),
|
183
|
+
indices : new Uint16Array(indices)
|
184
|
+
};
|
185
|
+
}
|
186
|
+
})();
|
@@ -0,0 +1,47 @@
|
|
1
|
+
SceneJS.Types.addType("prims/grid", {
|
2
|
+
|
3
|
+
construct:function (params) {
|
4
|
+
|
5
|
+
this._translate = this.addNode({
|
6
|
+
type:"translate"
|
7
|
+
});
|
8
|
+
|
9
|
+
this._scale = this._translate.addNode({
|
10
|
+
type:"scale",
|
11
|
+
x:1000,
|
12
|
+
y:.5,
|
13
|
+
z:1000,
|
14
|
+
nodes:[
|
15
|
+
{
|
16
|
+
type:"rotate",
|
17
|
+
x:1,
|
18
|
+
angle:90,
|
19
|
+
nodes:[
|
20
|
+
{
|
21
|
+
type:"prims/plane",
|
22
|
+
wire:params.wire != false,
|
23
|
+
widthSegments:params.xSegments || 200,
|
24
|
+
heightSegments:params.zSegments || 200
|
25
|
+
}
|
26
|
+
]
|
27
|
+
}
|
28
|
+
]
|
29
|
+
});
|
30
|
+
|
31
|
+
if (params.pos) {
|
32
|
+
this.setPos(params.pos);
|
33
|
+
}
|
34
|
+
|
35
|
+
if (params.size) {
|
36
|
+
this.setSize(params.size);
|
37
|
+
}
|
38
|
+
},
|
39
|
+
|
40
|
+
setPos:function (pos) {
|
41
|
+
this._translate.setXYZ(pos);
|
42
|
+
},
|
43
|
+
|
44
|
+
setSize:function (size) {
|
45
|
+
this._scale.setXYZ(size);
|
46
|
+
}
|
47
|
+
});
|
@@ -0,0 +1,137 @@
|
|
1
|
+
/**
|
2
|
+
* Plane geometry node type
|
3
|
+
*
|
4
|
+
* Usage example:
|
5
|
+
*
|
6
|
+
* someNode.addNode({
|
7
|
+
* type: "prims/plane",
|
8
|
+
* width: 10,
|
9
|
+
* height: 20,
|
10
|
+
* wire: false // Default
|
11
|
+
* });
|
12
|
+
*/
|
13
|
+
(function () {
|
14
|
+
|
15
|
+
SceneJS.Types.addType("prims/plane", {
|
16
|
+
|
17
|
+
construct:function (params) {
|
18
|
+
this.addNode(build.call(this, params));
|
19
|
+
}
|
20
|
+
});
|
21
|
+
|
22
|
+
function build(params) {
|
23
|
+
|
24
|
+
var width = params.width || 1.0;
|
25
|
+
var height = params.height || 1.0;
|
26
|
+
|
27
|
+
var widthSegments = params.widthSegments || 1;
|
28
|
+
var heightSegments = params.heightSegments || 1;
|
29
|
+
|
30
|
+
var coreId = "prims/plane_" + (params.wire == true ? "wire_" : "") + height + "_" + widthSegments + "_" + heightSegments;
|
31
|
+
|
32
|
+
// If a node core already exists for a prim with the given properties,
|
33
|
+
// then for efficiency we'll share that core rather than create another geometry
|
34
|
+
if (this.getScene().hasCore("geometry", coreId)) {
|
35
|
+
return {
|
36
|
+
type: "geometry",
|
37
|
+
coreId:coreId
|
38
|
+
};
|
39
|
+
}
|
40
|
+
|
41
|
+
// Otherwise, create a new geometry
|
42
|
+
|
43
|
+
var positions = [];
|
44
|
+
var normals = [];
|
45
|
+
var uvs = [];
|
46
|
+
var indices = [];
|
47
|
+
|
48
|
+
var ix, iz;
|
49
|
+
var halfWidth = width / 2;
|
50
|
+
var halfHeight = height / 2;
|
51
|
+
|
52
|
+
var gridX = widthSegments;
|
53
|
+
var gridZ = heightSegments;
|
54
|
+
|
55
|
+
var gridX1 = gridX + 1;
|
56
|
+
var gridZ1 = gridZ + 1;
|
57
|
+
|
58
|
+
var segWidth = width / gridX;
|
59
|
+
var segHeight = height / gridZ;
|
60
|
+
|
61
|
+
var x;
|
62
|
+
var y;
|
63
|
+
|
64
|
+
for (iz = 0; iz < gridZ1; iz++) {
|
65
|
+
for (ix = 0; ix < gridX1; ix++) {
|
66
|
+
|
67
|
+
x = ix * segWidth - halfWidth;
|
68
|
+
y = iz * segHeight - halfHeight;
|
69
|
+
|
70
|
+
positions.push(x);
|
71
|
+
positions.push(-y);
|
72
|
+
positions.push(0);
|
73
|
+
|
74
|
+
normals.push(0);
|
75
|
+
normals.push(0);
|
76
|
+
normals.push(1);
|
77
|
+
}
|
78
|
+
}
|
79
|
+
|
80
|
+
var a;
|
81
|
+
var b;
|
82
|
+
var c;
|
83
|
+
var d;
|
84
|
+
|
85
|
+
for (iz = 0; iz < gridZ; iz++) {
|
86
|
+
for (ix = 0; ix < gridX; ix++) {
|
87
|
+
|
88
|
+
a = ix + gridX1 * iz;
|
89
|
+
b = ix + gridX1 * ( iz + 1 );
|
90
|
+
c = ( ix + 1 ) + gridX1 * ( iz + 1 );
|
91
|
+
d = ( ix + 1 ) + gridX1 * iz;
|
92
|
+
|
93
|
+
indices.push(a);
|
94
|
+
indices.push(b);
|
95
|
+
indices.push(c);
|
96
|
+
|
97
|
+
indices.push(c);
|
98
|
+
indices.push(d);
|
99
|
+
indices.push(a);
|
100
|
+
|
101
|
+
// a
|
102
|
+
uvs.push(ix / gridX);
|
103
|
+
uvs.push(1 - iz / gridZ);
|
104
|
+
|
105
|
+
//b
|
106
|
+
uvs.push(ix / gridX);
|
107
|
+
uvs.push(1 - ( iz + 1 ) / gridZ);
|
108
|
+
|
109
|
+
//c
|
110
|
+
uvs.push(( ix + 1 ) / gridX);
|
111
|
+
uvs.push(1 - ( iz + 1 ) / gridZ);
|
112
|
+
|
113
|
+
//c
|
114
|
+
uvs.push(( ix + 1 ) / gridX);
|
115
|
+
uvs.push(1 - ( iz + 1 ) / gridZ);
|
116
|
+
|
117
|
+
//d
|
118
|
+
uvs.push(( ix + 1 ) / gridX, 1 - iz / gridZ);
|
119
|
+
uvs.push(1 - iz / gridZ);
|
120
|
+
|
121
|
+
//a
|
122
|
+
uvs.push(ix / gridX);
|
123
|
+
uvs.push(1 - iz / gridZ);
|
124
|
+
}
|
125
|
+
}
|
126
|
+
|
127
|
+
return {
|
128
|
+
type: "geometry",
|
129
|
+
primitive:params.wire ? "lines" : "triangles",
|
130
|
+
coreId:coreId,
|
131
|
+
positions:new Float32Array(positions),
|
132
|
+
normals:new Float32Array(normals),
|
133
|
+
uv:new Float32Array(uvs),
|
134
|
+
indices:new Uint16Array(indices)
|
135
|
+
};
|
136
|
+
}
|
137
|
+
})();
|
@@ -0,0 +1,43 @@
|
|
1
|
+
/**
|
2
|
+
* Quad geometry node type
|
3
|
+
*
|
4
|
+
* Usage example:
|
5
|
+
*
|
6
|
+
* someNode.addNode({
|
7
|
+
* type: "prims/quad",
|
8
|
+
* wire: false // Default
|
9
|
+
* });
|
10
|
+
*/
|
11
|
+
(function () {
|
12
|
+
|
13
|
+
SceneJS.Types.addType("prims/quad", {
|
14
|
+
construct:function (params) {
|
15
|
+
this.addNode(build.call(this, params));
|
16
|
+
}
|
17
|
+
});
|
18
|
+
|
19
|
+
function build(params) {
|
20
|
+
|
21
|
+
var coreId = "prims/quad" + (params.wire ? "wire" : "_solid");
|
22
|
+
|
23
|
+
// If a node core already exists for a prim with the given properties,
|
24
|
+
// then for efficiency we'll share that core rather than create another geometry
|
25
|
+
if (this.getScene().hasCore("geometry", coreId)) {
|
26
|
+
return {
|
27
|
+
type: "geometry",
|
28
|
+
coreId:coreId
|
29
|
+
};
|
30
|
+
}
|
31
|
+
|
32
|
+
// Otherwise, create a new geometry
|
33
|
+
return {
|
34
|
+
type: "geometry",
|
35
|
+
primitive:params.wire ? "lines" : "triangles",
|
36
|
+
coreId:coreId,
|
37
|
+
positions:[ 1, 1, 0, -1, 1, 0, -1, -1, 0, 1, -1, 0 ],
|
38
|
+
normals:[ -1, 0, 0, -1, 0, 0, -1, 0, 0, -1, 0, 0 ],
|
39
|
+
uv:[ 1, 1, 0, 1, 0, 0, 1, 0 ],
|
40
|
+
indices:[ 0, 1, 2, 0, 2, 3 ]
|
41
|
+
};
|
42
|
+
}
|
43
|
+
})();
|
@@ -0,0 +1,107 @@
|
|
1
|
+
/**
|
2
|
+
* Sphere geometry node type
|
3
|
+
*
|
4
|
+
* Usage example:
|
5
|
+
*
|
6
|
+
* someNode.addNode({
|
7
|
+
* type: "prims/sphere",
|
8
|
+
* latitudeBands: 30, // Default
|
9
|
+
* longitudeBands: 30, // Default
|
10
|
+
* radius: 1, // Default
|
11
|
+
* wire: false // Default
|
12
|
+
* });
|
13
|
+
*/
|
14
|
+
(function () {
|
15
|
+
|
16
|
+
SceneJS.Types.addType("prims/sphere", {
|
17
|
+
|
18
|
+
construct:function (params) {
|
19
|
+
this.addNode(build.call(this, params));
|
20
|
+
}
|
21
|
+
});
|
22
|
+
|
23
|
+
function build(params) {
|
24
|
+
|
25
|
+
// Thanks awfully to: http://learningwebgl.com/cookbook/index.php/How_to_draw_a_sphere
|
26
|
+
|
27
|
+
var latitudeBands = params.latitudeBands || 30;
|
28
|
+
var longitudeBands = params.longitudeBands || 30;
|
29
|
+
var radius = params.radius || 1;
|
30
|
+
|
31
|
+
var coreId = "prims/sphere_" + (params.wire ? "wire" : "_solid") + radius + "_" + longitudeBands + "_" + latitudeBands;
|
32
|
+
|
33
|
+
// If a node core already exists for a prim with the given properties,
|
34
|
+
// then for efficiency we'll share that core rather than create another geometry
|
35
|
+
if (this.getScene().hasCore("geometry", coreId)) {
|
36
|
+
return {
|
37
|
+
type: "geometry",
|
38
|
+
coreId:coreId
|
39
|
+
};
|
40
|
+
}
|
41
|
+
|
42
|
+
// Otherwise, create a new geometry
|
43
|
+
|
44
|
+
var positions = [];
|
45
|
+
var normals = [];
|
46
|
+
var uvs = [];
|
47
|
+
for (var latNumber = 0; latNumber <= latitudeBands; latNumber++) {
|
48
|
+
var theta = latNumber * Math.PI / latitudeBands;
|
49
|
+
var sinTheta = Math.sin(theta);
|
50
|
+
var cosTheta = Math.cos(theta);
|
51
|
+
|
52
|
+
for (var longNumber = 0; longNumber <= longitudeBands; longNumber++) {
|
53
|
+
var phi = longNumber * 2 * Math.PI / longitudeBands;
|
54
|
+
var sinPhi = Math.sin(phi);
|
55
|
+
var cosPhi = Math.cos(phi);
|
56
|
+
|
57
|
+
var x = cosPhi * sinTheta;
|
58
|
+
var y = cosTheta;
|
59
|
+
var z = sinPhi * sinTheta;
|
60
|
+
var u = 1- (longNumber / longitudeBands);
|
61
|
+
var v = latNumber / latitudeBands;
|
62
|
+
|
63
|
+
normals.push(x);
|
64
|
+
normals.push(y);
|
65
|
+
normals.push(z);
|
66
|
+
uvs.push(u);
|
67
|
+
uvs.push(v);
|
68
|
+
positions.push(radius * x);
|
69
|
+
positions.push(radius * y);
|
70
|
+
positions.push(radius * z);
|
71
|
+
}
|
72
|
+
}
|
73
|
+
|
74
|
+
var indices = [];
|
75
|
+
for (var latNumber = 0; latNumber < latitudeBands; latNumber++) {
|
76
|
+
for (var longNumber = 0; longNumber < longitudeBands; longNumber++) {
|
77
|
+
var first = (latNumber * (longitudeBands + 1)) + longNumber;
|
78
|
+
var second = first + longitudeBands + 1;
|
79
|
+
// indices.push(first);
|
80
|
+
// indices.push(second);
|
81
|
+
// indices.push(first + 1);
|
82
|
+
//
|
83
|
+
// indices.push(second);
|
84
|
+
// indices.push(second + 1);
|
85
|
+
// indices.push(first + 1);
|
86
|
+
|
87
|
+
|
88
|
+
indices.push(first + 1);
|
89
|
+
indices.push(second + 1);
|
90
|
+
indices.push(second);
|
91
|
+
indices.push(first + 1);
|
92
|
+
indices.push(second);
|
93
|
+
indices.push(first);
|
94
|
+
}
|
95
|
+
}
|
96
|
+
|
97
|
+
return {
|
98
|
+
type: "geometry",
|
99
|
+
primitive:params.wire ? "lines" : "triangles",
|
100
|
+
coreId : coreId,
|
101
|
+
positions : new Float32Array(positions),
|
102
|
+
normals: new Float32Array(normals),
|
103
|
+
uv : new Float32Array(uvs),
|
104
|
+
indices : new Uint16Array(indices)
|
105
|
+
};
|
106
|
+
}
|
107
|
+
})();
|