faces
in a flat Array[Float]
# Compute the texture coordinates of `faces` in a flat `Array[Float]`
fun texture_coords(faces: Array[ObjFace]): Array[Float] do
var obj_def = obj_def
var coords = new Array[Float]
for face in faces do
# 1st triangle
var count = 0
for e in face.vertices do
var i = e.texture_coord_index
if i == null then
coords.add 0.0
coords.add 0.0
else
var tc = obj_def.texture_coords[i-1]
coords.add tc.u
coords.add tc.v
end
if count == 2 then break
count += 1
end
# If square, 2nd triangle
#
# This may not support all vertices ordering.
if face.vertices.length > 3 then
for e in [face.vertices[0], face.vertices[2], face.vertices[3]] do
var i = e.texture_coord_index
if i == null then
coords.add 0.0
coords.add 0.0
else
var tc = obj_def.texture_coords[i-1]
coords.add tc.u
coords.add tc.v
end
end
end
end
return coords
end
lib/gamnit/depth/more_models.nit:406,2--448,4