Jump to content

[1.12.2](Solved)Attempting to Render OBJ in TESR crashes with file not found exception


Codasylph

Recommended Posts

I have TESR that I need to render an obj with, (there will be animation and the obj in question is not always rendered in every circumstance, so yes, it really does need to be a tesr). Unfortunately, when it tries to load the model it crashes with this error: java.lang.RuntimeException: java.io.FileNotFoundException: demesne:models/item/retort_liquid. I don't really understand why it would event be looking for an item model, but I added the model to models/item as well as models/block and I still get the exact same error.  For reference this is my TESR code:

Spoiler

public class CauldronTESR extends TileEntitySpecialRenderer<CauldronTile>
{
	private IModel modelRetort;
	private IBakedModel bakedModelRetort;
	
    private IBakedModel getBakedModel() {
   	 
        if (bakedModelRetort == null) {
            try {
            	modelRetort = OBJLoader.INSTANCE.loadModel(new ResourceLocation(DemConstants.MODID, "models/block/retort_liquid"));
            } catch (Exception e) {
                throw new RuntimeException(e);
            }
            bakedModelRetort = modelRetort.bake(TRSRTransformation.identity(), DefaultVertexFormats.BLOCK,
                    location -> Minecraft.getMinecraft().getTextureMapBlocks().getAtlasSprite(location.toString()));
        }
        return bakedModelRetort;
    }
	
    @Override
    public void render(CauldronTile te, double x, double y, double z, float partialTicks, int destroyStage, float alpha)
    {
        GlStateManager.pushAttrib();
        GlStateManager.pushMatrix();

        GlStateManager.translate(x, y, z);
        GlStateManager.disableRescaleNormal();
        if(!te.getStackInSlot(0).isEmpty())
        {
        	Color color = new Color(ReagentItem.getColorFromStack(te.getStackInSlot(0)));
        	renderReagent(te, color.getRed() / 255.0F, color.getGreen() / 255.0F, color.getBlue() / 255.0F);
        }
      
    	renderItemFlat(te, 0, 0.25F, 0.625F, 0.25F);
    	renderItem(te, 1, 0.775F, 0.7F, 0.775F);
    	renderItem(te, 2, 0.6F, 0.7F, 0.85F);
    	renderItem(te, 3, 0.425F, 0.7F, 0.85F);
    	renderItem(te, 4, 0.25F, 0.7F, 0.775F);
        	
        GlStateManager.popMatrix();
        GlStateManager.popAttrib();
    }
    
    private void renderReagent(CauldronTile te, float red, float green, float blue)
    {
		GlStateManager.pushMatrix();
		GlStateManager.enableBlend();
		
		Tessellator tessellator = Tessellator.getInstance();
        tessellator.getBuffer().begin(GL11.GL_QUADS, DefaultVertexFormats.BLOCK);
        Minecraft.getMinecraft().getBlockRendererDispatcher().getBlockModelRenderer().renderModel(
                getWorld(),
                getBakedModel(),
                getWorld().getBlockState(te.getPos()),
                te.getPos(),
                Tessellator.getInstance().getBuffer(), false);
        tessellator.draw();
		
		GlStateManager.disableBlend();
		GlStateManager.popMatrix();
    }
    
    private void renderItem(CauldronTile te, int slot, float x, float y, float z)
    {
        ItemStack stack = te.getStackInSlot(slot);
        if (!stack.isEmpty())
        {
            RenderHelper.enableStandardItemLighting();
            GlStateManager.enableLighting();
            GlStateManager.pushMatrix();
            GlStateManager.translate(x, y, z);
            GlStateManager.scale(.2f, .2f, .2f);

            Minecraft.getMinecraft().getRenderItem().renderItem(stack, ItemCameraTransforms.TransformType.NONE);

            GlStateManager.popMatrix();
        }
    }
    
    private void renderItemFlat(CauldronTile te, int slot, float x, float y, float z)
    {
        ItemStack stack = te.getStackInSlot(slot);
        if (!stack.isEmpty() && !(stack.getItem() == DemItems.reagentItem && slot == 0))
        {
            RenderHelper.enableStandardItemLighting();
            GlStateManager.enableLighting();
            GlStateManager.pushMatrix();
            GlStateManager.translate(x, y, z);
            GlStateManager.scale(.25f, .25f, .25f);
            GlStateManager.rotate(90.0f, 1.0f, 0, 0);
            GlStateManager.rotate(180.0f, 0, 0, 1.0f);

            Minecraft.getMinecraft().getRenderItem().renderItem(stack, ItemCameraTransforms.TransformType.NONE);

            GlStateManager.popMatrix();
        }
    }
}

 

 

and the crash report can be found here:

https://pastebin.com/jpgxfm6m

 

 

Edited by Codasylph
Link to comment
Share on other sites

hey actually simple

you need to add .obj to the location string

if (bakedModelRetort == null) {
            try {
            	modelRetort = OBJLoader.INSTANCE.loadModel(new ResourceLocation(DemConstants.MODID, "models/block/retort_liquid.obj"));
            } catch (Exception e) {
                throw new RuntimeException(e);
            }
            bakedModelRetort = modelRetort.bake(TRSRTransformation.identity(), DefaultVertexFormats.BLOCK,
                    location -> Minecraft.getMinecraft().getTextureMapBlocks().getAtlasSprite(location.toString()));
        }

 

Edited by sir_titi

Always looking for new challenges, and happy to help the people where ever I can

Link to comment
Share on other sites

Ok, one more little thing.  I don't crash anymore, and it renders the obj properly. But it renders very very dark, almost black.  I can tell its actually rendering the texture, just super dark. I've tried using the RenderHelper#enableStandardItemLighting and a few other lighting things within GlStateManager but nothing seems to make the slightest difference.  I saw one other post with a similar issue here, but it had no replies. :(

 

For reference here is my updated code just for rendering the obj (since I wasn't actually binding a texture or anything in the previously posted code):

    private void renderReagent(CauldronTile te, float red, float green, float blue)
    {
		GlStateManager.pushMatrix();

        bindTexture(TextureMap.LOCATION_BLOCKS_TEXTURE);
//		GlStateManager.enableBlend();
 //       GlStateManager.blendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
//        GlStateManager.color(red, green, blue, .2f);
        GlStateManager.enableLight(1);
        GlStateManager.translate(-te.getPos().getX(), -te.getPos().getY()+1.0F, -te.getPos().getZ()+1.0F);
		
		Tessellator tessellator = Tessellator.getInstance();
        tessellator.getBuffer().begin(GL11.GL_QUADS, DefaultVertexFormats.BLOCK);
        Minecraft.getMinecraft().getBlockRendererDispatcher().getBlockModelRenderer().renderModel(
                getWorld(),
                getBakedModel(),
                getWorld().getBlockState(te.getPos()),
                te.getPos(),
                Tessellator.getInstance().getBuffer(), true);
        
        tessellator.draw();
		
//		GlStateManager.disableBlend();
        GlStateManager.translate(te.getPos().getX(), te.getPos().getY(), te.getPos().getZ());
		GlStateManager.popMatrix();
    }

 

Link to comment
Share on other sites

well for starters i use this

bufferBuilder.begin(GL11.GL_QUADS,Attributes.DEFAULT_BAKED_FORMAT);

and not

bufferBuilder.begin(GL11.GL_QUADS, DefaultVertexFormats.BLOCK);

not that i am saying that it could not work, but you are using bakedModels

 

private void renderReagent(CauldronTile te, float red, float green, float blue){
	GlStateManager.pushMatrix();
  	/*maybe this could help for the dark model \/\/*/
  	GL11.glDisable(GL11.GL_LIGHTING);
  
        bindTexture(TextureMap.LOCATION_BLOCKS_TEXTURE);
//	GlStateManager.enableBlend();
//      GlStateManager.blendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
//      GlStateManager.color(red, green, blue, .2f);
        GlStateManager.translate(-te.getPos().getX(), -te.getPos().getY()+1.0F, -te.getPos().getZ()+1.0F);
		
	Tessellator tessellator = Tessellator.getInstance();
  	BufferBuilder bufferbuilder = tessellator.getBuffer();
        bufferbuilder.begin(GL11.GL_QUADS, Attributes.DEFAULT_BAKED_FORMAT);//I prefer this since you are using bakedModels
        Minecraft.getMinecraft().getBlockRendererDispatcher().getBlockModelRenderer().renderModel(getWorld(),getBakedModel(), getWorld().getBlockState(te.getPos()),te.getPos(),bufferbuilder, true);
        
        tessellator.draw();
//	GlStateManager.disableBlend();
        GlStateManager.translate(te.getPos().getX(), te.getPos().getY(), te.getPos().getZ());
	GlStateManager.popMatrix();
  	/*maybe this could help for the dark model \/\/*/
  	GL11.glEnable(GL11.GL_LIGHTING);
    }

 And why are you translating back when done rendering? xs

Edited by sir_titi

Always looking for new challenges, and happy to help the people where ever I can

Link to comment
Share on other sites

well yes that is true for openGL stuff, but that is to what i know, if you pop the let's say the matrix everything in that matrix will be canceled.

But i may be wrong about that :P. Anyways glad to be able to help ;)

And for the translating back that could be useful if you have some other parts that need to be rendered. but yea if it works for you sure go ahead :P.

And to be honest i don't use the 

Minecraft.getMinecraft().getBlockRendererDispatcher().getBlockModelRenderer().renderModel

I made my own method's to render the models

 

Greets Sir_titi

Edited by sir_titi

Always looking for new challenges, and happy to help the people where ever I can

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Announcements



×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.