Hi again Riccardo, sorry about another late response but I was finally able to go through your code again. I see where I when wrong in understanding where the Flat projection stuff would take over.
Going through your code I saw a few things that didn't make sense to me and I just want to make sure I went about them in the right way.
if currentTextureTag[c4d.TEXTURETAG_PROJECTION] == c4d.TEXTURETAG_PROJECTION_UVW:
spot1 = uvwdict["a"]
spot2 = uvwdict["c"]
else:
# non UVW cases should be generated on the fly during the sampling loop
spot1 = 0#These need to be swapped to c4d.Vector(0), since later on it's looking for a vector.
spot2 = 0
And then the second one:
def ComputeFlatMapping(mappingInfo, p):
uv = c4d.Vector()
# check projection being set to flat
if mappingInfo["proj"] == c4d.TEXTURETAG_PROJECTION_FLAT:
d = p * mappingInfo["im"]
uv.x = (d.x * .5 - mappingInfo["ox"]) * mappingInfo["invLenx"] + 0.5
uv.y = (d.y * .5 + mappingInfo["oy"]) * mappingInfo["invLeny"] + 0.5 # this needs to be changed to "-(d.y * .5 + mappingInfo["oy"]) * mappingInfo["invLeny"] + 0.5"
return uv
Without changing it to minus in your checkerboard example doesn't seem to return the correct color samples. I was getting Vector(0,0,0) when I should have been getting Vector(1,1,1) and vice versa from what I could tell.
Swapping uv.y to the minus seemed to fix that.
Then I tried a new test with a new material, each quarter of it being a different color. Even with my 'fix' I was getting incorrect outputs.
My new test
What I'm getting as an output:
Vector(-300, 0, 200) / Vector(0.793, 0.803, 0) / Vector(1, 0, 0)
Vector(-400, 0, 300) / Vector(0.086, 0.803, 0) / Vector(0, 0, 0)
Vector(-300, 0, 300) / Vector(0.44, 0.45, 0) / Vector(0, 0, 0)
Vector(-200, 0, 300) / Vector(0.793, 0.096, 0) / Vector(1, 0, 0)
Vector(-300, 0, 400) / Vector(0.086, 0.096, 0) / Vector(0, 0, 0)
When I expect to get:
Vector(-300, 0, 200) / Vector(0.793, 0.803, 0) / Vector(1, 0, 0)
Vector(-400, 0, 300) / Vector(0.086, 0.803, 0) / Vector(0, 0, 0)
Vector(-300, 0, 300) / Vector(0.44, 0.45, 0) / Vector(1, 1, 1)
Vector(-200, 0, 300) / Vector(0.793, 0.096, 0) / Vector(0, 0, 1)
Vector(-300, 0, 400) / Vector(0.086, 0.096, 0) / Vector(1, 1, 1)
After all of that I still have one more question: where the end +.5 came from for the last bit of code. They are missing from the TexData example, but from what I can tell it needs them to function correctly.
/*TexData example for Flat Projection*/
Vector d = p * tdp->im;
uv->x = (d.x*0.5-tdp->ox)*lenxinv;
uv->y = -(d.y*0.5+tdp->oy)*lenyinv;
/* as opposed to your code*/
uv.x = (d.x * .5 - mappingInfo["ox"]) * mappingInfo["invLenx"] + 0.5
uv.y = (d.y * .5 + mappingInfo["oy"]) * mappingInfo["invLeny"] + 0.5
I'm just worried in doing the other projection types that there will be an unknown variable that I don't know that I need to add.
Again, thank you so much for all of your help, Riccardo.