On 24/10/2016 at 09:14, xxxxxxxx wrote:
Hi all,
I am writing a shader plugin, with amongst others two parameters, grid and scale. They are each others inverses, ie grid = Vector(1/scale.x, 1/scale.y, 1/scale.z). The Texture tags in c4d work the same, you can either set Length U/V or Tiles U/V and the other is automatically updated.
Now here comes the weird part: The code below does update the values in the usermenu (ie everything looks fine) and the print statement prints the correct values. But the value in self.scale and self.grid are never updated at all. So when I check scale and grid from the Output function, it is still Vector(1,1,1) or whatever I assigned them to in the __init__ function.
I have been struggling with this for a day now, and I hope somebody has some suggestions.
(Method 1)
def Message(self, node, id, msg) :
if (id==c4d.MSG_DESCRIPTION_POSTSETPARAMETER) :
bc = node.GetDataInstance()
if msg['descid'][0].id == INTERIOR_SCALE:
scale = bc.GetVector(INTERIOR_SCALE)
self.scale = 1.0 * scale
self.grid = Vector(1.0/scale.x, 1.0/scale.y, 1.0/scale.z)
bc.SetVector(INTERIOR_GRID, self.grid)
print 'scale', scale, self.scale
elif msg['descid'][0].id == INTERIOR_GRID:
grid = bc.GetVector(INTERIOR_GRID)
self.grid = 1.0 * grid
self.scale = Vector(1.0/grid.x, 1.0/grid.y, 1.0/grid.z)
bc.SetVector(INTERIOR_SCALE, self.scale)
print 'grid', grid, self.grid
If I put the code below in the InitRender method, all works fine, but the update of the inverse values happens only after the preview render, so is rather sluggish.
So why does Method 2 work, albeit sluggishly, and Method 1 not?
Regards,
Hermen
(Method 2)
def InitRender(self, sh, irs) :
bc = sh.GetDataInstance()
scale = bc.GetVector(INTERIOR_SCALE)
grid = bc.GetVector(INTERIOR_GRID)
if scale != self.scale:
print 'scale'
self.scale = scale
self.grid = Vector(1.0/scale.x, 1.0/scale.y, 1.0/scale.z)
bc.SetVector(INTERIOR_GRID, self.grid)
if grid != self.grid:
print 'grid'
self.grid = grid
self.scale = Vector(1.0/grid.x, 1.0/grid.y, 1.0/grid.z)
bc.SetVector(INTERIOR_SCALE, self.scale)
print 'initrender', self.scale