Created
March 15, 2016 20:46
-
-
Save riccardobl/74f5bb81124c0f60d7b9 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Testcase for http://hub.jmonkeyengine.org/t/see-if-a-mesh-has-been-changed/35346/ | |
import com.jme3.app.SimpleApplication; | |
import com.jme3.material.Material; | |
import com.jme3.math.ColorRGBA; | |
import com.jme3.math.Vector3f; | |
import com.jme3.scene.Geometry; | |
import com.jme3.scene.Mesh; | |
import com.jme3.scene.SceneGraphVisitor; | |
import com.jme3.scene.Spatial; | |
import com.jme3.scene.VertexBuffer; | |
import com.jme3.scene.VertexBuffer.Usage; | |
import com.jme3.scene.shape.Box; | |
public class IsMeshUpdated extends SimpleApplication{ | |
public static void main(String[] args) { | |
new IsMeshUpdated().start(); | |
} | |
protected boolean isMeshUpdateNeeded(Mesh m) { | |
System.out.println("############# isMeshUpdateNeeded #############"); | |
for(VertexBuffer b:m.getBufferList()){ | |
if(b.isUpdateNeeded()&&b.getUsage()!=Usage.CpuOnly){ | |
System.out.println("VertexBuffer "+b.getBufferType()+" need update. Usage "+b.getUsage()); | |
}else{ | |
System.out.println("VertexBuffer "+b.getBufferType()+" is updated. Usage "+b.getUsage()); | |
} | |
} | |
System.out.println("############# /isMeshUpdateNeeded #############"); | |
return false; | |
} | |
@Override | |
public void simpleInitApp() { | |
Box box1=new Box(1,1,1); | |
Geometry blue=new Geometry("Box",box1); | |
blue.setLocalTranslation(new Vector3f(1,-1,1)); | |
Material mat1=new Material(assetManager,"Common/MatDefs/Misc/Unshaded.j3md"); | |
mat1.setColor("Color",ColorRGBA.Blue); | |
blue.setMaterial(mat1); | |
rootNode.attachChild(blue); | |
} | |
@Override | |
public void simpleUpdate(float tpf){ | |
rootNode.depthFirstTraversal(new SceneGraphVisitor(){ | |
@Override | |
public void visit(Spatial spatial) { | |
if(spatial instanceof Geometry){ | |
Geometry g=(Geometry)spatial; | |
isMeshUpdateNeeded(g.getMesh()); | |
} | |
} | |
}); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment