0
\$\begingroup\$

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:

https://imgur.com/a/tE00E9F (2nd image, scroll down)

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:

enter image description here (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..

\$\endgroup\$
  • \$\begingroup\$ Not really sure what the exact issue is. Is it that everything is offset by half a block? \$\endgroup\$ – htmlcoderexe Apr 23 at 15:21
  • \$\begingroup\$ No, what I mean is that the vertices which I have are for the corners of blocks, but the way I want it is so that the vertices can be grouped into a single block. The coordinates of the block should ideally be any one of the vertex coordinates, but how would I group them? \$\endgroup\$ – Lucas Smith Apr 23 at 16:03
  • 1
    \$\begingroup\$ Hey Lucas, it’s very hard to figure out what your actual problem is from this post. Think you could make some more pictures for us? Some ideas: Draw outlines in MSPaint that show what you expect to happen, and compare them to examples of things going correctly \$\endgroup\$ – Jacob Panikulam Apr 23 at 19:16
  • \$\begingroup\$ @JacobPanikulam Take this image, imgur.com/a/LPwvExo .I have the vertices for each of the orange colours corners (the red ones are orange and red). Each orange vertex is 1 away from the next vertex in the coordinate system. How do i get rid of the vertices which arent also coloured in red? I have a list of the 'orange' vertices and I want to eliminate all orange coloured vertices which arent also red. How would i achieve this? \$\endgroup\$ – Lucas Smith Apr 25 at 9:11
  • \$\begingroup\$ Hm, I can’t quite see a pattern in the red vertices. Are those all of the vertices you want to keep in that image, or just some of them? Could it be that you’re trying to remove internal and redundant vertices? \$\endgroup\$ – Jacob Panikulam Apr 25 at 15:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.