/** Returns the offset for the first VertexAttribute with the specified usage. * @param usage The usage of the VertexAttribute. */ public int getOffset (int usage, int defaultIfNotFound) { VertexAttribute vertexAttribute = findByUsage(usage); if (vertexAttribute == null) return defaultIfNotFound; return vertexAttribute.offset / 4; }
/** Returns the offset for the first VertexAttribute with the specified usage. * @param usage The usage of the VertexAttribute. */ public int getOffset (int usage, int defaultIfNotFound) { VertexAttribute vertexAttribute = findByUsage(usage); if (vertexAttribute == null) return defaultIfNotFound; return vertexAttribute.offset / 4; }
this.stride = attributes.vertexSize / 4; if (this.vertex == null || this.vertex.length < stride) this.vertex = new float[stride]; VertexAttribute a = attributes.findByUsage(Usage.Position); if (a == null) throw new GdxRuntimeException("Cannot build mesh without position attribute"); posOffset = a.offset / 4; posSize = a.numComponents; a = attributes.findByUsage(Usage.Normal); norOffset = a == null ? -1 : a.offset / 4; a = attributes.findByUsage(Usage.BiNormal); biNorOffset = a == null ? -1 : a.offset / 4; a = attributes.findByUsage(Usage.Tangent); tangentOffset = a == null ? -1 : a.offset / 4; a = attributes.findByUsage(Usage.ColorUnpacked); colOffset = a == null ? -1 : a.offset / 4; colSize = a == null ? 0 : a.numComponents; a = attributes.findByUsage(Usage.ColorPacked); cpOffset = a == null ? -1 : a.offset / 4; a = attributes.findByUsage(Usage.TextureCoordinates); uvOffset = a == null ? -1 : a.offset / 4; setColor(null);
this.stride = attributes.vertexSize / 4; if (this.vertex == null || this.vertex.length < stride) this.vertex = new float[stride]; VertexAttribute a = attributes.findByUsage(Usage.Position); if (a == null) throw new GdxRuntimeException("Cannot build mesh without position attribute"); posOffset = a.offset / 4; posSize = a.numComponents; a = attributes.findByUsage(Usage.Normal); norOffset = a == null ? -1 : a.offset / 4; a = attributes.findByUsage(Usage.BiNormal); biNorOffset = a == null ? -1 : a.offset / 4; a = attributes.findByUsage(Usage.Tangent); tangentOffset = a == null ? -1 : a.offset / 4; a = attributes.findByUsage(Usage.ColorUnpacked); colOffset = a == null ? -1 : a.offset / 4; colSize = a == null ? 0 : a.numComponents; a = attributes.findByUsage(Usage.ColorPacked); cpOffset = a == null ? -1 : a.offset / 4; a = attributes.findByUsage(Usage.TextureCoordinates); uvOffset = a == null ? -1 : a.offset / 4; setColor(null);
int indicesCount = mesh.getNumIndices(); int vertexCount = mesh.getNumVertices(); int vertexSize = (short)(attributes.vertexSize / 4), positionOffset = (short)(attributes.findByUsage(Usage.Position).offset / 4); float[] vertices = new float[vertexCount * vertexSize]; mesh.getVertices(vertices);
int indicesCount = mesh.getNumIndices(); int vertexCount = mesh.getNumVertices(); int vertexSize = (short)(attributes.vertexSize / 4), positionOffset = (short)(attributes.findByUsage(Usage.Position).offset / 4); float[] vertices = new float[vertexCount * vertexSize]; mesh.getVertices(vertices);
ShortBuffer indicesBuffer = mesh.getIndicesBuffer(); int posOffset = mesh.getVertexAttributes().findByUsage(VertexAttributes.Usage.Position).offset / 4; int vertexSize = mesh.getVertexSize() / 4; int currentTriangleFirstVertexIndex = currentTriangleIndex * 3;
/** Returns the offset for the first VertexAttribute with the specified usage. * @param usage The usage of the VertexAttribute. */ public int getOffset (int usage, int defaultIfNotFound) { VertexAttribute vertexAttribute = findByUsage(usage); if (vertexAttribute == null) return defaultIfNotFound; return vertexAttribute.offset / 4; }
/** Begin building a mesh */ public void begin(final VertexAttributes attributes, int primitiveType) { if (this.attributes != null) throw new RuntimeException("Call end() first"); this.attributes = attributes; this.vertices.clear(); this.indices.clear(); this.parts.clear(); this.vindex = 0; this.istart = 0; this.part = null; this.stride = attributes.vertexSize / 4; this.vertex = new float[stride]; VertexAttribute a = attributes.findByUsage(Usage.Position); if (a == null) throw new GdxRuntimeException("Cannot build mesh without position attribute"); posOffset = a.offset / 4; posSize = a.numComponents; a = attributes.findByUsage(Usage.Normal); norOffset = a == null ? -1 : a.offset / 4; a = attributes.findByUsage(Usage.ColorUnpacked); colOffset = a == null ? -1 : a.offset / 4; colSize = a == null ? 0 : a.numComponents; a = attributes.findByUsage(Usage.ColorPacked); cpOffset = a == null ? -1 : a.offset / 4; a = attributes.findByUsage(Usage.TextureCoordinates); uvOffset = a == null ? -1 : a.offset / 4; setColor(null); this.primitiveType = primitiveType; }
this.stride = attributes.vertexSize / 4; if (this.vertex == null || this.vertex.length < stride) this.vertex = new float[stride]; VertexAttribute a = attributes.findByUsage(Usage.Position); if (a == null) throw new GdxRuntimeException("Cannot build mesh without position attribute"); posOffset = a.offset / 4; posSize = a.numComponents; a = attributes.findByUsage(Usage.Normal); norOffset = a == null ? -1 : a.offset / 4; a = attributes.findByUsage(Usage.BiNormal); biNorOffset = a == null ? -1 : a.offset / 4; a = attributes.findByUsage(Usage.Tangent); tangentOffset = a == null ? -1 : a.offset / 4; a = attributes.findByUsage(Usage.ColorUnpacked); colOffset = a == null ? -1 : a.offset / 4; colSize = a == null ? 0 : a.numComponents; a = attributes.findByUsage(Usage.ColorPacked); cpOffset = a == null ? -1 : a.offset / 4; a = attributes.findByUsage(Usage.TextureCoordinates); uvOffset = a == null ? -1 : a.offset / 4; setColor(null);
/** * Creates Vector3 objects from the vertices of the mesh. The resulting array follows the ordering of the provided * index array. * * @param mesh * @param indices * @return */ private static Vector3[] createVertexVectors(Mesh mesh, short[] indices) { FloatBuffer verticesBuffer = mesh.getVerticesBuffer(); int positionOffset = mesh.getVertexAttributes().findByUsage(VertexAttributes.Usage.Position).offset / 4; int vertexSize = mesh.getVertexSize() / 4; Vector3[] vertexVectors = new Vector3[mesh.getNumIndices()]; for (int i = 0; i < indices.length; i++) { short index = indices[i]; int a = index * vertexSize + positionOffset; float x = verticesBuffer.get(a++); float y = verticesBuffer.get(a++); float z = verticesBuffer.get(a); vertexVectors[index] = new Vector3(x, y, z); } return vertexVectors; }
int lastFloat = mesh.getNumVertices() * mesh.getVertexSize() / 4; int vertexFloats = (mesh.getVertexSize() / 4); VertexAttribute posAttr = mesh.getVertexAttributes().findByUsage(VertexAttributes.Usage.Position); VertexAttribute norAttr = mesh.getVertexAttributes().findByUsage(VertexAttributes.Usage.Normal); if (posAttr == null || norAttr == null) { throw new IllegalArgumentException("Position/normal vertex attribute not found");
int positionOffset = mesh.getVertexAttributes().findByUsage(VertexAttributes.Usage.Position).offset / 4;
int indicesCount = mesh.getNumIndices(); int vertexCount = mesh.getNumVertices(); int vertexSize = (short)(attributes.vertexSize / 4), positionOffset = (short)(attributes.findByUsage(Usage.Position).offset / 4); float[] vertices = new float[vertexCount * vertexSize]; mesh.getVertices(vertices);