Search in sources :

Example 1 with EditablePolygonalMeshComp

use of artisynth.core.renderables.EditablePolygonalMeshComp in project artisynth_core by artisynth.

the class MeshBodyEditor method applyAction.

public void applyAction(String actionCommand, LinkedList<ModelComponent> selection, Rectangle popupBounds) {
    if (containsMultipleSelection(selection, MeshComponent.class)) {
        if (containsSingleSelection(selection, MeshComponent.class)) {
            if (actionCommand == "Save local mesh as ...") {
                MeshComponent body = (MeshComponent) selection.get(0);
                MeshBase mesh = body.getMesh();
                EditorUtils.saveMesh(mesh, null);
            } else if (actionCommand == "Save world mesh as ...") {
                MeshComponent body = (MeshComponent) selection.get(0);
                MeshBase mesh = body.getMesh();
                EditorUtils.saveMesh(mesh, mesh != null ? mesh.getMeshToWorld() : null);
            } else if (actionCommand == "Add mesh inspector") {
                MeshComponent body = (MeshComponent) selection.get(0);
                MechModel mech = (MechModel) body.getGrandParent();
                EditablePolygonalMeshComp editMesh = new EditablePolygonalMeshComp((PolygonalMesh) body.getMesh());
                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 : MeshComponent(artisynth.core.mechmodels.MeshComponent) MechModel(artisynth.core.mechmodels.MechModel) EditablePolygonalMeshComp(artisynth.core.renderables.EditablePolygonalMeshComp) MeshBase(maspack.geometry.MeshBase)

Example 2 with EditablePolygonalMeshComp

use of artisynth.core.renderables.EditablePolygonalMeshComp 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)

Example 3 with EditablePolygonalMeshComp

use of artisynth.core.renderables.EditablePolygonalMeshComp in project artisynth_core by artisynth.

the class EditableMeshTest method build.

@Override
public void build(String[] args) throws IOException {
    super.build(args);
    Color[] colors = { Color.RED, Color.GREEN, Color.BLUE, Color.CYAN, Color.GRAY, Color.MAGENTA, Color.ORANGE, Color.PINK, Color.YELLOW, Color.RED.darker().darker(), Color.GREEN.darker().darker(), Color.BLUE.darker().darker(), Color.CYAN.darker().darker(), Color.GRAY.darker().darker(), Color.MAGENTA.darker().darker(), Color.ORANGE.darker().darker(), Color.PINK.darker().darker(), Color.YELLOW.darker().darker(), Color.RED.brighter().brighter(), Color.GREEN.brighter().brighter(), Color.BLUE.brighter().brighter(), Color.CYAN.brighter().brighter(), Color.GRAY.brighter().brighter(), Color.MAGENTA.brighter().brighter(), Color.ORANGE.brighter().brighter(), Color.PINK.brighter().brighter(), Color.YELLOW.brighter().brighter() };
    PolygonalMesh mesh = MeshFactory.createIcosahedralSphere(1, 0);
    mesh.setFeatureColoringEnabled();
    for (int i = 0; i < mesh.numColors(); ++i) {
        mesh.setColor(i, colors[i % colors.length]);
    }
    EditablePolygonalMeshComp comp = new EditablePolygonalMeshComp(mesh);
    addRenderable(comp);
}
Also used : EditablePolygonalMeshComp(artisynth.core.renderables.EditablePolygonalMeshComp) Color(java.awt.Color) PolygonalMesh(maspack.geometry.PolygonalMesh)

Aggregations

EditablePolygonalMeshComp (artisynth.core.renderables.EditablePolygonalMeshComp)3 MechModel (artisynth.core.mechmodels.MechModel)2 PolygonalMesh (maspack.geometry.PolygonalMesh)2 FrameMarker (artisynth.core.mechmodels.FrameMarker)1 MeshComponent (artisynth.core.mechmodels.MeshComponent)1 RigidBody (artisynth.core.mechmodels.RigidBody)1 Color (java.awt.Color)1 MeshBase (maspack.geometry.MeshBase)1