model_viewer: when switching to a new model, print its the path
[nit.git] / contrib / model_viewer / src / model_viewer.nit
index 6c50878..fefa9ed 100644 (file)
@@ -55,17 +55,17 @@ redef class App
                var logo = new Texture("splash.png")
                show_splash_screen logo
 
-               if args.length > 0 then
-                       # Load a model passed as the first command line argument
-                       var model_path = args.first
-                       if model_path.has_prefix("assets/") then model_path = model_path.substring_from(7)
+               # Load all models passed as command line argument
+               for arg in args.to_a.reversed do
+                       # Force an absolute path, this only works on desktop, but so does command args
+                       arg = getcwd / arg
 
-                       var model = new Model(model_path)
+                       var model = new Model(arg)
                        models.unshift model
                end
 
-               world_camera.near = 1.0
-               world_camera.far = 1000.0
+               world_camera.near = 0.1
+               world_camera.far = 100.0
 
                for model in models do model.load
                for texture in asset_textures_by_name.values do texture.load
@@ -78,12 +78,12 @@ redef class App
                ui_camera.reset_height 800.0
 
                var prev_sprite = new Sprite(ui_prev,
-                       ui_camera.bottom_left.offset(200, -40, 0))
+                       ui_camera.bottom_left.offset(200, 40, 0))
                prev_sprite.scale = 0.5
                ui_sprites.add prev_sprite
 
                var next_sprite = new Sprite(ui_next,
-                       ui_camera.bottom_right.offset(-165, -40, 0))
+                       ui_camera.bottom_right.offset(-165, 40, 0))
                next_sprite.scale = 0.5
                ui_sprites.add next_sprite
        end
@@ -91,15 +91,17 @@ redef class App
        # Set the currently displayed model
        fun model=(model: Model)
        do
+               if model isa ModelAsset then print "Model: {model.path}"
+
                var actor = new Actor(model, new Point3d[Float](0.0, 0.0, 0.0))
 
                model = model.leaves.first
                actor.center.x -= model.mesh.center.x
-               actor.center.y += model.mesh.center.y
+               actor.center.y -= model.mesh.center.y
                actor.center.z -= model.mesh.center.z
 
                var height = model.mesh.dimensions.y
-               world_camera.reset_height(height * 3.0)
+               world_camera.reset_height(height * 2.5)
 
                actors.clear
                actors.add actor
@@ -125,7 +127,7 @@ redef class App
                        else if event.is_arrow_left then
                                cycle_model -1
                        end
-               else if event isa PointerEvent and event.pressed then
+               else if event isa PointerEvent and event.depressed then
                        if event.x.to_i > display.width / 2 then
                                cycle_model 1
                        else cycle_model -1