Model transform
This commit is contained in:
parent
1ea7221f9f
commit
f853ac75d9
2 changed files with 16 additions and 6 deletions
|
@ -95,12 +95,12 @@ public class OBJBlockModel implements UnbakedModel, BakedModel {
|
||||||
sprites[i] = textureGetter.apply(materials.get(i));
|
sprites[i] = textureGetter.apply(materials.get(i));
|
||||||
}
|
}
|
||||||
quadsBaked.clear();
|
quadsBaked.clear();
|
||||||
quadsUnbaked.forEach(quad -> quadsBaked.add(quad.bake(sprites)));
|
quadsUnbaked.forEach(quad -> quadsBaked.add(quad.bake(sprites, modelState)));
|
||||||
for (Direction dir: BlocksHelper.DIRECTIONS) {
|
for (Direction dir: BlocksHelper.DIRECTIONS) {
|
||||||
List<UnbakedQuad> unbaked = quadsUnbakedMap.get(dir);
|
List<UnbakedQuad> unbaked = quadsUnbakedMap.get(dir);
|
||||||
List<BakedQuad> baked = quadsBakedMap.get(dir);
|
List<BakedQuad> baked = quadsBakedMap.get(dir);
|
||||||
baked.clear();
|
baked.clear();
|
||||||
unbaked.forEach(quad -> baked.add(quad.bake(sprites)));
|
unbaked.forEach(quad -> baked.add(quad.bake(sprites, modelState)));
|
||||||
}
|
}
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,14 +1,18 @@
|
||||||
package ru.bclib.client.models;
|
package ru.bclib.client.models;
|
||||||
|
|
||||||
|
import com.mojang.math.Matrix4f;
|
||||||
import com.mojang.math.Vector3f;
|
import com.mojang.math.Vector3f;
|
||||||
|
import com.mojang.math.Vector4f;
|
||||||
import net.fabricmc.api.EnvType;
|
import net.fabricmc.api.EnvType;
|
||||||
import net.fabricmc.api.Environment;
|
import net.fabricmc.api.Environment;
|
||||||
import net.minecraft.client.renderer.block.model.BakedQuad;
|
import net.minecraft.client.renderer.block.model.BakedQuad;
|
||||||
import net.minecraft.client.renderer.texture.TextureAtlasSprite;
|
import net.minecraft.client.renderer.texture.TextureAtlasSprite;
|
||||||
|
import net.minecraft.client.resources.model.ModelState;
|
||||||
import net.minecraft.core.Direction;
|
import net.minecraft.core.Direction;
|
||||||
|
|
||||||
@Environment(EnvType.CLIENT)
|
@Environment(EnvType.CLIENT)
|
||||||
public class UnbakedQuad {
|
public class UnbakedQuad {
|
||||||
|
private static final Vector4f POS = new Vector4f();
|
||||||
private float[] data = new float[20]; // 4 points with 3 positions and 2 uvs, 4 * (3 + 2)
|
private float[] data = new float[20]; // 4 points with 3 positions and 2 uvs, 4 * (3 + 2)
|
||||||
private Direction dir = Direction.UP;
|
private Direction dir = Direction.UP;
|
||||||
private boolean useShading = false;
|
private boolean useShading = false;
|
||||||
|
@ -39,15 +43,21 @@ public class UnbakedQuad {
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
public BakedQuad bake(TextureAtlasSprite[] sprites) {
|
public BakedQuad bake(TextureAtlasSprite[] sprites, ModelState modelState) {
|
||||||
|
Matrix4f matrix = modelState.getRotation().getMatrix();
|
||||||
TextureAtlasSprite sprite = sprites[spriteIndex];
|
TextureAtlasSprite sprite = sprites[spriteIndex];
|
||||||
int[] vertexData = new int[32];
|
int[] vertexData = new int[32];
|
||||||
for (int i = 0; i < 4; i++) {
|
for (int i = 0; i < 4; i++) {
|
||||||
int index = i << 3;
|
int index = i << 3;
|
||||||
int dataIndex = i * 5;
|
int dataIndex = i * 5;
|
||||||
vertexData[index] = Float.floatToIntBits(data[dataIndex++]); // X
|
float x = data[dataIndex++]; // X
|
||||||
vertexData[index | 1] = Float.floatToIntBits(data[dataIndex++]); // Y
|
float y = data[dataIndex++]; // Y
|
||||||
vertexData[index | 2] = Float.floatToIntBits(data[dataIndex++]); // Z
|
float z = data[dataIndex++]; // Z
|
||||||
|
POS.set(x, y, z, 0);
|
||||||
|
POS.transform(matrix);
|
||||||
|
vertexData[index] = Float.floatToIntBits(POS.x()); // X
|
||||||
|
vertexData[index | 1] = Float.floatToIntBits(POS.y()); // Y
|
||||||
|
vertexData[index | 2] = Float.floatToIntBits(POS.z()); // Z
|
||||||
vertexData[index | 3] = -1; // Unknown constant
|
vertexData[index | 3] = -1; // Unknown constant
|
||||||
vertexData[index | 4] = Float.floatToIntBits(sprite.getU(data[dataIndex++])); // U
|
vertexData[index | 4] = Float.floatToIntBits(sprite.getU(data[dataIndex++])); // U
|
||||||
vertexData[index | 5] = Float.floatToIntBits(sprite.getV(data[dataIndex])); // V
|
vertexData[index | 5] = Float.floatToIntBits(sprite.getV(data[dataIndex])); // V
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue