Пример #1
0
  @Override
  public void simpleInitApp() {

    Spatial gameLevel = assetManager.loadModel("Scenes/town/main.j3o");
    gameLevel.setLocalTranslation(0, -5.2f, 0);
    gameLevel.setLocalScale(2);
    rootNode.attachChild(gameLevel);

    Spatial teapot = assetManager.loadModel("Models/Teapot/Teapot.obj");
    Material mat_default = new Material(assetManager, "Common/MatDefs/Misc/ShowNormals.j3md");
    teapot.setMaterial(mat_default);
    rootNode.attachChild(teapot);

    // Create a wall with a simple texture from test data
    Box box = new Box(Vector3f.ZERO, 2.5f, 2.5f, 2.5f);
    Spatial wall = new Geometry("Box", box);
    Material mat_brick = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
    mat_brick.setTexture(
        "ColorMap", assetManager.loadTexture("Textures/Terrain/BrickWall/BrickWall.jpg"));
    wall.setMaterial(mat_brick);
    wall.setLocalTranslation(2.0f, -2.5f, 0.0f);
    rootNode.attachChild(wall);

    // Display a line of text with a default font
    guiNode.detachAllChildren();
    guiFont = assetManager.loadFont("Interface/Fonts/Default.fnt");
    BitmapText helloText = new BitmapText(guiFont, false);
    helloText.setSize(guiFont.getCharSet().getRenderedSize());
    helloText.setText("Hello World");
    helloText.setLocalTranslation(300, helloText.getLineHeight(), 0);
    guiNode.attachChild(helloText);

    // Load a model from test_data (OgreXML+material+texture)
    Spatial ninja = assetManager.loadModel("Models/Ninja/Ninja.mesh.xml");
    ninja.scale(0.05f, 0.05f, 0.05f);
    ninja.rotate(0.0f, -3.0f, 0.0f);
    ninja.setLocalTranslation(0.0f, -5.0f, -2.0f);
    rootNode.attachChild(ninja);
    // You must add a light to make the model visible
    DirectionalLight sun = new DirectionalLight();
    sun.setDirection(new Vector3f(-0.1f, -0.7f, -1.0f));
    rootNode.addLight(sun);
  }
Пример #2
0
  /**
   * Create a prop without adding it to the scene.
   *
   * @param propType which kind of prop to add (not null)
   * @param relativeSize the prop's size relative to standard (>0)
   * @return a new node to represent the prop, or null if the model is invalid
   */
  private Node create(String propType, float relativeSize) {
    assert propType != null;
    assert relativeSize > 0f : relativeSize;

    Node propNode = loadModel(propType);
    Node modelNode = (Node) propNode.getChild(0);
    List<Spatial> parts = modelNode.getChildren();
    /*
     * Texture each part of the prop and specify its hardness.
     */
    for (Spatial part : parts) {
      String partName = part.getName();
      if (!(part instanceof Geometry)) {
        logger.log(Level.SEVERE, "Prop part {0} is not a geometry.", MyString.quote(partName));
        return null;
      }
      String materialName = material(partName);
      SpatialProperties.setHardness(part, materialName);
      Material material = Assets.loadBlockMaterial(materialName);
      part.setMaterial(material);
    }
    /*
     * Set the scale factor.
     */
    float scaleFactor = scene.getScaleFactor();
    float modelScale = relativeSize / scaleFactor;
    propNode.setLocalScale(modelScale);
    assert getRelativeSize(propNode) == relativeSize : relativeSize;
    /*
     * Set other properties.
     */
    propNode.setShadowMode(RenderQueue.ShadowMode.CastAndReceive);
    /*
     * Give the prop a physics control.
     */
    CollisionShape shape = createShape(propType, relativeSize, parts);
    float mass = calculateMass(propType, relativeSize);
    RigidBodyControl rigidBodyControl = new RigidBodyControl(shape, mass);
    propNode.addControl(rigidBodyControl);
    /*
     * Configure the physics control.
     */
    rigidBodyControl.setFriction(friction);
    scene.getWorld().getPhysics().addObject(rigidBodyControl);
    /*
     * Give the prop a PickedControl.
     */
    SpatialProperties.setPickType(propNode, pickType);
    PickedControl pickedControl = new PickedControl();
    propNode.addControl(pickedControl);

    return propNode;
  }
 @Override
 public void modify(ModelObject modelObject) {
   SkeletonControl skeletonControl =
       modelObject.getModelSpatial().getControl(SkeletonControl.class);
   Node headNode = skeletonControl.getAttachmentsNode("head");
   float width = 1.6f;
   float height = (width * (4f / 5));
   Quad quad = new Quad(width, height, true);
   Spatial plane = new Geometry(null, quad);
   plane.setLocalTranslation((width / -2), 0.3f, -0.73f);
   JMonkeyUtil.setLocalRotation(plane, new Vector3f(0, -0.7f, 1));
   Material material = MaterialFactory.generateUnshadedMaterial("Models/cow/resources/baron.png");
   material.getAdditionalRenderState().setFaceCullMode(RenderState.FaceCullMode.Off);
   plane.setMaterial(material);
   headNode.attachChild(plane);
 }
Пример #4
0
  @Override
  public void simpleInitApp() {
    // put the camera in a bad position
    cam.setLocation(new Vector3f(0.7804813f, 1.7502685f, -2.1556435f));
    cam.setRotation(new Quaternion(0.1961598f, -0.7213164f, 0.2266092f, 0.6243975f));
    cam.setFrustumFar(10);

    Material mat = assetManager.loadMaterial("Common/Materials/WhiteColor.j3m");
    rootNode.setShadowMode(ShadowMode.Off);
    Box floor = new Box(Vector3f.ZERO, 3, 0.1f, 3);
    Geometry floorGeom = new Geometry("Floor", floor);
    floorGeom.setMaterial(mat);
    floorGeom.setLocalTranslation(0, -0.2f, 0);
    floorGeom.setShadowMode(ShadowMode.Receive);
    rootNode.attachChild(floorGeom);

    teapot = assetManager.loadModel("Models/Teapot/Teapot.obj");
    teapot.setLocalScale(2f);
    teapot.setMaterial(mat);
    teapot.setShadowMode(ShadowMode.CastAndReceive);
    rootNode.attachChild(teapot);
    //        lightMdl = new Geometry("Light", new Sphere(10, 10, 0.1f));
    //        lightMdl.setMaterial(mat);
    //        // disable shadowing for light representation
    //        lightMdl.setShadowMode(ShadowMode.Off);
    //        rootNode.attachChild(lightMdl);

    bsr = new BasicShadowRenderer(assetManager, 512);
    bsr.setDirection(new Vector3f(-1, -1, -1).normalizeLocal());
    viewPort.addProcessor(bsr);

    frustum = new WireFrustum(bsr.getPoints());
    frustumMdl = new Geometry("f", frustum);
    frustumMdl.setCullHint(Spatial.CullHint.Never);
    frustumMdl.setShadowMode(ShadowMode.Off);
    frustumMdl.setMaterial(new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md"));
    frustumMdl.getMaterial().getAdditionalRenderState().setWireframe(true);
    frustumMdl.getMaterial().setColor("Color", ColorRGBA.Red);
    rootNode.attachChild(frustumMdl);
  }
Пример #5
0
 public void setMaterial(Material material) {
   Spatial base = getChild("pathBoxGeometry");
   base.setMaterial(material);
 }
Пример #6
0
  public void requestPreview(
      String textureName,
      String displayName,
      int width,
      int height,
      JComponent picLabel,
      JLabel infoLabel) {
    TextureKey key = new TextureKey(textureName);
    picPreview = picLabel;
    assetManager.deleteFromCache(key);
    Texture t = assetManager.loadTexture(key);
    Spatial geom = quad;
    if (key.getTextureTypeHint() == Texture.Type.TwoDimensional) {
      material.setTexture("ColorMap", t);
      geom.setMaterial(material);
      if (infoLabel != null) {
        infoLabel.setText(
            " "
                + displayName
                + "    w : "
                + t.getImage().getWidth()
                + "    h : "
                + t.getImage().getHeight());
      }
    } else if (key.getTextureTypeHint() == Texture.Type.ThreeDimensional) {
      geom = quad3D;
      assetManager.deleteFromCache(key);
      key.setTextureTypeHint(Texture.Type.ThreeDimensional);
      t = assetManager.loadTexture(key);
      material3D.setTexture("Texture", t);
      geom.setMaterial(material3D);
      if (infoLabel != null) {
        infoLabel.setText(
            " "
                + displayName
                + " (Texture3D)    w : "
                + t.getImage().getWidth()
                + "    h : "
                + t.getImage().getHeight()
                + "    d : "
                + t.getImage().getDepth());
      }
    } else if (key.getTextureTypeHint() == Texture.Type.CubeMap) {
      assetManager.deleteFromCache(key);
      geom = SkyFactory.createSky(assetManager, textureName, SkyFactory.EnvMapType.CubeMap);
      if (infoLabel != null) {
        infoLabel.setText(
            " "
                + displayName
                + " (CubeMap)    w : "
                + t.getImage().getWidth()
                + "    h : "
                + t.getImage().getHeight());
      }
    }

    PreviewRequest request = new PreviewRequest(this, geom, width, height);
    request.getCameraRequest().setLocation(new Vector3f(0, 0, 5.3f));
    request.getCameraRequest().setLookAt(new Vector3f(0, 0, 0), Vector3f.UNIT_Y.mult(-1));
    SceneApplication.getApplication().createPreview(request);
  }