vertex sharing and vertex indices

Started by raft, December 28, 2009, 07:13:16 PM

Previous topic - Next topic

raft

hi,

indeed i would keep this as a surprise ::) what i'm after is to make a skeletal animation implementation based on Ardor3d's Collada loader. i'm aiming it will be very lightweight and the runtime will not require Ardor3d.

i've constructed the mesh out of Ardor3d's mesh, assigned texture and coordinates but stuck at vertex indices. Ardor3d stores weights and joint indices in buffers where data is ordered according to mesh vertices. i need a way to match ardor3d vertices and jPCT vertices but there seems no way. futhermore Ardor3d also makes its own vertex sharing among polygons (not sure if engine optimizes it or Collada file is already optimized but that doesnt matter). so Object3D.disableVertexSharing doesnt help either.

only solution i can think of is, use same exact vertices and vertex sharing in jPCT to create an Object3D.

so is it possible to add a method or constructor to Object3D which takes vertice and texture coordinates as float arrays and an int array as index buffer ?

thanks,
r a f t


EgonOlsen

It's no surprise. It was the only reasonable thing to assume by looking at your other posts... ;)

I'll look at it. I think i already have something similar that is package public only for loading indexed 3ds files. Either i may make that public (if it fits) or add something new.

EgonOlsen

Ok, here you go: http://www.jpct.net/download/beta/jpct.jar

I haven't tested it very well. Here's a simple test case that works fine:


import com.threed.jpct.*;

class BulkTest {

public static void main(String args[]) throws Exception {
float[] coords=new float[]{0,0,0,0,50,0,50,0,0,50,50,0};
float[] uvs=new float[]{0,0,0,1,1,0,1,1};
int[] indices=new int[]{0,1,2,2,1,3};

TextureManager texMan=TextureManager.getInstance();
texMan.addTexture("test", new Texture("test.jpg"));

Object3D ob=new Object3D(coords, uvs, indices, texMan.getTextureID("test"));

System.out.println("Triangles: "+ob.getMesh().getTriangleCount());
System.out.println("Vertices: "+ob.getMesh().getVertexCount());
System.out.println("Unique vertices: "+ob.getMesh().getUniqueVertexCount());

World world = new World();
world.setAmbientLight(200, 200, 200);

world.addObject(ob);

Camera cam = world.getCamera();
cam.moveCamera(Camera.CAMERA_MOVEOUT, 200);

FrameBuffer fb = new FrameBuffer(800, 600, FrameBuffer.SAMPLINGMODE_NORMAL);
fb.disableRenderer(IRenderer.RENDERER_SOFTWARE);
fb.enableRenderer(IRenderer.RENDERER_OPENGL);

ob.compile();
world.buildAllObjects();

while (!org.lwjgl.opengl.Display.isCloseRequested()) {
fb.clear();
world.renderScene(fb);
world.draw(fb);

fb.update();
fb.displayGLOnly();
Thread.sleep(10);
}
fb.disableRenderer(IRenderer.RENDERER_OPENGL);
fb.dispose();
System.exit(0);
}
}


If it doesn't work on your data, please provide the data you are using.

raft

great :) i will test it tonight or tomorrow

raft

i couldnt wait and tried it here. it loads ok :) seems as i dont need to call recreateTextureCoords in this case

can i suggest, if indices is null, loading vertices sequentially. it may be the case and as you kmow, invoking super class's constructor conditionally is not possible in java

EgonOlsen

Ok, i'll add that simply be creating my own, linear indices-array if none is present. That should do the trick in that case.

EgonOlsen

Is that Collada loader capable of loading multi textured objects and would it be possible to get those different uv-arrays somehow? If so, it might be worth it to add a constructor that takes multiple uv-arrays, because OBJ and 3DS both don't support this.

raft

i'm not sure if collada supports it but it's in the api. there are multiple texture bufferes.
the thing is i'm not using texture information at the moment, only the coordinates. so the user need to call Object3D.setTexture(..) which overrides all texture info of polygons, right ?

even if i use it, how will it be saved and reloaded again ? texture id's are created by TextureManager and will be meaningless in a new jvm session..

EgonOlsen

The textures don't matter, just the uv-coordinates. The textures will be applied in the same way on multiple layers as they are applied on one. What i have in mind is something like this:

new Object3D(coords, uvs, indices, textureIds);

Where uvs is a float[<layerCount>][<vertexCount>]-array and textureIds is a simple int[<layerCount>]-array. Collada supports multiple layers. I think i have an example file lying around somewhere. I'll look for it tomorrow.

raft

single texture and multiple layers  ??? what's the purpose ?

EgonOlsen

#10
Multiple layers AND multiple textures. That's why textureIds is an array...one for each layer.

raft

ok but who and how will set the multiple textures ? Object3D.setTexture(..) does not help in this case

EgonOlsen

#12
The constructor will do...and setTexture(...) will work fine too. You are not mixing the textures between the layers. You have layer0 with texture0 assigned, layer1 with texture1 assigned...like a Quake3 level where one layer is the texture- and the other layer is the lightmap. Currently, i have to load the level two times with different uv-mappings and merge the result into one. While this is doable for me, it isn't for the artist who has to create the content.

raft

ah, you mean Object3D.setTexture(TextureInfo), it supports multiple layers..

EgonOlsen