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,85 @@
|
|
1
|
+
/**
|
2
|
+
* Physics rigid-body
|
3
|
+
*
|
4
|
+
* Documentation: https://github.com/xeolabs/scenejs/wiki/Physics
|
5
|
+
*/
|
6
|
+
require([
|
7
|
+
// Prefix routes to plugin support libs
|
8
|
+
"scenejsPluginDeps/physics/physics"
|
9
|
+
],
|
10
|
+
function (physics) {
|
11
|
+
|
12
|
+
SceneJS.Types.addType("physics/body", {
|
13
|
+
|
14
|
+
construct:function (params) {
|
15
|
+
|
16
|
+
// Don't need to provide initial attributes for our scene nodes
|
17
|
+
// because that will will happen via an update from the physics
|
18
|
+
// system once we have created the physics body.
|
19
|
+
|
20
|
+
var translate;
|
21
|
+
var rotate;
|
22
|
+
|
23
|
+
if (params.shape == "sphere") {
|
24
|
+
|
25
|
+
// No point in rotating a sphere
|
26
|
+
translate = this.addNode({
|
27
|
+
type:"translate",
|
28
|
+
nodes:params.nodes
|
29
|
+
});
|
30
|
+
|
31
|
+
} else {
|
32
|
+
|
33
|
+
translate = this.addNode({
|
34
|
+
type:"translate"
|
35
|
+
});
|
36
|
+
|
37
|
+
rotate = translate.addNode({
|
38
|
+
type:"matrix",
|
39
|
+
nodes:params.nodes // Plugin node is responsible for attaching specified child nodes
|
40
|
+
});
|
41
|
+
}
|
42
|
+
|
43
|
+
// Get physics system for this scene
|
44
|
+
// When params.systemId is undefined, get the default system for this scene
|
45
|
+
this._system = physics.getSystem(this.getScene(), params.systemId);
|
46
|
+
|
47
|
+
try {
|
48
|
+
|
49
|
+
// There must be no overlap in params for SceneJS and the physics system
|
50
|
+
// because we are just passing those params straight through to the system.
|
51
|
+
|
52
|
+
this._bodyId = this._system.createBody(params,
|
53
|
+
function (pos, dir) { // Body update handler
|
54
|
+
translate.setXYZ({ x:pos[0], y:pos[1], z:pos[2] });
|
55
|
+
if (rotate) {
|
56
|
+
rotate.setElements(dir);
|
57
|
+
}
|
58
|
+
});
|
59
|
+
} catch (e) {
|
60
|
+
this.log("error", e);
|
61
|
+
}
|
62
|
+
},
|
63
|
+
|
64
|
+
preCompile:function () {
|
65
|
+
if (this._bodyId != undefined) {
|
66
|
+
var material = window._sceneJSPhysicsMaterial;
|
67
|
+
if (material) {
|
68
|
+
// Inherit state from parent "physics/material" node
|
69
|
+
this._system.updateBody(this._bodyId, material);
|
70
|
+
}
|
71
|
+
}
|
72
|
+
},
|
73
|
+
|
74
|
+
postCompile:function () {
|
75
|
+
// Not used
|
76
|
+
},
|
77
|
+
|
78
|
+
destruct:function () {
|
79
|
+
if (this._bodyId) {
|
80
|
+
this._system.removeBody(this._bodyId);
|
81
|
+
}
|
82
|
+
physics.putSystem(this._system);
|
83
|
+
}
|
84
|
+
});
|
85
|
+
});
|
@@ -0,0 +1,30 @@
|
|
1
|
+
/**
|
2
|
+
* A box geometry with rigid-body physics behavior
|
3
|
+
*
|
4
|
+
* Documentation: https://github.com/xeolabs/scenejs/wiki/Physics
|
5
|
+
*
|
6
|
+
*/
|
7
|
+
SceneJS.Types.addType("physics/box", {
|
8
|
+
construct:function (params) {
|
9
|
+
|
10
|
+
this.addNode({
|
11
|
+
type:"physics/body",
|
12
|
+
shape: "box",
|
13
|
+
pos: params.pos,
|
14
|
+
size: params.size,
|
15
|
+
mass: params.mass,
|
16
|
+
restitution: params.restitution,
|
17
|
+
friction: params.friction,
|
18
|
+
velocity: params.velocity,
|
19
|
+
movable: params.movable,
|
20
|
+
|
21
|
+
nodes:[
|
22
|
+
{
|
23
|
+
type:"prims/box",
|
24
|
+
size: params.size
|
25
|
+
}
|
26
|
+
]
|
27
|
+
});
|
28
|
+
}
|
29
|
+
});
|
30
|
+
|
@@ -0,0 +1,35 @@
|
|
1
|
+
/**
|
2
|
+
* Physics material
|
3
|
+
*
|
4
|
+
* Documentation: https://github.com/xeolabs/scenejs/wiki/Physics
|
5
|
+
*/
|
6
|
+
require([
|
7
|
+
// Prefix routes to plugin support libs
|
8
|
+
"scenejsPluginDeps/physics/physics"
|
9
|
+
],
|
10
|
+
function (physics) {
|
11
|
+
|
12
|
+
SceneJS.Types.addType("physics/material", {
|
13
|
+
|
14
|
+
construct:function (params) {
|
15
|
+
this._material = params;
|
16
|
+
if (params.nodes) {
|
17
|
+
this.addNodes(params.nodes);
|
18
|
+
}
|
19
|
+
},
|
20
|
+
|
21
|
+
preCompile:function () {
|
22
|
+
|
23
|
+
// Child "physics/body" nodes will look for this on the window scope.
|
24
|
+
|
25
|
+
// Seems a bit dirty to put it on window scope, but it's OK because
|
26
|
+
// there can only be one scene compilation happening at any moment.
|
27
|
+
|
28
|
+
window._sceneJSPhysicsMaterial = this._material;
|
29
|
+
},
|
30
|
+
|
31
|
+
postCompile:function () {
|
32
|
+
window._sceneJSPhysicsMaterial = null;
|
33
|
+
}
|
34
|
+
});
|
35
|
+
});
|
@@ -0,0 +1,47 @@
|
|
1
|
+
/**
|
2
|
+
* A plane geometry with rigid-body physics behavior
|
3
|
+
*
|
4
|
+
* Documentation: https://github.com/xeolabs/scenejs/wiki/Physics
|
5
|
+
*
|
6
|
+
*/
|
7
|
+
SceneJS.Types.addType("physics/plane", {
|
8
|
+
construct:function (params) {
|
9
|
+
|
10
|
+
this.addNode({
|
11
|
+
type:"physics/body",
|
12
|
+
shape:"plane",
|
13
|
+
pos:params.pos,
|
14
|
+
dir:params.dir,
|
15
|
+
mass:params.mass,
|
16
|
+
restitution:params.restitution,
|
17
|
+
friction:params.friction,
|
18
|
+
velocity:params.velocity,
|
19
|
+
movable:params.movable,
|
20
|
+
|
21
|
+
nodes:[
|
22
|
+
{
|
23
|
+
type:"scale",
|
24
|
+
x:1000,
|
25
|
+
y:.5,
|
26
|
+
z:1000,
|
27
|
+
nodes:[
|
28
|
+
{
|
29
|
+
type:"rotate",
|
30
|
+
x:1,
|
31
|
+
angle:90,
|
32
|
+
nodes:[
|
33
|
+
{
|
34
|
+
type:"prims/plane",
|
35
|
+
wire:params.wire,
|
36
|
+
xSegments:params.xSegments || 100,
|
37
|
+
zSegments:params.zSegments || 100
|
38
|
+
}
|
39
|
+
]
|
40
|
+
}
|
41
|
+
]
|
42
|
+
}
|
43
|
+
]
|
44
|
+
});
|
45
|
+
}
|
46
|
+
});
|
47
|
+
|
@@ -0,0 +1,32 @@
|
|
1
|
+
/**
|
2
|
+
* A sphere geometry with rigid-body physics behavior
|
3
|
+
*
|
4
|
+
* Documentation: https://github.com/xeolabs/scenejs/wiki/Physics
|
5
|
+
*
|
6
|
+
*/
|
7
|
+
SceneJS.Types.addType("physics/sphere", {
|
8
|
+
construct:function (params) {
|
9
|
+
|
10
|
+
this.addNode({
|
11
|
+
type:"physics/sphere",
|
12
|
+
shape: "sphere",
|
13
|
+
pos: params.pos,
|
14
|
+
radius: params.radius,
|
15
|
+
mass: params.mass,
|
16
|
+
restitution: params.restitution,
|
17
|
+
friction: params.friction,
|
18
|
+
velocity: params.velocity,
|
19
|
+
movable: params.movable,
|
20
|
+
|
21
|
+
nodes:[
|
22
|
+
{
|
23
|
+
type:"prims/radius",
|
24
|
+
latitudeBands: params.latitudeBands,
|
25
|
+
longitudeBands: params.longitudeBands,
|
26
|
+
radius: params.radius
|
27
|
+
}
|
28
|
+
]
|
29
|
+
});
|
30
|
+
}
|
31
|
+
});
|
32
|
+
|
@@ -0,0 +1,44 @@
|
|
1
|
+
/**
|
2
|
+
* Configuration for a physics system
|
3
|
+
*
|
4
|
+
* Documentation: https://github.com/xeolabs/scenejs/wiki/Physics
|
5
|
+
*/
|
6
|
+
require([
|
7
|
+
// Prefix routes to plugin support libs
|
8
|
+
"scenejsPluginDeps/physics/physics"
|
9
|
+
],
|
10
|
+
function (physics) {
|
11
|
+
|
12
|
+
SceneJS.Types.addType("physics/system", {
|
13
|
+
|
14
|
+
construct:function (params) {
|
15
|
+
|
16
|
+
// Get physics system for this scene
|
17
|
+
// When params.systemId is undefined, get the default system for this scene
|
18
|
+
this._system = physics.getSystem(this.getScene(), params.systemId);
|
19
|
+
|
20
|
+
this.setConfigs(params);
|
21
|
+
},
|
22
|
+
|
23
|
+
/**
|
24
|
+
* Configures the physics system
|
25
|
+
* @param params
|
26
|
+
*/
|
27
|
+
setConfigs:function (params) {
|
28
|
+
this._system.setConfigs(params);
|
29
|
+
},
|
30
|
+
|
31
|
+
/**
|
32
|
+
* Enable or disable this physics system.
|
33
|
+
* To save CPU, you would typically disable the system when its not in view.
|
34
|
+
* @param enabled
|
35
|
+
*/
|
36
|
+
setEnabled:function (enabled) {
|
37
|
+
this._system.setEnabled(enabled);
|
38
|
+
},
|
39
|
+
|
40
|
+
destruct:function () {
|
41
|
+
physics.putSystem(this._system);
|
42
|
+
}
|
43
|
+
});
|
44
|
+
});
|
@@ -0,0 +1,29 @@
|
|
1
|
+
/**
|
2
|
+
* A teapot geometry with rigid-body physics behavior
|
3
|
+
*
|
4
|
+
* Documentation: https://github.com/xeolabs/scenejs/wiki/Physics
|
5
|
+
*
|
6
|
+
*/
|
7
|
+
SceneJS.Types.addType("physics/teapot", {
|
8
|
+
construct:function (params) {
|
9
|
+
|
10
|
+
this.addNode({
|
11
|
+
type:"physics/body",
|
12
|
+
shape: "sphere",
|
13
|
+
pos: params.pos,
|
14
|
+
radius: 1,
|
15
|
+
mass: params.mass,
|
16
|
+
restitution: params.restitution,
|
17
|
+
friction: params.friction,
|
18
|
+
velocity: params.velocity,
|
19
|
+
movable: params.movable,
|
20
|
+
|
21
|
+
nodes:[
|
22
|
+
{
|
23
|
+
type:"prims/teapot"
|
24
|
+
}
|
25
|
+
]
|
26
|
+
});
|
27
|
+
}
|
28
|
+
});
|
29
|
+
|
@@ -0,0 +1,73 @@
|
|
1
|
+
/**
|
2
|
+
* Boundary geometry node type
|
3
|
+
*
|
4
|
+
* Usage example:
|
5
|
+
*
|
6
|
+
* someNode.addNode({
|
7
|
+
* type: "prims/box",
|
8
|
+
* min: [-9, -3, -2],
|
9
|
+
* max: [2,3,12],
|
10
|
+
* wire: false // Default
|
11
|
+
* });
|
12
|
+
*/
|
13
|
+
(function () {
|
14
|
+
|
15
|
+
SceneJS.Types.addType("prims/boundary", {
|
16
|
+
|
17
|
+
construct:function (params) {
|
18
|
+
this.addNode(build.call(this, params));
|
19
|
+
}
|
20
|
+
});
|
21
|
+
|
22
|
+
function build(params) {
|
23
|
+
|
24
|
+
var min = params.min || [0, 0, 0];
|
25
|
+
var max = params.max || [0, 0, 0];
|
26
|
+
|
27
|
+
var xmin = min[0];
|
28
|
+
var ymin = min[1];
|
29
|
+
var zmin = min[2];
|
30
|
+
var xmax = max[0];
|
31
|
+
var ymax = max[1];
|
32
|
+
var zmax = max[2];
|
33
|
+
|
34
|
+
var coreId = "prims/boundary_" + xmin + "_" + ymin + "_" + zmin + "_"
|
35
|
+
+ xmax + "_" + ymax + "_" + zmax + (params.wire ? "wire" : "_solid");
|
36
|
+
|
37
|
+
// If a node core already exists for a prim with the given properties,
|
38
|
+
// then for efficiency we'll share that core rather than create another geometry
|
39
|
+
if (this.getScene().hasCore("geometry", coreId)) {
|
40
|
+
return {
|
41
|
+
type:"geometry",
|
42
|
+
coreId:coreId
|
43
|
+
};
|
44
|
+
}
|
45
|
+
|
46
|
+
// Otherwise, create a new geometry
|
47
|
+
return {
|
48
|
+
type:"geometry",
|
49
|
+
primitive:params.wire ? "lines" : "triangles",
|
50
|
+
coreId:coreId,
|
51
|
+
positions:[
|
52
|
+
xmax, ymax, zmax,
|
53
|
+
xmax, ymin, zmax,
|
54
|
+
xmin, ymin, zmax,
|
55
|
+
xmin, ymax, zmax,
|
56
|
+
xmax, ymax, zmin,
|
57
|
+
xmax, ymin, zmin,
|
58
|
+
xmin, ymin, zmin,
|
59
|
+
xmin, ymax, zmin
|
60
|
+
],
|
61
|
+
indices:[
|
62
|
+
0, 1, 1,
|
63
|
+
2, 2, 3,
|
64
|
+
3, 0, 4,
|
65
|
+
5, 5, 6,
|
66
|
+
6, 7, 7,
|
67
|
+
4, 0, 4,
|
68
|
+
1, 5, 2,
|
69
|
+
6, 3, 7
|
70
|
+
]
|
71
|
+
}
|
72
|
+
}
|
73
|
+
})();
|
@@ -0,0 +1,87 @@
|
|
1
|
+
/**
|
2
|
+
* Box geometry node type
|
3
|
+
*
|
4
|
+
* Usage example:
|
5
|
+
*
|
6
|
+
* someNode.addNode({
|
7
|
+
* type: "prims/box",
|
8
|
+
* xSize: 10,
|
9
|
+
* ySize: 20,
|
10
|
+
* zSize: 1.5,
|
11
|
+
* wire: false // Default
|
12
|
+
* });
|
13
|
+
*/
|
14
|
+
(function () {
|
15
|
+
|
16
|
+
SceneJS.Types.addType("prims/box", {
|
17
|
+
|
18
|
+
construct:function (params) {
|
19
|
+
this.addNode(build.call(this, params));
|
20
|
+
}
|
21
|
+
});
|
22
|
+
|
23
|
+
function build(params) {
|
24
|
+
|
25
|
+
var x, y, z;
|
26
|
+
if (params.size) {
|
27
|
+
x = params.size[0];
|
28
|
+
y = params.size[1];
|
29
|
+
z = params.size[2];
|
30
|
+
} else {
|
31
|
+
// Deprecated
|
32
|
+
x = params.xSize || 1;
|
33
|
+
y = params.ySize || 1;
|
34
|
+
z = params.zSize || 1;
|
35
|
+
}
|
36
|
+
|
37
|
+
var coreId = "prims/box_" + x + "_" + y + "_" + z + (params.wire ? "wire" : "_solid");
|
38
|
+
|
39
|
+
// If a node core already exists for a prim with the given properties,
|
40
|
+
// then for efficiency we'll share that core rather than create another geometry
|
41
|
+
if (this.getScene().hasCore("geometry", coreId)) {
|
42
|
+
return {
|
43
|
+
type:"geometry",
|
44
|
+
coreId:coreId
|
45
|
+
};
|
46
|
+
}
|
47
|
+
|
48
|
+
// Otherwise, create a new geometry
|
49
|
+
return {
|
50
|
+
type:"geometry",
|
51
|
+
primitive:params.wire ? "lines" : "triangles",
|
52
|
+
coreId:coreId,
|
53
|
+
positions:new Float32Array([
|
54
|
+
x, y, z, -x, y, z, -x, -y, z, x, -y, z, // v0-v1-v2-v3 front
|
55
|
+
x, y, z, x, -y, z, x, -y, -z, x, y, -z, // v0-v3-v4-v5 right
|
56
|
+
x, y, z, x, y, -z, -x, y, -z, -x, y, z, // v0-v5-v6-v1 top
|
57
|
+
-x, y, z, -x, y, -z, -x, -y, -z, -x, -y, z, // v1-v6-v7-v2 left
|
58
|
+
-x, -y, -z, x, -y, -z, x, -y, z, -x, -y, z, // v7-v4-v3-v2 bottom
|
59
|
+
x, -y, -z, -x, -y, -z, -x, y, -z, x, y, -z // v4-v7-v6-v5 back
|
60
|
+
]),
|
61
|
+
normals:new Float32Array([
|
62
|
+
0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, // v0-v1-v2-v3 front
|
63
|
+
1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, // v0-v3-v4-v5 right
|
64
|
+
0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, // v0-v5-v6-v1 top
|
65
|
+
-1, 0, 0, -1, 0, 0, -1, 0, 0, -1, 0, 0, // v1-v6-v7-v2 left
|
66
|
+
0, -1, 0, 0, -1, 0, 0, -1, 0, 0, -1, 0, // v7-v4-v3-v2 bottom
|
67
|
+
0, 0, -1, 0, 0, -1, 0, 0, -1, 0, 0, -1 // v4-v7-v6-v5 back
|
68
|
+
]),
|
69
|
+
uv:new Float32Array([
|
70
|
+
x, y, 0, y, 0, 0, x, 0, // v0-v1-v2-v3 front
|
71
|
+
0, y, 0, 0, x, 0, x, y, // v0-v3-v4-v5 right
|
72
|
+
x, 0, x, y, 0, y, 0, 0, // v0-v5-v6-v1 top
|
73
|
+
x, y, 0, y, 0, 0, x, 0, // v1-v6-v7-v2 left
|
74
|
+
0, 0, x, 0, x, y, 0, y, // v7-v4-v3-v2 bottom
|
75
|
+
0, 0, x, 0, x, y, 0, y // v4-v7-v6-v5 back
|
76
|
+
]),
|
77
|
+
indices:new Uint16Array([
|
78
|
+
0, 1, 2, 0, 2, 3, // front
|
79
|
+
4, 5, 6, 4, 6, 7, // right
|
80
|
+
8, 9, 10, 8, 10, 11, // top
|
81
|
+
12, 13, 14, 12, 14, 15, // left
|
82
|
+
16, 17, 18, 16, 18, 19, // bottom
|
83
|
+
20, 21, 22, 20, 22, 23 // back
|
84
|
+
])
|
85
|
+
};
|
86
|
+
}
|
87
|
+
})();
|