Ejemplo n.º 1
0
 public MaterialAnimation.Material.Sampler GetSamplerData()
 {
     MaterialAnimation.Material.Sampler sampler = new MaterialAnimation.Material.Sampler();
     sampler.Text           = samplerNameTB.Text;
     sampler.group.Constant = constantChkBox.Checked;
     return(sampler);
 }
        private void LoadAniamtion(MaterialAnimation anim, MaterialAnimation.Material.Sampler 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.group.Constant && Frame != 0)
                    {
                        break;
                    }

                    var keyFrame = activeSampler.group.GetKeyFrame(Frame);

                    if (keyFrame.IsKeyed || activeSampler.group.Constant)
                    {
                        var tex = activeSampler.GetActiveTexture(Frame);

                        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" + activeSampler.GetActiveTextureName(Frame), imageIndex++);
                                });
                            }
                            else
                            {
                                listViewCustom1.Items.Add($"{Frame} / {anim.FrameCount} \n" + activeSampler.GetActiveTextureName(Frame), imageIndex++);
                            }
                        }
                    }
                }

                IsLoading = false;
            }));

            Thread.Start();
        }