diff --git a/GlTF_Animation.cs b/GlTF_Animation.cs index c152dac..3cd0794 100644 --- a/GlTF_Animation.cs +++ b/GlTF_Animation.cs @@ -7,13 +7,17 @@ public class GlTF_Animation : GlTF_Writer { public List channels = new List(); public List animSamplers = new List(); - //bool gotTranslation = false; - //bool gotRotation = false; - //bool gotScale = false; + + public enum ROTATION_TYPE + { + UNKNOWN, + QUATERNION, + EULER + }; int bakingFramerate = 30; // FPS - public GlTF_Animation (string n, string target) { + public GlTF_Animation (string n) { name = n; } @@ -21,7 +25,11 @@ private struct TargetCurveSet { public AnimationCurve[] translationCurves; public AnimationCurve[] rotationCurves; + //Additional curve types + public AnimationCurve[] localEulerAnglesRaw; + public AnimationCurve[] m_LocalEuler; public AnimationCurve[] scaleCurves; + public ROTATION_TYPE rotationType; public void Init() { translationCurves = new AnimationCurve[3]; @@ -153,8 +161,9 @@ private void collectClipCurves(AnimationClip clip, ref Dictionary().farClipPlane; cam.znear = tr.GetComponent().nearClipPlane; - cam.name = tr.name; + cam.name = GlTF_Writer.cleanNonAlphanumeric(tr.name); //cam.orthographic.xmag = tr.camera. GlTF_Writer.cameras.Add(cam); } @@ -60,7 +60,7 @@ public static void parseUnityCamera(Transform tr) cam.znear = tr.GetComponent().nearClipPlane; cam.aspect_ratio = tr.GetComponent().aspect; cam.yfov = tr.GetComponent().fieldOfView; - cam.name = tr.name; + cam.name = GlTF_Writer.cleanNonAlphanumeric(tr.name); GlTF_Writer.cameras.Add(cam); } } @@ -82,28 +82,28 @@ public static void parseUnityLight(Transform tr) case LightType.Point: GlTF_PointLight pl = new GlTF_PointLight(); pl.color = new GlTF_ColorRGB(tr.GetComponent().color); - pl.name = tr.name; + pl.name = GlTF_Writer.cleanNonAlphanumeric(tr.name); GlTF_Writer.lights.Add(pl); break; case LightType.Spot: GlTF_SpotLight sl = new GlTF_SpotLight(); sl.color = new GlTF_ColorRGB(tr.GetComponent().color); - sl.name = tr.name; + sl.name = GlTF_Writer.cleanNonAlphanumeric(tr.name); GlTF_Writer.lights.Add(sl); break; case LightType.Directional: GlTF_DirectionalLight dl = new GlTF_DirectionalLight(); dl.color = new GlTF_ColorRGB(tr.GetComponent().color); - dl.name = tr.name; + dl.name = GlTF_Writer.cleanNonAlphanumeric(tr.name); GlTF_Writer.lights.Add(dl); break; case LightType.Area: GlTF_AmbientLight al = new GlTF_AmbientLight(); al.color = new GlTF_ColorRGB(tr.GetComponent().color); - al.name = tr.name; + al.name = GlTF_Writer.cleanNonAlphanumeric(tr.name); GlTF_Writer.lights.Add(al); break; } @@ -192,7 +192,7 @@ public IEnumerator Export(string path, Preset presetAsset, bool buildZip, bool e // Initialize the node GlTF_Node node = new GlTF_Node(); node.id = GlTF_Node.GetNameFromObject(tr); - node.name = tr.name; + node.name = GlTF_Writer.cleanNonAlphanumeric(tr.name); if (tr.GetComponent() != null) parseUnityCamera(tr); @@ -204,7 +204,7 @@ public IEnumerator Export(string path, Preset presetAsset, bool buildZip, bool e if (m != null) { GlTF_Mesh mesh = new GlTF_Mesh(); - mesh.name = GlTF_Mesh.GetNameFromObject(m) + tr.name; + mesh.name = GlTF_Writer.cleanNonAlphanumeric(GlTF_Mesh.GetNameFromObject(m) + tr.name); GlTF_Accessor positionAccessor = new GlTF_Accessor(GlTF_Accessor.GetNameFromObject(m, "position"), GlTF_Accessor.Type.VEC3, GlTF_Accessor.ComponentType.FLOAT); positionAccessor.bufferView = GlTF_Writer.vec3BufferView; @@ -314,7 +314,7 @@ public IEnumerator Export(string path, Preset presetAsset, bool buildZip, bool e else { GlTF_Material material = new GlTF_Material(); - material.name = mat.name; + material.name = GlTF_Writer.cleanNonAlphanumeric(mat.name); primitive.materialIndex = GlTF_Writer.materials.Count; GlTF_Writer.materialNames.Add(matName); GlTF_Writer.materials.Add (material); @@ -490,7 +490,7 @@ public IEnumerator Export(string path, Preset presetAsset, bool buildZip, bool e for (int i = 0; i < clips.Length; i++) { //FIXME It seems not good to generate one animation per animator. - GlTF_Animation anim = new GlTF_Animation(a.name, node.name); + GlTF_Animation anim = new GlTF_Animation(GlTF_Writer.cleanNonAlphanumeric(a.name)); anim.Populate(clips[i], tr, GlTF_Writer.bakeAnimation); if(anim.channels.Count > 0) GlTF_Writer.animations.Add(anim); @@ -502,7 +502,7 @@ public IEnumerator Export(string path, Preset presetAsset, bool buildZip, bool e { AnimationClip clip = animation.clip; //FIXME It seems not good to generate one animation per animator. - GlTF_Animation anim = new GlTF_Animation(animation.name, node.name); + GlTF_Animation anim = new GlTF_Animation(GlTF_Writer.cleanNonAlphanumeric(animation.name)); anim.Populate(clip, tr, GlTF_Writer.bakeAnimation); if (anim.channels.Count > 0) GlTF_Writer.animations.Add(anim); @@ -544,10 +544,10 @@ public IEnumerator Export(string path, Preset presetAsset, bool buildZip, bool e if (tr.GetComponent() != null) { - node.cameraName = tr.name; + node.cameraName = GlTF_Writer.cleanNonAlphanumeric(tr.name); } else if (tr.GetComponent() != null) - node.lightName = tr.name; + node.lightName = GlTF_Writer.cleanNonAlphanumeric(tr.name); // Parse node's skin data GlTF_Accessor invBindMatrixAccessor = null; @@ -557,7 +557,7 @@ public IEnumerator Export(string path, Preset presetAsset, bool buildZip, bool e node.skeletons = GlTF_Skin.findRootSkeletons(skinMesh); GlTF_Skin skin = new GlTF_Skin(); skin.setBindShapeMatrix(tr); - skin.name = skinMesh.rootBone.name + "_skeleton_" + node.name + tr.GetInstanceID(); + skin.name = GlTF_Writer.cleanNonAlphanumeric(skinMesh.rootBone.name) + "_skeleton_" + GlTF_Writer.cleanNonAlphanumeric(node.name) + tr.GetInstanceID(); // Create invBindMatrices accessor invBindMatrixAccessor = new GlTF_Accessor(skin.name + "invBindMatrices", GlTF_Accessor.Type.MAT4, GlTF_Accessor.ComponentType.FLOAT);