Sorry if this is the wrong place to ask this, please do tell me where a question like this is better asked.
Im importing a model from another game into the video game minecraft, which uses a coordinate system where a coordinate maps to a block in the world. Ive scaled it correctly as good as I can but each block (or set of 8 vertices for each corner) are scaled wrong. This is hard to explain but here take this image:
The blocks which import to minecraft are scaled wrong, and the blocks vertices are where the fence poles are in the model (the poles in the fence are trying to represent the set of vertices connected in the model right now. So in the picture above, in minecraft the width is 5 blocks, but it should be 4 blocks because If you see the fence poles they show the outlines of the block which should be placed. Ideally I want to create the block at ONE of the corners of each fence pole (which represents a block), it doesnt matter the corner as the model would still import, just with a 1 offset depending on which vertex (bottom left,bottom right,top right or top left, + all the others for the z coordinate…) the block is placed at. But the fence poles is just a perspective of it, another way to look at it which is the way it is, is that the vertices are already at the block coordinates, but because the block coordinates in minecraft map to one block, the blocks are almost streched out to create a 2x2 block, where is should be one.
i.e, the left 8 blocks in the picture represent the 8 vertices of the single block in the right:
(top one, there are 8 blocks on the left, although it seems 4. The vertices right now are right in the middle of the blocks, and then they join up to create the actual single block, but because minecraft has a block coordinate at one of the corners of the block, this wont work and hence places at the block at the corner of the block. So I need to sort of needing to shift the vertices by 0.5 of a block to the the minecraft coordinate)
Since this does not need to be done fast, I just loop though each vertex of the blocks that should be placed and are in the model, but place a block at each vertex instead. Maybe I have to group these vertices up? If so, how would I do that with big models?
I read the vertices from a file here, this is the loop right now:
for(int x = 1; x <= vertCount; x++) {
float f = buf.readFloat();
p.verts.add(f);
}
If thats confusing (above), each vertex in the loop above gets grouped in threes. So when the loop variable x = 1, thats the x coord of the first vertex, then y and z, then 'new loop' etc.. (A better way would have been to store the x,y,z coordinates in arrays of 3 in a big array)
So the problem is that im placing blocks in minecraft at the vertices of the block that should be placed.
(P.S, the vertices are in floats, but they are whole numbers its just some are smaller than a block and have decimal points but I handle that elsewhere, and I might just not import them if they have decimals in the end)
This is where I group the vertices:
int i=0;
short index1; //cache the x
short index2;//cache the y
for(short x : faces){
if(i==1) {//this loop gets the x
index1=x;
i++;
continue;
}else if(i==2) {//this lop gets the y
index2=x;
i++;
continue;
}else {//this loop gets the z, also place the block here too and start collecting x,y,z again
float pos1x = poly.verts.get(index1*3) /100;
float pos1y = poly.verts.get((index1*3)+1) /100;
float pos1z = poly.verts.get((index1*3)+2) /100;
float pos2x = poly.verts.get(index2*3) /100;
float pos2y = poly.verts.get((index2*3)+1) /100;
float pos2z = poly.verts.get((index2*3)+2) /100;
float pos3x = poly.verts.get(x*3) /100;
float pos3y = poly.verts.get((x*3)+1) /100;
float pos3z = poly.verts.get((x*3)+2) /100;
drawTriangle(pos1x,pos1y,pos1z,pos2x,pos2y,pos2z,pos3x,pos3y,pos3z);
i=1;
continue;
}
}
In the code above I'm looping though each FACE (a set of three coordinates (like the vertices list), inside a list of 16bit shorts to specify the indices in the vertices list that should connect, so just a list of shorts grouped in sets of 3(x,y,z)).
The drawTriangle takes three points and just places a block at each block inbetween the three corners of the face in the face (so a 3D triangle), as the model im importing is just lots of triangles which make a mesh. However, this is not where the problem is and I would want to sort out the vertices before this so the faces can draw using the correct block coordinates, not vertices.
The vertices might be connected to other vertices to form other blocks aswell.
EDIT: The dividing of 100 scales the model into blocks which are the same size as minecraft. Also, the model being imported is blocks, no circles, etc..