Points Order

Moho allows users to write new tools and plugins. Discuss scripting ideas and problems here.

Moderators: Víctor Paredes, Belgarath, slowtiger

Post Reply
User avatar
MehdiZangenehBar
Posts: 114
Joined: Wed Feb 07, 2024 7:17 pm
Contact:

Points Order

Post by MehdiZangenehBar »

I'm really confused about this,how we can get shape points in correct order?
If we recreate new shape based on those points, result would be very different.
Please take a look at the picture and sample file:
https://drive.google.com/file/d/1G8Ekqw ... sp=sharing
https://drive.google.com/file/d/10Eo_7- ... sp=sharing
Any possible way to get shape points in correct order?
User avatar
MehdiZangenehBar
Posts: 114
Joined: Wed Feb 07, 2024 7:17 pm
Contact:

Re: Points Order

Post by MehdiZangenehBar »

Please! someone help me!
User avatar
hayasidist
Posts: 3841
Joined: Wed Feb 16, 2011 8:12 pm
Location: Kent, England

Re: Points Order

Post by hayasidist »

it looks as though you're using the wrong point reference number to draw. take a look at https://mohoscripting.com/methods/782 for an explanation of "point sequence in curve" vs "point number in mesh"


also, to draw a closed shape you need to do (e.g.)

one AddLonePoint https://mohoscripting.com/methods/843
some AppendPoint https://mohoscripting.com/methods/844
then close the loop with a WeldPoints https://mohoscripting.com/methods/846

For an example, take a look at HS_Shape:MakeLoop in hs_shape.lua: https://mohoscripts.com/script/hs_shape
User avatar
MehdiZangenehBar
Posts: 114
Joined: Wed Feb 07, 2024 7:17 pm
Contact:

Re: Points Order

Post by MehdiZangenehBar »

hayasidist wrote: Fri Aug 16, 2024 12:35 pm it looks as though you're using the wrong point reference number to draw. take a look at https://mohoscripting.com/methods/782 for an explanation of "point sequence in curve" vs "point number in mesh"
I undrstand there is difference between mesh,curve and shape points. Drawing is not my problem, I'm looking for a correct SEQUENCE OF POINTS that created a shape.
I just created another example and script to TEST:

https://drive.google.com/file/d/1oPlX_z ... sp=sharing

if you open up the scene and hit "Select Point" button several times, you can see points are selected one by one based on Shape:GetPoint() function. (I created curves in different direction on purpose)

Code: Select all

-- **************************************************
-- General information about this script
-- **************************************************

ScriptName = "MZ_Test_Script"
MZ_Test_Script = {}

function MZ_Test_Script:OnMouseDown(moho, mouseEvent)
end

function MZ_Test_Script:DoLayout(moho, layout)
	layout:AddChild(LM.GUI.Button('Select Point', MOHO.MSG_BASE))
end

function MZ_Test_Script:HandleMessage(moho, view, msg)
    MZ_Test_Script:GetPointsTable(moho)
end

-- **************************************************
-- Functions
-- **************************************************

function MZ_Test_Script:NextPointOnCurve(mesh,shape,point_1)
    for i = 0 , point_1:CountCurves() - 1 do
        local where_1 = -1
        local curve_1, where_1 = point_1:Curve(i, where_1)
        for j = 0, shape:CountPoints() -1 do
            local point_2 = mesh:Point(shape:GetPoint(j))
            for k = 0 , point_2:CountCurves() - 1 do
                local where_2 = -1
                local curve_2, where_2 = point_2:Curve(k, where_2)
                if curve_2 == curve_1 and where_2 == where_1 + 1 then return point_2 end
            end
        end
    end
end

function MZ_Test_Script:TableHasValue(_table,value)
    for i,v in ipairs(_table) do
        if v == value then return true end
    end
    return false
end

function MZ_Test_Script:UniqueTableInsert(_table,value)
    if MZ_Test_Script:TableHasValue(_table,value) == false then table.insert(_table,value) end
end

MZ_Test_Script.counter = 0

function MZ_Test_Script:GetPointsTable(moho)
    local doc = moho.document
    local frame = moho.frame
	local layer = moho:LayerAsVector(moho.layer)
	local mesh = layer:Mesh()
	local shape = mesh:Shape(0)

    mesh:DeselectPoints()
    local point = mesh:Point(shape:GetPoint(MZ_Test_Script.counter))
    point.fSelected = true
    MZ_Test_Script.counter = MZ_Test_Script.counter + 1
    if MZ_Test_Script.counter == shape:CountPoints() then MZ_Test_Script.counter = 0 end
end
Last edited by MehdiZangenehBar on Fri Aug 16, 2024 2:41 pm, edited 1 time in total.
User avatar
MehdiZangenehBar
Posts: 114
Joined: Wed Feb 07, 2024 7:17 pm
Contact:

Re: Points Order

Post by MehdiZangenehBar »

I undrstand moho don't give us a correct sequence of points, how we can rebuild it from scratch?
User avatar
MehdiZangenehBar
Posts: 114
Joined: Wed Feb 07, 2024 7:17 pm
Contact:

Re: Points Order

Post by MehdiZangenehBar »

Any idea?
Post Reply