Search in sources :

Example 1 with Transrotator3d

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

the class MultiViewerTesterBase method addTransRotator.

protected static void addTransRotator(MultiViewer tester) {
    for (SimpleViewerApp app : tester.getWindows()) {
        Transrotator3d dragger = new Transrotator3d();
        dragger.setPosition(new Vector3d(1, 0, 0.2));
        app.viewer.addDragger(dragger);
    }
}
Also used : Vector3d(maspack.matrix.Vector3d) SimpleViewerApp(maspack.test.GL.MultiViewer.SimpleViewerApp) Transrotator3d(maspack.render.Transrotator3d)

Example 2 with Transrotator3d

use of maspack.render.Transrotator3d 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 Transrotator3d

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

the class FemModel3dAgent method createPreviewModel.

private void createPreviewModel() {
    fem = new FemModel3d();
    setProperties(fem, getPrototypeComponent(myComponentType));
    setProperties(myPrototype, myPrototype);
    FemElementType elemType = null;
    FemMeshType meshType = (FemMeshType) meshSelector.getValue();
    if (elemSelector.isEnabledAll()) {
        elemType = (FemElementType) elemSelector.getValue();
    }
    switch(meshType) {
        case Grid:
            {
                VectorBase dims = gridDimField.getVectorValue();
                int[] divs = gridDivField.getVectorValue();
                FemFactory.createGrid(fem, elemType, dims.get(0), dims.get(1), dims.get(2), divs[0], divs[1], divs[2]);
                break;
            }
        case Tube:
            {
                VectorBase dims = tubeDimField.getVectorValue();
                int[] divs = tubeDivField.getVectorValue();
                FemFactory.createTube(fem, elemType, dims.get(0), dims.get(1), dims.get(2), divs[0], divs[1], divs[2]);
                break;
            }
        case Torus:
            {
                VectorBase dims = torusDimField.getVectorValue();
                int[] divs = torusDivField.getVectorValue();
                FemFactory.createTorus(fem, elemType, dims.get(0), dims.get(1), dims.get(2), divs[0], divs[1], divs[2]);
                break;
            }
        case Sphere:
            {
                int nodes = (Integer) sphereNodesField.getValue();
                String meshPath;
                if (nodes == SPHERE_NODE_OPTIONS[0]) {
                    meshPath = ArtisynthPath.getHomeRelativePath(SPHERE_54_MESH_PATH, ".");
                } else if (nodes == SPHERE_NODE_OPTIONS[1]) {
                    meshPath = ArtisynthPath.getHomeRelativePath(SPHERE_196_MESH_PATH, ".");
                } else {
                    EditorUtils.showError(myDisplay, "Invalid number of nodes for sphere");
                    return;
                }
                try {
                    TetGenReader.read(fem, 1000, meshPath + ".node", meshPath + ".ele", new Vector3d(1, 1, 1));
                } catch (Exception e) {
                    EditorUtils.showError(myDisplay, "Error reading file: " + e.getMessage());
                    return;
                }
                break;
            }
        case Extrusion:
            {
                double d = extrusDepthField.getDoubleValue();
                int n = extrusLayersField.getIntValue();
                String meshFileName = extrusFileField.getStringValue();
                try {
                    PolygonalMesh mesh = new PolygonalMesh(new File(meshFileName));
                    FemFactory.createExtrusion(fem, elemType, n, d, 0, mesh);
                } catch (Exception e) {
                    EditorUtils.showError(myDisplay, "Error reading file: " + e.getMessage());
                    return;
                }
                break;
            }
        case AnsysMesh:
            {
                String nodeFileName = ansysNodeFileField.getStringValue();
                String elemFileName = ansysElemFileField.getStringValue();
                try {
                    AnsysReader.read(fem, nodeFileName, elemFileName, 1000, null, /*options=*/
                    0);
                } catch (Exception e) {
                    EditorUtils.showError(myDisplay, "Error reading file: " + e.getMessage());
                    return;
                }
                break;
            }
        case TetgenMesh:
            {
                String nodeFileName = tetgenNodeFileField.getStringValue();
                String eleFileName = tetgenEleFileField.getStringValue();
                try {
                    TetGenReader.read(fem, 1000, nodeFileName, eleFileName, new Vector3d(1, 1, 1));
                } catch (Exception e) {
                    EditorUtils.showError(myDisplay, "Error reading file: " + e.getMessage());
                    return;
                }
                break;
            }
        case UCDMesh:
            {
                String ucdFileName = ucdMeshFileField.getStringValue();
                try {
                    UCDReader.read(fem, ucdFileName, 1000);
                } catch (Exception e) {
                    EditorUtils.showError(myDisplay, "Error reading file: " + e.getMessage());
                    return;
                }
                break;
            }
        case SurfaceMesh:
            {
                String objFileName = surfaceMeshFileField.getStringValue();
                PolygonalMesh surfaceMesh = null;
                try {
                    surfaceMesh = new PolygonalMesh(new File(objFileName));
                } catch (Exception e) {
                    EditorUtils.showError(myDisplay, "Error reading file: " + e.getMessage());
                    return;
                }
                try {
                    FemFactory.createFromMesh(fem, surfaceMesh, /*quality=*/
                    2.0);
                } catch (Exception e) {
                    e.printStackTrace();
                    EditorUtils.showError(myDisplay, "Error tessellating mesh: " + e.getMessage());
                    return;
                }
                break;
            }
        default:
            {
                throw new InternalErrorException("Unimplemented mesh type");
            }
    }
    RigidTransform3d X = new RigidTransform3d();
    X.p.set(positionField.getVectorValue());
    X.R.setAxisAngle(orientationField.getAxisAngleValue());
    PolygonalMesh mesh = fem.getSurfaceMesh();
    RenderProps props = mesh.createRenderProps();
    props.setFaceStyle(Renderer.FaceStyle.NONE);
    props.setDrawEdges(true);
    props.setLineColor(Color.LIGHT_GRAY);
    mesh.setRenderProps(props);
    mesh.setMeshToWorld(X);
    mesh.setFixed(false);
    mesh.setRenderBuffered(false);
    if (meshPropPanel.getComponentIndex(scaleField) != -1) {
        scaleField.maskValueChangeListeners(true);
        scaleField.setValue(1.0);
        scaleField.maskValueChangeListeners(false);
        lastScale = 1.0;
    }
    myMain.getWorkspace().getViewerManager().addRenderable(mesh);
    rotator = new Transrotator3d();
    GLViewer viewer = myMain.getMain().getViewer();
    rotator.setDraggerToWorld(X);
    rotator.setSize(viewer.distancePerPixel(viewer.getCenter()) * viewer.getScreenWidth() / 6);
    rotator.addListener(new FemModelDraggerListener());
    myMain.getWorkspace().getViewerManager().addDragger(rotator);
    myMain.rerender();
}
Also used : RigidTransform3d(maspack.matrix.RigidTransform3d) FemModel3d(artisynth.core.femmodels.FemModel3d) FemElementType(artisynth.core.femmodels.FemFactory.FemElementType) RenderProps(maspack.render.RenderProps) Transrotator3d(maspack.render.Transrotator3d) InternalErrorException(maspack.util.InternalErrorException) PolygonalMesh(maspack.geometry.PolygonalMesh) InternalErrorException(maspack.util.InternalErrorException) GLViewer(maspack.render.GL.GLViewer) Vector3d(maspack.matrix.Vector3d) VectorBase(maspack.matrix.VectorBase) File(java.io.File)

Aggregations

Transrotator3d (maspack.render.Transrotator3d)3 RigidTransform3d (maspack.matrix.RigidTransform3d)2 Vector3d (maspack.matrix.Vector3d)2 GLViewer (maspack.render.GL.GLViewer)2 RenderProps (maspack.render.RenderProps)2 FemElementType (artisynth.core.femmodels.FemFactory.FemElementType)1 FemModel3d (artisynth.core.femmodels.FemModel3d)1 RigidBody (artisynth.core.mechmodels.RigidBody)1 File (java.io.File)1 PolygonalMesh (maspack.geometry.PolygonalMesh)1 VectorBase (maspack.matrix.VectorBase)1 SimpleViewerApp (maspack.test.GL.MultiViewer.SimpleViewerApp)1 InternalErrorException (maspack.util.InternalErrorException)1