Skip to content
Browse files

adding in sample 9. getting an error currently

  • Loading branch information...
1 parent 5cc9aaf commit afcabc3d42916ba4637b425af3a0eeaaac05efc8 @jwoertink committed
Showing with 55 additions and 0 deletions.
  1. +55 −0 lib/sample9.rb
View
55 lib/sample9.rb
@@ -0,0 +1,55 @@
+java_import "com.jme3.app.SimpleApplication"
+java_import "com.jme3.material.Material"
+java_import "com.jme3.terrain.geomipmap.TerrainLodControl"
+java_import "com.jme3.terrain.heightmap.AbstractHeightMap"
+java_import "com.jme3.terrain.geomipmap.TerrainQuad"
+java_import "com.jme3.terrain.geomipmap.lodcalc.DistanceLodCalculator"
+java_import "com.jme3.terrain.heightmap.HillHeightMap"
+java_import "com.jme3.terrain.heightmap.ImageBasedHeightMap"
+java_import "com.jme3.texture.Texture" # ::WrapMode
+java_import "jme3tools.converters.ImageToAwt"
+
+class Sample9 < SimpleApplication
+ field_accessor :flyCam
+ attr_accessor :terrain, :mat_terrain
+
+ def simpleInitApp
+ begin
+ flyCam.move_speed = 50
+
+ self.mat_terrain = Material.new(asset_manager, File.join("Common", "MatDefs", "Terrain", "Terrain.j3md"))
+ mat_terrain.set_texture("Alpha", asset_manager.load_texture(File.join("Textures", "Terrain", "splat", "alphamap.png")))
+
+ grass = asset_manager.load_texture(File.join("Textures", "Terrain", "splat", "grass.jpg"))
+ grass.wrap = Texture::WrapMode::Repeat
+ mat_terrain.set_texture("Tex1", grass)
+ mat_terrain.set_float("Tex1Scale", 64.0)
+
+ dirt = asset_manager.load_texture(File.join("Textures", "Terrain", "splat", "dirt.jpg"))
+ dirt.wrap = Texture::WrapMode::Repeat
+ mat_terrain.set_texture("Tex2", dirt)
+ mat_terrain.set_float("Tex2Scale", 32.0)
+
+ rock = asset_manager.load_texture(File.join("Textures", "Terrain", "splat", "road.jpg"))
+ rock.wrap = Texture::WrapMode::Repeat
+ mat_terrain.set_texture("Tex3", rock)
+ mat_terrain.set_float("Tex3Scale", 128.0)
+ height_map_image = asset_manager.load_texture(File.join("Textures", "Terrain", "splat", "mountains512.png"))
+ heightmap = ImageBasedHeightMap.new(ImageToAwt.convert(height_map_image.image, false, true, 0))
+ heightmap.load
+
+ patch_size = 65
+ self.terrain = TerrainQuad.new("my terrain", patch_size, 513, heightmap.height_map)
+ terrain.material = mat_terrain
+ terrain.set_local_translation(0, -100, 0)
+ terrain.set_local_scale(2.0, 1.0, 2.0)
+ root_node.attach_child(terrain)
+ control = TerrainLodControl.new(terrain, get_camera)
+ control.lod_calculator = DistanceLodCalculator.new(patch_size, 2.7)
+ terrain.add_control(control)
+ rescue => e
+ puts "#{e}"
+ end
+ end
+
+end

0 comments on commit afcabc3

Please sign in to comment.
Something went wrong with that request. Please try again.