Maxon Developers Maxon Developers
    • Documentation
      • Cinema 4D Python API
      • Cinema 4D C++ API
      • Cineware API
      • ZBrush GoZ API
      • Code Examples on Github
    • Forum
    • Downloads
    • Support
      • Support Procedures
      • Registered Developer Program
      • Plugin IDs
      • Contact Us
    • Categories
      • Overview
      • News & Information
      • Cinema 4D SDK Support
      • Cineware SDK Support
      • ZBrush 4D SDK Support
      • Bugs
      • General Talk
    • Unread
    • Recent
    • Tags
    • Users
    • Login

    VolumeObject ReadObject and WriteObject no supported?

    Cinema 4D SDK
    c++ r20
    2
    3
    451
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • kbarK
      kbar
      last edited by r_gigante

      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?

      https://www.gamelogicdesign.com
      https://www.plugins4d.com

      1 Reply Last reply Reply Quote 0
      • r_giganteR
        r_gigante
        last edited by

        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.

        	iferr_scope;
        	
        	// 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
        	volObjWrite->SetVolume(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;
        	fn.SetMemoryWriteMode(mfs);
        	
        	// 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
        	hf->Close();
        
                //... 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");
        	
        	hf->Close();
        	
        	return maxon::OK;
        

        Best, Riccardo

        1 Reply Last reply Reply Quote 2
        • kbarK
          kbar
          last edited by

          Thanks Riccardo.

          https://www.gamelogicdesign.com
          https://www.plugins4d.com

          1 Reply Last reply Reply Quote 0
          • First post
            Last post