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
    • Recent
    • Tags
    • Users
    • Login

    DrawPoints - Invalid object length

    Scheduled Pinned Locked Moved PYTHON Development
    15 Posts 0 Posters 1.2k 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

      On 17/08/2015 at 07:48, xxxxxxxx wrote:

      I just found that to make it work simply omit passing 'vn' parameter i.e. call DrawPoints() with only 3 parameters.

      Originally posted by xxxxxxxx

      Another question: Is there a faster/ better way to select one of the point or handles of the spline in the HUD?
      ScottA uses the mouse position and compares it with the position of the points.

      I think the mouse checks to get the current control point moved should be done in MouseInput() after the call to win.MouseDragStart(), not in GetCursorInfo().

      Originally posted by xxxxxxxx

      PS Before I submit a bug, I like to be sure that it is not an error from my side.

      The issue can be reproduced if None is passed for 'vn' parameter and I think there's the same issue with 'vc'.

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

        On 17/08/2015 at 07:59, xxxxxxxx wrote:

        All clear now, thanks again.

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

          On 24/08/2015 at 02:31, xxxxxxxx wrote:

          I works ok in R15, but in R16, the spline is displayed twice. Once in the view port / Hud and once normal.

          Here the code Draw:

              def Draw(self, doc, data, bd, bh, bt, flags) :	
          	
                  ################# This is the control points section ####################
            
                  p1x = myDict['cp1x']
                  p1y = myDict['cp1y']		
                  cntrl_p1 = c4d.Vector(p1x,p1y,0)     #The first control point(the start of the spline)
          		
                  p2x = myDict['cp2x']
                  p2y = myDict['cp2y']
                  cntrl_p2 = c4d.Vector(p2x,p2y,0)     #The second control point
          		
                  p3x = myDict['cp3x']
                  p3y = myDict['cp3y']		
                  cntrl_p3 = c4d.Vector(p3x,p3y,0)      #The third control point
          		
                  p4x = myDict['cp4x']
                  p4y = myDict['cp4y']			
                  cntrl_p4 = c4d.Vector(p4x,p4y,0)     #The fourth control point(the end of the splne)
          		
                  cntrl_points = [cntrl_p1,cntrl_p2,cntrl_p3,cntrl_p4] #A list array containing the control points
                  bd.SetPointSize(15.0)                                 #Set the size of the points		
                  col = [.9, .1, .1]*4                                 #Set the color of the CV points	
                  bd.DrawPoints(cntrl_points, col, 3)	         #Draw the spline Control Points		
            
                  ################# This is the spline's points section ####################
                  steps = myDict['segments']                        #The number of line segments 
                  s_points = smoothPoints(cntrl_points, steps)      #The points of the spline		
                  cadr = [1]*924                                    #Set the color values for the points				
                  bd.SetPointSize(3.0) 
            
                  bd.DrawPoints(s_points, cadr, 3)	          #Draw points so we can see where each line in the spline begins/ends
            
                  print "_points: ", s_points
                  #Create a line between two points (except the last point) to create a spline
                  size = len(s_points)		
                  for i in xrange(0,size-1) :
                      bd.SetPen(c4d.Vector(1, 1, 1))                #Set color for draw operations
                      bd.DrawLine2D(c4d.Vector(s_points[i].x,s_points[i].y, 0) , c4d.Vector(s_points[i+1].x,s_points[i+1].y, 0))		
          		
                  c4d.EventAdd()        
                  return c4d.TOOLDRAW_HANDLES|c4d.TOOLDRAW_AXIS
          	
          

          In the documentation I do not see any relevant changes in R15 to R16.

          Also, is there a way to display and use Tangents in the viewport / Hud?

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

            On 24/08/2015 at 05:49, xxxxxxxx wrote:

            Changing bd.DrawPoints to bd.DrawPoint2D seems to solve the issue.
            Now only the 2d is shown.
            Of course, bd.SetPointSize is not used. Only a one pixel point is displayed using DrawPoint2D.

            Still trying to find out how to display / set tangents.

            -Pim

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

              On 24/08/2015 at 07:33, xxxxxxxx wrote:

              Hi Pim,

              I wrote this plugin using R13. And it works properly with that version.
              But Maxon keeps on making major changes to the SDK. Especially the Python SDK.
              So try not to follow my code too closely. Just use it as a general guide.

              With all of the change they make to the SDK from version to version.
              You might have to completely re-write it for R16++.

              -ScottA

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

                On 24/08/2015 at 08:01, xxxxxxxx wrote:

                Hi Scott,

                Thanks again for all your plugins and yes I use them mostly as guidelines.
                I learn a lot that way.
                It is step by step, but I think I am getting there.
                Now the main issue is, how to get the tangents.

                -Pim

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

                  On 25/08/2015 at 01:12, xxxxxxxx wrote:

                  Hi Pim,

                  You can also use bd.DrawLine2D() to draw tangents.

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

                    On 25/08/2015 at 04:44, xxxxxxxx wrote:

                    Ok, does that means I must write my own tangent calculation or can I use sdk functions / routines?

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

                      On 25/08/2015 at 06:13, xxxxxxxx wrote:

                      Originally posted by xxxxxxxx

                      Ok, does that means I must write my own tangent calculation or can I use sdk functions / routines?

                      You may use the spline data and calculation in the API provided by SplineData.

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

                        On 25/08/2015 at 07:43, xxxxxxxx wrote:

                        The only reason why my plugin exists at all is because the C4D SDK doesn't have any 2D Spline Draw classes in it.
                        And when I asked for help with how to make them myself. All I got were crickets chirping. 🙂

                        After weeks and weeks of searching the internet for examples. I found mostly just the maths posted for this subject. 😠
                        The math for splines is quite complex. And not easy to convert into computer code.
                        It took me quite a lot of time and effort to figure out how to draw a 2D spline to the Editor view in C4D. Too long!
                        I did not want anyone else to have to go through the same hell I went through just to draw a smooth cubic spline in 2D. So I posted my code for everyone to see how simple it is, once you have the complex maths converted into computer code.

                        So if there are people out there that do know how to write the tangents code part for this. Or even have other types of code for drawing splines in their tool kit. Please do what I did, and pay it forward and post an example for the rest of use to learn from.
                        Posting a bunch of complex maths to WIKI does not help. We need to see it in code form.
                        This is one of those subjects where finding good simple code examples was very difficult to find.

                        Thanks,
                        -ScottA

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

                          On 25/08/2015 at 12:23, xxxxxxxx wrote:

                          I have the following options /thoughts, I still need to investigate.

                          1) C4dJack wrote an article on c4dprogramming on "drawing a spline in the viewport".
                          I want to use that as a start, assuming viewport = hud. So a 2d spline.

                          2) To calculate tangent, I want to use the code Martin provided:

                              
                              
                                  #_______________________________________________________  
                                #Soft interpolation  
                                lenRight = (pointList[i+1] - pointList[i]).GetLength()  
                                lenLeft = (pointList[i-1] - pointList[i]).GetLength()  
                                lenAverage = (lenLeft + lenRight)/2  
                                if lenAverage > lenRight:  
                                    lenAverage = lenRight  
                                elif lenAverage > lenLeft:  
                                    lenAverage = lenLeft  
                                orientation = (pointList[i+1] - pointList[i-1]).GetNormalized()  
                                tangent = orientation * lenAverage / 4  
                                spline.SetTangent(i, -tangent, tangent)
                          

                          3) And of course SplineData as Yannick said.
                          "You may use the spline data and calculation in the API provided by SplineData."
                          I will asked him to elaborate on this (give me more details).

                          These are just some thoughts I still need to investigate.

                          -Pim

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

                            On 25/08/2015 at 12:25, xxxxxxxx wrote:

                            Originally posted by xxxxxxxx

                            Originally posted by xxxxxxxx

                            Ok, does that means I must write my own tangent calculation or can I use sdk functions / routines?

                            You may use the spline data and calculation in the API provided by SplineData.

                            Hi Yannick,

                            Could you elaborate a bit more on what you mean.
                            If possible, more details, directions to display a 2d (hud) spline.

                            -Pim

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