• Godot Help3D
  • Map different images to different sides of BoxMesh

I am downloading images from the web dynamically and want to map each image to a different face of the BoxMesh. I understand that when I have prepared textures, I use the UV1 values to map it properly to each side but how do I do it with variable images?

Thanks for any pointers! 🙂

Max

  • xyz replied to this.

    max_godot Blit images to proper places in actual texture. Or have a custom box where each face has full 0-1 range UVs, plug all 6 textures as uniforms into shader and decide which one to use by looking at the face normal.

      23 days later

      Finally getting back to this 🙂
      I found some instructions regarding blit here and tried it out: https://ask.godotengine.org/83298/how-create-new-image-inside-godot-from-fragments-other-images

      My code

      func _ready():
      	var img = Image.new()
      	img.create(1200, 1200, false, Image.FORMAT_RGB8)
      	var blitImage = Image.new()
      	blitImage.load("res://avatar.jpg")
      	img.blit_rect(blitImage, blitImage.get_used_rect(), Vector2(40, 40))
      	img.save_jpg("res://avatar_blit.jpg")

      but when I run it, it returns

      E 0:00:00:0578   Node.gd:10 @ _ready(): Condition "dsize == 0" is true.
        <C++ Source>   core/io/image.cpp:2786 @ blit_rect()
        <Stack Trace>  Node.gd:10 @ _ready()
      
      E 0:00:00:0578   Node.gd:11 @ _ready(): Condition "p_img.is_null() || p_img->is_empty()" is true. Returning: ERR_INVALID_PARAMETER
        <C++ Source>   modules/jpg/image_loader_jpegd.cpp:158 @ _jpgd_save_to_output_stream()
        <Stack Trace>  Node.gd:11 @ _ready()

      I have already checked, according to the Godot inspector the avatar.jpg is of format RGB8 so that can be ruled out as issue.
      What am I missing here?

      You can find the complete project here for reference:
      https://www.dropbox.com/scl/fi/iglu4lu96gq8uksy2mljq/blit.zip?rlkey=yj95vki9xelmkqrldevkh3kl4&dl=0