use of org.joml.Vector2f in project Terasology by MovingBlocks.
the class VectorEventSerializer method testEventSerializationConstant.
@Test
public void testEventSerializationConstant() throws IOException {
Vector3fTestEvent a = new Vector3fTestEvent();
a.v1 = new Vector3f(1.0f, 2.0f, 3.0f);
a.v2 = new Vector4f(1.0f, 2.0f, 3.0f, 5.0f);
a.v3 = new Vector2f(1.0f, 2.0f);
a.v1c = new Vector3f(1.0f, 1.0f, 1.0f);
a.v2c = new Vector4f(1.0f, 1.0f, 2.0f, 2.0f);
a.v3c = new Vector2f(1.0f, 1.0f);
EntityData.Event ev = serializer.serialize(a);
Event dev = serializer.deserialize(ev);
assumeTrue(dev instanceof Vector3fTestEvent);
assertEquals(((Vector3fTestEvent) dev).v1, new Vector3f(1.0f, 2.0f, 3.0f), .00001f);
assertEquals(((Vector3fTestEvent) dev).v2, new Vector4f(1.0f, 2.0f, 3.0f, 5.0f), .00001f);
assertEquals(((Vector3fTestEvent) dev).v3, new Vector2f(1.0f, 2.0f), .00001f);
assertEquals(((Vector3fTestEvent) dev).v1c, new Vector3f(1.0f, 1.0f, 1.0f), .00001f);
assertEquals(((Vector3fTestEvent) dev).v2c, new Vector4f(1.0f, 1.0f, 2.0f, 2.0f), .00001f);
assertEquals(((Vector3fTestEvent) dev).v3c, new Vector2f(1.0f, 1.0f), .00001f);
}
use of org.joml.Vector2f in project Terasology by MovingBlocks.
the class ObjMeshFormat method readMeshData.
private void readMeshData(BufferedReader reader, List<Vector3f> rawVertices, List<Vector3f> rawNormals, List<Vector2f> rawTexCoords, List<Vector3i[]> rawIndices) throws IOException {
String line = null;
int lineNum = 0;
try {
while ((line = reader.readLine()) != null) {
line = line.trim();
lineNum++;
if (line.isEmpty()) {
continue;
}
String[] prefixSplit = line.trim().split("\\s+", 2);
String prefix = prefixSplit[0];
// Comment
if ("#".equals(prefix)) {
continue;
}
if (prefixSplit.length < 2) {
throw new IOException("Incomplete statement");
}
switch(prefix) {
// Object name
case "o":
// Just skip the name
break;
// Vertex position
case "v":
{
String[] floats = prefixSplit[1].trim().split("\\s+", 4);
if (floats.length != 3) {
throw new IOException("Bad statement");
}
rawVertices.add(new Vector3f(Float.parseFloat(floats[0]), Float.parseFloat(floats[1]), Float.parseFloat(floats[2])));
break;
}
// Vertex texture coords
case "vt":
{
String[] floats = prefixSplit[1].trim().split("\\s+", 4);
if (floats.length < 2 || floats.length > 3) {
throw new IOException("Bad statement");
}
// Need to flip v coord, apparently
rawTexCoords.add(new Vector2f(Float.parseFloat(floats[0]), Float.parseFloat(floats[1])));
break;
}
// Vertex normal
case "vn":
{
String[] floats = prefixSplit[1].trim().split("\\s+", 4);
if (floats.length != 3) {
throw new IOException("Bad statement");
}
rawNormals.add(new Vector3f(Float.parseFloat(floats[0]), Float.parseFloat(floats[1]), Float.parseFloat(floats[2])));
break;
}
// Material name (ignored)
case "usemtl":
break;
// Smoothing group (not supported)
case "s":
{
if (!"off".equals(prefixSplit[1]) && !"0".equals(prefixSplit[1])) {
logger.warn("Smoothing groups not supported in obj import yet");
}
break;
}
// Face (polygon)
case "f":
{
String[] elements = prefixSplit[1].trim().split("\\s+");
Vector3i[] result = new Vector3i[elements.length];
for (int i = 0; i < elements.length; ++i) {
String[] parts = elements[i].split("/", 4);
if (parts.length > 3) {
throw new IOException("Bad Statement");
}
result[i] = new Vector3i(Integer.parseInt(parts[0]), -1, -1);
if (parts.length > 1 && !parts[1].isEmpty()) {
result[i].y = Integer.parseInt(parts[1]);
}
if (parts.length > 2 && !parts[2].isEmpty()) {
result[i].z = Integer.parseInt(parts[2]);
}
}
rawIndices.add(result);
break;
}
default:
logger.warn("Skipping unsupported obj statement on line {}:\"{}\"", lineNum, line);
}
}
} catch (RuntimeException e) {
throw new IOException(String.format("Failed to process line %d:\"%s\"", lineNum, line), e);
}
}
use of org.joml.Vector2f in project Terasology by MovingBlocks.
the class ObjMeshFormat method load.
@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");
}
return processData(rawVertices, rawNormals, rawTexCoords, rawIndices);
}
}
use of org.joml.Vector2f in project Terasology by MovingBlocks.
the class ScreenQuadMeshProducer method getAssetData.
@Override
public Optional<MeshData> getAssetData(ResourceUrn urn) throws IOException {
if (TerasologyConstants.ENGINE_MODULE.equals(urn.getModuleName())) {
if (SCREEN_QUAD_RESOURCE_NAME.equals(urn.getResourceName())) {
StandardMeshData data = new StandardMeshData();
Vector3f posDest = new Vector3f();
Vector2f uvDest = new Vector2f();
data.position.put(posDest.set(-1.0f, -1.0f, 0.0f));
data.position.put(posDest.set(-1.0f, 1.0f, 0.0f));
data.position.put(posDest.set(1.0f, 1.0f, 0.0f));
data.position.put(posDest.set(1.0f, -1.0f, 0.0f));
data.indices.put(0);
data.indices.put(1);
data.indices.put(2);
data.indices.put(0);
data.indices.put(2);
data.indices.put(3);
data.uv0.put(uvDest.set(0.0f, 0.0f));
data.uv0.put(uvDest.set(0.0f, 1.0f));
data.uv0.put(uvDest.set(1.0f, 1.0f));
data.uv0.put(uvDest.set(1.0f, 0.0f));
return Optional.of(data);
}
}
return Optional.empty();
}
use of org.joml.Vector2f in project Terasology by MovingBlocks.
the class TessellatorHelper method addBlockMesh.
public static void addBlockMesh(Tessellator tessellator, Vector4f color, float size, float light1, float light2, float posX, float posY, float posZ) {
Vector2f defaultSize = new Vector2f(1.0f, 1.0f);
Vector2f defaultOffset = new Vector2f(0.0f, 0.0f);
addBlockMesh(tessellator, color, defaultOffset, defaultSize, size, light1, light2, posX, posY, posZ);
}
Aggregations