Property definitions

gamnit $ ObjDef :: defaultinit
# Geometry from a .obj file
class ObjDef
	# Vertex coordinates
	var vertex_points = new Array[Vec4]

	# Texture coordinates
	var texture_coords = new Array[Vec3]

	# Normals
	var normals = new Array[Vec3]

	# Surface parameters
	var params = new Array[Vec3]

	# Sub-objects
	var objects = new Array[ObjObj]

	# Relative paths to referenced material libraries
	fun material_libs: Set[String] do
		var libs = new Set[String]
		for obj in objects do
			for face in obj.faces do
				var lib = face.material_lib
				if lib != null then libs.add lib
			end
		end
		return libs
	end

	# Check the coherence of the model
	#
	# Returns `false` on error and prints details to stderr.
	#
	# This service can be useful for debugging, however it should not
	# be executed at each execution of a game.
	fun is_coherent: Bool
	do
		for obj in objects do
			for f in obj.faces do
				if f.vertices.length < 3 then return error("Face with less than 3 vertices")
			end

			for f in obj.faces do for v in f.vertices do
				var i = v.vertex_point_index
				if i < 1 then return error("Vertex point index < 1")
				if i > vertex_points.length then return error("Vertex point index > than length")

				var j = v.texture_coord_index
				if j != null then
					if j < 1 then return error("Texture coord index < 1")
					if j > texture_coords.length then return error("Texture coord index > than length")
				end

				j = v.normal_index
				if j != null then
					if j < 1 then return error("Normal index < 1")
					if j > normals.length then return error("Normal index > than length")
				end
			end
		end
		return true
	end

	# Service to print errors for `is_coherent`
	private fun error(msg: Text): Bool
	do
		print_error "ObjDef Error: {msg}"
		return false
	end
end
lib/gamnit/model_parsers/obj.nit:149,1--218,3