Beispiel #1
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);
        }
Beispiel #2
0
        public static string CopyOrCreateMesh(GameObject geometryObject, bool isCollisionGeometry)
        {
            string prefabPath = GetPrefabPath(geometryObject);

            bool foundExistingColladaOrStl = false;

            if (prefabPath != null && prefabPath != "")
            {
                if (Path.GetExtension(prefabPath).ToLower() == ".dae")
                {
                    foundExistingColladaOrStl = true;
                }
                else //Find STL file that corresponds to the prefab, if it already exists
                {
                    string[] foldersToSearch = { Path.GetDirectoryName(prefabPath) };
                    string   prefabName      = Path.GetFileNameWithoutExtension(prefabPath);

                    foreach (string guid2 in RuntimeUrdf.AssetDatabase_FindAssets(prefabName, foldersToSearch))
                    {
                        string possiblePath = RuntimeUrdf.AssetDatabase_GUIDToAssetPath(guid2);
                        if (possiblePath.ToLower().Contains(".stl"))
                        {
                            prefabPath = possiblePath;
                            foundExistingColladaOrStl = true;
                            break;
                        }
                    }
                }
            }

            if (foundExistingColladaOrStl)
            {
                return(CopyMeshToExportDestination(prefabPath));
            }

            return(CreateNewStlFile(geometryObject, isCollisionGeometry));
        }
Beispiel #3
0
 public void AssetDatabase_FindAssets_AssetAsRoot()
 {
     RuntimeUrdf.runtimeModeEnabled = false;
     Assert.IsTrue(RuntimeUrdf.AssetDatabase_FindAssets("TestAsset", new string[] { "Assets/Tests" }).Length > 0);
 }