ObjectData plugin Draw() question



  • I draw a line and some points, but I want him to show it in front of all the objects (my target: just like measure objects, you can always see them, even if you don't choose to measure objects, they are not covered by any objects)

    • 1: When drawpass = DRAWPASS_HANDLES draw, I only select the object to achieve the first display, but I have to choose, this is not what I want.
    • 2: when draw pass = DRAWPASS_OBJECT draw, I don't choose Show lines, but he will be covered by other objects

    this is my code:

    def Draw(self,op, drawpass, bd, bh):
        
        if drawpass == c4d.DRAWPASS_OBJECT:
            if not op[c4d.S_MOTIONTRAIL_GTWO_DRAWENABLE]:
                return c4d.DRAWRESULT_OK
            bd.SetMatrix_Matrix(None, c4d.Matrix())
    
            all_pos = self.parameters['all_pos']
            color_lis = self.parameters['color_lis']
            point_size = op[c4d.S_MOTIONTRAIL_GTWO_POINTSIZE]
            bd.SetPointSize(point_size)
            for per_pos,color in zip(all_pos,color_lis):
                bd.SetPen(color)
                cnt = len(per_pos)
                for i in xrange(cnt-1):
                    bd.DrawLine(per_pos[i],per_pos[i+1],c4d.NOCLIP_D)
                bd.DrawPoints(per_pos,None)
        
    
        return c4d.DRAWRESULT_OK
    

    Thanks for any help!



  • Hi,in another post I found a way to achieve my goal of converting the coordinate position to camera space and then scaling it to a small size so that he appears first.

    this is new code:

    def Draw(self,op, drawpass, bd, bh):
        
        
        if not op[c4d.S_MOTIONTRAIL_GTWO_DRAWENABLE]:
            return c4d.DRAWRESULT_OK
        #bd.SetMatrix_Matrix(None, c4d.Matrix())
        pmg = ~bd.GetMg()
        bd.SetMatrix_Camera()
    
        all_pos = self.parameters['all_pos']
        color_lis = self.parameters['color_lis']
        point_size = op[c4d.S_MOTIONTRAIL_GTWO_POINTSIZE]
        bd.SetPointSize(point_size)
        for per_pos,color in zip(all_pos,color_lis):
            bd.SetPen(color)
            cnt = len(per_pos)
            temp_lis = []
            for i in xrange(cnt-1):
                c = (pmg * per_pos[i]).GetNormalized() * 20
                f = (pmg * per_pos[i+1]).GetNormalized() * 20
                bd.DrawLine(c,f,c4d.NOCLIP_D)
                temp_lis.append(c)
            temp_lis.append(f)
            bd.DrawPoints(temp_lis)
        
    
        return c4d.DRAWRESULT_OK
    

    why * 20 will work, * 1or 2 not work (c = (pmg * per_pos[i]).GetNormalized() * 20)?



  • hello,

    while this solution is pretty nice and work in most of the case, if you activate the "near clipping" of the camera you will get into trouble.

    As you have understood, the line is drawn really near the camera. The scalar *20 is just another way to say "how far" from the camera the line must be draw. If you enter really big number, objects will clip your lines.

    I can't confirm but *1 seem too close and it's clipped by default.

    If you really want to draw everything "on top", you have to jump to c++ and create a scenehook (you can't create a scenehook in python)
    As you seems to have a good understanding of Cinema4D API you should. The team is here to help you in case you have issue.

    Cheers
    Manuel



  • @m_magalhaes Thanks,i will try to use C++☺


Log in to reply