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.
Files changed (117) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +5 -5
  3. data/app/controllers/scenejs_controller.rb +53 -0
  4. data/app/views/scenejs/get_scenejs_data.html.erb +3 -0
  5. data/lib/scenejs_on_rails.rb +1 -1
  6. data/lib/scenejs_on_rails/rails.rb +5 -0
  7. data/lib/scenejs_on_rails/version.rb +1 -1
  8. data/vendor/assets/javascripts/scenejs.js +17307 -0
  9. data/vendor/assets/javascripts/scenejs_extras/gui.js +478 -0
  10. data/vendor/assets/javascripts/scenejs_extras/gui/README.md +4 -0
  11. data/vendor/assets/javascripts/scenejs_extras/gui/dat.gui.min.js +94 -0
  12. data/vendor/assets/javascripts/scenejs_extras/gui/gui.js +385 -0
  13. data/vendor/assets/javascripts/scenejs_lib/cityBuilder.js +457 -0
  14. data/vendor/assets/javascripts/scenejs_lib/dat.gui.min.js +94 -0
  15. data/vendor/assets/javascripts/scenejs_lib/gl-matrix-min.js +28 -0
  16. data/vendor/assets/javascripts/scenejs_lib/gl-matrix.js +4078 -0
  17. data/vendor/assets/javascripts/scenejs_lib/require.js +36 -0
  18. data/vendor/assets/javascripts/scenejs_lib/requireConfig.js +18 -0
  19. data/vendor/assets/javascripts/scenejs_lib/requireWrapperEnd.js +1 -0
  20. data/vendor/assets/javascripts/scenejs_lib/requireWrapperStart.js +2 -0
  21. data/vendor/assets/javascripts/scenejs_lib/stats.min.js +6 -0
  22. data/vendor/assets/javascripts/scenejs_lib/sylvester.js +1 -0
  23. data/vendor/assets/javascripts/scenejs_lib/webgl-debug-utils.js +839 -0
  24. data/vendor/assets/javascripts/scenejs_plugins/geometry/boundary.js +59 -0
  25. data/vendor/assets/javascripts/scenejs_plugins/geometry/box.js +72 -0
  26. data/vendor/assets/javascripts/scenejs_plugins/geometry/plane.js +126 -0
  27. data/vendor/assets/javascripts/scenejs_plugins/geometry/quad.js +37 -0
  28. data/vendor/assets/javascripts/scenejs_plugins/geometry/skybox.js +86 -0
  29. data/vendor/assets/javascripts/scenejs_plugins/geometry/sphere.js +82 -0
  30. data/vendor/assets/javascripts/scenejs_plugins/geometry/teapot.js +5853 -0
  31. data/vendor/assets/javascripts/scenejs_plugins/geometry/torus.js +139 -0
  32. data/vendor/assets/javascripts/scenejs_plugins/geometry/vectorText.js +1499 -0
  33. data/vendor/assets/javascripts/scenejs_plugins/geometry/wobblyBox.js +44 -0
  34. data/vendor/assets/javascripts/scenejs_plugins/lib/canvas2image.js +198 -0
  35. data/vendor/assets/javascripts/scenejs_plugins/lib/frustum/frustumCullEngine.js +810 -0
  36. data/vendor/assets/javascripts/scenejs_plugins/lib/frustum/frustumCullSystem.js +185 -0
  37. data/vendor/assets/javascripts/scenejs_plugins/lib/frustum/frustumCullSystemPool.js +174 -0
  38. data/vendor/assets/javascripts/scenejs_plugins/lib/frustum/frustumCullWorker.js +142 -0
  39. data/vendor/assets/javascripts/scenejs_plugins/lib/gl-matrix-min.js +28 -0
  40. data/vendor/assets/javascripts/scenejs_plugins/lib/jquery-1.8.3.min.js +2 -0
  41. data/vendor/assets/javascripts/scenejs_plugins/lib/k3d.js +1029 -0
  42. data/vendor/assets/javascripts/scenejs_plugins/lib/physics/jiglib.all.min.js +3 -0
  43. data/vendor/assets/javascripts/scenejs_plugins/lib/physics/physics.js +223 -0
  44. data/vendor/assets/javascripts/scenejs_plugins/lib/physics/worker.js +330 -0
  45. data/vendor/assets/javascripts/scenejs_plugins/node/alpha/orbitTracking.js +295 -0
  46. data/vendor/assets/javascripts/scenejs_plugins/node/alpha/orbitTrackingTarget.js +43 -0
  47. data/vendor/assets/javascripts/scenejs_plugins/node/backgrounds/gradient.js +148 -0
  48. data/vendor/assets/javascripts/scenejs_plugins/node/cameras/orbit.js +172 -0
  49. data/vendor/assets/javascripts/scenejs_plugins/node/cameras/pickFlyOrbit.js +409 -0
  50. data/vendor/assets/javascripts/scenejs_plugins/node/canvas/capture.js +107 -0
  51. data/vendor/assets/javascripts/scenejs_plugins/node/demos/color.js +30 -0
  52. data/vendor/assets/javascripts/scenejs_plugins/node/demos/redTeapot.js +52 -0
  53. data/vendor/assets/javascripts/scenejs_plugins/node/demos/spinningTeapot.js +43 -0
  54. data/vendor/assets/javascripts/scenejs_plugins/node/effects/crt.js +36 -0
  55. data/vendor/assets/javascripts/scenejs_plugins/node/effects/fog.js +159 -0
  56. data/vendor/assets/javascripts/scenejs_plugins/node/effects/snowyPeaks.js +50 -0
  57. data/vendor/assets/javascripts/scenejs_plugins/node/effects/wobble.js +42 -0
  58. data/vendor/assets/javascripts/scenejs_plugins/node/effects/xray.js +126 -0
  59. data/vendor/assets/javascripts/scenejs_plugins/node/frustum/body.js +112 -0
  60. data/vendor/assets/javascripts/scenejs_plugins/node/frustum/cull.js +42 -0
  61. data/vendor/assets/javascripts/scenejs_plugins/node/frustum/lod.js +125 -0
  62. data/vendor/assets/javascripts/scenejs_plugins/node/heightmaps/custom.js +185 -0
  63. data/vendor/assets/javascripts/scenejs_plugins/node/import/3ds.js +91 -0
  64. data/vendor/assets/javascripts/scenejs_plugins/node/import/md2.js +139 -0
  65. data/vendor/assets/javascripts/scenejs_plugins/node/import/obj.js +100 -0
  66. data/vendor/assets/javascripts/scenejs_plugins/node/objects/buildings/building.js +352 -0
  67. data/vendor/assets/javascripts/scenejs_plugins/node/objects/buildings/building/HighRiseGlass.jpg +0 -0
  68. data/vendor/assets/javascripts/scenejs_plugins/node/objects/buildings/building/HighRiseGlassSpecular.jpg +0 -0
  69. data/vendor/assets/javascripts/scenejs_plugins/node/objects/buildings/building/highrise-windows.jpg +0 -0
  70. data/vendor/assets/javascripts/scenejs_plugins/node/objects/buildings/building/pixelcity_windows7.jpg +0 -0
  71. data/vendor/assets/javascripts/scenejs_plugins/node/objects/buildings/city.js +26 -0
  72. data/vendor/assets/javascripts/scenejs_plugins/node/objects/plants/ghostTree.js +387 -0
  73. data/vendor/assets/javascripts/scenejs_plugins/node/objects/space/planets/earth.js +168 -0
  74. data/vendor/assets/javascripts/scenejs_plugins/node/objects/space/planets/earth/earth-lights.gif +0 -0
  75. data/vendor/assets/javascripts/scenejs_plugins/node/objects/space/planets/earth/earth-specular.gif +0 -0
  76. data/vendor/assets/javascripts/scenejs_plugins/node/objects/space/planets/earth/earth-specular.jpg +0 -0
  77. data/vendor/assets/javascripts/scenejs_plugins/node/objects/space/planets/earth/earth.jpg +0 -0
  78. data/vendor/assets/javascripts/scenejs_plugins/node/objects/space/planets/earth/earthbump.jpg +0 -0
  79. data/vendor/assets/javascripts/scenejs_plugins/node/objects/space/planets/earth/earthclouds.jpg +0 -0
  80. data/vendor/assets/javascripts/scenejs_plugins/node/objects/toys/drinkingBird.js +632 -0
  81. data/vendor/assets/javascripts/scenejs_plugins/node/objects/vehicles/tank.js +77670 -0
  82. data/vendor/assets/javascripts/scenejs_plugins/node/objects/vehicles/tank.js~ +77636 -0
  83. data/vendor/assets/javascripts/scenejs_plugins/node/physics/body.js +85 -0
  84. data/vendor/assets/javascripts/scenejs_plugins/node/physics/box.js +30 -0
  85. data/vendor/assets/javascripts/scenejs_plugins/node/physics/material.js +35 -0
  86. data/vendor/assets/javascripts/scenejs_plugins/node/physics/plane.js +47 -0
  87. data/vendor/assets/javascripts/scenejs_plugins/node/physics/sphere.js +32 -0
  88. data/vendor/assets/javascripts/scenejs_plugins/node/physics/system.js +44 -0
  89. data/vendor/assets/javascripts/scenejs_plugins/node/physics/teapot.js +29 -0
  90. data/vendor/assets/javascripts/scenejs_plugins/node/prims/boundary.js +73 -0
  91. data/vendor/assets/javascripts/scenejs_plugins/node/prims/box.js +87 -0
  92. data/vendor/assets/javascripts/scenejs_plugins/node/prims/cylinder.js +186 -0
  93. data/vendor/assets/javascripts/scenejs_plugins/node/prims/grid.js +47 -0
  94. data/vendor/assets/javascripts/scenejs_plugins/node/prims/plane.js +137 -0
  95. data/vendor/assets/javascripts/scenejs_plugins/node/prims/quad.js +43 -0
  96. data/vendor/assets/javascripts/scenejs_plugins/node/prims/sphere.js +107 -0
  97. data/vendor/assets/javascripts/scenejs_plugins/node/prims/teapot.js +5846 -0
  98. data/vendor/assets/javascripts/scenejs_plugins/node/prims/torus.js +149 -0
  99. data/vendor/assets/javascripts/scenejs_plugins/node/prims/vectorText.js +1508 -0
  100. data/vendor/assets/javascripts/scenejs_plugins/node/skyboxes/clouds.js +19 -0
  101. data/vendor/assets/javascripts/scenejs_plugins/node/skyboxes/cloudySea.js +19 -0
  102. data/vendor/assets/javascripts/scenejs_plugins/node/skyboxes/custom.js +150 -0
  103. data/vendor/assets/javascripts/scenejs_plugins/node/skyboxes/grimmNight.js +19 -0
  104. data/vendor/assets/javascripts/scenejs_plugins/node/skyboxes/interstellarClouds.js +19 -0
  105. data/vendor/assets/javascripts/scenejs_plugins/node/skyboxes/miramarClouds.js +19 -0
  106. data/vendor/assets/javascripts/scenejs_plugins/node/skyboxes/stormyDays.js +19 -0
  107. data/vendor/assets/javascripts/scenejs_plugins/node/skyboxes/textures/clouds.jpg +0 -0
  108. data/vendor/assets/javascripts/scenejs_plugins/node/skyboxes/textures/cloudySea.jpg +0 -0
  109. data/vendor/assets/javascripts/scenejs_plugins/node/skyboxes/textures/grimmNight.jpg +0 -0
  110. data/vendor/assets/javascripts/scenejs_plugins/node/skyboxes/textures/interstellarClouds.jpg +0 -0
  111. data/vendor/assets/javascripts/scenejs_plugins/node/skyboxes/textures/miramarClouds.jpg +0 -0
  112. data/vendor/assets/javascripts/scenejs_plugins/node/skyboxes/textures/stormyDays.jpg +0 -0
  113. data/vendor/assets/javascripts/scenejs_plugins/node/skyboxes/textures/violentDays.jpg +0 -0
  114. data/vendor/assets/javascripts/scenejs_plugins/node/skyboxes/violentDays.js +19 -0
  115. data/vendor/assets/javascripts/scenejs_plugins/texture/image.js +67 -0
  116. data/vendor/assets/javascripts/scenejs_plugins/texture/video.js +105 -0
  117. metadata +113 -1
@@ -0,0 +1,59 @@
1
+ // Geometry plugin which renders a box primitive defined as min-max extents
2
+ SceneJS.Plugins.addPlugin(
3
+
4
+ "geometry", // Node type
5
+ "boundary", // Plugin type
6
+
7
+ new (function () {
8
+
9
+ this.getSource = function () {
10
+ var publish;
11
+ return {
12
+ subscribe:function (fn) {
13
+ publish = fn;
14
+ },
15
+ configure:function (cfg) {
16
+ publish(build(cfg));
17
+ }
18
+ };
19
+ };
20
+
21
+ function build(cfg) {
22
+
23
+ var xmin = cfg.xmin != undefined ? cfg.xmin : 0;
24
+ var ymin = cfg.ymin != undefined ? cfg.ymin : 0;
25
+ var zmin = cfg.zmin != undefined ? cfg.zmin : 0;
26
+ var xmax = cfg.xmax != undefined ? cfg.xmax : 0;
27
+ var ymax = cfg.ymax != undefined ? cfg.ymax : 0;
28
+ var zmax = cfg.zmax != undefined ? cfg.zmax : 0;
29
+
30
+ var positions = [
31
+ xmax, ymax, zmax,
32
+ xmax, ymin, zmax,
33
+ xmin, ymin, zmax,
34
+ xmin, ymax, zmax,
35
+ xmax, ymax, zmin,
36
+ xmax, ymin, zmin,
37
+ xmin, ymin, zmin,
38
+ xmin, ymax, zmin
39
+ ];
40
+
41
+ var indices = [
42
+ 0, 1, 1,
43
+ 2, 2, 3,
44
+ 3, 0, 4,
45
+ 5, 5, 6,
46
+ 6, 7, 7,
47
+ 4, 0, 4,
48
+ 1, 5, 2,
49
+ 6, 3, 7
50
+ ];
51
+
52
+ return {
53
+ primitive:"lines",
54
+ positions:new Float32Array(positions),
55
+ indices:new Uint16Array(indices)
56
+ };
57
+ }
58
+
59
+ })());
@@ -0,0 +1,72 @@
1
+ SceneJS.Plugins.addPlugin(
2
+
3
+ "geometry", // Node type
4
+ "box", // Plugin type
5
+
6
+ new (function () {
7
+
8
+ this.getSource = function () {
9
+ var publish;
10
+ return {
11
+ subscribe:function (fn) {
12
+ publish = fn;
13
+ },
14
+ configure:function (cfg) {
15
+ publish(build(cfg));
16
+ }
17
+ };
18
+ };
19
+
20
+ function build(cfg) {
21
+
22
+ var x = cfg.xSize || 1;
23
+ var y = cfg.ySize || 1;
24
+ var z = cfg.zSize || 1;
25
+
26
+ var positions = [
27
+ x, y, z, -x, y, z, -x, -y, z, x, -y, z, // v0-v1-v2-v3 front
28
+ x, y, z, x, -y, z, x, -y, -z, x, y, -z, // v0-v3-v4-v5 right
29
+ x, y, z, x, y, -z, -x, y, -z, -x, y, z, // v0-v5-v6-v1 top
30
+ -x, y, z, -x, y, -z, -x, -y, -z, -x, -y, z, // v1-v6-v7-v2 left
31
+ -x, -y, -z, x, -y, -z, x, -y, z, -x, -y, z, // v7-v4-v3-v2 bottom
32
+ x, -y, -z, -x, -y, -z, -x, y, -z, x, y, -z // v4-v7-v6-v5 back
33
+ ];
34
+
35
+ var normals = [
36
+ 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, // v0-v1-v2-v3 front
37
+ 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, // v0-v3-v4-v5 right
38
+ 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, // v0-v5-v6-v1 top
39
+ -1, 0, 0, -1, 0, 0, -1, 0, 0, -1, 0, 0, // v1-v6-v7-v2 left
40
+ 0, -1, 0, 0, -1, 0, 0, -1, 0, 0, -1, 0, // v7-v4-v3-v2 bottom
41
+ 0, 0, -1, 0, 0, -1, 0, 0, -1, 0, 0, -1 // v4-v7-v6-v5 back
42
+ ];
43
+
44
+ var uv = [
45
+ x, y, 0, y, 0, 0, x, 0, // v0-v1-v2-v3 front
46
+ 0, y, 0, 0, x, 0, x, y, // v0-v3-v4-v5 right
47
+ x, 0, x, y, 0, y, 0, 0, // v0-v5-v6-v1 top
48
+ x, y, 0, y, 0, 0, x, 0, // v1-v6-v7-v2 left
49
+ 0, 0, x, 0, x, y, 0, y, // v7-v4-v3-v2 bottom
50
+ 0, 0, x, 0, x, y, 0, y
51
+ ]; // v4-v7-v6-v5 back
52
+
53
+ var indices = [
54
+ 0, 1, 2, 0, 2, 3, // front
55
+ 4, 5, 6, 4, 6, 7, // right
56
+ 8, 9, 10, 8, 10, 11, // top
57
+ 12, 13, 14, 12, 14, 15, // left
58
+ 16, 17, 18, 16, 18, 19, // bottom
59
+ 20, 21, 22, 20, 22, 23
60
+ ]; // back
61
+
62
+ return {
63
+ primitive:cfg.wire ? "lines" : "triangles",
64
+ coreId:"box_" + x + "_" + y + "_" + z + (cfg.wire ? "wire" : "_solid"),
65
+ positions:new Float32Array(positions),
66
+ normals:new Float32Array(normals),
67
+ uv:new Float32Array(uv),
68
+ indices:new Uint16Array(indices)
69
+ };
70
+ }
71
+
72
+ })());
@@ -0,0 +1,126 @@
1
+ /*
2
+ * Based on PlaneGeometry by Mr. Doob
3
+ */
4
+ SceneJS.Plugins.addPlugin(
5
+
6
+ "geometry", // Node type
7
+ "plane",
8
+
9
+ new (function () {
10
+
11
+ this.getSource = function () {
12
+ var publish;
13
+ return {
14
+ subscribe:function (fn) {
15
+ publish = fn;
16
+ },
17
+ configure:function (cfg) {
18
+ publish(build(cfg));
19
+ }
20
+ };
21
+ };
22
+
23
+ function build(cfg) {
24
+
25
+ var positions = [];
26
+ var normals = [];
27
+ var uvs = [];
28
+ var indices = [];
29
+
30
+ var width = cfg.width || 1.0;
31
+ var height = cfg.height || 1.0;
32
+
33
+ var widthSegments = cfg.widthSegments || 1;
34
+ var heightSegments = cfg.heightSegments || 1;
35
+
36
+ var coreId = "plane_" + (cfg.wire == true ? "wire_" : "") + height + "_" + widthSegments + "_" + heightSegments;
37
+
38
+ var ix, iz;
39
+ var halfWidth = width / 2;
40
+ var halfHeight = height / 2;
41
+
42
+ var gridX = widthSegments;
43
+ var gridZ = heightSegments;
44
+
45
+ var gridX1 = gridX + 1;
46
+ var gridZ1 = gridZ + 1;
47
+
48
+ var segWidth = width / gridX;
49
+ var segHeight = height / gridZ;
50
+
51
+ var x;
52
+ var y;
53
+
54
+ for (iz = 0; iz < gridZ1; iz++) {
55
+ for (ix = 0; ix < gridX1; ix++) {
56
+
57
+ x = ix * segWidth - halfWidth;
58
+ y = iz * segHeight - halfHeight;
59
+
60
+ positions.push(x);
61
+ positions.push(-y);
62
+ positions.push(0);
63
+
64
+ normals.push(0);
65
+ normals.push(0);
66
+ normals.push(1);
67
+ }
68
+ }
69
+
70
+ var a;
71
+ var b;
72
+ var c;
73
+ var d;
74
+
75
+ for (iz = 0; iz < gridZ; iz++) {
76
+ for (ix = 0; ix < gridX; ix++) {
77
+
78
+ a = ix + gridX1 * iz;
79
+ b = ix + gridX1 * ( iz + 1 );
80
+ c = ( ix + 1 ) + gridX1 * ( iz + 1 );
81
+ d = ( ix + 1 ) + gridX1 * iz;
82
+
83
+ indices.push(a);
84
+ indices.push(b);
85
+ indices.push(c);
86
+
87
+ indices.push(c);
88
+ indices.push(d);
89
+ indices.push(a);
90
+
91
+ // a
92
+ uvs.push(ix / gridX);
93
+ uvs.push(1 - iz / gridZ);
94
+
95
+ //b
96
+ uvs.push(ix / gridX);
97
+ uvs.push(1 - ( iz + 1 ) / gridZ);
98
+
99
+ //c
100
+ uvs.push(( ix + 1 ) / gridX);
101
+ uvs.push(1 - ( iz + 1 ) / gridZ);
102
+
103
+ //c
104
+ uvs.push(( ix + 1 ) / gridX);
105
+ uvs.push(1 - ( iz + 1 ) / gridZ);
106
+
107
+ //d
108
+ uvs.push(( ix + 1 ) / gridX, 1 - iz / gridZ);
109
+ uvs.push(1 - iz / gridZ);
110
+
111
+ //a
112
+ uvs.push(ix / gridX);
113
+ uvs.push(1 - iz / gridZ);
114
+ }
115
+ }
116
+
117
+ return {
118
+ primitive:cfg.wire ? "lines" : "triangles",
119
+ coreId:coreId,
120
+ positions:new Float32Array(positions),
121
+ normals:new Float32Array(normals),
122
+ uv:new Float32Array(uvs),
123
+ indices:new Uint16Array(indices)
124
+ };
125
+ }
126
+ })());
@@ -0,0 +1,37 @@
1
+ SceneJS.Plugins.addPlugin(
2
+
3
+ "geometry", // Node type
4
+ "quad",
5
+
6
+ new (function () {
7
+
8
+ this.getSource = function () {
9
+ var publish;
10
+ return {
11
+ subscribe:function (fn) {
12
+ publish = fn;
13
+ },
14
+ configure:function (cfg) {
15
+ publish(build(cfg));
16
+ }
17
+ };
18
+ };
19
+
20
+ function build(cfg) {
21
+
22
+ var positions = [ 1, 1, 0, -1, 1, 0, -1, -1, 0, 1, -1, 0 ];
23
+ var normals = [ -1, 0, 0, -1, 0, 0, -1, 0, 0, -1, 0, 0 ];
24
+ var uv = [ 1, 1, 0, 1, 0, 0, 1, 0 ];
25
+ var indices = [ 0, 1, 2, 0, 2, 3 ];
26
+
27
+ return {
28
+ primitive:cfg.wire ? "lines" : "triangles",
29
+ coreId:"quad" + (cfg.wire ? "wire" : "_solid"),
30
+ positions:new Float32Array(positions),
31
+ normals:new Float32Array(normals),
32
+ uv:new Float32Array(uv),
33
+ indices:new Uint16Array(indices)
34
+ };
35
+ }
36
+
37
+ })());
@@ -0,0 +1,86 @@
1
+ SceneJS.Plugins.addPlugin(
2
+
3
+ "geometry", // Node type
4
+ "skybox", // Plugin type
5
+
6
+ new (function () {
7
+
8
+ this.getSource = function () {
9
+ var publish;
10
+ return {
11
+ subscribe:function (fn) {
12
+ publish = fn;
13
+ },
14
+ configure:function (cfg) {
15
+ publish(build(cfg));
16
+ }
17
+ };
18
+ };
19
+
20
+ function build(cfg) {
21
+
22
+ var x = cfg.xSize || 1;
23
+ var y = cfg.ySize || 1;
24
+ var z = cfg.zSize || 1;
25
+
26
+ var positions = [
27
+ x, y, z, -x, y, z, -x, -y, z, x, -y, z, // v0-v1-v2-v3 front
28
+ x, y, z, x, -y, z, x, -y, -z, x, y, -z, // v0-v3-v4-v5 right
29
+ x, y, z, x, y, -z, -x, y, -z, -x, y, z, // v0-v5-v6-v1 top
30
+ -x, y, z, -x, y, -z, -x, -y, -z, -x, -y, z, // v1-v6-v7-v2 left
31
+ -x, -y, -z, x, -y, -z, x, -y, z, -x, -y, z, // v7-v4-v3-v2 bottom
32
+ x, -y, -z, -x, -y, -z, -x, y, -z, x, y, -z // v4-v7-v6-v5 back
33
+ ];
34
+
35
+ var uv = [
36
+ 0.5, 0.6666,
37
+ 0.25, 0.6666,
38
+ 0.25, 0.3333,
39
+ 0.5, 0.3333,
40
+ 0.5, 0.6666,
41
+ 0.5, 0.3333,
42
+ 0.75, 0.3333,
43
+ 0.75, 0.6666,
44
+ 0.5, 0.6666,
45
+ 0.5, 1,
46
+ 0.25, 1,
47
+ 0.25, 0.6666,
48
+ 0.25, 0.6666,
49
+ 0.0, 0.6666,
50
+ 0.0, 0.3333,
51
+ 0.25, 0.3333,
52
+ 0.50, 0,
53
+ 0.25, 0,
54
+ 0.25, 0.3333,
55
+ 0.50, 0.3333,
56
+ 0.75, 0.3333,
57
+ 1.0, 0.3333,
58
+ 1.0, 0.6666,
59
+ 0.75, 0.6666
60
+ ];
61
+
62
+ var indices = [
63
+ 0, 1, 2,
64
+ 0, 2, 3,
65
+ 4, 5, 6,
66
+ 4, 6, 7,
67
+ 8, 9, 10,
68
+ 8, 10, 11,
69
+ 12, 13, 14,
70
+ 12, 14, 15,
71
+ 16, 17, 18,
72
+ 16, 18, 19,
73
+ 20, 21, 22,
74
+ 20, 22, 23
75
+ ];
76
+
77
+ return {
78
+ primitive:"triangles",
79
+ coreId:"skybox_" + x + "_" + y + "_" + z,
80
+ positions:new Float32Array(positions),
81
+ uv:new Float32Array(uv),
82
+ indices:new Uint16Array(indices)
83
+ };
84
+ }
85
+
86
+ })());
@@ -0,0 +1,82 @@
1
+ SceneJS.Plugins.addPlugin(
2
+
3
+ "geometry", // Node type
4
+ "sphere",
5
+
6
+ new (function() {
7
+
8
+ this.getSource = function () {
9
+ var publish;
10
+ return {
11
+ subscribe:function (fn) {
12
+ publish = fn;
13
+ },
14
+ configure:function (cfg) {
15
+ publish(build(cfg));
16
+ }
17
+ };
18
+ };
19
+
20
+ function build(cfg) {
21
+
22
+ // Thanks awfully to: http://learningwebgl.com/cookbook/index.php/How_to_draw_a_sphere
23
+
24
+ var latitudeBands = cfg.latitudeBands || 30;
25
+ var longitudeBands = cfg.longitudeBands || 30;
26
+ var radius = cfg.radius || 1;
27
+
28
+ var positions = [];
29
+ var normals = [];
30
+ var uvs = [];
31
+ for (var latNumber = 0; latNumber <= latitudeBands; latNumber++) {
32
+ var theta = latNumber * Math.PI / latitudeBands;
33
+ var sinTheta = Math.sin(theta);
34
+ var cosTheta = Math.cos(theta);
35
+
36
+ for (var longNumber = 0; longNumber <= longitudeBands; longNumber++) {
37
+ var phi = longNumber * 2 * Math.PI / longitudeBands;
38
+ var sinPhi = Math.sin(phi);
39
+ var cosPhi = Math.cos(phi);
40
+
41
+ var x = cosPhi * sinTheta;
42
+ var y = cosTheta;
43
+ var z = sinPhi * sinTheta;
44
+ var u = 1- (longNumber / longitudeBands);
45
+ var v = latNumber / latitudeBands;
46
+
47
+ normals.push(x);
48
+ normals.push(y);
49
+ normals.push(z);
50
+ uvs.push(u);
51
+ uvs.push(v);
52
+ positions.push(radius * x);
53
+ positions.push(radius * y);
54
+ positions.push(radius * z);
55
+ }
56
+ }
57
+
58
+ var indices = [];
59
+ for (var latNumber = 0; latNumber < latitudeBands; latNumber++) {
60
+ for (var longNumber = 0; longNumber < longitudeBands; longNumber++) {
61
+ var first = (latNumber * (longitudeBands + 1)) + longNumber;
62
+ var second = first + longitudeBands + 1;
63
+ indices.push(first);
64
+ indices.push(second);
65
+ indices.push(first + 1);
66
+
67
+ indices.push(second);
68
+ indices.push(second + 1);
69
+ indices.push(first + 1);
70
+ }
71
+ }
72
+
73
+ return {
74
+ primitive:cfg.wire ? "lines" : "triangles",
75
+ coreId : "sphere_" + (cfg.wire ? "wire" : "_solid") + radius + "_" + longitudeBands + "_" + latitudeBands,
76
+ positions : new Float32Array(positions),
77
+ normals: new Float32Array(normals),
78
+ uv : new Float32Array(uvs),
79
+ indices : new Uint16Array(indices)
80
+ };
81
+ }
82
+ })());