How to access Volume Data?
-
@s_bach said in Ovolumeloader:
Hello,
a volume loader is just an ordinary generator. This means the stuff it creates is in its cache. You can access the volumes stored in its cache as usual:
if (baseObject->IsInstanceOf(Ovolumeloader) == false) return maxon::IllegalArgumentError(MAXON_SOURCE_LOCATION); BaseObject* const cache = baseObject->GetCache(); if (cache == nullptr) return maxon::IllegalArgumentError(MAXON_SOURCE_LOCATION); if (cache->IsInstanceOf(Ovolume) == false) return maxon::UnexpectedError(MAXON_SOURCE_LOCATION); const VolumeObject* const volumeObject = static_cast<VolumeObject*>(cache); ApplicationOutput("Volume Object: " + volumeObject->GetName());
See also VolumeObject Manual.
best wishes,
SebastianHello guys!
May I ask if this is possible to do with Python too? I tried but the equivalent of
cache.IsInstanceOf(c4d.Ovolume)
is not returning True.Thanks!
-
Hello @cybor09,
Thank you for reaching out to us. This question of yours did deviate too far from the subject of the old topic. Due to that, your posting has been forked. Note that our Forum Guidelines state:
- A topic must cover a singular subject; the initial posting must be a singular question.
- Users can ask follow-up questions, asking for clarification or alternative approaches, but follow-up questions cannot change the subject.
- When the subject of the topic is "How to create a cube object?", then a follow-up question cannot be "How to add a material to that cube?" as this would change the subject.
- A valid follow-up question would be "Are there other ways to create a cube object, as the proposed solution has the drawback X for my use-case?" or "Could you please clarify the thing Y you did mention in your answer, as this is still unclear to me?".
- There is some leverage-room for this rule, but it is rather small. Small changes in the subject are allowed, large changes are not.
Please try to follow these rules in the future. It is certainly no catastrophe when users violate these from time to time, as it can be tricky to decide when something is on-topic or not. But we must enforce this rule to a reasonable degree, so that the forum remains a searchable knowledge base.
About your Question
First of all, we have these extensive volume examples for Python. Volumes can also be a bit trickly composed, see my example below. For everything else, we need code from you.
Cheers,
FerdinandResult for first running the script on the volume builder and then on the Pyro output:
Code:
"""Demonstrates accessing volume caches. Volumes are composed differently based on part of application using them but this script demonstrates how most of them can be accessed. """ import c4d doc: c4d.documents.BaseDocument # The active document op: c4d.BaseObject | None # The active object, None if unselected def main() -> None: """ """ if not op: return # Volume output is contained in the caches of objects. In this case an Ovolume is directly # the cache content of some tangible scene object. cache: c4d.BaseObject = op.GetCache() if cache.CheckType(c4d.Ovolume): print (f"{cache = }") # Sometimes, e.g., Pyro, volumes are loaded from VDB files on disk, in that case the loading # tangible scene object usually holds a Ovolumeloader as the first child of its cache. if cache.CheckType(c4d.Ovolumeloader): cache = cache.GetCache() # Many things contain not only a singular volume but sets of them. Which then hold their content # as children. Stuff can get more complex as always the case with caches in Cinema 4D, but the # cache structure of a Pyro Output object loading data from disk could look like this: # # PyroOutput # Cache: Ovolumeloader # Cache: Ovolumeset # Child: Ovolume (Color) # Child: Ovolume (Density) # ... if cache.CheckType(c4d.Ovolumeset): cache = cache.GetCache() for item in cache.GetChildren(): print (f"{item = }") if __name__ == '__main__': main()
- A topic must cover a singular subject; the initial posting must be a singular question.
-
Hello @ferdinand ,
First of all thanks a lot for your answer, it does exactly what I was trying to achieve, print the names of the volume grids stored on a Volume Loader with Python, I just added the
GetName()
on the last loop for that.Sorry about the rule violation, I thought it was a good idea to have the C++ and the Python code equivalent at the same place because of the same reason that you mentioned, if someone was looking for doing this they could find both versions at the same place, also as you mentioned, sometimes it can be tricky to decide when something is on-topic or not.
Here is the updated code with the grid name:
"""Demonstrates accessing volume caches. Volumes are composed differently based on part of application using them but this script demonstrates how most of them can be accessed. """ import c4d doc: c4d.documents.BaseDocument # The active document op: c4d.BaseObject | None # The active object, None if unselected def main() -> None: """ """ if not op: return # Volume output is contained in the caches of objects. In this case an Ovolume is directly # the cache content of some tangible scene object. cache: c4d.BaseObject = op.GetCache() if cache.CheckType(c4d.Ovolume): print (f"{cache = }") # Sometimes, e.g., Pyro, volumes are loaded from VDB files on disk, in that case the loading # tangible scene object usually holds a Ovolumeloader as the first child of its cache. if cache.CheckType(c4d.Ovolumeloader): cache = cache.GetCache() # Many things contain not only a singular volume but sets of them. Which then hold their content # as children. Stuff can get more complex as always the case with caches in Cinema 4D, but the # cache structure of a Pyro Output object loading data from disk could look like this: # # PyroOutput # Cache: Ovolumeloader # Cache: Ovolumeset # Child: Ovolume (Color) # Child: Ovolume (Density) # ... if cache.CheckType(c4d.Ovolumeset): cache = cache.GetCache() for item in cache.GetChildren(): print (f"{item = }") print ("grid name = " + item.GetName()) if __name__ == '__main__': main()