public void Update(Skeleton skeleton, bool updateAabb)
        {
            List <BoundingBoxAttachment> boundingBoxes = BoundingBoxes;
            List <Polygon> polygons  = Polygons;
            List <Slot>    slots     = skeleton.slots;
            int            slotCount = slots.Count;

            boundingBoxes.Clear();
            foreach (Polygon polygon in polygons)
            {
                polygonPool.Add(polygon);
            }
            polygons.Clear();

            for (int i = 0; i < slotCount; i++)
            {
                Slot slot = slots[i];
                BoundingBoxAttachment boundingBox = slot.attachment as BoundingBoxAttachment;
                if (boundingBox == null)
                {
                    continue;
                }
                boundingBoxes.Add(boundingBox);

                Polygon polygon   = null;
                int     poolCount = polygonPool.Count;
                if (poolCount > 0)
                {
                    polygon = polygonPool[poolCount - 1];
                    polygonPool.RemoveAt(poolCount - 1);
                }
                else
                {
                    polygon          = new Polygon();
                    polygon.Count    = boundingBox.Vertices.Length;
                    polygon.Vertices = boundingBox.Vertices;
                }
                polygons.Add(polygon);

                boundingBox.ComputeWorldVertices(slot.bone, polygon.Vertices.ToArray());
            }

            Polygons = polygons;

            if (updateAabb)
            {
                aabbCompute();
            }
        }
Esempio n. 2
0
        public void Update(Skeleton skeleton)
        {
            aabb = false;

            List <BoundingBoxAttachment> boundingBoxes = BoundingBoxes;
            List <Polygon> polygons = Polygons;
            List <Slot>    slots = skeleton.Slots;
            int            slotCount = slots.Count;
            float          x = skeleton.X, y = skeleton.Y;

            boundingBoxes.Clear();
            foreach (Polygon polygon in polygons)
            {
                polygonPool.Add(polygon);
            }
            polygons.Clear();

            for (int i = 0; i < slotCount; i++)
            {
                Slot slot = slots[i];
                BoundingBoxAttachment boundingBox = slot.Attachment as BoundingBoxAttachment;
                if (boundingBox == null)
                {
                    continue;
                }
                boundingBoxes.Add(boundingBox);

                Polygon polygon   = null;
                int     poolCount = polygonPool.Count;
                if (poolCount > 0)
                {
                    polygon = polygonPool[poolCount - 1];
                    polygonPool.RemoveAt(poolCount - 1);
                }
                else
                {
                    polygon = new Polygon();
                }
                polygons.Add(polygon);
                polygon.Count = boundingBox.Vertices.Length;
                if (polygon.Vertices.Length < polygon.Count)
                {
                    polygon.Vertices = new float[polygon.Count];
                }
                boundingBox.ComputeWorldVertices(x, y, slot.Bone, polygon.Vertices);
            }
        }
Esempio n. 3
0
        /// <summary>
        /// Clears any previous polygons, finds all visible bounding box attachments,
        /// and computes the world vertices for each bounding box's polygon.</summary>
        /// <param name="skeleton">The skeleton.</param>
        /// <param name="updateAabb">
        /// If true, the axis aligned bounding box containing all the polygons is computed.
        /// If false, the SkeletonBounds AABB methods will always return true.
        /// </param>
        public void Update(Skeleton skeleton, bool updateAabb)
        {
            ExposedList <BoundingBoxAttachment> boundingBoxes = BoundingBoxes;
            ExposedList <Polygon> polygons = Polygons;
            ExposedList <Slot>    slots    = skeleton.slots;
            int slotCount = slots.Count;

            boundingBoxes.Clear();
            for (int i = 0, n = polygons.Count; i < n; i++)
            {
                polygonPool.Add(polygons.Items[i]);
            }
            polygons.Clear();

            for (int i = 0; i < slotCount; i++)
            {
                Slot slot = slots.Items[i];
                if (!slot.bone.active)
                {
                    continue;
                }
                BoundingBoxAttachment boundingBox = slot.attachment as BoundingBoxAttachment;
                if (boundingBox == null)
                {
                    continue;
                }
                boundingBoxes.Add(boundingBox);

                Polygon polygon   = null;
                int     poolCount = polygonPool.Count;
                if (poolCount > 0)
                {
                    polygon = polygonPool.Items[poolCount - 1];
                    polygonPool.RemoveAt(poolCount - 1);
                }
                else
                {
                    polygon = new Polygon();
                }
                polygons.Add(polygon);

                int count = boundingBox.worldVerticesLength;
                polygon.Count = count;
                if (polygon.Vertices.Length < count)
                {
                    polygon.Vertices = new float[count];
                }
                boundingBox.ComputeWorldVertices(slot, polygon.Vertices);
            }

            if (updateAabb)
            {
                AabbCompute();
            }
            else
            {
                minX = int.MinValue;
                minY = int.MinValue;
                maxX = int.MaxValue;
                maxY = int.MaxValue;
            }
        }
		static void DrawBoundingBox (Slot slot, BoundingBoxAttachment box) {
			if (box.Vertices.Length <= 0) return; // Handle cases where user creates a BoundingBoxAttachment but doesn't actually define it.

			var worldVerts = new float[box.Vertices.Length];
			box.ComputeWorldVertices(slot, worldVerts);

			Handles.color = Color.green;
			Vector3 lastVert = Vector3.back;
			Vector3 vert = Vector3.back;
			Vector3 firstVert = new Vector3(worldVerts[0], worldVerts[1], -1);
			for (int i = 0; i < worldVerts.Length; i += 2) {
				vert.x = worldVerts[i];
				vert.y = worldVerts[i + 1];

				if (i > 0)
					Handles.DrawLine(lastVert, vert);

				lastVert = vert;
			}

			Handles.DrawLine(lastVert, firstVert);

		}
	void DrawBoundingBox (Bone bone, BoundingBoxAttachment box) {
		float[] worldVerts = new float[box.Vertices.Length];
		box.ComputeWorldVertices(bone, worldVerts);

		Handles.color = Color.green;
		Vector3 lastVert = Vector3.back;
		Vector3 vert = Vector3.back;
		Vector3 firstVert = new Vector3(worldVerts[0], worldVerts[1], -1);
		for (int i = 0; i < worldVerts.Length; i += 2) {
			vert.x = worldVerts[i];
			vert.y = worldVerts[i + 1];

			if (i > 0) {
				Handles.DrawLine(lastVert, vert);
			}


			lastVert = vert;
		}

		Handles.DrawLine(lastVert, firstVert);

		
		
	}