Note that there are some explanatory texts on larger screens.

plurals
  1. POReusing JSON object nodes with SceneJS
    primarykey
    data
    text
    <p>I've created a webgl animation using the scenejs framework. As it'll contain a lot of identical elements, I want to minimize the amount of code used and re-use the elements as much as possible.</p> <p>Firstly, I've got diskJSON defined as following:</p> <pre><code>var diskJSON = [{ type: "disk", radius: 3, inner_radius: 2}]; </code></pre> <p>When I run the following code with sceneJS, it works fine.</p> <pre><code>{ 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 }] } ] } ] } </code></pre> <p>However, when I try to reuse the same diskJSON as defined previously, it only creates one node, instead of 4:</p> <pre><code>{ 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 } ] } ] } </code></pre> <p>The application will have thousands of these nodes, so having to redefine it every single time seems quite a waste. Is this a problem with scenejs or is this working as intended in regards to Javascript/JSON functionality? </p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload