BaseDraw problems



  • On 28/04/2016 at 03:44, xxxxxxxx wrote:

    Hello people!

    I have some problems with the BaseDraw, one with DrawTexture() and one with SetMatrix_Screen().

    1. Using SetMatrix_Screen() causes other object's visuals to be corrupted
    2. I get a strange "cut" on the right side of the image drawn with DrawTexture()
    3. I can't get the image to be drawn on top of the Cube

    This image shows all problems:

    You can download a full example to reproduce here: https://cloud.niklasrosenstein.com/index.php/s/wkAnX8zFfvlV7VV

    The relevant code is:

      def Draw(self, op, drawpass, bd, bh) :
        if drawpass != c4d.DRAWPASS_OBJECT: return c4d.DRAWRESULT_SKIP
        if not self.PluginIcon: return c4d.DRAWRESULT_SKIP
      
        wpsize = 48
      
        # Draw the object icon on the screen.
        pos = bd.WS(op.GetMg().off)
        bmp = self.PluginIcon
        padr = get_draw_screen_padr(pos, wpsize, wpsize, ALIGN_CENTERH | ALIGN_BOTTOM)
        uvadr = get_draw_screen_uvcoords(bmp, 0, 0, bmp.GetBw(), bmp.GetBh())
        cadr = [c4d.Vector(1.0)] * 4
        vnadr = [c4d.Vector(0.0, 0.0, 1.0)] * 4
        mode = c4d.DRAW_ALPHA_NORMAL
        flags = c4d.DRAW_TEXTUREFLAGS_0
      
        bd.SetMatrix_Screen(4)
        bd.DrawTexture(self.PluginIcon, padr, cadr, vnadr, uvadr, 4, mode, flags)
      
        return c4d.DRAWRESULT_OK
    

    I have no idea how to solve either of those issues. Looking forward to your input!

    Thanks in advance,
    Niklas



  • On 28/04/2016 at 04:25, xxxxxxxx wrote:

    Update:  The first issue about the "cut" is resolved. I used the wrong order for the uvadr  and padr.
    Now interestingly, this also seems to fix the strange looks of the Cube for some reason!
    So the first and second issue are resolved by this :) You can find the corrected versions of the
    functions below.

    The third question remains though: How can I get the texture to be drawn over  the
    Cube (or above everything)? Currently, it gives a very strange effect.

    ------

    ALIGN_LEFT = (1 << 0)
    ALIGN_RIGHT = (1 << 1)
    ALIGN_CENTERH = (1 << 2)
    ALIGN_TOP = (1 << 3)
    ALIGN_BOTTOM = (1 << 4)
    ALIGN_CENTERV = (1 << 5)
      
    def get_draw_screen_uvcoords(bmp, x, y, w, h) :
      bmpw, bmph = map(float, bmp.GetSize())
      corners = [x / bmpw, y / bmph, (x + w) / bmpw, (y + h) / bmph]
      return [
        c4d.Vector(corners[0], corners[1], 0.0),
        c4d.Vector(corners[2], corners[1], 0.0),
        c4d.Vector(corners[2], corners[3], 0.0),
        c4d.Vector(corners[0], corners[3], 0.0)]
      
      
    def get_draw_screen_padr(pos, w, h, align) :
      if align & ALIGN_LEFT:
        xoff = 0
      elif align & ALIGN_RIGHT:
        xoff = w
      elif align & ALIGN_CENTERH or True:
        xoff = w / 2.0
      if align & ALIGN_TOP:
        yoff = 0
      elif align & ALIGN_BOTTOM:
        yoff = h
      elif align & ALIGN_CENTERV or True:
        yoff = h / 2.0
      
      x, y = (pos.x - xoff, pos.y - yoff)
      return [
        c4d.Vector(x,     y, 0.0),
        c4d.Vector(x + w, y, 0.0),
        c4d.Vector(x + w, y + h, 0.0),
        c4d.Vector(x,     y + h, 0.0)]
    


  • On 29/04/2016 at 03:23, xxxxxxxx wrote:

    Hi Niklas,

    I'm afraid you'll have to wait till next week to get an answer for your problem with BaseDraw.DrawTexture().



  • On 02/05/2016 at 03:01, xxxxxxxx wrote:

    Hello,

    the best way to draw elements in 2D over other elements is probably to draw them in a SceneHook. See 2D viewport drawing using a SceneHook.

    Beside that I don't see any way to handle this situation.

    Best wishes,
    Sebastian



  • On 16/05/2016 at 22:09, xxxxxxxx wrote:

    Hi Sebastian,

    thanks for your reply! Good idea, I also think that would work.
    I'm in a Python plugin so a SceneHook is not an option. No longer
    so important now anyway :)

    Cheers, Niklas


Log in to reply