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

    UV Mapping Projection

    PYTHON Development
    0
    13
    1.7k
    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
      Helper
      last edited by

      On 08/10/2015 at 08:13, xxxxxxxx wrote:

      Several years ago I asked how to execute the "Frontal" UV button in BP. And Matthias told me that we cannot execute those buttons.
      I was upset about that. So he (and some other members) posted some code on how to create the UV's like the Frontal button does for me.

      If Maxon can't give us access to these buttons. Then it would be nice if they posted the source code for them.
      AFAIK. The code they use contains nothing secret that they need to keep secret from their competitors. It's all the same maths used by every single software company.
      But math is painful.😂

      It would handy to have the code behind those buttons.

      -ScottA

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

        On 08/10/2015 at 08:31, xxxxxxxx wrote:

        Well that sucks.

        Thanks for taking the time to respond.

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

          On 08/10/2015 at 09:07, xxxxxxxx wrote:

          Hello,

          as Scott mentions, it is unfortunately not possible to access this functionality.

          Best wishes,
          Sebastian

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

            On 08/10/2015 at 09:14, xxxxxxxx wrote:

            Thanks for checking into it.  Maybe in the future it will be available via CallCommand.

            I'm writing a productivity script and it would have saved a step.  I can just click the Box button when I'm in BP adjusting the UV to fit the texture.

            I'm pretty happy that python will get me to that point.  Have to leave something for humans to do or I would be out of a job. 😂

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

              On 09/10/2015 at 08:30, xxxxxxxx wrote:

              Originally posted by xxxxxxxx

              So he (and some other members) posted some code on how to create the UV's like the Frontal button does for me.

              -ScottA

              Could you point us to the posted code?

              -Pim

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

                On 09/10/2015 at 12:06, xxxxxxxx wrote:

                The code was posted in C++ so I don't know if it will help you or not:
                https://developers.maxon.net/forum/topic/6483/6972_uv-mirror-hv&KW=Frontal&PN=1

                This is what I have in my C++ notes:

                //This code creates the equivalent to the flat mapping button in the BP UV options  
                  
                  
                #define SIGDIG    5.0                   //Define a value macro to be used several times later on  
                  
                static Real sign(Real n)  
                {  
                  if( n > 0.0 )    return 1.0;        //Returns zero by default   
                  if( n < 0.0 )    return -1.0;       //Otherwise Returns 1.0 or -1.0  
                  return 0.0;  
                }  
                  
                static Real TrimDecimal(Real num, Real digits)  
                {   
                  Real n;   
                  n = num * Pow((Real)10.0, digits);   
                  n = sign(n) * Abs(Floor(n + 0.5));   
                  return n / Pow((Real)10.0, digits);   
                }   
                  
                Bool FrontalMapUVs(PolygonObject *op, Matrix mg)  
                {  
                  if( !op ) return false;  
                  
                  LONG numFaces = op->GetPolygonCount();  
                  LONG numVerts = op->GetPointCount();  
                  Vector *pVerts = op->GetPointW();  
                  CPolygon *pPolys = op->GetPolygonW();  
                  
                  UVWTag *pUVTag = (UVWTag * )op->MakeVariableTag(Tuvw, numFaces);  
                  if( !pUVTag ) return false;  
                  
                  UVWHandle pUVHndl = pUVTag->GetDataAddressW();  
                  if( !pUVHndl ) return false;  
                  
                  LONG ndx;  
                  Real lenxinv, lenyinv, lenzinv;  
                  Vector mapCenter, mapSize, vMin, vMax;  
                  
                  vMin.x = 100000.0;  
                  vMin.y = 100000.0;  
                  vMin.z = 100000.0;  
                  vMax.x = -100000.0;  
                  vMax.y = -100000.0;  
                  vMax.z = -100000.0;  
                  
                  for(ndx=0; ndx<numVerts; ndx++)  
                  {  
                      Vector pt = pVerts[ndx] * mg;  
                  
                      if( pt.x < vMin.x ) vMin.x = pt.x;  
                      if( pt.x > vMax.x ) vMax.x = pt.x;  
                      if( pt.y < vMin.y ) vMin.y = pt.y;  
                      if( pt.y > vMax.y ) vMax.y = pt.y;  
                      if( pt.z < vMin.z ) vMin.z = pt.z;  
                      if( pt.z > vMax.z ) vMax.z = pt.z;  
                  }  
                  
                  mapSize.x = Abs(vMax.x - vMin.x);  
                  mapSize.y = Abs(vMax.y - vMin.y);  
                  mapSize.z = Abs(vMax.z - vMin.z);  
                  
                  mapCenter.x = vMin.x+(mapSize.x*0.5);  
                  mapCenter.y = vMin.y+(mapSize.y*0.5);  
                  mapCenter.z = vMin.z+(mapSize.z*0.5);  
                  
                  if (mapSize.x!=0.0) lenxinv = 1.0/mapSize.x;    else lenxinv = 0.0;  
                  if (mapSize.y!=0.0) lenyinv = 1.0/mapSize.y;    else lenyinv = 0.0;  
                  if (mapSize.z!=0.0) lenzinv = 1.0/mapSize.z;    else lenzinv = 0.0;  
                  
                  // Walk the list of polygons and map the UVs  
                  for(ndx=0; ndx<numFaces; ndx++)  
                  {  
                      UVWStruct uvw;  
                      pUVTag->Get(pUVHndl, ndx, uvw);  
                  
                      Vector pt_a = (pVerts[pPolys[ndx].a] - mapCenter) + mg.off;  
                      Vector pt_b = (pVerts[pPolys[ndx].b] - mapCenter) + mg.off;  
                      Vector pt_c = (pVerts[pPolys[ndx].c] - mapCenter) + mg.off;  
                      Vector pt_d = (pVerts[pPolys[ndx].d] - mapCenter) + mg.off;  
                  
                      uvw.a.x = TrimDecimal((pt_a.x*lenxinv)+0.5, SIGDIG);  
                      uvw.a.y = TrimDecimal((-pt_a.y*lenyinv)+0.5, SIGDIG);  
                  
                      uvw.b.x = TrimDecimal((pt_b.x*lenxinv)+0.5, SIGDIG);  
                      uvw.b.y = TrimDecimal((-pt_b.y*lenyinv)+0.5, SIGDIG);  
                  
                      uvw.c.x = TrimDecimal((pt_c.x*lenxinv)+0.5, SIGDIG);  
                      uvw.c.y = TrimDecimal((-pt_c.y*lenyinv)+0.5, SIGDIG);  
                  
                      uvw.d.x = TrimDecimal((pt_d.x*lenxinv)+0.5, SIGDIG);  
                      uvw.d.y = TrimDecimal((-pt_d.y*lenyinv)+0.5, SIGDIG);  
                   
                      pUVTag->Set(pUVHndl, ndx, uvw);  
                  }  
                  return true;  
                }
                

                -ScottA

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

                  On 12/10/2015 at 00:24, xxxxxxxx wrote:

                  Thanks again.
                  -Pim

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

                    On 07/12/2015 at 02:03, xxxxxxxx wrote:

                    Originally posted by xxxxxxxx

                    Hello,

                    as Scott mentions, it is unfortunately not possible to access this functionality.

                    Best wishes,
                    Sebastian

                    Hi,
                    Any ideas IF this will be accessible in future SDK updates, and if this future is near or far away?
                    Thanks.

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

                      On 08/12/2015 at 01:28, xxxxxxxx wrote:

                      Hello,

                      currently we cannot make any statements on future releases or API functions.

                      Best wishes,
                      Sebastian

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

                        On 23/12/2015 at 01:33, xxxxxxxx wrote:

                        As the original request to access the projection buttons was from 2012, and seeing that these currently still cannot be called from Python (or even C++, if I read correctly) I thought that with the change in communication we finally would get to know if or when more access to the bodypaint module would be provided.

                        Thanks for reading.

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