On 26/03/2015 at 14:14, xxxxxxxx wrote:
I think there is a big performance issue in the for statement. i want to transfer the color of a noise texture on my clones. this works fine but incredible slow. also if i drag something in the viewport it callculate all the samples again. any suggestions to awoid that? i also has to add a black color vector before the render statment to stop a variable issue with shader_lum
import c4d
from c4d.modules import mograph as mo
from c4d.modules import render as render
from c4d import Vector
from c4d.modules.render import ChannelData, InitRenderStruct
import random
def main() :
shader = op[c4d.ID_USERDATA,1]
cd = ChannelData()
md = mo.GeGetMoData(op)
cnt = md.GetCount()
tresh = 0.5
coll = md.GetArray(c4d.MODATA_COLOR)
uvm = md.GetArray(c4d.MODATA_UVW)
visible = md.GetArray(c4d.MODATA_FLAGS)
random.seed(666)
if md==None: return False
#if shader ==None: return False
for i in reversed(xrange(0, cnt)) :
cd.p = uvm[i]
irs = render.InitRenderStruct()
shader_lum = Vector(0,0,0)
if shader.InitRender(irs) :
shader_lum = shader.Sample(cd)
shader.FreeRender()
coll[i] = shader_lum
md.SetArray(c4d.MODATA_FLAGS, visible, True)
md.SetArray(c4d.MODATA_COLOR, coll, True)
return True