Advertisement
Guest User

applyOutput()

a guest
Feb 25th, 2013
123
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.64 KB | None | 0 0
  1.   public static void applyOutput(final DecalMeshGenerator.Output output, final Mesh decalMesh)
  2.   {
  3.     applyOutput(output, decalMesh, false);
  4.   }
  5.  
  6.   private static void applyDynamicFloatArray(final Mesh decalMesh, final VertexBuffer.Type type, final int components, final DynamicFloatArray src)
  7.   {
  8.     VertexBuffer destVB = decalMesh.getBuffer(type);
  9.     if (destVB != null)
  10.     {
  11.       FloatBuffer dest = (FloatBuffer)destVB.getData();
  12.       if (dest != null && dest.capacity() >= src.getLength())
  13.       {
  14.         dest.clear();
  15.         src.toFloatBuffer(dest);
  16.         dest.position(0).limit(src.getLength());
  17.         destVB.updateData(dest);
  18.         return;
  19.       }
  20.     }
  21.    
  22.     decalMesh.setBuffer(type, components, src.toFloatBuffer());
  23.   }
  24.  
  25.   public static void applyOutput(final DecalMeshGenerator.Output output, final Mesh decalMesh, boolean generateIndexData)
  26.   {
  27.     applyDynamicFloatArray(decalMesh, VertexBuffer.Type.Position, 3, output.Positions);
  28.     applyDynamicFloatArray(decalMesh, VertexBuffer.Type.Normal, 3, output.Normals);
  29.     applyDynamicFloatArray(decalMesh, VertexBuffer.Type.TexCoord, 2, output.TexCoords);
  30.    
  31.     if (generateIndexData)
  32.     {
  33.       int indexDataSize = output.Positions.getLength() / 3;
  34.       IndexBuffer ib = decalMesh.getIndexBuffer();
  35.       Buffer ibb;
  36.       if (ib != null)
  37.       {
  38.         ibb = ib.getBuffer();
  39.         if (ibb != null && ibb.capacity() >= indexDataSize)
  40.         {
  41.           ibb.limit(indexDataSize).rewind();
  42.         }
  43.         else
  44.         {
  45.           ib = IndexBuffer.createIndexBuffer(indexDataSize, indexDataSize);
  46.           ibb = ib.getBuffer();
  47.         }
  48.       }
  49.       else
  50.       {
  51.         ib = IndexBuffer.createIndexBuffer(indexDataSize, indexDataSize);
  52.         ibb = ib.getBuffer();        
  53.       }
  54.      
  55.       for (int i = 0; i < indexDataSize; i++)
  56.       {
  57.         ib.put(i, i);
  58.       }
  59.      
  60.       if (ibb instanceof IntBuffer)
  61.       {
  62.         decalMesh.setBuffer(VertexBuffer.Type.Index, 3, (IntBuffer)ibb);        
  63.       }
  64.       else
  65.       {
  66.         decalMesh.setBuffer(VertexBuffer.Type.Index, 3, (ShortBuffer)ibb);                
  67.       }        
  68.     }
  69.     else
  70.     {
  71.       decalMesh.clearBuffer(VertexBuffer.Type.Index);
  72.     }
  73.  
  74.     if (output.Tangents != null)
  75.     {
  76.       applyDynamicFloatArray(decalMesh, VertexBuffer.Type.Tangent, 4, output.Tangents);
  77.       output.Tangents.reset();
  78.     }
  79.     else
  80.     {
  81.       decalMesh.clearBuffer(VertexBuffer.Type.Tangent);
  82.     }
  83.  
  84.     output.Positions.reset();
  85.     output.Normals.reset();
  86.     output.TexCoords.reset();
  87.  
  88.     decalMesh.updateCounts();
  89.     decalMesh.updateBound();
  90.   }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement