package org.pollux3d.state;
import com.jme3.app.Application;
import com.jme3.app.state.AbstractAppState;
import com.jme3.app.state.AppStateManager;
import com.jme3.asset.AssetManager;
import com.jme3.asset.TextureKey;
import com.jme3.material.Material;
import com.jme3.math.Vector3f;
import com.jme3.renderer.queue.RenderQueue.Bucket;
import com.jme3.scene.Geometry;
import com.jme3.scene.Node;
import com.jme3.scene.Spatial;
import com.jme3.scene.shape.Sphere;
import com.jme3.texture.Texture;
//import com.jme3.util.SkyFactory;
public class BackgroundState extends AbstractAppState {
private Node bgNode = new Node("Background State");
private AssetManager assetManager;
private Sphere sphereMesh = new Sphere(10, 10, 100, false, true);
private Geometry sphere = new Geometry("Sky", sphereMesh);
public Node getBgNode() {
return bgNode;
}
public void initialize (AppStateManager stateManager, Application app){
super.initialize(stateManager, app);
assetManager = app.getAssetManager();
bgNode.setCullHint(Spatial.CullHint.Never);
//Spatial sky = SkyFactory.createSky(assetManager, "Textures/Stars_big.dds", false);
//Spatial sky = SkyFactory.createSky(assetManager, "Textures/Stars_Sphere_big.jpg", true);
//bgNode.attachChild(sky);
sphere.updateModelBound();
sphere.setQueueBucket(Bucket.Sky);
Material sky = new Material(assetManager, "Common/MatDefs/Misc/Sky.j3md");
TextureKey key = new TextureKey("Textures/Sky/Stars.dds", true);
key.setGenerateMips(true);
key.setAsCube(true);
Texture tex = assetManager.loadTexture(key);
sky.setTexture("m_Texture", tex);
sky.setVector3("m_NormalScale", Vector3f.UNIT_XYZ);
sphere.setMaterial(sky);
sphere.setCullHint(Spatial.CullHint.Never);
bgNode.attachChild(sphere);
}
}