Maxon Developers Maxon Developers
    • Documentation
      • Cinema 4D Python API
      • Cinema 4D C++ API
      • Cineware API
      • ZBrush Python API
      • ZBrush GoZ API
      • Code Examples on Github
    • Forum
    • Downloads
    • Support
      • Support Procedures
      • Registered Developer Program
      • Plugin IDs
      • Contact Us
    • Categories
      • Overview
      • News & Information
      • Cinema 4D SDK Support
      • Cineware SDK Support
      • ZBrush 4D SDK Support
      • Bugs
      • General Talk
    • Unread
    • Recent
    • Tags
    • Users
    • Login

    Trouble with Enhanced OpenGL display

    Scheduled Pinned Locked Moved PYTHON Development
    14 Posts 0 Posters 1.5k Views
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • H Offline
      Helper
      last edited by

      THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

      On 20/07/2012 at 12:57, xxxxxxxx wrote:

      Could you show a little of the code that actually draws the text?

      -Nik

      1 Reply Last reply Reply Quote 0
      • H Offline
        Helper
        last edited by

        THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

        On 20/07/2012 at 14:15, xxxxxxxx wrote:

        Sure 🙂

        The actual code that draws the lines is:

        def draw_atom(d,pos,coords,scale,up,bd) :
             # d is the digit to draw (0-9)
             # pos is the position if the digit inside the number (0 to the number of digits that the number has)
             # coords is the coordinates in world space where to draw the number
             # scale is the scaling value to draw the numbers in varying sizes
             # up is the value to add to the Y coordinate so that the numbers don't overlap the point handles
             # bd is the BaseDraw     
             number=numbers[d]     # get the list with the numbers coordinates
             n=len(number)
             pos2=pos*100*scale     # calculate the position
             for f in range(0,n-1) :
                  # calculate the coordinates
                  p1=c4d.Vector(pos2+number[f][0]*scale,number[f][1]*scale-up,0)
                  p2=c4d.Vector(pos2+number[f+1][0]*scale,number[f+1][1]*scale-up,0)
                  # draw the lines that compose the number
                  bd.DrawLine(coords+p1,coords+p2,c4d.NOCLIP_Z)
             return

        But, before calling this, I set the drawing matrix with:

        bd.SetMatrix_Matrix(op, op.GetMg(),5)

        I know the problem should be in the matrix setting but I really don't know how to solve this.
        Oh, the coords that are fed into the draw_atom procedure are derived from the world position of the vertexes of the object, with:

        coords=op.GetPoint(idd)*op.GetMg()

        Thank you for checking this 🙂

        Rui Batista

        1 Reply Last reply Reply Quote 0
        • H Offline
          Helper
          last edited by

          THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

          On 21/07/2012 at 07:34, xxxxxxxx wrote:

          An option is to convert object point positions to camera space and calculate the DrawLine() start and end points there.

          This example draws a '4' on the fourth point of an object. It always faces the camera and maintains a constant size when zooming and resizing viewports.

          It currently works for the perspective and parallel cameras and the standard orthographic views (not Axonometric).

          Let me know of any issues if you end up using it.

          //------------------------------------------------

          def RotateMatrix(m, rot) :
              pos = m.off
              scale = c4d.Vector(m.v1.GetLength(), m.v2.GetLength(), m.v3.GetLength())
              
              m = utils.HPBToMatrix(rot)
              m.off = pos
              m.v1 = m.v1.GetNormalized() * scale.x
              m.v2 = m.v2.GetNormalized() * scale.y
              m.v3 = m.v3.GetNormalized() * scale.z
              
              return m
              
          def RotationOffset(proj) :
              if proj is c4d.Pright: rotOffs = c4d.Vector(utils.Rad(90), 0, 0)
              elif proj is c4d.Pleft: rotOffs = c4d.Vector(utils.Rad(-90), 0, 0)
              elif proj is c4d.Ptop: rotOffs = c4d.Vector(0, utils.Rad(-90), 0)
              elif proj is c4d.Pbottom: rotOffs = c4d.Vector(0, utils.Rad(90), 0)
              elif proj is c4d.Pback: rotOffs = c4d.Vector(utils.Rad(180), 0, 0)
              else: rotOffs = c4d.Vector(0, 0, 0)
              
              return rotOffs    
              
          def ViewSize(doc, bd) :
              frame = bd.GetFrame()
              frameWdth = frame['cr']
              frameHght = frame['cb']
              
              rd = doc.GetActiveRenderData()
              x_res = rd[c4d.RDATA_XRES_VIRTUAL]
              y_res = rd[c4d.RDATA_YRES_VIRTUAL]
              aspRat = y_res / x_res

          if float(frameHght) / frameWdth >= aspRat:
               viewSize = float(frameWdth)
              else:
               viewSize = (1.0 / aspRat) * frameHght

          return viewSize

          class PyDrawTest(plugins.TagData) :
              def Init(self, tag) :
                  return True

          def Draw(self, tag, op, bd, bh) :
               doc = documents.GetActiveDocument()
               camera = bd.GetSceneCamera(doc)
               if camera is None: camera = bd.GetEditorCamera()
               
               mCam = camera.GetMg()     
               bd.SetPen(c4d.Vector(1.0, 1.0, 1.0))
               proj = bd.GetProjection()     
               
               if proj is not c4d.Pperspective and proj is not c4d.Pparallel:
                   mCam = RotateMatrix(mCam, RotationOffset(proj))
                   
               bd.SetMatrix_Matrix(camera, mCam, 4)    
                   
               points = op.GetAllPoints()               
               pt_g = op.GetMg() * points[4]
               pt = ~mCam * pt_g         
                   
               defaultFlen = 36.0
               viewSize = ViewSize(doc, bd)
               scale = 1000.0

          if proj is c4d.Pperspective:
                   zoom = camera[c4d.CAMERA_FOCUS] / defaultFlen * viewSize * 1000.0
               else:
                   zoom = camera[c4d.CAMERA_ZOOM] * pt.z * viewSize

          number = [[0, 0], [0, 20], [-8, 10], [4, 10]]
               n = len(number)
               
               for x in xrange(n - 1) :
                   offs1_x = number[x][0] * pt.z * scale / zoom
                   offs1_y = number[x][1] * pt.z * scale / zoom
                   offs2_x = number[x+1][0] * pt.z * scale / zoom
                   offs2_y = number[x+1][1] * pt.z * scale / zoom
                   
                   p1 = c4d.Vector(pt.x + offs1_x, pt.y + offs1_y, pt.z)     
                   p2 = c4d.Vector(pt.x + offs2_x, pt.y + offs2_y, pt.z)

          bd.DrawLine(p1, p2, c4d.NOCLIP_Z)
                   
               return True

          //------------------------------------------------

          1 Reply Last reply Reply Quote 0
          • H Offline
            Helper
            last edited by

            THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

            On 21/07/2012 at 10:38, xxxxxxxx wrote:

            Thanks for posting that David.
            But I don't get any result from it. It doesn't draw anything.

            I don't think the problem is with your code. Because I can make it work in the py-DoubleCircle ObjectData plugin example just fine.
            The problem is that tag's seem to need something else to draw that isn't listed in your code. And I can't figure out what that is.

            Much Simpler Example:

                def Draw(self, tag, op, bd, bh) :  
                  doc = documents.GetActiveDocument()       
                  bd.SetMatrix_Screen()  
                  bd.SetPen(c4d.Vector(1.0, 1.0, 1.0))  
                  bd.DrawLine(c4d.Vector(0,0,0), c4d.Vector(200,200,0), c4d.NOCLIP_Z)  
                     
                  return True
            

            This simple code should draw a simple line on the screen. But it doesn't.
            Something is missing. And I can't find it.
            Do you have a simpler example like this of just drawing a simple line using a tag plugin?

            -ScottA

            1 Reply Last reply Reply Quote 0
            • H Offline
              Helper
              last edited by

              THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

              On 21/07/2012 at 17:20, xxxxxxxx wrote:

              Thank you very much, David.
              After some fiddling to adjust it to my structure, I finally made it work.
              Except... for the orthogonal views. For some reason, it is not drawing the numbers on the orthogonal views, only on the perspective view. Not even in the parallel perspectives... just on the perspective view 😞

              1 Reply Last reply Reply Quote 0
              • H Offline
                Helper
                last edited by

                THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

                On 21/07/2012 at 18:25, xxxxxxxx wrote:

                That's a drag. Here's the plugin and test scene I've been using. Hopefully this will be enough for you to shoehorn it into your plugin. Otherwise, perhaps the solution posted today in SDK Help will work.

                1 Reply Last reply Reply Quote 0
                • H Offline
                  Helper
                  last edited by

                  THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

                  On 21/07/2012 at 18:49, xxxxxxxx wrote:

                  Got it working!!! 🙂
                  Thank you very, very much, David.
                  Now, on to optimizing the speed.

                  Rui Batista

                  1 Reply Last reply Reply Quote 0
                  • H Offline
                    Helper
                    last edited by

                    THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

                    On 21/07/2012 at 20:14, xxxxxxxx wrote:

                    Good to hear!

                    Originally posted by xxxxxxxx

                    The problem is that tag's seem to need something else to draw that isn't listed in your code. And I can't figure out what that is.

                    See how you go with my uploaded example Scott. Hopefully this will work for you as well.

                    1 Reply Last reply Reply Quote 0
                    • H Offline
                      Helper
                      last edited by

                      THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

                      On 21/07/2012 at 22:18, xxxxxxxx wrote:

                      Thanks for the file David.
                      I had an indentation problem in my code using your draw method. But the stupid console wasn't picking it up. And it actually ran the plugin even though the indentation was wrong!

                      After playing around with this. I think I know why my small example doesn't.
                      I think it's because I'm trying to use SetMatrix_Screen(). And that function might require width and height variables to work.

                      Everything works fine using bd.SetMatrix_Matrix(camera, mCam, 4).
                      But that ties the lines being drawn to the object. And I was trying to draw lines on the screen, not tied to any object using a tag.
                      I can do this in C++ using the GeClipMap() class(although the text is still a background object and I can't figure out to make it a foreground object😠). So That might be the way I'll have to do it in Python too.

                      -ScottA

                      1 Reply Last reply Reply Quote 0
                      • H Offline
                        Helper
                        last edited by

                        THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

                        On 23/07/2012 at 00:54, xxxxxxxx wrote:

                        No worries Scott.

                        Width and height variables aren't necessary when using screen space coordinates. BaseView.WS() will convert coordinates from world to screen space for you.

                        I've found the BaseDraw 2D drawing functions to be much faster than GeClipMap. Also, reliably drawing in the foreground can be done using these functions with a SceneHookData plugin. Unfortunately this class isn't currently supported in the Python SDK.

                        1 Reply Last reply Reply Quote 0
                        • First post
                          Last post