Jump to content

Recommended Posts

Posted

I am trying to create a model from another model at runtime. I need to translate and scale BakedQuads. Is there a method somewhere that does this, or do I have to manipulate the vertex data directly?

Posted

Was looking for same thing - ended up operating on vertexes. Here just to say - there is nothing bad in it.

 

Just note - getGeneralQuads() in your model is a mutable list of quads. You need to generate new Quads based on old ones and cache them in smart way (if possible).

 

There might be better solutoin tho.

1.7.10 is no longer supported by forge, you are on your own.

Posted

Here is what I have based on http://greyminecraftcoder.blogspot.com.au/2014/12/block-models-texturing-quads-faces.html.

 

I've screwed something up somewhere. It's close but not quite right. translation is t and scale is s. Any advice?

 

 

private BakedQuad scaleAndTranslateQuad(BakedQuad q, Vec3i t, float s) {

	int[] v = q.getVertexData().clone();		
	int x = t.getX();
	int y = t.getY();
	int z = t.getZ();

	switch (q.getFace()) {
	case UP:
		v[0] = transform(v[0], x, s);
		v[7] = transform(v[7], x, s);
		v[14] = transform(v[14], x, s);
		v[21] = transform(v[21], x, s);

		v[1] = transform(v[1], -z, s);
		v[8] = transform(v[8], -z, s);
		v[15] = transform(v[15], -z, s);
		v[22] = transform(v[22], -z, s);

		v[2] = transform(v[2], y, s);
		v[9] = transform(v[9], y, s);
		v[16] = transform(v[16], y, s);
		v[23] = transform(v[23], y, s);
		break;
	case DOWN:
		v[0] = transform(v[0], x, s);
		v[7] = transform(v[7], x, s);
		v[14] = transform(v[14], x, s);
		v[21] = transform(v[21], x, s);

		v[1] = transform(v[1], z, s);
		v[8] = transform(v[8], z, s);
		v[15] = transform(v[15], z, s);
		v[22] = transform(v[22], z, s);

		v[2] = transform(v[2], -y, s);
		v[9] = transform(v[9], -y, s);
		v[16] = transform(v[16], -y, s);
		v[23] = transform(v[23], -y, s);
		break;
	case EAST:
		v[0] = transform(v[0], z, s);
		v[7] = transform(v[7], z, s);
		v[14] = transform(v[14], z, s);
		v[21] = transform(v[21], z, s);

		v[1] = transform(v[1], y, s);
		v[8] = transform(v[8], y, s);
		v[15] = transform(v[15], y, s);
		v[22] = transform(v[22], y, s);

		v[2] = transform(v[2], x, s);
		v[9] = transform(v[9], x, s);
		v[16] = transform(v[16], x, s);
		v[23] = transform(v[23], x, s);
		break;
	case WEST:
		v[0] = transform(v[0], z, s);
		v[7] = transform(v[7], z, s);
		v[14] = transform(v[14], z, s);
		v[21] = transform(v[21], z, s);

		v[1] = transform(v[1], y, s);
		v[8] = transform(v[8], y, s);
		v[15] = transform(v[15], y, s);
		v[22] = transform(v[22], y, s);

		v[2] = transform(v[2], -x, s);
		v[9] = transform(v[9], -x, s);
		v[16] = transform(v[16], -x, s);
		v[23] = transform(v[23], -x, s);
		break;
	case NORTH:
		v[0] = transform(v[0], -x, s);
		v[7] = transform(v[7], -x, s);
		v[14] = transform(v[14], -x, s);
		v[21] = transform(v[21], -x, s);

		v[1] = transform(v[1], y, s);
		v[8] = transform(v[8], y, s);
		v[15] = transform(v[15], y, s);
		v[22] = transform(v[22], y, s);

		v[2] = transform(v[2], -z, s);
		v[9] = transform(v[9], -z, s);
		v[16] = transform(v[16], -z, s);
		v[23] = transform(v[23], -z, s);
		break;
	case SOUTH:
		// Case where quad coordinates are aligned with world coordinates
		v[0] = transform(v[0], x, s);
		v[7] = transform(v[7], x, s);
		v[14] = transform(v[14], x, s);
		v[21] = transform(v[21], x, s);

		v[1] = transform(v[1], y, s);
		v[8] = transform(v[8], y, s);
		v[15] = transform(v[15], y, s);
		v[22] = transform(v[22], y, s);

		v[2] = transform(v[2], z, s);
		v[9] = transform(v[9], z, s);
		v[16] = transform(v[16], z, s);
		v[23] = transform(v[23], z, s);
		break;
	default:
		break;
	}

	return new BakedQuad(v, q.getTintIndex(), q.getFace());
}

private int transform(int i, int t, float s) {
	float f = Float.intBitsToFloat(i);
	f = (f + t) * s;
	return Float.floatToRawIntBits(f);
}

 

Edit:

A model generated from two stone bricks slabs:

Posted

Finally  :P Got it working like this:

 

 

private BakedQuad scaleAndTranslateQuad(BakedQuad q, Vec3i t, float s) {

	int[] v = q.getVertexData().clone();
	// leftRigh, upDown, frontBack
	int lr, ud, fb;

	// A quad has four verticies
	// indices of x values of vertices are 0, 7, 14, 21
	// indices of y values of vertices are 1, 8, 15, 22
	// indices of z values of vertices are 2, 9, 16, 23

	// east: x
	// south: z
	// up: y

	switch (q.getFace()) {
	case UP:
		// Quad up is towards north
		lr = t.getX();
		ud = t.getZ();
		fb = t.getY();

		v[0] = transform(v[0], lr, s);
		v[7] = transform(v[7], lr, s);
		v[14] = transform(v[14], lr, s);
		v[21] = transform(v[21], lr, s);

		v[1] = transform(v[1], fb, s);
		v[8] = transform(v[8], fb, s);
		v[15] = transform(v[15], fb, s);
		v[22] = transform(v[22], fb, s);

		v[2] = transform(v[2], ud, s);
		v[9] = transform(v[9], ud, s);
		v[16] = transform(v[16], ud, s);
		v[23] = transform(v[23], ud, s);
		break;

	case DOWN:
		// Quad up is towards south
		lr = t.getX();
		ud = t.getZ();
		fb = t.getY();

		v[0] = transform(v[0], lr, s);
		v[7] = transform(v[7], lr, s);
		v[14] = transform(v[14], lr, s);
		v[21] = transform(v[21], lr, s);

		v[1] = transform(v[1], fb, s);
		v[8] = transform(v[8], fb, s);
		v[15] = transform(v[15], fb, s);
		v[22] = transform(v[22], fb, s);

		v[2] = transform(v[2], -ud, s);
		v[9] = transform(v[9], -ud, s);
		v[16] = transform(v[16], -ud, s);
		v[23] = transform(v[23], -ud, s);
		break;

	case WEST:
		lr = t.getZ();
		ud = t.getY();
		fb = t.getX();

		v[0] = transform(v[0], fb, s);
		v[7] = transform(v[7], fb, s);
		v[14] = transform(v[14], fb, s);
		v[21] = transform(v[21], fb, s);

		v[1] = transform(v[1], ud, s);
		v[8] = transform(v[8], ud, s);
		v[15] = transform(v[15], ud, s);
		v[22] = transform(v[22], ud, s);

		v[2] = transform(v[2], lr, s);
		v[9] = transform(v[9], lr, s);
		v[16] = transform(v[16], lr, s);
		v[23] = transform(v[23], lr, s);
		break;

	case EAST:
		lr = t.getZ();
		ud = t.getY();
		fb = t.getX();

		v[0] = transform(v[0], fb, s);
		v[7] = transform(v[7], fb, s);
		v[14] = transform(v[14], fb, s);
		v[21] = transform(v[21], fb, s);

		v[1] = transform(v[1], ud, s);
		v[8] = transform(v[8], ud, s);
		v[15] = transform(v[15], ud, s);
		v[22] = transform(v[22], ud, s);

		v[2] = transform(v[2], lr, s);
		v[9] = transform(v[9], lr, s);
		v[16] = transform(v[16], lr, s);
		v[23] = transform(v[23], lr, s);
		break;

	case NORTH:
		lr = t.getX();
		ud = t.getY();
		fb = t.getZ();

		v[0] = transform(v[0], lr, s);
		v[7] = transform(v[7], lr, s);
		v[14] = transform(v[14], lr, s);
		v[21] = transform(v[21], lr, s);

		v[1] = transform(v[1], ud, s);
		v[8] = transform(v[8], ud, s);
		v[15] = transform(v[15], ud, s);
		v[22] = transform(v[22], ud, s);

		v[2] = transform(v[2], fb, s);
		v[9] = transform(v[9], fb, s);
		v[16] = transform(v[16], fb, s);
		v[23] = transform(v[23], fb, s);
		break;

	case SOUTH:
		// Case where quad is aligned with world coordinates
		lr = t.getX();
		ud = t.getY();
		fb = t.getZ();

		v[0] = transform(v[0], lr, s);
		v[7] = transform(v[7], lr, s);
		v[14] = transform(v[14], lr, s);
		v[21] = transform(v[21], lr, s);

		v[1] = transform(v[1], ud, s);
		v[8] = transform(v[8], ud, s);
		v[15] = transform(v[15], ud, s);
		v[22] = transform(v[22], ud, s);

		v[2] = transform(v[2], fb, s);
		v[9] = transform(v[9], fb, s);
		v[16] = transform(v[16], fb, s);
		v[23] = transform(v[23], fb, s);
		break;

	default:
		System.out.println("Unexpected face=" + q.getFace());
		break;
	}

	return new BakedQuad(v, q.getTintIndex(), q.getFace());
}

private int transform(int i, int t, float s) {
	float f = Float.intBitsToFloat(i);
	f = (f + t) * s;
	return Float.floatToRawIntBits(f);
}

 

 

Please contribute any suggestions to abbreviate the code

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Announcements



×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.