use of gnu.trove.list.array.TFloatArrayList in project Terasology by MovingBlocks.
the class ColladaLoader method parseMeshData.
protected void parseMeshData(Element rootElement) throws ColladaParseException {
vertices = new TFloatArrayList();
texCoord0 = new TFloatArrayList();
texCoord1 = new TFloatArrayList();
normals = new TFloatArrayList();
colors = new TFloatArrayList();
indices = new TIntArrayList();
int vertCount = 0;
ElementSet upAxisSet = rootElement.find("asset", "up_axis");
if (1 != upAxisSet.size()) {
throw new ColladaParseException("Found multiple up_axis asset values");
}
Element upAxisElement = upAxisSet.first();
String upAxis = upAxisElement.text();
ElementSet unitSet = rootElement.find("asset", "unit");
if (1 != unitSet.size()) {
throw new ColladaParseException("Found multiple unit asset values");
}
Element unitElement = unitSet.first();
String unitsPerMeterString = unitElement.attr("meter");
if (null != unitsPerMeterString) {
unitsPerMeter = Double.parseDouble(unitsPerMeterString);
}
boolean yUp = "Y_UP".equals(upAxis);
boolean zUp = "Z_UP".equals(upAxis);
boolean xUp = "X_UP".equals(upAxis);
if (xUp) {
throw new ColladaParseException("Not supporting X_UP as the upAxis value yet.");
}
// TODO: we shouldn't just cram everything into a single mesh, but should expect separate meshes with differing materials
ElementSet geometrySet = rootElement.find("library_geometries", "geometry");
for (Element geometry : geometrySet) {
ElementSet meshSet = geometry.find("mesh");
if (1 != meshSet.size()) {
throw new ColladaParseException("Found " + meshSet.size() + " mesh sets for geometry id=" + geometry.id() + " name=" + geometry.name());
}
logger.info("Parsing geometry id=" + geometry.id() + " name=" + geometry.name());
for (Element mesh : meshSet) {
ElementSet trianglesSet = mesh.find("triangles");
for (Element triangles : trianglesSet) {
vertCount = parseTriangles(rootElement, vertices, texCoord0, normals, indices, colors, vertCount, geometry, mesh, triangles, yUp, zUp);
}
ElementSet polylistSet = mesh.find("polylist");
for (Element polylist : polylistSet) {
ElementSet vCountSet = polylist.find("vcount");
if (1 != vCountSet.size()) {
throw new ColladaParseException("Found " + vCountSet.size() + " vcount sets for polylist in geometry id=" + geometry.id() + " name=" + geometry.name());
}
Element vCountElement = vCountSet.first();
TIntList vcountList = new TIntArrayList();
String[] vCountStrings = getItemsInString(vCountElement.text());
for (String string : vCountStrings) {
int vCount = Integer.parseInt(string);
vcountList.add(vCount);
}
vertCount = parseFaces(rootElement, vcountList, vertices, texCoord0, normals, indices, colors, vertCount, geometry, mesh, polylist, yUp, zUp);
}
}
}
}
use of gnu.trove.list.array.TFloatArrayList in project BuildCraft by BuildCraft.
the class NbtSquishMapWriter method write.
private void write(DataOutput to) throws IOException {
profiler.startSection("write");
profiler.startSection("flags");
WrittenType type = map.getWrittenType();
type.writeType(to);
TByteArrayList bytes = map.bytes;
TShortArrayList shorts = map.shorts;
TIntArrayList ints = map.ints;
TLongArrayList longs = map.longs;
TFloatArrayList floats = map.floats;
TDoubleArrayList doubles = map.doubles;
List<TByteArrayList> byteArrays = map.byteArrays;
List<TIntArrayList> intArrays = map.intArrays;
List<String> strings = map.strings;
List<NBTBase> complex = map.complex;
int flags = 0;
if (!bytes.isEmpty())
flags |= NbtSquishConstants.FLAG_HAS_BYTES;
if (!shorts.isEmpty())
flags |= NbtSquishConstants.FLAG_HAS_SHORTS;
if (!ints.isEmpty())
flags |= NbtSquishConstants.FLAG_HAS_INTS;
if (!longs.isEmpty())
flags |= NbtSquishConstants.FLAG_HAS_LONGS;
if (!floats.isEmpty())
flags |= NbtSquishConstants.FLAG_HAS_FLOATS;
if (!doubles.isEmpty())
flags |= NbtSquishConstants.FLAG_HAS_DOUBLES;
if (!byteArrays.isEmpty())
flags |= NbtSquishConstants.FLAG_HAS_BYTE_ARRAYS;
if (!intArrays.isEmpty())
flags |= NbtSquishConstants.FLAG_HAS_INT_ARRAYS;
if (!strings.isEmpty())
flags |= NbtSquishConstants.FLAG_HAS_STRINGS;
if (!complex.isEmpty())
flags |= NbtSquishConstants.FLAG_HAS_COMPLEX;
if (debug)
log("\nUsed flags = " + Integer.toBinaryString(flags));
to.writeInt(flags);
profiler.endStartSection("bytes");
if (!bytes.isEmpty()) {
if (debug)
log("\nByte dictionary size = " + bytes.size());
if (sort)
bytes.sort();
writeVarInt(to, bytes.size());
for (byte b : bytes.toArray()) {
to.writeByte(b);
}
}
profiler.endStartSection("shorts");
if (!shorts.isEmpty()) {
if (debug)
log("\nShort dictionary size = " + shorts.size());
if (sort)
shorts.sort();
writeVarInt(to, shorts.size());
for (short s : shorts.toArray()) {
to.writeShort(s);
}
}
profiler.endStartSection("integers");
if (!ints.isEmpty()) {
if (debug)
log("\nInt dictionary size = " + ints.size());
if (sort)
ints.sort();
writeVarInt(to, ints.size());
for (int i : ints.toArray()) {
to.writeInt(i);
}
}
profiler.endStartSection("longs");
if (!longs.isEmpty()) {
if (debug)
log("\nLong dictionary size = " + longs.size());
if (sort)
longs.sort();
writeVarInt(to, longs.size());
for (long l : longs.toArray()) {
to.writeLong(l);
}
}
profiler.endStartSection("floats");
if (!floats.isEmpty()) {
if (debug)
log("\nFloat dictionary size = " + floats.size());
if (sort)
floats.sort();
writeVarInt(to, floats.size());
for (float f : floats.toArray()) {
to.writeFloat(f);
}
}
profiler.endStartSection("doubles");
if (!doubles.isEmpty()) {
if (debug)
log("\nDouble dictionary size = " + doubles.size());
if (sort)
doubles.sort();
writeVarInt(to, doubles.size());
for (double d : doubles.toArray()) {
to.writeDouble(d);
}
}
profiler.endStartSection("byte_arrays");
if (!byteArrays.isEmpty()) {
if (debug)
log("\nByte Array dictionary size = " + byteArrays.size());
writeVarInt(to, byteArrays.size());
for (TByteArrayList ba : byteArrays) {
to.writeShort(ba.size());
for (byte b : ba.toArray()) {
to.writeByte(b);
}
}
}
profiler.endStartSection("int_arrays");
if (!intArrays.isEmpty()) {
if (debug)
log("\nInt Array dictionary size = " + intArrays.size());
writeVarInt(to, intArrays.size());
for (TIntArrayList ia : intArrays) {
to.writeShort(ia.size());
for (int i : ia.toArray()) {
to.writeInt(i);
}
}
}
profiler.endStartSection("strings");
if (!strings.isEmpty()) {
if (debug)
log("\nString dictionary size = " + strings.size());
if (sort)
Collections.sort(strings);
writeVarInt(to, strings.size());
for (int i = 0; i < strings.size(); i++) {
String s = strings.get(i);
if (debug)
log("\n String " + i + " = " + s);
byte[] stringBytes = s.getBytes(StandardCharsets.UTF_8);
to.writeShort(stringBytes.length);
to.write(stringBytes);
}
}
profiler.endStartSection("complex");
if (!complex.isEmpty()) {
if (debug)
log("\nComplex dictionary size = " + complex.size());
writeVarInt(to, complex.size());
for (NBTBase nbt : complex) {
if (nbt instanceof NBTTagList) {
NBTTagList list = (NBTTagList) nbt;
writeList(type, list, to);
} else {
NBTTagCompound compound = (NBTTagCompound) nbt;
writeCompound(type, compound, to);
}
}
}
profiler.endSection();
profiler.endSection();
}
Aggregations