Ejemplo n.º 1
0
        private void AddKeyFrame(int Index, int Frame, int ImageIndex)
        {
            if (activeSampler == null)
            {
                return;
            }

            bool IsValidIndex = Index < ActiveMaterialAnim.Textures.Count && Index != -1;

            if (!IsValidIndex) //Indices can be invalid for example if an animation is switched quickly in editor
            {
                return;
            }

            string TextureKey = activeSampler.GetActiveTextureNameByIndex((int)Index);

            var tex = activeSampler.GetActiveTexture((int)Index);

            if (tex != null)
            {
                listViewCustom1.Items.Add($"{Frame} / {ActiveMaterialAnim.FrameCount} \n" + tex.Text, ImageIndex);
            }
            else
            {
                listViewCustom1.Items.Add($"{Frame} / {ActiveMaterialAnim.FrameCount} \n" + TextureKey, ImageIndex);
            }
        }
        private void LoadAniamtion(MaterialAnimation anim, MaterialAnimation.SamplerKeyGroup activeSampler)
        {
            if (activeSampler == null || IsLoading)
            {
                return;
            }

            int imageIndex = 0;

            imgList.Images.Clear();
            Images.Clear();
            KeyFrames.Clear();

            listViewCustom1.SmallImageList = imgList;
            listViewCustom1.Items.Clear();
            listViewCustom1.View = View.SmallIcon;

            Thread Thread = new Thread((ThreadStart)(() =>
            {
                IsLoading = true;

                for (int Frame = 0; Frame <= anim.FrameCount; Frame++)
                {
                    //Constants always show so break after first frame
                    if (activeSampler.Constant && Frame != 0)
                    {
                        break;
                    }

                    var keyFrame = activeSampler.GetKeyFrame(Frame);

                    if (keyFrame.IsKeyed || activeSampler.Constant)
                    {
                        string TextureKey = activeSampler.GetActiveTextureNameByIndex((int)keyFrame.Value);

                        var tex = activeSampler.GetActiveTexture((int)keyFrame.Value);

                        if (tex != null)
                        {
                            Bitmap temp = tex.GetBitmap();
                            Images.Add(Frame, temp);
                            KeyFrames.Add(Frame);

                            if (listViewCustom1.InvokeRequired)
                            {
                                listViewCustom1.Invoke((MethodInvoker) delegate {
                                    // Running on the UI thread
                                    listViewCustom1.Items.Add($"{Frame} / {anim.FrameCount} \n" + tex.Text, imageIndex++);
                                    imgList.Images.Add(temp);
                                    var dummy = imgList.Handle;
                                });
                            }
                            else
                            {
                                listViewCustom1.Items.Add($"{Frame} / {anim.FrameCount} \n" + tex.Text, imageIndex++);
                            }
                        }
                        else
                        {
                            if (listViewCustom1.InvokeRequired)
                            {
                                listViewCustom1.Invoke((MethodInvoker) delegate {
                                    listViewCustom1.Items.Add($"{Frame} / {anim.FrameCount} \n" + TextureKey, imageIndex++);
                                });
                            }
                            else
                            {
                                listViewCustom1.Items.Add($"{Frame} / {anim.FrameCount} \n" + TextureKey, imageIndex++);
                            }
                        }
                    }
                }

                IsLoading = false;
            }));

            Thread.Start();
        }