THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED
On 06/05/2011 at 13:43, xxxxxxxx wrote:
I couldn't figure out how to edit existing gradients. So I tried allocating a new one. And it seems to replace the old one. So I guess that will work. *shrug*
Here's the entire plugin code:
#include "c4d.h"
#include "c4d_symbols.h"
#include "../../cinema4dsdk/res/description/xsdkgradient.h"
#include "../../modules/shader/res/description/xnoise.h"
#define PLUGIN_ID 10000010 // ID FOR TESTING ONLY!!!!!!!!!!
class SimplePlugin : public CommandData
{
public:
SimplePlugin(); //The Constructor
virtual Bool Execute(BaseDocument *doc);
};
SimplePlugin::SimplePlugin() // The Constructor
{
//not used in this example
}
Bool SimplePlugin::Execute(BaseDocument *doc)
{
BaseMaterial *mat = doc->GetFirstMaterial(); // Get the first material and assign a variable to it
if(!mat) return TRUE; // Error handling
BaseContainer *data = mat->GetDataInstance(); // Get the material's container
BaseShader *shd = BaseShader::Alloc(Xsimplenoise); // Creates simple noise instance....For other types(fresnel,etc..). Look up "enum Xbase" in the SDK
if(!shd) return FALSE; // Error handling
data->SetLink(MATERIAL_COLOR_SHADER, shd); // Adds a SimpleNoise shader to the color channel in memory only
BaseContainer *shddata = shd->GetDataInstance(); // Get the shader's container
AutoAlloc<Gradient> gradient; // Creates a new gradient
if (!gradient) return FALSE; // Error handling
GradientKnot k1,k2; // Create two variables to hold the two knot values
k1.col = Vector(0.0,0.0,0.0); // First knot's color is black
k1.pos = 0.0; // First knot's position
k2.col = Vector(1.0,1.0,1.0); // Second knot's color is white
k2.pos = 1.0; // Second knot's position
gradient->InsertKnot(k1); //Adds the First knot from memory
gradient->InsertKnot(k2); //Adds the Second knot from memory
shddata->SetData(SDKGRADIENTSHADER_COLOR,GeData(CUSTOMDATATYPE_GRADIENT,gradient)); // Executes the knot changes from memory
shddata->SetData(SDKGRADIENTSHADER_MODE,GeData(1)); //Sets the mode<---BROKEN!!
shd->SetParameter(DescID(NOISESHADER_SCALEX), GeData(5.0), DESCFLAGS_SET_0); // Sets the scaleX value
shd->SetParameter(DescID(NOISESHADER_SCALEY), GeData(5.0), DESCFLAGS_SET_0); // Sets the scaleY value
mat->InsertShader(shd, NULL); // Adds the Simple Noise to the color channel from memory with all it's settings made
mat->Message(MSG_UPDATE); // update the changes
mat->Update(TRUE, TRUE); // updates the material icon
void Free(BaseMaterial*& mat); // Free memory used in the code(not sure if this is needed)
return true;
}
Bool RegisterSimplePlugin()
{
return RegisterCommandPlugin(PLUGIN_ID, GeLoadString(IDS_My_Simple_Plugin), 0, AutoBitmap("icon.tif"), String("Help text Goes here"), gNew SimplePlugin);
}
I hope this helps any newbs out there get up running a lot easier.
The mode option is still broken. But I'm exhausted from starring at this thing. So I'm taking a break.
Thanks for the help guys,
-ScottA