Package com.jme3.scene

Examples of com.jme3.scene.Node


  public static Node createPatchField(Spatial spatial,
      AssetManager assetManager, String texturePath,
      float patchScaleVariation, float patchWidth, float patchHeight,
      float inc, float fadeEnd, float fadeRange, float minIntensity,
      int channelId, int clusters) {
    Node spatNode = (Node) spatial;
    Node grassLayer = new Node("grass_" + spatial.getName());
    grassLayer.setModelBound(new BoundingBox());

    Texture tex = assetManager.loadTexture(texturePath);
    Material faceMat = new Material(assetManager,
        "/com/l2client/materials/LightingGrass.j3md");
    faceMat.getAdditionalRenderState().setBlendMode(
        RenderState.BlendMode.Alpha);
    faceMat.getAdditionalRenderState().setFaceCullMode(FaceCullMode.Off);
    faceMat.getAdditionalRenderState().setDepthWrite(true);
    faceMat.getAdditionalRenderState().setDepthTest(true);
    faceMat.setTransparent(true);
    faceMat.setTextureParam("DiffuseMap", VarType.Texture2D, tex);
    faceMat.setFloat("AlphaDiscardThreshold", 0.3f);
    // faceMat.setTextureParam("AlphaMap", VarType.Texture2D,tex);
    faceMat.setBoolean("UseAlpha", true);
    if (fadeEnd > 0f) {
      faceMat.setFloat("FadeEnd", fadeEnd);// 300f);
      faceMat.setFloat("FadeRange", fadeRange); // 50f);
      faceMat.setBoolean("FadeEnabled", true);
    }
    faceMat.setBoolean("Swaying", true);
    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()));
            }
          }
        } catch (Exception e) {
          // TODO Auto-generated catch block
          e.printStackTrace();
        }

      }
    }

    GeometryBatchFactory.optimize(grassLayer);
    grassLayer.updateGeometricState();
   
//    DistanceLodControl c = new DistanceLodControl();
//    (grassLayer).getChild(0).addControl(c);
//    c.setDistTolerance(250f);

View Full Code Here


  }

  private static Node createGrassPatch(Vector3f location, Material faceMat,
      float patchScaleVariation, float patchWidth, float patchHeight,
      float rand) {
    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);

    return grassPatch;
  }
View Full Code Here

   
  }
 
  public void addSkyDome(Camera cam, int timeOffset){
    if(sky == null)
      sky = new Node("Sky");
   
    skyLight = new DirectionalLight();
    skyLight.setColor(new ColorRGBA(1f, 1f, 1f, 1f));
    Singleton.get().getSceneManager().changeRootLight(skyLight, Action.ADD);
   
View Full Code Here

      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 "
View Full Code Here

          txt.setBox(new Rectangle(-off, 0f, w, txt.getHeight()));
          txt.setAlignment(Align.Center);
          txt.setQueueBucket(Bucket.Transparent);
          txt.addControl(new BillboardControl());
     
      label = new Node("label");
          if(vis.getWorldBound() instanceof BoundingBox){
            BoundingBox bbox = (BoundingBox)vis.getWorldBound();
            label.setLocalTranslation(0f, bbox.getYExtent()+bbox.getYExtent()+0.5f, 0f);
            logger.finest("Label by BBox "+txt.getText()+" @ "+label.getLocalTranslation());
          }
View Full Code Here

        txt.setBox(new Rectangle(-off, 0f, w, txt.getHeight()));
        txt.setAlignment(Align.Center);
        txt.setQueueBucket(Bucket.Transparent);
        txt.addControl(new MessagesBillboardControl(ttl,speed));
   
        Node node = new Node("Message");
        if(label != null){
          node.setLocalTranslation(0f,label.getLocalTranslation().y+0.5f, 0f);
        } else {
          if(vis.getWorldBound() instanceof BoundingBox){
            BoundingBox bbox = (BoundingBox)vis.getWorldBound();
            node.setLocalTranslation(0f, bbox.getYExtent()+bbox.getYExtent()+0.5f, 0f);
            logger.finest("Message by BBox "+msg+" @ "+node.getLocalTranslation());
          }
          else if(vis.getWorldBound() instanceof BoundingSphere){
            BoundingSphere bound = (BoundingSphere)vis.getWorldBound();
            node.setLocalTranslation(0f, bound.getRadius()+bound.getRadius()+0.5f, 0f);
            logger.finest("Message by BSphere "+msg+" @ "+node.getLocalTranslation());
          }
          else {
            node.setLocalTranslation(0f, 2.5f+0.5f, 0f);
            logger.finest("Message by Code "+msg+" @ "+node.getLocalTranslation());
          }
        }
        node.attachChild(txt);
    Singleton.get().getSceneManager().changeAnyNode(this, node, Action.ADD);
  }
View Full Code Here

      return selectionMarker; 
  }
 
 
  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());
        }
        else if(vis.getWorldBound() instanceof BoundingSphere){
          BoundingSphere bound = (BoundingSphere)vis.getWorldBound();
          n.setLocalTranslation(0f, bound.getRadius()+0.6f, 0f);
          logger.finest("Healthbar by BSphere @ "+n.getLocalTranslation());
        }
        else {
          n.setLocalTranslation(0f, 2.8f, 0f);
          logger.finest("Healthbar by Code @ "+n.getLocalTranslation());
        }
        n.addControl(new BillboardControl());
//        n.setLocalRotation(new Quaternion().fromAngleAxis(FastMath.HALF_PI, Vector3f.UNIT_X));
//        n.updateGeometricState();

      return n; 
  }
View Full Code Here

    if(model instanceof Geometry){
      fixHWSkinningBuffers(((Geometry)model).getMesh());
      return;
    } else {
      if(model instanceof Node){
        Node n = (Node) model;
        for(Spatial c : n.getChildren())
          fixHWModels(c);
      }
    }
  }
View Full Code Here

public class Assembler2Test extends TestCase {

  public void testSelf() throws MalformedURLException{
    Singleton.get().getPartManager().loadParts("megaset.test.csv");

    Node node = Assembler2.getModel("halberd");
   
    assertNotNull(node);
  }
View Full Code Here

            case "move":
                if (!json.getString("info").equalsIgnoreCase("ok"))
                    break;
                int id = json.getInt("source");
                if (model.objects.containsKey(id)) {
                    Node object = model.objects.get(id);
                    String target_cell = json.getString("target_cell");
                    int x = Integer.parseInt(target_cell.split(",")[0]);
                    int y = Integer.parseInt(target_cell.split(",")[1]);
                    object.setLocalTranslation(x, 1, y);
                }
                break;
        }
    }
View Full Code Here

TOP

Related Classes of com.jme3.scene.Node

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.