View Full Version : Knife cut using projected spline?
chromecity 01-17-2007, 06:44 PM Okay, this seems like it might be fairly easy, but I went digging through R10 and the vast amount of plug-ins I use and I can't figure out how to do this in C4D...
Is there a straight-forward way to perform a knife cut on an object, using a projected spline to create the cut? And if there's no direct way, what's the best work-around?
|
|
Per-Anders
01-17-2007, 07:43 PM
There's no direct plugin for that that I know of, the easiest workaround to do this is to create the spline, create an extrudenurbs of the spline without caps, then boolean A without B (object to cut followed by extrudenurbs) and "Hide new edges" turned on. It should be possible to write a script to automate this.
chromecity
01-17-2007, 08:56 PM
Hi Per-Anders,
Thanks for your advice. I had tried booleaning the extruded spline as well (although I hadn't chosen to hide the new edges) but things can get real ugly real fast. I suppose there's no getting around the fact that a lot of geometry needs to be created to support this sort of activity, especially when dealing with curved surfaces and curvy splines. Hmmm. It seems like it would be such a useful ability to have, but probably isn't very doable outside of a fully NURBS-reliant system.
Per-Anders
01-17-2007, 09:06 PM
Well here's a script that does the job in a single click for you. But yes it will always create heavier geometry i'm afraid, you can try changing the spline interpolation and reducing things so that there are less points in the cutting spline.
FindActiveType(doc, op, type)
{
while (op)
{
if (op->GetBit(BIT_ACTIVE))
if (op->IsInstanceOf(type)) return op;
if (op->GetDown())
{
op = op->GetDown();
}
else
{
while (!op->GetNext())
{
op = op->GetUp();
}
if (op) op = op->GetNext();
}
}
return NULL;
}
main(doc, op)
{
var data = new(BaseContainer);
data->SetData(MDATA_CURRENTSTATETOOBJECT_INHERITANCE, TRUE);
var spline = FindActiveType(doc, doc->GetFirstObject(), Ospline);
if (spline == NULL) return;
var poly = FindActiveType(doc, doc->GetFirstObject(), Opolygon);
if (poly == NULL) return;
var pspline = spline->GetPrev();
var uspline = spline->GetUp();
var ppoly = poly->GetPrev();
var upoly = poly->GetUp();
doc->StartUndo();
var boole =AllocObject(Oboole);
doc->InsertObject(boole, NULL, NULL);
if (!boole) return;
doc->AddUndo(UNDO_NEW, boole);
var extrude = AllocObject(Oextrude);
if (!extrude) return;
doc->InsertObject(extrude, boole, NULL);
doc->AddUndo(UNDO_NEW, extrude);
var cam = doc->GetActiveBaseDraw()#BASEDRAW_DATA_CAMERA;
if (!cam) return;
var smg = spline->GetMg();
extrude->SetMg(smg);
doc->AddUndo(UNDO_CHANGE, spline);
spline->Remove();
spline->InsertUnder(extrude);
spline->SetPosition(vector(0.0,0.0,0.0));
spline->SetRotation(vector(0.0,0.0,0.0));
spline->SetScale(vector(1.0,1.0,1.0));
extrude#EXTRUDEOBJECT_MOVE:VECTOR_Z = 100000.0;
extrude#CAP_START = 0;
extrude#CAP_END = 0;
boole#BOOLEOBJECT_TYPE = BOOLEOBJECT_TYPE_WITHOUT;
boole#BOOLEOBJECT_HIGHQUALiTY = TRUE;
boole#BOOLEOBJECT_HIDE_NEW_EDGES = TRUE;
doc->AddUndo(UNDO_CHANGE, poly);
poly->Remove();
poly->InsertUnder(boole);
if ( !SendModelingCommand( MCOMMAND_CURRENTSTATETOOBJECT, doc, boole, data, MODIFY_ALL)) return;
var newobj = doc->GetActiveObject();
var newchl = newobj->GetDown();
doc->AddUndo(UNDO_NEW, newobj);
if (uspline == poly) uspline = newchl;
if (pspline == poly) pspline = newchl;
if (upoly == spline || ppoly == spline)
{
doc->AddUndo(UNDO_CHANGE, spline);
spline->Remove();
doc->InsertObject(spline, uspline, pspline);
doc->AddUndo(UNDO_CHANGE, newchl);
newchl->Remove();
doc->InsertObject(newchl, upoly, ppoly);
}
else
{
doc->AddUndo(UNDO_CHANGE, newchl);
newchl->Remove();
doc->InsertObject(newchl, upoly, ppoly);
doc->AddUndo(UNDO_CHANGE, spline);
spline->Remove();
doc->InsertObject(spline, uspline, pspline);
}
doc->AddUndo(UNDO_CHANGE, spline);
spline->SetMg(smg);
doc->AddUndo(UNDO_DELETE, poly);
poly->Remove();
doc->AddUndo(UNDO_DELETE, extrude);
extrude->Remove();
doc->AddUndo(UNDO_DELETE, boole);
boole->Remove();
doc->AddUndo(UNDO_DELETE, newobj);
newobj->Remove();
doc->EndUndo();
}
just assign it a shortcut or icon and you're off. Make sure that you move the spline in front of the mesh, and have the mesh (make sure it's editable) and the spline selected.
tcastudios
01-17-2007, 09:20 PM
I thinks AvK (Arndt) have/had something called EdgeExtruder that could use splines.
I think there is a bit of manual input in the process, but there was some pictures how it was used and it looked good.
Cheers
Lennart
chromecity
01-17-2007, 09:21 PM
Hi Per-Anders,
Well thank you very much for the script. I don't seem to know enough about its usage requirements. For example, I have tried executing it in scene that contains just an editable spline and an editable polygon object (in that order, as you stipulated). Whether I have...
...okay, as I was typing this, I noticed that you had updated your last post. Still, with the spline first in the object manager, both items editable, and both selected, executing the script does not appear to be doing anything for me? Is there something else I might need to do?
Per-Anders
01-17-2007, 09:23 PM
Hi Per-Anders,
Well thank you very much for the script. I don't seem to know enough about its usage requirements. For example, I have tried executing it in scene that contains just an editable spline and an editable polygon object (in that order, as you stipulated). Whether I have...
...okay, as I was typing this, I noticed that you had updated your last post. Still, with the spline first in the object manager, both items editable, and both selected, executing the script does not appear to be doing anything for me? Is there something else I might need to do?
Not in front of the mesh in the OM, but in the viewport, it has to be between your camera and the object, as it only cuts what's behind the spline. Haven't tested it to see if it works in the orthographic views yet. The spline and poly object can be anywhere at all in the OM, it's only important that they're both selected.
chromecity
01-17-2007, 09:47 PM
Hi Per-Anders,
Okay, I did not understand that was what you meant, but happened to have the spline in front by chance. I did not have a camera initially, but added one in case it is necessary. Still no luck.
I've put the R10 scene I've been attempting to use, along with an image of how I've been attempting to use it (perspective view with both items selected, spline in front, and executing the script either from the script manager or a shortcut), into a small zip file you can download here (http://www.chromecity.com/C4D/SplineEtch.zip). Perhaps you could verify that the script works with that scene?
-------------------------
Hi Lennart,
Back in the R7 timeframe, I spent a fair bit of time in Arndt's book (the last one published in English, I believe) which used a version of EdgeExtrude and a couple of his other plug-ins throughout. I'm pretty sure I also purchased EdgeExtrude Pro somewhere along the line, but haven't used it in so long that I don't recall if it could do any of this. I'll try to dig it up to refresh my memory of its capabilities. Thanks.
tcastudios
01-17-2007, 09:53 PM
There is a small typo in the script.Line 79 I think
if (!SendModelingCommand(MCOMMAND_CURRENTSTATETOOBJEC T, doc, boole, data, MODIFY_ALL)) return;
should be;
if (!SendModelingCommand(MCOMMAND_CURRENTSTATETOOBJECT, doc, boole, data, MODIFY_ALL)) return;
see if it helps.
Darn its not a typo. What ever I do it becommes the same fault (here at the post).
It is the T ending that have a "hole" on the script.
For some reason I can't get rid of it either here.
Cheers
Lennart
Per-Anders
01-17-2007, 10:02 PM
It works here, though because it's a closed spline it cuts a hole rather than cuts the polygons (also you don't need a new camera in there, it's very simple doesn't require any complex setup), TCA your change still leaves the "typo" it's a problem to dow ith CGTalks forum software, sometimes it just adds spaces where there shouldn't be any from copied in text, but you are right, that space shouldn't be there. I've now modified it so that it's not there and the script should now work (try recopying/pasting it)
coincidentally to go with this here's a new script htat does use the current camera location (doesn't require you to add any cameras) to project the spline rather than the splines own matrix
FindActiveType(doc, op, type)
{
while (op)
{
if (op->GetBit(BIT_ACTIVE))
if (op->IsInstanceOf(type)) return op;
if (op->GetDown())
{
op = op->GetDown();
}
else
{
while (!op->GetNext())
{
op = op->GetUp();
}
if (op) op = op->GetNext();
}
}
return NULL;
}
main(doc, op)
{
var data = new(BaseContainer);
data->SetData(MDATA_CURRENTSTATETOOBJECT_INHERITANCE, TRUE);
var spline = FindActiveType(doc, doc->GetFirstObject(), Ospline);
if (spline == NULL) return;
var poly = FindActiveType(doc, doc->GetFirstObject(), Opolygon);
if (poly == NULL) return;
var pspline = spline->GetPrev();
var uspline = spline->GetUp();
var ppoly = poly->GetPrev();
var upoly = poly->GetUp();
doc->StartUndo();
var boole =AllocObject(Oboole);
doc->InsertObject(boole, NULL, NULL);
if (!boole) return;
doc->AddUndo(UNDO_NEW, boole);
var extrude = AllocObject(Oextrude);
if (!extrude) return;
doc->InsertObject(extrude, boole, NULL);
doc->AddUndo(UNDO_NEW, extrude);
var cam = doc->GetActiveBaseDraw()#BASEDRAW_DATA_CAMERA;
if (!cam) return;
var smg = spline->GetMg();
extrude->SetMg(cam->GetMg());
doc->AddUndo(UNDO_CHANGE, spline);
spline->Remove();
spline->InsertUnder(extrude);
spline->SetMg(smg);
extrude#EXTRUDEOBJECT_MOVE:VECTOR_Z = 100000.0;
extrude#CAP_START = 0;
extrude#CAP_END = 0;
boole#BOOLEOBJECT_TYPE = BOOLEOBJECT_TYPE_WITHOUT;
boole#BOOLEOBJECT_HIGHQUALiTY = TRUE;
boole#BOOLEOBJECT_HIDE_NEW_EDGES = TRUE;
doc->AddUndo(UNDO_CHANGE, poly);
poly->Remove();
poly->InsertUnder(boole);
if ( !SendModelingCommand( MCOMMAND_CURRENTSTATETOOBJECT, doc, boole, data, MODIFY_ALL)) return;
var newobj = doc->GetActiveObject();
var newchl = newobj->GetDown();
doc->AddUndo(UNDO_NEW, newobj);
if (uspline == poly) uspline = newchl;
if (pspline == poly) pspline = newchl;
if (upoly == spline || ppoly == spline)
{
doc->AddUndo(UNDO_CHANGE, spline);
spline->Remove();
doc->InsertObject(spline, uspline, pspline);
doc->AddUndo(UNDO_CHANGE, newchl);
newchl->Remove();
doc->InsertObject(newchl, upoly, ppoly);
}
else
{
doc->AddUndo(UNDO_CHANGE, newchl);
newchl->Remove();
doc->InsertObject(newchl, upoly, ppoly);
doc->AddUndo(UNDO_CHANGE, spline);
spline->Remove();
doc->InsertObject(spline, uspline, pspline);
}
doc->AddUndo(UNDO_CHANGE, spline);
spline->SetMg(smg);
doc->AddUndo(UNDO_DELETE, poly);
poly->Remove();
doc->AddUndo(UNDO_DELETE, extrude);
extrude->Remove();
doc->AddUndo(UNDO_DELETE, boole);
boole->Remove();
doc->AddUndo(UNDO_DELETE, newobj);
newobj->Remove();
doc->EndUndo();
}
Rantin Al
01-17-2007, 10:39 PM
AHi Per, that script works great, just like the China Syndrome.:)
Is there any way of restricting it to a selection so that it doesn't cut all the way through the backface of a solid object.
I tried a selection and hiding but it cut right through regardless.
Cheers, Alan.
Edit: A workaround is to Split a selection, delete on original, apply the Cutter to the split selection, Connect and Optimize.
Not very elegant, but it allows the use of the Cutter.
chromecity
01-17-2007, 10:41 PM
Hi Per-Anders & Lennart,
Yep, it was the spaced-out T that Lennart found which was making mine not work. I did not have the console open due to limited screen space on my laptop. If I had been smart enough to check it though, I would have seen the script failure on line 77. Doh. Thanks, Lennart.
And thanks for the additional script, Per-Anders. Any thoughts on 'etching' closed splines?
Per-Anders
01-17-2007, 10:48 PM
There's no way to do that with this, You can always do a current state to object on the spline itself then use that, and with any luck all you'll need to do to finish off the path will then be a single knife cut.
CGTalk Moderation
01-17-2007, 10:48 PM
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.