Points of Segment
Moderators: Víctor Paredes, Belgarath, slowtiger
- MehdiZangenehBar
- Posts: 114
- Joined: Wed Feb 07, 2024 7:17 pm
- Contact:
Points of Segment
We can get a segment of the shape using
M_Shape:GetEdge(edgeID, curveID, segID)
We can also get one of the points on the curve using:
M_Point:GetEndpointEdge(curveID, segID)
My question is how we can get second point?
In other word, any function to get two points that made a shape segment?
M_Shape:GetEdge(edgeID, curveID, segID)
We can also get one of the points on the curve using:
M_Point:GetEndpointEdge(curveID, segID)
My question is how we can get second point?
In other word, any function to get two points that made a shape segment?
Re: Points of Segment
Each point on the curve has its own ID, which is different from the ID of a point in the mesh.
If you have an endpoint on the curve and the curve itself, and you need to get the neighboring point, you can check the point's ID on the curve using M_Curve:PointID(point).
If PointID == 0, then the neighboring point will have the ID PointID + 1. If PointID ~= 0, then the neighboring point will have the ID PointID - 1.
If you have an endpoint on the curve and the curve itself, and you need to get the neighboring point, you can check the point's ID on the curve using M_Curve:PointID(point).
If PointID == 0, then the neighboring point will have the ID PointID + 1. If PointID ~= 0, then the neighboring point will have the ID PointID - 1.
- MehdiZangenehBar
- Posts: 114
- Joined: Wed Feb 07, 2024 7:17 pm
- Contact:
Re: Points of Segment
Thanks!KuzKuz wrote: ↑Mon Aug 12, 2024 11:10 pm Each point on the curve has its own ID, which is different from the ID of a point in the mesh.
If you have an endpoint on the curve and the curve itself, and you need to get the neighboring point, you can check the point's ID on the curve using M_Curve:PointID(point).
If PointID == 0, then the neighboring point will have the ID PointID + 1. If PointID ~= 0, then the neighboring point will have the ID PointID - 1.
I'm little confused,
Is it possible for you to write it like a functions?
Re: Points of Segment
Try taking a look at how my script MR Curve Tool works.
There's a lot of code related to points and curves.
If you can't figure it out, I will write the function you need.
https://mohoscripts.com/script/mr_curve_tool
There's a lot of code related to points and curves.
If you can't figure it out, I will write the function you need.
https://mohoscripts.com/script/mr_curve_tool
- MehdiZangenehBar
- Posts: 114
- Joined: Wed Feb 07, 2024 7:17 pm
- Contact:
Re: Points of Segment
Alright, I will write the code that returns the neighboring point on the curve. However, I recommend that you study other people's scripts.
You don't need to read 4740 lines of code to understand how curves and points work.
Use the search function to find methods related to curves and study how they are used.
That's how I learned.
You don't need to read 4740 lines of code to understand how curves and points work.
Use the search function to find methods related to curves and study how they are used.
That's how I learned.
- MehdiZangenehBar
- Posts: 114
- Joined: Wed Feb 07, 2024 7:17 pm
- Contact:
Re: Points of Segment
Thank you!KuzKuz wrote: ↑Tue Aug 13, 2024 11:03 am Alright, I will write the code that returns the neighboring point on the curve. However, I recommend that you study other people's scripts.
You don't need to read 4740 lines of code to understand how curves and points work.
Use the search function to find methods related to curves and study how they are used.
That's how I learned.
Yea, That is my method as well, but in this case I'm looking for a more spicific function that support's all conditions, not only cases you implemented in that code, so yes, I need help from you to write a fuction that covers all cases.
For example when point have more than one curve.
- MehdiZangenehBar
- Posts: 114
- Joined: Wed Feb 07, 2024 7:17 pm
- Contact:
Re: Points of Segment
Please take a look at my other topic to undrstand why I need that function: viewtopic.php?t=37310
The problem is when I iterate over Shape > Points, the point order goes in the wrong direction:
https://drive.google.com/file/d/1dJbbig ... sp=sharing
This script might help you to find it better:
The problem is when I iterate over Shape > Points, the point order goes in the wrong direction:
https://drive.google.com/file/d/1dJbbig ... sp=sharing
This script might help you to find it better:
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('Get Points Table', MOHO.MSG_BASE))
end
function MZ_Test_Script:HandleMessage(moho, view, msg)
MZ_Test_Script:GetPointsTable(moho)
end
-- **************************************************
-- Functions
-- **************************************************
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()
if MZ_Test_Script.counter < shape:CountPoints() then
local point = mesh:Point(shape:GetPoint(MZ_Test_Script.counter))
point.fSelected = true
print(MZ_Test_Script.counter)
if MZ_Test_Script.counter == 27 or MZ_Test_Script.counter == 31 then print('Point goes to the wrong direction.') end
MZ_Test_Script.counter = MZ_Test_Script.counter + 1
end
end
Re: Points of Segment
Can you describe in detail what this function should do? What is the final result you want to achieve? As I understand it, simply accessing the neighboring point won't be enough for you? Please clarify what you mean by "covers all cases"?MehdiZangenehBar wrote: ↑Tue Aug 13, 2024 11:19 amThank you!KuzKuz wrote: ↑Tue Aug 13, 2024 11:03 am Alright, I will write the code that returns the neighboring point on the curve. However, I recommend that you study other people's scripts.
You don't need to read 4740 lines of code to understand how curves and points work.
Use the search function to find methods related to curves and study how they are used.
That's how I learned.
Yea, That is my method as well, but in this case I'm looking for a more spicific function that support's all conditions, not only cases you implemented in that code, so yes, I need help from you to write a fuction that covers all cases.
For example when point have more than one curve.
Re: Points of Segment
If you just need to change the direction in your code:MehdiZangenehBar wrote: ↑Tue Aug 13, 2024 11:49 am Please take a look at my other topic to undrstand why I need that function: viewtopic.php?t=37310
The problem is when I iterate over Shape > Points, the point order goes in the wrong direction:
https://drive.google.com/file/d/1dJbbig ... sp=sharing
This script might help you to find it better: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('Get Points Table', MOHO.MSG_BASE)) end function MZ_Test_Script:HandleMessage(moho, view, msg) MZ_Test_Script:GetPointsTable(moho) end -- ************************************************** -- Functions -- ************************************************** 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() if MZ_Test_Script.counter < shape:CountPoints() then local point = mesh:Point(shape:GetPoint(MZ_Test_Script.counter)) point.fSelected = true print(MZ_Test_Script.counter) if MZ_Test_Script.counter == 27 or MZ_Test_Script.counter == 31 then print('Point goes to the wrong direction.') end MZ_Test_Script.counter = MZ_Test_Script.counter + 1 end end
Code: Select all
MZ_Test_Script.counter = nil
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)
if MZ_Test_Script.counter == nil then
MZ_Test_Script.counter = shape:CountPoints()-1
end
mesh:DeselectPoints()
if MZ_Test_Script.counter >= 0 then
local point = mesh:Point(shape:GetPoint(MZ_Test_Script.counter))
point.fSelected = true
print(MZ_Test_Script.counter)
if MZ_Test_Script.counter == 27 or MZ_Test_Script.counter == 31 then
print('Point goes to the wrong direction.')
end
MZ_Test_Script.counter = MZ_Test_Script.counter - 1
end
end
- MehdiZangenehBar
- Posts: 114
- Joined: Wed Feb 07, 2024 7:17 pm
- Contact:
Re: Points of Segment
Sorry, you didn't get it at all!