UnityGLTF插件扩展,支持加载bmp贴图
插件原方法:
public Stream LoadStream(string relativeFilePath) { if (relativeFilePath == null) { throw new ArgumentNullException("relativeFilePath"); } string pathToLoad = Path.Combine(_rootDirectoryPath, relativeFilePath); pathToLoad = pathToLoad.Replace("file:///", ""); if (!File.Exists(pathToLoad)) { Debug.LogError("Buffer file not found" + pathToLoad); throw new FileNotFoundException("Buffer file not found", relativeFilePath); } return File.OpenRead(pathToLoad); }
修改后:
public Stream LoadStream(string relativeFilePath) { if (relativeFilePath == null) { throw new ArgumentNullException("relativeFilePath"); } string pathToLoad = Path.Combine(_rootDirectoryPath, relativeFilePath); pathToLoad = pathToLoad.Replace("file:///", ""); if (!File.Exists(pathToLoad)) { Debug.LogError("Buffer file not found" + pathToLoad); throw new FileNotFoundException("Buffer file not found", relativeFilePath); } var fileStream = File.OpenRead(pathToLoad); if (!string.IsNullOrEmpty(relativeFilePath) && relativeFilePath.ToLower().EndsWith(".bmp")) { var bitmap = new System.Drawing.Bitmap(fileStream); var memoryStream = new MemoryStream(); bitmap.Save(memoryStream, System.Drawing.Imaging.ImageFormat.Png); bitmap.Dispose(); fileStream.Dispose(); return memoryStream; } else { return fileStream; } }