• Runtimes
  • C++ render mesh attachment

Hi.
I'm trying to render spine in my c++ project with Directx9.
I success render region attachment with DrawIndexedPrimitiveUP by quadIndices

unsigned short quadIndices[] = { 0, 1, 2, 2, 3, 0 };

but as C++ Runtime Document Code (Render mesh attachment code)
vertices size is more than 4, so don't know how can i get index of them.
how can i get mesh attachment vertices index and draw them?

  • Harald ответили на это сообщение.
    Related Discussions
    ...

    kdy8780 You can access the indices array via MeshAttachment::getTriangles().

    It might help to check out other renderer implementations based on the spine-cpp runtime such as the UE4 renderer implementation, see SpineSkeletonRendererComponent.cpp.

    This general documentation page might perhaps help as well:
    https://esotericsoftware.com/spine-cpp#Implementing-Rendering

    • kdy8780 ответили на это сообщение.
      5 дней спустя
      • Изменено

      Harald

      Thanks for reply.
      MeshAttachment::getTriangles() seems work.
      however, drawing mesh has problem.
      the code right this. I draw attachment with like this, but mesh don't draw anything.

      MeshAttachment* pMesh = (MeshAttachment*)pAttachment;
      vecVertices.setSize(pMesh->getWorldVerticesLength() / 2, SpineVertex());
      size_t iNumVertices = pMesh->getWorldVerticesLength() / 2;
      pMesh->computeWorldVertices(*pSlot, 0, iNumVertices, &(vecVertices.buffer()->x), 0, 7);
      pTexture = (CKTDXDeviceTexture*)((AtlasRegion*)pMesh->getRegion())->page->getRendererObject();
      SetTexture(pTexture);
      for (size_t j = 0, l = 0; j < iNumVertices; j++, l += 2)
      {
      	SpineVertex& kVertex = vecVertices[j];
      	kVertex.z = 1.f;
      	kVertex.rhw = 1.f;
      	kVertex.color = ((int)(kTint.r * 255) << 24) | ((int)(kTint.g * 255) << 16) | ((int)(kTint.b * 255) << 8) | (int)(kTint.a * 255);
      	kVertex.u = pMesh->getUVs()[l];
      	kVertex.v = pMesh->getUVs()[l + 1];
      }
      
      unsigned short* indices = pMesh->getTriangles().buffer();
      DrawIndexedPrimitiveUP(D3DPT_TRIANGLELIST, 0, iNumVertices, 2, indices, D3DFMT_INDEX16, vecVertices.buffer(), sizeof(SpineVertex));

      It's impossible for us to help with this piece of code, as too many things not in the code can go wrong. More over, I'm not a DirectX expert (anymore), so I can't tell if your use of the DirectX APIs is correct.

      I suggest you start by plugging in known "good" data for vecVertices and indices, e.g. a simple triangle. That helps you validate that your DirectX code is correct. Then, I'd create a simple Spine skeleton with a single mesh attachement that consists of a single triangle. It's then very easy to debug the rest of the code with that data.