Maxon Developers Maxon Developers
    • Documentation
      • Cinema 4D Python API
      • Cinema 4D C++ API
      • Cineware 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
    • Register
    • Login

    UA is update too often

    Cinema 4D SDK
    r21 r20 python
    2
    3
    527
    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.
    • P
      pim
      last edited by

      I have a User Area (UA) where I display thumbnails from image files.
      I scale the image files in DrawMsg().

      result, ismovie = self.bmp.InitWith(path)
      width, height = self.bmp.GetSize()
      self.DrawBitmap(self.bmp, x1, y1, 100, 100, 0, 0, width, height, c4d.BMP_NORMAL)
      

      This of course takes some time.

      I noticed that the UA (and thus the image files scaled) is often updated.
      For example, when I click in the UA or I move the slider of the UA.

      What can I do to make it more efficient?

      1 Reply Last reply Reply Quote 0
      • S
        s_bach
        last edited by

        Hello,

        as always, efficiency is the result of good software design. One way of speeding things up is to use caches.

        DrawMsg() is called by Cinema whenever Cinema things something might have changed. I don't think you can do anything about that.

        You have to make sure that within DrawMsg() you only draw and do nothing else. Why are you loading the bitmap in the context of DrawMsg()? Why are you scaling the images in the context of DrawMsg()? Why not earlier?

        I guess at some point, your program knowns what images to display. At that point you could load all these (scaled) images into a cache. Then in DrawMsg(), you can simply access the data in that cache.

        Compare e.g. BaseShader.InitRender() which is used to do all the heavy lifting, so that BaseShader.Sample() can be fast.

        Depending on the reason for the redraw, you could optimize further. E.g. you could use a GeClipMap to draw whatever you want into a BaseBitmap and simply draw that BaseBitmap in the context of DrawMsg().

        Speed is the result of software design. Caches can help, but of course they increase code complexity and memory footprint.

        Best wishes,
        Sebastian

        MAXON SDK Specialist

        Development Blog, MAXON Registered Developer

        1 Reply Last reply Reply Quote 0
        • P
          pim
          last edited by

          Thanks for the answer.
          And yes, you are fully correct. Things should not be done in DrawMsg()

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