Materials



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

    On 20/12/2010 at 19:03, xxxxxxxx wrote:

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

    ---------
    Hello,
    How can I change the values (for example the color) of a Material?
    With BaseMaterial *mat = BaseMaterial::Alloc(Mmaterial); I can create a grey Material and with doc->InsertMaterial(mat); I can add it to the document. But how do I change the Color and the Texture of that material?
    The "documentation" and the example files have no information about that.
    All I found is that there is a function "GetChannel(CHANNEL_COLOR);" but the return value has no information about the color :(



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

    On 20/12/2010 at 19:30, xxxxxxxx wrote:

    Vector colorv = ;
    Material* mat = ;

    mat->SetParameter(DescID(MATERIAL_COLOR_COLOR), GeData(colorv), DESCFLAGS_SET_DONTCHECKMINMAX);

    You have to realize that there is a Color for many of the channels and you have to handle each channel separately.  Most channels also have a Texture and unique parameters.  The information is stored in the resource\res\description\mmaterial.h file and using SetParameter and GetParameter to set and get the data of the material.



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

    On 20/12/2010 at 21:42, xxxxxxxx wrote:

    Thank you very much! That works.
    I was also able to add UVWCoords to my PolygonObject.
    How do I add a texture to my Material?

    Edit: Got it to work now! If someone has similar problems, here is my test code:

    ZPolygon *polygons = (ZPolygon* )GeAlloc(sizeof(ZPolygon) * 1);
         polygons[0].a.x = 0;
         polygons[0].a.y = 0;
         polygons[0].a.z = 0;
         polygons[0].b.x = 100;
         polygons[0].b.y = 0;
         polygons[0].b.z = 0;
         polygons[0].c.x = 100;
         polygons[0].c.y = 100;
         polygons[0].c.z = 0;
         PolygonObject *op = PolygonObject::Alloc(3 * 100, 100);
         op->SetName("Name");
         CPolygon *pol = op->GetPolygonW();
         Vector *vertices = op->GetPointW();

    pol[0] = CPolygon(0, 1, 2);
         vertices[0] = polygons[0].a;
         vertices[1] = polygons[0].b;
         vertices[2] = polygons[0].c;

    BaseMaterial *mat = BaseMaterial::Alloc(Mmaterial);
         if(!mat)
              op->SetName("Failed");
         else {
              Vector colorv = Vector(1.0, 0.7, 0.3);
              mat->SetParameter(DescID(MATERIAL_COLOR_COLOR), GeData(colorv), NULL);
              UVWTag *uvtag = (UVWTag* )op->MakeVariableTag(Tuvw, 1);
              UVWStruct str = UVWStruct(Vector(0, 1, 0), Vector(1, 1, 0), Vector(1, 0, 0));
              BaseChannel *ch = mat->GetChannel(CHANNEL_COLOR);
              BaseContainer bc = ch->GetData();
              bc.SetString(BASECHANNEL_TEXTURE, "C:\\Path\\To\\Image.jpg");
              ch->SetData(bc);
              uvtag->SetSlow(0, str);
              doc->InsertMaterial(mat);
              TextureTag* textag = TextureTag::Alloc();
              textag->SetMaterial(mat);
              textag->SetParameter(TEXTURETAG_PROJECTION, GeData(TEXTURETAG_PROJECTION_UVW), NULL);
              op->InsertTag(textag);
         }

    op->Message(MSG_UPDATE);

    doc->InsertObject(op, NULL, NULL);
    EventAdd();



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

    On 16/06/2012 at 06:17, xxxxxxxx wrote:

    After problems with uvw coordinates in my code i decide to try out the code above. But the problem is still the same. I can't see the texture, but after using the mouse to move the uvw-tag the texture appears correct. Thereby it's not the position of the uvw-tag. if i move it back it still works fine.

    I've tryed to make any types of refreshs and redraws but nothing seems to work.

    I've changed the 3rd parameter of SetParameter from NULL to DESCFLAGS_SET_0 (R13)

    Is there anybody with a simular problem or an idea?



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

    On 16/06/2012 at 08:34, xxxxxxxx wrote:

    This code works for me in R12.

    //This example creates a polygon. Then adds a material with a texture image to it  
      
      PolygonObject *mypoly = PolygonObject::Alloc(4,1); if(!mypoly) return NULL;  
      Vector *gp = mypoly->GetPointW();//Gets the array of points in the polygon and assigns it to a variable "gp"          
      gp[0] = Vector(-100,0,-100);    // Place the first point here  
      gp[1] = Vector(-100,0,100);     // Place the first point here  
      gp[2] = Vector(100,0,100);      // Place the first point here  
      gp[3] = Vector(100,0,-100);     // Place the fourth point here  
      
    // Create the new poly based on the points  
      CPolygon *p = mypoly->GetPolygonW();  
      p->a = 0;   
      p->b = 1;  
      p->c = 2;   //Assign the four points of the polygon to the same positions as the gp[] points above  
      p->d = 3;  
      p->d = mypoly->GetPointCount()-1;    //<---Creates a quad polygon  
      
      BaseMaterial *mat = BaseMaterial::Alloc(Mmaterial);  
      if(!mat) mypoly->SetName("Failed");  
      else {  
            Vector colorv = Vector(1.0, 0.7, 0.3);  
            mat->SetParameter(DescID(MATERIAL_COLOR_COLOR), GeData(colorv), DESCFLAGS_SET_0);  
            UVWTag *uvtag = (UVWTag* )mypoly->MakeVariableTag(Tuvw, 1);  
            UVWStruct str = UVWStruct(Vector(0, 1, 0), Vector(1, 1, 0), Vector(1, 0, 0));  
            BaseChannel *ch = mat->GetChannel(CHANNEL_COLOR);  
            BaseContainer bc = ch->GetData();  
            bc.SetString(BASECHANNEL_TEXTURE, "\\Users\\user\\Desktop\\scales.jpg");  
            ch->SetData(bc);  
            uvtag->SetSlow(0, str);  
            doc->InsertMaterial(mat);  
            TextureTag* textag = TextureTag::Alloc();  
            textag->SetMaterial(mat);  
            textag->SetParameter(TEXTURETAG_PROJECTION, GeData(TEXTURETAG_PROJECTION_UVW), DESCFLAGS_SET_0);  
            mypoly->InsertTag(textag);  
       }  
      
      mypoly->Message(MSG_UPDATE);  
      doc->InsertObject(mypoly, NULL, NULL);  
      EventAdd();
    

    -ScottA



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

    On 16/06/2012 at 09:10, xxxxxxxx wrote:

    Thank you !!!
    I've tryed out your code and it works! great!
    Now i can compare it with my own code, this helps!!!


Log in to reply