18 #include "../../Api.h"
19 #include "AL/maya/utils/Api.h"
21 #include "maya/MDagPath.h"
23 #include "pxr/base/tf/refBase.h"
24 #include "pxr/base/tf/type.h"
25 #include "pxr/base/tf/weakBase.h"
26 #include "pxr/base/tf/registryManager.h"
27 #include "pxr/usd/usd/prim.h"
30 #include <unordered_map>
32 #include "AL/usdmaya/fileio/translators/TranslatorContext.h"
33 #include "AL/usdmaya/fileio/ExportParams.h"
38 namespace translators {
82 :
public TfRefBase,
public TfWeakBase
87 typedef TfWeakPtr<This>
Ptr;
109 {
return MS::kSuccess; }
118 virtual MStatus
import(
const UsdPrim& prim, MObject& parent, MObject& createdObj)
119 {
return MS::kSuccess; }
121 virtual UsdPrim exportObject(UsdStageRefPtr stage, MDagPath dagPath,
const SdfPath& usdPath,
const ExporterParams& params)
122 {
return UsdPrim(); }
129 {
return MS::kSuccess; }
136 {
return MS::kSuccess; }
146 {
return MStatus::kNotImplemented; }
163 virtual MStatus
update(
const UsdPrim& prim)
164 {
return MStatus::kNotImplemented; }
168 {
return ExportFlag::kNotSupported; }
182 typedef TfRefPtr<This>
RefPtr;
190 {
return m_translatedType; }
195 {
return m_context; }
202 static RefPtr
manufacture(
const std::string& primType, TranslatorContextPtr
context) =
delete;
207 {
return context()->getUsdStage(); }
214 virtual void exportCustomAnim(
const MDagPath& path, UsdPrim& prim,
const UsdTimeCode& timeCode)
227 { m_translatedType = translatedType; }
235 TfType m_translatedType;
236 TranslatorContextPtr m_context;
239 typedef TfRefPtr<TranslatorBase> TranslatorRefPtr;
240 typedef std::vector<TranslatorRefPtr> TranslatorRefPtrVector;
250 typedef std::vector<RefPtr> RefPtrVector;
262 RefPtr get(
const TfToken type_name);
268 RefPtr get(
const MObject& mayaObject);
271 std::unordered_map<std::string, TranslatorRefPtr> m_translatorsMap;
279 :
public TfType::FactoryBase
286 virtual TfRefPtr<TranslatorBase>
create(TranslatorContextPtr ctx)
const = 0;
293 template <
typename T>
300 TfRefPtr<TranslatorBase>
create(TranslatorContextPtr ctx)
const override
301 {
return T::create(ctx); }
308 #define AL_USDMAYA_DECLARE_TRANSLATOR(PlugClass) \
309 typedef PlugClass This; \
310 typedef TfRefPtr<This> RefPtr; \
311 typedef TfWeakPtr<This> Ptr; \
312 AL_MAYA_MACROS_PUBLIC \
313 static RefPtr create(TranslatorContextPtr context);
320 #define AL_USDMAYA_DEFINE_TRANSLATOR(PlugClass, TranslatedType) \
321 TfRefPtr<PlugClass> \
322 PlugClass::create(TranslatorContextPtr context) { \
323 TfType const &type = TfType::Find<TranslatedType>(); \
324 if(!type.IsUnknown()) { \
325 TfRefPtr<PlugClass> plugin = TfCreateRefPtr(new This()); \
326 plugin->setTranslatedType(type); \
327 plugin->setContext(context); \
328 if(!plugin->initialize()) return TfRefPtr<PlugClass>(); \
333 "Failed to get %s usd type, maybe the needed plugin is not loaded", \
334 typeid(TranslatedType).name()); \
339 TF_REGISTRY_FUNCTION(TfType) \
341 TfType::Define<PlugClass, TfType::Bases<TranslatorBase>>() \
342 .SetFactory<TranslatorFactory<PlugClass>>(); \
The base class interface of all translator plugins. The absolute minimum a translator plugin must imp...
Definition: TranslatorBase.h:81
the factory interface, used to create an instance of a particular translator type ...
Definition: TranslatorBase.h:278
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:226
virtual TfType getTranslatedType() const =0
Override to specify the schema type of the prim that this translator plugin is responsible for...
parameters for the exporter. These parameters are constructed by any command or file translator that ...
Definition: ExportParams.h:35
virtual void exportCustomAnim(const MDagPath &path, UsdPrim &prim, const UsdTimeCode &timeCode)
override if you have a node that needs to generate animation that cannot be mapped between an MPlug a...
Definition: TranslatorBase.h:214
the factory instance for a given translator type
Definition: TranslatorBase.h:294
virtual ~TranslatorAbstract()
dtor
Definition: TranslatorBase.h:90
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:163
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:194
static AL_USDMAYA_PUBLIC RefPtr manufacture(const std::string &primType, TranslatorContextPtr context)=delete
Internal method used to create a new instance of a plugin translator.
TfRefPtr< This > RefPtr
the type of a reference this type
Definition: TranslatorBase.h:86
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:108
virtual ExportFlag canExport(const MObject &obj)
Method used to test a Maya node to see whether it can be exported.
Definition: TranslatorBase.h:167
AL_USDMAYA_PUBLIC TranslatorManufacture(TranslatorContextPtr context)
constructs a registry of translator plugins that are currently registered within usd maya...
TfType getTranslatedType() const override
returns the translated prim type
Definition: TranslatorBase.h:189
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:101
TfWeakPtr< This > Ptr
weak pointer to this type
Definition: TranslatorBase.h:87
virtual AL_USDMAYA_PUBLIC TfRefPtr< TranslatorBase > create(TranslatorContextPtr ctx) const =0
overridden by the TranslatorFactory to create a new translator for a given type
Forms a registry of all plug-in translator types registered.
Definition: TranslatorBase.h:246
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:135
Base class for maya translator usd plugins. The TfType of these plugins has to be derived from the ba...
Definition: TranslatorBase.h:177
TfRefPtr< TranslatorBase > create(TranslatorContextPtr ctx) const override
creates a new translator for a given type T
Definition: TranslatorBase.h:300
TfRefPtr< TranslatorBase > RefPtr
handle to a plug-in translator
Definition: TranslatorBase.h:249
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:145
UsdStageRefPtr getUsdStage() const
return the usd stage associated with this context
Definition: TranslatorBase.h:206
TranslatorAbstract This
this type
Definition: TranslatorBase.h:85
virtual ~TranslatorBase()
dtor
Definition: TranslatorBase.h:185
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:128
virtual bool importableByDefault() const
If a translator is importableByDefault=true, it will always be automatically imported on ProxyShape i...
Definition: TranslatorBase.h:156
virtual bool supportsUpdate() const
override this method and return true if the translator supports update
Definition: TranslatorBase.h:150
virtual void setContext(const TranslatorContextPtr context)
internal method. Used within AL_USDMAYA_DEFINE_TRANSLATOR macro to set the translation context ...
Definition: TranslatorBase.h:231