[Closed] C++/Plugin problem
I’m making what I thought was a fairly straight forward (texture map) plugin. The key part I’m having trouble with is altering the UVW in the shadecontext in a loop. To do that I’ve made my own shade context, and in my loop I’m setting an index on that SC so that any calls to it’s UVW return the right one. I am a C# guy so if anything obvious stands out, don’t assume I’ve seen it :p. Here’s a few snippets:
AColor MultiPlanar::EvalColor(ShadeContext& sc)
{
AColor result = black;
Point3 uvw = sc.UVW();
MultiPlanarSC mpsc = MultiPlanarSC(&sc);
mpsc.SetChannel(1);
mpsc.SetUVW(uvw);
mpsc.CalculatePoints();
for(int i = 0; i < 6; i++)
{
mpsc.SetCurrentIndex(i);
result = lerp(result, subtex[0] -> EvalColor(mpsc), 1.0);
}
return result;
}
And the overriden UVW in my SC:
inline Point3 MultiPlanarSC::UVW(int channel)
{
Matrix3 m = MultiPlanarSC::Matrices[planeIndex];
return m * sc->PObj();
}
planeIndex is a private variable, SetCurrentIndex sets that variable. Looking at the visual result and from debugging, planeIndex is ALWAYS 0. Why!?
edit: Attached the whole project. Requires VS2010, Max2014 x64. Most of the action is at line 298 of MultiPlanar.cpp, line 158 of MultiPlanarSC.h
there is no way (at least for me) looking on these snippets to guess what is happening in your classes. the part of code you are asking about is not published.
int index = planeIndex;
index = max(6, index);
index = min(0, index);
Well, the code of MultiPlanarSC::SetCurrentIndex is commented out in the uploaded code, but besides that I think you mixed up min/max inside MultiPlanarSC::UVW.
I didn’t look further now.
Daniel
True, part of trying different things (i put the planeIndex in the constructor instead). I’ve fixed both of these and the issue remains.
What’s the difference between me doing this:
void SetCurrentIndex(int index)
{
planeIndex = index;
}
…and this?
void SetCurrentIndex(int index)
{
MultiPlanarSC::planeIndex = index;
}
Should only make a difference if there is also another variable called planeIndex.
By adding the classname you are simply more specific, so the compiler wouldn’t use a locally defined variable of the same name for example.
Daniel
Alright – got it! I tried overriding all the GetCache calls (in my shadecontext) and it’s working, so it’s something to do with that. I still want it to cache so I’ll have to work out something for that, but at least I know why it wasn’t working.
Hi, I have just a quick question
MultiPlanarSC mpsc = MultiPlanarSC(&sc);
mpsc.SetChannel(1);
mpsc.SetUVW(uvw);
mpsc.CalculatePoints();
the top line looks like he defined the MultiPlanarSC mpsc as MultiPlanarSC(&sc)
underneath it he has mpsc as the variable with functions/properties being called on it.
is mpsc in the lower 3 lines a predefined function that we don’t see? Or is mpsc related to the top line that was defined? Just wondering how he used mpsc if it isn’t directly related to the top line, and inversely what exactly the top line is doing if its not related?
Nothing wrong with it, but simpler and better would be just:
MultiPlanarSC mpsc(&sc);
The original would create a needless temporary object MultiPlanarSC just to then copy the values over into the new mpsc object.
Daniel
I did not know that, so thanks for that tip. Also, I tried fiddling with the cache by checking against a map<cacheid, vector<bool>> (where cacheid is an int), to see if the caller has hit that planeIndex, but it slowed down rendering considerably.