IEnumerator DownloadModel(string path, string ext, Action <GameObject[]> done) { using (UnityWebRequest www = UnityWebRequest.Get(path)) { yield return(www.SendWebRequest()); if (www.isNetworkError || www.isHttpError) { Debug.LogError(www.error); } else { if (ext == "stl") { Mesh[] meshes = StlLoader.Parse(www.downloadHandler.data); 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); } } } }
// 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); }
public ObjectController(GameObject cache) { _objectCache = cache; _objLoader = new OBJLoader(); _colladaLoader = new ColladaLoader(); _stlLoader = new StlLoader(); _meshCache = new Dictionary <string, GameObject>(); }
// 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); } }