1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90
| package test.jmonkey.implementation;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import org.monklypse.core.SWTDefaultImplementor;
import com.jme.bounding.BoundingBox;
import com.jme.bounding.BoundingSphere;
import com.jme.math.Vector3f;
import com.jme.scene.Node;
import com.jme.scene.shape.Box;
import com.jme.scene.shape.Sphere;
import com.jme.util.export.binary.BinaryImporter;
import com.jmex.model.converters.FormatConverter;
import com.jmex.model.converters.MaxToJme;
public class TheGame extends SWTDefaultImplementor {
public TheGame(int width, int height) {
super(width, height);
}
public TheGame() {
super(700, 700);
}
@Override
public void simpleRender() {
}
@Override
public void simpleSetup() {
Box box1 = new Box("Box numero uno", new Vector3f(0,1,0),1,1,1);
box1.setModelBound(new BoundingBox());
box1.updateModelBound();
rootNode.attachChild(box1);
Box box2 = new Box("Box numero dos", new Vector3f(0,-1,0),10,0.25f,10);
box2.setModelBound(new BoundingBox());
box2.updateModelBound();
rootNode.attachChild(box2);
Sphere sphere1 = new Sphere("Sphere number one", new Vector3f(0,1,1), 20, 20, 1);
sphere1.setModelBound(new BoundingSphere());
sphere1.updateModelBound();
rootNode.attachChild(sphere1);
rootNode.setModelBound(new BoundingBox());
rootNode.updateModelBound();
Node myCube;
myCube = this.getBlenderObject("BlenderModels\\Monkey.3ds");
myCube.setModelBound(new BoundingBox());
rootNode.attachChild(myCube);
myCube.updateModelBound();
}
@Override
public void simpleUpdate() {
}
private Node getBlenderObject(String objectPath) {
Node myObject;
FileInputStream myObjectInputStream;
try {
myObjectInputStream = new FileInputStream(objectPath);
FormatConverter converter = new MaxToJme();
converter.setProperty("mtllib", myObjectInputStream);
ByteArrayOutputStream BO = new ByteArrayOutputStream();
try {
converter.convert(myObjectInputStream, BO);
myObject = (Node) BinaryImporter.getInstance().load(new ByteArrayInputStream(BO.toByteArray()));
return myObject;
} catch (IOException e) {
System.out.println("Damn exceptions!" + e);
e.printStackTrace();
System.exit(0);
}
} catch (FileNotFoundException e1) {
e1.printStackTrace();
}
return null;
}
} |
Partager