Knife 1 polygon diagonal



  • On 26/02/2016 at 04:43, xxxxxxxx wrote:

    I want to knife one polygon over its diagonal.
    So from poly.a to poly.c. In fact triangulate without using triangulation.

    I found this example, but I do not how to define v1 and v2.
    P1 = poly.a and P2 = poly.c
    MDATA_KNIFE_RESTRICT = True to Knife only the selected polygon.

        bc = c4d.BaseContainer()
        bc.SetVector(c4d.MDATA_KNIFE_P1, p1)
        bc.SetVector(c4d.MDATA_KNIFE_P2, p2)
        bc.SetVector(c4d.MDATA_KNIFE_V1, v1)
        bc.SetVector(c4d.MDATA_KNIFE_V2, v2)
        bc.SetBool(c4d.MDATA_KNIFE_RESTRICT, True)
        bc.SetBool(c4d.MDATA_KNIFE_SELECTCUTS, False)
        
        utils.SendModelingCommand(command = c4d.MCOMMAND_KNIFE,
                                  list = [op],
                                  bc = bc,
                                  flags = c4d.MODELINGCOMMANDFLAGS_CREATEUNDO)
    

    -Pim



  • On 26/02/2016 at 18:15, xxxxxxxx wrote:

    The knife tool uses the editor view's coords. Not the polygon's points.
    It's most likely the example you found is something like this one. Where the knife cuts any polygons that happen to be underneath the knife's cutting line. Which is defined by editor view coords:

    import c4d  
    from c4d import utils  
    def main() :  
        
      bd = doc.GetActiveBaseDraw()  
      frame = bd.GetFrame()                       #The editor view  
      middleX = (frame['cr']-frame['cl'])/2       #Gets the middle of the view  
        
      #This constructs a virtual cutting plane object      
      p1 = bd.SW(c4d.Vector(middleX, frame['ct'], 0.0))  
      v1 = bd.SW(c4d.Vector(middleX, frame['ct'], 100.0)) - p1  
      p2 = bd.SW(c4d.Vector(middleX, frame['cb'], 0.0))  
      v2 = bd.SW(c4d.Vector(middleX, frame['cb'], 100.0)) - p2  
        
      bc = c4d.BaseContainer()  
      bc.SetVector(c4d.MDATA_KNIFE_P1, p1)  
      bc.SetVector(c4d.MDATA_KNIFE_P2, p2)  
      bc.SetVector(c4d.MDATA_KNIFE_V1, v1)  
      bc.SetVector(c4d.MDATA_KNIFE_V2, v2)  
      bc.SetBool(c4d.MDATA_KNIFE_RESTRICT, False)  
      bc.SetBool(c4d.MDATA_KNIFE_SELECTCUTS, True)  
        
      utils.SendModelingCommand(command = c4d.MCOMMAND_KNIFE,  
                                    list = [op],  
                                    bc = bc,  
                                    doc = doc,  
                                    flags = c4d.MODELINGCOMMANDFLAGS_CREATEUNDO)  
      c4d.EventAdd()      
      
    if __name__=='__main__':  
      main()
    

    If you wanted to cut from one polygon point to another. You'd have to get their editor view coords.
    And use those instead of frame['ct'], frame['cb'], frame['cr'], frame['cl'].
    But... if the object or camera is rotated by the user. Where those points are blocked by other polygons. You would cut those other polygons instead.
    Because of this. The knife tool isn't a good choice for splitting quads.

    -ScottA



  • On 27/02/2016 at 06:01, xxxxxxxx wrote:

    Ok, I use my own method:
    - delete the poygon
    - create 2 new triangles

    Thanks, Pim


Log in to reply