use of maspack.geometry.PolygonalMesh in project artisynth_core by artisynth.
the class OpenSimAscReader method readMesh.
public PolygonalMesh readMesh(PolygonalMesh mesh) throws IOException {
if (mesh == null) {
mesh = new PolygonalMesh();
} else {
mesh.clear();
}
ReaderTokenizer rtok = new ReaderTokenizer(new InputStreamReader(myIstream));
rtok.eolIsSignificant(false);
boolean oldFormat = false;
int nVertices = 0;
int nFaces = 0;
double[] tmp = new double[6];
int nReadVals = 6;
// read first symbol, which should be NORM_ASCII or a number of vertices
if (rtok.nextToken() != ReaderTokenizer.TT_WORD) {
if (rtok.ttype == ReaderTokenizer.TT_NUMBER) {
oldFormat = true;
nReadVals = 3;
nVertices = (int) rtok.nval;
} else {
throw new IOException("Expected " + ReaderTokenizer.TT_WORD + " on line " + rtok.lineno());
}
}
if (!oldFormat) {
String type = rtok.sval;
if (type.compareTo("NORM_ASCII") != 0) {
throw new IOException("Unknown file type: " + type);
}
if (rtok.nextToken() != ReaderTokenizer.TT_NUMBER) {
throw new IOException("Expected " + ReaderTokenizer.TT_NUMBER + " on line " + rtok.lineno());
}
nVertices = (int) rtok.nval;
}
if (rtok.nextToken() != ReaderTokenizer.TT_NUMBER) {
throw new IOException("Expected " + ReaderTokenizer.TT_NUMBER + " on line " + rtok.lineno());
}
nFaces = (int) rtok.nval;
if (!oldFormat) {
// bounding box
int iRead = rtok.scanNumbers(tmp, 6);
if (iRead != 6) {
throw new IOException("Expected bounding box on line " + rtok.lineno());
}
}
// load all vertices now
for (int i = 0; i < nVertices; i++) {
int nRead = rtok.scanNumbers(tmp, nReadVals);
if (nRead != nReadVals) {
throw new IOException("Expected number of values on line " + rtok.lineno());
}
mesh.addVertex(tmp[0], tmp[1], tmp[2]);
}
// load all faces
for (int i = 0; i < nFaces; i++) {
int nV = (int) rtok.scanNumber();
int[] face = new int[nV];
if (scanIntegers(rtok, face, nV) != nV) {
throw new IOException("Expected number of vertices on line " + rtok.lineno());
}
if (oldFormat) {
for (int j = 0; j < nV; j++) {
// start indices at zero
face[j] -= 1;
}
}
mesh.addFace(face);
}
return mesh;
}
use of maspack.geometry.PolygonalMesh in project artisynth_core by artisynth.
the class MultiViewerTesterBase method loadStanfordBunny.
protected static PolygonalMesh loadStanfordBunny() {
// read Standford bunny directly
String bunnyURL = "http://graphics.stanford.edu/~mdfisher/Data/Meshes/bunny.obj";
// bunny
File bunnyFile = new File("tmp/data/stanford_bunny.obj");
PolygonalMesh bunny = null;
try {
if (!bunnyFile.exists()) {
bunnyFile.getParentFile().mkdirs();
// read file directly from remote
FileCacher cacher = new FileCacher();
cacher.initialize();
cacher.cache(new URIx(bunnyURL), bunnyFile);
cacher.release();
}
WavefrontReader reader = new WavefrontReader(bunnyFile);
bunny = new PolygonalMesh();
reader.readMesh(bunny);
// bunny.computeVertexNormals();
// normalize bunny
double r = bunny.computeRadius();
Vector3d c = new Vector3d();
bunny.computeCentroid(c);
c.negate();
bunny.scale(1.0 / r);
c.z -= 0.5;
bunny.transform(new RigidTransform3d(c, new AxisAngle(1, 0, 0, Math.PI / 2)));
reader.close();
} catch (IOException e1) {
e1.printStackTrace();
System.out.println("Unable to load stanford bunny... requires internet connection");
bunny = null;
}
return bunny;
}
use of maspack.geometry.PolygonalMesh in project artisynth_core by artisynth.
the class SingleGL2Tester method addRenderObjects.
protected static void addRenderObjects(MultiViewer tester) {
addCube(tester);
addAxes(tester);
addTransRotator(tester);
addCylinder(tester);
PolygonalMesh bunny = loadStanfordBunny();
addStanfordBunnies(tester, bunny);
addSolidBunny(tester, bunny);
addHalfBunny(tester, bunny);
}
use of maspack.geometry.PolygonalMesh in project artisynth_core by artisynth.
the class SingleGL3Tester method addRenderObjects.
protected static void addRenderObjects(MultiViewer tester) {
addCube(tester);
addAxes(tester);
addTransRotator(tester);
addCylinder(tester);
PolygonalMesh bunny = loadStanfordBunny();
addStanfordBunnies(tester, bunny);
addSolidBunny(tester, bunny);
addHalfBunny(tester, bunny);
}
use of maspack.geometry.PolygonalMesh in project artisynth_core by artisynth.
the class TextureEgyptianTest method addContent.
@Override
protected void addContent(MultiViewer mv) {
JFrame frame = new JFrame();
JPanel controls = new JPanel();
frame.add(controls);
PolygonalMesh plane = MeshFactory.createRectangle(4000, 400, 32, 8, /*texture=*/
true);
RenderProps rprops = plane.getRenderProps();
if (rprops == null) {
rprops = new RenderProps();
}
rprops.setShading(Shading.SMOOTH);
rprops.setShininess(20);
rprops.setFaceColor(new Color(155, 196, 30));
rprops.setSpecular(new Color(255, 113, 0));
rprops.setFaceStyle(FaceStyle.FRONT_AND_BACK);
plane.transform(new RigidTransform3d(Vector3d.ZERO, AxisAngle.ROT_X_90));
String srcDir = PathFinder.findSourceDir(this);
ColorMapProps dprops = new ColorMapProps();
dprops.setFileName(srcDir + "/data/specular_map.jpg");
dprops.setColorMixing(ColorMixing.MODULATE);
dprops.setEnabled(true);
NormalMapProps normalProps = new NormalMapProps();
normalProps.setFileName(srcDir + "/data/foil_normal_map2.png");
normalProps.setScaling(0.3f);
normalProps.setEnabled(true);
BumpMapProps bumpProps = new BumpMapProps();
bumpProps.setFileName(srcDir + "/data/egyptian_friz_2.png");
bumpProps.setScaling(2.5f);
bumpProps.setEnabled(true);
rprops.setColorMap(dprops);
rprops.setNormalMap(normalProps);
rprops.setBumpMap(bumpProps);
// FixedMeshBody fm = new FixedMeshBody(plane);
// fm.setRenderProps(rprops);
mv.addRenderable(plane);
if (false) {
mv.addRenderable(new IsRenderable() {
@Override
public void updateBounds(Vector3d pmin, Vector3d pmax) {
Point3d.X_UNIT.updateBounds(pmin, pmax);
Point3d.Y_UNIT.updateBounds(pmin, pmax);
Point3d.Z_UNIT.updateBounds(pmin, pmax);
Point3d.NEG_X_UNIT.updateBounds(pmin, pmax);
Point3d.NEG_Y_UNIT.updateBounds(pmin, pmax);
Point3d.NEG_Z_UNIT.updateBounds(pmin, pmax);
}
@Override
public void render(Renderer renderer, int flags) {
renderer.setColor(Color.CYAN);
renderer.setFaceStyle(FaceStyle.FRONT_AND_BACK);
renderer.drawSphere(Point3d.ZERO, 1);
}
@Override
public void prerender(RenderList list) {
// TODO Auto-generated method stub
}
@Override
public int getRenderHints() {
// TODO Auto-generated method stub
return 0;
}
});
}
mv.autoFitViewers();
LabeledComponentBase base = PropertyWidget.create("Color texture", rprops.getColorMap(), "enabled");
controls.add(base);
base = PropertyWidget.create("Normal map", rprops.getNormalMap(), "enabled");
controls.add(base);
base = PropertyWidget.create("Bump map", rprops.getBumpMap(), "enabled");
controls.add(base);
base = PropertyWidget.create("Specular", rprops.getColorMap(), "specularColoring");
controls.add(base);
base = PropertyWidget.create("Bump map scale", rprops.getBumpMap(), "scaling");
controls.add(base);
base = PropertyWidget.create("Normal map scale", rprops.getNormalMap(), "scaling");
controls.add(base);
frame.pack();
frame.setVisible(true);
}
Aggregations