Jump to content

Recommended Posts

Posted

I am using an IBakedModel to render an OBJ(it's meant to be animated but that's a struggle for tomorrow), but in  game it renders black, when the texture is bright blue and white.

package keegan.labstuff.render;

import org.lwjgl.opengl.GL11;

import keegan.labstuff.tileentity.TileEntitySolenoidAxel;
import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.*;
import net.minecraft.client.renderer.block.model.*;
import net.minecraft.client.renderer.texture.TextureMap;
import net.minecraft.client.renderer.tileentity.TileEntitySpecialRenderer;
import net.minecraft.client.renderer.vertex.DefaultVertexFormats;
import net.minecraft.item.ItemStack;
import net.minecraft.util.ResourceLocation;
import net.minecraft.world.World;
import net.minecraftforge.client.model.*;
import net.minecraftforge.client.model.obj.OBJLoader;
import net.minecraftforge.common.model.TRSRTransformation;
import net.minecraftforge.fml.relauncher.*;

@SideOnly(Side.CLIENT)
public class RenderSolenoid extends TileEntitySpecialRenderer<TileEntitySolenoidAxel> {

    private IModel model;
    private IBakedModel bakedModel;

    private IBakedModel getBakedModel() {
        // Since we cannot bake in preInit() we do lazy baking of the model as soon as we need it
        // for rendering
        if (bakedModel == null) {
            try {
                model = OBJLoader.INSTANCE.loadModel(new ResourceLocation("labstuff", "models/block/solenoid.obj"));
            } catch (Exception e) {
                throw new RuntimeException(e);
            }
            bakedModel = model.bake(TRSRTransformation.identity(), DefaultVertexFormats.BLOCK,
                    location -> Minecraft.getMinecraft().getTextureMapBlocks().getAtlasSprite(location.toString()));
        }
        return bakedModel;
    }

    @Override
    public void renderTileEntityAt(TileEntitySolenoidAxel te, double x, double y, double z, float partialTicks, int destroyStage) {
        GlStateManager.pushAttrib();
        GlStateManager.pushMatrix();

        // Translate to the location of our tile entity
        GlStateManager.translate(x, y, z);
        GlStateManager.disableRescaleNormal();

        // Render the rotating handles
        if(te.isMultiBlock())
        	renderHandles(te);


        GlStateManager.popMatrix();
        GlStateManager.popAttrib();

    }

    private void renderHandles(TileEntitySolenoidAxel te) {
        GlStateManager.pushMatrix();

        GlStateManager.translate(.5, 0, .5);
        long angle = (long)te.angle;
        GlStateManager.rotate(angle, 0, 1, 0);

        RenderHelper.disableStandardItemLighting();
        this.bindTexture(new ResourceLocation("labstuff:textures/models/solenoid.png"));
        if (Minecraft.isAmbientOcclusionEnabled()) {
            GlStateManager.shadeModel(GL11.GL_SMOOTH);
        } else {
            GlStateManager.shadeModel(GL11.GL_FLAT);
        }

        World world = te.getWorld();
        // Translate back to local view coordinates so that we can do the acual rendering here
        GlStateManager.translate(-te.getPos().getX(), -te.getPos().getY(), -te.getPos().getZ());

        Tessellator tessellator = Tessellator.getInstance();
        tessellator.getBuffer().begin(GL11.GL_QUADS, DefaultVertexFormats.BLOCK);
        Minecraft.getMinecraft().getBlockRendererDispatcher().getBlockModelRenderer().renderModel(
                world,
                getBakedModel(),
                world.getBlockState(te.getPos()),
                te.getPos(),
                Tessellator.getInstance().getBuffer(),
                true);
        tessellator.draw();

        RenderHelper.enableStandardItemLighting();
        GlStateManager.popMatrix();
    }


}

 

HPFjl7f.png

[shadow=gray,left][glow=red,2,300]KEEGAN[/glow][/shadow]

Posted

I remember reading that obj need to have proper normal /texture mapping .

Disclaimer:  I been told to keep my opinions to myself, to shut up and that I am spreading lies and misinformation or even that my methods are unorthodox and or too irregular. Here are my suggestions take it or leave it.

Posted

Try flipping the normal's your model in the modeling package you are using. If it was an OpenGL texture issue then the model would be either white with a gradient from the normals or it would have another textured being displayed on the mesh because glBindTexture(GL_TEXTURE_2D, ...) wasn't passed zero to unbind the texture.

Posted

I re exported with normals, no change. Unless you meant something else?

 

I was thinking of uv texture mapping . When you add a texture to a 3d model and you kinda pick and choose where it goes. All objs used with MC need to have proper uv mapping done. Then when you place a texture on them they will texture themselves the same way you picked. If you never done the uv map is likely the object will look black.  Maybe

Disclaimer:  I been told to keep my opinions to myself, to shut up and that I am spreading lies and misinformation or even that my methods are unorthodox and or too irregular. Here are my suggestions take it or leave it.

Posted

I re exported with normals, no change. Unless you meant something else?

 

I was thinking of uv texture mapping . When you add a texture to a 3d model and you kinda pick and choose where it goes. All objs used with MC need to have proper uv mapping done. Then when you place a texture on them they will texture themselves the same way you picked. If you never done the uv map is likely the object will look black.  Maybe

 

UV map is in place in the above picture.

[shadow=gray,left][glow=red,2,300]KEEGAN[/glow][/shadow]

Posted

Try flipping the normal's your model in the modeling package you are using. If it was an OpenGL texture issue then the model would be either white with a gradient from the normals or it would have another textured being displayed on the mesh because glBindTexture(GL_TEXTURE_2D, ...) wasn't passed zero to unbind the texture.

 

No dice, still black

[shadow=gray,left][glow=red,2,300]KEEGAN[/glow][/shadow]

Posted

Not sure at all that this will work, but I did see a public method in the

BlockModelRenderer

yesterday called

renderModelBrightness

. What happens if you call this instead of using the tessellator? (renderModelBrightness does a few jumps, and at last lands on renderModelBrightnessColorQuads which seems to draw the model for you (remember to translate the model to where you want it before doing this!))

The call would thus be

Minecraft.getMinecraft().getBlockRendererDispatcher().getBlockModelRenderer().renderModelBrightness

Pass

true

for the last boolean btw. If false, it seems to color... the model with the value of the passed brightness...

 

I'm not stating that this will work. I'm working on the tangent that your model has no brightness = renders completely dark. If that's incorrect, well then, then we know that is not the case.

Also previously known as eAndPi.

"Pi, is there a station coming up where we can board your train of thought?" -Kronnn

Published Mods: Underworld

Handy links: Vic_'s Forge events Own WIP Tutorials.

Posted

We get an error now!

Caused by: java.lang.IllegalStateException: Already building!
at net.minecraft.client.renderer.VertexBuffer.begin(VertexBuffer.java:188) ~[VertexBuffer.class:?]
at net.minecraft.client.renderer.BlockModelRenderer.renderModelBrightnessColorQuads(BlockModelRenderer.java:373) ~[blockModelRenderer.class:?]
at net.minecraft.client.renderer.BlockModelRenderer.renderModelBrightnessColor(BlockModelRenderer.java:338) ~[blockModelRenderer.class:?]
at net.minecraft.client.renderer.BlockModelRenderer.renderModelBrightness(BlockModelRenderer.java:361) ~[blockModelRenderer.class:?]
at keegan.labstuff.render.RenderSolenoid.renderHandles(RenderSolenoid.java:86) ~[RenderSolenoid.class:?]
at keegan.labstuff.render.RenderSolenoid.renderTileEntityAt(RenderSolenoid.java:52) ~[RenderSolenoid.class:?]
at keegan.labstuff.render.RenderSolenoid.renderTileEntityAt(RenderSolenoid.java:1) ~[RenderSolenoid.class:?]
at net.minecraft.client.renderer.tileentity.TileEntityRendererDispatcher.renderTileEntityAt(TileEntityRendererDispatcher.java:153) ~[TileEntityRendererDispatcher.class:?]
... 20 more

[shadow=gray,left][glow=red,2,300]KEEGAN[/glow][/shadow]

Posted

We get an error now!

Caused by: java.lang.IllegalStateException: Already building!
at net.minecraft.client.renderer.VertexBuffer.begin(VertexBuffer.java:188) ~[VertexBuffer.class:?]
at net.minecraft.client.renderer.BlockModelRenderer.renderModelBrightnessColorQuads(BlockModelRenderer.java:373) ~[blockModelRenderer.class:?]
at net.minecraft.client.renderer.BlockModelRenderer.renderModelBrightnessColor(BlockModelRenderer.java:338) ~[blockModelRenderer.class:?]
at net.minecraft.client.renderer.BlockModelRenderer.renderModelBrightness(BlockModelRenderer.java:361) ~[blockModelRenderer.class:?]
at keegan.labstuff.render.RenderSolenoid.renderHandles(RenderSolenoid.java:86) ~[RenderSolenoid.class:?]
at keegan.labstuff.render.RenderSolenoid.renderTileEntityAt(RenderSolenoid.java:52) ~[RenderSolenoid.class:?]
at keegan.labstuff.render.RenderSolenoid.renderTileEntityAt(RenderSolenoid.java:1) ~[RenderSolenoid.class:?]
at net.minecraft.client.renderer.tileentity.TileEntityRendererDispatcher.renderTileEntityAt(TileEntityRendererDispatcher.java:153) ~[TileEntityRendererDispatcher.class:?]
... 20 more

That one is obvious, since BlockModelRenderer#renderModelBrightness will call VertexBuffer#begin() in its own, you shouldn't call the begin method yourself. Same will apply for Tessellator#draw().

It seems that there's problem with lighting texture settings while in the TESR.

I. Stellarium for Minecraft: Configurable Universe for Minecraft! (WIP)

II. Stellar Sky, Better Star Rendering&Sky Utility mod, had separated from Stellarium.

Posted

Well now it's invisible

GlStateManager.enableLighting();
        GlStateManager.pushMatrix();

        GlStateManager.translate(.5, 0, .5);
        long angle = (long)te.angle;
        GlStateManager.rotate(angle, 0, 1, 0);

        //RenderHelper.disableStandardItemLighting();
        this.bindTexture(new ResourceLocation("labstuff:textures/models/solenoid.png"));
        int bright = 0xF0;
        int brightX = bright % 65536;
        int brightY = bright / 65536;
        OpenGlHelper.setLightmapTextureCoords(OpenGlHelper.lightmapTexUnit, brightX, brightY);
        if (Minecraft.isAmbientOcclusionEnabled()) {
            GlStateManager.shadeModel(GL11.GL_SMOOTH);
        } else {
            GlStateManager.shadeModel(GL11.GL_FLAT);
        }

        World world = te.getWorld();
        // Translate back to local view coordinates so that we can do the acual rendering here
        GlStateManager.translate(-te.getPos().getX(), -te.getPos().getY(), -te.getPos().getZ());

        Tessellator tessellator = Tessellator.getInstance();
        Minecraft.getMinecraft().getBlockRendererDispatcher().getBlockModelRenderer().renderModelBrightness(getBakedModel(), world.getBlockState(te.getPos()), bright, true);

        //RenderHelper.enableStandardItemLighting();
        GlStateManager.popMatrix();

[shadow=gray,left][glow=red,2,300]KEEGAN[/glow][/shadow]

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.