gamnit: move `new SmoothMaterial::default` to `new Material`
authorAlexis Laferrière <alexis.laf@xymus.net>
Sun, 7 May 2017 03:44:36 +0000 (23:44 -0400)
committerAlexis Laferrière <alexis.laf@xymus.net>
Sun, 7 May 2017 16:32:10 +0000 (12:32 -0400)
Signed-off-by: Alexis Laferrière <alexis.laf@xymus.net>

lib/gamnit/depth/more_materials.nit
lib/gamnit/depth/more_models.nit

index b77c85e..e8c6746 100644 (file)
@@ -18,15 +18,17 @@ module more_materials
 intrude import depth_core
 intrude import flat
 
-# Simple material with static colors used for debugging or display abstract objects
-class SmoothMaterial
-       super Material
-
+redef class Material
        # Get the default blueish material
-       init default do init(
+       new do return new SmoothMaterial(
                [0.0, 0.0, 0.3, 1.0],
                [0.0, 0.0, 0.6, 1.0],
                [1.0, 1.0, 1.0, 1.0])
+end
+
+# Simple material with static colors used for debugging or display abstract objects
+class SmoothMaterial
+       super Material
 
        # Ambient color, always visible
        var ambient_color: Array[Float] is writable
index c2b9664..8d7d8a1 100644 (file)
@@ -62,7 +62,7 @@ class ModelAsset
                var content = text_asset.to_s
                if content.is_empty then
                        print_error "Model failed to load: Asset empty at '{self.path}'"
-                       leaves.add new LeafModel(new Cube, new SmoothMaterial.default)
+                       leaves.add new LeafModel(new Cube, new Material)
                        return
                end
 
@@ -71,7 +71,7 @@ class ModelAsset
                var obj_def = parser.parse
                if obj_def == null then
                        print_error "Model failed to load: .obj format error on '{self.path}'"
-                       leaves.add new LeafModel(new Cube, new SmoothMaterial.default)
+                       leaves.add new LeafModel(new Cube, new Material)
                        return
                end
 
@@ -212,7 +212,7 @@ private class ModelFromObj
                # Create models and store them
                for mesh, mtl_def in mesh_to_mtl do
                        var material = materials.get_or_null(mtl_def)
-                       if material == null then material = new SmoothMaterial.default
+                       if material == null then material = new Material
 
                        var model = new LeafModel(mesh, material)
                        array.add model
@@ -387,5 +387,5 @@ redef class Sys
        # Blue cube of 1 unit on each side, acting as placeholder for models failing to load
        #
        # This model can be freely used by any `Actor` as placeholder or for debugging.
-       var placeholder_model = new LeafModel(new Cube, new SmoothMaterial.default) is lazy
+       var placeholder_model = new LeafModel(new Cube, new Material) is lazy
 end