Esempio n. 1
0
        public Bone(SkeletonViewModel skeleton, string name, IMemory <CmTransform> transformMem, SkeletonService.Bone definition)
        {
            this.poseService = Services.Get <PoseService>();

            this.Skeleton     = skeleton;
            this.Definition   = definition;
            this.BoneName     = name;
            this.transformMem = transformMem;
            this.transformMem.ValueChanged += this.OnTransformMemValueChanged;

            this.rotation = new RotateTransform3D();
            this.scale    = new ScaleTransform3D();
            this.position = new TranslateTransform3D();

            Transform3DGroup transformGroup = new Transform3DGroup();

            transformGroup.Children.Add(this.scale);
            transformGroup.Children.Add(this.rotation);
            transformGroup.Children.Add(this.position);

            this.Transform = transformGroup;

            PaletteHelper ph = new PaletteHelper();

            Sphere sphere = new Sphere();

            sphere.Radius = 0.015;
            System.Windows.Media.Color c1 = ph.GetTheme().Paper;
            c1.A            = 255;
            sphere.Material = new DiffuseMaterial(new SolidColorBrush(c1));
            this.Children.Add(sphere);
        }
Esempio n. 2
0
        public async Task Write(SkeletonViewModel skeleton, Groups groups)
        {
            PoseService poseService = Services.Get <PoseService>();

            poseService.IsEnabled = true;

            // don't freeze positions if we aren't writing any
            poseService.FreezePositions = this.IncludePositions;

            foreach (Bone bone in skeleton.Bones)
            {
                if (!bone.IsEnabled)
                {
                    continue;
                }

                Groups group = Enum.Parse <Groups>(bone.Definition.Group);
                if (!groups.HasFlag(group))
                {
                    continue;
                }

                if (this.Bones.ContainsKey(bone.BoneName))
                {
                    try
                    {
                        this.Bones[bone.BoneName].Rotation.Normalize();

                        Transform trans    = bone.LiveTransform;
                        Transform newTrans = this.Bones[bone.BoneName];

                        if (this.IncludeScale && newTrans.Scale != Vector.Zero)
                        {
                            trans.Scale = newTrans.Scale;
                        }

                        if (this.IncludePositions && newTrans.Position != Vector.Zero)
                        {
                            trans.Position = newTrans.Position;
                        }

                        ////if (newTrans.Rotation != Quaternion.Identity)
                        trans.Rotation = newTrans.Rotation;

                        bone.LiveTransform = trans;
                        bone.ReadTransform();
                    }
                    catch (Exception ex)
                    {
                        throw new Exception("Failed to apply pose transform to bone: " + bone.BoneName, ex);
                    }
                }
            }

            await Task.Delay(100);

            poseService.FreezePositions = true;

            skeleton.RefreshBones();
        }
Esempio n. 3
0
        public SkeletonViewModel()
        {
            Application.Current.Dispatcher.Invoke(() =>
            {
                this.Root = new ModelVisual3D();
            });

            PoseService poseService = Services.Get <PoseService>();

            poseService.EnabledChanged += this.OnPoseServiceEnabledChanged;
        }