Maxon Developers Maxon Developers
    • Documentation
      • Cinema 4D Python API
      • Cinema 4D C++ API
      • Cineware API
      • ZBrush Python API
      • ZBrush GoZ API
      • Code Examples on Github
    • Forum
    • Downloads
    • Support
      • Support Procedures
      • Registered Developer Program
      • Plugin IDs
      • Contact Us
    • Categories
      • Overview
      • News & Information
      • Cinema 4D SDK Support
      • Cineware SDK Support
      • ZBrush 4D SDK Support
      • Bugs
      • General Talk
    • Unread
    • Recent
    • Tags
    • Users
    • Login

    Is there any way to get mouse drawn direction information?

    Cinema 4D SDK
    python r19 r20 r21
    3
    4
    603
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • gheyretG
      gheyret
      last edited by

      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:
      asdadwdasd.png

      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😅

      www.boghma.com

      1 Reply Last reply Reply Quote 0
      • ferdinandF
        ferdinand
        last edited by ferdinand

        Hi,

        1. You will have to overdraw ToolData.MouseInput to implement this. Check out the liquid painter SDK Example on github for details.
        2. 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.
        3. 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!)
        4. 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).
        5. 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.
        6. You will probably also have to do some input filtering to get a smooth spline.

        Cheers
        zipit

        MAXON SDK Specialist
        developers.maxon.net

        gheyretG 1 Reply Last reply Reply Quote 0
        • gheyretG
          gheyret @ferdinand
          last edited by

          @zipit
          No spline path,just surface of object

          www.boghma.com

          1 Reply Last reply Reply Quote 0
          • S
            s_bach
            last edited by

            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

            MAXON SDK Specialist

            Development Blog, MAXON Registered Developer

            1 Reply Last reply Reply Quote 0
            • First post
              Last post