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
    • Login
    1. Maxon Developers Forum
    2. wuzelwazel
    W
    • Profile
    • Following 0
    • Followers 0
    • Topics 12
    • Posts 42
    • Best 10
    • Controversial 0
    • Groups 0

    wuzelwazel

    @wuzelwazel

    13
    Reputation
    69
    Profile views
    42
    Posts
    0
    Followers
    0
    Following
    Joined Last Online

    wuzelwazel Unfollow Follow

    Best posts made by wuzelwazel

    • C++ Shader Plug-In Best Practices

      Hello there,

      I've taken my first leap into the C++ SDK and experienced some early triumphs and defeats. I'm working slowly on a shader starting from the Xbitmapdistortion SDK example. I have the SDK documentation open in about 20 tabs but still feel unsure about how I'm approaching what I'd like to accomplish.

      I'm hoping to write a bare bones Ptex shader. I don't need to deal with most of the issues that surround Ptex as my only goal is to get a shader that I can bake into UDIMs 😁 I figured I'd start the effort by generating per-polygon UV coordinates. It took me a while but I came up with a working solution which exists mostly in the Output method of my young shader:

      Vector PtexData::Output(BaseShader* chn, ChannelData* cd)
      {
      	if (cd->vd == nullptr) // It took me a while to realize I needed this here :)
      		return Vector(0.0);
      
      	RayPolyWeight weight;
      	RayHitID hit = cd->vd->lhit;
      	Int32 faceid = hit.GetPolygon();
      	/* I'm not currently using the faceid, but I will need it to index into the sub-images
      	of the Ptex file; is this a bad idea? Is there another way?*/
      
      	cd->vd->GetWeights(hit, cd->vd->p, &weight);
      
      	Vector coord = Vector(weight.wa + weight.wb, weight.wb + weight.wc, 0.0);
      
      	return coord;
      }
      

      poly_uvw.png

      So first off I suppose I'm wondering: have I done anything horribly wrong or inefficient in the above code? That leads me to my next question: what is the best practice for loading an external texture (in this case Ptex)? I was not planning to build a Ptex file handler but instead to 'brute force' this and load the required Ptex images into a PtexCache in my InitRender() and use Ptex's getPixel() method to 'sample' directly using the coordinates I've generated. I have several concerns with this approach (do I need to consider MIP levels? even if my only goal is to bake the shader?). Unfortunately I don't even know enough to know whether they're valid concerns or not 🀷

      Does anyone have a suggestion for an acceptable (not necessarily best) approach for doing this?

      Finally, could anyone recommend additional avenues for getting up to speed on modern C++ more generally (this is the first time I've touched C++ since 2001) and the Cinema 4D SDK in particular?

      posted in Cinema 4D SDK c++ r21 sdk windows
      W
      wuzelwazel
    • Ptex Shader Progress

      I've managed to stumble my way through to a working (debug) prototype of a Ptex Shader. It "works" but I've been developing it with a very specific purpose in mind: converting the Moana dataset Ptex files to UDIMs. As a result, and due in large part to my inexperience with C++ and the SDK, this prototype is missing pretty much all of the features it would require to be a production ready shader 😁 I'm not doing proper error checking and it's quite possible I've written a memory leak or two in here 🀷

      Most telling: the plug-in is crashing when I switch the build to release. Debug is working, but I am unfortunately clueless when it comes to debugging πŸ™

      isMountainA.jpg
      isLavaRocks1.jpg

      This Ptex shader doesn't work under several conditions that would need to be addressed if I were working on this for other people to use in production:

      • Doesn't work if the mesh has been subdivided (no correction for the change to polygon indices and coordinates)
      • Similarly doesn't work as an input for sub-polygon displacement
      • Only reads .ptex files whose filenames match objects that the shader is being evaluated on
      • Only works on Windows
      • Only works with a Debug build
      • Not designed as a general purpose shader, specifically built to work with the Moana dataset

      With all of those caveats out of the way, I've uploaded the source to Google Drive in the hopes that folks will point out the idiotic things I've done so that I can improve and also so that someone more capable might pick this up and carry it through to a real shader 😁

      P.S. For anyone working on Windows that doesn't yet know: I highly recommend picking up vcpkg. If I'd had to build Ptex from scratch I don't think I'd even have gotten this far.

      posted in General Talk c++ windows r21
      W
      wuzelwazel
    • RE: Make Deformer Affect Objects Outside Hierarchy?

      @bentraje I'm not sure that this will address your desired use case, but if I ever need to apply the same deformer to objects in different hierarchies I'll turn to the Surface deformer.

      posted in Cinema 4D SDK
      W
      wuzelwazel
    • RE: Ptex Shader Progress

      @kbar said in Ptex Shader Progress:

      I had planned on doing this again and converting the OBJ files to C4D files in the process, to make them smaller and faster to load. Which is what you are doing with Redshift proxies I believe?

      Yes, the Redshift Proxies work as a sort of reference so the main c4d file would be quite small. In addition the display of each proxy can be simplified to either reduce or eliminate the viewport being bogged down with drawing faces. Of course, when everything is just a bounding box the scene doesn't look like much before rendering!

      The other benefit of the proxy is specific to Redshift in that the mesh will not need to be processed before the BVH is constructed and rendering can begin.

      posted in General Talk
      W
      wuzelwazel
    • RE: Bend Deformer Using C++

      The only thing I can think of would be to Clone a light onto a Matrix and apply the bend to the Matrix object. The resulting positions and rotations of the Matrix should follow the bend but you will not get any deformation of the lights. They will still be flat lights but they should be distributed along the bend.

      posted in Cinema 4D SDK
      W
      wuzelwazel
    • RE: Make Deformer Affect Objects Outside Hierarchy?

      @bentraje it does, but it essentially behaves as an instance of another deformer. So the deformation is defined in one hierarchy location but can also be re-applied in any arbitrary location.

      Like I said, that might not be what you're after, but it's helped me in certain situations.

      posted in Cinema 4D SDK
      W
      wuzelwazel
    • RE: Make Deformer Affect Objects Outside Hierarchy?

      @bentraje Apologies, I was perhaps a bit misleading in my description of the Surface Deformer. It actually behaves more like an 'instance' of the entire deformer stack that's affecting another object.

      c4d194_deformer_affect_outside_hierarchy_v002.c4d

      posted in Cinema 4D SDK
      W
      wuzelwazel
    • RE: OBJ loading polygon order

      @kbar I was able to load OBJs from the Moana dataset in R20 using Python and the ids did align with the Ptex face indices. My method was fairly naïve: loop from face 0 up to the ptex file's faceCount and assume they align ☺

      hibiscus.png
      rs_moana_bonsai_solo.png

      Unfortunately I was using OpenImageIO bindings that I built myself and some of the Ptex files were coming in horribly corrupted. I posted about it to the oiio mailing list but got no responses. I found that solid color tiles might be the cause of the OIIO corruption of the Ptex files and posted an example here: https://drive.google.com/open?id=1z4N3xru0_TPRxVRDoCaQ7ODAUliJRfjM

      In the above case the corrupted tiles should be solid white.

      Eventually I gave up on solving this through Python + OpenImageIO. I'm trying to pick C++ back up to tackle Ptex but I haven't touched it in 20 years and it's slow going ☹ I finally managed to get Visual Studio to build the SDK examples πŸ˜‰

      At any rate, I don't think there's an issue with the OBJ polygon ids in R20.

      posted in Cinema 4D SDK
      W
      wuzelwazel
    • RE: Generating Splines from JSON Data

      Here are my results after 35 minutes of processing:

      Cinema_4D_2020-06-21_17-15-13.png

      Much better than the 12 hours and 0 results I got from my previous attempt πŸ˜‚

      It looks like there are 5,183,087 segments. I have them split across 519 spline objects. The scene's viewport navigation is still fairly responsive, about 25fps when all the splines are visible. Higher if I zoom into a section.

      I'd still like to improve the method if anyone can provide more information on how I might use SetAllPoints for the splines here.

      posted in Cinema 4D SDK
      W
      wuzelwazel
    • Python API OpenGL Information

      I wanted to try making a small python control panel to monitor viewport OpenGL memory usage. I was also going to explore methods to force a reduction in VRAM usage.

      However, I've noticed several pieces that seem to be missing or non-functional in the Python API and was hoping I could get some info on them.

      First it seems that several of the flags returned by c4d.GeGetSystemInfo() are missing from the python API. The only ones that appear to exist are c4d.SYSTEMINFO_NOGUI and c4d.SYSTEMINFO_OSX. I was hoping that c4d.SYSTEMINFO_OPENGL would be in there.

      Second and more importantly I can't seem to get any information that's useful in my case from c4d.storage.GeGetMemoryStat(). The BaseContainer returned seems to only have values for c4d.C4D_MEMORY_STAT_MEMORY_INUSE and c4d.C4D_MEMORY_STAT_MEMORY_PEAK. All of the other keys return 0 or the keys don't exist in the BaseContainer at all. The latter is the case for c4d.C4D_MEMORY_STAT_OPENGL_USED and c4d.C4D_MEMORY_STAT_OPENGL_ALLOCATED which are the ones I was hoping for.

      posted in Cinema 4D SDK r23 python
      W
      wuzelwazel

    Latest posts made by wuzelwazel

    • Very Slow - AddUndo() Before Removing Object From the Document

      I'm looping through 397 objects in my current scene and removing them all with the following code:

      for obj, _ in instance_grp:
          self.doc.AddUndo(c4d.UNDOTYPE_DELETEOBJ, obj)
          obj.Remove()
      

      I've timed the sub-section of the script where this is happening. When I AddUndo() here the script takes a total of ~4.3 seconds to run and this section in particular takes ~3.1 seconds.

      If I comment out the AddUndo() line like so:

      for obj, mtx in instance_grp:
          #self.doc.AddUndo(c4d.UNDOTYPE_CHANGE, obj)
          obj.Remove()
      

      Then the total runtime of the script is ~1.2 seconds and this section takes ~0.09 seconds. This is unexpected. Is there something I could be doing differently; is this a bug?

      posted in Cinema 4D SDK python 2023
      W
      wuzelwazel
    • RE: How to make Python Field react to camera?

      Calling AddEventNotification() in Python seems to consistently crash Cinema 4D 😞

      posted in Cinema 4D SDK
      W
      wuzelwazel
    • RE: How to make Python Field react to camera?

      @manuel Amazing! Thank you for stepping through this with me.

      I was thinking that messages could be the solution here but I'd only ever dealt with them in the context of a MessageData plug-in and was not aware of AddEventNotification().

      posted in Cinema 4D SDK
      W
      wuzelwazel
    • RE: How to make Python Field react to camera?

      @manuel thanks for getting back to me and apologies for the delay in providing more information.

      I'm attaching a C4D scene file here that includes the setup with Python Field and Camera object.

      camera_field_simple.c4d

      The part of the code where I'm attempting to trigger a refresh of the sampling is in the InitSampling() function and it's pretty simple:

      if camera.GetDirty(c4d.DIRTYFLAGS_MATRIX | c4d.DIRTYFLAGS_DATA):
              op.SetDirty(c4d.DIRTYFLAGS_DATA)
      

      I had also attempted getting the active BaseDraw from the document, checking whether it's linked camera was the one linked in the field, and checking the BaseDraw dirty state instead of the camera but that didn't work out.

      I've also noticed that if I transform the camera and undo the transform the field does not update.

      posted in Cinema 4D SDK
      W
      wuzelwazel
    • How to make Python Field react to camera?

      I'm working on a Python Field that updates based on a camera linked by user data. I was able to get the field to update as the camera attributes are modified or animated by "forwarding" the camera's dirty state to the field object. However, this doesn't work when viewing through the camera and manipulating with shortcuts in the viewport.

      I tried reading the dirty state of the associated BaseDraw but that didn't seem to work. Is this a priority issue? Is there an alternative method to trigger calculation of the field when manipulating the active camera?

      Thanks.

      posted in Cinema 4D SDK python 2023
      W
      wuzelwazel
    • Modifying Cinema 4D Preferences from External Python Script?

      I'm curious whether it would be possible to create a system whereby an external python script could modify the preferences of a running instance of Cinema 4D.

      My first thought was to generate some code in the external script and pass it to Cinema 4D for execution, but that seems (A) potentially unsafe and (B) more complex than it needs to be.

      My second thought was to set a system environment variable from the external script and read it from Cinema 4D. In my case it could be something simple like setting EXTERNAL_STATE = 1 under certain circumstances. This would require Cinema 4D to watch for changes to the environment variable and I'm not sure that's possible.

      The third approach might be for the external script to create a temporary file to represent one state and then remove it in another state. Alternatively it could write data into that file for Cinema 4D to read. This would still require some way for Cinema 4D to watch for changes.

      I suppose I'm curious if there are any known approaches to this sort of thing or which of my 3 potential approaches might be most reasonable. In the 2nd and 3rd cases I'm also curious whether anyone knows of an elegant/efficient way to watch for a change to an environment variable or file.

      Thinking on it a bit more I suppose the most elegant solution would be to send messages directly to Cinema 4D that it could catch and handle in a plug-in. Is that possible?

      Thanks!

      posted in Cinema 4D SDK r23 s24 r25 python sdk
      W
      wuzelwazel
    • Undo Block through Context Manager

      I was just brushing up on the Undo system for a simple Python script and it occurred to me that a context manager like this:

      with doc.UndoBlock():
          doc.AddUndo(...)
          #code that needs to be undone
      

      Might be a nice little quality of life improvement. I suspect that this would be a break from the C++ API so perhaps it's not in the cards, but I thought it was worth bringing up. I would propose that the current method remain valid but a context manager be added as well.

      posted in Cinema 4D SDK
      W
      wuzelwazel
    • RE: Python API OpenGL Information

      @ferdinand it looks like this hasn't changed in S24. Is there an expected timeline for a fix to these bindings?

      Thanks!

      posted in Cinema 4D SDK
      W
      wuzelwazel
    • RE: Python API OpenGL Information

      Thanks again for the update. GPUtil came up as an option when I was researching external modules but it only works with NVIDIA hardware. That might not be so bad for now especially as the Python check for GPU hardware vendor in Cinema 4D does seem to be working.

      I'll mark this as solved for now. I look forward to the API updates!

      posted in Cinema 4D SDK
      W
      wuzelwazel
    • RE: Python API OpenGL Information

      @zipit thank you so much! c4d.GeGetCinemaInfo() makes sense. Unfortunately the current Python documentation is a bit misleading as c4d.GeGetSystemInfo() is not listed as deprecated and the description for c4d.GeGetCinemaInfo() makes it sound like it's exclusively for determining if the current C4D session is NFR.

      Thank you very much for looking into c4d.storage.GeGetMemoryStat(). I'm excited to work on my little OpenGL control panel and stretch my GUI knowledge further πŸ˜‚ πŸ‘

      posted in Cinema 4D SDK
      W
      wuzelwazel