All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
meshWriter.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 PXRUSDTRANSLATORS_MESH_WRITER_H
25 #define PXRUSDTRANSLATORS_MESH_WRITER_H
26 
28 
29 #include "pxr/pxr.h"
30 #include "usdMaya/primWriter.h"
31 
33 
34 #include "pxr/base/gf/vec2f.h"
35 #include "pxr/base/gf/vec3f.h"
36 #include "pxr/base/gf/vec4f.h"
37 #include "pxr/base/tf/token.h"
38 #include "pxr/base/vt/array.h"
39 #include "pxr/usd/sdf/path.h"
40 #include "pxr/usd/usd/timeCode.h"
41 #include "pxr/usd/usdGeom/gprim.h"
42 #include "pxr/usd/usdGeom/mesh.h"
43 #include "pxr/usd/usdGeom/primvar.h"
44 
45 #include <maya/MFnDependencyNode.h>
46 #include <maya/MFnMesh.h>
47 #include <maya/MString.h>
48 
49 #include <set>
50 #include <string>
51 
52 
53 PXR_NAMESPACE_OPEN_SCOPE
54 
55 
59 {
60 public:
62  const MFnDependencyNode& depNodeFn,
63  const SdfPath& usdPath,
64  UsdMayaWriteJobContext& jobCtx);
65 
66  void Write(const UsdTimeCode& usdTime) override;
67  bool ExportsGprims() const override;
68 
69  void PostExport() override;
70 
71 protected:
72  bool writeMeshAttrs(const UsdTimeCode& usdTime, UsdGeomMesh& primSchema);
73 
74 private:
75  bool isMeshValid();
76  void assignSubDivTagsToUSDPrim(MFnMesh& meshFn, UsdGeomMesh& primSchema);
77 
87  MObject writeSkinningData(UsdGeomMesh& primSchema);
88 
89  bool _GetMeshUVSetData(
90  const MObject& meshObj,
91  const MString& uvSetName,
92  VtArray<GfVec2f>* uvArray,
93  TfToken* interpolation,
94  VtArray<int>* assignmentIndices);
95 
96  bool _GetMeshColorSetData(
97  const MObject& meshObj,
98  const MString& colorSet,
99  bool isDisplayColor,
100  const VtArray<GfVec3f>& shadersRGBData,
101  const VtArray<float>& shadersAlphaData,
102  const VtArray<int>& shadersAssignmentIndices,
103  VtArray<GfVec3f>* colorSetRGBData,
104  VtArray<float>* colorSetAlphaData,
105  TfToken* interpolation,
106  VtArray<int>* colorSetAssignmentIndices,
107  MFnMesh::MColorRepresentation* colorSetRep,
108  bool* clamped);
109 
110  bool _createAlphaPrimVar(
111  UsdGeomGprim& primSchema,
112  const TfToken& name,
113  const UsdTimeCode& usdTime,
114  const VtArray<float>& data,
115  const TfToken& interpolation,
116  const VtArray<int>& assignmentIndices,
117  bool clamped);
118 
119  bool _createRGBPrimVar(
120  UsdGeomGprim& primSchema,
121  const TfToken& name,
122  const UsdTimeCode& usdTime,
123  const VtArray<GfVec3f>& data,
124  const TfToken& interpolation,
125  const VtArray<int>& assignmentIndices,
126  bool clamped);
127 
128  bool _createRGBAPrimVar(
129  UsdGeomGprim& primSchema,
130  const TfToken& name,
131  const UsdTimeCode& usdTime,
132  const VtArray<GfVec3f>& rgbData,
133  const VtArray<float>& alphaData,
134  const TfToken& interpolation,
135  const VtArray<int>& assignmentIndices,
136  bool clamped);
137 
138  bool _createUVPrimVar(
139  UsdGeomGprim& primSchema,
140  const TfToken& name,
141  const UsdTimeCode& usdTime,
142  const VtArray<GfVec2f>& data,
143  const TfToken& interpolation,
144  const VtArray<int>& assignmentIndices);
145 
149  bool _addDisplayPrimvars(
150  UsdGeomGprim& primSchema,
151  const UsdTimeCode& usdTime,
152  const MFnMesh::MColorRepresentation colorRep,
153  const VtArray<GfVec3f>& RGBData,
154  const VtArray<float>& AlphaData,
155  const TfToken& interpolation,
156  const VtArray<int>& assignmentIndices,
157  const bool clamped,
158  const bool authored);
159 
173  void _SetPrimvar(
174  const UsdGeomPrimvar& primvar,
175  const VtIntArray& indices,
176  const VtValue& values,
177  const VtValue& defaultValue,
178  const UsdTimeCode& usdTime);
179 
181  void _CleanupPrimvars();
182 
187  bool _IsMeshAnimated() const;
188 
191  static const GfVec2f _DefaultUV;
192 
195  static const GfVec3f _ShaderDefaultRGB;
196  static const float _ShaderDefaultAlpha;
197 
200  static const GfVec3f _ColorSetDefaultRGB;
201  static const float _ColorSetDefaultAlpha;
202  static const GfVec4f _ColorSetDefaultRGBA;
203 
205  MObject _skelInputMesh;
206 
209  std::set<std::string> _excludeColorSets;
210 };
211 
212 
213 PXR_NAMESPACE_CLOSE_SCOPE
214 
215 
216 #endif
Provides basic functionality and access to shared data for UsdMayaPrimWriters.
Exports Maya mesh objects (MFnMesh)as UsdGeomMesh prims, taking into account subd/poly, skinning, reference objects, UVs, and color sets.
Definition: meshWriter.h:58
Basic type for a vector of 3 float components.
Definition: vec3f.h:63
void PostExport() override
Post export function that runs before saving the stage.
Token for efficient comparison, assignment, and hashing of known strings.
Definition: token.h:89
Represent a time value, which may be either numeric, holding a double value, or a sentinel value UsdT...
Definition: timeCode.h:85
A path value used to locate objects in layers or scenegraphs.
Definition: path.h:287
Basic type for a vector of 4 float components.
Definition: vec4f.h:63
void Write(const UsdTimeCode &usdTime) override
Main export function that runs when the traversal hits the node.
Base class for all geometric primitives.
Definition: gprim.h:66
Basic type for a vector of 2 float components.
Definition: vec2f.h:63
Schema wrapper for UsdAttribute for authoring and introspecting attributes that are primvars...
Definition: primvar.h:260
Base class for all built-in and user-defined prim writers.
Definition: primWriter.h:64
Encodes a mesh surface whose definition and feature-set will converge with that of OpenSubdiv...
Definition: mesh.h:86
Provides a container which may hold any type, and provides introspection and iteration over array typ...
Definition: value.h:182
bool ExportsGprims() const override
Whether this prim writer directly create one or more gprims on the current model on the USD stage...