Search in sources :

Example 26 with GLViewer

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

the class ViewerManager method resetViewers.

public void resetViewers(AxisAngle frontView) {
    AxisAlignedRotation view = AxisAlignedRotation.getNearest(new RotationMatrix3d(frontView));
    for (GLViewer v : myViewers) {
        v.setDefaultAxialView(view);
        resetViewer(v);
    }
}
Also used : AxisAlignedRotation(maspack.matrix.AxisAlignedRotation) GLViewer(maspack.render.GL.GLViewer) RotationMatrix3d(maspack.matrix.RotationMatrix3d)

Example 27 with GLViewer

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

the class SpecularTest method detach.

@Override
public void detach(DriverInterface driver) {
    super.detach(driver);
    GLViewer viewer = driver.getViewer();
    viewer.setDefaultLights();
}
Also used : GLViewer(maspack.render.GL.GLViewer)

Example 28 with GLViewer

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

the class SpecularTest method attach.

@Override
public void attach(DriverInterface driver) {
    super.attach(driver);
    GLViewer viewer = driver.getViewer();
    for (int i = viewer.numLights(); i-- > 0; ) {
        viewer.removeLight(i);
    }
    Light light = new Light();
    light.setAmbient(0, 0, 0, 0);
    light.setDiffuse(0, 0, 0, 0);
    light.setSpecular(1, 1, 1, 1);
    light.setPosition(0, 0, 1);
    light.setDirection(0, 0, -1);
    light.setType(LightType.POINT);
    viewer.addLight(light);
    LightComponent lc = new LightComponent(light);
    ComponentList<LightComponent> lights = new ComponentList<>(LightComponent.class, "lights");
    lights.add(lc);
    add(lights);
}
Also used : GLViewer(maspack.render.GL.GLViewer) Light(maspack.render.Light) LightComponent(artisynth.core.renderables.LightComponent) ComponentList(artisynth.core.modelbase.ComponentList)

Example 29 with GLViewer

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

the class FemMeshCompEditor method rebuildAsSurfaceMesh.

private void rebuildAsSurfaceMesh(FemMeshComp mcomp) {
    GLViewer v = myMain.getViewer();
    mcomp.createSurface(new ClippedElementFilter(v.getClipPlanes()));
}
Also used : GLViewer(maspack.render.GL.GLViewer)

Example 30 with GLViewer

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

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