Python Volume access
I'm trying to read a VolumeObject from Python, just trying to visualize the voxel count for now. When I acces a volume interface, like this...
def GetDParameter(self, node, id, flags): paramId = id.id if paramId == c4d.UNITY_VOLUME_VoxelCount: volume = self.get_volume_object(node) if volume == None: return False vi = volume.GetVolume() data = vi.GetActiveVoxelCount() return (True, data, flags | c4d.DESCFLAGS_GET_PARAM_GET) return False
It works, but I always hit this debug breakpoint. Removing that code stops the critical stop.
Do I need to dispose the interface in any way?
/Volumes/Branches/build_osx/osx-4-release/depot/release/20.0/frameworks/kernel.framework/source/memory/systemallocator.cpp(487): CRITICAL: Stop: Damaged block (or from a different allocator
Also, how to iterate the volume using a GridIterator?
There's nothing like the step methods from C++ SDK, how do I do the loop?
m_adam last edited by
Especially gridaccessor_read_r20.py which demonstrate how to read data for a given voxel.
So here on a volume builder, the next script is working as expected, note that it's very important to import maxon and volume from maxon.frameworks.
import c4d import maxon from maxon.frameworks import volume def main(): # Checks if there is an active object if op is None: raise RuntimeError("Failed to retrieve op.") # Checks if the active object is a Volume builder if not op.IsInstanceOf(c4d.Ovolumebuilder): raise TypeError("op is not a c4d.Ovolumebuilder.") # Gets the C4D Volume Object from the cache cache = op.GetCache() if cache is None: raise RuntimeError("Failed to retrieve the cache of the volume builder.") # Checks if the cache is a C4D Volume Object if not cache.IsInstanceOf(c4d.Ovolume): raise TypeError("cache is not a c4d.Ovolume.") # Gets the Volume object linked to this Ovolume object. volume = cache.GetVolume() if volume is None: raise RuntimeError("Failed to retrieve the maxon.frameworks.volume.VolumeRef.") print(volume.GetActiveVoxelCount()) if __name__ == '__main__': main()
Unfortunately, there is no GridIterator in Python available.
So even if you import maxon, and the volume module you still have the issue, I would say that maybe your volumeobject is not correctly built, but without more code, it's hard to reproduce your issue.
rsodre last edited by rsodre
I'll devour hat repository, thanks!
I'm getting the volume from a VolumeBuilder's cache.
My code so far is here (very early WIP)
About the critical stop, it happens even with your code.
I run C4D R20.059 from XCode 10.3
What should the coordinate in
If I try the voxel coordinate, it always returns the same value, testing everything inside
If I try world coordinates, all values are negative (inside and outside) the volume.
From the docs,
volume. GetWorldBoundingBox()should return a
maxon.Range, but this type is not documented anywhere. In practice, it returns a type that is unknown...
I need to extract a normalized SDF from the volume.
Pretty basic but I can't figure out how just with api descriptions.
m_adam last edited by
Hi @rsodre, unfortunately, due to a bug solved in R21, it's not possible in R20 to run Cinema 4D as debug mode and call MAXON_CPYTHON_FUNCTION in release mode.
The issue is that the Python volume framework does use the MAXON_CPYTHON_FUNCTION, so this leads to the behavior that the memory model is not the same.
So I guess if you try your code in regular Cinema 4D (without Xcode and not running c4d in debug mode), it will work without issue, could you confirm?
GetValueworks in the global space of the volume grid. This grid can be retrieved from a
However, since it's a
maxon.Matrix64this is a bit problematic since
maxon.Vectordoesn't support * operator. So you have to translate them in c4d type (manually) then reconvert it back to a Maxon datatype (this will be done on the fly).
maxon.Rangeis not yet implemented in Python so a UnknownDataType is returned so C++.
While I'm happy to assist you on Python Maxon API, I have to admit that the Maxon API regarding Python is far from being feature complete, and regarding your knowledge I advise you to do what you want in C++, it will be far way easier with the GridAccessor.