Here it is then:
Client.java
public class Client {
/**
* @param args
*/
public static void main(String[] args) {
Loader.AddtoPrecache ("textures/cursor/cursor normal.png","normalCursor",Loader.TextureState);
// Loader.AddtoPrecache ("c:/miau.3ds","spam",Loader.UnanimatedModel);
try{
EngineBase game = new EngineBase();
game.setDialogBehaviour(2);
game.start();
}
catch(Exception e){
Console.println(e.toString());
}
}
}
Console.java
import java.awt.BorderLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.DefaultListModel;
import javax.swing.JButton;
import javax.swing.JInternalFrame;
import javax.swing.JList;
import javax.swing.JScrollPane;
import javax.swing.JTextField;
public class Console extends JInternalFrame{
private static final long serialVersionUID = 1L;
static Console myself = null;
static DefaultListModel content;
public JTextField input;
public JScrollPane scroller;
private Console(){
myself = this;
setSize( 300, 200 );
setTitle("Console");
setDefaultCloseOperation(HIDE_ON_CLOSE);
setLayout( new BorderLayout(5, 5) );
JButton save = new JButton("Save Console Dump");
add(save,BorderLayout.PAGE_START );
content = new DefaultListModel();
JList console = new JList(content);
scroller = new JScrollPane(console);
scroller.setAlignmentY(100);
add(scroller);
input = new JTextField();
input.addActionListener( new ActionListener() {
public void actionPerformed( ActionEvent e ) {
Console.GetConsole().CommenceCommand(e.getActionCommand());
input.setText("");
}
});
add(input,BorderLayout.PAGE_END);
setVisible( true );
Console.println("Created Console");
}
public JScrollPane getScroller() {
return scroller;
}
public void CommenceCommand(String bla){
println(bla);
if (bla == "exit")
System.exit(ABORT);
}
public static Console GetConsole(){
if (myself == null){
return new Console();
}
return myself;
}
static void println(String toadd){
GetConsole();
content.addElement(toadd);
System.out.println(toadd);
}
}
Cursor.java
import com.jme.input.AbsoluteMouse;
import com.jme.input.Mouse;
import com.jme.math.Vector3f;
import com.jme.renderer.Renderer;
import com.jme.scene.state.AlphaState;
import com.jme.scene.state.RenderState;
import com.jme.system.DisplaySystem;
public class Cursor {
static final int NormalMouse = 1;
static private Mouse cursor;
Cursor() throws Exception{
cursor = new AbsoluteMouse( "cursor",DisplaySystem.getDisplaySystem().getWidth(),DisplaySystem.getDisplaySystem().getHeight());
cursor.setRenderQueueMode( Renderer.QUEUE_ORTHO );
cursor.registerWithInputHandler( EngineBase.getInput() );
EngineBase.getHudnode().attachChild(cursor);
SetMode(Cursor.NormalMouse);
}
static public void SetMode(int mode) throws Exception{
switch(mode){
case(1):{
DisplaySystem display = DisplaySystem.getDisplaySystem();
cursor.setRenderState((RenderState) Loader.Get("normalCursor"));
cursor.setHotSpotOffset(new Vector3f(0,0,0));
AlphaState as = display.getRenderer().createAlphaState();
as.setBlendEnabled( true );
as.setSrcFunction( AlphaState.SB_SRC_ALPHA );
as.setDstFunction( AlphaState.DB_ONE_MINUS_SRC_ALPHA );
as.setTestEnabled( true );
as.setTestFunction( AlphaState.TF_GREATER );
cursor.setRenderState( as );
EngineBase.getHudnode().updateRenderState();
}
}
}
}
EngineBase.java
import java.awt.FlowLayout;
import java.net.DatagramSocket;
import java.net.SocketException;
import javax.swing.JButton;
import javax.swing.JDesktopPane;
import javax.swing.JInternalFrame;
import javax.swing.UIManager;
import javax.swing.plaf.metal.MetalLookAndFeel;
import com.jme.app.VariableTimestepGame;
import com.jme.input.FirstPersonHandler;
import com.jme.input.InputHandler;
import com.jme.math.Vector3f;
import com.jme.renderer.Camera;
import com.jme.renderer.ColorRGBA;
import com.jme.renderer.Renderer;
import com.jme.scene.Node;
import com.jme.scene.SceneElement;
import com.jme.scene.Text;
import com.jme.scene.state.LightState;
import com.jme.scene.state.ZBufferState;
import com.jme.system.DisplaySystem;
import com.jme.system.JmeException;
import com.jme.util.Timer;
import com.jmex.awt.swingui.JMEDesktop;
public class EngineBase extends VariableTimestepGame {
static EngineBase myself;
protected Camera cam;
public Node rootNode;
private static Node Hudnode;
protected static InputHandler input;
protected Timer timer;
protected Text fps;
protected float tpf;
protected boolean showBounds = false;
private static JDesktopPane desktopPane;
static String render;
public static DatagramSocket socket;
public EngineBase() {
myself = this;
// TODO Auto-generated constructor stub
}
@Override
protected void cleanup() {
// TODO Auto-generated method stub
}
@Override
protected void initGame() {
try{
display.getRenderer().setBackgroundColor( ColorRGBA.black.clone() );
rootNode = new Node("rootNode");
ZBufferState buf = display.getRenderer().createZBufferState();
buf.setEnabled(true);
buf.setFunction(ZBufferState.CF_LEQUAL);
rootNode.setRenderState(buf);
rootNode.setCullMode( SceneElement.CULL_NEVER );
Hudnode = new Node( "desktop node" );
rootNode.attachChild( Hudnode );
Hudnode.setRenderQueueMode( Renderer.QUEUE_ORTHO );
UIManager.setLookAndFeel( new MetalLookAndFeel() );
JMEDesktop jmeDesktop = new JMEDesktop("SwingDestop");
jmeDesktop.setup( display.getWidth(), display.getHeight(), false, input );
jmeDesktop.setLightCombineMode( LightState.OFF );
jmeDesktop.setLightCombineMode( LightState.OFF );
Hudnode.attachChild( jmeDesktop );
desktopPane = jmeDesktop.getJDesktop();
final JInternalFrame internalFrame = new JInternalFrame("Wayne");
internalFrame.setLocation(display.getWidth()/2,display.getHeight()/2);
internalFrame.setResizable( false );
internalFrame.getContentPane().setLayout( new FlowLayout() );
internalFrame.getContentPane().add(new JButton("lol"));
internalFrame.setVisible( true );
internalFrame.pack();
internalFrame.grabFocus();
desktopPane.add( internalFrame );
new LoadingScreen();
rootNode.updateRenderState();
}
catch(Exception e){
e.printStackTrace();
}
}
public static JDesktopPane getDesktopPane() {
return desktopPane;
}
public static InputHandler getInput() {
return input;
}
public float getTpf() {
return tpf;
}
public static Node getHudnode() {
return Hudnode;
}
private void CreateConnection() throws SocketException {
socket = new DatagramSocket();
Console.println("Socket created at "+ socket.getLocalPort());
}
public static DatagramSocket GetSocket(){
return socket;
}
@Override
protected void initSystem() {
try {
display = DisplaySystem.getDisplaySystem(properties.getRenderer());
display.setTitle("New Horizons");
display.createWindow(properties.getWidth(),properties.getHeight(),properties.getDepth(),properties.getFreq(),properties.getFullscreen());
//Save screen size for later use!
display.setVSyncEnabled(true); //we really don't need more frames than we can display!
cam = display.getRenderer().createCamera(display.getWidth(),display.getHeight());
cam.setFrustumPerspective(45.0f,(float) display.getWidth()/(float)display.getHeight(),1,1000);
Vector3f loc = new Vector3f(0.0f, 0.0f, 25.0f);
Vector3f left = new Vector3f( -1.0f, 0.0f, 0.0f);
Vector3f up = new Vector3f(0.0f, 1.0f, 0.0f);
Vector3f dir = new Vector3f(0.0f, 0f, -1.0f);
cam.setFrame(loc, left, up, dir);
cam.update();
display.getRenderer().setCamera(cam);
FirstPersonHandler firstPersonHandler = new FirstPersonHandler(cam,50,1);
input = firstPersonHandler;
timer = Timer.getTimer();
}
catch (JmeException e) {
Console.println(e.toString());
}
}
@Override
protected void reinit() {
// TODO Auto-generated method stub
}
@Override
protected void render(float interpolation) {
display.getRenderer().clearStatistics();
display.getRenderer().clearBuffers();
display.getRenderer().draw(rootNode);
}
@Override
protected void update(float interpolation) {
timer.update();
tpf = timer.getTimePerFrame();
input.update( tpf );
rootNode.updateGeometricState(tpf, true);
}
}
Loader.java
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.net.URL;
import java.util.Vector;
import com.jme.image.Image;
import com.jme.image.Texture;
import com.jme.scene.Node;
import com.jme.scene.state.TextureState;
import com.jme.system.DisplaySystem;
import com.jme.util.TextureManager;
import com.jme.util.export.binary.BinaryImporter;
import com.jme.util.resource.ResourceLocatorTool;
import com.jme.util.resource.SimpleResourceLocator;
import com.jmex.model.converters.FormatConverter;
import com.jmex.model.converters.MaxToJme;
public class Loader extends Thread{
static final int TextureState = 1; //tell the precacher to load a TextureState!
static final int UnanimatedModel = 0;
static Loader myself = null;
static Vector<String> topprecache = new Vector<String>();//Stores the filename and path
static Vector<String> name = new Vector<String>(); //Stores the simple name if any
static Vector<Integer> Types = new Vector<Integer>();//Stores informations what the Loader should Return
static Vector<Object> files = new Vector<Object>(); //Stores the Loaded objects may need to be converted prior returning depending on type enum
//Disable instancing, use Getlaoder instead!
private Loader(){
}
public static void AddtoPrecache (String filename,int Type){
AddtoPrecache(filename,filename,Type);
}
public static void AddtoPrecache (String filename,String simplename,int Type){
System.out.println(filename + " added to precache");
topprecache.add(filename);
name.add(simplename);
Types.add(Type);
}
public static void GetPrecached(String Filename,int Type){
}
public static Loader GetLoader(){
if (myself == null){
Console.println("Created new Loader");
myself = new Loader();
return myself;
}
else{
return myself;
}
}
public void run(){
Console.println("Started Loader");
//Start the Loader!
//How many Items do we have to load?
int size = topprecache.size();
Console.println("Loading " + size + " Items");
//Based on that we could create a loading Bar
int index = 0;
while(index < size){
try{
Object loaded = LoadFile(topprecache.get(index),Types.get(index)); //Returns a model or a Textur object!
Console.println(index + " " + loaded.toString());
files.add(index,loaded);
index++;
}
catch(Exception e){
e.printStackTrace();
index++;//Skip it it does not work
}
}
//Continue the Game!
Console.println("Finsihed Loader");
LoadingScreen.Get().getParent().detachChild(LoadingScreen.Get());
try {
new Cursor();
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
EngineBase.getHudnode().updateRenderState();
}
public Object LoadFile(String name, int Type) throws Exception{
Console.println("Loading " + name);
int dotPos = name.lastIndexOf(".");
String extension = name.substring(dotPos);
String filename = name.substring(0,dotPos);
Console.println("Filename = " + filename);
Console.println("Filetype = " + extension);
Object Loaded = null;
if (Type == Loader.TextureState){
Loaded = LoadTextureState(name);
}
if (Type == Loader.UnanimatedModel){
if (extension.equals(".3ds")){
Loaded = getModel3ds(name);
}
}
return Loaded;
}
private Node getModel3ds(String name) throws FileNotFoundException, IOException {
File file = new File(name);
FormatConverter converter = new MaxToJme();
Node model = null;
ByteArrayOutputStream bo = new ByteArrayOutputStream();
File input = new File("cache/"+file.getName() + ".jme");
// check if there is a cached jme format model for the requested file
if(input.isFile()) {
ResourceLocatorTool.addResourceLocator(ResourceLocatorTool.TYPE_TEXTURE,new SimpleResourceLocator(file.getParentFile().toURI()));
model = (Node)BinaryImporter.getInstance().load(input);
ResourceLocatorTool.removeResourceLocator(ResourceLocatorTool.TYPE_TEXTURE,
new SimpleResourceLocator(file.getParentFile().toURI()));
return model;
}
// no cached model found -> convert the 3ds file and cache it
ResourceLocatorTool.addResourceLocator(ResourceLocatorTool.TYPE_TEXTURE,new SimpleResourceLocator(file.getParentFile().toURI()));
converter.convert(new FileInputStream(file), bo);
model = (Node)BinaryImporter.getInstance().load(new ByteArrayInputStream(bo.toByteArray()));
//bo.writeTo(new FileOutputStream("cache/"+file.getName()+".jme"));
ResourceLocatorTool.removeResourceLocator(ResourceLocatorTool.TYPE_TEXTURE,new SimpleResourceLocator(file.getParentFile().toURI()));
return model;
}
private TextureState LoadTextureState(String filename) {
Console.println("Loading TextureState = " + filename);
TextureState ts = DisplaySystem.getDisplaySystem().getRenderer().createTextureState();
URL texurl = Loader.class.getClassLoader().getResource(filename);
ts.setTexture(TextureManager.loadTexture(texurl,Texture.MM_LINEAR,Texture.FM_LINEAR, Image.GUESS_FORMAT_NO_S3TC,1,true));
return ts;
}
static Object Get(String simplename) throws Exception{ //returns the first object with the givin simplename!
int index = name.indexOf(simplename);
//Searching for the item!
//Depending on type we should sue a shared geometry or a cloned one here (or just the same for every)
Console.println("Trying to get item at " + index);
return files.get(index);
}
}
LoadingScreen.java
import com.jme.image.Texture;
import com.jme.scene.Node;
import com.jme.scene.shape.Quad;
import com.jme.scene.state.LightState;
import com.jme.scene.state.TextureState;
import com.jme.system.DisplaySystem;
import com.jme.util.TextureManager;
public class LoadingScreen extends Node {
private static final long serialVersionUID = 1150983124443967599L;
static DisplaySystem display = DisplaySystem.getDisplaySystem();
static Node myself;
public LoadingScreen() {
super("LoginScreen");
myself = this;
//Just a small background block!
//We need the background now!
String texturepath = "Textures/LoadingScreen_" + (int)(Math.random()*10) + ".png";
Console.println("Loading file "+ texturepath); //$NON-NLS-1$
Texture loadingscreentexture = TextureManager.loadTexture(LoadingScreen.class.getClassLoader().getResource(texturepath),Texture.MM_LINEAR_LINEAR,Texture.FM_LINEAR );
Quad loadscreen = new Quad("Quad",DisplaySystem.getDisplaySystem().getWidth(),DisplaySystem.getDisplaySystem().getHeight()); //$NON-NLS-1$
TextureState ts = display.getRenderer().createTextureState();
ts.setTexture(loadingscreentexture);
ts.setEnabled(true );
loadscreen.setRenderState( ts );
loadscreen.updateRenderState();
this.setLocalTranslation( display.getWidth() / 2, display.getHeight() / 2, 0 );
this.attachChild(loadscreen);
this.setLightCombineMode( LightState.OFF );
EngineBase.getHudnode().attachChild(this);
//Load the models before continuing
Loader myloader = Loader.GetLoader();
// myloader.run();
myloader.start();
}
static Node Get(){
return myself;
}
public void update(float interpolation){
}
}
And finally here the used Textures
http://empirephoenix.de/Textures.rar