Example #1
0
        void nui_SkeletonFrameReady(object sender, SkeletonFrameReadyEventArgs e)
        {
            SkeletonFrame allSkeletons = e.SkeletonFrame;

            //get the first tracked skeleton
            SkeletonData skeleton = (from s in allSkeletons.Skeletons
                                     where s.TrackingState == SkeletonTrackingState.Tracked
                                     select s).FirstOrDefault();
            if (skeleton != null)
            {
                this._skel = skeleton;
                Joint head = skeleton.Joints[JointID.Head];
                HumanSkeleton hs = new HumanSkeleton(skeleton.Joints);
                NaoSkeleton ns = new NaoSkeleton(hs);
                UpdateTextBoxes(ns, hs);
                controller.update(ns);

                SetLineAngle(RightArmTopDown, Util.radToDeg(hs.RightShoulderYaw));
                SetLineAngle(LeftArmTopDown, Util.radToDeg(hs.LeftShoulderYaw));
                SetLineAngle(RightArmFront, Util.radToDeg(-hs.RightShoulderPitch) + 90);
                SetLineAngle(LeftArmFront, Util.radToDeg(hs.LeftShoulderPitch) - 90);
                SetLineAngle(RightArm, Util.radToDeg(-hs.RightShoulderRoll) + 90);
                SetLineAngle(LeftArm, Util.radToDeg(hs.LeftShoulderRoll) - 90);
            }
        }
        /// <summary>
        /// Crunches Kinect SDK's Skeleton Data and spits out a format more useful for DTW
        /// </summary>
        /// <param name="data">Kinect SDK's Skeleton Data</param>
        public static void ProcessData(SkeletonData data)
        {
            // Extract the coordinates of the points.
            var p = new Point3D[6];
            Point3D shoulderRight = new Point3D(), shoulderLeft = new Point3D();
            foreach (Joint j in data.Joints)
            {
                switch (j.ID)
                {
                    case JointID.HandLeft:
                        p[0] = new Point3D(j.Position.X, j.Position.Y, j.Position.Z);
                        break;
                    case JointID.WristLeft:
                        p[1] = new Point3D(j.Position.X, j.Position.Y, j.Position.Z);
                        break;
                    case JointID.ElbowLeft:
                        p[2] = new Point3D(j.Position.X, j.Position.Y, j.Position.Z);
                        break;
                    case JointID.ElbowRight:
                        p[3] = new Point3D(j.Position.X, j.Position.Y, j.Position.Z);
                        break;
                    case JointID.WristRight:
                        p[4] = new Point3D(j.Position.X, j.Position.Y, j.Position.Z);
                        break;
                    case JointID.HandRight:
                        p[5] = new Point3D(j.Position.X, j.Position.Y, j.Position.Z);
                        break;
                    case JointID.ShoulderLeft:
                        shoulderLeft = new Point3D(j.Position.X, j.Position.Y, j.Position.Z);
                        break;
                    case JointID.ShoulderRight:
                        shoulderRight = new Point3D(j.Position.X, j.Position.Y, j.Position.Z);
                        break;
                }
            }

            // Centre the data
            var center = new Point3D((shoulderLeft.X + shoulderRight.X) / 2, (shoulderLeft.Y + shoulderRight.Y) / 2, (shoulderLeft.Z + shoulderRight.Z) / 2);
            for (int i = 0; i < 6; i++)
            {
                p[i].X -= center.X;
                p[i].Y -= center.Y;
                p[i].Z -= center.Z;
            }

            // Normalization of the coordinates
            double shoulderDist =
                Math.Sqrt(Math.Pow((shoulderLeft.X - shoulderRight.X), 2) +
                          Math.Pow((shoulderLeft.Y - shoulderRight.Y), 2) +
                          Math.Pow((shoulderLeft.Z - shoulderRight.Z), 2));
            for (int i = 0; i < 6; i++)
            {
                p[i].X /= shoulderDist;
                p[i].Y /= shoulderDist;
                p[i].Z /= shoulderDist;
            }

            // Launch the event!
            Skeleton3DdataCoordReady(null, new Skeleton3DdataCoordEventArgs(p));
        }
        private void DrawSkeleton(SkeletonData skeleton)
        {
            if (markers == null)
            {
                markers = new Dictionary<JointID, Ellipse>();
            }

            if (markers.Count == 0)
            {
                foreach (Joint joint in skeleton.Joints)
                {
                    if (!markers.ContainsKey(joint.ID))
                    {
                        Ellipse jointEllipse = Copy(EllipseTemplate);
                        jointEllipse.Visibility = Visibility.Visible;

                        markers.Add(joint.ID, jointEllipse);

                        MainCanvas.Children.Add(markers[joint.ID]);
                    }
                }
            }

            foreach (Joint joint in skeleton.Joints)
            {
                SetUIElementPosition(markers[joint.ID], joint);
            }
        }
        //This function will be implemented by you in the subclass files provided.
        //A simple example of highlighting targets when hovered over has been provided below

        //Note: targets is a dictionary that allows you to retrieve the corresponding target on screen
        //and manipulate its state and position, as well as hide/show it (see class defn. below).
        //It is indexed from 1, thus you can retrieve an individual target with the expression
        //targets[3], which would retrieve the target labeled "3" on screen.
        public virtual void processSkeletonFrame(SkeletonData skeleton, Dictionary<int, Target> targets)
        {

            /*Example implementation*/

            foreach (var target in targets)
            {
                Target cur = target.Value;
                int targetID = cur.id; //ID in range [1..5]

                //Scale the joints to the size of the window
                Joint leftHand = skeleton.Joints[JointID.HandLeft].ScaleTo(640, 480, window.k_xMaxJointScale, window.k_yMaxJointScale);
                Joint rightHand = skeleton.Joints[JointID.HandRight].ScaleTo(640, 480, window.k_xMaxJointScale, window.k_yMaxJointScale);
                
                //Calculate how far our left hand is from the target in both x and y directions
                double deltaX_left = Math.Abs(leftHand.Position.X - cur.getXPosition());
                double deltaY_left = Math.Abs(leftHand.Position.Y - cur.getYPosition());

                //Calculate how far our right hand is from the target in both x and y directions
                double deltaX_right = Math.Abs(rightHand.Position.X - cur.getXPosition());
                double deltaY_right = Math.Abs(rightHand.Position.Y - cur.getYPosition());

                //If we have a hit in a reasonable range, highlight the target
                if (deltaX_left < 15 && deltaY_left < 15 || deltaX_right < 15 && deltaY_right < 15)
                {
                    cur.setTargetSelected();
                }
                else
                {
                    cur.setTargetUnselected();
                }
            }

        }
Example #5
0
        //Note: targets is a dictionary that allows you to retrieve the corresponding target on screen
        //and manipulate its state and position, as well as hide/show it (see class defn. below).
        //It is indexed from 1, thus you can retrieve an individual target with the expression
        //targets[3], which would retrieve the target labeled "3" on screen.
        public override void processSkeletonFrame(SkeletonData skeleton, Dictionary<int, Target> targets)
        {
            Joint head = skeleton.Joints[JointID.Head].ScaleTo(640, 480, window.k_xMaxJointScale, window.k_yMaxJointScale);
            //Joint center = skeleton.Joints[JointID.HipCenter].ScaleTo(640, 480, window.k_xMaxJointScale, window.k_yMaxJointScale);
            Joint leftShoulder = skeleton.Joints[JointID.ShoulderLeft].ScaleTo(640, 480, window.k_xMaxJointScale, window.k_yMaxJointScale);
            Joint rightShoulder = skeleton.Joints[JointID.ShoulderRight].ScaleTo(640, 480, window.k_xMaxJointScale, window.k_yMaxJointScale);
            Joint leftHand = skeleton.Joints[JointID.HandLeft].ScaleTo(640, 480, window.k_xMaxJointScale, window.k_yMaxJointScale);
            Joint rightHand = skeleton.Joints[JointID.HandRight].ScaleTo(640, 480, window.k_xMaxJointScale, window.k_yMaxJointScale);

            //Check targets for highlighting and selection
            for (var i = 1; i <= 5; i++)
            {
                double targetXPos = targets[i].getXPosition();

                //Check to see which region
                if (Math.Abs(targetXPos - head.Position.X) < 40)
                {
                    highlighting = i;

                    //Check to see if the arms are above the head
                    if (leftHand.Position.Y < leftShoulder.Position.Y || rightHand.Position.Y < leftShoulder.Position.Y || leftHand.Position.Y < rightShoulder.Position.Y || rightHand.Position.Y < rightShoulder.Position.Y)
                    {
                        selecting = i;
                    }
                }
            }

            //Reflect the current highlighting/selection state in the targets
            for (var i = 1; i <= 5; i++)
            {
                targets[i].setTargetUnselected();
            }
            if (highlighting > 0) targets[highlighting].setTargetHighlighted();
            if (selecting > 0) targets[selecting].setTargetSelected();
        }
Example #6
0
        private void DrawSkeleton(SkeletonData data)
        {
            skeletonCanvas.Children.Clear();

            // Draw bones
            Brush brush = new SolidColorBrush(Colors.Green);
            skeletonCanvas.Children.Add(GetBodySegment(data.Joints, brush, JointID.HipCenter, JointID.Spine, JointID.ShoulderCenter, JointID.Head));
            skeletonCanvas.Children.Add(GetBodySegment(data.Joints, brush, JointID.ShoulderCenter, JointID.ShoulderLeft, JointID.ElbowLeft, JointID.WristLeft, JointID.HandLeft));
            skeletonCanvas.Children.Add(GetBodySegment(data.Joints, brush, JointID.ShoulderCenter, JointID.ShoulderRight, JointID.ElbowRight, JointID.WristRight, JointID.HandRight));
            skeletonCanvas.Children.Add(GetBodySegment(data.Joints, brush, JointID.HipCenter, JointID.HipLeft, JointID.KneeLeft, JointID.AnkleLeft, JointID.FootLeft));
            skeletonCanvas.Children.Add(GetBodySegment(data.Joints, brush, JointID.HipCenter, JointID.HipRight, JointID.KneeRight, JointID.AnkleRight, JointID.FootRight));

            // Draw joints
            foreach (Line jointLine in
                from Joint joint in data.Joints
                let jointPos = GetDisplayPosition(joint)
                select new Line
                {
                    Stroke = jointColors[joint.ID],
                    StrokeThickness = 6,
                    X1 = jointPos.X - 3,
                    X2 = jointPos.X + 3,
                    Y1 = jointPos.Y,
                    Y2 = jointPos.Y
                }) { skeletonCanvas.Children.Add(jointLine); }
        }
 private void detect_Pause(SkeletonData skeleton)
 {
     float hipX = Math.Abs(skeleton.Joints[JointID.HipCenter].Position.Y), hipY = Math.Abs(skeleton.Joints[JointID.HipCenter].Position.X),
         hipZ = Math.Abs(skeleton.Joints[JointID.HipCenter].Position.Z), rHandX = Math.Abs(skeleton.Joints[JointID.HandRight].Position.X),
         rHandY = Math.Abs(skeleton.Joints[JointID.HandRight].Position.Y), rHandZ = Math.Abs(skeleton.Joints[JointID.HandRight].Position.Z),
         lHandX = Math.Abs(skeleton.Joints[JointID.HandLeft].Position.X), lHandY = Math.Abs(skeleton.Joints[JointID.HandLeft].Position.Y),
         lHandZ = Math.Abs(skeleton.Joints[JointID.HandLeft].Position.Z), lElbowY = Math.Abs(skeleton.Joints[JointID.ElbowLeft].Position.Y),
         spineY = Math.Abs(skeleton.Joints[JointID.Spine].Position.Y);
     detected = false;
     if(DEBUG)
         textBox1.AppendText("Checking for pause:\n");
     if (DEBUG2)
     {
         //textBox1.AppendText("" + (lHandX <= (hipX + VAL)) + " | " + (lHandX >= (hipX - VAL)) + " | " + (lHandZ >= (hipZ + VAL)) + "\n");
         textBox1.AppendText("hip: " + hipX + " " + hipY + " " + hipZ + " | " + "lHand: " + lHandX + " " + lHandY + " " + lHandZ + "\n");
     }
     if (lHandX <= (hipX + VAL) && lHandX >= (hipX - VAL) && (lHandZ + VAL) <= hipZ && lHandY <= (lElbowY + VAL))
     {
         if(DEBUG)
             textBox1.AppendText("Passed test.\n");
         static_Count++;
         shuffle.Opacity = 0.25;
         wave.Opacity = 0.25;
         detected = true;
         if (static_Count >= 4)
         {
             if (DEBUG)
                 textBox1.AppendText("Changing button opacity.\n");
             pause.Opacity = 1;
             static_Count = 3;
         }
     }
 }
 public SkeletonProcessing(SkeletonData _skeleton, float _scale)
 {
     skeleton = _skeleton;
     screenheight = Height;
     screenwidth = Width;
     scale = _scale;
     coords = new coord[11];
 }
 private void DrawSkeleton(SkeletonData skeleton)
 {
     SetUIElementPosition(HeadImage, skeleton.Joints[JointID.Head]);
     SetUIElementPosition(LeftHandImage, skeleton.Joints[JointID.HandLeft]);
     SetUIElementPosition(RighthandImage, skeleton.Joints[JointID.HandRight]);
     SetUIElementPosition(LeftBootImage, skeleton.Joints[JointID.FootLeft], 50);
     SetUIElementPosition(RightBootImage, skeleton.Joints[JointID.FootRight], 50);
 }
Example #10
0
        public static Vector3D CalculateHeadInclination(SkeletonData bodyPartData)
        {
            Vector centerShoulderPosition = bodyPartData.Joints[JointID.ShoulderCenter].Position;
            Vector headPosition = bodyPartData.Joints[JointID.Head].Position;

            return new Vector3D(headPosition.X - centerShoulderPosition.X, headPosition.Y - centerShoulderPosition.Y,
                headPosition.Z - centerShoulderPosition.Z);
        }
Example #11
0
        public static Vector3D CalculateTorsoInclination(SkeletonData bodyPartData)
        {
            Vector hipCenterPosition = bodyPartData.Joints[JointID.HipCenter].Position;
            Vector shoulderCenterPosition = bodyPartData.Joints[JointID.ShoulderCenter].Position;

            return new Vector3D(shoulderCenterPosition.X - hipCenterPosition.X, shoulderCenterPosition.Y - hipCenterPosition.Y,
                shoulderCenterPosition.Z - hipCenterPosition.Z);
        }
Example #12
0
        public override void processSkeletonFrame(SkeletonData skeleton, Dictionary<int, Target> targets)
        {
            Joint leftHand = skeleton.Joints[JointID.HandLeft].ScaleTo(640, 480, window.k_xMaxJointScale, window.k_yMaxJointScale);
            Joint head = skeleton.Joints[JointID.ShoulderCenter].ScaleTo(640, 480, window.k_xMaxJointScale, window.k_yMaxJointScale);

            // If we are currently in selection mode
            if (selectMode)
            {
                // Leave selection mode if left hand is below head
                if (leftHand.Position.Y > head.Position.Y)
                {
                    selectMode = false;
                    foreach (var target in targets)
                    {
                        target.Value.setTargetUnselected();
                    }
                }
                // Compute which target to select based on horizontal distance of right hand from center position
                // Note: Target keys must be in the range 1..targets.Count
                else
                {
                    Joint rightHand = skeleton.Joints[JointID.HandRight].ScaleTo(640, 480, window.k_xMaxJointScale, window.k_yMaxJointScale);
                    double deltaX = rightHand.Position.X - centerX;;
                    int targetToSelect = Math.Min(targets.Count, Math.Max(1, (int)Math.Ceiling((deltaX / rangeX + 0.5) * targets.Count)));
                    foreach (var target in targets)
                    {
                        if (target.Key == targetToSelect)
                        {
                            if (rightHandTargetID < 0)
                            {
                                startTimer(target.Value, 1.5);
                            }
                            else if (rightHandTargetID != target.Key)
                            {
                                stopTimer(rightHandTarget);
                                startTimer(target.Value, 1.5);
                            }
                        }
                        else
                        {
                            target.Value.setTargetUnselected();
                        }
                    }
                }
            }

            // Not in selection mode
            else
            {
                // Enter selection mode if left hand is above head
                if (leftHand.Position.Y < head.Position.Y)
                {
                    selectMode = true;
                    Joint rightHand = skeleton.Joints[JointID.HandRight].ScaleTo(640, 480, window.k_xMaxJointScale, window.k_yMaxJointScale);
                    centerX = rightHand.Position.X;
                }
            }
        }
Example #13
0
        public override void processSkeletonFrame(SkeletonData skeleton, Dictionary<int, Target> targets)
        {
            // Gets right shoulder position
            Point rightShoulderPosition;
            Joint rightShoulder = skeleton.Joints[JointID.ShoulderRight];
            rightShoulderPosition = new Point(rightShoulder.Position.X, rightShoulder.Position.Z);

            Point leftShoulderPosition;
            Joint leftShoulder = skeleton.Joints[JointID.ShoulderLeft];
            leftShoulderPosition = new Point(leftShoulder.Position.X, leftShoulder.Position.Z);

            double shoulderDifferential = leftShoulderPosition.Y - rightShoulderPosition.Y;

            if (shoulderDifferential < -0.08)       // Rightmost (i.e. 5)
            {
                targets[1].setTargetUnselected();
                targets[2].setTargetUnselected();
                targets[3].setTargetUnselected();
                targets[4].setTargetUnselected();
                targets[5].setTargetSelected();

            }
            else if (shoulderDifferential < -0.025 && shoulderDifferential > -0.08)   // "4"
            {
                targets[1].setTargetUnselected();
                targets[2].setTargetUnselected();
                targets[3].setTargetUnselected();
                targets[4].setTargetSelected();
                targets[5].setTargetUnselected();

            }
            else if (shoulderDifferential > -0.025 && shoulderDifferential < 0.025)   // "3"
            {
                targets[1].setTargetUnselected();
                targets[2].setTargetUnselected();
                targets[3].setTargetSelected();
                targets[4].setTargetUnselected();
                targets[5].setTargetUnselected();

            }
            else if (shoulderDifferential > 0.025 && shoulderDifferential < 0.08)    // "2"
            {
                targets[1].setTargetUnselected();
                targets[2].setTargetSelected();
                targets[3].setTargetUnselected();
                targets[4].setTargetUnselected();
                targets[5].setTargetUnselected();
            }
            else if (shoulderDifferential > 0.08)       // "1" or leftmost
            {
                targets[1].setTargetSelected();
                targets[2].setTargetUnselected();
                targets[3].setTargetUnselected();
                targets[4].setTargetUnselected();
                targets[5].setTargetUnselected();

            }
        }
Example #14
0
        //void UpdateSegmentPosition(JointID j1, JointID j2, PlayerUtils.Segment seg)
        //{
        //    var bone = new PlayerUtils.Bone(j1, j2);
        //    if (segments.ContainsKey(bone))
        //    {
        //        PlayerUtils.BoneData data = segments[bone];
        //        data.UpdateSegment(seg);
        //        segments[bone] = data;
        //    }
        //    else
        //        segments.Add(bone, new PlayerUtils.BoneData(seg));
        //}
        //public void UpdateBonePosition(Microsoft.Research.Kinect.Nui.JointsCollection joints, JointID j1, JointID j2)
        //{
        //    var seg = new PlayerUtils.Segment(joints[j1].Position.X * playerScale + playerCenter.X,
        //                          playerCenter.Y - joints[j1].Position.Y * playerScale,
        //                          joints[j2].Position.X * playerScale + playerCenter.X,
        //                          playerCenter.Y - joints[j2].Position.Y * playerScale);
        //    seg.radius = Math.Max(3.0, playerBounds.Height * BONE_SIZE) / 2;
        //    UpdateSegmentPosition(j1, j2, seg);
        //}
        public void UpdateJointPosition(SkeletonData data)
        {
            this.skeleton = data;
            //var seg = new PlayerUtils.Segment(joints[j].Position.X * playerScale + playerCenter.X,
            //                      playerCenter.Y - joints[j].Position.Y * playerScale);

            //seg.radius = playerBounds.Height * ((j == JointID.Head) ? HEAD_SIZE : HAND_SIZE) / 2;
            //UpdateSegmentPosition(j, j, seg);
        }
Example #15
0
 public override bool IsComplete(SkeletonData skeleton)
 {
     if (DateTime.Now.Subtract(this.startGestureTime).TotalMilliseconds > HOLD_TIME)
     {
         hasGestureEscaped = false;
         return true;
     }
     return false;
 }
Example #16
0
 public override double GetTriggerScore(SkeletonData skeleton)
 {
     if (IsRightArmThrusting(skeleton) && hasGestureEscaped)
     {
         return 1.0;
     }
     hasGestureEscaped = true;
     return 0.0;
 }
        public override void processSkeletonFrame(SkeletonData skeleton, Dictionary<int, Target> targets)
        {
            //Scale the joints to the size of the window
            Joint leftHand = skeleton.Joints[JointID.HandLeft].ScaleTo(640, 480, window.k_xMaxJointScale, window.k_yMaxJointScale);
            Joint rightHand = skeleton.Joints[JointID.HandRight].ScaleTo(640, 480, window.k_xMaxJointScale, window.k_yMaxJointScale);

            trackHand(leftHand, 0, targets);
            trackHand(rightHand, 1, targets);
        }
Example #18
0
        public TorsoOrientation(SkeletonData bodyPartData)
        {
            this.rotation = TorsoOrientation.CalculateTorsoRotation(bodyPartData);
            this.inclination = TorsoOrientation.CalculateTorsoInclination(bodyPartData);
            this.inclination.Normalize();

            this.calibratedRotation = this.rotation;
            this.calibratedInclination = this.inclination;
        }
 public KinectPointerEventArgs(Vector3 righthand, Vector3 lefthand,Vector3 previousrighthand,Vector3 previouslefthand,SkeletonData data,int player)
 {
     this.RightHandPosition = righthand;
     this.LeftHandPosition = lefthand;
     this.PreviousLeftHandPosition = previouslefthand;
     this.PreviousRightHandPosition = previousrighthand;
     this.SkeletonData = data;
     this.PlayerID = player;
 }
Example #20
0
 public static Body FromSkeleton(SkeletonData skeleton)
 {
     return new Body
                {
                    Head = skeleton.Joints[JointID.Head].Position,
                    RightHand = skeleton.Joints[JointID.HandRight].Position,
                    LeftHand = skeleton.Joints[JointID.HandLeft].Position,
                };
 }
Example #21
0
        public override bool IsBodyPartInOrientation(SkeletonData bodyPartData)
        {
            Vector3D currentInclination = HeadOrientation.CalculateHeadInclination(bodyPartData);

            if (Vector3D.AngleBetween(currentInclination, this.calibratedInclination) > SharedContent.GetAllowableDeviationInDegrees())
            {
                return false;
            }
            return true;
        }
        public ReplaySkeletonData(SkeletonData data)
        {
            Position = data.Position;
            Quality = data.Quality;
            TrackingID = data.TrackingID;
            TrackingState = data.TrackingState;
            UserIndex = data.UserIndex;

            Joints = data.Joints.Cast<Joint>().ToList();
        }
        private int CheckAimConditions(SkeletonData latestSkeleton)
        {
            int gestureResult = (int)ResultCodes.Success;
             do
            {

                bool aim = false;
                bool isInsideAim = false;

                if (latestSkeleton == null)
                {
                    gestureResult = (int)ResultCodes.OutOfMemory;
                    break;
                }

                if (!this.aimDetected)
                {
                    aim = IsAimTrue(latestSkeleton);
                }

                if (aim && !this.aimDetected)
                {
                    MouseEventData mouseData = new MouseEventData();
                    mouseData.MouseAction = (int)MouseButton.RIGHT_MOUSE_BUTTON;
                    mouseData.XCoordinate = -1;
                    mouseData.YCoordinate = -1;
                    mouseData.KeyPersistance = (int)MousePresistance.PRESS_AND_RELEASE;

                    this.RaiseMouseEvent(mouseData);
                    this.aimDetected = true;

                    break;
                }

                isInsideAim = JackInManojsBox(latestSkeleton);

                if (!isInsideAim && this.aimDetected)
                {
                    MouseEventData mouseData = new MouseEventData();
                    mouseData.MouseAction = (int)MouseButton.RIGHT_MOUSE_BUTTON;
                    mouseData.XCoordinate = -1;
                    mouseData.YCoordinate = -1;
                    mouseData.KeyPersistance = (int)MousePresistance.PRESS_AND_RELEASE;

                    this.RaiseMouseEvent(mouseData);
                    this.aimDetected = false;

                    break;
                }

            } while (false);

            return gestureResult;
        }
Example #24
0
        public override bool IsOut(SkeletonData skeleton)
        {
            if (!Active) return false;
            Joint handRight = skeleton.Joints[JointID.HandRight];
            Joint elbowRight = skeleton.Joints[JointID.ElbowRight];
            Joint central = skeleton.Joints[JointID.Spine];

            Vector boundingBox = CreateVector(2.0f, 0.3f, 10.0f);
            Vector relativeToCentral = CreateVector(0f, 0.5f, 0.3f);

            return (!IsInBoundingBox(handRight.Position, central.Position, relativeToCentral, boundingBox));
        }
Example #25
0
        public LimbOrientation(SharedContent.BodyPartID limbID, SkeletonData bodyPartData)
        {
            this.limbID = limbID;
            this.upperLimbInclination = LimbOrientation.CalculateUpperLimbInclination(limbID, bodyPartData);
            this.upperLimbInclination.Normalize();
            this.lowerLimbInclination = LimbOrientation.CalculateLowerLimbInclination(limbID, bodyPartData);
            this.lowerLimbInclination.Normalize();
            this.bendInLimb = Vector3D.AngleBetween(this.upperLimbInclination, this.lowerLimbInclination);

            this.calibratedUpperLimbInclination = this.upperLimbInclination;
            this.calibratedLowerLimbInclination = this.lowerLimbInclination;
            this.calibratedBendInLimb = this.bendInLimb;
        }
public SkeletonDataAlternative(SkeletonData data)
{
    Joints = new List<Joint>();
            foreach (Joint j in data.Joints)
            {
                Joints.Add(JointPositionConverter(j));
            }
            Position = SkeletonDataPositionConverter(data.Position);
            Quality = data.Quality;
            TrackingID = data.TrackingID;
            TrackingState = data.TrackingState;
            UserIndex = data.UserIndex;
}
Example #27
0
 private void kinectSensor_SkeletonFrameReady(object sender, SkeletonFrameReadyEventArgs e)
 {
     foreach (SkeletonData s in e.SkeletonFrame.Skeletons)
     {
         if (s.TrackingState == SkeletonTrackingState.Tracked)
         {
             resolution = new Vector2(640, 480);
             skeleton = s;
             rightHandJoint = skeleton.Joints[JointID.HandRight];
             position = new Vector2((((0.5f * rightHandJoint.Position.X) + 0.5f) * (resolution.X)), (((-0.5f * rightHandJoint.Position.Y) + 0.5f) * (resolution.Y)));
         }
     }
 }
Example #28
0
        protected override void updateSkeleton(SkeletonData skeleton)
        {
            Vector3 elbowRight     = getLoc(skeleton.Joints[JointID.ElbowRight]),
                    handRight      = getLoc(skeleton.Joints[JointID.HandRight]),
                    shoulderRight  = getLoc(skeleton.Joints[JointID.ShoulderRight]),
                    shoulderLeft   = getLoc(skeleton.Joints[JointID.ShoulderLeft]),
                    shoulderCenter = getLoc(skeleton.Joints[JointID.ShoulderCenter]),
                    spine          = getLoc(skeleton.Joints[JointID.Spine]),
                    elbowLeft      = getLoc(skeleton.Joints[JointID.ElbowLeft]);

            lines.Clear();
            // ...
        }
        private SkeletonData CreateSkeletonData(string jsonFile, float scale, string jsonText)
        {
            JObject data = JObject.Parse(jsonText);
            var skeletonData = new SkeletonData(Path.GetFileNameWithoutExtension(jsonFile));

            ReadSkeletonBones(skeletonData, data, scale);
            ReadSkeletonSlots(skeletonData, data);
            ReadSkeletonSkins(skeletonData, data, scale);

            skeletonData.Bones.TrimExcess();
            skeletonData.Slots.TrimExcess();
            skeletonData.Skins.TrimExcess();
            return skeletonData;
        }
        private bool IsFistRolled(SkeletonData trackedSkeleton)
        {
            bool isRolled = false;

            this.logger.Debug("*****************************************************************");
            this.logger.Debug(trackedSkeleton.Joints[JointID.HandLeft].Position.X + "," + trackedSkeleton.Joints[JointID.HandLeft].Position.Y + "," + trackedSkeleton.Joints[JointID.HandLeft].Position.Z);
            this.logger.Debug(trackedSkeleton.Joints[JointID.WristLeft].Position.X + "," + trackedSkeleton.Joints[JointID.WristLeft].Position.Y + "," + trackedSkeleton.Joints[JointID.WristLeft].Position.Z);
            this.logger.Debug("*****************************************************************");

            string wristLeftData = (trackedSkeleton.Joints[JointID.WristLeft].Position.X + "," + trackedSkeleton.Joints[JointID.WristLeft].Position.Y + "," + trackedSkeleton.Joints[JointID.WristLeft].Position.Z);
            string handLeftData = (trackedSkeleton.Joints[JointID.HandLeft].Position.X + "," + trackedSkeleton.Joints[JointID.HandLeft].Position.Y + "," + trackedSkeleton.Joints[JointID.HandLeft].Position.Z);

            return isRolled;
        }
        protected override void PopulateMenu(GenericMenu menu, SerializedProperty property, SpineSkin targetAttribute, SkeletonData data)
        {
            menu.AddDisabledItem(new GUIContent(skeletonDataAsset.name));
            menu.AddSeparator("");

            for (int i = 0; i < data.Skins.Count; i++)
            {
                string name = data.Skins.Items[i].Name;
                if (name.StartsWith(targetAttribute.startsWith, StringComparison.Ordinal))
                {
                    bool   isDefault   = string.Equals(name, DefaultSkinName, StringComparison.Ordinal);
                    string choiceValue = TargetAttribute.defaultAsEmptyString && isDefault ? string.Empty : name;
                    menu.AddItem(new GUIContent(name), !property.hasMultipleDifferentValues && choiceValue == property.stringValue, HandleSelect, new SpineDrawerValuePair(choiceValue, property));
                }
            }
        }
Example #32
0
    public void Update(GameTime gameTime)
    {
        if (App.globalValues.SelectAnimeName != "" && App.globalValues.SetAnime)
        {
            state.ClearTracks();
            skeleton.SetToSetupPose();
            state.SetAnimation(0, App.globalValues.SelectAnimeName, App.globalValues.IsLoop);
            App.globalValues.SetAnime = false;
        }

        if (App.globalValues.SelectSkin != "" && App.globalValues.SetSkin)
        {
            skeleton.SetSkin(App.globalValues.SelectSkin);
            skeleton.SetSlotsToSetupPose();
            App.globalValues.SetSkin = false;
        }
        if (App.globalValues.SelectSpineVersion != "3.6.53" || App.globalValues.FileHash != skeleton.Data.Hash)
        {
            state            = null;
            skeletonRenderer = null;
            return;
        }
        App.graphicsDevice.Clear(Color.Transparent);

        Player.DrawBG(ref App.spriteBatch);
        App.globalValues.TimeScale = (float)((float)(App.globalValues.Speed) / 30f);

        state.Update((float)gameTime.ElapsedGameTime.TotalMilliseconds / 1000f);

        state.Apply(skeleton);
        if (binary != null)
        {
            if (App.globalValues.Scale != binary.Scale)
            {
                binary.Scale = App.globalValues.Scale;
                skeletonData = binary.ReadSkeletonData(App.globalValues.SelectSpineFile);
                skeleton     = new Skeleton(skeletonData);
            }
        }
        else if (json != null)
        {
            if (App.globalValues.Scale != json.Scale)
            {
                json.Scale   = App.globalValues.Scale;
                skeletonData = json.ReadSkeletonData(App.globalValues.SelectSpineFile);
                skeleton     = new Skeleton(skeletonData);
            }
        }

        skeleton.X     = App.globalValues.PosX;
        skeleton.Y     = App.globalValues.PosY;
        skeleton.FlipX = App.globalValues.FilpX;
        skeleton.FlipY = App.globalValues.FilpY;


        skeleton.RootBone.Rotation = App.globalValues.Rotation;
        skeleton.UpdateWorldTransform();
        skeletonRenderer.PremultipliedAlpha = App.globalValues.Alpha;
        if (skeletonRenderer.Effect is BasicEffect)
        {
            ((BasicEffect)skeletonRenderer.Effect).Projection = Matrix.CreateOrthographicOffCenter(0, App.graphicsDevice.Viewport.Width, App.graphicsDevice.Viewport.Height, 0, 1, 0);
        }
        else
        {
            skeletonRenderer.Effect.Parameters["Projection"].SetValue(Matrix.CreateOrthographicOffCenter(0, App.graphicsDevice.Viewport.Width, App.graphicsDevice.Viewport.Height, 0, 1, 0));
        }
        skeletonRenderer.Begin();
        skeletonRenderer.Draw(skeleton);
        skeletonRenderer.End();
    }
Example #33
0
        /// <summary>
        /// Initialize this component. Attempts to load the SkeletonData and creates the internal Skeleton object and buffers.</summary>
        /// <param name="overwrite">If set to <c>true</c>, it will overwrite internal objects if they were already generated. Otherwise, the initialized component will ignore subsequent calls to initialize.</param>
        public virtual void Initialize(bool overwrite)
        {
            if (valid && !overwrite)
            {
                return;
            }

            // Clear
            {
                // Note: do not reset meshFilter.sharedMesh or meshRenderer.sharedMaterial to null,
                // otherwise constant reloading will be triggered at prefabs.
                currentInstructions.Clear();
                rendererBuffers.Clear();
                meshGenerator.Begin();
                skeleton = null;
                valid    = false;
            }

            if (skeletonDataAsset == null)
            {
                return;
            }

            SkeletonData skeletonData = skeletonDataAsset.GetSkeletonData(false);

            if (skeletonData == null)
            {
                return;
            }
            valid = true;

            meshFilter   = GetComponent <MeshFilter>();
            meshRenderer = GetComponent <MeshRenderer>();
            rendererBuffers.Initialize();

            skeleton = new Skeleton(skeletonData)
            {
                ScaleX = initialFlipX ? -1 : 1,
                ScaleY = initialFlipY ? -1 : 1
            };

            if (!string.IsNullOrEmpty(initialSkinName) && !string.Equals(initialSkinName, "default", System.StringComparison.Ordinal))
            {
                skeleton.SetSkin(initialSkinName);
            }

            separatorSlots.Clear();
            for (int i = 0; i < separatorSlotNames.Length; i++)
            {
                separatorSlots.Add(skeleton.FindSlot(separatorSlotNames[i]));
            }

            LateUpdate();             // Generate mesh for the first frame it exists.

            if (OnRebuild != null)
            {
                OnRebuild(this);
            }

                        #if UNITY_EDITOR
            if (!Application.isPlaying)
            {
                string errorMessage = null;
                if (MaterialChecks.IsMaterialSetupProblematic(this, ref errorMessage))
                {
                    Debug.LogWarningFormat(this, "Problematic material setup at {0}: {1}", this.name, errorMessage);
                }
            }
                        #endif
        }
        /// <summary>
        /// Initialize this component. Attempts to load the SkeletonData and creates the internal Skeleton object and buffers.</summary>
        /// <param name="overwrite">If set to <c>true</c>, it will overwrite internal objects if they were already generated. Otherwise, the initialized component will ignore subsequent calls to initialize.</param>
        public virtual void Initialize(bool overwrite)
        {
            if (valid && !overwrite)
            {
                return;
            }

            // Clear
            {
                if (meshFilter != null)
                {
                    meshFilter.sharedMesh = null;
                }

                meshRenderer = GetComponent <MeshRenderer>();
                if (meshRenderer != null)
                {
                    meshRenderer.sharedMaterial = null;
                }

                currentInstructions.Clear();
                rendererBuffers.Clear();
                meshGenerator.Begin();
                skeleton = null;
                valid    = false;
            }

            if (skeletonDataAsset == null)
            {
                return;
            }

            SkeletonData skeletonData = skeletonDataAsset.GetSkeletonData(false);

            if (skeletonData == null)
            {
                return;
            }
            valid = true;

            meshFilter   = GetComponent <MeshFilter>();
            meshRenderer = GetComponent <MeshRenderer>();
            rendererBuffers.Initialize();

            skeleton = new Skeleton(skeletonData)
            {
                scaleX = initialFlipX ? -1 : 1,
                scaleY = initialFlipY ? -1 : 1
            };

            if (!string.IsNullOrEmpty(initialSkinName) && !string.Equals(initialSkinName, "default", System.StringComparison.Ordinal))
            {
                skeleton.SetSkin(initialSkinName);
            }

            separatorSlots.Clear();
            for (int i = 0; i < separatorSlotNames.Length; i++)
            {
                separatorSlots.Add(skeleton.FindSlot(separatorSlotNames[i]));
            }

            LateUpdate();             // Generate mesh for the first frame it exists.

            if (OnRebuild != null)
            {
                OnRebuild(this);
            }
        }
Example #35
0
 internal void InitializeWithData(SkeletonData sd)
 {
     this.skeletonData = sd;
     this.stateData    = new AnimationStateData(skeletonData);
     FillStateData();
 }
Example #36
0
        protected override void PopulateMenu(GenericMenu menu, SerializedProperty property, SpineAttachment targetAttribute, SkeletonData data)
        {
            ISkeletonComponent skeletonComponent = GetTargetSkeletonComponent(property);
            var validSkins = new List <Skin>();

            if (skeletonComponent != null && targetAttribute.currentSkinOnly)
            {
                var currentSkin = skeletonComponent.Skeleton.Skin;
                if (currentSkin != null)
                {
                    validSkins.Add(currentSkin);
                }
                else
                {
                    validSkins.Add(data.Skins.Items[0]);
                }
            }
            else
            {
                foreach (Skin skin in data.Skins)
                {
                    if (skin != null)
                    {
                        validSkins.Add(skin);
                    }
                }
            }

            var    attachmentNames  = new List <string>();
            var    placeholderNames = new List <string>();
            string prefix           = "";

            if (skeletonComponent != null && targetAttribute.currentSkinOnly)
            {
                menu.AddDisabledItem(new GUIContent((skeletonComponent as Component).gameObject.name + " (Skeleton)"));
            }
            else
            {
                menu.AddDisabledItem(new GUIContent(skeletonDataAsset.name));
            }

            menu.AddSeparator("");
            menu.AddItem(new GUIContent("Null"), property.stringValue == "", HandleSelect, new SpineDrawerValuePair("", property));
            menu.AddSeparator("");

            Skin defaultSkin = data.Skins.Items[0];

            SerializedProperty slotProperty = property.serializedObject.FindProperty(targetAttribute.slotField);
            string             slotMatch    = "";

            if (slotProperty != null)
            {
                if (slotProperty.propertyType == SerializedPropertyType.String)
                {
                    slotMatch = slotProperty.stringValue.ToLower();
                }
            }

            foreach (Skin skin in validSkins)
            {
                string skinPrefix = skin.Name + "/";

                if (validSkins.Count > 1)
                {
                    prefix = skinPrefix;
                }

                for (int i = 0; i < data.Slots.Count; i++)
                {
                    if (slotMatch.Length > 0 && !(data.Slots.Items[i].Name.ToLower().Contains(slotMatch)))
                    {
                        continue;
                    }

                    attachmentNames.Clear();
                    placeholderNames.Clear();

                    skin.FindNamesForSlot(i, attachmentNames);
                    if (skin != defaultSkin)
                    {
                        defaultSkin.FindNamesForSlot(i, attachmentNames);
                        skin.FindNamesForSlot(i, placeholderNames);
                    }

                    for (int a = 0; a < attachmentNames.Count; a++)
                    {
                        string attachmentPath = attachmentNames[a];
                        string menuPath       = prefix + data.Slots.Items[i].Name + "/" + attachmentPath;
                        string name           = attachmentNames[a];

                        if (targetAttribute.returnAttachmentPath)
                        {
                            name = skin.Name + "/" + data.Slots.Items[i].Name + "/" + attachmentPath;
                        }

                        if (targetAttribute.placeholdersOnly && !placeholderNames.Contains(attachmentPath))
                        {
                            menu.AddDisabledItem(new GUIContent(menuPath));
                        }
                        else
                        {
                            menu.AddItem(new GUIContent(menuPath), name == property.stringValue, HandleSelect, new SpineDrawerValuePair(name, property));
                        }
                    }
                }
            }
        }
Example #37
0
        protected override void PopulateMenu(GenericMenu menu, SerializedProperty property, SpineBone targetAttribute, SkeletonData data)
        {
            menu.AddDisabledItem(new GUIContent(skeletonDataAsset.name));
            menu.AddSeparator("");

            for (int i = 0; i < data.Bones.Count; i++)
            {
                string name = data.Bones.Items[i].Name;
                if (name.StartsWith(targetAttribute.startsWith, StringComparison.Ordinal))
                {
                    menu.AddItem(new GUIContent(name), name == property.stringValue, HandleSelect, new SpineDrawerValuePair(name, property));
                }
            }
        }
        private void LoadContent(ContentManager contentManager)
        {
            skeletonRenderer = new SkeletonMeshRenderer(_graphicsDevice);
            skeletonRenderer.PremultipliedAlpha = App.GV.Alpha;

            atlas = new Atlas(App.GV.SelectFile, new XnaTextureLoader(_graphicsDevice));


            json         = new SkeletonJson(atlas);
            json.Scale   = App.GV.Scale;
            skeletonData = json.ReadSkeletonData(Common.GetJsonPath(App.GV.SelectFile));


            skeleton = new Skeleton(skeletonData);

            if (isNew)
            {
                App.GV.PosX = skeleton.Data.Width;
                App.GV.PosY = skeleton.Data.Height;
            }
            App.GV.FileHash = skeleton.Data.Hash;

            stateData = new AnimationStateData(skeleton.Data);

            state = new AnimationState(stateData);

            if (isRecoding)
            {
                state.Start    += State_Start;
                state.Complete += State_Complete;
            }


            List <string> AnimationNames = new List <string>();

            LA = state.Data.skeletonData.Animations;
            foreach (Animation An in LA)
            {
                AnimationNames.Add(An.name);
            }
            App.GV.AnimeList = AnimationNames;

            List <string> SkinNames = new List <string>();

            LS = state.Data.skeletonData.Skins;
            foreach (Skin Sk in LS)
            {
                SkinNames.Add(Sk.name);
            }
            App.GV.SkinList = SkinNames;

            if (App.GV.SelectAnimeName != "")
            {
                state.SetAnimation(0, App.GV.SelectAnimeName, App.GV.IsLoop);
            }
            else
            {
                state.SetAnimation(0, state.Data.skeletonData.animations[0].name, App.GV.IsLoop);
            }

            if (isNew)
            {
                MainWindow.SetCBAnimeName();
            }
            isNew = false;
        }
Example #39
0
    override public void OnInspectorGUI()
    {
        serializedObject.Update();
        SkeletonDataAsset asset = (SkeletonDataAsset)target;

        EditorGUI.BeginChangeCheck();
        EditorGUILayout.PropertyField(atlasAsset);
        EditorGUILayout.PropertyField(skeletonJSON);
        EditorGUILayout.PropertyField(scale);
        if (EditorGUI.EndChangeCheck())
        {
            if (m_previewUtility != null)
            {
                m_previewUtility.Cleanup();
                m_previewUtility = null;
            }
        }

        SkeletonData skeletonData = asset.GetSkeletonData(asset.atlasAsset == null || asset.skeletonJSON == null);

        if (skeletonData != null)
        {
            showAnimationStateData = EditorGUILayout.Foldout(showAnimationStateData, "Animation State Data");
            if (showAnimationStateData)
            {
                EditorGUILayout.PropertyField(defaultMix);

                // Animation names
                String[] animations = new String[skeletonData.Animations.Count];
                for (int i = 0; i < animations.Length; i++)
                {
                    animations[i] = skeletonData.Animations[i].Name;
                }

                for (int i = 0; i < fromAnimation.arraySize; i++)
                {
                    SerializedProperty from         = fromAnimation.GetArrayElementAtIndex(i);
                    SerializedProperty to           = toAnimation.GetArrayElementAtIndex(i);
                    SerializedProperty durationProp = duration.GetArrayElementAtIndex(i);
                    EditorGUILayout.BeginHorizontal();
                    from.stringValue        = animations[EditorGUILayout.Popup(Math.Max(Array.IndexOf(animations, from.stringValue), 0), animations)];
                    to.stringValue          = animations[EditorGUILayout.Popup(Math.Max(Array.IndexOf(animations, to.stringValue), 0), animations)];
                    durationProp.floatValue = EditorGUILayout.FloatField(durationProp.floatValue);
                    if (GUILayout.Button("Delete"))
                    {
                        duration.DeleteArrayElementAtIndex(i);
                        toAnimation.DeleteArrayElementAtIndex(i);
                        fromAnimation.DeleteArrayElementAtIndex(i);
                    }
                    EditorGUILayout.EndHorizontal();
                }
                EditorGUILayout.BeginHorizontal();
                EditorGUILayout.Space();
                if (GUILayout.Button("Add Mix"))
                {
                    duration.arraySize++;
                    toAnimation.arraySize++;
                    fromAnimation.arraySize++;
                }
                EditorGUILayout.Space();
                EditorGUILayout.EndHorizontal();
            }

            if (GUILayout.Button(new GUIContent("Setup Pose", SpineEditorUtilities.Icons.skeleton), GUILayout.Width(105), GUILayout.Height(18)))
            {
                StopAnimation();
                m_skeletonAnimation.skeleton.SetToSetupPose();
                m_requireRefresh = true;
            }

                        #if UNITY_4_3
            m_showAnimationList = EditorGUILayout.Foldout(m_showAnimationList, new GUIContent("Animations", SpineEditorUtilities.Icons.animationRoot));
            if (m_showAnimationList)
            {
                        #else
            m_showAnimationList.target = EditorGUILayout.Foldout(m_showAnimationList.target, new GUIContent("Animations", SpineEditorUtilities.Icons.animationRoot));
            if (EditorGUILayout.BeginFadeGroup(m_showAnimationList.faded))
            {
                                #endif



                EditorGUILayout.LabelField("Name", "Duration");
                foreach (Spine.Animation a in skeletonData.Animations)
                {
                    GUILayout.BeginHorizontal();

                    if (m_skeletonAnimation != null && m_skeletonAnimation.state != null)
                    {
                        if (m_skeletonAnimation.state.GetCurrent(0) != null && m_skeletonAnimation.state.GetCurrent(0).Animation == a)
                        {
                            GUI.contentColor = Color.black;
                            if (GUILayout.Button("\u25BA", GUILayout.Width(24)))
                            {
                                StopAnimation();
                            }
                            GUI.contentColor = Color.white;
                        }
                        else
                        {
                            if (GUILayout.Button("\u25BA", GUILayout.Width(24)))
                            {
                                PlayAnimation(a.Name, true);
                            }
                        }
                    }
                    else
                    {
                        GUILayout.Label("?", GUILayout.Width(24));
                    }
                    EditorGUILayout.LabelField(new GUIContent(a.Name, SpineEditorUtilities.Icons.animation), new GUIContent(a.Duration.ToString("f3") + "s" + ("(" + (Mathf.RoundToInt(a.Duration * 30)) + ")").PadLeft(12, ' ')));
                    GUILayout.EndHorizontal();
                }
            }
                        #if !UNITY_4_3
            EditorGUILayout.EndFadeGroup();
                        #endif
        }

        if (!Application.isPlaying)
        {
            if (serializedObject.ApplyModifiedProperties() ||
                (UnityEngine.Event.current.type == EventType.ValidateCommand && UnityEngine.Event.current.commandName == "UndoRedoPerformed")
                )
            {
                asset.Reset();
            }
        }
    }
 public static RegionAttachment AddUnitySprite(this SkeletonData skeletonData, string slotName, Sprite sprite, string skinName = "", string shaderName = SpriteAttacher.DefaultPMAShader, bool applyPMA = true)
 {
     return(skeletonData.AddUnitySprite(slotName, sprite, skinName, Shader.Find(shaderName), applyPMA));
 }
Example #41
0
 // Event handler for the SkeletonUpdate event
 private void onSkeletonUpdate(SkeletonData skeletonData)
 {
     _skeletonData = skeletonData;
 }
Example #42
0
    public virtual void Reset()
    {
        if (meshFilter != null)
        {
            meshFilter.sharedMesh = null;
        }
        if (renderer != null)
        {
            renderer.sharedMaterial = null;
        }
        mesh1           = null;
        mesh2           = null;
        lastVertexCount = 0;
        vertices        = null;
        colors          = null;
        uvs             = null;
        sharedMaterials = new Material[0];
        submeshMaterials.Clear();
        submeshes.Clear();
        skeleton = null;

        valid = false;
        if (!skeletonDataAsset)
        {
            if (logErrors)
            {
                Debug.LogError("Missing SkeletonData asset.", this);
            }

            return;
        }
        SkeletonData skeletonData = skeletonDataAsset.GetSkeletonData(false);

        if (skeletonData == null)
        {
            return;
        }
        valid = true;

        meshFilter = GetComponent <MeshFilter>();
        mesh1      = newMesh();
        mesh2      = newMesh();
        vertices   = new Vector3[0];

        skeleton = new Skeleton(skeletonData);
        if (initialSkinName != null && initialSkinName.Length > 0 && initialSkinName != "default")
        {
            skeleton.SetSkin(initialSkinName);
        }

        submeshSeparatorSlots.Clear();
        for (int i = 0; i < submeshSeparators.Length; i++)
        {
            submeshSeparatorSlots.Add(skeleton.FindSlot(submeshSeparators[i]));
        }

        if (OnReset != null)
        {
            OnReset(this);
        }
    }
Example #43
0
        protected override void PopulateMenu(GenericMenu menu, SerializedProperty property, SpineEvent targetAttribute, SkeletonData data)
        {
            var events = skeletonDataAsset.GetSkeletonData(false).Events;

            // <None> item
            menu.AddItem(new GUIContent(NoneLabel), string.IsNullOrEmpty(property.stringValue), HandleSelect, new SpineDrawerValuePair("", property));

            for (int i = 0; i < events.Count; i++)
            {
                string name = events.Items[i].Name;
                if (name.StartsWith(targetAttribute.startsWith, StringComparison.Ordinal))
                {
                    menu.AddItem(new GUIContent(name), name == property.stringValue, HandleSelect, new SpineDrawerValuePair(name, property));
                }
            }
        }
Example #44
0
        protected override void PopulateMenu(GenericMenu menu, SerializedProperty property, SpineSlot targetAttribute, SkeletonData data)
        {
            for (int i = 0; i < data.Slots.Count; i++)
            {
                string name = data.Slots.Items[i].Name;
                if (name.StartsWith(targetAttribute.startsWith, StringComparison.Ordinal))
                {
                    if (targetAttribute.containsBoundingBoxes)
                    {
                        int slotIndex   = i;
                        var attachments = new List <Attachment>();
                        foreach (var skin in data.Skins)
                        {
                            skin.FindAttachmentsForSlot(slotIndex, attachments);
                        }

                        bool hasBoundingBox = false;
                        foreach (var attachment in attachments)
                        {
                            if (attachment is BoundingBoxAttachment)
                            {
                                menu.AddItem(new GUIContent(name), name == property.stringValue, HandleSelect, new SpineDrawerValuePair(name, property));
                                hasBoundingBox = true;
                                break;
                            }
                        }

                        if (!hasBoundingBox)
                        {
                            menu.AddDisabledItem(new GUIContent(name));
                        }
                    }
                    else
                    {
                        menu.AddItem(new GUIContent(name), name == property.stringValue, HandleSelect, new SpineDrawerValuePair(name, property));
                    }
                }
            }
        }
Example #45
0
 public TakeDamageState(FinitStateMachine stateMachine, SkeletonData data, IState next) : base(stateMachine)
 {
     _locomotionController = data.LocomotionController;
     _animator             = data.Animator;
     _next = next;
 }
Example #46
0
 protected abstract void PopulateMenu(GenericMenu menu, SerializedProperty property, T targetAttribute, SkeletonData data);
Example #47
0
 public static Attachment AddUnitySprite(this SkeletonData skeletonData, string slotName, Sprite sprite, string skinName = "", string shaderName = "Spine/Skeleton", bool applyPMA = true)
 {
     return(skeletonData.AddUnitySprite(slotName, sprite, skinName, Shader.Find(shaderName), applyPMA));
 }
 void Clear()
 {
     preview.Clear();
     targetSkeletonDataAsset.Clear();
     targetSkeletonData = null;
 }
 public override void Apply(SkeletonData skeletonData)
 {
     ApplyMaterials(skeletonData, multiplyMaterialTemplate, screenMaterialTemplate, additiveMaterialTemplate, applyAdditiveMaterial);
 }
Example #50
0
    override public void OnInspectorGUI()
    {
        serializedObject.Update();
        SkeletonDataAsset asset = (SkeletonDataAsset)target;

        EditorGUILayout.PropertyField(atlasAsset);
        EditorGUILayout.PropertyField(skeletonJSON);
        EditorGUILayout.PropertyField(scale);

        SkeletonData skeletonData = asset.GetSkeletonData(asset.atlasAsset == null || asset.skeletonJSON == null);

        if (skeletonData != null)
        {
            showAnimationStateData = EditorGUILayout.Foldout(showAnimationStateData, "Animation State Data");
            if (showAnimationStateData)
            {
                // Animation names.
                String[] animations = new String[skeletonData.Animations.Count];
                for (int i = 0; i < animations.Length; i++)
                {
                    animations[i] = skeletonData.Animations[i].Name;
                }

                for (int i = 0; i < fromAnimation.arraySize; i++)
                {
                    SerializedProperty from         = fromAnimation.GetArrayElementAtIndex(i);
                    SerializedProperty to           = toAnimation.GetArrayElementAtIndex(i);
                    SerializedProperty durationProp = duration.GetArrayElementAtIndex(i);
                    EditorGUILayout.BeginHorizontal();
                    from.stringValue        = animations[EditorGUILayout.Popup(Math.Max(Array.IndexOf(animations, from.stringValue), 0), animations)];
                    to.stringValue          = animations[EditorGUILayout.Popup(Math.Max(Array.IndexOf(animations, to.stringValue), 0), animations)];
                    durationProp.floatValue = EditorGUILayout.FloatField(durationProp.floatValue);
                    if (GUILayout.Button("Delete"))
                    {
                        duration.DeleteArrayElementAtIndex(i);
                        toAnimation.DeleteArrayElementAtIndex(i);
                        fromAnimation.DeleteArrayElementAtIndex(i);
                    }
                    EditorGUILayout.EndHorizontal();
                }
                EditorGUILayout.BeginHorizontal();
                EditorGUILayout.Space();
                if (GUILayout.Button("Add Mix"))
                {
                    duration.arraySize++;
                    toAnimation.arraySize++;
                    fromAnimation.arraySize++;
                }
                EditorGUILayout.Space();
                EditorGUILayout.EndHorizontal();
            }
        }

        if (!Application.isPlaying)
        {
            if (serializedObject.ApplyModifiedProperties() ||
                (UnityEngine.Event.current.type == EventType.ValidateCommand && UnityEngine.Event.current.commandName == "UndoRedoPerformed")
                )
            {
                asset.Clear();
            }
        }
    }
 public abstract void Apply(SkeletonData skeletonData);
        protected override void PopulateMenu(GenericMenu menu, SerializedProperty property, SpineAttachment targetAttribute, SkeletonData data)
        {
            ISkeletonComponent skeletonComponent = GetTargetSkeletonComponent(property);
            var validSkins = new List <Skin>();

            if (skeletonComponent != null && targetAttribute.currentSkinOnly)
            {
                Skin currentSkin = null;

                var skinProperty = property.FindBaseOrSiblingProperty(targetAttribute.skinField);
                if (skinProperty != null)
                {
                    currentSkin = skeletonComponent.Skeleton.Data.FindSkin(skinProperty.stringValue);
                }

                currentSkin = currentSkin ?? skeletonComponent.Skeleton.Skin;
                if (currentSkin != null)
                {
                    validSkins.Add(currentSkin);
                }
                else
                {
                    validSkins.Add(data.Skins.Items[0]);
                }
            }
            else
            {
                foreach (Skin skin in data.Skins)
                {
                    if (skin != null)
                    {
                        validSkins.Add(skin);
                    }
                }
            }

            var    attachmentNames  = new List <string>();
            var    placeholderNames = new List <string>();
            string prefix           = "";

            if (skeletonComponent != null && targetAttribute.currentSkinOnly)
            {
                menu.AddDisabledItem(new GUIContent((skeletonComponent as Component).gameObject.name + " (Skeleton)"));
            }
            else
            {
                menu.AddDisabledItem(new GUIContent(skeletonDataAsset.name));
            }

            menu.AddSeparator("");
            if (TargetAttribute.includeNone)
            {
                const string NullAttachmentName = "";
                menu.AddItem(new GUIContent("Null"), !property.hasMultipleDifferentValues && property.stringValue == NullAttachmentName, HandleSelect, new SpineDrawerValuePair(NullAttachmentName, property));
                menu.AddSeparator("");
            }

            Skin defaultSkin  = data.Skins.Items[0];
            var  slotProperty = property.FindBaseOrSiblingProperty(TargetAttribute.slotField);

            string slotMatch = "";

            if (slotProperty != null)
            {
                if (slotProperty.propertyType == SerializedPropertyType.String)
                {
                    slotMatch = slotProperty.stringValue.ToLower();
                }
            }

            foreach (Skin skin in validSkins)
            {
                string skinPrefix = skin.Name + "/";

                if (validSkins.Count > 1)
                {
                    prefix = skinPrefix;
                }

                for (int i = 0; i < data.Slots.Count; i++)
                {
                    if (slotMatch.Length > 0 && !(data.Slots.Items[i].Name.Equals(slotMatch, StringComparison.OrdinalIgnoreCase)))
                    {
                        continue;
                    }

                    attachmentNames.Clear();
                    placeholderNames.Clear();

                    var skinEntries = new List <Skin.SkinEntry>();
                    skin.GetAttachments(i, skinEntries);
                    foreach (var entry in skinEntries)
                    {
                        attachmentNames.Add(entry.Name);
                    }

                    if (skin != defaultSkin)
                    {
                        foreach (var entry in skinEntries)
                        {
                            placeholderNames.Add(entry.Name);
                        }
                        skinEntries.Clear();
                        defaultSkin.GetAttachments(i, skinEntries);
                        foreach (var entry in skinEntries)
                        {
                            attachmentNames.Add(entry.Name);
                        }
                    }

                    for (int a = 0; a < attachmentNames.Count; a++)
                    {
                        string attachmentPath = attachmentNames[a];
                        string menuPath       = prefix + data.Slots.Items[i].Name + "/" + attachmentPath;
                        string name           = attachmentNames[a];

                        if (targetAttribute.returnAttachmentPath)
                        {
                            name = skin.Name + "/" + data.Slots.Items[i].Name + "/" + attachmentPath;
                        }

                        if (targetAttribute.placeholdersOnly && !placeholderNames.Contains(attachmentPath))
                        {
                            menu.AddDisabledItem(new GUIContent(menuPath));
                        }
                        else
                        {
                            menu.AddItem(new GUIContent(menuPath), !property.hasMultipleDifferentValues && name == property.stringValue, HandleSelect, new SpineDrawerValuePair(name, property));
                        }
                    }
                }
            }
        }
    public virtual void Update()
    {
        SkeletonData skeletonData = skeletonDataAsset.GetSkeletonData(false);

        // Clear fields if missing information to render.
        if (skeletonDataAsset == null || skeletonData == null)
        {
            Clear();
            return;
        }

        // Initialize fields.
        if (skeleton == null || skeleton.Data != skeletonData)
        {
            Initialize();
        }

        UpdateSkeleton();

        // Count quads and submeshes.
        int      quadCount = 0, submeshQuadCount = 0;
        Material lastMaterial = null;

        submeshMaterials.Clear();
        List <Slot> drawOrder = skeleton.DrawOrder;

        for (int i = 0, n = drawOrder.Count; i < n; i++)
        {
            RegionAttachment regionAttachment = drawOrder[i].Attachment as RegionAttachment;
            if (regionAttachment == null)
            {
                continue;
            }

            // Add submesh when material changes.
            Material material = (Material)regionAttachment.RendererObject;
            if (lastMaterial != material && lastMaterial != null)
            {
                addSubmesh(lastMaterial, quadCount, submeshQuadCount, false);
                submeshQuadCount = 0;
            }
            lastMaterial = material;

            quadCount++;
            submeshQuadCount++;
        }
        addSubmesh(lastMaterial, quadCount, submeshQuadCount, true);

        // Set materials.
        if (submeshMaterials.Count == sharedMaterials.Length)
        {
            submeshMaterials.CopyTo(sharedMaterials);
        }
        else
        {
            sharedMaterials = submeshMaterials.ToArray();
        }
        renderer.sharedMaterials = sharedMaterials;

        // Ensure mesh data is the right size.
        Mesh mesh = this.mesh;

        Vector3[] vertices     = this.vertices;
        int       vertexCount  = quadCount * 4;
        bool      newTriangles = vertexCount > vertices.Length;

        if (newTriangles)
        {
            // Not enough vertices, increase size.
            this.vertices = vertices = new Vector3[vertexCount];
            this.colors   = new Color32[vertexCount];
            this.uvs      = new Vector2[vertexCount];
            mesh.Clear();
        }
        else
        {
            // Too many vertices, zero the extra.
            Vector3 zero = new Vector3(0, 0, 0);
            for (int i = vertexCount, n = lastVertexCount; i < n; i++)
            {
                vertices[i] = zero;
            }
        }
        lastVertexCount = vertexCount;

        // Setup mesh.
        float[]   vertexPositions = this.vertexPositions;
        Vector2[] uvs             = this.uvs;
        Color32[] colors          = this.colors;
        int       vertexIndex     = 0;
        Color32   color           = new Color32();

        for (int i = 0, n = drawOrder.Count; i < n; i++)
        {
            Slot             slot             = drawOrder[i];
            RegionAttachment regionAttachment = slot.Attachment as RegionAttachment;
            if (regionAttachment == null)
            {
                continue;
            }

            regionAttachment.ComputeVertices(skeleton.X, skeleton.Y, slot.Bone, vertexPositions);

            vertices[vertexIndex]     = new Vector3(vertexPositions[RegionAttachment.X1], vertexPositions[RegionAttachment.Y1], 0);
            vertices[vertexIndex + 1] = new Vector3(vertexPositions[RegionAttachment.X4], vertexPositions[RegionAttachment.Y4], 0);
            vertices[vertexIndex + 2] = new Vector3(vertexPositions[RegionAttachment.X2], vertexPositions[RegionAttachment.Y2], 0);
            vertices[vertexIndex + 3] = new Vector3(vertexPositions[RegionAttachment.X3], vertexPositions[RegionAttachment.Y3], 0);

            color.a                 = (byte)(skeleton.A * slot.A * 255);
            color.r                 = (byte)(skeleton.R * slot.R * color.a);
            color.g                 = (byte)(skeleton.G * slot.G * color.a);
            color.b                 = (byte)(skeleton.B * slot.B * color.a);
            colors[vertexIndex]     = color;
            colors[vertexIndex + 1] = color;
            colors[vertexIndex + 2] = color;
            colors[vertexIndex + 3] = color;

            float[] regionUVs = regionAttachment.UVs;
            uvs[vertexIndex]     = new Vector2(regionUVs[RegionAttachment.X1], regionUVs[RegionAttachment.Y1]);
            uvs[vertexIndex + 1] = new Vector2(regionUVs[RegionAttachment.X4], regionUVs[RegionAttachment.Y4]);
            uvs[vertexIndex + 2] = new Vector2(regionUVs[RegionAttachment.X2], regionUVs[RegionAttachment.Y2]);
            uvs[vertexIndex + 3] = new Vector2(regionUVs[RegionAttachment.X3], regionUVs[RegionAttachment.Y3]);

            vertexIndex += 4;
        }
        mesh.vertices = vertices;
        mesh.colors32 = colors;
        mesh.uv       = uvs;

        mesh.subMeshCount = submeshMaterials.Count;
        for (int i = 0; i < mesh.subMeshCount; ++i)
        {
            mesh.SetTriangles(submeshIndexes[i], i);
        }

        if (calculateNormals)
        {
            mesh.RecalculateNormals();
            if (calculateTangents)
            {
                Vector4[] tangents = this.tangents;
                int       count    = mesh.normals.Length;
                if (tangents.Length != count)
                {
                    this.tangents = tangents = new Vector4[count];
                }
                for (int i = 0; i < count; i++)
                {
                    tangents[i] = new Vector4(1, 0, 0, 1);
                }
                mesh.tangents = tangents;
            }
        }
    }
Example #54
0
    public void LoadContent(ContentManager contentManager)
    {
        skeletonRenderer = new SkeletonRenderer(App.graphicsDevice);
        skeletonRenderer.PremultipliedAlpha = App.globalValues.Alpha;

        atlas = new Atlas(App.globalValues.SelectAtlasFile, new XnaTextureLoader(App.graphicsDevice));

        if (Common.IsBinaryData(App.globalValues.SelectSpineFile))
        {
            binary       = new SkeletonBinary(atlas);
            binary.Scale = App.globalValues.Scale;
            skeletonData = binary.ReadSkeletonData(App.globalValues.SelectSpineFile);
        }
        else
        {
            json         = new SkeletonJson(atlas);
            json.Scale   = App.globalValues.Scale;
            skeletonData = json.ReadSkeletonData(App.globalValues.SelectSpineFile);
        }
        App.globalValues.SpineVersion = skeletonData.Version;
        skeleton = new Skeleton(skeletonData);

        Common.SetInitLocation(skeleton.Data.Height);
        App.globalValues.FileHash = skeleton.Data.Hash;

        stateData = new AnimationStateData(skeleton.Data);

        state = new AnimationState(stateData);

        List <string> AnimationNames = new List <string>();

        listAnimation = state.Data.skeletonData.Animations;
        foreach (Animation An in listAnimation)
        {
            AnimationNames.Add(An.name);
        }
        App.globalValues.AnimeList = AnimationNames;

        List <string> SkinNames = new List <string>();

        listSkin = state.Data.skeletonData.Skins;
        foreach (Skin Sk in listSkin)
        {
            SkinNames.Add(Sk.name);
        }
        App.globalValues.SkinList = SkinNames;

        if (App.globalValues.SelectAnimeName != "")
        {
            state.SetAnimation(0, App.globalValues.SelectAnimeName, App.globalValues.IsLoop);
        }
        else
        {
            state.SetAnimation(0, state.Data.skeletonData.animations.Items[0].name, App.globalValues.IsLoop);
        }

        if (App.isNew)
        {
            MainWindow.SetCBAnimeName();
        }
        App.isNew = false;
    }
        protected override void PopulateMenu(GenericMenu menu, SerializedProperty property, SpineBone targetAttribute, SkeletonData data)
        {
            menu.AddDisabledItem(new GUIContent(skeletonDataAsset.name));
            menu.AddSeparator("");

            if (TargetAttribute.includeNone)
            {
                menu.AddItem(new GUIContent(NoneString), !property.hasMultipleDifferentValues && string.IsNullOrEmpty(property.stringValue), HandleSelect, new SpineDrawerValuePair(string.Empty, property));
            }

            for (int i = 0; i < data.Bones.Count; i++)
            {
                string name = data.Bones.Items[i].Name;
                if (name.StartsWith(targetAttribute.startsWith, StringComparison.Ordinal))
                {
                    menu.AddItem(new GUIContent(name), !property.hasMultipleDifferentValues && name == property.stringValue, HandleSelect, new SpineDrawerValuePair(name, property));
                }
            }
        }
Example #56
0
 public void Clear()
 {
     skeletonData = null;
     stateData    = null;
 }
        protected override void PopulateMenu(GenericMenu menu, SerializedProperty property, SpineTransformConstraint targetAttribute, SkeletonData data)
        {
            var constraints = skeletonDataAsset.GetSkeletonData(false).TransformConstraints;

            if (TargetAttribute.includeNone)
            {
                menu.AddItem(new GUIContent(NoneString), !property.hasMultipleDifferentValues && string.IsNullOrEmpty(property.stringValue), HandleSelect, new SpineDrawerValuePair(string.Empty, property));
            }

            for (int i = 0; i < constraints.Count; i++)
            {
                string name = constraints.Items[i].Name;
                if (name.StartsWith(targetAttribute.startsWith, StringComparison.Ordinal))
                {
                    menu.AddItem(new GUIContent(name), !property.hasMultipleDifferentValues && name == property.stringValue, HandleSelect, new SpineDrawerValuePair(name, property));
                }
            }
        }
Example #58
0
        public virtual void Initialize(bool overwrite)
        {
            if (valid && !overwrite)
            {
                return;
            }

            // Clear
            {
                if (meshFilter != null)
                {
                    meshFilter.sharedMesh = null;
                }

                meshRenderer = GetComponent <MeshRenderer>();
                if (meshRenderer != null)
                {
                    meshRenderer.sharedMaterial = null;
                }

                currentInstructions.Clear();
                vertices        = null;
                colors          = null;
                uvs             = null;
                sharedMaterials = new Material[0];
                submeshMaterials.Clear();
                submeshes.Clear();
                skeleton = null;

                valid = false;
            }

            if (!skeletonDataAsset)
            {
                if (logErrors)
                {
                    Debug.LogError("Missing SkeletonData asset.", this);
                }

                return;
            }
            SkeletonData skeletonData = skeletonDataAsset.GetSkeletonData(false);

            if (skeletonData == null)
            {
                return;
            }
            valid = true;

            meshFilter         = GetComponent <MeshFilter>();
            meshRenderer       = GetComponent <MeshRenderer>();
            doubleBufferedMesh = new DoubleBuffered <SmartMesh>();
            vertices           = new Vector3[0];

            skeleton = new Skeleton(skeletonData);
            if (!string.IsNullOrEmpty(initialSkinName) && initialSkinName != "default")
            {
                skeleton.SetSkin(initialSkinName);
            }

            separatorSlots.Clear();
            for (int i = 0; i < separatorSlotNames.Length; i++)
            {
                separatorSlots.Add(skeleton.FindSlot(separatorSlotNames[i]));
            }

            LateUpdate();

            if (OnRebuild != null)
            {
                OnRebuild(this);
            }
        }
Example #59
0
 /// <summary>
 /// default ctor
 /// </summary>
 /// <param name="data">the adapted object</param>
 public SkeletonDataAdapter(SkeletonData data)
 {
     this.adaptedData = data;
 }
        override public void OnInspectorGUI()
        {
            if (serializedObject.isEditingMultipleObjects)
            {
                using (new SpineInspectorUtility.BoxScope()) {
                    EditorGUILayout.LabelField("SkeletonData", EditorStyles.boldLabel);
                    EditorGUILayout.PropertyField(skeletonJSON, new GUIContent(skeletonJSON.displayName, Icons.spine));
                    EditorGUILayout.PropertyField(scale);
                }

                using (new SpineInspectorUtility.BoxScope()) {
                    EditorGUILayout.LabelField("Atlas", EditorStyles.boldLabel);
                                        #if !SPINE_TK2D
                    EditorGUILayout.PropertyField(atlasAssets, true);
                                        #else
                    using (new EditorGUI.DisabledGroupScope(spriteCollection.objectReferenceValue != null)) {
                        EditorGUILayout.PropertyField(atlasAssets, true);
                    }
                    EditorGUILayout.LabelField("spine-tk2d", EditorStyles.boldLabel);
                    EditorGUILayout.PropertyField(spriteCollection, true);
                                        #endif
                }

                using (new SpineInspectorUtility.BoxScope()) {
                    EditorGUILayout.LabelField("Mix Settings", EditorStyles.boldLabel);
                    SpineInspectorUtility.PropertyFieldWideLabel(defaultMix, DefaultMixLabel, 160);
                    EditorGUILayout.Space();
                }
                return;
            }

            {
                // Lazy initialization because accessing EditorStyles values in OnEnable during a recompile causes UnityEditor to throw null exceptions. (Unity 5.3.5)
                idlePlayButtonStyle = idlePlayButtonStyle ?? new GUIStyle(EditorStyles.miniButton);
                if (activePlayButtonStyle == null)
                {
                    activePlayButtonStyle = new GUIStyle(idlePlayButtonStyle);
                    activePlayButtonStyle.normal.textColor = Color.red;
                }
            }

            serializedObject.Update();

            EditorGUILayout.LabelField(new GUIContent(target.name + " (SkeletonDataAsset)", Icons.spine), EditorStyles.whiteLargeLabel);
            if (m_skeletonData != null)
            {
                EditorGUILayout.LabelField("(Drag and Drop to instantiate.)", EditorStyles.miniLabel);
            }

            EditorGUI.BeginChangeCheck();

            // SkeletonData
            using (new SpineInspectorUtility.BoxScope()) {
                using (new EditorGUILayout.HorizontalScope()) {
                    EditorGUILayout.LabelField("SkeletonData", EditorStyles.boldLabel);
//					if (m_skeletonData != null) {
//						var sd = m_skeletonData;
//						string m = string.Format("{8} - {0} {1}\nBones: {2}\tConstraints: {5} IK + {6} Path + {7} Transform\nSlots: {3}\t\tSkins: {4}\n",
//							sd.Version, string.IsNullOrEmpty(sd.Version) ? "" : "export", sd.Bones.Count, sd.Slots.Count, sd.Skins.Count, sd.IkConstraints.Count, sd.PathConstraints.Count, sd.TransformConstraints.Count, skeletonJSON.objectReferenceValue.name);
//						EditorGUILayout.LabelField(new GUIContent("SkeletonData"), new GUIContent("+", m), EditorStyles.boldLabel);
//					}
                }

                EditorGUILayout.PropertyField(skeletonJSON, new GUIContent(skeletonJSON.displayName, Icons.spine));
                EditorGUILayout.PropertyField(scale);
            }

//			if (m_skeletonData != null) {
//				if (SpineInspectorUtility.CenteredButton(new GUIContent("Instantiate", Icons.spine, "Creates a new Spine GameObject in the active scene using this Skeleton Data.\nYou can also instantiate by dragging the SkeletonData asset from Project view into Scene View.")))
//					SpineEditorUtilities.ShowInstantiateContextMenu(this.m_skeletonDataAsset, Vector3.zero);
//			}

            // Atlas
            using (new SpineInspectorUtility.BoxScope()) {
                EditorGUILayout.LabelField("Atlas", EditorStyles.boldLabel);
                                #if !SPINE_TK2D
                EditorGUILayout.PropertyField(atlasAssets, true);
                                #else
                using (new EditorGUI.DisabledGroupScope(spriteCollection.objectReferenceValue != null)) {
                    EditorGUILayout.PropertyField(atlasAssets, true);
                }
                EditorGUILayout.LabelField("spine-tk2d", EditorStyles.boldLabel);
                EditorGUILayout.PropertyField(spriteCollection, true);
                                #endif
            }

            if (EditorGUI.EndChangeCheck())
            {
                if (serializedObject.ApplyModifiedProperties())
                {
                    if (m_previewUtility != null)
                    {
                        m_previewUtility.Cleanup();
                        m_previewUtility = null;
                    }
                    m_skeletonDataAsset.Clear();
                    m_skeletonData = null;
                    OnEnable();                     // Should call RepopulateWarnings.
                    return;
                }
            }

            // Some code depends on the existence of m_skeletonAnimation instance.
            // If m_skeletonAnimation is lazy-instantiated elsewhere, this can cause contents to change between Layout and Repaint events, causing GUILayout control count errors.
            InitPreview();
            if (m_skeletonData != null)
            {
                GUILayout.Space(20f);

                using (new SpineInspectorUtility.BoxScope()) {
                    EditorGUILayout.LabelField("Mix Settings", EditorStyles.boldLabel);
                    DrawAnimationStateInfo();
                    EditorGUILayout.Space();
                }

                EditorGUILayout.LabelField("Preview", EditorStyles.boldLabel);
                DrawAnimationList();
                EditorGUILayout.Space();
                DrawSlotList();
                EditorGUILayout.Space();
                DrawUnityTools();
            }
            else
            {
                                #if !SPINE_TK2D
                // Reimport Button
                using (new EditorGUI.DisabledGroupScope(skeletonJSON.objectReferenceValue == null)) {
                    if (GUILayout.Button(new GUIContent("Attempt Reimport", Icons.warning)))
                    {
                        DoReimport();
                    }
                }
                                #else
                EditorGUILayout.HelpBox("Couldn't load SkeletonData.", MessageType.Error);
                                #endif

                // List warnings.
                foreach (var line in warnings)
                {
                    EditorGUILayout.LabelField(new GUIContent(line, Icons.warning));
                }
            }

            if (!Application.isPlaying)
            {
                serializedObject.ApplyModifiedProperties();
            }
        }