Beispiel #1
0
        public void ExportGeometryData_MeshUnityDecomposer_DefaultGeometry()
        {
            // Force runtime mode to set testing package root
            RuntimeUrdf.runtimeModeEnabled = true;
            UrdfAssetPathHandler.SetPackageRoot("Packages/com.unity.robotics.urdf-importer/Tests/Runtime/Assets/URDF/cube/");
            RuntimeUrdf.runtimeModeEnabled     = false;
            UrdfRobotExtensions.importsettings = ImportSettings.DefaultSettings();
            UrdfRobotExtensions.importsettings.convexMethod = ImportSettings.convexDecomposer.unity;

            var    parent       = new GameObject("Parent").transform;
            string path         = "package://meshes/cube.stl";
            var    meshGeometry = new Geometry(mesh: new Mesh(path, new double[] { 1, 1, 1 }));

            UrdfCollisionExtensions.Create(parent, new Collision(meshGeometry));

            UrdfExportPathHandler.SetExportPath("Assets");
            var t      = parent.GetComponentInChildren <UrdfCollision>().transform.GetChild(0);
            var export = UrdfGeometry.ExportGeometryData(GeometryTypes.Mesh, t);

            Assert.IsNotNull(export);

            Object.DestroyImmediate(parent.gameObject);
            List <string> outFailedPaths = new List <string>();

            AssetDatabase.DeleteAssets(new string[] { "Assets/meshes" }, outFailedPaths);
        }
Beispiel #2
0
        public void Create_FromStlVhacdRuntime_CubeMesh()
        {
            // Force runtime mode to set testing package root
            RuntimeUrdf.runtimeModeEnabled = true;
            UrdfAssetPathHandler.SetPackageRoot("Packages/com.unity.robotics.urdf-importer/Tests/Runtime/Assets/URDF/cube/");
            UrdfRobotExtensions.importsettings = ImportSettings.DefaultSettings();

            var    parent       = new GameObject("Parent").transform;
            string path         = "package://meshes/cube.stl";
            var    meshGeometry = new Geometry(mesh: new Mesh(path, new double[] { 1, 1, 1 }));

            UrdfCollisionExtensions.Create(parent, new Collision(meshGeometry));

            // Verify geometry created in Hierarchy
            var urdfCollision = parent.GetComponentInChildren <UrdfCollision>().transform;
            var mesh          = urdfCollision.Find("cube/cube_0").gameObject;

            Assert.IsTrue(mesh.activeInHierarchy);
            Assert.IsNotNull(mesh.GetComponent <MeshCollider>());
            Assert.AreEqual(8, mesh.GetComponent <MeshCollider>().sharedMesh.vertexCount);
            Assert.IsTrue(Vector3.Distance(Vector3.one * 15f, mesh.GetComponent <MeshCollider>().sharedMesh.bounds.extents) < scaleDelta);

            // Verify geometry created in Assets
            Assert.IsNotNull(AssetDatabase.FindAssets("cube t:mesh", new string[] { "Packages/com.unity.robotics.urdf-importer/Tests/Runtime/Assets/URDF/cube/meshes" }));

            AssetDatabase.DeleteAsset("Packages/com.unity.robotics.urdf-importer/Tests/Runtime/Assets/URDF/cube/meshes/cube_1.asset");
            Object.DestroyImmediate(parent.gameObject);
        }
Beispiel #3
0
        public void CreateMatchingMeshCollision_CubeMesh_CopiedCube()
        {
            var urdfFile = "Packages/com.unity.robotics.urdf-importer/Tests/Runtime/Assets/URDF/cube/cube.urdf";

            UrdfRobotExtensions.importsettings = ImportSettings.DefaultSettings();
            UrdfRobotExtensions.importsettings.convexMethod = ImportSettings.convexDecomposer.unity;
            var       robotObject  = UrdfRobotExtensions.CreateRuntime(urdfFile, UrdfRobotExtensions.importsettings);
            Transform visualToCopy = robotObject.transform.Find("base_link/Visuals/unnamed/cube");

            var parent = new GameObject("Parent").transform;

            UrdfGeometryCollision.CreateMatchingMeshCollision(parent, visualToCopy);

            Assert.AreEqual(1, parent.childCount);
            var mesh = parent.GetChild(0).gameObject;

            Assert.IsTrue(mesh.activeInHierarchy);
            Assert.IsNotNull(mesh.GetComponent <MeshCollider>());
            Assert.AreEqual(36, mesh.GetComponent <MeshCollider>().sharedMesh.vertexCount);
            Assert.IsTrue(Vector3.Distance(Vector3.one * 15f, mesh.GetComponent <MeshCollider>().sharedMesh.bounds.extents) < scaleDelta);

            Object.DestroyImmediate(parent.gameObject);  
            Object.DestroyImmediate(robotObject.gameObject);  
        }