Jump to content

[Fixed][1.8.9] Missing OBJ Texture


micdoodle8
 Share

Recommended Posts

Hey there,

 

I can't seem to get the correct texture from the block texture map to display on my OBJ model.

 

1.7.10:

g4GRNZS.png

 

1.8.9:

sUuOPXt.png

 

1.7.10 code:

 

 

@SideOnly(Side.CLIENT)
public class TileEntityMinerBaseRenderer extends TileEntitySpecialRenderer
{
    public static final ResourceLocation minerBaseTexture = new ResourceLocation(AsteroidsModule.ASSET_PREFIX, "textures/model/minerbase.png");
    public static IModelCustom minerBaseModel;

    public TileEntityMinerBaseRenderer()
    {
        TileEntityMinerBaseRenderer.minerBaseModel = AdvancedModelLoader.loadModel(new ResourceLocation(AsteroidsModule.ASSET_PREFIX, "models/minerbase.obj"));
    }

    public void renderModelAt(TileEntityMinerBase tileEntity, double d, double d1, double d2, float f)
    {
        GL11.glDisable(GL12.GL_RESCALE_NORMAL);
    	if (!tileEntity.isMaster) return;
    	// Texture file
        FMLClientHandler.instance().getClient().renderEngine.bindTexture(TileEntityMinerBaseRenderer.minerBaseTexture);

        int i = tileEntity.getWorldObj().getLightBrightnessForSkyBlocks(tileEntity.xCoord, tileEntity.yCoord + 1, tileEntity.zCoord, 0);
        int j = i % 65536;
        int k = i / 65536;
        OpenGlHelper.setLightmapTextureCoords(OpenGlHelper.lightmapTexUnit, j / 1.0F, k / 1.0F);

        GL11.glPushMatrix();
        GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);

        GL11.glTranslatef((float) d + 1F, (float) d1 + 1F, (float) d2 + 1F);
        GL11.glScalef(0.05F, 0.05F, 0.05F);

        switch (tileEntity.facing)
        {
        case 0:
            GL11.glRotatef(180F, 0, 1F, 0);
            break;
        case 1:
            break;
        case 2:
            GL11.glRotatef(270F, 0, 1F, 0);
            break;
        case 3:
            GL11.glRotatef(90F, 0, 1F, 0);
            break;
        }

        TileEntityMinerBaseRenderer.minerBaseModel.renderAll();

        GL11.glPopMatrix();
    }

    @Override
    public void renderTileEntityAt(TileEntity tileEntity, double var2, double var4, double var6, float var8)
    {
        this.renderModelAt((TileEntityMinerBase) tileEntity, var2, var4, var6, var8);
    }
}

 

 

 

1.8.9 code:

 

 

@SideOnly(Side.CLIENT)
public class TileEntityMinerBaseRenderer extends TileEntitySpecialRenderer
{
    public static IModel minerBaseModel;
    public static IBakedModel minerBaseModelBaked;

    public IBakedModel getBakedModel()
    {
        if (minerBaseModelBaked == null)
        {
            try
            {
                minerBaseModel = ModelLoaderRegistry.getModel(new ResourceLocation(GalacticraftPlanets.ASSET_PREFIX, "minerbase0.obj"));
            }
            catch (Exception e)
            {
                throw new RuntimeException(e);
            }
            Function<ResourceLocation, TextureAtlasSprite> spriteFunction = new Function<ResourceLocation, TextureAtlasSprite>() {
                @Override
                public TextureAtlasSprite apply(ResourceLocation location) {
                    return Minecraft.getMinecraft().getTextureMapBlocks().getAtlasSprite(location.toString());
                }
            };
            minerBaseModelBaked = minerBaseModel.bake(TRSRTransformation.identity(), DefaultVertexFormats.ITEM, spriteFunction);
        }
        return minerBaseModelBaked;
    }

    public void renderTileEntityAt(TileEntity tile, double x, double y, double z, float p_180535_8_, int p_180535_9_)
    {
        TileEntityMinerBase minerBase = (TileEntityMinerBase) tile;
        GL11.glDisable(GL12.GL_RESCALE_NORMAL);

        int i = minerBase.getWorld().getLightFor(EnumSkyBlock.SKY, minerBase.getPos().up());
        int j = i % 65536;
        int k = i / 65536;
        OpenGlHelper.setLightmapTextureCoords(OpenGlHelper.lightmapTexUnit, j / 1.0F, k / 1.0F);

        GL11.glPushMatrix();
        GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);

        GL11.glTranslatef((float) x + 1F, (float) y + 1F, (float) z + 1F);
        GL11.glScalef(0.05F, 0.05F, 0.05F);

        switch (minerBase.facing)
        {
        case SOUTH:
            GL11.glRotatef(180F, 0, 1F, 0);
            break;
        case WEST:
            break;
        case NORTH:
            GL11.glRotatef(270F, 0, 1F, 0);
            break;
        case EAST:
            GL11.glRotatef(90F, 0, 1F, 0);
            break;
        }

        RenderHelper.disableStandardItemLighting();
        this.bindTexture(TextureMap.locationBlocksTexture);

        if (Minecraft.isAmbientOcclusionEnabled()) 
        {
            GlStateManager.shadeModel(GL11.GL_SMOOTH);
        } 
        else 
        {
            GlStateManager.shadeModel(GL11.GL_FLAT);
        }

        Tessellator tessellator = Tessellator.getInstance();
        tessellator.getWorldRenderer().begin(GL11.GL_QUADS, DefaultVertexFormats.BLOCK);
        GlStateManager.translate(-tile.getPos().getX(), -tile.getPos().getY(), -tile.getPos().getZ());
        Minecraft.getMinecraft().getBlockRendererDispatcher().getBlockModelRenderer().renderModel(tile.getWorld(), getBakedModel(), tile.getWorld().getBlockState(tile.getPos()), tile.getPos(), tessellator.getWorldRenderer());
        tessellator.draw();

        RenderHelper.enableStandardItemLighting();
        GL11.glPopMatrix();
    }
}

 

 

 

OBJ File

 

 

mtllib minerbase0.mtl

o dock

v -20.000000 -20.000004 19.999996

v -20.000000 -19.999996 -20.000004

v 20.000000 -19.999996 -20.000004

v 20.000000 -20.000004 19.999996

v -20.000000 19.999996 20.000004

v 20.000000 19.999996 20.000004

v 20.000000 20.000000 -4.374997

v -20.000000 20.000000 -4.374997

v 20.000000 4.374997 20.000000

v -20.000000 4.374997 20.000000

v 20.000000 4.375003 -20.000000

v 18.125000 4.374997 16.875000

v -18.125000 4.374997 16.875000

v -18.125000 14.999997 16.875002

v 18.125000 14.999997 16.875002

v -20.000000 4.375003 -20.000000

v -18.125000 -18.124996 -20.000004

v 18.125000 -18.124996 -20.000004

v 18.125000 15.000002 -9.374997

v -18.125000 15.000002 -9.374997

v 18.125000 4.375003 -20.000000

v -18.125000 4.375003 -20.000000

v -18.125000 -18.125002 16.874996

v 18.125000 -18.125002 16.874996

v 11.250000 15.000002 -9.374997

v 18.125000 11.250002 -13.124998

v 11.911800 11.250002 -13.124998

v 18.125000 4.375001 -6.250000

v 13.125000 4.374997 16.875000

v 13.125000 4.375001 -6.250000

v 11.911800 11.249997 16.875002

v 11.250000 14.999997 16.875002

v 17.500000 -18.124996 -20.000004

v 11.250000 -18.124996 -20.000004

v 11.250000 -16.874996 -20.000002

v 17.500000 -8.124997 -20.000002

v -11.250000 -18.124996 -20.000004

v -11.250000 -16.874996 -20.000002

v -17.500000 -18.124996 -20.000004

v -17.500000 -8.124997 -20.000002

v -16.250000 -6.250001 9.374999

v -10.000000 -15.000002 9.374997

v -10.000000 -15.000000 -1.875003

v -16.250000 -6.250000 -1.875001

v 10.000000 -15.000002 9.374997

v 10.000000 -15.000000 -1.875003

v 16.250000 -6.250001 9.374999

v 16.250000 -6.250000 -1.875001

v -11.250000 -16.874998 -6.250003

v -17.500000 -8.124999 -6.250001

v 11.250000 -16.874998 -6.250003

v 17.500000 -8.124999 -6.250001

v 18.125000 -8.124997 -20.000002

v -18.125000 -8.124997 -20.000002

v -18.125000 -6.250000 -1.875001

v -18.125000 -6.250001 9.374999

v -18.125000 -8.124999 -6.250001

v 18.125000 -6.250001 9.374999

v 18.125000 -6.250000 -1.875001

v 18.125000 -8.124999 -6.250001

v 18.125000 -3.125001 9.374999

v -18.125000 -3.125001 9.374999

v 18.125000 -15.000002 9.374997

v -18.125000 -15.000002 9.374997

v 6.250000 -16.874996 -20.000002

v -6.250000 -16.874996 -20.000002

v -6.250000 -14.999997 -18.125002

v 6.250000 -14.999997 -18.125002

v -6.250000 -16.874998 -6.250003

v -6.250000 -15.000000 -1.875003

v 6.250000 -15.000000 -1.875003

v 6.250000 -16.874998 -6.250003

v 6.875000 -3.125001 9.374999

v -6.875000 -3.125001 9.374999

v -6.875000 6.874999 9.375001

v 6.875000 6.874999 9.375001

v -6.875000 4.374997 16.875000

v -6.875000 6.874997 16.875002

v 6.875000 6.874997 16.875002

v 6.875000 4.374997 16.875000

v -11.250000 15.000002 -9.374997

v -11.911700 11.250002 -13.124998

v -18.125000 11.250002 -13.124998

v -18.125000 4.375001 -6.250000

v -13.125000 4.375001 -6.250000

v -13.125000 4.374997 16.875000

v -11.911800 11.249997 16.875002

v -11.250000 14.999997 16.875002

vt 1.000000 0.386900

vt 1.000000 0.767900

vt 0.666700 0.767900

vt 0.666700 0.386900

vt 0.333300 0.642900

vt 0.000000 0.642900

vt 0.000000 0.410700

vt 0.333300 0.410700

vt 0.666700 0.000000

vt 1.000000 0.000000

vt 1.000000 0.232100

vt 0.666700 0.232100

vt 1.000000 0.381000

vt 0.666700 0.381000

vt 0.333300 0.000000

vt 0.333300 0.232100

vt 0.463500 0.381000

vt 0.343800 0.577400

vt 0.645800 0.577400

vt 0.645800 0.678600

vt 0.343800 0.678600

vt -0.000000 0.000000

vt 0.317700 0.017900

vt 0.015600 0.017900

vt 0.015600 0.363100

vt 0.317700 0.363100

vt -0.000000 0.232100

vt 0.015600 0.232100

vt 0.000000 0.261900

vt 0.015600 0.261900

vt 0.317700 0.232100

vt 0.333300 0.261900

vt 0.317700 0.261900

vt 0.651000 0.684500

vt 0.651000 0.898800

vt 0.958300 0.898800

vt 0.958300 0.684500

vt 0.739600 1.000000

vt 0.958300 1.000000

vt 0.645800 0.928600

vt 0.343800 0.928600

vt 0.260400 0.363100

vt 0.317700 0.327400

vt 0.265600 0.327400

vt 0.208300 0.214300

vt 0.015600 0.214300

vt 0.208300 0.261900

vt 0.015600 0.327400

vt 0.234400 0.363100

vt 0.276000 0.261900

vt 0.020800 0.017900

vt 0.072900 0.017900

vt 0.072900 0.029800

vt 0.020800 0.113100

vt 0.260400 0.017900

vt 0.260400 0.029800

vt 0.312500 0.017900

vt 0.312500 0.113100

vt 0.057300 0.964300

vt 0.130200 0.964300

vt 0.130200 0.857100

vt 0.057300 0.857100

vt 0.307300 0.964300

vt 0.140600 0.964300

vt 0.140600 0.857100

vt 0.307300 0.857100

vt 0.130200 0.815500

vt 0.057300 0.815500

vt 0.317700 0.815500

vt 0.015600 0.113100

vt 0.317700 0.113100

vt 0.041700 0.857100

vt 0.041700 0.964300

vt 0.046900 0.815500

vt 0.041700 0.815500

vt 0.057300 0.684500

vt 0.130200 0.684500

vt 0.317700 0.684500

vt 0.041700 0.684500

vt 0.046900 0.684500

vt 0.343800 0.506000

vt 0.645800 0.506000

vt 0.343800 0.392900

vt 0.645800 0.392900

vt 0.171900 0.654800

vt 0.276000 0.654800

vt 0.276000 0.684500

vt 0.171900 0.684500

vt 0.057300 0.654800

vt 0.020800 0.672600

vt 0.156300 0.672600

vt 0.276000 0.839300

vt 0.171900 0.839300

vt 0.109400 0.047600

vt 0.224000 0.047600

vt 0.224000 0.142900

vt 0.109400 0.142900

vt 0.088500 0.214300

vt 0.109400 0.214300

vt 0.026000 0.142900

vt 0.224000 0.214300

vn 0.000000 -1.000000 -0.000000

vn 0.000000 1.000000 0.000000

vn 0.000000 -0.000000 1.000000

vn 1.000000 0.000000 0.000000

vn 0.000000 0.000000 -1.000000

vn -1.000000 0.000000 0.000000

vn 0.000000 0.707100 -0.707100

vn -0.984800 -0.173800 -0.000000

vn 0.000000 -0.707100 -0.707100

vn 0.813700 0.581200 0.000000

vn -0.813700 0.581200 0.000000

vn 0.733100 0.523700 -0.433900

vn 0.000000 0.919100 -0.393900

vn -0.733100 0.523700 -0.433900

vn 0.984800 -0.173800 0.000000

usemtl MinerBase

s off

f 1/1/1 2/2/1 3/3/1 4/4/1

f 5/5/2 6/6/2 7/7/2 8/8/2

f 1/9/3 4/10/3 9/11/3 10/12/3

f 10/12/3 9/11/3 6/13/3 5/14/3

f 4/9/4 3/15/4 11/16/4 9/12/4

f 9/12/4 11/16/4 7/17/4 6/14/4

f 12/18/5 13/19/5 14/20/5 15/21/5

f 2/15/6 1/9/6 10/12/6 16/16/6

f 16/16/6 10/12/6 5/14/6 8/17/6

f 3/22/5 2/15/5 17/23/5 18/24/5

f 8/8/7 7/7/7 19/25/7 20/26/7

f 11/27/5 3/22/5 18/24/5 21/28/5

f 7/7/7 11/29/7 21/30/7 19/25/7

f 2/15/5 16/16/5 22/31/5 17/23/5

f 16/32/7 8/8/7 20/26/7 22/33/7

f 17/34/4 22/35/4 13/36/4 23/37/4

f 21/35/6 18/34/6 24/37/6 12/36/6

f 22/35/4 20/38/4 14/39/4 13/36/4

f 20/40/1 19/41/1 15/21/1 14/20/1

f 19/38/6 21/35/6 12/36/6 15/39/6

f 25/42/7 19/26/7 26/43/7 27/44/7

f 28/45/1 12/46/1 29/30/1 30/47/1

f 27/44/8 31/48/8 32/25/8 25/49/8

f 31/48/8 27/44/8 30/47/8 29/30/8

f 27/44/9 26/43/9 28/33/9 30/50/9

f 33/51/5 34/52/5 35/53/5 36/54/5

f 34/52/5 37/55/5 38/56/5 35/53/5

f 37/55/5 39/57/5 40/58/5 38/56/5

f 41/59/10 42/60/10 43/61/10 44/62/10

f 42/63/2 45/64/2 46/65/2 43/66/2

f 45/60/11 47/59/11 48/62/11 46/61/11

f 44/62/12 43/61/12 49/67/12 50/68/12

f 43/66/13 46/65/13 51/67/13 49/69/13

f 46/61/14 48/62/14 52/68/14 51/67/14

f 33/51/5 36/54/5 53/70/5 18/24/5

f 40/58/5 39/57/5 17/23/5 54/71/5

f 41/59/2 44/62/2 55/72/2 56/73/2

f 44/62/13 50/74/13 57/75/13 55/72/13

f 48/62/2 47/59/2 58/73/2 59/72/2

f 52/74/13 48/62/13 59/72/13 60/75/13

f 51/67/11 52/68/11 36/76/11 35/77/11

f 49/69/2 51/67/2 35/77/2 38/78/2

f 50/68/10 49/67/10 38/77/10 40/76/10

f 52/74/2 60/75/2 53/79/2 36/80/2

f 57/75/2 50/74/2 40/80/2 54/79/2

f 20/26/7 81/42/7 82/44/7 83/43/7

f 13/46/1 84/45/1 85/47/1 86/30/1

f 86/30/15 85/47/15 82/44/15 87/48/15

f 81/49/15 88/25/15 87/48/15 82/44/15

f 83/43/9 82/44/9 85/50/9 84/33/9

s 1

f 12/18/7 61/81/7 62/82/7 13/19/7

f 61/81/5 63/83/5 64/84/5 62/82/5

f 65/85/7 66/86/7 67/87/7 68/88/7

f 69/89/6 70/90/6 67/91/6 66/85/6

f 70/92/2 71/93/2 68/88/2 67/87/2

f 71/90/4 72/89/4 65/85/4 68/91/4

f 73/94/5 74/95/5 75/96/5 76/97/5

f 77/98/6 78/99/6 75/97/6 74/100/6

f 78/99/2 79/101/2 76/96/2 75/97/2

f 79/99/4 80/98/4 73/100/4 76/97/4

 

 

 

Material File

 

 

newmtl MinerBase

map_Kd galacticraftplanets:blocks/minerbase

 

 

 

If anyone has any ideas about why the texture is not being mapped properly, it would be much appreciated.

Link to comment
Share on other sites

Greetings. I am thinking you need to register your textures. Everything else looks good as far as I can tell. In 1.8.9 we need to @SubscribeEvent the client side event: "TextureStitchEvent" and then you can register your textures in that.

For example:

event.map.registerSprite(new ResourceLocation("bibliocraft:models/bookcase_books"));

 

Hope that helps.

 

 

Link to comment
Share on other sites

Thank you, it was a combination of not stitching the texture into the block map, and the texture not being square. The non-square texture worked in <1.8 but the error got lost in the log with a lot of other problems on the go.

Link to comment
Share on other sites

Guest
This topic is now closed to further replies.
 Share



×
×
  • Create New...

Important Information

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