Search in sources :

Example 41 with RenderProps

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

the class TextureHeartTest method addContent.

@Override
protected void addContent(MultiViewer mv) {
    JFrame frame = new JFrame();
    JPanel controls = new JPanel();
    frame.add(controls);
    String heartObjFilename = PathFinder.findSourceDir(this) + "/data/heart/HumanHeart.obj";
    WavefrontReader reader = null;
    try {
        reader = new WavefrontReader(new File(heartObjFilename));
        PolygonalMesh mesh = reader.readMesh();
        RenderProps rprops = mesh.getRenderProps();
        if (rprops == null) {
            rprops = new RenderProps();
        }
        rprops.setShading(Shading.SMOOTH);
        rprops.setFaceColor(new Color(0.8f, 0.8f, 0.8f));
        rprops.getColorMap().setColorMixing(ColorMixing.MODULATE);
        rprops.setSpecular(new Color(0.4f, 0.4f, 0.4f));
        rprops.getBumpMap().setScaling(0.5f);
        rprops.setShininess(128);
        // mesh.setRenderProps(rprops);
        // FixedMeshBody fm = new FixedMeshBody (mesh);
        // fm.setRenderProps (mesh.getRenderProps ());
        // RenderProps rprops = mesh.getRenderProps();
        LabeledComponentBase base = PropertyWidget.create("Map", rprops.getColorMap(), "enabled");
        controls.add(base);
        base = PropertyWidget.create("Bump map", rprops.getBumpMap(), "enabled");
        controls.add(base);
        base = PropertyWidget.create("Lighting", rprops, "shading");
        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);
        mv.addRenderable(mesh);
    } catch (IOException e) {
        e.printStackTrace();
    }
    if (reader != null) {
        reader.close();
    }
    mv.autoFitViewers();
    frame.pack();
    frame.setVisible(true);
}
Also used : WavefrontReader(maspack.geometry.io.WavefrontReader) JPanel(javax.swing.JPanel) JFrame(javax.swing.JFrame) Color(java.awt.Color) RenderProps(maspack.render.RenderProps) LabeledComponentBase(maspack.widgets.LabeledComponentBase) IOException(java.io.IOException) File(java.io.File) PolygonalMesh(maspack.geometry.PolygonalMesh)

Example 42 with RenderProps

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

the class TriangleLightingTest 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.WHITE);
            props.setBackColor(Color.WHITE);
            renderer.setFaceColoring(props, /*highlight=*/
            false);
            renderer.setShading(Shading.SMOOTH);
            renderer.setFaceStyle(FaceStyle.FRONT_AND_BACK);
            renderer.setColor(props.getFaceColorF());
            renderer.setBackColor(props.getBackColorF());
            renderer.drawTriangle(new float[] { 1, 1, 0 }, new float[] { -1, 1, 0 }, new float[] { -1, -1, 0 });
            renderer.drawTriangle(new float[] { -1, -1, 0 }, new float[] { 1, -1, 0 }, new float[] { 1, 1, 0 });
            renderer.setDepthOffset(1);
            renderer.drawAxes(RigidTransform3d.IDENTITY, 1, 1, false);
            renderer.setDepthOffset(0);
        }

        @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);
    mv.setAxialView(AxisAlignedRotation.X_Y);
}
Also used : SimpleSelectable(maspack.test.GL.MultiViewer.SimpleSelectable) Vector3d(maspack.matrix.Vector3d) RenderProps(maspack.render.RenderProps) Renderer(maspack.render.Renderer) RenderList(maspack.render.RenderList) LinkedList(java.util.LinkedList)

Example 43 with RenderProps

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

the class VolumePrimitivesTest 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);
            props.setBackColor(Color.MAGENTA);
            renderer.setFaceColoring(props, /*highlight=*/
            false);
            renderer.setColor(props.getFaceColorF());
            renderer.setBackColor(props.getBackColorF());
            renderer.setFaceStyle(FaceStyle.FRONT_AND_BACK);
            // renderer.drawSphere (new float[] {0.1f,0.2f,0.3f}, 0.05);
            // renderer.drawSpindle (new float[]{-0.1f,-0.2f,-0.3f}, new float[]{-0.3f,-0.2f,-0.1f}, 0.05);
            // renderer.drawSpindle (new float[]{0.1f,-0.2f,0.3f}, new float[]{0.3f,-0.2f,0.1f}, 0.25);
            // renderer.drawCylinder (new float[]{-0.1f,0.2f,-0.3f}, new float[]{-0.3f,0.2f,-0.1f}, 0.3, true);
            // renderer.drawCylinder (new float[]{0.1f,0.2f,-0.3f}, new float[]{-0.3f,-0.2f,-0.3f}, 0.2, true);
            // renderer.drawCone (new float[]{-0.1f,0.2f,0.3f}, new float[]{0.3f,0.2f,-0.1f}, 0.1, 0, false);
            // renderer.drawCone (new float[]{-0.3f,0.2f,0.3f}, new float[]{0.5f,0.2f,-0.1f}, 0, 0.2, true);
            // renderer.drawSphere (new float[]{-0.1f,-0.2f,-0.3f}, 0.2);
            // renderer.drawSphere (new float[] {0.1f,0.2f,0.3f}, 0.02);
            // renderer.drawSphere (new float[] {0.1f,0.2f,0.6f}, 0.03);
            // renderer.drawSphere (new float[] {0.1f,0.2f,0.8f}, 0.04);
            // renderer.drawSphere (new float[] {0.1f,0.2f,1f}, 0.05);
            // renderer.drawCone (new float[]{0.1f,0.1f,-0.1f}, new float[]{0.3f,0.1f,-0.1f}, 0.05, 0.02, true);
            renderer.drawCube(new float[] { -0.2f, -0.2f, -0.2f }, 0.5);
        }

        @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) RenderList(maspack.render.RenderList) LinkedList(java.util.LinkedList)

Example 44 with RenderProps

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

the class ColouredSphereTest method addContent.

@Override
protected void addContent(MultiViewer mv) {
    PolygonalMesh mesh = MeshFactory.createOctahedralSphere(1, 4);
    HueColorMap map = new HueColorMap();
    mesh.setVertexColoringEnabled();
    for (int i = 0; i < mesh.numVertices(); ++i) {
        // hsv interpolation of colors based on height (-1 to 1)
        Vertex3d vtx = mesh.getVertex(i);
        double pos = vtx.getPosition().z;
        Color c = map.getColor((pos + 1) / 2);
        mesh.setColor(i, c);
    }
    RenderProps rprops = new RenderProps();
    rprops.setShading(Shading.SMOOTH);
    rprops.setShininess(128);
    rprops.setSpecular(Color.WHITE);
    mesh.setRenderProps(rprops);
    // FixedMeshBody fm = new FixedMeshBody (mesh);
    mv.addRenderable(mesh);
}
Also used : HueColorMap(maspack.render.color.HueColorMap) Vertex3d(maspack.geometry.Vertex3d) Color(java.awt.Color) RenderProps(maspack.render.RenderProps) PolygonalMesh(maspack.geometry.PolygonalMesh)

Example 45 with RenderProps

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

the class CollisionManager method createRenderProps.

// ===== RenderableComponent methods ======
public RenderProps createRenderProps() {
    RenderProps props = RenderProps.createRenderProps(this);
    props.setVisible(false);
    return props;
}
Also used : RenderProps(maspack.render.RenderProps)

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