// TODO update to builder private int[] vertexToInts( float x, float y, float z, int color, TextureAtlasSprite texture, float u, float v) { return new int[] { Float.floatToRawIntBits(x), Float.floatToRawIntBits(y), Float.floatToRawIntBits(z), color, Float.floatToRawIntBits(texture.getInterpolatedU(u)), Float.floatToRawIntBits(texture.getInterpolatedV(v)), 0 }; }
public void putIntoBakedQuadBuilder( UnpackedBakedQuad.Builder builder, TextureAtlasSprite sprite) { Vertex transformed = getTransformedVertex(); Tuple4f positionBuffer = new Vector4f(); transformed.getPosition(positionBuffer); Tuple3f normalBuffer = new Vector3f(); transformed.getNormal(normalBuffer); Tuple2f uvBuffer = new Vector2f(); transformed.getUV(uvBuffer); VertexFormat vertexFormat = builder.getVertexFormat(); int elementCount = vertexFormat.getElementCount(); for (int e = 0; e < elementCount; e++) { VertexFormatElement element = vertexFormat.getElement(e); switch (element.getUsage()) { case POSITION: builder.put(e, positionBuffer.x, positionBuffer.z, -positionBuffer.y, positionBuffer.w); break; case NORMAL: builder.put(e, normalBuffer.x, normalBuffer.z, -normalBuffer.y, 0); break; case UV: if (element.getIndex() != 0) break; builder.put( e, sprite.getInterpolatedU(uvBuffer.x * 16), sprite.getInterpolatedV(uvBuffer.y * 16), 0, 1); break; case COLOR: builder.put(e, 1, 1, 1, 1); break; default: builder.put(e); } } }
public BakedFluid( Optional<TRSRTransformation> transformation, ImmutableMap<TransformType, TRSRTransformation> transforms, VertexFormat format, int color, TextureAtlasSprite still, TextureAtlasSprite flowing, boolean gas, boolean statePresent, int[] cornerRound, int flowRound) { this.transformation = transformation; this.transforms = transforms; this.format = format; this.color = color; this.still = still; this.flowing = flowing; this.gas = gas; faceQuads = Maps.newEnumMap(EnumFacing.class); for (EnumFacing side : EnumFacing.values()) { faceQuads.put(side, ImmutableList.<BakedQuad>of()); } if (statePresent) { float[] y = new float[4]; for (int i = 0; i < 4; i++) { if (gas) { y[i] = 1 - cornerRound[i] / 768f; } else { y[i] = cornerRound[i] / 768f; } } float flow = (float) Math.toRadians(flowRound); // top TextureAtlasSprite topSprite = flowing; float scale = 4; if (flow < -17F) { flow = 0; scale = 8; topSprite = still; } float c = MathHelper.cos(flow) * scale; float s = MathHelper.sin(flow) * scale; EnumFacing side = gas ? EnumFacing.DOWN : EnumFacing.UP; UnpackedBakedQuad.Builder builder; ImmutableList.Builder<BakedQuad> topFaceBuilder = ImmutableList.builder(); for (int k = 0; k < 2; k++) { builder = new UnpackedBakedQuad.Builder(format); builder.setQuadOrientation(side); builder.setTexture(topSprite); for (int i = gas ? 3 : 0; i != (gas ? -1 : 4); i += (gas ? -1 : 1)) { int l = (k * 3) + (1 - 2 * k) * i; putVertex( builder, side, x[l], y[l], z[l], topSprite.getInterpolatedU(8 + c * (x[l] * 2 - 1) + s * (z[l] * 2 - 1)), topSprite.getInterpolatedV( 8 + c * (x[(l + 1) % 4] * 2 - 1) + s * (z[(l + 1) % 4] * 2 - 1))); } topFaceBuilder.add(builder.build()); } faceQuads.put(side, topFaceBuilder.build()); // bottom side = side.getOpposite(); builder = new UnpackedBakedQuad.Builder(format); builder.setQuadOrientation(side); builder.setTexture(still); for (int i = gas ? 3 : 0; i != (gas ? -1 : 4); i += (gas ? -1 : 1)) { putVertex( builder, side, z[i], gas ? 1 : 0, x[i], still.getInterpolatedU(z[i] * 16), still.getInterpolatedV(x[i] * 16)); } faceQuads.put(side, ImmutableList.<BakedQuad>of(builder.build())); // sides for (int i = 0; i < 4; i++) { side = EnumFacing.getHorizontal((5 - i) % 4); BakedQuad q[] = new BakedQuad[2]; for (int k = 0; k < 2; k++) { builder = new UnpackedBakedQuad.Builder(format); builder.setQuadOrientation(side); builder.setTexture(flowing); for (int j = 0; j < 4; j++) { int l = (k * 3) + (1 - 2 * k) * j; float yl = z[l] * y[(i + x[l]) % 4]; if (gas && z[l] == 0) yl = 1; putVertex( builder, side, x[(i + x[l]) % 4], yl, z[(i + x[l]) % 4], flowing.getInterpolatedU(x[l] * 8), flowing.getInterpolatedV((gas ? yl : 1 - yl) * 8)); } q[k] = builder.build(); } faceQuads.put(side, ImmutableList.of(q[0], q[1])); } } else { // 1 quad for inventory UnpackedBakedQuad.Builder builder = new UnpackedBakedQuad.Builder(format); builder.setQuadOrientation(EnumFacing.UP); builder.setTexture(still); for (int i = 0; i < 4; i++) { putVertex( builder, EnumFacing.UP, z[i], x[i], 0, still.getInterpolatedU(z[i] * 16), still.getInterpolatedV(x[i] * 16)); } faceQuads.put(EnumFacing.SOUTH, ImmutableList.<BakedQuad>of(builder.build())); } }