1 // Author: Kirill Gavrilov
2 // Copyright (c) 2018-2019 OPEN CASCADE SAS
4 // This file is part of Open CASCADE Technology software library.
6 // This library is free software; you can redistribute it and/or modify it under
7 // the terms of the GNU Lesser General Public License version 2.1 as published
8 // by the Free Software Foundation, with special exception defined in the file
9 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
10 // distribution for complete text of the license and disclaimer of any warranty.
12 // Alternatively, this file may be used under the terms of Open CASCADE
13 // commercial license or contractual agreement.
15 #include <RWGltf_GltfLatePrimitiveArray.hxx>
17 #include <RWGltf_MaterialMetallicRoughness.hxx>
18 #include <RWGltf_MaterialCommon.hxx>
20 #include <Message.hxx>
21 #include <Message_Messenger.hxx>
22 #include <OSD_OpenFile.hxx>
23 #include <Standard_ArrayStreamBuffer.hxx>
27 IMPLEMENT_STANDARD_RTTIEXT(RWGltf_GltfLatePrimitiveArray, Poly_Triangulation)
29 // =======================================================================
30 // function : RWGltf_GltfLatePrimitiveArray
32 // =======================================================================
33 RWGltf_GltfLatePrimitiveArray::RWGltf_GltfLatePrimitiveArray (const TCollection_AsciiString& theId,
34 const TCollection_AsciiString& theName)
35 : Poly_Triangulation (3, 1, false),
38 myPrimMode (RWGltf_GltfPrimitiveMode_UNKNOWN)
40 SetBoundingBox (Bnd_Box());
43 // =======================================================================
44 // function : ~RWGltf_GltfLatePrimitiveArray
46 // =======================================================================
47 RWGltf_GltfLatePrimitiveArray::~RWGltf_GltfLatePrimitiveArray()
52 // =======================================================================
53 // function : BaseColor
55 // =======================================================================
56 Quantity_ColorRGBA RWGltf_GltfLatePrimitiveArray::BaseColor() const
58 if (!myMaterialPbr.IsNull())
60 return myMaterialPbr->BaseColor;
62 else if (!myMaterialCommon.IsNull())
64 return Quantity_ColorRGBA (myMaterialCommon->DiffuseColor, 1.0f - myMaterialCommon->Transparency);
66 return Quantity_ColorRGBA();
69 // =======================================================================
70 // function : AddPrimArrayData
72 // =======================================================================
73 RWGltf_GltfPrimArrayData& RWGltf_GltfLatePrimitiveArray::AddPrimArrayData (RWGltf_GltfArrayType theType)
75 if (theType == RWGltf_GltfArrayType_Position)
77 // make sure positions go first
78 myData.Prepend (RWGltf_GltfPrimArrayData (theType));
79 return myData.ChangeFirst();
81 else if (theType == RWGltf_GltfArrayType_Indices)
83 // make sure indexes go after vertex positions but before any other vertex attributes
84 if (myData.First().Type == RWGltf_GltfArrayType_Position)
86 myData.InsertAfter (myData.Lower(), RWGltf_GltfPrimArrayData (theType));
87 return myData.ChangeValue (myData.Lower() + 1);
91 myData.Prepend (RWGltf_GltfPrimArrayData (theType));
92 return myData.ChangeFirst();
97 myData.Append (RWGltf_GltfPrimArrayData (theType));
98 return myData.ChangeLast();
102 // =======================================================================
103 // function : SetBoundingBox
105 // =======================================================================
106 void RWGltf_GltfLatePrimitiveArray::SetBoundingBox (const Bnd_Box& theBox)
112 Poly_Triangulation::myNodes = TColgp_Array1OfPnt();
113 Poly_Triangulation::myTriangles = Poly_Array1OfTriangle();
117 // define 8 nodes so that AABB will be huge enough to include mesh even with transformation applied
118 Poly_Triangulation::myNodes.Resize (1, 8, false);
119 const gp_Pnt aMin = theBox.CornerMin();
120 const gp_Pnt aMax = theBox.CornerMax();
121 Poly_Triangulation::ChangeNode(1).SetCoord(aMin.X(), aMin.Y(), aMin.Z());
122 Poly_Triangulation::ChangeNode(2).SetCoord(aMax.X(), aMax.Y(), aMax.Z());
123 Poly_Triangulation::ChangeNode(3).SetCoord(aMin.X(), aMin.Y(), aMax.Z());
124 Poly_Triangulation::ChangeNode(4).SetCoord(aMin.X(), aMax.Y(), aMax.Z());
125 Poly_Triangulation::ChangeNode(5).SetCoord(aMax.X(), aMax.Y(), aMin.Z());
126 Poly_Triangulation::ChangeNode(6).SetCoord(aMax.X(), aMin.Y(), aMin.Z());
127 Poly_Triangulation::ChangeNode(7).SetCoord(aMin.X(), aMax.Y(), aMin.Z());
128 Poly_Triangulation::ChangeNode(8).SetCoord(aMax.X(), aMin.Y(), aMax.Z());
130 Poly_Triangulation::myTriangles.Resize (1, 1, false);
131 Poly_Triangulation::ChangeTriangle (1).Set (1, 2, 1);
132 //Poly_Triangulation::myTriangles = Poly_Array1OfTriangle();