int createLine ( int pt0; int pt1 )
{
int pr = addprim ( geoself ( ), "polyline" );
addvertex ( geoself ( ), pr, pt0 );
addvertex ( geoself ( ), pr, pt1 );
return pr;
}
int createPolygon ( int pt0; int pt1; int pt2 )
{
int pr = addprim ( geoself ( ), "poly" );
addvertex ( geoself ( ), pr, pt0 );
addvertex ( geoself ( ), pr, pt1 );
addvertex ( geoself ( ), pr, pt2 );
return pr;
}
int createPolygon ( int pt0; int pt1; int pt2; int pt3 )
{
int pr = addprim ( geoself ( ), "poly" );
addvertex ( geoself ( ), pr, pt0 );
addvertex ( geoself ( ), pr, pt1 );
addvertex ( geoself ( ), pr, pt2 );
addvertex ( geoself ( ), pr, pt3 );
return pr;
}
void createAxisGeometry ( float s; vector n; vector t; vector c; int color; int arrow; int scale )
{
vector p [ ];
push ( p, 0 );
push ( p, set ( s, 0, 0 ) );
if ( arrow )
{
float x = scale ? 0.75 * s : s - 0.25;
float y = 0.03 * ( scale ? s : 1 );
push ( p, set ( x, y, y ) );
push ( p, set ( x, y, -y ) );
push ( p, set ( x, -y, y ) );
push ( p, set ( x, -y, -y ) );
}
for ( int i = 0; i < arraylength ( p ); ++i )
{
matrix3 xform = dihedral ( { 1, 0, 0 }, { 0, 0, -1 } ) * lookat ( 0, n );
p [ i ] = p [ i ] * xform + t;
}
int pt [ ];
for ( int i = 0; i < arraylength ( p ); ++i )
pt [ i ] = addpoint ( geoself ( ), p [ i ] );
if ( color )
{
for ( int i = 0; i < arraylength ( pt ); ++i )
setattrib ( geoself ( ), "point", "Cd", pt [ i ], -1, c, "set" );
}
createLine ( pt [ 0 ], pt [ 1 ] );
if ( arrow )
{
createPolygon ( pt [ 1 ], pt [ 2 ], pt [ 3 ] );
createPolygon ( pt [ 1 ], pt [ 3 ], pt [ 5 ] );
createPolygon ( pt [ 1 ], pt [ 5 ], pt [ 4 ] );
createPolygon ( pt [ 1 ], pt [ 4 ], pt [ 2 ] );
createPolygon ( pt [ 2 ], pt [ 4 ], pt [ 5 ], pt [ 3 ] );
}
}
createAxisGeometry ( ch("s"), chv("n"), chv("t"), chv("c"), chi("color"), chi("arrow"), chi("scale") );
You need to create Cd point attribute before the AttribWrangle as AFAIK there is no other way to do this in code for points since setpointattrib doesn't create a new attribute and this code runs in