0 votes

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

in Engine by (12 points)

1 Answer

+1 vote

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.

by (3,248 points)

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?

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)

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to webmaster@godotengine.org with your username.