I stole this code from here and just tweaked it to suit your purposes. Ill call the triangles T and _T. Each triangle is made of three coordinates, (x1,y1,z1), (x2,y2,z2) and (x3,y3,z3), and every triange has a number c corresponding to its color. This example plots only two triangles. In the mymesh structure the triangles are stored as (x1,_x1,y1,_y1,z1,_z1,...,z3,_z3,c,_c)
. The dimension is 2x10 because there are two triangles and a triangle is represented by 10 numbers, nine for coordinates and one for the color.
mymesh <- structure(c(0,0,0,0,0,0,1,0,0,1,0,0,1,1,1,1,0,0,100,200),
.Dim = c(2, 10),
.Dimnames = list( NULL, c("x1", "y1", "z1",
"x2", "y2", "z2",
"x3", "y3", "z3",
"value")
)
)
library(rgl)
rgl.open()
i <- 1
vertices <- c(mymesh[i,1:3],1,mymesh[i,4:6],1,mymesh[i,7:9],1)
indices <- c( 1, 2, 3)
shade3d( tmesh3d(vertices,indices) , col=1)
bg3d(color = "white")
for(i in 2:2){
vertices <- c(mymesh[i,1:3],1,mymesh[i,4:6],1,mymesh[i,7:9],1)
indices <- c( 1, 2, 3)
shade3d( tmesh3d(vertices,indices) , col= i)
}
The output is

There's probably a better way. I don't really know R, and the coordinates seem to be stored in a stupid way because R uses column major order. You can change it so that you enter the coordinates in a more natural way i.e. (x1,y1,z1,x2,..._y3,_z3,_c)
and then pass the transpose of this to the structure.