warrenm / GLTFKit2

A glTF 2.0 asset loader and exporter for Objective-C and Swift.
MIT License
150 stars 26 forks source link

How to use GLTFDracoMeshDecompressor need example #53

Closed dev9970 closed 5 months ago

dev9970 commented 5 months ago

Is there any example of How to use GLTFDracoMeshDecompressor in swift ? need more explanation with example

warrenm commented 5 months ago

GLTFAsset.dracoDecompressorClassName = "DracoDecompressor"

daninils commented 5 months ago

There is a sample implementation of it here: https://github.com/warrenm/GLTFKit2/blob/395eca255a2f1f9ae9d1bb91034a6cb58b1c5a63/GLTFViewer/macOS/SampleDracoPlugin.mm#L64

warrenm commented 5 months ago

There's a complete example of how to use GLTFKit2 with draco decompression in the official glTF viewer for iOS published by the Khronos group here.

Here's a list of steps you can use to add draco support to your own app, assuming you have an existing Swift project that already uses GLTFKit2 as a Swift package.

  1. Add DracoSwift as a Swift package dependency. This will automatically download and link against a pre-built draco binary that has support for most Apple platforms. (Alternatively, you can build draco from source yourself, but that's outside the scope of this issue).
  2. Copy the SampleDracoPlugin.h and SampleDracoPlugin.mm files from the macOS sample viewer in the GLTFKit2 repo. These contain an Objective-C implementation of a basic draco decompressor that conforms to the protocol expected by GLTFKit2's draco plugin system. (It may be possible to write such a class in Swift with Swift 5.9's C++ interoperability, but I haven't tried this myself and can't guarantee it will work).
  3. If you don't already have a bridging header in your Swift project, add one.
  4. #import "SampleDracoPlugin.h" (or your own plugin's header) in the bridging header so your plugin's interface becomes available to your Swift code.
  5. Before loading any assets (e.g., at app launch), set the class name of your plugin as the dracoDecompressorClassName class property on the GLTFAsset class. This will allow the asset loader to instantiate your loader plugin and decode draco-compressed assets for you.
warrenm commented 5 months ago

This issue will be automatically closed as complete in seven days if no further response is received.

warrenm commented 5 months ago

Closing.