This class is used for describing the mesh stream requirements of a material.
By default, 3ds Max automatically generates MaterialRequiredStreams for all materials. However if a material plugin wants to provide customized hardware shaders, it must provide a MaterialRequiredStreams as well. Other plugins like the object plugin, will provide render items that suffice the requirement.
We create this class for two reasons:
First, a mesh contains a lot of channels however a material may be interested in a few channels of that mesh (eg. Position and the first texture coordinate channel). Converting a mesh channel to vertex buffer is a time and memory consuming job, therefore the material provide a MaterialRequiredStreams to indicate which channel is used by the material to minimize the number of vertex buffers we created.
Second, after we converted mesh channels to vertex buffers, it is necessary to indicate details like how is the vertex buffers are organized in hardware streams and the usage index of the channels. The usage index is used by hardware shaders of the material to differentiate the channels with the same type and usage. For example, if a material wants uv map channel 99 be treated as TEX0 in hardware shaders and uv map channel 32 may be treated as TEX1. Then the following code may be necessary:
MaterialRequiredStreams requirement; // add position, normal and other streams. ... MaterialRequiredStreamElement texCoord99; texCoord99.SetType(EVertexType_Float3); texCoord99.SetUsage(EVertexUsage_Texcoord); texCoord99.SetChannelID(99); // set the max channel id texCoord99.SetUsageIndex(0); requirement.AddStream(texCoord99); // uv channel 99 is TEX0 in shaders MaterialRequiredStreamElement texCoord32; texCoord32.SetType(EVertexType_Float3); texCoord32.SetUsage(EVertexUsage_Texcoord); texCoord32.SetChannelID(32); // set the max channel id texCoord99.SetUsageIndex(1); requirement.AddStream(texCoord32); // uv channel 32 is TEX1 in shaders
#include <MaterialRequiredStreams.h>
Public Member Functions |
|
DataBridgeAPI | MaterialRequiredStreams () |
DataBridgeAPI | MaterialRequiredStreams (const MaterialRequiredStreams &from) |
DataBridgeAPI MaterialRequiredStreams & |
operator= (const MaterialRequiredStreams &from) |
DataBridgeAPI | ~MaterialRequiredStreams () |
DataBridgeAPI void | Clear () |
Remove all streams from this requirement.
|
|
DataBridgeAPI size_t | AddStream (const MaterialRequiredStreamElement &streamElement) |
Add a stream to this requirement. |
|
DataBridgeAPI size_t | FindStream (const MaterialRequiredStreamElement &streamElement) const |
Find the index of a stream element. |
|
DataBridgeAPI void | RemoveStream (size_t index) |
Remove the stream element specified by the
given index from this requirement. |
|
DataBridgeAPI size_t | GetNumberOfStreams () const |
Get the number of streams of the
requirement. |
|
DataBridgeAPI
const MaterialRequiredStreamElement & |
GetStreamElement (size_t i) const |
Get the field of the i-th stream. |
|
DataBridgeAPI int | Compare (const MaterialRequiredStreams &rhs) const |
Compare two
MaterialRequiredStreams. |
|
DataBridgeAPI unsigned long | GetFlags () const |
Get extra flags of this requirement.
|
|
DataBridgeAPI void | SetFlags (unsigned long flags) |
Set extra flags of this requirement.
|
|
bool | operator== (const MaterialRequiredStreams &rhs) const |
bool | operator!= (const MaterialRequiredStreams &rhs) const |
bool | operator< (const MaterialRequiredStreams &rhs) const |
bool | operator<= (const MaterialRequiredStreams &rhs) const |
bool | operator> (const MaterialRequiredStreams &rhs) const |
bool | operator>= (const MaterialRequiredStreams &rhs) const |
DataBridgeAPI MaterialRequiredStreams | ( | ) |
DataBridgeAPI MaterialRequiredStreams | ( | const MaterialRequiredStreams & | from | ) |
DataBridgeAPI ~MaterialRequiredStreams | ( | ) |
DataBridgeAPI MaterialRequiredStreams& operator= | ( | const MaterialRequiredStreams & | from | ) |
DataBridgeAPI void Clear | ( | ) |
Remove all streams from this requirement.
DataBridgeAPI size_t AddStream | ( | const MaterialRequiredStreamElement & | streamElement | ) |
Add a stream to this requirement.
Simply return existing stream index if the stream to be added is already in the array.
streamElement | the stream element to add. |
DataBridgeAPI size_t FindStream | ( | const MaterialRequiredStreamElement & | streamElement | ) | const |
Find the index of a stream element.
streamElement | the element to find |
DataBridgeAPI void RemoveStream | ( | size_t | index | ) |
Remove the stream element specified by the given index from this requirement.
index | the index to the stream element. |
DataBridgeAPI size_t GetNumberOfStreams | ( | ) | const |
Get the number of streams of the requirement.
DataBridgeAPI const MaterialRequiredStreamElement& GetStreamElement | ( | size_t | i | ) | const |
Get the field of the i-th stream.
i | the index to the stream. |
DataBridgeAPI int Compare | ( | const MaterialRequiredStreams & | rhs | ) | const |
Compare two MaterialRequiredStreams.
rhs | the "right-hand-side" MaterialRequiredStreams of the compare function. |
DataBridgeAPI unsigned long GetFlags | ( | ) | const |
Get extra flags of this requirement.
The extra flag should be a combination of MaterialRequirementFlags.
DataBridgeAPI void SetFlags | ( | unsigned long | flags | ) |
Set extra flags of this requirement.
The extra flag should be a combination of MaterialRequirementFlags.
flags | extra flags. |
bool operator== | ( | const MaterialRequiredStreams & | rhs | ) | const [inline] |
{ return Compare(rhs) == 0; }
bool operator!= | ( | const MaterialRequiredStreams & | rhs | ) | const [inline] |
{ return Compare(rhs) != 0; }
bool operator< | ( | const MaterialRequiredStreams & | rhs | ) | const [inline] |
{ return Compare(rhs) < 0; }
bool operator<= | ( | const MaterialRequiredStreams & | rhs | ) | const [inline] |
{ return Compare(rhs) <= 0; }
bool operator> | ( | const MaterialRequiredStreams & | rhs | ) | const [inline] |
{ return Compare(rhs) > 0; }
bool operator>= | ( | const MaterialRequiredStreams & | rhs | ) | const [inline] |
{ return Compare(rhs) >= 0; }