Package com.jme3.scene

Examples of com.jme3.scene.Geometry


  }
 
  private static Geometry getLine(Vector3f st, Vector3f en, float size){
    Line b = new Line(st, en);//, 0.1f, 0.4f, 0.1f);
    b.setLineWidth(size);
    return new Geometry("",b);
  }
View Full Code Here


      camera.setLocation(new Vector3f(0,0,0))
   
    Singleton.get().getSceneManager().removeAll();
      Quad b = new Quad(80f,60f);
      b.updateBound();
      Geometry geom = new Geometry("backdrop", b);
      Material mat = new Material(Singleton.get().getAssetManager().getJmeAssetMan(), "Common/MatDefs/Misc/Unshaded.j3md");
      mat.setTexture("ColorMap", Singleton.get().getAssetManager().getJmeAssetMan().loadTexture("start/backdrop.png"));
      geom.setMaterial(mat);
      geom.setLocalTranslation(-40f, -30f, -90f);     
      Singleton.get().getSceneManager().changeTerrainNode(geom,Action.ADD);
     
      Quad b2 = new Quad(38f,29f);
      b2.updateBound();
      Geometry geom2 = new Geometry("wolf", b2);
      Material mat2 = new Material(Singleton.get().getAssetManager().getJmeAssetMan(), "Common/MatDefs/Misc/Unshaded.j3md");
      mat2.setTexture("ColorMap", Singleton.get().getAssetManager().getJmeAssetMan().loadTexture("start/wolf.png"));
      mat2.getAdditionalRenderState().setBlendMode(BlendMode.Alpha); // activate transparency
      geom2.setMaterial(mat2);
      geom2.setQueueBucket(Bucket.Transparent);
      geom2.setLocalTranslation(-39f, -15f, -90f)
      Singleton.get().getSceneManager().changeTerrainNode(geom2,Action.ADD);
     
    AmbientLight al = new AmbientLight();
      al.setColor(new ColorRGBA(.8f, .8f, .8f, 1.0f));
    Singleton.get().getSceneManager().changeRootLight(al,Action.ADD);
View Full Code Here

      }
    }
   
    private void setShadowCasterReceiver(Spatial n) {
      if(n instanceof Geometry) {
        Geometry v = (Geometry)n;
        if(n.getQueueBucket().equals(RenderQueue.Bucket.Opaque))
          n.setShadowMode(ShadowMode.CastAndReceive);
//          TangentBinormalGenerator.generate(n);
      } else if (n instanceof Node){
        Node v = (Node)n;
        for(Spatial  child : v.getChildren()){
          setShadowCasterReceiver(child);
        }
      }
    }
View Full Code Here

    faceMat.setVector3("SwayData", new Vector3f(1.0f, 0.5f, 300f));// frequency,
                                    // variation,
                                    // third?
    faceMat.setVector2("Wind", new Vector2f(1f, 1f));

    Geometry terrain = null;

    if (spatial instanceof Geometry) {
      terrain = (Geometry) spatial;
    } else {
      for (Spatial currentSpatial : spatNode.getChildren()) {
        if (currentSpatial instanceof Geometry) {
          terrain = (Geometry) currentSpatial;
          break;
        }
      }
    }

    if (terrain == null || spatNode.getChildren().isEmpty()) {
      Logger.getLogger(GrassLayerUtil.class.getName()).log(Level.SEVERE,
          "Could not find terrain object.", new Exception());
      System.exit(0);
    }

    // Generate grass uniformly with random offset.
    float terrainWidth = 1f * 256; // get width length of terrain(assuming
                    // its a square)
    BoundingVolume bounds = ((Spatial) terrain).getWorldBound();
    if (BoundingVolume.Type.AABB.equals(bounds.getType())) {
      BoundingBox bb = ((BoundingBox) bounds);
      terrainWidth = Math.max(bb.getXExtent(), bb.getZExtent());
      terrainWidth *= 2f;
    } else if (BoundingVolume.Type.Sphere.equals(bounds.getType())) {
      terrainWidth = ((BoundingSphere) bounds).getRadius();
      terrainWidth *= 2f;
    }
    Vector3f centre = bounds.getCenter(); // get the centr location of the
                        // terrain
    Vector2f grassPatchRandomOffset = new Vector2f().zero();
    Vector3f candidateGrassPatchLocation = new Vector3f();

    Random rand = new Random();
    Ray ray = new Ray(Vector3f.ZERO, Vector3f.UNIT_Y.mult(-1f));
    CollisionResults results = new CollisionResults();
    float ax, az;
    for (float x = centre.x - terrainWidth / 2 + inc; x < centre.x
        + terrainWidth / 2 - inc; x += inc) {
      for (float z = centre.z - terrainWidth / 2 + inc; z < centre.z
          + terrainWidth / 2 - inc; z += inc) {
        grassPatchRandomOffset.set(inc, inc);
        grassPatchRandomOffset.multLocal(rand.nextFloat()); // make the
                                  // off set
                                  // length a
                                  // random
                                  // distance
                                  // smaller
                                  // than the
                                  // increment
                                  // size
        grassPatchRandomOffset
            .rotateAroundOrigin(
                (float) (((int) (rand.nextFloat() * 359)) * (Math.PI / 180)),
                true); // rotate the offset by a random angle

        ax = x + grassPatchRandomOffset.x;
        az = z + grassPatchRandomOffset.y;
        ray.setOrigin(new Vector3f(ax, centre.y + terrainWidth, az));
        terrain.collideWith(ray, results);

        if (results.size() <= 0)
          continue;

        try {
          if (results.size() > 0) {

            candidateGrassPatchLocation.set(ax, results
                .getCollision(0).getContactPoint().y, az);
            results.clear();

            if (isGrassLayer(candidateGrassPatchLocation, terrain,
                minIntensity, terrainWidth, channelId)) {
              // this will be in world coords, but we want it to
              // be in local
              candidateGrassPatchLocation.subtractLocal(terrain
                  .getWorldTranslation());
              grassLayer.attachChild(createGrassPatch(
                  candidateGrassPatchLocation, faceMat,
                  patchScaleVariation, patchWidth,
                  patchHeight, rand.nextFloat()));
View Full Code Here

    Node grassPatch = new Node();
    float selectedSizeVariation = (float) (rand * (patchScaleVariation - (1 / patchScaleVariation)))
        + (1 / patchScaleVariation);
    Quad faceShape = new Quad((patchWidth * selectedSizeVariation),
        patchHeight * selectedSizeVariation, false);
    Geometry face1 = new Geometry("face1", faceShape);
    face1.move(-(patchWidth * selectedSizeVariation) / 2, 0, 0);
    grassPatch.attachChild(face1);

    Geometry face2 = new Geometry("face2", faceShape);
    face2.rotate(new Quaternion().fromAngleAxis(-FastMath.PI / 2,
        new Vector3f(0, 1, 0)));
    face2.move(0, 0, -(patchWidth * selectedSizeVariation) / 2);
    grassPatch.attachChild(face2);

    grassPatch.setCullHint(Spatial.CullHint.Dynamic);
    grassPatch.setQueueBucket(RenderQueue.Bucket.Transparent);

    face1.setMaterial(faceMat);
    face2.setMaterial(faceMat);

    grassPatch.rotate(new Quaternion().fromAngleAxis(
        (((int) (Math.random() * 359)) + 1) * (FastMath.PI / 190),
        new Vector3f(0, 1, 0)));
    grassPatch.setLocalTranslation(location);
View Full Code Here

    Timer t = new NanoTimer();
    float time = 0f;

    // new loader each time, yes
    try {
      Geometry g;
      // need to load vial loadModel, JME does not see obj, etc as
      // Assets..
      t.reset();
      Spatial n = (Spatial) assetMan.loadModel(from.getAbsolutePath());
      time = t.getTimeInSeconds();
      System.out.println("File " + from.getAbsolutePath() + " loaded in "
          + time + " seconds");
      if (n instanceof Geometry) {
        g = (Geometry) n;
        n = new Node(g.getName());
        ((Node)n).attachChild(g);
      } else if (n instanceof Node) {
        if (((Node) n).getChildren().size() > 1)
          throw new Throwable(
              "Mesh with more children detected than one on "
                  + from.getName());
        g = (Geometry) ((Node) n).getChild(0);
      } else
        throw new Throwable("Spatial loaded was unexpected type "
            + n.getClass());
      // jme fucked up the model names, and ignores any object name
      // entries so we fix a bit
      String fName = from.getName().substring(0,
          from.getName().length() - fileEnding.length());// without .nav
      g.setName(fName.toLowerCase());
      TiledNavMesh navMesh = new TiledNavMesh();

      {
      String[] xy = from.getParentFile().getName().split("_");
      // l2j's center is in x between region 19 (-32768) and 20 (+32768)
      // and in y between region 18 (+32768) and 17 (-32768)
     
      // minus 20*2048, 20 because region count starts with 0_0,
      // 2048 because one region consists of 8x8 tiles (each 256x256 long)
      int xd = (Integer.parseInt(xy[0]) * 256) - (20 * 2048);
      // minus 18*2048
      int yd = (Integer.parseInt(xy[1])) * 256 - (18 * 2048);
     
      // center is in top left corner for nav mesh to be consistent with
      // this for borders move x right, move y up by half size
      Vector3f offset = new Vector3f(xd + 128, 0, yd - 128);
      //System.out.println("Offset for "+from.getParentFile().getName()+"/nav2.obj should be at:"+offset);
      }
     
      navMesh.loadFromMesh(g.getMesh(), Vector3f.ZERO, isMeshRelative);
     
      time = t.getTimeInSeconds();
      System.out.println("File " + from.getAbsolutePath()
          + " converted in " + time + " seconds");
      String path = from.getAbsolutePath();
View Full Code Here

   
  }
 
  private Geometry createSelectionMarker(){
    float size = 2f;
    Geometry selectionMarker = new Geometry("selection", new Quad(size, size));
    selectionMarker.setLocalTranslation(-0.5f*size, 0.2f, 0.5f*size);
    selectionMarker.setLocalRotation(new Quaternion().fromAngleAxis(-FastMath.HALF_PI, Vector3f.UNIT_X));

      com.jme3.asset.AssetManager am = Singleton.get().getAssetManager().getJmeAssetMan();
      Material mat = new Material(am, "Common/MatDefs/Light/Lighting.j3md");
      Texture sel = am.loadTexture("models/textures/flare4.png");
      sel.setWrap(WrapMode.Repeat);
      mat.setTexture("DiffuseMap", sel);
      mat.getAdditionalRenderState().setBlendMode(BlendMode.Alpha);
      mat.getAdditionalRenderState().setDepthWrite(false);
      selectionMarker.setMaterial(mat);
      selectionMarker.setQueueBucket(Bucket.Transparent);
      selectionMarker.setShadowMode(ShadowMode.Off);
     
      return selectionMarker; 
  }
View Full Code Here

  }
 
 
  private Node createHealthBar(){
    Node n = new Node("health");
    Geometry frame = new Geometry("health_frame", new Quad(1f, 0.02f));
    Material mat = null;
      com.jme3.asset.AssetManager am = Singleton.get().getAssetManager().getJmeAssetMan();
      mat = new Material(am, "Common/MatDefs/Misc/Unshaded.j3md");
        mat.setColor("Color", ColorRGBA.White);
      frame.setMaterial(mat);
      frame.setQueueBucket(Bucket.Transparent);
      frame.setShadowMode(ShadowMode.Off);
    frame.setLocalTranslation(-0.5f, 0.11f, 0f);
      n.attachChild(frame);
     
    Geometry bar = new Geometry("health_bar", new Quad(1f, 0.1f));
      mat = new Material(am, "Common/MatDefs/Misc/Unshaded.j3md");
        mat.setColor("Color", ColorRGBA.Red);
        bar.setMaterial(mat);
      bar.setQueueBucket(Bucket.Transparent);
        bar.setShadowMode(ShadowMode.Off);
        bar.setLocalTranslation(-0.5f, 0f, 0f);
      n.attachChild(bar);
        if(vis.getWorldBound() instanceof BoundingBox){
          BoundingBox bbox = (BoundingBox)vis.getWorldBound();
          n.setLocalTranslation(0f, bbox.getYExtent()+0.6f, 0f);
          logger.finest("Healthbar by BBox @ "+n.getLocalTranslation());
View Full Code Here

            // ONLY if not using shared geometry
            // This includes the shared geoemtry itself actually
            for (int i = 0; i < geoms.length; i++) {
              meshes[i] = geoms[i].getMesh().cloneForAnim();

              Geometry g = new Geometry(geoms[i].getName(), meshes[i]);
              Material m = geoms[i].getMaterial();
              g.setMaterial(m);
              materials.add(m);
                model.attachChild(g);
            }

            if(useOptimization) {
View Full Code Here

    TiledNavMesh m = getNavMesh("0_0", Vector3f.ZERO);
    try {
      BinaryExporter.getInstance().save(m, new File("0_0.jnv"));
      m = (TiledNavMesh) BinaryImporter.getInstance().load(new File("0_0.jnv"));
      DesktopAssetManager assetManager = new DesktopAssetManager(true);
      Geometry g00 = (Geometry) assetManager.loadAsset("grid.0_0.j3o");
      assertNotNull("Asset for grid 0_0 is missing", g00);
      m = new TiledNavMesh();
     
      long eT = 0L;
          long sT =  System.currentTimeMillis();         
View Full Code Here

TOP

Related Classes of com.jme3.scene.Geometry

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.