stream the viewport to python api that sends an image back and use that as a texture
-
Hey Forum
Here is what I am trying to do:
- capture the current viewport as an image
- send it to a Python API
- wait for the API to send an image back
- use this image as a texture.
I realise my question involves a few steps and is complicated. I think some bits I'll be able to figure out. I think the external API bit sending and receiving will be easier, but I don't know much about the APIs in c4d. I am pretty good at Python and coding, but I have never worked with the API. I looked at the documentation and the GitHub examples but couldn't see any examples for the viewport and capturing it as an image.
Right now, I would like to start at step 01. Can you capture a viewport or, alternatively the render view? Can you capture (save an image) from any c4d window? For example from the RS or Arnold viewport even?
thank you,
T -
Hello @thomas,
Welcome to the Plugin Café forum and the Cinema 4D development community, it is great to have you with us!
Getting Started
Before creating your next postings, we would recommend making yourself accustomed with our Forum and Support Guidelines, as they line out details about the Maxon SDK Group support procedures. Of special importance are:
- Support Procedures: Scope of Support: Lines out the things we will do and what we will not do.
- Support Procedures: Confidential Data: Most questions should be accompanied by code but code cannot always be shared publicly. This section explains how to share code confidentially with Maxon.
- Forum Structure and Features: Lines out how the forum works.
- Structure of a Question: Lines out how to ask a good technical question. It is not mandatory to follow this exactly, but you follow the idea of keeping things short and mentioning your primary question in a clear manner.
About your First Question
I have trouble understanding what you mean with the loaded terms stream, send, and receive. I assume you want to simply get access to the framebuffer of a viewport to use it as a texture.
- Viewports are represented by the inheritance chain c4d.BaseView<-c4d.BaseDraw where most of the functionalities is realized in
c4d.BaseDraw
, a canvas like type with which you can draw into a viewport. - In C++ there is BaseDraw::GetViewportImage which exposes the current color framebuffer state of the viewport as an
maxon::ImageRef
. This method has not been wrapped for Python. - But you can simply render the document using the hardware preview renderer. The topic has been discussed before for example here.
- You could then reference the render result file on disk as a texture.
Cheers,
Ferdinand -
hi Ferdinand.
thanks so much for your help. This will be enough to get me going for now.
-
Hi @ferdinand, your links really helped me a lot, and I managed to write a script that starts a render and sends the rendered image to a web service.
Can the SDK grab the live preview image from the redshift IPR? I assume not looking at the documentation: https://developers.maxon.net/docs/py/2023_2/search.html?q=redshift&check_keywords=yes&area=default