Create LOD Mesh From Imported COLLADA

Hi all,



I'm having some trouble creating a AreaClodMesh from my imported COLLADA file…  The particular trouble I'm having is how to get the TriMesh from the Node returned by:


Node importedModel = ColladaImporter.getModel();



Any ideas?

EDIT: some background would be good...  I know there are TriMeshes in there, I can see them in SceneWorker/SceneMonitor...  I just can't seem to get to them when iterating through the Nodes.  I get an NPE after the first pass of the for loop

for(int i=0; i<importedModel.getChildren().size(); i++){
Spatial thisChild = ((Node) importedModel).getChildren().get(i);
System.out.println("TESTING " + thisChild.getName() + " inside of " + importedModel.getName());
if(thisChild instanceof TriMesh){
System.out.println("FOUND TRIMESH");
}
}


Edit Again:
The plot thickens apparently... it seems that the importedModel node has no children when it's first received from the COLLADA importer.. yet I use the children extensively later on in the application.  Going to try rewriting my import routines

Spatial thisChild = ((Node) importedModel).getChildren().get(i);

This will most likely get you visualSceneNode. Since the trimesh is too deep/down in the node, you will need to call

Spatial visualscenenode = ((Node) importedModel).getChildren().get(i);
Spatial seb_file_node= ((Node) visualscenenode).getChildren().get(i);
Spatial polysurface= ((Node) seb_file).getChildren().get(i);
Trimesh t = polysurface.getChildren().get(i);


Maybe a more generic trimesh "searcher" would be more useful:



// Recursive (!!) function to add all (Tri-)Meshes of a Spatial to a collection)
private void findMeshes(Spatial sp, Collection<TriMesh> meshes) {
   if(sp instanceof TriMesh) {
        meshes.add((TriMesh) sp);
   } else if(sp instanceof Node) {
        Node node = (Node) sp;
        for(Spatial child : node.getChildren()) {
            findMeshes(child, meshes); // Recursive call to findMeshes in children
        }
   }
   // ignore other subclasses of Spatial.
}



If you want to add QuadMeshes to, or convert them to TriMeshes, you would have to add a check for them in the Loop, too.

Thanks Tim,



That worked great, though I changed it to a Vector…  Too bad it took me 10 minutes to remember Java!=C++ and that I had to initialize it :stuck_out_tongue:

I don't now where you changed it to a Vector…



you could just call:



Vector<TriMesh> meshes = new Vector<TriMesh>();

findMeshes(myCOLLADANode, meshes);

// I'm happy having my meshes in the Vector :smiley:





Cause i think Vector implements Collections :smiley:

I don't now where you changed it to a Vector…



you could just call:



Vector<TriMesh> meshes = new Vector<TriMesh>();

findMeshes(myCOLLADANode, meshes);

// I'm happy having my meshes in the Vector :smiley:





Cause i think Vector implements Collections :smiley: