Understanding 3D Scene Logic

As a scene designer, you manipulate mesh nodes in the scene editor during design-time. But during run-time, you can also perform the same changes with Snap blocks.

When showing off some products in a 3D scene, you may want to make some substantial changes to parts of the scene programmatically. For example:

  • Change the spacing between fenceposts surrounding a deck, depending on the type of fencing material.

  • Create or remove a number of embellishments on a door frame, based on logic.

You already know how to do these things in the scene editor. This article shows you how to perform just about any node manipulation using Snap.

What are nodes?

Remember that every logical part of a scene is considered a “node”, including the scene node itself. All nodes are listed in the object hierarchy of the scene editor. Usually, you create, clone, delete, or adjust the properties of these nodes during design-time in the scene editor, and see your changes immediately.

To start manipulating a scene node with a scene rule or action, you need to specify which node you want. Nodes in the scene (like fields in the configurator) can be referred to in two different ways: by reference, or by name.

Here are two blocks of Snap code that do the same thing: change the height of a node called “Box” to 1. Note how two different “set node” blocks are available to perform the same action:

  1. The first line of code refers to the Box node by reference: you simply pick the node from a drop-down list. Usually, this is the best way to refer to a node. The Snap blocks are shorter and simpler to use.

  2. The second line of code refers by name. You spell out the exact name of the node you want with a text block, and you also have to specify the type of node you are manipulating (here, we chose “BoxNode”). This Snap block is longer and more complex, but offers some benefits.

Use Case By Reference

By Name

 

Ease of use. You want to find a node quickly and easily, selecting it from a list of all nodes in the scene. Typing the first letter or two in its name shortens the list of choices.

 

No broken references. You want your Snap code to automatically update, if the name of any node changes, it updates in the Snap code as well.

 

Wildcards. You want to manipulate a collection of nodes with similar names (such as Box1, Box2, Box3 ) with a single asterisk wildcard: “Box*”

 

More transportable code. You want your code to be transportable to another scene with nodes having the same names.

 

How do I refer to a node with Snap?

What’s the bottom line? Use the shorter Snap blocks to refer to nodes by reference almost all the time. Just don’t forget about the programming power available if you refer to nodes by name.

 

Snap blocks to manipulate nodes often appear in pairs: one by reference, and one by name.

For brevity, this article will focus on the short, simple blocks referring by reference.

Node operations with Snap

Getting nodes

  • get node

Your users see one type of node: a mesh. But other node types help make the scene work: viewpoints, materials, and the overall environment are all nodes in the scene editor, and available to Snap.

  • get node by type
    (if you have a complex scene with many nodes and not a consistent naming convention, use this block instead of the “get node” block. The nodes are first filtered by a drop-down list by type, and then by the node name.

  • get children of type
    Nodes can be children of other nodes: this means transformations applied to the parent are also applied to the child. You can use this block to gather up the child nodes of a parent node into a collection. Loop through that collection to manipulate specific individual nodes within that group.

  • get parent
    The opposite of the “get children…” block, this “get parent” block drills up the scene hierarchy from one node to its parent. The top or root node of the scene is the scene node itself.

Getting specific types of nodes

Each of these Snap blocks works like the fundamental “get node” block, but with a convenient filter in place so only the nodes of the specified type appear in the drop-down list.

  • mesh

  • viewpoint

  • material

  • environment

Getting node properties

These Snap blocks help you get properties of a node, including the unique ID of the node itself.

  • get property

  • get ID
    If you find a node by its name, or have otherwise traversed the node tree to get to it, you may have a node to manipulate but don’t know the actual unique ID of the node. Some Snap blocks require this ID to do their work. Use this property to state the ID of a node into blocks which require it.

Setting node properties

First, use get node or one of its variants (like the mesh or viewpoint blocks) to gather up a node. Once you have a node, you can manipulate its specifics with these blocks.

  • Set property

  • set mesh material

  • set parent

  • copy properties from
    This block completely updates all the properties of a node with those from another node. Only the ID of the node is left alone (all node IDs are, by definition, unique). After using this block, you may consider updating the name of the freshly-overwritten block, so it’s easier to get a handle to in Snap.

Creating, copying, and destroying nodes

  • create node as child of

  • clone node as child of

  • delete node

Was this article helpful?