# 3D model composed of `Mesh` and `Material`, loaded from the assets folder by default
#
-# Instances can be created at any time and must be loaded after or at the end of `on_create`.
+# Instances can be created at any time and must be loaded after or at the end of `create_scene`.
# If loading fails, the model is replaced by `placeholder_model`.
#
# ~~~
# Usually, there is one `LeafModel` per material.
# At each frame, each material is asked to draw all the live `LeafModel` instaces.
fun leaves: Array[LeafModel] is abstract
+
+ # Sub-models with names, usually declared in the asset file
+ var named_parts = new Map[Text, Model]
end
# Model composed of one or many other `LeafModel`
# ~~~
class Mesh
- # Vertices coordinates
+ # 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`
private var indices_c = new CUInt16Array.from(indices) is lazy, writable
- # Normals on each vertex
+ # Normals, 3 floats per vertex
var normals = new Array[Float] is lazy, writable
- # Coordinates on the texture per vertex
+ # 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`
end
# Source of light
-#
-# Instances of this class define a light source position and type.
-class Light
-
- # TODO point light, spotlight, directional light, etc.
+abstract class Light
# Center of this light source in world coordinates
var position = new Point3d[Float](0.0, 1000.0, 0.0)
end
+# Basic light projected from a single point
+class PointLight
+ super Light
+end
+
+# Source of light casting shadows
+abstract class LightCastingShadows
+ super Light
+
+ # View from the camera, used for shadow mapping, implemented by sub-classes
+ fun camera: Camera is abstract
+end
+
redef class App
# Live actors to be drawn on screen
var actors = new Array[Actor]
# Single light of the scene
- var light = new Light
+ var light: Light = new PointLight is writable
# TODO move `actors & light` to a scene object
# TODO support more than 1 light