light3js: Add a light source to a data3js object

View source: R/3JSobjects.R

light3jsR Documentation

Add a light source to a data3js object

Description

When no light source is provided the 3d scene is lit from the top left, this function allows you to specify different numbers of light sources at different positions - not yet fully implemented.

Usage

light3js(
  data3js,
  position = NULL,
  intensity = 1,
  type = "directional",
  col = "white"
)

Arguments

data3js

The data3js object

position

Position of the light source in x, y, z coords, see details.

intensity

Light intensity

type

Type of light, either "point", "directional" or "ambient", see details.

col

Light color

Details

If light position is "directional", the default light will appear to come from the direction of the position argument but from an infinite distance. If "point" the light will appear to emanate from that position in coordinate space light a light bulb. If "ambient" any position argument is ignored and the light will light all aspects of the scene evenly from no particular position.

Value

Returns an updated data3js object

See Also

Other plot components: arrows3js(), axis3js(), box3js(), grid3js(), legend3js(), lines3js(), mtext3js(), points3js(), segments3js(), shape3js(), sphere3js(), surface3js(), text3js(), triangle3js()

Examples

# Set up a plot
p0 <- plot3js(
  x = 1:4,
  y = c(2,1,3,4),
  z = c(3,2,4,1),
  xlim = c(0, 5),
  ylim = c(0, 5),
  zlim = c(0, 5),
  size = 20,
  col = c("white", "blue", "red", "green"),
  grid_col = "grey40",
  background = "black"
)

# Light scene intensely from above
p <- light3js(
  p0,
  position = c(0, 1, 0)
)
r3js(p, zoom = 2)

# Light scene positionally from the middle of the plot
p <- light3js(
  p0,
  position = c(2.5, 2.5, 2.5),
  type = "point"
)
r3js(p, zoom = 2)

# Light scene ambiently with a yellow light
p <- light3js(
  p0,
  intensity = 0.3,
  type = "ambient",
  col = "yellow"
)
r3js(p, zoom = 2)


r3js documentation built on March 31, 2023, 7:23 p.m.