I've utilized the scenejs framework to develop a webgl animation that includes numerous identical elements. To optimize code efficiency and reuse elements whenever necessary, I'm looking to minimize redundant code usage.
Initially, I've defined diskJSON in the following manner:
var diskJSON = [{
type: "disk",
radius: 3,
inner_radius: 2}];
The code below executes successfully with sceneJS implementation:
{
type: "material",
emit: 0,
baseColor: {
r: 0.3,
g: 0.3,
b: 0.9
},
specularColor: {
r: 0.9,
g: 0.9,
b: 0.9
},
specular: 0.9,
shine: 100.0,
nodes: [{
type: "translate",
x:10,
y:1,
nodes: [{
type: "translate",
z:speedMultiplier*0.8,
nodes:[{
type: "disk",
radius: 3,
inner_radius: 2
}]
},
{
type: "translate",
z:speedMultiplier*9.8,
nodes:[{
type: "disk",
radius: 3,
inner_radius: 2
}]
},
{
type: "translate",
z:speedMultiplier*11.64,
nodes:[{
type: "disk",
radius: 3,
inner_radius: 2
}]
},
{
type: "translate",
z:speedMultiplier*13.32,
nodes:[{
type: "disk",
radius: 3,
inner_radius: 2
}]
}
]
}
]
}
However, attempting to recycle the same diskJSON definition only results in a single node instead of four:
{
type: "material",
emit: 0,
baseColor: {
r: 0.3,
g: 0.3,
b: 0.9
},
specularColor: {
r: 0.9,
g: 0.9,
b: 0.9
},
specular: 0.9,
shine: 100.0,
nodes: [{
type: "translate",
x:10,
y:1,
nodes: [
{
type: "translate",
z:speedMultiplier*0.8,
nodes:diskJSON
},
{
type: "translate",
z:speedMultiplier*9.8,
nodes:diskJSON
},
{
type: "translate",
z:speedMultiplier*11.64,
nodes:diskJSON
},
{
type: "translate",
z:speedMultiplier*13.32,
nodes:diskJSON
}
]
}
]
}
Given that the application will involve thousands of these nodes, continuously redefining them seems inefficient. Is this a limitation with scenejs or is it intended behavior within Javascript/JSON functionality?