我正在学习实例缓冲区的几何形状,并尝试扩展LambertMaterial着色器以旋转每个实例。
library(ggplot2)
library(data.table)
library(ggrepel)
year <- 2008:2018
cvd <- rnorm(11, 15, 1)
alz <- rnorm(11, 10, 0.5)
ui <- rnorm(11, 10, .5)
stro <- rnorm(11, 6, 3)
df <- data.frame("Year" = rep(year, 4), "Number of Deaths" = c(cvd, alz, ui, stro), "Cause of Death" = c(
rep("Cardiovascular Disease", 11),
rep("Alzheimers Disease", 11),
rep("Unidentified Cause of Death", 11),
rep("Stroke", 11)
))
#Sorry, I think in terms of data.table.
dt <- data.table(df)
dt2 <- dt[Year==2018]
ggplot(data=dt, aes(x=Year, y=Number.of.Deaths, group=Cause.of.Death, color = Cause.of.Death)) +
geom_line() +
geom_text_repel(data=dt2,
aes(x=Year,y=Number.of.Deaths,label=Cause.of.Death),
direction = "y",
nudge_x = .5,
hjust=0,
size=3,
segment.size = .2,
segment.colour = "black")+
#xlim(c(2008,2020))+
scale_x_continuous(breaks=2008:2018,limits = c(2008,2020))+
theme_minimal()+
theme(legend.position = "none")
在浏览google之后,我使用了类似的方法,但是根本没有旋转它们。无论我输入什么数字,它们都位于相同的位置。
不知道这是否是正确的转换。 我应该如何适当地扩展着色器以添加旋转?
答案 0 :(得分:1)
使用THREE.InstancedMesh时,可以对所有内置材料使用实例渲染,并分别转换每个实例。查看下面的示例演示此方法:
https://threejs.org/examples/webgl_instancing_dynamic
想法是使用InstancedMesh.setMatrixAt()以便为动画循环中的每个实例设置局部转换。
如果由于某些原因仍要使用InstancedBufferGeometry
,则可以将以下示例用作代码模板:
https://threejs.org/examples/webgl_buffergeometry_instancing_lambert
它显示了如何使用实例渲染增强MeshLambertMaterial
。
three.js R113