Is there any way to get mouse drawn direction information?
-
Hello! guys! I want to make a tool plugin like a brush tool, and i can use this tool draw objects on other object surface.And now, i want my drawn object to follow the direction of my mouse, like this:
Actually, i have a simple idea for this;
next_obj = parent_obj.GetDown().GetNext() while next_obj: pos = -(next_obj.GetPred().GetRelPos() - next_obj.GetRelPos()) normalized = pos.GetNormalized() rot = c4d.utils.VectorToHPB(normalized) pred = obj.GetPred() pred.SetRelRot(rot) next_obj = next_obj.GetNext()
But I think this method is too forced, I don't know if I can get the mouse direction information
-
Hi,
- You will have to overdraw
ToolData.MouseInput
to implement this. Check out the liquid painter SDK Example on github for details. - If you don't mind some overhead, you could just use some of C4D's existing tools (mograph or something else) to generate the ouput of your tool.
- It is also not quite clear to me what you want to do: Align the objects to the surface of an object or align them to the path of a spline on the surface of an object ? (these are not the same!)
- You should use matrices / frames to orient your objects (also do error checking, your code will raise an unhandeled excpetion if op has no children).
- Depending on what you want to do, you have to either construct your object frames with the surface normal of the polygon under the cursor, or construct your frames along a spline (similar to your code, which however will ingore banking). To construct a smooth series of frames along a spline you will have to use an algrithm like the parallel transport frame algorithm or the rotation minimizing frame algorithm.
- You will probably also have to do some input filtering to get a smooth spline.
Cheers
zipit - You will have to overdraw
-
@zipit
No spline path,just surface of object -
Hello,
there is no thing as mouse direction. The mouse has a position. The direction is the result of comparing two mouse positions.
as @zipit stated, you can create a tool that implements MouseInput(). Within
MouseInput()
you can use ViewportSelect.PickObject() to check what object and what point the mouse is currently over (Using BaseView.SW()). You can store the previous mouse position and compare it to the current mouse position to calculate the direction.Unfortunately, there is an issue with the Python version of PickObject() (How do I find the z-depth with Python ViewportSelect.PickObject()?), so you might have to implement your idea as a C++ plugin. You find some code in the pickobject.cpp example.
best wishes,
Sebastian