PreviewImageProviderInterface Implementation

Table of Contents

About

An implementation of maxon::nodes::PreviewImageProviderInterface provides preview images of a node.

Methods

Note
Initialize() should not take long since it blocks the UI. One should create a clone of the given node graph and access that clone in ComputeIteration().

For accessing and searching for nodes in the node graph, see GraphNodes Manual.

Settings provided in Initialize() are:

  • maxon::nodes::PREVIEWIMAGEREQUEST::TEXTURESIZE: Defines the requested preview size in pixels.
  • maxon::nodes::PREVIEWIMAGEREQUEST::SUBJECT: Points to the node requested for preview.
  • maxon::nodes::PREVIEWIMAGEREQUEST::PROGRESSIONTHRESHOLD: Constraints the iterative refinement.
  • maxon::nodes::PREVIEWIMAGEREQUEST::URANGE: For 2D previews defines the horizontal range to be sampled.
  • maxon::nodes::PREVIEWIMAGEREQUEST::VRANGE: For 2D previews defines the vertical range to be sampled.
  • maxon::nodes::PREVIEWIMAGEREQUEST::SCENETYPE: The type of the 3D scene. See also maxon::nodes::NODESPACE::MATERIALPREVIEWIDS.
  • maxon::nodes::PREVIEWIMAGEREQUEST::FLIPVERTICALLY: Defines whether a request was made for a flipped version
  • maxon::nodes::PREVIEWIMAGEREQUEST::TEXTUREIDS: The set of attributes requested for preview.
  • maxon::nodes::PREVIEWIMAGEREQUEST::PROVIDER: Defines the instance of a PreviewImageProviderRef that is used to compute the preview.
// This example implementation of PreviewImageProviderInterface::Initialize() stores the given texture size,
// the node path and creates a copy of the given node graph.
MAXON_METHOD maxon::Result<void> Initialize(maxon::DataDictionaryObjectRef request, maxon::Int numThreads)
{
// store target image size
_imageSize = request.Get(maxon::nodes::PREVIEWIMAGEREQUEST::TEXTURESIZE, maxon::IntVector2d());
// get node or port for this call
maxon::GraphNode node = request.Get(maxon::nodes::PREVIEWIMAGEREQUEST::SUBJECT, maxon::GraphNode());
if (node.IsValid() == false)
{
return maxon::UnexpectedError(MAXON_SOURCE_LOCATION);
}
// get graph clone
maxon::nodes::NodesGraphModelRef graph = maxon::Cast<maxon::nodes::NodesGraphModelRef>(node.GetGraph());
_graph = graph.GetManager().GetMainView().Clone() iferr_return;
// get node path
_nodePath = node.GetPath();
// get preview scene if needed
maxon::UseVariable(sceneType);
return maxon::OK;
}
Definition: graph.h:1950
Int64 Int
signed 32/64 bit int, size depends on the platform
Definition: apibase.h:188
return OK
Definition: apibase.h:2690
#define MAXON_SOURCE_LOCATION
Definition: memoryallocationbase.h:67
#define MAXON_METHOD
Definition: interfacebase.h:1001
SCENETYPE
Definition: previewimageprovider.h:89
@ MatPreviewDefault
Default (may be a user preference).
#define iferr_scope
Definition: resultbase.h:1384
#define iferr_return
Definition: resultbase.h:1519
Definition: node.h:10
// These are example implementations of ComputeIteration() and TakeOutput().
// ComputeIteration() is called asynchronously so it must operate on the previously stored copy of the graph.
MAXON_METHOD maxon::Result<void> ComputeIteration(const maxon::JobRef parentThread)
{
// the path either references a port/node or is nullptr (render the material node)
// get node the node from the graph copy
const maxon::GraphNode node = _graph.GetNode(_nodePath);
// depending on the node, fill the image
// prepare image
result.Resize(_imageSize.x * _imageSize.y) iferr_return;
// fill image
for (maxon::Int y = 0; y < _imageSize.y; ++y)
{
for (maxon::Int x = 0; x < _imageSize.x; ++x)
{
maxon::nodes::SampleFloat32& sample = result[x + y * _imageSize.x];
sample = maxon::nodes::SampleFloat32(maxon::Vector32(1.0, 1.0, 1.0));
}
}
_final = true;
return maxon::OK;
}
{
// provide information on the rendering process if the preview image is rendered iteratively.
output._iterationCount = 2;
output._currentIterationIndex = 1;
// store image data
image._imageSize = _imageSize;
image._samplesFloat32Linear = _currentResult;
image._isFinal = _final;
output.SetResult(image) iferr_return;
return output;
}
private:
maxon::IntVector2d _imageSize;
maxon::Bool _final;
maxon::NodePath _nodePath;
maxon::nodes::NodesGraphModelRef _graph;
Definition: basearray.h:412
Definition: baseref.h:62
Reference to a job (JobInterface).
Definition: job.h:1222
PyObject PyObject * result
Definition: abstract.h:43
PyObject * x
Definition: bytesobject.h:38
Py_ssize_t char * output
Definition: unicodeobject.h:985
bool Bool
boolean type, possible values are only false/true, 8 bit
Definition: apibase.h:181
Vec4< Float32 > SampleFloat32
Convenience definitions for the immutable preview image.
Definition: previewimageprovider.h:134
#define NewObj(T,...)
Definition: newobj.h:108
A vector consisting of three components X, Y and Z.
Definition: vec.h:21
A vector consisting of four components X, Y, Z and W.
Definition: vec4.h:21
Definition: previewimageprovider.h:265
Definition: previewimageprovider.h:230
Bool _isFinal
Definition: previewimageprovider.h:249
SamplesFloat32ConstRef _samplesFloat32Linear
Definition: previewimageprovider.h:242
IntVector2d _imageSize
Definition: previewimageprovider.h:235