VolumeObject ReadObject and WriteObject no supported?

  • I am manually saving objects within my own Generator. It seems that if I write out, then read a VolumeObject that it does not save any volume data at all. Calling GetVolume() returns nullptr; My volumes do have data in them so I would expect it to save and load.

    pObj = VolumeObject::Alloc();
    pObj->ReadObject(hf, true);
    maxon::VolumeInterface* data = pObj->GetVolume();

    data is null;

    Can someone confirm if this is actually true and the correct behaviour?

  • Hi Kent, thanks for reaching out us.

    With regard to your issue, at the moment writing/reading a VolumeObject using the C4DAtom::WriteObject / C4DAtom::ReadObject using an Hyperfile is not supported if the HyperFile object operates on disk.

    At the moment a workaround is represented by using a temporary memory file, write into that, write that to disk. To read/write using MemoryFileStruct please visit here.

    The following code shows how to read/write VolumeObject from/to memory-located HF.

    	// alloc the VolumeObject to write
    	AutoAlloc<VolumeObject> volObjWrite;
    	if (!volObjWrite)
    		return maxon::OutOfMemoryError(MAXON_SOURCE_LOCATION);
    	// put some data in the VolumeObject
    	const maxon::Int    gridIndex = 0;
    	const maxon::Url volumeUrl ("<your path to a vdb>"_s);
    	const maxon::Volume volume = maxon::VolumeInterface::CreateFromFile(volumeUrl, 1.0, gridIndex) iferr_return;
    	// insert volume
    	// alloc HF
    	AutoAlloc<HyperFile> hf;
    	if (!hf)
    		return maxon::OutOfMemoryError(MAXON_SOURCE_LOCATION);
    	// alloc MemoryFileStruct
    	AutoAlloc<MemoryFileStruct> mfs;
    	if (!mfs)
    		return maxon::OutOfMemoryError(MAXON_SOURCE_LOCATION);
    	// alloc Filename and set to memory
    	Filename fn;
    	// open HyperFile to write
    	if (!hf->Open(0, fn, FILEOPEN::WRITE, FILEDIALOG::NONE))
    		return maxon::UnknownError(MAXON_SOURCE_LOCATION);
    	// write volume to memory HF
      Bool writeRes = volObjWrite->WriteObject(hf);
    	if (writeRes)
    		DiagnosticOutput("volume written on HF");
    	// close written HF
            //... write memory-located HF to disk
            //... do your stuff
            //...read from disk the memory-located HF
    	// open HF to read
    	if (!hf->Open(0, fn, FILEOPEN::READ, FILEDIALOG::NONE))
    		return maxon::UnknownError(MAXON_SOURCE_LOCATION);
    	// alloc the VolumeObject to read
    	AutoAlloc<VolumeObject> volObjRead;
    	if (!volObjRead)
    		return maxon::OutOfMemoryError(MAXON_SOURCE_LOCATION);
    	// read volume from memory HF
    	Bool readRes = volObjRead->ReadObject(hf, true);
    	const maxon::VolumeInterface* volRead = volObjRead->GetVolume();
    	if (readRes && volRead)
    		DiagnosticOutput("volume read from HF");
    	return maxon::OK;

    Best, Riccardo

  • Thanks Riccardo.

Log in to reply