浏览代码

[cpp] Fix DeformTimeline, Slot::setAttachment

DeformTimeline had a misplaced return, Slot::setAttachment was not exactly matching the reference implementation if _attachment or inValue where NULL.
Mario Zechner 4 年之前
父节点
当前提交
eedaccc418
共有 2 个文件被更改,包括 8 次插入6 次删除
  1. 5 5
      spine-cpp/spine-cpp/src/spine/DeformTimeline.cpp
  2. 3 1
      spine-cpp/spine-cpp/src/spine/Slot.cpp

+ 5 - 5
spine-cpp/spine-cpp/src/spine/DeformTimeline.cpp

@@ -100,23 +100,23 @@ void DeformTimeline::apply(Skeleton &skeleton, float lastTime, float time, Vecto
 					return;
 					return;
 				}
 				}
 				deformArray.setSize(vertexCount, 0);
 				deformArray.setSize(vertexCount, 0);
-				Vector<float> &deformInner = deformArray;
+				Vector<float> &deform = deformArray;
 				if (attachment->getBones().size() == 0) {
 				if (attachment->getBones().size() == 0) {
 					// Unweighted vertex positions.
 					// Unweighted vertex positions.
 					Vector<float> &setupVertices = attachment->getVertices();
 					Vector<float> &setupVertices = attachment->getVertices();
 					for (size_t i = 0; i < vertexCount; i++)
 					for (size_t i = 0; i < vertexCount; i++)
-						deformInner[i] += (setupVertices[i] - deformInner[i]) * alpha;
+						deform[i] += (setupVertices[i] - deform[i]) * alpha;
 				} else {
 				} else {
 					// Weighted deform offsets.
 					// Weighted deform offsets.
 					alpha = 1 - alpha;
 					alpha = 1 - alpha;
 					for (size_t i = 0; i < vertexCount; i++)
 					for (size_t i = 0; i < vertexCount; i++)
-						deformInner[i] *= alpha;
+						deform[i] *= alpha;
 				}
 				}
 			}
 			}
 			case MixBlend_Replace:
 			case MixBlend_Replace:
-			case MixBlend_Add:
-				return;
+			case MixBlend_Add: {}
 		}
 		}
+		return;
 	}
 	}
 
 
 	deformArray.setSize(vertexCount, 0);
 	deformArray.setSize(vertexCount, 0);

+ 3 - 1
spine-cpp/spine-cpp/src/spine/Slot.cpp

@@ -99,7 +99,9 @@ void Slot::setAttachment(Attachment *inValue) {
 		return;
 		return;
 	}
 	}
 
 
-	if (inValue && _attachment) {
+	if (!inValue || !_attachment) {
+		_deform.clear();
+	} else {
 		if (!(inValue->getRTTI().instanceOf(VertexAttachment::rtti)) ||
 		if (!(inValue->getRTTI().instanceOf(VertexAttachment::rtti)) ||
 			!(_attachment->getRTTI().instanceOf(VertexAttachment::rtti)) ||
 			!(_attachment->getRTTI().instanceOf(VertexAttachment::rtti)) ||
 			(static_cast<VertexAttachment *>(inValue)->getDeformAttachment() !=
 			(static_cast<VertexAttachment *>(inValue)->getDeformAttachment() !=