X-Git-Url: http://nitlanguage.org diff --git a/contrib/model_viewer/src/model_viewer.nit b/contrib/model_viewer/src/model_viewer.nit index 578f660..0c2cae6 100644 --- a/contrib/model_viewer/src/model_viewer.nit +++ b/contrib/model_viewer/src/model_viewer.nit @@ -30,9 +30,9 @@ redef class App # All available models var models: Array[Model] = [ - new LeafModel(new Cube, new SmoothMaterial.default), - new LeafModel(new Mesh.uv_sphere(4.0, 32, 16), new SmoothMaterial.default), - new LeafModel(new Mesh.uv_sphere(4.0, 32, 16), new NormalsMaterial), + new LeafModel(new Cube, new Material), + new LeafModel(new UVSphere(4.0, 32, 16), new Material), + new LeafModel(new UVSphere(4.0, 32, 16), new NormalsMaterial), new Model("models/Tree_01.obj"), new Model("models/Oak_Fall_01.obj"), new Model("models/Quandtum_BA-2_v1_1.obj"), @@ -55,12 +55,12 @@ 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 @@ -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,18 @@ 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.z -= model.mesh.center.z + # Align on Y only + actor.center.y -= model.center.y - var height = model.mesh.dimensions.y - world_camera.reset_height(height * 2.5) + # Fit in viewport + var height = model.dimensions.x + height = height.max(model.dimensions.y) + height = height.max(model.dimensions.z) + world_camera.reset_height(height * 1.5) actors.clear actors.add actor @@ -125,7 +128,7 @@ redef class App else if event.is_arrow_left then cycle_model -1 end - else if event isa PointerEvent and event.depressed then + else if event isa PointerEvent and not event.is_move and event.depressed then if event.x.to_i > display.width / 2 then cycle_model 1 else cycle_model -1