tylermorganwall / rayvertex

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

'scene_from_list()' bug #10

Closed trevorld closed 2 years ago

trevorld commented 2 years ago

I've found a case with {rayvertex} v0.4.11 where scene_from_list() throws an ERROR when building a scene from a list of "ray_mesh" objects:

library("piecepackr")
library("ppgames") # remotes::install_github("piecepackr/ppgames")
library("rayvertex", warn.conflicts = FALSE) # masks `rayrender::r_obj`
df <- ppgames::df_international_chess()
envir <- game_systems("dejavu3d", round=TRUE, pawn="joystick")
l <- pmap_piece(df, piece_mesh, trans=op_transform, envir = envir, scale = 0.98, res = 150, as_top="pawn_face")
scene <- scene_from_list(l)
Error in scene_list[[i]]$material_hashes[[j]] : subscript out of bounds

Note though one can still build a scene from this list of "ray_mesh" objects by using add_shape() perhaps via Reduce():

scene <- Reduce(add_shape, l)

Note every element of the list is a "ray_mesh"

> vapply(l, function(x) inherits(x, "ray_mesh"), logical(1))
piece.16 piece.15 piece.14 piece.13 piece.12 piece.11 piece.10  piece.9 
    TRUE     TRUE     TRUE     TRUE     TRUE     TRUE     TRUE     TRUE 
 piece.8  piece.7  piece.6  piece.5  piece.4  piece.3  piece.2  piece.1 
    TRUE     TRUE     TRUE     TRUE     TRUE     TRUE     TRUE     TRUE 
piece.38 piece.47 piece.45 piece.37 piece.24 piece.23 piece.22 piece.21 
    TRUE     TRUE     TRUE     TRUE     TRUE     TRUE     TRUE     TRUE 
piece.20 piece.19 piece.18 piece.17 piece.32 piece.31 piece.30 piece.29 
    TRUE     TRUE     TRUE     TRUE     TRUE     TRUE     TRUE     TRUE 
piece.28 piece.27 piece.26 piece.25 piece.39 piece.48 piece.46 piece.40 
    TRUE     TRUE     TRUE     TRUE     TRUE     TRUE     TRUE     TRUE 
piece.34 piece.33 piece.35 piece.36 piece.42 piece.41 piece.43 piece.44 
    TRUE     TRUE     TRUE     TRUE     TRUE     TRUE     TRUE     TRUE 
tylermorganwall commented 2 years ago

Should be fixed in the latest commit—check it out and report back if not. Re-organized the material structure in ray_mesh objects so materials should be consistent regardless of how the scene was built now.

trevorld commented 2 years ago

Looks good on my end!