Package org.pollux3d.map

Source Code of org.pollux3d.map.PlanetSimple

package org.pollux3d.map;

import org.pollux3d.cam.CamTarget;
import org.pollux3d.core.Pollux;
import org.pollux3d.menu.Markable;
import org.pollux3d.menu.CircleMarker;

import com.jme3.asset.AssetManager;
import com.jme3.material.Material;
import com.jme3.material.RenderState.BlendMode;
import com.jme3.math.ColorRGBA;
import com.jme3.renderer.queue.RenderQueue.ShadowMode;
import com.jme3.scene.Geometry;
import com.jme3.scene.shape.Sphere;
import com.jme3.texture.Texture;
import com.jme3.util.TangentBinormalGenerator;

public class PlanetSimple extends MapEntity implements CamTarget, Markable {
 
  private Geometry planet;
  private Geometry atmosphere;
  private AssetManager assetManager;
  private CircleMarker marker;
  private String texture;
  private float size;
 
  public PlanetSimple(String name, String texture) {
    this(name, texture, 50, true);
  }
 
  public PlanetSimple(String name, String texture, int size) {
    this(name, texture, size, true);
  }

  public PlanetSimple(String name, String texture, float size, boolean mark) {
    super(name);
    this.assetManager = Pollux.get().getAssetManager();
    this.texture = texture;
    this.size = size;
    genPlanet();
    // make planet clickable
    Pollux.get().getGeometryManager().registerGeometry(planet, this);
    if (mark) {
      marker = new CircleMarker(size/2+10);
      hideMark();
      this.attachChild(marker);
    }
  }
 
  private void genPlanet() {
    Sphere planetSphere = new Sphere(48, 48, size, false, false);
    //Material mat = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
    Material mat = new Material(assetManager, "Common/MatDefs/Light/Lighting.j3md");
      Texture tex = assetManager.loadTexture("Textures/"+texture);
      planetSphere.setTextureMode(Sphere.TextureMode.Projected); // better quality on spheres
      TangentBinormalGenerator.generate(planetSphere);           // for lighting effect
      mat.setTexture("DiffuseMap", tex);
      mat.setFloat("Shininess", 0.0001f);
      planet = new Geometry("geo_"+name, planetSphere);
      planet.setMaterial(mat);
      planet.setShadowMode(ShadowMode.CastAndReceive);
      this.attachChild(planet);
     
      Sphere planetAtmosphere = new Sphere(48, 48, size*1.1f, false, true);
      Material matAtmosphere = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
      matAtmosphere.setColor("Color", new ColorRGBA(0,0,1,0.1f));
      matAtmosphere.getAdditionalRenderState().setBlendMode(BlendMode.AlphaAdditive);
      atmosphere = new Geometry("geo_"+name+"_atmosphere", planetAtmosphere);
      atmosphere.setMaterial(matAtmosphere);
      this.attachChild(atmosphere);
  }

  public float getZoomDistance() {
    return 180;
  }

  public void hideMark() {
    marker.hideMark();
  }

  public void showMark() {
    marker.showMark();
  }


}
TOP

Related Classes of org.pollux3d.map.PlanetSimple

TOP
Copyright © 2018 www.massapi.com. 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.