Package artofillusion.object

Examples of artofillusion.object.TriangleMesh$TriangleMeshKeyframe


  {
    if (faceIndexParam == null)
      return;
    faceIndexParam = null;
    jointWeightParam = null;
    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 < newparams.length; i++)
    {
      newparams[i] = params[i];
      newvalues[i] = values[i];
    }
    mesh.setParameters(newparams);
    mesh.setParameterValues(newvalues);
    getObject().clearCachedMeshes();
  }
View Full Code Here


    return divMesh;
  }

  protected void doOk()
  {
    TriangleMesh theMesh = (TriangleMesh) objInfo.getObject();
    if (((TriangleMesh) oldMesh).getMaterial() != null)
    {
      if (!theMesh.isClosed())
      {
        String options[] = new String [] {Translate.text("button.ok"), Translate.text("button.cancel")};
        BStandardDialog dlg = new BStandardDialog("", UIUtilities.breakString(Translate.text("surfaceNoLongerClosed")), BStandardDialog.WARNING);
        int choice = dlg.showOptionDialog(this, options, options[0]);
        if (choice == 1)
          return;
        theMesh.setMaterial(null, null);
      }
      else
        theMesh.setMaterial(((TriangleMesh) oldMesh).getMaterial(), ((TriangleMesh) oldMesh).getMaterialMapping());
    }
    removeExtraParameters();
    oldMesh.copyObject(theMesh);
    oldMesh = null;
    dispose();
View Full Code Here

 
  /** Find edges which should be hidden to make the object seem to be made of quads. */
 
  private void findQuads()
  {
    TriangleMesh mesh = (TriangleMesh) getObject().getObject();
    Vertex v[] = (Vertex []) mesh.getVertices();
    Edge e[] = mesh.getEdges();
    Face f[] = mesh.getFaces();
    if (hideEdge == null || hideEdge.length != e.length)
      hideEdge = new boolean [e.length];
    if (hideFace == null)
      for (int i = 0; i < e.length; i++)
        hideEdge[i] = false;
View Full Code Here

  /** When the selection mode changes, do our best to convert the old selection to the
      new mode. */
 
  public void setSelectionMode(int mode)
  {
    TriangleMesh mesh = (TriangleMesh) getObject().getObject();
    Vertex v[] = (Vertex []) mesh.getVertices();
    Edge e[] = mesh.getEdges();
    Face f[] = mesh.getFaces();
    boolean newSel[];
    int i;
   
    if (mode == selectMode)
      return;
View Full Code Here

  /** Calculate the distance (in edges) between each vertex and the nearest selected vertex. */

  void findSelectionDistance()
  {
    int i, j;
    TriangleMesh mesh = (TriangleMesh) getObject().getObject();
    int dist[] = new int [mesh.getVertices().length];
    Edge e[] = mesh.getEdges();
    Face f[] = mesh.getFaces();
   
    maxDistance = getTensionDistance();
   
    // First, set each distance to 0 or -1, depending on whether that vertex is part of the
    // current selection.
View Full Code Here

 
  /** Hide the selected part of the mesh. */
 
  public void hideSelectionCommand()
  {
    TriangleMesh theMesh = (TriangleMesh) objInfo.getObject();
    boolean hide[] = new boolean [theMesh.getFaces().length];
    if (selectMode == FACE_MODE)
      System.arraycopy(selected, 0, hide, 0, selected.length);
    else if (selectMode == EDGE_MODE)
    {
      TriangleMesh.Edge edge[] = theMesh.getEdges();
      for (int i = 0; i < selected.length; i++)
        if (selected[i])
          hide[edge[i].f1] = hide[edge[i].f2] = true;
    }
    else
    {
      TriangleMesh.Face face[] = theMesh.getFaces();
      for (int i = 0; i < face.length; i++)
        hide[i] = (selected[face[i].v1] || selected[face[i].v2] || selected[face[i].v3]);
    }
    boolean wasHidden[] = hideFace;
    if (wasHidden != null)
View Full Code Here

 
  /** Select the edges which form the boundary of the mesh. */
 
  public void selectObjectBoundaryCommand()
  {
    TriangleMesh theMesh = (TriangleMesh) objInfo.getObject();
    TriangleMesh.Edge edge[] = theMesh.getEdges();
    boolean newSel[] = new boolean [edge.length];
   
    for (int i = 0; i < newSel.length; i++)
      newSel[i] = (edge[i].f2 == -1);
    setUndoRecord(new UndoRecord(this, false, UndoRecord.SET_MESH_SELECTION, new Object [] {this, new Integer(selectMode), selected}));
View Full Code Here

  /** Extend the selection outward by one edge. */

  public void extendSelectionCommand()
  {
    TriangleMesh theMesh = (TriangleMesh) objInfo.getObject();
    int dist[] = getSelectionDistance();
    boolean selectedVert[] = new boolean [dist.length];
    TriangleMesh.Edge edge[] = theMesh.getEdges();
   
    setUndoRecord(new UndoRecord(this, false, UndoRecord.SET_MESH_SELECTION, new Object [] {this, new Integer(selectMode), selected.clone()}));
    for (int i = 0; i < edge.length; i++)
      if ((dist[edge[i].v1] == 0 || dist[edge[i].v2] == 0) && !isEdgeHidden(i))
        selectedVert[edge[i].v1] = selectedVert[edge[i].v2] = true;
    if (selectMode == POINT_MODE)
      setSelection(selectedVert);
    else if (selectMode == EDGE_MODE)
    {
      for (int i = 0; i < edge.length; i++)
        selected[i] = (selectedVert[edge[i].v1] && selectedVert[edge[i].v2]);
      setSelection(selected);
    }
    else
    {
      TriangleMesh.Face face[] = theMesh.getFaces();
      for (int i = 0; i < face.length; i++)
        selected[i] = (selectedVert[face[i].v1] && selectedVert[face[i].v2] && selectedVert[face[i].v3]);
      setSelection(selected);
    }
  }
View Full Code Here

 
  public void deleteCommand()
  {
    if (!topology)
      return;
    TriangleMesh theMesh = (TriangleMesh) objInfo.getObject();
    Vertex vert[] = (Vertex []) theMesh.getVertices();
    Edge edge[] = theMesh.getEdges();
    Face face[] = theMesh.getFaces();
    boolean deleteVert[] = new boolean [vert.length];
    boolean deleteFace[] = new boolean [face.length];

    // Determine which parts of the mesh to delete.
   
    if (selectMode == POINT_MODE)
    {
      for (int i = 0; i < deleteVert.length; i++)
        deleteVert[i] = selected[i];
      for (int i = 0; i < deleteFace.length; i++)
        deleteFace[i] = (deleteVert[face[i].v1] || deleteVert[face[i].v2] || deleteVert[face[i].v3]);
    }
    else if (selectMode == EDGE_MODE)
    {
      for (int i = 0; i < deleteFace.length; i++)
        deleteFace[i] = (selected[face[i].e1] || selected[face[i].e2] || selected[face[i].e3]);
      for (int i = 0; i < deleteVert.length; i++)
        deleteVert[i] = true;
      for (int i = 0; i < deleteFace.length; i++)
        if (!deleteFace[i])
          deleteVert[face[i].v1] = deleteVert[face[i].v2] = deleteVert[face[i].v3] = false;
    }
    else
    {
      for (int i = 0; i < deleteFace.length; i++)
        deleteFace[i] = selected[i];
      for (int i = 0; i < deleteVert.length; i++)
        deleteVert[i] = true;
      for (int i = 0; i < deleteFace.length; i++)
        if (!deleteFace[i])
          deleteVert[face[i].v1] = deleteVert[face[i].v2] = deleteVert[face[i].v3] = false;
    }
   
    // Make sure this will still be a valid object.
   
    for (int i = 0; i < vert.length; i++)
    {
      int e[] = vert[i].getEdges();
      int f, fprev = edge[e[0]].f1, breaks = 0;
      for (int j = 1; j < e.length; j++)
      {
        f = (edge[e[j]].f1 == fprev ? edge[e[j]].f2 : edge[e[j]].f1);
        if (f == -1)
          break;
        if (!deleteFace[fprev] && deleteFace[f])
          breaks++;
        fprev = f;
      }
      if (!deleteFace[fprev] && (edge[e[0]].f2 == -1 || deleteFace[edge[e[0]].f1]))
        breaks++;
      int vertFaceCount[] = new int [vert.length];
      for (int j = 0; j < face.length; j++)
        if (!deleteFace[j])
        {
          vertFaceCount[face[j].v1]++;
          vertFaceCount[face[j].v2]++;
          vertFaceCount[face[j].v3]++;
        }
      boolean strayVert = false;
      for (int j = 0; j < vertFaceCount.length; j++)
        if (!deleteVert[j] && vertFaceCount[j] == 0)
          strayVert = true;
      if (breaks > 1 || strayVert)
      {
        new BStandardDialog("", UIUtilities.breakString(Translate.text("illegalDelete")), BStandardDialog.ERROR).showMessageDialog(this);
        return;
      }
    }
   
    // Find the new lists of vertices and faces.
   
    int newVertCount = 0, newFaceCount = 0;
    int newVertIndex[] = new int [vert.length];
    for (int i = 0; i < deleteVert.length; i++)
    {
      newVertIndex[i] = -1;
      if (!deleteVert[i])
        newVertCount++;
    }
    for (int i = 0; i < deleteFace.length; i++)
      if (!deleteFace[i])
        newFaceCount++;
    Vertex v[] = new Vertex [newVertCount];
    int f[][] = new int [newFaceCount][];
    newVertCount = 0;
    for (int i = 0; i < vert.length; i++)
      if (!deleteVert[i])
      {
        newVertIndex[i] = newVertCount;
        v[newVertCount++] = vert[i];
      }
    newFaceCount = 0;
    for (int i = 0; i < face.length; i++)
      if (!deleteFace[i])
        f[newFaceCount++] = new int [] {newVertIndex[face[i].v1], newVertIndex[face[i].v2], newVertIndex[face[i].v3]};

    // Update the texture parameters.
   
    ParameterValue oldParamVal[] = theMesh.getParameterValues();
    ParameterValue newParamVal[] = new ParameterValue [oldParamVal.length];
    for (int i = 0; i < oldParamVal.length; i++)
    {
      if (oldParamVal[i] instanceof VertexParameterValue)
      {
        double oldval[] = ((VertexParameterValue) oldParamVal[i]).getValue();
        double newval[] = new double [newVertCount];
        for (int j = 0, k = 0; j < oldval.length; j++)
          if (!deleteVert[j])
            newval[k++] = oldval[j];
        newParamVal[i] = new VertexParameterValue(newval);
      }
      else if (oldParamVal[i] instanceof FaceParameterValue)
      {
        double oldval[] = ((FaceParameterValue) oldParamVal[i]).getValue();
        double newval[] = new double [newFaceCount];
        for (int j = 0, k = 0; j < oldval.length; j++)
          if (!deleteFace[j])
            newval[k++] = oldval[j];
        newParamVal[i] = new FaceParameterValue(newval);
      }
      else if (oldParamVal[i] instanceof FaceVertexParameterValue)
      {
        FaceVertexParameterValue fvpv = (FaceVertexParameterValue) oldParamVal[i];
        double newval[][] = new double [newFaceCount][3];
        for (int j = 0, k = 0; j < fvpv.getFaceCount(); j++)
          if (!deleteFace[j])
          {
            newval[k][0] = fvpv.getValue(j, 0);
            newval[k][1] = fvpv.getValue(j, 1);
            newval[k][2] = fvpv.getValue(j, 2);
            k++;
          }
        newParamVal[i] = new FaceVertexParameterValue(newval);
      }
      else
        newParamVal[i] = oldParamVal[i].duplicate();
    }
   
    // Construct the new mesh.
   
    TriangleMesh newmesh = new TriangleMesh(v, f);
    Edge newedge[] = newmesh.getEdges();
    newmesh.getSkeleton().copy(theMesh.getSkeleton());
    newmesh.copyTextureAndMaterial(theMesh);
    newmesh.setSmoothingMethod(theMesh.getSmoothingMethod());
    newmesh.setParameterValues(newParamVal);
   
    // Copy over the smoothness values for edges.
   
    for (int i = 0; i < edge.length; i++)
    {
View Full Code Here

  /** Subdivide selected edges or faces of the mesh. */
 
  public void subdivideCommand()
  {
    int i, j;
    TriangleMesh theMesh = (TriangleMesh) objInfo.getObject(), newmesh;
    boolean newselection[];
    Edge edges[];
    Face faces[];
       
    if (selectMode != EDGE_MODE && selectMode != FACE_MODE)
      return;
    for (i = 0; !selected[i] && i < selected.length; i++);
    if (i == selected.length)
      return;
   
    if (selectMode == EDGE_MODE)
    {
      // Subdivide selected edges, using the appropriate method.

      i = theMesh.getVertices().length;
      if (theMesh.getSmoothingMethod() == TriangleMesh.APPROXIMATING)
        newmesh = TriangleMesh.subdivideLoop(theMesh, selected, Double.MAX_VALUE);
      else if (theMesh.getSmoothingMethod() == TriangleMesh.INTERPOLATING)
        newmesh = TriangleMesh.subdivideButterfly(theMesh, selected, Double.MAX_VALUE);
      else
        newmesh = TriangleMesh.subdivideLinear(theMesh, selected);
      setUndoRecord(new UndoRecord(this, false, UndoRecord.COPY_OBJECT, new Object [] {newmesh, theMesh}));
      setMesh(newmesh);

      // Update the selection.

      edges = newmesh.getEdges();
      newselection = new boolean [edges.length];
      for (j = 0; j < edges.length; j++)
        newselection[j] = (edges[j].v1 >= i || edges[j].v2 >= i);
      setSelection(newselection);
    }
    else
    {
      // Subdivide selected faces.

      i = theMesh.getVertices().length;
      newmesh = TriangleMesh.subdivideFaces(theMesh, selected);
      setUndoRecord(new UndoRecord(this, false, UndoRecord.COPY_OBJECT, new Object [] {newmesh, theMesh}));
      setMesh(newmesh);

      // Update the selection.
View Full Code Here

TOP

Related Classes of artofillusion.object.TriangleMesh$TriangleMeshKeyframe

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.