Programmatically creating UVWs



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

    On 15/08/2012 at 10:01, xxxxxxxx wrote:

    User Information:
    Cinema 4D Version:    
    Platform:      
    Language(s) :

    ---------
    Hello,

    I'am programmatically creating a mesh which in fact is nothing than just a deformed plane. I want to create an UVW tag onto the virtual object of my generator object to enable UVW mapping for texture-tags. But my current approach is not giving satisfying results.

    The algorithm is to lay out the points of the mesh just like a plane in 2D space, and it looks ok in the UV Edit editor.

    if (info.generate_uvw) {  
      UVWTag* tag = UVWTag::Alloc(n_polys);  
      if (not tag) {  
          goto end;  
      }  
      info.target->InsertTag(tag);  
      
      UVWStruct uvwpoly;  
      LONG poly_i = 0;  
      Real useg = (Real) info.useg;   // Width Segments  
      Real vseg = (Real) info.vseg;   // Height Segments  
      for (LONG i=0; i < info.useg; i++) {  
          for (LONG j=0; j < info.vseg; j++) {  
      
              uvwpoly.d = Vector((i / useg),          (j / vseg),         0);  
              uvwpoly.c = Vector(((i + 1) / useg),    (j / vseg),         0);  
              uvwpoly.b = Vector(((i + 1) / useg),    ((j + 1) / vseg),   0);  
              uvwpoly.a = Vector((i / useg),          ((j + 1) / vseg),   0);  
      
              tag->SetSlow(poly_i, uvwpoly);  
              poly_i++;  
          }  
      }  
    }
    

    The edges might appear like disabled Phong, but it isn't.

    No changes were made to the phong tag.

    Is there some deep magic behind UVW generation? 😄

    Thank you in advance,
    Niklas



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

    On 15/08/2012 at 20:51, xxxxxxxx wrote:

    Speed up your algorithm by defining useg and vseg as inverse and multiplying instead of dividing (expensive) :

    if (info.generate_uvw) {  
      UVWTag* tag = UVWTag::Alloc(n_polys);  
      if (not tag) {  
          goto end;  
      }  
      info.target->InsertTag(tag);  
      
      UVWStruct uvwpoly;  
      LONG poly_i = 0;  
      Real useg = 1.0 / (Real) info.useg;   // Width Segments  
      Real vseg = 1.0 / (Real) info.vseg;   // Height Segments  
      for (LONG i=0; i < info.useg; i++) {  
          for (LONG j=0; j < info.vseg; j++) {  
      
              uvwpoly.d = Vector((i * useg),          (j * vseg),         0);  
              uvwpoly.c = Vector(((i + 1) * useg),    (j * vseg),         0);  
              uvwpoly.b = Vector(((i + 1) * useg),    ((j + 1) * vseg),   0);  
              uvwpoly.a = Vector((i * useg),          ((j + 1) * vseg),   0);  
      
              tag->SetSlow(poly_i, uvwpoly);  
              poly_i++;  
          }  
      }  
    }
    

    Second, the only thing that I can think is that when you generate your object mesh polygons, the order of the vertices for the polygons isn't like how you are arranging the UV coordinates.  Verify that polygon 0 (index) is indeed at the bottom-left (0,0 UV) and so on and that the vertex indices (a,b,c,d) are always in the same orientation (starting with d at the top-left for instance).



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

    On 16/08/2012 at 03:53, xxxxxxxx wrote:

    Thank you very much for your answer, Robert.
    It really just was the order of the points. This one seems to work very fine.

       if (info.generate_uvw) {  
          UVWTag* tag = UVWTag::Alloc(n_polys);  
          if (not tag) goto end;  
          info.target->InsertTag(tag);  
      
          UVWStruct uvwpoly;  
          poly_i = 0;  
          Real useg = 1.0 / (Real) info.useg;  
          Real vseg = 1.0 / (Real) info.vseg;  
          for (LONG i=0; i < info.useg; i++) {  
              for (LONG j=0; j < info.vseg; j++) {  
                  Real a = i;  
                  Real b = j;  
                  Real c = i + 1;  
                  Real d = j + 1;  
                  uvwpoly.a = Vector((c * useg), (b * vseg), 0);  
                  uvwpoly.b = Vector((c * useg), (d * vseg), 0);  
                  uvwpoly.c = Vector((a * useg), (d * vseg), 0);  
                  uvwpoly.d = Vector((a * useg), (b * vseg), 0);  
      
                  tag->SetSlow(poly_i, uvwpoly);  
                  poly_i++;  
              }  
          }  
      }
    

    Thank you!
    Niklas



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

    On 08/12/2012 at 20:47, xxxxxxxx wrote:

    Hi Folks,
     
    sorry to bring up a slightly ageing post, but I was wondering if someone could elaborate on the UVWStruct a little more?
     
    Is it possible to edit a polygon's UV's without having a UVWTag? Whenever I delete the tag on a polygon object, the UV data etc disappears from the structure menu. Where does the structure menu get it's info from?
     
    Cheers,
     
    WP.



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

    On 09/12/2012 at 06:33, xxxxxxxx wrote:

    No.  The UVWTag stores the UVs for the polygon object.  That would explain why the UV data disappears when the tag is deleted.

    UVWStruct is a way to retrieve and set the UVs on a single polygon in the UVWTag.  Every polygon has its own set of UV vertices.  If you need to edit a particular 3D vertex for all polygons that contain it, you will need to set the coordinate of the vertex index (a,b,c, or d) for all of those polygons to have the vertex UV coordinates change in concert.



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

    On 09/12/2012 at 16:59, xxxxxxxx wrote:

    Thanks for the clarification Rob,
     
    is it possible at all then to make/store UV's in your own tag?
     
    It wouldn't matter if the UVW info is displayed in the structure menu or not as my tag could show this in it's own tab/menu.
     
    WP.



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

    On 09/12/2012 at 17:41, xxxxxxxx wrote:

    You could but the Material system uses the UVWTag for texturing using UV mapping.  I don't know if there is a way to achieve this without the UVWTag.  It isn't just an arbitrary tag for storing UVs, it is *the* tag for all UV mapping considerations of polygon objects in C4D, connecting the Polygon object to the Materials.  So, you would still need a UVWTag but you could use your own tag as input into it (say, to store alternative UV mappings).



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

    On 10/12/2012 at 08:37, xxxxxxxx wrote:

    Just to add some additional clarification... you can actually have multiple UVWTags on the same object.  Each "Texture Tag" (which references a Material) set to UVW Mapping will get it's UVW info from the "next UVWTag to the right of itself" - assuming there are more than one.



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

    On 10/12/2012 at 18:57, xxxxxxxx wrote:

    Really enjoying the support this site provides =)
     
    Thanks to both of you. Re: the UV's - I've got a few things to think about now. Cheers,
     
    WP.


Log in to reply