materials
-
THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED
On 23/10/2008 at 09:02, xxxxxxxx wrote:
User Information:
Cinema 4D Version: 11
Platform: Mac OSX ;
Language(s) : C.O.F.F.E.E ;---------
I'm wanting to populate a document with many random shapes and colors. I don't understand how to assign materials to these shapes via COFFEE. For instance, say I've got this:>
var foo_sphere; \> foo_sphere=new(SphereObject); \> doc->InsertObject(foo_sphere,NULL,NULL);
,and I'd like to
- create a material
- fill, say, the luminance channel with a particular color
- assign that material to the sphere I've just created above.
If someone could show me the few lines of COFFEE code that would do this, and/or point me somewhere in the "minimalist" documentation to look, I'd be extremely appreciative.
thanks,
Michael -
THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED
On 23/10/2008 at 12:54, xxxxxxxx wrote:
Materials are assigned to objects using Texture tags (Ttexture). So:
- create a material
- configure the material's channels
- create a Texture tag on the object (sphere)
- assign the material to the Texture tag (TextureTag::SetMaterial()).
There is example code at the bottom of the BaseMaterial and BaseChannel sections in the COFFEE documentation.
For the Texture tag do something like this:
var mat = AllocMaterial(Mmaterial);
if (!mat) // error: return FALSE or something
var textag = AllocTag(Ttexture);
if (!textag) // error: good to check allocations always!
foo_sphere->InsertTag(textag, NULL);
textag->SetMaterial(mat);
// Get your channel, configure, and set the channel here
mat->Update(); -
THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED
On 23/10/2008 at 14:33, xxxxxxxx wrote:
Thanks! That is immensely helpful. One last thing on this: I don't see in the documentation (in the portions that you mentioned) how to write vectors of color data to individual channels, such as the luminance channel. Any tips on that score would be again immensely appreciated!
best,
Michael -
THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED
On 23/10/2008 at 15:28, xxxxxxxx wrote:
If you have trouble with SetMaterial() because it wants a Marker, use this method instead:
textag->SetMaterial(mat->GetMarker());
For changing Channel colors,
// Enable (or disable 'FALSE') material channel
material->SetChannelState(CHANNEL_COLOR, TRUE);
// Get Channel
var channel = material->GetChannel(CHANNEL_COLOR);
if (!channel) return FALSE;
// Get Channel's BaseContainer
var container = channel->GetContainer();
if (!container) return FALSE;
// Set Color to Red
container->SetData(CH_COLOR, vector(1.0, 0.0, 0.0));
// Set Channel's BaseContainer (with changes)
channel->SetContainer(container); -
THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED
On 23/10/2008 at 19:44, xxxxxxxx wrote:
Sorry to be a nag here, (and I'm going to go away and play with this for weeks once I'm in business), but for some reason the color isn't taking (though the material and the tag are). I tried to collate the stuff from the above posts. There are no errors, but the material simply doesn't turn red. Also, why does this execute on every frame, even though I'm testing the value of "f?"
I really appreciate the help!
regards, Michael>
var f = 0; \> \> main(doc,op) \> { \> \> if (f == 0); \> { \> \> f++; \> \> var foo_sphere=new(SphereObject); \> doc->InsertObject(foo_sphere,NULL,NULL); \> \> var mat = AllocMaterial(Mmaterial); \> if (!mat) return FALSE; \> \> var textag = AllocTag(Ttexture); \> if (!textag) return FALSE; \> \> foo_sphere->InsertTag(textag, NULL); \> textag->SetMaterial(mat->GetMarker()); \> \> // Enable (or disable 'FALSE') material channel \> mat->SetChannelState(CHANNEL_COLOR, TRUE); \> \> // Get Channel \> var channel = mat->GetChannel(CHANNEL_COLOR); \> if (!channel) return FALSE; \> \> // Get Channel's BaseContainer \> var container = channel->GetContainer(); \> if (!container) return FALSE; \> \> // Set Color to Red \> container->SetData(CH_COLOR, vector(1.0, 0.0, 0.0)); \> \> // Set Channel's BaseContainer (with changes) \> channel->SetContainer(container); \> mat->Update(); \> } \> \> }
-
THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED
On 23/10/2008 at 20:21, xxxxxxxx wrote:
You're doing it in a COFFEE tag or Xpresso node? The tag is evaluated at every frame. But that isn't your problem. See this:
if (f == 0);
That's you entire conditional 'if' block. Delete the ';' so that the {} block after it is part of the conditional.
After you create the material you need to insert it into the document:
doc->InsertMaterial(mat);
Sorry about that. COFFEE isn't my normal language. I mainly do C++ plugins.
If that still doesn't help, add an EventAdd(); call after the mat->Update(); call.
-
THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED
On 23/10/2008 at 20:46, xxxxxxxx wrote:
Is the code at bottom in the order that you were suggesting? This compiles with no errors, but on execute it complains that the doc->InsertMaterial(mat); has too few parameters, and the texture tag no longer gets applied.
I found this in the docs:
>InsertMaterial( mat, [prev] ) \> [bool] InsertMaterial([BaseMaterial] mat, [[BaseMaterial] prev = NULL});
Is not the 2nd argument optional? If so, why would it complain about too few parameters? Thanks for all your help so far, Robert!
>
var f = 0; \> \> main(doc,op) \> { \> \> if (f == 0) \> { \> \> f++; \> \> var foo_sphere=new(SphereObject); \> doc->InsertObject(foo_sphere,NULL,NULL); \> \> \> var mat = AllocMaterial(Mmaterial); \> if (!mat) return FALSE; \> doc->InsertMaterial(mat); //on execute, we stop here with "too few parameters" \> \> var textag = AllocTag(Ttexture); \> if (!textag) return FALSE; \> \> foo_sphere->InsertTag(textag, NULL); \> textag->SetMaterial(mat->GetMarker()); \> \> // Enable (or disable 'FALSE') material channel \> mat->SetChannelState(CHANNEL_COLOR, TRUE); \> \> \> // Get Channel \> var channel = mat->GetChannel(CHANNEL_COLOR); \> if (!channel) return FALSE; \> \> // Get Channel's BaseContainer \> var container = channel->GetContainer(); \> if (!container) return FALSE; \> \> // Set Color to Red \> container->SetData(CH_COLOR, vector(1.0, 0.0, 0.0)); \> \> // Set Channel's BaseContainer (with changes) \> channel->SetContainer(container); \> \> mat->Update(); \> \> EventAdd(); \> \> } \> \> }
-
THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED
On 23/10/2008 at 21:18, xxxxxxxx wrote:
It is possible that something has changed with R11 but the second argument shouldn't be needed (it has a default value). Try doc->InsertMaterial(mat, NULL); and see if it still complains.
-
THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED
On 23/10/2008 at 21:22, xxxxxxxx wrote:
That was it! Thank you very, very much. I've got a project that is now ready to fully take off with this information. regards,
Michael -
THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED
On 23/10/2008 at 21:37, xxxxxxxx wrote:
Glad to help.
-
THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED
On 24/10/2008 at 01:35, xxxxxxxx wrote:
You can use the operators directly as well, like:
>
\> var hue = vector(huevalue,1,1); // Create a color range using hue value \> var torgb = HSVToRGB(hue); // Convert the HSV values to RGB values \> mat#MATERIAL_COLOR_COLOR = torgb; // Set the RGB into the ColorChannel \> mat#MATERIAL_LUMINANCE_COLOR = torgb; \>
Cheers
Lennart -
THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED
On 24/10/2008 at 08:51, xxxxxxxx wrote:
super cool! Thanks for the help, Lennart and Robert!