BASECHANNEL_COLOR_EX
-
On 09/04/2014 at 13:40, xxxxxxxx wrote:
User Information:
Cinema 4D Version: 13-15
Platform: Windows ;
Language(s) : C++ ;---------
Hi,I just want to make a simple color material, i.e. just allocating a new base material and setting the color vector of the color channel. But that seems to be not as simple as you might assume. The BASECHANNEL_COLOR_EX id makes is very simple setting the color vector in the color channel. But this is not documentated in the SDK help, and the "EX" implicates, it's not the way you should do.
What is the right way?
Thanks.
-
On 09/04/2014 at 18:23, xxxxxxxx wrote:
BaseMaterial *mat = BaseMaterial::Alloc(Mmaterial); //Generate a new material and assign a variable to it Vector colorv = Vector(1.0, 0.7, 0.3); //Sets the color to yellow mat->SetParameter(DescID(MATERIAL_COLOR_COLOR), GeData(colorv), DESCFLAGS_SET_0); //Applies the color to the color channel mat->SetParameter(DescID(MATERIAL_COLOR_BRIGHTNESS), GeData(.5), DESCFLAGS_SET_0); //Change the Brightness slider to 50% doc->InsertMaterial(mat); // Adds the new material to the material Manager mat->Update(TRUE, TRUE); // Updates the thumbnail image void Free(BaseMaterial*& mat); EventAdd();
-ScottA
-
On 10/04/2014 at 02:23, xxxxxxxx wrote:
Thanks ScottA. That's even simpler than the EX version, since you don't need to create a base channel. But I don't understand the line
void Free(BaseMaterial*& mat);
Could you explain that please?
-
On 10/04/2014 at 07:25, xxxxxxxx wrote:
You can probably safely leave that code out of your code if you want.
I only included it in my code because one of the Maxon developers wrote it that way in an example. So I tend to use it out of habit.Whenever we use ::Alloc we very often have to free the memory it's using to prevent a memory leak.
It's sort of like using the word new in raw C++.
But in some cases (like allocating objects & materials) where C4D owns the object we're allocating with ::Alloc. C4D handles the memory stuff for us. So we don't need to free them manually.You should of course always check your C++ code for memory leaks using the SDK tool for that.
I wrote lots of plugins with small memory leaks in them before I learned that lesson.-ScottA
-
On 11/04/2014 at 07:11, xxxxxxxx wrote:
void Free(BaseMaterial*& mat);
Doesn't do anything at all, it is a function declaration. Also, you mustn't free the BaseMaterial after
you gave ownership to the BaseDocument by calling BaseDocument::InsertMaterial()!! But since
that's not what it's doin', it's fine.Where did you see one of the developers use that line in a function?
Best,
-Niklas -
On 11/04/2014 at 07:53, xxxxxxxx wrote:
I can't remember who gave it to me. It's in my notes from a long time ago.
It might have been Matthias.Most of the time when someone asks a question here. I typically already have the answer to it in my notes. So I tend to copy and paste most of the code directly from my notes rather than write it all from scratch.
And sometimes I have weird things like that in my code and I forget to remove them.Sorry if that caused any confusion.
-ScottA
-
On 11/04/2014 at 08:05, xxxxxxxx wrote:
It's alright, just wanted to clear things up. Its natural that sometimes
false information is accidentally, not knowingly or willingly, distributed.