public FormAnimatorDragDrop(AnimatorEditor destEditor)
        {
            InitializeComponent();
            startSize = new SizeF(Width, Height);
            this.SaveDesignSizes();
            editor = destEditor;

            numericFrameId.Maximum = editor.Frames.Count - 1;
            numericMeshId.Maximum  = editor.Frames.Count - 1;
        }
Ejemplo n.º 2
0
 static void Collect(AnimatorEditor editor, HashSet <Component> collection)
 {
     foreach (Transform frame in editor.Frames)
     {
         GameObject gameObj = frame.m_GameObject.instance;
         collection.Add(gameObj);
         foreach (var comp in gameObj.m_Component)
         {
             collection.Add(comp.Value.asset);
             if (comp.Value.asset.classID1 == UnityClassID.Animator)
             {
                 Animator anim = (Animator)comp.Value.asset;
                 if (anim.m_Avatar.instance != null)
                 {
                     collection.Add(anim.m_Avatar.instance);
                 }
             }
         }
         if (frame.UnknownChilds != null)
         {
             foreach (PPtr <Transform> childPtr in frame.UnknownChilds)
             {
                 if (!(childPtr.asset is Transform))
                 {
                     collection.Add(childPtr.asset);
                     MultiLink mLink = childPtr.asset as MultiLink;
                     if (mLink != null)
                     {
                         foreach (PPtr <Object> objPtr in mLink.Links)
                         {
                             collection.Add(objPtr.asset);
                         }
                     }
                 }
             }
         }
     }
     foreach (MeshRenderer meshR in editor.Meshes)
     {
         collection.Add(Operations.GetMesh(meshR));
         foreach (PPtr <Material> matPtr in meshR.m_Materials)
         {
             if (matPtr.instance != null)
             {
                 Material mat = matPtr.instance;
                 collection.Add(mat);
                 Collect(mat.m_Shader.instance, collection);
                 foreach (var texPair in mat.m_SavedProperties.m_TexEnvs)
                 {
                     collection.Add(texPair.Value.m_Texture.asset);
                 }
             }
         }
     }
 }
Ejemplo n.º 3
0
 static void SegmentClick()
 {
     if (AnimatorEditor.GetFlag("playing"))
     {
         segments.Select(2);
     }
     else
     {
         segments.Select(-1);
     }
 }
Ejemplo n.º 4
0
 private void trackBarNmlFactor_ValueChanged(object sender, EventArgs e)
 {
     try
     {
         FormAnimator       dstFormAnim  = null;
         string             animatorName = Editor.Parser.m_Name.Substring(0, Editor.Parser.m_Name.Length - 4);
         List <DockContent> formAnimators;
         if (Gui.Docking.DockContents.TryGetValue(typeof(FormAnimator), out formAnimators))
         {
             foreach (var form in formAnimators)
             {
                 FormAnimator   formAnim = (FormAnimator)form;
                 AnimatorEditor ed       = formAnim.Editor;
                 if (ed.Parser.m_GameObject.instance.m_Name.StartsWith(animatorName))
                 {
                     dstFormAnim = formAnim;
                     break;
                 }
             }
         }
         if (dstFormAnim == null)
         {
             return;
         }
         float blendFactor = trackBarNmlFactor.Value / (trackBarNmlFactor.Maximum - 1f);
         foreach (ListViewItem item in dstFormAnim.listViewMesh.SelectedItems)
         {
             int               id        = (int)item.Tag;
             MeshRenderer      meshR     = dstFormAnim.Editor.Meshes[id];
             RenderObjectUnity renderObj = dstFormAnim.renderObjectMeshes[id];
             foreach (var param in Editor.Parser.Param)
             {
                 if (param.ObjectName == meshR.m_GameObject.instance.m_Name)
                 {
                     if (blendFactor <= 1)
                     {
                         renderObj.SetNmlParam(param, blendFactor);
                     }
                     else
                     {
                         renderObj.ResetNormalsAndUVs(meshR);
                     }
                     break;
                 }
             }
         }
         Gui.Renderer.Render();
     }
     catch (Exception ex)
     {
         Utility.ReportException(ex);
     }
 }
Ejemplo n.º 5
0
        private FormAnimator GetFormAnimatorFromParserName(out List <DockContent> formAnimators)
        {
            FormAnimator dstFormAnim  = null;
            string       animatorName = Editor.Parser.m_Name.Substring(0, Editor.Parser.m_Name.Length - 4);

            if (Gui.Docking.DockContents.TryGetValue(typeof(FormAnimator), out formAnimators))
            {
                foreach (var form in formAnimators)
                {
                    FormAnimator   formAnim = (FormAnimator)form;
                    AnimatorEditor ed       = formAnim.Editor;
                    if (ed.Parser.m_GameObject.instance.m_Name.StartsWith(animatorName))
                    {
                        dstFormAnim = formAnim;
                        break;
                    }
                }
            }
            if (dstFormAnim == null)
            {
                foreach (var form in formAnimators)
                {
                    FormAnimator   formAnim       = (FormAnimator)form;
                    AnimatorEditor ed             = formAnim.Editor;
                    int            matchingMeshes = 0;
                    foreach (ListViewItem item in listViewNmlMeshes.SelectedItems)
                    {
                        var obj = Editor.GenericMonos[(int)item.Tag];
                        if (ed.GetMeshRendererId(obj.ObjectName) >= 0)
                        {
                            matchingMeshes++;
                        }
                    }
                    if (matchingMeshes == listViewNmlMeshes.SelectedItems.Count)
                    {
                        dstFormAnim = formAnim;
                        Report.ReportLog("Warning! Using Animator " + dstFormAnim.Text + " although it has a mismatching name.");
                        break;
                    }
                }

                if (dstFormAnim == null)
                {
                    throw new Exception("No Animator beginning with " + Editor.Parser.m_Name.Substring(0, Editor.Parser.m_Name.Length - 4) + " has been opened.");
                }
            }

            return(dstFormAnim);
        }
Ejemplo n.º 6
0
        public void ComputeMinMaxNormals(object[] nmlMeshIds, AnimatorEditor dstAnimatorEditor, object[] adjacentAnimatorEditorMeshIdPairs, double adjacentSquaredDistance, bool worldCoordinates)
        {
            string path      = Path.GetDirectoryName(Parser.file.Parser.FilePath);
            string file      = Path.GetFileNameWithoutExtension(Parser.file.Parser.FilePath);
            string backupExt = Path.GetExtension(Parser.file.Parser.FilePath);

            backupExt = backupExt == String.Empty ? backupExt = "None" : backupExt.Substring(1);
            backupExt = (string)Properties.Settings.Default["BackupExtension" + backupExt];
            UnityParser   srcFileParser = new UnityParser(path + @"\" + file + ".bak0" + backupExt);
            Unity3dEditor srcFileEditor = new Unity3dEditor(srcFileParser);

            srcFileEditor.GetAssetNames(true);
            Animator srcAnimator = null;

            if (dstAnimatorEditor.Parser.classID() != UnityClassID.Animator)
            {
                Component baseAsset = srcFileParser.Cabinet.Components.Find
                                      (
                    delegate(Component asset)
                {
                    return(asset is NotLoaded && asset.classID() == UnityClassID.GameObject && ((NotLoaded)asset).Name == dstAnimatorEditor.Parser.m_GameObject.instance.m_Name);
                }
                                      );
                srcAnimator = srcFileEditor.OpenVirtualAnimator(srcFileParser.Cabinet.Components.IndexOf(baseAsset));
            }
            else
            {
                Component baseAsset = srcFileParser.Cabinet.Components.Find
                                      (
                    delegate(Component asset)
                {
                    return(asset is NotLoaded && asset.classID() == UnityClassID.Animator && ((NotLoaded)asset).Name == dstAnimatorEditor.Parser.m_GameObject.instance.m_Name);
                }
                                      );
                srcAnimator = srcFileEditor.OpenAnimator(srcFileParser.Cabinet.Components.IndexOf(baseAsset));
            }
            AnimatorEditor srcAnimatorEditor = new AnimatorEditor(srcAnimator);

            Component srcNmlAsset = srcFileParser.Cabinet.Components.Find
                                    (
                delegate(Component asset)
            {
                return(asset is NotLoaded && asset.classID() == UnityClassID.MonoBehaviour && ((NotLoaded)asset).Name == Parser.m_Name);
            }
                                    );
            NmlMonoBehaviour srcNml = srcFileEditor.OpenNmlMonoBehaviour(srcFileParser.Cabinet.Components.IndexOf(srcNmlAsset));

            ComputeMinMaxNormals(nmlMeshIds, dstAnimatorEditor, srcNml, -1, srcAnimatorEditor, adjacentAnimatorEditorMeshIdPairs, adjacentSquaredDistance, worldCoordinates);
        }
Ejemplo n.º 7
0
        private void RefreshLabelSourceWarning()
        {
            Tuple <string, string> item = (Tuple <string, string>)comboBoxSourceAnimator.SelectedItem;

            if (item == null || item.Item2 == null)
            {
                labelSourceWarning.Visible = true;
                return;
            }

            AnimatorEditor editor = (AnimatorEditor)Gui.Scripting.Variables[item.Item2];
            var            obj    = (Tuple <string, int>)comboBoxSourceMesh.SelectedItem;

            labelSourceWarning.Visible = obj == null || editor.GetMeshRendererId(obj.Item1) < 0;
        }
        public void SetRenderer(int id, AnimatorEditor editor, string name)
        {
            foreach (var renderer in editor.Meshes)
            {
                if (String.Compare(renderer.m_GameObject.instance.m_Name, name, true) == 0)
                {
                    Datas[id].rendererName = renderer.m_GameObject.instance.m_Name;
                    Datas[id].renderer     = new PPtr <MeshRenderer>(renderer);
                    Parser.datas           = Datas;

                    Changed = true;
                    break;
                }
            }
        }
Ejemplo n.º 9
0
        public FormCamera(string animatorEditorVar, int transformId)
        {
            InitializeComponent();
            startSize = new SizeF(Width, Height);
            this.SaveDesignSizes();
            this.AdjustSize((Size)Properties.Settings.Default["DialogCameraSize"], startSize);

            AEditor = (AnimatorEditor)Gui.Scripting.Variables[animatorEditorVar];
            Transform frame  = AEditor.Frames[transformId];
            Camera    camera = frame.m_GameObject.instance.FindLinkedComponent(UnityClassID.Camera);
            int       index  = AEditor.Cabinet.Components.IndexOf(camera);

            this.Text = camera.m_GameObject.instance.m_Name;

            EditorVar = Gui.Scripting.GetNextVariable("cameraEditor");
            Editor    = (CameraEditor)Gui.Scripting.RunScript(EditorVar + " = CameraEditor(parser=" + animatorEditorVar + ".Cabinet.Components[" + index + "])");

            Init();
            LoadCamera();

            checkBoxCameraEnabled.CheckedChanged                   += AttributeChanged;
            comboBoxCameraClearFlags.SelectedIndexChanged          += AttributeChanged;
            editTextBoxCameraBackgroundRed.AfterEditTextChanged    += AttributeChanged;
            editTextBoxCameraBackgroundGreen.AfterEditTextChanged  += AttributeChanged;
            editTextBoxCameraBackgroundBlue.AfterEditTextChanged   += AttributeChanged;
            editTextBoxCameraBackgroundAlpha.AfterEditTextChanged  += AttributeChanged;
            editTextBoxCameraCullingMask.AfterEditTextChanged      += AttributeChanged;
            checkBoxCameraOrthographic.CheckedChanged              += AttributeChanged;
            editTextBoxCameraOrthographicSize.AfterEditTextChanged += AttributeChanged;
            editTextBoxCameraFieldOfView.AfterEditTextChanged      += AttributeChanged;
            editTextBoxCameraNearClip.AfterEditTextChanged         += AttributeChanged;
            editTextBoxCameraFarClip.AfterEditTextChanged          += AttributeChanged;
            editTextBoxCameraViewportX.AfterEditTextChanged        += AttributeChanged;
            editTextBoxCameraViewportY.AfterEditTextChanged        += AttributeChanged;
            editTextBoxCameraViewportWidth.AfterEditTextChanged    += AttributeChanged;
            editTextBoxCameraViewportHeight.AfterEditTextChanged   += AttributeChanged;
            editTextBoxCameraDepth.AfterEditTextChanged            += AttributeChanged;
            comboBoxCameraRenderingPath.SelectedIndexChanged       += AttributeChanged;
            //comboBoxCameraTargetTexture.SelectedIndexChanged += AttributeChanged;
            checkBoxCameraOcclusionCulling.CheckedChanged += AttributeChanged;
            checkBoxCameraHDR.CheckedChanged += AttributeChanged;
            editTextBoxCameraTargetDisplay.AfterEditTextChanged     += AttributeChanged;
            editTextBoxCameraTargetEye.AfterEditTextChanged         += AttributeChanged;
            editTextBoxCameraStereoConvergence.AfterEditTextChanged += AttributeChanged;
            editTextBoxCameraStereoSeparation.AfterEditTextChanged  += AttributeChanged;
            checkBoxCameraStereoMirrorMode.CheckedChanged           += AttributeChanged;
        }
Ejemplo n.º 10
0
        public FormAnimatorDragDrop(AnimatorEditor destEditor)
        {
            InitializeComponent();
            startSize = new SizeF(Width, Height);
            this.SaveDesignSizes();
            this.AdjustSize((Size)Gui.Config["DialogXXDragDropSize"], startSize);
            editor = destEditor;

            numericFrameId.Maximum = editor.Frames.Count - 1;
            numericMeshId.Maximum  = editor.Frames.Count - 1;

            Tuple <string, Operations.SlotOperation>[] ops = new Tuple <string, Operations.SlotOperation>[2]
            {
                new Tuple <string, Operations.SlotOperation>("equals", Operations.SlotOperation.Equals),
                new Tuple <string, Operations.SlotOperation>("contains", Operations.SlotOperation.Contains)
            };
            comboBoxSlotOperationDiffuse.DisplayMember = "Item1";
            comboBoxSlotOperationDiffuse.ValueMember   = "Item2";
            comboBoxSlotOperationDiffuse.Items.AddRange(ops);
            comboBoxSlotOperationAmbient.DisplayMember = "Item1";
            comboBoxSlotOperationAmbient.ValueMember   = "Item2";
            comboBoxSlotOperationAmbient.Items.AddRange(ops);
            comboBoxSlotOperationEmissive.DisplayMember = "Item1";
            comboBoxSlotOperationEmissive.ValueMember   = "Item2";
            comboBoxSlotOperationEmissive.Items.AddRange(ops);
            comboBoxSlotOperationSpecular.DisplayMember = "Item1";
            comboBoxSlotOperationSpecular.ValueMember   = "Item2";
            comboBoxSlotOperationSpecular.Items.AddRange(ops);
            comboBoxSlotOperationBump.DisplayMember = "Item1";
            comboBoxSlotOperationBump.ValueMember   = "Item2";
            comboBoxSlotOperationBump.Items.AddRange(ops);
            comboBoxSlotOperationDiffuse.SelectedIndex  = 0;
            comboBoxSlotOperationAmbient.SelectedIndex  = 0;
            comboBoxSlotOperationEmissive.SelectedIndex = 1;
            comboBoxSlotOperationSpecular.SelectedIndex = 1;
            comboBoxSlotOperationBump.SelectedIndex     = 0;
            textBoxSlotDiffuse.Text  = "_MainTex";
            textBoxSlotAmbient.Text  = "unused";
            textBoxSlotEmissive.Text = "Spec";
            textBoxSlotSpecular.Text = "Norm";
            textBoxSlotBump.Text     = "_BumpMap";
        }
Ejemplo n.º 11
0
 private void comboBoxSourceAnimator_DropDown(object sender, EventArgs e)
 {
     try
     {
         HashSet <string> editors = new HashSet <string>();
         for (int i = 1; i < comboBoxSourceAnimator.Items.Count; i++)
         {
             Tuple <string, string> item = (Tuple <string, string>)comboBoxSourceAnimator.Items[i];
             object editor;
             if (!Gui.Scripting.Variables.TryGetValue(item.Item2, out editor))
             {
                 comboBoxSourceAnimator.Items.RemoveAt(i--);
                 continue;
             }
             editors.Add(item.Item2);
         }
         if (comboBoxSourceAnimator.Items.Count == 0)
         {
             comboBoxSourceAnimator.Items.Add(new Tuple <string, string>("(none)", null));
             comboBoxSourceAnimator.SelectedIndexChanged -= comboBoxSourceAnimator_SelectedIndexChanged;
             comboBoxSourceAnimator.SelectedItem          = comboBoxSourceAnimator.Items[0];
             comboBoxSourceAnimator.SelectedIndexChanged += comboBoxSourceAnimator_SelectedIndexChanged;
         }
         foreach (var pair in Gui.Scripting.Variables)
         {
             if (pair.Value is AnimatorEditor)
             {
                 AnimatorEditor editor = (AnimatorEditor)pair.Value;
                 if (!editors.Contains(pair.Key))
                 {
                     Tuple <string, string> item = new Tuple <string, string>(editor.Parser.m_GameObject.instance.m_Name, pair.Key);
                     comboBoxSourceAnimator.Items.Add(item);
                 }
             }
         }
     }
     catch (Exception ex)
     {
         Utility.ReportException(ex);
     }
 }
Ejemplo n.º 12
0
        private void comboBoxSourceAnimator_SelectedIndexChanged(object sender, EventArgs e)
        {
            try
            {
                Tuple <string, string> item = (Tuple <string, string>)comboBoxSourceAnimator.SelectedItem;
                if (item == null || item.Item2 == null)
                {
                    toolTip1.SetToolTip(comboBoxSourceAnimator, null);
                    labelSourceWarning.Visible = true;
                    return;
                }

                AnimatorEditor editor = (AnimatorEditor)Gui.Scripting.Variables[item.Item2];
                string         tip    = item.Item1 + " (" + editor.Parser.file.Parser.FilePath + ")";
                toolTip1.SetToolTip(comboBoxSourceAnimator, tip);
                RefreshLabelSourceWarning();
            }
            catch (Exception ex)
            {
                Utility.ReportException(ex);
            }
        }
Ejemplo n.º 13
0
        public void CopyNormals(int id, AnimatorEditor dstAnimatorEditor, bool minOrMax, bool setOrGet)
        {
            GenericMono  dstData    = GenericMonos[(int)id];
            int          dstMeshRId = dstAnimatorEditor.GetMeshRendererId(dstData.ObjectName);
            MeshRenderer mr         = (MeshRenderer)dstAnimatorEditor.Meshes[dstMeshRId];

            Operations.vMesh m       = new Operations.vMesh(mr, false, false);
            List <Vector3>   normals = minOrMax ? dstData.NormalMax : dstData.NormalMin;

            if (setOrGet)
            {
                for (int i = 0; i < m.submeshes.Count; i++)
                {
                    Operations.vSubmesh s = m.submeshes[i];
                    for (int j = 0; j < s.vertexList.Count; j++)
                    {
                        s.vertexList[j].normal = normals[j];
                    }
                }
                m.Flush();
            }
            else
            {
                normals.Clear();
                for (int i = 0; i < m.submeshes.Count; i++)
                {
                    Operations.vSubmesh s = m.submeshes[i];
                    for (int j = 0; j < s.vertexList.Count; j++)
                    {
                        normals.Add(s.vertexList[j].normal);
                    }
                }
                Parser.Param = GenericMonos;
            }

            Changed = true;
        }
Ejemplo n.º 14
0
 static void Collect(AnimatorEditor editor, HashSet <Component> collection)
 {
     foreach (Transform frame in editor.Frames)
     {
         GameObject gameObj = frame.m_GameObject.instance;
         collection.Add(gameObj);
         foreach (var comp in gameObj.m_Component)
         {
             collection.Add(comp.Value.asset);
             if (comp.Value.asset.classID() == UnityClassID.Animator)
             {
                 Animator anim = (Animator)comp.Value.asset;
                 if (anim.m_Avatar.instance != null && anim.m_Avatar.instance.classID() == UnityClassID.Avatar)
                 {
                     collection.Add(anim.m_Avatar.instance);
                 }
             }
         }
     }
     foreach (MeshRenderer meshR in editor.Meshes)
     {
         collection.Add(Operations.GetMesh(meshR));
         foreach (PPtr <Material> matPtr in meshR.m_Materials)
         {
             if (matPtr.instance != null)
             {
                 Material mat = matPtr.instance;
                 collection.Add(mat);
                 Collect(mat.m_Shader.instance, collection);
                 foreach (var texPair in mat.m_SavedProperties.m_TexEnvs)
                 {
                     collection.Add(texPair.Value.m_Texture.asset);
                 }
             }
         }
     }
 }
Ejemplo n.º 15
0
        public void ComputeMinMaxNormals(object[] nmlMeshIds, AnimatorEditor dstAnimatorEditor, NmlMonoBehaviourEditor srcNmlEditor, int srcNmlMeshId, AnimatorEditor srcAnimatorEditor, object[] adjacentAnimatorEditorMeshIdPairs, double adjacentSquaredDistance, bool worldCoordinates)
        {
            foreach (double id in nmlMeshIds)
            {
                int dstMeshRId = dstAnimatorEditor.GetMeshRendererId(GenericMonos[(int)id].ObjectName);
                SkinnedMeshRenderer       dstSMesh    = (SkinnedMeshRenderer)dstAnimatorEditor.Meshes[dstMeshRId];
                Operations.vMesh          dstVMesh    = new Operations.vMesh(dstSMesh, false, false);
                List <Operations.vVertex> dstVertList = dstVMesh.submeshes[0].vertexList;
                for (int i = 1; i < dstVMesh.submeshes.Count; i++)
                {
                    dstVertList.AddRange(dstVMesh.submeshes[i].vertexList);
                }
                Transform meshTransform       = dstSMesh.m_GameObject.instance.FindLinkedComponent(typeof(Transform));
                Matrix    meshTransformMatrix = Transform.WorldTransform(meshTransform);
                foreach (var vert in dstVertList)
                {
                    vert.position = Vector3.TransformCoordinate(vert.position, meshTransformMatrix);
                }

                int srcMeshRId = srcAnimatorEditor.GetMeshRendererId(srcNmlMeshId < 0 ? dstSMesh.m_GameObject.instance.m_Name : srcNmlEditor.GenericMonos[srcNmlMeshId].ObjectName);
                SkinnedMeshRenderer       srcSMesh    = (SkinnedMeshRenderer)srcAnimatorEditor.Meshes[srcMeshRId];
                Operations.vMesh          srcVMesh    = new Operations.vMesh(srcSMesh, false, false);
                List <Operations.vVertex> srcVertList = srcVMesh.submeshes[0].vertexList;
                for (int i = 1; i < srcVMesh.submeshes.Count; i++)
                {
                    srcVertList.AddRange(srcVMesh.submeshes[i].vertexList);
                }
                meshTransform       = srcSMesh.m_GameObject.instance.FindLinkedComponent(typeof(Transform));
                meshTransformMatrix = Transform.WorldTransform(meshTransform);
                foreach (var vert in srcVertList)
                {
                    vert.position = Vector3.TransformCoordinate(vert.position, meshTransformMatrix);
                }

                GenericMono dstGenMono = GenericMonos.Find
                                         (
                    delegate(GenericMono m)
                {
                    return(m.ObjectName == dstSMesh.m_GameObject.instance.m_Name);
                }
                                         );
                if (dstGenMono == null)
                {
                    dstGenMono            = new GenericMono();
                    dstGenMono.ObjectName = dstSMesh.m_GameObject.instance.m_Name;
                    GenericMonos.Add(dstGenMono);
                }
                else
                {
                    dstGenMono.NormalMin.Clear();
                    dstGenMono.NormalMax.Clear();
                }

                GenericMono srcGenMono = srcNmlMeshId < 0
                                        ? srcNmlEditor.GenericMonos.Find
                                         (
                    delegate(GenericMono m)
                {
                    return(m.ObjectName == dstSMesh.m_GameObject.instance.m_Name);
                }
                                         )
                                        : srcNmlEditor.GenericMonos[srcNmlMeshId];
                if (srcGenMono == null)
                {
                    throw new Exception("Source GenericMono for " + dstSMesh.m_GameObject.instance.m_Name + " not found");
                }
                if (srcGenMono.NormalMin.Count != srcVertList.Count)
                {
                    throw new Exception("Source GenericMono for " + dstSMesh.m_GameObject.instance.m_Name + " has " + srcGenMono.NormalMin.Count + " normals, but the source mesh has " + srcVertList.Count + " vertices.");
                }

                for (int i = 0; i < dstVertList.Count; i++)
                {
                    var   vert       = dstVertList[i];
                    int   vertIdx    = -1;
                    float minDistPos = float.MaxValue;
                    float minDistUV  = float.MaxValue;
                    for (int j = 0; j < srcVertList.Count; j++)
                    {
                        var   srcVert    = srcVertList[j];
                        float distSquare = (vert.position - srcVert.position).LengthSquared();
                        if (distSquare < minDistPos)
                        {
                            vertIdx = j;
                            if ((minDistPos = distSquare) == 0)
                            {
                                distSquare = (new Vector2(vert.uv[0], vert.uv[1]) - new Vector2(srcVert.uv[0], srcVert.uv[1])).LengthSquared();
                                if (distSquare < minDistUV)
                                {
                                    if ((minDistUV = distSquare) == 0)
                                    {
                                        break;
                                    }
                                }
                            }
                        }
                        else if (distSquare == minDistPos)
                        {
                            distSquare = (new Vector2(vert.uv[0], vert.uv[1]) - new Vector2(srcVert.uv[0], srcVert.uv[1])).LengthSquared();
                            if (distSquare < minDistUV)
                            {
                                vertIdx = j;
                                if ((minDistUV = distSquare) == 0)
                                {
                                    break;
                                }
                            }
                        }
                    }
                    dstGenMono.NormalMin.Add(vert.normal + srcGenMono.NormalMin[vertIdx] - srcGenMono.NormalMax[vertIdx]);
                    dstGenMono.NormalMax.Add(vert.normal);
                }

                if (adjacentAnimatorEditorMeshIdPairs != null)
                {
                    HashSet <int>      dstVertIndices = new HashSet <int>();
                    Operations.vMesh[] adjVMeshes     = new Operations.vMesh[adjacentAnimatorEditorMeshIdPairs.Length / 2];
                    for (int i = 0; i < adjacentAnimatorEditorMeshIdPairs.Length / 2; i++)
                    {
                        MeshRenderer adjMeshR = (MeshRenderer)((AnimatorEditor)adjacentAnimatorEditorMeshIdPairs[i * 2]).Meshes[(int)(double)adjacentAnimatorEditorMeshIdPairs[i * 2 + 1]];
                        Matrix       worldTransform;
                        if (worldCoordinates)
                        {
                            meshTransform  = adjMeshR.m_GameObject.instance.FindLinkedComponent(typeof(Transform));
                            worldTransform = Transform.WorldTransform(meshTransform);
                        }
                        else
                        {
                            worldTransform = Matrix.Identity;
                        }
                        Operations.vMesh adjVMesh = new Operations.vMesh(adjMeshR, false, false);
                        int adjVertsAdapted       = 0;
                        foreach (var adjSubmesh in adjVMesh.submeshes)
                        {
                            foreach (var adjVert in adjSubmesh.vertexList)
                            {
                                Vector3 adjPos = worldCoordinates
                                                                        ? Vector3.TransformCoordinate(adjVert.position, worldTransform)
                                                                        : adjVert.position;
                                for (int j = 0; j < dstVertList.Count; j++)
                                {
                                    var dstVert = dstVertList[j];
                                    if ((adjPos - dstVert.position).LengthSquared() < adjacentSquaredDistance)
                                    {
                                        if (dstVertIndices.Add(j))
                                        {
                                            dstGenMono.NormalMin[j] = dstGenMono.NormalMax[j] = (dstGenMono.NormalMin[j] + dstGenMono.NormalMax[j]) / 2;
                                        }
                                        adjVert.normal = dstGenMono.NormalMin[j];
                                        adjVertsAdapted++;
                                        break;
                                    }
                                }
                            }
                        }
                        if (adjVertsAdapted > 0)
                        {
                            adjVMeshes[i] = adjVMesh;
                            Report.ReportLog("Adjacent MeshRenderer " + adjMeshR.m_GameObject.instance.m_Name + " has " + adjVertsAdapted + " verts smaller squared distance than " + ((float)adjacentSquaredDistance).ToFloatString());
                        }
                    }

                    for (int i = 0; i < adjVMeshes.Length; i++)
                    {
                        var adjVMesh = adjVMeshes[i];
                        if (adjVMesh != null)
                        {
                            adjVMesh.Flush();
                            ((AnimatorEditor)adjacentAnimatorEditorMeshIdPairs[i * 2]).Changed = true;
                        }
                    }
                }
            }

            Parser.Param = GenericMonos;

            Changed = true;
        }
Ejemplo n.º 16
0
        public void ComputeMinMaxNormals(object[] nmlMeshIds, AnimatorEditor dstAnimatorEditor, NmlMonoBehaviour srcNmlParser, int srcNmlMeshId, AnimatorEditor srcAnimatorEditor, object[] adjacentAnimatorEditorMeshIdPairs, double adjacentSquaredDistance, bool worldCoordinates)
        {
            NmlMonoBehaviourEditor srcNmlEditor = new NmlMonoBehaviourEditor(srcNmlParser);

            ComputeMinMaxNormals(nmlMeshIds, dstAnimatorEditor, srcNmlEditor, srcNmlMeshId, srcAnimatorEditor, adjacentAnimatorEditorMeshIdPairs, adjacentSquaredDistance, worldCoordinates);
        }
Ejemplo n.º 17
0
        public void ComputeUVNormalBlendData(object[] uvnbMeshIds, AnimatorEditor dstAnimatorEditor, UVNormalBlendMonoBehaviour srcUVNBParser, int srcUVNBMeshId, AnimatorEditor srcAnimatorEditor, object[] adjacentAnimatorEditorMeshIdPairs, double adjacentSquaredDistance, bool worldCoordinates)
        {
            UVNormalBlendMonoBehaviourEditor srcUVNBEditor = new UVNormalBlendMonoBehaviourEditor(srcUVNBParser);

            ComputeUVNormalBlendData(uvnbMeshIds, dstAnimatorEditor, srcUVNBEditor, srcUVNBMeshId, srcAnimatorEditor, adjacentAnimatorEditorMeshIdPairs, adjacentSquaredDistance, worldCoordinates);
        }
Ejemplo n.º 18
0
        public void ComputeUVNormalBlendData(object[] uvnbMeshIds, AnimatorEditor dstAnimatorEditor, object[] adjacentAnimatorEditorMeshIdPairs, double adjacentSquaredDistance, bool worldCoordinates)
        {
            string path      = Path.GetDirectoryName(Parser.file.Parser.FilePath);
            string file      = Path.GetFileNameWithoutExtension(Parser.file.Parser.FilePath);
            string backupExt = Path.GetExtension(Parser.file.Parser.FilePath);

            backupExt = backupExt == String.Empty ? "None" : backupExt.Substring(1);
            backupExt = (string)Properties.Settings.Default["BackupExtension" + backupExt];
            UnityParser   srcFileParser = new UnityParser(path + @"\" + file + ".bak0" + backupExt);
            Unity3dEditor srcFileEditor = new Unity3dEditor(srcFileParser);

            srcFileEditor.GetAssetNames(true);
            Animator srcAnimator = null;

            if (dstAnimatorEditor.Parser.classID() != UnityClassID.Animator)
            {
                Component baseAsset = srcFileParser.Cabinet.Components.Find
                                      (
                    delegate(Component asset)
                {
                    return(asset is NotLoaded && asset.classID() == UnityClassID.GameObject && ((NotLoaded)asset).Name == dstAnimatorEditor.Parser.m_GameObject.instance.m_Name);
                }
                                      );
                srcAnimator = srcFileEditor.OpenVirtualAnimator(srcFileParser.Cabinet.Components.IndexOf(baseAsset));
            }
            else
            {
                Component baseAsset = srcFileParser.Cabinet.Components.Find
                                      (
                    delegate(Component asset)
                {
                    return(asset is NotLoaded && asset.classID() == UnityClassID.Animator && ((NotLoaded)asset).Name == dstAnimatorEditor.Parser.m_GameObject.instance.m_Name);
                }
                                      );
                srcAnimator = srcFileEditor.OpenAnimator(srcFileParser.Cabinet.Components.IndexOf(baseAsset));
            }
            AnimatorEditor srcAnimatorEditor = new AnimatorEditor(srcAnimator);

            Transform srcUVNBFrame = srcAnimatorEditor.Frames.Find
                                     (
                delegate(Transform asset)
            {
                return(asset.m_GameObject.instance.m_Name == Parser.m_GameObject.instance.m_Name);
            }
                                     );
            UVNormalBlendMonoBehaviour srcUVNB = null;

            srcUVNBFrame.m_GameObject.instance.m_Component.Find
            (
                delegate(KeyValuePair <UnityClassID, PPtr <Component> > componentEntry)
            {
                Component asset = componentEntry.Value.asset;
                if (asset is NotLoaded && asset.classID() == UnityClassID.MonoBehaviour && ((NotLoaded)asset).replacement is UVNormalBlendMonoBehaviour)
                {
                    srcUVNB = asset as UVNormalBlendMonoBehaviour;
                    return(true);
                }
                if (asset is UVNormalBlendMonoBehaviour)
                {
                    srcUVNB = (UVNormalBlendMonoBehaviour)asset;
                    return(true);
                }
                return(false);
            }
            );

            ComputeUVNormalBlendData(uvnbMeshIds, dstAnimatorEditor, srcUVNB, -1, srcAnimatorEditor, adjacentAnimatorEditorMeshIdPairs, adjacentSquaredDistance, worldCoordinates);
        }
Ejemplo n.º 19
0
    static void TouchBar_Manager_OnReady()
    {
        TouchBar.Manager.OnReady -= TouchBar_Manager_OnReady;
        EditorApplication.update += EditorApplication_Update;
        group = new TouchBar.Group("animation", 4);

        segments = group.AddSegments("segments", 5);

        recordButton = group.AddImageButton("record", "/Editor/UniTouchBar/Icons/record.png", "", () => {
            if (AnimatorEditor.GetFlag("recording"))
            {
                //STOP
                System.Type.GetType("UnityEditorInternal.AnimationWindowState, UnityEditor.dll").GetMethod("StopRecording").Invoke(AnimatorEditor.stateWindow, null);
                recordButton.UpdateImage("/Editor/UniTouchBar/Icons/record.png");
            }
            else
            {
                //START
                System.Type.GetType("UnityEditorInternal.AnimationWindowState, UnityEditor.dll").GetMethod("StartRecording").Invoke(AnimatorEditor.stateWindow, null);
                recordButton.UpdateImage("/Editor/UniTouchBar/Icons/recording.png");
            }
            AnimatorEditor.Repaint();
        });

        slider = group.AddSlider("slider", 0, 100, 1, (double obj) => {
            try {
                object[] parameters = new object[] {
                    (float)obj
                };
                System.Type.GetType("UnityEditorInternal.IAnimationWindowControl, UnityEditor.dll").GetMethod("GoToTime").Invoke(AnimatorEditor.controlInterface, parameters);
                AnimatorEditor.Repaint();
            } catch (System.Exception ex) {
                TouchBar.Log(ex);
            }

            ///TouchBar.Log(System.Type.GetType("UnityEditorInternal.AnimationWindowState, UnityEditor.dll").GetProperty("maxTime").GetValue(AnimatorEditor.stateWindow, null));
        });
        TouchBar.AddGroup(group);
        segments.SetOptionWithImage(0, "/Editor/UniTouchBar/Icons/segment_rewind_back.png", () => {
            System.Type.GetType("UnityEditorInternal.IAnimationWindowControl, UnityEditor.dll").GetMethod("GoToFirstKeyframe").Invoke(AnimatorEditor.controlInterface, null);
            AnimatorEditor.Repaint();
            AnimatorTouchBar.SegmentClick();
        });
        segments.SetOptionWithImage(1, "/Editor/UniTouchBar/Icons/segment_step_back.png", () => {
            System.Type.GetType("UnityEditorInternal.IAnimationWindowControl, UnityEditor.dll").GetMethod("GoToPreviousKeyframe").Invoke(AnimatorEditor.controlInterface, null);
            AnimatorEditor.Repaint();
            AnimatorTouchBar.SegmentClick();
        });
        segments.SetOptionWithImage(2, "/Editor/UniTouchBar/Icons/segment_play.png", () => {
            if (AnimatorEditor.GetFlag("playing"))
            {
                //STOP
                segments.Select(-1);
                System.Type.GetType("UnityEditorInternal.AnimationWindowState, UnityEditor.dll").GetMethod("StopPlayback").Invoke(AnimatorEditor.stateWindow, null);
            }
            else
            {
                //START
                segments.Select(2);
                System.Type.GetType("UnityEditorInternal.AnimationWindowState, UnityEditor.dll").GetMethod("StartPlayback").Invoke(AnimatorEditor.stateWindow, null);
            }
            AnimatorEditor.Repaint();
        });
        segments.SetOptionWithImage(3, "/Editor/UniTouchBar/Icons/segment_step.png", () => {
            System.Type.GetType("UnityEditorInternal.IAnimationWindowControl, UnityEditor.dll").GetMethod("GoToNextKeyframe").Invoke(AnimatorEditor.controlInterface, null);
            AnimatorEditor.Repaint();
            AnimatorTouchBar.SegmentClick();
        });
        segments.SetOptionWithImage(4, "/Editor/UniTouchBar/Icons/segment_rewind.png", () => {
            System.Type.GetType("UnityEditorInternal.IAnimationWindowControl, UnityEditor.dll").GetMethod("GoToLastKeyframe").Invoke(AnimatorEditor.controlInterface, null);
            AnimatorEditor.Repaint();
            AnimatorTouchBar.SegmentClick();
        });

        group.ShowOnWindow(TouchBar.Windows.Animation);
        group.ShowOnWindow(TouchBar.Windows.Scene);
        group.OnShow += () => {
            AnimatorEditor.Clean();
            //            TouchBar.Log("Hello");
            loaded = true;
            if (AnimatorEditor.window == null)
            {
                group.Hide();
                loaded = false;
            }

            if ((EditorWindow.focusedWindow != null) && (EditorWindow.focusedWindow.titleContent.text == "Scene"))
            {
            }
        };
    }
Ejemplo n.º 20
0
        public static void ProcessDragDropSources(TreeNode srcNode, TreeView dstTreeView, EditTextBox editTextBoxValue, AssetCabinet dstCabinet)
        {
            if (srcNode.Tag != null && srcNode.Tag.GetType() == typeof(List <TreeNode>))
            {
                srcNode = ((List <TreeNode>)srcNode.Tag)[0];
            }
            if (srcNode.Tag is DragSource)
            {
                if (!(srcNode.TreeView.FindForm() is FormAnimator))
                {
                    return;
                }

                TreeNode dest = null;
                if (dstTreeView.SelectedNode != null)
                {
                    if (dstTreeView.SelectedNode.Tag is string && ((string)dstTreeView.SelectedNode.Tag).Contains("PPtr<"))
                    {
                        dest = dstTreeView.SelectedNode;
                    }
                }
                if (dest == null)
                {
                    return;
                }

                DragSource     source    = (DragSource)srcNode.Tag;
                AnimatorEditor srcEditor = Gui.Scripting.Variables[source.Variable] as AnimatorEditor;
                if (srcEditor != null && srcEditor.Cabinet.VersionNumber != dstCabinet.VersionNumber)
                {
                    using (FormVersionWarning versionWarning = new FormVersionWarning(srcEditor.Cabinet.Parser, dstCabinet.Parser))
                    {
                        DialogResult result = versionWarning.ShowDialog();
                        if (result != DialogResult.OK)
                        {
                            return;
                        }
                    }
                }
                editTextBoxValue.Focus();
                if (source.Type == typeof(Transform))
                {
                    editTextBoxValue.Text = srcEditor.Frames[(int)source.Id].pathID.ToString();
                }
                else if (source.Id is MonoBehaviour ||
                         source.Type == typeof(NotLoaded) && ((NotLoaded)source.Id).classID() == UnityClassID.MonoBehaviour)
                {
                    editTextBoxValue.Text = ((Component)source.Id).pathID.ToString();
                }
                else if (source.Type == typeof(Material))
                {
                    editTextBoxValue.Text = srcEditor.Materials[(int)source.Id].pathID.ToString();
                }
                else if (source.Type == typeof(Texture2D))
                {
                    editTextBoxValue.Text = srcEditor.Textures[(int)source.Id].pathID.ToString();
                }
                else if (source.Type == typeof(MeshRenderer) || source.Type.IsSubclassOf(typeof(MeshRenderer)))
                {
                    editTextBoxValue.Text = srcEditor.Meshes[(int)source.Id].pathID.ToString();
                }
                else if (source.Id is LinkedByGameObject)
                {
                    editTextBoxValue.Text = ((LinkedByGameObject)source.Id).pathID.ToString();
                }
                else if (source.Id is int)
                {
                    Transform animatorFrame = srcEditor.Frames[(int)source.Id];
                    editTextBoxValue.Text = animatorFrame.m_GameObject.instance.FindLinkedComponent(UnityClassID.Animator).pathID.ToString();
                }
            }
        }