Tutorial 14 - Defaults

While most inputs are required to have default values it’s not strictly necessary to provide explicit values for those defaults. If a default is required and not specified then it will get a default value equal to an empty value. See the table at the bottom for what is considered an “empty” value for each type of attribute.

OgnTutorialDefaults.ogn

The ogn file shows the implementation of a node named “omni.graph.tutorials.Defaults”, which has sample inputs of several types without default values and matching outputs.

  1{
  2    "Defaults": {
  3        "version": 1,
  4        "categories": "tutorials",
  5        "scheduling": ["threadsafe"],
  6        "description": ["This is a tutorial node. It will move the values of inputs to corresponding outputs.",
  7                        "Inputs all have unspecified, and therefore empty, default values."
  8        ],
  9        "metadata":
 10        {
 11           "uiName": "Tutorial Node: Defaults"
 12        },
 13        "inputs": {
 14            "a_bool": {
 15                "type": "bool",
 16                "description": ["This is an attribute of type boolean"]
 17             },
 18            "a_half": {
 19                "type": "half",
 20                "description": ["This is an attribute of type 16 bit floating point"]
 21             },
 22            "a_int": {
 23                "type": "int",
 24                "description": ["This is an attribute of type 32 bit integer"]
 25             },
 26            "a_int64": {
 27                "type": "int64",
 28                "description": ["This is an attribute of type 64 bit integer"]
 29             },
 30            "a_float": {
 31                "type": "float",
 32                "description": ["This is an attribute of type 32 bit floating point"]
 33             },
 34            "a_double": {
 35                "type": "double",
 36                "description": ["This is an attribute of type 64 bit floating point"]
 37             },
 38             "a_string": {
 39                "type": "string",
 40                "description": ["This is an attribute of type string"]
 41            },
 42            "a_token": {
 43                "type": "token",
 44                "description": ["This is an attribute of type interned string with fast comparison and hashing"]
 45            },
 46            "a_uchar": {
 47               "type": "uchar",
 48               "description": ["This is an attribute of type unsigned 8 bit integer"]
 49           },
 50            "a_uint": {
 51               "type": "uint",
 52               "description": ["This is an attribute of type unsigned 32 bit integer"]
 53            },
 54            "a_uint64": {
 55                "type": "uint64",
 56                "description": ["This is an attribute of type unsigned 64 bit integer"]
 57            },
 58            "a_int2": {
 59                "type": "int[2]",
 60                "description": ["This is an attribute of type 2-tuple of integers"]
 61            },
 62            "a_matrix": {
 63                "type": "matrixd[2]",
 64                "description": ["This is an attribute of type 2x2 matrix"]
 65            },
 66            "a_array": {
 67                "type": "float[]",
 68                "description": ["This is an attribute of type array of floats"]
 69             }
 70        },
 71        "outputs": {
 72            "a_bool": {
 73                "type": "bool",
 74                "description": ["This is a computed attribute of type boolean"]
 75             },
 76            "a_half": {
 77                "type": "half",
 78                "description": ["This is a computed attribute of type 16 bit floating point"]
 79             },
 80            "a_int": {
 81                "type": "int",
 82                "description": ["This is a computed attribute of type 32 bit integer"]
 83             },
 84            "a_int64": {
 85                "type": "int64",
 86                "description": ["This is a computed attribute of type 64 bit integer"]
 87             },
 88            "a_float": {
 89                "type": "float",
 90                "description": ["This is a computed attribute of type 32 bit floating point"]
 91             },
 92            "a_double": {
 93                "type": "double",
 94                "description": ["This is a computed attribute of type 64 bit floating point"]
 95            },
 96            "a_string": {
 97                "type": "string",
 98                "description": ["This is a computed attribute of type string"]
 99            },
100            "a_token": {
101                "type": "token",
102                "description": ["This is a computed attribute of type interned string with fast comparison and hashing"]
103            },
104            "a_uchar": {
105                "type": "uchar",
106                "description": ["This is a computed attribute of type unsigned 8 bit integer"]
107            },
108            "a_uint": {
109                "type": "uint",
110                "description": ["This is a computed attribute of type unsigned 32 bit integer"]
111            },
112            "a_uint64": {
113                "type": "uint64",
114                "description": ["This is a computed attribute of type unsigned 64 bit integer"]
115            },
116            "a_int2": {
117                "type": "int[2]",
118                "description": ["This is a computed attribute of type 2-tuple of integers"]
119            },
120            "a_matrix": {
121                "type": "matrixd[2]",
122                "description": ["This is a computed attribute of type 2x2 matrix"]
123            },
124            "a_array": {
125                "type": "float[]",
126                "description": ["This is a computed attribute of type array of floats"]
127            }
128        },
129        "tests": [
130            {
131                "outputs:a_bool": false,
132                "outputs:a_double": 0.0,
133                "outputs:a_float": 0.0,
134                "outputs:a_half": 0.0,
135                "outputs:a_int": 0,
136                "outputs:a_int64": 0,
137                "outputs:a_string": "",
138                "outputs:a_token": "",
139                "outputs:a_uchar": 0,
140                "outputs:a_uint": 0,
141                "outputs:a_uint64": 0,
142                "outputs:a_int2": [0, 0],
143                "outputs:a_matrix": [[1.0, 0.0], [0.0, 1.0]],
144                "outputs:a_array": []
145            }
146        ]
147    }
148}

OgnTutorialDefaults.cpp

The cpp file contains the implementation of the compute method, which copies the input values over to the corresponding outputs. All values should be the empty defaults.

Empty Values For Attribute Types

The empty values for each of the attribute types is defined below. Having no default specified in the .ogn file for any of them is equivalent to defining a default of the given value.

Type Name

Empty Default

bool

False

double

0.0

float

0.0

half

0.0

int

0

int64

0

string

“”

token

“”

uchar

0

uint

0

uint64

0

Note

All attributes that are array types have empty defaults equal to the empty array []

Note

All tuple types have empty defaults equal to a tuple of the correct count, each member containing the empty value for the base type. e.g. a float[2] will have empty default [0.0, 0.0], and a matrix[2] will have empty default [[0.0, 0.0], [0.0, 0.0]]