View Full Version : Edge To Spline script needed
Hi. I need a script and am hoping someone here can help me out. I am designing some hair styles by modeling them first as a mesh and then running the Edge to Spline command on the finished mesh. I then explode the segments of the resulting spline to get a set of splines that I can then turn into hair guides. The problem is that many of the splines end up in the wrong direction, and then have to be checked and reversed if needed one by one.
Let me illustrate:
http://mvpny.com/EdgeToSpline/RunEdgeToSplineMV1.jpg
The above image shows a default plane with some edges selected.
If Edge To Spline is run on these edges, and the resulting spline is exploded with the Explode Segments command, you will find that one of the splines does not run in the same direction as the others. In this case it's just one spline that runs the wrong way, but in my meshes there are many more, and checking each is very tedious as there are many such splines to check.
http://mvpny.com/EdgeToSpline/SplineInWrongDirectionMV1.jpg
So, what I need is a script that will run the Edge To Spline Command, then run Explode Segments on the resulting spline. Then I need the script to check each of the resulting splines created by the Explode Segments command and see if the pre selected point is equal to point 0. If not, I need that spline to be reversed.
So to recap, this is what I need the script to do:
-----------------------------------
I have a polygon object with some edges selected as well as some points selected.
Edge to spline
This creates a spline object that is the child of the original mesh object
Select newly created spline
Explode segments (this creates a group of child splines)
Go to first newly created spline
Check if selected point is the first point. (Is equal to zero)
If not, reverse sequence.
Check next spline until all newly created splines are done.
I need this because currently the Edge to Spline command creates some splines that aren't sequenced in the order I need.
|
|
Little_Devil
11-08-2009, 07:05 AM
how are you generating splines created by explode spline command with a selection ?
can't test this right now, but aren't losing the exploded segments all their selections ?
dispite this fact - i think this is a quite complicated problem, if you are not setting up
a tight set of rules how the splines are facing each other. u need to determine some
kind of flow normal for the splines and search for nearby splines (all this with a messed
up datapool of reversed splines ...). doing it per hand will be faster than wrting a script.
edit : the automation of edges to spline > explode can be easily done by yourself with
the inbuilt record script command of c4d.
edit2 : cant test this too, but if i'm not mistaken all selected points in your example are
splinepoint 0. reverse spline reverts the spline - so the point order is also turned.
sry for my english :)
how are you generating splines created by explode spline command with a selection ?
can't test this right now, but aren't losing the exploded segments all their selections ?
dispite this fact - i think this is a quite complicated problem, if you are not setting up
a tight set of rules how the splines are facing each other. u need to determine some
kind of flow normal for the splines and search for nearby splines (all this with a messed
up datapool of reversed splines ...). doing it per hand will be faster than wrting a script.
edit : the automation of edges to spline > explode can be easily done by yourself with
the inbuilt record script command of c4d.
edit2 : cant test this too, but if i'm not mistaken all selected points in your example are
splinepoint 0. reverse spline reverts the spline - so the point order is also turned.
sry for my english :)
Thanks for your interest. The exploded splines do not lose their point selections. See this file which is a standard plane object that has been converted.
File (http://mvpny.com/EdgeToSpline/RunEdgeToSplineMV1.c4d)
If you run Edge to Spline on this file, and then explode the resulting spline, you will see that one of the splines has the first point on the other side, as in the illustration I attached before. Any points selected before the Edge To Spline selection will be retained even after the created spline is exploded. This should make it possible to preselect the points you want checked in the script.
Little_Devil
11-08-2009, 08:32 AM
hi,
just to clarify my math & coding skills are arather low, not to say inexistent :) i took a
short visit to our cip-pool to take a look at your file. first of all - i can't reproduce this
select some points -> explode spline > new splines have a selection . but this isn't
really a problem, because you have just selected the first point of a spline (point 0 as you
said). checking the points number for zero will alway return true, because a reversed spline
also has a reversersed point order (respectively this is what reverse is meant to do :). check
it in your own example with the structure manager.
so you will have to gather the data in a diffrent way. assuming u want to do this on hairstyle
mesh this task is getting incredible difficult (at least for my poor math skills). if there is no
way to do this and taking this rather simple hair style as an example :
http://farm4.static.flickr.com/3119/2891326017_a2d99d9c93.jpg
splines start on the forehead and end in the neck. (some are reversed)
1. place a null dumy "xyz" on the forehead
2. get poinz zeros position of each spline
3. check if there are more points which are closer to xyz than points which are farther
4. if true reverse the spline
just to stress it again my math & coding skills are low and might have overlook your
general idea ? correct me please if it is so ...
My apologizes. I had tested this several times and found that the preselected points were retained, but on further testing, I can't reproduce it. That freaks me out, but it looks like you're right. So that isn't going to work. So instead, what I will need is simply a script that will look at a set of already exploded splines that have points selected.
Ok, this should greatly simplify things. In this attached file:
File (http://mvpny.com/EdgeToSpline/TestIfSelectedPointIsFirstPointIfNotReverseMV1.c4d)
There are four splines, all of which have a point selection. If you run this script on the first spline only (already selected) the spline will be reversed. The only problem I have now is that this script is not working as it should with multiple selection. If you select all four splines in the file and run this script, the results will be incorrect.
GNHO(obj, stopAt)
{
if (!obj) return NULL;
var next;
if (next = obj->GetDown()) return next;
if (next = obj->GetNext()) return next;
var up = obj;
while (up = up->GetUp())
{
if (up == stopAt) return NULL;
if (next = up->GetNext()) return next;
}
}
main(doc,op)
{
doc->StartUndo();
var temp = doc->GetFirstObject();
while(temp)
{
if(temp->GetBit(BIT_AOBJ)==1)
{
var bs = temp->GetPointSelection();
if(!bs->IsSelected(0)) CallCommand(12141); // Reverse Sequence
}
temp = GNHO(temp,NULL);
}
doc->EndUndo();
}
Darter
11-11-2009, 12:15 PM
You need to call SendModelingCommand() explicitly for each spline.
This script recursively searches the scene for active splines with a single point selected. If the selected point isn't 0, the spline's point sequence will be reversed.
SplineReverse(doc, obj)
{
while(obj)
{
if(obj->GetType() == Ospline && obj->GetBit(BIT_AOBJ))
{
var bs = obj->GetPointSelection();
if(bs->GetCount() == 1 && !bs->IsSelected(0))
{
var bc = obj->GetContainer();
SendModelingCommand(MCOMMAND_SPLINE_REVERSE, doc, obj, bc, MODIFY_ALL);
}
}
SplineReverse(doc, obj->GetDown());
obj = obj->GetNext();
}
}
main(doc, op)
{
var obj = doc->GetFirstObject();
SplineReverse(doc, obj);
}
Perfect. Great thanks David. If you ever come to New York let me know. I owe you a beer!
Darter
11-13-2009, 11:35 AM
Mmmm, beer...
CGTalk Moderation
11-13-2009, 11:35 AM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.
vBulletin v3.0.5, Copyright ©2000-2012, Jelsoft Enterprises Ltd.