Option to create scenes from JSON
Reported by lindsay.kay (at xeolabs) | August 18th, 2010 @ 05:35 PM | in V0.7.7
Provide the option to create scenes from real JSON, ie. the purely declarative stuff without any function calls in it.
Wiki page at: http://scenejs.wikispaces.com/JSON+Scene+Definition
Scene Definition
For example:
var exampleScene = SceneJS.createNode({
type: "scene",
cfg: {
canvasId: 'theCanvas',
loggingElementId: "theLoggingDiv"
},
nodes: [
{
type: "lookat",
cfg: {
eye : { x: 0, y: 0, z: -10},
look : { x : 0.0, y : 0.0, z : 0 },
up : { x: 0.0, y: 1.0, z: 0.0 }
},
nodes: [
{
type: "camera",
cfg: {
optics: {
type: "perspective",
fovy : 45.0,
aspect : 1.0,
near : 0.10,
far : 300.0
}
},
nodes: [
{
type: "lights",
cfg: {
sources: [
{
type: "dir",
color: { r: 1.0, g: 0.5, b: 0.5 },
diffuse: true,
specular: true,
dir: { x: 1.0, y: 1.0, z: -1.0 }
},
{
type: "dir",
color: { r: 0.5, g: 1.0, b: 0.5 },
diffuse: true,
specular: true,
dir: { x: 0.0, y: 1.0, z: -1.0 }
},
{
type: "dir",
color: { r: 0.2, g: 0.2, b: 1.0 },
diffuse: true,
specular: true,
dir: { x: -1.0, y: 0.0, z: -1.0 }
}
]
}
},
{
type: "material",
cfg: {
baseColor: { r: 0.3, g: 0.3, b: 0.9 },
specularColor: { r: 0.9, g: 0.9, b: 0.9 },
specular: 0.9,
shine: 6.0
},
nodes: [
{
type: "teapot",
cfg: { sid: "teapot1" }
}
]
}
]
}
]
}
]
});
Adding JSON Child Nodes
In addition to JSON scene definition, allow addition of JSON-defined children to nodes as well:
exampleScene.addNode({
type: "camera",
cfg: {
optics: {
type: "perspective",
fovy : 45.0,
aspect : 1.0,
near : 0.10,
far : 300.0
}
}
});
Pushing JSON Scene State and Definitions Around in Events
JSON representations can be pushed into nodes through events:
SceneJS.fireEvent("configure", "myCamera", {
cfg: {
/* Set new optics on the camera
*/
optics: {
type: "perspective",
fovy : 75.0,
aspect : 1.0,
near : 0.10,
far : 300.0
},
/* Push a new base colour into the camera's child material
*/
"#myMaterial": {
baseColor: { r: 0.9, g: 0.3, b: 0.3 }
},
/* Add a new child node to the camera
*/
"+node" : {
type: "rotate",
cfg: {
angle: 45,
y: 1.0
}
}
}
});
Comments and changes to this ticket
-
lindsay.kay (at xeolabs) August 31st, 2010 @ 09:51 AM
- State changed from new to resolved
Please Sign in or create a free account to add a new ticket.
With your very own profile, you can contribute to projects, track your activity, watch tickets, receive and update tickets through your email and much more.
Create your profile
Help contribute to this project by taking a few moments to create your personal profile. Create your profile ยป
SceneJS provides easy access to WebGL through a simple and declarative JavaScript API. The SceneJS API is functional, which enables its scene definitions to be really compact and expressive, while hooking into other JavaScript code just that little bit more smoothly.