Mesh with all geometry data

May be created via Plane, Cube or UVSphere, or loaded from the assets folder indirectly with a Model.

import gamnit::depth

var plane = new Plane
var cube = new Cube
var sphere = new UVSphere(1.0, 32, 16)

Introduced properties

fun center: Point3d[Float]

gamnit :: Mesh :: center

Center coordinates of all the vertices
fun center=(center: Point3d[Float])

gamnit :: Mesh :: center=

Center coordinates of all the vertices
fun dimensions: Point3d[Float]

gamnit :: Mesh :: dimensions

Dimensions of the bounding box containing all vertices
fun dimensions=(dimensions: Point3d[Float])

gamnit :: Mesh :: dimensions=

Dimensions of the bounding box containing all vertices
fun draw_mode: GLDrawMode

gamnit :: Mesh :: draw_mode

GLDrawMode used to display this mesh, defaults to gl_TRIANGLES
fun indices: Array[Int]

gamnit :: Mesh :: indices

Indices to draw triangles with glDrawElements
fun indices=(indices: Array[Int])

gamnit :: Mesh :: indices=

Indices to draw triangles with glDrawElements
fun indices_c=(indices_c: CUInt16Array)

gamnit :: Mesh :: indices_c=

fun max: Point3d[Float]

gamnit :: Mesh :: max

Maximum coordinates of all vertices on each axes
protected fun max=(max: Point3d[Float])

gamnit :: Mesh :: max=

Maximum coordinates of all vertices on each axes
fun min: Point3d[Float]

gamnit :: Mesh :: min

Minimum coordinates of all vertices on each axes
protected fun min=(min: Point3d[Float])

gamnit :: Mesh :: min=

Minimum coordinates of all vertices on each axes
fun n_vertices: Int

gamnit :: Mesh :: n_vertices

Number for vertices
fun normals: Array[Float]

gamnit :: Mesh :: normals

Normals, 3 floats per vertex
fun normals=(normals: Array[Float])

gamnit :: Mesh :: normals=

Normals, 3 floats per vertex
fun texture_coords: Array[Float]

gamnit :: Mesh :: texture_coords

Coordinates on the texture, 2 floats per vertex
fun texture_coords=(texture_coords: Array[Float])

gamnit :: Mesh :: texture_coords=

Coordinates on the texture, 2 floats per vertex
fun vertices: Array[Float]

gamnit :: Mesh :: vertices

Vertices relative coordinates, 3 floats per vertex
fun vertices=(vertices: Array[Float])

gamnit :: Mesh :: vertices=

Vertices relative coordinates, 3 floats per vertex

Redefined properties

redef type SELF: Mesh

gamnit $ Mesh :: SELF

Type of this instance, automatically specialized in every class

All properties

fun !=(other: nullable Object): Bool

core :: Object :: !=

Have self and other different values?
fun ==(other: nullable Object): Bool

core :: Object :: ==

Have self and other the same value?
type CLASS: Class[SELF]

core :: Object :: CLASS

The type of the class of self.
type SELF: Object

core :: Object :: SELF

Type of this instance, automatically specialized in every class
fun center: Point3d[Float]

gamnit :: Mesh :: center

Center coordinates of all the vertices
fun center=(center: Point3d[Float])

gamnit :: Mesh :: center=

Center coordinates of all the vertices
protected fun class_factory(name: String): CLASS

core :: Object :: class_factory

Implementation used by get_class to create the specific class.
fun class_name: String

core :: Object :: class_name

The class name of the object.
fun dimensions: Point3d[Float]

gamnit :: Mesh :: dimensions

Dimensions of the bounding box containing all vertices
fun dimensions=(dimensions: Point3d[Float])

gamnit :: Mesh :: dimensions=

Dimensions of the bounding box containing all vertices
fun draw_mode: GLDrawMode

gamnit :: Mesh :: draw_mode

GLDrawMode used to display this mesh, defaults to gl_TRIANGLES
fun get_class: CLASS

core :: Object :: get_class

The meta-object representing the dynamic type of self.
fun hash: Int

core :: Object :: hash

The hash code of the object.
fun indices: Array[Int]

gamnit :: Mesh :: indices

Indices to draw triangles with glDrawElements
fun indices=(indices: Array[Int])

gamnit :: Mesh :: indices=

Indices to draw triangles with glDrawElements
fun indices_c=(indices_c: CUInt16Array)

gamnit :: Mesh :: indices_c=

init init

core :: Object :: init

fun inspect: String

core :: Object :: inspect

Developer readable representation of self.
protected fun inspect_head: String

core :: Object :: inspect_head

Return "CLASSNAME:#OBJECTID".
intern fun is_same_instance(other: nullable Object): Bool

core :: Object :: is_same_instance

Return true if self and other are the same instance (i.e. same identity).
fun is_same_serialized(other: nullable Object): Bool

core :: Object :: is_same_serialized

Is self the same as other in a serialization context?
intern fun is_same_type(other: Object): Bool

core :: Object :: is_same_type

Return true if self and other have the same dynamic type.
fun max: Point3d[Float]

gamnit :: Mesh :: max

Maximum coordinates of all vertices on each axes
protected fun max=(max: Point3d[Float])

gamnit :: Mesh :: max=

Maximum coordinates of all vertices on each axes
fun min: Point3d[Float]

gamnit :: Mesh :: min

Minimum coordinates of all vertices on each axes
protected fun min=(min: Point3d[Float])

gamnit :: Mesh :: min=

Minimum coordinates of all vertices on each axes
fun n_vertices: Int

gamnit :: Mesh :: n_vertices

Number for vertices
fun normals: Array[Float]

gamnit :: Mesh :: normals

Normals, 3 floats per vertex
fun normals=(normals: Array[Float])

gamnit :: Mesh :: normals=

Normals, 3 floats per vertex
intern fun object_id: Int

core :: Object :: object_id

An internal hash code for the object based on its identity.
fun output

core :: Object :: output

Display self on stdout (debug only).
intern fun output_class_name

core :: Object :: output_class_name

Display class name on stdout (debug only).
fun serialization_hash: Int

core :: Object :: serialization_hash

Hash value use for serialization
intern fun sys: Sys

core :: Object :: sys

Return the global sys object, the only instance of the Sys class.
fun texture_coords: Array[Float]

gamnit :: Mesh :: texture_coords

Coordinates on the texture, 2 floats per vertex
fun texture_coords=(texture_coords: Array[Float])

gamnit :: Mesh :: texture_coords=

Coordinates on the texture, 2 floats per vertex
abstract fun to_jvalue(env: JniEnv): JValue

core :: Object :: to_jvalue

fun to_s: String

core :: Object :: to_s

User readable representation of self.
fun vertices: Array[Float]

gamnit :: Mesh :: vertices

Vertices relative coordinates, 3 floats per vertex
fun vertices=(vertices: Array[Float])

gamnit :: Mesh :: vertices=

Vertices relative coordinates, 3 floats per vertex
package_diagram gamnit::Mesh Mesh core::Object Object gamnit::Mesh->core::Object gamnit::Plane Plane gamnit::Plane->gamnit::Mesh gamnit::Cuboid Cuboid gamnit::Cuboid->gamnit::Mesh gamnit::UVSphere UVSphere gamnit::UVSphere->gamnit::Mesh gamnit::Cube Cube gamnit::Cube->gamnit::Cuboid gamnit::Cube... ... gamnit::Cube...->gamnit::Cube

Parents

interface Object

core :: Object

The root of the class hierarchy.

Children

class Cuboid

gamnit :: Cuboid

Cuboid, or rectangular prism, with 6 faces and right angles
class Plane

gamnit :: Plane

Simple flat mesh, sits on the axes X and Z, normal on Y
class UVSphere

gamnit :: UVSphere

Sphere with radius and a number of faces set by n_meridians and n_parallels

Descendants

class Cube

gamnit :: Cube

Cube, with 6 faces, edges of equal length and square angles

Class definitions

gamnit $ Mesh
# Mesh with all geometry data
#
# May be created via `Plane`, `Cube` or `UVSphere`,
# or loaded from the assets folder indirectly with a `Model`.
#
# ~~~
# import gamnit::depth
#
# var plane = new Plane
# var cube = new Cube
# var sphere = new UVSphere(1.0, 32, 16)
# ~~~
class Mesh

	# Number for vertices
	fun n_vertices: Int do return vertices.length / 3

	# Vertices relative coordinates, 3 floats per vertex
	var vertices = new Array[Float] is lazy, writable

	# Indices to draw triangles with `glDrawElements`
	#
	# If `not_empty`, use `glDrawElements`, otherwise use `glDrawArrays`.
	var indices = new Array[Int] is lazy, writable

	private var indices_c = new CUInt16Array.from(indices) is lazy, writable

	# Normals, 3 floats per vertex
	var normals = new Array[Float] is lazy, writable

	# Coordinates on the texture, 2 floats per vertex
	var texture_coords = new Array[Float] is lazy, writable

	# `GLDrawMode` used to display this mesh, defaults to `gl_TRIANGLES`
	fun draw_mode: GLDrawMode do return gl_TRIANGLES
end
lib/gamnit/depth/depth_core.nit:174,1--209,3

gamnit :: model_dimensions $ Mesh
redef class Mesh

	# Dimensions of the bounding box containing all vertices
	var dimensions = new Point3d[Float](max.x-min.x, max.y-min.y, max.z-min.z) is lazy, writable

	# Center coordinates of all the vertices
	var center = new Point3d[Float]((min.x+max.x)/2.0, (min.y+max.y)/2.0, (min.z+max.z)/2.0) is lazy, writable

	# Minimum coordinates of all vertices on each axes
	#
	# This is a corner of the bounding box.
	var min: Point3d[Float] is lazy do
		var mx = inf
		var my = inf
		var mz = inf
		var i = 0
		while i < vertices.length do
			mx = mx.min(vertices[i])
			my = my.min(vertices[i+1])
			mz = mz.min(vertices[i+2])
			i += 3
		end
		return new Point3d[Float](mx, my, mz)
	end

	# Maximum coordinates of all vertices on each axes
	#
	# This is a corner of the bounding box.
	 var max: Point3d[Float] is lazy do
		var mx = -inf
		var my = -inf
		var mz = -inf
		var i = 0
		while i < vertices.length do
			mx = mx.max(vertices[i])
			my = my.max(vertices[i+1])
			mz = mz.max(vertices[i+2])
			i += 3
		end
		return new Point3d[Float](mx, my, mz)
	end
end
lib/gamnit/depth/model_dimensions.nit:68,1--109,3