User Guide Cancel

ag_functions | Substance 3D Automation ToolKit

ag_functions

Module ag_functions provides the definition of the classes FunctionContext, used for making it simpler to define functions using the ag_types classes.

class autograph.ag_functions.FunctionContext(doc, fn_node=None, name=None, use_constant_cache=True, layout_nodes=True, remove_unused_nodes=True)
class autograph.ag_functions.FunctionContext(doc, fn_node=None, name=None, use_constant_cache=True, layout_nodes=True, remove_unused_nodes=True)
 class autograph.ag_functions.FunctionContext(doc, fn_node=None, name=None, use_constant_cache=True, layout_nodes=True, remove_unused_nodes=True)  

Bases: object

Class helping out generating functions by keeping track of the document and the root node in which the construction happens

input_parameter(name, widget_type)
input_parameter(name, widget_type)
 input_parameter(name, widget_type)  

Creates an input parameter for the graph and returns the node for accessing it.

Parameters:
  • name (string) – The name of the input parameter
  • widget_type (WidgetEnum) – The type with its visual representation
Returns:

Type

variable(self, name, widget_type, use_param_type=False)
variable(self, name, widget_type, use_param_type=False)
 variable(self, name, widget_type, use_param_type=False)  

Creates a reference to a variable in the graph and returns the node for accessing it.

Parameters:
  • name (string) – The name of the input parameter
  • widget_type (WidgetEnum) – The type with its visual representation
  • use_param_type (bool) – use ParamTypeEnum instead of WidgetEnum
Returns:

Type

constant(constant, t=None)
constant(constant, t=None)
 constant(constant, t=None)  

Creates a constant

Parameters:
  • constant (int, bool, float, [int], [float]) – The constant value
  • t (None or a class such as Float3) – Type constructor None means autodetect
Returns:

Type

import_external_function(path)
import_external_function(path)
 import_external_function(path)  

Imports a function from the same document as the function is created in

Parameters:path (string) – Path to function to import
Returns:Type the node representing the imported function
import_local_function(name)
import_local_function(name)
 import_local_function(name)  

Imports a function from an external file

Parameters:name (string) – Name of function to import
Returns:Type the node representing the imported function
generate(output_node)
generate(output_node)
 generate(output_node)  

Finalizes function generation.

Parameters:output_node (Type) – The node that is the return value
Returns:Type the output node
dot(a, b)
dot(a, b)
 dot(a, b)  

Dot product

Parameters:
  • a (FloatType, float or list of float) – input parameter 1
  • b (FloatType, float or list of float) – input parameter 2
Returns:

Float1

sqrt(a)
sqrt(a)
 sqrt(a)  

Sqrt

Parameters:a (FloatType, float or list of float) – input parameter 1
Returns:FloatType
atan2(a)
atan2(a)
 atan2(a)  

Atan2

Parameters:a (FloatType, float or list of float) – input parameter 1
Returns:FloatType
abs_of(a)
abs_of(a)
 abs_of(a)  

Modulus, or Absolute value, of a.

Parameters:a (FloatType, float or list of float) – input parameter 1
Returns:FloatType
log(a)
log(a)
 log(a)  

Log

Parameters:a (FloatType, float or list of float) – input parameter 1
Returns:FloatType
exp(a)
exp(a)
 exp(a)  

Exp

Parameters:a (FloatType, float or list of float) – input parameter 1
Returns:FloatType
log2(a)
log2(a)
 log2(a)  

Log2

Parameters:a (FloatType, float or list of float) – input parameter 1
Returns:FloatType
pow2(a)
pow2(a)
 pow2(a)  

Pow2

Parameters:a (FloatType, float or list of float) – input parameter 1
Returns:FloatType
floor(a)
floor(a)
 floor(a)  

Floor

Parameters:a (FloatType, float or list of float) – input parameter 1
Returns:FloatType
ceil(a)
ceil(a)
 ceil(a)  

Ceil

Parameters:a (FloatType, float or list of float) – input parameter 1
Returns:FloatType
cos(a)
cos(a)
 cos(a)  

Cos

Parameters:a (FloatType, float or list of float) – input parameter 1
Returns:FloatType
sin(a)
sin(a)
 sin(a)  

Sin

Parameters:a (FloatType, float or list of float) – input parameter 1
Returns:FloatType
tan(a)
tan(a)
 tan(a)  

Tan

Parameters:a (FloatType, float or list of float) – input parameter 1
Returns:FloatType
rand(a)
rand(a)
 rand(a)  

Rand

Parameters:a (FloatType, float or list of float) – input parameter 1
Returns:FloatType
cartesian(a, b)
cartesian(a, b)
 cartesian(a, b)  

Cartesian

Parameters:
  • a (FloatType) – input parameter 1, float or list of float
  • b (FloatType) – input parameter 2, float or list of float
Returns:

Float2

max_of(a, b)
max_of(a, b)
 max_of(a, b)  

Maximum of a and b

Parameters:
  • a (VectorType, int, float, list of float or list of int) – input parameter 1
  • b (VectorType, int, float, list of float or list of int) – input parameter 2
Returns:

VectorType

maximum(*values)
maximum(*values)
 maximum(*values)  

Maximum value of the values

Parameters:values (VectorType, int, float, list of float or list of int) – input values
Returns:VectorType
min_of(a, b)
min_of(a, b)
 min_of(a, b)  

Minimum of a and b

Parameters:
  • a (VectorType, int, float, list of float or list of int) – input parameter 1
  • b (VectorType, int, float, list of float or list of int) – input parameter 2
Returns:

VectorType

minimum(*values)
minimum(*values)
 minimum(*values)  

Minimum value of the values

Parameters:values (VectorType, int, float, list of float or list of int) – input values
Returns:VectorType
clamp(a, b, x)
clamp(a, b, x)
 clamp(a, b, x)  

Clamp value x between a and b.

Parameters:
  • a (VectorType, int, float, list of float or list of int) – min value of clamped x
  • b (VectorType, int, float, list of float or list of int) – max value of clamped x
  • x – value to clamp
Returns:

VectorType

lerp(a, b, x)
lerp(a, b, x)
 lerp(a, b, x)  

Lerp

Parameters:
  • a (FloatType, float or list of float) – input parameter 1
  • b (FloatType, float or list of float) – input parameter 2
  • x (Float1 or float) – lerp position
Returns:

FloatType

swizzle_float1(src, out_vars)
swizzle_float1(src, out_vars)
 swizzle_float1(src, out_vars)  

Swizzle Float1

Parameters:
  • src – input parameter
  • srcFloatType, float or list of float
  • out_vars (list of int) – Output variable index
Returns:

Float1

swizzle_float2(src, out_vars)
swizzle_float2(src, out_vars)
 swizzle_float2(src, out_vars)  

Swizzle Float2

Parameters:
  • src – input parameter
  • srcFloatType, float or list of float
  • out_vars (list of int) – Output variable indices
Returns:

Float2

swizzle_float3(src, out_vars)
swizzle_float3(src, out_vars)
 swizzle_float3(src, out_vars)  

Swizzle Float3

Parameters:
  • src – input parameter
  • srcFloatType, float or list of float
  • out_vars (list of int) – Output variable indices
Returns:

Float3

swizzle_float4(src, out_vars)
swizzle_float4(src, out_vars)
 swizzle_float4(src, out_vars)  

Swizzle Float4

Parameters:
  • src – input parameter
  • srcFloatType, float or list of float
  • out_vars (list of int) – Output variable indices
Returns:

Float4

swizzle_int1(src, out_vars)
swizzle_int1(src, out_vars)
 swizzle_int1(src, out_vars)  

Swizzle Int1

Parameters:
  • src – input parameter
  • srcIntType, int or list of int
  • out_vars (list of int) – Output variable indices
Returns:

Int1

swizzle_int2(src, out_vars)
swizzle_int2(src, out_vars)
 swizzle_int2(src, out_vars)  

Swizzle Int2

Parameters:
  • src – input parameter
  • srcIntType, int or list of int
  • out_vars (list of int) – Output variable indices
Returns:

Int2

swizzle_int3(src, out_vars)
swizzle_int3(src, out_vars)
 swizzle_int3(src, out_vars)  

Swizzle Int3

Parameters:
  • src – input parameter
  • srcIntType, int or list of int
  • out_vars (list of int) – Output variable indices
Returns:

Int3

swizzle_int4(src, out_vars)
swizzle_int4(src, out_vars)
 swizzle_int4(src, out_vars)  

Swizzle Int4

Parameters:
  • src – input parameter
  • srcIntType, int or list of int
  • out_vars (list of int) – Output variable indices
Returns:

Int4

expand_to_int2(src, fill)
expand_to_int2(src, fill)
 expand_to_int2(src, fill)  

Expands a Int1 to Int2

Parameters:
  • src (Int1 or int) – source vector
  • fill (IntType, int or list of int) – What to fill the empty values with
Returns:

Int2

expand_to_int3(src, fill)
expand_to_int3(src, fill)
 expand_to_int3(src, fill)  

Expands a Int1 or Int2 to Int3

Parameters:
  • src (IntType, int or list of int) – source vector
  • fill (IntType, int or list of int) – What to fill the empty values with
Returns:

Int3

expand_to_int4(src, fill)
expand_to_int4(src, fill)
 expand_to_int4(src, fill)  

Expands a Int1, Int2 or Int3 to Int4

Parameters:
  • src (IntType, int or list of int) – source vector
  • fill (IntType, int or list of int) – What to fill the empty values with
Returns:

Int4

expand_to_float2(src, fill)
expand_to_float2(src, fill)
 expand_to_float2(src, fill)  

Expands a Float1 to Float2

Parameters:
  • src (Float1 or float) – source vector
  • fill (FloatType, float or list of float) – What to fill the empty values with
Returns:

Float2

expand_to_float3(src, fill)
expand_to_float3(src, fill)
 expand_to_float3(src, fill)  

Expands a Float1 or Float2 to Float3

Parameters:
  • src (FloatType, float or list of float) – source vector
  • fill (FloatType, float or list of float) – What to fill the empty values with
Returns:

Float3

expand_to_float4(src, fill)
expand_to_float4(src, fill)
 expand_to_float4(src, fill)  

Expands a Float1, Float2 or Float3 to Float4

Parameters:
  • src (FloatType, float or list of float) – source vector
  • fill (FloatType, float or list of float) – What to fill the empty values with
Returns:

Float4

expand(*vectors)
expand(*vectors)
 expand(*vectors)  

Expand two vector to a vector of the appropriate type and dimension.

The sum of the dimension of the input vectors must not be larger than 4. Plus all input vectors must be integers or all input vectors must be float.

Parameters:vectors (VectorType, int, float, list of int, list of float) – vectors to concatenate
Returns:VectorType
cast_to_float1(src)
cast_to_float1(src)
 cast_to_float1(src)  

Casts an Int1 to Float1

Parameters:src (Int1 or int) – source
Returns:Float1
cast_to_float2(src)
cast_to_float2(src)
 cast_to_float2(src)  

Casts an Int2 to Float2

Parameters:src (Int2 or list of int) – source
Returns:Float2
cast_to_float3(src)
cast_to_float3(src)
 cast_to_float3(src)  

Casts an Int3 to Float3

Parameters:src (Int3 or list of int) – source
Returns:Float3
cast_to_float4(src)
cast_to_float4(src)
 cast_to_float4(src)  

Casts an Int4 to Float4

Parameters:src (Int4 or list of int) – source
Returns:Float4
auto_cast_to_float(src)
auto_cast_to_float(src)
 auto_cast_to_float(src)  

Casts a numeric vector to a float vector of the same dimension

Parameters:src (IntType, int or list of int) – source vector
Returns:FloatType
cast_to_int1(src)
cast_to_int1(src)
 cast_to_int1(src)  

Casts a Float1 to Int1

Parameters:src (Float1 or float) – source
Returns:Int1
cast_to_int2(src)
cast_to_int2(src)
 cast_to_int2(src)  

Casts a Float2 to Int2

Parameters:src (Float2 or list of float) – source
Returns:Int2
cast_to_int3(src)
cast_to_int3(src)
 cast_to_int3(src)  

Casts a Float3 to Int3

Parameters:src (Float3 or list of float) – source
Returns:Int3
cast_to_int4(src)
cast_to_int4(src)
 cast_to_int4(src)  

Casts a Float4 to Int4

Parameters:src (Float4 or list of float) – source
Returns:Int4
auto_cast_to_int(src)
auto_cast_to_int(src)
 auto_cast_to_int(src)  

Casts a numeric vector to an Int vector of the same dimension

Parameters:src (FloatType float or list of float) – source vector
Returns:IntType
if_else(condition, value_on_true, value_on_false)
if_else(condition, value_on_true, value_on_false)
 if_else(condition, value_on_true, value_on_false)  

Choose one of two values based on a condition

Parameters:
  • condition (Boolean or bool) – The condition to select on
  • value_on_true (VectorType, float, int, list of float or list of int) – Return value for true
  • value_on_false (VectorType, float, int, list of float or list of int) – Return value for false
Returns:

VectorType

seq(a, b)
seq(a, b)
 seq(a, b)  

Execute all nodes resulting in branch a then execute all nodes resulting in branch b. Outputs the output of branch b.

Parameters:
  • a (Type) – input sequence 1
  • b (Type) – input sequence 2
Returns:

Type

sequence(*values)
sequence(*values)
 sequence(*values)  

Execute all nodes in sequence and output the output of the last input.

Parameters:values (Type) – input sequences
Returns:Type
set_var(a, name)
set_var(a, name)
 set_var(a, name)  

Set a variable name to the give value.

Parameters:
  • a (Type, bool, int, float, list of int or list of float) – value to set
  • name (str) – name of the set value
Returns:

Type

create_color_sampler(pos, input_index)
create_color_sampler(pos, input_index)
 create_color_sampler(pos, input_index)  

Creates a color sampler

Parameters:
  • pos (Float2 or list of float) – Point to sample
  • input_index (int) – Index of input to sample from
  • filtering_mode (FilteringEnum) – Filter to use for the sampler
Returns:

Float4

create_gray_sampler(pos, input_index)
create_gray_sampler(pos, input_index)
 create_gray_sampler(pos, input_index)  

Creates a gray scale sampler

Parameters:
  • pos (Float2 or list of float) – Point to sample
  • input_index (int) – Index of input to sample from
  • filtering_mode (FilteringEnum) – Filter to use for the sampler
Returns:

Float1

create_passthrough(src)
create_passthrough(src)
 create_passthrough(src)  

passthrough(src) Create a PassThrough (dot) node function

Parameters:src (Type, any class that inherits Type) – source
Returns:SBSFunction
normalize(a)
normalize(a)
 normalize(a)  

Normalize a vector

Parameters:a (FloatType or list of float) – Vector to normalize
Returns:FloatType
autograph.ag_functions.generate_function(fn, doc, fn_node=None, name=None, layout_nodes=True, remove_unused_nodes=True)
autograph.ag_functions.generate_function(fn, doc, fn_node=None, name=None, layout_nodes=True, remove_unused_nodes=True)
 autograph.ag_functions.generate_function(fn, doc, fn_node=None, name=None, layout_nodes=True, remove_unused_nodes=True)  

Generates a function by calling back to the generator function

Parameters:
  • fn (Python function, taking as unique parameter a FunctionContext) – Function taking a FunctionContext as input that generates the actual operations
  • doc (SBSDocument) – The document to create the network in
  • fn_node (SBSDynamicValue) – A function node in which the function should be created, must be None if the name is not None
  • name (string) – Name of the function to be created. Must be None if fn_node is not None
  • layout_nodes (bool) – Whether the nodes should be laid out left to right
  • remove_unused_nodes (bool) – Whether nodes not connected to the output node should be removed. Only works if layout_nodes is true
Returns:

function to call to create node

Get help faster and easier

New user?