OBJ model offset

This commit is contained in:
paulevsGitch 2021-07-24 20:02:25 +03:00
parent 5efab22561
commit 4a6d618598
2 changed files with 15 additions and 7 deletions

View file

@ -57,7 +57,7 @@ public class OBJBlockModel implements UnbakedModel, BakedModel {
protected boolean useShading;
protected byte particleIndex;
public OBJBlockModel(ResourceLocation location, boolean useCulling, boolean useShading, byte particleIndex, ResourceLocation... textureIDs) {
public OBJBlockModel(ResourceLocation location, Vector3f offset, boolean useCulling, boolean useShading, byte particleIndex, ResourceLocation... textureIDs) {
for (Direction dir: BlocksHelper.DIRECTIONS) {
quadsUnbakedMap.put(dir, Lists.newArrayList());
quadsBakedMap.put(dir, Lists.newArrayList());
@ -69,7 +69,7 @@ public class OBJBlockModel implements UnbakedModel, BakedModel {
this.particleIndex = particleIndex;
this.useCulling = useCulling;
this.useShading = useShading;
loadModel(location, textureIDs);
loadModel(location, textureIDs, offset);
}
// UnbakedModel //
@ -163,7 +163,7 @@ public class OBJBlockModel implements UnbakedModel, BakedModel {
return resource;
}
private void loadModel(ResourceLocation location, ResourceLocation[] textureIDs) {
private void loadModel(ResourceLocation location, ResourceLocation[] textureIDs, Vector3f offset) {
Resource resource = getResource(location);
if (resource == null) {
return;
@ -227,9 +227,9 @@ public class OBJBlockModel implements UnbakedModel, BakedModel {
for (int i = 0; i < 4; i++) {
int index = vertexIndex.get(i) * 3;
int quadIndex = i * 5;
quad.addData(quadIndex++, vertecies.get(index++)); // X
quad.addData(quadIndex++, vertecies.get(index++)); // Y
quad.addData(quadIndex++, vertecies.get(index)); // Z
quad.addData(quadIndex++, vertecies.get(index++) + offset.x()); // X
quad.addData(quadIndex++, vertecies.get(index++) + offset.y()); // Y
quad.addData(quadIndex++, vertecies.get(index) + offset.z()); // Z
if (hasUV) {
index = uvIndex.get(i) * 2;
quad.addData(quadIndex++, uvs.get(index++) * 16F); // U

View file

@ -1,6 +1,7 @@
package ru.bclib.client.models;
import com.google.common.collect.Lists;
import com.mojang.math.Vector3f;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
import net.minecraft.resources.ResourceLocation;
@ -15,6 +16,7 @@ public class OBJModelBuilder {
private ResourceLocation particles;
private boolean useCulling;
private boolean useShading;
private Vector3f offset;
private OBJModelBuilder() {}
@ -24,6 +26,7 @@ public class OBJModelBuilder {
*/
public static OBJModelBuilder start(ResourceLocation modelLocation) {
INSTANCE.modelLocation = modelLocation;
INSTANCE.offset.set(0, 0, 0);
INSTANCE.useCulling = true;
INSTANCE.useShading = true;
INSTANCE.particles = null;
@ -76,6 +79,11 @@ public class OBJModelBuilder {
return this;
}
public OBJModelBuilder setOffset(float x, float y, float z) {
this.offset.set(x, y, z);
return this;
}
/**
* Builds model from all required data.
* @return {@link OBJBlockModel}.
@ -90,6 +98,6 @@ public class OBJModelBuilder {
}
}
ResourceLocation[] sprites = textures.toArray(new ResourceLocation[textures.size()]);
return new OBJBlockModel(modelLocation, useCulling, useShading, particleIndex, sprites);
return new OBJBlockModel(modelLocation, offset, useCulling, useShading, particleIndex, sprites);
}
}