Unity editor wizard that exports to a web page
Clone or download
Pull request Compare This branch is 16 commits ahead, 11 commits behind sketchfab:master.
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
Dependancies
Resources
Samples
.gitignore
ExporterHeader.png
ExporterScene2WebPage.cs
GlTF_Accessor.cs
GlTF_AmbientLight.cs
GlTF_AnimSampler.cs
GlTF_Animation.cs
GlTF_Attributes.cs
GlTF_BufferView.cs
GlTF_Camera.cs
GlTF_Channel.cs
GlTF_ColorOrTexture.cs
GlTF_ColorRGB.cs
GlTF_ColorRGBA.cs
GlTF_DirectionalLight.cs
GlTF_ExporterWindow.cs
GlTF_FloatArray.cs
GlTF_FloatArray4.cs
GlTF_Image.cs
GlTF_Light.cs
GlTF_Material.cs
GlTF_MaterialColor.cs
GlTF_MaterialTexture.cs
GlTF_Matrix.cs
GlTF_Mesh.cs
GlTF_Node.cs
GlTF_Orthographic.cs
GlTF_Perspective.cs
GlTF_PointLight.cs
GlTF_Primitive.cs
GlTF_Program.cs
GlTF_Rotation.cs
GlTF_Sampler.cs
GlTF_Scale.cs
GlTF_Shader.cs
GlTF_Skin.cs
GlTF_SpotLight.cs
GlTF_Target.cs
GlTF_Technique.cs
GlTF_Texture.cs
GlTF_Translation.cs
GlTF_Vector3.cs
GlTF_Writer.cs
LICENSE
Preset.cs
README.md
SceneToGlTFWiz.cs
SimpleJSON.cs

README.md

Unity Scene to Webpage exporter

(A Work In Progress) Unity editor wizard that exports a Unity Scene to a web page using the glTF 2.0 format and three.js to load it.

Plugin based on Unity-glTF-Exporter from https://github.com/tparisi/Unity-glTF-Exporter & https://github.com/sketchfab/Unity-glTF-Exporter

How to use it

Video @ https://youtu.be/kHxErX1yYVM

  • Copy the Unity-Scene2WebPage folder to your Assets/Editor folder. (The folder location and name are important)
  • Once the plugin is imported a new item should appear in the Tools menu. You can access the exporter by going through Tools/Convert Scene to Web page
  • Clicking on it, will launch the browser with the page.

CREDITS

"Low Poly Earth" model (https://www.blendswap.com/blends/view/86599) by CraigForster (https://www.blendswap.com/user/CraigForster) released under CC-0 license.

Supported Unity objects and features so far:

  • Scene objects such as transforms and meshes
  • PBR materials (both Standard and Standard (Specular setup) for metal/smoothness and specular/smoothness respectively). Other materials may also be exported but not with all their channels.
  • Solid and skinning animation (note that custom scripts or humanoid skeletal animation are not exported yet).
  • Lights (In Progress: Basic support available via KHR_Lights extension)

(Note that animation is still in beta)

Please note that custom scripts, shaders and post processes are not exported.

Features

PBR materials

glTF 2.0 core specification includes metal/roughness PBR material declaration. Specular/glossiness workflow is also available but kept under an extension for now.

Link to the glTF 2.0 specification: https://github.com/KhronosGroup/glTF/tree/2.0/specification/2.0

Note: in order to get a correct conversion with Sketchfab materials, the exporter exports bump maps (i.e greyscale textures converted to normal map inside unity) under bumpTexture instead of normalTexture. It's a temporary workaround that will be quickly fixed.

For example,

"normalTexture" : {
    "index" : 2,
    "texCoord" : 0,
    "scale" : 1
},

becomes

"bumpTexture" : {
    "index" : 2,
    "texCoord" : 0,
    "scale" : 1
},

The following example describes a Metallic-Roughness material with transparency:

    "materials": [
        {
            "pbrMetallicRoughness": {
                "baseColorFactor": [1, 1, 1, 1],
                "baseColorTexture" : {
                    "index" : 0,
                    "texCoord" : 0
                },
                "roughnessFactor": 1,
                "metallicFactor": 1,
                "metallicRoughnessTexture" : {
                    "index" : 1,
                    "texCoord" : 0
                }
            },
            "doubleSided": false,
            "alphaMode": "BLEND",
            "alphaCutoff": 0.5,
            "normalTexture" : {
                "index" : 2,
                "texCoord" : 0,
                "scale" : 1
            },
            "occlusionTexture" : {
                "index" : 3,
                "texCoord" : 0,
                "strength" : 0.13
            },
            "emissiveFactor": [1, 1, 1],
            "emissiveTexture" : {
                "index" : 4,
                "texCoord" : 0
            },
            "name": "metallicPlane"
        }
    ],

It's composed of a set of PBR textures, under pbrMetallicRoughness, and a set of additionnal maps. For specular/glossiness workflow, it's still kept under an extension.

The following example describes an opaque Specular-Glossiness material:

{
    "materials": [
        {
            "extensions": {
                "KHR_materials_pbrSpecularGlossiness": {
                    "diffuseFactor": [1, 1, 1, 1],
                    "diffuseTexture" : {
                        "index" : 0,
                        "texCoord" : 0
                    },
                    "glossinessFactor": 0.358,
                    "specularFactor": [0.2, 0.2, 0.2, 1],
                    "specularGlossinessTexture" : {
                        "index" : 1,
                        "texCoord" : 0
                    }               }

            },
            "doubleSided": false,
            "bumpTexture" : {
                "index" : 2,
                "texCoord" : 0
            },
            "emissiveFactor": [0, 0, 0],
            "name": "specularPlane"
        }
    ],

Texture conversion

glTF specification considers OpenGL flipY flag being disabled for images (see this implementation note).

(For more details about Flip Y flag in WebGL, see gl.UNPACK_FLIP_Y_WEBGL parameter).

This flag is enabled for most software, including Unity, so textures need to be flipped along Y axis in order to match glTF specification. The exporter applies this operation on all the exported textures.

Moreover, Unity uses smoothness and not roughness, so alpha channel is inverted for RGBA Metallic/Smoothness textures, also to match glTF specification.

Important notes

Please note that for now, output glTF files may not be 100% compliant with the current state of glTF 2.0 (as mentioned above with bump maps).