Coder Social home page Coder Social logo

demkeys / unity-gltf-importer Goto Github PK

View Code? Open in Web Editor NEW
2.0 2.0 0.0 30 KB

A very basic glTF importer for Unity. Made for educational purposes.

C# 100.00%
gltf gltf-format unity3d gltf2-loader unity3d-plugin unity-plugin gltf2 importer unity

unity-gltf-importer's Introduction

Unity-glTF-Importer

A very basic glTF importer for Unity. I made this for educational purpose so that I can understand the glTF file format better. You are free to use the code in this repo however your like.


This is a Scripted Importer to import *.gltf files. Currently only supports glTF Embedded files. Support for glTF Separate files and glTF Binary files might be added at a later time.

Features:

  • Reads and processes first node of the glTF file. Currently only Mesh geometry datais processed. Support for Animation, Skinning, etc. data may be added in the future.
  • Creates a prefab containing:
    • Gameobject (Main Object) containing:
      • MeshFilter
      • MeshRenderer
    • Mesh (Sub Object)
    • One or more Materails (Sub Objects)
  • Supports meshes with multiple materials.

Notes:

  • Child gameobjects are currently not supported. Support may be added in the future.
  • SubAssets are not editable in the Inspector by default. So to allow materials to be editable, the material assets are created spearately and referenced in the main asset. Since they are individual assets you will be able to edit them in the inspector. This is a temp fix implemented due to time constraints.
  • When a glTF file is imported, if a material it requires already exists in the same directory, that material will be referenced. If it doesn't exist, a new material asset will be created in the directory. Something to look out for here is that a material (that already exists in the directory) that is being referenced could be a SubAsset of another asset and might not be editable. It's a not a huge problem but something to keep in mind.

Future note: To add support for child gameobjects, maybe change the logic a bit so that all the nodes are scanned and the first node that contains children is converted to a gameobject, along with all it's child gameobjects.

Usage Instructions:

Import GLTF folder into your project. This will import the Scripted Importer along with all the other files needed. You can then drag and drop a *.gltf file into your project and the importer will generate a prefab out of it.

Tested with Unity 2021.1.0f1.

unity-gltf-importer's People

Contributors

demkeys avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar

unity-gltf-importer's Issues

Already existing materials (same name) get overridden on import

Scenario:
Asset A1 is imported. A1's MeshRenderer expects a material M1, so material M1 is created during the import process and a reference to it is added in the A1 prefab's MeshRenderer.
Then Asset A2 is imported. A2's MeshRenderer also expects a material named M1 so the importer creates a new material asset named M1 and adds a reference to it in A2's prefab. This causes the previous M1 material asset to get overridden. Somehow there is still an M1 material attach to A1's MeshRenderer, but it is not linked to any asset.

Possible solution:
Before creating the material M1 object and asset, scan the current folder to see if a material M1 asset already exists. If yes, load the material object from that asset and add a reference to that in A1's MeshRenderer. If no, the proceed with creating a name material object and asset. As a result, when A2 gets imported, if should then have a reference to the earlier created M1 material, and will not try to create it's own M1 material, but will instead add a reference to that material.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.