Problems with texture scaling/orientation since Minetest 5

Problems with texture scaling/orientation since Minetest 5

Postby blachner » Mon Mar 18, 2019 6:07 pm

I'm working on a small "Gallery" mod for Minetest. I started development with Minetest 0.4.17 and my code more or less works there:

Image

OK, pictures on the floor and ceiling aren't really useful, but it helps to illustrate my problem. ;-) After upgrading to Minetest 5 my mod looks like this:

Image

I use the following code to register the nodes for the pictures:

Code: Select all
for n=1, N do

    local groups = {choppy=2, dig_immediate=3, picture=1, not_in_creative_inventory=1}
    if n == 1 then
        groups = {choppy=2, dig_immediate=3, picture=1}
    end

    -- Texture for the frame
    local frame_texture = "metal_1.png"
    -- Pixel size of the resulting texture for the node. Higher resolutions for more details.
    local resulttexture_pix = 800
    -- Frame border width in percent
    local frame_widthpercent = 2.5
    -- Scaling of the picture
    local pic_scale = 2.5

    -- Get the width and height of the picture from the file in pixel
    local pic_pixwidth,pic_pixheight=get_pngwidthheight(n)
    -- Get the max side lenght of the picture in pixel
    local pic_pixmax = math.max(pic_pixwidth,pic_pixheight)
    -- Frame border width in pixel
    local frame_widthpixel = math.ceil(frame_widthpercent * pic_pixmax / 100.0)

    -- Distance beetween the frame and the picture in pixel
    local border_pix = 4
    -- Pixel size of the combined square texture of the picture with frame and border
    local pictexture_pix = pic_pixmax + (frame_widthpixel * 2) + (border_pix * 2)
    -- X and Y position oft the picture in the combined square texture of the picture with frame and border
    local pic_xoffset = ((pic_pixmax - pic_pixwidth) / 2) + frame_widthpixel + border_pix
    local pic_yoffset = ((pic_pixmax - pic_pixheight) / 2) + frame_widthpixel + border_pix

    -- Frame border width of the node
    local frame_widthnode = 1.0 / pictexture_pix * frame_widthpixel
    -- Frame border thickness of the node
    local frame_thickness = 0.1

    -- Picture width of the node (whole picture including frame)
    local pic_width = 1.0
    -- Picture height of the node (whole picture including frame)
    local pic_height = 1.0
    -- Picture thickness of the node
    local pic_thickness = 0.05

    if pic_pixwidth > pic_pixheight then
        -- Landscape picture. Set the Picture height of the node (whole picture including frame) accordingly to the original picture aspect ratio
        pic_height = (pic_width / pictexture_pix) * (pic_pixheight + 2 * (frame_widthpixel + border_pix))
    else
        -- Potrait picture Set the Picture width of the node (whole picture including frame) accordingly to the original picture aspect ratio
        pic_width = (pic_height / pictexture_pix) * (pic_pixwidth + 2 * (frame_widthpixel + border_pix))
    end

    -- node
    minetest.register_node("gallery:node_"..n.."", {
        description = "Picture #"..n.."",
        drawtype = "nodebox",
         -- Tile definition in the follwing order: +Y, -Y, +X, -X, +Z, -Z.
        tiles = {
            {name="("..frame_texture.."^[resize:"..resulttexture_pix.."x"..resulttexture_pix..")^([combine:"..pictexture_pix.."x"..pictexture_pix..":"..pic_xoffset..","..pic_yoffset.."=picture_"..n..".png^[resize:"..resulttexture_pix.."x"..resulttexture_pix..")"},
            {name=frame_texture}
        },
        visual_scale = pic_scale,
        inventory_image = "gallery_inventory.png",
        wield_image = "gallery_inventory.png",
        paramtype = "light",
        paramtype2 = "wallmounted",
        sunlight_propagates = true,
        walkable = false,
        node_box = {
            type = "fixed",
            -- Box definition in following order: {x1, y1, z1, x2, y2, z2}
            fixed = {
                -- Picture
                {-pic_width/2.0, -0.5/pic_scale, -pic_height/2.0, pic_width/2.0, -(0.5 - pic_thickness) / pic_scale, pic_height/2.0},                   
                -- Left frame border
                {-pic_width/2.0, -0.5/pic_scale, -pic_height/2.0, -pic_width/2.0+frame_widthnode, -(0.5 - frame_thickness) / pic_scale, pic_height/2.0},
                -- Right frame border
                {pic_width/2.0-frame_widthnode, -0.5/pic_scale, -pic_height/2.0, pic_width/2.0, -(0.5 - frame_thickness) / pic_scale, pic_height/2.0},
                 -- Bottom frame border
                {-pic_width/2.0, -0.5/pic_scale, -pic_height/2.0, pic_width/2.0, -(0.5 - frame_thickness) / pic_scale, -pic_height/2.0+frame_widthnode},
                -- Top frame border
                {-pic_width/2.0, -0.5/pic_scale, pic_height/2.0-frame_widthnode, pic_width/2.0, -(0.5 - frame_thickness) / pic_scale, pic_height/2.0},
            },
        },


Now I see two problems after upgrading to Minetest 5:

1) The nodes are rotated to the walls like with Minetest 0.4.17. But the texture isn't rotated in Minetest 5 anymore. Bug or feature?

2) The node definition and the texture isn't scaled by the parameter visual_scale anymore. OK I read in the documentation that visual_scale is for the wielded image. So this may be a bug in Minetest 0.4.17 and is corrected now?

I found a solution to scale the node, with the following code:
Code: Select all
for n=1, N do

    local groups = {choppy=2, dig_immediate=3, picture=1, not_in_creative_inventory=1}
    if n == 1 then
        groups = {choppy=2, dig_immediate=3, picture=1}
    end

    -- Texture for the frame
    local frame_texture = "metal_1.png"
    -- Pixel size of the resulting texture for the node. Higher resolutions for more details.
    local resulttexture_pix = 800
    -- Frame border width in percent
    local frame_widthpercent = 2.5
    -- Scaling of the picture
    local pic_scale = 2.5

    -- Get the width and height of the picture from the file in pixel
    local pic_pixwidth,pic_pixheight=get_pngwidthheight(n)
    -- Get the max side lenght of the picture in pixel
    local pic_pixmax = math.max(pic_pixwidth,pic_pixheight)
    -- Frame border width in pixel
    local frame_widthpixel = math.ceil(frame_widthpercent * pic_pixmax / 100.0)

    -- Distance beetween the frame and the picture in pixel
    local border_pix = 4
    -- Pixel size of the combined square texture of the picture with frame and border
    local pictexture_pix = pic_pixmax + (frame_widthpixel * 2) + (border_pix * 2)
    -- X and Y position oft the picture in the combined square texture of the picture with frame and border
    local pic_xoffset = ((pic_pixmax - pic_pixwidth) / 2) + frame_widthpixel + border_pix
    local pic_yoffset = ((pic_pixmax - pic_pixheight) / 2) + frame_widthpixel + border_pix

    -- Frame border width of the node
    local frame_widthnode = 1.0 / pictexture_pix * frame_widthpixel
    -- Frame border thickness of the node
    local frame_thickness = 0.1

    -- Picture width of the node (whole picture including frame)
    local pic_width = 1.0
    -- Picture height of the node (whole picture including frame)
    local pic_height = 1.0
    -- Picture thickness of the node
    local pic_thickness = 0.05

    pic_width = pic_width * pic_scale
    pic_height = pic_height * pic_scale
   
    if pic_pixwidth > pic_pixheight then
        -- Landscape picture. Set the Picture height of the node (whole picture including frame) accordingly to the original picture aspect ratio
        pic_height = (pic_width / pictexture_pix) * (pic_pixheight + 2 * (frame_widthpixel + border_pix))
    else
        -- Potrait picture Set the Picture width of the node (whole picture including frame) accordingly to the original picture aspect ratio
        pic_width = (pic_height / pictexture_pix) * (pic_pixwidth + 2 * (frame_widthpixel + border_pix))
    end

    -- node
    minetest.register_node("gallery:node_"..n.."", {
        description = "Picture #"..n.."",
        drawtype = "nodebox",
         -- Tile definition in the follwing order: +Y, -Y, +X, -X, +Z, -Z.
        tiles = {
            {name="("..frame_texture.."^[resize:"..resulttexture_pix.."x"..resulttexture_pix..")^([combine:"..pictexture_pix.."x"..pictexture_pix..":"..pic_xoffset..","..pic_yoffset.."=picture_"..n..".png^[resize:"..resulttexture_pix.."x"..resulttexture_pix..")"},
            {name=frame_texture}
        },
        visual_scale = pic_scale,
        inventory_image = "gallery_inventory.png",
        wield_image = "gallery_inventory.png",
        paramtype = "light",
        paramtype2 = "wallmounted",
        sunlight_propagates = true,
        walkable = false,
        node_box = {
            type = "fixed",
            -- Box definition in following order: {x1, y1, z1, x2, y2, z2}
            fixed = {
                -- Picture
                {-pic_width/2.0, -0.5, -pic_height/2.0, pic_width/2.0, -(0.5 - pic_thickness) , pic_height/2.0},                   
                -- Left frame border
                {-pic_width/2.0, -0.5, -pic_height/2.0, -pic_width/2.0+frame_widthnode, -(0.5 - frame_thickness) , pic_height/2.0},
                -- Right frame border
                {pic_width/2.0-frame_widthnode, -0.5, -pic_height/2.0, pic_width/2.0, -(0.5 - frame_thickness) , pic_height/2.0},
                 -- Bottom frame border
                {-pic_width/2.0, -0.5, -pic_height/2.0, pic_width/2.0, -(0.5 - frame_thickness) , -pic_height/2.0+frame_widthnode},
                -- Top frame border
                {-pic_width/2.0, -0.5, pic_height/2.0-frame_widthnode, pic_width/2.0, -(0.5 - frame_thickness) , pic_height/2.0},
            },
        },
        selection_box = {
            type = "wallmounted",
        },
        groups = groups,


Than it looks like this in Minetest 5:

Image

But I have no idea how to scale the texture over more than one node?
And why isn't the texture rotated with the node?

Maybe someone have an idea and can help.
blachner
New member
 
Posts: 2
Joined: Sun Mar 17, 2019 8:26 pm

Re: Problems with texture scaling/orientation since Minetest

Postby sfan5 » Mon Mar 18, 2019 8:42 pm

blachner wrote:1) The nodes are rotated to the walls like with Minetest 0.4.17. But the texture isn't rotated in Minetest 5 anymore. Bug or feature?

Bug, it's being tracked here: https://github.com/minetest/minetest/issues/8358
blachner wrote:2) The node definition and the texture isn't scaled by the parameter visual_scale anymore

Looks like a bug, but this isn't certain yet.
sfan5
Moderator
 
Posts: 3784
Joined: Wed Aug 24, 2011 9:44 am
GitHub: sfan5

Re: Problems with texture scaling/orientation since Minetest

Postby runs » Tue Mar 19, 2019 10:05 am

blachner wrote:2) The node definition and the texture isn't scaled by the parameter visual_scale anymore

Looks like a bug, but this isn't certain yet.[/quote]

Some problem here.
runs
Member
 
Posts: 328
Joined: Sat Oct 27, 2018 8:32 am
GitHub: runsy

Re: Problems with texture scaling/orientation since Minetest

Postby blachner » Tue Mar 19, 2019 8:09 pm

OK after adding the fix for rotation from here https://github.com/minetest/minetest/pull/8401/commits/47e81b4ded0ba5cc11ebfca268386e0c265af0b7 it and compile Minetes 5 it looks like these:

Image

Now I only need a solution to fix the texture scaling. I don't find a workaround for this yet. This issue is tracked here: https://github.com/minetest/minetest/issues/8400
blachner
New member
 
Posts: 2
Joined: Sun Mar 17, 2019 8:26 pm

Re: Problems with texture scaling/orientation since Minetest

Postby paramat » Tue Mar 19, 2019 11:44 pm

The rotation fix is merged and will be in the soon-released 5.0.1.
Scaling nodeboxes was never officially supported, it happened by accident because nodeboxes were internally converted into meshes in MT 0.4.x (but are not in 5.0.0).
However, although fixing the scaling of nodeboxes is easy, scaling textures is not, so we may well work on making that possible, but probably not for 5.0.1 to not delay that.
paramat
Developer
 
Posts: 3344
Joined: Sun Oct 28, 2012 12:05 am
GitHub: paramat



Return to Modding Discussion



Who is online

Users browsing this forum: Yandex Bot [Bot] and 0 guests