private void pushTexCoord(Attributes attribs) throws SAXException { if (texCoordIndex >= 8) { return; // More than 8 not supported by ogre. } Type type = TEXCOORD_TYPES[texCoordIndex]; VertexBuffer tcvb = mesh.getBuffer(type); FloatBuffer buf = (FloatBuffer) tcvb.getData(); buf.put(parseFloat(attribs.getValue("u"))); if (tcvb.getNumComponents() >= 2) { buf.put(parseFloat(attribs.getValue("v"))); if (tcvb.getNumComponents() >= 3) { buf.put(parseFloat(attribs.getValue("w"))); if (tcvb.getNumComponents() == 4) { buf.put(parseFloat(attribs.getValue("x"))); } } } texCoordIndex++; }
private void pushTangent(Attributes attribs) throws SAXException { try { VertexBuffer tangentBuf = mesh.getBuffer(Type.Tangent); FloatBuffer buf = (FloatBuffer) tangentBuf.getData(); buf.put(parseFloat(attribs.getValue("x"))).put(parseFloat(attribs.getValue("y"))).put(parseFloat(attribs.getValue("z"))); if (tangentBuf.getNumComponents() == 4) { buf.put(parseFloat(attribs.getValue("w"))); } } catch (Exception ex) { throw new SAXException("Failed to push attrib", ex); } }
public static void printMesh(Mesh mesh) { for (int bufType = 0; bufType < Type.values().length; bufType++) { VertexBuffer outBuf = mesh.getBuffer(Type.values()[bufType]); if (outBuf == null) { continue; } System.out.println(outBuf.getBufferType() + ": "); for (int vert = 0; vert < outBuf.getNumElements(); vert++) { String str = "["; for (int comp = 0; comp < outBuf.getNumComponents(); comp++) { Object val = outBuf.getElementComponent(vert, comp); outBuf.setElementComponent(vert, comp, val); val = outBuf.getElementComponent(vert, comp); str += val; if (comp != outBuf.getNumComponents() - 1) { str += ", "; } } str += "]"; System.out.println(str); } System.out.println("------"); } }
if (tc.getNumComponents() != 2) { throw new UnsupportedOperationException("Only 2D texture coords are supported");
if(vb==null || vb.getNumComponents() == 0) continue; }else{ Buffer newVerts = VertexBuffer.createBuffer(vb.getFormat(), vb.getNumComponents(), nbVertices); if (buffer != null) { buffer.rewind(); newVerts.position(vertexData.size() * vb.getNumComponents()); for (int j = 0; j < newVertices.size(); j++) { int oldInd = indiceMap.get(index) ; for (int i = 0; i < vb.getNumComponents(); i++) { putValue(vb.getFormat(), newVerts, buffer, oldInd* vb.getNumComponents() + i);
/** * Update the {@link #getVertexCount() vertex} and * {@link #getTriangleCount() triangle} counts for this mesh * based on the current data. This method should be called * after the {@link Buffer#capacity() capacities} of the mesh's * {@link VertexBuffer vertex buffers} has been altered. * * @throws IllegalStateException If this mesh is in * {@link #setInterleaved() interleaved} format. */ public void updateCounts(){ if (getBuffer(Type.InterleavedData) != null) { throw new IllegalStateException("Should update counts before interleave"); } VertexBuffer pb = getBuffer(Type.Position); VertexBuffer ib = getBuffer(Type.Index); if (pb != null){ vertCount = pb.getData().limit() / pb.getNumComponents(); } if (ib != null){ elementCount = computeNumElements(ib.getData().limit()); }else{ elementCount = computeNumElements(vertCount); } instanceCount = computeInstanceCount(); }
case BoneIndex: case HWBoneIndex: b = BufferUtils.createIntBuffer(geom.getMesh().getVertexCount() * types.get(type).getNumComponents()); break; case InterleavedData: b = BufferUtils.createByteBuffer(geom.getMesh().getVertexCount() * types.get(type).getNumComponents()); break; default: b = BufferUtils.createFloatBuffer(geom.getMesh().getVertexCount() * types.get(type).getNumComponents()); vb.setupData(types.get(type).getUsage(), types.get(type).getNumComponents(), types.get(type).getFormat(), b); geom.getMesh().setBuffer(vb); logger.log(Level.FINE, "geom {0} misses buffer {1}. Creating", new Object[]{geom.getName(), type});
/** * Creates a {@link VertexBuffer} for the mesh or modifies * the existing one per the parameters given. * * @param type The type of the buffer * @param components Number of components * @param format Data format * @param buf The buffer data * * @throws UnsupportedOperationException If the buffer already set is * incompatible with the parameters given. */ public void setBuffer(Type type, int components, Format format, Buffer buf){ VertexBuffer vb = buffers.get(type.ordinal()); if (vb == null){ vb = new VertexBuffer(type); vb.setupData(Usage.Dynamic, components, format, buf); setBuffer(vb); }else{ if (vb.getNumComponents() != components || vb.getFormat() != format){ throw new UnsupportedOperationException("The buffer already set " + "is incompatible with the given parameters"); } vb.updateData(buf); updateCounts(); } }
/** * Gets the triangle vertex positions at the given triangle index * and stores them into the v1, v2, v3 arguments. * * @param index The index of the triangle. * Should be between 0 and {@link #getTriangleCount()}. * * @param v1 Vector to contain first vertex position * @param v2 Vector to contain second vertex position * @param v3 Vector to contain third vertex position */ public void getTriangle(int index, Vector3f v1, Vector3f v2, Vector3f v3){ VertexBuffer pb = getBuffer(Type.Position); IndexBuffer ib = getIndicesAsList(); if (pb != null && pb.getFormat() == Format.Float && pb.getNumComponents() == 3){ FloatBuffer fpb = (FloatBuffer) pb.getData(); // aquire triangle's vertex indices int vertIndex = index * 3; int vert1 = ib.get(vertIndex); int vert2 = ib.get(vertIndex+1); int vert3 = ib.get(vertIndex+2); BufferUtils.populateFromBuffer(v1, fpb, vert1); BufferUtils.populateFromBuffer(v2, fpb, vert2); BufferUtils.populateFromBuffer(v3, fpb, vert3); }else{ throw new UnsupportedOperationException("Position buffer not set or " + " has incompatible format"); } }
if (vb.getNumComponents() > 4) { if (vb.getNumComponents() % 4 != 0) { throw new RendererException("Number of components in multi-slot " + "buffers must be divisible by 4"); slotsRequired = vb.getNumComponents() / 4; vb.getNumComponents(), convertFormat(vb.getFormat()), vb.isNormalized(),
pos.getNumComponents(), pos.getFormat(), BufferUtils.clone(pos.getData())); VertexBuffer bindNorm = new VertexBuffer(Type.BindPoseNormal); bindNorm.setupData(Usage.CpuOnly, norm.getNumComponents(), norm.getFormat(), BufferUtils.clone(norm.getData())); VertexBuffer bindTangents = new VertexBuffer(Type.BindPoseTangent); bindTangents.setupData(Usage.CpuOnly, tangents.getNumComponents(), tangents.getFormat(), BufferUtils.clone(tangents.getData()));
oldIdxBuf.getNumComponents(), newIndexBuf instanceof IndexIntBuffer ? Format.UnsignedInt : Format.UnsignedShort, newIndexBuf.getBuffer()); Buffer buffer = VertexBuffer.createBuffer(oldVb.getFormat(), oldVb.getNumComponents(), newNumVerts); newVb.setupData(oldVb.getUsage(), oldVb.getNumComponents(), oldVb.getFormat(), buffer);
FloatBuffer lineColor = BufferUtils.createFloatBuffer(vertexBuffer.limit() / 3 * 4 * 4); boolean hasParity = mesh.getBuffer(Type.Tangent).getNumComponents() == 4; float tangentW = 1;
result = directIndex; indicesHW.setupData(Usage.Static, indices.getNumComponents(), indices.getFormat(), result); originalWeight.clear(); directWeight.put(originalWeight); weightsHW.setupData(Usage.Static, weights.getNumComponents(), weights.getFormat(), directWeight);
if (vb.getBufferType() != Type.Index && currentCompsForBuf != 0 && currentCompsForBuf != vb.getNumComponents()) { throw new UnsupportedOperationException("The geometry " + geom + " buffer " + vb.getBufferType() + " has different number of components than the rest of the meshes " + "(this: " + vb.getNumComponents() + ", expected: " + currentCompsForBuf + ")"); compsForBuf[vb.getBufferType().ordinal()] = vb.getNumComponents(); formatForBuf[vb.getBufferType().ordinal()] = vb.getFormat(); normForBuf[vb.getBufferType().ordinal()] = vb.isNormalized(); FloatBuffer inPos = (FloatBuffer) inBuf.getDataReadOnly(); FloatBuffer outPos = (FloatBuffer) outBuf.getData(); int components = inBuf.getNumComponents(); doTransformTangents(inPos, globalVertIndex, components, outPos, worldMatrix); } else {
if (vb.getBufferType() != VertexBuffer.Type.Index && currentCompsForBuf != 0 && currentCompsForBuf != vb.getNumComponents()) { throw new UnsupportedOperationException("The geometry " + geom + " buffer " + vb.getBufferType() + " has different number of components than the rest of the meshes " + "(this: " + vb.getNumComponents() + ", expected: " + currentCompsForBuf + ")"); compsForBuf[vb.getBufferType().ordinal()] = vb.getNumComponents(); formatForBuf[vb.getBufferType().ordinal()] = vb.getFormat(); normForBuf[vb.getBufferType().ordinal()] = vb.isNormalized();
private void pushTangent(Attributes attribs) throws SAXException { try { VertexBuffer tangentBuf = mesh.getBuffer(Type.Tangent); FloatBuffer buf = (FloatBuffer) tangentBuf.getData(); buf.put(parseFloat(attribs.getValue("x"))).put(parseFloat(attribs.getValue("y"))).put(parseFloat(attribs.getValue("z"))); if (tangentBuf.getNumComponents() == 4) { buf.put(parseFloat(attribs.getValue("w"))); } } catch (Exception ex) { throw new SAXException("Failed to push attrib", ex); } }
private void pushTangent(Attributes attribs) throws SAXException { try { VertexBuffer tangentBuf = mesh.getBuffer(Type.Tangent); FloatBuffer buf = (FloatBuffer) tangentBuf.getData(); buf.put(parseFloat(attribs.getValue("x"))).put(parseFloat(attribs.getValue("y"))).put(parseFloat(attribs.getValue("z"))); if (tangentBuf.getNumComponents() == 4) { buf.put(parseFloat(attribs.getValue("w"))); } } catch (Exception ex) { throw new SAXException("Failed to push attrib", ex); } }
private void pushTangent(Attributes attribs) throws SAXException { try { VertexBuffer tangentBuf = mesh.getBuffer(Type.Tangent); FloatBuffer buf = (FloatBuffer) tangentBuf.getData(); buf.put(parseFloat(attribs.getValue("x"))).put(parseFloat(attribs.getValue("y"))).put(parseFloat(attribs.getValue("z"))); if (tangentBuf.getNumComponents() == 4) { buf.put(parseFloat(attribs.getValue("w"))); } } catch (Exception ex) { throw new SAXException("Failed to push attrib", ex); } }
public static VertexBuffer convertToUByte(VertexBuffer vb){ FloatBuffer fb = (FloatBuffer) vb.getData(); ByteBuffer bb = BufferUtils.createByteBuffer(fb.capacity()); convertToUByte(fb, bb); VertexBuffer newVb = new VertexBuffer(vb.getBufferType()); newVb.setupData(vb.getUsage(), vb.getNumComponents(), Format.UnsignedByte, bb); newVb.setNormalized(true); return newVb; }