Snapping Plugin Example ? [SOLVED]



  • On 24/10/2014 at 03:15, xxxxxxxx wrote:

    User Information:
    Cinema 4D Version:   16 
    Platform:      Mac OSX  ; 
    Language(s) :     C++  ;

    ---------
    Hey

    is there a snapping example ? i use the search but don`t fount one

    in the examples are a snap tool but with RegisterToolPlugin and not with refisterSnapPlugin

    Thanks



  • On 27/10/2014 at 00:54, xxxxxxxx wrote:

    Hello,

    currently there is no official SnapData example. Do you have any specific questions about this class?

    Best wishes,
    Sebastian



  • On 01/11/2014 at 03:19, xxxxxxxx wrote:

    Hey sebastian,

    thanks for your reply.

    I need a example or a bit more documentation to get an idea how I can build up a snapping plugin :(



  • On 03/11/2014 at 09:02, xxxxxxxx wrote:

    Hello,

    I'll write a simple example plugin showing how to use SnapData. It may take some days but when I'm done I'll share it online.

    Best wishes,
    Sebastian



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

    sounds great - thanks sebastian



  • 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



  • 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();
    		...	
    		}
    	}
    }
     
    


  • 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 class.

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

    Best wishes,
    Sebastian



  • 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 ?



  • 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



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

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



  • 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's WS() 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



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

    thanks - now i get it



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

    Is there a message snapping is correct released ?



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

    Hello,

    the snap system 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


Log in to reply