Skip to content
This repository has been archived by the owner on Oct 11, 2020. It is now read-only.

Commit

Permalink
Improved test for tangents and added standalone versione
Browse files Browse the repository at this point in the history
  • Loading branch information
riccardobl committed Jun 27, 2016
1 parent 1e9f8da commit a023c0f
Show file tree
Hide file tree
Showing 9 changed files with 289 additions and 156 deletions.
9 changes: 9 additions & 0 deletions src/test/java/UnitTests.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import com.jme3.util.TangentBinormalGenerator;
import com.jme3.util.mikktspace.MikktspaceTangentGenerator;

import utils.TestHelpers;
import wf.frk.f3b.jme3.F3bKey;
import wf.frk.f3b.jme3.debug.Debug;
import wf.frk.f3b.jme3.runtime.F3bPhysicsRuntimeLoader;
Expand Down Expand Up @@ -97,6 +98,14 @@ public void visit(Spatial s) {
s.setMaterial(mat);
}else if(s.getUserData("imported")!=null){
s.setMaterial(mat);
}else if(s.getUserData("frag")!=null){
Material m=mat.clone();
m.setBoolean("ComputeInFrag",true);
s.setMaterial(m);
}else if(s.getUserData("vert")!=null){
Material m=mat.clone();
m.setBoolean("ComputeInVert",true);
s.setMaterial(m);
}
}
});
Expand Down
220 changes: 110 additions & 110 deletions src/test/java/jme3_f3b_loader/nonunit/Commons.java
Original file line number Diff line number Diff line change
@@ -1,110 +1,110 @@
//package jme3_xbuf_loader.nonunit;
//import java.io.File;
//import java.util.List;
//
//import com.jme3.app.SimpleApplication;
//import com.jme3.asset.AssetManager;
//import com.jme3.asset.plugins.FileLocator;
//import com.jme3.asset.plugins.UrlLocator;
//import com.jme3.bullet.BulletAppState;
//import com.jme3.bullet.BulletAppState.ThreadingType;
//import com.jme3.bullet.collision.shapes.CollisionShape;
//import com.jme3.bullet.collision.shapes.MeshCollisionShape;
//import com.jme3.bullet.control.RigidBodyControl;
//import com.jme3.light.DirectionalLight;
//import com.jme3.material.Material;
//import com.jme3.math.ColorRGBA;
//import com.jme3.math.Vector3f;
//import com.jme3.scene.Geometry;
//import com.jme3.scene.Node;
//import com.jme3.scene.Spatial;
//import com.jme3.scene.shape.Box;
//
//public class Commons{
//
// public static Geometry getGeom(Spatial s){
// if(s instanceof Geometry)return (Geometry)s;
// else if(s instanceof Node){
// List<Spatial> children=((Node)s).getChildren();
// for(Spatial child:children){
// Geometry g=getGeom(child);
// if(g!=null)return g;
// }
// }
// return null;
// }
//
// public static void loadTestData(AssetManager am){
//
// String home=(System.getProperty("os.name").toUpperCase().contains("WIN")?System.getenv("APPDATA"):System.getProperty("user.home"))+File.separator;
//
// String possible_paths[]=new String[]{
// home+".TestData/",
// home+"TestData/",
// new File("TestData/").getAbsolutePath(),
// "/DEV/TestData/"
// };
//
// boolean found_test_data=false;
// for(String path:possible_paths){
// if(new File(path).exists()){
// found_test_data=true;
// System.out.println("TestData found "+path);
// am.registerLocator(path+"/assets",FileLocator.class);
// break;
// }
// }
// if(!found_test_data){
// System.out.println("TestData not found. The assets will be loaded from web.");
// System.out.println("This could take a while.");
// System.out.println("To speedup the loading you can clone the TestData repository (from https://github.com/riccardobl/TestData)");
// System.out.println("in one of the following directories ");
// for(String path:possible_paths){
// System.out.println(" "+path);
// }
// System.out.println("and restart the application.");
// }
// am.registerLocator("https://github.com/riccardobl/TestData/raw/master/assets/",UrlLocator.class);
//
// }
//
// public static void initApp(SimpleApplication simpleapp) {
// loadTestData(simpleapp.getAssetManager());
//
// simpleapp.getFlyByCamera().setMoveSpeed(100f);
// simpleapp.setPauseOnLostFocus(false);
// BulletAppState bullet=new BulletAppState();
// bullet.setThreadingType(ThreadingType.PARALLEL);
//
// simpleapp.getStateManager().attach(bullet);
// Node rootNode=simpleapp.getRootNode();
// DirectionalLight dl=new DirectionalLight(new Vector3f(0f, -1f, 0),new ColorRGBA(.72f,.97f,1f,1f).mult(1.4f));
// rootNode.addLight(dl);
// dl=new DirectionalLight(new Vector3f(0f, 0f, -1),new ColorRGBA(.72f,.97f,1f,1f).mult(.4f));
// rootNode.addLight(dl);
// dl=new DirectionalLight(new Vector3f(0f, 0f, 1),new ColorRGBA(.72f,.97f,1f,1f).mult(.4f));
// rootNode.addLight(dl);
// dl=new DirectionalLight(new Vector3f(-1f, 0f, 0),new ColorRGBA(.72f,.97f,1f,1f).mult(.4f));
// rootNode.addLight(dl);
// dl=new DirectionalLight(new Vector3f(1f, 0f, 0),new ColorRGBA(.72f,.97f,1f,1f).mult(.4f));
// rootNode.addLight(dl);
// }
//
//
// public static void makeFloor(SimpleApplication app) {
// Box box=new Box(160,.2f,160);
// Geometry floor=new Geometry("the Floor",box);
// floor.setLocalTranslation(0,-4f,0);
// Material mat1=new Material(app.getAssetManager(),"Common/MatDefs/Light/Lighting.j3md");
// mat1.setColor("Diffuse",new ColorRGBA(.54f,.68f,.16f,1f));
// mat1.setBoolean("UseMaterialColors",true);
// floor.setMaterial(mat1);
//
// CollisionShape floorcs=new MeshCollisionShape(floor.getMesh());
// RigidBodyControl floor_phy=new RigidBodyControl(floorcs,0);
// floor.addControl(floor_phy);
// floor_phy.setPhysicsLocation(new Vector3f(0,-30,0));
// app.getStateManager().getState(BulletAppState.class).getPhysicsSpace().add(floor_phy);
// app.getRootNode().attachChild(floor);
// }
//}
package jme3_f3b_loader.nonunit;
import java.io.File;
import java.util.List;

import com.jme3.app.SimpleApplication;
import com.jme3.asset.AssetManager;
import com.jme3.asset.plugins.FileLocator;
import com.jme3.asset.plugins.UrlLocator;
import com.jme3.bullet.BulletAppState;
import com.jme3.bullet.BulletAppState.ThreadingType;
import com.jme3.bullet.collision.shapes.CollisionShape;
import com.jme3.bullet.collision.shapes.MeshCollisionShape;
import com.jme3.bullet.control.RigidBodyControl;
import com.jme3.light.DirectionalLight;
import com.jme3.material.Material;
import com.jme3.math.ColorRGBA;
import com.jme3.math.Vector3f;
import com.jme3.scene.Geometry;
import com.jme3.scene.Node;
import com.jme3.scene.Spatial;
import com.jme3.scene.shape.Box;

public class Commons{

public static Geometry getGeom(Spatial s){
if(s instanceof Geometry)return (Geometry)s;
else if(s instanceof Node){
List<Spatial> children=((Node)s).getChildren();
for(Spatial child:children){
Geometry g=getGeom(child);
if(g!=null)return g;
}
}
return null;
}

public static void loadTestData(AssetManager am){

String home=(System.getProperty("os.name").toUpperCase().contains("WIN")?System.getenv("APPDATA"):System.getProperty("user.home"))+File.separator;

String possible_paths[]=new String[]{
home+".TestData/",
home+"TestData/",
new File("TestData/").getAbsolutePath(),
"/DEV/TestData/"
};

boolean found_test_data=false;
for(String path:possible_paths){
if(new File(path).exists()){
found_test_data=true;
System.out.println("TestData found "+path);
am.registerLocator(path+"/assets",FileLocator.class);
break;
}
}
if(!found_test_data){
System.out.println("TestData not found. The assets will be loaded from web.");
System.out.println("This could take a while.");
System.out.println("To speedup the loading you can clone the TestData repository (from https://github.com/riccardobl/TestData)");
System.out.println("in one of the following directories ");
for(String path:possible_paths){
System.out.println(" "+path);
}
System.out.println("and restart the application.");
}
am.registerLocator("https://github.com/riccardobl/TestData/raw/master/assets/",UrlLocator.class);

}

public static void initApp(SimpleApplication simpleapp) {
loadTestData(simpleapp.getAssetManager());

simpleapp.getFlyByCamera().setMoveSpeed(100f);
simpleapp.setPauseOnLostFocus(false);
BulletAppState bullet=new BulletAppState();
bullet.setThreadingType(ThreadingType.PARALLEL);

simpleapp.getStateManager().attach(bullet);
Node rootNode=simpleapp.getRootNode();
DirectionalLight dl=new DirectionalLight(new Vector3f(0f, -1f, 0),new ColorRGBA(.72f,.97f,1f,1f).mult(1.4f));
rootNode.addLight(dl);
dl=new DirectionalLight(new Vector3f(0f, 0f, -1),new ColorRGBA(.72f,.97f,1f,1f).mult(.4f));
rootNode.addLight(dl);
dl=new DirectionalLight(new Vector3f(0f, 0f, 1),new ColorRGBA(.72f,.97f,1f,1f).mult(.4f));
rootNode.addLight(dl);
dl=new DirectionalLight(new Vector3f(-1f, 0f, 0),new ColorRGBA(.72f,.97f,1f,1f).mult(.4f));
rootNode.addLight(dl);
dl=new DirectionalLight(new Vector3f(1f, 0f, 0),new ColorRGBA(.72f,.97f,1f,1f).mult(.4f));
rootNode.addLight(dl);
}


public static void makeFloor(SimpleApplication app) {
Box box=new Box(160,.2f,160);
Geometry floor=new Geometry("the Floor",box);
floor.setLocalTranslation(0,-4f,0);
Material mat1=new Material(app.getAssetManager(),"Common/MatDefs/Light/Lighting.j3md");
mat1.setColor("Diffuse",new ColorRGBA(.54f,.68f,.16f,1f));
mat1.setBoolean("UseMaterialColors",true);
floor.setMaterial(mat1);

CollisionShape floorcs=new MeshCollisionShape(floor.getMesh());
RigidBodyControl floor_phy=new RigidBodyControl(floorcs,0);
floor.addControl(floor_phy);
floor_phy.setPhysicsLocation(new Vector3f(0,-30,0));
app.getStateManager().getState(BulletAppState.class).getPhysicsSpace().add(floor_phy);
app.getRootNode().attachChild(floor);
}
}
57 changes: 27 additions & 30 deletions src/test/java/jme3_f3b_loader/nonunit/PhysicsLoaderTest.java
Original file line number Diff line number Diff line change
@@ -1,28 +1,25 @@
//package jme3_xbuf_loader.nonunit;
//
//import java.io.File;
//
//import com.jme3.app.SimpleApplication;
//import com.jme3.bullet.BulletAppState;
//import com.jme3.bullet.control.RigidBodyControl;
//import com.jme3.bullet.joints.PhysicsJoint;
//import com.jme3.bullet.vhacd.VHACDCollisionShapeFactory;
//import com.jme3.bullet.vhacd.cache.PersistentByBuffersCaching;
//import com.jme3.math.Vector3f;
//import com.jme3.physicsloader.impl.bullet.BulletPhysicsLoader;
//import com.jme3.scene.Spatial;
//
//import jme3_ext_xbuf.XbufKey;
//import jme3_ext_xbuf.XbufLoader;
//import vhacd.VHACDParameters;
//import wf.frk.f3b.physics.F3bPhysicsLoader;
//
//public class PhysicsLoaderTest extends SimpleApplication{
//
//
//
// @Override
// public void simpleInitApp() {
package jme3_f3b_loader.nonunit;

import java.io.File;

import com.jme3.app.SimpleApplication;
import com.jme3.bullet.BulletAppState;
import com.jme3.bullet.control.RigidBodyControl;
import com.jme3.bullet.joints.PhysicsJoint;
import com.jme3.bullet.vhacd.VHACDCollisionShapeFactory;
import com.jme3.bullet.vhacd.cache.PersistentByBuffersCaching;
import com.jme3.math.Vector3f;
import com.jme3.physicsloader.impl.bullet.BulletPhysicsLoader;
import com.jme3.scene.Spatial;

import vhacd.VHACDParameters;

public class PhysicsLoaderTest extends SimpleApplication{
//
//
//
@Override
public void simpleInitApp() {
// cam.setLocation(new Vector3f(0,100,100));
// cam.lookAt(Vector3f.ZERO,Vector3f.UNIT_Y);
// Commons.initApp(this);
Expand All @@ -49,9 +46,9 @@
// F3bPhysicsLoader.load(key,xbuf_scene,bullet.getPhysicsSpace());
//
// rootNode.attachChild(xbuf_scene);
// }
}
//
// public static void main(String[] args) {
// new PhysicsLoaderTest().start();
// }
//}
public static void main(String[] args) {
new PhysicsLoaderTest().start();
}
}
56 changes: 56 additions & 0 deletions src/test/java/jme3_f3b_loader/nonunit/TestTangents.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
package jme3_f3b_loader.nonunit;

import static org.junit.Assert.assertTrue;

import com.jme3.app.SimpleApplication;
import com.jme3.material.Material;
import com.jme3.scene.SceneGraphVisitor;
import com.jme3.scene.Spatial;
import com.jme3.util.TangentBinormalGenerator;
import com.jme3.util.mikktspace.MikktspaceTangentGenerator;

import utils.TestHelpers;
import wf.frk.f3b.jme3.F3bKey;

public class TestTangents {
public static void main(String[] args) {
boolean headless=false;
final SimpleApplication app=TestHelpers.buildApp(headless);


TestHelpers.hijackUpdateThread(app);
F3bKey key=new F3bKey("unit_tests/f3b/tangents.f3b");

Spatial scene=app.getAssetManager().loadModel(key);
app.getRootNode().attachChild(scene);

final Material mat=new Material(app.getAssetManager(),"MatDefs/TangentsViewer.j3md");

scene.depthFirstTraversal(new SceneGraphVisitor(){
@Override
public void visit(Spatial s) {
if (s.getUserData("tgbn_gen")!=null){
TangentBinormalGenerator.generate(s);
s.setMaterial(mat);
}else if(s.getUserData("mikkt_gen")!=null){
MikktspaceTangentGenerator.generate(s);
s.setMaterial(mat);
}else if(s.getUserData("imported")!=null){
s.setMaterial(mat);
}else if(s.getUserData("frag")!=null){
Material m=mat.clone();
m.setBoolean("ComputeInFrag",true);
s.setMaterial(m);
}else if(s.getUserData("vert")!=null){
Material m=mat.clone();
m.setBoolean("ComputeInVert",true);
s.setMaterial(m);
}
}
});

TestHelpers.releaseUpdateThread(app);
if(!headless)TestHelpers.waitFor(app);
TestHelpers.closeApp(app);
}
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
package utils;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.atomic.AtomicBoolean;
Expand Down Expand Up @@ -66,6 +67,7 @@ public void simpleInitApp() {
settings.setSamples(4);
settings.setVSync(true);
app.setSettings(settings);

app.start(headless?JmeContext.Type.Headless:JmeContext.Type.Display);
while(run_tab.get(app)==null){
try{
Expand Down
Loading

0 comments on commit a023c0f

Please sign in to comment.