Author Topic: model offsets problems  (Read 2490 times)

Offline dutch_delight

  • int
  • **
  • Posts: 58
    • View Profile
model offsets problems
« on: March 17, 2011, 01:17:20 am »
Just been trying to get my gameworld lods to work and I'm having some trouble.

My world is a large quad plane (landscape) that is sliced up into smaller erm,... slices. Each slice is about 3000 faces.
I move each slice to position 0,0,0 in 3dsmax, reset the xform and set the object pivot to 0,0,0 and then export to 3ds format as lod1.
I then apply an optimize modifier so that there are about 1000 triangles and is saved as lod2.
Finally another optimize modifer results in about 200 triangles and that's saved as lod3.
(I need to do it like this because my gaming world is big. On top of the terrain are instances of all my objects so framerate is tight.)


When I load lod1, it is roughly where i expect it to be in world space
But when I display lod2, it is a lot lower in world space than lod1
Lod3 appears even lower down than that.

I'm not transforming the objects, just load and build.
I tried this with loading 3ds and serialized files.

I've tried everything I could find in the forum but no help. I've been using 3dsmax for a long time now (I am a full time game developer/technical artist in real life) so i know a little bit about 3dsmax and can't think of anything else to try.

I am just guessing here but could it be that the amount of verts or faces is being subtracted (or added) from the object position in the load process causing the offset?
(I know it is a known issue but I really need this to work)

Thanks for any advice




Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11777
    • View Profile
    • http://www.jpct.net
Re: model offsets problems
« Reply #1 on: March 17, 2011, 08:42:19 am »
Nothing is added or subtracted by the loader. The loader loads the data as it is defined in the file. How much lower is "lower" in this case?

Offline dutch_delight

  • int
  • **
  • Posts: 58
    • View Profile
Re: model offsets problems
« Reply #2 on: March 19, 2011, 05:44:56 pm »
As a test, I'm using a generic object that I change to load a different model file.
I cant even see the 2nd and 3rd lod so I do this:
float dist = (LevelA.getTransformedCenter().calcSub(world.getCamera().getPosition()).length());

Lod1 = -2563.4226
Lod2 = -12606.766
Lod3 = -27966.719

In 3dsmax, they are all in the exact same position with identical pivots.

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11777
    • View Profile
    • http://www.jpct.net
Re: model offsets problems
« Reply #3 on: March 19, 2011, 09:16:08 pm »
As said, the loader loads what the file's content says. It doesn't apply any translations. Maybe a problem with the exporter?

Offline raft

  • quad
  • ******
  • Posts: 1973
    • View Profile
    • http://www.aptalkarga.com
Re: model offsets problems
« Reply #4 on: March 20, 2011, 12:53:48 pm »

Offline dutch_delight

  • int
  • **
  • Posts: 58
    • View Profile
Re: model offsets problems
« Reply #5 on: March 20, 2011, 04:31:23 pm »
I've already tried all the suggestions in there.

Perhaps I'll try to subtract the distances and apply them as transformations might move them to the right positions?


Offline dutch_delight

  • int
  • **
  • Posts: 58
    • View Profile
Re: model offsets problems
« Reply #6 on: March 22, 2011, 10:46:23 am »
Well, I'm now calculating the offset and sutracting them from the models which put them roughly in the same position. Still not accurate unfortunately.

I take it that getTransformedCenter() will not be the same for each object?
Is there a way of setting the pivot point like in max? Pivot point being the point around which the mesh is build.

If i could set a pivot point to a certain vertex, I could do that for all and move the objects to that point.


I hope I can because I've started work on my own mesh exporter but I havent got enough Java experience to make that work efficiently.


Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11777
    • View Profile
    • http://www.jpct.net
Re: model offsets problems
« Reply #7 on: March 22, 2011, 10:34:46 pm »
getTransformedCenter, as well as getCenter, is calculated based on the actual geometry. This differs in your case and so do these values. I don't get, what the pivot point is supposed to do...setting such a point can't magically adjust things, because it's impossible to know the intentions of the maker of the model. All it can do is to translate the model, but you can already do that. The question is by how far and setting some pivot doesn't help there.  I would rather try to figure out what's the problem with exported models. Maybe you can offer them for download (the exported ones), so that we verify the problem?

Offline dutch_delight

  • int
  • **
  • Posts: 58
    • View Profile
Re: model offsets problems
« Reply #8 on: March 22, 2011, 11:54:53 pm »
Sorry, I've been writing plugins for 3dsmax for too long so probably aproaching this from the wrong angle.
I didnt want to burden anyone but if someone could have a look at my models I would really appreciate it.
I've included 3ds and ser files.
http://www.richterdesigns.co.uk/stuff/terrain_slices.zip

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11777
    • View Profile
    • http://www.jpct.net
Re: model offsets problems
« Reply #9 on: March 24, 2011, 08:23:02 pm »
The models are fine. Maybe your loading code does something fishy? Here's an example for desktop jPCT that displays the different LODs when pressing the left mouse button.

Code: [Select]
import java.awt.Color;

import org.lwjgl.input.Mouse;

import com.threed.jpct.Config;
import com.threed.jpct.FrameBuffer;
import com.threed.jpct.IRenderer;
import com.threed.jpct.Loader;
import com.threed.jpct.Object3D;
import com.threed.jpct.Texture;
import com.threed.jpct.TextureManager;
import com.threed.jpct.World;

public class TerrainLODTest {

private World world;

private FrameBuffer buffer;

private Object3D[] terrains = new Object3D[3];

private int index = 0;

public static void main(String[] args) throws Exception {
new TerrainLODTest().loop();
}

public TerrainLODTest() throws Exception {

Config.glUseVBO = true;

world = new World();
world.setAmbientLight(0, 255, 0);

TextureManager.getInstance().addTexture("box", new Texture("box.jpg"));

terrains[0] = Loader.load3DS("mesh/mlvlaee1.3DS", 0.01f)[0];
terrains[1] = Loader.load3DS("mesh/mlvlaee2.3DS", 0.01f)[0];
terrains[2] = Loader.load3DS("mesh/mlvlaee3.3DS", 0.01f)[0];

for (int i = 0; i < 3; i++) {
world.addObject(terrains[i]);
terrains[i].setVisibility(i == 0);
terrains[i].compile();
terrains[i].setTexture("box");
}

world.buildAllObjects();

world.setClippingPlanes(1, 20000);

world.getCamera().setPosition(0, 2000, 500);
world.getCamera().lookAt(terrains[0].getTransformedCenter());
}

private void loop() throws Exception {
buffer = new FrameBuffer(800, 600, FrameBuffer.SAMPLINGMODE_GL_AA_2X);
buffer.disableRenderer(IRenderer.RENDERER_SOFTWARE);
buffer.enableRenderer(IRenderer.RENDERER_OPENGL);

while (!org.lwjgl.opengl.Display.isCloseRequested()) {

if (Mouse.isButtonDown(0)) {
index++;
index %= 3;
for (int i=0; i<3; i++) {
terrains[i].setVisibility(i==index);
}
Thread.sleep(200);
}

buffer.clear(java.awt.Color.BLUE);
world.renderScene(buffer);
world.draw(buffer);
world.drawWireframe(buffer, Color.RED);
buffer.update();
buffer.displayGLOnly();
Thread.sleep(10);
}
buffer.disableRenderer(IRenderer.RENDERER_OPENGL);
buffer.dispose();
System.exit(0);
}
}

Offline dutch_delight

  • int
  • **
  • Posts: 58
    • View Profile
Re: model offsets problems
« Reply #10 on: March 25, 2011, 10:32:05 am »
very strange.

I think the problem happens when I rotate my objects. After I load my Ser files, I rotate them 90 degrees and then scale them to the same amount you do. I suppose it rotates each object around it's transform center which is different for each object. Maybe?
But when I load the 3ds like you do, I have no problems (cant believe I didnt test this myself.)

For now, I rotate the objects in max and load them as 3ds files which seems to be perfect. Tonight I'll try to see what happens if I link all the lods to a dummy and rotate just the dummy.

Thanks for testing and for taking the time to look at my problem.