All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
primWriter.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_PRIM_WRITER_H
25 #define PXRUSDMAYA_PRIM_WRITER_H
26 
28 
29 #include "pxr/pxr.h"
30 #include "usdMaya/api.h"
31 
32 #include "usdMaya/jobArgs.h"
33 #include "usdMaya/util.h"
34 
35 #include "pxr/base/vt/value.h"
36 #include "pxr/usd/sdf/path.h"
37 #include "pxr/usd/usd/attribute.h"
38 #include "pxr/usd/usd/prim.h"
39 #include "pxr/usd/usd/stage.h"
40 #include "pxr/usd/usd/timeCode.h"
41 #include "pxr/usd/usdUtils/sparseValueWriter.h"
42 
43 #include <maya/MDagPath.h>
44 #include <maya/MFnDependencyNode.h>
45 #include <maya/MObject.h>
46 
47 #include <memory>
48 
49 
50 PXR_NAMESPACE_OPEN_SCOPE
51 
52 
54 
55 
65 {
66 public:
74  PXRUSDMAYA_API
76  const MFnDependencyNode& depNodeFn,
77  const SdfPath& usdPath,
78  UsdMayaWriteJobContext& jobCtx);
79 
80  PXRUSDMAYA_API
81  virtual ~UsdMayaPrimWriter();
82 
88  PXRUSDMAYA_API
89  virtual void Write(const UsdTimeCode& usdTime);
90 
94  PXRUSDMAYA_API
95  virtual void PostExport();
96 
104  PXRUSDMAYA_API
105  virtual bool ExportsGprims() const;
106 
115  PXRUSDMAYA_API
116  virtual bool ShouldPruneChildren() const;
117 
121  PXRUSDMAYA_API
122  bool GetExportVisibility() const;
123 
126  PXRUSDMAYA_API
127  void SetExportVisibility(const bool exportVis);
128 
137  PXRUSDMAYA_API
138  virtual const SdfPathVector& GetModelPaths() const;
139 
151  PXRUSDMAYA_API
152  virtual const UsdMayaUtil::MDagPathMap<SdfPath>&
153  GetDagToUsdPathMapping() const;
154 
159  PXRUSDMAYA_API
160  const MDagPath& GetDagPath() const;
161 
163  PXRUSDMAYA_API
164  const MObject& GetMayaObject() const;
165 
167  PXRUSDMAYA_API
168  const SdfPath& GetUsdPath() const;
169 
171  PXRUSDMAYA_API
172  const UsdPrim& GetUsdPrim() const;
173 
175  PXRUSDMAYA_API
176  const UsdStageRefPtr& GetUsdStage() const;
177 
178 protected:
181  PXRUSDMAYA_API
182  virtual bool _HasAnimCurves() const;
183 
185  PXRUSDMAYA_API
186  const UsdMayaJobExportArgs& _GetExportArgs() const;
187 
192  template <typename T>
194  const UsdAttribute& attr,
195  const T& value,
196  const UsdTimeCode time = UsdTimeCode::Default()) {
197  VtValue val(value);
198  return _valueWriter.SetAttribute(attr, &val, time);
199  }
200 
206  template <typename T>
208  const UsdAttribute& attr,
209  T* value,
210  const UsdTimeCode time = UsdTimeCode::Default()) {
211  return _valueWriter.SetAttribute(attr, VtValue::Take(*value), time);
212  }
213 
217  PXRUSDMAYA_API
219 
220  UsdPrim _usdPrim;
221  UsdMayaWriteJobContext& _writeJobCtx;
222 
223 private:
226  bool _IsMergedTransform() const;
227 
230  bool _IsMergedShape() const;
231 
234  const MDagPath _dagPath;
235 
238  const MObject _mayaObject;
239 
240  const SdfPath _usdPath;
241  const UsdMayaUtil::MDagPathMap<SdfPath> _baseDagToUsdPaths;
242 
243  UsdUtilsSparseValueWriter _valueWriter;
244 
245  bool _exportVisibility;
246  bool _hasAnimCurves;
247 };
248 
249 typedef std::shared_ptr<UsdMayaPrimWriter> UsdMayaPrimWriterSharedPtr;
250 
251 
252 PXR_NAMESPACE_CLOSE_SCOPE
253 
254 
255 #endif
PXRUSDMAYA_API void SetExportVisibility(const bool exportVis)
Sets whether visibility can be exported for this prim.
bool _SetAttribute(const UsdAttribute &attr, const T &value, const UsdTimeCode time=UsdTimeCode::Default())
Sets the value of attr to value at time with value compression.
Definition: primWriter.h:193
PXRUSDMAYA_API const UsdMayaJobExportArgs & _GetExportArgs() const
Gets the current global export args in effect.
Provides basic functionality and access to shared data for UsdMayaPrimWriters.
std::map< MDagPath, V, _CmpDag > MDagPathMap
Mapping of DAG paths to an arbitrary type.
Definition: util.h:97
virtual PXRUSDMAYA_API const SdfPathVector & GetModelPaths() const
Gets all of the exported prim paths that are potentially models, i.e.
PXRUSDMAYA_API const MObject & GetMayaObject() const
The MObject for the Maya node being written by this writer.
Scenegraph object for authoring and retrieving numeric, string, and array valued data, sampled over time.
Definition: attribute.h:176
virtual PXRUSDMAYA_API void Write(const UsdTimeCode &usdTime)
Main export function that runs when the traversal hits the node.
Utility class that manages sparse authoring of a set of UsdAttributes.
virtual PXRUSDMAYA_API bool ShouldPruneChildren() const
Whether the traversal routine using this prim writer should skip all of the Maya node&#39;s descendants w...
PXRUSDMAYA_API const MDagPath & GetDagPath() const
The source Maya DAG path that we are consuming.
virtual PXRUSDMAYA_API bool _HasAnimCurves() const
Helper function for determining whether the current node has input animation curves.
static VtValue Take(T &obj)
Create a new VtValue, taking its contents from obj.
Definition: value.h:679
Represent a time value, which may be either numeric, holding a double value, or a sentinel value UsdT...
Definition: timeCode.h:85
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
PXRUSDMAYA_API UsdUtilsSparseValueWriter * _GetSparseValueWriter()
Get the attribute value-writer object to be used when writing attributes.
virtual PXRUSDMAYA_API void PostExport()
Post export function that runs before saving the stage.
PXRUSDMAYA_API const SdfPath & GetUsdPath() const
The path of the destination USD prim to which we are writing.
virtual PXRUSDMAYA_API bool ExportsGprims() const
Whether this prim writer directly create one or more gprims on the current model on the USD stage...
PXRUSDMAYA_API const UsdStageRefPtr & GetUsdStage() const
Gets the USD stage that we&#39;re writing to.
static constexpr UsdTimeCode Default()
Produce a UsdTimeCode representing the sentinel value for &#39;default&#39;.
Definition: timeCode.h:113
virtual PXRUSDMAYA_API const UsdMayaUtil::MDagPathMap< SdfPath > & GetDagToUsdPathMapping() const
Gets a mapping from MDagPaths to exported prim paths.
Base class for all built-in and user-defined prim writers.
Definition: primWriter.h:64
bool _SetAttribute(const UsdAttribute &attr, T *value, const UsdTimeCode time=UsdTimeCode::Default())
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition: primWriter.h:207
PXRUSDMAYA_API const UsdPrim & GetUsdPrim() const
The destination USD prim to which we are writing.
PXRUSDMAYA_API bool GetExportVisibility() const
Whether visibility can be exported for this prim.
PXRUSDMAYA_API UsdMayaPrimWriter(const MFnDependencyNode &depNodeFn, const SdfPath &usdPath, UsdMayaWriteJobContext &jobCtx)
Constructs a prim writer for writing a Maya DG or DAG node.
Provides a container which may hold any type, and provides introspection and iteration over array typ...
Definition: value.h:182
USDUTILS_API bool SetAttribute(const UsdAttribute &attr, const VtValue &value, const UsdTimeCode time=UsdTimeCode::Default())
Sets the value of attr to value at time time.