Jump to content

[1.10.2] OBJ UV Coordinates


KeeganDeathman

Recommended Posts

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]

Link to comment
Share on other sites

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]

Link to comment
Share on other sites

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]

Link to comment
Share on other sites

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]

Link to comment
Share on other sites

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]

Link to comment
Share on other sites

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]

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.



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • Hello! I have recently purchased a new computer and cannot download Optifine or Forge. The issue I am having is that the Java program 'javaw.exe' does not seem to open .jar files for me. As far as I can tell, I cannot open .jar files at all. The trouble-shooting I have tried so far is that I have un-downloaded and re-downloaded Java and that has not fixed it. I have followed the pathway to 'open with->choose another app->choose an app on your pc->Program Files (x86)->Java->jre-1.8->bin. and from inside bin I have tried opening these programs with each and every java application in there assuming I may have been wrong about which one I need to use. Still no luck. From there I checked to make sure that Java was allowed through my firewall and have seen no instances of any application with Java in the name anywhere in the list of apps to let through fire wall. I'm unsure of what to try next, so I would absolutely love help figuring out why my computer is not letting me open .jar files. Specifically these ones that I know are meant to open as installers. Any ideas are appreciated. Thanks in advance!
    • Thanks again for your anwsers, I tested without practical_plushies_mobs, practical_plushies_animals and dark-waters and now red forge loading screen appears however few seconds later it crashed again.  How I could put my file codes in my minecraft folder? log crash report
    • I have a modded mob that when I try to spawn it, it won't spawn and a crash happens (doesn't crash whole game though) and it says "Duplicate id value for 16!" and points to the mob's defineSynchedData method. Anyone know what's going on? Here's the method it was pointing to: @Override protected void defineSynchedData() { super.defineSynchedData(); this.entityData.define(MY_BOOLEAN_DATA, false); }  
    • Click Here -- Official Website -- Order Now ➡️● For Order Official Website - https://sale365day.com/get-restore-cbd-gummies ➡️● Item Name: — Restore CBD Gummies ➡️● Ingredients: — All Natural ➡️● Incidental Effects: — NA ➡️● Accessibility: — Online ✅HUGE DISCOUNT ! HURRY UP! ORDER NOW!✅ ✅HUGE DISCOUNT ! HURRY UP! ORDER NOW!✅ ✅HUGE DISCOUNT ! HURRY UP! ORDER NOW!✅   Restore CBD Gummies is a strong contender for the top gummy of the year. Due to its strong concentration of CBD and purity, you will achieve excellent results while using it if you stick with this solution. Most people who suffer from constant pain, anxiety, depression, and insomnia are currently solving these problems, and you can be the next one. All you need to do is give Restore CBD Gummies a chance and let this fantastic product change your life. Visit the official website to order your Restore CBD Gummies today! After reading Restore CBD Gummies reviews, we now know that knee replacement surgeries are not the only option to treat knee pain, inflammation, joint discomfort, and stiffness. These CBD gummies can heal your joints and provide you relief from pain and stress so that you can lead a happy life. Prosper Wellness Restore CBD Gummies can improve joint mobility and improve knee health so that you can remain healthy. Exclusive Details: *Restore CBD Gummies* Read More Details on Official Website #USA! https://www.facebook.com/claritox.pro.unitedstates https://www.facebook.com/illudermaUCAAU https://www.facebook.com/awakenxtusa https://groups.google.com/a/chromium.org/g/chromium-reviews/c/8NMUVKgd-FA https://groups.google.com/g/microsoft.public.project/c/0UZQQKOZF58 https://groups.google.com/g/comp.editors/c/r_BcRRrvGhs https://medium.com/@illuderma/illuderma-reviews-fda-approved-breakthrough-or-clever-skincare-scam-36088ae82c3e https://medium.com/@claritoxpros/claritox-pro-reviews-legitimate-or-deceptive-dr-warns-of-potential-dangers-d5ff3867b34d https://medium.com/@thedetoxall17/detoxall-17-reviews-scam-alert-or-legit-detox-solution-customer-report-inside-1fd4c6920c9e https://groups.google.com/a/chromium.org/g/chromium-reviews/c/RONgLAl6vwM https://groups.google.com/g/microsoft.public.project/c/TgtOMRFt6nQ https://groups.google.com/g/comp.editors/c/fUfg0L2YfzU https://crediblehealths.blogspot.com/2023/12/revitalize-with-restore-cbd-gummies.html https://community.weddingwire.in/forum/restore-cbd-gummies-uncovered-fda-approved-breakthrough-or-deceptive-wellness-scam--t206896 https://restorecbdgummies.bandcamp.com/album/restore-cbd-gummies-uncovered-fda-approved https://my-restore-cb.clubeo.com/page/restore-cbd-gummies-reviews-customer-alert-drs-warning-genuine-or-wellness-hoax.html https://my-restore-cb.clubeo.com/page/restore-cbd-gummies-reviews-scam-alert-or-legit-relief-solution-customer-report-inside.html https://medium.com/@restorecbdgum/restore-cbd-gummies-reviews-warning-2023-update-real-or-a-powerful-relief-hoax-caution-350b61472a3f https://devfolio.co/@restorecbdgum https://restore-cbd-gummies-9.jimdosite.com/ https://devfolio.co/project/new/restore-cbd-gummies-reviews-scam-or-legit-custo-7bd6 https://groups.google.com/a/chromium.org/g/chromium-reviews/c/R0enUCvfs8s https://groups.google.com/g/microsoft.public.project/c/miJma2yOMDQ https://groups.google.com/g/comp.os.vms/c/S_HG94aaKFo https://groups.google.com/g/mozilla.dev.platform/c/qb6WpMUYLu0 https://hellobiz.in/restore-cbd-gummies-reviews-warning-2023-update-genuine-wellness-or-another-hoax-caution-211948390 https://pdfhost.io/v/ir5l.cseV_Restore_CBD_Gummies_Reviews_WARNING_2023_Update_Genuine_Wellness_or_Another_Hoax_Caution https://odoe.powerappsportals.us/en-US/forums/general-discussion/7c8b3f62-6d96-ee11-a81c-001dd8066f2b https://gamma.app/public/Restore-CBD-Gummies-ssh57nprs2l6xgq https://restorecbdgummies.quora.com/ https://www.facebook.com/RestoreCBDGummiesUS https://groups.google.com/g/restorecbdgum/c/9KHVNp3oy3E https://sites.google.com/view/restorecbdgummiesreviewsfdaapp/home https://experiment.com/projects/pjyhtzvpcvllopsglcph/methods https://lookerstudio.google.com/reporting/e5e9f52d-ae52-4c84-96c6-96b97932215f/page/XtkkD https://restore-cbd-gummies-reviews-is-it-a-sca.webflow.io/ https://colab.research.google.com/drive/1xZoc6E2H-jliBSZRVl0vnVqrkc3ix4YU https://soundcloud.com/restore-cbd-gummies-821066674/restore-cbd-gummies https://www.eventcreate.com/e/restore-cbd-gummies-reviews https://restorecbdgummies.godaddysites.com/ https://sketchfab.com/3d-models/restore-cbd-gummies-reviews-fda-approved-7cfe1fb8b003481c81689dd9489d2812 https://www.scoop.it/topic/restore-cbd-gummies-by-restore-cbd-gummies-9 https://events.humanitix.com/restore-cbd-gummies https://communityforums.atmeta.com/t5/General-Development/Restore-CBD-Gummies/m-p/1113602
  • Topics

×
×
  • Create New...

Important Information

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