# Invalid ON\_Brep from OpenNURBS

**URL:** <https://discourse.mcneel.com/t/invalid-on-brep-from-opennurbs/189236>\
**Category:** openNURBS\
**Tags:** windows\
**Created:** [August 8, 2024, 7:08am UTC](https://discourse.mcneel.com/t/invalid-on-brep-from-opennurbs/189236 "2024-08-08T07:08:58Z")\
**Posts on this page:** 13\
**Page:** 1

<div class="post-metadata">

**Author:** ![sw11](https://sea3.discourse-cdn.com/mcneel/user_avatar/discourse.mcneel.com/sw11/32/676976_2.png) [@sw11](https://discourse.mcneel.com/u/sw11)\
**Post date:** [August 8, 2024, 7:08am UTC](https://discourse.mcneel.com/t/invalid-on-brep-from-opennurbs/189236/1 "2024-08-08T07:08:58Z")

</div>

Hi.  
When exporting geometries with OpenNURBS 8.0, I found some ON\_Brep with invalid bounding box and the meshes got from ON\_Brep::GetMesh() seem distorted. For example, `ON_Brep::m_box：{m_min={x=-1.033144777886e-309#DEN y=0.0000000000000000 z=18373.311983570755 } m_max={x=4252825.4858648088 y=3476811.6673364569 z=4.9228653096998468e+179 } }`. How can I solve these problems? Thanks.

---

<div class="post-metadata">

**Author:** ![menno](https://sea3.discourse-cdn.com/mcneel/user_avatar/discourse.mcneel.com/menno/32/557284_2.png) [@menno](https://discourse.mcneel.com/u/menno)\
**Post date:** [August 8, 2024, 7:40am UTC](https://discourse.mcneel.com/t/invalid-on-brep-from-opennurbs/189236/2 "2024-08-08T07:40:26Z")

</div>

It would be helpful if you tell some more about how you got the invalid ON\_Brep objects, and share your code that gives this problems if possible.

---

<div class="post-metadata">

**Author:** ![sw11](https://sea3.discourse-cdn.com/mcneel/user_avatar/discourse.mcneel.com/sw11/32/676976_2.png) [@sw11](https://discourse.mcneel.com/u/sw11)\
**Post date:** [August 8, 2024, 7:49am UTC](https://discourse.mcneel.com/t/invalid-on-brep-from-opennurbs/189236/3 "2024-08-08T07:49:55Z")

</div>

This is part of my code.

```auto
ONX_ModelComponentIterator it(onxModel, ON_ModelComponent::Type::ModelGeometry);
for (ON_ModelComponentReference mcr = it.FirstComponentReference(); false == mcr.IsEmpty(); mcr = it.NextComponentReference())
{
    const ON_ModelComponent* modelComponent = mcr.ModelComponent();
    const ON_ModelGeometryComponent* mgc = dynamic_cast<const ON_ModelGeometryComponent*>(modelComponent);
    const ON_Geometry* geometry = mgc->Geometry();
    ON_Brep* aBrep = const_cast<ON_Brep*>(dynamic_cast<const ON_Brep*>(geometry));
    //get boundingBox
    if (NULL != aBrep)
    {
        ON_SimpleArray<const ON_Mesh*> meshs;
        int retValue = aBrep->GetMesh(ON::MeshType(4), meshs);
        for (int mesh_index = 0; mesh_index < meshs.Count(); mesh_index++)
        {
            const ON_Mesh** aMesh = meshs.At(mesh_index);
            int size = (*aMesh)->m_dV.Count() ? (*aMesh)->m_dV.Count() : (*aMesh)->m_V.Count();
            for (int vertexIndex = 0; vertexIndex < size; vertexIndex++)
            {
                ON_3dPoint point = (*aMesh)->m_dV.Count() ? (*aMesh)->m_dV[vertexIndex] : (*aMesh)->m_V[vertexIndex];
                //get vertices...
            }
        }
    }
}

```

---

<div class="post-metadata">

**Author:** ![dale](https://sea3.discourse-cdn.com/mcneel/user_avatar/discourse.mcneel.com/dale/32/685184_2.png) [@dale](https://discourse.mcneel.com/u/dale)\
**Post date:** [August 8, 2024, 8:11pm UTC](https://discourse.mcneel.com/t/invalid-on-brep-from-opennurbs/189236/4 "2024-08-08T20:11:47Z")

</div>

Hi @sw11,

Can you share the .3dm file that produces this?

Thanks,

– Dale

---

<div class="post-metadata">

**Author:** ![sw11](https://sea3.discourse-cdn.com/mcneel/user_avatar/discourse.mcneel.com/sw11/32/676976_2.png) [@sw11](https://discourse.mcneel.com/u/sw11)\
**Post date:** [August 9, 2024, 1:48am UTC](https://discourse.mcneel.com/t/invalid-on-brep-from-opennurbs/189236/5 "2024-08-09T01:48:26Z")

</div>

Hi Dale,  
The .3dm file is too large(997M), how can I send it to you?

---

<div class="post-metadata">

**Author:** ![dale](https://sea3.discourse-cdn.com/mcneel/user_avatar/discourse.mcneel.com/dale/32/685184_2.png) [@dale](https://discourse.mcneel.com/u/dale)\
**Post date:** [August 9, 2024, 4:33am UTC](https://discourse.mcneel.com/t/invalid-on-brep-from-opennurbs/189236/6 "2024-08-09T04:33:52Z")

</div>

[https://www.rhino3d.com/upload](https://www.rhino3d.com/upload)

Sent to [dale@mcneel.com](mailto:dale@mcneel.com)

---

<div class="post-metadata">

**Author:** ![sw11](https://sea3.discourse-cdn.com/mcneel/user_avatar/discourse.mcneel.com/sw11/32/676976_2.png) [@sw11](https://discourse.mcneel.com/u/sw11)\
**Post date:** [August 9, 2024, 8:49am UTC](https://discourse.mcneel.com/t/invalid-on-brep-from-opennurbs/189236/7 "2024-08-09T08:49:53Z")

</div>

The file has been uploaded.

---

<div class="post-metadata">

**Author:** ![dale](https://sea3.discourse-cdn.com/mcneel/user_avatar/discourse.mcneel.com/dale/32/685184_2.png) [@dale](https://discourse.mcneel.com/u/dale)\
**Post date:** [August 9, 2024, 3:16pm UTC](https://discourse.mcneel.com/t/invalid-on-brep-from-opennurbs/189236/8 "2024-08-09T15:16:02Z")

</div>

Hi @sw11,

I am not seeing your file. Can you zip and resend?

Thanks,

– Dale

---

<div class="post-metadata">

**Author:** ![sw11](https://sea3.discourse-cdn.com/mcneel/user_avatar/discourse.mcneel.com/sw11/32/676976_2.png) [@sw11](https://discourse.mcneel.com/u/sw11)\
**Post date:** [August 20, 2024, 2:05pm UTC](https://discourse.mcneel.com/t/invalid-on-brep-from-opennurbs/189236/9 "2024-08-20T14:05:13Z")

</div>

Hi @dale  
I’ve reuploaded it. Did you received the file?

---

<div class="post-metadata">

**Author:** ![dale](https://sea3.discourse-cdn.com/mcneel/user_avatar/discourse.mcneel.com/dale/32/685184_2.png) [@dale](https://discourse.mcneel.com/u/dale)\
**Post date:** [August 20, 2024, 5:49pm UTC](https://discourse.mcneel.com/t/invalid-on-brep-from-opennurbs/189236/10 "2024-08-20T17:49:04Z")

</div>

Hi @sw11,

Yes, I was finally able to get your file - thank you.

I’m not finding any Breps with invalid bounding boxes.

```auto
  int brep_count = 0;
  int invalid_bbox_count = 0;

  ONX_ModelComponentIterator it(model, ON_ModelComponent::Type::ModelGeometry);
  const ON_ModelComponent* model_component = nullptr;
  for (model_component = it.FirstComponent(); nullptr != model_component; model_component = it.NextComponent())
  {
    const ON_ModelGeometryComponent* model_geometry = ON_ModelGeometryComponent::Cast(model_component);
    if (nullptr != model_geometry)
    {
      const ON_Brep* brep = ON_Brep::Cast(model_geometry->Geometry(nullptr));
      if (nullptr != brep)
      {
        brep_count++;
        ON_BoundingBox bbox = brep->BoundingBox();
        if (!bbox.IsValid())
        {
          invalid_bbox_count++;
        }
      }
    }
  }

```

8432 Breps, 0 with invalid bounding boxes.

To compute the bounding box of a mesh, use `ON_Mesh::GetBoundingBox`.

– Dale

---

<div class="post-metadata">

**Author:** ![sw11](https://sea3.discourse-cdn.com/mcneel/user_avatar/discourse.mcneel.com/sw11/32/676976_2.png) [@sw11](https://discourse.mcneel.com/u/sw11)\
**Post date:** [August 21, 2024, 3:13am UTC](https://discourse.mcneel.com/t/invalid-on-brep-from-opennurbs/189236/11 "2024-08-21T03:13:20Z")

</div>

Hi @dale ,  
For example, ON\_ModelGeometryComponent{af5e78fb-be34-48bf-834b-ae1a4c4e85eb} and  
{9170d6f7-1390-4df7-bfb6-8cc77b3f3200}, the z value of their box.m\_max is extremely large. Is that normal?  
I also get the corresponding meshes from ON\_Brep::GetMesh(). And the bounding box computed from ON\_Mesh::m\_dV is different from ON\_Mesh::BoundingBox(). And the mesh got from brep seems to be distorted when rendering. Why does this happen?  
Thanks.

---

<div class="post-metadata">

**Author:** ![dale](https://sea3.discourse-cdn.com/mcneel/user_avatar/discourse.mcneel.com/dale/32/685184_2.png) [@dale](https://discourse.mcneel.com/u/dale)\
**Post date:** [August 21, 2024, 5:21pm UTC](https://discourse.mcneel.com/t/invalid-on-brep-from-opennurbs/189236/12 "2024-08-21T17:21:40Z")

</div>

Hi @sw11,

The two objects appear to be microscopic - use Rhino’s `SelId` command to select them.

The model’s unit seem is in millimeters, seems wrong.

– Dale

---

<div class="post-metadata">

**Author:** ![sw11](https://sea3.discourse-cdn.com/mcneel/user_avatar/discourse.mcneel.com/sw11/32/676976_2.png) [@sw11](https://discourse.mcneel.com/u/sw11)\
**Post date:** [August 27, 2024, 7:28am UTC](https://discourse.mcneel.com/t/invalid-on-brep-from-opennurbs/189236/13 "2024-08-27T07:28:59Z")

</div>

Hi @dale ,  
When I use the SelId command, I still can’ see the two objects. May be the .3dm file obtained from the upstream users is wrong. - so Is the problematic bounding box caused by microscopic objects? Is there any approach to identify this kind of objects in advance?
