Thanks for your help. mergeObjects is the method i need (i want to add an octree). The following code throws this exception:
Exception occurred during event dispatching:
java.lang.StackOverflowError
at com/threed/jpct/OcTree.createChildren
at com/threed/jpct/OcTree.createChildren
at com/threed/jpct/OcTree.createChildren
at com/threed/jpct/OcTree.createChildren
at com/threed/jpct/OcTree.createChildren
at com/threed/jpct/OcTree.createChildren
at com/threed/jpct/OcTree.createChildren
at com/threed/jpct/OcTree.createChildren
at com/threed/jpct/OcTree.createChildren
at com/threed/jpct/OcTree.createChildren
public void loadLevel(String level)
{
int y = 0;
int z = 0;
boolean onPlatform = false;
levelObj = new Object3D(0);
try{
URL url = new URL(getCodeBase(),level);
InputStream inStream = url.openStream();
BufferedReader dataStream =new BufferedReader(new InputStreamReader(inStream));
String inLine = null;
while((inLine = dataStream.readLine()) != null)
{
if(!inLine.equals(";"))
{
int x = 0;
while(x < inLine.length())
{
if(inLine.charAt(x) == '#')
{
//This command adds a blue block
Object3D Box1 = block.cloneObject();
if(!onPlatform)
Box1.translate(x*4,y*4,z*4);
else
Box1.translate(x*4,(y*4)-0.5f,z*4);
levelObj = Object3D.mergeObjects(levelObj,Box1); //add the block to the level
}
else
if(inLine.charAt(x) == 'R')
{
//This command moves the red sphere
sphere1.translate(x+5,y-1.5f,z-2); //move the sphere
camera.setPosition(x+5,y-1.5f,z-10); //move the camera
}
x++;
}
z++;
}
else
{
//go to the next platform or to the 2nd layer of the current platform
if(onPlatform)
onPlatform = false;
else
onPlatform = true;
z = 0;
if(!onPlatform)
y--;
}
}
}
catch(Exception e){System.out.println("Exception while loading the level: " + e);}
levelObj.createTriangleStrips(2);
OcTree tree = new OcTree(levelObj,12,OcTree.MODE_OPTIMIZED);
levelObj.setOcTree(tree);
theWorld.addObject(levelObj);
theWorld.buildAllObjects();
}
I don't know what is wrong.