Hat model caching
This commit is contained in:
@@ -3,11 +3,11 @@ package org.saturnclient.cosmetics.hat;
|
||||
import java.io.IOException;
|
||||
import java.util.Map;
|
||||
|
||||
import org.saturnclient.cosmetics.obj.ObjModel;
|
||||
import org.saturnclient.cosmetics.obj.ObjRenderer;
|
||||
import org.saturnclient.saturnclient.client.player.SaturnPlayer;
|
||||
|
||||
import de.javagl.obj.Mtl;
|
||||
import de.javagl.obj.Obj;
|
||||
import net.minecraft.client.render.OverlayTexture;
|
||||
import net.minecraft.client.render.VertexConsumerProvider;
|
||||
import net.minecraft.client.render.entity.feature.FeatureRenderer;
|
||||
@@ -19,15 +19,12 @@ import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.Identifier;
|
||||
|
||||
public class HatFeatureRenderer extends FeatureRenderer<PlayerEntityRenderState, PlayerEntityModel> {
|
||||
static Identifier HAT = Identifier.of("saturnclient", "models/item/horns/horns.obj");
|
||||
static Identifier BLACK_MTL = Identifier.of("saturnclient", "models/item/black.mtl");
|
||||
Obj obj;
|
||||
static Identifier BLACK_MTL = Identifier.of("saturnclient", "models/cosmetic/black.mtl");
|
||||
Map<String, Mtl> mtl;
|
||||
|
||||
public HatFeatureRenderer(FeatureRendererContext<PlayerEntityRenderState, PlayerEntityModel> context) {
|
||||
super(context);
|
||||
try {
|
||||
this.obj = ObjRenderer.loadObj(HAT);
|
||||
this.mtl = ObjRenderer.loadMtl(BLACK_MTL);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
@@ -52,9 +49,9 @@ public class HatFeatureRenderer extends FeatureRenderer<PlayerEntityRenderState,
|
||||
|
||||
matrices.scale(0.25f, 0.25f, 0.25f);
|
||||
matrices.translate(0.0f, 1.0f, 0.0f);
|
||||
|
||||
// Identifier.of("saturnclient:hat_" + player.hat);
|
||||
ObjRenderer.renderObj(this.obj, this.mtl, matrices, vertexConsumers, light, OverlayTexture.DEFAULT_UV);
|
||||
ObjModel.of(Identifier.of("saturnclient", "models/cosmetic/" + player.hat.split("_")[0] + "/model")).render(
|
||||
this.mtl,
|
||||
matrices, vertexConsumers, light, OverlayTexture.DEFAULT_UV);
|
||||
|
||||
matrices.pop();
|
||||
}
|
||||
|
||||
@@ -0,0 +1,57 @@
|
||||
package org.saturnclient.cosmetics.obj;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonFormat;
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
|
||||
import de.javagl.obj.Mtl;
|
||||
import de.javagl.obj.Obj;
|
||||
import net.minecraft.client.render.VertexConsumerProvider;
|
||||
import net.minecraft.client.util.math.MatrixStack;
|
||||
import net.minecraft.util.Identifier;
|
||||
|
||||
public class ObjModel {
|
||||
public static final Map<Identifier, ObjModel> loadedObjModels = new HashMap<>();
|
||||
|
||||
public record Config(
|
||||
@JsonProperty("transform") Transform transform) {
|
||||
|
||||
@JsonFormat(shape = JsonFormat.Shape.ARRAY)
|
||||
public record Transform(double x, double y, double z) {
|
||||
}
|
||||
}
|
||||
|
||||
Obj obj;
|
||||
Config config;
|
||||
|
||||
public static ObjModel of(Identifier obj) {
|
||||
if (loadedObjModels.containsKey(obj))
|
||||
return loadedObjModels.get(obj);
|
||||
|
||||
ObjModel o = new ObjModel(obj);
|
||||
loadedObjModels.put(obj, o);
|
||||
return o;
|
||||
}
|
||||
|
||||
ObjModel(Identifier identifier) {
|
||||
Identifier obj = Identifier.of(identifier.getNamespace(), identifier.getPath() + ".obj");
|
||||
System.out.println(obj);
|
||||
// Identifier json = Identifier.of(identifier.getNamespace(), identifier.getPath() + ".json");
|
||||
|
||||
try {
|
||||
this.obj = ObjRenderer.loadObj(obj);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
Identifier.of(obj.toString());
|
||||
}
|
||||
|
||||
public void render(Map<String, Mtl> mtlMap, MatrixStack matrices, VertexConsumerProvider vertexConsumers, int light,
|
||||
int overlay) {
|
||||
ObjRenderer.renderObj(this.obj, mtlMap, matrices, vertexConsumers, light, overlay);
|
||||
}
|
||||
}
|
||||
@@ -15,7 +15,6 @@ import net.minecraft.client.util.math.MatrixStack;
|
||||
import net.minecraft.util.Identifier;
|
||||
|
||||
public class ObjRenderer {
|
||||
|
||||
public static Obj loadObj(Identifier objId) throws IOException {
|
||||
try (InputStream is = MinecraftClient.getInstance().getResourceManager()
|
||||
.getResource(objId).get().getInputStream()) {
|
||||
@@ -37,7 +36,6 @@ public class ObjRenderer {
|
||||
|
||||
public static void renderObj(Obj obj, Map<String, Mtl> mtlMap, MatrixStack matrices,
|
||||
VertexConsumerProvider vertexConsumers, int light, int overlay) {
|
||||
|
||||
MatrixStack.Entry entry = matrices.peek();
|
||||
|
||||
Map<String, Obj> materialGroups = ObjSplitting.splitByMaterialGroups(obj);
|
||||
|
||||
@@ -1,6 +0,0 @@
|
||||
{
|
||||
"model": {
|
||||
"type": "minecraft:model",
|
||||
"model": "saturnclient:item/halo/white"
|
||||
}
|
||||
}
|
||||
@@ -1,6 +0,0 @@
|
||||
{
|
||||
"model": {
|
||||
"type": "minecraft:model",
|
||||
"model": "saturnclient:item/halo/black"
|
||||
}
|
||||
}
|
||||
@@ -1,6 +0,0 @@
|
||||
{
|
||||
"model": {
|
||||
"type": "minecraft:model",
|
||||
"model": "saturnclient:item/horns/black"
|
||||
}
|
||||
}
|
||||
@@ -1,6 +0,0 @@
|
||||
{
|
||||
"model": {
|
||||
"type": "minecraft:model",
|
||||
"model": "saturnclient:item/horns/white"
|
||||
}
|
||||
}
|
||||
@@ -1,13 +0,0 @@
|
||||
{
|
||||
"parent": "special-model-loader:builtin/obj",
|
||||
"model": "saturnclient:models/item/halo/halo.obj",
|
||||
"mtl_override": "saturnclient:models/item/black.mtl",
|
||||
"flip_v": true,
|
||||
"display": {
|
||||
"thirdperson_righthand": {
|
||||
"rotation": [0, 0, 0],
|
||||
"translation": [1.5, 12, 1.5],
|
||||
"scale": [0.2, 0.2, 0.2]
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,13 +0,0 @@
|
||||
{
|
||||
"parent": "special-model-loader:builtin/obj",
|
||||
"model": "saturnclient:models/item/halo/halo.obj",
|
||||
"mtl_override": "saturnclient:models/item/white.mtl",
|
||||
"flip_v": true,
|
||||
"display": {
|
||||
"thirdperson_righthand": {
|
||||
"rotation": [0, 0, 0],
|
||||
"translation": [1.5, 12, 1.5],
|
||||
"scale": [0.2, 0.2, 0.2]
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,13 +0,0 @@
|
||||
{
|
||||
"parent": "special-model-loader:builtin/obj",
|
||||
"model": "saturnclient:models/item/horns/horns.obj",
|
||||
"mtl_override": "saturnclient:models/item/black.mtl",
|
||||
"flip_v": true,
|
||||
"display": {
|
||||
"thirdperson_righthand": {
|
||||
"rotation": [0, 0, 0],
|
||||
"translation": [2, 6, 2],
|
||||
"scale": [0.25, 0.25, 0.25]
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,13 +0,0 @@
|
||||
{
|
||||
"parent": "special-model-loader:builtin/obj",
|
||||
"model": "saturnclient:models/item/horns/horns.obj",
|
||||
"mtl_override": "saturnclient:models/item/white.mtl",
|
||||
"flip_v": true,
|
||||
"display": {
|
||||
"thirdperson_righthand": {
|
||||
"rotation": [0, 0, 0],
|
||||
"translation": [2, 6, 2],
|
||||
"scale": [0.25, 0.25, 0.25]
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user