Skip to content

Commit

Permalink
fix code style
Browse files Browse the repository at this point in the history
  • Loading branch information
zhakesi committed Jun 30, 2023
1 parent 5e9108f commit 27d384e
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 22 deletions.
2 changes: 1 addition & 1 deletion cocos/spine/lib/spine-core.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1277,7 +1277,7 @@ declare namespace spine {
class SkeletonInstance {
initSkeleton(data: SkeletonData);
getAnimationState();
setAnimation(trackIndex: number, name: string, loop: boolean): spine.TrackEntry;
setAnimation(trackIndex: number, name: string, loop: boolean): spine.TrackEntry | null;
setSkin(name: string);
setPremultipliedAlpha(usePremultipliedAlpha: boolean);
setColor(r: number, g: number, b: number, a: number);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1058,7 +1058,7 @@ void SkeletonRenderer::setSlotTexture(const std::string &slotName, cc::Texture2D
}
AttachmentVertices *attachmentVertices = nullptr;
if (attachment->getRTTI().isExactly(spine::RegionAttachment::rtti)) {
auto region = (RegionAttachment *)attachment;
auto region = static_cast<RegionAttachment *>(attachment);
region->setRegionWidth(width);
region->setRegionHeight(height);
region->setRegionOriginalWidth(width);
Expand All @@ -1067,18 +1067,19 @@ void SkeletonRenderer::setSlotTexture(const std::string &slotName, cc::Texture2D
region->setHeight(height);
region->setUVs(0, 0, 1.0f, 1.0f, false);
region->updateOffset();
attachmentVertices = (AttachmentVertices *)region->getRendererObject();
attachmentVertices = static_cast<AttachmentVertices *>(region->getRendererObject());
if (createAttachment) {
attachmentVertices = attachmentVertices->copy();
region->setRendererObject(attachmentVertices);
}
V3F_T2F_C4B *vertices = attachmentVertices->_triangles->verts;
auto UVs = region->getUVs();
for (int i = 0, ii = 0; i < 4; ++i, ii += 2) {
vertices[i].texCoord.u = region->getUVs()[ii];
vertices[i].texCoord.v = region->getUVs()[ii + 1];
vertices[i].texCoord.u = UVs[ii];
vertices[i].texCoord.v = UVs[ii + 1];
}
} else if (attachment->getRTTI().isExactly(spine::MeshAttachment::rtti)) {
auto mesh = (MeshAttachment *)attachment;
auto mesh = static_cast<MeshAttachment *>(attachment);
mesh->setRegionWidth(width);
mesh->setRegionHeight(height);
mesh->setRegionOriginalWidth(width);
Expand All @@ -1092,22 +1093,23 @@ void SkeletonRenderer::setSlotTexture(const std::string &slotName, cc::Texture2D
mesh->setRegionRotate(true);
mesh->setRegionDegrees(0);
mesh->updateUVs();
attachmentVertices = (AttachmentVertices *)mesh->getRendererObject();
attachmentVertices = static_cast<AttachmentVertices *>(mesh->getRendererObject());
if (createAttachment) {
attachmentVertices = attachmentVertices->copy();
mesh->setRendererObject(attachmentVertices);
}
V3F_T2F_C4B *vertices = attachmentVertices->_triangles->verts;
auto UVs = mesh->getUVs();
for (size_t i = 0, ii = 0, nn = mesh->getWorldVerticesLength(); ii < nn; ++i, ii += 2) {
vertices[i].texCoord.u = mesh->getUVs()[ii];
vertices[i].texCoord.v = mesh->getUVs()[ii + 1];
vertices[i].texCoord.u = UVs[ii];
vertices[i].texCoord.v = UVs[ii + 1];
}
}
if (!attachmentVertices) return;
middleware::Texture2D* middlewareTexture = nullptr;
for (auto it = _slotTextureSet.begin(); it != _slotTextureSet.end(); it++) {
if ((*it)->getRealTexture() == tex2d) {
middlewareTexture = *it;
for (auto &it : _slotTextureSet) {
if (it->getRealTexture() == tex2d) {
middlewareTexture = it;
break;
}
}
Expand Down
22 changes: 12 additions & 10 deletions native/cocos/editor-support/spine-wasm/spine-skeleton-instance.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -340,15 +340,15 @@ void SpineSkeletonInstance::collectMeshData() {
// record debug shape info
if (_userData.debugMode) {
SpineDebugShape debugShape;
debugShape.type = (uint32_t)debugShapeType;
debugShape.type = static_cast<uint32_t>(debugShapeType);
debugShape.vOffset = _model->vCount;
debugShape.vCount = currMesh.vCount;
debugShape.iOffset = _model->iCount;
debugShape.iCount = currMesh.iCount;
_debugShapes.push_back(debugShape);
}

currMesh.blendMode = (uint32_t)slot->getData().getBlendMode();
currMesh.blendMode = static_cast<uint32_t>(slot->getData().getBlendMode());
if (_userData.useSlotTexture) {
currMesh.textureID = findSlotTextureID(slot);
} else {
Expand Down Expand Up @@ -483,7 +483,7 @@ void SpineSkeletonInstance::resizeSlotRegion(const std::string& slotName, uint32
slot->setAttachment(attachment);
}
if (attachment->getRTTI().isExactly(spine::RegionAttachment::rtti)) {
auto region = (RegionAttachment *)attachment;
auto region = static_cast<RegionAttachment *>(attachment);
region->setRegionWidth(width);
region->setRegionHeight(height);
region->setRegionOriginalWidth(width);
Expand All @@ -492,18 +492,19 @@ void SpineSkeletonInstance::resizeSlotRegion(const std::string& slotName, uint32
region->setHeight(height);
region->setUVs(0, 0, 1.0f, 1.0f, false);
region->updateOffset();
auto attachmentVertices = (AttachmentVertices*)region->getRendererObject();
auto attachmentVertices = static_cast<AttachmentVertices*>(region->getRendererObject());
if (createNew) {
attachmentVertices = attachmentVertices->copy();
region->setRendererObject(attachmentVertices);
}
V3F_T2F_C4B *vertices = attachmentVertices->_triangles->verts;
auto UVs = region->getUVs();
for (int i = 0, ii = 0; i < 4; ++i, ii += 2) {
vertices[i].texCoord.u = region->getUVs()[ii];
vertices[i].texCoord.v = region->getUVs()[ii + 1];
vertices[i].texCoord.u = UVs[ii];
vertices[i].texCoord.v = UVs[ii + 1];
}
} else if (attachment->getRTTI().isExactly(spine::MeshAttachment::rtti)) {
auto mesh = (MeshAttachment *)attachment;
auto mesh = static_cast<MeshAttachment *>(attachment);
mesh->setRegionWidth(width);
mesh->setRegionHeight(height);
mesh->setRegionOriginalWidth(width);
Expand All @@ -517,15 +518,16 @@ void SpineSkeletonInstance::resizeSlotRegion(const std::string& slotName, uint32
mesh->setRegionRotate(true);
mesh->setRegionDegrees(0);
mesh->updateUVs();
auto attachmentVertices = (AttachmentVertices *)mesh->getRendererObject();
auto attachmentVertices = static_cast<AttachmentVertices *>(mesh->getRendererObject());
if (createNew) {
attachmentVertices = attachmentVertices->copy();
mesh->setRendererObject(attachmentVertices);
}
V3F_T2F_C4B *vertices = attachmentVertices->_triangles->verts;
auto UVs = mesh->getUVs();
for (size_t i = 0, ii = 0, nn = mesh->getWorldVerticesLength(); ii < nn; ++i, ii += 2) {
vertices[i].texCoord.u = mesh->getUVs()[ii];
vertices[i].texCoord.v = mesh->getUVs()[ii + 1];
vertices[i].texCoord.u = UVs[ii];
vertices[i].texCoord.v = UVs[ii + 1];
}
}
}
Expand Down

0 comments on commit 27d384e

Please sign in to comment.