Skip to content

Commit

Permalink
WIP0
Browse files Browse the repository at this point in the history
  • Loading branch information
HuguesDelorme committed Aug 22, 2024
1 parent 9791ed5 commit de4de56
Show file tree
Hide file tree
Showing 13 changed files with 284 additions and 32 deletions.
22 changes: 16 additions & 6 deletions src/base/mesh_access.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,8 @@ class XCafFace_MeshAccess : public IMeshAccess {
const TopLoc_Location locShape = XCaf::shapeAbsoluteLocation(doc->modelTree(), treeNode.id());
TopLoc_Location locFace;
m_triangulation = BRep_Tool::Triangulation(face, locFace);
m_location = locShape * locFace;
m_absoluteLocation = locShape * locFace;
m_basisLocation = locFace;
}

std::optional<Quantity_Color> nodeColor(int i) const override
Expand All @@ -62,11 +63,18 @@ class XCafFace_MeshAccess : public IMeshAccess {
return {};
}

const TopLoc_Location& location() const override {
return m_location;
const TopLoc_Location& absoluteLocation() const override
{
return m_absoluteLocation;
}

const OccHandle<Poly_Triangulation>& triangulation() const override {
const TopLoc_Location& basisLocation() const override
{
return m_basisLocation;
}

const OccHandle<Poly_Triangulation>& triangulation() const override
{
return m_triangulation;
}

Expand All @@ -88,13 +96,15 @@ class XCafFace_MeshAccess : public IMeshAccess {

std::optional<Quantity_Color> m_faceColor;
Span<const Quantity_Color> m_nodeColors;
TopLoc_Location m_location;
TopLoc_Location m_absoluteLocation;
TopLoc_Location m_basisLocation;
OccHandle<Poly_Triangulation> m_triangulation;
};

void IMeshAccess_visitMeshes(
const DocumentTreeNode& treeNode,
std::function<void(const IMeshAccess&)> fnCallback)
std::function<void(const IMeshAccess&)> fnCallback
)
{
if (!fnCallback || !treeNode.isValid())
return;
Expand Down
14 changes: 12 additions & 2 deletions src/base/mesh_access.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,22 @@ namespace Mayo {
// Provides an interface to access mesh geometry
class IMeshAccess {
public:
// Returns the color at mesh node(or "vertex") of index `i`
virtual std::optional<Quantity_Color> nodeColor(int i) const = 0;
virtual const TopLoc_Location& location() const = 0;

// Returns the complete(or "absolute") location of the mesh in the assembly tree
// This includes as the basis location(actually being last component)
virtual const TopLoc_Location& absoluteLocation() const = 0;

// Returns the fundamental(or "basis") location of the mesh, independant of the parent nodes in
// the assembly tree
virtual const TopLoc_Location& basisLocation() const = 0;

// Returns the Poly_Triangulation supporting object
virtual const OccHandle<Poly_Triangulation>& triangulation() const = 0;
};

// Iterates over meshes from `treeNode` and call `fnCallback` for each item.
// Iterates over meshes from `treeNode` and call `fnCallback` for each item
void IMeshAccess_visitMeshes(
const DocumentTreeNode& treeNode,
std::function<void(const IMeshAccess&)> fnCallback
Expand Down
27 changes: 27 additions & 0 deletions src/base/mesh_utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,33 @@ double triangulationArea(const OccHandle<Poly_Triangulation>& triangulation)
return area;
}

Poly_Triangulation_NormalElementType normalX(const Poly_Triangulation_NormalType& n)
{
#if OCC_VERSION_HEX >= 0x070600
return n.x();
#else
return n.X();
#endif
}

Poly_Triangulation_NormalElementType normalY(const Poly_Triangulation_NormalType& n)
{
#if OCC_VERSION_HEX >= 0x070600
return n.y();
#else
return n.Y();
#endif
}

Poly_Triangulation_NormalElementType normalZ(const Poly_Triangulation_NormalType& n)
{
#if OCC_VERSION_HEX >= 0x070600
return n.z();
#else
return n.Z();
#endif
}

void setNode(const OccHandle<Poly_Triangulation>& triangulation, int index, const gp_Pnt& pnt)
{
#if OCC_VERSION_HEX >= 0x070600
Expand Down
8 changes: 7 additions & 1 deletion src/base/mesh_utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,18 +26,24 @@ double triangulationArea(const OccHandle<Poly_Triangulation>& triangulation);

#if OCC_VERSION_HEX >= 0x070600
using Poly_Triangulation_NormalType = gp_Vec3f;
using Poly_Triangulation_NormalElementType = Standard_ShortReal;
#else
using Poly_Triangulation_NormalType = gp_Vec;
using Poly_Triangulation_NormalElementType = Standard_Real;
#endif

Poly_Triangulation_NormalType normal(const OccHandle<Poly_Triangulation>& triangulation, int index);
Poly_Triangulation_NormalElementType normalX(const Poly_Triangulation_NormalType& n);
Poly_Triangulation_NormalElementType normalY(const Poly_Triangulation_NormalType& n);
Poly_Triangulation_NormalElementType normalZ(const Poly_Triangulation_NormalType& n);

void setNode(const OccHandle<Poly_Triangulation>& triangulation, int index, const gp_Pnt& pnt);
void setNormal(const OccHandle<Poly_Triangulation>& triangulation, int index, const Poly_Triangulation_NormalType& n);
void setTriangle(const OccHandle<Poly_Triangulation>& triangulation, int index, const Poly_Triangle& triangle);
void setUvNode(const OccHandle<Poly_Triangulation>& triangulation, int index, double u, double v);

void allocateNormals(const OccHandle<Poly_Triangulation>& triangulation);

Poly_Triangulation_NormalType normal(const OccHandle<Poly_Triangulation>& triangulation, int index);
const Poly_Array1OfTriangle& triangles(const OccHandle<Poly_Triangulation>& triangulation);

enum class Orientation {
Expand Down
14 changes: 9 additions & 5 deletions src/base/triangulation_annex_data.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,17 +31,19 @@ TriangulationAnnexDataPtr TriangulationAnnexData::Set(const TDF_Label& label)
}

TriangulationAnnexDataPtr TriangulationAnnexData::Set(
const TDF_Label& label, Span<const Quantity_Color> spanNodeColor)
const TDF_Label& label, Span<const Quantity_Color> spanNodeColor
)
{
TriangulationAnnexDataPtr data = TriangulationAnnexData::Set(label);
auto data = TriangulationAnnexData::Set(label);
data->copyNodeColors(spanNodeColor);
return data;
}

TriangulationAnnexDataPtr TriangulationAnnexData::Set(
const TDF_Label& label, std::vector<Quantity_Color>&& vecNodeColor)
const TDF_Label& label, std::vector<Quantity_Color>&& vecNodeColor
)
{
TriangulationAnnexDataPtr data = TriangulationAnnexData::Set(label);
auto data = TriangulationAnnexData::Set(label);
data->m_vecNodeColor = std::move(vecNodeColor);
return data;
}
Expand All @@ -63,7 +65,9 @@ OccHandle<TDF_Attribute> TriangulationAnnexData::NewEmpty() const
return new TriangulationAnnexData;
}

void TriangulationAnnexData::Paste(const OccHandle<TDF_Attribute>& into, const OccHandle<TDF_RelocationTable>&) const
void TriangulationAnnexData::Paste(
const OccHandle<TDF_Attribute>& into, const OccHandle<TDF_RelocationTable>&
) const
{
auto data = TriangulationAnnexDataPtr::DownCast(into);
if (data)
Expand Down
39 changes: 35 additions & 4 deletions src/io_assimp/io_assimp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@

#include "io_assimp.h"
#include "io_assimp_reader.h"
#include "io_assimp_writer.h"

#include <assimp/version.h>

namespace Mayo {
namespace IO {
namespace Mayo::IO {

Span<const Format> AssimpFactoryReader::formats() const
{
Expand Down Expand Up @@ -45,6 +45,37 @@ std::unique_ptr<PropertyGroup> AssimpFactoryReader::createProperties(Format form
return {};
}

Span<const Format> AssimpFactoryWriter::formats() const
{
static const Format array[] = {
Format_3DS,
Format_3MF,
Format_COLLADA,
Format_FBX,
Format_DirectX
};
return array;
}

std::unique_ptr<Writer> AssimpFactoryWriter::create(Format format) const
{
auto itFound = std::find(this->formats().begin(), this->formats().end(), format);
if (itFound != this->formats().end())
return std::make_unique<AssimpWriter>();

return {};
}

std::unique_ptr<PropertyGroup> AssimpFactoryWriter::createProperties(Format format, PropertyGroup* parentGroup) const
{
auto itFound = std::find(this->formats().begin(), this->formats().end(), format);
if (itFound != this->formats().end())
return AssimpWriter::createProperties(parentGroup);

return {};
}


std::string_view AssimpLib::strVersion()
{
static std::string str;
Expand Down Expand Up @@ -98,5 +129,5 @@ std::string_view AssimpLib::strVersionDetails()

return str;
}
} // namespace IO
} // namespace Mayo

} // namespace Mayo::IO
23 changes: 19 additions & 4 deletions src/io_assimp/io_assimp.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@
****************************************************************************/

#include "../base/io_reader.h"
#include "../base/io_writer.h"
#include "../base/property.h"
#include <common/mayo_config.h>

#include <memory>

namespace Mayo {
namespace IO {
namespace Mayo::IO {

// Provides factory for Assimp-based Reader objects
class AssimpFactoryReader : public FactoryReader {
Expand All @@ -29,6 +29,22 @@ class AssimpFactoryReader : public FactoryReader {
}
};

// Provides factory for Assimp-based Writer objects
class AssimpFactoryWriter : public FactoryWriter {
public:
Span<const Format> formats() const override;
std::unique_ptr<Writer> create(Format format) const override;
std::unique_ptr<PropertyGroup> createProperties(Format format, PropertyGroup* parentGroup) const override;

static std::unique_ptr<FactoryWriter> create() {
#ifdef MAYO_HAVE_ASSIMP
return std::make_unique<AssimpFactoryWriter>();
#else
return {};
#endif
}
};

struct AssimpLib {
static std::string_view strName() { return "Assimp"; }
#ifdef MAYO_HAVE_ASSIMP
Expand All @@ -40,5 +56,4 @@ struct AssimpLib {
#endif
};

} // namespace IO
} // namespace Mayo
} // namespace Mayo::IO
6 changes: 2 additions & 4 deletions src/io_assimp/io_assimp_reader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,7 @@

//#define MAYO_ASSIMP_READER_HANDLE_SCALING 1

namespace Mayo {
namespace IO {
namespace Mayo::IO {

namespace {

Expand Down Expand Up @@ -766,5 +765,4 @@ void AssimpReader::transferSceneNode(
this->transferSceneNode(node->mChildren[ichild], targetDoc, labelEntity, fnCallbackMesh);
}

} // namespace IO
} // namespace Mayo
} // namespace Mayo::IO
6 changes: 2 additions & 4 deletions src/io_assimp/io_assimp_reader.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,7 @@ struct aiMesh;
struct aiNode;
struct aiTexture;

namespace Mayo {
namespace IO {
namespace Mayo::IO {

// Assimp-based reader
// Requires OpenCascade >= v7.5.0(for XCAFDoc_VisMaterial)
Expand Down Expand Up @@ -69,5 +68,4 @@ class AssimpReader : public Reader {
std::unordered_map<std::string, OccHandle<Image_Texture>> m_mapFileTexture;
};

} // namespace IO
} // namespace Mayo
} // namespace Mayo::IO
Loading

0 comments on commit de4de56

Please sign in to comment.