HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
GLTF_Exporter.h
Go to the documentation of this file.
1 #ifndef __GLTF_Exporter_h__
2 #define __GLTF_Exporter_h__
3 
4 #include "GLTFZ_API.h"
5 #include "GLTF_AnimationData.h"
6 #include "GLTF_ErrorManager.h"
7 #include "GLTF_ExportOptions.h"
8 #include "GLTF_Types.h"
9 #include "GLTF_Writer.h"
10 
11 #include <GA/GA_ElementGroup.h>
12 #include <GA/GA_Types.h>
13 #include <UT/UT_Array.h>
14 #include <UT/UT_ArrayStringMap.h>
15 #include <UT/UT_Optional.h>
16 #include <UT/UT_SharedPtr.h>
17 #include <UT/UT_StringHolder.h>
18 
19 class GLTF_Codec;
20 class GEO_PrimCamera;
21 class GU_Detail;
22 class GU_PrimPacked;
23 class OBJ_Camera;
24 class OBJ_Light;
25 class OBJ_Node;
26 class OP_Operator;
27 class SOP_Node;
28 class UT_InfoTree;
29 
31 {
32 public:
33 
34  GLTF_Writer& getWriter() { return myWriter; }
35  GLTF_ExportOptions& getExportOptions() { return myOptions; }
36  const GLTF_ErrorManager& getErrorManager() { return myErrors; }
37 
38  void setGltfFile(const char* filepath)
39  {
40  myExportFilePath = filepath;
41  }
42 
44  {
45  myExportingTime = time;
46  }
47 
48  bool exportObjectGraph(
49  UT_Array<OBJ_Node*>& root_obj_nodes);
50 
51  bool exportSop(
52  SOP_Node& sop);
53 
54  bool exportDetail(
55  const GU_Detail& gdp);
56 
57  bool exportFrameAnimData(
58  const GLTF_Index anim_id,
59  const fpreal time,
60  const fpreal keyframe);
61 
62 private:
63 
64  bool doExportObjectGraph(
65  OBJ_Node& obj_node,
66  UT_Optional<GLTF_Index> parent_id);
67 
68  bool doExportObjectCamera(
69  OBJ_Camera& camera,
70  const GLTF_Index* parent_id,
71  GLTF_Index* new_node_id,
72  const char* new_node_name);
73 
74  bool doExportObjectLight(
75  OBJ_Light& light,
76  const GLTF_Index* parent_id,
77  GLTF_Index* new_node_id,
78  const char* new_node_name);
79 
80  bool doExportSop(
81  SOP_Node& sop);
82 
83  bool doExportDetail(
84  const GU_Detail& gdp,
85  const char* detail_name=nullptr);
86 
87  bool doExportNode(
88  const GU_Detail& gdp,
89  const GLTF_Index* parent_id,
90  GLTF_Index* node_id,
91  const char* node_name);
92 
93  bool doExportPackedPrimitive(
94  const GU_Detail& gdp,
95  const GU_PrimPacked& prim,
96  const GLTF_Index* parent_id,
97  GLTF_Index* exported_node);
98 
99  bool doExportSopCamera(
100  const GEO_PrimCamera& prim_cam,
101  const GLTF_Index node_id,
102  const char* node_name);
103 
104  bool doExportMesh(
105  const GU_Detail& src_gdp,
106  GLTF_Index &mesh_id);
107 
108  bool doExportMeshPrimitives(
109  const GU_Detail& gdp,
110  GLTF_Index mesh_id);
111 
112  bool doExportAssignedMaterial(
113  const GU_Detail& gdp,
114  const GLTF_Index mesh_id,
115  const GLTF_Index prim_id);
116 
117 private:
118 
119  bool exportGltfExtrasDictAttrib(
120  const GU_Detail& gdp,
121  const UT_StringHolder& attrib_name,
122  GA_AttributeOwner owner,
123  GLTF_Index prop_index,
124  GA_Offset attrib_offset = GA_DETAIL_OFFSET);
125 
126  bool traverseAndExportPathAttribDefinedSceneGraph(
127  const UT_InfoTree& graph,
128  const UT_StringHolder& node_path,
129  const GLTF_Index* parent_id,
130  const UT_ArrayStringMap<int>& nodes_map,
131  UT_Array<GA_PrimitiveGroup>& prim_groups,
132  const GU_Detail& gdp);
133 
134  void compensateForParentTransforms(
135  const GLTF_Index node_id,
136  const GLTF_Index* parent_node_id=nullptr);
137 
138 private:
139 
141  createMatchingMeshCodec();
143  createMatchingMaterialCodec(
144  const char* matname,
145  const OP_Operator* mat_op);
146 
147 private:
148 
149  UT_StringHolder myExportFilePath;
150 
151  GLTF_Writer myWriter;
152  GLTF_ExportOptions myOptions;
153  GLTF_ErrorManager myErrors;
154 
155  fpreal myExportingTime;
156 };
157 
158 #endif // __GLTF_Exporter_h__
GT_API const UT_StringHolder time
void setGltfFile(const char *filepath)
Definition: GLTF_Exporter.h:38
std::optional< T > UT_Optional
Definition: UT_Optional.h:26
GA_Size GA_Offset
Definition: GA_Types.h:653
GLTF_Writer & getWriter()
Definition: GLTF_Exporter.h:34
std::shared_ptr< T > UT_SharedPtr
Wrapper around std::shared_ptr.
Definition: UT_SharedPtr.h:36
GLTF_ExportOptions & getExportOptions()
Definition: GLTF_Exporter.h:35
std::size_t GLTF_Index
Definition: GLTF_Types.h:13
void setExportingTime(const fpreal time)
Definition: GLTF_Exporter.h:43
GA_AttributeOwner
Definition: GA_Types.h:35
fpreal64 fpreal
Definition: SYS_Types.h:283
#define GA_DETAIL_OFFSET
Definition: GA_Types.h:698
#define GLTFZ_API
Definition: GLTFZ_API.h:37
const GLTF_ErrorManager & getErrorManager()
Definition: GLTF_Exporter.h:36