Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 23 additions & 13 deletions src/highlevel-api.jl
Original file line number Diff line number Diff line change
Expand Up @@ -282,11 +282,7 @@ GeometryTypes (Meshes and geometry primitives alike).
"""
function Shape(context::Context, meshlike; kw...)
m = uv_normal_mesh(meshlike; kw...)
v, n, fs, uv = decompose(Point3f, m), normals(m), faces(m), texturecoordinates(m)
if isnothing(n)
n = normals(v, fs)
end
return Shape(context, v, n, fs, uv)
return Shape(context, decompose(Point3f, m), decompose_normals(m), faces(m), decompose_uv(m))
end

#=
Expand All @@ -297,23 +293,37 @@ https://gist.github.com/SimonDanisch/475064ae102141554f65e926f3070630
=#
function Shape(context::Context, vertices, normals, faces, uvs)
@assert length(vertices) == length(normals)
@assert length(vertices) == length(uvs)
@assert isnothing(uvs) || (length(vertices) == length(uvs))

vraw = decompose(Point3f, vertices)
@assert eltype(vraw) == Point3f

nraw = decompose(Vec3f, normals)
uvraw = map(uv -> Vec2f(1 - uv[2], 1 - uv[1]), uvs)
@assert eltype(nraw) == Vec3f

if isnothing(uvs)
uvraw = C_NULL
uvlength = 0
uvbytesize = 0
else
uvraw = map(uv -> Vec2f(1 - uv[2], 1 - uv[1]), uvs)
@assert eltype(uvraw) == Vec2f
uvlength = length(uvs)
uvbytesize = sizeof(Vec2f)
end

f = decompose(TriangleFace{OffsetInteger{-1,rpr_int}}, faces)
iraw = collect(reinterpret(rpr_int, f))
facelens = fill(rpr_int(3), length(faces))

@assert eltype(vraw) == Point3f
@assert eltype(nraw) == Vec3f
@assert eltype(uvraw) == Vec2f

foreach(i -> checkbounds(vertices, i + 1), iraw)
rpr_mesh = rprContextCreateMesh(context, vraw, length(vertices), sizeof(Point3f), nraw, length(normals),
sizeof(Vec3f), uvraw, length(uvs), sizeof(Vec2f), iraw, sizeof(rpr_int),
iraw, sizeof(rpr_int), iraw, sizeof(rpr_int), facelens, length(faces))
rpr_mesh = rprContextCreateMesh(context,
vraw, length(vertices), sizeof(Point3f),
nraw, length(normals), sizeof(Vec3f),
uvraw, uvlength, uvbytesize,
iraw, sizeof(rpr_int), iraw, sizeof(rpr_int), iraw, sizeof(rpr_int), facelens, length(faces)
)

jl_references = (vraw, nraw, uvraw, iraw, facelens)
shape = Shape(rpr_mesh, context, jl_references)
Expand Down
Loading