Search in sources :

Example 1 with HueColorMap

use of maspack.render.color.HueColorMap in project artisynth_core by artisynth.

the class ColoredSphereTest method build.

@Override
public void build(String[] args) throws IOException {
    super.build(args);
    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);
    addRenderable(fm);
}
Also used : HueColorMap(maspack.render.color.HueColorMap) Vertex3d(maspack.geometry.Vertex3d) Color(java.awt.Color) RenderProps(maspack.render.RenderProps) FixedMeshBody(artisynth.core.mechmodels.FixedMeshBody) PolygonalMesh(maspack.geometry.PolygonalMesh)

Example 2 with HueColorMap

use of maspack.render.color.HueColorMap 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)

Aggregations

Color (java.awt.Color)2 PolygonalMesh (maspack.geometry.PolygonalMesh)2 Vertex3d (maspack.geometry.Vertex3d)2 RenderProps (maspack.render.RenderProps)2 HueColorMap (maspack.render.color.HueColorMap)2 FixedMeshBody (artisynth.core.mechmodels.FixedMeshBody)1