public void multiply(float amount) { this.multipliers.add(amount); }
/** * Creates a new AABB that contains the vertices as represented by a {@link TFloatList}. * * @param vertices The vertices to encompass. It is assumed that the X, Y, Z components of each * vertex are stored consecutively in the {@link TFloatList}. * * For the {@code i}th vertex in the list, the X, Y, and Z components * are stored at indices {@code 3 * i}, {@code 3 * i + 1}, and * {@code 3 * i + 2} respectively. * * @return The created AABB. */ public static AABB createEncompasing(TFloatList vertices) { int vertexCount = vertices.size() / 3; if (vertexCount == 0) { return AABB.createEmpty(); } Vector3f min = new Vector3f(vertices.get(0), vertices.get(1), vertices.get(2)); Vector3f max = new Vector3f(vertices.get(0), vertices.get(1), vertices.get(2)); for (int index = 1; index < vertexCount; ++index) { min.x = Math.min(min.x, vertices.get(3 * index)); max.x = Math.max(max.x, vertices.get(3 * index)); min.y = Math.min(min.y, vertices.get(3 * index + 1)); max.y = Math.max(max.y, vertices.get(3 * index + 1)); min.z = Math.min(min.z, vertices.get(3 * index + 2)); max.z = Math.max(max.z, vertices.get(3 * index + 2)); } return AABB.createMinMax(min, max); }
@Override public Float set( int index, Float value ) { float previous_value = list.set( index, value ); if ( previous_value == list.getNoEntryValue() ) return null; else return Float.valueOf( previous_value ); }
@Override public Float get( int index ) { float value = list.get( index ); if ( value == list.getNoEntryValue() ) return null; else return Float.valueOf( value ); }
private static void loadIndices(int[] rawIndices, TObjectIntMap<String> offsets, TIntList indices, TFloatList rawTextureCoords, TFloatList textureCoords, TFloatList rawNormals, TFloatList normals) { final int positionOffset = offsets.get(SEMANTIC_VERTEX); final int texCoordsOffset = offsets.get(SEMANTIC_TEXCOORD); final int normalOffset = offsets.get(SEMANTIC_NORMAL); final int components = texCoordsOffset == -1 ? normalOffset == -1 ? 1 : 2 : 3; if (textureCoords != null && texCoordsOffset != -1) { textureCoords.fill(0, rawTextureCoords.size(), 0); } if (normals != null && normalOffset != -1) { normals.fill(0, rawNormals.size(), 0); } for (int i = 0; i < rawIndices.length; i += components) { final int positionIndex = rawIndices[i + positionOffset]; indices.add(positionIndex); if (textureCoords != null && texCoordsOffset != -1) { final int texCoordsIndex = rawIndices[i + texCoordsOffset] * STEP_TEXCOORD; for (int s = 0; s < STEP_TEXCOORD; s++) { textureCoords.set(positionIndex * STEP_TEXCOORD + s, rawTextureCoords.get(texCoordsIndex + s)); } } if (normals != null && normalOffset != -1) { final int normalIndex = rawIndices[i + normalOffset] * STEP_NORMAL; for (int s = 0; s < STEP_NORMAL; s++) { normals.set(positionIndex * STEP_NORMAL + s, rawNormals.get(normalIndex + s)); } } } }
for (int i = 0; i < loader.getVertices().size(); i++) { float originalVertexValue = loader.getVertices().get(i); float adjustedVertexValue = (float) (originalVertexValue * loader.getUnitsPerMeter()); verticesMesh.add(adjustedVertexValue); colorsMesh.addAll(loader.getColors()); texCoord0Mesh.addAll(loader.getTexCoord0()); normalsMesh.addAll(loader.getNormals()); indicesMesh.addAll(loader.getIndices()); if (((null == data.getColors()) || (0 == data.getColors().size())) && ((null == data.getTexCoord0()) || (0 == data.getTexCoord0().size()))) { throw new IOException("There must be either texture coordinates or vertex colors provided."); if ((null != data.getTexCoord0()) && (0 != data.getTexCoord0().size())) { if (data.getTexCoord0().size() / 2 != data.getVertices().size() / 3) { throw new IOException("The number of tex coords (" + data.getTexCoord0().size() / 2 + ") does not match the number of vertices (" + data.getVertices().size() / 3 + ")."); if ((null != data.getColors()) && (0 != data.getColors().size())) { if (data.getColors().size() / 4 != data.getVertices().size() / 3) { throw new IOException("The number of vertex colors (" + data.getColors().size() / 4 + ") does not match the number of vertices (" + data.getVertices().size() / 3 + ").");
int positionsSize = positions.size(); final float x = positions.get(i); final float y = positions.get(i + 1); final float z = positions.get(i + 2); final float ox = positions.get(ii); final float oy = positions.get(ii + 1); final float oz = positions.get(ii + 2); if (x == ox && y == oy && z == oz) { positions.remove(ii, 3); positionsSize -= 3; ii -= 3; final Vector3f p00 = new Vector3f(positions.get(i0 * 3), positions.get(i0 * 3 + 1), positions.get(i0 * 3 + 2)); final Vector3f p01 = new Vector3f(positions.get(i1 * 3), positions.get(i1 * 3 + 1), positions.get(i1 * 3 + 2)); final Vector3f p02 = new Vector3f(positions.get(i2 * 3), positions.get(i2 * 3 + 1), positions.get(i2 * 3 + 2)); final int ii2 = indices.get(ii + 2); final Vector3f p10 = new Vector3f(positions.get(ii0 * 3), positions.get(ii0 * 3 + 1), positions.get(ii0 * 3 + 2)); final Vector3f p11 = new Vector3f(positions.get(ii1 * 3), positions.get(ii1 * 3 + 1), positions.get(ii1 * 3 + 2)); final Vector3f p12 = new Vector3f(positions.get(ii2 * 3), positions.get(ii2 * 3 + 1), positions.get(ii2 * 3 + 2));
public float get( int index ) { synchronized( mutex ) { return list.get( index ); } } public float set( int index, float element) {
public float[] toArray( float[] dest, int offset, int len ) { synchronized( mutex ) { return list.toArray( dest, offset, len ); } } public float[] toArray( float[] dest, int source_pos, int dest_pos, int len ) {
int vertexCount = newData.getVertices().size() / VERTEX_SIZE; int vertexSize = VERTEX_SIZE; parts.add(newData.getVertices().iterator()); partSizes.add(VERTEX_SIZE); if (newData.getTexCoord0() != null && newData.getTexCoord0().size() / TEX_COORD_0_SIZE == vertexCount) { parts.add(newData.getTexCoord0().iterator()); partSizes.add(TEX_COORD_0_SIZE); texCoord0Offset = vertexSize * FLOAT_SIZE; hasTexCoord0 = true; if (newData.getTexCoord1() != null && newData.getTexCoord1().size() / TEX_COORD_1_SIZE == vertexCount) { parts.add(newData.getTexCoord1().iterator()); partSizes.add(TEX_COORD_1_SIZE); texCoord1Offset = vertexSize * FLOAT_SIZE; hasTexCoord1 = true; if (newData.getNormals() != null && newData.getNormals().size() / NORMAL_SIZE == vertexCount) { parts.add(newData.getNormals().iterator()); partSizes.add(NORMAL_SIZE); normalOffset = vertexSize * FLOAT_SIZE; if (newData.getColors() != null && newData.getColors().size() / COLOR_SIZE == vertexCount) { parts.add(newData.getColors().iterator()); partSizes.add(COLOR_SIZE); colorOffset = vertexSize * FLOAT_SIZE;
public TFloatLinkedList(TFloatList list) { no_entry_value = list.getNoEntryValue(); // for (TFloatIterator iterator = list.iterator(); iterator.hasNext();) { float next = iterator.next(); add(next); } }
public void fill( float val ) { synchronized( mutex ) { list.fill( val ); } } public void fill( int fromIndex, int toIndex, float val ) {
public float set( int index, float element) { synchronized( mutex ) { return list.set( index, element ); } } public void set( int offset, float[] values ) {
@Override public int size() { return list.size(); }
public int binarySearch( float value ) { synchronized( mutex ) { return list.binarySearch( value ); } } public int binarySearch( float value, int fromIndex, int toIndex ) {
public boolean forEachDescending( TFloatProcedure procedure ) { return list.forEachDescending( procedure ); }
public void remove( int offset, int length ) { synchronized( mutex ) { list.remove( offset, length ); } } public float removeAt( int offset ) {
@Override public MeshData load(ResourceUrn urn, List<AssetDataFile> inputs) throws IOException { try (BufferedReader reader = new BufferedReader(new InputStreamReader(inputs.get(0).openStream()))) { List<Vector3f> rawVertices = Lists.newArrayList(); List<Vector3f> rawNormals = Lists.newArrayList(); List<Vector2f> rawTexCoords = Lists.newArrayList(); List<Vector3i[]> rawIndices = Lists.newArrayList(); // Gather data readMeshData(reader, rawVertices, rawNormals, rawTexCoords, rawIndices); // Determine face format; if (rawIndices.size() == 0) { throw new IOException("No index data"); } MeshData data = processData(rawVertices, rawNormals, rawTexCoords, rawIndices); if (data.getVertices() == null) { throw new IOException("No vertices define"); } if (!data.getNormals().isEmpty() && data.getNormals().size() != data.getVertices().size()) { throw new IOException("The number of normals does not match the number of vertices."); } if (!data.getTexCoord0().isEmpty() && data.getTexCoord0().size() / 2 != data.getVertices().size() / 3) { throw new IOException("The number of tex coords does not match the number of vertices."); } return data; } }
public float getResultValue() { // For now, add all modifiers and multiply by all multipliers. Negative modifiers cap to zero, but negative // multipliers remain. float result = baseValue; TFloatIterator modifierIter = modifiers.iterator(); while (modifierIter.hasNext()) { result += modifierIter.next(); } result = Math.max(0, result); TFloatIterator multiplierIter = multipliers.iterator(); while (multiplierIter.hasNext()) { result *= multiplierIter.next(); } final TFloatIterator postModifierIter = postModifiers.iterator(); while (postModifierIter.hasNext()) { result += postModifierIter.next(); } return result; }
parseComponents(positions, line); if (positionSize == -1) { positionSize = positions.size(); textureCoordSize = rawTextureCoords.size(); normalSize = rawNormalComponents.size(); final boolean hasTextureCoords; final boolean hasNormals; if (!textureCoordIndices.isEmpty() && !rawTextureCoords.isEmpty()) { textureCoords.fill(0, positions.size() / positionSize * textureCoordSize, 0); hasTextureCoords = true; } else { hasTextureCoords = false; if (!normalIndices.isEmpty() && !rawNormalComponents.isEmpty()) { normals.fill(0, positions.size() / positionSize * normalSize, 0); hasNormals = true; } else { final int positionIndex = indices.get(i) * textureCoordSize; for (int ii = 0; ii < textureCoordSize; ii++) { textureCoords.set(positionIndex + ii, rawTextureCoords.get(textureCoordIndex + ii)); final int positionIndex = indices.get(i) * normalSize; for (int ii = 0; ii < normalSize; ii++) { normals.set(positionIndex + ii, rawNormalComponents.get(normalIndex + ii));