Author Topic: Incomprehensible Translations  (Read 1016 times)

Offline AGP

  • quad
  • ******
  • Posts: 1516
    • View Profile
Incomprehensible Translations
« on: October 17, 2013, 09:36:01 am »
I have a very large 3x3 city. I haven't really tested the chunk's individual sizes, just going by trial-and-error. Nevertheless, the results should be more predictable. The following code generates the following screenshot. Overlapping (but not symmetrically so) chunks can be seen on it.

Code: [Select]
     private void loadModels() {
TextureManager manager = TextureManager.getInstance();
manager.addTexture("Girl", new Texture("Girl.jpg"));
FilenameFilter filter = new FilenameFilter() {
     public boolean accept(File dir, String name) {
return name.toLowerCase().endsWith("png");
     }
};
String[] textures = new File("./").list(filter);
for (int i = 0; i < textures.length; i++)
     manager.addTexture(textures[i], new Texture(textures[i]));
oneByOne = Object3D.mergeAll(Loader.loadOBJ("1x1.obj", "1x1.mtl", .01f));
twoByOne = Object3D.mergeAll(Loader.loadOBJ("2x1.obj", "2x1.mtl", .01f));
threeByOne = Object3D.mergeAll(Loader.loadOBJ("3x1.obj", "3x1.mtl", .01f));
oneByTwo = Object3D.mergeAll(Loader.loadOBJ("1x2.obj", "1x2.mtl", .01f));
twoByTwo = Object3D.mergeAll(Loader.loadOBJ("2x2.obj", "2x2.mtl", .01f));
threeByTwo = Object3D.mergeAll(Loader.loadOBJ("3x2.obj", "3x2.mtl", .01f));
oneByThree = Object3D.mergeAll(Loader.loadOBJ("1x3.obj", "1x3.mtl", .01f));
twoByThree = Object3D.mergeAll(Loader.loadOBJ("2x3.obj", "2x3.mtl", .01f));
threeByThree = Object3D.mergeAll(Loader.loadOBJ("3x3.obj", "3x3.mtl", .01f));
oneByOne.setCenter(SimpleVector.ORIGIN);
twoByOne.setCenter(SimpleVector.ORIGIN);
threeByOne.setCenter(SimpleVector.ORIGIN);
oneByTwo.setCenter(SimpleVector.ORIGIN);
twoByTwo.setCenter(SimpleVector.ORIGIN);
threeByTwo.setCenter(SimpleVector.ORIGIN);
oneByThree.setCenter(SimpleVector.ORIGIN);
twoByThree.setCenter(SimpleVector.ORIGIN);
threeByThree.setCenter(SimpleVector.ORIGIN);
oneByOne.rotateX((float)Math.PI*-.5f);
twoByOne.rotateX((float)Math.PI*-.5f);
threeByOne.rotateX((float)Math.PI*-.5f);
oneByTwo.rotateX((float)Math.PI*-.5f);
twoByTwo.rotateX((float)Math.PI*-.5f);
threeByTwo.rotateX((float)Math.PI*-.5f);
oneByThree.rotateX((float)Math.PI*-.5f);
twoByThree.rotateX((float)Math.PI*-.5f);
threeByThree.rotateX((float)Math.PI*-.5f);
final float sizeX = 11000f, sizeZ = -7200f;//CHUNKS ARE 1.6:1, BUT ON WHAT AXIS?
oneByOne.translate(-sizeX, 0, 0);
threeByOne.translate(sizeX, 0, 0);
oneByTwo.translate(-sizeX, 0, sizeZ);
twoByTwo.translate(0, 0, sizeZ);
threeByTwo.translate(sizeX, 0, sizeZ);
oneByThree.translate(-sizeX, 0, sizeZ*2f);
twoByThree.translate(0, 0, sizeZ*2f);
threeByThree.translate(sizeX, 0, sizeZ*2f);
theWorld.addObject(oneByOne);
theWorld.addObject(twoByOne);
theWorld.addObject(threeByOne);
theWorld.addObject(oneByTwo);
theWorld.addObject(twoByTwo);
theWorld.addObject(threeByTwo);
theWorld.addObject(oneByThree);
theWorld.addObject(twoByThree);
theWorld.addObject(threeByThree);

try {hero = BonesIO.loadGroup(new java.io.FileInputStream("Girl.bones"));}
catch (java.io.FileNotFoundException e) {System.out.println("No such file: "+e.getMessage());}
catch (Exception e) {System.out.println("IO: "+e.getMessage());}
hero.get(0).setTexture("Girl");
hero.addToWorld(theWorld);

theWorld.buildAllObjects();
identifyAnimations();
     }


Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11745
    • View Profile
    • http://www.jpct.net
Re: Incomprehensible Translations
« Reply #1 on: October 17, 2013, 11:17:02 am »
I'm not sure what the actual question is here. A translation simply translates the mesh from object into world space. It's basically a simple addition to the mesh's vertices. If the outcome doesn't fit, the models already differ in object space.

Offline AGP

  • quad
  • ******
  • Posts: 1516
    • View Profile
Re: Incomprehensible Translations
« Reply #2 on: October 17, 2013, 11:25:50 am »
They fit perfectly in Max (and they're all of the same size). Either it's a pivot thing (which I tried to address with the setCenter(ORIGIN) calls) or it's something else. But what I'm getting I don't understand.

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11745
    • View Profile
    • http://www.jpct.net
Re: Incomprehensible Translations
« Reply #3 on: October 17, 2013, 08:27:03 pm »
The pivot has no effect on the translation, only on the rotation. If you rotate your models after loading, this might explain what you are seeing. Have you tried to export them as 3ds files instead and load the rotation pivot from the file (http://www.jpct.net/doc/com/threed/jpct/Config.html#useRotationPivotFrom3DS)?

Offline AGP

  • quad
  • ******
  • Posts: 1516
    • View Profile
Re: Incomprehensible Translations
« Reply #4 on: October 17, 2013, 08:37:53 pm »
That's almost never an option for me, because I usually have to convert the textures to power-of-two pngs first. Max's OBJ exporter does that, whereas its 3ds one does not.

I do rotate them, as you can see in that code.

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11745
    • View Profile
    • http://www.jpct.net
Re: Incomprehensible Translations
« Reply #5 on: October 18, 2013, 08:32:29 pm »
Well, in that case, i don't see a solution other than either good old trial-and-error or some code that tries to match the object based on their bounding boxes.