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

    Creating a NormalTag?

    SDK Help
    0
    3
    286
    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 17/04/2017 at 10:24, xxxxxxxx wrote:

      User Information:
      Cinema 4D Version:   R13 
      Platform:   Windows  ;   
      Language(s) :     C++  ;

      ---------
      Hi,

      I'm having trouble creating a proper NormalTag on my polygon objects.
      When I add the new tag. The object is filled with tiny little lines. It looks like OpenGL is freaking out or something.
      I think this is happening because I have not set the tag data. But I'm having trouble figuring out use the Set() function.
      Can someone please post a working example?

      Thanks,
      -ScottA

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

        On 18/04/2017 at 02:43, xxxxxxxx wrote:

        Hi Scott,

        please check out the NormalTag manual, I think it should contain everything you need.

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

          On 18/04/2017 at 07:49, xxxxxxxx wrote:

          Thanks Andreas. That helped me out a lot.

          This is the code version I added to my notes:

          //This is how to create a new normals tag on a polygon object  
              
            PolygonObject *pobj = (PolygonObject* )doc->GetActiveObject();  
            if (!pobj || pobj->GetType() != Opolygon) return false;    
            
            CPolygon *polys = pobj->GetPolygonW();  
            LONG polyCount = pobj->GetPolygonCount();  
            
            //Get the NormalTag on the object  
            NormalTag *normalTag = static_cast<NormalTag*>(pobj->GetTag(Tnormal));      
            
            //If the object doesn't already have a normals tag on it...we add a new tag  
            //NOTE: At this point the object will look very bad...filled with tiny openGL lines!!  
            if (!normalTag)  
            {  
                normalTag = NormalTag::Alloc(pobj->GetPolygonCount());  
                if(normalTag)  
                {  
                    pobj->InsertTag(normalTag);  
                    EventAdd();  
                }  
            }  
            
            /////////////////////////////////////////////////////////////////////////////////////  
            //To fix this uglyness   
            //We need to get the normal vectors of the object and store them in the new NormalTag  
            /////////////////////////////////////////////////////////////////////////////////////  
            
            //First make sure there is a phong tag on the object  
            if (!pobj->GetTag(Tphong)) pobj->MakeTag(Tphong);  
            
            //Get and store the polygon vectors in the new NormalTag so it doesn't look ugly anymore  
            NormalHandle handle = normalTag->GetDataAddressW();  
            for (LONG i = 0; i < polyCount; ++i)  
            {  
                const CPolygon polygon = polys[i];  
            
                //Calculate the default face normals  
                Vector normal = CalcFaceNormal(pobj->GetPointR(), polygon);  
                NormalStruct normals;   
            
                //Save the normals data in the NormalTag  
                normals.a = normal;  
                normals.b = normal;  
                normals.c = normal;  
                normals.d = normal;  
                NormalTag::Set(handle, i, normals);  
            }  
            pobj->Message(MSG_UPDATE);
          

          -ScottA

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