Java Model Importer - Design Discussion

Started by Neoptolemus, March 02, 2015, 13:41:28

Previous topic - Next topic

Neoptolemus

Hi everyone,

I'm currently working on a library for importing various model types. The idea is that with a single easy command ModelImporter.import(Path to file), it will return an object representing the scene. The scene consists of all the individual meshes, and any lights, cameras, textures etc defined within the import. If anyone has ever used the AssImp library (which is written in C++) then I basically want to try and create that but in pure Java.

I wanted to spark a discussion on how to structure the scene object in such a way that it makes it fast and efficient for people to handle things like animations and the like. At the moment the scene consists of a mesh array containing each mesh defined within the scene, and each mesh contains various primitive array types for things like vertices, normals, indices and so on:

JUMIScene:
   ArrayList<JUMIMesh> meshes;

   public JUMIMesh getMeshByIndex(int index);
   public JUMIMesh getMeshByName(String meshName);

JUMIMesh:
    float[] vertices;
    float[] normals;
    float[] tangents;
    float[] textureCoordinates;
    float[] interleavedAttributes; Not currently in use, will be used to store interleaved data for those wanting to use an interleaved VBO
   
FaceType faceType (an enum defining how faces are defined, currently either QUADS or TRIANGLES);

    public float[] getVertices(); Just returns vertices
    public float[] getNormals(); etc
    public float[] getUVs(); etc
    public float[] getTangents(); etc


This is my general structure at the moment and it works fine if all you want to do is render a mesh with a texture (I have some more bits and pieces related to retrieving texture data, but I've left that out for now as you get the idea on how my data structure looks). However, I want to support animation as well, and I'm not sure how efficient this type of structure is going to be when you throw that into the mix.

I was wondering if anyone would be able to offer some ideas on how they'd want their dream data structure to look like, to make it as easy and fast as possible to extract the vertex information you need, interpolate it based on animation data and get it buffered into the VBO with the minimum of fuss? Remember that I want this to support multiple file formats, so format-specific stuff should be avoided if possible.

Thanks in advance!

quew8

Like I said on JGO. I base mine on COLLADA. But to give some extra detail, I have my importers implement access interfaces so the programmer can interpret the data in the files however they want. There are abstract "Interpreter" classes which get given the access interfaces along with index and face and skinning information. Example:

public interface DataInput {
    public int[] getVCount();
    public void putData(SemanticSet source, float[] dest, int offset, int initialIndex, int n);
    public void putData(SemanticSet source, String[] dest, int offset, int initialIndex, int n);
    public void putData(SemanticSet source, Matrix[] dest, int offset, int initialIndex, int n);
}


That's one of the access interfaces. I'd post an interpreter class but they're a bit more complex.