3ds Max USD API Reference
Loading...
Searching...
No Matches
ShadingModeRegistry.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
11#include "MaxUsd/MaxUSDAPI.h"
12#include <MaxUsd/Translators/ShadingModeExporter.h>
13
14#include <pxr/base/tf/registryManager.h>
15#include <pxr/base/tf/singleton.h>
16#include <pxr/base/tf/staticTokens.h>
17#include <pxr/base/tf/token.h>
18#include <pxr/base/tf/weakBase.h>
19#include <pxr/pxr.h>
20
21#include <string>
22
23PXR_NAMESPACE_OPEN_SCOPE
24
25// clang-format off
26// ShadingMode - shading schema to use
27// none - export no shading data to the USD
28// useRegistry - registry based to export the 3ds Max materials to an equivalent UsdShade network
29// additional ShadingMode types can be added thru the use of the RegisterExporter method
30#define PXR_MAXUSD_SHADINGMODE_TOKENS \
31 (none) \
32 (useRegistry)
33// clang-format on
34
35TF_DECLARE_PUBLIC_TOKENS(
36 MaxUsdShadingModeTokens,
37 MaxUSDAPI,
38 PXR_MAXUSD_SHADINGMODE_TOKENS);
39
40// clang-format off
41// ShadingConversion - shading schema to use
42// none - export no shading data to the USD
43// useRegistry - registry based to export the 3ds Max materials to an equivalent UsdShade network
44// additional ShadingMode types can be added thru the use of the RegisterExporter method
45#define PXR_MAXUSD_SHADINGCONVERSION_TOKENS \
46 (none) \
47 (usdPreviewSurface)
48// clang-format on
49
50TF_DECLARE_PUBLIC_TOKENS(
51 MaxUsdPreferredMaterialTokens,
52 MaxUSDAPI,
53 PXR_MAXUSD_SHADINGCONVERSION_TOKENS);
54
55TF_DECLARE_WEAK_PTRS(MaxUsdShadingModeRegistry);
56
63
95class MaxUsdShadingModeRegistry : public TfWeakBase
96{
97public:
98 static MaxUsdShadingModeExporterCreator GetExporter(const TfToken& name)
99 {
100 return GetInstance()._GetExporter(name);
101 }
102 static TfTokenVector ListExporters() { return GetInstance()._ListExporters(); }
103
105 static const std::string& GetExporterNiceName(const TfToken& name)
106 {
107 return GetInstance()._GetExporterNiceName(name);
108 }
109
111 static const std::string& GetExporterDescription(const TfToken& name)
112 {
113 return GetInstance()._GetExporterDescription(name);
114 }
115
116 MaxUSDAPI
117 static MaxUsdShadingModeRegistry& GetInstance();
118
119 MaxUSDAPI
120 bool RegisterExporter(
121 const std::string& name,
122 std::string niceName,
123 std::string description,
124 MaxUsdShadingModeExporterCreator fn);
125
126
127
129 static TfTokenVector ListMaterialConversions()
130 {
131 return GetInstance()._ListMaterialConversions();
132 }
133
136 {
137 TfToken renderContext;
138 TfToken niceName;
139 TfToken exportDescription;
140 bool hasExporter = false;
141
142 ConversionInfo() = default;
143 ConversionInfo(TfToken rc, TfToken nn, TfToken ed, bool he)
144 : renderContext(rc)
145 , niceName(nn)
146 , exportDescription(ed)
147 , hasExporter(he)
148 {
149 }
150 };
151
153 static const ConversionInfo& GetMaterialConversionInfo(const TfToken& materialConversion)
154 {
155 return GetInstance()._GetMaterialConversionInfo(materialConversion);
156 }
157
172 MaxUSDAPI
174 const TfToken& materialConversion,
175 const TfToken& renderContext,
176 const TfToken& niceName,
177 const TfToken& description);
178
179private:
180 MaxUSDAPI
181 MaxUsdShadingModeExporterCreator _GetExporter(const TfToken& name);
182 MaxUSDAPI const std::string& _GetExporterNiceName(const TfToken&);
183 MaxUSDAPI const std::string& _GetExporterDescription(const TfToken&);
184
185 MaxUSDAPI TfTokenVector _ListExporters();
186
187 MaxUSDAPI TfTokenVector _ListMaterialConversions();
188 MaxUSDAPI const ConversionInfo& _GetMaterialConversionInfo(const TfToken&);
189
192 friend class TfSingleton<MaxUsdShadingModeRegistry>;
193};
194
195#define REGISTER_SHADING_MODE_EXPORT_MATERIAL_CONVERSION( \
196 name, renderContext, niceName, description) \
197 TF_REGISTRY_FUNCTION(MaxUsdShadingModeExportContext) \
198 { \
199 MaxUsdShadingModeRegistry::GetInstance().RegisterExportConversion( \
200 name, renderContext, niceName, description); \
201 }
202
203PXR_NAMESPACE_CLOSE_SCOPE
Definition: ShadingModeRegistry.h:96
static const ConversionInfo & GetMaterialConversionInfo(const TfToken &materialConversion)
Gets the conversion information associated with materialConversion on export and import.
Definition: ShadingModeRegistry.h:153
static TfTokenVector ListMaterialConversions()
Get all registered export conversions:
Definition: ShadingModeRegistry.h:129
MaxUSDAPI void RegisterExportConversion(const TfToken &materialConversion, const TfToken &renderContext, const TfToken &niceName, const TfToken &description)
static const std::string & GetExporterDescription(const TfToken &name)
Gets the description of an exporter. Used for the popup help of the export options.
Definition: ShadingModeRegistry.h:111
static const std::string & GetExporterNiceName(const TfToken &name)
Gets the nice name of an exporter. Used for the UI label of the export options.
Definition: ShadingModeRegistry.h:105
All the information registered for a specific material conversion.
Definition: ShadingModeRegistry.h:136