All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
exportTranslator.h
1 //
2 // Copyright 2019 Google LLC
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 
25 #ifndef USDDRACO_EXPORT_TRANSLATOR_H
26 #define USDDRACO_EXPORT_TRANSLATOR_H
27 
28 #include "attributeDescriptor.h"
29 #include "exportAttribute.h"
30 #include "flag.h"
31 
32 #include "pxr/pxr.h"
33 #include "pxr/usd/usdGeom/mesh.h"
34 
35 #include <draco/mesh/mesh.h>
36 
37 
38 PXR_NAMESPACE_OPEN_SCOPE
39 
40 
46 public:
48  static bool Translate(const UsdGeomMesh &usdMesh,
49  draco::Mesh *dracoMesh,
50  UsdDracoFlag<bool> preservePolygons,
51  UsdDracoFlag<bool> preservePositionOrder,
52  UsdDracoFlag<bool> preserveHoles);
53 
58  static std::unique_ptr<UsdDracoExportAttributeInterface>
59  CreateAttributeFrom(const UsdGeomPrimvar &primvar);
60 
61 private:
63  draco::Mesh *dracoMesh);
64  bool _Translate(UsdDracoFlag<bool> preservePolygons,
65  UsdDracoFlag<bool> preservePositionOrder,
66  UsdDracoFlag<bool> preserveHoles);
67  bool _CheckDescriptors() const;
68  void _GetAttributesFromMesh();
69  void _GetConnectivityFromMesh();
70  void _CheckUnsupportedPrimvar(const UsdGeomPrimvar &primvar);
71  bool _CheckData() const;
72  bool _CheckPrimvarData(
73  const UsdDracoExportAttributeInterface &attribute) const;
74  void _ConfigureHelperAttributes(UsdDracoFlag<bool> preservePolygons,
75  UsdDracoFlag<bool> preservePositionOrder,
76  UsdDracoFlag<bool> preserveHoles);
77  void _SetNumPointsToMesh() const;
78  void _SetAttributesToMesh();
79  void _SetPointMapsToMesh();
80  void _Deduplicate() const;
81  bool _HasTrianglesOnly() const;
82  bool _SubdivisionRefersToPositions() const;
83  bool _SubdivisionRefersToFaces() const;
84  static size_t _Triangulate(size_t triIndex, size_t triCorner);
85  static bool _IsNewEdge(size_t triCount, size_t triIndex, size_t triCorner);
86 
87 private:
88  const UsdGeomMesh &_usdMesh;
89  draco::Mesh *_dracoMesh;
90 
91  // Named attributes.
95 
96  // Helper attributes that allow Draco to support USD geometries that are
97  // not supported out of the box, such as quads and hole indices.
101 
102  // Generic attributes.
103  std::vector<std::unique_ptr<UsdDracoExportAttributeInterface>>
104  _genericAttributes;
105 
106  VtIntArray _faceVertexCounts;
107  VtIntArray _faceVertexIndices;
108  VtIntArray _holeIndices;
109 
110  // Flag that indicates that there are unsupported primvars in the mesh
111  // that require position order to be preserved.
112  bool _unsupportedPrimvarsReferToPositions;
113 };
114 
115 PXR_NAMESPACE_CLOSE_SCOPE
116 
117 #endif // USDDRACO_EXPORT_TRANSLATOR_H
Stores command-line flag value and whether it has been explicitly specified by the user...
Definition: flag.h:38
static std::unique_ptr< UsdDracoExportAttributeInterface > CreateAttributeFrom(const UsdGeomPrimvar &primvar)
Creates and returns an export attribute from USD primvar or a nullptr if primvar cannot be exported t...
Translates USD mesh to Draco mesh.
static bool Translate(const UsdGeomMesh &usdMesh, draco::Mesh *dracoMesh, UsdDracoFlag< bool > preservePolygons, UsdDracoFlag< bool > preservePositionOrder, UsdDracoFlag< bool > preserveHoles)
Translates USD mesh to Draco mesh and returns true on success.
Base class for UsdDracoExportAttribute&lt;T&gt; classes.
Schema wrapper for UsdAttribute for authoring and introspecting attributes that are primvars...
Definition: primvar.h:260
Encodes a mesh surface whose definition and feature-set will converge with that of OpenSubdiv...
Definition: mesh.h:86