SplineVertex to PointPosition on Spline



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

    On 30/03/2012 at 05:54, xxxxxxxx wrote:

    After trying every possible combination of the SplineHelp() functions I'm realy helpless.

    My goal is to get the position of the vertexpoints when using the mode adaptive for the spline interpolation.

    Getting the vertexcount is easy while using the SplineHelp()-class. But when it comes to the point to calculate their individual positions I stuck.

    import c4d  
    from c4d import utils  
    from utils import SplineHelp  
      
    ...  
      
    splineHelper = SplineHelp()  
    splineHelper.InitSpline(myPath,use_deformed_points=True)             #myPath is a simple not closed spline  
      
    for i in xrange(splineHelper.GetVertexCount(0)) :                     #0 is the first segment of the spline  
    vertexM = splineHelper.GetVertexMatrix(i)  
      
    splineHelper.FreeSpline()
    

    My used spline has 3 points and 10 vertices.
    But iterating this 10 vertices throws an error when reaching the 4th iteration.

    Reading the SDK I've found the information, that GetVertexMatrix(index) uses tje line object vertex and not the spline vertex.

    But the line object vertex is represented of the spline points.

    After that I've tried to convert the vertex-type with SplineHelp.SplineToLineIndex(index).
    But this seems to convert in the wrong direction.
    0 is converted to 0.
    1 is converted to 2.
    2 is converted to 9.

    Can anyone help me please?
    Or does anyone knows a different way to get the position of the spline vertices?

    Best regards,
    Sven



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

    On 30/03/2012 at 06:12, xxxxxxxx wrote:

    After testing the single parts of the code I've noticed that SplineHelp.SplineToLineIndex() is out of range.

    Does this mean there are more line vertices then spline vertices?

    The SDK says that SplineHelp.GetVertexCount() return the number of vertices of a spline segment.
    In my case it returns 10. But 3 is out of index. Is it an failure in the sdk?



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

    On 30/03/2012 at 06:15, xxxxxxxx wrote:

    if you just want to read the vertex point  not an interpolation point why don't you use
    c4d.pointobject as a spline is derived from a pointobject ?

    print myspline.GetPoint(id)

    edit : ah my fault mixed up spline vertex and interpolation vertex, so you want calc an
    interpolation point.



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

    On 30/03/2012 at 06:28, xxxxxxxx wrote:

    But I'm trying to get the interpolation points. :)

    And how I wrote it have to be the adaptive-mode of the spline interpolation.
    The types none, natural (? don't know how it's called in the english version) and constant (the same as before) are working already.

    But I need all five interpolation types.

    Edit: Right. :)



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

    On 30/03/2012 at 06:56, xxxxxxxx wrote:

    you are using .GetVertexMatrix() wrong it expects a float as offset value not an index integer.
    also your import statment for the splinehelper is incorrect.

    import c4d
    from c4d import utils
    from c4d.utils import SplineHelp
      
    def main() :
        splineHelper = SplineHelp()
        splineHelper.InitSpline(spline,use_deformed_points=True)    
        print splineHelper.GetVertexMatrix(0.5)
    

    this will return for the default circle

    Matrix(v1: (-0.965, -0.26, 0); v2: (0, 0, 1); v3: (-0.26, 0.965, 0); off: (200, 0, 0))

    i guess v1-v3 are tangent data. i think you should stick with SplineObject.GetSplinePoint() it
    returns an interpolated point on a spline. however calculating the exact vertex of spline 
    interpolated with adaptive subdiv will be tricky. i guess you will have to use GetVertexMatrix
    and redo the interpolation with the tangents.



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

    On 30/03/2012 at 07:18, xxxxxxxx wrote:

    SplineHelp.GetVertexMatrix() takes a line object point index and should be in the range of [0, PointObject.GetPointCount()].

    The loop to retrieve the vertices matrix should looks like:

    for i in xrange(myPath.GetPointCount()) :
        vertexM = splineHelper.GetVertexMatrix(i)
    


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

    On 31/03/2012 at 05:52, xxxxxxxx wrote:

    @littledevil: The import statement was only wrong in my code example. :)
    It seem's you're right and it'll be tricky to get the original vertex on splines with adaptive subdiv.

    @Yannik: I understand how GetVertexMatrix works but I hoped to find a way to convert a spline vertex index to a line object vertex index. After I've found the SplineToLineIndex() I thought that this would saves me. But the function seems to convert a line object vertex index to a spline vertex index.

    Any ideas how to write a reverse function for SplineToLineIndex? :)

    Thank you both for your help.

    cheers,
    Sven



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

    On 02/04/2012 at 02:38, xxxxxxxx wrote:

    I like days like those one. :)

    Ok, some testing gives me the solution.
    After playing around with different approaches I was asking me how it comes that a spline have an uniform and a natural offset.

    And that's it! The natural offset is influencend by the internal spline interpolation. :)
    In other words: a spline with a spline vertex count of 39 has it's natural center offset at vertex 19.

    Here a little script for testing:

      
    import c4d  
    from c4d import documents, utils  
      
    def main() :  
      doc = documents.GetActiveDocument()  
      obj = doc.SearchObject("pfad")                              #my spline-object  
        
      splineHelper = utils.SplineHelp()  
      splineHelper.InitSpline(obj)  
        
      vertexStepSize = float(1) / (splineHelper.GetVertexCount(0)-1)     # 1 / x because SplineHelp.GetMatrix() expects a float between 0 and SplineHelp.GetSegmentCount(), what's 1 in my case  
        
      for i in xrange(splineHelper.GetVertexCount(0)) :            #get the count of all existing spline! vertices  
          cs = None  
          if doc.SearchObject("checker"+str(i)) is None:          #checker is a polygon-object I've used for visual tracing  
              cs = doc.SearchObject("checker").GetClone()  
              cs.SetName("checker"+str(i))  
              cs.InsertAfter(doc.SearchObject("con"))             #con is only a null-object containing my script  
          else:  
              cs = doc.SearchObject("checker"+str(i))  
                
          checkerM = splineHelper.GetMatrix(i*vertexStepSize)  
          cs.SetMg(checkerM)  
            
      splineHelper.FreeSpline()  
        
    

    Try it by yourself.
    Don't know where to upload my testfile. But the script works.

    cheers,
    Sven


Log in to reply