use of org.terasology.math.geom.Vector2f in project Terasology by MovingBlocks.
the class OpenGLSkeletalMesh method doReload.
@Override
protected void doReload(SkeletalMeshData newData) {
try {
GameThread.synch(() -> {
this.data = newData;
if (disposalAction.vboPosNormBuffer == 0) {
disposalAction.vboPosNormBuffer = disposalAction.bufferPool.get(getUrn().toString());
}
IntBuffer indexBuffer = BufferUtils.createIntBuffer(newData.getIndices().size());
indexBuffer.put(newData.getIndices().toArray());
indexBuffer.flip();
if (disposalAction.vboIndexBuffer == 0) {
disposalAction.vboIndexBuffer = disposalAction.bufferPool.get(getUrn().toString());
}
VertexBufferObjectUtil.bufferVboElementData(disposalAction.vboIndexBuffer, indexBuffer, GL15.GL_STATIC_DRAW);
FloatBuffer uvBuffer = BufferUtils.createFloatBuffer(newData.getUVs().size() * 2);
for (Vector2f uv : newData.getUVs()) {
uvBuffer.put(uv.x);
uvBuffer.put(uv.y);
}
uvBuffer.flip();
if (disposalAction.vboUVBuffer == 0) {
disposalAction.vboUVBuffer = disposalAction.bufferPool.get(getUrn().toString());
}
VertexBufferObjectUtil.bufferVboData(disposalAction.vboUVBuffer, uvBuffer, GL15.GL_STATIC_DRAW);
});
} catch (InterruptedException e) {
logger.error("Failed to reload {}", getUrn(), e);
}
}
use of org.terasology.math.geom.Vector2f in project Terasology by MovingBlocks.
the class Tessellator method addMeshPart.
private void addMeshPart(BlockMeshPart part, boolean doubleSided) {
for (int i = 0; i < part.size(); ++i) {
Vector3f vertex = part.getVertex(i);
meshData.getVertices().add(vertex.x);
meshData.getVertices().add(vertex.y);
meshData.getVertices().add(vertex.z);
meshData.getColors().add(activeColor.x);
meshData.getColors().add(activeColor.y);
meshData.getColors().add(activeColor.z);
meshData.getColors().add(activeColor.w);
Vector3f normal = part.getNormal(i);
meshData.getNormals().add(normal.x);
meshData.getNormals().add(normal.y);
meshData.getNormals().add(normal.z);
Vector2f uv = part.getTexCoord(i);
meshData.getTexCoord0().add(uv.x);
meshData.getTexCoord0().add(uv.y);
meshData.getTexCoord1().add(lighting.x);
meshData.getTexCoord1().add(lighting.y);
meshData.getTexCoord1().add(lighting.z);
}
for (int i = 0; i < part.indicesSize(); ++i) {
meshData.getIndices().add(nextIndex + part.getIndex(i));
}
if (doubleSided) {
for (int i = 0; i < part.indicesSize(); i += 3) {
int i1 = nextIndex + part.getIndex(i);
int i2 = nextIndex + part.getIndex(i + 1);
int i3 = nextIndex + part.getIndex(i + 2);
meshData.getIndices().add(i1);
meshData.getIndices().add(i3);
meshData.getIndices().add(i2);
}
}
nextIndex += part.size();
}
use of org.terasology.math.geom.Vector2f in project Terasology by MovingBlocks.
the class TessellatorHelper method addBlockMesh.
public static void addBlockMesh(Tessellator tessellator, Vector4f color, Vector2f[] texOffsets, Vector2f[] texSizes, float size, float light1, float light2, float posX, float posY, float posZ) {
final float sizeHalf = size / 2;
tessellator.resetParams();
tessellator.setColor(new Vector4f(light1 * color.x, light1 * color.y, light1 * color.z, color.w));
tessellator.setNormal(new Vector3f(0, 1, 0));
tessellator.addPoly(new Vector3f[] { new Vector3f(-sizeHalf + posX, sizeHalf + posY, sizeHalf + posZ), new Vector3f(sizeHalf + posX, sizeHalf + posY, sizeHalf + posZ), new Vector3f(sizeHalf + posX, sizeHalf + posY, -sizeHalf + posZ), new Vector3f(-sizeHalf + posX, sizeHalf + posY, -sizeHalf + posZ) }, new Vector2f[] { new Vector2f(texOffsets[0].x, texOffsets[0].y), new Vector2f(texOffsets[0].x + texSizes[0].x, texOffsets[0].y), new Vector2f(texOffsets[0].x + texSizes[0].x, texOffsets[0].y + texSizes[0].y), new Vector2f(texOffsets[0].x, texOffsets[0].y + texSizes[0].y) });
tessellator.setNormal(new Vector3f(-1, 0, 0));
tessellator.addPoly(new Vector3f[] { new Vector3f(-sizeHalf + posX, -sizeHalf + posY, -sizeHalf + posZ), new Vector3f(-sizeHalf + posX, -sizeHalf + posY, sizeHalf + posZ), new Vector3f(-sizeHalf + posX, sizeHalf + posY, sizeHalf + posZ), new Vector3f(-sizeHalf + posX, sizeHalf + posY, -sizeHalf + posZ) }, new Vector2f[] { new Vector2f(texOffsets[1].x, texOffsets[1].y + texSizes[1].y), new Vector2f(texOffsets[1].x + texSizes[1].x, texOffsets[1].y + texSizes[1].y), new Vector2f(texOffsets[1].x + texSizes[1].x, texOffsets[1].y), new Vector2f(texOffsets[1].x, texOffsets[1].y) });
tessellator.setNormal(new Vector3f(1, 0, 0));
tessellator.addPoly(new Vector3f[] { new Vector3f(sizeHalf + posX, sizeHalf + posY, -sizeHalf + posZ), new Vector3f(sizeHalf + posX, sizeHalf + posY, sizeHalf + posZ), new Vector3f(sizeHalf + posX, -sizeHalf + posY, sizeHalf + posZ), new Vector3f(sizeHalf + posX, -sizeHalf + posY, -sizeHalf + posZ) }, new Vector2f[] { new Vector2f(texOffsets[2].x, texOffsets[2].y), new Vector2f(texOffsets[2].x + texSizes[2].x, texOffsets[2].y), new Vector2f(texOffsets[2].x + texSizes[2].x, texOffsets[2].y + texSizes[2].y), new Vector2f(texOffsets[2].x, texOffsets[2].y + texSizes[2].y) });
tessellator.setColor(new Vector4f(light2 * color.x, light2 * color.y, light2 * color.z, color.w));
tessellator.setNormal(new Vector3f(0, 0, -1));
tessellator.addPoly(new Vector3f[] { new Vector3f(-sizeHalf + posX, sizeHalf + posY, -sizeHalf + posZ), new Vector3f(sizeHalf + posX, sizeHalf + posY, -sizeHalf + posZ), new Vector3f(sizeHalf + posX, -sizeHalf + posY, -sizeHalf + posZ), new Vector3f(-sizeHalf + posX, -sizeHalf + posY, -sizeHalf + posZ) }, new Vector2f[] { new Vector2f(texOffsets[3].x, texOffsets[3].y), new Vector2f(texOffsets[3].x + texSizes[3].x, texOffsets[3].y), new Vector2f(texOffsets[3].x + texSizes[3].x, texOffsets[3].y + texSizes[3].y), new Vector2f(texOffsets[3].x, texOffsets[3].y + texSizes[3].y) });
tessellator.setNormal(new Vector3f(0, 0, 1));
tessellator.addPoly(new Vector3f[] { new Vector3f(-sizeHalf + posX, -sizeHalf + posY, sizeHalf + posZ), new Vector3f(sizeHalf + posX, -sizeHalf + posY, sizeHalf + posZ), new Vector3f(sizeHalf + posX, sizeHalf + posY, sizeHalf + posZ), new Vector3f(-sizeHalf + posX, sizeHalf + posY, sizeHalf + posZ) }, new Vector2f[] { new Vector2f(texOffsets[4].x, texOffsets[4].y + texSizes[4].y), new Vector2f(texOffsets[4].x + texSizes[4].x, texOffsets[4].y + texSizes[4].y), new Vector2f(texOffsets[4].x + texSizes[4].x, texOffsets[4].y), new Vector2f(texOffsets[4].x, texOffsets[4].y) });
tessellator.setNormal(new Vector3f(0, -1, 0));
tessellator.addPoly(new Vector3f[] { new Vector3f(-sizeHalf + posX, -sizeHalf + posY, -sizeHalf + posZ), new Vector3f(sizeHalf + posX, -sizeHalf + posY, -sizeHalf + posZ), new Vector3f(sizeHalf + posX, -sizeHalf + posY, sizeHalf + posZ), new Vector3f(-sizeHalf + posX, -sizeHalf + posY, sizeHalf + posZ) }, new Vector2f[] { new Vector2f(texOffsets[5].x, texOffsets[5].y), new Vector2f(texOffsets[5].x + texSizes[5].x, texOffsets[5].y), new Vector2f(texOffsets[5].x + texSizes[5].x, texOffsets[5].y + texSizes[5].y), new Vector2f(texOffsets[5].x, texOffsets[5].y + texSizes[5].y) });
}
use of org.terasology.math.geom.Vector2f in project Terasology by MovingBlocks.
the class TessellatorHelper method addGUIQuadMesh.
public static void addGUIQuadMesh(Tessellator tessellator, Vector4f color, float sizeX, float sizeY) {
tessellator.resetParams();
tessellator.setColor(new Vector4f(color.x, color.y, color.z, color.w));
tessellator.setUseLighting(false);
tessellator.setUseNormals(false);
tessellator.addPoly(new Vector3f[] { new Vector3f(0, 0, 0), new Vector3f(sizeX, 0, 0), new Vector3f(sizeX, sizeY, 0), new Vector3f(0, sizeY, 0) }, new Vector2f[] { new Vector2f(0, 0), new Vector2f(1, 0), new Vector2f(1, 1), new Vector2f(0, 1) });
tessellator.setUseLighting(true);
tessellator.setUseNormals(true);
}
use of org.terasology.math.geom.Vector2f in project Terasology by MovingBlocks.
the class MD5SkeletonLoader method load.
@Override
public SkeletalMeshData load(ResourceUrn urn, List<AssetDataFile> inputs) throws IOException {
try (InputStream stream = inputs.get(0).openStream()) {
MD5 md5 = parse(stream);
SkeletalMeshDataBuilder skeletonBuilder = new SkeletalMeshDataBuilder();
List<Bone> bones = Lists.newArrayListWithCapacity(md5.numJoints);
for (int i = 0; i < md5.numJoints; ++i) {
MD5Joint joint = md5.joints[i];
Bone bone = new Bone(i, joint.name, joint.position, joint.orientation);
bones.add(bone);
if (joint.parent != -1) {
bones.get(joint.parent).addChild(bone);
}
skeletonBuilder.addBone(bone);
}
if (md5.meshes.length > 0) {
// TODO: Support multiple mesh somehow?
MD5Mesh mesh = md5.meshes[0];
for (MD5Weight weight : mesh.weightList) {
skeletonBuilder.addWeight(new BoneWeight(weight.position, weight.bias, weight.jointIndex));
}
List<Vector2f> uvs = Lists.newArrayList();
TIntList vertexStartWeight = new TIntArrayList(mesh.numVertices);
TIntList vertexWeightCount = new TIntArrayList(mesh.numVertices);
for (MD5Vertex vert : mesh.vertexList) {
uvs.add(vert.uv);
vertexStartWeight.add(vert.startWeight);
vertexWeightCount.add(vert.countWeight);
}
skeletonBuilder.setVertexWeights(vertexStartWeight, vertexWeightCount);
skeletonBuilder.setUvs(uvs);
TIntList indices = new TIntArrayList(mesh.indexList.length);
for (int i = 0; i < mesh.numTriangles; ++i) {
indices.add(mesh.indexList[i * 3]);
indices.add(mesh.indexList[i * 3 + 2]);
indices.add(mesh.indexList[i * 3 + 1]);
}
skeletonBuilder.setIndices(indices);
}
return skeletonBuilder.build();
} catch (NumberFormatException e) {
throw new IOException("Error parsing " + inputs.get(0).getFilename(), e);
}
}
Aggregations