Search in sources :

Example 36 with RenderProps

use of maspack.render.RenderProps in project artisynth_core by artisynth.

the class MultiViewerTesterBase method addStanfordBunnies.

protected static void addStanfordBunnies(MultiViewer tester, PolygonalMesh bunny) {
    RenderProps rprops = new RenderProps();
    rprops.setFaceStyle(FaceStyle.FRONT_AND_BACK);
    rprops.setShading(Shading.SMOOTH);
    rprops.setFaceColor(Color.WHITE.darker());
    rprops.setBackColor(Color.BLUE);
    rprops.setLineColor(Color.ORANGE);
    rprops.setSpecular(Color.WHITE);
    rprops.setShininess(1000);
    // rprops.setPointSlices(24);
    // rprops.setLineSlices(24);
    rprops.setShading(Shading.SMOOTH);
    if (bunny != null) {
        // one bunny
        RenderObject bunnyRO;
        RenderObjectWrapper rbunny;
        bunnyRO = RenderObjectFactory.createFromMesh(bunny, rprops.getShading() == Shading.FLAT, rprops.getDrawEdges());
        rbunny = new RenderObjectWrapper(bunnyRO);
        rbunny.setTransform(new RigidTransform3d(new Vector3d(-0.707, 0.707, 0), AxisAngle.IDENTITY));
        rbunny.setRenderProps(rprops);
        tester.addRenderable(rbunny);
        // two bunny
        bunnyRO = RenderObjectFactory.createFromMesh(bunny, rprops.getShading() == Shading.FLAT, true);
        rbunny = new RenderObjectWrapper(bunnyRO);
        rbunny.setTransform(new RigidTransform3d(new Vector3d(0.707, -0.707, 0), AxisAngle.IDENTITY));
        rbunny.setRenderProps(new RenderProps(rprops));
        rbunny.getRenderProps().setDrawEdges(true);
        rbunny.getRenderProps().setFaceColor(new Color(175, 153, 128));
        rbunny.getRenderProps().setEdgeColor(new Color(175, 153, 128).darker());
        tester.addRenderable(rbunny);
    }
}
Also used : RigidTransform3d(maspack.matrix.RigidTransform3d) Vector3d(maspack.matrix.Vector3d) Color(java.awt.Color) RenderProps(maspack.render.RenderProps) RenderObject(maspack.render.RenderObject)

Example 37 with RenderProps

use of maspack.render.RenderProps in project artisynth_core by artisynth.

the class MultiViewerTesterBase method addSolidBunny.

protected static void addSolidBunny(MultiViewer tester, PolygonalMesh bunny) {
    RenderProps rprops = new RenderProps();
    rprops.setFaceStyle(FaceStyle.FRONT_AND_BACK);
    rprops.setShading(Shading.SMOOTH);
    rprops.setFaceColor(new Color(20, 20, 20));
    rprops.setBackColor(Color.MAGENTA.darker());
    rprops.setLineColor(Color.ORANGE);
    rprops.setPointColor(Color.PINK);
    rprops.setSpecular(Color.WHITE);
    rprops.setShininess(1000);
    // rprops.setPointSlices(24);
    // rprops.setLineSlices(24);
    rprops.setShading(Shading.SMOOTH);
    rprops.setPointStyle(PointStyle.SPHERE);
    rprops.setLineStyle(LineStyle.SOLID_ARROW);
    rprops.setLineRadius(0.001);
    rprops.setPointRadius(0.005);
    if (bunny != null) {
        // one bunny
        RenderObject bunnyRO;
        RenderObjectWrapper rbunny;
        bunnyRO = RenderObjectFactory.createFromMesh(bunny, rprops.getShading() == Shading.FLAT, true);
        // vertices
        for (int i = 0; i < bunnyRO.numVertices(); ++i) {
            bunnyRO.addPoint(i);
        }
        rbunny = new RenderObjectWrapper(bunnyRO);
        rbunny.setTransform(new RigidTransform3d(new Vector3d(0, 0, 0), AxisAngle.IDENTITY));
        rbunny.setRenderProps(rprops);
        tester.addRenderable(rbunny);
    }
}
Also used : RigidTransform3d(maspack.matrix.RigidTransform3d) Vector3d(maspack.matrix.Vector3d) Color(java.awt.Color) RenderProps(maspack.render.RenderProps) RenderObject(maspack.render.RenderObject)

Example 38 with RenderProps

use of maspack.render.RenderProps in project artisynth_core by artisynth.

the class MultiViewerTesterBase method addCylinder.

protected static void addCylinder(MultiViewer tester) {
    // cylinder
    RenderObject cylinderRO = RenderObjectFactory.createCylinder(32, true);
    RenderObjectWrapper rcylinder = new RenderObjectWrapper(cylinderRO);
    AffineTransform3d cscale = new AffineTransform3d();
    cscale.setTranslation(0.3, 0.3, 0);
    cscale.setRotation(new AxisAngle(1d / Math.sqrt(2), -1d / Math.sqrt(2), 0, Math.PI / 8));
    cscale.applyScaling(0.05, 0.05, 1.0);
    rcylinder.setTransform(cscale);
    RenderProps rprops2 = rcylinder.getRenderProps();
    rprops2.setFaceColor(Color.CYAN);
    rprops2.setShading(Shading.SMOOTH);
    tester.addRenderable(rcylinder);
}
Also used : AxisAngle(maspack.matrix.AxisAngle) RenderProps(maspack.render.RenderProps) RenderObject(maspack.render.RenderObject) AffineTransform3d(maspack.matrix.AffineTransform3d)

Example 39 with RenderProps

use of maspack.render.RenderProps in project artisynth_core by artisynth.

the class MultiViewerTesterBase method addHalfBunny.

protected static void addHalfBunny(MultiViewer tester, PolygonalMesh bunny) {
    RenderProps rprops = new RenderProps();
    rprops.setFaceStyle(FaceStyle.FRONT_AND_BACK);
    rprops.setShading(Shading.SMOOTH);
    rprops.setBackColor(Color.MAGENTA.darker());
    rprops.setSpecular(Color.WHITE);
    rprops.setShininess(1000);
    if (bunny != null) {
        RenderObject r = new RenderObject();
        // add all appropriate info
        for (Vertex3d vtx : bunny.getVertices()) {
            Point3d pos = vtx.getPosition();
            r.addPosition((float) pos.x, (float) pos.y, (float) pos.z);
        }
        for (Vector3d nrm : bunny.getNormals()) {
            r.addNormal((float) nrm.x, (float) nrm.y, (float) nrm.z);
        }
        int[] nidxs = bunny.getNormalIndices();
        // left
        r.createTriangleGroup();
        // right
        r.createTriangleGroup();
        // build faces
        List<Face> faces = bunny.getFaces();
        int[] indexOffs = bunny.getFeatureIndexOffsets();
        Vector3d centroid = new Vector3d();
        for (int i = 0; i < faces.size(); i++) {
            Face f = faces.get(i);
            int foff = indexOffs[f.idx];
            int[] pidxs = f.getVertexIndices();
            // vertex indices
            int[] vidxs = new int[pidxs.length];
            for (int j = 0; j < pidxs.length; j++) {
                // only add if unique combination
                vidxs[j] = r.addVertex(pidxs[j], nidxs[foff + j], -1, -1);
            }
            // triangle fan for faces
            f.computeCentroid(centroid);
            if (centroid.x < centroid.y) {
                r.triangleGroup(0);
            } else {
                r.triangleGroup(1);
            }
            r.addTriangleFan(vidxs);
        }
        MultiTriangleGroupWrapper rbunny = new MultiTriangleGroupWrapper(r);
        rbunny.setTransform(new RigidTransform3d(new Vector3d(1.3, 1.3, 0.5), AxisAngle.IDENTITY));
        rbunny.setRenderProps(rprops);
        rbunny.setFaceColors(Color.RED, Color.BLUE);
        tester.addRenderable(rbunny);
    }
}
Also used : Vertex3d(maspack.geometry.Vertex3d) RigidTransform3d(maspack.matrix.RigidTransform3d) Vector3d(maspack.matrix.Vector3d) Point3d(maspack.matrix.Point3d) RenderProps(maspack.render.RenderProps) RenderObject(maspack.render.RenderObject) Face(maspack.geometry.Face)

Example 40 with RenderProps

use of maspack.render.RenderProps in project artisynth_core by artisynth.

the class PrimitivesTest method addContent.

@Override
protected void addContent(MultiViewer mv) {
    SimpleSelectable renderable = new SimpleSelectable() {

        RenderProps props = new RenderProps();

        @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) {
            props.setFaceColor(Color.CYAN);
            renderer.setFaceColoring(props, false);
            renderer.setColor(props.getFaceColorF());
            Shading savedShading = renderer.setShading(Shading.NONE);
            renderer.setPointSize(20f);
            renderer.drawPoint(new float[] { 0.1f, 0.2f, 0.3f });
            renderer.setLineWidth(20f);
            renderer.drawLine(new float[] { -0.1f, -0.2f, -0.3f }, new float[] { -0.3f, -0.2f, -0.1f });
            renderer.setShading(savedShading);
            renderer.drawTriangle(new float[] { 0.1f, 0.1f, -0.1f }, new float[] { 0.3f, 0.1f, -0.1f }, new float[] { 0.1f, 0.3f, -0.1f });
        }

        @Override
        public void prerender(RenderList list) {
        }

        @Override
        public int getRenderHints() {
            return 0;
        }

        @Override
        public int numSelectionQueriesNeeded() {
            return 0;
        }

        @Override
        public boolean isSelectable() {
            return false;
        }

        @Override
        public void getSelection(LinkedList<Object> list, int qid) {
        }

        @Override
        public void setSelected(boolean set) {
        }

        @Override
        public boolean isSelected() {
            // TODO Auto-generated method stub
            return false;
        }
    };
    mv.addRenderable(renderable);
}
Also used : SimpleSelectable(maspack.test.GL.MultiViewer.SimpleSelectable) Vector3d(maspack.matrix.Vector3d) RenderProps(maspack.render.RenderProps) Renderer(maspack.render.Renderer) Shading(maspack.render.Renderer.Shading) RenderList(maspack.render.RenderList) LinkedList(java.util.LinkedList)

Aggregations

RenderProps (maspack.render.RenderProps)86 Color (java.awt.Color)17 Vector3d (maspack.matrix.Vector3d)17 RigidBody (artisynth.core.mechmodels.RigidBody)11 RigidTransform3d (maspack.matrix.RigidTransform3d)11 Shading (maspack.render.Renderer.Shading)10 PolygonalMesh (maspack.geometry.PolygonalMesh)8 Point3d (maspack.matrix.Point3d)8 RenderObject (maspack.render.RenderObject)7 FrameMarker (artisynth.core.mechmodels.FrameMarker)6 File (java.io.File)6 IOException (java.io.IOException)6 Vertex3d (maspack.geometry.Vertex3d)6 AffineTransform3d (maspack.matrix.AffineTransform3d)4 ColorMapProps (maspack.render.ColorMapProps)4 HasRenderProps (maspack.render.HasRenderProps)4 LineRenderProps (maspack.render.LineRenderProps)4 AxialSpring (artisynth.core.mechmodels.AxialSpring)3 Muscle (artisynth.core.mechmodels.Muscle)3 LinkedList (java.util.LinkedList)3