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

    Snapping Plugin Example ? [SOLVED]

    SDK Help
    0
    15
    1.2k
    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.
    • H
      Helper
      last edited by

      On 04/11/2014 at 08:22, xxxxxxxx wrote:

      sounds great - thanks sebastian

      1 Reply Last reply Reply Quote 0
      • H
        Helper
        last edited by

        On 11/11/2014 at 00:25, xxxxxxxx wrote:

        Hello,

        I just uploaded a simple SnapData example. We may include it in the SDK with the next release.

        Download SnapData example (ZIP)

        Best wishes,
        Sebastian

        1 Reply Last reply Reply Quote 0
        • H
          Helper
          last edited by

          On 03/12/2014 at 02:51, xxxxxxxx wrote:

          Thanks Sebastian,

          the example is great I stuck on the distance calculation.

          I try to calc a offset from the activeObject to subpoints and calculate for each subpoints

          second question - 
          i like to rotate the activeObject - snapping to fit the rotation of the target point - but when move it away to rotate on origin rotation

          Thanks

          Bool MagnetsData::Snap(const Vector& p, const SnapStruct& ss, SnapPoint& result)
          {
              const BaseObject* const activeObject = ss.doc->GetActiveObject();
            
          	...
            
          	Vector screenPos = ss.bd->WS(p);
               screenPos.z = 0.0f;
          	Float64 minDistance = LIMIT<Float64>::Max();
               _targetObject = nullptr;
            
          for(Int32 si = 0; si < SubSourceObjectCount; ++si)
              {
          	//calculate offset to subobjects 
          	const Matrix sourcesubobjectOffset = subobejct->GetMg() - activeObject->GetMg();
          	Vector subscreenPos = screenPos - sourcemagnetOffset.off;
          	
            
          	for(Int32 i = 0; i < targetsObjectCount; ++i)
                  {
          	...
          	const Vector objectPosition	= _targetObject->GetMg().off;
                          
                          Vector objectScreenSpacePosition	= ss.bd->WS(objectPosition);
                          objectScreenSpacePosition.z				= 0;
                          
                          const Vector difference = subscreenPos - objectScreenSpacePosition;
                          
                          const Float64 screenSpaceDistance = difference.GetSquaredLength();
          		...	
          		}
          	}
          }
           
          
          1 Reply Last reply Reply Quote 0
          • H
            Helper
            last edited by

            On 03/12/2014 at 06:49, xxxxxxxx wrote:

            Hello,

            you are calculating the world space transformation between subobject and activeObject. Then you are somehow subtracting this transformation's translation member from a screen space position. This won't make sense. You have to calculate the screen space position of the subobjects when you want to compare the screen space positions.

            While the snapping system does support matrix snapping it depends on the used tools how the result matrix is used. If you want to handle the rotation of the moved object you may have to write your own tool that uses the SnapCore[URL-REMOVED] class.

            For questions no longer related to the original topic please open a new thread. Thanks.

            Best wishes,
            Sebastian


            [URL-REMOVED] @maxon: This section contained a non-resolving link which has been removed.

            1 Reply Last reply Reply Quote 0
            • H
              Helper
              last edited by

              On 03/12/2014 at 08:50, xxxxxxxx wrote:

              i tried to calculate the offset from the original object to the sub object - can you give me the line to calculate the correct distance in the direction of view ?

              1 Reply Last reply Reply Quote 0
              • H
                Helper
                last edited by

                On 03/12/2014 at 09:53, xxxxxxxx wrote:

                Hello,

                what exactly do you mean with "correct distance in the direction of view"?

                Best wishes,
                Sebastian

                1 Reply Last reply Reply Quote 0
                • H
                  Helper
                  last edited by

                  On 03/12/2014 at 11:08, xxxxxxxx wrote:

                  not the real distance - only the 2d distance in the actual view

                  1 Reply Last reply Reply Quote 0
                  • H
                    Helper
                    last edited by

                    On 04/12/2014 at 01:41, xxxxxxxx wrote:

                    Hello,

                    to calculate the screen space distance of two elements you have to calculate the screen space position of these elements. Simply use a BaseView[URL-REMOVED]'s WS()[URL-REMOVED] function to get the screen space position. As shown in the example you have to set the z-value of the result vectors to zero when you want to get the 2D distance by handling these vectors.

                      
                     Vector screenSpacePosA = ss.bd->WS(objectPositionA);  
                     screenSpacePosA.z = 0;  
                     Vector screenSpacePoB = ss.bd->WS(objectPositionB);  
                     screenSpacePoB.z = 0;  
                     Vector difference = screenSpacePosA - screenSpacePoB;  
                    

                    best wishes,
                    Sebastian


                    [URL-REMOVED] @maxon: This section contained a non-resolving link which has been removed.

                    1 Reply Last reply Reply Quote 0
                    • H
                      Helper
                      last edited by

                      On 04/12/2014 at 02:46, xxxxxxxx wrote:

                      thanks - now i get it

                      1 Reply Last reply Reply Quote 0
                      • H
                        Helper
                        last edited by

                        On 04/12/2014 at 04:13, xxxxxxxx wrote:

                        Is there a message snapping is correct released ?

                        1 Reply Last reply Reply Quote 0
                        • H
                          Helper
                          last edited by

                          On 04/12/2014 at 09:29, xxxxxxxx wrote:

                          Hello,

                          the snap system[URL-REMOVED] is build so a tool can use it to take advantage of different snap modes. There is no message sent in this context. To see how this works take a look at the SnapTool example in the SDK.

                          For questions no longer related to this thread's original topic please open a new thread. Thanks.

                          best wishes,
                          Sebastian


                          [URL-REMOVED] @maxon: This section contained a non-resolving link which has been removed.

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