@Override public double getInterpU(double u) { return sprite.getInterpolatedU(u * 16); }
uv.u1 = texture.getInterpolatedU( x1 * 16 ); uv.v1 = texture.getInterpolatedV( z1 * 16 ); uv.u2 = texture.getInterpolatedU( x2 * 16 ); uv.v2 = texture.getInterpolatedV( z2 * 16 ); break; case UP: uv.u1 = texture.getInterpolatedU( x1 * 16 ); uv.v1 = texture.getInterpolatedV( z1 * 16 ); uv.u2 = texture.getInterpolatedU( x2 * 16 ); uv.v2 = texture.getInterpolatedV( z2 * 16 ); break; case NORTH: uv.u1 = texture.getInterpolatedU( x1 * 16 ); uv.v1 = texture.getInterpolatedV( 16 - y1 * 16 ); uv.u2 = texture.getInterpolatedU( x2 * 16 ); uv.v2 = texture.getInterpolatedV( 16 - y2 * 16 ); break; case SOUTH: uv.u1 = texture.getInterpolatedU( x1 * 16 ); uv.v1 = texture.getInterpolatedV( 16 - y1 * 16 ); uv.u2 = texture.getInterpolatedU( x2 * 16 ); uv.v2 = texture.getInterpolatedV( 16 - y2 * 16 ); break; case WEST: uv.u1 = texture.getInterpolatedU( z1 * 16 ); uv.v1 = texture.getInterpolatedV( 16 - y1 * 16 ); uv.u2 = texture.getInterpolatedU( z2 * 16 ); uv.v2 = texture.getInterpolatedV( 16 - y2 * 16 ); break;
uv.u1 = texture.getInterpolatedU( x1 * 16 ); uv.v1 = texture.getInterpolatedV( 16 - z1 * 16 ); uv.u2 = texture.getInterpolatedU( x2 * 16 ); uv.v2 = texture.getInterpolatedV( 16 - z2 * 16 ); break; case UP: uv.u1 = texture.getInterpolatedU( x1 * 16 ); uv.v1 = texture.getInterpolatedV( z1 * 16 ); uv.u2 = texture.getInterpolatedU( x2 * 16 ); uv.v2 = texture.getInterpolatedV( z2 * 16 ); break; case NORTH: uv.u1 = texture.getInterpolatedU( 16 - x1 * 16 ); uv.v1 = texture.getInterpolatedV( 16 - y1 * 16 ); uv.u2 = texture.getInterpolatedU( 16 - x2 * 16 ); uv.v2 = texture.getInterpolatedV( 16 - y2 * 16 ); break; case SOUTH: uv.u1 = texture.getInterpolatedU( x1 * 16 ); uv.v1 = texture.getInterpolatedV( 16 - y1 * 16 ); uv.u2 = texture.getInterpolatedU( x2 * 16 ); uv.v2 = texture.getInterpolatedV( 16 - y2 * 16 ); break; case WEST: uv.u1 = texture.getInterpolatedU( z1 * 16 ); uv.v1 = texture.getInterpolatedV( 16 - y1 * 16 ); uv.u2 = texture.getInterpolatedU( z2 * 16 ); uv.v2 = texture.getInterpolatedV( 16 - y2 * 16 ); break;
buffer.pos( TwoPx, middle + press, TwoPx ).tex( tas.getInterpolatedU( 2 ), tas.getInterpolatedV( 13 ) ).endVertex(); buffer.pos( 1.0 - TwoPx, middle + press, TwoPx ).tex( tas.getInterpolatedU( 14 ), tas.getInterpolatedV( 13 ) ).endVertex(); buffer.pos( 1.0 - TwoPx, middle + press, 1.0 - TwoPx ).tex( tas.getInterpolatedU( 14 ), tas.getInterpolatedV( 2 ) ).endVertex(); buffer.pos( TwoPx, middle + press, 1.0 - TwoPx ).tex( tas.getInterpolatedU( 2 ), tas.getInterpolatedV( 2 ) ).endVertex(); buffer.pos( TwoPx, middle + base, TwoPx ).tex( tas.getInterpolatedU( 2 ), tas.getInterpolatedV( 3 - 16 * ( press - base ) ) ).endVertex(); buffer.pos( 1.0 - TwoPx, middle + base, TwoPx ).tex( tas.getInterpolatedU( 14 ), tas.getInterpolatedV( 3 - 16 * ( press - base ) ) ).endVertex(); buffer.pos( 1.0 - TwoPx, middle + press, TwoPx ).tex( tas.getInterpolatedU( 14 ), tas.getInterpolatedV( 3 ) ).endVertex(); buffer.pos( TwoPx, middle + press, TwoPx ).tex( tas.getInterpolatedU( 2 ), tas.getInterpolatedV( 3 ) ).endVertex(); buffer.pos( 1.0 - TwoPx, middle - press, TwoPx ).tex( tas.getInterpolatedU( 2 ), tas.getInterpolatedV( 13 ) ).endVertex(); buffer.pos( TwoPx, middle - press, TwoPx ).tex( tas.getInterpolatedU( 14 ), tas.getInterpolatedV( 13 ) ).endVertex(); buffer.pos( TwoPx, middle - press, 1.0 - TwoPx ).tex( tas.getInterpolatedU( 14 ), tas.getInterpolatedV( 2 ) ).endVertex(); buffer.pos( 1.0 - TwoPx, middle - press, 1.0 - TwoPx ).tex( tas.getInterpolatedU( 2 ), tas.getInterpolatedV( 2 ) ).endVertex(); buffer.pos( 1.0 - TwoPx, middle + -base, TwoPx ).tex( tas.getInterpolatedU( 2 ), tas.getInterpolatedV( 3 - 16 * ( press - base ) ) ).endVertex(); buffer.pos( TwoPx, middle - base, TwoPx ).tex( tas.getInterpolatedU( 14 ), tas.getInterpolatedV( 3 - 16 * ( press - base ) ) ).endVertex(); buffer.pos( TwoPx, middle - press, TwoPx ).tex( tas.getInterpolatedU( 14 ), tas.getInterpolatedV( 3 ) ).endVertex(); buffer.pos( 1.0 - TwoPx, middle - press, TwoPx ).tex( tas.getInterpolatedU( 2 ), tas.getInterpolatedV( 3 ) ).endVertex();
private void putVertex( UnpackedBakedQuad.Builder builder, Vec3d normal, double x, double y, double z, TextureAtlasSprite sprite, float u, float v ) { for( int e = 0; e < this.vertexFormat.getElementCount(); e++ ) { switch( this.vertexFormat.getElement( e ).getUsage() ) { case POSITION: builder.put( e, (float) x, (float) y, (float) z, 1.0f ); break; case COLOR: builder.put( e, 1.0f, 1.0f, 1.0f, 1.0f ); break; case UV: if( this.vertexFormat.getElement( e ).getIndex() == 0 ) { u = sprite.getInterpolatedU( u ); v = sprite.getInterpolatedV( v ); builder.put( e, u, v, 0f, 1f ); break; } case NORMAL: builder.put( e, (float) normal.x, (float) normal.y, (float) normal.z, 0f ); break; default: builder.put( e ); break; } } }
if( customUv != null ) uv.u1 = texture.getInterpolatedU( customUv.x ); uv.v1 = texture.getInterpolatedV( customUv.y ); uv.u2 = texture.getInterpolatedU( customUv.z ); uv.v2 = texture.getInterpolatedV( customUv.w );
/** * Converts the vertex information to the int array format expected by BakedQuads. Useful if you don't know * in advance what it should be. * @param x x coordinate * @param y y coordinate * @param z z coordinate * @param color RGBA colour format - white for no effect, non-white to tint the face with the specified colour * @param texture the texture to use for the face * @param u u-coordinate of the texture (0 - 16) corresponding to [x,y,z] * @param v v-coordinate of the texture (0 - 16) corresponding to [x,y,z] * @param normal the packed representation of the normal vector, see calculatePackedNormal(). Used for lighting items. * @return */ private int[] vertexToInts(float x, float y, float z, int color, TextureAtlasSprite texture, float u, float v, int normal) { return new int[] { Float.floatToRawIntBits(x), Float.floatToRawIntBits(y), Float.floatToRawIntBits(z), color, Float.floatToRawIntBits(texture.getInterpolatedU(u)), Float.floatToRawIntBits(texture.getInterpolatedV(v)), normal }; }
public LimitedTextureAtlasSprite(TextureAtlasSprite parent, Vector4f uv) { super(parent.getIconName()); copyFrom(parent); minU = super.getInterpolatedU(uv.x * 16); maxU = super.getInterpolatedU(uv.z * 16); minV = super.getInterpolatedV(uv.y * 16); maxV = super.getInterpolatedV(uv.w * 16); }
/** * Draw an arbitrarily sized quad with the specified texture coordinates and texture. * <p> * The UV coordinates are relative to the sprite. * * @param sprite the sprite to render. * @param x the x position of the quad. * @param y the y position of the quad. * @param w the width of the quad. * @param h the height of the quad. * @param u0 lower u texture coordinate. * @param v0 lower v texture coordinate. * @param u1 upper u texture coordinate. * @param v1 upper v texture coordinate. */ @SideOnly(Side.CLIENT) public static void drawQuad(final TextureAtlasSprite sprite, final float x, final float y, final float w, final float h, final float u0, final float v0, final float u1, final float v1) { drawQuad(x, y, w, h, sprite.getInterpolatedU(u0 * 16), sprite.getInterpolatedV(v0 * 16), sprite.getInterpolatedU(u1 * 16), sprite.getInterpolatedV(v1 * 16)); }
protected void renderTransmissionDynamic(@Nonnull IConduit conduit, @Nonnull IConduitTexture tex, @Nullable Vector4f color, @Nonnull CollidableComponent component, float selfIllum) { float scaleFactor = 0.6f; final EnumFacing componentDirection = component.getDirection(); float xLen = Math.abs(componentDirection.getFrontOffsetX()) == 1 ? 1 : scaleFactor; float yLen = Math.abs(componentDirection.getFrontOffsetY()) == 1 ? 1 : scaleFactor; float zLen = Math.abs(componentDirection.getFrontOffsetZ()) == 1 ? 1 : scaleFactor; GlStateManager.color(1, 1, 1); BoundingBox cube = component.bound; BoundingBox bb = cube.scale(xLen, yLen, zLen); TextureAtlasSprite sprite = tex.getSprite(); drawDynamicSection(bb, sprite.getInterpolatedU(tex.getUv().x * 16), sprite.getInterpolatedU(tex.getUv().z * 16), sprite.getInterpolatedV(tex.getUv().y * 16), sprite.getInterpolatedV(tex.getUv().w * 16), color, componentDirection, false); }
protected void drawCutIcon(BufferBuilder buffer, TextureAtlasSprite icon, int x, int y, int width, int height, int cut) { addVertexWithUV(buffer, x, y + height, zLevel, icon.getMinU(), icon.getInterpolatedV(height)); addVertexWithUV(buffer, x + width, y + height, zLevel, icon.getInterpolatedU(width), icon.getInterpolatedV(height)); addVertexWithUV(buffer, x + width, y + cut, zLevel, icon.getInterpolatedU(width), icon.getInterpolatedV(cut)); addVertexWithUV(buffer, x, y + cut, zLevel, icon.getMinU(), icon.getInterpolatedV(cut)); }
@Override protected void renderTransmissionDynamic(@Nonnull IConduit conduit, @Nonnull IConduitTexture tex, @Nullable Vector4f color, @Nonnull CollidableComponent component, float selfIllum) { final float filledRatio = ((LiquidConduit) conduit).getTank().getFilledRatio(); if (filledRatio <= 0) { return; } if (component.isDirectional()) { TextureAtlasSprite sprite = tex.getSprite(); BoundingBox[] cubes = toCubes(component.bound); for (BoundingBox cube : cubes) { if (cube != null) { float shrink = 1 / 128f; final EnumFacing componentDirection = component.getDirection(); float xLen = Math.abs(componentDirection.getFrontOffsetX()) == 1 ? 0 : shrink; float yLen = Math.abs(componentDirection.getFrontOffsetY()) == 1 ? 0 : shrink; float zLen = Math.abs(componentDirection.getFrontOffsetZ()) == 1 ? 0 : shrink; BoundingBox bb = cube.expand(-xLen, -yLen, -zLen); // TODO: This leaves holes between conduits as it only render 4 sides instead of the needed 5-6 sides drawDynamicSection(bb, sprite.getInterpolatedU(tex.getUv().x * 16), sprite.getInterpolatedU(tex.getUv().z * 16), sprite.getInterpolatedV(tex.getUv().y * 16), sprite.getInterpolatedV(tex.getUv().w * 16), color, componentDirection, true); } } } else { // TODO: HL: I commented this out because component.getDirection() (the second to last parameter) is always null in // this else branch and drawDynamicSection() with isTransmission=true (last parameter) would NPE on it. (Not a // mistake in the component.dir encapsulation, this was that way before.) // drawDynamicSection(component.bound, tex.getMinU(), tex.getMaxU(), tex.getMinV(), tex.getMaxV(), color, component.getDir(), true); } }
protected void renderConduitDynamic(@Nonnull IConduitTexture tex, @Nonnull IClientConduit.WithDefaultRendering conduit, @Nonnull CollidableComponent component, float brightness) { GlStateManager.color(1, 1, 1); if (component.isDirectional() && component.data == null) { final EnumFacing componentDirection = component.getDirection(); float scaleFactor = 0.75f; float xLen = Math.abs(componentDirection.getFrontOffsetX()) == 1 ? 1 : scaleFactor; float yLen = Math.abs(componentDirection.getFrontOffsetY()) == 1 ? 1 : scaleFactor; float zLen = Math.abs(componentDirection.getFrontOffsetZ()) == 1 ? 1 : scaleFactor; BoundingBox cube = component.bound; BoundingBox bb = cube.scale(xLen, yLen, zLen); TextureAtlasSprite sprite = tex.getSprite(); drawDynamicSection(bb, sprite.getInterpolatedU(tex.getUv().x * 16), sprite.getInterpolatedU(tex.getUv().z * 16), sprite.getInterpolatedV(tex.getUv().y * 16), sprite.getInterpolatedV(tex.getUv().w * 16), componentDirection, false, conduit.shouldMirrorTexture()); if (conduit.getConnectionMode(componentDirection) == ConnectionMode.DISABLED) { TextureAtlasSprite tex2 = ConduitBundleRenderManager.instance.getConnectorIcon(component.data); List<Vertex> corners = component.bound.getCornersWithUvForFace(componentDirection, tex2.getMinU(), tex2.getMaxU(), tex2.getMinV(), tex2.getMaxV()); RenderUtil.addVerticesToTessellator(corners, DefaultVertexFormats.POSITION_TEX, false); } } else { // TODO: HL: I commented this out because component.getDirection() (the second to last parameter) is always null in // this else branch and drawDynamicSection() with isTransmission=true (last parameter) would NPE on it. (Not a // mistake in the component.dir encapsulation, this was that way before.) // drawDynamicSection(component.bound, tex.getMinU(), tex.getMaxU(), tex.getMinV(), tex.getMaxV(), dir, true); } }
public void render(@Nonnull BufferBuilder tes) { for (Vertex v : corners) { tes.pos(v.x(), v.y(), v.z()).tex(tex.getInterpolatedU(v.u() * 16), tex.getInterpolatedV(v.v() * 16)).color(color.x, color.y, color.z, color.w) .normal(v.nx(), v.ny(), v.nz()).endVertex(); } }
private void drawCutIcon(TextureAtlasSprite icon, int x, int y, int width, int height, int cut) { Tessellator tess = Tessellator.getInstance(); BufferBuilder buffer = tess.getBuffer(); buffer.begin(GL11.GL_QUADS, DefaultVertexFormats.POSITION_TEX); buffer.pos(x, y + height, zLevel).tex(icon.getMinU(), icon.getInterpolatedV(height)).endVertex(); buffer.pos(x + width, y + height, zLevel).tex(icon.getInterpolatedU(width), icon.getInterpolatedV(height)).endVertex(); buffer.pos(x + width, y + cut, zLevel).tex(icon.getInterpolatedU(width), icon.getInterpolatedV(cut)).endVertex(); buffer.pos(x, y + cut, zLevel).tex(icon.getMinU(), icon.getInterpolatedV(cut)).endVertex(); tess.draw(); } }
private void putVertexData(@Nonnull Builder builder, @Nonnull Vertex v, float w) { VertexFormat format = builder.getVertexFormat(); for (int e = 0; e < format.getElementCount(); e++) { switch (format.getElement(e).getUsage()) { case POSITION: builder.put(e, (float) v.x(), (float) v.y(), (float) v.z(), 1); break; case COLOR: float d = LightUtil.diffuseLight(v.nx(), v.ny(), v.nz()); builder.put(e, d * color.x, d * color.y, d * color.z, color.w); break; case UV: builder.put(e, tex.getInterpolatedU(v.u() * 16) * w, tex.getInterpolatedV(v.v() * 16) * w, 0, w); break; case NORMAL: builder.put(e, v.nx(), v.ny(), v.nz(), 0); break; default: builder.put(e); } } }
private void putVertex(UnpackedBakedQuad.Builder builder, Vec3d normal, double x, double y, double z, float u, float v, TextureAtlasSprite sprite, float color) { for (int e = 0; e < format.getElementCount(); e++) { switch (format.getElement(e).getUsage()) { case POSITION: builder.put(e, (float)x, (float)y, (float)z, 1.0f); break; case COLOR: builder.put(e, color, color, color, 1.0f); break; case UV: if (format.getElement(e).getIndex() == 0) { u = sprite.getInterpolatedU(u); v = sprite.getInterpolatedV(v); builder.put(e, u, v, 0f, 1f); break; } case NORMAL: builder.put(e, (float) normal.x, (float) normal.y, (float) normal.z, 0f); break; default: builder.put(e); break; } } }
private void putVertex(UnpackedBakedQuad.Builder builder, Vec3d normal, double x, double y, double z, float u, float v) { for (int e = 0; e < format.getElementCount(); e++) { switch (format.getElement(e).getUsage()) { case POSITION: builder.put(e, (float)x, (float)y, (float)z, 1.0f); break; case COLOR: builder.put(e, 1.0f, 1.0f, 1.0f, 1.0f); break; case UV: if (format.getElement(e).getIndex() == 0) { u = sprite.getInterpolatedU(u); v = sprite.getInterpolatedV(v); builder.put(e, u, v, 0f, 1f); break; } case NORMAL: builder.put(e, (float) normal.x, (float) normal.y, (float) normal.z, 0f); break; default: builder.put(e); break; } } }
protected void putVertex(UnpackedBakedQuad.Builder builder, Vec3d normal, TextureAtlasSprite sprite, double x, double y, double z, float u, float v, int rgbaColor) { for (int e = 0; e < format.getElementCount(); e++) { switch (format.getElement(e).getUsage()) { case POSITION: builder.put(e, (float) x, (float) y, (float) z, 1.0f); break; case COLOR: float red = ((rgbaColor >> 16) & 0xFF) / 255.0f; float green = ((rgbaColor >> 8) & 0xFF) / 255.0f; float blue = ((rgbaColor) & 0xFF) / 255.0f; builder.put(e, red, green, blue, 1.0f); break; case UV: if (format.getElement(e).getIndex() == 0) { u = sprite.getInterpolatedU(u); v = sprite.getInterpolatedV(v); builder.put(e, u, v, 0f, 1f); break; } case NORMAL: builder.put(e, (float) normal.x, (float) normal.y, (float) normal.z, 0f); break; default: builder.put(e); break; } } }
public static void putVertex(UnpackedBakedQuad.Builder builder, Vec3d normal, double x, double y, double z, float u, float v, TextureAtlasSprite sprite) { VertexFormat format = builder.getVertexFormat(); for (int e = 0; e < format.getElementCount(); ++e) { switch (format.getElement(e).getUsage()) { case POSITION: builder.put(e, (float) x, (float) y, (float) z, 1.0f); break; case COLOR: builder.put(e, 1.0f, 1.0f, 1.0f, 1.0f); break; case UV: if (format.getElement(e).getIndex() == 0) { u = sprite.getInterpolatedU((double) u); v = sprite.getInterpolatedV((double) v); builder.put(e, u, v, 0.0F, 1.0F); } break; case NORMAL: builder.put(e, (float) normal.x, (float) normal.y, (float) normal.z, 0.0F); break; default: builder.put(e); break; } } } }