On 16/08/2016 at 00:16, xxxxxxxx wrote:
User Information:
Cinema 4D Version: 14+
Platform: Windows ; Mac ; Mac OSX ;
Language(s) : C++ ;
---------
Hi,
I would like to get a basearray of vectors from rayobject->link and use it in a shader.
Basically, say I have a generator plugin that generates 2 cubes (1 BaseObject and 1 instance of it) and inserts them under a null.
In MyGenerator plugin, GetVirtualObjects goes like this (a very simplified version):
BaseObject* groupNull = BaseObject::Alloc(Onull);
BaseObject* cube = BaseObject::Alloc(Ocube);
BaseObject* cubeInstance = BaseObject::Alloc(Oinstance);
BaseContainer* ibc = cubeInstance->GetDataInstance();
ibc->SetLink(INSTANCEOBJECT_LINK, cube);
ibc->SetBool(INSTANCEOBJECT_RENDERINSTANCE, TRUE);
cube->InsertUnder(groupNull);
cubeInstance->InsertUnder(groupNull);
maxon::BaseArray<Vector> colors;
colors.Resize(2);
colors[0] = Vector(1,0,0);
colors[1] = Vector(0,1,0);
return groupNull;
This works great. The problem is with the shader.
MyShader plugin needs to get the rayobject, the colors basearray and assign the respective color to each cube. This is from Output(BaseShader *chn, ChannelData *cd) :
Vector color = Vector(0); // defaults to black
if (cd->vd)
{
RayObject *rayObj = NULL;
rayObj = cd->vd->op;
if (!rayObj) return 0.0;
BaseObject* myObject=(BaseObject* )rayObj->link; // or should I use: rayObj->link->GetCacheParent();
// now I need to set the color vector to read form the colors basearray
//....how do I proceed from here??
return color;
}