@@ -282,11 +282,7 @@ GeometryTypes (Meshes and geometry primitives alike).
282282"""
283283function Shape (context:: Context , meshlike; kw... )
284284 m = uv_normal_mesh (meshlike; kw... )
285- v, n, fs, uv = decompose (Point3f, m), normals (m), faces (m), texturecoordinates (m)
286- if isnothing (n)
287- n = normals (v, fs)
288- end
289- return Shape (context, v, n, fs, uv)
285+ return Shape (context, decompose (Point3f, m), decompose_normals (m), faces (m), decompose_uv (m))
290286end
291287
292288#=
@@ -297,23 +293,37 @@ https://gist.github.com/SimonDanisch/475064ae102141554f65e926f3070630
297293=#
298294function Shape (context:: Context , vertices, normals, faces, uvs)
299295 @assert length (vertices) == length (normals)
300- @assert length (vertices) == length (uvs)
296+ @assert isnothing (uvs) || ( length (vertices) == length (uvs) )
301297
302298 vraw = decompose (Point3f, vertices)
299+ @assert eltype (vraw) == Point3f
300+
303301 nraw = decompose (Vec3f, normals)
304- uvraw = map (uv -> Vec2f (1 - uv[2 ], 1 - uv[1 ]), uvs)
302+ @assert eltype (nraw) == Vec3f
303+
304+ if isnothing (uvs)
305+ uvraw = C_NULL
306+ uvlength = 0
307+ uvbytesize = 0
308+ else
309+ uvraw = map (uv -> Vec2f (1 - uv[2 ], 1 - uv[1 ]), uvs)
310+ @assert eltype (uvraw) == Vec2f
311+ uvlength = length (uvs)
312+ uvbytesize = sizeof (Vec2f)
313+ end
314+
305315 f = decompose (TriangleFace{OffsetInteger{- 1 ,rpr_int}}, faces)
306316 iraw = collect (reinterpret (rpr_int, f))
307317 facelens = fill (rpr_int (3 ), length (faces))
308318
309- @assert eltype (vraw) == Point3f
310- @assert eltype (nraw) == Vec3f
311- @assert eltype (uvraw) == Vec2f
312319
313320 foreach (i -> checkbounds (vertices, i + 1 ), iraw)
314- rpr_mesh = rprContextCreateMesh (context, vraw, length (vertices), sizeof (Point3f), nraw, length (normals),
315- sizeof (Vec3f), uvraw, length (uvs), sizeof (Vec2f), iraw, sizeof (rpr_int),
316- iraw, sizeof (rpr_int), iraw, sizeof (rpr_int), facelens, length (faces))
321+ rpr_mesh = rprContextCreateMesh (context,
322+ vraw, length (vertices), sizeof (Point3f),
323+ nraw, length (normals), sizeof (Vec3f),
324+ uvraw, uvlength, uvbytesize,
325+ iraw, sizeof (rpr_int), iraw, sizeof (rpr_int), iraw, sizeof (rpr_int), facelens, length (faces)
326+ )
317327
318328 jl_references = (vraw, nraw, uvraw, iraw, facelens)
319329 shape = Shape (rpr_mesh, context, jl_references)
0 commit comments