Randomize Inheritance Morph Motion Object

Become a member of the CGSociety

Connect, Share, and Learn with our Large Growing CG Art Community. It's Free!

THREAD CLOSED
 
Thread Tools Search this Thread Display Modes
  03 March 2013
Randomize Inheritance Morph Motion Object

That's the shortest title I could think of, honest.

Basically, I have a Matrix grid (25x25), whose visibility is being affected by a volume effector.

Then, I have a cloner, with far fewer objects (just 50) than the Matrix object. I am using the Inheritance Effector with Morph Motion Object to move the cloner objects to the Matrix objects positions.

Unfortunately, they all stack up neatly at the bottom of the Matrix grid. I need them to be distributed randomly amongst the Matrix grid.

Is this possible? Or am I approaching it the wrong way entirely?

Basically, I need to specify a large, empty grid, and then randomly distribute objects on it.

Thanks!
 
  03 March 2013
You could use a Python Effector to shuffle the indexes of the Matrix Object.
You shouldn't need much more than this information :


 you need these :
 import  math, random
 
 you could set up the shuffle like this :
 def dotheshuffle(array,seedvalue):
 	random.seed(seedvalue)
 	random.shuffle(array)
 	return array
 
 here you actually do the shuffle :
 marrshuffled = dotheshuffleshuffle(marr, seedvalue)
 
 And finally, right before setting the Array you do the switch :
  marr[i] = marrshuffled[i]


you can use a User Data for a seed value.

you're a clever guy,
you should be able to fill in the blanks.

have fun,
d
 
  03 March 2013
Take a Plain Effector and make everything but 50 matrices invisible with a MoSelection?

Last edited by typografschaft : 03 March 2013 at 10:59 AM.
 
  03 March 2013
douwe, thanks for pointing me in the right direction. That's exactly what I wish to achieve - randomize the indexes of the matrix object.

Unfortunately, your faith in my abilities was a bit misplaced. I've never written a python script in C4D before and this is what I've managed to put together from various huntings:

import c4d
from c4d.modules import mograph as mo
import math, random
def dotheshuffle(array,seedvalue):
	random.seed(seedvalue)
	random.shuffle(array)
	return array
def main():
	seedvalue=1
	md = mo.GeGetMoData(op)
	if md==None: return False
	cnt = md.GetCount()
	marr = md.GetArray(c4d.MODATA_MATRIX)
		
	marrshuffled = dotheshuffleshuffle(marr, seedvalue)
	marr[i] = marrshuffled[i]
	md.SetArray(c4d.MODATA_MATRIX, marr, True)
	return True
 


That doesn't seem to do anything to the matrix. It would seem that I would need a loop on the marr[i]=marrshuffled[i] line, but I can't be sure.

Why this isn't built into the Grid arrays is beyond me.
 
  03 March 2013
Ah - the old shuffle thing (Hi Douwe)

Didn't ever work out why you have to close and reopen the file everytime time you change the cloner or matrix numbers. But it does shuffle both.

Anyhow file included if its of any help - or if anyone knows how to reinitialise the effector without having to close and reopen the scene

btw - can't believe in this day an age that the upload limit is a ridiculously minute 1 meg!
 
  03 March 2013
You're close eikono,
Check out this example : douwe-randomindexeffector.c4d

Hey Paul, the old shuffle thing indeed
the issue you mention (my example also has it) may be fixed already if you get the Array again right before you do that shuffle.

Finally, yader is right :
Just a MoSelection is a lot easier and faster to set up.

cheers,
d
 
  03 March 2013
Thanks deepshade. I'm almost there now.

The only issue is that the indexes seem to keep randomizing. I've added douwe's seedvalue bits to the code in your file, but it still seems to use a random seed every time.

I need to just generate a random set of positions and then lock that down.

Here's the modified code:

import c4d
from c4d.modules import  mograph as mo
import  math, random
# re compile everytime you change the scene
def my_shuffle(array,seedvalue):
		random.seed(seedvalue)
		random.shuffle(array)
		return array
def main():
	seedvalue = 1
	md = mo.GeGetMoData(op)
	if md==None: return False
	cnt = md.GetCount()
	marr = md.GetArray(c4d.MODATA_MATRIX)
	fall = md.GetFalloffs()
	global marr1
	try:
		marr = marr1
	except NameError:
		pass
   
	frame = doc.GetTime().GetFrame(doc.GetFps()) 
	
	if frame==0:
		marr1 = my_shuffle(marr, seedvalue)
	for i in reversed(xrange(0, cnt)):
		marr[i].off = marr[i].off
	md.SetArray(c4d.MODATA_MATRIX, marr, True)
	return True
 
 
  03 March 2013
Ah that was quick! Ignore my previous post. Thanks douwe, I think I'm sorted now.

typografschaft's suggestion is indeed simpler, but not flexible enough for what I need to do. The array I'm dealing with is quite large and the number of clones is quite large too (the numbers I used in my first post were for illustration only). That's a lot of manual, tedious work, especially when you consider that the positions are subject to change.

I really hope that "Randomize Index" makes a checkbox appearance in the next version.
 
  03 March 2013
Thread automatically closed

This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.
__________________
CGTalk Policy/Legalities
Note that as CGTalk Members, you agree to the terms and conditions of using this website.
 
Thread Closed share thread



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
CGSociety
Society of Digital Artists
www.cgsociety.org

Powered by vBulletin
Copyright 2000 - 2006,
Jelsoft Enterprises Ltd.
Minimize Ads
Forum Jump
Miscellaneous

All times are GMT. The time now is 06:10 AM.


Powered by vBulletin
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.