private static GameObject CreateStlParent(string stlFile) { Mesh[] meshes = StlImporter.ImportMesh(stlFile); if (meshes == null) { return(null); } GameObject parent = new GameObject(Path.GetFileNameWithoutExtension(stlFile)); Material material = GetDefaultDiffuseMaterial(); for (int i = 0; i < meshes.Length; i++) { string meshAssetPath = GetMeshAssetPath(stlFile, i); RuntimeUrdf.AssetDatabase_CreateAsset(meshes[i], meshAssetPath); GameObject gameObject = CreateStlGameObject(meshAssetPath, material); gameObject.transform.SetParent(parent.transform, false); } return(parent); }
public static GameObject CreateStlGameObjectRuntime(string stlFile) { Mesh[] meshes = StlImporter.ImportMesh(stlFile); if (meshes == null) { return(null); } GameObject parent = new GameObject(Path.GetFileNameWithoutExtension(stlFile)); Material material = GetDefaultDiffuseMaterial(); for (int i = 0; i < meshes.Length; i++) { GameObject gameObject = new GameObject(Path.GetFileNameWithoutExtension(GetMeshAssetPath(stlFile, i))); gameObject.AddComponent <MeshFilter>().sharedMesh = meshes[i]; gameObject.AddComponent <MeshRenderer>().sharedMaterial = material; gameObject.transform.SetParent(parent.transform, false); } return(parent); }