Snap mouse pointer to object?
-
THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED
On 31/03/2012 at 09:44, xxxxxxxx wrote:
User Information:
Cinema 4D Version: 12
Platform: Windows ;
Language(s) : C++ ;---------
I've long wished for bezier spline tools in C4D. So that we can paint smooth accurate custom curves.
The only way I see to draw a custom curved paint stroke in C4D is to use the spline shader. Which relies on UV's. Making it not very predictable or interactive.Is there a way to make the mouse pointer snap to a spline in the API?
Or maybe a way to turn an object into a paintbrush somehow?
If an object could be used to paint another object. Then I could snap that object to a spline path and create smooth custom paint strokes that way.-ScottA
-
THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED
On 31/03/2012 at 10:19, xxxxxxxx wrote:
-
THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED
On 31/03/2012 at 11:12, xxxxxxxx wrote:
That's cool.
But it doesn't help me learn how to make it myself.-ScottA
-
THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED
On 02/04/2012 at 10:29, xxxxxxxx wrote:
You may check the Snapping library and its main class, DetectSnapping.
If you want to use it in a tool plugin, here is how to initialize and invoke this class in ToolData::MouseInput() :Bool MyToolData::MouseInput(BaseDocument* doc, BaseContainer& data, BaseDraw* bd, EditorWindow* win, const BaseContainer& msg) { AutoAlloc<DetectSnapping> snap; if (!snap) return FALSE; snap->Init(doc, bd, NULL, Vector(), 0, FALSE, TRUE, TRUE); Vector delta; Vector pos = bd->SW(Vector(Real(msg.GetLong(BFM_INPUT_X)), Real(msg.GetLong(BFM_INPUT_Y)), RCO 0)); if (snap->SnapTo(pos, &delta)) { pos += delta; } return TRUE; }
-
THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED
On 02/04/2012 at 11:53, xxxxxxxx wrote:
Thanks Yannick.
Sorry for being stupid.
But when I use that code in a tool plugin. Nothing happens.-ScottA
-
THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED
On 02/04/2012 at 14:13, xxxxxxxx wrote:
Hi,
Yannick code is fine you only have to apply it in your case.
here a little example try to put it in liquid tool in c4dsdk example and remember to turn on and set snap settings:Bool LiquidToolData::MouseInput(BaseDocument *doc, BaseContainer &data;, BaseDraw *bd,EditorWindow *win, const BaseContainer &msg;) { //get mouse position Real mx = msg.GetReal(BFM_INPUT_X); Real my = msg.GetReal(BFM_INPUT_Y); Vector pos = bd->SW(Vector(mx, my, 500)); // bring mouse pos in world space Vector delta = Vector(); BaseObject *active = doc->GetActiveObject(); // get the active object LONG button; switch (msg.GetLong(BFM_INPUT_CHANNEL)) { case BFM_INPUT_MOUSELEFT : button=KEY_MLEFT; break; case BFM_INPUT_MOUSERIGHT: button=KEY_MRIGHT; break; default: return TRUE; } if (!active) // if no active object create a new sphere and inser it in document { active = BaseObject::Alloc(Osphere); if (!active) return FALSE; doc->InsertObject(active, NULL, NULL, TRUE); active->SetAbsPos(pos); } AutoAlloc<DetectSnapping>snap; // alloc the snap if (!snap) return FALSE; snap->Init(doc, bd, NULL, Vector(), 0, FALSE, TRUE, TRUE); // initialize snap Real dx,dy; BaseContainer bc; BaseContainer device; win->MouseDragStart(button,mx,my,MOUSEDRAGFLAGS_DONTHIDEMOUSE|MOUSEDRAGFLAGS_NOMOVE); while (win->MouseDrag(&dx;,&dy;,&device;)==MOUSEDRAGRESULT_CONTINUE) // start drag { // increment mouse position during drag mx+=dx; my+=dy; pos = bd->SW(Vector(mx, my, 500)); // update pos if (snap->SnapTo(pos, δ)) // if point snap anywhere { pos += delta; // pos will be updated with snapped delta } if (active) active->SetAbsPos(pos); // set the object position to the new one! DrawViews(DRAWFLAGS_ONLY_ACTIVE_VIEW|DRAWFLAGS_NO_THREAD|DRAWFLAGS_NO_ANIMATION); //update viewport } win->MouseDragEnd(); // reset viewport status EventAdd(); return TRUE; }
i hope this help
Franz -
THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED
On 02/04/2012 at 15:24, xxxxxxxx wrote:
Thank you Franz. That does make it more clear.
That gives me a way to snap an object to a spline. While also staying attached to the mouse cursor.
Acting like a brush.
But now I have to somehow paint with that object. Like that paint shader does.Any ideas how I would accomplish that?
-ScottA