Virtalis Reach Help

Appendix A – JSON Template Processor Rules

Introduction

The JSON Template Processor allows us to specify rules to apply to a Project before the Visualization is generated. 

There are currently three different rules you can create, and these require a “Pattern” which follows the path matching described in Appendix B - Rule Path Syntax.

All of these JSON rules must be provided in an array, even if there is only one rule.

ChangePropertyRule

This rule allows you to change the value of any property of any node. The JSON looks like:

[
{
  "Type" : "ChangePropertyRule",
  "Pattern" : "some-pattern",
  "PropertyName" : "property-name",
  "Value" : "newValue"
}
]

Where some-pattern, property-name, newValue are set accordingly.

Example 1: Changing diffuse colour of a material

[
{
  "Type" : "ChangePropertyRule",
  "Pattern" : "/:StdMaterial;Material_1",
  "PropertyName" : "Diffuse",
  "Value" : "0.0 1.0 0.0"
}
]

This will get all StdMaterials named ‘Material_1’ and change their Diffuse colour to green (r: 0, g:1, b:0).

Example 2: Changing smoothness of all materials in a specific library

[
{
  "Type" : "ChangePropertyRule",
  "Pattern" : "/:Library;MyLibrary/:StdMaterial",
  "PropertyName" : "Smoothness",
  "Value" : "1.0"
}
]

This will change the smoothness to 1.0 for all StdMaterials in a Library named ‘MyLibrary’.

Example 3: Changing diffuse colour of all materials

[
{
  "Type" : "ChangePropertyRule",
  "Pattern" : "/:StdMaterial",
  "PropertyName" : "Diffuse",
  "Value" : "0.0 1.0 0.0"
}
]

This will get all StdMaterials and change their Diffuse colour to green (r: 0, g:1, b:0).

DeleteNodesRule

Allows you to delete a node, and everything beneath it in the scene tree.

[
{
  "Type" : "DeleteNodesRule",
  "Pattern" : "some-pattern"
}
]

Where some-pattern is replaced with a pattern of the node(s) to delete.

Example

[
{
  "Type" : "DeleteNodesRule",
  "Pattern" : "/:Assembly;LEGO/:Assembly;RedPiece"
}
]

Deletes any Assembly nodes (and children of) called ‘RedPiece’, which are themselves a child of an Assembly called ‘LEGO’.

CreateNodeRule

Allows an entirely new node to be created. The “Pattern” specifies the parent node of the newly created node. Care must be taken that the pattern matches only a single node otherwise the rule will fail.

[
{
  "Type": "CreateNodeRule",
  "Pattern": "/:SceneList",
  "Metanode": "Assembly",
  "Name": "MyNewNodeName"
}
]

Defining Multiple Rules

Example

[
{
  "Type" : "DeleteNodesRule",
  "Pattern" : "/:Assembly;LEGO/:Assembly;RedPiece"
},
{
  "Type" : "ChangePropertyRule",
  "Pattern" : "/:Library;MyLibrary/:StdMaterial",
  "PropertyName" : "Smoothness",
  "Value" : "1.0"
},
{
  "Type": "CreateNodeRule",
  "Pattern": "/:SceneList",
  "Metanode": "Assembly",
  "Name": "MyNewNodeName"
}
]
Print page
2021.4
November 5, 2021 7:06

Need more?