-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathadd_shape.R
More file actions
50 lines (48 loc) · 1.76 KB
/
add_shape.R
File metadata and controls
50 lines (48 loc) · 1.76 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#'@title Add Shape
#'
#'@description Add shape to the scene.
#'
#'@param scene The scene to add the shape.
#'@param shape The mesh to add to the scene.
#'@return Scene with shape added.
#'@export
#'
#'@examplesIf interactive() || isTRUE(as.logical(Sys.getenv("IN_PKGDOWN")))
#'#Generate several spheres in the cornell box
#'scene = generate_cornell_mesh()
#'set.seed(1)
#'
#'for(i in 1:30) {
#' col = hsv(runif(1))
#' scene = add_shape(scene, sphere_mesh(position=runif(3)*400+155/2,
#' material=material_list(diffuse=col, type="phong",
#' ambient=col,ambient_intensity=0.2),
#' radius=30))
#'}
#'rasterize_scene(scene, light_info=directional_light(direction=c(0.1,0.6,-1)))
add_shape = function(scene, shape = NULL) {
if (is.null(shape)) {
return(scene)
}
if (is.null(scene)) {
return(shape)
}
new_hashes = c(attr(scene, "material_hashes"), attr(shape, "material_hashes"))
scene$shapes = vctrs::vec_c(scene$shapes, shape$shapes)
scene$vertices = vctrs::vec_c(scene$vertices, shape$vertices)
scene$normals = vctrs::vec_c(scene$normals, shape$normals)
scene$texcoords = vctrs::vec_c(scene$texcoords, shape$texcoords)
scene$materials = vctrs::vec_c(scene$materials, shape$materials)
# new_scene = ray_mesh(scene)
new_scene = (scene)
attr(new_scene, "material_hashes") = new_hashes
if (!is.null(attr(shape, "cornell")) || !is.null(attr(scene, "cornell"))) {
attr(new_scene, "cornell") = TRUE
if (!is.null(attr(shape, "cornell"))) {
attr(new_scene, "cornell_light") = attr(shape, "cornell_light")
} else {
attr(new_scene, "cornell_light") = attr(scene, "cornell_light")
}
}
return(new_scene)
}