Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#642 create from threejs json #643

Closed
wants to merge 31 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
bca4ab1
small update to testing.md
fraguada Jul 30, 2024
a66ec9b
starting to add nanobind.
fraguada Jul 30, 2024
1135588
js ctor for ViewInfo
fraguada Aug 1, 2024
68b966f
more nanobind work still fails to compile due to cast, tuples, dicts,…
fraguada Aug 5, 2024
49413d0
update bindings.h/.cpp
fraguada Aug 5, 2024
96c5d61
closer to a compile
sbaer Aug 5, 2024
e80d143
cleanup bindings
fraguada Aug 6, 2024
42f8b6c
build nanobind before linking
fraguada Aug 6, 2024
7bbce1e
more cleanup and casting fixes. compiles!
fraguada Aug 6, 2024
76982ff
Switch back to pybind11 in setup.py before merge to dev
fraguada Aug 7, 2024
a0a154b
some more things to revert for pybind11
fraguada Aug 7, 2024
381f912
fix for emscripten
fraguada Aug 7, 2024
20c258e
add ctor to ViewInfo
fraguada Aug 7, 2024
8d4f86c
Merge pull request #634 from mcneel/wip/nanobind
fraguada Aug 7, 2024
7cdeeb4
Some ifdefs to make it easier to switch between oybind and nanobind
fraguada Aug 7, 2024
a3e7e80
bump version numbers
fraguada Aug 7, 2024
dfb100a
changing the way we access ViewInfo.Viewport() in js/py
fraguada Aug 9, 2024
876db73
update tests for js and py
fraguada Aug 9, 2024
e559fa9
cleanup test
fraguada Aug 9, 2024
90f1f4f
Merge pull request #635 from mcneel/wip/createview2
fraguada Aug 9, 2024
d3ca009
update opennurbs to 8.10
fraguada Aug 22, 2024
f88ca6a
add file3dm tables test for python
fraguada Aug 22, 2024
4004253
try without debug in ci
fraguada Aug 22, 2024
598f948
small tuneup to workflow ci
fraguada Aug 22, 2024
8ba49e6
try to build release on mcneel/amazonlinux2023
fraguada Sep 13, 2024
f61239a
add container/image back to release workflow
fraguada Sep 13, 2024
8e099b3
Swap order of "add" arguments.
prideout Sep 29, 2024
27cf990
Merge pull request #639 from prideout/patch-1
fraguada Oct 2, 2024
b5b58a1
Merge pull request #640 from mcneel/dockerfile_AL2023
fraguada Oct 2, 2024
73999e0
#642
pedrocortesark Oct 9, 2024
bb7f1f7
#642 Fixed declaration error
pedrocortesark Oct 10, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
closer to a compile
  • Loading branch information
sbaer committed Aug 5, 2024
commit 96c5d611bde51acc5d03c3a4f58c7b162e259e4b
23 changes: 14 additions & 9 deletions src/bindings/bindings.cpp
Original file line number Diff line number Diff line change
@@ -1,16 +1,9 @@
#include "bindings.h"

#if defined(ON_PYTHON_COMPILE)
#if defined(NANOBIND)
namespace py = nanobind;
NB_MODULE(_rhino3dm, m) {
m.doc() = "rhino3dm python package. OpenNURBS wrappers with a RhinoCommon style";
#else
namespace py = pybind11;
PYBIND11_MODULE(_rhino3dm, m){
RH3DM_PYTHON_BINDING(_rhino3dm, m) {
m.doc() = "rhino3dm python package. OpenNURBS wrappers with a RhinoCommon style";
#endif
#endif

#if defined(ON_WASM_COMPILE)
using namespace emscripten;
Expand Down Expand Up @@ -95,6 +88,14 @@ EMSCRIPTEN_BINDINGS(rhino3dm) {

}

#if defined(ON_PYTHON_COMPILE)
std::string ToStdString(const py::str& str)
{
std::string rc = str;
return rc;
}
#endif

BND_TUPLE CreateTuple(int count)
{
#if defined(ON_PYTHON_COMPILE)
Expand All @@ -108,7 +109,11 @@ BND_TUPLE CreateTuple(int count)
BND_TUPLE NullTuple()
{
#if defined(ON_PYTHON_COMPILE)
return py::none();
#if defined(NANOBIND)
UNIMPLEMENTED_EXCEPTION;
#else
return py::none();
#endif
#else
return emscripten::val::null();
#endif
Expand Down
14 changes: 14 additions & 0 deletions src/bindings/bindings.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,21 @@
#include <nanobind/stl/string.h>
#include <nanobind/stl/tuple.h>
namespace py = nanobind;
typedef nanobind::module_ rh3dmpymodule;
#define RH3DM_PYTHON_BINDING(name, variable) NB_MODULE(name, variable)
#define def_property def_prop_rw
#define def_property_readonly def_prop_ro
#define UNIMPLEMENTED_EXCEPTION throw std::exception()

#else
#include <pybind11/pybind11.h>
#include <pybind11/stl.h>
namespace py = pybind11;
#define RH3DM_PYTHON_BINDING(name, variable) PYBIND11_MODULE(name, variable)
typedef pybind11::module_ rh3dmpymodule;
#endif

std::string ToStdString(const py::str& str);
#include "datetime.h"
#pragma comment(lib, "rpcrt4.lib")
#pragma comment(lib, "shlwapi.lib")
Expand Down Expand Up @@ -50,7 +60,11 @@ template<typename T>
void SetTuple(BND_TUPLE& tuple, int index, const T& value)
{
#if defined(ON_PYTHON_COMPILE)
#if defined(NANOBIND)
UNIMPLEMENTED_EXCEPTION;
#else
tuple[index] = value;
#endif
#else
tuple.set(index, value);
#endif
Expand Down
27 changes: 13 additions & 14 deletions src/bindings/bnd_extensions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -671,7 +671,7 @@ BND_FileObject* BND_ONXModel_ObjectTable::ModelObjectAt(int index)
{
#if defined(ON_PYTHON_COMPILE)
if (index < 0)
throw pybind11::index_error();
throw py::index_error();
#else
if (index < 0)
return nullptr;
Expand Down Expand Up @@ -706,7 +706,7 @@ BND_FileObject* BND_ONXModel_ObjectTable::ModelObjectAt(int index)
}

#if defined(ON_PYTHON_COMPILE)
throw pybind11::index_error();
throw py::index_error();
#else
return nullptr;
#endif
Expand Down Expand Up @@ -775,7 +775,7 @@ BND_Material* BND_File3dmMaterialTable::FindIndex(int index)
return new BND_Material(modelmaterial, &compref);

#if defined(ON_PYTHON_COMPILE)
throw pybind11::index_error();
throw py::index_error();
#else
return nullptr;
#endif
Expand Down Expand Up @@ -930,7 +930,7 @@ BND_Bitmap* BND_File3dmBitmapTable::FindIndex(int index)
return new BND_Bitmap(modelbitmap, &compref);

#if defined(ON_PYTHON_COMPILE)
throw pybind11::index_error();
throw py::index_error();
#else
return nullptr;
#endif
Expand Down Expand Up @@ -994,7 +994,7 @@ BND_Layer* BND_File3dmLayerTable::FindIndex(int index)
return new BND_Layer(modellayer, &compref, m_model);

#if defined(ON_PYTHON_COMPILE)
throw pybind11::index_error();
throw py::index_error();
#else
return nullptr;
#endif
Expand Down Expand Up @@ -1056,7 +1056,7 @@ BND_Group* BND_File3dmGroupTable::FindIndex(int index)
}

#if defined(ON_PYTHON_COMPILE)
throw pybind11::index_error();
throw py::index_error();
#else
return nullptr;
#endif
Expand Down Expand Up @@ -1129,7 +1129,7 @@ BND_ViewInfo* BND_File3dmViewTable::GetItem(int index) const

#if defined(ON_PYTHON_COMPILE)
if (index < 0 || index >= count)
throw pybind11::index_error();
throw py::index_error();
#else
if (index < 0 || index >= count)
return nullptr;
Expand Down Expand Up @@ -1176,7 +1176,7 @@ BND_DimensionStyle* BND_File3dmDimStyleTable::FindIndex(int index) const
return new BND_DimensionStyle(modeldimstyle, &compref);

#if defined(ON_PYTHON_COMPILE)
throw pybind11::index_error();
throw py::index_error();
#else
return nullptr;
#endif
Expand Down Expand Up @@ -1234,8 +1234,8 @@ int BND_File3dmInstanceDefinitionTable::Add(std::wstring name, std::wstring desc
{

#if defined(ON_PYTHON_COMPILE)
BND_GeometryBase g = geometry[i].cast<BND_GeometryBase>();
BND_3dmObjectAttributes oa = attributes[i].cast<BND_3dmObjectAttributes>();
BND_GeometryBase g = py::cast<BND_GeometryBase>(geometry[i]);
BND_3dmObjectAttributes oa = py::cast<BND_3dmObjectAttributes>(attributes[i]);
#else
BND_GeometryBase g = geometry[i].as<BND_GeometryBase>();
BND_3dmObjectAttributes oa = attributes[i].as<BND_3dmObjectAttributes>();
Expand Down Expand Up @@ -1318,7 +1318,7 @@ BND_InstanceDefinitionGeometry* BND_File3dmInstanceDefinitionTable::FindIndex(in
}

#if defined(ON_PYTHON_COMPILE)
throw pybind11::index_error();
throw py::index_error();
#else
return nullptr;
#endif
Expand Down Expand Up @@ -1363,7 +1363,7 @@ BND_File3dmPlugInData* BND_File3dmPlugInDataTable::GetPlugInData(int index)
{
#if defined(ON_PYTHON_COMPILE)
if (index < 0 || index >= m_model->m_userdata_table.Count())
throw pybind11::index_error();
throw py::index_error();
#else
if (index < 0 || index >= m_model->m_userdata_table.Count())
return nullptr;
Expand Down Expand Up @@ -1415,7 +1415,7 @@ BND_TUPLE BND_File3dmStringTable::GetKeyValue(int i) const

#if defined(ON_PYTHON_COMPILE)
if (i < 0 || i >= strings.Count())
throw pybind11::index_error();
throw py::index_error();
#endif

const ON_UserString& us = strings[i];
Expand Down Expand Up @@ -1626,7 +1626,6 @@ BND_TUPLE BND_FileObject::GetTextureMapping( const class BND_File3dm* file3dm, i

// --------------------- Iterator helpers ------- //
#if defined(ON_PYTHON_COMPILE)
namespace py = pybind11;

template <typename IT, typename ET>
struct PyBNDIterator {
Expand Down
8 changes: 1 addition & 7 deletions src/bindings/bnd_file_utilities.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,7 @@ BND_FileReference BND_FileReference::CreateFromFullAndRelativePaths(std::wstring
//////////////////////////////////////////////////////////////////////////////

#if defined(ON_PYTHON_COMPILE)
#if defined(NANOBIND)
namespace py = nanobind;
void initFileUtilitiesBindings(py::module_& m){}
#else
namespace py = pybind11;
void initFileUtilitiesBindings(py::module& m)
void initFileUtilitiesBindings(rh3dmpymodule& m)
{
py::class_<BND_FileReference>(m, "FileReference")
.def_static("CreateFromFullPath", &BND_FileReference::CreateFromFullPath, py::arg("path"))
Expand All @@ -35,7 +30,6 @@ void initFileUtilitiesBindings(py::module& m)
;
}
#endif
#endif

#if defined(ON_WASM_COMPILE)
using namespace emscripten;
Expand Down
3 changes: 1 addition & 2 deletions src/bindings/bnd_intersect.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -210,8 +210,7 @@ BND_TUPLE BND_Intersection::LineBox(const ON_Line& line, const BND_BoundingBox&
//////////////////////////////////////////////////////////////////////////////

#if defined(ON_PYTHON_COMPILE)
namespace py = pybind11;
void initIntersectBindings(pybind11::module& m)
void initIntersectBindings(py::module_& m)
{
//py::enum_<PlaneCircleIntersection>(m, "PlaneCircleIntersection")
// .value("None", PlaneCircleIntersection::None)
Expand Down
43 changes: 31 additions & 12 deletions src/bindings/bnd_mesh.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@


#if defined(ON_PYTHON_COMPILE)
pybind11::dict BND_MeshingParameters::Encode() const
py::dict BND_MeshingParameters::Encode() const
{
pybind11::dict d;
py::dict d;
d["TextureRange"] = GetTextureRange();
d["JaggedSeams"] = GetJaggedSeams();
d["RefineGrid"] = GetRefineGrid();
Expand All @@ -27,9 +27,10 @@ pybind11::dict BND_MeshingParameters::Encode() const
return d;
}

BND_MeshingParameters* BND_MeshingParameters::Decode(pybind11::dict jsonObject)
BND_MeshingParameters* BND_MeshingParameters::Decode(py::dict jsonObject)
{
BND_MeshingParameters* mp = new BND_MeshingParameters();
/*
mp->SetTextureRange(jsonObject["TextureRange"].cast<int>());
mp->SetJaggedSeams(jsonObject["JaggedSeams"].cast<bool>());
mp->SetRefineGrid(jsonObject["RefineGrid"].cast<bool>());
Expand All @@ -47,6 +48,24 @@ BND_MeshingParameters* BND_MeshingParameters::Decode(pybind11::dict jsonObject)
mp->SetMinimumEdgeLength(jsonObject["MinimumEdgeLength"].cast<double>());
mp->SetMaximumEdgeLength(jsonObject["MaximumEdgeLength"].cast<double>());
mp->SetRefineAngle(jsonObject["RefineAngle"].cast<double>());
*/
mp->SetTextureRange(py::cast<int>(jsonObject["TextureRange"]));
mp->SetJaggedSeams(py::cast<bool>(jsonObject["JaggedSeams"]));
mp->SetRefineGrid(py::cast<bool>(jsonObject["RefineGrid"]));
mp->SetSimplePlanes(py::cast<bool>(jsonObject["SimplePlanes"]));
mp->SetComputeCurvature(py::cast<bool>(jsonObject["ComputeCurvature"]));
mp->SetClosedObjectPostProcess(py::cast<bool>(jsonObject["ClosedObjectPostProcess"]));
mp->SetGridMinCount(py::cast<bool>(jsonObject["GridMinCount"]));
mp->SetGridMaxCount(py::cast<int>(jsonObject["GridMaxCount"]));
mp->SetGridAngle(py::cast<double>(jsonObject["GridAngle"]));
mp->SetGridAspectRatio(py::cast<double>(jsonObject["GridAspectRatio"]));
mp->SetGridAmplification(py::cast<double>(jsonObject["GridAmplification"]));
mp->SetTolerance(py::cast<double>(jsonObject["Tolerance"]));
mp->SetMinimumTolerance(py::cast<double>(jsonObject["MinimumTolerance"]));
mp->SetRelativeTolerance(py::cast<double>(jsonObject["RelativeTolerance"]));
mp->SetMinimumEdgeLength(py::cast<double>(jsonObject["MinimumEdgeLength"]));
mp->SetMaximumEdgeLength(py::cast<double>(jsonObject["MaximumEdgeLength"]));
mp->SetRefineAngle(py::cast<double>(jsonObject["RefineAngle"]));
return mp;
}
#endif
Expand Down Expand Up @@ -473,7 +492,7 @@ ON_3fPoint BND_MeshVertexList::GetVertex(int i) const
{
#if defined(ON_PYTHON_COMPILE)
if (i<0 || i>=m_mesh->m_V.Count())
throw pybind11::index_error();
throw py::index_error();
#endif
return m_mesh->m_V[i];
}
Expand All @@ -482,7 +501,7 @@ void BND_MeshVertexList::SetVertex(int i, ON_3fPoint pt)
{
#if defined(ON_PYTHON_COMPILE)
if (i < 0 || i >= m_mesh->m_V.Count())
throw pybind11::index_error();
throw py::index_error();
#endif
m_mesh->m_V[i] = pt;
}
Expand Down Expand Up @@ -707,7 +726,7 @@ BND_TUPLE BND_MeshFaceList::GetFace(int i) const
{
#if defined(ON_PYTHON_COMPILE)
if (i < 0 || i >= m_mesh->m_F.Count())
throw pybind11::index_error();
throw py::index_error();
#endif

ON_MeshFace& face = m_mesh->m_F[i];
Expand Down Expand Up @@ -784,7 +803,7 @@ BND_Color BND_MeshVertexColorList::GetColor(int index) const
{
#if defined(ON_PYTHON_COMPILE)
if (index < 0 || index >= m_mesh->m_C.Count())
throw pybind11::index_error();
throw py::index_error();
#endif
return ON_Color_to_Binding(m_mesh->m_C[index]);
}
Expand All @@ -793,7 +812,7 @@ void BND_MeshVertexColorList::SetColor(int index, BND_Color color)
{
#if defined(ON_PYTHON_COMPILE)
if (index < 0 || index >= m_mesh->m_C.Count())
throw pybind11::index_error();
throw py::index_error();
#endif

// if index == count, then we are appending
Expand All @@ -816,7 +835,7 @@ ON_3fVector BND_MeshNormalList::GetNormal(int i) const
{
#if defined(ON_PYTHON_COMPILE)
if (i < 0 || i >= m_mesh->m_N.Count())
throw pybind11::index_error();
throw py::index_error();
#endif

return m_mesh->m_N[i];
Expand All @@ -826,7 +845,7 @@ void BND_MeshNormalList::SetNormal(int i, ON_3fVector v)
{
#if defined(ON_PYTHON_COMPILE)
if (i < 0 || i >= m_mesh->m_N.Count())
throw pybind11::index_error();
throw py::index_error();
#endif
m_mesh->m_N[i] = v;
}
Expand All @@ -841,7 +860,7 @@ ON_2fPoint BND_MeshTextureCoordinateList::GetTextureCoordinate(int i) const
{
#if defined(ON_PYTHON_COMPILE)
if (i<0 || i >= m_mesh->m_T.Count())
throw pybind11::index_error();
throw py::index_error();
#endif
return m_mesh->m_T[i];
}
Expand All @@ -850,7 +869,7 @@ void BND_MeshTextureCoordinateList::SetTextureCoordinate(int i, ON_2fPoint tc)
{
#if defined(ON_PYTHON_COMPILE)
if (i < 0 || i >= m_mesh->m_T.Count())
throw pybind11::index_error();
throw py::index_error();
#endif
m_mesh->m_T[i] = tc;
}
Expand Down
8 changes: 4 additions & 4 deletions src/bindings/bnd_nurbscurve.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ ON_4dPoint BND_NurbsCurvePointList::GetControlPoint(int index) const
{
#if defined(ON_PYTHON_COMPILE)
if (index >= Count() || index < 0)
throw pybind11::index_error("list index out of range");
throw py::index_error("list index out of range");
#endif
ON_4dPoint pt;
m_nurbs_curve->GetCV(index, pt);
Expand All @@ -22,7 +22,7 @@ void BND_NurbsCurvePointList::SetControlPoint(int index, ON_4dPoint point)
{
#if defined(ON_PYTHON_COMPILE)
if (index >= Count() || index < 0)
throw pybind11::index_error("list index out of range");
throw py::index_error("list index out of range");
#endif
m_nurbs_curve->SetCV(index, point);
}
Expand All @@ -40,7 +40,7 @@ double BND_NurbsCurveKnotList::GetKnot(int index) const
{
#if defined(ON_PYTHON_COMPILE)
if (index >= Count() || index < 0)
throw pybind11::index_error("list index out of range");
throw py::index_error("list index out of range");
#endif
return m_nurbs_curve->Knot(index);
}
Expand All @@ -49,7 +49,7 @@ void BND_NurbsCurveKnotList::SetKnot(int index, double k)
{
#if defined(ON_PYTHON_COMPILE)
if (index >= Count() || index < 0)
throw pybind11::index_error("list index out of range");
throw py::index_error("list index out of range");
#endif
m_nurbs_curve->SetKnot(index, k);
}
Expand Down
Loading
Loading