Atoms Crowd  7.0.0
UsdExporterUtils.h
1 #pragma once
2 // ===========================================================================
3 // Copyright (c) 2015 Toolchefs Ltd. All rights reserved.
4 //
5 // Use of this software is subject to the terms of the Toolchefs license
6 // agreement provided at the time of installation or download, or which
7 // otherwise accompanies this software in either electronic or hard copy form.
8 // ===========================================================================
9 #ifndef ATOMS_UNREAL
10 #ifndef NOMINMAX
11 #define NOMINMAX
12 #endif
13 
14 #include <pxr/pxr.h>
15 #include <pxr/usd/usd/stage.h>
16 #include <pxr/usd/usd/modelAPI.h>
17 #include <pxr/usd/usd/editContext.h>
18 #if (PXR_MINOR_VERSION < 20)
19 #include <pxr/usd/usd/references.h>
20 #else
21 #include <pxr/usd/usd/payloads.h>
22 #endif
23 #include <pxr/usd/kind/registry.h>
24 #include <pxr/usd/usdGeom/scope.h>
25 #include <pxr/usd/usdGeom/metrics.h>
26 #include <pxr/usd/usdGeom/xform.h>
27 #include <pxr/usd/usdGeom/mesh.h>
28 #include <pxr/usd/usdGeom/primvarsAPI.h>
29 #include <pxr/usd/usdSkel/skeleton.h>
30 #include <pxr/usd/usdSkel/blendShape.h>
31 #include <pxr/usd/usdSkel/bindingAPI.h>
32 #include <pxr/usd/usdSkel/animation.h>
33 #include <pxr/usd/sdf/valueTypeName.h>
34 #include <pxr/usd/sdf/path.h>
35 #include <pxr/usd/usdShade/materialBindingAPI.h>
36 #include <pxr/base/tf/token.h>
37 #include <pxr/base/gf/matrix4d.h>
38 #include <pxr/base/vt/types.h>
39 #include <pxr/base/vt/value.h>
40 
41 #include <Atoms/Usd/Globals.h>
42 #include <AtomsCore/AtomsMath.h>
43 #include <AtomsCore/Metadata/MapMetadata.h>
44 #include <AtomsCore/Metadata/ArrayMetadata.h>
45 #include <AtomsCore/Metadata/MeshMetadata.h>
46 #include <AtomsCore/Joint.h>
47 #include <AtomsCore/Skeleton.h>
48 #include <Atoms/Variations.h>
49 
50 
51 
52 struct MaterialData {
53  AtomsCore::Vector3 diffuseColorValue;
54  AtomsCore::Vector3 specularColorValue;
55  std::string diffusePathValue;
56  std::string specularPathValue;
57  std::string normalPathValue;
58  double diffuseWeight;
59  double specularWeight;
60  double cosinePowerValue;
61  double specularEccentricity;
62 
63  MaterialData() :
64  diffusePathValue(""),
65  diffuseColorValue(AtomsCore::Vector3(0.0, 1.0, 0.0)),
66  specularPathValue(""),
67  specularColorValue(AtomsCore::Vector3(1.0, 1.0, 1.0)),
68  normalPathValue(""),
69  diffuseWeight(0.8),
70  specularWeight(0.2),
71  cosinePowerValue(0.5),
72  specularEccentricity(0.5)
73  {
74 
75  }
76 };
77 
78 
79 struct TransformData {
80  PXR_NS::VtVec3fArray t;
81  PXR_NS::VtVec3hArray s;
82  PXR_NS::VtQuatfArray r;
83  PXR_NS::GfMatrix4d w;
84  PXR_NS::TfToken v;
85  AtomsMath::Box3f box;
86  AtomsCore::MapMetadata metadata;
87  bool useVisibility;
88 
89  TransformData() :
90  v(PXR_NS::UsdGeomTokensType().inherited),
91  useVisibility(true)
92  {
93  t.clear();
94  s.clear();
95  r.clear();
96  w.SetIdentity();
97  box.makeEmpty();
98  metadata.clear();
99  }
100 };
101 
102 
104  PXR_NS::VtTokenArray blendShapeNames;
105  std::map<int, PXR_NS::VtFloatArray> blendShapeWeights;
106 
108  {
109  blendShapeNames.clear();
110  blendShapeWeights.clear();
111  }
112 };
113 
115 {
116  std::string agentType;
117  std::string variation;
118  std::string lod;
119  std::string groupName;
120  int variationSeed;
121  int sourceGroupId;
122  std::vector<std::string> variationsOverrides;
123  std::vector<std::string> variationsGeometryFilters;
124  std::vector<std::string> variationsGeoMatOverrides;
125  int groupId;
126  std::map<int, TransformData> transforms;
127  BlendShapeData blendShapes;
128 };
129 
130 
131 std::string cleanNameForUSD(
132  const std::string& name);
133 
134 PXR_NS::GfMatrix4d convertAtomsMatrix(
135  const AtomsCore::Matrix& mtx);
136 
137 AtomsCore::Matrix convertUsdMatrix(
138  const PXR_NS::GfMatrix4d& mtx);
139 
140 void convertMaterial(
141  const PXR_NS::UsdStageRefPtr& stage,
142  const std::string& name,
143  const std::string& parent,
144  MaterialData& materialData,
145  PXR_NS::UsdShadeMaterial& material);
146 
147 
148 std::string buildJointFullPath(
149  const AtomsCore::Joint& j);
150 
151 
152 std::vector<std::string> buildJointNamesFromSkeleton(
153  const AtomsCore::Skeleton& skeleton);
154 
155 
156 std::vector<std::string> convertAtomsSkeleton(
157  const AtomsCore::Skeleton& atomsSkeleton,
158  const PXR_NS::UsdSkelSkeleton& skel);
159 
160 std::vector<std::string> saveAtomsSkeleton(
161  const AtomsCore::Skeleton& atomsSkeleton,
162  const std::string& skeletonOutput,
163  const std::string& name);
164 
165 
166 void atomsMeshToUsdMesh(
167  const AtomsUtils::Mesh& atomsMesh,
168  PXR_NS::UsdGeomMesh& meshPrim,
169  const AtomsCore::Matrix& worldMatrix);
170 
171 
172 void setupSkinWeights(
173  AtomsPtr<const AtomsCore::MapMetadata> geoMap,
174  PXR_NS::UsdGeomMesh& meshPrim);
175 
176 
177 void setMetadataPrimVar(
178  PXR_NS::UsdGeomPrimvarsAPI& primvarsApi,
179  const PXR_NS::TfToken& primVarName,
180  const std::string& metaName,
181  unsigned int metaTypeId,
182  AtomsPtr<const AtomsCore::MapMetadata> meta,
183  int* frame = nullptr);
184 
185 void setMetadataAsAttributes(
186  PXR_NS::UsdPrim& primvarsApi,
187  const std::string& metaName,
188  const AtomsPtr<AtomsCore::Metadata>& meta,
189  int* frame = nullptr);
190 
191 
192 std::vector<std::string> getBlendShapeNames(
193  const Atoms::Variations& variationMap,
194  const std::string& agentTypeName,
195  const std::string& variationName);
196 
197 
198 void atomsBlendShapesToUsdBlendShapes(
199  const PXR_NS::UsdStageRefPtr& stage,
200  PXR_NS::UsdGeomMesh& meshPrim,
201  const AtomsUtils::Mesh& atomsMesh,
202  AtomsPtr<const AtomsCore::ArrayMetadata>& blendShapes,
203  const std::string& blendShapeName);
204 
205 
206 void processChildMesh(
207  const PXR_NS::UsdStageRefPtr& stage,
208  const std::string& childPath,
209  AtomsPtr<const AtomsCore::MapMetadata>& currentChild,
210  bool useDefaultMaterial,
211  const std::string& blendShapeName,
212  const std::string& outAssetFolder,
213  bool mergeTransformAndShape,
214  PXR_NS::SdfPathVector& meshesPaths);
215 
216 bool saveAtomsMesh(
217  const AtomsCore::MapMetadata* atomsMesh,
218  const std::string& putputPath,
219  const std::string& name,
220  AtomsCore::MapMetadata* parameters);
221 
222 PXR_NS::UsdStageRefPtr createNewUSDStage(const std::string& path);
223 
224 #endif
Variations class.
Definition: Variations.h:839
Joint class.
Definition: Joint.h:30
MapMetadata class.
Definition: MapMetadata.h:24
void clear()
Clear map.
Skeleton class.
Definition: Skeleton.h:68
Mesh class.
Definition: Mesh.h:30
AtomsMath::Vector3 Vector3
Vector3 class.
Definition: AtomsMath.h:57
AtomsMath::Matrix Matrix
Matrix class.
Definition: AtomsMath.h:63
Definition: UsdExporterUtils.h:103
Definition: UsdExporterUtils.h:52
Definition: UsdExporterUtils.h:79
Definition: UsdExporterUtils.h:115