Search in sources :

Example 1 with NURBSSurface

use of maspack.geometry.NURBSSurface in project artisynth_core by artisynth.

the class NURBSViewer method addNURBS.

public void addNURBS(File file) throws IOException {
    WavefrontReader wfr = new WavefrontReader(file);
    wfr.parse();
    Vector4d[] allControlPnts = wfr.getHomogeneousPoints();
    for (WavefrontReader.Curve curve : wfr.getCurveList()) {
        NURBSCurve3d curveCopy = new NURBSCurve3d();
        try {
            curveCopy.set(curve, allControlPnts);
        } catch (IllegalArgumentException e) {
            throw new IOException(e.getMessage());
        }
        addNURBS(curveCopy);
    }
    for (WavefrontReader.Surface surf : wfr.getSurfaceList()) {
        NURBSSurface surfCopy = new NURBSSurface();
        try {
            surfCopy.set(surf, allControlPnts);
        } catch (IllegalArgumentException e) {
            throw new IOException(e.getMessage());
        }
        addNURBS(surfCopy);
    }
}
Also used : WavefrontReader(maspack.geometry.io.WavefrontReader) Vector4d(maspack.matrix.Vector4d) NURBSCurve3d(maspack.geometry.NURBSCurve3d) IOException(java.io.IOException) NURBSSurface(maspack.geometry.NURBSSurface)

Example 2 with NURBSSurface

use of maspack.geometry.NURBSSurface in project artisynth_core by artisynth.

the class NURBSViewer method addNURBSWithMesh.

public void addNURBSWithMesh(NURBSObject nurbs) {
    addNURBS(nurbs);
    if (nurbs instanceof NURBSSurface) {
        NURBSMesh mesh = new NURBSMesh();
        mesh.set((NURBSSurface) nurbs, /* triangular= */
        true);
        // mesh.setRenderEdges (true);
        Color gold = new Color(0.93f, 0.8f, 0.063f);
        RenderProps.setFaceColor(mesh, gold);
        meshTable.put(nurbs, mesh);
        System.out.println("mesh.numVerts=" + mesh.numVertices());
        viewer.addRenderable(mesh);
    }
}
Also used : Color(java.awt.Color) NURBSMesh(maspack.geometry.NURBSMesh) NURBSSurface(maspack.geometry.NURBSSurface)

Example 3 with NURBSSurface

use of maspack.geometry.NURBSSurface in project artisynth_core by artisynth.

the class NURBSViewer method main.

public static void main(String[] args) {
    StringHolder fileName = new StringHolder();
    IntHolder width = new IntHolder(400);
    IntHolder height = new IntHolder(400);
    ArgParser parser = new ArgParser("java maspack.geometry.NURBSViewer");
    parser.addOption("-width %d #width (pixels)", width);
    parser.addOption("-height %d #height (pixels)", height);
    parser.addOption("-drawAxes %v #draw coordinate axes", drawAxes);
    parser.addOption("-file %s #wavefront file name", fileName);
    parser.addOption("-sphere %v #create a NURBS sphere", addSphere);
    parser.addOption("-circle %v #create a NURBS circle", addCircle);
    parser.addOption("-mesh %v #create a mesh for surfaces", addMesh);
    parser.addOption("-collider %v #create a colliding object for meshes", collider);
    parser.addOption("-axisLength %f #coordinate axis length", axisLength);
    parser.addOption("-GLVersion %d{2,3} " + "#version of openGL for graphics", glVersion);
    parser.matchAllArgs(args);
    NURBSViewer viewFrame = null;
    try {
        GLVersion glv = (glVersion.value == 3 ? GLVersion.GL3 : GLVersion.GL2);
        viewFrame = new NURBSViewer(width.value, height.value, glv);
        GLViewer viewer = viewFrame.getViewer();
        if (fileName.value != null) {
            viewFrame.addNURBS(new File(fileName.value));
        }
        if (addSphere.value) {
            NURBSSurface sphere = new NURBSSurface();
            sphere.setSphere(0, 0, 0, 10);
            if (addMesh.value) {
                viewFrame.addNURBSWithMesh(sphere);
            } else {
                viewFrame.addNURBS(sphere);
            }
        }
        if (addCircle.value) {
            NURBSCurve3d circle = new NURBSCurve3d();
            circle.setCircle(0, 0, 10);
            viewFrame.addNURBS(circle);
        }
        viewer.autoFitPerspective();
        if (drawAxes.value) {
            if (axisLength.value > 0) {
                viewer.setAxisLength(axisLength.value);
            } else {
                viewer.setAxisLength(GLViewer.AUTO_FIT);
            }
        }
        if (collider.value) {
            viewFrame.addCollidable();
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
    viewFrame.setVisible(true);
}
Also used : GLVersion(maspack.render.GL.GLViewer.GLVersion) GLViewer(maspack.render.GL.GLViewer) StringHolder(argparser.StringHolder) NURBSCurve3d(maspack.geometry.NURBSCurve3d) IntHolder(argparser.IntHolder) ArgParser(argparser.ArgParser) File(java.io.File) IOException(java.io.IOException) NURBSSurface(maspack.geometry.NURBSSurface)

Aggregations

NURBSSurface (maspack.geometry.NURBSSurface)3 IOException (java.io.IOException)2 NURBSCurve3d (maspack.geometry.NURBSCurve3d)2 ArgParser (argparser.ArgParser)1 IntHolder (argparser.IntHolder)1 StringHolder (argparser.StringHolder)1 Color (java.awt.Color)1 File (java.io.File)1 NURBSMesh (maspack.geometry.NURBSMesh)1 WavefrontReader (maspack.geometry.io.WavefrontReader)1 Vector4d (maspack.matrix.Vector4d)1 GLViewer (maspack.render.GL.GLViewer)1 GLVersion (maspack.render.GL.GLViewer.GLVersion)1