// Utilities // Default mesh loading function that can load STLs from file public static void LoadMesh(string path, string ext, Action <GameObject[]> done) { Mesh[] meshes = null; if (ext == "stl") { print("building stl file " + path); meshes = StlLoader.Load(path); } else { throw new Exception("Filetype '" + ext + "' not supported"); } GameObject[] result = new GameObject[meshes.Length]; for (int i = 0; i < meshes.Length; i++) { GameObject gameObject = GameObject.CreatePrimitive(PrimitiveType.Cube); Mesh mesh = meshes[i]; Renderer renderer = gameObject.GetComponent <Renderer>(); renderer.GetComponent <MeshFilter>().mesh = mesh; result[i] = gameObject; } done(result); }
// Default mesh loading function that can // load STLs from file public static void LoadMesh(string path, System.Action <Mesh[]> done) { string fileType = Path.GetExtension(path).ToLower().Replace(".", ""); if (fileType == "stl") { done(StlLoader.Load(path)); } else { throw new System.Exception("Filetype '" + fileType + "' not supported"); } }
// Default mesh loading function that can // load STLs from file public static void LoadMesh(string path, System.Action <Mesh[], Material[]> done) { string fileType = Path.GetExtension(path).ToLower().Replace(".", ""); if (fileType == "stl") { print("building stl file " + path); done(StlLoader.Load(path), null); } else if (fileType == "dae") { print("building dae file " + path); var empty = new string[0]; done(DAELoader.Load(path, ref empty), null); } else { throw new System.Exception("Filetype '" + fileType + "' not supported"); } }
// Default mesh loading function that can // load STLs from file public static void LoadMesh(string path, string ext, Action <GameObject[]> done) { Mesh[] meshes = null; if (ext == "stl") { print("building stl file " + path); meshes = StlLoader.Load(path); } else if (ext == "dae") { print("building dae file " + path); var empty = new string[0]; meshes = DAELoader.LoadFromPath(path, ref empty); } if (meshes == null) { throw new Exception("Filetype '" + ext + "' not supported"); } else { GameObject[] res = new GameObject[meshes.Length]; for (int i = 0; i < meshes.Length; i++) { var mesh = meshes[i]; Renderer r = GameObject .CreatePrimitive(PrimitiveType.Cube) .GetComponent <Renderer>(); r.GetComponent <MeshFilter>().mesh = mesh; res[i] = r.gameObject; } done(res); } }
public GameObject CreateMesh(GameObject root, string meshFile, float sx, float sy, float sz, bool flipYz = false) { // meshFile is file name without file extension related to Resources directory // sx, sy, sz is scale GameObject mesh = null; if (_meshCache.ContainsKey(meshFile) && _meshCache[meshFile] != null) { } else { if (!File.Exists(meshFile)) { throw new RsuResourceException("Cannot find mesh file: " + meshFile); } GameObject loadedMesh = null; string fileExtension = Path.GetExtension(meshFile); switch (fileExtension) { case ".dae": loadedMesh = _colladaLoader.Load(meshFile); break; case ".obj": loadedMesh = _objLoader.Load(meshFile); break; case ".stl": loadedMesh = _stlLoader.Load(meshFile); break; default: // TODO Notsupported Mesh type break; } // save to cache loadedMesh.name = meshFile; loadedMesh.transform.SetParent(_objectCache.transform); loadedMesh.SetActive(false); _meshCache.Add(meshFile, loadedMesh); } mesh = GameObject.Instantiate(_meshCache[meshFile]); if (mesh == null) { throw new RsuResourceException("Cannot load mesh file: " + meshFile); } mesh.SetActive(true); mesh.name = "mesh"; mesh.transform.SetParent(root.transform, true); mesh.transform.localScale = new Vector3((float)sx, (float)sy, (float)sz); mesh.transform.localRotation = new Quaternion(-0.7071f, 0, 0, 0.7071f); // add collider to children foreach (Transform children in mesh.transform) { children.gameObject.AddComponent <MeshCollider>(); } return(mesh); }