9.2 KiB
9.2 KiB
Maya Node Implementation Specification
Overview
This document specifies the implementation details for the Maya MPxNode plugin that handles video file input and frame output for the Image Plane Node.
Requirements
- Create a custom MPxNode that accepts video file path as input
- Output video frame data that can be consumed by viewport rendering
- Support attributes for frame rate control and playback rate adjustment
- Integrate with FFmpeg video decoding component
- Provide frame caching interface
- Follow Maya API best practices for node creation
Implementation Details
Node Definition
- Node Name:
imagePlaneVideo - Node ID: Unique ID obtained from Autodesk
- Classification:
filterorimage(to be determined based on Maya's categorization) - Register as a Maya plugin using MFnPlugin
Attributes
Input Attributes
videoFile(message or string) - Path to the video fileframeRate(double) - Playback rate multiplier (1.0 = normal speed)useMayaFrameRate(bool) - Whether to synchronize with Maya's timeline frame ratecurrentTime(double) - Connection to Maya's timeline (for frame calculation)loop(bool) - Whether to loop the video playbackpostEffectCrop(double4) - Crop parameters (x, y, width, height)postEffectResize(double2) - Resize parameters (width, height)postEffectFlip(bool2) - Flip parameters (flipX, flipY)
Output Attributes
outFrameData(message or custom data type) - Pointer to video frame dataoutFrameWidth(int) - Width of current frameoutFrameHeight(int) - Height of current frameoutFrameFormat(int) - Pixel format of current frame (RGB, RGBA, etc.)outFrameTimestamp(double) - Timestamp of current frameisValid(bool) - Whether the current frame data is valid
Core Components
VideoFrameData Class
Custom data class to hold video frame information:
- Pointer to pixel data (RGB/RGBA buffer)
- Width and height
- Pixel format
- Timestamp
- Reference counting for proper cleanup
Node Computation
In the compute() method:
- Check if video file attribute has changed
- If changed, initialize FFmpeg decoder with new file
- Calculate target frame based on:
- Maya's current time (if useMayaFrameRate is true)
- Frame rate multiplier attribute
- Loop settings
- Request frame from FFmpeg decoder (or cache)
- Apply post-effects if specified
- Update output attributes with frame data
- Mark node as clean
Integration Points
- FFmpeg Integration: Use VideoDecoder class from FFmpeg integration spec
- Viewport 2.0 Integration: Provide frame data to MPxDrawOverride via output attributes
- Caching: Interface with frame caching mechanism (to be specified separately)
- Post-effects: Apply transformations after decoding but before output
Threading Considerations
- Node computation occurs on Maya's main thread
- FFmpeg decoding should happen on background thread
- Use thread-safe mechanisms to transfer decoded frames to main thread
- Cache access must be thread-safe
Error Handling and Validation
- Validate video file path exists and is readable
- Check FFmpeg initialization success
- Handle end-of-file conditions (loop or stop)
- Provide error states via output attributes
- Log errors to Maya's script editor using MGlobal::displayError
Node Initialization and Cleanup
initialize(): Define all attributes and set up attribute affectsconstructor(): Initialize member variablesdestructor(): Clean up FFmpeg decoder and frame datapostConstructor(): Set node to be internally managed if needed
Attribute Affects
Specify which attributes affect which outputs:
- videoFile -> outFrameData, outFrameWidth, outFrameHeight, outFrameFormat, isValid
- frameRate -> outFrameData, outFrameTimestamp
- useMayaFrameRate -> outFrameData, outFrameTimestamp
- currentTime -> outFrameData, outFrameTimestamp
- loop -> outFrameData, outFrameTimestamp
- postEffect* -> outFrameData (if implemented as part of node computation)
Performance Considerations
- Minimize computation in
compute()method - Cache frequently accessed values
- Avoid expensive operations during node evaluation
- Use dirty propagation to minimize unnecessary recomputation
Maya API Specifics
- Use MFnTypedAttribute for message/string attributes
- Use MFnNumericAttribute for double/int/bool attributes
- Use MFnEnumAttribute for format options if needed
- Set appropriate attribute properties (keyable, storable, readable, writable)
- Use MTypeId for unique node identification
- Register node with MFnPlugin::registerNode
Dependencies
- FFmpeg integration component
- Frame caching mechanism
- Maya API 2023 (OpenMaya, OpenMayaFX)
Overview
This document specifies the implementation details for the Maya MPxNode plugin that handles video file input and frame output for the Image Plane Node.
Requirements
- Create a custom MPxNode that accepts video file path as input
- Output video frame data that can be consumed by viewport rendering
- Support attributes for frame rate control and playback rate adjustment
- Integrate with FFmpeg video decoding component
- Provide frame caching interface
- Follow Maya API best practices for node creation
Implementation Details
Node Definition
- Node Name:
imagePlaneVideo - Node ID: Unique ID obtained from Autodesk
- Classification:
filterorimage(to be determined based on Maya's categorization) - Register as a Maya plugin using MFnPlugin
Attributes
Input Attributes
videoFile(message or string) - Path to the video fileframeRate(double) - Playback rate multiplier (1.0 = normal speed)useMayaFrameRate(bool) - Whether to synchronize with Maya's timeline frame ratecurrentTime(double) - Connection to Maya's timeline (for frame calculation)loop(bool) - Whether to loop the video playbackpostEffectCrop(double4) - Crop parameters (x, y, width, height)postEffectResize(double2) - Resize parameters (width, height)postEffectFlip(bool2) - Flip parameters (flipX, flipY)
Output Attributes
outFrameData(message or custom data type) - Pointer to video frame dataoutFrameWidth(int) - Width of current frameoutFrameHeight(int) - Height of current frameoutFrameFormat(int) - Pixel format of current frame (RGB, RGBA, etc.)outFrameTimestamp(double) - Timestamp of current frameisValid(bool) - Whether the current frame data is valid
Core Components
VideoFrameData Class
Custom data class to hold video frame information:
- Pointer to pixel data (RGB/RGBA buffer)
- Width and height
- Pixel format
- Timestamp
- Reference counting for proper cleanup
Node Computation
In the compute() method:
- Check if video file attribute has changed
- If changed, initialize FFmpeg decoder with new file
- Calculate target frame based on:
- Maya's current time (if useMayaFrameRate is true)
- Frame rate multiplier attribute
- Loop settings
- Request frame from FFmpeg decoder (or cache)
- Apply post-effects if specified
- Update output attributes with frame data
- Mark node as clean
Integration Points
- FFmpeg Integration: Use VideoDecoder class from FFmpeg integration spec
- Viewport 2.0 Integration: Provide frame data to MPxDrawOverride via output attributes
- Caching: Interface with frame caching mechanism (to be specified separately)
- Post-effects: Apply transformations after decoding but before output
Threading Considerations
- Node computation occurs on Maya's main thread
- FFmpeg decoding should happen on background thread
- Use thread-safe mechanisms to transfer decoded frames to main thread
- Cache access must be thread-safe
Error Handling and Validation
- Validate video file path exists and is readable
- Check FFmpeg initialization success
- Handle end-of-file conditions (loop or stop)
- Provide error states via output attributes
- Log errors to Maya's script editor using MGlobal::displayError
Node Initialization and Cleanup
initialize(): Define all attributes and set up attribute affectsconstructor(): Initialize member variablesdestructor(): Clean up FFmpeg decoder and frame datapostConstructor(): Set node to be internally managed if needed
Attribute Affects
Specify which attributes affect which outputs:
- videoFile -> outFrameData, outFrameWidth, outFrameHeight, outFrameFormat, isValid
- frameRate -> outFrameData, outFrameTimestamp
- useMayaFrameRate -> outFrameData, outFrameTimestamp
- currentTime -> outFrameData, outFrameTimestamp
- loop -> outFrameData, outFrameTimestamp
- postEffect* -> outFrameData (if implemented as part of node computation)
Performance Considerations
- Minimize computation in
compute()method - Cache frequently accessed values
- Avoid expensive operations during node evaluation
- Use dirty propagation to minimize unnecessary recomputation
Maya API Specifics
- Use MFnTypedAttribute for message/string attributes
- Use MFnNumericAttribute for double/int/bool attributes
- Use MFnEnumAttribute for format options if needed
- Set appropriate attribute properties (keyable, storable, readable, writable)
- Use MTypeId for unique node identification
- Register node with MFnPlugin::registerNode
Dependencies
- FFmpeg integration component
- Frame caching mechanism
- Maya API 2023 (OpenMaya, OpenMayaFX)