CreateAnimMesh.cpp 3.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. /*
  2. ---------------------------------------------------------------------------
  3. Open Asset Import Library (assimp)
  4. ---------------------------------------------------------------------------
  5. Copyright (C) 2016 The Qt Company Ltd.
  6. Copyright (c) 2006-2020, assimp team
  7. All rights reserved.
  8. Redistribution and use of this software in source and binary forms,
  9. with or without modification, are permitted provided that the following
  10. conditions are met:
  11. * Redistributions of source code must retain the above
  12. copyright notice, this list of conditions and the
  13. following disclaimer.
  14. * Redistributions in binary form must reproduce the above
  15. copyright notice, this list of conditions and the
  16. following disclaimer in the documentation and/or other
  17. materials provided with the distribution.
  18. * Neither the name of the assimp team, nor the names of its
  19. contributors may be used to endorse or promote products
  20. derived from this software without specific prior
  21. written permission of the assimp team.
  22. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  23. "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  24. LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  25. A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  26. OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  27. SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  28. LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  29. DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  30. THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  31. (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  32. OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  33. ---------------------------------------------------------------------------
  34. */
  35. #include <assimp/CreateAnimMesh.h>
  36. namespace Assimp {
  37. aiAnimMesh *aiCreateAnimMesh(const aiMesh *mesh, bool needPositions, bool needNormals, bool needTangents, bool needColors, bool needTexCoords)
  38. {
  39. aiAnimMesh *animesh = new aiAnimMesh;
  40. animesh->mNumVertices = mesh->mNumVertices;
  41. if (needPositions && mesh->mVertices) {
  42. animesh->mVertices = new aiVector3D[animesh->mNumVertices];
  43. std::memcpy(animesh->mVertices, mesh->mVertices, mesh->mNumVertices * sizeof(aiVector3D));
  44. }
  45. if (needNormals && mesh->mNormals) {
  46. animesh->mNormals = new aiVector3D[animesh->mNumVertices];
  47. std::memcpy(animesh->mNormals, mesh->mNormals, mesh->mNumVertices * sizeof(aiVector3D));
  48. }
  49. if (needTangents && mesh->mTangents) {
  50. animesh->mTangents = new aiVector3D[animesh->mNumVertices];
  51. std::memcpy(animesh->mTangents, mesh->mTangents, mesh->mNumVertices * sizeof(aiVector3D));
  52. }
  53. if (needTangents && mesh->mBitangents) {
  54. animesh->mBitangents = new aiVector3D[animesh->mNumVertices];
  55. std::memcpy(animesh->mBitangents, mesh->mBitangents, mesh->mNumVertices * sizeof(aiVector3D));
  56. }
  57. if (needColors) {
  58. for (int i = 0; i < AI_MAX_NUMBER_OF_COLOR_SETS; ++i) {
  59. if (mesh->mColors[i]) {
  60. animesh->mColors[i] = new aiColor4D[animesh->mNumVertices];
  61. std::memcpy(animesh->mColors[i], mesh->mColors[i], mesh->mNumVertices * sizeof(aiColor4D));
  62. } else {
  63. animesh->mColors[i] = nullptr;
  64. }
  65. }
  66. }
  67. if (needTexCoords) {
  68. for (int i = 0; i < AI_MAX_NUMBER_OF_TEXTURECOORDS; ++i) {
  69. if (mesh->mTextureCoords[i]) {
  70. animesh->mTextureCoords[i] = new aiVector3D[animesh->mNumVertices];
  71. std::memcpy(animesh->mTextureCoords[i], mesh->mTextureCoords[i], mesh->mNumVertices * sizeof(aiVector3D));
  72. } else {
  73. animesh->mTextureCoords[i] = nullptr;
  74. }
  75. }
  76. }
  77. return animesh;
  78. }
  79. } // end of namespace Assimp