use of maspack.geometry.PolygonalMesh in project artisynth_core by artisynth.
the class MayaAsciiReader method getPolygonalMesh.
public PolygonalMesh getPolygonalMesh(Node<MayaNode> root, UnitInfo units) {
if (units == null) {
units = defaultUnits;
}
PolygonalMesh mesh = new PolygonalMesh();
AffineTransform3d trans = new AffineTransform3d();
recursiveBuildParentTransform(root, trans, units);
recursiveAddPolygonalMeshes(root, mesh, trans, units);
return mesh;
}
use of maspack.geometry.PolygonalMesh in project artisynth_core by artisynth.
the class OffReader method buildMesh.
private static PolygonalMesh buildMesh(PolygonalMesh mesh, ArrayList<Point3d> nodes, ArrayList<ArrayList<Integer>> faces) {
if (mesh == null) {
mesh = new PolygonalMesh();
} else {
mesh.clear();
}
Point3d[] pnts = new Point3d[nodes.size()];
int[][] faceIndices = new int[faces.size()][];
for (int i = 0; i < nodes.size(); i++) {
pnts[i] = nodes.get(i);
}
ArrayList<Integer> face;
for (int i = 0; i < faces.size(); i++) {
face = faces.get(i);
faceIndices[i] = new int[face.size()];
for (int j = 0; j < face.size(); j++) {
faceIndices[i][j] = face.get(j);
}
}
mesh.set(pnts, faceIndices);
return mesh;
}
use of maspack.geometry.PolygonalMesh in project artisynth_core by artisynth.
the class GtsReader method readMesh.
public PolygonalMesh readMesh(PolygonalMesh mesh) throws IOException {
if (mesh == null) {
mesh = new PolygonalMesh();
} else {
mesh.clear();
}
ReaderTokenizer rtok = new ReaderTokenizer(new BufferedReader(new InputStreamReader(myIstream)));
rtok.commentChar('!');
rtok.commentChar('#');
rtok.eolIsSignificant(true);
int numVerts = rtok.scanInteger();
int numEdges = rtok.scanInteger();
int numFaces = rtok.scanInteger();
while (rtok.nextToken() != ReaderTokenizer.TT_EOL) ;
ArrayList<Edge> edgeList = new ArrayList<Edge>();
for (int i = 0; i < numVerts; i++) {
double x = rtok.scanNumber();
double y = rtok.scanNumber();
double z = rtok.scanNumber();
mesh.addVertex(new Point3d(x, y, z));
while (rtok.nextToken() != ReaderTokenizer.TT_EOL) ;
}
ArrayList<Vertex3d> verts = mesh.getVertices();
for (int i = 0; i < numEdges; i++) {
int idx1 = rtok.scanInteger() - 1;
int idx2 = rtok.scanInteger() - 1;
if (idx1 < 0 || idx1 >= numVerts) {
System.out.println("Error: vertex " + idx1 + " out of range, " + rtok);
System.exit(1);
}
if (idx2 < 0 || idx2 >= numVerts) {
System.out.println("Error: vertex " + idx2 + " out of range, " + rtok);
System.exit(1);
}
edgeList.add(new Edge(verts.get(idx1), verts.get(idx2)));
while (rtok.nextToken() != ReaderTokenizer.TT_EOL) ;
}
for (int i = 0; i < numFaces; i++) {
ArrayList<Edge> edges = new ArrayList<Edge>();
while (rtok.nextToken() == ReaderTokenizer.TT_NUMBER) {
if (!rtok.tokenIsInteger()) {
System.out.println("Error: edge index expected, " + rtok);
System.exit(1);
}
int idx = (int) rtok.lval - 1;
if (idx < 0 || idx >= edgeList.size()) {
System.out.println("Error: edge index " + idx + " out of range, " + rtok);
System.exit(1);
}
edges.add(edgeList.get(idx));
}
int[] idxs = getFaceIndices(edges);
if (idxs == null) {
System.out.println("Error: face edges are not adjacent, " + rtok);
}
mesh.addFace(idxs);
rtok.pushBack();
while (rtok.nextToken() != ReaderTokenizer.TT_EOL) ;
}
return mesh;
}
use of maspack.geometry.PolygonalMesh in project artisynth_core by artisynth.
the class EditorUtils method saveMesh.
public static void saveMesh(MeshBase mesh, AffineTransform3dBase X) {
Main main = Main.getMain();
JFrame frame = main.getMainFrame();
if (mesh == null) {
showError(frame, "Component does not have a mesh");
return;
}
if (X != null) {
mesh = mesh.copy();
mesh.transform(X);
}
JFileChooser chooser = new JFileChooser();
chooser.setCurrentDirectory(main.getModelDirectory());
int retVal = chooser.showSaveDialog(frame);
if (retVal == JFileChooser.APPROVE_OPTION) {
File file = chooser.getSelectedFile();
try {
if (mesh instanceof PolygonalMesh) {
GenericMeshWriter writer = new GenericMeshWriter(file);
writer.writeMesh(mesh);
writer.close();
} else {
PrintWriter pw = new PrintWriter(new BufferedOutputStream(new FileOutputStream(file)));
mesh.write(pw, "%.8g");
pw.close();
}
} catch (Exception ex) {
ex.printStackTrace();
showError(frame, "Error saving file: " + ex.getMessage());
}
main.setModelDirectory(chooser.getCurrentDirectory());
}
}
use of maspack.geometry.PolygonalMesh in project artisynth_core by artisynth.
the class FemModel3dAgent method actionPerformed.
public void actionPerformed(ActionEvent evt) {
String cmd = evt.getActionCommand();
if (cmd.equals("Add")) {
ViewerManager viewerMan = myMain.getWorkspace().getViewerManager();
viewerMan.removeRenderable(fem.getSurfaceMesh());
viewerMan.removeDragger(rotator);
rotator = null;
setProperties(fem, getPrototypeComponent(myComponentType));
// basicPropTree.setTreeValuesInHost (
// fem, getPrototypeComponent (myComponentType));
// myPropTree.setTreeValuesInHost (
// fem, getPrototypeComponent (myComponentType));
setProperties(myPrototype, myPrototype);
PolygonalMesh mesh = fem.getSurfaceMesh();
mesh.setRenderProps(mesh.createRenderProps());
mesh.setMeshToWorld(RigidTransform3d.IDENTITY);
mesh.setFixed(false);
mesh.setColorsFixed(false);
RigidTransform3d rigidX = new RigidTransform3d();
rigidX.p.set(positionField.getVectorValue());
rigidX.R.setAxisAngle(orientationField.getAxisAngleValue());
AffineTransform3d X = new AffineTransform3d();
X.set(rigidX);
Object scale = scaleField.getValue();
resetScaling();
double sx = 1, sy = 1, sz = 1;
if (scale instanceof Double) {
sx = sy = sz = (Double) scale;
} else if (scale instanceof Vector3d) {
sx = ((Vector3d) scale).x;
sy = ((Vector3d) scale).y;
sz = ((Vector3d) scale).z;
}
X.applyScaling(sx, sy, sz);
fem.transformGeometry(X);
addComponent(new AddComponentsCommand("add FemModel3d", fem, myContainer));
myDisplay.setVisible(false);
dispose();
} else if (cmd.equals("Clear")) {
maskAllValueChangeListeners(true);
restoreDefaultValues();
myHostList.restoreBackupValues();
myPropertyPanel.updateWidgetValues();
// basicHostList.restoreBackupValues();
// moreHostList.restoreBackupValues();
// basicPropsPanel.updateWidgetValues();
// morePropsPanel.updateWidgetValues();
disposePreviewModel();
resetState();
maskAllValueChangeListeners(false);
updateMeshPanel();
updateState();
} else if (cmd.equals("Cancel")) {
disposePreviewModel();
myDisplay.setVisible(false);
dispose();
} else if (evt.getSource() == autoScaleBtn) {
if (fem != null) {
updateScale();
}
} else {
super.actionPerformed(evt);
}
}
Aggregations