All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
writeJobContext.h
Go to the documentation of this file.
1 //
2 // Copyright 2016 Pixar
3 //
4 // Licensed under the Apache License, Version 2.0 (the "Apache License")
5 // with the following modification; you may not use this file except in
6 // compliance with the Apache License and the following modification to it:
7 // Section 6. Trademarks. is deleted and replaced with:
8 //
9 // 6. Trademarks. This License does not grant permission to use the trade
10 // names, trademarks, service marks, or product names of the Licensor
11 // and its affiliates, except as required to comply with Section 4(c) of
12 // the License and to reproduce the content of the NOTICE file.
13 //
14 // You may obtain a copy of the Apache License at
15 //
16 // http://www.apache.org/licenses/LICENSE-2.0
17 //
18 // Unless required by applicable law or agreed to in writing, software
19 // distributed under the Apache License with the above modification is
20 // distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
21 // KIND, either express or implied. See the Apache License for the specific
22 // language governing permissions and limitations under the Apache License.
23 //
24 #ifndef PXRUSDMAYA_WRITE_JOB_CONTEXT_H
25 #define PXRUSDMAYA_WRITE_JOB_CONTEXT_H
26 
28 
29 #include "usdMaya/api.h"
30 #include "usdMaya/jobArgs.h"
31 #include "usdMaya/primWriter.h"
33 
34 #include "pxr/pxr.h"
35 
36 #include "pxr/usd/sdf/path.h"
37 
38 #include <maya/MDagPath.h>
39 #include <maya/MFnDependencyNode.h>
40 #include <maya/MObjectHandle.h>
41 
42 #include <memory>
43 
44 
45 PXR_NAMESPACE_OPEN_SCOPE
46 
47 
49 class UsdMaya_WriteJob;
50 
58 {
59 protected:
60  friend class UsdMaya_WriteJob;
61 
62  PXRUSDMAYA_API
63  UsdMayaWriteJobContext(const UsdMayaJobExportArgs& args);
64 
65  PXRUSDMAYA_API
66  ~UsdMayaWriteJobContext();
67 
68 public:
69  const UsdMayaJobExportArgs& GetArgs() const;
70  const UsdStageRefPtr& GetUsdStage() const;
71 
76  PXRUSDMAYA_API
77  bool IsMergedTransform(const MDagPath& path) const;
78 
84  PXRUSDMAYA_API
85  SdfPath ConvertDagToUsdPath(const MDagPath& dagPath) const;
86 
102  PXRUSDMAYA_API
103  UsdMayaPrimWriterSharedPtr CreatePrimWriter(
104  const MFnDependencyNode& depNodeFn,
105  const SdfPath& usdPath = SdfPath(),
106  const bool forceUninstance = false);
107 
123  PXRUSDMAYA_API
125  const MDagPath& rootDag,
126  const SdfPath& rootUsdPath,
127  const bool forceUninstance,
128  const bool exportRootVisibility,
129  std::vector<UsdMayaPrimWriterSharedPtr>* primWritersOut);
130 
139  PXRUSDMAYA_API
140  void MarkSkelBindings(
141  const SdfPath& path,
142  const SdfPath& skelPath,
143  const TfToken& config);
144 
145 protected:
148  PXRUSDMAYA_API
149  bool _OpenFile(const std::string& filename, bool append);
150 
153  PXRUSDMAYA_API
154  bool _NeedToTraverse(const MDagPath& curDag) const;
155 
157  PXRUSDMAYA_API
158  bool _PostProcess();
159 
160  UsdMayaJobExportArgs mArgs;
161  // List of the primitive writers to iterate over
162  std::vector<UsdMayaPrimWriterSharedPtr> mMayaPrimWriterList;
163  // Stage used to write out USD file
164  UsdStageRefPtr mStage;
165 
166 private:
171  typedef std::pair<SdfPath, SdfPath> _ExportAndRefPaths;
172 
178  _ExportAndRefPaths _GetInstanceMasterPaths(
179  const MDagPath& instancePath) const;
180 
184  _ExportAndRefPaths _FindOrCreateInstanceMaster(
185  const MDagPath& instancePath);
186 
192  bool _GetInstanceMasterPrimWriters(
193  const MDagPath& instancePath,
194  std::vector<UsdMayaPrimWriterSharedPtr>::const_iterator* begin,
195  std::vector<UsdMayaPrimWriterSharedPtr>::const_iterator* end) const;
196 
199  const std::string& mayaNodeType);
200 
201  struct MObjectHandleComp {
202  bool operator()(const MObjectHandle& rhs, const MObjectHandle& lhs) const {
203  return rhs.hashCode() < lhs.hashCode();
204  }
205  };
206 
210  std::map<MObjectHandle, _ExportAndRefPaths, MObjectHandleComp>
211  _objectsToMasterPaths;
212 
213  // Mapping of Maya object handles to the indices of the instance master's
214  // prim writers in mMayaPrimWriterList. An instance master has a prim writer
215  // for each node in its hierarchy; thus, the value represents an interval
216  // of indices [first, last) in mMayaPrimWriterList. This avoids having to
217  // manage two containers of shared pointers.
218  std::map<MObjectHandle, std::pair<size_t, size_t>, MObjectHandleComp>
219  _objectsToMasterWriters;
220 
221  UsdPrim mInstancesPrim;
222  SdfPath mParentScopePath;
223 
224  std::unique_ptr<UsdMaya_SkelBindingsProcessor> _skelBindingsProcessor;
225 
226  // Cache of node type names mapped to their "resolved" writer factory,
227  // taking into account Maya's type hierarchy (note that this means that
228  // some types not resolved by the UsdMayaPrimWriterRegistry will get
229  // resolved in this map).
230  std::map<std::string, UsdMayaPrimWriterRegistry::WriterFactoryFn>
231  mWriterFactoryCache;
232 
233  // UsdMaya_InstancedNodeWriter is in a separate file, but functions as
234  // an internal helper for UsdMayaWriteJobContext.
235  friend class UsdMaya_InstancedNodeWriter;
236 };
237 
238 
239 PXR_NAMESPACE_CLOSE_SCOPE
240 
241 
242 #endif
Provides basic functionality and access to shared data for UsdMayaPrimWriters.
PXRUSDMAYA_API bool _PostProcess()
Perform any necessary cleanup; call this before you save the stage.
This is a &quot;helper&quot; prim writer used internally by UsdMayaWriteJobContext to author nodes that are dir...
PXRUSDMAYA_API SdfPath ConvertDagToUsdPath(const MDagPath &dagPath) const
Convert DAG paths to USD paths, taking into account the current path translation rules (such as merge...
Token for efficient comparison, assignment, and hashing of known strings.
Definition: token.h:89
PXRUSDMAYA_API UsdMayaPrimWriterSharedPtr CreatePrimWriter(const MFnDependencyNode &depNodeFn, const SdfPath &usdPath=SdfPath(), const bool forceUninstance=false)
Creates a prim writer that writes the Maya node depNodeFn, excluding its descendants, to the given usdPath.
PXRUSDMAYA_API void CreatePrimWriterHierarchy(const MDagPath &rootDag, const SdfPath &rootUsdPath, const bool forceUninstance, const bool exportRootVisibility, std::vector< UsdMayaPrimWriterSharedPtr > *primWritersOut)
Creates all prim writers necessary for writing the Maya node hierarchy rooted at rootDag to the USD n...
PXRUSDMAYA_API bool _OpenFile(const std::string &filename, bool append)
Opens the stage with the given filename for writing.
PXRUSDMAYA_API void MarkSkelBindings(const SdfPath &path, const SdfPath &skelPath, const TfToken &config)
Mark path as containing bindings utilizing the skeleton at skelPath.
UsdPrim is the sole persistent scenegraph object on a UsdStage, and is the embodiment of a &quot;Prim&quot; as ...
Definition: prim.h:131
A path value used to locate objects in layers or scenegraphs.
Definition: path.h:287
This class encapsulates all of the logic for writing or modifying SkelRoot prims for all scopes that ...
PXRUSDMAYA_API bool IsMergedTransform(const MDagPath &path) const
Whether we will merge the transform at path with its single exportable child shape, given its hierarchy and the current path translation rules.
PXRUSDMAYA_API bool _NeedToTraverse(const MDagPath &curDag) const
Whether the current export options should traverse curDag and its descendants.
std::function< UsdMayaPrimWriterSharedPtr(const MFnDependencyNode &, const SdfPath &, UsdMayaWriteJobContext &) > WriterFactoryFn
Writer factory function, i.e.