Java Code Examples for net.minecraft.client.renderer.block.model.BakedQuad#getVertexData()

The following examples show how to use net.minecraft.client.renderer.block.model.BakedQuad#getVertexData() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: GTBakedQuadTinted.java    From GT-Classic with GNU Lesser General Public License v3.0 5 votes vote down vote up
public GTBakedQuadTinted(BakedQuad quad, int rgb) {
	super(quad.getVertexData(), quad.getTintIndex(), quad.getFace(), quad.getSprite(), quad.shouldApplyDiffuseLighting(), quad.getFormat());
	this.vertexData = quad.getVertexData();
	for (int i = 0; i < 4; i++) {
		vertexData[(format.getColorOffset() / 4) + format.getIntegerSize() * i] = GTModelUtils.rgbToABGR(rgb);
	}
}
 
Example 2
Source File: BWBakedModel.java    From NOVA-Core with GNU Lesser General Public License v3.0 4 votes vote down vote up
public Face quadToFace(BakedQuad quad) {
	Face face = new Face();
	final VertexFormat format = quad.getFormat();

	int[] data = quad.getVertexData();
	Optional<TextureAtlasSprite> texture = Optional.ofNullable(quad.getSprite() == null ? wrapped.getParticleTexture() : quad.getSprite());

	final Optional<VertexFormatElement> posElement = ((Collection<VertexFormatElement>)format.getElements()).stream()
		.filter(VertexFormatElement::isPositionElement)
		.findFirst();

	final Optional<VertexFormatElement> uvElement = ((Collection<VertexFormatElement>)format.getElements()).stream()
		.filter(vfe -> vfe.getUsage() == VertexFormatElement.EnumUsage.UV)
		.findFirst();

	face.texture = texture
		.filter(t -> uvElement.isPresent())
		.map(TextureAtlasSprite::getIconName)
		.map(ResourceLocation::new)
		.map(AssetConverter.instance()::toNovaTexture);

	// `VertexFormat` offsets are for a `ByteBuffer`
	// `data` is an int array, so we convert it

	// TODO: support offsets which are not divisible by four
	final int posOffset = posElement.map(VertexFormatElement::getIndex).map(i -> i / 4).orElse(-1);
	final int uvOffset = uvElement.map(VertexFormatElement::getIndex).map(i -> i / 4).orElse(-1);
	final int colorOffset = format.hasColor() ? (format.getColorOffset() / 4) : -1;
	final int normalOffset = format.hasNormal() ? (format.getNormalOffset() / 4) : -1;

	for (int i = 0; i < data.length; i += 7) {
		Vector3D pos = posElement.isPresent() ? new Vector3D(
			Float.intBitsToFloat(data[i + posOffset]),
			Float.intBitsToFloat(data[i + posOffset + 1]),
			Float.intBitsToFloat(data[i + posOffset + 2])) : Vector3D.ZERO;

		Vector2D uv = uvElement.isPresent() ? new Vector2D(
			deinterpolateU(Float.intBitsToFloat(data[i + uvOffset]), texture),
			deinterpolateV(Float.intBitsToFloat(data[i + uvOffset + 1]), texture)) : Vector2D.ZERO;

		Vertex vertex = new Vertex(pos, uv);
		if (format.hasColor()) {
			vertex.color = Color.argb(data[i + colorOffset]);
		}

		Optional<Vector3D> normal = Optional.empty();
		if (format.hasNormal()) {
			int mergedNormal = data[i + normalOffset];
			if (mergedNormal != 0)
				normal = Optional.of(new Vector3D(((byte)(mergedNormal & 0xFF)) / 127D,
					((byte)((mergedNormal >> 8) & 0xFF)) / 127D,
					((byte)((mergedNormal >> 16) & 0xFF)) / 127D));
		}

		if (format.hasNormal())
			vertex.normal = normal;
		face.drawVertex(vertex);
	}
	face.normal = Vector3DUtil.calculateNormal(face);
	return face;
}
 
Example 3
Source File: BWBakedModel.java    From NOVA-Core with GNU Lesser General Public License v3.0 4 votes vote down vote up
@SuppressWarnings("unchecked")
public Face quadToFace(BakedQuad quad) {
	Face face = new Face();
	final VertexFormat format = this.format; // 1.11.2 stores VertexFormat on a per-quad basis.

	int[] data = quad.getVertexData();
	Optional<TextureAtlasSprite> texture = Optional.ofNullable(wrapped.getTexture());

	final Optional<VertexFormatElement> posElement = ((Collection<VertexFormatElement>)format.getElements()).stream()
		.filter(VertexFormatElement::isPositionElement)
		.findFirst();

	final Optional<VertexFormatElement> uvElement = ((Collection<VertexFormatElement>)format.getElements()).stream()
		.filter(vfe -> vfe.getUsage() == VertexFormatElement.EnumUsage.UV)
		.findFirst();

	face.texture = texture
		.filter(t -> uvElement.isPresent())
		.map(TextureAtlasSprite::getIconName)
		.map(ResourceLocation::new)
		.map(AssetConverter.instance()::toNovaTexture);

	// `VertexFormat` offsets are for a `ByteBuffer`
	// `data` is an int array, so we convert the offsets

	// TODO: support offsets which are not divisible by four
	final int posOffset = posElement.map(VertexFormatElement::getOffset).map(i -> i / 4).orElse(-1);
	final int uvOffset = uvElement.map(VertexFormatElement::getOffset).map(i -> i / 4).orElse(-1);
	final int colorOffset = format.hasColor() ? (format.getColorOffset() / 4) : -1;
	final int normalOffset = format.hasNormal() ? (format.getNormalOffset() / 4) : -1;

	for (int i = 0; i < data.length; i += 7) {
		Vector3D pos = posElement.isPresent() ? new Vector3D(
			Float.intBitsToFloat(data[i + posOffset]),
			Float.intBitsToFloat(data[i + posOffset + 1]),
			Float.intBitsToFloat(data[i + posOffset + 2])) : Vector3D.ZERO;

		Vector2D uv = uvElement.isPresent() ? new Vector2D(
			deinterpolateU(Float.intBitsToFloat(data[i + uvOffset]), texture),
			deinterpolateV(Float.intBitsToFloat(data[i + uvOffset + 1]), texture)) : Vector2D.ZERO;

		Vertex vertex = new Vertex(pos, uv);
		if (format.hasColor()) {
			if (DefaultVertexFormats.BLOCK.equals(format))
				vertex.color = Color.argb(data[i + colorOffset]);
			else
				vertex.color = Color.rgba(data[i + colorOffset]);
		}

		Optional<Vector3D> normal = Optional.empty();
		if (format.hasNormal()) {
			int mergedNormal = data[i + normalOffset];
			if (mergedNormal != 0)
				normal = Optional.of(new Vector3D(((byte)(mergedNormal & 0xFF)) / 127D,
					((byte)((mergedNormal >> 8) & 0xFF)) / 127D,
					((byte)((mergedNormal >> 16) & 0xFF)) / 127D));
		}

		if (format.hasNormal())
			vertex.normal = normal;
		face.drawVertex(vertex);
	}
	face.normal = Vector3DUtil.calculateNormal(face);
	return face;
}