ObjectFromTube:
PROC [tube: Tube, matrix: Matrix ←
NIL]
RETURNS [
vertices: REF VertexSequence,
shades: REF ShadingSequence,
textures: TripleSequence,
polygons: REF NatTable
] ~ {
Point: PointProc ~ {
vertices[n].x ← position.x;
vertices[n].y ← position.y;
vertices[n].z ← position.z;
shades[n].xn ← normal.x;
shades[n].yn ← normal.y;
shades[n].zn ← normal.z;
textures[n] ← [u, v, 0.0];
n ← n+1;
};
Poly: PolyProc ~ {
polygons[id] ← NEW[NatSequence[3]];
polygons[id].length ← 3;
polygons[id][0] ← p0;
polygons[id][1] ← p1;
polygons[id][2] ← p2;
};
n: INTEGER ← 0;
nPolys: INTEGER ← TubeMisc.NPolys[tube];
nVertices: INTEGER ← TubeMisc.NPoints[tube];
vertices ← NEW[VertexSequence[nVertices]];
shades ← NEW[ShadingSequence[nVertices]];
textures ← NEW[TripleSequenceRep[nVertices]];
polygons ← NEW[NatTable[nPolys]];
polygons.length ← nPolys;
FOR n:
NAT
IN [0..nVertices)
DO
vertices[n] ← NEW[Vertex];
shades[n] ← NEW[ShadingValue];
ENDLOOP;
[] ← TubeMisc.Points[tube, Point, matrix];
[] ← TubeMisc.Polys[tube, Poly];
RETURN[vertices, shades, textures, polygons];
};
AddTube:
PUBLIC
PROC [
tube: Tube, context3d: Context3d, renderStyle: RenderStyle ← faceted, matrix: Matrix ← NIL]
~ {
vertices: REF VertexSequence;
shades: REF ShadingSequence;
textures: TripleSequence;
polygons: REF NatTable;
[vertices, shades, textures, polygons] ← ObjectFromTube[tube, matrix];
Render3d.AddObject[
context3d, polygons, vertices, shades, textures, , tube.name, renderStyle, TRUE];
};