Convert Figma logo to code with AI

Siccity logoGLTFUtility

Simple GLTF importer for Unity

1,025
220
1,025
117

Top Related Projects

1,255

Efficient glTF 3D import / export package for Unity

5,133

PUER(普洱) Typescript. Let's write your game in UE or Unity with TypeScript.

Quick Overview

GLTFUtility is a lightweight and easy-to-use Unity package for importing glTF files. It provides a simple way to load 3D models, animations, and materials from glTF and glb files directly into Unity projects, supporting both runtime and editor imports.

Pros

  • Simple and straightforward API for importing glTF files
  • Supports both runtime and editor imports
  • Lightweight with minimal dependencies
  • Handles animations, materials, and textures

Cons

  • Limited export functionality
  • May not support all advanced glTF features
  • Occasional issues with complex models or non-standard glTF implementations
  • Limited documentation and examples

Code Examples

Loading a glTF file at runtime:

using Siccity.GLTFUtility;

// Load glTF file asynchronously
Importer.LoadFromFileAsync("path/to/model.gltf", new ImportSettings(), (GameObject result) => {
    // Handle the imported GameObject
    result.transform.SetParent(transform);
});

Loading a glb file at runtime:

using Siccity.GLTFUtility;

// Load glb file synchronously
GameObject result = Importer.LoadFromFile("path/to/model.glb");
result.transform.SetParent(transform);

Importing with custom import settings:

using Siccity.GLTFUtility;

ImportSettings settings = new ImportSettings {
    generateMipMaps = true,
    readWriteEnabled = true,
    animationSettings = new AnimationSettings {
        looping = true,
        interpolationMode = InterpolationMode.LINEAR
    }
};

Importer.LoadFromFileAsync("path/to/model.gltf", settings, (GameObject result) => {
    // Handle the imported GameObject
});

Getting Started

  1. Install the package via Unity Package Manager:

    • Open the Package Manager (Window > Package Manager)
    • Click the "+" button and choose "Add package from git URL"
    • Enter: https://github.com/Siccity/GLTFUtility.git
  2. Import and use in your script:

using UnityEngine;
using Siccity.GLTFUtility;

public class GLTFLoader : MonoBehaviour
{
    public string gltfFilePath = "path/to/your/model.gltf";

    void Start()
    {
        Importer.LoadFromFileAsync(gltfFilePath, null, OnGLTFLoaded);
    }

    void OnGLTFLoaded(GameObject result)
    {
        Debug.Log("GLTF model loaded successfully!");
        result.transform.SetParent(transform);
    }
}

Competitor Comparisons

1,255

Efficient glTF 3D import / export package for Unity

Pros of glTFast

  • Faster loading and runtime performance, especially for large models
  • Better support for Unity's Universal Render Pipeline (URP) and High Definition Render Pipeline (HDRP)
  • More active development and frequent updates

Cons of glTFast

  • Steeper learning curve and more complex API
  • Less comprehensive documentation compared to GLTFUtility

Code Comparison

GLTFUtility:

public static async Task<GameObject> ImportGLTF(string path) {
    GLTFObject gltfObject = await GLTFParser.ParseGLTF(path);
    return gltfObject.CreateObject();
}

glTFast:

public async Task<bool> Load(string url) {
    var settings = new ImportSettings { generateMipMaps = true };
    var gltf = new GltfImport();
    return await gltf.Load(url, settings);
}

Both libraries provide methods for loading glTF files, but glTFast offers more granular control over import settings and uses a different approach to instantiation. GLTFUtility's API is simpler and more straightforward, while glTFast provides more flexibility at the cost of increased complexity.

5,133

PUER(普洱) Typescript. Let's write your game in UE or Unity with TypeScript.

Pros of puerts

  • Supports TypeScript, allowing for type-safe JavaScript development in Unity
  • Provides a bridge between C# and JavaScript, enabling easier integration of web technologies
  • Offers hot-reload capabilities for faster development iterations

Cons of puerts

  • Steeper learning curve due to its focus on JavaScript/TypeScript integration
  • May introduce additional complexity to Unity projects compared to native C# solutions
  • Potential performance overhead from JavaScript execution

Code Comparison

GLTFUtility (C#):

public static GameObject Import(string path) {
    GLTFObject gltfObject = JsonConvert.DeserializeObject<GLTFObject>(File.ReadAllText(path));
    return gltfObject.Create();
}

puerts (TypeScript):

import { UnityEngine } from 'csharp'

function importGLTF(path: string): UnityEngine.GameObject {
    // Implementation would depend on puerts-specific APIs
    // and how it interfaces with Unity's GameObject system
}

Note: The code comparison is illustrative, as GLTFUtility and puerts serve different purposes. GLTFUtility is specifically for GLTF importing, while puerts is a general-purpose JavaScript bridge for Unity.

Convert Figma logo designs to code with AI

Visual Copilot

Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.

Try Visual Copilot

README

Discord GitHub issues GitHub license

GLTFUtility

Allows you to import and export glTF files during runtime and in editor. glTF is a new opensource 3d model transmission format which supports everything you'll ever need from a format in Unity. Read more about glTF here

2019-04-01_00-46-27 image image

What makes GLTFUtility different?

Focusing on simplicity and ease of use, GLTFUtility aims to be an import-and-forget solution, keeping consistency with built-in functionality.

Installation

Using Unity Package Manager (Help)
  1. "com.siccity.gltfutility": "https://github.com/siccity/gltfutility.git"
Using git
  1. Get Newtonsoft.JSON from one of these sources
  2. Clone GLTFUtility by itself or as a submodule
    • Clone into your assets folder git clone git@github.com:Siccity/GLTFUtility.git
    • Add repo as submodule git submodule add git@github.com:Siccity/GLTFUtility.git Assets/Submodules/GLTFUtility
Manual download
  1. Get Newtonsoft.JSON from the asset store
  2. Download GLTFUtility-master.zip and extract to your project assets

Important notice

Features

System

  • Editor import
  • Editor export
  • Runtime import API
  • Runtime export API
  • GLTF format
  • GLB format
  • Multithreading
  • URP #75
  • HDRP #73
  • LWRP

Spec

  • Static mesh (with submeshes)
  • UVs (up to 8 channels)
  • Normals
  • Tangents
  • Vertex colors
  • Materials (metallic/specular, opaque/mask/blend)
  • Textures (embedded/external)
  • Remote textures (during async only)
  • Rig
  • Avatar/Mask #70
  • Animations (multiple)
  • Morph targets (with experimental names)
  • Cameras

Extensions

  • KHR_texture_transform (partial support)
  • KHR_materials_pbrSpecularGlossiness
  • KHR_lights_punctual #25
  • KHR_draco_mesh_compression #27 WARNING: Said to cause issues on WebGL.
  • KHR_mesh_quantization

Known issues

  • ArgumentNullException: Value cannot be null in build but not in editor.
    • This is most likely due to shaders being stripped from the build. To fix this, add the GLTFUtility shaders to the Always Included Shaders list in Graphic Settings.
  • Draco compression does not work on iOS and UWP

Runtime import API

// Single thread
using Siccity.GLTFUtility;

void ImportGLTF(string filepath) {
   GameObject result = Importer.LoadFromFile(filepath);
}
// Multithreaded
using Siccity.GLTFUtility;

void ImportGLTFAsync(string filepath) {
   Importer.ImportGLTFAsync(filepath, new ImportSettings(), OnFinishAsync);
}

void OnFinishAsync(GameObject result, AnimationClip[] animations) {
   Debug.Log("Finished importing " + result.name);
}

Important shader note

To ensure that Unity includes the GLTFUtility shaders in builds, you must add these shaders to the 'Always Included Shaders' list.

  1. Open Edit -> Project Settings
  2. Open Graphics
  3. Scroll to Always Included Shaders
  4. Under Size, increase the value by 4 and hit Enter.
  5. In the Project panel, navigate to Packages/GLTFUtility/Materials/Built-in.
  6. In this directory are 4 .shader files.
  7. Drag and drop each of the 4 files into one of the 4 newly created rows in Always Included Shaders.