HAIR API



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

    On 09/12/2006 at 07:42, xxxxxxxx wrote:

    thanks for ur reply...so there is no way to change hair color,frizz,wave..etc using coffee??



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

    On 11/12/2006 at 03:27, xxxxxxxx wrote:

    You can access the Hair paramters through XPresso. Not sure how this will help you because I don't know what you want to achieve.

    cheers,
    Matthias



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

    On 13/12/2006 at 08:28, xxxxxxxx wrote:

    hi..thanks for ur reply...i'm trying to develop a hair plugin using coffee..and create a few default hair styles to grow hair with a click of a button..is it possible to set data for hair color,frizz,wave,curl using coffee so that i could style an object?? because i dont know how to access the hair material tag using coffee because frizz curl etc is under hair material tag...i'm having a deadline to develop this plug-in, pls do reply asap if this is possible...

    thanks
    benny



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

    On 14/12/2006 at 04:40, xxxxxxxx wrote:

    Ok, had another look at Hair and COFFEE and it seems Hair is supported by COFFEE.

    You know that you can get the description IDs by dragging them into the COFFEE script editor? Here a little script that creates a new Hair material and switches on the Bend channel and sets the Bend strength to 100 percent.

      
    var myhairmat = AllocMaterial(Mhair);  
    myhairmat#HAIRMATERIAL_USE_BEND = TRUE;  
    myhairmat#HAIRMATERIAL_BEND = 1;  
    doc->InsertMaterial(myhairmat,NULL);  
    

    cheers,
    Matthias



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

    On 16/12/2006 at 07:35, xxxxxxxx wrote:

    hi matthias..thanks alot for ur reply..this is what i could come up with so far to grow the hair...but i dont know how to link it to my script so that the hair material tag comes up , it gives errors.i tried to use HAIRMATERIAL_COLOR_GRADIENT,vector(0.5,0.5,0.5) to change the hair color but it doesent work, but others work, like frizz etc..would u be able to look at the script and let me know how to link the hair material u sent,into my script so that it works to change parameters under hair material tag? i'm very new to C4D and coffee and quaite lost.

    var doc = GetActiveDocument();
    doc->InsertMaterial(AllocMaterial(Mhair), NULL);

    // Activates the bump channel for a material
    var mat = doc->GetFirstMaterial();
    mat->SetName("Hair");
    //mat->SetChannelState(CHANNEL_COLOR, TRUE);
    //mat->SetChannelState(CHANNEL_BUMP, FALSE);
    //mat->SetChannelState(CHANNEL_SPECULAR, TRUE);

    // Sets a texture for it
    //var color = mat->GetChannel(CHANNEL_COLOR);
    //var colorBc = color->GetContainer();
    //colorBc->SetData(CH_COLOR,vector(0.5,0,0));
    //color->SetContainer(colorBc);

    var hobj = AllocObject(oHair);
    var hcon = hobj->GetContainer();
    var tobj = doc->FindObject("Cube");
    hcon->SetData(HAIRSTYLE_HAIR_COUNT, 40000);
    hcon->SetData(HAIRSTYLE_LINK,tobj);
    hcon->SetData(HAIRSTYLE_FUR,true);
    hcon->SetData(HAIRSTYLE_FUR_COUNT,4800);
    hobj->SetContainer(hcon);

    // Insert a NURBS object
    if(!doc->InsertObject(hobj, NULL, NULL)) return FALSE;

    //new - texture
    var tag,nam;
    nam = hobj->GetName();
    hobj->InsertTag(AllocTag(Ttexture));

    // Messages
    GeEventAdd(NEW_ACTIVE_OBJECT);
    doc->Message(MSG_UPDATE);
    doc->Message(DOCUMENT_CHANGED);

    // var mat1 = vDoc->FindMaterial("Rail");
    var mat2 = doc->FindMaterial("Hair");

    tag = hobj->GetFirstTag();
    var ma;

    ma = mat2->GetMarker();

    while (tag)
        {

    if (instanceof(tag,TextureTag))
        {
              tag->SetMaterial(ma);
          }

    tag = tag->GetNext();

    } //while end

    GeEventAdd(DOCUMENT_CHANGED);



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

    On 18/12/2006 at 02:03, xxxxxxxx wrote:

    Here a little script how to get the Hair material from the hair tag and how to set the colors of the Color gradient. Not that you can't add knots to the gradients with COFFEE, so at the moment you are restricted to the two default knots. Also the script adds Hair to a selected object ( CallCommand(1018401) ).

      
    SetHairMat(hairmat)  
    {  
         hairmat#HAIRMATERIAL_COLOR_GRADIENT:10100 = vector(1,0,0);  
         hairmat#HAIRMATERIAL_COLOR_GRADIENT:10200 = vector(0,0,1);  
    }  
      
    main(doc,op)  
    {  
         CallCommand(1018401);  
         var hairtag = doc->GetActiveObject()->GetFirstTag();  
         while(hairtag)  
         {  
              if(hairtag->GetType() == Thairmaterial)  
              {  
                   SetHairMat(hairtag#HAIRMATERIAL_TAG_LINK);            
                   break;  
              }  
              hairtag->GetNext();  
         }  
    }  
    

    hope this helps

    cheers,
    Matthias



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

    On 18/12/2006 at 07:32, xxxxxxxx wrote:

    hi matthias..the script really helped me to set the parameters under hair material...there is just one more thing that i need to know, how do u set data to change hair length , hair count and fur count? beacuse it doesent come under hair material data, so that i could add it to the script...

    thanks a million for ur help.. i really appreciate it...



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

    On 18/12/2006 at 08:14, xxxxxxxx wrote:

    hi... wanted to ask u one more thing...when i execute the script u sent using the script manager it works but it doesent work when i compile it using the compiler and put it under plug-ins?



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

    On 19/12/2006 at 02:26, xxxxxxxx wrote:

    Well you have to build a plugin framework first, in your case you probably want to create a menu plugin. Check the COFFEE documentation for plugin types. There is a template framework example for each plugin type. For a menu plugin this is "menuplugin.cof".

    cheers,
    Matthias



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

    On 19/12/2006 at 07:30, xxxxxxxx wrote:

    yes...i have already created the menu plug-in frame and it works... when i try to link the main script u sent to the plug-in frame there seems to be some error...the plug-in doesent show up under the plug-in menu..what i like to know is, how do u change hair length,count , fur count and use the relax button?? becasue it doesent come under hair material...it's description id's comes as "HAIRSTYLE" pls do let me know if u know how to do that and how to link it to the above program u sent earlier without any errors so that i could change hair length , count etc...

    thanks again for ur replies,really appreciate it..



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

    On 22/12/2006 at 09:38, xxxxxxxx wrote:

    hi...matthias, would u b able to assist me with this last part of the coffee script which i cant figure out...which is, how to change hair length,count, fur count and relax the hair in the same script u sent me earlier, becasue i tried changing it but since these things are not under hair material, i dont know which commands to use......i would much appreciate it,if u could help me with this as soon as possible...

    thanks..
    cheers



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

    On 26/12/2006 at 23:26, xxxxxxxx wrote:

    hi...matthias, thanks alot for ur replies...would u b able to assist me with this last part of the coffee script which i cant figure out...which is, how to change hair length,count, fur count and relax the hair in the same script u sent me earlier, becasue i tried changing it but since these things are not under hair material, i dont know which commands to use......i would much appreciate it,if u could help me with this as soon as possible...

    merry x mas
    cheers



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

    On 29/12/2006 at 03:09, xxxxxxxx wrote:

    Here is the modified code. I am not sure what you mean with relax, if you mean the Relax button on the dynamics page then I am sorry to tell you that you can't access it with COFFEE.

      
    SetHairMat(hairmat)  
    {  
         hairmat#HAIRMATERIAL_COLOR_GRADIENT:10100 = vector(1,0,0);  
         hairmat#HAIRMATERIAL_COLOR_GRADIENT:10200 = vector(0,0,1);  
    }  
      
    main(doc,op)  
    {  
         CallCommand(1018401);  
         var hairobj = doc->GetActiveObject();  
         hairobj#HAIRSTYLE_LENGTH = 50; //Hair length  
         hairobj#HAIRSTYLE_HAIR_COUNT = 2500; //Hair count  
         hairobj#HAIRSTYLE_FUR = TRUE; //switch on Fill hairs  
         hairobj#HAIRSTYLE_FUR_COUNT = 10000; //Fill hair count  
         hairobj#HAIRSTYLE_DYNAMICS_FRAMES = 20; //relax frame count  
      
         var hairtag = hairobj->GetFirstTag();  
         while(hairtag)  
         {  
              if(hairtag->GetType() == Thairmaterial)  
              {  
                   SetHairMat(hairtag#HAIRMATERIAL_TAG_LINK);            
                   break;  
              }  
              hairtag->GetNext();  
         }  
    }  
    

    cheers,
    Matthias



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

    On 30/12/2006 at 09:10, xxxxxxxx wrote:

    hi matthias...u been a gr8 help....thanks alot for ur assistance....

    happy holidays
    and happy new year
    cheers



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

    On 25/01/2007 at 11:03, xxxxxxxx wrote:

    Is there more Examples how to proper use Hair API inside GetVirtualObjects()?

    Is there any possibility to fill RootObjectData self?
    What is with GetRootObject(), why is there no SetRootObject() ?

    C4D SDK 6.9 do not talk a lot about Hair API...



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

    On 26/01/2007 at 03:54, xxxxxxxx wrote:

    I'll give a quick outline of how to create guides for a hair object in GetVirtualObjects, if you have anything specific you need to know then ask and I'll reply asap.

    First allocate a hair object with HairObject::Alloc(), then before you can modify or create guides you must use the Lock() function, as this is a newly created object you don't need it to run a validate (so set that to FALSE). The validate option ensures that any guides are still valid (checking the roots and root object). Just pass 0 for flags.

    Now you can start adding guides. To do this use the HairGuides::Alloc() function, passing the number of guides and segments per guide. You then need to set the guides into the hair object, so call SetGuides() from the hair object passing the guides pointer. Set clone to FALSE (otherwise it will just copy the guides leaving you to free the guides you allocated).

    Next you need to set the guides world matrix, so call SetMg() from the guides pointer. This matrix is used to transform the guides to the world origin whenever they need to be styled or transformed to a new coordinate system. This is only needed if you are creating your guides relative to something else (like a surface of an object).

    Now you can fill in the guides points, call GetPoints() from the guides pointer.

    When you have finished setting the points for the guides you just call Unlock() for the hair object.

    Before you exit GetVirtualObjects() you need to call the Update() function from the hairobject, this just runs the hair objects Execute() so that the hair updates to any changes made to the guides/parameters. Update must never be called in a lock.



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

    On 26/01/2007 at 04:47, xxxxxxxx wrote:

    Thanks David for you fast reply!

    Well this is that what I have do but without Lock() and Update(), will try wit it now.

    Actually my Guides are in most cases relative an Object. So do I need to link this object to Hair Object in some way except of SetMg()?

    Will the Hair Dynamics work now in this way?



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

    On 26/01/2007 at 06:02, xxxxxxxx wrote:

    So I have done all this and the Hair do not want to render now.
    If hair->Update(doc); will be removed then hair will be rendered but the Hair Material do not affect them.
    What is wrong?

      
    HairObject *hair = HairObject::Alloc(); if(!hair) return NULL;  
    hair->Lock(doc,thread,FALSE,0); // Loock Hair  
      
    HairGuides *hairGuides = HairGuides::Alloc(m_Count,m_Segments);  
    if (hairGuides) hair->SetGuides(hairGuides,FALSE);  
    hairGuides->SetMg(mg);  
      
    Vector     *pnts = hairGuides->GetPoints();  
      
      
    //... Create Guides ...  
      
      
    hair->Unlock(); // Unlock Hair  
    hair->Update(doc);  
    return hair;  
    


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

    On 27/01/2007 at 08:56, xxxxxxxx wrote:

    If creating a hair object from a generator as the cache will be destroyed at various times dynamics won't work as any previous data is lost. You would need to hold a copy of the hair object and update it in Execute (with Update(), this does the dynamics also).

    As for not rendering, I added a quick SDK example and this works fine (code below). Had you added the Hair Renderer? Also you would need to copy any tags from your generator to the created hair object for any materials to be used at render time.

    This is the sdk example code and seems fine:

      
    /////////////////////////////////////////////////////////////  
    // CINEMA 4D SDK                                           //  
    /////////////////////////////////////////////////////////////  
    // (c) 1989-2007 MAXON Computer GmbH, all rights reserved //  
    /////////////////////////////////////////////////////////////  
      
    // example code for creating a generator that creates Hair  
      
    //////////////////////////////////////////////////////////////////////////  
      
    #include "c4d.h"  
    #include "c4d_symbols.h"  
    #include "lib_hair.h"  
    #include "ohairsdkgen.h"  
      
    //////////////////////////////////////////////////////////////////////////  
      
    class HairGeneratorObject : public ObjectData  
    {  
         INSTANCEOF(HairGeneratorObject,ObjectData)  
      
    public:  
      
         virtual Bool Init(GeListNode *node);  
         virtual void Free(GeListNode *node);  
      
         virtual Bool Message(GeListNode *node, LONG type, void *data);  
         virtual Bool Draw(PluginObject* op, LONG drawpass, BaseDraw* bd, BaseDrawHelp* bh);  
         virtual BaseObject* GetVirtualObjects(PluginObject *op, HierarchyHelp *hh);  
      
         virtual Bool AddToExecution(PluginObject* op, PriorityList* list);  
         virtual LONG Execute(PluginObject* op, BaseDocument* doc, BaseThread* bt, LONG priority, LONG flags);  
      
         static NodeData *Alloc(void) { return gNew HairGeneratorObject; }  
    };  
      
    //////////////////////////////////////////////////////////////////////////  
      
    Bool HairGeneratorObject::Init(GeListNode *node)  
    {  
         BaseContainer *bc=((BaseList2D* )node)->GetDataInstance();  
           
         bc->SetLong(HAIR_GEN_COUNT,5000);  
         bc->SetLong(HAIR_GEN_SEGMENTS,6);  
         bc->SetReal(HAIR_GEN_LENGTH,15);  
         bc->SetReal(HAIR_GEN_LENGTH_VAR,5);  
         bc->SetReal(HAIR_GEN_NOISE,0.2);  
         bc->SetBool(HAIR_GEN_GENERATE,FALSE);  
      
         return TRUE;  
    }  
      
    void HairGeneratorObject::Free(GeListNode *node)  
    {  
    }  
      
    Bool HairGeneratorObject::Message(GeListNode *node, LONG type, void *data)  
    {  
         return SUPER::Message(node,type,data);  
    }  
      
    Bool HairGeneratorObject::Draw(PluginObject* op, LONG drawpass, BaseDraw* bd, BaseDrawHelp* bh)  
    {  
         return TRUE;  
    }  
      
    Bool HairGeneratorObject::AddToExecution(PluginObject* op, PriorityList* list)  
    {  
         list->Add(op,EXECUTION_GENERATOR,-1);  
         return TRUE;  
    }  
      
    static void RunExecute(BaseObject *op, BaseDocument *doc)  
    {  
         while (op)  
         {  
              if (op->IsInstanceOf(Ohair)) ((HairObject* )op)->Update(doc);  
              RunExecute(op->GetDown(),doc);  
              op=op->GetNext();  
         }  
    }  
      
    LONG HairGeneratorObject::Execute(PluginObject* op, BaseDocument* doc, BaseThread* bt, LONG priority, LONG flags)  
    {  
         RunExecute(op->GetCache(),doc);  
         return EXECUTION_RESULT_OK;  
    }  
      
    BaseObject *HairGeneratorObject::GetVirtualObjects(PluginObject *pObject, HierarchyHelp *hh)  
    {  
         Bool bDirty = pObject->CheckCache(hh);  
         HairObject *main=NULL;  
      
         if (!bDirty) bDirty = pObject->IsDirty(DIRTY_DATA|DIRTY_MATRIX);  
         if (!bDirty) return pObject->GetCache(hh);  
      
         BaseContainer *bc=pObject->GetDataInstance();  
      
         main = HairObject::Alloc();  
         if (!main) goto Error;  
      
         main->Lock(hh->GetDocument(),hh->GetThread(),FALSE,0);  
      
         HairGuides *guides = HairGuides::Alloc(1000,8);  
         if (!guides) goto Error;  
      
         main->SetGuides(guides,FALSE);  
         //guides->SetMg(mg);  
      
         Vector *pnts = guides->GetPoints();  
      
         LONG i,l;  
      
         for (i=0;i<1000;i++)  
         {  
              for (l=0;l<=8;l++)  
              {  
                   pnts[i*9+l]=Vector(i,l*20.0,0.0);  
              }  
         }  
      
         main->Unlock();  
      
         if (!pObject->CopyTagsTo(main,TRUE,FALSE,FALSE,NULL)) goto Error;  
      
         main->Update(hh->GetDocument());  
      
         return main;  
      
    Error:  
      
         HairObject::Free(main);  
      
         return BaseObject::Alloc(Onull);  
    }  
      
    //////////////////////////////////////////////////////////////////////////  
      
    #define ID_HAIR_GENERATOR_EXAMPLE 1020787  
      
    Bool RegisterGeneratorObject()  
    {  
         return RegisterObjectPlugin(ID_HAIR_GENERATOR_EXAMPLE,GeLoadString(IDS_HAIR_GENERATOR_EXAMPLE),OBJECT_GENERATOR|OBJECT_INPUT,HairGeneratorObject::Alloc,"Ohairsdkgen","hairgen.tif",0);  
    }  
      
    


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

    On 28/01/2007 at 14:19, xxxxxxxx wrote:

    Thanks David now it working.
    The rendering problem was becouse I still have used hairGuides->SetRoot(0,hroot,FALSE); probably with wrong HairRootData.


Log in to reply