# Example 1: relative position
# create group
g = create_group('Group A')
# create two spheres at 10,0,0, but s2 is relative to group A
s1 = geom_sphere('Sphere 1', radius = 2, position = c(10,0,0))
s2 = geom_sphere('Sphere 2', radius = 2, position = c(10,0,0), group = g)
# set transform (rotation)
g$set_transform(matrix(c(
0,1,0,0,
1,0,0,0,
0,0,1,0,
0,0,0,1
), byrow = TRUE, ncol = 4))
# global position for s2 is 0,10,0
if( interactive() ) { threejs_brain(s1, s2) }
# Example 2: cache
if (FALSE) {
# download N27 brain
# Make sure you have N27 brain downloaded to `default_template_directory()`
# download_N27()
template_dir <- default_template_directory()
dat = freesurferformats::read.fs.surface(
file.path(template_dir, 'N27/surf/lh.pial')
)
vertex = dat$vertices[,1:3]
face = dat$faces[,1:3]
# 1. dynamically serialize
mesh = geom_freemesh('lh', vertex = vertex, face = face, layer = 1)
# 2. cache
# Create group, all geometries in this group are relatively positioned
tmp_file = tempfile()
mesh = geom_freemesh('Left Hemisphere cached', vertex = vertex,
face = face, cache_file = tmp_file)
}
Run the code above in your browser using DataLab