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

    How to join 2 spline objects?

    Scheduled Pinned Locked Moved PYTHON Development
    5 Posts 0 Posters 929 Views
    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 Offline
      Helper
      last edited by

      THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

      On 05/08/2012 at 14:06, xxxxxxxx wrote:

      Hello everybody. Another problem here. A Phython XPresso node gets three object link inputs. All are spline objects. I want the Python script to merge the content of the first and the second one into number 3. However I don't want the separate splines to be removed.
      I was thinking of cloning the objects, then using MCOMMAND_JOIN. But I want to merge them into the given object3 and not into a new object!
      Maybe there's a different much easier way, without using MCOMMAND_JOIN?
      Thanks for all your help!

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

        THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

        On 06/08/2012 at 01:48, xxxxxxxx wrote:

        Half done. I found the "manual" way to join all spline objects. However currently it creates just one spline using all points I create. Still have to find a way to separate these. Also the first spline point always has the position 0|0|0 (the first points of the input splines are not at 0|0|0).
        Think one part is still missing. Currently I think it's the segments. By now I couldn't find out how they work. All the separate splines have a segment count of 0. If I increase segment count on the target object, it will just create points but no splines. Using just one segment it connects all points.
        This is the relevant code:

        def Join2(lst, targetspline) :  
        	  
        	# empty target spline  
        	targetspline.ResizeObject(0)  
        	  
        	# add the points of each input spline  
        	for inputspline in lst:  
        		# allocate space for new points  
        		p_targetct = targetspline.GetPointCount()  
        		p_offset = p_targetct  
        		p_inputct = inputspline.GetPointCount()  
        		p_newct = p_targetct + p_inputct  
        		  
        		# allocate space for new segments  
        		s_targetct = targetspline.GetSegmentCount()  
        		s_offset = s_targetct  
        		s_inputct = inputspline.GetSegmentCount() + 1  
        		s_newct = s_targetct + s_inputct  
        		  
        		t_targetct = targetspline.GetTangentCount()  
        		t_offset = t_targetct  
        		t_inputct = inputspline.GetTangentCount()  
        		  
        		print "p_targetct:"+`p_targetct`  
        		print "p_inputct:"+`p_inputct`  
        		print "s_targetct:"+`s_targetct`  
        		print "s_inputct:"+`s_inputct`  
        		print "t_inputct:"+`t_inputct`  
        		  
        		targetspline.ResizeObject(p_newct, s_newct)  
        		  
        		# add points to target spline  
        		for id in range(0,p_inputct-1) :  
        			p = inputspline.GetPoint(id)  
        			targetspline.SetPoint(p_offset+id, p)  
        		  
        		# add segments to target spline  
        		for id in range(0,s_inputct-1) :  
        			s = inputspline.GetSegment(id)  
        			targetspline.SetSegment(s_offset+id, s['cnt'], s['closed'])  
        		  
        		# add tangents to target spline  
        		for id in range(0,t_inputct-1) :  
        			t = inputspline.GetTangent(id)  
        			targetspline.SetTangent(t_offset+id, t['vl'], t['vr'])  
        		  
        	targetspline.Message(c4d.MSG_UPDATE)  
        	return;  
        
        
        1 Reply Last reply Reply Quote 0
        • H Offline
          Helper
          last edited by

          THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

          On 06/08/2012 at 02:10, xxxxxxxx wrote:

          Unfortunately I cannot edit my posts... I did some research on another spline object. Segments are the way to go, however just increasing the segment count and copying the segment0 data from the other splines doesn't work. Think I'm missing something. But currently I have no clue what it is.

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

            THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

            On 06/08/2012 at 03:51, xxxxxxxx wrote:

            It feels weird to be the only one posting in this thread, however I almost found a solution. When it's working I'll share it here so that everyone who might have this problem in future can use it.
            The target spline now contains all separated input splines but now I have to calculate the spline points in relation to the target object's matrix. But I think it shouldn't be too hard to figure that out.

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

              On 26/01/2013 at 02:40, xxxxxxxx wrote:

              Hey,

              I got the same problem. Anyone an idea? What I have tried:

                
                
              LONG splinePointCount= spline->GetPointCount();  
              LONG splineSegmentCount= spline->GetSegmentCount();  
                
              spline->ResizeObject(splinePointCount*2, splineSegmentCount*2);  
                
                
              Vector* points = spline->GetPointW();  
              const Vector* newPoints = spline2->GetPointR();  
                
              for (int i = splinePointCount-1, k = 0; k < splinePointCount; k++, i++)  
              {  
                points[i] = newPoints[k];  
              }  
                
              Segment *segments = spline->GetSegmentW();  
              const Segment *newSegments = spline2->GetSegmentR();  
                
              for (int i = splineSegmentCount-1, k = 0; k < splineSegmentCount; k++, i++)  
              {  
                segments[i] = newSegments[k];  
              }  
                
              

              The result is not complete false:

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