Texturing a 3D mesh using a spritesheet

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By lukastk

I’d like to know how to apply a texture to a mesh by only using a part of a larger PNG file, the same way one can do this easily in 2D by simply selecting a region of a spritesheet.

I have a MeshInstance, with a PlaneMesh, and I tried to do the following:

  • Added a SpatialMaterial.
  • Added an AtlasTexture, loaded with my spritesheet png.
  • Selected the desired region

This did not seem to work, as my mesh simply shows up white with no textures whatsoever.

enter image description here

When I play the scene the mesh shows up with the whole spritesheet, instead of with the desired region.

enter image description here

:bust_in_silhouette: Reply From: wombatstampede

The UVs define what part of a Texture is shown on the Mesh surface. Each face of a Mesh consist of a number of vertices (points) and each of this vertice has (among other attributes) a set of X/Y UV coordinates assigned. UV-Coordinates are floating point and usually range from 0 to 1.

So if you want only a part of the texture to show then you’ll enter the UV-Editor of your 3D-Editor (i.e. Blender) and assign the UV-Mappings accordingly.

If you’ve got a simple plane with a UV-Mapping from 0,0 on one corner to 1,1 to the opposite then you might be able to work with the SpatialMaterials UV1 offset and UV1 scale.

But this is not all. If you place textures of non-adjacent faces next to each other in the texture image then this might provide unwanted results depending on how the texture flags are set. I.e. you might often want to disable “MipMap” as this will interpolate the texture image when it is further away. Because this will tend to let textures “bleed” into each other.

Thank you very much! Managed to do it with your help. Although the texture bleeding is still there, and I can’t find the MipMap property. Is that a feature of Godot 3?

lukastk | 2019-05-25 15:17

You define the Mipmaps property on import of the texture. Select the image file/texture (jpg/png whatever) in the Filesystem part of the GodotWindow. Then select the Import tab. Yo should see several options. You can try “Lossy” or “Lossless” mode. You should disable “Mipmaps” any maybe also “Filter”. You can also disable any checkmarks in “Process”. (Feel free to experiment though)

Then click on Reimport (at the bottom of the Import display)

wombatstampede | 2019-05-25 15:57