defold / defold

Defold is a completely free to use game engine for development of desktop, mobile and web games.
https://www.defold.com
Other
4.46k stars 312 forks source link

Gui node width and height not correct after resource.set_atlas if image in atlas rotated #8784

Open d954mas opened 7 months ago

d954mas commented 7 months ago

Describe the bug (REQUIRED) Gui node width and height not correct after resource.set_atlas if image in atlas rotated

Look at second node. Width and height are swapped.

2024-04-11_11-06-29

I use 3 atlases.

Also i try reproduce this in gui and in sprites. Sprites not worked when i change atlas https://github.com/defold/defold/issues/8783 So for now sprites use "assets/skins.atlas"

go.property("atlas_empty", resource.atlas("/assets/skins_empty.atlas"))
go.property("atlas_empty_fixed", resource.atlas("/assets/skins_empty_fixed.atlas"))
go.property("atlas", resource.atlas("/assets/skins.atlas"))

function init(self)
    local atlas = resource.get_atlas(self.atlas)
    resource.set_atlas(self.atlas_empty, atlas)

    for idx, geometry in ipairs(atlas.geometries) do
        local anim = atlas.animations[idx]
        local data = {
            id = anim.id,
        }

        if geometry.uvs[1] ~= geometry.uvs[3] then
            data.need_rotate = true
            local tc = geometry.vertices
            --add rotation to geometry
            local new_vertices = {
                tc[3], tc[4],
                tc[5], tc[6],
                tc[7], tc[8],
                tc[1], tc[2],
            }

            geometry.vertices = new_vertices
            --now rotate uv and vertices to by 90
        end
    end
    resource.set_atlas(self.atlas_empty_fixed, atlas)

    timer.delay(1, false, function()
        factory.create("/factories#factory1",vmath.vector3(480-100,170,0))
        factory.create("/factories#factory2",vmath.vector3(480,170,0))
        factory.create("/factories#factory3",vmath.vector3(480+100,170,0))
    end)

end

To Reproduce (REQUIRED) See repro case.

Expected behavior (REQUIRED) If i change atlas gui nodes show it correctly.

Defold version (REQUIRED):

Platforms (REQUIRED):

Minimal repro case project (OPTIONAL):

gui_width_height_not_correct.zip

Additional context (OPTIONAL): https://forum.defold.com/t/replace-atlast-with-liveupdate-version/76540/3

d954mas commented 4 months ago

Update repro case. Sprite was fixed.

Now you can see, that sprites is rotated but have correct width and height Gui is rotated but width and height is swapped gui_width_height_not_correct.zip

2024-07-30_18-45-27

https://github.com/user-attachments/assets/3fbacfec-8ab6-4ace-88bf-1b20708b2e6f

d954mas commented 4 months ago

Maybe correctly way to fix it will be add geometry rotation to get/set atlas resources? For now we can't create rotated image in runtime created atlas

https://github.com/defold/defold/blob/a8b8e544c5f6db1e7612bc65124597ef6ff1ab1d/engine/gamesys/proto/gamesys/texture_set_ddf.proto#L40

https://github.com/defold/defold/blob/a8b8e544c5f6db1e7612bc65124597ef6ff1ab1d/engine/gamesys/src/gamesys/scripts/script_resource.cpp#L1894

https://github.com/defold/defold/blob/a8b8e544c5f6db1e7612bc65124597ef6ff1ab1d/engine/gamesys/src/gamesys/scripts/script_resource.cpp#L1889

d954mas commented 4 months ago

My case for that code. I have 2 atlases. skins_empty.atlas and skins_liveupdate.atlas.

When liveupdate is loaded i am replaced skinks atlas with full version