Skip to content

Commit

Permalink
Updating the JCAD to check for bad faces in Obj generation
Browse files Browse the repository at this point in the history
  • Loading branch information
Kevin Harrington committed May 31, 2024
1 parent 729ac54 commit 5e90ecd
Show file tree
Hide file tree
Showing 4 changed files with 73 additions and 65 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ dependencies {
//compile group: 'com.neuronrobotics', name:'GithubPasswordManager', version:'0.6.1'
//compile "com.neuronrobotics:JavaCad:0.14.0"
//compile project('JCSG')
compile group: 'com.neuronrobotics', name: 'JavaCad', version:'1.0.7'
compile group: 'com.neuronrobotics', name: 'JavaCad', version:'1.0.8'

//compile "com.neuronrobotics:CHDK-PTP-Java:0.5.3-SNAPSHOT"
//compile "com.neuronrobotics:java-bowler:3.25.4"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
package com.neuronrobotics.bowlerstudio.physics;

import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.math.BigDecimal;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.ArrayList;
Expand Down Expand Up @@ -49,6 +52,8 @@
import eu.mihosoft.vrl.v3d.Sphere;
import eu.mihosoft.vrl.v3d.Transform;
import eu.mihosoft.vrl.v3d.Vector3d;
import eu.mihosoft.vrl.v3d.ext.openjfx.importers.obj.ObjImporter;
import eu.mihosoft.vrl.v3d.ext.quickhull3d.HullUtil;
import javafx.scene.paint.Color;
import javafx.scene.transform.Affine;

Expand Down Expand Up @@ -805,7 +810,7 @@ public void addFreePart(List<CSG> partsIn) throws IOException {
if (!checkForPhysics(part))
continue;
;
try {
// try {
CSG hull = part.moveToCenter();

Vector3d center = part.getCenter();
Expand All @@ -827,14 +832,14 @@ public void addFreePart(List<CSG> partsIn) throws IOException {
hull = hull.move(center.minus(centerGroup));
hull.setManipulator(new Affine());
ArrayList<CSG> parts = getMapNameToCSGParts(nameOfBODY);
putCSGInAssets(nameOfCSG, hull.hull(), true);
putCSGInAssets(nameOfCSG, hull, true);
org.mujoco.xml.body.GeomType.Builder<?> geom;
geom = addBody.addGeom().withMass(BigDecimal.valueOf(part.getMassKG(0.001)));
parts.add(hull);
setCSGMeshToGeom(nameOfCSG, geom);
}catch(Throwable t) {
t.printStackTrace(System.out);
}
// }catch(Throwable t) {
// t.printStackTrace(System.out);
// }
}
}

Expand Down Expand Up @@ -931,9 +936,23 @@ public void putCSGInAssets(String nameOfCSG, CSG hull, boolean isFree) throws IO
if (!useCache) {
long start = System.currentTimeMillis();
System.out.print("\nWriting " + tempFile.getName());
String xml = hull.toObjString();
Files.write(Paths.get(tempFile.getAbsolutePath()), xml.getBytes());
System.out.print(" " + (System.currentTimeMillis() - start));
ArrayList<Vector3d> points = new ArrayList<>();
List<Polygon> polygons = hull.getPolygons();
for (int j = 0; j < polygons.size(); j++) {
Polygon p = polygons.get(j);
List<Vector3d> points2 = p.getPoints();
for (int i = 0; i < points2.size(); i++) {
Vector3d v = points2.get(i);
points.add(v);
}
}
String obj = HullUtil.hull(points).toObjString();
// InputStream in=new ByteArrayInputStream(obj.getBytes(StandardCharsets.UTF_8));
//
// ObjImporter importer = new ObjImporter(in);

Files.write(Paths.get(tempFile.getAbsolutePath()), obj.getBytes());
System.out.print(" " + (System.currentTimeMillis() - start+"\n"));
} else {
System.out.println("Loading cache " + tempFile.getName());
}
Expand Down
99 changes: 44 additions & 55 deletions test/java/src/junit/bowler/MuJoCoBowlerIntegrationTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,63 +22,52 @@ public class MuJoCoBowlerIntegrationTest {

@Test
public void test() throws Exception {
// try {
// JavaFXInitializer.go();
// } catch (Throwable t) {
// t.printStackTrace();
// System.err.println("ERROR No UI engine availible");
// }
// ArrayList<MobileBase> bases = new ArrayList<>();
// ArrayList<CSG> lifted =new ArrayList<>();
// ArrayList<CSG> terrain = new ArrayList<>();
//
//// MobileBase cat = (MobileBase) ScriptingEngine.gitScriptRun(
//// "https://github.com/OperationSmallKat/Marcos.git",
//// "Marcos.xml");
//// cat.connect();
//// bases.add(cat);
// List<CSG> parts = new ArrayList<>();// uncomment the line below to run the full test with all the pieces. this is removed to work with CI ram limits
//// List<CSG> parts = (List<CSG>) ScriptingEngine.gitScriptRun(
//// "https://gist.github.com/4814b39ee72e9f590757.git",
//// "javaCad.groovy");
// System.out.println("Parts size = "+parts.size());
// //terrain.add(new Cube(10000,10000,100).toCSG().toZMax());
// if(parts.size()>45)
// for(int i=45;i<parts.size();i++) {
// if (i==27||i==25)
// continue;
// CSG p= parts.get(i);
// CSG pl=p.roty(15).movez(200);
// pl.setName(p.getName());
// lifted.add(pl);
// terrain.add(p);
// }
// MuJoCoPhysicsManager manager = new MuJoCoPhysicsManager("javaCadTest", bases, lifted, terrain, new File("./physicsTest"));
try {
JavaFXInitializer.go();
} catch (Throwable t) {
t.printStackTrace();
System.err.println("ERROR No UI engine availible");
}
ArrayList<MobileBase> bases = new ArrayList<>();
ArrayList<CSG> free =new ArrayList<>();
ArrayList<CSG> terrain = new ArrayList<>();


List<CSG> parts = (List<CSG>) ScriptingEngine.gitScriptRun(
"https://github.com/madhephaestus/VexHighStakes2024.git",
"fieldElements.groovy");
terrain= (ArrayList<CSG>) ScriptingEngine.gitScriptRun(
"https://github.com/madhephaestus/VexHighStakes2024.git",
"field.groovy");
System.out.println("Parts size = "+parts.size());
//terrain.add(new Cube(10000,10000,100).toCSG().toZMax());
free.addAll(parts);
MuJoCoPhysicsManager manager = new MuJoCoPhysicsManager("javaCadTest", bases, free, terrain, new File("./physicsTest"));
// manager.setTimestep(0.005);
// manager.setIntegratorType(IntegratorType.IMPLICITFAST);
// manager.generateNewModel();// generate model before start counting time
// long start = System.currentTimeMillis();
// double now = 0;
// boolean first=true;
// while((now=manager.getCurrentSimulationTimeSeconds())<5) {
// long took;
// if((took = manager.stepAndWait())>(manager.getCurrentSimulationTimeSeconds()*1000.0)) {
// if(first) {
// first=false;
// continue;
// }
// fail("Real time broken! "+took+" instead of expected "+manager.getCurrentSimulationTimeSeconds());
// }else {
// System.out.println("Time "+now);
// }
// long timeSinceStart = System.currentTimeMillis()-start;
// double sec = ((double)timeSinceStart)/1000.0;
// if((sec-1)>now) {
// fail("Simulation froze and restarted! "+sec+" expected "+now);
// }
// }
// manager.close();
// System.out.println("Success!");
manager.generateNewModel();// generate model before start counting time
long start = System.currentTimeMillis();
double now = 0;
boolean first=true;
while((now=manager.getCurrentSimulationTimeSeconds())<5) {
long took;
if((took = manager.stepAndWait())>(manager.getCurrentSimulationTimeSeconds()*1000.0)) {
if(first) {
first=false;
continue;
}
fail("Real time broken! "+took+" instead of expected "+manager.getCurrentSimulationTimeSeconds());
}else {
System.out.println("Time "+now);
}
long timeSinceStart = System.currentTimeMillis()-start;
double sec = ((double)timeSinceStart)/1000.0;
if((sec-1)>now) {
fail("Simulation froze and restarted! "+sec+" expected "+now);
}
}
manager.close();
System.out.println("Success!");

}

Expand Down

0 comments on commit 5e90ecd

Please sign in to comment.