class MRenderUtil

Jump to documentation

Static class providing common API rendering functions (OpenMayaRender) (OpenMayaRender.py)

public members:

enum MRenderState
kNotRendering
Maya is not currently rendering
kBatchRender
Maya is performing a batch render
kInteractiveRender
Maya is performing an interactive render
kIprRender
Maya is performing an IPR render
kHardwareRender
Maya is performing a hardware render
enum MRenderPass
kAll
Default case
kColorOnly
Only the color information is being computed, no shadows
kShadowOnly
Only the shadow information is being computed, no color
kAmbientOnly
Only the specular information is being computed
kDiffuseOnly
Only the specular information is being computed
kSpecularOnly
Only the specular information is being computed
static MRenderState mayaRenderState ()
static MStatus raytrace ( const MFloatVector & rayOrigin, const MFloatVector & rayDirection, const void* objectId, const void* raySampler, const short rayDepth, MFloatVector & resultColor, MFloatVector & resultTransparency, const bool isReflectedRays = true )
static MStatus raytrace ( const MFloatVectorArray & rayOrigins, const MFloatVectorArray & rayDirections, const void* objectId, const void* raySampler, const short rayDepth, MFloatVectorArray & resultColors, MFloatVectorArray & resultTransparencies, const bool isReflectedRays = true )
static MStatus raytraceFirstGeometryIntersections ( const MFloatVectorArray & rayOrigins, const MFloatVectorArray & rayDirections, const void* objectId, const void* raySampler, MFloatVectorArray & resultIntersections, MIntArray & resultIntersected )
static MStatus sampleShadingNetwork ( MString shadingNodeName, int numSamples, bool useShadowMaps, bool reuseMaps, MFloatMatrix &cameraMatrix, MFloatPointArray *points, MFloatArray *uCoords, MFloatArray *vCoords, MFloatVectorArray *normals, MFloatPointArray *refPoints, MFloatVectorArray *tangentUs, MFloatVectorArray *tangentVs, MFloatArray *filterSizes, MFloatVectorArray &resultColors, MFloatVectorArray &resultTransparencies )
static bool generatingIprFile ()
static MString relativeFileName ( const MString & absFileName, MStatus *ReturnStatus = NULL )
static bool exactFileTextureName ( const MObject & fileNode, MString & texturePath, MStatus *ReturnStatus = NULL )
static bool exactFileTextureName ( const MString & baseName, bool useFrameExt, const MString & currentFrameExt, MString & exactName, MStatus *ReturnStatus = NULL )
static bool convertPsdFile ( const MObject & fileNode, MString & texturePath, const bool &state = false, MStatus *ReturnStatus = NULL )
Internal use only
static bool exactImagePlaneFileName ( const MObject & imagePlaneNode, MString & texturePath, MStatus *ReturnStatus = NULL )
static MString exactFileTextureName ( const MObject & fileNode, MStatus *ReturnStatus = NULL )
static MString exactFileTextureName ( const MString & baseName, bool useFrameExt, const MString & currentFrameExt, MStatus *ReturnStatus = NULL )
static MString convertPsdFile ( const MObject & fileNode, const bool &state = false, MStatus *ReturnStatus = NULL )
Internal use only
static MString exactImagePlaneFileName ( const MObject & imagePlaneNode, MStatus *ReturnStatus = NULL )
static bool inCurrentRenderLayer ( const MDagPath & objectPath, MStatus *ReturnStatus = NULL )
static MRenderPass renderPass ( void )
static float diffuseReflectance ( const void* lightBlindData, const MFloatVector & lightDirection, const MFloatVector & pointCamera, const MFloatVector & normal, bool lightBackFace, MStatus *ReturnStatus = NULL )
static MFloatVector maximumSpecularReflection ( const void* lightBlindData, const MFloatVector & lightDirection, const MFloatVector & pointCamera, const MFloatVector & normal, const MFloatVector & rayDirection, MStatus *ReturnStatus = NULL )
static float lightAttenuation ( const void* lightBlindData, const MFloatVector & pointCamera, const MFloatVector & normal, bool lightBackFace, MStatus *ReturnStatus = NULL )
static float hemisphereCoverage ( const void* lightBlindData, const MFloatVector & lightDirection, const MFloatVector & pointCamera, const MFloatVector & rayDirection, bool lightBackFace, MStatus *ReturnStatus = NULL )
static void sendRenderProgressInfo (const MString &pixFile, int percentageDone)
static MStatus renderObjectItem ( const void* objectId, MSelectionList & item)

Documentation

Static class providing common API rendering functions (OpenMayaRender) (OpenMayaRender.py)
Description

MRenderUtil is a static class which provides API access to Maya's rendering functionalities.

Functions

MRenderUtil::MRenderState MRenderUtil:: mayaRenderState ()
Description

Returns an enumerated type specifying the current state of the Maya renderer.

Return Value

  • MRenderUtil::kNotRendering Maya is not currently rendering
  • MRenderUtil::kBatchRender Maya is performing a batch render
  • MRenderUtil::kInteractiveRender Maya is performing an interactive render
  • MRenderUtil::kIprRender Maya is performing an IPR render
  • MRenderUtil::kHardwareRender Maya is performing a hardware render

MStatus MRenderUtil:: raytrace ( const MFloatVector & rayOrigin, const MFloatVector & rayDirection, const void* notUsed, const void* raySampler, const short rayDepth, MFloatVector & resultColor, MFloatVector & resultTransparency, const bool isReflectedRays )
Description

This utility method provides functionality to raytrace from within a shader plug-in.

This method shoots a single ray given a ray origin and a ray direction, and returns the color and transparency of the result.

In order for a shader plug-in to raytrace, the following steps are necessary:

raySampler is needed from the renderer. This can be obtained by creating an input attribute named 'raySampler' (rtr).

rayDepth is needed from the renderer. This can be obtained by creating an input attribute named 'rayDepth' (rd).

The "Enable Raytracing" flag needs to be turned on in renderGlobal-> renderQuality->raytracing.

isReflectedRays tells if these rays are for reflection or refraction. This allows the raytracer to check the corresponding ray depth limit under renderGlobal->renderQuality for terminating the rays.

All objects to be seen by the raytracer need to have their "Visible In Reflections" or "Visible In Refraction" flags turned on.

This method only works in the software renderer.

Arguments

  • rayOrigin Origin of the ray to shoot from in camera space
  • rayDirection Direction of the ray to shoot at in camera space
  • notUsed unused argument left for compatability
  • raySampler Pointer to the raytracer from the renderer
  • rayDepth Current ray depth from the renderer
  • resultColor Storage for the result color
  • resultTransparency Storage for the result transparency
  • isRefractedRays true for reflected rays (default), false for refracted rays

Return Value

  • Status Code (see below)

Status Codes

  • MS::kSuccess Return is valid
  • MS::kInvalidParameter Raytracing failed due to bad raySampler pointer passed in.

MStatus MRenderUtil:: raytrace ( const MFloatVectorArray & rayOrigins, const MFloatVectorArray & rayDirections, const void* notUsed, const void* raySampler, const short rayDepth, MFloatVectorArray & resultColors, MFloatVectorArray & resultTransparencies, const bool isReflectedRays )
Description

This utility method provides functionality to raytrace from within a shader plug-in.

This method shoots a number of rays given ray origins and ray directions, and returns the colors and transparencies of the results.

The size of rayOrigins, rayDirections, colors, and transparencies arrays must be the same.

In order for a shader plug-in to raytrace, the following steps are necessary:

raySampler is needed from the renderer. This can be obtained by creating an input attribute named 'raySampler' (rtr).

rayDepth is needed from the renderer. This can be obtained by creating an input attribute named 'rayDepth' (rd).

The "Enable Raytracing" flag needs to be turned on in renderGlobal-> renderQuality->raytracing.

isReflectedRays tells if these rays are for reflection or refraction. This allows the raytracer to check the corresponding ray depth limit under renderGlobal->renderQuality for terminating the rays.

All objects to be seen by the raytracer need to have their "Visible In Reflections" or "Visible In Refraction" flags turned on.

This method only works in the software renderer.

Arguments

  • rayOrigins Origins of the ray to shoot from in camera space
  • rayDirections Directions of the ray to shoot at in camera space
  • notUsed unused argument left for compatability
  • raySampler Pointer to the raytracer from the renderer
  • rayDepth Current ray depth from the renderer
  • resultColors Storage for the result colors
  • resultTransparencies Storage for the result transparencies
  • isRefraction true for reflected rays (default), false for refracted rays

Return Value

  • Status Code (see below)

Status Codes

  • MS::kSuccess Return is valid
  • MS::kIndexOutOfRange Array size do not match.
  • MS::kInvalidParameter Raytracing failed due to bad raySampler pointer passed in.

MStatus MRenderUtil:: raytraceFirstGeometryIntersections ( const MFloatVectorArray & rayOrigins, const MFloatVectorArray & rayDirections, const void* notUsed, const void* raySampler, MFloatVectorArray & resultIntersections, MIntArray & resultIntersected )
Description

This utility method provides functionality to find the location of the first geometry intersected by a ray from within a shader plug-in.

This method shoots a number of rays given ray origins and ray directions, and returns whether the rays intersected anything, and if so, the locations of the first geometry intersected in camera space. The plug-in should check the resultIntersected values to see if a ray has intersected any geometry (0 = no geometry intersected, 1 = geometry intersected).

The size of rayOrigins, rayDirections, resultIntersections, and resultIntersected arrays must be the same.

In order for a shader plug-in to raytrace, the following steps are necessary:

raySampler is needed from the renderer. This can be obtained by creating an input attribute named 'raySampler' (rtr).

The "Enable Raytracing" flag needs to be turned on in renderGlobal-> renderQuality->raytracing.

All objects to be seen by the raytracer need to have their "Visible In Reflections" flags turned on.

This method only works in the software renderer.

Arguments

  • rayOrigins Origins of the ray to shoot from in camera space
  • rayDirections Directions of the ray to shoot at in camera space
  • notUsed unused argument left for compatability
  • raySampler Pointer to the raytracer from the renderer
  • resultIntersections Storage for the result intersection locations in camera space
  • resultIntersected Storage for the result intersected flags (0 = no geometry intersected, 1 = geometry intersected)

Return Value

  • Status Code (see below)

Status Codes

  • MS::kSuccess Return is valid
  • MS::kIndexOutOfRange Array size do not match.
  • MS::kInvalidParameter Raytracing failed due to bad raySampler pointer passed in.

bool MRenderUtil:: inCurrentRenderLayer ( const MDagPath & objectPath, MStatus *ReturnStatus )
Description

Returns true if the specified path is in the current render layer.

If the object at the end of the DAG path has not been assigned to any layer, then each node in hierarchy from bottom up will be tested whether its contained in the current render layer.

Arguments

  • objectPath Path of object to test
  • ReturnStatus Status code

Return Value

  • true will be returned if the object is in the current render layer

Status Codes

  • MS::kSuccess Success
  • MS::kFailure Invalid object

MRenderUtil::MRenderPass MRenderUtil:: renderPass ( void )
Description

Returns an enumerated type specifying the current pass the Maya renderer is executing.

Return Value

  • MRenderUtil::kAll Default case.
  • MRenderUtil::kColorOnly Only color information is being calculated.
  • MRenderUtil::kShadowOnly Only shadow information is being calculated.
  • MRenderUtil::kAmbientOnly Only ambient information is being calculated.
  • MRenderUtil::kDiffuseOnly Only diffuse information is being calculated.
  • MRenderUtil::kSpecularOnly Only specular information is being calculated.

bool MRenderUtil:: generatingIprFile ()
Description

Returns true if an IPR file is being created. This can be used to optimize the IPR file. Lights do not need to request particle information (IPR does not support particle rendering) when creating a IPR file.

Return Value

    true - IPR file is being generated. false - IPR file is not being generated.

bool MRenderUtil:: exactFileTextureName ( const MObject & fileNode, MString & texturePath, MStatus *ReturnStatus )
Description

Attempts to resolve the file texture name specified on a file texture node into an absolute path to an image file on disk. The function applies exactly the same logic that is used by the file texture node internally for resolving the image file path.

Python Notes

This method is not supported in Python. See the version which returns a string.

Arguments

  • fileNode a file texture node
  • resultTexturePath returns an absolute pathname to the texture file referenced by the node.
  • status status code

Return Value

  • true if the image file pathname was successfully resolved.
  • false if the pathname could not be resolved.

Status Codes

  • MS::kSuccess Return is valid
  • MS::kInvalidParameter fileNode pointer is not a valid file texture node.

bool MRenderUtil:: exactFileTextureName (const MString & baseName, bool useFrameExt, const MString & currentFrameExt, MString & exactName, MStatus *ReturnStatus )
Description

Attempts to resolve the file name specified into an absolute path to a file on disk. The function applies exactly the same logic that is used by the file texture node internally for resolving the image file path.

Python Notes

This method is not supported in Python. See the version which returns a string.

Arguments

  • baseName a file name to be resolved
  • (\bf useFrameExt) use frame extention for image file name
  • currentFrameExt specify a frame extention if useFrameExt is used.
  • (\bf exactName) resolved file name with absolute path
  • status status code

Return Value

  • true if the file pathname was successfully resolved.
  • false if the pathname could not be resolved.

Status Codes

  • MS::kSuccess Return is valid

MString MRenderUtil:: exactFileTextureName ( const MObject & fileNode, MStatus *ReturnStatus )
Description

Attempts to resolve the file texture name specified on a file texture node into an absolute path to an image file on disk. The function applies exactly the same logic that is used by the file texture node internally for resolving the image file path.

Arguments

  • fileNode a file texture node
  • status status code

Return Value

  • an absolute pathname to the texture file referenced by the node. If the path cannot be resolved than an empty string is returned

Status Codes

  • MS::kSuccess Return is valid
  • MS::kInvalidParameter fileNode pointer is not a valid file texture node.

MString MRenderUtil:: exactFileTextureName (const MString & baseName, bool useFrameExt, const MString & currentFrameExt, MStatus *ReturnStatus )
Description

Attempts to resolve the file name specified into an absolute path to a file on disk. The function applies exactly the same logic that is used by the file texture node internally for resolving the image file path.

Arguments

  • baseName a file name to be resolved
  • (\bf useFrameExt) use frame extention for image file name
  • currentFrameExt specify a frame extention if useFrameExt is used.
  • (\bf exactName) resolved file name with absolute path
  • status status code

Return Value

  • true if the file pathname was successfully resolved.
  • false if the pathname could not be resolved.

Status Codes

  • MS::kSuccess Return is valid

MString MRenderUtil:: relativeFileName (const MString & absFileName, MStatus *ReturnStatus )
Description

Extract relative file name from the given (absolute) file name. If the given file name does not begin with a project root, return value is same as the input file name.

Arguments

  • absFileName input file name
  • status status code

Return Value

  • file name without the project path

Status Codes

  • MS::kSuccess Return is valid
  • MS::kInvalidParameter absFileName is empty

bool MRenderUtil:: convertPsdFile ( const MObject & fileNode, MString & texturePath, const bool &state, MStatus *ReturnStatus )
Description

This method converts a Psd file texture to an IFF file that can be used by Maya. It writes out the current layer set image the file node. The intermediate image will be either 8 or 16 b.p.c, based on the input psd file.

Python Notes

This method is not supported in Python. See the version which returns a string.

Arguments

  • fileNode a file texture node
  • resultTexturePath returns an absolute pathname to the texture file referenced by the node.
  • status status code

Return Value

  • true if the image file pathname was successfully resolved and exporting psd file is succeeded.
  • false if the pathname could not be resolved or exporting psd file fails.

Status Codes

  • MS::kSuccess Return is valid
  • MS::kInvalidObjectType fileNode pointer is not a valid file texture node.
  • MS::kInvalidParameter fileNode has empty file name string

MString MRenderUtil:: convertPsdFile ( const MObject & fileNode, const bool &state, MStatus *ReturnStatus )
Description

This method converts a Psd file texture to an IFF file that can be used by Maya. It writes out the current layer set image the file node. The intermediate image will be either 8 or 16 b.p.c, based on the input psd file.

Arguments

  • fileNode a file texture node
  • resultTexturePath returns an absolute pathname to the texture file referenced by the node.
  • status status code

Return Value

  • true if the image file pathname was successfully resolved and exporting psd file is succeeded.
  • false if the pathname could not be resolved or exporting psd file fails.

Status Codes

  • MS::kSuccess Return is valid
  • MS::kInvalidObjectType fileNode pointer is not a valid file texture node.
  • MS::kInvalidParameter fileNode has empty file name string

MString MRenderUtil:: exactImagePlaneFileName ( const MObject & imagePlaneNode, MStatus *ReturnStatus )
Description

Attempts to resolve the file texture name specified on an image plane node into an absolute path to an image file on disk. The function applies exactly the same logic that is used by the image plane node internally for resolving the image file path.

Arguments

  • imagePlaneNode an image plane node
  • status status code

Return Value

  • returns an absolute pathname to the texture file referenced by the node. If the pathname cannot be resolved, then the returned string is empty

Status Codes

  • MS::kSuccess Return is valid
  • MS::kInvalidParameter imagePlaneNode pointer is not a valid image plane node.

bool MRenderUtil:: exactImagePlaneFileName ( const MObject & imagePlaneNode, MString & texturePath, MStatus *ReturnStatus )
Description

Attempts to resolve the file texture name specified on an image plane node into an absolute path to an image file on disk. The function applies exactly the same logic that is used by the image plane node internally for resolving the image file path.

Python Notes

This method is not supported in Python. See the version which returns a string.

Arguments

  • imagePlaneNode an image plane node
  • resultTexturePath returns an absolute pathname to the texture file referenced by the node.
  • status status code

Return Value

  • true if the image file pathname was successfully resolved.
  • false if the pathname could not be resolved.

Status Codes

  • MS::kSuccess Return is valid
  • MS::kInvalidParameter imagePlaneNode pointer is not a valid image plane node.

float MRenderUtil:: diffuseReflectance ( const void* lightBlindData, const MFloatVector & lightDirection, const MFloatVector & pointCamera, const MFloatVector & normal, bool lightBackFace, MStatus *ReturnStatus )
Description

This utility function computes and returns the diffuse or lambertian reflectance for a given light source and surface.

Arguments

  • lightBlindData The reference to the aLightBlindData attribute of the current light being evaluated
  • lightDirection The direction of the light being evaluated
  • pointCamera The position of the camera
  • normal The surface normal
  • lightBackFace Is the back face being lit, true or false.
  • ReturnStatus Status code

MFloatVector MRenderUtil:: maximumSpecularReflection ( const void* lightBlindData, const MFloatVector & lightDirection, const MFloatVector & pointCamera, const MFloatVector & normal, const MFloatVector & rayDirection, MStatus *ReturnStatus )
Description

This utility function computes and returns the vector corresponding to the point on the light source that provides the maximum specular reflection.

Arguments

  • lightBlindData The reference to the aLightBlindData attribute of the current light being evaluated
  • lightDirection The direction of the light being evaluated
  • pointCamera The position of the camera
  • normal The surface normal
  • rayDirection The direction of the current intersection ray in camera space
  • ReturnStatus Status code

float MRenderUtil:: lightAttenuation ( const void* lightBlindData, const MFloatVector & pointCamera, const MFloatVector & normal, bool lightBackFace, MStatus *ReturnStatus )
Description

This utility function computes and returns light attentuation factor of a light. Note that the result of 1 will be returned if the light being evaluated does not support light attentuation.

Arguments

  • lightBlindData The reference to the aLightBlindData attribute of the current light being evaluated
  • pointCamera The position of the camera
  • normal The surface normal
  • lightBackFace Is the back face being lit, true or false.
  • ReturnStatus Status code

float MRenderUtil:: hemisphereCoverage ( const void* lightBlindData, const MFloatVector & lightDirection, const MFloatVector & pointCamera, const MFloatVector & rayDirection, bool lightBackFace, MStatus *ReturnStatus )
Description

This utility function computes and returns the fraction of the light that is transmitted by an object. It is mostly used for translucence and scattering effects.

Arguments

  • lightBlindData The reference to the aLightBlindData attribute of the current light being evaluated
  • lightDirection The direction of the light being evaluated
  • pointCamera The position of the camera
  • rayDirection The direction of the current intersection ray in camera space
  • lightBackFace Is the back face being lit, true or false.
  • ReturnStatus Status code

void MRenderUtil:: sendRenderProgressInfo (const MString &pixFile, int percentageDone)
Description

This utility function sends batch rendering status to Maya

Arguments

  • pixFile File name of the last rendered batch image
  • percentageDone percentage rendered

void MRenderUtil:: getCommonRenderSettings ( MCommonRenderSettingsData &mrgData)
Fill the set of common render setting values

MStatus MRenderUtil:: renderObjectItem (const void* objectId, MSelectionList & item)
Description

Procedure to look up a selection item for a given sample object id. This is only guaranteed to work when software rendering. As multiple processors may be used when software rendering; a critical section should be used to protect multiple threads from simulaneously performing DG evaluation. This includes querying attribute values.

Arguments

  • objectId The sample object id to look-up
  • item The corresponding item for the id

Return Value

  • Status Code (see below)

Status Codes

  • MS::kSuccess Returned if valid
  • MS::kInvalidParameter The objectId parameter is NULL
  • MS::kNotFound The item was not found

Functions

MStatus MRenderUtil:: sampleShadingNetwork ( MString shadingNodeName, int numSamples, bool useShadowMaps, bool reuseMaps, MFloatMatrix &cameraMatrix, MFloatPointArray *points, MFloatArray *uCoords, MFloatArray *vCoords, MFloatVectorArray *normals, MFloatPointArray *refPoints, MFloatVectorArray *tangentUs, MFloatVectorArray *tangentVs, MFloatArray *filterSizes, MFloatVectorArray &resultColors, MFloatVectorArray &resultTransparencies )
Description

This utility method allows you to sample a shading node/shading engine. You can specify the location and property of the sample point, and the method will return the result color and transparency. If you are sampling a shading engine, and there are lights in the scene, you can optionally request shadows to be computed as well.

If you specify a shading node to be evaluated, you'll need to provide the attribute to be evaluated. For example, valid shading nodes are checker1.outAlpha, file1.outColor, etc.

If you specify a shading engine to be evaluated, only the name will be needed. For example, valid shading engines are initialShadingGroup, phong1SG, etc.

Since setting up sampling is an expensive operation, try to pass in as many sample points at one time as possible and let the sampler process them in batch. Try to avoid calling the sampler with just one sample.

For extremely complicated shading networks, it is possible that passing in too many samples in one batch will cause a stack overflow. If this condition occurs, simply reduce the number of samples per batch.

Certain type of shading network requires certain type of input, and not all inputs are needed. For example, a 2D texture such as file or checker does not need point/normal/tangent information. Pass in NULL for parameters which are not needed.

In general, 2D textures require UV coordinates, 3D textures require points and refPoints, lighting calculations require points and normals.

To calculate camera space related shaders, such as hilights in a phong shader, an eye to world matrix needs to be supplied. This matrix is used to convert supplied world coordinates into camera coordinate. The matrix can be obtained by getting the inclusive matrix of the camera's DAG node.

This method can be used in both interactive and batch.

Arguments

  • shadingNodeName Name of the shading node/shading engine
  • numSamples Number of samples to be calculated
  • useShadowMaps Whether to calculate shadows
  • reuseMaps If calculating shadows, whether to reuse shadowmaps
  • cameraMatrix The eyeToWorld matrix to be used for conversion
  • points Locations to be sampled in world space
  • uCoords U coordinates of the samples
  • vCoords V coordinates of the samples
  • normals Normals at the sample points in world space
  • refPoints RefPoints to be used for 3D texture in world space
  • tangentUs U tangents at the sample points in world space
  • tangentVs V tangents at the sample points in world space
  • filterSizes Filter sizes to be used for 2D/3D textures
  • resultColors Storage for result colors
  • resultTransparencies storage for result transparencies

Return Value

  • Status Code (see below)

Status Codes

  • MS::kSuccess Return is valid
  • MS::kNoModelActive Unable to get the active model
  • MS::kObjectDoesNotExist Unable to find the specified shadingNodeName
  • MS::kInvalidDataType Specified node is not a shading engine
  • MS::kFailure Failed to sample the given shading network

This class has no child classes.


Autodesk® Maya® 2008 © 1997-2007 Autodesk, Inc. All rights reserved. doc++ Copyright