Search in sources :

Example 16 with GLViewer

use of maspack.render.GL.GLViewer in project artisynth_core by artisynth.

the class AddComponentAgent method getDefaultPointRadius.

/**
 * Returns a default value for the sphere radius render property.
 */
protected double getDefaultPointRadius() {
    GLViewer viewer = myViewerManager.getViewer(0);
    double r = viewer.estimateRadiusAndCenter(null);
    // return 3*viewer.distancePerPixel (viewer.getCenter());
    return 0.015 * r;
}
Also used : GLViewer(maspack.render.GL.GLViewer)

Example 17 with GLViewer

use of maspack.render.GL.GLViewer in project artisynth_core by artisynth.

the class RigidBodyAgent method updateScale.

private void updateScale() {
    resetScaling();
    Vector3d minBound = new Vector3d();
    Vector3d maxBound = new Vector3d();
    body.getMesh().getWorldBounds(minBound, maxBound);
    double meshWidth = maxBound.x - minBound.x;
    double meshHeight = maxBound.y - minBound.y;
    GLViewer viewer = myMain.getMain().getViewer();
    double distancePerPixel = viewer.distancePerPixel(viewer.getCenter());
    double width = distancePerPixel * viewer.getScreenWidth() / 4;
    double height = distancePerPixel * viewer.getScreenHeight() / 4;
    double meshScale = 1;
    if (meshScale * meshWidth > width || meshScale * meshHeight > height) {
        for (int i = -1; width < meshScale * meshWidth && height < meshScale * meshHeight; i++) {
            meshScale /= (i % 3 == 0) ? 2.5 : 2.0;
        }
    } else {
        for (int i = -1; width > meshScale * meshWidth || height > meshScale * meshHeight; i++) {
            double increment = (i % 3 == 0) ? 2.5 : 2.0;
            if (width <= meshScale * meshWidth * increment || height <= meshScale * meshHeight * increment) {
                break;
            }
            meshScale *= increment;
        }
    }
    scaleField.setValue(meshScale);
}
Also used : GLViewer(maspack.render.GL.GLViewer) Vector3d(maspack.matrix.Vector3d)

Example 18 with GLViewer

use of maspack.render.GL.GLViewer 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 19 with GLViewer

use of maspack.render.GL.GLViewer 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 20 with GLViewer

use of maspack.render.GL.GLViewer in project artisynth_core by artisynth.

the class RigidBodyAgent method valueChange.

public void valueChange(ValueChangeEvent evt) {
    Object source = evt.getSource();
    if (source == positionField) {
        updateState();
        updateDisplayGeometry();
        if (geometrySelector.getValue() == GeometryType.Mesh && body != null) {
            updateScale();
        }
    } else if (source == orientationField) {
        updateDisplayGeometry();
    } else if (source == geometrySelector) {
        GLViewer viewer = myMain.getMain().getViewer();
        double width = viewer.distancePerPixel(viewer.getCenter()) * viewer.getScreenWidth() / 6;
        if (geometrySelector.getValue() == GeometryType.Mesh) {
            File file = new File(myGeometryPanel.myMeshFileField.getStringValue());
            if (!file.isFile()) {
                fileCheck = false;
                updateState();
            }
            resetPreviewModel();
            if (body != null) {
                updateScale();
            }
        } else {
            fileCheck = true;
            updateState();
            double scale = 1;
            if (width > scale) {
                for (int i = -1; width > scale; i++) {
                    scale *= (i % 3 == 0) ? 2.5 : 2.0;
                }
            } else {
                for (int i = -1; width < scale; i++) {
                    scale /= (i % 3 == 0) ? 2.5 : 2.0;
                }
            }
            if (geometrySelector.getValue() == GeometryType.Box) {
                myGeometryPanel.myBoxWidthsField.setValue(new Vector3d(scale, scale, scale));
            } else if (geometrySelector.getValue() == GeometryType.Sphere) {
                myGeometryPanel.myPointRadiusField.setValue(scale / 2);
            }
            resetPreviewModel();
            myMain.rerender();
        }
    } else if (source == myGeometryPanel.myBoxWidthsField || source == myGeometryPanel.myPointRadiusField || source == myGeometryPanel.myPointSlicesField || source == myGeometryPanel.myMeshXformWidget.getTranslationField()) {
        resetPreviewModel();
        myMain.rerender();
    } else if (source == myGeometryPanel.myMeshFileField) {
        File file = new File(myGeometryPanel.myMeshFileField.getStringValue());
        if (file.isFile()) {
            fileCheck = true;
            updateState();
            resetPreviewModel();
            if (body != null) {
                updateScale();
            }
        } else {
            fileCheck = false;
            EditorUtils.showError(myDisplay, "File does not exist:" + file.getAbsolutePath());
        }
    } else {
        super.valueChange(evt);
    }
}
Also used : GLViewer(maspack.render.GL.GLViewer) Vector3d(maspack.matrix.Vector3d) File(java.io.File)

Aggregations

GLViewer (maspack.render.GL.GLViewer)36 Vector3d (maspack.matrix.Vector3d)9 File (java.io.File)5 RigidTransform3d (maspack.matrix.RigidTransform3d)4 AxisAngle (maspack.matrix.AxisAngle)3 Point3d (maspack.matrix.Point3d)3 GLViewerFrame (maspack.render.GL.GLViewerFrame)3 RigidBody (artisynth.core.mechmodels.RigidBody)2 ExtensionFileFilter (artisynth.core.util.ExtensionFileFilter)2 JFileChooser (javax.swing.JFileChooser)2 FileFilter (javax.swing.filechooser.FileFilter)2 PolygonalMesh (maspack.geometry.PolygonalMesh)2 RotationMatrix3d (maspack.matrix.RotationMatrix3d)2 GLGridPlane (maspack.render.GL.GLGridPlane)2 RenderProps (maspack.render.RenderProps)2 Transrotator3d (maspack.render.Transrotator3d)2 GenericFileFilter (maspack.util.GenericFileFilter)2 InternalErrorException (maspack.util.InternalErrorException)2 ArgParser (argparser.ArgParser)1 IntHolder (argparser.IntHolder)1