Search in sources :

Example 6 with Renderable

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

the class RootModel method prerender.

// implementations for Renderable
public void prerender(RenderList list) {
    for (Controller c : myControllers) {
        if (c instanceof Renderable) {
            list.addIfVisible((Renderable) c);
        }
    }
    for (Model m : myModels) {
        if (m instanceof Renderable) {
            list.addIfVisible((Renderable) m);
        }
    }
    for (Monitor m : myMonitors) {
        if (m instanceof Renderable) {
            list.addIfVisible((Renderable) m);
        }
    }
    list.addIfVisible(myOutputProbes);
    list.addIfVisible(myInputProbes);
    list.addIfVisible(myRenderables);
}
Also used : Renderable(maspack.render.Renderable) IsRenderable(maspack.render.IsRenderable) Monitor(artisynth.core.modelbase.Monitor) Model(artisynth.core.modelbase.Model) Controller(artisynth.core.modelbase.Controller)

Example 7 with Renderable

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

the class CSGCubeTest method build.

@Override
public void build(String[] args) throws IOException {
    super.build(args);
    PolygonalMesh cube1 = MeshFactory.createBox(1, 1, 1);
    PolygonalMesh cube2 = MeshFactory.createBox(0.5, 0.5, 0.5);
    cube2.transform(new RigidTransform3d(new Vector3d(0.25, 0.25, 0.25), AxisAngle.IDENTITY));
    cube1.setHardEdgesFromFaceNormals(0.707);
    cube2.setHardEdgesFromFaceNormals(0.707);
    PolygonalMesh isect = MeshFactory.getIntersection(cube1, cube2);
    isect.setHardEdgesFromFaceNormals(0.707);
    PolygonalMesh sub = MeshFactory.getSubtraction(cube1, cube2);
    sub.setHardEdgesFromFaceNormals(0.707);
    PolygonalMesh union = MeshFactory.getUnion(cube1, cube2);
    union.setHardEdgesFromFaceNormals(0.707);
    addRenderable(new FixedMeshBody("cube1", cube1));
    addRenderable(new FixedMeshBody("cube2", cube2));
    addRenderable(new FixedMeshBody("intersection", isect));
    addRenderable(new FixedMeshBody("subtraction", sub));
    addRenderable(new FixedMeshBody("union", union));
    for (Renderable r : renderables()) {
        if (r instanceof FixedMeshBody) {
            FixedMeshBody fmesh = (FixedMeshBody) r;
            PolygonalMesh mesh = (PolygonalMesh) (fmesh.getMesh());
            System.out.println("Mesh: " + fmesh.getName());
            System.out.println("  # verts: " + mesh.numVertices());
            System.out.println("  # faces: " + mesh.numFaces());
            System.out.println("  closed:  " + mesh.isClosed());
            System.out.println("  manifo:  " + mesh.isManifold());
            System.out.println("  area:    " + mesh.computeArea());
            System.out.println("  volume:  " + mesh.computeVolume());
        }
    }
    // PolygonalMesh cube3 = new PolygonalMesh(cube1);
    // cube3 = MeshFactory.subdivide(cube3);
    // cube3.mergeCoplanarFaces(0.99);
    // for (Face f : cube3.getFaces()) {
    // System.out.println(f.getIndex() + ", " + f.numEdges());
    // }
    // 
    // int[] nrmIdxs = cube3.getNormalIndices();
    // int[] offsets = cube3.getFeatureIndexOffsets();
    // for (int i=0; i<offsets.length-1; ++i) {
    // System.out.println("Face " + i + ": ");
    // for (int j = offsets[i]; j<offsets[i+1]; ++j) {
    // Vector3d nrm = cube3.getNormal(nrmIdxs[j]);
    // System.out.println(nrm.toString());
    // }
    // }
    // FixedMeshBody fm = new FixedMeshBody("cube3", cube3);
    // addRenderable(fm);
    // RenderProps.setFaceStyle(fm, FaceStyle.FRONT_AND_BACK);
    // RenderProps.setFaceColor(fm, Color.BLUE);
    // RenderProps.setBackColor(fm, Color.YELLOW);
    RenderProps.setDrawEdges(this, true);
}
Also used : RigidTransform3d(maspack.matrix.RigidTransform3d) Renderable(maspack.render.Renderable) Vector3d(maspack.matrix.Vector3d) FixedMeshBody(artisynth.core.mechmodels.FixedMeshBody) PolygonalMesh(maspack.geometry.PolygonalMesh)

Example 8 with Renderable

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

the class SimpleCollide method setBottomObject.

private void setBottomObject(Collidable comp, ObjectType type) {
    Renderable rcomp = (Renderable) comp;
    ((TransformableGeometry) comp).transformGeometry(AffineTransform3d.createScaling(myBottomScale));
    switch(type) {
        case FemEllipsoid:
        case FemSphere:
            {
                RenderProps.setPointColor(rcomp, Color.green);
                // fix the lower nodes
                Point3d min = new Point3d();
                RenderableUtils.getBounds(rcomp, min, null);
                FemModel3d fem = (FemModel3d) comp;
                fem.getSurfaceMesh();
                for (FemNode3d n : fem.getNodes()) {
                    if (fem.isSurfaceNode(n) && n.getPosition().z <= (min.z + mySize * 0.5)) {
                        n.setDynamic(false);
                    }
                }
                fem.resetRestPosition();
                break;
            }
        case FemCube:
            {
                RenderProps.setPointColor(rcomp, Color.green);
                // fix the lower nodes
                Point3d min = new Point3d();
                RenderableUtils.getBounds(rcomp, min, null);
                FemModel3d fem = (FemModel3d) comp;
                fem.getSurfaceMesh();
                for (FemNode3d n : fem.getNodes()) {
                    if (fem.isSurfaceNode(n) && n.getPosition().z <= (min.z + mySize * 0.1)) {
                        n.setDynamic(false);
                    }
                }
                // RenderProps.setAlpha (rcomp, 0.3);
                fem.resetRestPosition();
                break;
            }
        case Box:
            {
                ((RigidBody) comp).setDynamic(false);
                ((RigidBody) comp).setDistanceGridRes(new Vector3i(10, 5, 5));
                break;
            }
        case Molar:
            {
                ((RigidBody) comp).setPose(new RigidTransform3d(0, 0, 0, 0, -1, 0, Math.toRadians(172.09)));
                ((RigidBody) comp).setDynamic(false);
                break;
            }
        case Bin:
            {
                ((RigidBody) comp).setPose(new RigidTransform3d(0, 0, 0, 0, 0, 0, 0));
                ((RigidBody) comp).setDynamic(false);
                break;
            }
        case Paw:
        case House:
            {
                ((RigidBody) comp).setDynamic(false);
                break;
            }
        default:
            {
                throw new InternalErrorException("Unimplemented type " + type);
            }
    }
    myBottomObject = comp;
    myBottomType = type;
}
Also used : TransformableGeometry(artisynth.core.modelbase.TransformableGeometry) RigidTransform3d(maspack.matrix.RigidTransform3d) Renderable(maspack.render.Renderable) FemModel3d(artisynth.core.femmodels.FemModel3d) Point3d(maspack.matrix.Point3d) FemNode3d(artisynth.core.femmodels.FemNode3d) Vector3i(maspack.matrix.Vector3i) InternalErrorException(maspack.util.InternalErrorException)

Example 9 with Renderable

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

the class Main method setDragger.

private void setDragger() {
    translator3d.setVisible(false);
    transrotator3d.setVisible(false);
    scalar3d.setVisible(false);
    rotator3d.setVisible(false);
    constrainedTranslator3d.setVisible(false);
    constrainedTranslator3d.setMesh(null);
    currentDragger = null;
    myDraggableComponents.clear();
    if (mySelectionMode != SelectionMode.Select && mySelectionMode != SelectionMode.EllipticSelect && mySelectionMode != SelectionMode.Pull) {
        Point3d pmin = new Point3d(inf, inf, inf);
        Point3d pmax = new Point3d(-inf, -inf, -inf);
        int n = 0;
        for (ModelComponent sel : mySelectionManager.getCurrentSelection()) {
            if (sel instanceof Renderable && sel instanceof TransformableGeometry && !ComponentUtils.isAncestorSelected(sel)) {
                myDraggableComponents.add(sel);
                ((Renderable) sel).updateBounds(pmin, pmax);
                n++;
            }
        }
        if (n > 0) {
            RigidTransform3d TDW = new RigidTransform3d();
            double radius = computeDraggerToWorld(TDW, myDraggableComponents, null);
            // set a minimum radius to about 1/6 of the viewer window width
            radius = Math.max(radius, myViewer.distancePerPixel(myViewer.getCenter()) * myViewer.getScreenWidth() / 6);
            if (mySelectionMode == SelectionMode.Translate) {
                translator3d.setVisible(true);
                translator3d.setDraggerToWorld(TDW);
                translator3d.setSize(radius);
                currentDragger = translator3d;
            } else if (mySelectionMode == SelectionMode.Transrotate) {
                transrotator3d.setVisible(true);
                transrotator3d.setDraggerToWorld(TDW);
                transrotator3d.setSize(radius);
                currentDragger = transrotator3d;
            } else if (mySelectionMode == SelectionMode.Scale) {
                scalar3d.setVisible(true);
                scalar3d.setDraggerToWorld(TDW);
                scalar3d.setSize(radius);
                currentDragger = scalar3d;
            } else if (mySelectionMode == SelectionMode.Rotate) {
                rotator3d.setVisible(true);
                rotator3d.setDraggerToWorld(TDW);
                rotator3d.setSize(radius);
                currentDragger = rotator3d;
            } else if (mySelectionMode == SelectionMode.ConstrainedTranslate) {
                PolygonalMesh mesh = null;
                for (Object sel : mySelectionManager.getCurrentSelection()) {
                    if (sel instanceof FrameMarker) {
                        FrameMarker frameMarker = (FrameMarker) sel;
                        Point3d p = new Point3d(frameMarker.getPosition());
                        constrainedTranslator3d.setLocation(p);
                        Frame frame = frameMarker.getFrame();
                        if (frame instanceof RigidBody) {
                            mesh = ((RigidBody) frame).getMesh();
                        }
                        break;
                    }
                }
                if (mesh != null) {
                    constrainedTranslator3d.setSize(radius);
                    constrainedTranslator3d.setMesh(mesh);
                    constrainedTranslator3d.setVisible(true);
                    currentDragger = constrainedTranslator3d;
                }
            }
        }
    }
}
Also used : TransformableGeometry(artisynth.core.modelbase.TransformableGeometry) OrientedTransformableGeometry(artisynth.core.modelbase.OrientedTransformableGeometry) RigidTransform3d(maspack.matrix.RigidTransform3d) JFrame(javax.swing.JFrame) GLViewerFrame(maspack.render.GL.GLViewerFrame) Frame(artisynth.core.mechmodels.Frame) HasCoordinateFrame(artisynth.core.modelbase.HasCoordinateFrame) Renderable(maspack.render.Renderable) ModelComponent(artisynth.core.modelbase.ModelComponent) FrameMarker(artisynth.core.mechmodels.FrameMarker) Point3d(maspack.matrix.Point3d) RigidBody(artisynth.core.mechmodels.RigidBody) PolygonalMesh(maspack.geometry.PolygonalMesh) WayPoint(artisynth.core.probes.WayPoint)

Example 10 with Renderable

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

the class Main method centerViewOnSelection.

void centerViewOnSelection() {
    Point3d center = new Point3d();
    Point3d pmin = new Point3d(inf, inf, inf);
    Point3d pmax = new Point3d(-inf, -inf, -inf);
    int n = 0;
    ModelComponent firstComp = null;
    for (ModelComponent sel : mySelectionManager.getCurrentSelection()) {
        if (sel instanceof Renderable && !ComponentUtils.isAncestorSelected(sel)) {
            if (firstComp == null) {
                firstComp = sel;
            }
            ((Renderable) sel).updateBounds(pmin, pmax);
            n++;
        }
    }
    if (n > 0) {
        if (n == 1 && firstComp instanceof HasCoordinateFrame) {
            RigidTransform3d X = new RigidTransform3d();
            ((HasCoordinateFrame) firstComp).getPose(X);
            center.set(X.p);
        } else {
            center.add(pmin, pmax);
            center.scale(0.5);
        }
        myViewer.setCenter(center);
        rerender();
    }
}
Also used : HasCoordinateFrame(artisynth.core.modelbase.HasCoordinateFrame) RigidTransform3d(maspack.matrix.RigidTransform3d) Renderable(maspack.render.Renderable) ModelComponent(artisynth.core.modelbase.ModelComponent) Point3d(maspack.matrix.Point3d) WayPoint(artisynth.core.probes.WayPoint)

Aggregations

Renderable (maspack.render.Renderable)12 RigidTransform3d (maspack.matrix.RigidTransform3d)6 Point3d (maspack.matrix.Point3d)5 ModelComponent (artisynth.core.modelbase.ModelComponent)4 PolygonalMesh (maspack.geometry.PolygonalMesh)4 HasCoordinateFrame (artisynth.core.modelbase.HasCoordinateFrame)3 TransformableGeometry (artisynth.core.modelbase.TransformableGeometry)3 WayPoint (artisynth.core.probes.WayPoint)3 FemModel3d (artisynth.core.femmodels.FemModel3d)2 FemNode3d (artisynth.core.femmodels.FemNode3d)2 RigidBody (artisynth.core.mechmodels.RigidBody)2 Model (artisynth.core.modelbase.Model)2 IsRenderable (maspack.render.IsRenderable)2 InternalErrorException (maspack.util.InternalErrorException)2 FemElement (artisynth.core.femmodels.FemElement)1 FemMarker (artisynth.core.femmodels.FemMarker)1 FemNode (artisynth.core.femmodels.FemNode)1 EditorBase (artisynth.core.gui.editorManager.EditorBase)1 AxialSpring (artisynth.core.mechmodels.AxialSpring)1 FixedMeshBody (artisynth.core.mechmodels.FixedMeshBody)1