public void TestFindCenter()
        {
            // Create 3 objects
            var cube  = CreateGameObject("cube");
            var cube1 = CreateGameObject("cube1");
            var cube2 = CreateGameObject("cube2");

            // Set their transforms
            cube.transform.localPosition  = new Vector3(23, -5, 10);
            cube1.transform.localPosition = new Vector3(23, -5, 4);
            cube1.transform.localScale    = new Vector3(1, 1, 2);
            cube2.transform.localPosition = new Vector3(28, 0, 10);
            cube2.transform.localScale    = new Vector3(3, 1, 1);

            // Find the center
            var center = ModelExporter.FindCenter(new GameObject[] { cube, cube1, cube2 });

            // Check that it is what we expect
            Assert.AreEqual(center, new Vector3(26, -2.5f, 6.75f));
        }
Exemplo n.º 2
0
        public void TestDefaultSelection()
        {
            // Default selection behavior:
            //  - Export descendants
            //  - Don't export siblings
            //  - Don't export parents
            //  - If both a parent and descendant are selected,
            //    then result will be the same as if just the parent
            //    were selected
            //
            // Default transform export:
            //  - if there is only one root GameObject being exported
            //    then zero out the root transform, leave all descendants
            //    with local transform
            //  - if there are multiple root GameObjects, export
            //    the global transform of root GameObjects, and local transform
            //    of descendants.
            //    if Center Objects is checked in the preferences,
            //    then export the translations so they are centered
            //    around the center of the union of the bounding boxes.

            m_root = CreateHierarchy();
            Assert.IsNotNull(m_root);

            // test without centered objects
            m_centerObjectsSetting.SetObjectPosition(ExportSettings.ObjectPosition.WorldAbsolute);

            // test Export Root
            // Expected result: everything gets exported
            // Expected transform: all transforms unchanged
            var exportedRoot = ExportSelection(m_root, m_centerObjectsSetting);

            CompareHierarchies(m_root, exportedRoot, true, false);
            CompareGlobalTransform(exportedRoot.transform, m_root.transform);

            // test Export Parent1, Child1
            // Expected result: Parent1, Child1, Child2
            // Expected transform: all transforms unchanged
            var parent1 = m_root.transform.Find("Parent1");
            var child1  = parent1.Find("Child1");

            exportedRoot = ExportSelection(new Object[] { parent1.gameObject, child1.gameObject }, m_centerObjectsSetting);
            CompareHierarchies(parent1.gameObject, exportedRoot, true, false);
            CompareGlobalTransform(exportedRoot.transform, parent1);

            // test Export Child2
            // Expected result: Child2
            // Expected transform: Child2 unchanged
            var child2 = parent1.Find("Child2").gameObject;

            exportedRoot = ExportSelection(child2, m_centerObjectsSetting);
            CompareHierarchies(child2, exportedRoot, true, false);
            CompareGlobalTransform(exportedRoot.transform, child2.transform);

            // test Export Child2, Parent2
            // Expected result: Parent2, Child3, Child2
            // Expected transform: Child2 and Parent2 maintain global transform
            var parent2   = m_root.transform.Find("Parent2");
            var exportSet = new Object[] { child2, parent2 };
            // for passing to FindCenter()
            var goExportSet = new GameObject[] { child2.gameObject, parent2.gameObject };

            // test without centering objects
            m_centerObjectsSetting.SetObjectPosition(ExportSettings.ObjectPosition.WorldAbsolute);

            exportedRoot = ExportSelection(exportSet, m_centerObjectsSetting);
            List <GameObject> children = new List <GameObject> ();

            foreach (Transform child in exportedRoot.transform)
            {
                children.Add(child.gameObject);
            }
            CompareHierarchies(new GameObject[] { child2, parent2.gameObject }, children.ToArray());

            // test with centered objects
            m_centerObjectsSetting.SetObjectPosition(ExportSettings.ObjectPosition.LocalCentered);
            var newCenter = ModelExporter.FindCenter(goExportSet);

            exportedRoot = ExportSelection(exportSet, m_centerObjectsSetting);
            children     = new List <GameObject> ();
            foreach (Transform child in exportedRoot.transform)
            {
                children.Add(child.gameObject);
            }
            CompareHierarchies(new GameObject[] { child2, parent2.gameObject }, children.ToArray(), newCenter);
        }