Services to parse models from a text description

Introduced classes

class Vec3

gamnit :: Vec3

Vector of 3 values, either x, y, z, u, v, z or r, g, b
class Vec4

gamnit :: Vec4

Vector of 4 values, either x, y, z, w, u, v, z, w or r, g, b, a

Redefined classes

redef class StringProcessor

gamnit :: model_parser_base $ StringProcessor

Basic facilities for common parser operations on String sources

All class definitions

redef class StringProcessor

gamnit :: model_parser_base $ StringProcessor

Basic facilities for common parser operations on String sources
class Vec3

gamnit $ Vec3

Vector of 3 values, either x, y, z, u, v, z or r, g, b
class Vec4

gamnit $ Vec4

Vector of 4 values, either x, y, z, w, u, v, z, w or r, g, b, a
package_diagram gamnit::model_parser_base model_parser_base parser_base parser_base gamnit::model_parser_base->parser_base serialization serialization parser_base->serialization ...serialization ... ...serialization->serialization gamnit::obj obj gamnit::obj->gamnit::model_parser_base gamnit::mtl mtl gamnit::mtl->gamnit::model_parser_base gamnit::more_models more_models gamnit::more_models->gamnit::obj gamnit::more_models->gamnit::mtl gamnit::more_models... ... gamnit::more_models...->gamnit::more_models

Ancestors

module abstract_collection

core :: abstract_collection

Abstract collection classes and services.
module abstract_text

core :: abstract_text

Abstract class for manipulation of sequences of characters
module array

core :: array

This module introduces the standard array structure.
module bitset

core :: bitset

Services to handle BitSet
module bytes

core :: bytes

Services for byte streams and arrays
module caching

serialization :: caching

Services for caching serialization engines
module circular_array

core :: circular_array

Efficient data structure to access both end of the sequence.
module codec_base

core :: codec_base

Base for codecs to use with streams
module codecs

core :: codecs

Group module for all codec-related manipulations
module collection

core :: collection

This module define several collection classes.
module core

core :: core

Standard classes and methods used by default by Nit programs and libraries.
module engine_tools

serialization :: engine_tools

Advanced services for serialization engines
module environ

core :: environ

Access to the environment variables of the process
module error

core :: error

Standard error-management infrastructure.
module exec

core :: exec

Invocation and management of operating system sub-processes.
module file

core :: file

File manipulations (create, read, write, etc.)
module fixed_ints

core :: fixed_ints

Basic integers of fixed-precision
module fixed_ints_text

core :: fixed_ints_text

Text services to complement fixed_ints
module flat

core :: flat

All the array-based text representations
module gc

core :: gc

Access to the Nit internal garbage collection mechanism
module hash_collection

core :: hash_collection

Introduce HashMap and HashSet.
module inspect

serialization :: inspect

Refine Serializable::inspect to show more useful information
module iso8859_1

core :: iso8859_1

Codec for ISO8859-1 I/O
module kernel

core :: kernel

Most basic classes and methods.
module list

core :: list

This module handle double linked lists
module math

core :: math

Mathematical operations
module meta

meta :: meta

Simple user-defined meta-level to manipulate types of instances as object.
module native

core :: native

Native structures for text and bytes
module numeric

core :: numeric

Advanced services for Numeric types
module protocol

core :: protocol

module queue

core :: queue

Queuing data structures and wrappers
module range

core :: range

Module for range of discrete objects.
module re

core :: re

Regular expression support for all services based on Pattern
module ropes

core :: ropes

Tree-based representation of a String.
module serialization

serialization :: serialization

General serialization services
module serialization_core

serialization :: serialization_core

Abstract services to serialize Nit objects to different formats
module sorter

core :: sorter

This module contains classes used to compare things and sorts arrays.
module stream

core :: stream

Input and output streams of characters
module text

core :: text

All the classes and methods related to the manipulation of text entities
module time

core :: time

Management of time and dates
module union_find

core :: union_find

union–find algorithm using an efficient disjoint-set data structure
module utf8

core :: utf8

Codec for UTF-8 I/O

Parents

module parser_base

parser_base :: parser_base

Simple base for hand-made parsers of all kinds

Children

module mtl

gamnit :: mtl

Services to parse .mtl material files
module obj

gamnit :: obj

Services to parse .obj geometry files

Descendants

module a_star-m

a_star-m

module cardboard

gamnit :: cardboard

Update the orientation of world_camera at each frame using the head position given by android::cardboard
module depth

gamnit :: depth

Framework for 3D games in Nit
module more_models

gamnit :: more_models

Services to load models from the assets folder
module stereoscopic_view

gamnit :: stereoscopic_view

Refine EulerCamera and App::frame_core_draw to get a stereoscopic view
module vr

gamnit :: vr

VR support for gamnit depth, for Android only
# Services to parse models from a text description
module model_parser_base

import parser_base

# Vector of 3 values, either `x, y, z`, `u, v, z` or `r, g, b`
class Vec3

	# X value
	var x = 0.0 is writable

	# Y value
	var y = 0.0 is writable

	# Z value
	var z = 0.0 is writable

	# U value (redirection as `x`)
	fun u: Float do return x

	# Set U value (redirection for `x=`)
	fun u=(value: Float) do x = value

	# V value (redirection as `y`)
	fun v: Float do return y

	# Set V value (redirection for `y=`)
	fun v=(value: Float) do y = value

	# R value
	fun r: Float do return x

	# Set R value (redirection for `x=`)
	fun r=(value: Float) do x = value

	# G value
	fun g: Float do return y

	# Set G value (redirection for `y=`)
	fun g=(value: Float) do y = value

	# B value
	fun b: Float do return z

	# Set B value (redirection for `z=`)
	fun b=(value: Float) do z = value

	# Return all values into a new `Array[Float]`
	fun to_a: Array[Float] do return [x, y, z]

	redef fun to_s do return "<{class_name} {x} {y} {z}>"
end

# Vector of 4 values, either `x, y, z, w`, `u, v, z, w` or `r, g, b, a`
class Vec4
	super Vec3

	# W value
	var w = 1.0 is writable

	# A value (redirection to `z`)
	fun a: Float do return z

	# Set A value (redirection for `z=`)
	fun a=(value: Float) do z = value

	# Return all values into a new `Array[Float]`
	redef fun to_a do return [x, y, z, w]

	redef fun to_s do return "<{class_name} {x} {y} {z} {w}>"
end

redef class StringProcessor
	# Read a single token after skipping preceding whitespaces
	#
	# Returns an empty string when at `eof`
	protected fun read_token: String
	do
		while not eof and src[pos].is_whitespace and src[pos] != '\n' do
			pos += 1
		end

		var start = pos
		ignore_until_whitespace_or_comment
		var ending = pos
		var str = src.substring(start, ending-start)
		return str
	end

	# Read 3 or 4 numbers and return them as a `Vec4`
	#
	# If there is no fourth value, `Vec4::w` is set to 1.0.
	protected fun read_vec4: Vec4
	do
		var vec = new Vec4
		vec.x = read_number
		vec.y = read_number
		vec.z = read_number

		var wstr = read_token
		if wstr.length > 0 then
			vec.w = if wstr.is_numeric then wstr.to_f else 0.0
		else
			vec.w = 1.0
		end

		return vec
	end

	# Read 2 or 3 numbers and return them as a `Vec3`
	#
	# If there is no third value, `Vec3::z` is set to 0.0.
	protected fun read_vec3: Vec3
	do
		var vec = new Vec3
		vec.x = read_number
		vec.y = read_number # Make optional

		var wstr = read_token
		if wstr.length > 0 then
			vec.z = if wstr.is_numeric then wstr.to_f else 0.0
		else
			vec.z = 0.0
		end

		return vec
	end

	# Advance `pos` until a whitespace or `#` is encountered
	protected fun ignore_until_whitespace_or_comment: Int
	do
		while src.length > pos and not src[pos].is_whitespace and src[pos] != '#' do
			pos += 1
		end
		return pos
	end

	# Read a token and parse it as a `Float`
	protected fun read_number: Float
	do
		var str = read_token
		return if str.is_numeric then str.to_f else 0.0
	end

	# Advance `pos` until the next end of line or a `#`
	protected fun read_until_eol_or_comment: String
	do
		ignore_whitespaces
		var start = pos
		while not eof and src[pos] != '#' and src[pos] != '\n' do
			pos += 1
		end
		var ending = pos
		var str = src.substring(start, ending-start)
		return str.trim
	end

	# Advance `pos` to skip the next end of line
	protected fun skip_eol
	do
		while not eof do
			var c = src.chars[pos]
			pos += 1
			if c == '\n' then break
		end
	end
end
lib/gamnit/model_parsers/model_parser_base.nit:15,1--181,3