Skip to content

Commit

Permalink
Merge pull request #661 from mcneel/luis/extrusionWithPlane
Browse files Browse the repository at this point in the history
Luis/extrusion with plane
  • Loading branch information
fraguada authored Nov 26, 2024
2 parents 0735f1a + 7642d85 commit a562aaf
Show file tree
Hide file tree
Showing 7 changed files with 93 additions and 7 deletions.
11 changes: 6 additions & 5 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,23 +13,24 @@ diff:
- (js, py) DimensionStyle.Id
- (js, py) Several delete methods for File3dm Tables: File3dmMaterialTable::Delete, BND_File3dmLayerTable::Delete, BND_File3dmDimStyleTable::Delete
- (js, py) Added tests for various ::Delete methods.
- (js, py) Extrusion::CreateWithPlane #636
- (py) Added python 3.13 target #654
- (py) BND_MeshingParameters::Decode now supports more properties
- (js) Layer.Index #655
- (dotnet) Linux release builds in an Amazon Linux 2023 container
- (js) BND_PointCloud::CreateFromThreeJSON #642
- (py) BND_MeshingParameters::Decode now supports more properties

- (js) Added several methods and properties for Planes #568
- (dotnet) Linux release builds in an Amazon Linux 2023 container

### Changed

- (py) switching from pybind11 to nanobind. WIP. This affects a lot of the src/binding files, which now include many `#if defined()`. When the switch is complete these will be cleaned up.
- (js) File3dm.objects().deleteItem(id) -> File3dm.objects().delete(id)
- (py) File3dmObjectTable now accepts negative indexing #651 @StudioWEngineers
- (js) File3dm.objects().deleteItem(id) -> File3dm.objects().delete(id)

### Fixed

- (js, py) Changes to ViewInfo.Viewport would not set.
- (py) uuid conversion in c++ was broken
- (js, py) Changes to ViewInfo.Viewport would not set.
- (js) BND_Mesh::CreateFromThreeJSON did not pay attention to vertex colors #641
- (js) BND_PointCloud::CreateFromThreeJSON did not pay attention to RGBA (4 channel) colors #641

Expand Down
12 changes: 12 additions & 0 deletions src/bindings/bnd_beam.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,16 @@ BND_Extrusion* BND_Extrusion::Create(const BND_Curve& planarCurve, double height
return new BND_Extrusion(ext, nullptr);
}

BND_Extrusion* BND_Extrusion::CreateWithPlane(const BND_Curve& planarCurve, const class BND_Plane& plane, double height, bool cap)
{
const ON_Plane& on_plane_ref = plane.ToOnPlane();
const ON_Plane* on_plane = &on_plane_ref;
ON_Extrusion* ext = ON_Extrusion::CreateFrom3dCurve(*planarCurve.m_curve, on_plane, height, cap);
if (nullptr == ext)
return nullptr;
return new BND_Extrusion(ext, nullptr);
}

BND_Extrusion* BND_Extrusion::CreateBoxExtrusion(const BND_Box& box, bool cap)
{
if (!box.m_box.IsValid()) return nullptr;
Expand Down Expand Up @@ -197,6 +207,7 @@ void initExtrusionBindings(rh3dmpymodule& m)
{
py::class_<BND_Extrusion, BND_Surface>(m, "Extrusion")
.def_static("Create", &BND_Extrusion::Create, py::arg("planarCurve"), py::arg("height"), py::arg("cap"))
.def_static("CreateWithPlane", &BND_Extrusion::CreateWithPlane, py::arg("planarCurve"), py::arg("plane"), py::arg("height"), py::arg("cap"))
.def_static("CreateBoxExtrusion", &BND_Extrusion::CreateBoxExtrusion, py::arg("box"), py::arg("cap"))
.def_static("CreateCylinderExtrusion", &BND_Extrusion::CreateCylinderExtrusion, py::arg("cylinder"), py::arg("capBottom"), py::arg("capTop"))
.def_static("CreatePipeExtrusion", &BND_Extrusion::CreatePipeExtrusion, py::arg("cylinder"), py::arg("otherRadius"), py::arg("capBottom"), py::arg("capTop"))
Expand Down Expand Up @@ -240,6 +251,7 @@ void initExtrusionBindings(void*)
class_<BND_Extrusion, base<BND_Surface>>("Extrusion")
.constructor<>()
.class_function("create", &BND_Extrusion::Create, allow_raw_pointers())
.class_function("createWithPlane", &BND_Extrusion::CreateWithPlane, allow_raw_pointers())
.class_function("createBoxExtrusion", &BND_Extrusion::CreateBoxExtrusion, allow_raw_pointers())
.class_function("createCylinderExtrusion", &BND_Extrusion::CreateCylinderExtrusion, allow_raw_pointers())
.class_function("createPipeExtrusion", &BND_Extrusion::CreatePipeExtrusion, allow_raw_pointers())
Expand Down
1 change: 1 addition & 0 deletions src/bindings/bnd_beam.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ class BND_Extrusion : public BND_Surface

public:
static BND_Extrusion* Create(const class BND_Curve& planarCurve, double height, bool cap);
static BND_Extrusion* CreateWithPlane(const class BND_Curve& planarCurve, const class BND_Plane& plane, double height, bool cap);
static BND_Extrusion* CreateBoxExtrusion(const class BND_Box& box, bool cap);
static BND_Extrusion* CreateCylinderExtrusion(const class BND_Cylinder& cylinder, bool capBottom, bool capTop);
static BND_Extrusion* CreatePipeExtrusion(const class BND_Cylinder& cylinder, double otherRadius, bool capTop, bool capBottom);
Expand Down
21 changes: 20 additions & 1 deletion src/bindings/bnd_plane.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,21 @@ BND_Plane BND_PlaneHelper::WorldXY()
return BND_Plane::WorldXY();
}

BND_Plane BND_PlaneHelper::WorldYZ()
{
return BND_Plane::WorldYZ();
}

BND_Plane BND_PlaneHelper::WorldZX()
{
return BND_Plane::WorldZX();
}

BND_Plane BND_PlaneHelper::Unset()
{
return BND_Plane::Unset();
}

#if defined(ON_PYTHON_COMPILE)

void initPlaneBindings(rh3dmpymodule& m)
Expand Down Expand Up @@ -240,7 +255,11 @@ void initPlaneBindings(void*)
.field("zAxis", &BND_Plane::m_zaxis);

class_<BND_PlaneHelper>("Plane")
.class_function("worldXY", &BND_PlaneHelper::WorldXY);
.class_function("worldXY", &BND_PlaneHelper::WorldXY)
.class_function("worldYZ", &BND_PlaneHelper::WorldYZ)
.class_function("worldZX", &BND_PlaneHelper::WorldZX)
.class_function("unset", &BND_PlaneHelper::Unset)
;

}
#endif
5 changes: 4 additions & 1 deletion src/bindings/bnd_plane.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class BND_Plane
ON_3dPoint PointAtUV(double u, double v) const;
ON_3dPoint PointAtUVW(double u, double v, double w) const;

#if defined(__EMSCRIPTEN__)
#if defined(ON_WASM_COMPILE)
emscripten::val toJSON(emscripten::val key);
emscripten::val Encode() const;
static BND_Plane* Decode(emscripten::val jsonObject);
Expand All @@ -50,5 +50,8 @@ class BND_PlaneHelper
{
public:
static BND_Plane WorldXY();
static BND_Plane WorldYZ();
static BND_Plane WorldZX();
static BND_Plane Unset();

};
25 changes: 25 additions & 0 deletions tests/javascript/extrusion.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
const rhino3dm = require('rhino3dm')

let rhino
beforeEach( async() => {
rhino = await rhino3dm()
})

// objective: to test that creating and extrusion vs creating an extrusion with a place yield similar extrusions in different places
test('createExtrusion', async () => {

const circle1 = new rhino.Circle(1.0);
const extrusion1 = rhino.Extrusion.create(circle1.toNurbsCurve(), 10.0, true)
const plane = new rhino.Plane.worldXY()
plane.origin = [10,10,10]
const circle2 = new rhino.Circle(1.0);
circle2.plane = plane
const extrusion2 = rhino.Extrusion.createWithPlane(circle2.toNurbsCurve(), plane, 10.0, true)

const bb1 = extrusion1.getBoundingBox()
const bb2 = extrusion2.getBoundingBox()

expect(bb1.volume).toBeCloseTo(bb2.volume, 5)
expect(bb1.center === bb2.center).toBe(false)

})
25 changes: 25 additions & 0 deletions tests/python/test_Extrusion.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import rhino3dm
import unittest

#objective: to test that creating and extrusion vs creating an extrusion with a place yield similar extrusions in different places
class TestExtrusion(unittest.TestCase):
def test_createExtrusion(self):

circle1 = rhino3dm.Circle( 1 )
extrusion1 = rhino3dm.Extrusion.Create(circle1.ToNurbsCurve(), 10, True)
plane = rhino3dm.Plane.WorldXY()
plane.Origin = rhino3dm.Point3d(10, 10, 10)
circle2 = rhino3dm.Circle( 1 )
circle2.Plane = plane
extrusion2 = rhino3dm.Extrusion.CreateWithPlane(circle2.ToNurbsCurve(), plane, 10, True)

bb1 = extrusion1.GetBoundingBox()
bb2 = extrusion2.GetBoundingBox()

self.assertAlmostEqual( bb1.Volume, bb2.Volume, 5 )
self.assertFalse( bb1.Center == bb2.Center )

if __name__ == '__main__':
print("running tests")
unittest.main()
print("tests complete")

0 comments on commit a562aaf

Please sign in to comment.