Beispiel #1
0
        /// <summary>
        /// Retrieves import options for the mesh we're currently inspecting.
        /// </summary>
        /// <returns>Mesh import options object.</returns>
        private MeshImportOptions GetImportOptions()
        {
            MeshImportOptions output = null;

            LibraryEntry meshEntry = ProjectLibrary.GetEntry(InspectedResourcePath);

            if (meshEntry != null && meshEntry.Type == LibraryEntryType.File)
            {
                FileEntry meshFileEntry = (FileEntry)meshEntry;
                output = meshFileEntry.Options as MeshImportOptions;
            }

            if (output == null)
            {
                if (importOptions == null)
                {
                    output = new MeshImportOptions();
                }
                else
                {
                    output = importOptions;
                }
            }

            return(output);
        }
        /// <summary>
        /// Retrieves import options for the mesh we're currently inspecting.
        /// </summary>
        /// <returns>Mesh import options object.</returns>
        private MeshImportOptions GetImportOptions()
        {
            Mesh mesh = InspectedObject as Mesh;
            MeshImportOptions output = null;

            if (mesh != null)
            {
                LibraryEntry meshEntry = ProjectLibrary.GetEntry(ProjectLibrary.GetPath(mesh));
                if (meshEntry != null && meshEntry.Type == LibraryEntryType.File)
                {
                    FileEntry meshFileEntry = (FileEntry)meshEntry;
                    output = meshFileEntry.Options as MeshImportOptions;
                }
            }

            if (output == null)
            {
                if (importOptions == null)
                {
                    output = new MeshImportOptions();
                }
                else
                {
                    output = importOptions;
                }
            }

            return(output);
        }
        /// <inheritdoc/>
        protected internal override void Initialize()
        {
            if (InspectedObject != null)
            {
                importOptions = GetImportOptions();

                normalsField.OnChanged     += x => importOptions.ImportNormals = x;
                tangentsField.OnChanged    += x => importOptions.ImportTangents = x;
                skinField.OnChanged        += x => importOptions.ImportSkin = x;
                blendShapesField.OnChanged += x => importOptions.ImportBlendShapes = x;
                animationField.OnChanged   += x => importOptions.ImportAnimation = x;
                scaleField.OnChanged       += x => importOptions.Scale = x;
                cpuReadableField.OnChanged += x => importOptions.CPUReadable = x;
                collisionMeshTypeField.OnSelectionChanged += x => importOptions.CollisionMeshType = (CollisionMeshType)x;

                reimportButton.OnClick += TriggerReimport;

                Layout.AddElement(normalsField);
                Layout.AddElement(tangentsField);
                Layout.AddElement(skinField);
                Layout.AddElement(blendShapesField);
                Layout.AddElement(animationField);
                Layout.AddElement(scaleField);
                Layout.AddElement(cpuReadableField);
                Layout.AddElement(collisionMeshTypeField);
                Layout.AddSpace(10);

                GUILayout reimportButtonLayout = Layout.AddLayoutX();
                reimportButtonLayout.AddFlexibleSpace();
                reimportButtonLayout.AddElement(reimportButton);
            }
        }
Beispiel #4
0
        /// <inheritdoc/>
        protected internal override void Initialize()
        {
            if (InspectedObject != null)
            {
                importOptions = GetImportOptions();

                normalsField.OnChanged += x => importOptions.ImportNormals = x;
                tangentsField.OnChanged += x => importOptions.ImportTangents = x;
                skinField.OnChanged += x => importOptions.ImportSkin = x;
                blendShapesField.OnChanged += x => importOptions.ImportBlendShapes = x;
                animationField.OnChanged += x => importOptions.ImportAnimation = x;
                scaleField.OnChanged += x => importOptions.Scale = x;
                cpuReadableField.OnChanged += x => importOptions.CPUReadable = x;
                collisionMeshTypeField.OnSelectionChanged += x => importOptions.CollisionMeshType = (CollisionMeshType)x;

                reimportButton.OnClick += TriggerReimport;

                Layout.AddElement(normalsField);
                Layout.AddElement(tangentsField);
                Layout.AddElement(skinField);
                Layout.AddElement(blendShapesField);
                Layout.AddElement(animationField);
                Layout.AddElement(scaleField);
                Layout.AddElement(cpuReadableField);
                Layout.AddElement(collisionMeshTypeField);
                Layout.AddSpace(10);

                GUILayout reimportButtonLayout = Layout.AddLayoutX();
                reimportButtonLayout.AddFlexibleSpace();
                reimportButtonLayout.AddElement(reimportButton);
            }
        }
 /// <inheritdoc/>
 protected internal override void Initialize()
 {
     if (InspectedObject != null)
     {
         importOptions = GetImportOptions();
         BuildGUI();
     }
 }
        /// <summary>
        /// Saves the animation curves and events stored in this object, into the associated animation clip resource.
        /// Relevant animation clip resource must already be created and exist in the project library.
        /// </summary>
        public void SaveToClip()
        {
            if (!isImported)
            {
                EditorAnimClipTangents tangents;
                Apply(out tangents);

                string resourcePath = ProjectLibrary.GetPath(clip);
                ProjectLibrary.Save(clip);

                ProjectLibrary.SetEditorData(resourcePath, tangents);
            }
            else
            {
                string       resourcePath = ProjectLibrary.GetPath(clip);
                LibraryEntry entry        = ProjectLibrary.GetEntry(resourcePath);

                if (entry != null && entry.Type == LibraryEntryType.File)
                {
                    FileEntry         fileEntry         = (FileEntry)entry;
                    MeshImportOptions meshImportOptions = (MeshImportOptions)fileEntry.Options;

                    string clipName = PathEx.GetTail(resourcePath);

                    List <ImportedAnimationEvents> newEvents = new List <ImportedAnimationEvents>();
                    newEvents.AddRange(meshImportOptions.AnimationEvents);

                    bool isExisting = false;
                    for (int i = 0; i < newEvents.Count; i++)
                    {
                        if (newEvents[i].name == clipName)
                        {
                            newEvents[i].events = events;
                            isExisting          = true;
                            break;
                        }
                    }

                    if (!isExisting)
                    {
                        ImportedAnimationEvents newEntry = new ImportedAnimationEvents();
                        newEntry.name   = clipName;
                        newEntry.events = events;

                        newEvents.Add(newEntry);
                    }

                    meshImportOptions.AnimationEvents = newEvents.ToArray();

                    ProjectLibrary.Reimport(resourcePath, meshImportOptions, true);
                }
            }
        }
Beispiel #7
0
        /// <inheritdoc/>
        protected internal override InspectableState Refresh()
        {
            MeshImportOptions newImportOptions = GetImportOptions();

            bool rebuildGUI = false;

            AnimationSplitInfo[] splitInfos = newImportOptions.AnimationClipSplits;
            if (splitInfos == null)
            {
                rebuildGUI |= animSplitInfoField.Array != null;
            }
            else
            {
                if (animSplitInfoField.Array == null)
                {
                    rebuildGUI = true;
                }
                else
                {
                    rebuildGUI |= splitInfos.Length != animSplitInfoField.Array.GetLength(0);
                }
            }

            if (rebuildGUI)
            {
                BuildGUI();
            }

            InspectableState splitInfosModified = animSplitInfoField.Refresh();

            if (splitInfosModified == InspectableState.Modified)
            {
                newImportOptions.AnimationClipSplits = splitInfos;
            }

            normalsField.Value           = newImportOptions.ImportNormals;
            tangentsField.Value          = newImportOptions.ImportTangents;
            skinField.Value              = newImportOptions.ImportSkin;
            blendShapesField.Value       = newImportOptions.ImportBlendShapes;
            animationField.Value         = newImportOptions.ImportAnimation;
            scaleField.Value             = newImportOptions.Scale;
            cpuReadableField.Value       = newImportOptions.CPUReadable;
            collisionMeshTypeField.Value = (ulong)newImportOptions.CollisionMeshType;
            keyFrameReductionField.Value = newImportOptions.KeyframeReduction;

            importOptions = newImportOptions;

            return(InspectableState.NotModified);
        }
Beispiel #8
0
        /// <inheritdoc/>
        protected internal override InspectableState Refresh()
        {
            MeshImportOptions newImportOptions = GetImportOptions();

            normalsField.Value     = newImportOptions.ImportNormals;
            tangentsField.Value    = newImportOptions.ImportTangents;
            skinField.Value        = newImportOptions.ImportSkin;
            blendShapesField.Value = newImportOptions.ImportBlendShapes;
            animationField.Value   = newImportOptions.ImportAnimation;
            scaleField.Value       = newImportOptions.Scale;
            cpuReadableField.Value = newImportOptions.CPUReadable;

            importOptions = newImportOptions;

            return(InspectableState.NotModified);
        }
Beispiel #9
0
        /// <inheritdoc/>
        protected internal override InspectableState Refresh()
        {
            MeshImportOptions newImportOptions = GetImportOptions();

            animSplitInfoField.Refresh();

            normalsField.Value           = newImportOptions.ImportNormals;
            tangentsField.Value          = newImportOptions.ImportTangents;
            skinField.Value              = newImportOptions.ImportSkin;
            blendShapesField.Value       = newImportOptions.ImportBlendShapes;
            animationField.Value         = newImportOptions.ImportAnimation;
            scaleField.Value             = newImportOptions.Scale;
            cpuCachedField.Value         = newImportOptions.CPUCached;
            collisionMeshTypeField.Value = (ulong)newImportOptions.CollisionMeshType;
            keyFrameReductionField.Value = newImportOptions.KeyframeReduction;
            rootMotionField.Value        = newImportOptions.ImportRootMotion;

            importOptions = newImportOptions;

            return(InspectableState.NotModified);
        }
Beispiel #10
0
 private static extern void Internal_CreateInstance(MeshImportOptions instance);
 private static extern void Internal_CreateInstance(MeshImportOptions instance);
Beispiel #12
0
 /// <inheritdoc/>
 protected internal override void Initialize()
 {
     importOptions = GetImportOptions();
     BuildGUI();
 }
Beispiel #13
0
        /// <summary>
        /// Saves the animation curves and events stored in this object, into the associated animation clip resource.
        /// Relevant animation clip resource must already be created and exist in the project library.
        /// </summary>
        public void SaveToClip()
        {
            if (!isImported)
            {
                List <NamedVector3Curve> positionCurves = new List <NamedVector3Curve>();
                List <NamedVector3Curve> rotationCurves = new List <NamedVector3Curve>();
                List <NamedVector3Curve> scaleCurves    = new List <NamedVector3Curve>();
                List <NamedFloatCurve>   floatCurves    = new List <NamedFloatCurve>();

                List <EditorVector3CurveTangents> positionTangents = new List <EditorVector3CurveTangents>();
                List <EditorVector3CurveTangents> rotationTangents = new List <EditorVector3CurveTangents>();
                List <EditorVector3CurveTangents> scaleTangents    = new List <EditorVector3CurveTangents>();
                List <EditorFloatCurveTangents>   floatTangents    = new List <EditorFloatCurveTangents>();

                foreach (var kvp in curves)
                {
                    string[] pathEntries = kvp.Key.Split('/');
                    if (pathEntries.Length == 0)
                    {
                        continue;
                    }

                    string lastEntry = pathEntries[pathEntries.Length - 1];

                    if (lastEntry == "Position" || lastEntry == "Rotation" || lastEntry == "Scale")
                    {
                        StringBuilder sb = new StringBuilder();
                        for (int i = 0; i < pathEntries.Length - 2; i++)
                        {
                            sb.Append(pathEntries[i] + "/");
                        }

                        if (pathEntries.Length > 1)
                        {
                            sb.Append(pathEntries[pathEntries.Length - 2]);
                        }

                        string curvePath = sb.ToString();

                        NamedVector3Curve curve = new NamedVector3Curve(curvePath,
                                                                        new AnimationCurve(kvp.Value.curveInfos[0].curve.KeyFrames),
                                                                        new AnimationCurve(kvp.Value.curveInfos[1].curve.KeyFrames),
                                                                        new AnimationCurve(kvp.Value.curveInfos[2].curve.KeyFrames));

                        EditorVector3CurveTangents tangents = new EditorVector3CurveTangents();
                        tangents.name      = curvePath;
                        tangents.tangentsX = kvp.Value.curveInfos[0].curve.TangentModes;
                        tangents.tangentsY = kvp.Value.curveInfos[1].curve.TangentModes;
                        tangents.tangentsZ = kvp.Value.curveInfos[2].curve.TangentModes;

                        if (lastEntry == "Position")
                        {
                            positionCurves.Add(curve);
                            positionTangents.Add(tangents);
                        }
                        else if (lastEntry == "Rotation")
                        {
                            rotationCurves.Add(curve);
                            rotationTangents.Add(tangents);
                        }
                        else if (lastEntry == "Scale")
                        {
                            scaleCurves.Add(curve);
                            scaleTangents.Add(tangents);
                        }
                    }
                    else
                    {
                        Action <int, string> addCurve = (idx, subPath) =>
                        {
                            string path = kvp.Key + subPath;

                            NamedFloatCurve curve = new NamedFloatCurve(path,
                                                                        new AnimationCurve(kvp.Value.curveInfos[idx].curve.KeyFrames));

                            EditorFloatCurveTangents tangents = new EditorFloatCurveTangents();
                            tangents.name     = path;
                            tangents.tangents = kvp.Value.curveInfos[idx].curve.TangentModes;

                            floatCurves.Add(curve);
                            floatTangents.Add(tangents);
                        };

                        switch (kvp.Value.type)
                        {
                        case SerializableProperty.FieldType.Vector2:
                            addCurve(0, ".x");
                            addCurve(1, ".y");
                            break;

                        case SerializableProperty.FieldType.Vector3:
                            addCurve(0, ".x");
                            addCurve(1, ".y");
                            addCurve(2, ".z");
                            break;

                        case SerializableProperty.FieldType.Vector4:
                            addCurve(0, ".x");
                            addCurve(1, ".y");
                            addCurve(2, ".z");
                            addCurve(3, ".w");
                            break;

                        case SerializableProperty.FieldType.Color:
                            addCurve(0, ".r");
                            addCurve(1, ".g");
                            addCurve(2, ".b");
                            addCurve(3, ".a");
                            break;

                        case SerializableProperty.FieldType.Bool:
                        case SerializableProperty.FieldType.Int:
                        case SerializableProperty.FieldType.Float:
                            addCurve(0, "");
                            break;
                        }
                    }
                }

                AnimationCurves newClipCurves = new AnimationCurves();
                newClipCurves.PositionCurves = positionCurves.ToArray();
                newClipCurves.RotationCurves = rotationCurves.ToArray();
                newClipCurves.ScaleCurves    = scaleCurves.ToArray();
                newClipCurves.FloatCurves    = floatCurves.ToArray();

                clip.Curves     = newClipCurves;
                clip.Events     = events;
                clip.SampleRate = sampleRate;

                string resourcePath = ProjectLibrary.GetPath(clip);
                ProjectLibrary.Save(clip);

                // Save tangents for editor only use
                EditorAnimClipTangents newCurveData = new EditorAnimClipTangents();
                newCurveData.positionCurves = positionTangents.ToArray();
                newCurveData.rotationCurves = rotationTangents.ToArray();
                newCurveData.scaleCurves    = scaleTangents.ToArray();
                newCurveData.floatCurves    = floatTangents.ToArray();

                ProjectLibrary.SetEditorData(resourcePath, newCurveData);
            }
            else
            {
                string       resourcePath = ProjectLibrary.GetPath(clip);
                LibraryEntry entry        = ProjectLibrary.GetEntry(resourcePath);

                if (entry != null && entry.Type == LibraryEntryType.File)
                {
                    FileEntry         fileEntry         = (FileEntry)entry;
                    MeshImportOptions meshImportOptions = (MeshImportOptions)fileEntry.Options;

                    string clipName = PathEx.GetTail(resourcePath);

                    List <ImportedAnimationEvents> newEvents = new List <ImportedAnimationEvents>();
                    newEvents.AddRange(meshImportOptions.AnimationEvents);

                    bool isExisting = false;
                    for (int i = 0; i < newEvents.Count; i++)
                    {
                        if (newEvents[i].name == clipName)
                        {
                            newEvents[i].events = events;
                            isExisting          = true;
                            break;
                        }
                    }

                    if (!isExisting)
                    {
                        ImportedAnimationEvents newEntry = new ImportedAnimationEvents();
                        newEntry.name   = clipName;
                        newEntry.events = events;

                        newEvents.Add(newEntry);
                    }

                    meshImportOptions.AnimationEvents = newEvents.ToArray();

                    ProjectLibrary.Reimport(resourcePath, meshImportOptions, true);
                }
            }
        }
Beispiel #14
0
 private static extern void Internal_create(MeshImportOptions managedInstance);
Beispiel #15
0
        /// <summary>
        /// Retrieves import options for the mesh we're currently inspecting.
        /// </summary>
        /// <returns>Mesh import options object.</returns>
        private MeshImportOptions GetImportOptions()
        {
            Mesh mesh = InspectedObject as Mesh;
            MeshImportOptions output = null;

            if (mesh != null)
            {
                LibraryEntry meshEntry = ProjectLibrary.GetEntry(ProjectLibrary.GetPath(mesh));
                if (meshEntry != null && meshEntry.Type == LibraryEntryType.File)
                {
                    FileEntry meshFileEntry = (FileEntry)meshEntry;
                    output = meshFileEntry.Options as MeshImportOptions;
                }
            }

            if (output == null)
            {
                if (importOptions == null)
                    output = new MeshImportOptions();
                else
                    output = importOptions;
            }

            return output;
        }
Beispiel #16
0
        /// <inheritdoc/>
        protected internal override InspectableState Refresh()
        {
            MeshImportOptions newImportOptions = GetImportOptions();

            normalsField.Value = newImportOptions.ImportNormals;
            tangentsField.Value = newImportOptions.ImportTangents;
            skinField.Value = newImportOptions.ImportSkin;
            blendShapesField.Value = newImportOptions.ImportBlendShapes;
            animationField.Value = newImportOptions.ImportAnimation;
            scaleField.Value = newImportOptions.Scale;
            cpuReadableField.Value = newImportOptions.CPUReadable;
            collisionMeshTypeField.Value = (ulong)newImportOptions.CollisionMeshType;

            importOptions = newImportOptions;

            return InspectableState.NotModified;
        }