methusalah / SplineMesh

A Unity plugin to create curved content in real-time with bézier curves
https://twitter.com/dumas181
MIT License
1.05k stars 104 forks source link

SplineMeshTiling direction bug #48

Closed programming2012 closed 3 years ago

programming2012 commented 3 years ago

Hi I am using SplineMeshTiling. There are two nodes on Spline. The fields of Element 0 are: Position(0,0,0), Direction(0,0,0). The flelds of Element 1 are: Position(0,-10,0), Direction(0,-10,0). And then i add Mesh and Material to SplineMeshTiling. You can see something wrong on the Element 0. If you set Direction of Element 0 to (0,-1,0). The Mesh rendering is correct. Thanks.

methusalah commented 3 years ago

"Direction" may be confusing, as this vector is really the control point of the curve, in Cubic Bezier Curve vocabulary. This mean the actual direction vector is the vector going from Position to Direction. Therefore, if you have the same value in Position and Direction, there is no direction at all and the result will be wrong.

Note that the vector [Direction - Position] gives the direction of the curve, and its magnitude gives the strength of the curvature.

programming2012 commented 3 years ago

"Direction" may be confusing, as this vector is really the control point of the curve, in Cubic Bezier Curve vocabulary. This mean the actual direction vector is the vector going from Position to Direction. Therefore, if you have the same value in Position and Direction, there is no direction at all and the result will be wrong.

Note that the vector [Direction - Position] gives the direction of the curve, and its magnitude gives the strength of the curvature.

Thank you very much for your reply. In this sample, if the position and direction is same, Can it be understood that this is not a Bezier Curve, but a Line segment. From the point of view of code implementation, is this feasible? Just like I have a telephone pole, it is vertical, like a line segment. Thanks.

methusalah commented 3 years ago

If you want to have a straight line as a bezier curve, you will at least need to set a direction from the node "n" to the node "n+1". The length of the vector won't be relevant as there is no curvature, but will at least need to be smaller than half the distance between the node to avoid the curve going back and forth on the line.

Typically : Node 1 Position 0, 0, 0 Direction 0.01, 0, 0 Node 2 Position 1, 0, 0 Direction 1.01, 0, 0

In Pseudo code, you could have node1.Direction = node1.Position + (node2.Position - node1.position).normalized 0.01f; node2.Direction = node2.position + (node2.Position - node1.position).normalized 0.01f;

Please note that in SplineMesh, the forward and backward directions at a single node are always mirrored, and SplineNode.Direction represents the forward direction in the spline space. It's a limitation of the asset.

Le lun. 9 août 2021 à 17:49, programming2012 @.***> a écrit :

"Direction" may be confusing, as this vector is really the control point of the curve, in Cubic Bezier Curve vocabulary. This mean the actual direction vector is the vector going from Position to Direction. Therefore, if you have the same value in Position and Direction, there is no direction at all and the result will be wrong.

Note that the vector [Direction - Position] gives the direction of the curve, and its magnitude gives the strength of the curvature.

Thank you very much for your reply. In this sample, if the position and direction is same, Can it be understood that this is not a Bezier Curve, but a Line segment. From the point of view of code implementation, is this feasible? Just like I have a telephone pole, it is vertical, like a line segment. Thanks.

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/benoit-dumas/SplineMesh/issues/48#issuecomment-895335057, or unsubscribe https://github.com/notifications/unsubscribe-auth/AB5QKTWE3LYUE6CNU2XEQSTT372G7ANCNFSM5B2DJTCQ . Triage notifications on the go with GitHub Mobile for iOS https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Android https://play.google.com/store/apps/details?id=com.github.android&utm_campaign=notification-email .

programming2012 commented 3 years ago

Thank you very much