VBO on imported models

Hi,

Is there a way to setVBO to the imported models?

I saw that setVBO is on TriMesh and the models dont use TriMesh, is there an explanation for that?

I have static model that could be using VBO, but how?

Spatial doesn't extend TriMesh.

Typecast the Spatial to a TriMesh if it works. (TriMesh)TheNameOfYourSpatial is how to do it. So, something like this:

((Trimesh)model).setVBO();

IDK then.

I had some performance issues as well and I used the following code to analyze the scene graph. You may not be interested in the numbers and you can remove that. It will also add VBO for the geometries that don't have one yet.

Beware: Don't run that on your root node if you have animated models - only use it on static ones.


package de.wom.client;

import com.jme.scene.Geometry;
import com.jme.scene.Node;
import com.jme.scene.Spatial;
import com.jme.scene.VBOInfo;

public class Analyzer {

   private int nodes;
   private int geometries;
   private int vbos;
   private boolean failed;
   private boolean addVBO;

   public void analyze(Node node, boolean addVBO) {
      nodes = 0;
      geometries = 0;
      vbos = 0;
      failed = false;
      this.addVBO = addVBO;
      try {
         analyze0(node);
      } catch (Exception ex) {
         failed = true;
      }
   }

   private void analyze0(Spatial sp) {
      if (sp instanceof Node) {
         nodes++;
         Node n = (Node)sp;
         if (n.getQuantity() > 0)
            for (Spatial child : n.getChildren())
               analyze0(child);
      } else if (sp instanceof Geometry) {
         geometries++;
         Geometry geo = (Geometry)sp;
         if (geo.getVBOInfo() != null)
            vbos++;
         else if (addVBO)
            geo.setVBOInfo(new VBOInfo(true));
      }
   }

   public String toString() {
      if (failed)
         return "Analyzer failed!";
      return "Analyzer found " + nodes + " nodes, " + geometries + " geometries, " + vbos + " VBO infos.";
   }

   public int getGeometries() {
      return geometries;
   }

   public int getNodes() {
      return nodes;
   }

   public int getVbos() {
      return vbos;
   }
}

I'll run it in my game if a get a performance boost.



Thanks!!