On 04/05/2017 at 17:36, xxxxxxxx wrote:
Excuse me if this isn't the correct place to post this... I'm new here. :)
I have a spline in the shape of a branching tree. Currently, each branch is it's own segment and I would like to convert it to a spline object with contiguous branches (so that scale would work correctly if I were to sweep the branch path). While my example is a binary tree I would like to be able to do this for any type of segmented tree.
_<_img src="http://phinary.net/shared/c4d/segmented_tree.png" height="344" width="473" border="0" /_>_
One of the dirty ways to deal with this in the viewport is to Extrude the Spline->Convert to Poly->Optimize the Poly->Select similar Poly Edge -> Convert Edge to Spline.
It's not pretty, but it works. I could mimic that in python, but I'm looking for something more elegant. I assumed a more pythonic way to deal with this problem would be to iterate hierarchies of segments and was curious if there's an existing function in the SDK or a pythonic approach that might best suited to help with this.
On 05/05/2017 at 06:33, xxxxxxxx wrote:
Hi The_Monkey, thanks for writing us and mostly important welcome in our community.
With reference to your request, it's not possible to create a single-segment branched spline. Considering the simple case of a branched spline shaped as a "Y", in the worst case you'll end up in having three branches, whilst in the best situation it will turn to be made of two branches. This is due to the fact that a segment should describe a single not-branched curve (whatever it is opened or closed) and considering the "Y" the first segment should describe the two angled lines whilst another segment should describe the vertical line.
This is also confirmed by running basic checks (in terms of counting the number of points and segments ) on the curve before and after your optimization workflow.
Considering that the SplineObject() inherits from PointObject() you can be easily provided with the list of points representing the passing points of the spline (depending on the spline type) and querying the segments present in the spline you could get informed on how many points (of the previous) belongs to that specific segment.
Unfortunately, to answer your final question, there's no SDK exposed function which starting from the points list optimizes the number of segments joining those segment sharing a point but there are plenty of options in the SDK to arrange a code doing it elegantly.
On 06/05/2017 at 06:02, xxxxxxxx wrote:
Thank you for the quick and thorough reply Riccardo. It's always very appreciated.
I had a feeling this would be the answer. As I began writing a function to do this I thought "surely, I'm not the first person to need this". ;)
For the sake of further clarity, I wasn't wanting to create a spline with one segment (I do recognize the impossibility of this). I was just interested in the "least" number of segments+points. I agree that in your "best case scenario" the scale still isn't quite perfect, but sometimes when you have a very deep/dense tree it's harder to discern the scale disparity... and that's usually all I need.