17#include "MaxUsd/MaxUSDAPI.h"
20#include <pxr/usd/usd/common.h>
21#include <pxr/usd/usdGeom/primvar.h>
22#include <pxr/usd/usdGeom/mesh.h>
23#include <pxr/usd/usd/stageCache.h>
24#include <pxr/usd/usdUtils/stageCache.h>
27#if _MSVC_LANG > 201402L
29namespace fs = std::filesystem;
31#include <experimental/filesystem>
32namespace fs = std::experimental::filesystem;
39namespace MAXUSD_NS_DEF {
50T fetchOrCreatePrim(
const pxr::UsdStagePtr stage,
const pxr::SdfPath& primPath, pxr::TfToken token)
53 T prim = T(stage->GetPrimAtPath(primPath));
58 pxr::SdfChangeBlock changeBlock;
59 const auto prim_spec = pxr::SdfCreatePrimInLayer(stage->GetRootLayer(), primPath);
60 prim_spec->SetSpecifier(pxr::SdfSpecifierDef);
61 prim_spec->SetTypeName(token);
63 prim = T(stage->GetPrimAtPath(primPath));
77bool wsmRequiresTransformToLocalSpace(INode* node,
const TimeValue& time);
85Matrix3 getMaxObjectOffsetTransform(INode* node);
95void applyObjectOffsetTransform(INode* node, pxr::UsdGeomXformable& xformable,
const TimeValue& time);
103MaxUSDAPI
bool isValidChannel(
int channel);
111MaxUSDAPI
bool getValidIdentifier(
const std::wstring& identifier, std::string& validIdentifier);
118MaxUSDAPI
size_t getTypeDimension(
const pxr::SdfValueTypeName& type);
131MaxUSDAPI
bool validateMappedDataForMesh(
size_t valueCount,
const pxr::VtIntArray indices,
const MNMesh& maxMesh,
132 const pxr::TfToken& interpolation,
bool isIndexed);
142MaxUSDAPI
bool isValidAbsolutePath(
const fs::path& path);
154MaxUSDAPI
bool findInstanceableNodes(
155 INode* node, INodeTab& instancesNode,
const std::unordered_set<INode*>& eligibleNodes);
166MaxUSDAPI Object* getFirstDerivedObjectWithModifier(INode* node);
176 MaxUSDAPI std::string getName(
const std::string& name);
177 MaxUSDAPI
void reset();
180 std::unordered_set<std::string> existingNames;
181 std::string getNextName(
const std::string& name);
199 auto& cache = pxr::UsdUtilsStageCache::Get();
200 if (!cache.Contains(cache.GetId(stage)))
202 id = cache.Insert(stage);
212 pxr::UsdUtilsStageCache::Get().Erase(
id);
217 pxr::UsdStageCache::Id id;
226MaxUSDAPI pxr::UsdTimeCode GetUsdTimeCodeFromMaxFrame(
const pxr::UsdStageWeakPtr& stage,
const double maxFrame);
234MaxUSDAPI
double GetMaxFrameFromUsdTimeCode(
const pxr::UsdStageWeakPtr& stage,
const pxr::UsdTimeCode usdTimeCode);
243MaxUSDAPI pxr::UsdTimeCode GetTimeCode(
const pxr::UsdStageWeakPtr& stage,
const TimeValue& timeValue);
255MaxUSDAPI pxr::UsdTimeCode GetOffsetTimeCode(
const pxr::UsdStageWeakPtr& stage,
const TimeValue& timeValue,
256 const double customAnimStartFrame,
const double customAnimationLength = 0);
263MaxUSDAPI
double GetUsdToMaxScaleFactor(
const pxr::UsdStageWeakPtr& stage);
271MaxUSDAPI pxr::GfMatrix4d GetStageAxisAndUnitRootTransform(pxr::UsdStageWeakPtr stage);
279MaxUSDAPI
short FindParamId(IParamBlock2* pb2,
const wchar_t* name);
286MaxUSDAPI std::string maxStringToUSDString(
const wchar_t* utf16EncodedWideString);
293MaxUSDAPI std::string usdStringToLower(std::string utf8EncodedString);
300MaxUSDAPI WStr usdStringToMaxString(
const std::string& utf8EncodedString);
306MaxUSDAPI
bool hasUnicodeCharacter(
const std::string& str);
310 double startFrame{ 0.0 };
311 double endFrame{ 0.0 };
312 double samplesPerFrame{ 1.0 };
314 bool IsAnimated()
const
316 return startFrame != endFrame;
330MaxUSDAPI
void convertFrames(
331 INode* node, std::function<
void(Object*,
const TimeValue&,
const pxr::UsdTimeCode&)> convertFrame,
333 std::function<Interval(Object*,
const TimeValue&)> objectValidityOverride = [](Object*,
const TimeValue&) {
346MaxUSDAPI std::pair<pxr::VtArray<TimeValue>, pxr::VtArray<pxr::UsdTimeCode>> getFramesFromValidityInterval(
348 const TimeConfig& usdTimeConfig
356MaxUSDAPI
bool isBoneObject(Object*
object);
363MaxUSDAPI
bool hasMorpherModifier(INode* node);
370MaxUSDAPI TimeValue getTicksFromFrame(
double frame);
377MaxUSDAPI std::string getNonLocalizedClassName(ClassDesc* classDesc);
386MaxUSDAPI pxr::SdfPath VerifyOrMakeSkelRoot(
const pxr::UsdStagePtr& usdStage,
const pxr::SdfPath& path,
const bool autoGenerate =
true);
399T VerifyOrMakePrimOfType(
const pxr::UsdStagePtr& usdStage,
const pxr::SdfPath& basePath,
400 const pxr::TfToken& primName)
402 UniqueNameGenerator subsetNameGenerator;
403 std::string currentPrimString = subsetNameGenerator.getName(primName.GetString());
404 pxr::SdfPath currentPath = basePath.AppendElementString(currentPrimString);
406 pxr::UsdPrim prim = usdStage->GetPrimAtPath(currentPath);
407 while(prim && !prim.IsA<T>())
409 currentPrimString = subsetNameGenerator.getName(currentPrimString);
410 currentPath = basePath.AppendElementString(currentPrimString);
411 prim = usdStage->GetPrimAtPath(currentPath);
417 return T::Define(usdStage, currentPath);
430pxr::UsdPrim FindRootmostXformOrSkelRoot(pxr::UsdStagePtr usdStage,
const pxr::SdfPath& path);
438bool SetPrimHidden(IParamBlock2* usdCustomAttributePb, pxr::UsdPrim& translatedPrim);
446bool SetPrimKind(IParamBlock2* usdCustomAttributePb, pxr::UsdPrim& translatedPrim);
454bool SetPrimPurpose(IParamBlock2* usdCustomAttributePb, pxr::UsdPrim& translatedPrim);
462std::vector<ISkin*> getMaxSkinModifiers(INode* node,
bool enabledOnly =
true);
470std::vector<Modifier*> getAllModifiers(INode* node,
bool enabledOnly =
true);
480typedef std::vector<maxUsd::PrimDef> PrimDefVector;
481typedef std::shared_ptr<PrimDefVector> PrimDefVectorPtr;
494enum class XformSplitRequirement
509enum class MaterialAssignRequirement
521enum class InstancingRequirement
536MaxUSDAPI pxr::GfMatrix4d getNodeTransform(INode* sourceNode, TimeValue time,
bool YUp);
546 ReferenceTarget* node =
nullptr;
547 bool hasDependentSkin =
false;
551 int proc(ReferenceMaker *rmaker)
override;
Callback helper class for enumerating Max node dependents with skin modifiers. This class is a callba...
Definition: TranslationUtils.h:544
RAII Scope guard for adding and remove a stage from the global stage cache.
Definition: TranslationUtils.h:188
StageCacheScopeGuard(const pxr::UsdStageRefPtr &stage)
Constructor, adds a stage to the global stage cache.
Definition: TranslationUtils.h:194
~StageCacheScopeGuard()
Destructor, removes the stage from the global stage cache.
Definition: TranslationUtils.h:208
Utility class to ensure every name is unique. To use, create an instance and call the getName functio...
Definition: TranslationUtils.h:174
Simple struct to define a Prim, from its path and type.
Definition: TranslationUtils.h:476
Definition: TranslationUtils.h:309