Jelajahi Sumber

[cpp] Closes #2252, add accessors for polygons and bounding boxes to SkeletonBounds.

Mario Zechner 2 tahun lalu
induk
melakukan
fbb0d0d41f

+ 1 - 0
CHANGELOG.md

@@ -27,6 +27,7 @@
   * Support for `shortestRotation` in animation state. See https://github.com/esotericsoftware/spine-runtimes/issues/2027.
   * Added CMake parameter `SPINE_SANITIZE` which will enable sanitizers on macOS and Linux.
     * Added `SPINE_MAJOR_VERSION`, `SPINE_MINOR_VERSION`, and `SPINE_VERSION_STRING`. Parsing skeleton .JSON and .skel files will report an error if the skeleton version does not match the runtime version.
+  * Added `SkeletonBounds::getBoundingBox()`, `SkeletonBounds::getPolygons()`, and `SkeletonBounds::getBoundingBoxes()`.
 * **Breaking changes**
   * `RegionAttachment` and `MeshAttachment` no longer implement `HasRendererObject`.
   * `RegionAttachment` and `MeshAttachment` now contain a `TextureRegion*` instead of encoding region fields directly.

+ 11 - 0
spine-cpp/spine-cpp/include/spine/SkeletonBounds.h

@@ -81,8 +81,19 @@ namespace spine {
 		/// Returns true if the polygon contains the line segment.
 		bool intersectsSegment(Polygon *polygon, float x1, float y1, float x2, float y2);
 
+        /// Returns the polygon for the given bounding box attachment or null if no
+        /// polygon can be found for the attachment. Requires a call to update() first.
 		Polygon *getPolygon(BoundingBoxAttachment *attachment);
 
+        /// Returns the bounding box for the given polygon or null. Requires a call to update() first.
+        BoundingBoxAttachment * getBoundingBox(Polygon *polygon);
+
+        /// Returns all polygons or an empty vector. Requires a call to update() first.
+        Vector<Polygon *> &getPolygons();
+
+        /// Returns all bounding boxes. Requires a call to update() first.
+        Vector<BoundingBoxAttachment *> &getBoundingBoxes();
+
 		float getWidth();
 
 		float getHeight();

+ 13 - 0
spine-cpp/spine-cpp/src/spine/SkeletonBounds.cpp

@@ -185,6 +185,19 @@ spine::Polygon *SkeletonBounds::getPolygon(BoundingBoxAttachment *attachment) {
 	return index == -1 ? NULL : _polygons[index];
 }
 
+BoundingBoxAttachment *SkeletonBounds::getBoundingBox(Polygon *polygon) {
+	int index = _polygons.indexOf(polygon);
+	return index == -1 ? NULL : _boundingBoxes[index];
+}
+
+Vector<Polygon *> &SkeletonBounds::getPolygons() {
+	return _polygons;
+}
+
+Vector<BoundingBoxAttachment *> &SkeletonBounds::getBoundingBoxes() {
+	return _boundingBoxes;
+}
+
 float SkeletonBounds::getWidth() {
 	return _maxX - _minX;
 }