[RELEASED] Piglet: glTF Importer

Hi everyone,

I’m happy to announce the first release of the Piglet glTF Importer!

Piglet can import glTF models into your Unity project, either in the Editor by drag-and-drop, or at runtime via a simple API. Piglet can help accelerate your game development by giving you access to free textures, materials, and 3D models from great sites like Sketchfab and Google Poly.

Features

  • import glTF models in the Editor or at runtime
  • import glTF models from .gltf, .glb, or .zip files, using file paths or HTTP URLs
  • extract textures and materials from glTF models, for use with your own 3D models
  • tested with glTF models from Sketchfab, Google Poly, and Blender
  • supported platforms: Windows, Android, WebGL (Unity 2018.4 or newer)
  • full source code provided

Links

Asset Store Page
Web Demo
Manual
Video: Editor Import Demo
Video: Runtime Import Tutorial
Sample Application: PigletViewer

Web Demo

Try Piglet before you buy it by visiting the Web Demo. Tested with Chrome and Firefox on Windows 10 64-bit.


Viewing “SciFi Gun” by mrfetch@sketchfab.com (CC Attribution License) in the Piglet Web Demo.

Editor Import Demo

Importing a glTF model in the Editor via drag-and-drop:

Runtime Import Tutorial

A basic tutorial for importing glTF models at runtime:

Sample Application: PigletViewer

The source code for the Web Demo is published on GitHub with an MIT License, as an additional resource for Piglet users:

https://github.com/AwesomesauceLabs/piglet-viewer

2 Likes

In exchange for early feedback, I’m giving away 10 evaluation copies of the asset.

Please send me a private message or e-mail awesomesaucelabs at gmail if you would like a voucher code. You can provide your feedback via private message, e-mail, or in an asset store review. If you leave an asset store review, please add a disclaimer stating that you received a free copy from the developer.

Thanks!

1 Like

Hey @awesomesaucelabs , I just bought Piglet and wrote you a review. I hope you’ll be able to get animation working soon, my team is looking at using it for .gltf model viewing on WebGL (we use GLTFUtility right now on PC and mobile devices).

Great work on this asset so far! Thanks for writing clean and well-documented code.

@DerrickBarra ,

Thanks so much for the kind words and the positive review! I’m getting a lot of interest in the asset and it’s my first experience of success as an indie developer, so it’s pretty exciting for me.

I’ve had a couple of requests to add animation support already, so I’ll get cracking on that. I’m not very familiar with Unity’s animation systems (yet!), but my best guess is that it will require 1-2 months of work.

@awesomesaucelabs : Don’t forget to take a look at how others have done it! GLTFUtility’s dev ended up adding the feature but was limited to adding the legacy animation system (which makes sense).

@DerrickBarra

Yep will do. Thanks for the tip!

@awesomesaucelabs : FYI I found a potential issue with Piglet’s editor code. You’re looking for Piglet to be under a specific path for your editor code to work, but if the plugin is moved you’ll encounter issues in the editor. It’s a simple fix for the user to do but you should consider either dynamically locating Piglet’s path or warning the user in some way to update a reference file so that your logic doesn’t break.

@DerrickBarra

I see what you mean, and thanks for taking the time to let me know. (I’ve added it to my TODO list for the next release.)

@DerrickBarra

FYI, there’s a new Piglet release (1.0.1) on the store now, which fixes the hard-coded path bug you mentioned above.

I’m making progress with the animation stuff but I expect it will take at least a few weeks still (maybe longer). Looking at the GLTFUtility code was indeed helpful (thank you). I see what you mean now about needing to use the legacy animation system, if you want to create animation clips at runtime.

@awesome-sauce Awesome! I also found another “bug”. If you have another plugin that uses JsonDotNet (in my case, GLTFUtility), then it can cause issues with Piglet being in the same project, which already has it’s own compiled version of JsonDotNet.

In my experience, deleting JsonDotNet from Piglet causes the GLTF plugin to get angry, and removing my separate JsonDotNet plugin from GLTFUtility causes that plugin to fail during model import on mobile devices. There’s probably more testing I could do but for now, I’m just redownloading Piglet whenever I work on Unity WebGL builds and removing GLTFUtility, and then removing piglet for mobile builds and readding GLTFUtility.

I also noticed Piglet doesn’t use its own assembly definition file, you should consider using one for your plugin.

@DerrickBarra

Not sure what’s going on there, but that does sound like an unnecessary hassle.

I never thought of using .asmdef(s) to prevent potential DLL conflicts, but it seems like a good idea. I’ll look into it for the next release.

@DerrickBarra

There’s a new version of Piglet out today (1.0.2) that I hope will make your life a bit easier.

It should now be possible to delete Piglet’s copy of Newtonsoft.Json.dll without getting any errors.

The problem was that GLTFSerialization.dll depended on a specific version of Newtonsoft.Json.dll (version 10:0:0:0). As I learned during debugging, all .NET DLLs must specify the exact versions of the assemblies they depend on, and there is no mechanism for specifying a range of acceptable versions. I solved the problem by replacing GLTFSerialization.dll with the corresponding C# source files, and now Piglet will compile with any recent version of Json.NET.

For good form, I also added .asmdef files in Piglet 1.0.2 like you suggested, although it turned out not to help much with this particular issue.

1 Like

Thanks @awesomesaucelabs , making my life easier!

Please add URP support if there isn’t already! It’s a must!
EDIT
Hm…from the video it doesn’t seem necessary. You don’t use custom shaders or anything.

Hi @Marks4 :slight_smile:

I don’t have any experience with SRP/URP/HDRP, but it’s probably time that I learned about those!

I do include some simple surface shaders with Piglet, which are essential for the proper functioning of the asset. They are located under Assets/Piglet/Resources/Shaders. Those shaders may need to be updated in some way for compatibility with URP, but I’m not sure at the moment.

I’ll look into what’s required for URP. At the moment, I’m pretty focused on animation support, so if it requires a lot of work I may not get to it until later.

Hi @awesomesaucelabs , heads up about a potential “bug” I found with GLTFUtility, and something you should check for with Piglet, since both plugins use JsonDotNet.

So with WebGL builds, making sure we support our ILCPP stripping level of ‘High’ is important for maximum build size reduction and freeing up as much memory as possible for mobile devices (especially mobile WebGL!).

I’m working on trying to do this with GTLFUtility using the [Preserve] attribute and link.xml files, but the GLTFUtility plugin loads models in with incorrect rotation when stripping is set to ‘Medium’ or ‘High’, and I believe it may be because of something being stripped from JsonDotNet (at this point I’ve set [Preserve] on every class and method of GLTFUtility, so the issue probably comes from the JsonDotNet dependency that I can’t fix since that’s a DLL.

Anyways, figured I would let you know about this potential issue with Piglet. I’m going to try to resolve this with the developer of GLTFUtility, but since the issue might be with JsonDotNet, it might affect Piglet as well.

Thanks for the heads up, @DerrickBarra

I don’t have any experience with ILCPP stripping, unfortunately. I wonder if it would it be possible to exclude Json.NET DLL from stripping, while still stripping the rest of the code (maybe via link.xml)?. That would be a good way to test your hypothesis about Json.NET.

Your comment gives me pause, since I have been planning to add the MathNet.Numerics DLL (1.6 MB) to the next version of Piglet (for animation curve calculations).

@awesomesaucelabs So for ILCPP stripping it’s pretty simple, basically for every assembly definition file in your project, the ILCPP tech strips out any classes, methods, and variables that are unused in your project. So for projects like ours where everything is dynamically loaded, we have to put [Preserve] or use link.xml files a lot since technically we don’t use much of anything at build time, since it’s all loaded at runtime.

I am curious to see how much of the MathNet.Numerics library could be stripped out. Unity’s recommendation is to instead of using an entire DLL, developers instead make a new library that only has what they need in order to prevent an entire library from being used. Which seems like the right call to take with JsonDotNet and MathNet.Numerics (use what you need and throw the rest out).

As for making a new library, as long as JsonDotNet and MathNet.Numerics are open source so you can see how they achieved what you need, you can make your own classes/functions that do the same (that’s often times much easier than trying to carefully rip out sections of an existing library without causing bugs).

So for JsonDotNet in GLTFUtility for example, the AOT library is about 400kb, which as far as libraries goes, is very big. So theoretically by only using the JSON logic you specifically need and making a smaller library/classes for that functionality, you could significantly decrease that size.

@DerrickBarra

Thanks for the good advice!

I agree, extracting a subset of the JSON to C# Converter Tool | Iron Software classes/files seems like the best strategy – it’s a good middle ground between using the stock DLLs and writing my own implementations from scratch. For my particular application (linear equation solver), I expect that I’ll be able to cut down the MathNet code quite a bit.

Yeah, I’m aware that the Json.NET DLL is quite big. I’ve often thought about removing my dependency on Json.NET entirely, but stripping it down would be a good first step.

Looking to purchase this for my project, looks super cool and easy to use! I love that it will take a .zip file. Definitely looking forward to Animation support, but URP/HDRP would be awesome too!
If I purchase and edit some of the required shaders you mentioned earlier to hopefully work with URP, do you know of any other functions that might break?

There are plenty of simple tutorials on YouTube on upgrading shaders, so that might be worth looking into :slight_smile:
https://www.youtube.com/results?search_query=upgrade+shaders+to+urp