All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
writeUtil.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 
26 
27 #ifndef PXRUSDMAYA_WRITEUTIL_H
28 #define PXRUSDMAYA_WRITEUTIL_H
29 
30 #include "pxr/pxr.h"
31 #include "usdMaya/api.h"
33 
34 #include "pxr/base/tf/token.h"
35 #include "pxr/base/vt/types.h"
36 #include "pxr/usd/sdf/valueTypeName.h"
37 #include "pxr/usd/usd/attribute.h"
38 #include "pxr/usd/usd/prim.h"
39 #include "pxr/usd/usd/timeCode.h"
40 #include "pxr/usd/usdGeom/imageable.h"
41 #include "pxr/usd/usdGeom/pointInstancer.h"
42 #include "pxr/usd/usdGeom/primvar.h"
43 
44 #include <maya/MFnArrayAttrsData.h>
45 #include <maya/MFnDependencyNode.h>
46 #include <maya/MObject.h>
47 #include <maya/MPlug.h>
48 #include <maya/MString.h>
49 
50 #include <string>
51 
52 PXR_NAMESPACE_OPEN_SCOPE
53 
55 
58 {
61 
64  PXRUSDMAYA_API
65  static bool WriteUVAsFloat2();
66 
71  PXRUSDMAYA_API
73  const MPlug& attrPlug,
74  const bool translateMayaDoubleToUsdSinglePrecision =
76 
86  PXRUSDMAYA_API
88  const MPlug& attrPlug,
89  const UsdPrim& usdPrim,
90  const std::string& attrName,
91  const bool custom = false,
92  const bool translateMayaDoubleToUsdSinglePrecision =
94 
101  PXRUSDMAYA_API
103  const MPlug& attrPlug,
104  UsdGeomImageable& imageable,
105  const std::string& primvarName,
106  const TfToken& interpolation = TfToken(),
107  const int elementSize = -1,
108  const bool translateMayaDoubleToUsdSinglePrecision =
110 
117  PXRUSDMAYA_API
119  const MPlug& attrPlug,
120  const UsdPrim& usdPrim,
121  const std::string& attrName,
122  const std::string& nameSpace = "user",
123  const bool translateMayaDoubleToUsdSinglePrecision =
125 
133  PXRUSDMAYA_API
134  static VtValue GetVtValue(
135  const MPlug& attrPlug,
136  const SdfValueTypeName& typeName,
137  const bool linearizeColors = true);
138 
146  PXRUSDMAYA_API
147  static VtValue GetVtValue(
148  const MPlug& attrPlug,
149  const TfType& type,
150  const TfToken& role,
151  const bool linearizeColors = true);
152 
159  PXRUSDMAYA_API
160  static bool SetUsdAttr(
161  const MPlug& attrPlug,
162  const UsdAttribute& usdAttr,
163  const UsdTimeCode& usdTime,
164  UsdUtilsSparseValueWriter *valueWriter=nullptr);
165 
169  PXRUSDMAYA_API
170  static bool WriteUserExportedAttributes(
171  const MObject& mayaNode,
172  const UsdPrim& usdPrim,
173  const UsdTimeCode& usdTime,
174  UsdUtilsSparseValueWriter *valueWriter=nullptr);
175 
178  PXRUSDMAYA_API
179  static bool WriteMetadataToPrim(
180  const MObject& mayaObject,
181  const UsdPrim& prim);
182 
188  PXRUSDMAYA_API
189  static bool WriteAPISchemaAttributesToPrim(
190  const MObject& mayaObject,
191  const UsdPrim& prim,
192  UsdUtilsSparseValueWriter *valueWriter=nullptr);
193 
194  template <typename T>
195  static size_t WriteSchemaAttributesToPrim(
196  const MObject& object,
197  const UsdPrim& prim,
198  const std::vector<TfToken>& attributeNames,
199  const UsdTimeCode& usdTime = UsdTimeCode::Default(),
200  UsdUtilsSparseValueWriter *valueWriter=nullptr)
201  {
202  return WriteSchemaAttributesToPrim(
203  object,
204  prim,
205  TfType::Find<T>(),
206  attributeNames,
207  usdTime,
208  valueWriter);
209  }
210 
217  static size_t WriteSchemaAttributesToPrim(
218  const MObject& object,
219  const UsdPrim& prim,
220  const TfType& schemaType,
221  const std::vector<TfToken>& attributeNames,
222  const UsdTimeCode& usdTime = UsdTimeCode::Default(),
223  UsdUtilsSparseValueWriter *valueWriter=nullptr);
224 
228  PXRUSDMAYA_API
229  static bool WriteClassInherits(
230  const UsdPrim& usdPrim,
231  const std::vector<std::string>& inheritClassNames);
232 
237  PXRUSDMAYA_API
238  static bool WriteArrayAttrsToInstancer(
239  MFnArrayAttrsData& inputPointsData,
240  const UsdGeomPointInstancer& instancer,
241  const size_t numPrototypes,
242  const UsdTimeCode& usdTime,
243  UsdUtilsSparseValueWriter *valueWriter=nullptr);
244 
246 
249 
251  PXRUSDMAYA_API
252  static bool ReadMayaAttribute(
253  const MFnDependencyNode& depNode,
254  const MString& name,
255  std::string* val);
256 
257  PXRUSDMAYA_API
258  static bool ReadMayaAttribute(
259  const MFnDependencyNode& depNode,
260  const MString& name,
261  std::vector<std::string>* val);
262 
264  PXRUSDMAYA_API
265  static bool ReadMayaAttribute(
266  const MFnDependencyNode& depNode,
267  const MString& name,
268  VtIntArray* val);
269 
271  PXRUSDMAYA_API
272  static bool ReadMayaAttribute(
273  const MFnDependencyNode& depNode,
274  const MString& name,
275  VtFloatArray* val);
276 
278  PXRUSDMAYA_API
279  static bool ReadMayaAttribute(
280  const MFnDependencyNode& depNode,
281  const MString& name,
282  VtVec3fArray* val);
284 
286 
307  PXRUSDMAYA_API
308  static std::vector<double> GetTimeSamples(
309  const GfInterval& frameRange,
310  const std::set<double>& subframeOffsets,
311  const double stride = 1.0);
312 
314 
315 };
316 
317 
318 PXR_NAMESPACE_CLOSE_SCOPE
319 
320 #endif
static PXRUSDMAYA_API SdfValueTypeName GetUsdTypeName(const MPlug &attrPlug, const bool translateMayaDoubleToUsdSinglePrecision=UsdMayaUserTaggedAttribute::GetFallbackTranslateMayaDoubleToUsdSinglePrecision())
Get the SdfValueTypeName that corresponds to the given plug attrPlug.
static PXRUSDMAYA_API bool WriteMetadataToPrim(const MObject &mayaObject, const UsdPrim &prim)
Writes all of the adaptor metadata from mayaObject onto the prim.
static PXRUSDMAYA_API UsdAttribute GetOrCreateUsdRiAttribute(const MPlug &attrPlug, const UsdPrim &usdPrim, const std::string &attrName, const std::string &nameSpace="user", const bool translateMayaDoubleToUsdSinglePrecision=UsdMayaUserTaggedAttribute::GetFallbackTranslateMayaDoubleToUsdSinglePrecision())
Given an attrPlug, try to create a UsdRi attribute on usdPrim with the name attrName.
Represents a value type name, i.e.
Definition: valueTypeName.h:83
static PXRUSDMAYA_API bool WriteUserExportedAttributes(const MObject &mayaNode, const UsdPrim &usdPrim, const UsdTimeCode &usdTime, UsdUtilsSparseValueWriter *valueWriter=nullptr)
Given a Maya node mayaNode, inspect it for attributes tagged by the user for export to USD and write ...
static PXRUSDMAYA_API bool WriteClassInherits(const UsdPrim &usdPrim, const std::vector< std::string > &inheritClassNames)
Authors class inherits on usdPrim.
Scenegraph object for authoring and retrieving numeric, string, and array valued data, sampled over time.
Definition: attribute.h:176
Utility class that manages sparse authoring of a set of UsdAttributes.
static PXRUSDMAYA_API bool ReadMayaAttribute(const MFnDependencyNode &depNode, const MString &name, std::string *val)
Reads attribute name on depNode into val.
static PXRUSDMAYA_API bool WriteAPISchemaAttributesToPrim(const MObject &mayaObject, const UsdPrim &prim, UsdUtilsSparseValueWriter *valueWriter=nullptr)
Writes all of the adaptor API schema attributes from mayaObject onto the prim.
Token for efficient comparison, assignment, and hashing of known strings.
Definition: token.h:89
static bool GetFallbackTranslateMayaDoubleToUsdSinglePrecision()
Gets the fallback value for whether attribute types should be mapped from double precision types in M...
Represent a time value, which may be either numeric, holding a double value, or a sentinel value UsdT...
Definition: timeCode.h:85
static PXRUSDMAYA_API bool WriteArrayAttrsToInstancer(MFnArrayAttrsData &inputPointsData, const UsdGeomPointInstancer &instancer, const size_t numPrototypes, const UsdTimeCode &usdTime, UsdUtilsSparseValueWriter *valueWriter=nullptr)
Given inputPointsData (native Maya particle data), writes the arrays as point-instancer attributes on...
This struct contains helpers for writing USD (thus reading Maya data).
Definition: writeUtil.h:57
static PXRUSDMAYA_API UsdGeomPrimvar GetOrCreatePrimvar(const MPlug &attrPlug, UsdGeomImageable &imageable, const std::string &primvarName, const TfToken &interpolation=TfToken(), const int elementSize=-1, const bool translateMayaDoubleToUsdSinglePrecision=UsdMayaUserTaggedAttribute::GetFallbackTranslateMayaDoubleToUsdSinglePrecision())
Given an attrPlug, try to create a primvar on imageable with the name primvarName.
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 basic mathematical interval class.
Definition: interval.h:50
static PXRUSDMAYA_API bool SetUsdAttr(const MPlug &attrPlug, const UsdAttribute &usdAttr, const UsdTimeCode &usdTime, UsdUtilsSparseValueWriter *valueWriter=nullptr)
Given an attrPlug, determine it&#39;s value and set it on usdAttr at usdTime.
static PXRUSDMAYA_API UsdAttribute GetOrCreateUsdAttr(const MPlug &attrPlug, const UsdPrim &usdPrim, const std::string &attrName, const bool custom=false, const bool translateMayaDoubleToUsdSinglePrecision=UsdMayaUserTaggedAttribute::GetFallbackTranslateMayaDoubleToUsdSinglePrecision())
Given an attrPlug, try to create a USD attribute on usdPrim with the name attrName.
static constexpr UsdTimeCode Default()
Produce a UsdTimeCode representing the sentinel value for &#39;default&#39;.
Definition: timeCode.h:113
static PXRUSDMAYA_API VtValue GetVtValue(const MPlug &attrPlug, const SdfValueTypeName &typeName, const bool linearizeColors=true)
Given an attrPlug, reads its value and returns it as a wrapped VtValue.
static PXRUSDMAYA_API std::vector< double > GetTimeSamples(const GfInterval &frameRange, const std::set< double > &subframeOffsets, const double stride=1.0)
Gets an ordered list of frame samples for the given frameRange, advancing the time by stride on each ...
static PXRUSDMAYA_API bool WriteUVAsFloat2()
Returns whether the environment setting for writing the TexCoord types is set to true.
TfType represents a dynamic runtime type.
Definition: type.h:70
Encodes vectorized instancing of multiple, potentially animated, prototypes (object/instance masters)...
Schema wrapper for UsdAttribute for authoring and introspecting attributes that are primvars...
Definition: primvar.h:260
Base class for all prims that may require rendering or visualization of some sort.
Definition: imageable.h:74
Provides a container which may hold any type, and provides introspection and iteration over array typ...
Definition: value.h:182