#Atlas Textures in 3D
1 messages · Page 1 of 1 (latest)
Current work I concepted
extends Node3D
@onready var meshparent = $meshparent
@onready var RockMesh = $RockMesh
func _ready():
apply_data()
func apply_data():
if Rockregistry.current_rocks:
var temp = Rockregistry.current_rocks.pick_random()
var data = temp.duplicate()
var inst = load(data.mesh_path).instantiate()
meshparent.add_child(inst)
var atlas = AtlasTexture.new()
atlas.atlas = data.atlas_texture
var rect = Rect2(data.offset.x, data.offset.y, 16, 16)
atlas.set_region(rect)
var mat = StandardMaterial3D.new()
mat.albedo_texture = atlas
mat.texture_filter = BaseMaterial3D.TEXTURE_FILTER_NEAREST
for i in meshparent.get_children():
for j in i.get_children():
if j is MeshInstance3D:
j.material_override = mat
AtlasTexture only works for 2D. for 3D you would just set your UVs accordingly in your mesh.
you could also use Texture2DArray as an option
Literally just did that and it worked! was really hoping for atlas textures to translate though. 
It’s a tricky one to make work with random 3D meshes. I wouldn’t expect to see that supported anytime soon so stick with what you have working now!
It's surprisingly easy to make it work with the standard shader with a few tweaks.
- Calculate the pixel to UV ratio.
- Calculate number of pixels in selected region.
- Use this to calculate the new UV ratio.
- Multiply existing UVs by this ratio (wrap any exceeding 1.0)
5.. Offset UVs by using region start point and pixel to UV ratio calculated earlier.
what mesh type did you try to put on? It would probably make most sense on a Quad. Or Sprite3D if you want it to be shown as a 2D billboard in a 3D scene