3ds Max USD API Reference
Loading...
Searching...
No Matches
MeshConverter.h
1//**************************************************************************/
2// Copyright (c) 2022 Autodesk, Inc.
3// All rights reserved.
4//
5// Use of this software is subject to the terms of the Autodesk license
6// agreement provided at the time of installation or download, or which
7// otherwise accompanies this software in either electronic or hard copy form.
8//**************************************************************************/
9#pragma once
10
11#include "MaxUsd/MaxUSDAPI.h"
12#include <polyobj.h>
13#include <pxr/usd/sdf/path.h>
14#include <pxr/usd/usdGeom/mesh.h>
15#include <pxr/usd/usdGeom/subset.h>
16
17#include <stdmat.h>
18
19#include "MaxUsd/MappedAttributeBuilder.h"
20#include "MaxMeshConversionOptions.h"
21#include "PrimvarMappingOptions.h"
22#include "MaxUsd/Utilities/TranslationUtils.h"
23
24#include "MeshFacade.h"
25
33class MaxUSDAPI MeshConverter
34{
35public:
46 pxr::UsdGeomMesh ConvertToUSDMesh(INode* node, const pxr::UsdStagePtr& stage, const pxr::SdfPath& path, const MaxMeshConversionOptions& options, const maxUsd::TimeConfig& time, bool applyOffsetTransform);
47
59 void ConvertToUSDMesh(maxUsd::MeshFacade& maxMesh, const pxr::UsdStagePtr& stage, const pxr::SdfPath& path,
60 const MaxMeshConversionOptions& options, pxr::UsdGeomMesh& usdMesh, const pxr::UsdTimeCode& timecode,
61 std::map<MtlID, pxr::VtIntArray>& materialIdToFacesMap, bool animated);
65 void ConvertToUSDMesh(maxUsd::MeshFacade&& maxMesh, const pxr::UsdStagePtr& stage, const pxr::SdfPath& path,
66 const MaxMeshConversionOptions& options, pxr::UsdGeomMesh& usdMesh, const pxr::UsdTimeCode& timecode,
67 std::map<MtlID, pxr::VtIntArray>& materialIdToFacesMap, bool animated)
68 {
69 ConvertToUSDMesh(maxMesh, stage, path, options, usdMesh, timecode, materialIdToFacesMap, animated);
70 }
71
81 PolyObject* ConvertToPolyObject(const pxr::UsdGeomMesh& mesh, const PrimvarMappingOptions& options, std::map<int, std::string>& channelNames, MultiMtl** geomSubsetsMaterial, pxr::UsdTimeCode
82 timeCode);
83
93 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());
94
101 static int GetMaterialIdFromCustomData(const pxr::UsdPrim& usdPrim);
102
103protected:
104
111 static void ApplyUSDNormals(const pxr::UsdGeomMesh& mesh, MNMesh& maxMesh, pxr::UsdTimeCode timeCode = pxr::UsdTimeCode::Default());
112
122 static bool ApplyMaxNormals(maxUsd::MeshFacade& maxMesh, pxr::UsdGeomMesh& mesh, const MaxMeshConversionOptions& options, pxr::UsdTimeCode timeCode = pxr::UsdTimeCode::Default(), bool animated = false);
123
133 static void ApplyMaxMapChannels(maxUsd::MeshFacade& maxMesh, pxr::UsdGeomMesh& mesh, const MaxMeshConversionOptions& options,
134 pxr::UsdTimeCode timeCode, bool animated);
135
146 static bool ChannelToPrimvar(maxUsd::MeshFacade& maxMesh, int channel, pxr::UsdGeomMesh& mesh,
147 const maxUsd::MappedAttributeBuilder::Config& primvarConfig, const pxr::UsdTimeCode& timeCode, bool animated);
148
158 static void ResolveChannelPrimvars(const pxr::UsdGeomMesh& mesh, const PrimvarMappingOptions& options, std::map<int, pxr::UsdGeomPrimvar>& channelPrimvars);
159
168 static void ApplyUSDPrimvars(const pxr::UsdGeomMesh& mesh, MNMesh& maxMesh, const PrimvarMappingOptions& options, std::map<int, std::string>& channelNames, const pxr::UsdTimeCode& timeCode);
169
176 static void ApplyMaxMaterialIDs(Mtl* mtl, const std::map<MtlID, pxr::VtIntArray>& materialIdToFacesMap, const pxr::UsdPrim& usdPrim);
177
186 static void ApplyUSDMaterialIDs(const pxr::UsdPrim& usdPrim, MNMesh& maxMesh, const pxr::UsdTimeCode& timeCode, MultiMtl** geomSubsetMaterial = nullptr);
187
194 static void ApplyMaxVertCreases(maxUsd::MeshFacade& maxMesh, pxr::UsdGeomMesh& usdMesh, pxr::UsdTimeCode timeCode = pxr::UsdTimeCode::Default());
195
202 static void ApplyUSDVertCreases(const pxr::UsdGeomMesh& usdMesh, MNMesh& maxMesh, pxr::UsdTimeCode timeCode = pxr::UsdTimeCode::Default());
203
210 static void ApplyMaxEdgeCreases(maxUsd::MeshFacade& maxMesh, pxr::UsdGeomMesh& usdMesh, pxr::UsdTimeCode timeCode = pxr::UsdTimeCode::Default());
211
218 static void ApplyUSDEdgeCreases(const pxr::UsdGeomMesh& usdMesh, MNMesh& maxMesh, pxr::UsdTimeCode timeCode = pxr::UsdTimeCode::Default());
219
227 static void ApplyMatIdToMesh(const pxr::UsdGeomSubset& subset, MNMesh& maxMesh, int matId, const pxr::UsdTimeCode& timeCode);
228
229
230};
Definition: MaxMeshConversionOptions.h:13
Definition: MeshConverter.h:34
static int GetMaterialIdFromCustomData(const pxr::UsdPrim &usdPrim)
Get the material id from custom data on the given usd prim.
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.
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.
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.
static void ApplyUSDVertCreases(const pxr::UsdGeomMesh &usdMesh, MNMesh &maxMesh, pxr::UsdTimeCode timeCode=pxr::UsdTimeCode::Default())
Applies the USD vert creases to the given MNmesh.
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.
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.
static void ApplyUSDEdgeCreases(const pxr::UsdGeomMesh &usdMesh, MNMesh &maxMesh, pxr::UsdTimeCode timeCode=pxr::UsdTimeCode::Default())
Applies the USD edge creases to the given MNmesh.
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.
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.
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 MeshFac...
Definition: MeshConverter.h:65
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.
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.
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.
static void ApplyUSDNormals(const pxr::UsdGeomMesh &mesh, MNMesh &maxMesh, pxr::UsdTimeCode timeCode=pxr::UsdTimeCode::Default())
Applies the USD normals to the given MNmesh.
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 materialIdToFacesM...
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...
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.
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.
This class exposes methods for getting and setting primvar/channel mapping options.
Definition: PrimvarMappingOptions.h:19