Box and Bounding box have different normals

I’m talking about when box is created using Rhino.Input.RhinoGet.GetBox() command compared with box created from rs.AddBox(rs.BoundingBox(some_object_id))

here’s example code:

import rhinoscriptsyntax as rs
import scriptcontext as sc
import Rhino
import time

def test_func():
    box = Rhino.Input.RhinoGet.GetBox()[1]
    box_id = sc.doc.Objects.AddBox(box)
    bbox = rs.BoundingBox(box_id)
    bbox_id = rs.AddBox(bbox)

test_func()

The two objects (boxes) that result from the script have different normal direction on the top face.

Update:
Actually it could be the bottom face.

Is there a way to differentiate between polysurface and extrusion so I can adjust my scripts?
I got it rs.filter.extrusion

Hmm, how is that possible, boxes, as all closed volumes, should have all the normals pointing outwards…

What I do see is that sc.doc.Objects.AddBox(box) creates an extrusion object - even though I have UseExtrusions set to No. When you explode that you get 6 “plane surfaces”.

whereas

bbox_id = rs.AddBox(bbox) creates a polysurface that is composed of 6 faces which when exploded are classified as NURBS surfaces of degree 1 and not plane surfaces as above.

Difficult to know what Rhino.DocObjects.Tables.ObjectTable.AddBox(Box) is actually doing behind the scenes… But it obviously does something differently than rs.AddBox(), which is doing the following with the list of 8 corners:

    box = rhutil.coerce3dpointlist(corners, True)
    brep = Rhino.Geometry.Brep.CreateFromBox(box)
    rc = scriptcontext.doc.Objects.AddBrep(brep)

Edit: Oh, what I wanted to say is that the difference may not be between bounding box and box, because the following (without using bounding box) produces the same effect here:

import rhinoscriptsyntax as rs
import scriptcontext as sc
import Rhino
import time

def test_func():
    box = Rhino.Input.RhinoGet.GetBox()[1]
    box_id = sc.doc.Objects.AddBox(box)
    corners=box.GetCorners()
    bbox_id = rs.AddBox(corners)

test_func()

Still don’t see the problem with the normals though.

Thanks for the reply Mitch,

I have a script that breaks due to this. I’ll try to extract a piece of it that demonstrates the issue. I don’t want to share the complete script in public yet.

@Helvetosaur

Take a look at this code:

import rhinoscriptsyntax as rs
import scriptcontext as sc
import Rhino
import time

tol=sc.doc.ModelAbsoluteTolerance

def test_func():
    box = Rhino.Input.RhinoGet.GetBox()[1]
    box_id = sc.doc.Objects.AddBox(box)
    bbox = rs.BoundingBox(box_id)
    bbox_id = rs.AddBox(bbox)
    
    box_brep = box.ToBrep()
    bbox_brep = rs.coercebrep(bbox_id)
    #
    return box_brep, bbox_brep

def get_planes(brep):
    bbox_brep_faces_list = brep.Faces
    
    # getting all surfaces from the list as separate objects
    s1,s2,s3,s4,s5,s6 = bbox_brep_faces_list
    
    # get plane from the face
    pl1 = s1.TryGetPlane(tol)[1]
    pl2 = s2.TryGetPlane(tol)[1]
    pl3 = s3.TryGetPlane(tol)[1]
    pl4 = s4.TryGetPlane(tol)[1]
    pl5 = s5.TryGetPlane(tol)[1]
    pl6 = s6.TryGetPlane(tol)[1]
    
    list_of_planes = [pl1,pl2,pl3,pl4,pl5,pl6]
    
    return list_of_planes

if __name__ == "__main__":
    ts = time.time()
    
    list_breps = test_func()
    for brep in list_breps:
        print get_planes(brep)
    
    te = time.time()
    print "Elapsed time is {:.2f}".format(te-ts)

The code is printing two lists of planes of both the box and the bbox
These lists I wish to be exactly the same. So that users can select extrusions and polysurfaces with the same result.

The order and the values (normal vector) should be exactly the same.

I think that may be wishful thinking. First, I’m not sure the boxes always have their faces in the same order, and second, even if they do, the return from TryGetPlane() might be different - could be the same “physical” plane in space, but maybe have a different plane origin point and/or a different axis orientation…

The origins appears to be the same. It’s taking the area centroid of the faces, but the order and the axes do not match. It’s very unreliable.

I need to figure out an universal way of flipping and reordering the planes to get the desired result.