Skip to content

Commit c1fa59b

Browse files
committed
IO_Assimp: use OccHandle and makeOccHandle()
1 parent 93eeabc commit c1fa59b

File tree

2 files changed

+24
-23
lines changed

2 files changed

+24
-23
lines changed

src/io_assimp/io_assimp_reader.cpp

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ bool deep_aiNodeTransformationHasScaling(const aiNode* node)
9494
|| scaling.x < 0. || scaling.y < 0. || scaling.z < 0.
9595
)
9696
{
97-
//std::cout << "[TRACE] hasScaling: " << scaling.x << " " << scaling.y << " " <<scaling.z << std::endl;
97+
//std::cout << "[TRACE] hasScaling: " << scaling.x << " " << scaling.y << " " << scaling.z << std::endl;
9898
return true;
9999
}
100100

@@ -121,9 +121,9 @@ gp_Trsf toOccTrsf(const aiMatrix4x4& matrix)
121121
const aiVector3D scaling = aiMatrixScaling(matrix);
122122
gp_Trsf trsf;
123123
trsf.SetValues(
124-
matrix.a1 / scaling.x, matrix.a2 / scaling.x, matrix.a3 / scaling.x, matrix.a4,
125-
matrix.b1 / scaling.y, matrix.b2 / scaling.y, matrix.b3 / scaling.y, matrix.b4,
126-
matrix.c1 / scaling.z, matrix.c2 / scaling.z, matrix.c3 / scaling.z, matrix.c4
124+
matrix.a1 / scaling.x, matrix.a2 / scaling.x, matrix.a3 / scaling.x, matrix.a4,
125+
matrix.b1 / scaling.y, matrix.b2 / scaling.y, matrix.b3 / scaling.y, matrix.b4,
126+
matrix.c1 / scaling.z, matrix.c2 / scaling.z, matrix.c3 / scaling.z, matrix.c4
127127
);
128128
return trsf;
129129
}
@@ -135,12 +135,12 @@ Quantity_Color toOccColor(const aiColor4D& color, Quantity_TypeOfColor colorType
135135
}
136136

137137
// Create an OpenCascade Image_Texture object from assimp texture
138-
Handle(Image_Texture) createOccTexture(const aiTexture* texture)
138+
OccHandle<Image_Texture> createOccTexture(const aiTexture* texture)
139139
{
140140
const auto textureWidth = texture->mWidth;
141141
const auto textureHeight = texture->mHeight;
142142
const auto textureSize = textureHeight == 0 ? textureWidth : 4 * textureWidth * textureHeight;
143-
Handle(NCollection_Buffer) buff = new NCollection_Buffer(
143+
auto buff = makeOccHandle<NCollection_Buffer>(
144144
NCollection_BaseAllocator::CommonBaseAllocator(),
145145
textureSize
146146
);
@@ -151,14 +151,14 @@ Handle(Image_Texture) createOccTexture(const aiTexture* texture)
151151

152152
// Create an OpenCascade Poly_Triangulation object from assimp mesh
153153
// The input 'mesh' is assumed to contain only triangles
154-
Handle(Poly_Triangulation) createOccTriangulation(const aiMesh* mesh)
154+
OccHandle<Poly_Triangulation> createOccTriangulation(const aiMesh* mesh)
155155
{
156156
assert(mesh != nullptr);
157157
assert(mesh->mPrimitiveTypes & aiPrimitiveType_TRIANGLE);
158158

159159
const unsigned textureIndex = 0;
160160
const bool hasUvNodes = mesh->HasTextureCoords(textureIndex) && mesh->mNumUVComponents[textureIndex] == 2;
161-
Handle(Poly_Triangulation) triangulation = new Poly_Triangulation(mesh->mNumVertices, mesh->mNumFaces, hasUvNodes);
161+
auto triangulation = makeOccHandle<Poly_Triangulation>(mesh->mNumVertices, mesh->mNumFaces, hasUvNodes);
162162

163163
for (unsigned i = 0; i < mesh->mNumVertices; ++i) {
164164
const aiVector3D& vertex = mesh->mVertices[i];
@@ -340,7 +340,7 @@ TDF_LabelSequence AssimpReader::transfer(DocumentPtr doc, TaskProgress* progress
340340

341341
// Add materials in target document
342342
auto materialTool = doc->xcaf().visMaterialTool();
343-
for (const Handle_XCAFDoc_VisMaterial& material : m_vecMaterial) {
343+
for (const OccHandle<XCAFDoc_VisMaterial>& material : m_vecMaterial) {
344344
const TDF_Label label = materialTool->AddMaterial(material, material->RawName()->String());
345345
m_mapMaterialLabel.insert({ material, label });
346346
}
@@ -370,22 +370,22 @@ void AssimpReader::applyProperties(const PropertyGroup* group)
370370
}
371371
}
372372

373-
Handle(Image_Texture) AssimpReader::findOccTexture(
373+
OccHandle<Image_Texture> AssimpReader::findOccTexture(
374374
const std::string& strFilepath, const FilePath& modelFilepath
375375
)
376376
{
377377
// Texture might be embedded
378378
{
379379
// Note: aiScene::GetEmbeddedTextureAndIndex() isn't available for version < 5.1
380380
const aiTexture* texture = m_scene->GetEmbeddedTexture(strFilepath.c_str());
381-
Handle(Image_Texture) occTexture = Cpp::findValue(texture, m_mapEmbeddedTexture);
381+
OccHandle<Image_Texture> occTexture = Cpp::findValue(texture, m_mapEmbeddedTexture);
382382
if (occTexture)
383383
return occTexture;
384384
}
385385

386386
// Texture might have already been loaded from file
387387
{
388-
Handle(Image_Texture) texture = CppUtils::findValue(strFilepath, m_mapFileTexture);
388+
OccHandle<Image_Texture> texture = CppUtils::findValue(strFilepath, m_mapFileTexture);
389389
if (texture)
390390
return texture;
391391
}
@@ -410,7 +410,7 @@ Handle(Image_Texture) AssimpReader::findOccTexture(
410410

411411
// Could find an existing filepath for the texture
412412
if (ptrTextureFilepath) {
413-
Handle(Image_Texture) texture = new Image_Texture(filepathTo<TCollection_AsciiString>(*ptrTextureFilepath));
413+
auto texture = makeOccHandle<Image_Texture>(filepathTo<TCollection_AsciiString>(*ptrTextureFilepath));
414414
// Cache texture
415415
m_mapFileTexture.insert({ strFilepath, texture });
416416
return texture;
@@ -425,11 +425,11 @@ Handle(Image_Texture) AssimpReader::findOccTexture(
425425
return {};
426426
}
427427

428-
Handle(XCAFDoc_VisMaterial) AssimpReader::createOccVisMaterial(
428+
OccHandle<XCAFDoc_VisMaterial> AssimpReader::createOccVisMaterial(
429429
const aiMaterial* material, const FilePath& modelFilepath
430430
)
431431
{
432-
Handle(XCAFDoc_VisMaterial) mat = new XCAFDoc_VisMaterial;
432+
auto mat = makeOccHandle<XCAFDoc_VisMaterial>();
433433

434434
//mat->SetAlphaMode(Graphic3d_AlphaMode_Opaque);
435435

@@ -448,7 +448,7 @@ Handle(XCAFDoc_VisMaterial) AssimpReader::createOccVisMaterial(
448448
aiString matName;
449449
material->Get(AI_MATKEY_NAME, matName);
450450
std::string_view vMatName{ matName.C_Str(), matName.length };
451-
mat->SetRawName(string_conv<Handle(TCollection_HAsciiString)>(vMatName));
451+
mat->SetRawName(string_conv<OccHandle<TCollection_HAsciiString>>(vMatName));
452452
}
453453

454454
// Backface culling

src/io_assimp/io_assimp_reader.h

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
#include "../base/document_ptr.h"
1010
#include "../base/io_reader.h"
11+
#include "../base/occ_handle.h"
1112
#include "../base/tkernel_utils.h"
1213

1314
#include <assimp/Importer.hpp>
@@ -42,11 +43,11 @@ class AssimpReader : public Reader {
4243
// Create OpenCascade texture object
4344
// Parameter 'strFilepath' is the filepath to the texture as specified by the assimp material
4445
// Parameter 'modelFilepath' is the filepath to the 3D model being imported with Reader::readFile()
45-
Handle(Image_Texture) findOccTexture(const std::string& strFilepath, const FilePath& modelFilepath);
46+
OccHandle<Image_Texture> findOccTexture(const std::string& strFilepath, const FilePath& modelFilepath);
4647

4748
// Create XCAFDoc_VisMaterial from assimp material
4849
// Parameter 'modelFilepath' is the filepath to the 3D model being imported with Reader::readFile()
49-
Handle(XCAFDoc_VisMaterial) createOccVisMaterial(const aiMaterial* material, const FilePath& modelFilepath);
50+
OccHandle<XCAFDoc_VisMaterial> createOccVisMaterial(const aiMaterial* material, const FilePath& modelFilepath);
5051

5152
void transferSceneNode(
5253
const aiNode* node,
@@ -64,12 +65,12 @@ class AssimpReader : public Reader {
6465
Assimp::Importer m_importer;
6566
const aiScene* m_scene = nullptr;
6667

67-
std::vector<Handle(Poly_Triangulation)> m_vecTriangulation;
68-
std::vector<Handle(XCAFDoc_VisMaterial)> m_vecMaterial;
69-
std::unordered_map<Handle(XCAFDoc_VisMaterial), TDF_Label> m_mapMaterialLabel;
68+
std::vector<OccHandle<Poly_Triangulation>> m_vecTriangulation;
69+
std::vector<OccHandle<XCAFDoc_VisMaterial>> m_vecMaterial;
70+
std::unordered_map<OccHandle<XCAFDoc_VisMaterial>, TDF_Label> m_mapMaterialLabel;
7071
std::unordered_map<const aiNode*, aiNodeData> m_mapNodeData;
71-
std::unordered_map<const aiTexture*, Handle(Image_Texture)> m_mapEmbeddedTexture;
72-
std::unordered_map<std::string, Handle(Image_Texture)> m_mapFileTexture;
72+
std::unordered_map<const aiTexture*, OccHandle<Image_Texture>> m_mapEmbeddedTexture;
73+
std::unordered_map<std::string, OccHandle<Image_Texture>> m_mapFileTexture;
7374
};
7475

7576
} // namespace IO

0 commit comments

Comments
 (0)