Your browser does not seem to support JavaScript. As a result, your viewing experience will be diminished, and you have been placed in read-only mode.
Please download a browser that supports JavaScript, or enable it if it's disabled (i.e. NoScript).
On 11/05/2015 at 00:26, xxxxxxxx wrote:
Hello friends,
I'm rather new at python and up to this point I've fought the urge to post my newbie questions, but I can't seem to find any resources on how to apply turbulent noise to a 3d grid of clones.
I'm using cinema's matrix object to generate the grid and a python effector for what will soon, hopefully, be the turbulent rotation (I only want to effect the rotation). When I compile the code below, each element is rotated the same amount, but my desired result looks like what you get when you use the turbulence setting on a random deformer:
My question is, how can I apply turbulence to the 3d grid as a whole to get a result similar to the picture? Here's what I have so far:
_____________________________________________ def main() : md = mo.GeGetMoData(op) if md==None: return False cnt = md.GetCount() marr = md.GetArray(c4d.MODATA_MATRIX) fall = md.GetFalloffs() for i in reversed(xrange(0, cnt)) : #Get PSR pos = marr.off rot = utils.MatrixToHPB(marr) scale = c4d.Vector(marr.v1.GetLength(), marr.v2.GetLength(), marr.v3.GetLength()) #Modify PSRF rot = c4d.Vector(c4d.utils.noise.Turbulence(c4d.Vector(rot.x, rot.y, rot.z), 4, False)) #Set PSR marr = utils.HPBToMatrix(rot) marr.off = pos marr.v1 = marr.v1.GetNormalized() * scale.x marr.v2 = marr.v2.GetNormalized() * scale.y marr.v3 = marr.v3.GetNormalized() * scale.z md.SetArray(c4d.MODATA_MATRIX, marr, True) _ _ _ return True___ _ _ _______________________________________________
_ _ Thanks.__
_ _ Robert__
On 12/05/2015 at 03:35, xxxxxxxx wrote:
Hi Robert,
there are a bunch of issues with your code. The main problem is, that you are not accessing the array (marr) correctly. And you might want to set your Python Effector to "Full Control" instead of parameter control, then you don't return a value from main.
Here's something I came up with:
import math import c4d from c4d.modules import mograph as mo #Welcome to the world of Python def main() : md = mo.GeGetMoData(op) if md==None: return 1.0 # False marr = md.GetArray(c4d.MODATA_MATRIX) for i in xrange(0, len(marr)) : pos = marr[i].off turb = c4d.utils.noise.Turbulence(pos, 4, False) # Sampling at position, Turbulence delivers -1 to 1 # get rotation matrices rotx = c4d.utils.MatrixRotX(turb * math.pi) roty = c4d.utils.MatrixRotY(turb * math.pi) rotz = c4d.utils.MatrixRotZ(turb * math.pi) # rotate marr[i] *= rotx marr[i] *= roty marr[i] *= rotz md.SetArray(c4d.MODATA_MATRIX, marr, True)
Hope this helps and is at least similar to what you are after.
On 14/05/2015 at 14:02, xxxxxxxx wrote:
Thank you, Andreas. This is much closer to what I'm after.
Now they're all facing different, seemingly random directions, but if I scale the grid down enough I think I can start to see some order in the rotations. So I think.. I just have to figure out how to up the noise scale...? I have an example from someone else where noise scale is controlled by incorporating the grid resolution and the ids of each element. Somehow.
Looking forward to it Thanks again.
On 15/05/2015 at 00:07, xxxxxxxx wrote:
There are a bunch of parameters you could change to the outcome: - maybe you don't want to sample by position - or you may want to scale the sampling points by scaling down the vector that goes into Turbulence - perhaps you don't want full plus/minus 180 degree rotation, change factor on building rotation matrices - number of octaves on Turbulence should also have an effect
On 15/05/2015 at 00:42, xxxxxxxx wrote:
pos = marr[i].off/500 Pow, pow, pow. Yes, that second method worked perfectly.
Many thanks, Andreas, especially for taking the time to write out some code.