Difference between revisions of "Prim Class"

From TouchDesigner Documentation
Jump to: navigation, search
(Prim Class Auto Create)
m
(Tag: 2018.28070)
 
(12 intermediate revisions by 4 users not shown)
Line 1: Line 1:
{{TDClassSummary|summary=A Prim describes an instance to a single geometry primitive.  They are accessible through the SOP.prims member.}}
+
{{TDClassSummary|label=Prim|summary=A Prim describes an instance to a single [[Primitive|geometry primitive]].  They are accessible through the [[SOP Class|SOP.prims]] member.}}
{{ClassMemberSection|empty=}}
+
<section begin=HELPBODY />
 +
{{ClassMemberSection|empty=
 +
|Sectionsummary=
 +
|items=
 +
 
{{ClassMember
 
{{ClassMember
 
     |class=Prim
 
     |class=Prim
 
     |name=center
 
     |name=center
     |returns=
+
     |type=tdu.Position
 +
    |set=1
 +
    |text=Get or set the barycentric coordinate of this primitive. It is expressed as a tdu.Position object.
 +
}}
 +
{{ClassMember
 +
    |class=Prim
 +
    |name=index
 +
    |type=int
 
     |set=0
 
     |set=0
     |text=Get or set the barycentric coordinate of this primitive. It is expressed as a named 4-tuple (x,y,z,w).
+
     |text=The primitive index in the list.
 
}}
 
}}
 
{{ClassMember
 
{{ClassMember
 
     |class=Prim
 
     |class=Prim
     |name=max
+
     |name=normal
     |returns=
+
     |type=tdu.Vector
 
     |set=0
 
     |set=0
     |text=The maximum coordinates of this primitive along each dimension, expressed as a named 4-tuple (x,y,z,w).
+
     |text=The calculated normal vector of this primitive, expressed as a tdu.Vector object.
 
}}
 
}}
 
{{ClassMember
 
{{ClassMember
 
     |class=Prim
 
     |class=Prim
     |name=min
+
     |name=owner
     |returns=
+
     |type=OP
 
     |set=0
 
     |set=0
     |text=The minimum coordinates of this primitive along each dimension, expressed as a named 4-tuple (x,y,z,w)
+
     |text=The [[OP Class|OP]] to which this object belongs.}}
}}
 
 
{{ClassMember
 
{{ClassMember
 
     |class=Prim
 
     |class=Prim
     |name=normal
+
     |name=weight
     |returns=
+
     |type=float
 
     |set=0
 
     |set=0
     |text=The calculated normal vector of this primitive, expressed as a named 4-tuple (x,y,z,w).
+
     |text=The associated weight of the primitive. Only certain primitives, such as those created by the [[Metaball SOP]] can modify this value from its default of 2.0.}}
}}
 
 
{{ClassMember
 
{{ClassMember
 
     |class=Prim
 
     |class=Prim
     |name=owner
+
     |name=direction
     |returns=
+
     |type=tdu.Vector
 
     |set=0
 
     |set=0
     |text=The OP to which this object belongs.
+
     |text=A normalized vector pointing from the centroid of the SOP to the centroid of this primitive.
 
}}
 
}}
 
{{ClassMember
 
{{ClassMember
 
     |class=Prim
 
     |class=Prim
     |name=size
+
     |name=min
     |returns=
+
     |type=tdu.Position
 
     |set=0
 
     |set=0
     |text=The size of this primitive along each dimension, expressed as a named 4-tuple (x,y,z,w).
+
     |text=The minimum coordinates of this primitive along each dimension, expressed as a tdu.Position object.
 
}}
 
}}
 
{{ClassMember
 
{{ClassMember
 
     |class=Prim
 
     |class=Prim
     |name=weight
+
     |name=max
     |returns=
+
     |type=tdu.Position
 
     |set=0
 
     |set=0
     |text=The associated weight of the primitive.  Only certain primitives, such as those created by the Metaball SOP can modify this value from its default of 2.0.
+
     |text=The maximum coordinates of this primitive along each dimension, expressed as a tdu.Position object.
 
}}
 
}}
 
{{ClassMember
 
{{ClassMember
 
     |class=Prim
 
     |class=Prim
     |name=index
+
     |name=size
     |returns=
+
     |type=tdu.Position
 
     |set=0
 
     |set=0
     |text=The primitive index in the list.
+
     |text=The size of this primitive along each dimension, expressed as a tdu.Position object.
}}
+
}}}}
{{ClassMethodSection|empty=}}
+
{{ClassMethodSection|empty=
 +
|Sectionsummary=
 +
|items=
 +
{{ClassMethod
 +
    |class=Prim
 +
    |name=destroy
 +
    |call=destroy(destroyPoints=True)
 +
    |returns=None
 +
    |text=Destroy and remove the actual primitive this object refers to. This operation is only valid when the primitive belongs to a [[scriptSOP Class|scriptSOP]]. Note: after this call, other existing Prim objects in this SOP may no longer be valid.
 +
*destroyPoints - (Keyword, Optional) If True, its [[Point Class|points]] are destroyed as well, if false, they are simply detached. The argument is True by default.}}
 
{{ClassMethod
 
{{ClassMethod
 
     |class=Prim
 
     |class=Prim
 
     |name=eval
 
     |name=eval
 
     |call=eval(u, v)
 
     |call=eval(u, v)
     |returns=
+
     |returns=td.Position
     |text=: -> Position
+
     |text=Evaluate the [[Position Class|position]] on the primitive given the u,v coordinates. u,v should be in the range [0,1]. Polygons and curves ignore the v parameter.
Evaluate the position on the primitive given the u,v coordinates. u,v should be in the range [0,1]. Polygons and curves ignore the v parameter.
+
<syntaxhighlight lang=python>
 
center = op('box1').prim[0].eval(0.5, 0.5)
 
center = op('box1').prim[0].eval(0.5, 0.5)
 +
</syntaxhighlight>}}}}
 +
{{SubSection|title=Special Functions
 +
|text=
 +
{{ClassMethod
 +
    |class=Prim
 +
    |name=len
 +
    |call=len(Prim)
 +
    |returns=int
 +
    |text=Returns the total number of vertices.
 +
<syntaxhighlight lang=python>
 +
a = len(op('box1').prim[0])
 +
</syntaxhighlight>
 +
}}
 +
{{ClassMethod
 +
    |class=Prim
 +
    |name=[]
 +
    |call=[index]
 +
    |returns=td.Vertex
 +
    |text=Get specific vertex given an integer index
 +
<syntaxhighlight lang=python>
 +
n = op('box1').prims[5][0]
 +
</syntaxhighlight>
 
}}
 
}}
 
{{ClassMethod
 
{{ClassMethod
 
     |class=Prim
 
     |class=Prim
     |name=destroy
+
     |name=[]
     |call=destroy(destroyPoints=True)
+
     |call=[row, col]
     |returns=
+
     |returns=td.Vertex
     |text=:
+
     |text=Get specific vertex from a Mesh given integer row and column values.
Destroy and remove the actual primitive this object refers to.  This operation is only valid when the primitive belongs to a scriptSOP.
+
<syntaxhighlight lang=python>
Note: after this call, other existing Prim objects in this SOP may no longer be valid.
+
v = op('grid1').prims[2,3]
destroyPoints - (Keyword, Optional) If True, its points are destroyed as well, if false, they are simply detached.  The argument is True by default.
+
</syntaxhighlight>
 
}}
 
}}
<taggedhistory/>
+
{{ClassMethod
 
+
    |class=Prim
{{{{#invoke:Category|list|Python Reference}}}}
+
    |name=Iterator
 +
    |call=Iterator
 +
    |returns=td.Vertex
 +
    |text=Iterate over each vertex.
 +
<syntaxhighlight lang=python>
 +
for m in op('box1').prims[5]:
 +
# do something with m, which is a Vertex
 +
</syntaxhighlight>
 +
}}}}
 +
<section end=HELPBODY />
 +
{{History}}
 +
{{#invoke:Category|list|Python Reference}}

Latest revision as of 13:57, 11 January 2019

A Prim describes an instance to a single geometry primitive. They are accessible through the SOP.prims member.


Members[edit]

centertdu.Position :

Get or set the barycentric coordinate of this primitive. It is expressed as a tdu.Position object.

indexint (Read Only):

The primitive index in the list.

normaltdu.Vector (Read Only):

The calculated normal vector of this primitive, expressed as a tdu.Vector object.

ownerOP (Read Only):

The OP to which this object belongs.

weightfloat (Read Only):

The associated weight of the primitive. Only certain primitives, such as those created by the Metaball SOP can modify this value from its default of 2.0.

directiontdu.Vector (Read Only):

A normalized vector pointing from the centroid of the SOP to the centroid of this primitive.

mintdu.Position (Read Only):

The minimum coordinates of this primitive along each dimension, expressed as a tdu.Position object.

maxtdu.Position (Read Only):

The maximum coordinates of this primitive along each dimension, expressed as a tdu.Position object.

sizetdu.Position (Read Only):

The size of this primitive along each dimension, expressed as a tdu.Position object.

Methods[edit]

destroy(destroyPoints=True)None:

Destroy and remove the actual primitive this object refers to. This operation is only valid when the primitive belongs to a scriptSOP. Note: after this call, other existing Prim objects in this SOP may no longer be valid.

  • destroyPoints - (Keyword, Optional) If True, its points are destroyed as well, if false, they are simply detached. The argument is True by default.

eval(u, v)td.Position:

Evaluate the position on the primitive given the u,v coordinates. u,v should be in the range [0,1]. Polygons and curves ignore the v parameter.

center = op('box1').prim[0].eval(0.5, 0.5)

Special Functions[edit]

len(Prim)int:

Returns the total number of vertices.

a = len(op('box1').prim[0])

[index]td.Vertex:

Get specific vertex given an integer index

n = op('box1').prims[5][0]

[row, col]td.Vertex:

Get specific vertex from a Mesh given integer row and column values.

v = op('grid1').prims[2,3]

Iteratortd.Vertex:

Iterate over each vertex.

for m in op('box1').prims[5]:
	# do something with m, which is a Vertex


TouchDesigner Build:

Any of the procedural data operators. OPs do all the work in TouchDesigner. They "cook" and output data to other OPs, which ultimately result in new images, data and audio being generated. See Node.

An Operator Family that reads, creates and modifies 3D polygons, curves, NURBS surfaces, spheres, meatballs and other 3D surface data.