Skip to content

Asset transforms

Brian Wandell edited this page Sep 24, 2021 · 23 revisions

Asset transforms

The asset tree includes definitions of the shapes and the transforms that position, rotate, and scale these shapes. The information about the transformations is contained in the 'branch' nodes of the tree. The transformations specified in each branch node apply to all of the objects beneath that branch node in the tree.

For a tutorial script on using transforms see t_piIntro_transforms.m

Transform node structs

(The examples here follow the script t_piIntro_transforms.)

We are working with a very simple scene of a colored cube. thisR = piRecipeDefault('scene name','coloredCube');

The cube is defined by its six sides that are each defined in the leaf of a tree. The 6 sides are all underneath a branch node. We can visualize the tree organization with the command thisR.show;

Clicking on one of the nodes in the image prints the node struct into your command window. Here is the result of clicking on the 0003ID_Cube_B node

--------Selected Node-----------
  struct with fields:

               type: 'branch'
               name: '0003ID_Cube_B'
               size: [1×1 struct]
              scale: {[1.0000 1.0000 1.0000]}
        translation: {[3×1 double]}
           rotation: {[4×3 double]}
    concattransform: []
             motion: []
         transorder: 'TRS'

We can read the node from the tree with a thisR.get() command. To read a node, we can use either the whole name - including the ID - or just the part of the name after the 'XXXXID_' string.

nodeName = 'Cube_B';    % Notice that this is the part after the XXXXID_ component of the name.
thisNode = thisR.get('asset',nodeName);

Please notice that the name of the node was specified WITHOUT using the ID. The value of the ID of the node change as we edit the recipe. But the part after the ID should say the same.

Order of transformations

The branch nodes containing the transforms specify multiple translations, rotations and scales. The parameters for each of these is stored in a cell array with the corresponding name. Here is a branch node after we have applied several transforms.

>> thisR.get('node',assetName)

ans = 

  struct with fields:

               type: 'branch'
               name: '0003ID_Cube_B'
               size: [1×1 struct]
              scale: {[1.0000 1.0000 1.0000]  [1.3000 1.3000 1.3000]}
        translation: {[3×1 double]  [3×1 double]}
           rotation: {[4×3 double]}
    concattransform: []
             motion: []
         transorder: 'TRSTS'

>> 

Notice that each of the slots (translation, rotation, scale) is a cell array. Each entry of the cell array contains the parameters for one operation. The nodes also specify the order of these operations in the slot 'transorder'. In this example, we apply a TRSTS order (S for scale, T for translate, R for rotate). There are two translate and two scale calls, and thus the cell arrays for translation and scale have two entries.

Translations

To apply a translation to a branch node, we use the command

thisR.set('node', thisNode.name, 'translate', [0.3 0.3 0]);

The parameters in the final slot are (x,y,z) in meters.

Often we want to set the position of an object to a specific place in the image, not just translate it. For this function you can call

thisR.set('node',thisNode.name,'world position',[1 2 1.3]);

You can use the function piAssetGeometry(thisR) to visualize the positions of all the objects in the scene.

You can also use thisR.show('objects') to print a list of the positions and other object properties.

>> thisR.show('objects');
                              material            positions (m)           sizes (m)     
                         __________________    ___________________    __________________

    0004ID_001_Cube_O    {'YellowMaterial'}    {'0.41 -0.11 3.06'}    {'0.65 0.00 0.65'}
    0005ID_002_Cube_O    {'GreenMaterial' }    {'0.41 -0.11 3.06'}    {'0.00 0.65 0.65'}
    0006ID_003_Cube_O    {'BlueMaterial'  }    {'0.41 -0.11 3.06'}    {'0.65 0.65 0.00'}
    0007ID_004_Cube_O    {'RedMaterial'   }    {'0.41 -0.11 3.06'}    {'0.00 0.65 0.65'}
    0008ID_005_Cube_O    {'PurpleMaterial'}    {'0.41 -0.11 3.06'}    {'0.65 0.65 0.00'}
    0009ID_006_Cube_O    {'CyanMaterial'  }    {'0.41 -0.11 3.06'}    {'0.65 0.00 0.65'}

Rotations

Scale

Sequencing the operations

Clone this wiki locally