18 #include "../../Api.h"
20 #include <AL/usdmaya/ForwardDeclares.h>
21 #include "maya/MPxData.h"
22 #include "maya/MGlobal.h"
23 #include "maya/MObject.h"
24 #include "maya/MObjectHandle.h"
25 #include "maya/MObjectArray.h"
26 #include "maya/MDGModifier.h"
28 #include "pxr/base/tf/refPtr.h"
29 #include "pxr/usd/usd/prim.h"
30 #include "pxr/base/tf/debug.h"
31 #include "AL/usdmaya/DebugCodes.h"
35 #include "AL/usd/utils/ForwardDeclares.h"
37 PXR_NAMESPACE_USING_DIRECTIVE
43 namespace translators {
45 typedef std::vector<MObjectHandle> MObjectHandleArray;
58 { forcePrimImport = forceImport; }
62 {
return forcePrimImport; }
65 bool forcePrimImport =
false;
85 RefPtr res = TfCreateRefPtr(
new This(proxyShape));
86 res->setForceDefaultRead(
false);
93 {
return m_proxyShape; }
114 bool getTransform(
const SdfPath& path, MObjectHandle&
object);
125 bool getMObject(
const UsdPrim& prim, MObjectHandle&
object, MTypeId type)
126 {
return getMObject(prim.GetPath(), object, type); }
138 bool getMObject(
const SdfPath& path, MObjectHandle&
object, MTypeId type);
149 bool getMObject(
const UsdPrim& prim, MObjectHandle&
object, MFn::Type type)
150 {
return getMObject(prim.GetPath(), object, type); }
162 bool getMObject(
const SdfPath& path, MObjectHandle&
object, MFn::Type type);
168 bool getMObjects(
const UsdPrim& prim, MObjectHandleArray& returned)
176 bool getMObjects(
const SdfPath& path, MObjectHandleArray& returned);
183 void insertItem(
const UsdPrim& prim, MObjectHandle
object);
206 const auto it = find(path);
207 if(it != m_primMapping.end())
211 TF_DEBUG(ALUSDMAYA_TRANSLATORS).Msg(
"TranslatorContext::getTypeForPath did not find item in mapping.%s\n", path.GetText());
226 void registerItem(
const UsdPrim& prim, MObjectHandle
object);
247 bool hasEntry(
const SdfPath& path,
const TfToken& type)
249 auto it = find(path);
250 if(it != m_primMapping.end())
252 return type == it->type();
263 void preRemoveEntry(
const SdfPath& primPath, SdfPathVector& itemsToRemove,
bool callPreUnload=
true);
281 : m_path(path), m_type(type), m_object(mayaObj), m_createdNodes() {}
299 {
return m_object.object(); }
309 {
return m_createdNodes; }
314 {
return m_createdNodes; }
319 MObjectHandle m_object;
320 MObjectHandleArray m_createdNodes;
334 {
return a.
path() < b; }
341 {
return a < b.
path(); }
354 { m_primMapping.clear(); }
362 auto foundPath = m_excludedGeometry.find(newPath);
364 if(foundPath != m_excludedGeometry.end())
369 m_excludedGeometry.insert(newPath);
370 m_isExcludedGeometryDirty =
true;
380 auto foundPath = m_excludedGeometry.find(newPath);
382 if(foundPath == m_excludedGeometry.end())
386 m_excludedGeometry.erase(newPath);
387 m_isExcludedGeometryDirty =
true;
394 {
return m_excludedGeometry;}
399 {
return m_isExcludedGeometryDirty;}
403 const SdfPath& primPath,
404 const MObject& primObj);
407 const MObject& primObj);
409 bool isNodeAncestorOf(MObjectHandle ancestorHandle, MObjectHandle objectHandleToTest);
413 bool isPrimInTransformChain(
const SdfPath& path);
415 inline PrimLookups::iterator find(
const SdfPath& path)
417 PrimLookups::iterator end = m_primMapping.end();
418 PrimLookups::iterator it = std::lower_bound(m_primMapping.begin(), end, path, value_compare());
421 if(it->path() == path)
427 inline PrimLookups::const_iterator find(
const SdfPath& path)
const
429 PrimLookups::const_iterator end = m_primMapping.end();
430 PrimLookups::const_iterator it = std::lower_bound(m_primMapping.begin(), end, path, value_compare());
433 if(it->path() == path)
439 inline PrimLookups::iterator findLocation(
const SdfPath& path)
441 PrimLookups::iterator end = m_primMapping.end();
442 PrimLookups::iterator it = std::lower_bound(m_primMapping.begin(), end, path, value_compare());
447 TranslatorContext(nodes::ProxyShape* proxyShape)
448 : m_proxyShape(proxyShape), m_primMapping()
451 nodes::ProxyShape* m_proxyShape;
458 bool m_forcePrimImport;
461 SdfPathSet m_excludedGeometry;
462 bool m_isExcludedGeometryDirty;
465 void setForceDefaultRead(
bool forceDefaultRead)
466 { m_forceDefaultRead = forceDefaultRead; }
468 bool getForceDefaultRead()
469 {
return m_forceDefaultRead; }
473 bool m_forceDefaultRead;
477 typedef TfRefPtr<TranslatorContext> TranslatorContextPtr;
This class provides a context to store mappings between UsdPrims, and the Maya nodes that represent t...
Definition: TranslatorContext.h:73
TfRefPtr< This > RefPtr
pointer to this type
Definition: TranslatorContext.h:78
std::vector< PrimLookup > PrimLookups
a sorted array of prim mappings
Definition: TranslatorContext.h:324
AL_USDMAYA_PUBLIC void preRemoveEntry(const SdfPath &primPath, SdfPathVector &itemsToRemove, bool callPreUnload=true)
This is called during a variant switch to determine whether the variant switch will allow Maya nodes ...
AL_USDMAYA_PUBLIC void updatePrimTypes()
this method is used after a variant switch to check to see if the prim types have changed in the stag...
AL_USDMAYA_PUBLIC void validatePrims()
debugging utility to help keep track of prims during a variant switch
AL_USDMAYA_PUBLIC bool removeExcludedGeometry(const SdfPath &newPath)
remove geometry from the exclusion list
Definition: TranslatorContext.h:378
A custom proxy shape node that attaches itself to a USD file, and then renders it. The stage is held internally as a member variable, and it will be composed based on a change to the "filePath" attribute.
Definition: ProxyShape.h:244
An internal structure used to store a mapping between an SdfPath, the type of prim found at that loca...
Definition: TranslatorContext.h:273
bool hasEntry(const SdfPath &path, const TfToken &type)
This method is used to determine whether this DB has an entry for the specified prim path and the giv...
Definition: TranslatorContext.h:247
comparison utility (for sorting array of pointers to node references based on their path) ...
Definition: TranslatorContext.h:327
AL_USDMAYA_PUBLIC bool addExcludedGeometry(const SdfPath &newPath)
add geometry to the exclusion list
Definition: TranslatorContext.h:360
Transient aggregate of values that aims to direct the Translation of Prims. Typically an object of th...
Definition: TranslatorContext.h:54
const MObjectHandleArray & createdNodes() const
get created maya nodes
Definition: TranslatorContext.h:313
TranslatorContext This
this type
Definition: TranslatorContext.h:77
void setForcePrimImport(bool forceImport)
Flag that determines if all Prim schema types should be forced to be imported.
Definition: TranslatorContext.h:57
const SdfPathSet & excludedGeometry()
retrieve currently excluded translator geometries
Definition: TranslatorContext.h:393
MObject object() const
get the maya object of the node
Definition: TranslatorContext.h:298
AL_USDMAYA_PUBLIC void deserialise(const MString &string)
deserialises the string back into the translator context
AL_USDMAYA_PUBLIC void registerItem(const UsdPrim &prim, MObjectHandle object)
Internal method. If within your custom translator plug-in you need to create any maya nodes...
bool getMObjects(const UsdPrim &prim, MObjectHandleArray &returned)
returns all of the maya nodes that were created by the specific prim
Definition: TranslatorContext.h:168
void removeItems(const UsdPrim &prim)
during a variant switch, if we lose a prim, then it's path will be passed into this method...
Definition: TranslatorContext.h:188
AL_USDMAYA_PUBLIC void insertItem(const UsdPrim &prim, MObjectHandle object)
If within your custom translator plug-in you need to create any maya nodes, associate that maya node ...
AL_USDMAYA_PUBLIC UsdStageRefPtr getUsdStage() const
return the usd stage associated with this context
MObjectHandle objectHandle() const
get the maya object of the node
Definition: TranslatorContext.h:293
PrimLookup(const SdfPath &path, const TfToken &type, MObject mayaObj)
ctor
Definition: TranslatorContext.h:280
const nodes::ProxyShape * getProxyShape() const
return the proxy shape associated with this context
Definition: TranslatorContext.h:92
TfToken type() const
get the prim type
Definition: TranslatorContext.h:303
bool getTransform(const UsdPrim &prim, MObjectHandle &object)
given a USD prim, this will see whether a maya node exists for it. If it does, that will be returned ...
Definition: TranslatorContext.h:105
bool getMObject(const UsdPrim &prim, MObjectHandle &object, MTypeId type)
given a USD prim, this will see whether a maya node exists for it. If it does, that will be returned ...
Definition: TranslatorContext.h:125
AL_USDMAYA_PUBLIC MString serialise() const
serialises the content of the translator context to a text string.
const SdfPath & path() const
get the prim path of this reference
Definition: TranslatorContext.h:288
AL_USDMAYA_PUBLIC ~TranslatorContext()
dtor
MObjectHandleArray & createdNodes()
get created maya nodes
Definition: TranslatorContext.h:308
static RefPtr create(nodes::ProxyShape *proxyShape)
construct a new context for the specified proxy shape node
Definition: TranslatorContext.h:83
AL_USDMAYA_PUBLIC void removeEntries(const SdfPathVector &itemsToRemove)
call this to remove a prim from the DB (you do not need to lock/unlock here).
bool getMObject(const UsdPrim &prim, MObjectHandle &object, MFn::Type type)
given a USD prim, this will see whether a maya node exists for it. If it does, that will be returned ...
Definition: TranslatorContext.h:149
~PrimLookup()
dtor
Definition: TranslatorContext.h:284
void clearPrimMappings()
This is used for testing only. Do not call.
Definition: TranslatorContext.h:353
TfToken getTypeForPath(SdfPath path) const
given a path to a prim, return the prim type we are aware of at that path
Definition: TranslatorContext.h:204
bool isExcludedGeometryDirty()
Retrieves if the the excluded geometry has been pushed to the renderer.
Definition: TranslatorContext.h:398
bool operator()(const PrimLookup &a, const SdfPath &b) const
compare schema node ref to path
Definition: TranslatorContext.h:333
bool forceTranslatorImport() const
Retrieves the flag that determines if all the Prim schema types should be imported.
Definition: TranslatorContext.h:61