SOLVED DrawMultipleHUDText issue

Hello PluginCafe! 🙂

I'm using Draw() method if TagData plugin for displaying multiple text values but I can't figure out, how the DrawMultipleHUDText works.

Let's assume I have a list of strings
abc = [ "Hello", "World", ]

And a list of vectors (Usually I'm importing c4d.Vector as v)
xyz = [v(0,100,0), v(0,200,0)]

How should I pass them into DrawMultipleHUDText?

I tried this method and it does not work.

    def Draw(self, tag, op, bd, bh):

        abc = ["Hello", "World"]
        xyz = [v(0, 100, 0), v(0, 200, 0)]

        values = {'_txt': abc, "_position": xyz}

        bd.DrawMultipleHUDText(values)


        return c4d.DRAWRESULT_OK

I want to display these values on top of other viewport elements.

Seems like I figured this out but it's kinda complicated.

    def Draw(self, tag, op, bd, bh):

        values0 = [{'_txt': "Hello", "_position": v(100,100,0)},{'_txt': "World", "_position": v(200,200,0)}]

        bd.DrawMultipleHUDText(values0)

        return c4d.DRAWRESULT_OK

The method above causes shading problems which can be solved by enabling depth option. bd.SetDepth(True)

But it's still displayed on the background. Is it possible to bring it to the front?

hello,

I can resume your question to "Drawing something in front of everything"

It's possible in a SCENEHOOK (witch is not supported in python).

did you try to change the BaseDraw matrix ?

I can point you to this thread the "solution" is to set the matrix of the BaseDraw so the drawing is done really near the camera. Be aware you can have issue with the clipping functions.

hope this help.

Cheers
Manuel

hello,

setting the matrix to screen seems to work.

"""
Draw multiple text From Tag

"""

import c4d

from c4d import plugins, utils, bitmaps, gui

# Be sure to use a unique ID obtained from www.plugincafe.com
PLUGIN_ID = 1052927


class TDRAW_EXAMPLE(c4d.plugins.TagData):


    def Draw(self, tag, op, bd, bh):
        
        # Returns if object is not a polygon object
        if not op.IsInstanceOf(c4d.Opolygon):
            return c4d.DRAWRESULT_OK

        # Retrieves the Object Matrix    
        opMg = op.GetMg()

        # Retrieves All Points
        points = op.GetAllPoints()
        # Retrieves Global Coordinates
        points = [opMg * p for p in points]

        # From world to screen Coordinates (in another array)
        screenPoints  =  [ bd.WS(p) for p in points  ]

        # Prepares the dictionary for the draw multipleHUDText Draw Point Coordinates (world space) at screenPoint Position.
        value =  [ { "_txt" : "point " + str(i) + " " + str(pos[0]) , "_position" : pos[1]  }    for i, pos in enumerate(zip(points, screenPoints)) ]

        # Sets the matrix to screen space
        bd.SetMatrix_Screen()

        # Enables depth buffer.
        bd.SetDepth(True)

        # Draws points indices at point coordinates
        bd.DrawMultipleHUDText(value)

        return c4d.DRAWRESULT_OK



    def Execute(self, tag, doc, op, bt, priority, flags):
        return c4d.EXECUTIONRESULT_OK


if __name__ == "__main__":

    # Register the tag
    c4d.plugins.RegisterTagPlugin(id=PLUGIN_ID,
                                  str="Tag that draw on viewport",
                                  info=c4d.TAG_EXPRESSION | c4d.TAG_VISIBLE,
                                  g=TDRAW_EXAMPLE,
                                  description="tdrawexample",
                                  icon=None)


tree.JPG

tdrawexample.h

#ifndef __TDRAWEXAMPLE_H__
#define __TDRAWEXAMPLE_H__

enum
{


};

#endif // __pc11519_H__

tdrawexample.res

CONTAINER tdrawexample
{
	NAME tdrawexample;
	INCLUDE Obase;

    GROUP ID_OBJECTPROPERTIES

	{


	}


}

tdrawexample.str

STRINGTABLE tdrawexample
{
	tdrawexample								"Draw on viewport from tag";


}

c4d_symbol.h

enum
{
    // End of symbol definition
    _DUMMY_ELEMENT_
};

Cheers
Manuel

OMG! You just wrote the entire plugin for my silly question. 😱
Thank You!!! 💙

I have only one question.
Why did you use
Draw(self, op, drawpass, bd, bh)
instead of
Draw(self, tag, op, bd, bh)
will not drawpass be treated as op and op as a tag?

well,

@merkvilson cause i started from an old ObjectData project and i didn't changed the signature xD
And exact, the name changed but not the object of course.

so, now you don't even need to retrieve the object from the tag 🙂 I've updated the code.

(always refresh your mind before starting another project ^^)

cheers
Manuel

OK. Now I get it. 👌

Thank you very much! I really appreciate what you've done. 😁

Have a good day! 💙

-Merk