Work on ModelBaker

This commit is contained in:
Nedelosk committed 2016-05-05 12:48:10 +02:00
1 parent 7bf554b024
commit 66d6a4d75e
10 files changed
+106 -55

No files matched your search

@@ -12,6 +12,7 @@ import net.minecraft.block.Block;
import net.minecraft.client.renderer.block.model.IBakedModel;
import net.minecraft.client.renderer.texture.TextureAtlasSprite;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.math.AxisAlignedBB;
import net.minecraft.util.math.BlockPos;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
@@ -22,15 +23,19 @@ import net.minecraftforge.fml.relauncher.SideOnly;
@SideOnly(Side.CLIENT)
public interface IModelBaker {
void setRenderBoundsFromBlock(@Nonnull Block block);
void setRenderBounds(@Nonnull AxisAlignedBB renderBounds);
void setRenderBounds(double d, double e, double f, double g, double h, double i );
void setRenderBounds(double d, double e, double f, double g, double h, double i);
void setColorIndex(int color);
void addBlockModel(@Nonnull Block block, @Nullable BlockPos pos, @Nonnull TextureAtlasSprite[] sprites, int colorIndex);
void addBlockModel(@Nonnull Block block, @Nonnull AxisAlignedBB renderBounds, @Nullable BlockPos pos, @Nonnull TextureAtlasSprite[] sprites, int colorIndex);
void addBlockModel(@Nonnull Block block, @Nullable BlockPos pos, @Nonnull TextureAtlasSprite sprites, int colorIndex);
void addBlockModel(@Nonnull Block block, @Nonnull AxisAlignedBB renderBounds, @Nullable BlockPos pos, @Nonnull TextureAtlasSprite sprites, int colorIndex);
void addModel(@Nonnull AxisAlignedBB renderBounds, @Nonnull TextureAtlasSprite[] textures, int colorIndex);
void addModel(@Nonnull AxisAlignedBB renderBounds, @Nonnull TextureAtlasSprite texture, int colorIndex);
void addBakedModel(@Nonnull IBakedModel model);
@@ -5,10 +5,14 @@
******************************************************************************/
package forestry.api.core;
import java.util.List;
import net.minecraft.client.renderer.block.model.BakedQuad;
import net.minecraft.client.renderer.block.model.IBakedModel;
import net.minecraft.client.renderer.block.model.SimpleBakedModel;
import net.minecraft.client.renderer.texture.TextureAtlasSprite;
import net.minecraft.client.renderer.vertex.VertexFormat;
import net.minecraft.util.EnumFacing;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
@@ -23,6 +27,8 @@ public interface IModelBakerModel extends IBakedModel {
// void setFormat(VertexFormat formate);
void addQuad(EnumFacing facing, BakedQuad quad);
void setRotation(float[] rotation);
void setTranslation(float[] translation);
@@ -92,13 +92,13 @@ public class ModelDecorativeLeaves extends ModelBlockOverlay<BlockDecorativeLeav
TextureAtlasSprite leaveSprite = leafSpriteProvider.getSprite(false, Proxies.render.fancyGraphicsEnabled());
// Render the plain leaf block.
baker.addBlockModel(block, null, leaveSprite, 0);
baker.addBlockModel(block, Block.FULL_BLOCK_AABB, null, leaveSprite, 0);
// Render overlay for fruit leaves.
TextureAtlasSprite fruitSprite = TextureManager.getInstance().getSprite(genome.getFruitProvider().getDecorativeSpriteIndex());
if (fruitSprite != null) {
baker.addBlockModel(block, null, fruitSprite, 1);
baker.addBlockModel(block, Block.FULL_BLOCK_AABB, null, fruitSprite, 1);
}
// Set the particle sprite
@@ -12,6 +12,7 @@ package forestry.arboriculture.models;
import javax.annotation.Nonnull;
import net.minecraft.block.Block;
import net.minecraft.client.renderer.texture.TextureAtlasSprite;
import net.minecraft.item.ItemStack;
import net.minecraft.util.math.BlockPos;
@@ -52,7 +53,7 @@ public class ModelLeaves extends ModelBlockOverlay<BlockForestryLeaves> {
return;
}
baker.addBlockModel(block, null, leavesIcon, 0);
baker.addBlockModel(block, Block.FULL_BLOCK_AABB, null, leavesIcon, 0);
// add fruit
if (!leaves.hasFruit()) {
@@ -63,7 +64,7 @@ public class ModelLeaves extends ModelBlockOverlay<BlockForestryLeaves> {
if (fruitTexture == null) {
return;
}
baker.addBlockModel(block, null, fruitTexture, 1);
baker.addBlockModel(block, Block.FULL_BLOCK_AABB, null, fruitTexture, 1);
}
@Override
@@ -76,13 +77,13 @@ public class ModelLeaves extends ModelBlockOverlay<BlockForestryLeaves> {
TextureAtlasSprite leaveSprite = tile.getLeaveSprite(Proxies.render.fancyGraphicsEnabled());
// Render the plain leaf block.
baker.addBlockModel(block, pos, leaveSprite, 0);
baker.addBlockModel(block, Block.FULL_BLOCK_AABB, pos, leaveSprite, 0);
// Render overlay for fruit leaves.
TextureAtlasSprite fruitSprite = tile.getFruitSprite();
if (fruitSprite != null) {
baker.addBlockModel(block, pos, fruitSprite, 1);
baker.addBlockModel(block, Block.FULL_BLOCK_AABB, pos, fruitSprite, 1);
}
// Set the particle sprite
@@ -63,7 +63,7 @@ public abstract class ModelBlockOverlay<B extends Block> implements IBakedModel
}
B bBlock = blockClass.cast(block);
baker.setRenderBoundsFromBlock(block);
baker.setRenderBounds(block.getBoundingBox(state, world, pos));
bakeWorldBlock(bBlock, world, pos, stateExtended, baker);
latestBlockModel = baker.bakeModel(false);
@@ -145,7 +145,7 @@ public abstract class ModelBlockOverlay<B extends Block> implements IBakedModel
}
B bBlock = blockClass.cast(block);
baker.setRenderBoundsFromBlock(block);
baker.setRenderBounds(block.getBoundingBox(block.getStateFromMeta(stack.getItemDamage()), world, null));
bakeInventoryBlock(bBlock, stack, baker);
return latestItemModel = baker.bakeModel(true);
@@ -58,13 +58,12 @@ public class ModelBaker implements IModelBaker {
protected final float[] defUVs = new float[] { 0, 0, 1, 1 };
@Override
public void setRenderBoundsFromBlock(@Nonnull Block block) {
if (block == null) {
public void setRenderBounds(@Nonnull AxisAlignedBB renderBounds) {
if (renderBounds == null) {
return;
}
//TODO: Fixme
renderBounds = Block.FULL_BLOCK_AABB;
this.renderBounds = renderBounds;
}
@Override
@@ -80,25 +79,49 @@ public class ModelBaker implements IModelBaker {
}
@Override
public void addBlockModel(@Nonnull Block block, @Nullable BlockPos pos, @Nonnull TextureAtlasSprite[] textures, int colorIndex) {
setRenderBoundsFromBlock(block);
public void addModel(AxisAlignedBB renderBounds, @Nonnull TextureAtlasSprite[] textures, int colorIndex) {
setRenderBounds(renderBounds);
setColorIndex(colorIndex);
World world = Proxies.common.getRenderWorld();
IBlockState blockState = world.getBlockState(pos);
for (EnumFacing facing : EnumFacing.VALUES) {
if (pos == null || block.shouldSideBeRendered(blockState, world, pos, facing)) {
addFace(facing, textures[facing.ordinal()]);
}
setRenderBounds(Block.FULL_BLOCK_AABB);
}
@Override
public void addModel(AxisAlignedBB renderBounds, @Nonnull TextureAtlasSprite texture, int colorIndex) {
addModel(renderBounds, new TextureAtlasSprite[]{ texture, texture, texture, texture, texture, texture }, colorIndex);
}
@Override
public void addBlockModel(@Nonnull Block block, AxisAlignedBB renderBounds, @Nullable BlockPos pos, @Nonnull TextureAtlasSprite[] textures, int colorIndex) {
setRenderBounds(renderBounds);
setColorIndex(colorIndex);
if(pos != null){
World world = Proxies.common.getRenderWorld();
IBlockState blockState = world.getBlockState(pos);
for (EnumFacing facing : EnumFacing.VALUES) {
if (block.shouldSideBeRendered(blockState, world, pos, facing)) {
addFace(facing, textures[facing.ordinal()]);
}
}
}else {
for (EnumFacing facing : EnumFacing.VALUES) {
addFace(facing, textures[facing.ordinal()]);
}
}
setRenderBounds(0, 0, 0, 1, 1, 1);
setRenderBounds(Block.FULL_BLOCK_AABB);
}
@Override
public void addBlockModel(@Nonnull Block block, @Nullable BlockPos pos, @Nonnull TextureAtlasSprite texture, int colorIndex) {
addBlockModel(block, pos, new TextureAtlasSprite[]{ texture , texture, texture, texture, texture, texture }, colorIndex);
public void addBlockModel(@Nonnull Block block, @Nonnull AxisAlignedBB renderBounds, @Nullable BlockPos pos, @Nonnull TextureAtlasSprite texture, int colorIndex) {
addBlockModel(block, renderBounds, pos, new TextureAtlasSprite[]{ texture, texture, texture, texture, texture, texture }, colorIndex);
}
@Override
@@ -178,7 +201,7 @@ public class ModelBaker implements IModelBaker {
return;
}
boolean isEdge;
/*boolean isEdge;
switch (facing) {
case WEST:
isEdge = renderBounds.minX < 0.0001;
@@ -200,12 +223,12 @@ public class ModelBaker implements IModelBaker {
break;
default:
return;
}
}*/
Vector3f to = new Vector3f((float) renderBounds.minX * 16.0f, (float) renderBounds.minY * 16.0f, (float) renderBounds.minZ * 16.0f);
Vector3f from = new Vector3f((float) renderBounds.maxX * 16.0f, (float) renderBounds.maxY * 16.0f, (float) renderBounds.maxZ * 16.0f);
faces.add(new ModelBakerFace(facing, isEdge, colorIndex, to, from, defUVs, sprite));
faces.add(new ModelBakerFace(facing/*, isEdge*/, colorIndex, to, from, defUVs, sprite));
}
@Override
@@ -218,7 +241,7 @@ public class ModelBaker implements IModelBaker {
//Add baked models to the current model.
for(IBakedModel bakedModel : bakedModels){
this.currentModel.addModelQuads(bakedModel);
currentModel.addModelQuads(bakedModel);
}
for (ModelBakerFace face : faces) {
@@ -229,13 +252,9 @@ public class ModelBaker implements IModelBaker {
final BlockPartFace bpf = new BlockPartFace(myFace, face.colorIndex, "", uv);
BakedQuad bf = faceBakery.makeBakedQuad(face.to, face.from, bpf, face.spite, myFace, mr, null, true, true);
// bf = new IColoredBakedQuad.ColoredBakedQuad(bf.getVertexData(), face.colorIndex, bf.getFace());
// if (face.isEdge) {
// this.currentModel.getFaceQuads(myFace).add(bf);
// } else {
// this.currentModel.getGeneralQuads().add(bf);
// }
//if (face.isEdge) {
currentModel.addQuad(myFace, bf);
}
return currentModel;
@@ -27,7 +27,7 @@ import org.lwjgl.util.vector.Vector3f;
public class ModelBakerFace {
@Nonnull
public final EnumFacing face;
public final boolean isEdge;
//public final boolean isEdge;
public final Vector3f to;
public final Vector3f from;
@@ -38,10 +38,10 @@ public class ModelBakerFace {
public final int colorIndex;
public ModelBakerFace(@Nonnull EnumFacing face, boolean isEdge, int colorIndex, Vector3f to, Vector3f from, float[] defUVs2, TextureAtlasSprite sprite) {
public ModelBakerFace(@Nonnull EnumFacing face/*, boolean isEdge*/, int colorIndex, Vector3f to, Vector3f from, float[] defUVs2, TextureAtlasSprite sprite) {
this.colorIndex = colorIndex;
this.face = face;
this.isEdge = isEdge;
//this.isEdge = isEdge;
this.to = to;
this.from = from;
this.uv = defUVs2;
@@ -12,7 +12,9 @@ package forestry.core.models.baker;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import net.minecraft.block.state.IBlockState;
import net.minecraft.client.renderer.block.model.BakedQuad;
@@ -36,19 +38,29 @@ public class ModelBakerModel implements IModelBakerModel {
private boolean isAmbientOcclusion;
private VertexFormat format;
private TextureAtlasSprite particleSprite;
private final Map<EnumFacing, List<BakedQuad>> faceQuads;
private final List<BakedQuad> generalQuads;
private float[] rotation = getDefaultRotation();
private float[] translation = getDefaultTranslation();
private float[] scale = getDefaultScale();
public ModelBakerModel() {
models = new ArrayList<>();
faceQuads = new HashMap<>();
generalQuads = new ArrayList<>();
format = DefaultVertexFormats.BLOCK;
isGui3d = true;
isAmbientOcclusion = false;
for(EnumFacing face : EnumFacing.VALUES){
faceQuads.put(face, new ArrayList());
}
}
private ModelBakerModel(List<IBakedModel> models, boolean isGui3d, boolean isAmbientOcclusion, VertexFormat format, float[] rotation, float[] translation, float[] scale, TextureAtlasSprite particleSprite) {
private ModelBakerModel(List<IBakedModel> models, Map<EnumFacing, List<BakedQuad>> faceQuads, List<BakedQuad> generalQuads, boolean isGui3d, boolean isAmbientOcclusion, VertexFormat format, float[] rotation, float[] translation, float[] scale, TextureAtlasSprite particleSprite) {
this.models = models;
this.faceQuads = faceQuads;
this.generalQuads = generalQuads;
this.isGui3d = isGui3d;
this.isAmbientOcclusion = isAmbientOcclusion;
this.format = format;
@@ -148,23 +160,30 @@ public class ModelBakerModel implements IModelBakerModel {
public void addModelQuads(IBakedModel model) {
this.models.add(model);
}
@Override
public void addQuad(EnumFacing facing, BakedQuad quad) {
if(facing != null){
faceQuads.get(facing).add(quad);
}else{
generalQuads.add(quad);
}
}
@Override
public List<BakedQuad> getQuads(IBlockState state, EnumFacing side, long rand) {
List<BakedQuad> quads = new ArrayList<>();
if (side == null) {
for (IBakedModel model : this.models) {
quads.addAll(model.getQuads(state, null, rand));
}
} else {
for (IBakedModel model : this.models) {
quads.addAll(model.getQuads(state, side, rand));
}
for (IBakedModel model : this.models) {
quads.addAll(model.getQuads(state, side, rand));
}
if(side != null){
quads.addAll(faceQuads.get(side));
}
quads.addAll(generalQuads);
return quads;
}
public ModelBakerModel copy() {
return new ModelBakerModel(models, isGui3d, isAmbientOcclusion, format, rotation, translation, scale, particleSprite);
return new ModelBakerModel(models, faceQuads, generalQuads, isGui3d, isAmbientOcclusion, format, rotation, translation, scale, particleSprite);
}
}
@@ -2,6 +2,7 @@ package forestry.farming.models;
import javax.annotation.Nonnull;
import net.minecraft.block.Block;
import net.minecraft.client.renderer.texture.TextureAtlasSprite;
import net.minecraft.item.ItemStack;
import net.minecraft.util.math.BlockPos;
@@ -30,9 +31,9 @@ public class ModelFarmBlock extends ModelBlockOverlay<BlockFarm> {
EnumFarmBlockTexture type = EnumFarmBlockTexture.getFromCompound(item.getTagCompound());
// Add the plain block.
baker.addBlockModel(blockFarm, null, getSprites(type), 0);
baker.addBlockModel(blockFarm, Block.FULL_BLOCK_AABB, null, getSprites(type), 0);
// Add the overlay block.
baker.addBlockModel(blockFarm, null, getOverlaySprites(EnumFarmBlockType.VALUES[item.getItemDamage()]), 0);
baker.addBlockModel(blockFarm, Block.FULL_BLOCK_AABB, null, getOverlaySprites(EnumFarmBlockType.VALUES[item.getItemDamage()]), 0);
}
@Override
@@ -43,9 +44,9 @@ public class ModelFarmBlock extends ModelBlockOverlay<BlockFarm> {
TextureAtlasSprite[] textures = getSprites(farm.getFarmBlockTexture());
// Add the plain block.
baker.addBlockModel(blockFarm, pos, textures, 0);
baker.addBlockModel(blockFarm, Block.FULL_BLOCK_AABB, pos, textures, 0);
// Add the overlay block.
baker.addBlockModel(blockFarm, pos, getOverlaySprites(farm.getFarmBlockType()), 0);
baker.addBlockModel(blockFarm, Block.FULL_BLOCK_AABB, pos, getOverlaySprites(farm.getFarmBlockType()), 0);
// Set the particle sprite
baker.setParticleSprite(textures[0]);
@@ -60,12 +60,12 @@ public class ModelGreenhouse extends ModelBlockOverlay<BlockGreenhouse> {
else if (block.getGreenhouseType() == BlockGreenhouseType.GLASS) {
TextureAtlasSprite glassSprite = BlockGreenhouseType.getSprite(BlockGreenhouseType.GLASS, null, null, world, pos);
baker.addBlockModel(block, pos, BlockGreenhouseType.getSprite(BlockGreenhouseType.GLASS, null, null, world, pos), 100);
baker.addBlockModel(block, Block.FULL_BLOCK_AABB, pos, BlockGreenhouseType.getSprite(BlockGreenhouseType.GLASS, null, null, world, pos), 100);
baker.setParticleSprite(glassSprite);
} else {
TextureAtlasSprite plainSprite = BlockGreenhouseType.getSprite(BlockGreenhouseType.PLAIN, null, null, world, pos);
baker.addBlockModel(block, pos, BlockGreenhouseType.getSprite(BlockGreenhouseType.PLAIN, null, null, world, pos), 100);
baker.addBlockModel(block, Block.FULL_BLOCK_AABB, pos, BlockGreenhouseType.getSprite(BlockGreenhouseType.PLAIN, null, null, world, pos), 100);
baker.setParticleSprite(plainSprite);
}
@@ -74,7 +74,7 @@ public class ModelGreenhouse extends ModelBlockOverlay<BlockGreenhouse> {
for (EnumFacing facing : EnumFacing.VALUES) {
sprite[facing.ordinal()] = BlockGreenhouseType.getSprite(block.getGreenhouseType(), facing, stateExtended, world, pos);
}
baker.addBlockModel(block, pos, sprite, 101);
baker.addBlockModel(block, Block.FULL_BLOCK_AABB, pos, sprite, 101);
}
}