/** pack all the triangles into 2D rectangle */ public void packTriangles() { int rc = getTriCount(); CanonicalTri ct = new CanonicalTri(); m_packer = new RectPacking(); printf("RectPacking start\n"); long t0 = time(); for (int i = 0; i < rc; i++) { getCanonicalTri(i, ct); // add triangle with a safety gap around it // TODO - make proper margin around triangle // m_packer.addRect(ct.v1x+2*m_gap, ct.v2y + 2*m_gap); m_packer.addRect(ct.getWidth(), ct.getHeight()); if (false) printf("tri: %d %s\n", i, ct); } m_packer.pack(); if (DEBUG) printf("RectPacking done\n"); m_texCoord = new double[6 * m_triCount]; Vector2d origin = new Vector2d(); for (int k = 0; k < m_triCount; k++) { getCanonicalTri(k, ct); m_packer.getRectOrigin(k, origin); // TODO - make proper margin around triangle // origin.x += m_gap; // origin.y += m_gap; int texindex = k * 6; ct.getTexCoord(origin.x, origin.y, texindex, m_texCoord); } // re-build the mesh IndexedTriangleSetBuilder itsb = new IndexedTriangleSetBuilder(); getTriangles(itsb); m_triCoord = itsb.getVertices(); m_triIndex = itsb.getFaces(); m_texCoordIndex = new int[m_triCount * 3]; for (int k = 0; k < m_texCoordIndex.length; k++) { m_texCoordIndex[k] = k; } if (DEBUG) printf("packTriangles() done %d ms\n", time() - t0); }
public Vector2d getPackedSize() { return m_packer.getPackedSize(); }