162 lines
		
	
	
	
		
			5.2 KiB
		
	
	
	
		
			Java
		
	
	
	
	
	
			
		
		
	
	
			162 lines
		
	
	
	
		
			5.2 KiB
		
	
	
	
		
			Java
		
	
	
	
	
	
| package com.mojang.blaze3d.vertex;
 | |
| 
 | |
| import java.nio.ByteBuffer;
 | |
| import java.nio.IntBuffer;
 | |
| import net.fabricmc.api.EnvType;
 | |
| import net.fabricmc.api.Environment;
 | |
| import net.minecraft.client.renderer.LightTexture;
 | |
| import net.minecraft.client.renderer.block.model.BakedQuad;
 | |
| import net.minecraft.util.ARGB;
 | |
| import org.joml.Matrix3x2f;
 | |
| import org.joml.Matrix4f;
 | |
| import org.joml.Vector2f;
 | |
| import org.joml.Vector3f;
 | |
| import org.joml.Vector3fc;
 | |
| import org.lwjgl.system.MemoryStack;
 | |
| 
 | |
| @Environment(EnvType.CLIENT)
 | |
| public interface VertexConsumer {
 | |
| 	VertexConsumer addVertex(float x, float y, float z);
 | |
| 
 | |
| 	VertexConsumer setColor(int red, int green, int blue, int alpha);
 | |
| 
 | |
| 	VertexConsumer setUv(float u, float v);
 | |
| 
 | |
| 	VertexConsumer setUv1(int u, int v);
 | |
| 
 | |
| 	VertexConsumer setUv2(int u, int v);
 | |
| 
 | |
| 	VertexConsumer setNormal(float normalX, float normalY, float normalZ);
 | |
| 
 | |
| 	default void addVertex(float x, float y, float z, int color, float u, float v, int packedOverlay, int packedLight, float normalX, float normalY, float normalZ) {
 | |
| 		this.addVertex(x, y, z);
 | |
| 		this.setColor(color);
 | |
| 		this.setUv(u, v);
 | |
| 		this.setOverlay(packedOverlay);
 | |
| 		this.setLight(packedLight);
 | |
| 		this.setNormal(normalX, normalY, normalZ);
 | |
| 	}
 | |
| 
 | |
| 	default VertexConsumer setColor(float red, float green, float blue, float alpha) {
 | |
| 		return this.setColor((int)(red * 255.0F), (int)(green * 255.0F), (int)(blue * 255.0F), (int)(alpha * 255.0F));
 | |
| 	}
 | |
| 
 | |
| 	default VertexConsumer setColor(int color) {
 | |
| 		return this.setColor(ARGB.red(color), ARGB.green(color), ARGB.blue(color), ARGB.alpha(color));
 | |
| 	}
 | |
| 
 | |
| 	default VertexConsumer setWhiteAlpha(int alpha) {
 | |
| 		return this.setColor(ARGB.color(alpha, -1));
 | |
| 	}
 | |
| 
 | |
| 	default VertexConsumer setLight(int packedLight) {
 | |
| 		return this.setUv2(packedLight & 65535, packedLight >> 16 & 65535);
 | |
| 	}
 | |
| 
 | |
| 	default VertexConsumer setOverlay(int packedOverlay) {
 | |
| 		return this.setUv1(packedOverlay & 65535, packedOverlay >> 16 & 65535);
 | |
| 	}
 | |
| 
 | |
| 	default void putBulkData(PoseStack.Pose pose, BakedQuad quad, float red, float green, float blue, float alpha, int packedLight, int packedOverlay) {
 | |
| 		this.putBulkData(
 | |
| 			pose,
 | |
| 			quad,
 | |
| 			new float[]{1.0F, 1.0F, 1.0F, 1.0F},
 | |
| 			red,
 | |
| 			green,
 | |
| 			blue,
 | |
| 			alpha,
 | |
| 			new int[]{packedLight, packedLight, packedLight, packedLight},
 | |
| 			packedOverlay,
 | |
| 			false
 | |
| 		);
 | |
| 	}
 | |
| 
 | |
| 	default void putBulkData(
 | |
| 		PoseStack.Pose pose,
 | |
| 		BakedQuad quad,
 | |
| 		float[] brightness,
 | |
| 		float red,
 | |
| 		float green,
 | |
| 		float blue,
 | |
| 		float alpha,
 | |
| 		int[] lightmap,
 | |
| 		int packedOverlay,
 | |
| 		boolean readExistingColor
 | |
| 	) {
 | |
| 		int[] is = quad.vertices();
 | |
| 		Vector3fc vector3fc = quad.direction().getUnitVec3f();
 | |
| 		Matrix4f matrix4f = pose.pose();
 | |
| 		Vector3f vector3f = pose.transformNormal(vector3fc, new Vector3f());
 | |
| 		int i = 8;
 | |
| 		int j = is.length / 8;
 | |
| 		int k = (int)(alpha * 255.0F);
 | |
| 		int l = quad.lightEmission();
 | |
| 
 | |
| 		try (MemoryStack memoryStack = MemoryStack.stackPush()) {
 | |
| 			ByteBuffer byteBuffer = memoryStack.malloc(DefaultVertexFormat.BLOCK.getVertexSize());
 | |
| 			IntBuffer intBuffer = byteBuffer.asIntBuffer();
 | |
| 
 | |
| 			for (int m = 0; m < j; m++) {
 | |
| 				intBuffer.clear();
 | |
| 				intBuffer.put(is, m * 8, 8);
 | |
| 				float f = byteBuffer.getFloat(0);
 | |
| 				float g = byteBuffer.getFloat(4);
 | |
| 				float h = byteBuffer.getFloat(8);
 | |
| 				float q;
 | |
| 				float r;
 | |
| 				float s;
 | |
| 				if (readExistingColor) {
 | |
| 					float n = byteBuffer.get(12) & 255;
 | |
| 					float o = byteBuffer.get(13) & 255;
 | |
| 					float p = byteBuffer.get(14) & 255;
 | |
| 					q = n * brightness[m] * red;
 | |
| 					r = o * brightness[m] * green;
 | |
| 					s = p * brightness[m] * blue;
 | |
| 				} else {
 | |
| 					q = brightness[m] * red * 255.0F;
 | |
| 					r = brightness[m] * green * 255.0F;
 | |
| 					s = brightness[m] * blue * 255.0F;
 | |
| 				}
 | |
| 
 | |
| 				int t = ARGB.color(k, (int)q, (int)r, (int)s);
 | |
| 				int u = LightTexture.lightCoordsWithEmission(lightmap[m], l);
 | |
| 				float p = byteBuffer.getFloat(16);
 | |
| 				float v = byteBuffer.getFloat(20);
 | |
| 				Vector3f vector3f2 = matrix4f.transformPosition(f, g, h, new Vector3f());
 | |
| 				this.addVertex(vector3f2.x(), vector3f2.y(), vector3f2.z(), t, p, v, packedOverlay, u, vector3f.x(), vector3f.y(), vector3f.z());
 | |
| 			}
 | |
| 		}
 | |
| 	}
 | |
| 
 | |
| 	default VertexConsumer addVertex(Vector3f pos) {
 | |
| 		return this.addVertex(pos.x(), pos.y(), pos.z());
 | |
| 	}
 | |
| 
 | |
| 	default VertexConsumer addVertex(PoseStack.Pose pose, Vector3f pos) {
 | |
| 		return this.addVertex(pose, pos.x(), pos.y(), pos.z());
 | |
| 	}
 | |
| 
 | |
| 	default VertexConsumer addVertex(PoseStack.Pose pose, float x, float y, float z) {
 | |
| 		return this.addVertex(pose.pose(), x, y, z);
 | |
| 	}
 | |
| 
 | |
| 	default VertexConsumer addVertex(Matrix4f pose, float x, float y, float z) {
 | |
| 		Vector3f vector3f = pose.transformPosition(x, y, z, new Vector3f());
 | |
| 		return this.addVertex(vector3f.x(), vector3f.y(), vector3f.z());
 | |
| 	}
 | |
| 
 | |
| 	default VertexConsumer addVertexWith2DPose(Matrix3x2f pose, float x, float y, float z) {
 | |
| 		Vector2f vector2f = pose.transformPosition(x, y, new Vector2f());
 | |
| 		return this.addVertex(vector2f.x(), vector2f.y(), z);
 | |
| 	}
 | |
| 
 | |
| 	default VertexConsumer setNormal(PoseStack.Pose pose, float normalX, float normalY, float normalZ) {
 | |
| 		Vector3f vector3f = pose.transformNormal(normalX, normalY, normalZ, new Vector3f());
 | |
| 		return this.setNormal(vector3f.x(), vector3f.y(), vector3f.z());
 | |
| 	}
 | |
| 
 | |
| 	default VertexConsumer setNormal(PoseStack.Pose pose, Vector3f normalVector) {
 | |
| 		return this.setNormal(pose, normalVector.x(), normalVector.y(), normalVector.z());
 | |
| 	}
 | |
| }
 |