#Atlas Textures in 3D

1 messages · Page 1 of 1 (latest)

grand zinc
#

I am trying to put an atlas texture onto a MeshInstance3D. The only issue is, is when I try to create a region for the atlas, it doesn't really pay attention to it. The goal is to be able to grab anywhere on the atlas dynamically and put it onto a mesh instance.

#

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
bronze condor
#

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

grand zinc
bronze condor
vernal moss
full granite
#

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