File indexing completed on 2025-01-18 10:04:42
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014 #ifndef _RWGltf_CafWriter_HeaderFiler
0015 #define _RWGltf_CafWriter_HeaderFiler
0016
0017 #include <TColStd_IndexedDataMapOfStringString.hxx>
0018 #include <TColStd_MapOfAsciiString.hxx>
0019 #include <TDF_LabelSequence.hxx>
0020 #include <TopTools_ShapeMapHasher.hxx>
0021 #include <RWGltf_DracoParameters.hxx>
0022 #include <RWGltf_GltfBufferView.hxx>
0023 #include <RWGltf_GltfFace.hxx>
0024 #include <RWGltf_WriterTrsfFormat.hxx>
0025 #include <RWMesh_CoordinateSystemConverter.hxx>
0026 #include <RWMesh_NameFormat.hxx>
0027 #include <XCAFPrs_Style.hxx>
0028 #include <Poly_Triangle.hxx>
0029
0030 #include <memory>
0031
0032 class Message_ProgressRange;
0033 class RWMesh_FaceIterator;
0034 class RWGltf_GltfOStreamWriter;
0035 class RWGltf_GltfMaterialMap;
0036 class RWGltf_GltfSceneNodeMap;
0037 class TDocStd_Document;
0038
0039
0040 class RWGltf_CafWriter : public Standard_Transient
0041 {
0042 DEFINE_STANDARD_RTTIEXT(RWGltf_CafWriter, Standard_Transient)
0043 public:
0044
0045
0046 struct Mesh
0047 {
0048 std::vector<Graphic3d_Vec3> NodesVec;
0049 std::vector<Graphic3d_Vec3> NormalsVec;
0050 std::vector<Graphic3d_Vec2> TexCoordsVec;
0051 std::vector<Poly_Triangle> IndicesVec;
0052 };
0053
0054
0055
0056
0057 Standard_EXPORT RWGltf_CafWriter (const TCollection_AsciiString& theFile,
0058 Standard_Boolean theIsBinary);
0059
0060
0061 Standard_EXPORT virtual ~RWGltf_CafWriter();
0062
0063
0064 const RWMesh_CoordinateSystemConverter& CoordinateSystemConverter() const { return myCSTrsf; }
0065
0066
0067 RWMesh_CoordinateSystemConverter& ChangeCoordinateSystemConverter() { return myCSTrsf; }
0068
0069
0070 void SetCoordinateSystemConverter (const RWMesh_CoordinateSystemConverter& theConverter) { myCSTrsf = theConverter; }
0071
0072
0073 bool IsBinary() const { return myIsBinary; }
0074
0075
0076 RWGltf_WriterTrsfFormat TransformationFormat() const { return myTrsfFormat; }
0077
0078
0079 void SetTransformationFormat (RWGltf_WriterTrsfFormat theFormat) { myTrsfFormat = theFormat; }
0080
0081
0082 RWMesh_NameFormat NodeNameFormat() const { return myNodeNameFormat; }
0083
0084
0085 void SetNodeNameFormat (RWMesh_NameFormat theFormat) { myNodeNameFormat = theFormat; }
0086
0087
0088 RWMesh_NameFormat MeshNameFormat() const { return myMeshNameFormat; }
0089
0090
0091 void SetMeshNameFormat (RWMesh_NameFormat theFormat) { myMeshNameFormat = theFormat; }
0092
0093
0094 bool IsForcedUVExport() const { return myIsForcedUVExport; }
0095
0096
0097 void SetForcedUVExport (bool theToForce) { myIsForcedUVExport = theToForce; }
0098
0099
0100 const XCAFPrs_Style& DefaultStyle() const { return myDefaultStyle; }
0101
0102
0103 void SetDefaultStyle (const XCAFPrs_Style& theStyle) { myDefaultStyle = theStyle; }
0104
0105
0106
0107
0108 Standard_Boolean ToEmbedTexturesInGlb() { return myToEmbedTexturesInGlb; }
0109
0110
0111 void SetToEmbedTexturesInGlb (Standard_Boolean theToEmbedTexturesInGlb) { myToEmbedTexturesInGlb = theToEmbedTexturesInGlb; }
0112
0113
0114 bool ToMergeFaces() const { return myToMergeFaces; }
0115
0116
0117
0118 void SetMergeFaces (bool theToMerge) { myToMergeFaces = theToMerge; }
0119
0120
0121 bool ToSplitIndices16() const { return myToSplitIndices16; }
0122
0123
0124
0125
0126 void SetSplitIndices16 (bool theToSplit) { myToSplitIndices16 = theToSplit; }
0127
0128
0129 bool ToParallel() const { return myToParallel; }
0130
0131
0132 void SetParallel (bool theToParallel) { myToParallel = theToParallel; }
0133
0134
0135 const RWGltf_DracoParameters& CompressionParameters() const { return myDracoParameters; }
0136
0137
0138 void SetCompressionParameters(const RWGltf_DracoParameters& theDracoParameters) { myDracoParameters = theDracoParameters; }
0139
0140
0141
0142
0143
0144
0145
0146
0147
0148
0149
0150
0151 Standard_EXPORT virtual bool Perform (const Handle(TDocStd_Document)& theDocument,
0152 const TDF_LabelSequence& theRootLabels,
0153 const TColStd_MapOfAsciiString* theLabelFilter,
0154 const TColStd_IndexedDataMapOfStringString& theFileInfo,
0155 const Message_ProgressRange& theProgress);
0156
0157
0158
0159
0160
0161
0162
0163 Standard_EXPORT virtual bool Perform (const Handle(TDocStd_Document)& theDocument,
0164 const TColStd_IndexedDataMapOfStringString& theFileInfo,
0165 const Message_ProgressRange& theProgress);
0166
0167 protected:
0168
0169
0170
0171
0172
0173
0174
0175
0176 Standard_EXPORT virtual bool writeBinData (const Handle(TDocStd_Document)& theDocument,
0177 const TDF_LabelSequence& theRootLabels,
0178 const TColStd_MapOfAsciiString* theLabelFilter,
0179 const Message_ProgressRange& theProgress);
0180
0181
0182
0183
0184
0185
0186
0187
0188 Standard_EXPORT virtual bool writeJson (const Handle(TDocStd_Document)& theDocument,
0189 const TDF_LabelSequence& theRootLabels,
0190 const TColStd_MapOfAsciiString* theLabelFilter,
0191 const TColStd_IndexedDataMapOfStringString& theFileInfo,
0192 const Message_ProgressRange& theProgress);
0193
0194 protected:
0195
0196
0197 Standard_EXPORT virtual Standard_Boolean toSkipFaceMesh (const RWMesh_FaceIterator& theFaceIter);
0198
0199
0200
0201
0202
0203 Standard_EXPORT virtual TCollection_AsciiString formatName (RWMesh_NameFormat theFormat,
0204 const TDF_Label& theLabel,
0205 const TDF_Label& theRefLabel) const;
0206
0207
0208
0209
0210
0211
0212
0213 Standard_EXPORT virtual void saveNodes (RWGltf_GltfFace& theGltfFace,
0214 std::ostream& theBinFile,
0215 const RWMesh_FaceIterator& theFaceIter,
0216 Standard_Integer& theAccessorNb,
0217 const std::shared_ptr<RWGltf_CafWriter::Mesh>& theMesh) const;
0218
0219
0220
0221
0222
0223
0224
0225 Standard_EXPORT virtual void saveNormals (RWGltf_GltfFace& theGltfFace,
0226 std::ostream& theBinFile,
0227 RWMesh_FaceIterator& theFaceIter,
0228 Standard_Integer& theAccessorNb,
0229 const std::shared_ptr<RWGltf_CafWriter::Mesh>& theMesh) const;
0230
0231
0232
0233
0234
0235
0236
0237 Standard_EXPORT virtual void saveTextCoords (RWGltf_GltfFace& theGltfFace,
0238 std::ostream& theBinFile,
0239 const RWMesh_FaceIterator& theFaceIter,
0240 Standard_Integer& theAccessorNb,
0241 const std::shared_ptr<RWGltf_CafWriter::Mesh>& theMesh) const;
0242
0243
0244
0245
0246
0247
0248
0249 Standard_EXPORT virtual void saveIndices (RWGltf_GltfFace& theGltfFace,
0250 std::ostream& theBinFile,
0251 const RWMesh_FaceIterator& theFaceIter,
0252 Standard_Integer& theAccessorNb,
0253 const std::shared_ptr<RWGltf_CafWriter::Mesh>& theMesh);
0254
0255 protected:
0256
0257
0258
0259 Standard_EXPORT virtual void writePositions (const RWGltf_GltfFace& theGltfFace);
0260
0261
0262
0263 Standard_EXPORT virtual void writeNormals (const RWGltf_GltfFace& theGltfFace);
0264
0265
0266
0267 Standard_EXPORT virtual void writeTextCoords (const RWGltf_GltfFace& theGltfFace);
0268
0269
0270
0271 Standard_EXPORT virtual void writeIndices (const RWGltf_GltfFace& theGltfFace);
0272
0273 protected:
0274
0275
0276
0277 Standard_EXPORT virtual void writeAccessors (const RWGltf_GltfSceneNodeMap& theSceneNodeMap);
0278
0279
0280 Standard_EXPORT virtual void writeAnimations();
0281
0282
0283
0284 Standard_EXPORT virtual void writeAsset (const TColStd_IndexedDataMapOfStringString& theFileInfo);
0285
0286
0287
0288 Standard_EXPORT virtual void writeBufferViews (const Standard_Integer theBinDataBufferId);
0289
0290
0291 Standard_EXPORT virtual void writeBuffers();
0292
0293
0294 Standard_EXPORT virtual void writeExtensions();
0295
0296
0297
0298
0299 Standard_EXPORT virtual void writeImages (const RWGltf_GltfSceneNodeMap& theSceneNodeMap);
0300
0301
0302
0303
0304 Standard_EXPORT virtual void writeMaterials (const RWGltf_GltfSceneNodeMap& theSceneNodeMap);
0305
0306
0307
0308
0309 Standard_EXPORT virtual void writeMeshes (const RWGltf_GltfSceneNodeMap& theSceneNodeMap);
0310
0311
0312
0313
0314
0315
0316 Standard_EXPORT virtual void writePrimArray (const RWGltf_GltfFace& theGltfFace,
0317 const TCollection_AsciiString& theName,
0318 const int theDracoBufInd,
0319 bool& theToStartPrims);
0320
0321
0322
0323
0324
0325
0326
0327 Standard_EXPORT virtual void writeNodes (const Handle(TDocStd_Document)& theDocument,
0328 const TDF_LabelSequence& theRootLabels,
0329 const TColStd_MapOfAsciiString* theLabelFilter,
0330 const RWGltf_GltfSceneNodeMap& theSceneNodeMap,
0331 NCollection_Sequence<Standard_Integer>& theSceneRootNodeInds);
0332
0333
0334 Standard_EXPORT virtual void writeSamplers();
0335
0336
0337
0338 Standard_EXPORT virtual void writeScene (const Standard_Integer theDefSceneId);
0339
0340
0341
0342 Standard_EXPORT virtual void writeScenes (const NCollection_Sequence<Standard_Integer>& theSceneRootNodeInds);
0343
0344
0345 Standard_EXPORT virtual void writeSkins();
0346
0347
0348
0349
0350 Standard_EXPORT virtual void writeTextures (const RWGltf_GltfSceneNodeMap& theSceneNodeMap);
0351
0352 protected:
0353
0354
0355 struct RWGltf_StyledShape
0356 {
0357 TopoDS_Shape Shape;
0358 XCAFPrs_Style Style;
0359
0360 RWGltf_StyledShape()
0361 {}
0362 explicit RWGltf_StyledShape(const TopoDS_Shape& theShape) : Shape(theShape)
0363 {}
0364 explicit RWGltf_StyledShape(const TopoDS_Shape& theShape,
0365 const XCAFPrs_Style& theStyle) : Shape(theShape), Style(theStyle)
0366 {}
0367 bool operator==(const RWGltf_StyledShape& theStyledShape) const
0368 {
0369 return Shape.IsSame(theStyledShape.Shape)
0370 && Style.IsEqual(theStyledShape.Style);
0371 }
0372 };
0373
0374 struct Hasher
0375 {
0376 size_t operator()(const RWGltf_StyledShape& theShape) const noexcept
0377 {
0378 return std::hash<TopoDS_Shape>{}(theShape.Shape);
0379 }
0380
0381 bool operator()(const RWGltf_StyledShape& theShape1,
0382 const RWGltf_StyledShape& theShape2) const noexcept
0383 {
0384 return theShape1 == theShape2;
0385 }
0386 };
0387
0388 typedef NCollection_IndexedDataMap<RWGltf_StyledShape, Handle(RWGltf_GltfFaceList), Hasher> ShapeToGltfFaceMap;
0389
0390 protected:
0391
0392 TCollection_AsciiString myFile;
0393 TCollection_AsciiString myBinFileNameFull;
0394 TCollection_AsciiString myBinFileNameShort;
0395 RWGltf_WriterTrsfFormat myTrsfFormat;
0396 RWMesh_NameFormat myNodeNameFormat;
0397 RWMesh_NameFormat myMeshNameFormat;
0398 Standard_Boolean myIsBinary;
0399 Standard_Boolean myIsForcedUVExport;
0400 Standard_Boolean myToEmbedTexturesInGlb;
0401 Standard_Boolean myToMergeFaces;
0402 Standard_Boolean myToSplitIndices16;
0403 RWMesh_CoordinateSystemConverter myCSTrsf;
0404 XCAFPrs_Style myDefaultStyle;
0405
0406 std::shared_ptr<RWGltf_GltfOStreamWriter> myWriter;
0407 Handle(RWGltf_GltfMaterialMap) myMaterialMap;
0408 RWGltf_GltfBufferView myBuffViewPos;
0409 RWGltf_GltfBufferView myBuffViewNorm;
0410 RWGltf_GltfBufferView myBuffViewTextCoord;
0411 RWGltf_GltfBufferView myBuffViewInd;
0412 ShapeToGltfFaceMap myBinDataMap;
0413 int64_t myBinDataLen64;
0414
0415 std::vector<RWGltf_GltfBufferView> myBuffViewsDraco;
0416 Standard_Boolean myToParallel;
0417 RWGltf_DracoParameters myDracoParameters;
0418 };
0419
0420 #endif