OBJ model offset
This commit is contained in:
parent
5efab22561
commit
4a6d618598
2 changed files with 15 additions and 7 deletions
|
@ -57,7 +57,7 @@ public class OBJBlockModel implements UnbakedModel, BakedModel {
|
||||||
protected boolean useShading;
|
protected boolean useShading;
|
||||||
protected byte particleIndex;
|
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) {
|
for (Direction dir: BlocksHelper.DIRECTIONS) {
|
||||||
quadsUnbakedMap.put(dir, Lists.newArrayList());
|
quadsUnbakedMap.put(dir, Lists.newArrayList());
|
||||||
quadsBakedMap.put(dir, Lists.newArrayList());
|
quadsBakedMap.put(dir, Lists.newArrayList());
|
||||||
|
@ -69,7 +69,7 @@ public class OBJBlockModel implements UnbakedModel, BakedModel {
|
||||||
this.particleIndex = particleIndex;
|
this.particleIndex = particleIndex;
|
||||||
this.useCulling = useCulling;
|
this.useCulling = useCulling;
|
||||||
this.useShading = useShading;
|
this.useShading = useShading;
|
||||||
loadModel(location, textureIDs);
|
loadModel(location, textureIDs, offset);
|
||||||
}
|
}
|
||||||
|
|
||||||
// UnbakedModel //
|
// UnbakedModel //
|
||||||
|
@ -163,7 +163,7 @@ public class OBJBlockModel implements UnbakedModel, BakedModel {
|
||||||
return resource;
|
return resource;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void loadModel(ResourceLocation location, ResourceLocation[] textureIDs) {
|
private void loadModel(ResourceLocation location, ResourceLocation[] textureIDs, Vector3f offset) {
|
||||||
Resource resource = getResource(location);
|
Resource resource = getResource(location);
|
||||||
if (resource == null) {
|
if (resource == null) {
|
||||||
return;
|
return;
|
||||||
|
@ -227,9 +227,9 @@ public class OBJBlockModel implements UnbakedModel, BakedModel {
|
||||||
for (int i = 0; i < 4; i++) {
|
for (int i = 0; i < 4; i++) {
|
||||||
int index = vertexIndex.get(i) * 3;
|
int index = vertexIndex.get(i) * 3;
|
||||||
int quadIndex = i * 5;
|
int quadIndex = i * 5;
|
||||||
quad.addData(quadIndex++, vertecies.get(index++)); // X
|
quad.addData(quadIndex++, vertecies.get(index++) + offset.x()); // X
|
||||||
quad.addData(quadIndex++, vertecies.get(index++)); // Y
|
quad.addData(quadIndex++, vertecies.get(index++) + offset.y()); // Y
|
||||||
quad.addData(quadIndex++, vertecies.get(index)); // Z
|
quad.addData(quadIndex++, vertecies.get(index) + offset.z()); // Z
|
||||||
if (hasUV) {
|
if (hasUV) {
|
||||||
index = uvIndex.get(i) * 2;
|
index = uvIndex.get(i) * 2;
|
||||||
quad.addData(quadIndex++, uvs.get(index++) * 16F); // U
|
quad.addData(quadIndex++, uvs.get(index++) * 16F); // U
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
package ru.bclib.client.models;
|
package ru.bclib.client.models;
|
||||||
|
|
||||||
import com.google.common.collect.Lists;
|
import com.google.common.collect.Lists;
|
||||||
|
import com.mojang.math.Vector3f;
|
||||||
import net.fabricmc.api.EnvType;
|
import net.fabricmc.api.EnvType;
|
||||||
import net.fabricmc.api.Environment;
|
import net.fabricmc.api.Environment;
|
||||||
import net.minecraft.resources.ResourceLocation;
|
import net.minecraft.resources.ResourceLocation;
|
||||||
|
@ -15,6 +16,7 @@ public class OBJModelBuilder {
|
||||||
private ResourceLocation particles;
|
private ResourceLocation particles;
|
||||||
private boolean useCulling;
|
private boolean useCulling;
|
||||||
private boolean useShading;
|
private boolean useShading;
|
||||||
|
private Vector3f offset;
|
||||||
|
|
||||||
private OBJModelBuilder() {}
|
private OBJModelBuilder() {}
|
||||||
|
|
||||||
|
@ -24,6 +26,7 @@ public class OBJModelBuilder {
|
||||||
*/
|
*/
|
||||||
public static OBJModelBuilder start(ResourceLocation modelLocation) {
|
public static OBJModelBuilder start(ResourceLocation modelLocation) {
|
||||||
INSTANCE.modelLocation = modelLocation;
|
INSTANCE.modelLocation = modelLocation;
|
||||||
|
INSTANCE.offset.set(0, 0, 0);
|
||||||
INSTANCE.useCulling = true;
|
INSTANCE.useCulling = true;
|
||||||
INSTANCE.useShading = true;
|
INSTANCE.useShading = true;
|
||||||
INSTANCE.particles = null;
|
INSTANCE.particles = null;
|
||||||
|
@ -76,6 +79,11 @@ public class OBJModelBuilder {
|
||||||
return this;
|
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.
|
* Builds model from all required data.
|
||||||
* @return {@link OBJBlockModel}.
|
* @return {@link OBJBlockModel}.
|
||||||
|
@ -90,6 +98,6 @@ public class OBJModelBuilder {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
ResourceLocation[] sprites = textures.toArray(new ResourceLocation[textures.size()]);
|
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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue