Ejemplo n.º 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);
        }
Ejemplo n.º 2
0
        public void Create_CylinderMesh_AssetCreated()
        {
            // Force runtime mode to set testing package root
            RuntimeUrdf.runtimeModeEnabled = true;
            UrdfAssetPathHandler.SetPackageRoot("Assets/Tests/Runtime/GeometryTests");
            RuntimeUrdf.runtimeModeEnabled = false;
            var parent = new GameObject("Parent").transform;

            UrdfGeometryCollision.Create(parent, GeometryTypes.Cylinder);

            // Verify Cylinder created in Hierarchy
            var createdCylinder = parent.Find("Cylinder").gameObject;

            Assert.IsTrue(createdCylinder.activeInHierarchy);
            Assert.IsNotNull(createdCylinder.GetComponent <MeshCollider>());

            // Check for standard values on collider
            Assert.AreEqual(1864, createdCylinder.GetComponent <MeshCollider>().sharedMesh.vertexCount);
            Assert.IsTrue(Vector3.Distance(Vector3.zero, createdCylinder.GetComponent <MeshCollider>().sharedMesh.bounds.center) < centerDelta);
            Assert.IsTrue(Vector3.Distance(new Vector3(0.5f, 1f, 0.5f), createdCylinder.GetComponent <MeshCollider>().sharedMesh.bounds.extents) < scaleDelta);
            // Verify Cylinder created in Assets
            Assert.IsNotNull(RuntimeUrdf.AssetDatabase_FindAssets("Cylinder t:mesh", new string[] { "Assets/Tests/Runtime/GeometryTests" }));

            AssetDatabase.DeleteAsset("Assets/Tests/Runtime/GeometryTests/Cylinder.asset");
            Object.DestroyImmediate(parent.gameObject);
        }
Ejemplo n.º 3
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);
        }
 public void GetRelativeAssetPath_Runtime_Success()
 {
     RuntimeUrdf.runtimeModeEnabled = true;
     // Starting with Application.dataPath
     Assert.AreEqual("Assets/Valid/Path", UrdfAssetPathHandler.GetRelativeAssetPath($"{Application.dataPath}/Valid/Path"));
     // Not starting with dataPath
     Assert.AreEqual("Assets/Valid/Path", UrdfAssetPathHandler.GetRelativeAssetPath($"Assets/Valid/Path"));
 }
 public void GetRelativeAssetPath_Nonruntime_NullValues()
 {
     RuntimeUrdf.runtimeModeEnabled = false;
     // Everything returns null during non-runtime
     Assert.IsNull(UrdfAssetPathHandler.GetRelativeAssetPath("Invalid/Asset/Path"));
     Assert.IsNull(UrdfAssetPathHandler.GetRelativeAssetPath($"{assetRoot}/TestAsset.txt"));
     Assert.IsNull(UrdfAssetPathHandler.GetRelativeAssetPath($"Packages/com.unity.robotics.urdf-importer/Tests/Runtime/AssetHandlers/UrdfAssetPathHandlerTests.cs"));
 }
 public void GetSetPackageRoot_RuntimeModeEnabled_Success()
 {
     // Force runtime mode to set testing package root
     RuntimeUrdf.runtimeModeEnabled = true;
     UrdfAssetPathHandler.SetPackageRoot(assetRoot);       // Set oldPackagePath
     UrdfAssetPathHandler.SetPackageRoot(assetRoot, true); // Run correctPackageRoot
     Assert.AreEqual(assetRoot, UrdfAssetPathHandler.GetPackageRoot());
 }
        public void GetRelativeAssetPathFromUrdfPath_CubeUrdf_Success()
        {
            string urdfRoot = "Packages/com.unity.robotics.urdf-importer/Tests/Runtime/Assets/URDF/cube";

            // Force runtime mode to set testing package root
            RuntimeUrdf.runtimeModeEnabled = true;
            UrdfAssetPathHandler.SetPackageRoot(urdfRoot);
            RuntimeUrdf.runtimeModeEnabled = false;

            Assert.AreEqual($"{urdfRoot}/meshes/cube.prefab", UrdfAssetPathHandler.GetRelativeAssetPathFromUrdfPath("package://meshes/cube.stl"));
            Assert.AreEqual($"{urdfRoot}/meshes/cube.prefab", UrdfAssetPathHandler.GetRelativeAssetPathFromUrdfPath("../meshes/cube.stl"));
        }
Ejemplo n.º 8
0
    public void Synchronize(Robot robot, GameObject rootObject, string assetRoot)
    {
        GameObject robotGameObject = rootObject;

        robotGameObject.AddComponentIfNotExists <UrdfRobot>();

        UrdfAssetPathHandler.SetPackageRoot(assetRoot);
        UrdfMaterial.InitializeRobotMaterials(robot);
        UrdfPlugins.Synchronize(robotGameObject.transform, robot.plugins);

        UrdfLinkExtensions.Synchronize(robotGameObject.transform, robot.root);
    }
        public void GetMaterialAssetPath_AssetAndPackage_Success()
        {
            // Force runtime mode to set testing package root
            RuntimeUrdf.runtimeModeEnabled = true;
            UrdfAssetPathHandler.SetPackageRoot(assetRoot);
            RuntimeUrdf.runtimeModeEnabled = false;
            Assert.AreEqual($"{assetRoot}/Materials/TestMaterial.mat", UrdfAssetPathHandler.GetMaterialAssetPath("TestMaterial"));


            // Force runtime mode to set testing package root
            RuntimeUrdf.runtimeModeEnabled = true;
            UrdfAssetPathHandler.SetPackageRoot(packageRoot);
            RuntimeUrdf.runtimeModeEnabled = false;
            Assert.AreEqual($"{packageRoot}/Materials/TestMaterial.mat", UrdfAssetPathHandler.GetMaterialAssetPath("TestMaterial"));
        }
        private static void CreateUrdfObject()
        {
            //Get path to asset, check if it's a urdf file
            string assetPath = AssetDatabase.GetAssetPath(Selection.activeObject);

            if (Path.GetExtension(assetPath)?.ToLower() == ".urdf")
            {
                UrdfRobot.Create(UrdfAssetPathHandler.GetFullAssetPath(assetPath));
            }
            else
            {
                EditorUtility.DisplayDialog("URDF Import",
                                            "The file you selected was not a URDF file. A robot can only be imported from a valid URDF file.", "Ok");
            }
        }
        public void IsValidAssetPath_Nonruntime_Success()
        {
            RuntimeUrdf.runtimeModeEnabled = false;
            AssetDatabase.CreateAsset(new TextAsset("TestAsset"), $"{assetRoot}/TestAsset.txt");

            // Everything returns null during non-runtime
            Assert.IsFalse(UrdfAssetPathHandler.IsValidAssetPath("Invalid/Asset/Path"));
            Assert.IsFalse(UrdfAssetPathHandler.IsValidAssetPath($"{assetRoot}/TestAsset.txt"));
            Assert.IsFalse(UrdfAssetPathHandler.IsValidAssetPath($"Packages/com.unity.robotics.urdf-importer/Tests/Runtime/AssetHandlers/UrdfAssetPathHandlerTests.cs"));

            RuntimeUrdf.runtimeModeEnabled = true;
            // Everything returns true during runtime
            Assert.IsTrue(UrdfAssetPathHandler.IsValidAssetPath("Invalid/Asset/Path"));
            Assert.IsTrue(UrdfAssetPathHandler.IsValidAssetPath($"{assetRoot}/TestAsset.txt"));
            Assert.IsTrue(UrdfAssetPathHandler.IsValidAssetPath($"Packages/com.unity.robotics.urdf-importer/Tests/Runtime/AssetHandlers/UrdfAssetPathHandlerTests.cs"));
        }
        private static void CreateUrdfObject()
        {
            //Get path to asset, check if it's a urdf file
            string assetPath = AssetDatabase.GetAssetPath(Selection.activeObject);

            if (Path.GetExtension(assetPath)?.ToLower() == ".urdf")
            {
                // Get existing open window or if none, make a new one:
                FileImportMenu window = (FileImportMenu)EditorWindow.GetWindow(typeof(FileImportMenu));
                window.urdfFile = UrdfAssetPathHandler.GetFullAssetPath(assetPath);
                window.minSize  = new Vector2(500, 200);
                window.Show();
            }
            else
            {
                EditorUtility.DisplayDialog("URDF Import",
                                            "The file you selected was not a URDF file. Please select a valid URDF file.", "Ok");
            }
        }
        public void GetFullAssetPath_AssetAndPackageRoot_Success()
        {
            Assert.AreEqual($"{Application.dataPath}/Tests/Runtime/UrdfAssetPathHandler", UrdfAssetPathHandler.GetFullAssetPath(assetRoot));
            string projectPath = Application.dataPath.Substring(0, Application.dataPath.Length - "Assets".Length);

            Assert.AreEqual($"{projectPath}Packages/com.unity.robotics.urdf-importer/Tests/Runtime/UrdfAssetPathHandler", UrdfAssetPathHandler.GetFullAssetPath(packageRoot));
        }