use of maspack.render.GL.GLViewerFrame in project artisynth_core by artisynth.
the class Main method createViewerFrame.
public GLViewerFrame createViewerFrame() {
GLViewerFrame frame = new GLViewerFrame(myViewer, PROJECT_NAME, 400, 400);
GLViewer viewer = frame.getViewer();
// ViewerToolBar toolBar = new ViewerToolBar(viewer, this);
AxisAngle REW = getDefaultViewOrientation(getRootModel());
myViewerManager.addViewer(viewer);
ViewerToolBar toolBar = new ViewerToolBar(viewer, /*addGridPanel=*/
true);
frame.getContentPane().add(toolBar, BorderLayout.PAGE_START);
viewer.setDefaultAxialView(AxisAlignedRotation.getNearest(new RotationMatrix3d(REW)));
initializeViewer(viewer, REW);
frame.setVisible(true);
return frame;
}
use of maspack.render.GL.GLViewerFrame in project artisynth_core by artisynth.
the class GLHSVShaderTest method main.
public static void main(String[] args) {
GLViewerFrame vframe = new GLViewerFrame("GLHSVShader test", 640, 480);
vframe.setVisible(true);
GLViewer viewer = vframe.getViewer();
viewer.setCenter(new Point3d(0, 1, 0));
viewer.addRenderable(new GLHSVShaderTest());
}
use of maspack.render.GL.GLViewerFrame in project artisynth_core by artisynth.
the class MeshDemo method main.
public static void main(String[] args) {
// create a simple box
double wx = 9;
double wy = 4;
double wz = 1;
PolygonalMesh myMesh = new PolygonalMesh();
myMesh.addVertex(new Point3d(wx / 2, wy / 2, wz / 2));
myMesh.addVertex(new Point3d(wx / 2, wy / 2, -wz / 2));
myMesh.addVertex(new Point3d(-wx / 2, wy / 2, -wz / 2));
myMesh.addVertex(new Point3d(-wx / 2, wy / 2, wz / 2));
myMesh.addVertex(new Point3d(wx / 2, -wy / 2, wz / 2));
myMesh.addVertex(new Point3d(wx / 2, -wy / 2, -wz / 2));
myMesh.addVertex(new Point3d(-wx / 2, -wy / 2, -wz / 2));
myMesh.addVertex(new Point3d(-wx / 2, -wy / 2, wz / 2));
myMesh.addFace(new int[] { 0, 1, 2, 3 });
myMesh.addFace(new int[] { 0, 3, 7, 4 });
myMesh.addFace(new int[] { 1, 0, 4, 5 });
myMesh.addFace(new int[] { 2, 1, 5, 6 });
myMesh.addFace(new int[] { 3, 2, 6, 7 });
myMesh.addFace(new int[] { 4, 7, 6, 5 });
RenderProps props = myMesh.createRenderProps();
props.setDrawEdges(true);
// gold
props.setFaceColor(new Color(0.93f, 0.8f, 0.063f));
myMesh.setRenderProps(props);
GLViewerFrame frame = new GLViewerFrame("MeshDemo", 400, 400);
frame.getViewer().addRenderable(myMesh);
frame.getViewer().autoFitPerspective();
frame.setVisible(true);
}
use of maspack.render.GL.GLViewerFrame in project artisynth_core by artisynth.
the class Test method test1.
void test1() {
GLViewerFrame frame = new GLViewerFrame("collide", 1000, 800);
frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
GLViewer vw = frame.getViewer();
frame.setVisible(true);
KeyHandler keyHandler = new KeyHandler(vw);
vw.addKeyListener(keyHandler);
vw.addRenderable(new RenderableAxes());
case2(frame);
vw.autoFit();
mesh1.setRenderBuffered(false);
// Make sure all faces are included in the hierarchies.
/*
* AjlBvTree bvh = mesh0.getBvHierarchy(); for (Face f: mesh0.getFaces())
* if (!bvh.getRoot().includesFace(f)) throw new RuntimeException("missing
* face"); bvh = mesh1.getBvHierarchy(); for (Face f: mesh1.getFaces()) if
* (!bvh.getRoot().includesFace(f)) throw new RuntimeException("missing
* face");
*/
// Make sure intersections are consistent.
/*
* MeshIntersectionConsistencyTest.testConsistency(mesh0, mesh1);
* MeshIntersectionConsistencyTest.testConsistency(mesh1, mesh0);
*/
SurfaceMeshCollider collider = new SurfaceMeshCollider();
vw.rerender();
info = collider.getContacts(mesh1, mesh2);
// if (info != null) vw.addRenderable(info);
// vw.rerender();
Vector3d pert = new Vector3d(0.00003, 0, 0);
for (int i = 0; i < 4e5; i++) {
// if (info != null) vw.removeRenderable(info);
if (mesh1.isFixed()) {
mesh1.getMeshToWorld().p.add(pert);
} else {
for (Vertex3d v : mesh1.getVertices()) v.pnt.add(pert);
}
mesh1.notifyVertexPositionsModified();
// mesh1.invalidateWorldCoords();
// mesh1.invalidateFaceNormals();
mesh1.updateFaceNormals();
info = collider.getContacts(mesh1, mesh2);
// if (info != null) vw.addRenderable(info);
vw.rerender();
}
System.out.println("test done");
// if (info != null) vw.addRenderable(info);
vw.rerender();
}
use of maspack.render.GL.GLViewerFrame in project artisynth_core by artisynth.
the class MeshColliderTest method displayContacts.
void displayContacts(PolygonalMesh m0, PolygonalMesh m1) {
final PolygonalMesh mesh0 = m0;
final PolygonalMesh mesh1 = m1;
MeshCollider collider = new MeshCollider();
final ContactInfo info = collider.getContacts(mesh0, mesh1);
// final ContactInfo info = new ContactInfo(mesh0, mesh1);
// System.out.println("intersections " + info.intersections.size());
// System.out.println("regions " + info.regions.size());
GLViewerFrame frame = new GLViewerFrame("", 512, 512);
frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
mesh0.getRenderProps().setDrawEdges(true);
// mesh0.getRenderProps().setAlpha(0.3);
mesh1.getRenderProps().setDrawEdges(true);
// mesh1.getRenderProps().setAlpha(0.3);
frame.getViewer().addRenderable(mesh0);
frame.getViewer().addRenderable(mesh1);
frame.getViewer().addRenderable(new IsRenderable() {
public int getRenderHints() {
// TODO Auto-generated method stub
return 0;
}
public void prerender(RenderList list) {
}
public void render(Renderer renderer, int flags) {
renderer.setShading(Shading.NONE);
if (info != null) {
renderer.setColor(0, 0, 1);
renderer.setPointSize(6);
ArrayList<TriTriIntersection> intersections = info.getIntersections();
if (intersections != null) {
renderer.beginDraw(DrawMode.POINTS);
for (TriTriIntersection isect : intersections) {
for (Point3d p : isect.points) {
renderer.addVertex(p);
}
}
renderer.endDraw();
}
renderer.setColor(1, 0, 0);
renderer.beginDraw(DrawMode.LINES);
for (ContactPlane region : info.getContactPlanes()) {
Point3d avg = new Point3d();
int np = 0;
for (Point3d rp : region.points) {
avg.add(rp);
np++;
}
avg.scale(1.0 / np);
renderer.addVertex(avg);
avg.add(region.normal);
renderer.addVertex(avg);
}
renderer.endDraw();
}
;
// mesh0.getObbtree().render(renderer);
// mesh1.getObbtree().render(renderer);
// ////////////////////////////
// draw mesh numbers
Vector3d avg0 = new Vector3d();
Vector3d avg1 = new Vector3d();
for (Vertex3d v : mesh0.getVertices()) avg0.add(v.pnt);
avg0.scale(1.0 / mesh0.getVertices().size());
avg0.add(mesh0.getMeshToWorld().p);
for (Vertex3d v : mesh1.getVertices()) avg1.add(v.pnt);
avg1.scale(1.0 / mesh1.getVertices().size());
avg1.add(mesh1.getMeshToWorld().p);
// GLUT glut = new GLUT();
renderer.setColor(1, 1, 1);
// gl.glRasterPos3d (avg0.x, avg0.y, avg0.z);
// glut.glutBitmapString (GLUT.BITMAP_HELVETICA_18, "0");
// gl.glRasterPos3d (avg1.x, avg1.y, avg1.z);
// glut.glutBitmapString (GLUT.BITMAP_HELVETICA_18, "1");
// draw mesh normals
// //////////////////////////////
renderer.setShading(Shading.FLAT);
}
public void updateBounds(Vector3d pmin, Vector3d pmax) {
// TODO Auto-generated method stub
}
});
frame.getViewer().rerender();
frame.getViewer().autoFit();
frame.setVisible(true);
}
Aggregations