3 #include "maya/MDagPath.h"
5 #include "pxr/base/tf/refBase.h"
6 #include "pxr/base/tf/type.h"
7 #include "pxr/base/tf/weakBase.h"
8 #include "pxr/base/tf/registryManager.h"
9 #include "pxr/usd/usd/prim.h"
12 #include <unordered_map>
13 #include "AL/usdmaya/fileio/translators/TranslatorContext.h"
18 namespace translators {
54 :
public TfRefBase,
public TfWeakBase
59 typedef TfWeakPtr<This>
Ptr;
81 {
return MS::kSuccess; }
89 virtual MStatus
import(
const UsdPrim& prim, MObject& parent)
90 {
return MS::kSuccess; }
97 {
return MS::kSuccess; }
104 {
return MS::kSuccess; }
114 {
return MStatus::kNotImplemented; }
125 virtual MStatus
update(
const UsdPrim& prim)
126 {
return MStatus::kNotImplemented; }
140 typedef TfRefPtr<This>
RefPtr;
148 {
return m_translatedType; }
153 {
return m_context; }
159 static RefPtr
manufacture(
const std::string& primType, TranslatorContextPtr
context) =
delete;
164 {
return context()->getUsdStage(); }
172 { m_translatedType = translatedType; }
181 TfType m_translatedType;
182 TranslatorContextPtr m_context;
185 typedef TfRefPtr<TranslatorBase> TranslatorRefPtr;
200 RefPtr get(
const TfToken type_name, TranslatorContextPtr context);
203 std::unordered_map<std::string, TranslatorRefPtr> m_translatorsMap;
211 :
public TfType::FactoryBase
217 virtual TfRefPtr<TranslatorBase>
create(TranslatorContextPtr ctx)
const = 0;
224 template <
typename T>
231 virtual TfRefPtr<TranslatorBase>
create(TranslatorContextPtr ctx)
const
232 {
return T::create(ctx); }
239 #define AL_USDMAYA_DECLARE_TRANSLATOR(PlugClass) \
240 typedef PlugClass This; \
241 typedef TfRefPtr<This> RefPtr; \
242 typedef TfWeakPtr<This> Ptr; \
243 static RefPtr create(TranslatorContextPtr context);
249 #define AL_USDMAYA_DEFINE_TRANSLATOR(PlugClass, TranslatedType) \
250 TfRefPtr<PlugClass> \
251 PlugClass::create(TranslatorContextPtr context) { \
252 TfType const &type = TfType::Find<TranslatedType>(); \
253 if(not type.IsUnknown()) { \
254 TfRefPtr<PlugClass> plugin = TfCreateRefPtr(new This()); \
255 plugin->setTranslatedType(type); \
256 plugin->setContext(context); \
257 plugin->initialize(); \
262 "Failed to get %s usd type, maybe the needed plugin is not loaded", \
263 typeid(TranslatedType).name()); \
268 TF_REGISTRY_FUNCTION(TfType) \
270 TfType::Define<PlugClass, TfType::Bases<TranslatorBase>>() \
271 .SetFactory<TranslatorFactory<PlugClass>>(); \
The base class interface of all translator plugins. The absolute minimum a translator plugin must imp...
Definition: TranslatorBase.h:53
the factory interface, used to create an instance of a particular translator type ...
Definition: TranslatorBase.h:210
virtual void setTranslatedType(const TfType &translatedType)
internal method. Used within AL_USDMAYA_DEFINE_TRANSLATOR macro to set the schema type of the node we...
Definition: TranslatorBase.h:171
virtual TfType getTranslatedType() const =0
Override to specify the schema type of the prim that this translator plugin is responsible for...
the factory instance for a given translator type
Definition: TranslatorBase.h:225
virtual ~TranslatorAbstract()
dtor
Definition: TranslatorBase.h:62
virtual MStatus update(const UsdPrim &prim)
Optionally override this method to copy the attribute values from the prim onto the Maya nodes you ha...
Definition: TranslatorBase.h:125
TfRefPtr< This > RefPtr
the type of a reference this type
Definition: TranslatorBase.h:58
virtual MStatus initialize()
Override this to do a one time initialization of your translator. Primarily this is to allow you to e...
Definition: TranslatorBase.h:80
virtual TfRefPtr< TranslatorBase > create(TranslatorContextPtr ctx) const
creates a new translator for a given type T
Definition: TranslatorBase.h:231
virtual bool needsTransformParent() const
if the custom node type you are importing requires a parent transform (e.g. you are importing a shape...
Definition: TranslatorBase.h:73
virtual TfRefPtr< TranslatorBase > create(TranslatorContextPtr ctx) const =0
overridden by the TranslatorFactory to create a new translator for a given type
TfWeakPtr< This > Ptr
weak pointer to this type
Definition: TranslatorBase.h:59
virtual TranslatorContextPtr context() const
returns the context currently being used to translate the USD prims. The context can be used to add r...
Definition: TranslatorBase.h:152
virtual TfType getTranslatedType() const override
returns the translated prim type
Definition: TranslatorBase.h:147
Forms a registry of all plug-in translator types registered.
Definition: TranslatorBase.h:191
virtual MStatus preTearDown(UsdPrim &prim)
This method will be called prior to the tear down process taking place. This is the last chance you h...
Definition: TranslatorBase.h:103
Base class for maya translator usd plugins. The TfType of these plugins has to be derived from the ba...
Definition: TranslatorBase.h:135
static RefPtr manufacture(const std::string &primType, TranslatorContextPtr context)=delete
Internal method used to create a new instance of a plugin translator.
TfRefPtr< TranslatorBase > RefPtr
handle to a plug-in translator
Definition: TranslatorBase.h:194
virtual MStatus tearDown(const SdfPath &path)
If your plugin creates any nodes within Maya, then this method should be overridden to remove those n...
Definition: TranslatorBase.h:113
UsdStageRefPtr getUsdStage() const
return the usd stage associated with this context
Definition: TranslatorBase.h:163
TranslatorAbstract This
this type
Definition: TranslatorBase.h:57
virtual ~TranslatorBase()
dtor
Definition: TranslatorBase.h:143
virtual MStatus postImport(const UsdPrim &prim)
If your node needs to set up any relationships after import (for example, adding the node to a set...
Definition: TranslatorBase.h:96
virtual bool supportsUpdate() const
override this method and return true if the translator supports update
Definition: TranslatorBase.h:118
virtual void setContext(const TranslatorContextPtr context)
internal method. Used within AL_USDMAYA_DEFINE_TRANSLATOR macro to set the translation context ...
Definition: TranslatorBase.h:176