From eee454542bfe25cd05df82f6c8f103da8faa5c9e Mon Sep 17 00:00:00 2001 From: Thor Brigsted Date: Wed, 10 Oct 2018 23:13:11 +0200 Subject: [PATCH] Initial commit --- .gitignore | 25 ++++ LICENSE | 21 ++++ Scripts.meta | 10 ++ Scripts/Editor.meta | 10 ++ Scripts/Editor/GLTFImporter.cs | 38 ++++++ Scripts/Editor/GLTFImporter.cs.meta | 13 +++ Scripts/Extensions.cs | 12 ++ Scripts/Extensions.cs.meta | 13 +++ Scripts/GLTFAccessor.cs | 175 ++++++++++++++++++++++++++++ Scripts/GLTFAccessor.cs.meta | 13 +++ Scripts/GLTFBuffer.cs | 25 ++++ Scripts/GLTFBuffer.cs.meta | 13 +++ Scripts/GLTFBufferView.cs | 25 ++++ Scripts/GLTFBufferView.cs.meta | 13 +++ Scripts/GLTFMesh.cs | 83 +++++++++++++ Scripts/GLTFMesh.cs.meta | 13 +++ Scripts/GLTFNode.cs | 51 ++++++++ Scripts/GLTFNode.cs.meta | 13 +++ Scripts/GLTFObject.cs | 21 ++++ Scripts/GLTFObject.cs.meta | 13 +++ Scripts/GLTFPrimitive.cs | 31 +++++ Scripts/GLTFPrimitive.cs.meta | 13 +++ Scripts/GLTFScene.cs | 12 ++ Scripts/GLTFScene.cs.meta | 13 +++ 24 files changed, 669 insertions(+) create mode 100644 .gitignore create mode 100644 LICENSE create mode 100644 Scripts.meta create mode 100644 Scripts/Editor.meta create mode 100644 Scripts/Editor/GLTFImporter.cs create mode 100644 Scripts/Editor/GLTFImporter.cs.meta create mode 100644 Scripts/Extensions.cs create mode 100644 Scripts/Extensions.cs.meta create mode 100644 Scripts/GLTFAccessor.cs create mode 100644 Scripts/GLTFAccessor.cs.meta create mode 100644 Scripts/GLTFBuffer.cs create mode 100644 Scripts/GLTFBuffer.cs.meta create mode 100644 Scripts/GLTFBufferView.cs create mode 100644 Scripts/GLTFBufferView.cs.meta create mode 100644 Scripts/GLTFMesh.cs create mode 100644 Scripts/GLTFMesh.cs.meta create mode 100644 Scripts/GLTFNode.cs create mode 100644 Scripts/GLTFNode.cs.meta create mode 100644 Scripts/GLTFObject.cs create mode 100644 Scripts/GLTFObject.cs.meta create mode 100644 Scripts/GLTFPrimitive.cs create mode 100644 Scripts/GLTFPrimitive.cs.meta create mode 100644 Scripts/GLTFScene.cs create mode 100644 Scripts/GLTFScene.cs.meta diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..ed64e1c --- /dev/null +++ b/.gitignore @@ -0,0 +1,25 @@ +/[Ll]ibrary/ +/[Tt]emp/ +/[Oo]bj/ +/[Bb]uild/ + +# Autogenerated VS/MD solution and project files +*.csproj +*.unityproj +*.sln +*.suo +*.tmp +*.user +*.userprefs +*.pidb +*.booproj + +# Unity3D generated meta files +*.pidb.meta + +# Unity3D Generated File On Crash Reports +sysinfo.txt + +README.md.meta +LICENSE.md.meta +CONTRIBUTING.md.meta \ No newline at end of file diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..b200d55 --- /dev/null +++ b/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2018 Thor Brigsted + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/Scripts.meta b/Scripts.meta new file mode 100644 index 0000000..35e7f4f --- /dev/null +++ b/Scripts.meta @@ -0,0 +1,10 @@ +fileFormatVersion: 2 +guid: 1a53c6d71b38ddd45974d563dc47f847 +folderAsset: yes +timeCreated: 1538919605 +licenseType: Free +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Scripts/Editor.meta b/Scripts/Editor.meta new file mode 100644 index 0000000..214f21d --- /dev/null +++ b/Scripts/Editor.meta @@ -0,0 +1,10 @@ +fileFormatVersion: 2 +guid: 46478e359a7c2694db7532f3a07945f0 +folderAsset: yes +timeCreated: 1538919615 +licenseType: Free +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Scripts/Editor/GLTFImporter.cs b/Scripts/Editor/GLTFImporter.cs new file mode 100644 index 0000000..1557df1 --- /dev/null +++ b/Scripts/Editor/GLTFImporter.cs @@ -0,0 +1,38 @@ +using System.Collections.Generic; +using System.IO; +using System.Linq; +using UnityEditor.Experimental.AssetImporters; +using UnityEngine; + +namespace Siccity.GLTFUtility { + [ScriptedImporter(1, "gltf")] + public class GLTFImporter : ScriptedImporter { + + public override void OnImportAsset(AssetImportContext ctx) { + GLTFObject gltfObject = JsonUtility.FromJson(File.ReadAllText(ctx.assetPath)); + string directoryRoot = Directory.GetParent(ctx.assetPath).ToString() + "/"; + + // Read buffers + for (int i = 0; i < gltfObject.buffers.Count; i++) { + gltfObject.buffers[i].Read(directoryRoot); + } + + // Get root node indices from scenes + int[] rootNodes = gltfObject.scenes.SelectMany(x => x.nodes).ToArray(); + + if (rootNodes.Length != 1) { + Debug.LogError("Only one root node is currently supported"); + return; + } + + // Add meshes + for (int i = 0; i < gltfObject.meshes.Count; i++) { + ctx.AddSubAsset(gltfObject.meshes[i].name, gltfObject.meshes[i].GetMesh(gltfObject)); + } + + // Parse root node + GameObject root = gltfObject.nodes[0].Create(gltfObject, null); + ctx.SetMainAsset("main obj", root); + } + } +} \ No newline at end of file diff --git a/Scripts/Editor/GLTFImporter.cs.meta b/Scripts/Editor/GLTFImporter.cs.meta new file mode 100644 index 0000000..38aae38 --- /dev/null +++ b/Scripts/Editor/GLTFImporter.cs.meta @@ -0,0 +1,13 @@ +fileFormatVersion: 2 +guid: 1fa4dafe23771ae498589f7f7c22c974 +timeCreated: 1538919678 +licenseType: Free +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Scripts/Extensions.cs b/Scripts/Extensions.cs new file mode 100644 index 0000000..d1cb896 --- /dev/null +++ b/Scripts/Extensions.cs @@ -0,0 +1,12 @@ +using System; + +namespace Siccity.GLTFUtility { + public static class Extensions { + + public static T[] SubArray(this T[] data, int index, int length) { + T[] result = new T[length]; + Array.Copy(data, index, result, 0, length); + return result; + } + } +} \ No newline at end of file diff --git a/Scripts/Extensions.cs.meta b/Scripts/Extensions.cs.meta new file mode 100644 index 0000000..43e2ec0 --- /dev/null +++ b/Scripts/Extensions.cs.meta @@ -0,0 +1,13 @@ +fileFormatVersion: 2 +guid: b28e9070c77e9aa458e0629479371587 +timeCreated: 1539200073 +licenseType: Free +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Scripts/GLTFAccessor.cs b/Scripts/GLTFAccessor.cs new file mode 100644 index 0000000..2abf8a8 --- /dev/null +++ b/Scripts/GLTFAccessor.cs @@ -0,0 +1,175 @@ +using System; +using System.Collections; +using System.Collections.Generic; +using UnityEngine; + +namespace Siccity.GLTFUtility { + /// Reads data from BufferViews + [Serializable] + public class GLTFAccessor { + public int bufferView = -1; + public int byteOffset = -1; + public string type; + public GLType componentType = GLType.UNSET; + public int count = -1; + public float[] min; + public float[] max; + public Sparse sparse; + public Indices indices; + + public Vector4[] ReadVec4(GLTFObject gLTFObject) { + if (type != "VEC4") { + Debug.LogError("Type mismatch! Expected VEC4 got " + type); + return new Vector4[count]; + } + if (componentType != GLType.FLOAT) { + Debug.LogError("Non-float componentType not supported. Got " + (int) componentType); + return new Vector4[count]; + } + + Vector4[] verts = new Vector4[count]; + byte[] bytes = gLTFObject.bufferViews[bufferView].GetBytes(gLTFObject); + int componentSize = GetComponentSize(); + for (int i = 0; i < count; i++) { + int startIndex = i * componentSize; + verts[i].x = System.BitConverter.ToSingle(bytes, startIndex); + startIndex += GetComponentTypeSize(componentType); + verts[i].y = System.BitConverter.ToSingle(bytes, startIndex); + startIndex += GetComponentTypeSize(componentType); + verts[i].z = System.BitConverter.ToSingle(bytes, startIndex); + startIndex += GetComponentTypeSize(componentType); + verts[i].w = System.BitConverter.ToSingle(bytes, startIndex); + } + return verts; + } + + public Vector3[] ReadVec3(GLTFObject gLTFObject) { + if (type != "VEC3") { + Debug.LogError("Type mismatch! Expected VEC3 got " + type); + return new Vector3[count]; + } + if (componentType != GLType.FLOAT) { + Debug.LogError("Non-float componentType not supported. Got " + (int) componentType); + return new Vector3[count]; + } + + Vector3[] verts = new Vector3[count]; + byte[] bytes = gLTFObject.bufferViews[bufferView].GetBytes(gLTFObject); + int componentSize = GetComponentSize(); + for (int i = 0; i < count; i++) { + int startIndex = i * componentSize; + verts[i].x = System.BitConverter.ToSingle(bytes, startIndex); + startIndex += GetComponentTypeSize(componentType); + verts[i].y = System.BitConverter.ToSingle(bytes, startIndex); + startIndex += GetComponentTypeSize(componentType); + verts[i].z = System.BitConverter.ToSingle(bytes, startIndex); + } + return verts; + } + + public Vector2[] ReadVec2(GLTFObject gLTFObject) { + if (type != "VEC2") { + Debug.LogError("Type mismatch! Expected VEC2 got " + type); + return new Vector2[count]; + } + if (componentType != GLType.FLOAT) { + Debug.LogError("Non-float componentType not supported. Got " + (int) componentType); + return new Vector2[count]; + } + + Vector2[] verts = new Vector2[count]; + byte[] bytes = gLTFObject.bufferViews[bufferView].GetBytes(gLTFObject); + int componentSize = GetComponentSize(); + for (int i = 0; i < count; i++) { + int startIndex = i * componentSize; + verts[i].x = System.BitConverter.ToSingle(bytes, startIndex); + startIndex += GetComponentTypeSize(componentType); + verts[i].y = System.BitConverter.ToSingle(bytes, startIndex); + startIndex += GetComponentTypeSize(componentType); + } + return verts; + } + + public int[] ReadInt(GLTFObject gLTFObject) { + if (type != "SCALAR") { + Debug.LogError("Type mismatch! Expected SCALAR got " + type); + return new int[count]; + } + if (componentType != GLType.UNSIGNED_SHORT) { + Debug.LogError("Non-ushort componentType not supported. Got " + (int) componentType); + return new int[count]; + } + + int[] ints = new int[count]; + byte[] bytes = gLTFObject.bufferViews[bufferView].GetBytes(gLTFObject); + int componentSize = GetComponentSize(); + for (int i = 0; i < count; i++) { + int startIndex = i * componentSize; + ints[i] = System.BitConverter.ToUInt16(bytes, startIndex); + } + return ints; + } + + /// Get the size of the attribute type, in bytes + public int GetComponentSize() { + return GetComponentNumber(type) * GetComponentTypeSize(componentType); + } + + public static int GetComponentTypeSize(GLType componentType) { + switch (componentType) { + case GLType.BYTE: + return 1; + case GLType.UNSIGNED_BYTE: + return 1; + case GLType.SHORT: + return 2; + case GLType.UNSIGNED_SHORT: + return 2; + case GLType.FLOAT: + return 4; + default: + Debug.LogError("componentType " + (int) componentType + " not supported!"); + return 0; + } + } + + public static int GetComponentNumber(string type) { + switch (type) { + case "SCALAR": + return 1; + case "VEC2": + return 2; + case "VEC3": + return 3; + case "VEC4": + return 4; + case "MAT2": + return 4; + case "MAT3": + return 9; + case "MAT4": + return 16; + default: + Debug.LogError("type " + type + " not supported!"); + return 0; + } + } + + [Serializable] + public class Sparse { + public int count = -1; + public Values values; + + [Serializable] + public class Values { + public int bufferView = -1; + } + } + + [Serializable] + public class Indices { + public int bufferView = -1; + public int componentType = -1; + } + } +} \ No newline at end of file diff --git a/Scripts/GLTFAccessor.cs.meta b/Scripts/GLTFAccessor.cs.meta new file mode 100644 index 0000000..80c06a4 --- /dev/null +++ b/Scripts/GLTFAccessor.cs.meta @@ -0,0 +1,13 @@ +fileFormatVersion: 2 +guid: 2f27a48d4b05948419cd94312065cc96 +timeCreated: 1539029690 +licenseType: Free +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Scripts/GLTFBuffer.cs b/Scripts/GLTFBuffer.cs new file mode 100644 index 0000000..bcd15e4 --- /dev/null +++ b/Scripts/GLTFBuffer.cs @@ -0,0 +1,25 @@ +using System; +using System.Collections; +using System.Collections.Generic; +using System.IO; +using UnityEngine; + +namespace Siccity.GLTFUtility { + /// Contains raw binary data + [Serializable] + public class GLTFBuffer { + public int byteLength = -1; + public string uri; + + public byte[] cache; + + public void Read(string directoryRoot) { + if (cache == null) cache = File.ReadAllBytes(directoryRoot + uri); + } + + public byte[] GetBytes() { + if (cache == null) Debug.LogError("Need to call Read(directoryRoot) on GLTFBuffer before GetBytes()"); + return cache; + } + } +} \ No newline at end of file diff --git a/Scripts/GLTFBuffer.cs.meta b/Scripts/GLTFBuffer.cs.meta new file mode 100644 index 0000000..ee13fc0 --- /dev/null +++ b/Scripts/GLTFBuffer.cs.meta @@ -0,0 +1,13 @@ +fileFormatVersion: 2 +guid: 8a0e8a023d948d340989746154fbe314 +timeCreated: 1539024463 +licenseType: Free +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Scripts/GLTFBufferView.cs b/Scripts/GLTFBufferView.cs new file mode 100644 index 0000000..e3cb038 --- /dev/null +++ b/Scripts/GLTFBufferView.cs @@ -0,0 +1,25 @@ +using System; +using System.Collections; +using System.Collections.Generic; +using System.Linq; +using UnityEngine; + +namespace Siccity.GLTFUtility { + /// Defines sections within the Buffer + [Serializable] + public class GLTFBufferView { + public int buffer = -1; + public int byteOffset = -1; + public int byteLength = -1; + public int byteStride = -1; + /// OpenGL buffer target + public int target = -1; + + private byte[] cache; + + public byte[] GetBytes(GLTFObject gLTFObject) { + if (cache == null) cache = gLTFObject.buffers[buffer].GetBytes().SubArray(byteOffset, byteLength); + return cache; + } + } +} \ No newline at end of file diff --git a/Scripts/GLTFBufferView.cs.meta b/Scripts/GLTFBufferView.cs.meta new file mode 100644 index 0000000..c044834 --- /dev/null +++ b/Scripts/GLTFBufferView.cs.meta @@ -0,0 +1,13 @@ +fileFormatVersion: 2 +guid: f77c029d61e83644b812d926bc8a7706 +timeCreated: 1539029690 +licenseType: Free +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Scripts/GLTFMesh.cs b/Scripts/GLTFMesh.cs new file mode 100644 index 0000000..1468333 --- /dev/null +++ b/Scripts/GLTFMesh.cs @@ -0,0 +1,83 @@ +using System; +using System.Collections; +using System.Collections.Generic; +using UnityEngine; + +namespace Siccity.GLTFUtility { + [Serializable] + public class GLTFMesh { + public string name; + public List primitives; + /// Morph target weights + public List weights; + + private Mesh cache; + + public Mesh GetMesh(GLTFObject gLTFObject) { + if (cache == null) { + if (primitives.Count == 0) { + cache = new Mesh() { name = name }; + } else if (primitives.Count == 1) { + cache = new Mesh(); + + // Name + cache.name = name; + + // Verts + if (primitives[0].attributes.POSITION != -1) { + cache.vertices = gLTFObject.accessors[primitives[0].attributes.POSITION].ReadVec3(gLTFObject); + } + + // Tris + if (primitives[0].indices != -1) { + cache.triangles = gLTFObject.accessors[primitives[0].indices].ReadInt(gLTFObject); + } + + // Normals + if (primitives[0].attributes.NORMAL != -1) { + cache.normals = gLTFObject.accessors[primitives[0].attributes.NORMAL].ReadVec3(gLTFObject); + } else cache.RecalculateNormals(); + + // Tangents + if (primitives[0].attributes.TANGENT != -1) { + cache.tangents = gLTFObject.accessors[primitives[0].attributes.TANGENT].ReadVec4(gLTFObject); + } else cache.RecalculateTangents(); + + // UVs + if (primitives[0].attributes.TEXCOORD_0 != -1) { // UV 1 + Vector2[] uvs = gLTFObject.accessors[primitives[0].attributes.TEXCOORD_0].ReadVec2(gLTFObject); + FlipY(ref uvs); + cache.uv = uvs; + } + if (primitives[0].attributes.TEXCOORD_1 != -1) { // UV 2 + Vector2[] uvs = gLTFObject.accessors[primitives[0].attributes.TEXCOORD_1].ReadVec2(gLTFObject); + FlipY(ref uvs); + cache.uv2 = uvs; + } + if (primitives[0].attributes.TEXCOORD_2 != -1) { // UV 3 + Vector2[] uvs = gLTFObject.accessors[primitives[0].attributes.TEXCOORD_2].ReadVec2(gLTFObject); + FlipY(ref uvs); + cache.uv3 = uvs; + } + if (primitives[0].attributes.TEXCOORD_3 != -1) { // UV 4 + Vector2[] uvs = gLTFObject.accessors[primitives[0].attributes.TEXCOORD_3].ReadVec2(gLTFObject); + FlipY(ref uvs); + cache.uv4 = uvs; + } + + cache.RecalculateBounds(); + } else { + Debug.LogError("Multiple primitives per mesh not supported"); + return new Mesh() { name = name }; + } + } + return cache; + } + + public void FlipY(ref Vector2[] uv) { + for (int i = 0; i < uv.Length; i++) { + uv[i].y = 1 - uv[i].y; + } + } + } +} \ No newline at end of file diff --git a/Scripts/GLTFMesh.cs.meta b/Scripts/GLTFMesh.cs.meta new file mode 100644 index 0000000..6e827bb --- /dev/null +++ b/Scripts/GLTFMesh.cs.meta @@ -0,0 +1,13 @@ +fileFormatVersion: 2 +guid: 1ddbab1e140e1234fae1dc56d0d0f479 +timeCreated: 1539024463 +licenseType: Free +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Scripts/GLTFNode.cs b/Scripts/GLTFNode.cs new file mode 100644 index 0000000..04ab13a --- /dev/null +++ b/Scripts/GLTFNode.cs @@ -0,0 +1,51 @@ +using System; +using System.Collections; +using System.Collections.Generic; +using UnityEngine; + +namespace Siccity.GLTFUtility { + [Serializable] + public class GLTFNode { + public string name; + /// Indices of child nodes + public List children; + + /// Local TRS + public float[] matrix; + + /// Local position + public float[] translation; + /// Local rotation + public float[] rotation; + /// Local scale + public float[] scale; + + public int mesh = -1; + + public int camera = -1; + + public GameObject Create(GLTFObject gLTFObject, Transform parent) { + GameObject go = new GameObject(name); + go.transform.parent = parent; + if (matrix != null) Debug.LogWarning("MatrixTRS not supported."); + if (translation != null) go.transform.localPosition = new Vector3(translation[0], translation[1], translation[2]); + if (rotation != null) go.transform.localRotation = new Quaternion(rotation[0], rotation[1], rotation[2], rotation[3]); + if (scale != null) go.transform.localScale = new Vector3(scale[0], scale[1], scale[2]); + + if (mesh != -1) { + Mesh mesh = gLTFObject.meshes[0].GetMesh(gLTFObject); + MeshRenderer mr = go.AddComponent(); + MeshFilter mf = go.AddComponent(); +#if UNITY_EDITOR + mr.material = UnityEditor.AssetDatabase.GetBuiltinExtraResource("Default-Material.mat"); +#endif + mf.mesh = mesh; + } + + for (int i = 0; i < children.Count; i++) { + gLTFObject.nodes[children[i]].Create(gLTFObject, go.transform); + } + return go; + } + } +} \ No newline at end of file diff --git a/Scripts/GLTFNode.cs.meta b/Scripts/GLTFNode.cs.meta new file mode 100644 index 0000000..6754ff9 --- /dev/null +++ b/Scripts/GLTFNode.cs.meta @@ -0,0 +1,13 @@ +fileFormatVersion: 2 +guid: 276c161f2b15c0a48b89210deb9a6e24 +timeCreated: 1539024181 +licenseType: Free +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Scripts/GLTFObject.cs b/Scripts/GLTFObject.cs new file mode 100644 index 0000000..2eee4de --- /dev/null +++ b/Scripts/GLTFObject.cs @@ -0,0 +1,21 @@ +using System; +using System.Collections; +using System.Collections.Generic; +using UnityEngine; + +namespace Siccity.GLTFUtility { + public enum GLType { UNSET = -1, BYTE = 5120, UNSIGNED_BYTE = 5121, SHORT = 5122, UNSIGNED_SHORT = 5123, FLOAT = 5126 } + + [Serializable] + public class GLTFObject { + + /// Default scene + int scene = -1; + public List scenes; + public List nodes; + public List meshes; + public List buffers; + public List bufferViews; + public List accessors; + } +} \ No newline at end of file diff --git a/Scripts/GLTFObject.cs.meta b/Scripts/GLTFObject.cs.meta new file mode 100644 index 0000000..817886c --- /dev/null +++ b/Scripts/GLTFObject.cs.meta @@ -0,0 +1,13 @@ +fileFormatVersion: 2 +guid: 84e30c2ce8f61b443800564b827d7395 +timeCreated: 1539024463 +licenseType: Free +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Scripts/GLTFPrimitive.cs b/Scripts/GLTFPrimitive.cs new file mode 100644 index 0000000..90ec94f --- /dev/null +++ b/Scripts/GLTFPrimitive.cs @@ -0,0 +1,31 @@ +using System; +using System.Collections; +using System.Collections.Generic; +using UnityEngine; + +namespace Siccity.GLTFUtility { + [Serializable] + public class GLTFPrimitive { + public enum RenderingMode { Points = 1, Lines = 2, Triangles = 3 } + /// Rendering mode + public RenderingMode mode; + public int indices = -1; + public GLTFAttributes attributes; + public int material = -1; + /// Morph targets + public List targets; + + [Serializable] + public class GLTFAttributes { + public int POSITION = -1; + public int NORMAL = -1; + public int TANGENT = -1; + public int TEXCOORD_0 = -1; + public int TEXCOORD_1 = -1; + public int TEXCOORD_2 = -1; + public int TEXCOORD_3 = -1; + public int WEIGHTS_0 = -1; + public int WEIGHTS_1 = -1; + } + } +} \ No newline at end of file diff --git a/Scripts/GLTFPrimitive.cs.meta b/Scripts/GLTFPrimitive.cs.meta new file mode 100644 index 0000000..124da59 --- /dev/null +++ b/Scripts/GLTFPrimitive.cs.meta @@ -0,0 +1,13 @@ +fileFormatVersion: 2 +guid: f9acfe0fd7cc80849ad51216685cb042 +timeCreated: 1539024463 +licenseType: Free +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Scripts/GLTFScene.cs b/Scripts/GLTFScene.cs new file mode 100644 index 0000000..3282f9d --- /dev/null +++ b/Scripts/GLTFScene.cs @@ -0,0 +1,12 @@ +using System; +using System.Collections; +using System.Collections.Generic; +using UnityEngine; + +namespace Siccity.GLTFUtility { + [Serializable] + public class GLTFScene { + /// Indices of nodes + public List nodes; + } +} \ No newline at end of file diff --git a/Scripts/GLTFScene.cs.meta b/Scripts/GLTFScene.cs.meta new file mode 100644 index 0000000..c8033a2 --- /dev/null +++ b/Scripts/GLTFScene.cs.meta @@ -0,0 +1,13 @@ +fileFormatVersion: 2 +guid: 1328a8789f9666842985198e60afb2ad +timeCreated: 1539024181 +licenseType: Free +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: