Search in sources :

Example 1 with TransformableGeometry

use of artisynth.core.modelbase.TransformableGeometry 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 2 with TransformableGeometry

use of artisynth.core.modelbase.TransformableGeometry 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 3 with TransformableGeometry

use of artisynth.core.modelbase.TransformableGeometry in project artisynth_core by artisynth.

the class SimpleCollide method setTopObject.

private void setTopObject(Collidable comp, ObjectType type) {
    Renderable rcomp = (Renderable) comp;
    ((TransformableGeometry) comp).transformGeometry(new RigidTransform3d(0, /*-0.3*/
    0.0, mySeparation));
    ((TransformableGeometry) comp).transformGeometry(AffineTransform3d.createScaling(myTopScale));
    RenderProps.setFaceColor(rcomp, Color.red);
    switch(type) {
        case FemEllipsoid:
        case FemSphere:
        case FemCube:
            {
                RenderProps.setPointColor(rcomp, Color.gray);
                RenderProps.setAlpha(rcomp, 0.3);
                RenderProps.setDrawEdges(rcomp, true);
                RenderProps.setVisible(((FemModel3d) rcomp).getElements(), false);
                break;
            }
        case House:
            {
                ((TransformableGeometry) comp).transformGeometry(new RigidTransform3d(0, 0, 2 * mySeparation, 1, 1, 0, Math.toRadians(170)));
                break;
            }
        case Box:
        case Molar:
        case Bin:
        case Paw:
            {
                break;
            }
        default:
            {
                throw new InternalErrorException("Unimplemented type " + type);
            }
    }
    myTopObject = comp;
    myTopType = type;
}
Also used : TransformableGeometry(artisynth.core.modelbase.TransformableGeometry) RigidTransform3d(maspack.matrix.RigidTransform3d) Renderable(maspack.render.Renderable) FemModel3d(artisynth.core.femmodels.FemModel3d) InternalErrorException(maspack.util.InternalErrorException)

Aggregations

TransformableGeometry (artisynth.core.modelbase.TransformableGeometry)3 RigidTransform3d (maspack.matrix.RigidTransform3d)3 Renderable (maspack.render.Renderable)3 FemModel3d (artisynth.core.femmodels.FemModel3d)2 Point3d (maspack.matrix.Point3d)2 InternalErrorException (maspack.util.InternalErrorException)2 FemNode3d (artisynth.core.femmodels.FemNode3d)1 Frame (artisynth.core.mechmodels.Frame)1 FrameMarker (artisynth.core.mechmodels.FrameMarker)1 RigidBody (artisynth.core.mechmodels.RigidBody)1 HasCoordinateFrame (artisynth.core.modelbase.HasCoordinateFrame)1 ModelComponent (artisynth.core.modelbase.ModelComponent)1 OrientedTransformableGeometry (artisynth.core.modelbase.OrientedTransformableGeometry)1 WayPoint (artisynth.core.probes.WayPoint)1 JFrame (javax.swing.JFrame)1 PolygonalMesh (maspack.geometry.PolygonalMesh)1 Vector3i (maspack.matrix.Vector3i)1 GLViewerFrame (maspack.render.GL.GLViewerFrame)1