Search in sources :

Example 1 with RigidBody

use of artisynth.core.mechmodels.RigidBody in project artisynth_core by artisynth.

the class RigidBodyAgent method initializePrototype.

protected void initializePrototype(ModelComponent comp, Class type) {
    if (type == RigidBody.class) {
        RigidBody mkr = (RigidBody) comp;
        RenderProps.setPointRadius(mkr, getDefaultPointRadius());
    } else {
        throw new InternalErrorException("unimplemented type " + type);
    }
}
Also used : RigidBody(artisynth.core.mechmodels.RigidBody) InternalErrorException(maspack.util.InternalErrorException)

Example 2 with RigidBody

use of artisynth.core.mechmodels.RigidBody in project artisynth_core by artisynth.

the class RigidBodyAgent method createPreviewBody.

private void createPreviewBody() {
    resetScaling();
    body = new RigidBody();
    setProperties(body, getPrototypeComponent(myComponentType));
    setProperties(myPrototype, myPrototype);
    body.setMesh(myGeometryPanel.getMesh(), myGeometryPanel.getMeshFileName(), myGeometryPanel.getMeshTransform());
    RigidTransform3d X = new RigidTransform3d();
    X.p.set(positionField.getVectorValue());
    X.R.setAxisAngle(orientationField.getAxisAngleValue());
    body.setPose(X);
    RenderProps props = body.createRenderProps();
    props.setFaceStyle(Renderer.FaceStyle.NONE);
    props.setDrawEdges(true);
    props.setLineColor(Color.LIGHT_GRAY);
    body.setRenderProps(props);
    myMain.getWorkspace().getViewerManager().addRenderable(body);
    rotator = new Transrotator3d();
    GLViewer viewer = myMain.getMain().getViewer();
    rotator.setDraggerToWorld(X);
    rotator.setSize(viewer.distancePerPixel(viewer.getCenter()) * viewer.getScreenWidth() / 6);
    rotator.addListener(new RigidBodyDraggerListener());
    myMain.getWorkspace().getViewerManager().addDragger(rotator);
    myGeometryPanel.setAttachedBody(body);
    myMain.rerender();
}
Also used : RigidTransform3d(maspack.matrix.RigidTransform3d) GLViewer(maspack.render.GL.GLViewer) RenderProps(maspack.render.RenderProps) Transrotator3d(maspack.render.Transrotator3d) RigidBody(artisynth.core.mechmodels.RigidBody)

Example 3 with RigidBody

use of artisynth.core.mechmodels.RigidBody in project artisynth_core by artisynth.

the class RigidBodyAgent method createGeometryPanel.

protected void createGeometryPanel() {
    RigidBody protoBody = null;
    int numExistingBodies = myModel.rigidBodies().size();
    if (numExistingBodies > 0) {
        protoBody = myModel.rigidBodies().get(numExistingBodies - 1);
    }
    myGeometryPanel = new GeometryInertiaPanel(myGeometrySettings, protoBody, /* editing= */
    false);
    myGeometryPanel.setBorder(GuiUtils.createTitledPanelBorder("Geometry And Inertia"));
    if (myGeometrySettings == null) {
        GLViewer viewer = myMain.getMain().getViewer();
        double width = viewer.distancePerPixel(viewer.getCenter()) * viewer.getScreenWidth() / 6;
        double boxScale = 1;
        if (width > boxScale) {
            for (int i = -1; width > boxScale; i++) {
                boxScale *= (i % 3 == 0) ? 2.5 : 2.0;
            }
        } else {
            for (int i = -1; width < boxScale; i++) {
                boxScale /= (i % 3 == 0) ? 2.5 : 2.0;
            }
        }
        myGeometryPanel.myBoxWidthsField.setValue(new Vector3d(boxScale, boxScale, boxScale));
    }
    geometrySelector = myGeometryPanel.myGeometrySelector;
    geometrySelector.addValueChangeListener(this);
    myGeometryPanel.myBoxWidthsField.addValueChangeListener(this);
    myGeometryPanel.myPointRadiusField.addValueChangeListener(this);
    myGeometryPanel.myPointSlicesField.addValueChangeListener(this);
    myGeometryPanel.myMeshFileField.addValueChangeListener(this);
    AffineTransformWidget meshXformWidget = myGeometryPanel.myMeshXformWidget;
    meshXformWidget.getTranslationField().addValueChangeListener(this);
    myGeometryPanel.myDensityField.setValue(1.0);
    scaleField = meshXformWidget.getScaleField();
    autoScaleBtn = new JButton("Auto Scale");
    autoScaleBtn.addActionListener(this);
    scaleField.addMajorComponent(autoScaleBtn);
    addWidget(myGeometryPanel);
}
Also used : GLViewer(maspack.render.GL.GLViewer) Vector3d(maspack.matrix.Vector3d) AffineTransformWidget(maspack.widgets.AffineTransformWidget) JButton(javax.swing.JButton) RigidBody(artisynth.core.mechmodels.RigidBody)

Example 4 with RigidBody

use of artisynth.core.mechmodels.RigidBody in project artisynth_core by artisynth.

the class RigidBodyConnectorList method selectionChanged.

@Override
public void selectionChanged(SelectionEvent e) {
    ModelComponent c = e.getLastAddedComponent();
    if (myState == State.SelectingBodyA) {
        if (c instanceof RigidBody) {
            myBodyA = (RigidBody) c;
            setState(State.SelectingBodyB);
        }
    } else if (myState == State.SelectingBodyB) {
        if (c instanceof RigidBody) {
            myBodyB = (RigidBody) c;
            setState(State.SelectingLocation);
        }
    }
}
Also used : ModelComponent(artisynth.core.modelbase.ModelComponent) RigidBody(artisynth.core.mechmodels.RigidBody)

Example 5 with RigidBody

use of artisynth.core.mechmodels.RigidBody in project artisynth_core by artisynth.

the class RigidBodyEditor method applyAction.

public void applyAction(String actionCommand, LinkedList<ModelComponent> selection, Rectangle popupBounds) {
    if (containsMultipleSelection(selection, RigidBody.class)) {
        if (actionCommand == "Select markers") {
            LinkedList<ModelComponent> list = (LinkedList<ModelComponent>) selection.clone();
            for (ModelComponent c : list) {
                FrameMarker[] mkrs = ((RigidBody) c).getFrameMarkers();
                for (int i = 0; i < mkrs.length; i++) {
                    myMain.getSelectionManager().addSelected(mkrs[i]);
                }
                myMain.getSelectionManager().removeSelected(c);
            }
        }
        if (containsSingleSelection(selection, RigidBody.class)) {
            if (actionCommand == "Edit geometry and inertia ...") {
                if (myEditManager.acquireEditLock()) {
                    RigidBody body = (RigidBody) selection.get(0);
                    RigidBodyGeometryAgent agent = new RigidBodyGeometryAgent(myMain, body);
                    agent.show(popupBounds);
                }
            } else if (actionCommand == "Save mesh as ...") {
                RigidBody body = (RigidBody) selection.get(0);
                PolygonalMesh mesh = body.getMesh();
                EditorUtils.saveMesh(mesh, mesh != null ? mesh.getMeshToWorld() : null);
            } else if (actionCommand == "Attach particles ...") {
                if (myEditManager.acquireEditLock()) {
                    RigidBody body = (RigidBody) selection.get(0);
                    // XXX should be more general than this ... what if mechModel
                    // is a sub model?
                    MechModel mech = (MechModel) body.getGrandParent();
                    myMain.getSelectionManager().clearSelections();
                    AttachParticleBodyAgent agent = new AttachParticleBodyAgent(myMain, mech, body);
                    agent.show(popupBounds);
                }
            } else if (actionCommand == "Add mesh inspector") {
                RigidBody body = (RigidBody) selection.get(0);
                MechModel mech = (MechModel) body.getGrandParent();
                EditablePolygonalMeshComp editMesh = new EditablePolygonalMeshComp(body.getSurfaceMesh());
                double size = RenderableUtils.getRadius(editMesh);
                RenderProps.setVisible(editMesh, true);
                RenderProps.setPointStyle(editMesh, Renderer.PointStyle.SPHERE);
                RenderProps.setPointRadius(editMesh, 0.05 * size);
                mech.addRenderable(editMesh);
            }
        }
    }
}
Also used : MechModel(artisynth.core.mechmodels.MechModel) EditablePolygonalMeshComp(artisynth.core.renderables.EditablePolygonalMeshComp) FrameMarker(artisynth.core.mechmodels.FrameMarker) RigidBody(artisynth.core.mechmodels.RigidBody) PolygonalMesh(maspack.geometry.PolygonalMesh)

Aggregations

RigidBody (artisynth.core.mechmodels.RigidBody)55 MechModel (artisynth.core.mechmodels.MechModel)25 RigidTransform3d (maspack.matrix.RigidTransform3d)18 FrameMarker (artisynth.core.mechmodels.FrameMarker)11 RenderProps (maspack.render.RenderProps)11 Point3d (maspack.matrix.Point3d)10 PolygonalMesh (maspack.geometry.PolygonalMesh)9 RevoluteJoint (artisynth.core.mechmodels.RevoluteJoint)8 Vector3d (maspack.matrix.Vector3d)8 FemModel3d (artisynth.core.femmodels.FemModel3d)7 FemNode3d (artisynth.core.femmodels.FemNode3d)7 SphericalJoint (artisynth.core.mechmodels.SphericalJoint)7 WayPoint (artisynth.core.probes.WayPoint)6 AxialSpring (artisynth.core.mechmodels.AxialSpring)5 Particle (artisynth.core.mechmodels.Particle)5 Color (java.awt.Color)5 CollisionManager (artisynth.core.mechmodels.CollisionManager)4 File (java.io.File)4 IOException (java.io.IOException)4 AxisAngle (maspack.matrix.AxisAngle)4