Jump to content
Search In
  • More options...
Find results that contain...
Find results in...

Rendering custom obj model


Recommended Posts

Posted (edited)

I have a block with a tile entity, which has a regular cube model. I want to render a custom obj model on top of it with the specific rotation, so it can't be static. I managed to load and bake the model with my ModelLoader but I don't know how to render it, i.e. what to put in the TileEntityRenderer#render method.

Edited by BudRunBun
Link to post
Share on other sites
Posted (edited)

I don't know if it's possible to draw a quarter of a sphere via json models. I think you can only make a model out of cuboids.

Edited by BudRunBun
Link to post
Share on other sites
Posted (edited)

I tried BlockModelRenderer#renderMode(looked how PistonTileEntity does it) and that's what I got:png.png

I have several problems with it:

  • It renders only from specific angle: if I move a little bit or look somewhere else it disappears
  • It can be seen through blocks
  • I don't know how to scale it properly(I tried GlStateManagel#scalef but it didn't do anything)
  • It's very dark and has some problems with lightning
Edited by BudRunBun
Link to post
Share on other sites

This is my code:

package com.budrunbun.lavalamp.renderer;

import com.budrunbun.lavalamp.tileentity.TurretTileEntity;
import com.mojang.blaze3d.platform.GlStateManager;
import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.*;
import net.minecraft.client.renderer.model.IBakedModel;
import net.minecraft.client.renderer.model.ModelResourceLocation;
import net.minecraft.client.renderer.tileentity.TileEntityRenderer;
import net.minecraft.client.renderer.vertex.DefaultVertexFormats;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
import net.minecraftforge.client.model.ModelDataManager;
import net.minecraftforge.client.model.data.IModelData;

import javax.annotation.Nonnull;
import java.util.Random;

public class TurretRenderer extends TileEntityRenderer<TurretTileEntity> {
    private static final BlockRendererDispatcher blockRenderer = Minecraft.getInstance().getBlockRendererDispatcher();
    private IBakedModel sphereQuarter;

    @Override
    public void render(@Nonnull TurretTileEntity turret, double x, double y, double z, float partialTicks, int destroyStage) {
        Tessellator tessellator = Tessellator.getInstance();
        BufferBuilder buffer = tessellator.getBuffer();
        BlockPos pos = turret.getPos();
        World world = this.getWorld();

        RenderHelper.disableStandardItemLighting();
        GlStateManager.blendFunc(GlStateManager.SourceFactor.SRC_ALPHA, GlStateManager.DestFactor.ONE_MINUS_SRC_ALPHA);
        GlStateManager.enableBlend();
        GlStateManager.disableCull();
        if (Minecraft.isAmbientOcclusionEnabled())
            GlStateManager.shadeModel(7425);
        else
            GlStateManager.shadeModel(7424);

        BlockModelRenderer.enableCache();

        buffer.begin(7, DefaultVertexFormats.BLOCK);
        buffer.setTranslation(x - pos.getX(), y - pos.getY(), z - pos.getZ());

        if (sphereQuarter == null)
            sphereQuarter = Minecraft.getInstance().getModelManager().getModel(new ModelResourceLocation("lavalamp:sphere_quarter", ""));
        IModelData data = ModelDataManager.getModelData(world, pos);

        blockRenderer.getBlockModelRenderer().renderModel(
                world,
                this.sphereQuarter,
                turret.getBlockState(),
                turret.getPos(),
                buffer,
                false,
                new Random(),
                42,
                data
        );

        buffer.setTranslation(0.0D, 0.0D, 0.0D);
        tessellator.draw();

        BlockModelRenderer.disableCache();
        RenderHelper.enableStandardItemLighting();
    }
}

 

Link to post
Share on other sites
Posted (edited)
1 hour ago, BudRunBun said:

I don't know if it's possible to draw a quarter of a sphere via json models. I think you can only make a model out of cuboids.

Forge has custom model loader support through jsons. For example, there is a model loader for .obj models that takes in the location of the obj model and its material. The omnibus PR has more information on this.

 

As for the actual code, you shouldn't have any reason to refer to RenderSystem at all in a TER. The batch rendering system used by #renderModel should be perfectly capable of handling the shading and culling of your model.

Edited by ChampionAsh5357
Link to post
Share on other sites

Okay, I got rid of unnecessary calls to RenderSystem but how do I fix that strange behaviour? I have no idea how to even scale the model via buffer and I can't find any examples.

Link to post
Share on other sites
56 minutes ago, BudRunBun said:

Okay, I got rid of unnecessary calls to RenderSystem but how do I fix that strange behaviour? I have no idea how to even scale the model via buffer and I can't find any examples.

That's the point of the MatrixStack. It's a projection matrix transformation for how to draw the element to the screen. So, you can just call #scale on it to scale the entries drawn in this particular case.

Link to post
Share on other sites
Posted (edited)

I've dealt with the matrix stack before with the ItemRenderer and there glScalef worked fine but here it just ignores it. I think that I might be transforming not the matrix that BlockModelRenderer uses. Where should I get the right one?

Edited by BudRunBun
Link to post
Share on other sites

I just realized you are using a non-supported version of Forge based on the parameters of the render method as they are pre-1.15. The only versions supported are those in the blue banner at the top of the screen. Please update to one of the above versions to receive more support.

Link to post
Share on other sites
Guest
This topic is now closed to further replies.


  • Recently Browsing

    No registered users viewing this page.

  • Posts

    • when ever i click play in the minecraft launcher and have it set to 1.17.1 the launcher crashes and gives me a code: 0 error
    • Hello it says like in provided picture and installer log that it cant find the installer tho it is there?! https://pastebin.com/jUN8MV8E   <--- for installer.log https://imgur.com/iZhfLgg             <--- for image
    • Just downloaded MDK for 1.17.1, set up my project in IntelliJ IDEA Community 2021.1.3, but there's an error "Exception in thread "main" java.lang.module.ResolutionException: Module jline.terminal reads more than one module named cpw.mods.securejarhandler". Java version is 16.0.2. If I'll try to change it, there'll be new module instead of "jline.terminal". Here's the full log: Exception in thread "main" java.lang.module.ResolutionException: Module jline.terminal reads more than one module named cpw.mods.securejarhandler at java.base/java.lang.module.Resolver.resolveFail(Resolver.java:908) at java.base/java.lang.module.Resolver.checkExportSuppliers(Resolver.java:729) at java.base/java.lang.module.Resolver.finish(Resolver.java:379) at java.base/java.lang.module.Configuration.<init>(Configuration.java:140) at java.base/java.lang.module.Configuration.resolveAndBind(Configuration.java:494) at java.base/java.lang.module.Configuration.resolveAndBind(Configuration.java:298) at cpw.mods.bootstraplauncher@0.1.15/cpw.mods.bootstraplauncher.BootstrapLauncher.main(BootstrapLauncher.java:77) Process finished with exit code 1 Any ideas to fix it?
    • I'm trying to create a command that Changes the nbt data of the currently held item. Ive gotten to the point where everything works except for this line. EntityPlayer player= sender.getDisplayName(); @Override public void processCommand(ICommandSender sender, String[] args) { String output = String.join(" ", args); if(args.length == 0) { throw new CommandException("no name defined"); } else { EntityPlayer player= sender.getDisplayName(); ItemStack stack = player.getHeldItem(); addInformation(stack, player, output); } } public void addInformation(ItemStack istack, EntityPlayer player, String itemname) { NBTTagCompound tag = istack.stackTagCompound; if (tag == null) { tag = new NBTTagCompound(); tag.setTag("display", new NBTTagCompound()); istack.stackTagCompound = tag; } tag.getTag("display"); tag.setTag("display", new NBTTagCompound()); NBTTagCompound tagname = tag.getCompoundTag("display"); NBTTagList name = new NBTTagList(); name.appendTag(new NBTTagString("§b"+itemname)); tagname.setTag("Name", name); }  
    • How?? I don't know the method that can change time.
  • Topics

  • Who's Online (See full list)

×
×
  • Create New...

Important Information

By using this site, you agree to our Privacy Policy.