Advertisement
Guest User

Asset Helper - WORKING

a guest
Oct 8th, 2010
161
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 5 2.93 KB | None | 0 0
  1. import java.io.*;
  2. import com.jme3.app.SimpleApplication;
  3. import com.jme3.asset.plugins.ZipLocator;
  4. import com.jme3.asset.plugins.FileLocator;
  5. import com.jme3.font.BitmapText;
  6. import com.jme3.light.DirectionalLight;
  7. import com.jme3.material.Material;
  8. import com.jme3.math.ColorRGBA;
  9. import com.jme3.math.Vector3f;
  10. import com.jme3.scene.Geometry;
  11. import com.jme3.scene.Spatial;
  12. import com.jme3.scene.shape.Box;
  13.  
  14. /** Sample 3 - how to load an OBJ model, and OgreXML model,
  15.  * a material/texture, or text. */
  16. public class HelloAssets extends SimpleApplication {
  17.  
  18.     public static void main(String[] args) {
  19.         HelloAssets app = new HelloAssets();
  20.         app.start();
  21.     }
  22.  
  23.     @Override
  24.     public void simpleInitApp() {
  25.  
  26.         Spatial teapot = assetManager.loadModel("Models/Teapot/Teapot.obj");
  27.         Material mat_default = new Material(
  28.             assetManager, "Common/MatDefs/Misc/ShowNormals.j3md");
  29.         teapot.setMaterial(mat_default);
  30.         rootNode.attachChild(teapot);
  31.  
  32.         // Create a wall with a simple texture from test_data
  33.         Box box = new Box(Vector3f.ZERO, 2.5f,2.5f,1.0f);
  34.         Spatial wall = new Geometry("Box", box );
  35.         Material mat_brick = new Material(
  36.             assetManager, "Common/MatDefs/Misc/SimpleTextured.j3md");
  37.         mat_brick.setTexture("m_ColorMap",
  38.             assetManager.loadTexture("Textures/Terrain/BrickWall/BrickWall.jpg"));
  39.         wall.setMaterial(mat_brick);
  40.         wall.setLocalTranslation(2.0f,-2.5f,0.0f);
  41.         rootNode.attachChild(wall);
  42.  
  43.         // Display a line of text with a default font
  44.         guiNode.detachAllChildren();
  45.         guiFont = assetManager.loadFont("Interface/Fonts/Default.fnt");
  46.         BitmapText helloText = new BitmapText(guiFont, false);
  47.         helloText.setSize(guiFont.getCharSet().getRenderedSize());
  48.         helloText.setText("Hello World");
  49.         helloText.setColor(new ColorRGBA(1.0f, 1.0f, 1.0f, 1.0f));
  50.         helloText.setLocalTranslation(300, helloText.getLineHeight(), 0);
  51.         guiNode.attachChild(helloText);
  52.  
  53.        
  54.         //load town!
  55.         assetManager.registerLocator("town.zip", ZipLocator.class.getName());
  56.         Spatial gameLevel = assetManager.loadModel("main.scene");
  57.         gameLevel.setLocalTranslation(0, -5.2f, 0);
  58.         gameLevel.setLocalScale(2);
  59.         rootNode.attachChild(gameLevel);
  60.        
  61.         // Load a model from test_data (OgreXML + material + texture)
  62.         Spatial ninja = assetManager.loadModel("Models/Ninja/Ninja.mesh.xml");
  63.         ninja.scale(0.05f, 0.05f, 0.05f);
  64.         ninja.rotate(0.0f, -3.0f, 0.0f);
  65.         ninja.setLocalTranslation(0.0f, -5.0f, -2.0f);
  66.         rootNode.attachChild(ninja);
  67.        
  68.        
  69.         // You must add a light to make the model visible
  70.         DirectionalLight sun = new DirectionalLight();
  71.         sun.setDirection(new Vector3f(-0.1f, -0.7f, -1.0f));
  72.         rootNode.addLight(sun);
  73.  
  74.     }
  75. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement