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
    1. Home
    2. codysorgenfrey
    3. Posts
    • Profile
    • Following 0
    • Followers 0
    • Topics 6
    • Posts 17
    • Best 1
    • Controversial 0
    • Groups 0

    Posts made by codysorgenfrey

    • RE: Rotate object around world axis regardless of orientation

      Thanks so much @ferdinand! You all at Maxon are the best. Sorry my code is a shit show, just a quick hack at a rolling cube rig.

      For anyone in the future looking for this solution here's what I needed:

          # Rolling
          distTraveled = pos - PREV_POS
          numRevs.x = (distTraveled.x / circumfrence.x)
          numRevs.z = (distTraveled.z / circumfrence.z)
          outRot = numRevs * c4d.utils.DegToRad(360.0)
          objMx = rotObj.GetMl()
          worldXInLocal = ~objMx * c4d.Vector(1, 0, 0)
          worldZInLocal = ~objMx * c4d.Vector(0, 0, 1)
          xTrans = c4d.utils.RotAxisToMatrix(worldXInLocal, -outRot.z)
          zTrans = c4d.utils.RotAxisToMatrix(worldZInLocal, outRot.x)
          rotObj.SetMl(objMx * xTrans * zTrans)
      

      I needed the cube to be able to roll the correct way regardless of orientation. Admittedly this was a simple matrix transform issue that anyone who actually understood graphics programming would've known. (LOL not me)

      Here's the full scene for anyone interested. test_cube_roll.c4d

      posted in General Talk
      codysorgenfreyC
      codysorgenfrey
    • Rotate object around world axis regardless of orientation

      Hello!

      I'm having a hard time wrapping my brain around this script I'm trying to write.

      I want to rotate a cube along the floor in the direction that it's being animated. The problem I'm running into is that I need to be able to specify the rotation around the world axis (just like how the rotate tool does) so that when the cube is oriented in any direction, I can still rotate properly with the animation.

      Here's some pseudo code and a screen grab. Any help would be greatly appreciated!

      # Rolling
      distTraveled = pos - PREV_POS
      numRevs.x = (distTraveled.x / circumfrence.x)
      numRevs.z = (distTraveled.z / circumfrence.z)
      outRot = numRevs * c4d.utils.DegToRad(360.0)
      objMx = rotObj.GetMl()
      rotMx = c4d.utils.MatrixRotY(-outRot.z) * c4d.utils.MatrixRotZ(outRot.x)
      rotObj.SetMl(objMx * rotMx)
      

      https://microsoft-my.sharepoint-df.com/✌/p/cosorgen/ESTEQCvARE1Nn4F3qnKfCC8B1nahC5Y3iHhSvgOtkhO0DQ?e=xhrNCK

      This code almost works, but some of the time the cube rotates the wrong direction (although on the right axis).

      posted in General Talk python
      codysorgenfreyC
      codysorgenfrey
    • RE: FontData BaseContainer IDs

      I was actually able to get what I need through GeClipMap's GetFontDescription().

      Thanks!

      posted in Cinema 4D SDK
      codysorgenfreyC
      codysorgenfrey
    • FontData BaseContainer IDs

      Re: [python] SetFont not working

      @m_adam Thank you so much for this example of setting the FontData of a MoText. Would you mind showing me where I can figure out what each ID is setting?

      500: Font Family?
      501: ?
      502: Font Weight?
      503: ?
      509: Font family again?
      508: Font postscript name?

      Any help would be much appreciated!

      posted in Cinema 4D SDK python r20
      codysorgenfreyC
      codysorgenfrey
    • RE: Bug in mograph python effector default state R20

      Hey @m_adam thanks for getting back to me. I'm on R20.059.

      Here's the default python effector when switched to full control. I haven't touched anything. As you can see it does nothing even though it's supposed to be lifting each clone up 100cm.

      If you set the last parameter in the md.SetArray() function to False. It will work.

      python_effector_demo_01.c4d

      posted in Cinema 4D SDK
      codysorgenfreyC
      codysorgenfrey
    • Bug in mograph python effector default state R20

      When you use a mograph python effector switched to "full control" mode by default it doesn't work because of the absence of a falloff field. It took me awhile to figure out why my custom effectors didn't work coming from R18 to R20.

      I would suggested updating the boilerplate in the effector when switching to full control mode to check for a falloff if that's possible. If not maybe fall back to commented out version for with falloff and without?

      posted in Cinema 4D SDK r20 python
      codysorgenfreyC
      codysorgenfrey
    • RE: Getting MoData in GVO of a ObjectData Plugin

      @m_adam thanks so much for all your help on this!

      posted in Cinema 4D SDK
      codysorgenfreyC
      codysorgenfrey
    • RE: Getting MoData in GVO of a ObjectData Plugin

      @m_adam I'm finally getting around to implementing this fix, and it's working really well except for it's alway rebuilding the cache, GetAndCheckHeirarchyClone is always saying the input object is dirty.

      Is this how it's supposed to work?

      posted in Cinema 4D SDK
      codysorgenfreyC
      codysorgenfrey
    • RE: Sample a shader in 3D space in GVO

      Thanks @r_gigante that's what I thought.

      posted in Cinema 4D SDK
      codysorgenfreyC
      codysorgenfrey
    • Sample a shader in 3D space in GVO

      Hello,

      What's the proper way to sample a shader (noise, gradient, etc.) in 3D space without a given VolumeData object?

      I understand how to map the ChannelData's p (uvw) parameter to my object's uvw coordinates, but how do I sample in a way that works like Mograph's shader effector works?

      When I sample a noise, and put my objects uvw coordinates in the ChannelData object, if I switch the noise to "World Space", that doesn't work obviously, cause i'm still sampling in texture space in the code. Do you have to manually check that parameter in the BaseShader object?

      See simplified code:

      BaseObject* GetVirtualObjects(BaseObject* op, HierarchyHelp* hh)
      {
          GeData           myData;
          Bool             cacheDirty, dirty, frameUpdate;
          BaseObject       *outObject, *customShape;
          BaseShader       *shader;
          BaseDocument     *doc = hh->GetDocument();
          InitRenderStruct irs(doc);
          
          outObject = BaseObject::Alloc(Onull); // dummy output object
          
          cacheDirty = op->CheckCache(hh);
          dirty = op->IsDirty(DIRTYFLAGS_DATA | DIRTYFLAGS_MATRIX);
          
          op->GetParameter(DescLevel(FROMSHADER_FRAME_UPDATE), myData, DESCFLAGS_GET_0);
          frameUpdate = myData.GetBool();
          
          if (frameUpdate)
          {
              Int32 curFrame = doc->GetTime().GetFrame(doc->GetFps());
              if (curFrame != prevFrame){
                  dirty = true;
                  prevFrame = curFrame;
              }
          }
          
          if (!dirty && !cacheDirty)
          {
              blDelete(outObject);
              return op->GetCache();
          }
          
          op->GetParameter(DescLevel(FROMSHADER_SHADER), myData, DESCFLAGS_GET_0);
          shader = (BaseShader *)myData.GetLink(doc);
          
          if (!shader)
              goto error;
          
          StatusSetSpin();
          
          customShape = BaseObject::Alloc(Ocube);
          customShape->SetParameter(DescLevel(PRIM_CUBE_LEN), GeData(Vector(shapeSize)), DESCFLAGS_SET_0);
          customShape = MakeEditable(customShape, doc, true);
          
          if (!customShape)
              goto error;
          
          if (shader->InitRender(irs) != INITRENDERRESULT_OK)
              goto error;
          
          if (!helper->grid)
              return false;
          
          StatusSetText("Sampling Noise");
          
          Vector rad = customShape->GetRad();
          
          for ( ; iter; ++iter)
          {
              ChannelData cd;
      
              cd.off = 0;
              cd.scale = 0;
              cd.t = time;
              cd.texflag = CALC_TEXINFO(0, CHANNEL_COLOR);
              cd.d = Vector(1, 1, 1);
              cd.n = Vector(0, 1, 0);
              cd.vd = nullptr;
              Vector pos = iter.getPos();
              Vector worldPos = op->GetMg() * Vector(pos.x(), pos.y(), pos.z());
              Float min = 1 - ((rad.x + rad.y + rad.z) / 3);
              Float max = ((rad.x + rad.y + rad.z) / 3);
              cd.p = Vector((c4dPos.x - min) / (max - min),
                            (c4dPos.y - min) / (max - min),
                            (c4dPos.z - min) / (max - min));
      
              Vector col = shader->Sample(&cd);
              Float luma = 0.2126 * col.x + 0.7152 * col.y + 0.0722 * col.z; // calc luminence
              iter.setValue(luma);
          }
          
          shader->FreeRender();
          
          StatusClear();
          
          customShape->InsertUnder(outObject);
          
          return outObject;
          
      error:
          blDelete(outObject);
          StatusClear();
          return nullptr;
      }
      
      
      posted in Cinema 4D SDK c++ windows macos r19 sdk classic api
      codysorgenfreyC
      codysorgenfrey
    • RE: Getting MoData in GVO of a ObjectData Plugin

      @m_adam Thanks for the thorough response! This solution actually fits my needs better anyways.

      posted in Cinema 4D SDK
      codysorgenfreyC
      codysorgenfrey
    • RE: Getting MoData in GVO of a ObjectData Plugin

      So interesting find today. I think in order to get updates on the cache of a mograph matrix object I need to respond to MSG_MOGRAPH_REEVAULATE. Is this correct?

      It seems to be the only way to get notified of when the mograph cache is updated, especially when using effectors.

      posted in Cinema 4D SDK
      codysorgenfreyC
      codysorgenfrey
    • RE: Getting MoData in GVO of a ObjectData Plugin

      @m_adam Thanks for the update. I'm in no hurry as I can work on other parts of the project while I wait. I look forward to your investigation!

      posted in Cinema 4D SDK
      codysorgenfreyC
      codysorgenfrey
    • RE: Getting MoData in GVO of a ObjectData Plugin

      Also the mograph cache tag never returns modata, even when it's present and baked.

      posted in Cinema 4D SDK
      codysorgenfreyC
      codysorgenfrey
    • Getting MoData in GVO of a ObjectData Plugin

      Hello,
      I'm trying to get the positions of the mograph matrix object in my ObjectData plugin and i'm having trouble with checking if it's cache is dirty and updating.

      I'm using GetAndCheckHierarchyClone to tell if the cache is dirty, which is working, but for some reason it's saying that the cache is dirty twice.

      Also when it does say the cache is dirty, I go to read the Matrix Array, and it returns outdated data.

      Am I missing a step somewhere?

      I'm developing on Mac OSX with C4D R18.

      Here's my code (shortened for clarity and no error checking):

      BaseObject* GetVirtualObjects(BaseObject* op, HierarchyHelp* hh)
      {
          GeData     myData;
          Bool       dirty;
          BaseObject *outObject, *inObject, *hClone;
          
          outObject = BaseObject::Alloc(Ocube);
          dirty = false;
          hClone = nullptr;
          
          inObject = op->GetDown();
          
          hClone = op->GetAndCheckHierarchyClone(hh, inObject, HIERARCHYCLONEFLAGS_ASIS, &dirty, nullptr, false);
          
          if (!dirty) {
              blDelete(outObject);
              return hClone;
          }
          
          maxon::BaseArray<Vector> pointList;
          MoData *md;
          GetMoDataMessage mdm;
          mdm.modata = nullptr;
          mdm.index = 0; // Get first set of modata
          
          BaseTag *mct = hClone->GetTag(ID_MOBAKETAG); // check for cache
          BaseTag *mdt = hClone->GetTag(ID_MOTAGDATA); // get mograph tag
          if (!mct && !mdt) // we need at least one
              return nullptr;
          
          if (mct) // check cache first
              mct->Message(MSG_GET_MODATA, &mdm);
          
          if (!mdm.modata) // if cache didn't work, or if there is no cache
              mdt->Message(MSG_GET_MODATA, &mdm);
          
          if (mdm.user_owned)
              md = mdm.Release();
          else
              md = mdm.modata;
          
          MDArray<Matrix> marr = md->GetMatrixArray(MODATA_MATRIX);
          
          for (Int32 x = 0; x < md->GetCount(); x++)
          {
              pointList.Append(marr[x].off);
          }
          
          if (mdm.user_owned)
              MoData::Free(md);
          
          GePrint( String::IntToString( pointList.GetCount() ) );
          
          return outObject;
      }
      
      posted in Cinema 4D SDK c++ windows macos
      codysorgenfreyC
      codysorgenfrey
    • RE: Problem with DeleteObj() and maxon::PointerArray

      Ahhhh thanks! I couldn't find an Array Manual in the R18 documentation.

      I was going like this:

      maxon::PointerArray<MyCustomClass> myPointerArr = NewObj(maxon::PointerArray<MyCustomClass>);
      DoStuffWithArray(myPointerArr);
      DeleteObj(myPointerArr);
      

      It seems my problem was with the PointerArray taking ownership of my pointers, then deallocating them before I was done with them. Since it doesn't seem that R18 has maxon::UniqueRef objects I decided to go with a maxon::BaseArray<MyCustomClass*> instead.

      Thanks again for your help Sebastian!

      posted in Cinema 4D SDK
      codysorgenfreyC
      codysorgenfrey
    • Problem with DeleteObj() and maxon::PointerArray

      I'm workinig on a c++ plugin in R18 on Mac with Xcode. When I create a new maxon::PointerArray<customtype> with NewObj() in GetVirtualObjects, everything is working great. The problem is when I go to free the pointer array with DeleteObj() after i'm done with it I get a EXC_BAD_ACCESS.

      My question is, how do I free up this array? Do I need too, or does the auto memory management take care of it when it falls out of scope? It is local in my GetVirtualObjects method.

      Thanks!

      posted in Cinema 4D SDK c++ macos sdk
      codysorgenfreyC
      codysorgenfrey