finish proxies wip

This commit is contained in:
David Kekesi
2024-10-11 17:10:05 +02:00
parent 68c98abde9
commit 791e9f072f
5 changed files with 85 additions and 29 deletions
@@ -128,10 +128,12 @@ bool ProjectCollection::addMaterialProxy(const speckle::database::BIMIndex& mate
--------------------------------------------------------------------*/
bool ProjectCollection::addMaterialProxy(const ModelerAPI::Material& material, const speckle::database::BIMRecordID& objectID) {
auto finishID = Guid::fromInt(material.GenerateHashValue());
if (m_finishes->find(finishID) != m_finishes->end())
return false;
auto finish = std::make_unique<Finish>(material);
return m_finishes->insert({finishID, std::move(finish)}).second;
auto iter = m_finishes->find(finishID);
if (iter == m_finishes->end()) {
auto finish = std::make_unique<Finish>(material);
iter = m_finishes->insert({ finishID, std::move(finish) }).first;
}
return addMaterialProxy(finishID, objectID);
} //ProjectCollection::addMaterialProxy
#endif
+5 -5
View File
@@ -10,6 +10,7 @@
using namespace active::serialise;
using namespace speckle::primitive;
using namespace speckle::serialise;
namespace {
@@ -65,14 +66,13 @@ Cargo::Unique Mesh::getCargo(const Inventory::Item& item) const {
using namespace active::serialise;
switch (item.index) {
case vertexID:
return std::make_unique<ContainerWrap<std::vector<double>>>(vertices);
return std::make_unique<ContainerWrap<std::vector<double>>>(m_vertices);
case faceID:
return std::make_unique<ContainerWrap<std::vector<int>>>(faces);
return std::make_unique<ContainerWrap<std::vector<int>>>(m_faces);
case colorID:
return std::make_unique<ContainerWrap<std::vector<int>>>(colors);
return std::make_unique<ContainerWrap<std::vector<int>>>(m_colors);
case proxyID:
return nullptr; //Activate the following line when the mesh material is available to add to the collector
//return std::make_unique<FinishProxy>(getBIMID(), material);
return std::make_unique<FinishProxy>(getBIMID(), m_material);
default:
return nullptr; //Requested an unknown index
}
+13 -6
View File
@@ -4,6 +4,10 @@
#include "Speckle/Database/Content/BIMRecord.h"
#include "Speckle/Utility/String.h"
#ifdef ARCHICAD
#include "ModelMaterial.hpp"
#endif
namespace speckle::primitive {
/*!
@@ -22,7 +26,7 @@ namespace speckle::primitive {
Default constructor
@param unit The mesh unit type
*/
Mesh(active::measure::LengthType unit = active::measure::LengthType::metre) : base{unit} {}
Mesh(active::measure::LengthType unit = active::measure::LengthType::metre) : base{ utility::Guid{true}, utility::Guid{}, unit } {}
/*!
Constructor
@param vertices The mesh vertices
@@ -30,9 +34,9 @@ namespace speckle::primitive {
@param colors The mesh face colours
@param unit The mesh unit type
*/
Mesh(std::vector<double>&& vertices, std::vector<int>&& faces, std::vector<int>&& colors,
Mesh(std::vector<double>&& vertices, std::vector<int>&& faces, std::vector<int>&& colors, const ModelerAPI::Material& material,
active::measure::LengthType unit = active::measure::LengthType::metre) :
base{unit}, vertices {std::move(vertices)}, faces{std::move(faces)}, colors{std::move(colors)} {}
base{ unit }, m_vertices{ std::move(vertices) }, m_faces{ std::move(faces) }, m_colors{ std::move(colors) }, m_material{ material } {}
// MARK: - Functions (const)
@@ -58,9 +62,12 @@ namespace speckle::primitive {
active::serialise::Cargo::Unique getCargo(const active::serialise::Inventory::Item& item) const override;
private:
std::vector<double> vertices;
std::vector<int> faces;
std::vector<int> colors;
std::vector<double> m_vertices;
std::vector<int> m_faces;
std::vector<int> m_colors;
#ifdef ARCHICAD
ModelerAPI::Material m_material;
#endif
};
}
+57 -12
View File
@@ -2,6 +2,7 @@
#include "Active/Serialise/Item/Wrapper/ValueWrap.h"
#include "Active/Serialise/Management/Management.h"
#include "Active/Serialise/CargoHold.h"
#include "Active/Utility/BufferOut.h"
#include "Speckle/Serialise/Collection/FinishCollector.h"
#include "Speckle/Utility/Guid.h"
@@ -37,12 +38,20 @@ namespace {
///Serialisation fields
enum FieldIndex {
surfaceColourID,
diffuseID,
opacityID,
emissiveID,
metalnessID,
roughnessID,
};
///Serialisation field IDs
static std::array fieldID = {
Identity{"surfaceColour"},
Identity{"diffuse"},
Identity{"opacity"},
Identity{"emissive"},
Identity{"metalness"},
Identity{"roughness"},
};
#ifdef ARCHICAD
@@ -55,6 +64,28 @@ namespace {
colour.f_blue = modelColour.blue;
} //copyModelerColor
#endif
int32_t ARGBToInt(double alpha, double red, double green, double blue) {
// Convert double (0.0 - 1.0) to uint8_t (0 - 255)
uint8_t a = static_cast<uint8_t>(std::round(alpha * 255.0));
uint8_t r = static_cast<uint8_t>(std::round(red * 255.0));
uint8_t g = static_cast<uint8_t>(std::round(green * 255.0));
uint8_t b = static_cast<uint8_t>(std::round(blue * 255.0));
// Pack ARGB into a single 32-bit integer
return (a << 24) | (r << 16) | (g << 8) | b;
}
int32_t ARGBToInt(double alpha, const API_RGBColor& color) {
// Convert double (0.0 - 1.0) to uint8_t (0 - 255)
uint8_t a = static_cast<uint8_t>(std::round(alpha * 255.0));
uint8_t r = static_cast<uint8_t>(std::round(color.f_red * 255.0));
uint8_t g = static_cast<uint8_t>(std::round(color.f_green * 255.0));
uint8_t b = static_cast<uint8_t>(std::round(color.f_blue * 255.0));
// Pack ARGB into a single 32-bit integer
return (a << 24) | (r << 16) | (g << 8) | b;
}
}
/*--------------------------------------------------------------------
@@ -96,13 +127,13 @@ Finish::Finish(const ModelerAPI::Material& material) {
String{material.GetName()}.writeUTF8(active::utility::BufferOut{attr.header.name});
attr.header.guid = Guid{Guid::fromInt(material.GenerateHashValue())};
attr.material.mtype = static_cast<API_MaterTypeID>(material.GetType());
attr.material.ambientPc = material.GetAmbientReflection();
attr.material.diffusePc = material.GetDiffuseReflection();
attr.material.specularPc = material.GetSpecularReflection();
attr.material.transpPc = material.GetTransparency();
attr.material.shine = material.GetShining();
attr.material.transpAtt = material.GetTransparencyAttenuation();
attr.material.emissionAtt = material.GetEmissionAttenuation();
attr.material.ambientPc = static_cast<short>(material.GetAmbientReflection() * 100);
attr.material.diffusePc = static_cast<short>(material.GetDiffuseReflection() * 100);
attr.material.specularPc = static_cast<short>(material.GetSpecularReflection() * 100);
attr.material.transpPc = static_cast<short>(material.GetTransparency() * 100);
attr.material.shine = static_cast<short>(material.GetShining() * 10000);
attr.material.transpAtt = static_cast<short>(material.GetTransparencyAttenuation() * 400);
attr.material.emissionAtt = static_cast<short>(material.GetEmissionAttenuation() * 65535);
copyModelerColor(material.GetSurfaceColor(), attr.material.surfaceRGB);
copyModelerColor(material.GetSpecularColor(), attr.material.specularRGB);
copyModelerColor(material.GetEmissionColor(), attr.material.emissionRGB);
@@ -162,7 +193,11 @@ bool Finish::fillInventory(Inventory& inventory) const {
using enum Entry::Type;
inventory.merge(Inventory{
{
{ fieldID[surfaceColourID], surfaceColourID, element }, //TODO: implement other fields
{ fieldID[diffuseID], diffuseID, element },
{ fieldID[opacityID], opacityID, element },
{ fieldID[emissiveID], emissiveID, element },
{ fieldID[metalnessID], metalnessID, element },
{ fieldID[roughnessID], roughnessID, element },
},
}.withType(&typeid(Finish)));
return base::fillInventory(inventory);
@@ -182,8 +217,18 @@ Cargo::Unique Finish::getCargo(const Inventory::Item& item) const {
confirmData();
using namespace active::serialise;
switch (item.index) {
case surfaceColourID:
return nullptr; //TODO: lookup surface colour
case diffuseID: {
auto opacity = 1.0 - m_data->root.transpPc;
return std::make_unique<CargoHold<Int32Wrap, int32_t>>(ARGBToInt(opacity, m_data->root.surfaceRGB));
}
case opacityID:
return std::make_unique<CargoHold<DoubleWrap,double>>(1.0);
case emissiveID:
return std::make_unique<CargoHold<Int32Wrap, int32_t>>(ARGBToInt(0.0, 0.0, 0.0, 0.0));
case metalnessID:
return std::make_unique<CargoHold<DoubleWrap, double>>(1.0);
case roughnessID:
return std::make_unique<CargoHold<DoubleWrap, double>>(1.0);
default:
return nullptr; //Requested an unknown index
}
@@ -8,6 +8,7 @@
#include "Speckle/SpeckleResource.h"
#include "Speckle/Utility/Guid.h"
#ifdef ARCHICAD
#include "Sight.hpp"
#include "Model.hpp"
#include "ModelMaterial.hpp"
@@ -15,6 +16,7 @@
#include "exp.h"
#include "ModelMeshBody.hpp"
#include "ConvexPolygon.hpp"
#endif
using namespace active::serialise;
using namespace speckle::environment;
@@ -206,11 +208,11 @@ Element::Body* Element::getBody() const {
double alpha = material.GetTransparency();
ModelerAPI::Color color = material.GetSurfaceColor();
colors.push_back(ARGBToInt(alpha, color.red, color.green, color.blue));
//colors.push_back(ARGBToInt(alpha, color.red, color.green, color.blue));
faces.push_back(vertexIndex - 1);
}
elementBody->push_back(primitive::Mesh(std::move(vertices), std::move(faces), std::move(colors)));
elementBody->push_back(primitive::Mesh(std::move(vertices), std::move(faces), std::move(colors), material));
}
}
}