コード例 #1
0
VisMeshBuffer_cl *VRendererNodeHelper::GetSphereMeshBuffer()
{
  if (m_spSphereMeshBuffer != NULL)
    return m_spSphereMeshBuffer;

  VDynamicMesh *pMesh = Vision::Game.LoadDynamicMesh("\\Models\\MagicBall.model", true, false);
  VASSERT(pMesh!=NULL);

  m_spSphereMeshBuffer = new VisMeshBuffer_cl();
  m_spSphereMeshBuffer->SetPrimitiveType(VisMeshBuffer_cl::MB_PRIMTYPE_INDEXED_TRILIST);
#ifdef HK_DEBUG
  m_spSphereMeshBuffer->SetFilename("<DeferredShadingSphereMesh>");
#endif

  VisMBVertexDescriptor_t descr;
  descr.Reset();
  descr.m_iPosOfs = 0 | VERTEXDESC_FORMAT_FLOAT3;
  descr.m_iStride = sizeof(float)*3;

  // get model properties
  int iVertexCount = pMesh->GetNumOfVertices();
  int iIndexCount = pMesh->GetNumOfTriangles() * 3;

  // copy vertex buffer, normalize vertex positions
  m_spSphereMeshBuffer->AllocateVertices(descr, iVertexCount); 
  float *pDestVerts = (float *)m_spSphereMeshBuffer->LockVertices(VIS_LOCKFLAG_DISCARDABLE);
  pMesh->CopyMeshVertices(pDestVerts, descr, 0, iVertexCount);
  for (int i=0; i<iVertexCount*3; i+=3)
  {
    hkvVec3 vPos(pDestVerts[i], pDestVerts[i+1], pDestVerts[i+2]);
    vPos.normalizeIfNotZero();
    memcpy(&pDestVerts[i], vPos.data, 3*sizeof(float));
  }
  m_spSphereMeshBuffer->UnLockVertices();

  // copy index buffer
  m_spSphereMeshBuffer->AllocateIndexList(iIndexCount);
  unsigned short *pDestIndices = (unsigned short *)m_spSphereMeshBuffer->LockIndices(VIS_LOCKFLAG_DISCARDABLE);
  pMesh->CopyMeshIndices(pDestIndices, (VisSurface_cl *)NULL);
  m_spSphereMeshBuffer->UnLockIndices();

  return m_spSphereMeshBuffer;
}
コード例 #2
0
bool VisClothDeformer_cl::UpdateDeformerResult(VisVertexAnimResult_cl* pVertexAnimResult)
{
  VISION_PROFILE_FUNCTION(VIS_PROFILE_ANIMSYS_RESULT_VERTEX_ANIM);
   
  if(m_spMesh == NULL)
    return false;

  //// fill vertexanimresult with the mesh data
  // destination buffer
  float *pDestVertexPosition;
  const int  iDestVertexPositionStride = pVertexAnimResult->GetDestVertexPosition(pDestVertexPosition);
  float *pDestVertexNormal;
  const int  iDestVertexNormalStride = pVertexAnimResult->GetDestVertexNormal(pDestVertexNormal);

  int iVertexCount = m_spMesh->GetVertexCount();
  VDynamicMesh *pMesh = pVertexAnimResult->GetMesh();
  VASSERT(pMesh->GetNumOfVertices() == m_spMesh->GetVertexCount());
  VisObjectVertexDelta_t *pVertexDelta = m_spMesh->GetVertexDeltaList();

  // copy mesh vertices into vertexanim result
  hkvVec3 tempNormal(hkvNoInitialization);
  hkvVec3 vTranslate;
  if (m_pParentObject)
    vTranslate = m_pParentObject->GetPosition();

  for(int i=0; i<iVertexCount; i++, pVertexDelta++, ADVANCE_VERTEXPOINTERS)
  {
    pDestVertexPosition[0] = pVertexDelta->delta[0] - vTranslate.x;
    pDestVertexPosition[1] = pVertexDelta->delta[1] - vTranslate.y;
    pDestVertexPosition[2] = pVertexDelta->delta[2] - vTranslate.z;
    tempNormal.set(pVertexDelta->normal[0], pVertexDelta->normal[1], pVertexDelta->normal[2]);
    tempNormal.normalizeIfNotZero();
    pDestVertexNormal[0] = tempNormal.x;
    pDestVertexNormal[1] = tempNormal.y;
    pDestVertexNormal[2] = tempNormal.z;
  }

  return true;
}