Collada plugin for
After Effects

More info here
Plugins and Scripts > trueSpace > Development

Mesh

Triangle Processing

polygon to triangles using Newells Method

feed it a list of vertices space delimited "x1 y1 z1 x2 y2 z2 ..."

get back triangle data "#triangles,i1 j1 k1,i2 j2 k2, ..."

The polygon must have good geometry, will crash tS if fed bad geometry such as a rectangle that's been twisted into a bow tie shape.

polypoints = "-0.5 -0.5 -0.5 -0.5 -0.5 0.5 -0.5 0.5 0.5 -0.5 0.5 -0.5"
utilitydata = System.CreateDO("Clintons3D Package/Utility functions");
value = utilitydata.PolygonToTriangles(polypoints);
valArr = value.split(",");
for(var i = 0; i < valArr[0]*1; i++) {
	localindices = valArr[i+1].split(" ");

a little sloppy trailing space and comma in each triangle definition
value is "2,0 1 2 ,0 2 3 ,"

triangle neighbors

triangle neighbors diagram
//get triangle neighbors as a space delimited string of triangle indices
utilityFunctions = System.CreateDO("Clintons3D Package/Utility functions");
triangleIndex = 19;
neighborsS = utilityFunctions.GetTriangleNeighbors(firstSelected + "/Editable shape", triangleIndex);

result is "5 20 16", a space delimited list of neighbor indices at each edge of the triangle, -1 indicates no neighbor on that edge

the first value is the triangle index along the edge P1>P2, then P2>P3 and finally P3>P1

triangle edge visibility

meshdata = System.CreateDO("Space 3D Package/Mesh Data");
faceEdgeStream = System.CreateDO('Space 3D Package/Face Edges Stream Data');
meshdata = Node.Value(Node.FirstSelected() + "/Editable shape" ,"Mesh");
faceEdgeStream = meshdata.GetTrianglesStreamByName("Face Edges Stream Data");
triangleIndex = 19;
triangleEdgesS = faceEdgeStream.edges(triangleIndex);

result is the value of 1 to show that the first edge of the triangle is visible. if the second edge was also visible the value would be 1+2=3 and if the third edge was also visible it would be 1+2+4=7

truespace does not store polygon information. it stores triangle edge visibility to give the appearance and behavior of polygons

June 26, 2024

Script Crash Bug and Fix for GetSelectedFaceTriangle

This bug will crash tS if the command is run

Crash code

	var thesel = System.CreateDO("Space 3D Package/Selection Data");
	thesel = Node.Value(firstSel, "Selection");
	bobobo = thesel.GetSelectedFaceTriangle(0)

Plugin fix

    var thesel = System.CreateDO("Space 3D Package/Selection Data");
    thesel = Node.Value(firstSel, "Selection");
    util = System.CreateDO("Clintons3D Package/Utility functions");
    bobobo = util.GetSelectedFaceTriangle(0);
September 6, 2021

Mesh Commands

GetFacesUnities:

get a comma separated list of each triangle's polygon face index, supply the path to the "Shape" or "Editable shape" node

  • util = System.CreateDO("Clintons3D Package/Utility functions");
  • FacesUnities = util.GetFacesUnities(theMeshNode);

The order of the triangles is not guaranteed to be in order. It can be reorganized like so.

var faceToTriangleList = [];
for(var i=0;i<faceUnitiesArr.length;i++) {
    if(faceToTriangleList[faceUnitiesArr[i]])
        faceToTriangleList[faceUnitiesArr[i]].push(i);
    else
        faceToTriangleList[faceUnitiesArr[i]] = [i];
}

GetVertexTopology:

get a comma separated list of each triangle index that the given vertex is a part of,
supply the path to the "Shape" or "Editable shape" node and a vertex index

  • util = System.CreateDO("Clintons3D Package/Utility functions");
  • VertexTopology = util.GetVertexTopology(theMeshNode, index );

Vertex Colors

Requires special material setups to see the vertex colors. Vertex colors will disappear from a mesh if the mesh has geometry added or taken away. They will also disappear on shape changes if the mesh edit settings autotriangulation option is not set to "None".

FillVertexColor:

fill the supplied mesh's vertices with the desired color
supply the path to the "Shape" or "Editable shape" node and a color

  • util = System.CreateDO("Clintons3D Package/Utility functions");
  • util.FillVertexColor(theMeshNode, VertexColor, doFloatColor )
    VertexColor is a comma separated string in the form of "red, green, blue"
    doFloatColor is true if using floating point numbers (0 - 1) and false if using integers between 0 and 255

SetVertexColor:

set the color for a single mesh vertex
supply the path to the "Shape" or "Editable shape" node, a vertex index and a color

  • util = System.CreateDO("Clintons3D Package/Utility functions");
  • util.SetVertexColor(theMeshNode, vertexIndex, VertexColor, doFloatColor )
    vertexIndex is the index number of the vertex to paint
    VertexColor is a comma separated string in the form of "red, green, blue"
    doFloatColor is true if using floating point numbers (0 - 1) and false if using integers between 0 and 255

GetVertexColor:

get the color of a single vertex in a string of the form "red, green, blue"
supply the path to the "Shape" or "Editable shape" node and a vertex index

  • util = System.CreateDO("Clintons3D Package/Utility functions");
  • VertexColor = util.GetVertexColor(theMeshNode, vertexIndex, doFloatColor )
    vertexIndex is the index number of the vertex to paint
    doFloatColor is true will return floating point numbers (0 - 1) and if false will return integers between 0 and 255
    VertexColor will contain a comma separated string in the form of "red, green, blue"

CopyBitmapToVertices:

copy the colors from a bitmap texture onto the mesh vertices
supply the path to the bitmap node, the bitmap connector name, the "Shape" or "Editable shape" node, u and v offsets, wrap/clamp and the uv channel to use

  • util = System.CreateDO("Clintons3D Package/Utility functions");
  • CopyBitmapToVertices(BitmapNode, BitmapConn, MeshNode, uOffset, vOffset, wrap, uvChannel);
    BitmapNode is the node that has a bitmap connector
    BitmapConn is the name of the connector
    uOffset and vOffset will be added to the mesh uv values when looking up the bitmap color
    wrap will use repeating uv values when true and clamped values when false
    uvChannel is the uv channel used to read the bitmap colors, it is 1 or 2 and the uv channel must exist in the mesh

Vertex Paint Widget

used with the vertex painting script to apply colors to a mesh using a simple brush
This tool will continuously erase undo history, because running undo during or after using the widget will crash trueSpace.

trueSpace vertex colors do not have alpha value and are internally limited to the integer values between 0 and 255. So floating point values will really be a stepped value multiple of 1/255.

Jan 19, 2023
June 5, 2013