Plugin Cafe Homepage
Forum Home Forum Home > Plugin Cafe > SDK Help
  New Posts New Posts
  FAQ FAQ  Forum Search   Register Register  Login Login

Creating a NormalTag?

 Post Reply Post Reply
Author
Message
ScottA View Drop Down
Member
Member


Joined: 2011 Jan 07
Online Status: Offline
Posts: 2268
Post Options Post Options   Quote ScottA Quote  Post ReplyReply Direct Link To This Post Topic: Creating a NormalTag?
    Posted: 2017 Apr 17 at 10:24am

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

Back to Top
Andreas Block View Drop Down
Forum Moderator
Forum Moderator
Avatar

Joined: 2014 Oct 01
Location: Hannover
Online Status: Online
Posts: 1268
Post Options Post Options   Quote Andreas Block Quote  Post ReplyReply Direct Link To This Post Posted: 2017 Apr 18 at 2:43am
Hi Scott,

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

Cheers,
Andreas
SDK Support Engineer
Back to Top
ScottA View Drop Down
Member
Member


Joined: 2011 Jan 07
Online Status: Offline
Posts: 2268
Post Options Post Options   Quote ScottA Quote  Post ReplyReply Direct Link To This Post Posted: 2017 Apr 18 at 7:49am
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
Back to Top
 Post Reply Post Reply

Forum Jump Forum Permissions View Drop Down

Bulletin Board Software by Web Wiz Forums® version 9.61 [Free Express Edition]
Copyright ©2001-2009 Web Wiz

This page was generated in 0.093 seconds.