OBJ model enhancements and builder

This commit is contained in:
paulevsGitch 2021-07-24 18:20:29 +03:00
parent 099ecf68b6
commit ca9e32ae53
3 changed files with 199 additions and 23 deletions

View file

@ -1,12 +1,18 @@
package ru.bclib.client.models;
import com.mojang.math.Vector3f;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
import net.minecraft.client.renderer.block.model.BakedQuad;
import net.minecraft.client.renderer.texture.TextureAtlasSprite;
import net.minecraft.core.Direction;
@Environment(EnvType.CLIENT)
public class UnbakedQuad {
float[] data = new float[20]; // 4 points with 3 positions and 2 uvs, 4 * (3 + 2)
int spriteIndex;
private float[] data = new float[20]; // 4 points with 3 positions and 2 uvs, 4 * (3 + 2)
private Direction dir = Direction.UP;
private boolean useShading = false;
private int spriteIndex;
public void addData(int index, float value) {
data[index] = value;
@ -16,6 +22,23 @@ public class UnbakedQuad {
spriteIndex = index;
}
public void setDirection(Direction dir) {
this.dir = dir;
}
public void setShading(boolean useShading) {
this.useShading = useShading;
}
public Vector3f getPos(int index, Vector3f result) {
int dataIndex = index * 5;
float x = data[dataIndex++];
float y = data[dataIndex++];
float z = data[dataIndex];
result.set(x, y, z);
return result;
}
public BakedQuad bake(TextureAtlasSprite[] sprites) {
TextureAtlasSprite sprite = sprites[spriteIndex];
int[] vertexData = new int[32];
@ -30,6 +53,6 @@ public class UnbakedQuad {
vertexData[index | 5] = Float.floatToIntBits(sprite.getV(data[dataIndex])); // V
}
// vertices, tint index, direction, sprite, shade
return new BakedQuad(vertexData, 0, Direction.UP, sprites[spriteIndex], true);
return new BakedQuad(vertexData, 0, dir, sprites[spriteIndex], useShading);
}
}