Cant work with GLTF
JochnGst opened this issue · 2 comments
Hello,
I want to use the gltf-Toolkit in my projekt to convert gltf-Files to glb-Files for the Mixed Reality Viewer.
First I tried directly to use
var converted = await WindowsMRConversion.ConvertAssetForWindowsMR(tempGltfFile, outputFolder, 512, TexturePacking.OcclusionRoughnessMetallic);
but the result is always a empty ( 0 byte) glb file (without the "_converted" extention on the filename).
next I tried to first serialize the gltf-File to glb an then use the Conversion Methode.
StorageFile sourceGlbFile = await GLTFSerialization.PackGLTFAsync(gltfFile, ApplicationData.Current.LocalFolder, glbfileName);
Here I got direct an exeption "System.Runtime.InteropServices.COMException" in System.Private.CoreLib.ni.dll"
For my tests I use the BoomBox.gltf and Avocado.gltf from the Khronos Repod
https://github.com/KhronosGroup/glTF-Sample-Models/tree/master/sourceModels
Here my full Methode
` public async Task GLBConvertToWindowsMR()
{
const string gltfFileName = "Avocado.gltf";
// Pack the gltf back into a glb file
var gltfFile = await StorageFile.GetFileFromPathAsync(Path.Combine(ApplicationData.Current.LocalFolder.Path, gltfFileName));
var glbfileName = Path.ChangeExtension(gltfFileName, ".glb");
StorageFile sourceGlbFile = await GLTFSerialization.PackGLTFAsync(gltfFile, ApplicationData.Current.LocalFolder, glbfileName);
StorageFile tempGlbFile = await CopyFileToTempFolderAsync(sourceGlbFile.Path);
StorageFolder outputFolder = await CreateTemporaryOutputFolderAsync("Out_" + Path.GetFileNameWithoutExtension(gltfFileName));
var converted = await WindowsMRConversion.ConvertAssetForWindowsMR(tempGlbFile, outputFolder, 512, TexturePacking.OcclusionRoughnessMetallic);
}`
Hi @neuxxx ,
I tried it here and it seems to work fine.
A few notes: The CopyFileToTempFolderAsync
function from UWPTest specifically copies a file from the app package (ms-appx://) to a temp folder. How did you get your assets in the LocalFolder? Did you change CopyFileToTempFolderAsync?
Also note that you don't have to pack the GLTF to a GLB before converting. ConvertAssetToWindowsMR accepts GLTF files as well, as long as all the resources it depends on are also in the temp folder.
Here's my code to test your Avocado scenario from the app package (I added this directly to UWPTest.cs, and added the Avocado gltf and resources as Content to the Assets/Avocado folder on the app package):
public async Task GLBTestForNeuxxx()
{
const string gltfFileName = "Avocado.gltf";
// Copy all the resources to a temp folder, and save a reference to the GLTF file
var folder = await StorageFolder.GetFolderFromPathAsync(Path.Combine(Package.Current.InstalledLocation.Path, "Assets", "Avocado"));
StorageFile copiedGltfFile = null;
foreach (var resource in await folder.GetFilesAsync())
{
var copied = await resource.CopyAsync(ApplicationData.Current.TemporaryFolder, resource.Name, NameCollisionOption.ReplaceExisting);
if (resource.Name == gltfFileName)
{
copiedGltfFile = copied;
}
}
if (copiedGltfFile != null)
{
// Convert the file for Windows MR and pack it.
StorageFolder outputFolder = await CreateTemporaryOutputFolderAsync("Out_" + Path.GetFileNameWithoutExtension(gltfFileName));
var converted = await WindowsMRConversion.ConvertAssetForWindowsMR(copiedGltfFile, outputFolder, 512, TexturePacking.OcclusionRoughnessMetallic);
}
}
Closing - please reopen if necessary