3ds Max USD API Reference
Loading...
Searching...
No Matches
MeshConverter Class Reference

#include <MeshConverter.h>

Public Member Functions

pxr::UsdGeomMesh ConvertToUSDMesh (INode *node, const pxr::UsdStagePtr &stage, const pxr::SdfPath &path, const MaxMeshConversionOptions &options, const maxUsd::TimeConfig &time, bool applyOffsetTransform)
 Converts an INode carrying geometry to a UsdGeomMesh prim. More...
 
void ConvertToUSDMesh (maxUsd::MeshFacade &maxMesh, const pxr::UsdStagePtr &stage, const pxr::SdfPath &path, const MaxMeshConversionOptions &options, pxr::UsdGeomMesh &usdMesh, const pxr::UsdTimeCode &timecode, std::map< MtlID, pxr::VtIntArray > &materialIdToFacesMap, bool animated)
 Converts a MNMesh to a UsdGeomMesh prim. More...
 
void ConvertToUSDMesh (maxUsd::MeshFacade &&maxMesh, const pxr::UsdStagePtr &stage, const pxr::SdfPath &path, const MaxMeshConversionOptions &options, pxr::UsdGeomMesh &usdMesh, const pxr::UsdTimeCode &timecode, std::map< MtlID, pxr::VtIntArray > &materialIdToFacesMap, bool animated)
 Converts a MNMesh to a UsdGeomMesh prim. This overload was added to allow passing a temporary MeshFacade as parameter.
 
PolyObject * ConvertToPolyObject (const pxr::UsdGeomMesh &mesh, const PrimvarMappingOptions &options, std::map< int, std::string > &channelNames, MultiMtl **geomSubsetsMaterial, pxr::UsdTimeCode timeCode)
 Converts a UsdGeomMesh to a 3dsMax PolyObject. More...
 
void ConvertToMNMesh (const pxr::UsdGeomMesh &mesh, MNMesh &maxMesh, const PrimvarMappingOptions &options, std::map< int, std::string > &channelNames, MultiMtl **geomsubSetsMaterial=nullptr, pxr::UsdTimeCode timeCode=pxr::UsdTimeCode::Default())
 Converts a UsdGeomMesh to a MNesh. More...
 

Static Public Member Functions

static int GetMaterialIdFromCustomData (const pxr::UsdPrim &usdPrim)
 Get the material id from custom data on the given usd prim. More...
 

Static Protected Member Functions

static void ApplyUSDNormals (const pxr::UsdGeomMesh &mesh, MNMesh &maxMesh, pxr::UsdTimeCode timeCode=pxr::UsdTimeCode::Default())
 Applies the USD normals to the given MNmesh. More...
 
static bool ApplyMaxNormals (maxUsd::MeshFacade &maxMesh, pxr::UsdGeomMesh &mesh, const MaxMeshConversionOptions &options, pxr::UsdTimeCode timeCode=pxr::UsdTimeCode::Default(), bool animated=false)
 Applies a MNmesh's normals to a usd mesh. More...
 
static void ApplyMaxMapChannels (maxUsd::MeshFacade &maxMesh, pxr::UsdGeomMesh &mesh, const MaxMeshConversionOptions &options, pxr::UsdTimeCode timeCode, bool animated)
 Exports map channels to primvars on the target usd mesh. More...
 
static bool ChannelToPrimvar (maxUsd::MeshFacade &maxMesh, int channel, pxr::UsdGeomMesh &mesh, const maxUsd::MappedAttributeBuilder::Config &primvarConfig, const pxr::UsdTimeCode &timeCode, bool animated)
 Exports a channel to a primvar. More...
 
static void ResolveChannelPrimvars (const pxr::UsdGeomMesh &mesh, const PrimvarMappingOptions &options, std::map< int, pxr::UsdGeomPrimvar > &channelPrimvars)
 Resolves the target channels for the primvars of the given mesh. This takes care of incompatibilities and potential conflicts. Following a call to this method, we have a clear idea of what channel will host the data of what primvar for a specific mesh. More...
 
static void ApplyUSDPrimvars (const pxr::UsdGeomMesh &mesh, MNMesh &maxMesh, const PrimvarMappingOptions &options, std::map< int, std::string > &channelNames, const pxr::UsdTimeCode &timeCode)
 Applies USD primvars to the given Max mesh. More...
 
static void ApplyMaxMaterialIDs (Mtl *mtl, const std::map< MtlID, pxr::VtIntArray > &materialIdToFacesMap, const pxr::UsdPrim &usdPrim)
 Create USD subsets on the given usdMesh for the materialID information provided in materialIdToFacesMap. More...
 
static void ApplyUSDMaterialIDs (const pxr::UsdPrim &usdPrim, MNMesh &maxMesh, const pxr::UsdTimeCode &timeCode, MultiMtl **geomSubsetMaterial=nullptr)
 Apply material id on the provide MNMesh from the provide usdMesh prim subsets. More...
 
static void ApplyMaxVertCreases (maxUsd::MeshFacade &maxMesh, pxr::UsdGeomMesh &usdMesh, pxr::UsdTimeCode timeCode=pxr::UsdTimeCode::Default())
 Applies the MNMesh vert creases to the given USD mesh. More...
 
static void ApplyUSDVertCreases (const pxr::UsdGeomMesh &usdMesh, MNMesh &maxMesh, pxr::UsdTimeCode timeCode=pxr::UsdTimeCode::Default())
 Applies the USD vert creases to the given MNmesh. More...
 
static void ApplyMaxEdgeCreases (maxUsd::MeshFacade &maxMesh, pxr::UsdGeomMesh &usdMesh, pxr::UsdTimeCode timeCode=pxr::UsdTimeCode::Default())
 Applies the MNMesh edge creases to the given USD mesh. More...
 
static void ApplyUSDEdgeCreases (const pxr::UsdGeomMesh &usdMesh, MNMesh &maxMesh, pxr::UsdTimeCode timeCode=pxr::UsdTimeCode::Default())
 Applies the USD edge creases to the given MNmesh. More...
 
static void ApplyMatIdToMesh (const pxr::UsdGeomSubset &subset, MNMesh &maxMesh, int matId, const pxr::UsdTimeCode &timeCode)
 Applies the given matId on the given mesh for the face found in the given geom Subset. More...
 

Detailed Description

MeshConverter Utility Class

Example of use:

spherePrim = maxUsd.MeshConverter.ConvertToUSDMesh(nodeHandle, stage, prim.GetPath(), opts, applyOffset)
print("Write a Sphere as a USD Mesh prim!")

Member Function Documentation

◆ ApplyMatIdToMesh()

static void MeshConverter::ApplyMatIdToMesh ( const pxr::UsdGeomSubset &  subset,
MNMesh &  maxMesh,
int  matId,
const pxr::UsdTimeCode &  timeCode 
)
staticprotected

Applies the given matId on the given mesh for the face found in the given geom Subset.

Parameters
subsetThe USD geom subset in which to find the face indices
maxMeshThe max mesh where to apply the matId
matIdThe matId to apply to the faces found in the geom subset
timeCodeThe time code at which to get the faces.

◆ ApplyMaxEdgeCreases()

static void MeshConverter::ApplyMaxEdgeCreases ( maxUsd::MeshFacade &  maxMesh,
pxr::UsdGeomMesh &  usdMesh,
pxr::UsdTimeCode  timeCode = pxr::UsdTimeCode::Default() 
)
staticprotected

Applies the MNMesh edge creases to the given USD mesh.

Parameters
usdMeshThe USD mesh where to apply the edge creases.
maxMeshThe max mesh from which to read the edge creases.
timeCodeThe time code at which to get the edge creases.

◆ ApplyMaxMapChannels()

static void MeshConverter::ApplyMaxMapChannels ( maxUsd::MeshFacade &  maxMesh,
pxr::UsdGeomMesh &  mesh,
const MaxMeshConversionOptions options,
pxr::UsdTimeCode  timeCode,
bool  animated 
)
staticprotected

Exports map channels to primvars on the target usd mesh.

Parameters
maxMeshThe Max mesh where to read the channels.
meshThe target USD mesh.
optionsMesh conversion options.
timeCodeThe timecode where to write the primvars.
animatedWhether or not the conversion of the map channel is part of an animation.
Returns

◆ ApplyMaxMaterialIDs()

static void MeshConverter::ApplyMaxMaterialIDs ( Mtl *  mtl,
const std::map< MtlID, pxr::VtIntArray > &  materialIdToFacesMap,
const pxr::UsdPrim &  usdPrim 
)
staticprotected

Create USD subsets on the given usdMesh for the materialID information provided in materialIdToFacesMap.

Parameters
mtlThe 3ds Max material associated to the mesh.
materialIdToFacesMapA map of faces by material id.
usdPrimThe usd usdPrim on which to add the material binding subsets.

◆ ApplyMaxNormals()

static bool MeshConverter::ApplyMaxNormals ( maxUsd::MeshFacade &  maxMesh,
pxr::UsdGeomMesh &  mesh,
const MaxMeshConversionOptions options,
pxr::UsdTimeCode  timeCode = pxr::UsdTimeCode::Default(),
bool  animated = false 
)
staticprotected

Applies a MNmesh's normals to a usd mesh.

Parameters
maxMeshThe max mesh from which to fetch the normals.
meshThe usd mesh where to apply the normals.
optionsMesh conversion options.
timeCodeThe timecode at which to apply the normals.
animatedWhether or not the normal conversion is part of an animation.
Returns

◆ ApplyMaxVertCreases()

static void MeshConverter::ApplyMaxVertCreases ( maxUsd::MeshFacade &  maxMesh,
pxr::UsdGeomMesh &  usdMesh,
pxr::UsdTimeCode  timeCode = pxr::UsdTimeCode::Default() 
)
staticprotected

Applies the MNMesh vert creases to the given USD mesh.

Parameters
usdMeshThe USD mesh where to apply the vert creases.
maxMeshThe max mesh from which to read the vert creases.
timeCodeThe time code at which to get the vert creases.

◆ ApplyUSDEdgeCreases()

static void MeshConverter::ApplyUSDEdgeCreases ( const pxr::UsdGeomMesh &  usdMesh,
MNMesh &  maxMesh,
pxr::UsdTimeCode  timeCode = pxr::UsdTimeCode::Default() 
)
staticprotected

Applies the USD edge creases to the given MNmesh.

Parameters
usdMeshThe USD mesh from which to read the edge creases.
maxMeshThe max mesh where to apply the edge creases.
timeCodeThe time code at which to get the edge creases.

◆ ApplyUSDMaterialIDs()

static void MeshConverter::ApplyUSDMaterialIDs ( const pxr::UsdPrim &  usdPrim,
MNMesh &  maxMesh,
const pxr::UsdTimeCode &  timeCode,
MultiMtl **  geomSubsetMaterial = nullptr 
)
staticprotected

Apply material id on the provide MNMesh from the provide usdMesh prim subsets.

Parameters
usdPrimUsdPrim prim from which to extract the material id subsets
maxMeshMNMesh on which to add the material id
timeCodeThe USD time code at which to fetch the data.
geomSubsetMaterialOptional, a multimaterial to be filled with geomSubset information if any in case of multiple materials bound to the mesh.

◆ ApplyUSDNormals()

static void MeshConverter::ApplyUSDNormals ( const pxr::UsdGeomMesh &  mesh,
MNMesh &  maxMesh,
pxr::UsdTimeCode  timeCode = pxr::UsdTimeCode::Default() 
)
staticprotected

Applies the USD normals to the given MNmesh.

Parameters
meshThe USD mesh from which to read the normals.
maxMeshThe max mesh where to apply the normals.
timeCodeThe time code at which to get the normals.

◆ ApplyUSDPrimvars()

static void MeshConverter::ApplyUSDPrimvars ( const pxr::UsdGeomMesh &  mesh,
MNMesh &  maxMesh,
const PrimvarMappingOptions options,
std::map< int, std::string > &  channelNames,
const pxr::UsdTimeCode &  timeCode 
)
staticprotected

Applies USD primvars to the given Max mesh.

Parameters
meshThe usd mesh hosting the primvars to apply.
maxMeshThe target max mesh.
optionsThe primvar / channel mapping options.
channelNamesFilled map of names associated with each imported channels. Typically from primvar names.
timeCodeThe USD time code at which to fetch the data.

◆ ApplyUSDVertCreases()

static void MeshConverter::ApplyUSDVertCreases ( const pxr::UsdGeomMesh &  usdMesh,
MNMesh &  maxMesh,
pxr::UsdTimeCode  timeCode = pxr::UsdTimeCode::Default() 
)
staticprotected

Applies the USD vert creases to the given MNmesh.

Parameters
usdMeshThe USD mesh from which to read the vert creases.
maxMeshThe max mesh where to apply the vert creases.
timeCodeThe time code at which to get the vert creases.

◆ ChannelToPrimvar()

static bool MeshConverter::ChannelToPrimvar ( maxUsd::MeshFacade &  maxMesh,
int  channel,
pxr::UsdGeomMesh &  mesh,
const maxUsd::MappedAttributeBuilder::Config &  primvarConfig,
const pxr::UsdTimeCode &  timeCode,
bool  animated 
)
staticprotected

Exports a channel to a primvar.

Parameters
maxMeshThe max mesh.
channelThe channel to export to a primvar.
meshThe usd mesh where to create the primvar.
primvarConfigThe configuration for the primvar.
timeCodeThe timecode at which to output the data.
animatedWhether or not the map channel conversion is part of an animation.
Returns
True if successful, false otherwise.

◆ ConvertToMNMesh()

void MeshConverter::ConvertToMNMesh ( const pxr::UsdGeomMesh &  mesh,
MNMesh &  maxMesh,
const PrimvarMappingOptions options,
std::map< int, std::string > &  channelNames,
MultiMtl **  geomsubSetsMaterial = nullptr,
pxr::UsdTimeCode  timeCode = pxr::UsdTimeCode::Default() 
)

Converts a UsdGeomMesh to a MNesh.

Parameters
meshThe USD mesh to convert.
maxMeshThe output MNMesh.
optionsPrimvar mapping options.
channelNamesThe map channel names, generated from converted primvars.
geomsubSetsMaterialGenerated multi-material, representing any found UsdGeomSubsets.
timeCodeThe USD timeCode at which the conversion happens.

◆ ConvertToPolyObject()

PolyObject * MeshConverter::ConvertToPolyObject ( const pxr::UsdGeomMesh &  mesh,
const PrimvarMappingOptions options,
std::map< int, std::string > &  channelNames,
MultiMtl **  geomSubsetsMaterial,
pxr::UsdTimeCode  timeCode 
)

Converts a UsdGeomMesh to a 3dsMax PolyObject.

Parameters
meshThe USD mesh to be converted.
optionsPrimvar mapping options.
channelNamesThe map channel names, generated from converted primvars.
geomSubsetsMaterialGenerated multi-material, representing any found UsdGeomSubsets.
timeCodeThe USD timeCode at which the conversion happens.
Returns
The created PolyObject

◆ ConvertToUSDMesh() [1/2]

pxr::UsdGeomMesh MeshConverter::ConvertToUSDMesh ( INode *  node,
const pxr::UsdStagePtr &  stage,
const pxr::SdfPath &  path,
const MaxMeshConversionOptions options,
const maxUsd::TimeConfig &  time,
bool  applyOffsetTransform 
)

Converts an INode carrying geometry to a UsdGeomMesh prim.

Parameters
nodeThe node to convert.
stageThe stage in which the UsdGeomMesh will be created.
pathThe path to the output UsdGeomMesh.
optionsMesh conversion options.
timeThe time configuration for the conversion (which frames to export, at what sample rate).
applyOffsetTransformWhether or not to apply the object offset transform onto the mesh.
Returns
The converted UsdGeomMesh.

◆ ConvertToUSDMesh() [2/2]

void MeshConverter::ConvertToUSDMesh ( maxUsd::MeshFacade &  maxMesh,
const pxr::UsdStagePtr &  stage,
const pxr::SdfPath &  path,
const MaxMeshConversionOptions options,
pxr::UsdGeomMesh &  usdMesh,
const pxr::UsdTimeCode &  timecode,
std::map< MtlID, pxr::VtIntArray > &  materialIdToFacesMap,
bool  animated 
)

Converts a MNMesh to a UsdGeomMesh prim.

Parameters
maxMeshThe mesh to convert.
stageThe stage in which the UsdGeomMesh will be created.
pathThe path to the output UsdGeomMesh.
optionsMesh conversion options.
usdMeshThe output UsdGeomMesh.
timecodeThe USD timeCode at which the conversion happens.
materialIdToFacesMapMaterial mapping information.
animatedWhether or not the conversion is part of an animation.

◆ GetMaterialIdFromCustomData()

static int MeshConverter::GetMaterialIdFromCustomData ( const pxr::UsdPrim &  usdPrim)
static

Get the material id from custom data on the given usd prim.

Parameters
usdPrimThe USD prim that contain the matId custom data.
Returns
the matId contained in the custom data of the prim. Return -1 if there is no custom data or if the data is invalid.

◆ ResolveChannelPrimvars()

static void MeshConverter::ResolveChannelPrimvars ( const pxr::UsdGeomMesh &  mesh,
const PrimvarMappingOptions options,
std::map< int, pxr::UsdGeomPrimvar > &  channelPrimvars 
)
staticprotected

Resolves the target channels for the primvars of the given mesh. This takes care of incompatibilities and potential conflicts. Following a call to this method, we have a clear idea of what channel will host the data of what primvar for a specific mesh.

Parameters
meshThe usd mesh, potentially hosting primvars that will need to be imported.
optionsThe primvar to channel mapping options.
channelPrimvarsThe resolved association, max channel -> primvar.
Returns
The maximum channel used.

The documentation for this class was generated from the following file: