tylermorganwall / rayvertex

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

Regression in rendering textured meshes (imported via Wavefront OBJ files) #9

Closed trevorld closed 1 year ago

trevorld commented 1 year ago

In {rayvertex} v0.4.11 I'm observing a regression in rendering a textured mesh imported via Wavefront OBJ file:

# generate Wavefront OBJ file with {piecepackr}
library("piecepackr")
envir <- game_systems("sans3d", round=TRUE)
f <- save_piece_obj(piece_side = "tile_back", x = 1.5, y = 1.5, suit = 1, rank = 1,
                    cfg = envir$piecepack)

# import/render Wavefront OBJ file in {rayvertex}
library("rayvertex")
tile <- obj_mesh(f$obj)
table <- sphere_mesh(c(0, 0, -1e3), radius=1e3, material = material_list(diffuse="grey40"))
scene <- add_shape(table, tile)
rasterize_scene(scene, filename = "rayvertex_bug.png",
                lookat = c(4.5, 4, 0), lookfrom=c(4.5, -16, 20),
                light_info = directional_light(c(5, -7, 7), intensity = 2.5))

rayvertex_bug

In contrast things look fine with the latest version of {rayrender} (also look fine with {rgl} via {readobj} or an earlier version of {rayvertex} like v0.3.3)

# contrast with {rayrender}
library("rayrender")
tile <- obj_model(f$obj, load_textures = TRUE, load_material = TRUE)
table <- sphere(z=-1e3, radius=1e3, material=diffuse(color="grey40")) |>
         add_object(sphere(x=5,y=-4, z=30, material=light(intensity=420)))
scene <- add_object(table, tile)
render_scene(scene, filename = "rayrender.png",
             lookat = c(5, 5, 0), lookfrom = c(5, -7, 25),
             width = 500, height = 500, samples=200, clamp_value=8)

rayrender

tylermorganwall commented 1 year ago

THere's a couple unrelated bugs in the scene construction methods that I've mostly chased down, but I'm still working on why this regression appeared.

trevorld commented 1 year ago

git bisect indicates the regression was introduced in https://github.com/tylermorganwall/rayvertex/commit/cc263f7eb59fdc900dcdf20f816df6431763ab36

I wildly speculate that maybe there was an upstream regression in tinyobjloader? Assuming {rayrender} is using an older version of tinyobjloader that would explain why it still works fine.

tylermorganwall commented 1 year ago

Should be fixed in the latest commit. This issue simply stemming from not including the DEFINE that turned on the new (fixed) tinyobjloader earcuting algorithm in the last update. All works fine on my end now--check it out on yours.

trevorld commented 1 year ago

Looks good on my end!