public void copyVertex(int id, int offset, VertexBuffer vbuffer) { assert (id + offset < vcount) : "The destination vertex is not in bound of the destination buffer"; if (layout.equals(vbuffer.layout)) { ByteBuffer buf = vbuffer.buffer; int limit = offset + layout.getBytesize(); assert !(limit <= buf.capacity() || id > vcount) : "Couldn't copy Vertex"; buf.position(offset); buf.limit(limit); buffer.position(layout.getBytesize() * id); buffer.put(buf); } else { Vertex src = vbuffer.getVertex(id); Vertex dst = getVertex(id + offset); for (Element e : layout.getElements()) { if (vbuffer.layout.hasElement(e)) { dst.setAttribute(e, src.getAttribute(e)); } } } }
if (!vbuffer.layout.hasElement(POSITION)) { throw new IOException("The mesh doesn't have a float3 vertex position attribute!"); if (vbuffer.layout.hasElement(NORMAL)) { normals = new float[vc * CTM_NORMAL_ELEMENT_COUNT]; int k = 0; boolean hasUV = vbuffer.layout.hasElement(TEX_COORD); AttributeData[] texcoords = new AttributeData[hasUV ? 1 : 0]; if (hasUV) {
@Override public Mesh modifie(Mesh m) { VertexBuffer old = m.getVertices(); DataLayout layout = old.layout; boolean hasattr = layout.hasElement(position) && layout.hasElement(normal) && layout.hasElement(texcoord); if (m.getPrimitiv_typ() != GL.GL_TRIANGLES || !hasattr) { logger.warn("Mesh can't be transformed," + " only Triangle Meshs allowed!"); return m; } layout = new DataLayout(layout, tangent); VertexBuffer vb = new VertexBuffer(layout, old.getVcount()); vb.copyInto(0, old); int[] indice = m.getIndicies(); for (int i = 0; i < m.getIndexCount(); i += 3) { Vertex v0 = vb.getVertex(indice[i]); Vertex v1 = vb.getVertex(indice[i + 1]); Vertex v2 = vb.getVertex(indice[i + 2]); v0.setAttribute(tangent, calculateTangent(v0, v1, v2)); v1.setAttribute(tangent, calculateTangent(v1, v2, v0)); v2.setAttribute(tangent, calculateTangent(v2, v0, v1)); } return new Mesh(m.getIndicies(), vb, m.getPrimitiv_typ()); }