@zipit said in MoData.GetData()?:
Hi,
the correct method to access the individual arrays of a MoData
object would be GetArray
. Assuming that is what you are trying to do. You will also have to specify the array type you want to access, MODATA_MATRIX
for the particle matrices for example.
If you want to keep a copy of a MoGraph state, I would clone the generator in Python (unfortunately we cannot instantiate MoData
in Python directly). You could also do this manually, but you should keep in mind that most particle data is presented as mutable objects, so you would have to explicitly clone them or otherwise you will just reference them.
import c4d
def main():
"""
"""
# Get the MoData for the selected BaseObject, if there is either
# no selection or it does not yield some MoData, get out.
if not isinstance(op, c4d.BaseObject):
return
modata = c4d.modules.mograph.GeGetMoData(op)
if modata is None:
return
# Iterate over the matrices of our MoData. If you want other data,
# e.g. colors, weights, etc., you will have to iterate over these
# by using their respective symbol. Passing NOTOK will yield no data,
# I am not sure why MAXON did make this the method's default argument.
for matrix in modata.GetArray(c4d.MODATA_MATRIX):
print matrix
# We could cache the array's of our MoData individually, but an easier
# approach in Python would be just to clone the generator which hosts
# the MoData.
# This would be the object op in this example.
generator = modata.GetGenerator()
# Clone that object.
cache = generator.GetClone()
# So that we can later on access its data.
cached_data = c4d.modules.mograph.GeGetMoData(cache)
print cached_data
if __name__=='__main__':
main()
On a side note: I have not done any extensive tests on the performance of BaseContainer
, but they are just integer key hash maps that allow for the dynamic typing of their values. And hash maps are very efficient for larger data sets, especially when it comes to access, which is probably why MAXON used them as a basis for basically everything in Cinema.
Cheers,
zipit
Thanks @zipit, I'm aware of the usual way of getting and setting mograph data. Maxon's gone out of their way to consolidate these arrays in manageable number of basecontainers and I want to take advantage of that.
I'm not sure about storing an entire clone of the generator itself would be the most efficient method, and I'm trying to be as efficient as possible, but I don't know, to be honest. If I can get it down to as simple a method of storing away just the modata, then I'll be in good shape. But it's certainly more concise than breaking down the data into it's component parts and trying to stash it away in a basecontainer or hyperfile. Certainly worth a look-see:)
Regarding basecontainer efficiency, I've actually been hearing the opposite in a few posts, that it wasn't suited for large data sets. Now, this may have been expressed in a general sense as, without a perfect hash function, they can get very slow when the entry count gets very large. In the end it depends on the hash function. Wikipedia describes a few different perfect hash approaches, so Maxon is probably employing one of those. I say all that as a simple superuser with an internet connection and a penchant for getting in over my head, not a developer... that's about as deep as my knowledge on hash mapping goes haha! But ultimately, I don't want to rely on a possibility of reading/writing hundreds of thousands of individual basecontainer entries.
@m_magalhaes said in MoData.GetData()?:
hi,
After asking the dev, this is used internally and should be marked as private. Same goes for all modata functions that return a BaseContainer.
(GetDataIndexInstance, GetDataInstance)
Cheers,
Manuel
Thanks, Manuel. Private, eh? Which would mean I need access to the SetData() function of Modata, which isn't available in python. This just so happens to have become a C++ plugin, which has access to that function. Would I be correct in assuming that I can store these containers in my own basecontainer, then retrieve them later by passing them into a modata?
Thanks!
Kevin