tylermorganwall / rayvertex

3D Software Rasterizer for R
https://www.rayvertex.com
65 stars 2 forks source link

add_shape(NULL, NULL) now throws ERROR #11

Closed trevorld closed 1 year ago

trevorld commented 1 year ago

Unlike earlier versions of {rayvertex} where add_shape(NULL, NULL) returned a NULL I now observe that it throws an ERROR:

library("rayvertex")
scene <- add_shape(NULL, NULL)
Error in class(scene) <- c("ray_mesh", "list") : 
  attempt to set an attribute on NULL

In contrast scene_from_list() does seem to handle this case:

scene_from_list(list(NULL, NULL))
$shapes
list()

$materials
list()

$vertices
$vertices[[1]]
NULL

$texcoords
$texcoords[[1]]
NULL

$normals
$normals[[1]]
NULL

$material_hashes
character(0)

attr(,"class")
[1] "ray_mesh" "list"    

Is there something else I should be using for a "null" mesh other than NULL (i.e. a mesh too small or transparent that we know won't be visible and shouldn't be drawn as sometimes happens in animation transitions when things are appearing or disappearing)?

tylermorganwall commented 1 year ago

There was no behavior to deal with NULLs before, but try the latest commit: it should handle NULLs by returning the non-NULL object (or by returning NULL if both are NULL.

trevorld commented 1 year ago

There was no behavior to deal with NULLs before

In the previous CRAN release v0.3.3 (6930a8855e1887817091fb7a47021c418f20aa2f) add_shape(NULL, NULL) would return NULL but this very well could have been an accidental unplanned behavior.

try the latest commit: it should handle NULLs by returning the non-NULL object (or by returning NULL if both are NULL

I'm observing that add_shape(NULL, NULL) now returns NULL as it did in v0.3.3 but that scene_from_list(list(NULL, NULL)) now throws an error (which it didn't in the last CRAN release v0.4.11):

scene_from_list(list(NULL, NULL))
Error in do.call(rbind, old_scene$vertices) : 
  second argument must be a list
trevorld commented 1 year ago

One possible solution may be to filter the scene_list in scene_from_list() using Filter(Negate(is.null), scene_list)