3ds Max USD API Reference
Loading...
Searching...
No Matches
ExportChaserRegistry.h
1#pragma once
2//**************************************************************************/
3// Copyright (c) 2022 Autodesk, Inc.
4// All rights reserved.
5//
6// Use of this software is subject to the terms of the Autodesk license
7// agreement provided at the time of installation or download, or which
8// otherwise accompanies this software in either electronic or hard copy form.
9//**************************************************************************/
10#include <MaxUsd/MaxUSDAPI.h>
11#include <MaxUsd/Chaser/ExportChaser.h>
12#include <MaxUsd/Builders/USDSceneBuilderOptions.h>
13
14#include <pxr/base/tf/declarePtrs.h>
15#include <pxr/base/tf/registryManager.h>
16#include <pxr/base/tf/singleton.h>
17#include <pxr/pxr.h>
18
19#include <functional>
20
21PXR_NAMESPACE_OPEN_SCOPE
22
23TF_DECLARE_WEAK_PTRS(MaxUsdExportChaserRegistry);
24
34class MaxUsdExportChaserRegistry : public TfWeakBase
35{
36public:
44 {
45 public:
46 typedef std::map<std::string, INode*> PrimsToNodesMap;
47
48 MaxUSDAPI FactoryContext(
49 const UsdStagePtr& stage,
50 const PrimsToNodesMap& primsToNodes,
51 const USDSceneBuilderOptions& jobArgs,
52 const fs::path& filename);
53
58 MaxUSDAPI UsdStagePtr GetStage() const;
59
64 MaxUSDAPI const PrimsToNodesMap& GetPrimsToNodesMap() const;
65
70 MaxUSDAPI const USDSceneBuilderOptions& GetJobArgs() const;
71
76 MaxUSDAPI const fs::path& GetFilename() const;
77
78 private:
79 UsdStagePtr stage;
80 const PrimsToNodesMap& primsToNodes;
81 const USDSceneBuilderOptions& jobArgs;
82 const fs::path& filename;
83 };
84
85 typedef std::function<MaxUsdExportChaser*(const FactoryContext&)> FactoryFn;
86
89 {
90 TfToken chaser;
91 TfToken niceName;
92 TfToken description;
93 FactoryFn chaserFactory;
94
95 ChaserInfo() = default;
96
98 const TfToken& c,
99 const TfToken& nn,
100 const TfToken& cdsc,
101 FactoryFn cf)
102 : chaser(c)
103 , niceName(nn)
104 , description(cdsc)
105 , chaserFactory(cf)
106 {
107 }
108 };
109
111 static const ChaserInfo& GetChaserInfo(const TfToken& chaser)
112 {
113 return GetInstance()._GetChaserInfo(chaser);
114 }
115
124 MaxUSDAPI
126 const std::string& chaser,
127 const std::string& niceName,
128 const std::string& description,
129 FactoryFn fn,
130 bool fromPython = false);
131
133 MaxUSDAPI
134 static MaxUsdExportChaserRefPtr Create(const std::string& name, const FactoryContext& context)
135 {
136 return GetInstance()._Create(name, context);
137 }
138
140 MaxUSDAPI
141 static TfTokenVector GetAllRegisteredChasers()
142 {
143 return GetInstance()._GetAllRegisteredChasers();
144 }
145
146 MaxUSDAPI
147 static MaxUsdExportChaserRegistry& GetInstance();
148
149private:
150 MaxUSDAPI TfTokenVector _GetAllRegisteredChasers() const;
151 MaxUSDAPI const ChaserInfo& _GetChaserInfo(const TfToken&) const;
152 MaxUSDAPI MaxUsdExportChaserRefPtr _Create(const std::string& name, const FactoryContext& context) const;
153
156 friend class TfSingleton<MaxUsdExportChaserRegistry>;
157};
158
159#define PXR_MAXUSD_DEFINE_EXPORT_CHASER_FACTORY_4(name, niceName, description, contextArgName) \
160 static MaxUsdExportChaser* _ChaserFactory_##name( \
161 const MaxUsdExportChaserRegistry::FactoryContext&); \
162 TF_REGISTRY_FUNCTION_WITH_TAG(MaxUsdExportChaserRegistry, name) \
163 { \
164 MaxUsdExportChaserRegistry::GetInstance().RegisterFactory( \
165 #name, niceName, description, &_ChaserFactory_##name); \
166 } \
167 MaxUsdExportChaser* _ChaserFactory_##name( \
168 const MaxUsdExportChaserRegistry::FactoryContext& contextArgName)
169
170#define PXR_MAXUSD_DEFINE_EXPORT_CHASER_FACTORY_3(name, niceName, contextArgName) \
171 PXR_MAXUSD_DEFINE_EXPORT_CHASER_FACTORY_4(name, niceName, "", contextArgName)
172#define PXR_MAXUSD_DEFINE_EXPORT_CHASER_FACTORY_2(name, contextArgName) \
173 PXR_MAXUSD_DEFINE_EXPORT_CHASER_FACTORY_3(name, #name, contextArgName)
174#define PXR_MAXUSD_DEFINE_EXPORT_CHASER_FACTORY_1(name) \
175 PXR_MAXUSD_DEFINE_EXPORT_CHASER_FACTORY_2(name, ctx)
176#define PXR_MAXUSD_DEFINE_EXPORT_CHASER_FACTORY_0() \
177 static_assert(false, "Insufficient number of arguments for macro; expecting PXR_MAXUSD_DEFINE_EXPORT_CHASER_FACTORY(<chaserid>, <nice_name>, <description>, <context_arg_name>)"); \
178 PXR_MAXUSD_DEFINE_EXPORT_CHASER_FACTORY_1(InvalidChaserDeclaration)
179
180#define FUNC_CHOOSER(_f1, _f2, _f3, _f4, _f5, ...) _f5
181#define FUNC_RECOMPOSER(argsWithParentheses) FUNC_CHOOSER argsWithParentheses
182#define CHOOSE_FROM_ARG_COUNT(...) \
183 FUNC_RECOMPOSER((__VA_ARGS__, PXR_MAXUSD_DEFINE_EXPORT_CHASER_FACTORY_4, \
184 PXR_MAXUSD_DEFINE_EXPORT_CHASER_FACTORY_3, \
185 PXR_MAXUSD_DEFINE_EXPORT_CHASER_FACTORY_2, \
186 PXR_MAXUSD_DEFINE_EXPORT_CHASER_FACTORY_1, ))
187#define NO_ARG_EXPANDER() , , , , PXR_MAXUSD_DEFINE_EXPORT_CHASER_FACTORY_0
188#define MACRO_CHOOSER(...) CHOOSE_FROM_ARG_COUNT(NO_ARG_EXPANDER __VA_ARGS__())
189
199// PXR_MAXUSD_DEFINE_EXPORT_CHASER_FACTORY_FULL(name, niceName, description, contextArgName)
200#define PXR_MAXUSD_DEFINE_EXPORT_CHASER_FACTORY(...) \
201 MACRO_CHOOSER(__VA_ARGS__)(__VA_ARGS__)
202
203PXR_NAMESPACE_CLOSE_SCOPE
base class for plugin chasers which are plugins that run after the core usdExport out of 3ds Max.
Definition: ExportChaser.h:31
Holds data that can be accessed when constructing a MaxUsdExportChaser object.
Definition: ExportChaserRegistry.h:44
MaxUSDAPI const USDSceneBuilderOptions & GetJobArgs() const
Returns the current job args.
MaxUSDAPI const fs::path & GetFilename() const
Returns the filename to which the stage exports to.
MaxUSDAPI UsdStagePtr GetStage() const
Returns the exported stage.
MaxUSDAPI const PrimsToNodesMap & GetPrimsToNodesMap() const
Returns a map that maps full USD prim paths to INodes.
Registry for chaser plugins.
Definition: ExportChaserRegistry.h:35
MaxUSDAPI bool RegisterFactory(const std::string &chaser, const std::string &niceName, const std::string &description, FactoryFn fn, bool fromPython=false)
Register a chaser factory.
static MaxUSDAPI TfTokenVector GetAllRegisteredChasers()
Returns the names of all registered chasers.
Definition: ExportChaserRegistry.h:141
static MaxUSDAPI MaxUsdExportChaserRefPtr Create(const std::string &name, const FactoryContext &context)
Creates a chaser using the factoring registered to name.
Definition: ExportChaserRegistry.h:134
static const ChaserInfo & GetChaserInfo(const TfToken &chaser)
Gets the chaser information.
Definition: ExportChaserRegistry.h:111
USD Scene Build configuration options.
Definition: USDSceneBuilderOptions.h:49
All the information registered for a chaser.
Definition: ExportChaserRegistry.h:89