All Projects → warrenm → Gltfkit

warrenm / Gltfkit

Licence: isc
An Objective-C glTF 2.0 loader and Metal-based renderer

Projects that are alternatives of or similar to Gltfkit

mule
Minimal USD Layout Editor
Stars: ✭ 27 (-80.43%)
Mutual labels:  metal, scenekit
rendering-fw
Rendering framework with rasterizers & path tracers implemented using Vulkan, OptiX & OpenGL
Stars: ✭ 81 (-41.3%)
Mutual labels:  metal, gltf
HelloMetal
A Suite of Metal Examples written in Swift 4.2. Highlights: Model I/O - SceneKit - OpenEXR.
Stars: ✭ 36 (-73.91%)
Mutual labels:  metal, scenekit
Herebedragons
A basic 3D scene implemented with various engines, frameworks or APIs.
Stars: ✭ 1,616 (+1071.01%)
Mutual labels:  metal, scenekit
Gravitational Waves Playground
Make gravitational waves visible in an interactive iPad simulation.
Stars: ✭ 33 (-76.09%)
Mutual labels:  metal, scenekit
ThickRedLine
Thick Red Line - drawing thick lines for SceneKit with metal shaders
Stars: ✭ 40 (-71.01%)
Mutual labels:  metal, scenekit
GLTFKit2
A glTF 2.0 asset loader and exporter for Objective-C and Swift.
Stars: ✭ 30 (-78.26%)
Mutual labels:  scenekit, gltf
Ios Learning Materials
📚Curated list of articles, web-resources, tutorials and code repositories that may help you dig a little bit deeper into iOS [and Apple Platforms].
Stars: ✭ 1,380 (+900%)
Mutual labels:  metal, scenekit
Metalscope
Metal-backed 360° panorama view for iOS
Stars: ✭ 293 (+112.32%)
Mutual labels:  metal, scenekit
VRMKit
VRM loader and VRM renderer (3D model / gltf)
Stars: ✭ 85 (-38.41%)
Mutual labels:  scenekit, gltf
Arkit Sampler
Code examples for ARKit.
Stars: ✭ 1,334 (+866.67%)
Mutual labels:  metal, scenekit
Gltfscenekit
glTF loader for SceneKit
Stars: ✭ 124 (-10.14%)
Mutual labels:  gltf, scenekit
Metal Point Cloud
A point-cloud made from 3d data with Metal.
Stars: ✭ 116 (-15.94%)
Mutual labels:  metal
Crossshader
⚔️ A tool for cross compiling shaders. Convert between GLSL, HLSL, Metal Shader Language, or older versions of GLSL.
Stars: ✭ 113 (-18.12%)
Mutual labels:  metal
Artetris
Augmented Reality Tetris made with ARKit and SceneKit
Stars: ✭ 1,483 (+974.64%)
Mutual labels:  scenekit
Code Vr
🐍 Program and explore real applications with virtual reality! Learn how to program, compete to build apps, and even collaborate with other people in realtime, in game or not!
Stars: ✭ 131 (-5.07%)
Mutual labels:  gltf
Yudisplacementtransition
A GPU accelerated transition library makes use of displacement maps to create distortion effects.
Stars: ✭ 121 (-12.32%)
Mutual labels:  metal
Fna3d
FNA3D - 3D Graphics Library for FNA
Stars: ✭ 111 (-19.57%)
Mutual labels:  metal
Ios Rubik Solver
An iOS app that detects a 3x3 Rubik's cube, recognizes the color of all cubies, solves it and provides a 3D visualisation of the solving process.
Stars: ✭ 111 (-19.57%)
Mutual labels:  scenekit
Glsl Optimizer
GLSL optimizer based on Mesa's GLSL compiler. Used to be used in Unity for mobile shader optimization.
Stars: ✭ 1,506 (+991.3%)
Mutual labels:  metal

GLTFKit

An Objective-C glTF 2.0 loader and Metal-based renderer

A screenshot of a glTF asset rendered with the GLTFMTL framework

Contents

This project consists of several related parts:

  • GLTF.framework: A glTF 2.0 loader framework written in Objective-C (and suitable for use in Swift)
  • GLTFMTL.framework: A framework for rendering glTF assets with Metal
  • GLTFSCN.framework: A framework for converting glTF scenes into SceneKit scenes
  • A viewer app for macOS
  • A SceneKit sample app for macOS

Usage

Using the Framework Projects

You can add the GLTF and GLTFMTL projects as subprojects of your own Xcode project, or build them using the provided workspace and copy the resulting framework binaries into your project.

To use GLTF.framework, link against and embed GLTF.framework.

To use the provided Metal renderer, also link against and embed GLTFMTL framework.

Loading Assets

To load a glTF 2.0 model, import <GLTF/GLTF.h> and use the GLTFAsset class:

GLTFAsset *asset = [[GLTFAsset alloc] initWithURL:url bufferAllocator:bufferAllocator];

The URL must be a local file URL. Loading of remote assets and resources is not supported.

bufferAllocator is an object that knows how to allocate the memory into which glTF buffer data is loaded (it must conform to the GLTFBufferAllocator protocol). To render an asset with the provided Metal renderer, you may pass an instance of the concrete class GLTFMTLBufferAllocator, which is a specialized implementation of GLTFBufferAllocator that knows how to allocate GPU-accesible memory that can be read by Metal. To create such an allocator, you will need to provide it with a reference to a previously-created MTLDevice object:

id<MTLDevice> device = MTLCreateSystemDefaultDevice();
id<GLTFBufferAllocator> bufferAllocator = [[GLTFMTLBufferAllocator alloc] initWithDevice:device];

Rendering Assets

Creating a Metal Renderer

To create Metal renderer, provide the same device that you use to create your assets:

renderer = [[GLTFMTLRenderer alloc] initWithDevice:device];

On the renderer, you need to configure the initial drawable size and pixel formats of the color and depth attachments so that they match those of the textures configured on your render passes. The Metal renderer currently does not support MSAA, nor can these pixel formats be changed once an asset has been drawn for the first time.

If you are drawing into an MTKView, you can configure the renderer to match its settings:

renderer.drawableSize = mtkView.drawableSize;
renderer.colorPixelFormat = mtkView.colorPixelFormat;
renderer.depthStencilPixelFormat = mtkView.depthStencilPixelFormat;

Drawing

The renderer is designed to allow glTF assets to be drawn into the same render command encoder (pass) as other Metal draw calls.

Here is an example of creating a command buffer and command encoder and drawing a glTF asset:

id <MTLCommandBuffer> commandBuffer = [commandQueue commandBuffer];

MTLRenderPassDescriptor *renderPassDescriptor = mtkView.currentRenderPassDescriptor;

id <MTLRenderCommandEncoder> renderEncoder = [commandBuffer renderCommandEncoderWithDescriptor:renderPassDescriptor];

// ... additional command encoder configuration and draw calls ...

[renderer renderScene:asset.defaultScene
        commandBuffer:commandBuffer
       commandEncoder:renderEncoder];

// ... additional command encoder configuration and draw calls ...

[renderEncoder endEncoding];

[commandBuffer presentDrawable:mtkView.currentDrawable];

[commandBuffer addCompletedHandler:^(id<MTLCommandBuffer> buffer) {
    [renderer signalFrameCompletion];
}];

[commandBuffer commit];

Note that if your glTF asset contains transparent meshes, these will be drawn in the order they appear in the scene graph, and may therefore not composite correctly with opaque content or other content.

Interoperating with SceneKit

The included GLTFSCN framework can be used to easily transform glTF assets into collections of SCNScenes to interoperate with SceneKit.

To get the collection of scenes contained in a glTF asset, use the SCNScene class extension method +[SCNScene scenesFromGLTFAsset:options:]. This method returns an array of scenes because there is no SceneKit type that represents a collection of scenes.

Here is an example of how to load a GLTF asset, convert it to a collection of SceneKit scenes, and access the default scene:

id<GLTFBufferAllocator> bufferAllocator = [[GLTFDefaultBufferAllocator alloc] init];
GLTFAsset *asset = [[GLTFAsset alloc] initWithURL:url bufferAllocator:bufferAllocator];
GLTFSCNAsset *scnAsset = [SCNScene assetFromGLTFAsset:asset options:@{}];
SCNScene *scene = scnAsset.defaultScene;

Note the use of the GLTFDefaultBufferAllocator type. This is a buffer allocator that allocates regular memory rather than GPU-accessible memory. If you want to use an asset with both Metal and SceneKit, you should use the GLTFMTLBufferAllocator (as illustrated above) instead.

Status and Conformance

Below is a checklist of glTF features and their current level of support.

Status

Encodings

  • [x] JSON
  • [x] Binary (.glb)

Buffer Storage

  • [x] External references (buffer.uri)
  • [x] Base-64 encoded buffers

Well-Known Vertex Accessor Semantics

  • [x] POSITION
  • [x] NORMAL
  • [x] TANGENT
  • [x] TEXCOORD_0
  • [x] TEXCOORD_1
  • [x] COLOR_0
  • [x] JOINTS_0
  • [x] WEIGHTS_0

Primitive Types

  • [ ] Points
  • [ ] Lines
  • [ ] Line Loop
  • [ ] Line Strip
  • [x] Triangles
  • [x] Triangle Strip
  • [ ] Triangle Fan

Images

  • [x] External image references (image.uri)
  • [x] Base-64 encoded images
  • [x] PNG
  • [x] JPEG
  • [x] TIFF
  • [ ] OpenEXR
  • [x] Radiance

Materials

  • [x] Base color factor
  • [x] Metallic factor
  • [x] Roughness factor
  • [x] Emissive factor
  • [x] Base color map
  • [x] Metallic-roughness map
  • [x] Occlusion map
  • [x] Emissive map
  • [ ] Normal texture scale
  • [x] Alpha mode
    • [x] Opaque alpha mode
    • [x] Mask alpha mode
    • [x] Blend alpha mode
  • [x] Double-sided materials

Samplers

  • [x] Wrap mode
  • [x] Minification/magnification filters
  • [x] Mipmaps

Cameras

  • [x] Perspective cameras
  • [x] Orthographic cameras

Morph Targets

  • [ ] Morph targets

Animation

  • [x] Translation animations
  • [x] Rotation animations
  • [x] Scale animations
  • [ ] Morph target weight animations
  • [x] Linear interpolation
  • [ ] Discrete animations
  • [ ] Cubic spline interpolation

Skinning

  • [x] Joint matrix calculation
  • [x] GPU-based vertex skinning

Sparse Accessors

  • [ ] Sparse accessors

Extensions

  • [ ] KHR_materials_pbrSpecularGlossiness
  • [ ] KHR_materials_common
  • [ ] KHR_lights
  • [x] KHR_materials_unlit
  • [x] KHR_texture_transform
  • [x] EXT_pbr_attributes

Conformance

This implementation is known to be non-conforming to the glTF 2.0 specification and is under active development.

Contributing

Pull requests are gladly accepted, but will be audited strictly in order to maintain code style. If you have any concerns about contributing, please raise an issue on Github so we can talk about it.

License

 Copyright (c) 2018 Warren Moore. All rights reserved.

 Permission to use, copy, modify, and distribute this software for any
 purpose with or without fee is hereby granted, provided that the above
 copyright notice and this permission notice appear in all copies.

 THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
 WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
 MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
 ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
 WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
 ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
 OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.	
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].