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



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • I’m working on a Manta Ray entity in MCreator using GeckoLib animations, and my goal is to have a looping (flip) animation that ends at −360°, then transitions seamlessly into a swim animation starting at 0°. However, every method I’ve tried—like quickly interpolating the angle, inserting a brief keyframe at 0°, or using a micro “bridge” animation—still causes a visible “flash” https://imgur.com/a/5ucjUb9 or "jump" when the rotation resets. I want a perfectly smooth motion from the flip’s final rotation to the swim’s initial rotation. If anyone has solved this in MCreator/GeckoLib, or found a better trick for handling the −360° →0° gap without a snap, I’d appreciate some advice ! P.S.- I cannot set swim to start at -360 because I would have the same issue but in reverse. Here's the custom LoopingAnimationGoal :   class LoopingAnimationGoal extends Goal { private final MantaRayEntity entity; private final int cooldownTime; private int animationTimer; private int cooldownTimer; // New boolean to prevent double calls private boolean isLoopingActive = false; public LoopingAnimationGoal(MantaRayEntity entity, int cooldownTime) { this.entity = entity; this.cooldownTime = cooldownTime; this.animationTimer = 0; this.cooldownTimer = 0; this.setFlags(EnumSet.of(Flag.MOVE, Flag.LOOK)); } @Override public boolean canUse() { System.out.println("[DEBUG] LoopingGoal canUse => cooldownTimer=" + cooldownTimer); if (cooldownTimer > 0) { cooldownTimer--; return false; } BlockPos entityPos = entity.blockPosition(); boolean canUse = entity.isWaterAbove(entityPos, 4); System.out.println("[DEBUG] LoopingGoal canUse => WATER " + (canUse ? "DETECTED" : "NOT DETECTED") + " at " + entityPos + ", returning " + canUse); return canUse; } @Override public void start() { entity.setAnimation("looping"); animationTimer = 63; isLoopingActive = true; System.out.println("[DEBUG] Looping animation STARTED. Timer=" + animationTimer + ", gameTime=" + entity.level().getGameTime()); } @Override public boolean canContinueToUse() { System.out.println("[DEBUG] LoopingGoal canContinueToUse => animationTimer=" + animationTimer); return animationTimer > 0; } @Override public void tick() { animationTimer--; System.out.println("[DEBUG] LoopingGoal TICK => animationTimer=" + animationTimer); // We stop ONLY if we are still looping if (animationTimer <= 0 && isLoopingActive) { System.out.println("[DEBUG] condition => animationTimer <= 0 && isLoopingActive"); stop(); } } @Override public void stop() { // Check if already stopped if (!isLoopingActive) { System.out.println("[DEBUG] stop() called again, but isLoopingActive = false. Doing nothing."); return; } System.out.println("[DEBUG] Looping STOP at tick=" + entity.level().getGameTime() + ", last known rotation=" + entity.getXRot() + "/" + entity.getYRot() + ", animationTimer=" + animationTimer); // Immediately switch to "swim" entity.setAnimation("swim"); // Reset cooldown cooldownTimer = cooldownTime; // Disable looping to prevent a second stop isLoopingActive = false; System.out.println("[DEBUG] Looping STOP => setAnimation('swim'), cooldownTimer=" + cooldownTimer); } }  
    • So is the intention of the crusher for ores meant to be used with a silk touch pickaxe or something? Cause that seems like too much effort just to profit off of the machine, when everything drops as raw materials now. Am I just missing something? 
    • Update your AMD/ATI drivers - get the drivers from their website - do not update via system  
  • Topics

  • Who's Online (See full list)

×
×
  • Create New...

Important Information

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