Adding a MODATA_COLOR array in my object
-
On 15/11/2013 at 04:06, xxxxxxxx wrote:
Hi,
i have the following code in a Python Effector(Full) and the function md.SetArray(c4d.MODATA_COLOR, clrs, True) doesn't seem to set my new colors in the array. Printing "print clrs =md.GetArray(c4d.MODATA_COLOR)" says None. So i suppose my object is missing this MODATA_COLOR array. The md.SetArray(c4d.MODATA_MATRIX, marr, True) is working ok, so the MODATA_MATRIX is preset. How can I add the MODATA_COLOR array to my md object? I ve tried with md.AddArray(40000001) and different possibilieties but doesn t seem to work. Any ideea? Thanks
Screenshot: http://imgur.com/3i9B0QMimport c4d from c4d.modules import mograph as mo from random import randint #Welcome to the world of Python def randomColor() : r = randint(0,255) / 256.0 g = randint(0,255) / 256.0 b = randint(0,255) / 256.0 color = c4d.Vector(r*4,g*10,b*20) return color def main() : md = mo.GeGetMoData(op) if md==None: return False cnt = md.GetCount() marr = md.GetArray(c4d.MODATA_MATRIX) uvw = md.GetArray(c4d.MODATA_UVW) print uvw fall = md.GetFalloffs() for i in reversed(xrange(0, cnt)) : marr _._ off = marr.off+fall*100.0 print marr clrs = md.GetArray(c4d.MODATA_COLOR) print clrs clrs=[] for x in reversed(xrange(0, cnt)) : clrs.append(randomColor()) print clrs print '_____' print md.GetCurrentIndex() print md.GetArrayDescID(0) print md.GetArrayIndex(40000000) print md.GetArrayID(md.GetArrayIndex(40000004)) print md.GetName(0) print md.GetIndexName(0) print '_____' #print md.AddArray(40000001) md.SetArray(c4d.MODATA_MATRIX, marr, True) md.SetArray(c4d.MODATA_COLOR, clrs, True) print md.GetArray(c4d.MODATA_COLOR) return True _ ___
-
On 15/11/2013 at 07:48, xxxxxxxx wrote:
@admin : how should one use "square brackets" here ?
[ i ]
EDIT : mmm, appears to work.
-
On 15/11/2013 at 19:01, xxxxxxxx wrote:
You've got some errors in your for loop.
Try it like this.for i in reversed(xrange(0, cnt)) : marr[i].off = marr[i].off+fall[0]*100
-ScottA
-
On 16/11/2013 at 02:44, xxxxxxxx wrote:
Thanks, Scott. But I don t want to change the position in my object, I want to change the colors. So, I ve tried to take the colors from the object with md.GetArrayc4d.MODATA_COLORS), but it gives me None. So, then I thought to apply the array to the md Object with SetArray(...,my_array_of_clrs,true), but doesnt seems to work(no array is added). So I saw another function there, md.AddArray(...) but I m not sure how to use it to push my array into the Modata Object. Any ideea? http://imgur.com/3i9B0QM
-
On 16/11/2013 at 06:47, xxxxxxxx wrote:
I might sound grumpy, but I am not willing anymore to read such messy code. However, here is an example on how to write the color channel for modata particles (including some random noise for the position).
import c4d from c4d.utils import noise from c4d.modules import mograph as mo def getNoiseVector(p, uniform=False, negative=True) : """ :param p : input vector :param uniform : greyscale vector :param negative : include negative values :return : c4d.Vector """ if uniform and negative: n = noise.SNoise(p) return c4d.Vector(n, n, n) elif uniform: n = noise.Noise(p) return c4d.Vector(n, n, n) elif negative: return c4d.Vector(noise.SNoise(c4d.Vector(p.x, p.y, p.z)), noise.SNoise(c4d.Vector(p.z, p.x, p.y)), noise.SNoise(c4d.Vector(p.y, p.z, p.x))) else: return c4d.Vector(noise.Noise(c4d.Vector(p.x, p.y, p.z)), noise.Noise(c4d.Vector(p.z, p.x, p.y)), noise.Noise(c4d.Vector(p.y, p.z, p.x))) def main() : md = mo.GeGetMoData(op) if md==None: return False # writing the matrices array with some position noise cnt = md.GetCount() marr = md.GetArray(c4d.MODATA_MATRIX) for i in reversed(xrange(0, cnt)) : marr[i].off = getNoiseVector(c4d.Vector(i,0,0)) * 200 # writing the color array with some color noise carr = md.GetArray(c4d.MODATA_COLOR) for i in reversed(xrange(0, cnt)) : carr[i] = getNoiseVector(c4d.Vector(i,0,0), False, False) # write our data back md.SetArray(c4d.MODATA_COLOR, carr, False) md.SetArray(c4d.MODATA_MATRIX, marr, False) return True
The result will look something like this :
-
On 16/11/2013 at 11:08, xxxxxxxx wrote:
Hi, littledavid. First: my code desnt look good, I admit. But is the first code I am trying in c4d :). So, apologise. Second: your code may be beautifull, but it gives me the same error: TypeError: 'NoneType' object does not support item assignment , on line : carr = getNoiseVector(c4d.Vector(i,0,0), False, False) . So, my problem is that I can't assign an array on that carr in my specific object(is a Voxygen object ). So, I ve tried with AddArray , but I don't know to use it. So, any idea? Thanks for your effort _
_
-
On 16/11/2013 at 11:24, xxxxxxxx wrote:
What is a Voxgen object ? Is it that voxelizer addon by Paul Everett ? I suppose it does act as an MoGraph generator. When for carr = md.GetArray(c4d.MODATA_COLOR) carr is None for that object, there has to be a inconsitency with that plugin i guess, as the defintion of GetArray is :
MoData.GetArray
(id)[](file:///E:/Misc/SDK%20Help/C4d%20SDK%20Documentation%20Python/help/modules/c4d.modules/mograph/MoData/index.html#MoData.GetArray)Get an array.
Parameters:| id (int) –
The ID of the array:MODATA_MATRIX Matrix
[URL-REMOVED]Matrix of the clone. MODATA_COLOR Vector
[URL-REMOVED]Color of the clone. MODATA_SIZE Vector
[URL-REMOVED]Size of the clone. MODATA_UVW Vector
[URL-REMOVED]UV position of the clone. MODATA_FLAGS long Flags: _<_t_>_
> MOGENFLAG_CLONE_ON Particle is visible. > --- --- > MOGENFLAG_DISABLE Particle is permanently disabled. > MOGENFLAG_BORN Particle is just generated (internal use only). > MOGENFLAG_MODATASET The MoData
[URL-REMOVED] has been set and doesn't need the input of the transform panel.> MOGENFLAG_COLORSET The MoData
[URL-REMOVED] color has been set and doesn't need to be updated.> MOGENFLAG_TIMESET The MoData
[URL-REMOVED] time has been set and doesn't need to be updated._/t>MODATA_WEIGHT float Weight of the clone. MODATA_CLONE float Clone Offset (picks which child of the Cloner gets cloned or the blending between those children). MODATA_TIME float Time offset of the clone. MODATA_LASTMAT Matrix
[URL-REMOVED]Previous frame particle matrix. MODATA_STARTMAT Matrix
[URL-REMOVED]Matrix at the particle's birth. MODATA_ALT_INDEX long Alternative index value that can be used for instance by the Step Effector when cloned over a spline with an offset. MODATA_FALLOFF_WGT float Falloff weight. MODATA_SPLINE_SEGMENT long The segment index, mostly used with the MoSpline (currently unused). MODATA_GROWTH float Offset of growth for the particle on the MoSpline (currently unused)._r> Return type: list Returns: The array.<_<_t_>_ So you are guaranteed to get a list. It is a bit difficult to solve your problem without that plugin.
[URL-REMOVED] @maxon: This section contained a non-resolving link which has been removed.
-
On 16/11/2013 at 11:32, xxxxxxxx wrote:
Yea, this was also my first ideea. Bad design in the plugin :). You are right, is the Voxelizer(mograph generator,like Random). So is not my fault that I don t know how to use the c4d AP I, but a plugin problem. Anyway, Ill try to add that blody array in some way...:)
-
On 16/11/2013 at 11:46, xxxxxxxx wrote:
Well, as i said - normally you are guaranteed to find the default arrays (even if they are bugged
and empty like the size array). You can try to add the array manually, but i doubt that it will work
(as you do expect the color to be processed in the viewport). The descid for the color array would
be :(40000001, 3, 0) | 40000001
md.AddArray(c4d.DescID(c4d.DescLevel(40000001), c4d.DescLevel(3), c4d.DescLevel(0)))
edit : FYI, i wouldn't call it bad design in the plugin, as paul everett is also one of the authors of MoGraph, so he most likely knowing what hes doing. It is more a documentation problem.