Skip to content

EverseDevelopment/DracoWrapper

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

47 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Draco C# Wrapper

Nuget Package

Nuget Package

About

This a wrapper project to use google's Draco Compression algorithm with C#

How to use

            var decoder = new GltfDecoder();
            var res = decoder.DecodeFromFileToScene(fileToCompress);
            var scene = res.Value();
            DracoCompressionOptions options = new DracoCompressionOptions();
            SceneUtils.SetDracoCompressionOptions(options, scene);
            var encoder = new GltfEncoder();
            encoder.EncodeSceneToFile(scene, fileToCompressTemp);

When using the NuGet on .Net Core, an error like this "An attempt was made to load a program with an incorrect format" in that case, you can invoke the DLL directly to make it work

public class NonCollectibleAssemblyLoadContext : AssemblyLoadContext
    {
        public NonCollectibleAssemblyLoadContext() : base(isCollectible: false)
        {
        }
    }

var loadContext = new NonCollectibleAssemblyLoadContext();
var assemblyPath = @"C:\location\of\your\dll\DracoWrapper.dll";
Assembly mixedModeAssembly = loadContext.LoadFromAssemblyPath(assemblyPath);

var gltfDecoderType = mixedModeAssembly.GetType("dracowrapper.GltfDecoder");
var gltfDecoderInstance = Activator.CreateInstance(gltfDecoderType);

var decodeFromFileToSceneMethod = gltfDecoderType.GetMethod("DecodeFromFileToScene");
var res = decodeFromFileToSceneMethod.Invoke(gltfDecoderInstance, new object[] { fileToCompress });
var resType = res.GetType();
var valueMethod = resType.GetMethod("Value");
var scene = valueMethod.Invoke(res, null);

var dracoCompressionOptionsType = mixedModeAssembly.GetType("dracowrapper.DracoCompressionOptions");
var dracoCompressionOptionsInstance = Activator.CreateInstance(dracoCompressionOptionsType);

var sceneUtilsType = mixedModeAssembly.GetType("dracowrapper.SceneUtils");
var setDracoCompressionOptionsMethod = sceneUtilsType.GetMethod("SetDracoCompressionOptions");
setDracoCompressionOptionsMethod.Invoke(null, new object[] { dracoCompressionOptionsInstance, scene });

var gltfEncoderType = mixedModeAssembly.GetType("dracowrapper.GltfEncoder");
var gltfEncoderInstance = Activator.CreateInstance(gltfEncoderType);
var encodeSceneToFileMethod = gltfEncoderType.GetMethod("EncodeSceneToFile");
encodeSceneToFileMethod.Invoke(gltfEncoderInstance, new object[] { scene, fileToCompressTemp });

Contributors

This repo is primarily managed by E-verse and by People Like You™.

Help improve this repo

If you're interested in contributing to this repo, just submit a pull request or a feature request.

About us

We are an international mix of AEC professionals, product designers, and software developers. We work together to transform construction requirements into accurate and partnership-driven technological solutions.

About

This is a wrapper project to use google's Draco Compression algorithm with C#

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages