Package artofillusion.object

Examples of artofillusion.object.TriangleMesh


    // Build the final object.
   
    int faces[][] = new int [newFace.size()][];
    for (i = 0; i < faces.length; i++)
      faces[i] = (int []) newFace.elementAt(i);
    TriangleMesh mesh = new TriangleMesh(v, faces);
    Edge meshEdge[] = mesh.getEdges();
    for (i = 0; i < newEdge.size(); i++)
      {
        EdgeInfo info = (EdgeInfo) newEdge.elementAt(i);
        if (info.smoothness == 1.0f)
          continue;
        for (j = 0; j < meshEdge.length; j++)
          if ((meshEdge[j].v1 == info.v1 && meshEdge[j].v2 == info.v2) ||
              (meshEdge[j].v1 == info.v2 && meshEdge[j].v2 == info.v1))
            meshEdge[j].smoothness = info.smoothness;
      }
    mesh.setSmoothingMethod(Math.max(profile.getSmoothingMethod(), path.getSmoothingMethod()));
    mesh.makeRightSideOut();
    return mesh;
  }
View Full Code Here


  boolean visible[];

  public TriMeshViewer(MeshEditController window, RowContainer p)
  {
    super(window, p);
    TriangleMesh mesh = (TriangleMesh) window.getObject().getObject();
    visible = new boolean [mesh.getVertices().length];
  }
View Full Code Here

    visible = new boolean [mesh.getVertices().length];
  }

  protected void drawObject()
  {
    TriangleMesh mesh = (TriangleMesh) getController().getObject().getObject();
    MeshVertex v[] = mesh.getVertices();
    RenderingMesh previewMesh = getController().getObject().getPreviewMesh();
    boolean project = (controller instanceof TriMeshEditorWindow ? ((TriMeshEditorWindow) controller).getProjectOntoSurface() : false);
    Vec2 p[];

    // Calculate the screen coordinates of every vertex.

    screenVert = new Point [v.length];
    screenZ = new double [v.length];
    if (visible.length != v.length)
      visible = new boolean [v.length];
    p = new Vec2 [v.length];
    double clipDist = theCamera.getClipDistance();
    boolean hideVert[] = (controller instanceof TriMeshEditorWindow ? ((TriMeshEditorWindow) controller).hideVert : new boolean [v.length]);
    for (int i = 0; i < v.length; i++)
      {
        Vec3 pos = (project ? previewMesh.vert[i] : v[i].r);
        p[i] = theCamera.getObjectToScreen().timesXY(pos);
        screenVert[i] = new Point((int) p[i].x, (int) p[i].y);
        screenZ[i] = theCamera.getObjectToView().timesZ(pos);
        visible[i] = (!hideVert[i] && screenZ[i] > clipDist);
      }

    // Now draw the object.

    drawSurface();
    Color meshColor, selectedColor;
    if (currentTool instanceof SkeletonTool)
      {
        meshColor = disabledColor;
        selectedColor = new Color(255, 127, 255);
      }
    else
      {
        meshColor = lineColor;
        selectedColor = highlightColor;
        if (showSkeleton && mesh.getSkeleton() != null)
          mesh.getSkeleton().draw(this, false);
      }
    if (controller.getSelectionMode() == MeshEditController.POINT_MODE)
      {
        drawEdges(p, disabledColor, disabledColor);
        drawVertices(meshColor, currentTool.hilightSelection() ? selectedColor : meshColor);
      }
    else
      drawEdges(p, meshColor, currentTool.hilightSelection() ? selectedColor : meshColor);
    if (currentTool instanceof SkeletonTool)
      if (showSkeleton && mesh.getSkeleton() != null)
        mesh.getSkeleton().draw(this, true);
  }
View Full Code Here

    }
    else
    {
      // Draw the edges of the subdivided mesh that correspond to edges of the control mesh.

      TriangleMesh divMesh = ((TriMeshEditorWindow) controller).getSubdividedMesh();
      MeshVertex divVert[] = divMesh.getVertices();
      Edge divEdge[] = divMesh.getEdges();
      double divScreenZ[] = new double [divVert.length];
      Vec2 divPos[] = new Vec2 [divVert.length];
      for (int i = 0; i < divVert.length; i++)
      {
        divPos[i] = theCamera.getObjectToScreen().timesXY(divVert[i].r);
View Full Code Here

  /** When the user presses the mouse, forward events to the current tool as appropriate.
      If this is a vertex based tool, allow them to select or deselect vertices. */

  protected void mousePressed(WidgetMouseEvent e)
  {
    TriangleMesh mesh = (TriangleMesh) getController().getObject().getObject();
    Edge ed[] = mesh.getEdges();
    Face f[] = mesh.getFaces();
    int i, j, k;

    requestFocus();
    sentClick = false;
    deselect = -1;
View Full Code Here

    super.mouseDragged(e);
  }

  protected void mouseReleased(WidgetMouseEvent e)
  {
    TriangleMesh mesh = (TriangleMesh) getController().getObject().getObject();
    Edge ed[] = mesh.getEdges();
    Face fc[] = mesh.getFaces();

    moveToGrid(e);
    endDraggingSelection();
    boolean selected[] = controller.getSelection();
    boolean oldSelection[] = selected.clone();
    if (draggingSelectionBox && !e.isShiftDown() && !e.isControlDown())
      for (int i = 0; i < selected.length; i++)
        selected[i] = false;

    // If the user was dragging a selection box, then select or deselect anything
    // it intersects.
   
    boolean hideVert[] = (controller instanceof TriMeshEditorWindow ? ((TriMeshEditorWindow) controller).hideVert : new boolean [mesh.getVertices().length]);
    boolean hideEdge[] = (controller instanceof TriMeshEditorWindow ? ((TriMeshEditorWindow) controller).hideEdge : new boolean [ed.length]);
    boolean hideFace[] = (controller instanceof TriMeshEditorWindow ? ((TriMeshEditorWindow) controller).hideFace : new boolean [fc.length]);
    boolean tolerant = (controller instanceof TriMeshEditorWindow ? ((TriMeshEditorWindow) controller).tolerant : false);
    if (selectBounds != null)
    {
View Full Code Here

   
    boolean selected[] = controller.getSelection();
    boolean priorityToSelected = (getRenderMode() == RENDER_WIREFRAME || getRenderMode() == RENDER_TRANSPARENT);
    if (controller.getSelectionMode() == MeshEditController.POINT_MODE)
    {
      TriangleMesh mesh = (TriangleMesh) getController().getObject().getObject();
      Vertex vt[] = (Vertex []) mesh.getVertices();
      for (int i = 0; i < vt.length; i++)
      {
        if (!visible[i])
          continue;
        if (sel && !selected[i] && priorityToSelected)
          continue;
        Point v1 = screenVert[i];
        if (pos.x < v1.x-HANDLE_SIZE/2 || pos.x > v1.x+HANDLE_SIZE/2 ||
            pos.y < v1.y-HANDLE_SIZE/2 || pos.y > v1.y+HANDLE_SIZE/2)
          continue;
        z = theCamera.getObjectToView().timesZ(vt[i].r);
        if (z < closestz || (!sel && selected[i] && priorityToSelected))
        {
          which = i;
          closestz = z;
          sel = selected[i];
        }
      }
    }
    else if (controller.getSelectionMode() == MeshEditController.EDGE_MODE)
    {
      TriangleMesh mesh = (TriangleMesh) getController().getObject().getObject();
      Vertex vt[];
      Edge ed[], origEd[] = mesh.getEdges();
      int projectedEdge[] = null;
      if (controller instanceof TriMeshEditorWindow)
        projectedEdge = ((TriMeshEditorWindow) controller).findProjectedEdges();
      if (projectedEdge != null)
        mesh = ((TriMeshEditorWindow) controller).getSubdividedMesh();
      vt = (Vertex []) mesh.getVertices();
      ed = mesh.getEdges();
      boolean hideEdge[] = (controller instanceof TriMeshEditorWindow ? ((TriMeshEditorWindow) controller).hideEdge : new boolean [ed.length]);
      for (int i = 0; i < ed.length; i++)
      {
        Point v1, v2;
        if (projectedEdge == null)
        {
          if (!visible[ed[i].v1] || !visible[ed[i].v2])
            continue;
          if (hideEdge[i])
            continue;
          if (sel && !selected[i] && priorityToSelected)
            continue;
          v1 = screenVert[ed[i].v1];
          v2 = screenVert[ed[i].v2];
        }
        else
        {
          int orig = projectedEdge[i];
          if (orig == -1)
            continue;
          if (!visible[origEd[orig].v1] || !visible[origEd[orig].v2])
            continue;
          if (hideEdge[orig])
            continue;
          if (sel && !selected[orig] && priorityToSelected)
            continue;
          Vec2 screen1 = theCamera.getObjectToScreen().timesXY(vt[ed[i].v1].r);
          Vec2 screen2 = theCamera.getObjectToScreen().timesXY(vt[ed[i].v2].r);
          v1 = new Point((int) screen1.x, (int) screen1.y);
          v2 = new Point((int) screen2.x, (int) screen2.y);
        }
        if ((pos.x < v1.x-HANDLE_SIZE/2 && pos.x < v2.x-HANDLE_SIZE/2) ||
                (pos.x > v1.x+HANDLE_SIZE/2 && pos.x > v2.x+HANDLE_SIZE/2) ||
                (pos.y < v1.y-HANDLE_SIZE/2 && pos.y < v2.y-HANDLE_SIZE/2) ||
                (pos.y > v1.y+HANDLE_SIZE/2 && pos.y > v2.y+HANDLE_SIZE/2))
          continue;

        // Determine the distance of the click point from the line.

        if (Math.abs(v1.x-v2.x) > Math.abs(v1.y-v2.y))
        {
          if (v2.x > v1.x)
          {
            v = ((double) pos.x-v1.x)/(v2.x-v1.x);
            u = 1.0-v;
          }
          else
          {
            u = ((double) pos.x-v2.x)/(v1.x-v2.x);
            v = 1.0-u;
          }
          w = u*v1.y + v*v2.y - pos.y;
        }
        else
        {
          if (v2.y > v1.y)
          {
            v = ((double) pos.y-v1.y)/(v2.y-v1.y);
            u = 1.0-v;
          }
          else
          {
            u = ((double) pos.y-v2.y)/(v1.y-v2.y);
            v = 1.0-u;
          }
          w = u*v1.x + v*v2.x - pos.x;
        }
        if (Math.abs(w) > HANDLE_SIZE/2)
          continue;
        int index = (projectedEdge == null ? i : projectedEdge[i]);
        z = u*theCamera.getObjectToView().timesZ(vt[ed[i].v1].r) +
                v*theCamera.getObjectToView().timesZ(vt[ed[i].v2].r);
        if (z < closestz || (!sel && selected[index] && priorityToSelected))
        {
          which = index;
          closestz = z;
          sel = selected[which];
          if (uvw != null)
            uvw.set(u, v, w);
        }
      }
    }
    else
    {
      TriangleMesh mesh = null;
      if (controller instanceof TriMeshEditorWindow)
        mesh = ((TriMeshEditorWindow) controller).getSubdividedMesh();
      if (mesh == null)
        mesh = (TriangleMesh) getController().getObject().getObject();
      Vertex vt[] = (Vertex []) mesh.getVertices();
      Face fc[] = mesh.getFaces();
      Face origFc[] = ((TriangleMesh) getController().getObject().getObject()).getFaces();
      double param[] = null;
      boolean hideFace[] = null;
      if (controller instanceof TriMeshEditorWindow)
      {
        TriMeshEditorWindow win = (TriMeshEditorWindow) controller;
        if (win.getFaceIndexParameter() != null)
          param = ((FaceParameterValue) mesh.getParameterValue(win.getFaceIndexParameter())).getValue();
        hideFace = win.hideFace;
      }
      for (int i = 0; i < fc.length; i++)
      {
        int index = (param == null ? i : (int) param[i]);
View Full Code Here

    objInfo.clearCachedMeshes();
  }
 
  public void setMesh(Mesh mesh)
  {
    TriangleMesh obj = (TriangleMesh) mesh;
    setObject(obj);
    this.mesh = obj;
    hideVert = new boolean [mesh.getVertices().length];
    for (int i = 0; i < theView.length; i++)
    {
      if (getSelectionMode() == POINT_MODE && selected.length != obj.getVertices().length)
        {
          selected = new boolean [obj.getVertices().length];
          ((TriMeshViewer) theView[i]).visible = new boolean [obj.getVertices().length];
        }
      if (getSelectionMode() == EDGE_MODE && selected.length != obj.getEdges().length)
        {
          selected = new boolean [obj.getEdges().length];
          ((TriMeshViewer) theView[i]).visible = new boolean [obj.getEdges().length];
        }
      if (getSelectionMode() == FACE_MODE && selected.length != obj.getFaces().length)
        {
          selected = new boolean [obj.getFaces().length];
          ((TriMeshViewer) theView[i]).visible = new boolean [obj.getFaces().length];
        }
    }
    if (hideFace != null)
    {
      boolean oldHideFace[] = hideFace;
      FaceParameterValue val = (FaceParameterValue) getObject().getObject().getParameterValue(faceIndexParam);
      double param[] = val.getValue();
      hideFace = new boolean [obj.getFaces().length];
      for (int i = 0; i < param.length; i++)
      {
        int index = (int) param[i];
        if (index < oldHideFace.length)
          hideFace[i] = oldHideFace[index];
View Full Code Here

  }

  public void updateMenus()
  {
    super.updateMenus();
    TriangleMesh theMesh = (TriangleMesh) objInfo.getObject();
    MeshViewer view = (MeshViewer) theView[currentView];
    boolean any = false;
    int i;
   
    for (i = 0; i < selected.length && !selected[i]; i++);
    if (i < selected.length)
    {
      any = true;
      editMenuItem[0].setEnabled(true);
      editMenuItem[1].setEnabled(true);
      editMenuItem[6].setEnabled(true);
      for (i = 0; i < 12; i++)
        meshMenuItem[i].setEnabled(true);
      if (selectMode == EDGE_MODE)
      {
        meshMenuItem[0].setText(Translate.text("menu.subdivideEdges"));
        int boundaryList[][] = findSelectedBoundaries();
        meshMenuItem[6].setEnabled(false);
        meshMenuItem[7].setEnabled(boundaryList.length > 0);
        meshMenuItem[8].setEnabled(boundaryList.length == 2);
        meshMenuItem[9].setEnabled(false);
      }
      else if (selectMode == FACE_MODE)
      {
        meshMenuItem[0].setText(Translate.text("menu.subdivideFaces"));
        meshMenuItem[7].setEnabled(false);
        meshMenuItem[8].setEnabled(false);
        meshMenuItem[10].setEnabled(false);
        meshMenuItem[11].setEnabled(false);
      }
      else
      {
        meshMenuItem[0].setEnabled(false);
        meshMenuItem[7].setEnabled(false);
        meshMenuItem[8].setEnabled(false);
        meshMenuItem[9].setEnabled(false);
        meshMenuItem[10].setEnabled(false);
      }
      meshMenuItem[1].setText(Translate.text("menu.simplify"));
    }
    else   
    {
      editMenuItem[0].setEnabled(false);
      editMenuItem[1].setEnabled(false);
      editMenuItem[6].setEnabled(false);
      meshMenuItem[0].setEnabled(false);
      for (i = 2; i < 12; i++)
        meshMenuItem[i].setEnabled(false);
      meshMenuItem[1].setText(Translate.text("menu.simplifyMesh"));
    }
    editMenuItem[5].setEnabled(theMesh.getSmoothingMethod() == TriangleMesh.APPROXIMATING || theMesh.getSmoothingMethod() == TriangleMesh.INTERPOLATING);
    selectMenuItem[0].setEnabled(!objInfo.getObject().isClosed());
    selectMenuItem[1].setEnabled(any);
    selectMenuItem[2].setEnabled(any && selectMode == EDGE_MODE);
    selectMenuItem[3].setEnabled(any && selectMode == EDGE_MODE);
    Skeleton s = theMesh.getSkeleton();
    Joint selJoint = s.getJoint(view.getSelectedJoint());
    skeletonMenuItem[0].setEnabled(selJoint != null);
    skeletonMenuItem[1].setEnabled(selJoint != null && selJoint.children.length == 0);
    skeletonMenuItem[2].setEnabled(selJoint != null);
    skeletonMenuItem[4].setEnabled(any);
View Full Code Here

  {
    if (faceIndexParam != null)
      return;
    faceIndexParam = new TextureParameter(this, "Face Index", 0.0, Double.MAX_VALUE, 0.0);
    jointWeightParam = new TextureParameter(this, "Joint Weight", 0.0, 1.0, 0.0);
    TriangleMesh mesh = (TriangleMesh) getObject().getObject();
    TextureParameter params[] = mesh.getParameters();
    TextureParameter newparams[] = new TextureParameter [params.length+2];
    ParameterValue values[] = mesh.getParameterValues();
    ParameterValue newvalues[] = new ParameterValue [values.length+2];
    for (int i = 0; i < params.length; i++)
    {
      newparams[i] = params[i];
      newvalues[i] = values[i];
    }
    newparams[params.length] = faceIndexParam;
    newvalues[values.length] = new FaceParameterValue(mesh, faceIndexParam);
    double faceIndex[] = new double [mesh.getFaces().length];
    for (int i = 0; i < faceIndex.length; i++)
      faceIndex[i] = i;
    ((FaceParameterValue) newvalues[values.length]).setValue(faceIndex);
    newparams[params.length+1] = jointWeightParam;
    newvalues[values.length+1] = new VertexParameterValue(mesh, jointWeightParam);
    mesh.setParameters(newparams);
    mesh.setParameterValues(newvalues);
    getObject().clearCachedMeshes();
    updateJointWeightParam();
  }
View Full Code Here

TOP

Related Classes of artofillusion.object.TriangleMesh

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.