Mograph effector UVW [SOLVED]

On 29/05/2017 at 02:27, xxxxxxxx wrote:

Is there a way for moving uvw of an object inside a python effector?
Here is my attempt but it didn't work

import c4d
import random
from c4d.modules import mograph as mo
  
def main() :
    md = mo.GeGetMoData(op)
    if md is None: return False
    
    cnt = md.GetCount()
    mar_uv = md.GetArray(c4d.MODATA_UVW)
    fall = md.GetFalloffs()
    for i in reversed(xrange(0, cnt)) :
        before = mar_uv[i]
        random.seed(i)
        mar_uv[i] = (mar_uv[i]+ random.random() +fall[i] )
        mar_uv[i].x = mar_uv[i].x  % 1
        mar_uv[i].y = mar_uv[i].y  % 1
        mar_uv[i].z = mar_uv[i].z  % 1
        print "{} -> {}".format(before, mar_uv[i])
    
    md.SetArray(c4d.MODATA_UVW, mar_uv, True)
    return True

On 30/05/2017 at 13:12, xxxxxxxx wrote:

Hi gr4ph0s, thanks for writing us.

With reference to your question, assuming that you're already aware that the UVW values belonging to a clone has nothing to due with UVW values of the mesh (of the cloned object). For instance considering a MoGraph Cloner creating a Linear Array, the U value correnspond to the ration between the clone index and the total number of clones whilst for a Object Array the U and V values correnspond to the UV values of the mesh used to create the instances.

That said, it's also relevant to state that although all cloners objects have internal UV cooridinates that can be used to drive an Effector's effect, only a limited set of effectors (e.g. the Formula effector) can be influenced by such parameters.

The scene referred by this link, shows two cloners (a linear and an object) where a Formula Effector is used to modify size and position of a cloned object. 

Internally the effector uses the U and V coordinates of the clone to calculate the effect. On top of that a Python Effector randomise the U and V coordinates based on the script below before having them used by the Formula Effector.

import c4d
from c4d.modules import mograph as mo
import random
#Welcome to the world of Python
  
def main() :
    # retrieve the MoData attached to the MoGraph generator
    md = mo.GeGetMoData(op)
    if md is None: 
        return 1.0
    
    # the effector will run on all the clones and all the BlendIDs
    # GetCurrentIndex() returns the index of the current clone
    index = md.GetCurrentIndex()
    # GetBlendID() returns the current BlendIDs
    mode = md.GetBlendID()
    
    random.seed(index)
    value = 0.0
    # filter the BlendID
    if mode == c4d.ID_MG_BASEEFFECTOR_U:
        # update the U value and return
        value = random.random()        
        return value
    elif mode == c4d.ID_MG_BASEEFFECTOR_V:
        # update the V value and return
        value = float(index)/float(md.GetCount())    
        return value
    else:
        return 1.0

The approach you were trying to achieve instead aims to modify the MoData UVW array directly which is not the way the Python Effector is meant to be used.

Best regards, Riccardo

On 30/05/2017 at 13:33, xxxxxxxx wrote:

Thanks you a lot for this complete exemple ! I guess it's fixed ! :)

And to be honest I really never understand the meaning of uv in mograph but now, it's way more clear even if I still dont understand why they are called like that and not as a MoCustomStruct :p