ベースグラフィックには、これらの表現を解析してプロットコマンドに変換するための、全体的な "プロットマス"インフラストラクチャがあります。 rgl
はそれをまったく使用しません。
私はplotmathコードが使用可能な外ベースのグラフィックスだとは思わないので、唯一の可能性は一種の醜い:?3Dシーンでビットマップとして
:
をここでスプライトでそれをやっての第二の試みです。
テキストは通常は表示されませんが、スプライトはシーン内でサイズが変更されます。 (おそらくそれは機能でありバグではありません)あなたが望むものを得るには、おそらくcex
設定でプレイする必要があります。
ラベルのように余白にテキストを置くことはできません。これを行うには、mtext3d
関数を見てください。
text
で複数の要素をサポートするようになりました。
それが今では、まだ多くのテストを受けていない
text3d
のように振る舞うべきadj
パラメータを持っています。
とにかく、始まりです。あなたが改善を考えるなら、投稿してください。
plotmath3d <- function(x, y = NULL, z = NULL,
text,
cex = par("cex"), adj = par("adj"),
startsize = 480,
...) {
xyz <- xyz.coords(x, y, z)
n <- length(xyz$x)
if (is.vector(text))
text <- rep(text, length.out = n)
cex <- rep(cex, length.out = n)
adj <- c(adj, 0.5, 0.5)[1:2]
save <- par3d(skipRedraw = TRUE)
on.exit(par3d(save))
for (i in seq_len(n)) {
# The first device is to measure it.
f <- tempfile(fileext = ".png")
png(f, bg = "transparent", width = startsize, height = startsize)
par(mar = c(0, 0, 0, 0), xaxs = "i", xaxt = "n",
yaxs = "i", yaxt = "n",
usr = c(0, 1, 0, 1))
plot.new()
if (is.vector(text))
thistext <- text[i]
else
thistext <- text
w <- strwidth(thistext, cex = 5, ...)*(2*abs(adj[1] - 0.5) + 1)
h <- strheight(thistext, cex = 5, ...)*(2*abs(adj[2] - 0.5) + 1)
dev.off()
# Now make a smaller bitmap and draw it
expand <- 1.5
size <- round(expand*startsize*max(w, h))
png(f, bg = "transparent", width = size, height = size)
par(mar = c(0, 0, 0, 0), xaxs = "i", xaxt = "n",
yaxs = "i", yaxt = "n",
usr = c(0, 1, 0, 1))
plot.new()
text(0.5, 0.5, thistext, adj = adj, cex = 5, ...)
dev.off()
with(xyz, sprites3d(x[i], y[i], z[i], texture = f, textype = "rgba",
col = "white", lit = FALSE, radius = cex[i]*size/100))
}
}
これは素晴らしいです!私が作った小さな改善の1つは、アンチエイリアス処理がテキストの周りにやや厄介な境界線/ハローを生成する可能性があるということです。 'png()'の呼び出しで 'antialias =" none "'を指定した方が幾分良いように見えます。 – dww
提案をありがとう。私は今日は本当に忙しいですが、すぐにアンチエイリアスの問題を見ていきます。 – user2554330