Jump to content

Recommended Posts

Posted

I use Blender to create my OBJ models, and most are then rendered through a TESR(for animation purposes like spinning and stuff)

However, Forge doesn't "scale" or "proportion-ize" the UV coordinates up to the size of the texture file, and treats them as coordinates in the texture.

Blender(as far as I know) exports  "proportional" or "percentage" UV coordinates in relation to the size of the texture between 0 and 1. Is there a way to force or trick forge into treating these as percentages of the texture size, or having blender export as such, or do I have to go in and manually scale them up in the obj file(please no)

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

Posted (edited)

Well normaly this is how UVs work, UV are float/double from 0 to 1. Are you sure Forge is doing this wrong ?

Edited by MCenderdragon

catch(Exception e)

{

 

}

Yay, Pokémon exception handling, gotta catch 'em all (and then do nothing with 'em).

Posted

Well my models are textured using only the top left pixel stretched across the model, so either I was not told you need to tell forge "Hey, UV is a thing" or forge just doesn't do that

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

Posted

If my rendering code is of any use here it is

package keegan.labstuff.render;

import org.lwjgl.opengl.GL11;

import keegan.labstuff.tileentity.*;
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 RenderRocket extends TileEntitySpecialRenderer<TileEntityRocket> {

    private IModel model;
    private IBakedModel bakedModel;

    private IBakedModel getBakedModel(TileEntityRocket te) {
        // 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/" + te.getModel() + ".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(TileEntityRocket 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.formed)
        	renderHandles(te);


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

    }

    private void renderHandles(TileEntityRocket te) {
    	GlStateManager.enableLighting();
        GlStateManager.pushMatrix();

        GlStateManager.translate(.5, 0, .5);
        GlStateManager.translate(0, -te.rocket.length, 0);
        long height = (long)te.height;
        GlStateManager.translate(0, height, 0);

        //RenderHelper.disableStandardItemLighting();
        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());
        this.bindTexture(new ResourceLocation("labstuff:textures/models/" + te.getModel() + ".png"));
        Minecraft.getMinecraft().getBlockRendererDispatcher().getBlockModelRenderer().renderModelBrightness(getBakedModel(te), world.getBlockState(te.getPos()), bright, true);

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


}

 

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

Posted

Split them up? As in each face needs a texture?

I've actually made some obj models in blender now that I look, and they are texture properly in Minecraft. They use one texture file(assuming you're saying each face needs one texture file.) How did those export I wonder. Hmmm

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

Posted (edited)

NOTICE: DO NOT USE BIND TEXTURE IT OVERRIDES OBJ MATERIALS AND THUS OBJ

on a side not this one particular model like cycles through the textures in that folder, even some not connected to an obj, based on position I guess

EDIT: all models loaded through TESR do it, and I tried moving the model I was working with's texture into it's own subfolder but it still flashes between a different texture and missing.

Edited by KeeganDeathman

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

Posted

In blender I baked a UV map into the model, each face is represented fully(if scaled) in the map. This map was used in the creation of the texture. However, instead of each face using the portion of the texture, the UV assigns to that face, they all use one little pixel at UV (.75,.625) stretched across the entire face

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

Posted

Okay all here's how I fixed it.

When baking, use this

            bakedModel = model.bake(TRSRTransformation.identity(), Attributes.DEFAULT_BAKED_FORMAT, textureGetterFlipV);

/* Credit to Eternal Energy */
	public static Function<ResourceLocation, TextureAtlasSprite> textureGetterFlipV = new Function<ResourceLocation, TextureAtlasSprite>() 
	{
		@Override
		public TextureAtlasSprite apply(ResourceLocation location) 
		{
			return DummyAtlasTextureFlipV.instance;
		}
	};
    
    private static class DummyAtlasTextureFlipV extends TextureAtlasSprite 
    {
		public static DummyAtlasTextureFlipV instance = new DummyAtlasTextureFlipV();

		protected DummyAtlasTextureFlipV()
		{
			super("dummyFlipV");
		}

		@Override
		public float getInterpolatedU(double u)
		{
			return (float)u / 16;
		}

		@Override
		public float getInterpolatedV(double v) 
		{
			return (float)v / -16;
		}
	}

 

and then DO use bindTexture on your texture file. thanks all.

[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.