DrawLine Obscured by objects



  • I used DrawLine2D() to draw the "line", but it was blocked by the other objects. I hope "line" not obscured by any objects. (it's Tool_Plugin)

    this is code:

    def MouseInput(self, doc, data, bd, win, msg):
        mx = msg[c4d.BFM_INPUT_X]
        my = msg[c4d.BFM_INPUT_Y]
    
        device = 0
        if msg[c4d.BFM_INPUT_CHANNEL]==c4d.BFM_INPUT_MOUSELEFT:
            device = c4d.KEY_MLEFT
        elif msg[c4d.BFM_INPUT_CHANNEL]==c4d.BFM_INPUT_MOUSERIGHT:
             device = c4d.KEY_MRIGHT
        else:
            return True
        
        dx = 0.0
        dy = 0.0
        
        win.MouseDragStart(button=device, mx=int(mx), my=int(my), flags=c4d.MOUSEDRAGFLAGS_DONTHIDEMOUSE|c4d.MOUSEDRAGFLAGS_NOMOVE)
        result, dx, dy, channel = win.MouseDrag()
        
        ####Add code
        front_v = [c4d.Vector(mx,my,0)]
        current_v = [c4d.Vector(mx,my,0)]
        num = 0
        bd.SetPen(c4d.Vector(0,0,1.0))
        ####
        while result==c4d.MOUSEDRAGRESULT_CONTINUE:
            mx += dx
            my += dy
            
            ####Add code
            
            current_v[num] = c4d.Vector(mx,my,0)
            num += 1
            
            ####
            
            #continue if user doesnt move the mouse anymore
            if dx==0.0 and dy==0.0:
                result, dx, dy, channel = win.MouseDrag()
                num -= 1
                continue
            
    
            c4d.DrawViews(c4d.DA_ONLY_ACTIVE_VIEW|c4d.DA_NO_THREAD|c4d.DA_NO_ANIMATION)
            
            
            result, dx, dy, channel = win.MouseDrag()
            
            ####Add code
            
            for index in xrange(num):
                bd.DrawLine2D(front_v[index],current_v[index])
            front_v.append(c4d.Vector(mx,my,0))
            current_v.append(c4d.Vector(mx,my,0))
            
            
            
            ####
        
        c4d.DrawViews(c4d.DA_ONLY_ACTIVE_VIEW|c4d.DA_NO_THREAD|c4d.DA_NO_ANIMATION)
        return True
    

    drawline_test.png

    Thanks for any help!



  • Hello,

    You have to use the Draw function from the tooldata

    You can store the points in an array and than use that array in your draw function.

    try to check if the mouse have move "enough" instead of 0 to avoid creating too much points in the array.

      if dx < 1.0 and dy < 1.0:
                    result, dx, dy, channel = win.MouseDrag()
                    continue
    

    and once you have your array of points you can juste iterate it and draw lines

        def Draw(self, doc, data, bd, bh, bt, flags):
    
            if not flags:
                # Sets the pen color
                bd.SetPen(c4d.Vector(0, 0, 1.0))
                # Iterates through the array getting columns 1_2, 2_3, ... n-1_n
                for pa,pb in zip(self.data,self.data[1:]):
                    # Draw a line point by point
                    bd.DrawLine2D(pa, pb)
    
            return c4d.TOOLDRAW_NONE
      
    

    Cheers
    Manuel



  • Hello,

    You have to use the Draw function from the tooldata

    You can store the points in an array and than use that array in your draw function.

    try to check if the mouse have move "enough" instead of 0 to avoid creating too much points in the array.

      if dx < 1.0 and dy < 1.0:
                    result, dx, dy, channel = win.MouseDrag()
                    continue
    

    and once you have your array of points you can juste iterate it and draw lines

        def Draw(self, doc, data, bd, bh, bt, flags):
    
            if not flags:
                # Sets the pen color
                bd.SetPen(c4d.Vector(0, 0, 1.0))
                # Iterates through the array getting columns 1_2, 2_3, ... n-1_n
                for pa,pb in zip(self.data,self.data[1:]):
                    # Draw a line point by point
                    bd.DrawLine2D(pa, pb)
    
            return c4d.TOOLDRAW_NONE
      
    

    Cheers
    Manuel



  • @m_magalhaes Thanks for your help, I tried to store and then draw, but the result of this is that the lines are visible after drawing. My goal is to draw lines in real time, so I use DrawLine2D() and DrawView() in the While,make the view continuously draw the line.

    But my main problem has not been solved yet.

    • 1 (the main problem), how to make the lines I draw are not obscured by the cube. as pic above

    • 2 (minor problem), close Horizon in the window filter, the line will be abnormal, is this a bug or do I have to open Horizon? as pic below
      bug.png



  • ok,

    1 - you can call c4d.DrawViews in your while routine in mouseInput and i've change my code in my Draw function so it check for flags to draw the line.

    2 - can you share your mouseInput() and Draw() function so i have a chance to reproduce this bug ?

    cheers
    Manuel



  • @m_magalhaes Thanks ,it works well,I modified the code according to your answer.

    • 1 draw line not obscured by any object.solved

    • 2 before i just draw line in MouseImput() (not add Draw() funtion),as above pic/code, Now i draw line in Draw(),it works well.solved


Log in to reply