From 227a5233102c338ae914099736aa109a9530458e Mon Sep 17 00:00:00 2001 From: Diogo Raphael Cravo Date: Tue, 5 Apr 2022 10:17:14 -0300 Subject: [PATCH] fix production spec path used in bounding box computation --- core.go | 2 +- core_test.go | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 51 insertions(+), 1 deletion(-) diff --git a/core.go b/core.go index 3d635a3..0d2d16a 100644 --- a/core.go +++ b/core.go @@ -247,7 +247,7 @@ func (m *Model) BoundingBox() Box { defer wg.Done() item := m.Build.Items[i] if o, ok := m.FindObject(item.ObjectPath(), item.ObjectID); ok { - ibox := o.boundingBox(m, "") + ibox := o.boundingBox(m, item.ObjectPath()) if ibox != emptyBox { mu.Lock() box = box.extend(item.Transform.MulBox(ibox)) diff --git a/core_test.go b/core_test.go index 55803bd..3cba7d0 100644 --- a/core_test.go +++ b/core_test.go @@ -476,6 +476,56 @@ func TestModel_BoundingBox(t *testing.T) { }}}, }}, }, Box{Min: Point3D{10, 20, 30}, Max: Point3D{110, 120, 130}}}, + {"non-root-model", &Model{ + Build: Build{Items: []*Item{ + {ObjectID: 2, Transform: Identity(), AnyAttr: spec.AnyAttr{&fakeAttr{Value: "/other.model"}}}, + }}, + Resources: Resources{}, + Childs: map[string]*ChildModel{ + "/other.model": &ChildModel{ + Resources: Resources{Objects: []*Object{ + {ID: 1, Mesh: &Mesh{Vertices: Vertices{Vertex: []Point3D{ + {0, 10, 20}, + {100, 110, 120}, + }}}}, + {ID: 2, Components: &Components{Component: []*Component{ + {ObjectID: 1, Transform: Identity().Translate(10, 10, 10)}, + {ObjectID: 10}, + }}}, + }}, + }, + }, + }, Box{Min: Point3D{10, 20, 30}, Max: Point3D{110, 120, 130}}}, + {"model-tree", &Model{ + Build: Build{Items: []*Item{ + {ObjectID: 2, Transform: Identity(), AnyAttr: spec.AnyAttr{&fakeAttr{Value: "/other.model"}}}, + }}, + Resources: Resources{}, + Childs: map[string]*ChildModel{ + "/leaf.model": &ChildModel{ + Resources: Resources{Objects: []*Object{ + {ID: 1, Mesh: &Mesh{Vertices: Vertices{Vertex: []Point3D{ + {0, 10, 20}, + {100, 110, 120}, + }}}}, + }}, + }, + "/another.model": &ChildModel{ + Resources: Resources{Objects: []*Object{ + {ID: 2, Components: &Components{Component: []*Component{ + {ObjectID: 1, Transform: Identity().Translate(7, 7, 7), AnyAttr: spec.AnyAttr{&fakeAttr{Value: "/leaf.model"}}}, + }}}, + }}, + }, + "/other.model": &ChildModel{ + Resources: Resources{Objects: []*Object{ + {ID: 2, Components: &Components{Component: []*Component{ + {ObjectID: 2, Transform: Identity().Translate(3, 3, 3), AnyAttr: spec.AnyAttr{&fakeAttr{Value: "/another.model"}}}, + }}}, + }}, + }, + }, + }, Box{Min: Point3D{10, 20, 30}, Max: Point3D{110, 120, 130}}}, } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) {