(Note: I use rgl version 0.96.0
. If my memory is correct, wire3d()
and dot3d()
rules have been changed)
It isn't a good idea to give a color informatin when you make a class mesh3d
object, because shade3d()
, wire3d()
and dot3d()
use it in the different ways. It would be better to give plot-function a color information when you draw a object.
for example;
A <- matrix(c( 1, 0, 1, 0, 2, 0, 1, 0, 2), 3, 3)
c3d2 <- cube3d()
c3d_trans2 <- cube3d(A)
colv <- rep(2:7, each=4)
shade3d(c3d2, col = colv, alpha = 0.8)
wire3d(c3d2); dot3d(c3d2, size = 5)
shade3d(c3d_trans2, col = colv, alpha=0.5)
dot3d(c3d_trans2, size = 5)
[ the details related to colors and mesh3d.obj ]
Most important rule is that a vertex consumes a color whenever it is used (but it is a bit complex, please see below exampe). I call below matrix ib and mesh3d.obj$vb
's col number index .
cube3d()$ib
# [,1] [,2] [,3] [,4] [,5] [,6]
# [1,] 1 3 2 1 1 5
# [2,] 3 7 4 5 2 6
# [3,] 4 8 8 7 6 8
# [4,] 2 4 6 3 5 7
shade3d() rule (it's easy)
plot3d(cube3d(scaleMatrix(1.2,1.2,1.2)), alpha=0)
text3d(t(cube3d()$vb[1:3,]*1.05), texts=1:8) # indices
shade3d(cube3d(), col=c(rep(2,4), rep(3,4), rep(4,4), rep(5,4), rep(6,4), rep(7,4)), alpha=0.8)
# ib[1:4, 1] [1:4, 2] [1:4, 3] [1:4, 4] [1:4, 5] [1:4, 6]
# index 1,3,4,2 3,7,8,4 2,4,8,6, ...

wire3d rule (complex and terrible..; edited)
text3d(t(cube3d()$vb[1:3,]*1.05), texts=1:8, font=2) # indices
wire3d(cube3d(), col=c(rep(2,6), rep(3,6), rep(4,6), rep(5,6), rep(6,6), rep(7,6)))
# I gave each color 6 times.
index 1 3 4 2 1
ib$[1,1] - [2,1] - [3,1] - [4,1] - [1,1] - NA
col 2 2 2 2 2 2 # Why NA uses a color!!??
index 3 7 8 4 (skipped) 3 # the line already has been drawn, skipped.
ib$[1,2] - [2,2] - [3,2] - [4,2] - [1,2] - NA;
col 3 3 3 3 (skipped) 3 3
index 2 (sk) 4 (sk) 8 6 2
ib$[1,3] - [2,3] - [3,3] - [4,3] - [1,3] - NA;
col 4 (sk) 4 (sk) 4 4 4 4, and so on.
In one ib
's col
, one vertex have only one color (e.g., at ib[,1]
, Index3's color information is used both 1-3 and 3-4. When the line already has been drawn, it is skipped. It is too difficult (some patterns is impossible) to draw lines in different colors using wire3d()
. If you want to do, it would be better to use lines3d()
or segments3d()

dot3d rule
plot3d(cube3d(scaleMatrix(1.2,1.2,1.2)), alpha=0)
text3d(t(cube3d()$vb[1:3,]*1.05), texts=1:8) # indices
dot3d(cube3d(), col=1:8, size=8)
unique(c(cube3d()$ib))
# [1] 1 3 4 2 7 8 6 5
if you give col=1:8
, NOT index2 but index3 becomes col = 2
(red
).
So, col = c("col1", "col2", ..., "col8")[unique(c(object$ib))]
means index1 is col1
, index2 is col2
.
