Skip to content

Commit

Permalink
first pass at bindings AddInstanceDefinition
Browse files Browse the repository at this point in the history
  • Loading branch information
fraguada committed Dec 19, 2023
1 parent b628ad9 commit ecfece6
Show file tree
Hide file tree
Showing 2 changed files with 83 additions and 3 deletions.
85 changes: 82 additions & 3 deletions src/bindings/bnd_extensions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1144,12 +1144,90 @@ void BND_File3dmInstanceDefinitionTable::Add(const BND_InstanceDefinitionGeometr
m_model->AddModelComponent(*_idef);
}

/*
void BND_File3dmInstanceDefinitionTable::Add(std::wstring name, std::wstring description, std::wstring url, std::wstring urlTag, ON_3dPoint basePoint, const std::vector<ON_Geometry>& geometry, const std::vector<ON_3dmObjectAttributes>& attributes)

int BND_File3dmInstanceDefinitionTable::AddInstanceDefinition(std::wstring name, std::wstring description, std::wstring url, std::wstring url_tag, ON_3dPoint basePoint, const std::vector<ON_Geometry>& geometry, const std::vector<ON_3dmObjectAttributes>& attributes)
{
const int count_g = (int)geometry.size();
const int count_a = (int)attributes.size();
int index = -1;

if(m_model)
{

// Determine if we need to transform geometry to world origin
ON_Xform xf;
ON_Xform* pXform = nullptr;
if (basePoint.IsValid() && basePoint != ON_3dPoint::Origin)
{
xf = ON_Xform::TranslationTransformation(ON_3dPoint::Origin - basePoint);
pXform = &xf;
}

ON_SimpleArray<ON_UUID> object_uuids;

for ( int i = 0; i < count_g; i ++ )
{
const ON_Geometry* pConstGeom = &geometry[i];
const ON_3dmObjectAttributes* pConstAtts = i < count_a ? &attributes[i] : &ON_3dmObjectAttributes::DefaultAttributes;

if (pConstGeom && pConstAtts)
{
ON_Geometry* pGeom = pConstGeom->Duplicate(); // Copy so we can transform
if (pGeom)
{
// Make certain that proper flags are set for instance definiton geometry
ON_3dmObjectAttributes atts(*pConstAtts);
atts.m_uuid = ON_nil_uuid;
atts.SetMode(ON::object_mode::idef_object);
atts.RemoveFromAllGroups();
atts.m_space = ON::model_space;
atts.m_viewport_id = ON_nil_uuid;

// Transform if needed
if (pXform)
{
atts.Transform(pGeom, *pXform);
pGeom->Transform(*pXform);
}

BND_3dmObjectAttributes _atts;
_atts.m_attributes = &atts;
ON_UUID uuid = Internal_ONX_Model_AddModelGeometry(m_model.get(), pGeom, &_atts);
if (ON_UuidIsNotNil(uuid))
object_uuids.Append(uuid);

delete pGeom; // Don't leak...
}
}

}

if (object_uuids.Count())
{
ON_InstanceDefinition* idef = new ON_InstanceDefinition();
if (nullptr != idef)
{
idef->SetInstanceGeometryIdList(object_uuids);
idef->SetInstanceDefinitionType(ON_InstanceDefinition::IDEF_UPDATE_TYPE::Static);
idef->SetName(name.c_str());
idef->SetDescription(description.c_str());
idef->SetURL(url.c_str());
idef->SetURL_Tag(url_tag.c_str());
ON_ModelComponentReference model_component_reference = m_model->AddManagedModelComponent(idef, true);
if (!model_component_reference.IsEmpty())
{
const ON_ModelComponent* model_component = model_component_reference.ModelComponent();
if (nullptr != model_component)
index = model_component->Index();
}
}
}
}

return index;

}
*/


BND_InstanceDefinitionGeometry* BND_File3dmInstanceDefinitionTable::FindIndex(int index) const
{
Expand Down Expand Up @@ -1612,6 +1690,7 @@ void initExtensionsBindings(pybind11::module& m)
.def("__getitem__", &BND_File3dmInstanceDefinitionTable::FindIndex)
.def("__iter__", [](py::object s) { return PyBNDIterator<BND_File3dmInstanceDefinitionTable&, BND_InstanceDefinitionGeometry*>(s.cast<BND_File3dmInstanceDefinitionTable &>(), s); })
.def("Add", &BND_File3dmInstanceDefinitionTable::Add, py::arg("idef"))
.def("AddInstanceDefinition", &BND_File3dmInstanceDefinitionTable::AddInstanceDefinition, py::arg("name"), py::arg("description"), py::arg("url"), py::arg("urlTag"), py::arg("basePoint"), py::arg("geometry"), py::arg("attributes"))
.def("FindIndex", &BND_File3dmInstanceDefinitionTable::FindIndex, py::arg("index"))
.def("FindId", &BND_File3dmInstanceDefinitionTable::FindId, py::arg("id"))
;
Expand Down
1 change: 1 addition & 0 deletions src/bindings/bnd_extensions.h
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,7 @@ class BND_File3dmInstanceDefinitionTable
BND_File3dmInstanceDefinitionTable(std::shared_ptr<ONX_Model> m) { m_model = m; }
int Count() const { return m_model.get()->ActiveComponentCount(ON_ModelComponent::Type::InstanceDefinition); }
void Add(const class BND_InstanceDefinitionGeometry& idef);
int AddInstanceDefinition(std::wstring name, std::wstring description, std::wstring url, std::wstring url_tag, ON_3dPoint basePoint, const std::vector<ON_Geometry>& geometry, const std::vector<ON_3dmObjectAttributes>& attributes);
// public int Add(string name, string description, string url, string urlTag, Point3d basePoint, IEnumerable<GeometryBase> geometry, IEnumerable<ObjectAttributes> attributes)
//int Add(std::wstring name, std::wstring description, std::wstring url, std::wstring urlTag, ON_3dPoint basePoint, const std::vector<ON_Geometry>& geometry, const std::vector<ON_3dmObjectAttributes>& attributes);
// public int AddLinked(string filename, string name, string description)
Expand Down

0 comments on commit ecfece6

Please sign in to comment.