2015-05-19 03:48:29 +00:00
|
|
|
/*
|
|
|
|
---------------------------------------------------------------------------
|
|
|
|
Open Asset Import Library (assimp)
|
|
|
|
---------------------------------------------------------------------------
|
|
|
|
|
2022-01-10 20:13:43 +00:00
|
|
|
Copyright (c) 2006-2022, assimp team
|
2018-01-28 18:42:05 +00:00
|
|
|
|
2015-05-19 03:48:29 +00:00
|
|
|
All rights reserved.
|
|
|
|
|
2015-05-19 03:52:10 +00:00
|
|
|
Redistribution and use of this software in source and binary forms,
|
|
|
|
with or without modification, are permitted provided that the following
|
2015-05-19 03:48:29 +00:00
|
|
|
conditions are met:
|
|
|
|
|
|
|
|
* Redistributions of source code must retain the above
|
|
|
|
copyright notice, this list of conditions and the
|
|
|
|
following disclaimer.
|
|
|
|
|
|
|
|
* Redistributions in binary form must reproduce the above
|
|
|
|
copyright notice, this list of conditions and the
|
|
|
|
following disclaimer in the documentation and/or other
|
|
|
|
materials provided with the distribution.
|
|
|
|
|
|
|
|
* Neither the name of the assimp team, nor the names of its
|
|
|
|
contributors may be used to endorse or promote products
|
|
|
|
derived from this software without specific prior
|
|
|
|
written permission of the assimp team.
|
|
|
|
|
2015-05-19 03:52:10 +00:00
|
|
|
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
|
|
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
2015-05-19 03:48:29 +00:00
|
|
|
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
2015-05-19 03:52:10 +00:00
|
|
|
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
2015-05-19 03:48:29 +00:00
|
|
|
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
2015-05-19 03:52:10 +00:00
|
|
|
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
2015-05-19 03:48:29 +00:00
|
|
|
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
2015-05-19 03:52:10 +00:00
|
|
|
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
|
|
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
|
|
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
2015-05-19 03:48:29 +00:00
|
|
|
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
---------------------------------------------------------------------------
|
|
|
|
*/
|
|
|
|
|
2015-05-19 03:52:10 +00:00
|
|
|
/** @file SMDLoader.cpp
|
|
|
|
* @brief Implementation of the SMD importer class
|
2015-05-19 03:48:29 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
#ifndef ASSIMP_BUILD_NO_SMD_IMPORTER
|
|
|
|
|
2018-01-06 00:18:33 +00:00
|
|
|
#include <assimp/fast_atof.h>
|
|
|
|
#include <assimp/SkeletonMeshBuilder.h>
|
2016-06-06 20:04:29 +00:00
|
|
|
#include <assimp/Importer.hpp>
|
|
|
|
#include <assimp/IOSystem.hpp>
|
|
|
|
#include <assimp/scene.h>
|
|
|
|
#include <assimp/DefaultLogger.hpp>
|
2017-02-22 16:20:26 +00:00
|
|
|
#include <assimp/importerdesc.h>
|
2016-04-05 21:23:53 +00:00
|
|
|
#include <memory>
|
2018-11-30 01:47:29 +00:00
|
|
|
#include <assimp/DefaultIOSystem.h>
|
|
|
|
#include <tuple>
|
|
|
|
|
2018-11-30 21:17:42 +00:00
|
|
|
// internal headers
|
|
|
|
#include "SMDLoader.h"
|
|
|
|
|
2019-12-22 08:57:02 +00:00
|
|
|
#ifndef _MSC_VER
|
2018-11-30 01:47:29 +00:00
|
|
|
#define strtok_s strtok_r
|
|
|
|
#endif
|
2015-05-19 03:48:29 +00:00
|
|
|
|
|
|
|
using namespace Assimp;
|
|
|
|
|
|
|
|
static const aiImporterDesc desc = {
|
2015-05-19 03:57:13 +00:00
|
|
|
"Valve SMD Importer",
|
|
|
|
"",
|
|
|
|
"",
|
|
|
|
"",
|
|
|
|
aiImporterFlags_SupportTextFlavour,
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
"smd vta"
|
2015-05-19 03:48:29 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
// Constructor to be privately used by Importer
|
2022-01-18 21:28:54 +00:00
|
|
|
SMDImporter::SMDImporter() :
|
|
|
|
configFrameID(),
|
|
|
|
mBuffer(),
|
|
|
|
pScene( nullptr ),
|
|
|
|
iFileSize( 0 ),
|
|
|
|
iSmallestFrame( INT_MAX ),
|
|
|
|
dLengthOfAnim( 0.0 ),
|
|
|
|
bHasUVs(false ),
|
|
|
|
iLineNumber((unsigned int)-1) {
|
2016-09-04 18:40:34 +00:00
|
|
|
// empty
|
|
|
|
}
|
2015-05-19 03:48:29 +00:00
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
2015-05-19 03:52:10 +00:00
|
|
|
// Destructor, private as well
|
2022-08-25 16:20:13 +00:00
|
|
|
SMDImporter::~SMDImporter() = default;
|
2015-05-19 03:48:29 +00:00
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
2015-05-19 03:52:10 +00:00
|
|
|
// Returns whether the class can handle the format of the given file.
|
2022-01-18 21:28:54 +00:00
|
|
|
bool SMDImporter::CanRead( const std::string& filename, IOSystem* /*pIOHandler*/, bool) const {
|
|
|
|
return SimpleExtensionCheck(filename, "smd", "vta");
|
2015-05-19 03:48:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
// Get a list of all supported file extensions
|
2018-11-30 21:17:42 +00:00
|
|
|
const aiImporterDesc* SMDImporter::GetInfo () const {
|
2015-05-19 03:57:13 +00:00
|
|
|
return &desc;
|
2015-05-19 03:48:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
// Setup configuration properties
|
2018-11-30 21:17:42 +00:00
|
|
|
void SMDImporter::SetupProperties(const Importer* pImp) {
|
2015-05-19 03:57:13 +00:00
|
|
|
// The
|
|
|
|
// AI_CONFIG_IMPORT_SMD_KEYFRAME option overrides the
|
|
|
|
// AI_CONFIG_IMPORT_GLOBAL_KEYFRAME option.
|
|
|
|
configFrameID = pImp->GetPropertyInteger(AI_CONFIG_IMPORT_SMD_KEYFRAME,-1);
|
|
|
|
if(static_cast<unsigned int>(-1) == configFrameID) {
|
|
|
|
configFrameID = pImp->GetPropertyInteger(AI_CONFIG_IMPORT_GLOBAL_KEYFRAME,0);
|
|
|
|
}
|
2018-11-30 01:47:29 +00:00
|
|
|
|
|
|
|
bLoadAnimationList = pImp->GetPropertyBool(AI_CONFIG_IMPORT_SMD_LOAD_ANIMATION_LIST, true);
|
|
|
|
noSkeletonMesh = pImp->GetPropertyBool(AI_CONFIG_IMPORT_NO_SKELETON_MESHES, false);
|
2015-05-19 03:48:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
2015-05-19 03:52:10 +00:00
|
|
|
// Imports the given file into the given scene structure.
|
2020-03-08 20:24:01 +00:00
|
|
|
void SMDImporter::InternReadFile( const std::string& pFile, aiScene* scene, IOSystem* pIOHandler) {
|
|
|
|
this->pScene = scene;
|
2018-11-30 01:47:29 +00:00
|
|
|
ReadSmd(pFile, pIOHandler);
|
2015-05-19 03:57:13 +00:00
|
|
|
|
|
|
|
// If there are no triangles it seems to be an animation SMD,
|
|
|
|
// containing only the animation skeleton.
|
2018-11-30 21:17:42 +00:00
|
|
|
if (asTriangles.empty()) {
|
|
|
|
if (asBones.empty()) {
|
2015-05-19 03:57:13 +00:00
|
|
|
throw DeadlyImportError("SMD: No triangles and no bones have "
|
|
|
|
"been found in the file. This file seems to be invalid.");
|
|
|
|
}
|
|
|
|
|
|
|
|
// Set the flag in the scene structure which indicates
|
|
|
|
// that there is nothing than an animation skeleton
|
|
|
|
pScene->mFlags |= AI_SCENE_FLAGS_INCOMPLETE;
|
|
|
|
}
|
|
|
|
|
2018-11-30 21:17:42 +00:00
|
|
|
if (!asBones.empty()) {
|
2015-05-19 03:57:13 +00:00
|
|
|
// Check whether all bones have been initialized
|
2022-08-23 10:59:42 +00:00
|
|
|
for (const auto &asBone : asBones) {
|
|
|
|
if (!asBone.mName.length()) {
|
2018-04-19 15:21:21 +00:00
|
|
|
ASSIMP_LOG_WARN("SMD: Not all bones have been initialized");
|
2015-05-19 03:57:13 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// now fix invalid time values and make sure the animation starts at frame 0
|
|
|
|
FixTimeValues();
|
|
|
|
}
|
|
|
|
|
2018-11-30 06:30:18 +00:00
|
|
|
// build output nodes (bones are added as empty dummy nodes)
|
|
|
|
CreateOutputNodes();
|
|
|
|
|
2018-11-30 21:17:42 +00:00
|
|
|
if (!(pScene->mFlags & AI_SCENE_FLAGS_INCOMPLETE)) {
|
2015-05-19 03:57:13 +00:00
|
|
|
// create output meshes
|
|
|
|
CreateOutputMeshes();
|
|
|
|
|
|
|
|
// build an output material list
|
|
|
|
CreateOutputMaterials();
|
|
|
|
|
2018-11-30 06:30:18 +00:00
|
|
|
// use root node that renders all meshes
|
|
|
|
pScene->mRootNode->mNumMeshes = pScene->mNumMeshes;
|
|
|
|
pScene->mRootNode->mMeshes = new unsigned int[pScene->mNumMeshes];
|
2018-11-30 21:17:42 +00:00
|
|
|
for (unsigned int i = 0; i < pScene->mNumMeshes; ++i) {
|
2018-11-30 06:30:18 +00:00
|
|
|
pScene->mRootNode->mMeshes[i] = i;
|
2018-11-30 21:17:42 +00:00
|
|
|
}
|
2018-11-30 06:30:18 +00:00
|
|
|
}
|
2015-05-19 03:57:13 +00:00
|
|
|
|
2018-11-30 01:47:29 +00:00
|
|
|
// build the output animation
|
|
|
|
CreateOutputAnimations(pFile, pIOHandler);
|
|
|
|
|
2018-11-30 21:17:42 +00:00
|
|
|
if ((pScene->mFlags & AI_SCENE_FLAGS_INCOMPLETE) && !noSkeletonMesh) {
|
2015-05-19 03:57:13 +00:00
|
|
|
SkeletonMeshBuilder skeleton(pScene);
|
|
|
|
}
|
2015-05-19 03:48:29 +00:00
|
|
|
}
|
2018-11-30 21:17:42 +00:00
|
|
|
|
2015-05-19 03:48:29 +00:00
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
// Write an error message with line number to the log file
|
2018-11-30 21:17:42 +00:00
|
|
|
void SMDImporter::LogErrorNoThrow(const char* msg) {
|
2020-03-08 20:24:01 +00:00
|
|
|
const size_t _BufferSize = 1024;
|
|
|
|
char szTemp[_BufferSize];
|
|
|
|
ai_snprintf(szTemp,_BufferSize,"Line %u: %s",iLineNumber,msg);
|
2015-05-19 03:57:13 +00:00
|
|
|
DefaultLogger::get()->error(szTemp);
|
2015-05-19 03:48:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
// Write a warning with line number to the log file
|
2018-11-30 21:17:42 +00:00
|
|
|
void SMDImporter::LogWarning(const char* msg) {
|
2020-03-08 20:24:01 +00:00
|
|
|
const size_t _BufferSize = 1024;
|
|
|
|
char szTemp[_BufferSize];
|
2015-05-19 03:57:13 +00:00
|
|
|
ai_assert(strlen(msg) < 1000);
|
2020-03-08 20:24:01 +00:00
|
|
|
ai_snprintf(szTemp,_BufferSize,"Line %u: %s",iLineNumber,msg);
|
2018-04-19 15:21:21 +00:00
|
|
|
ASSIMP_LOG_WARN(szTemp);
|
2015-05-19 03:48:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
// Fix invalid time values in the file
|
2018-11-30 21:17:42 +00:00
|
|
|
void SMDImporter::FixTimeValues() {
|
2015-05-19 03:57:13 +00:00
|
|
|
double dDelta = (double)iSmallestFrame;
|
|
|
|
double dMax = 0.0f;
|
2022-08-23 10:59:42 +00:00
|
|
|
for (auto &asBone : asBones) {
|
2022-08-23 11:02:36 +00:00
|
|
|
for (auto &asKey : asBone.sAnim.asKeys) {
|
|
|
|
asKey.dTime -= dDelta;
|
|
|
|
dMax = std::max(dMax, asKey.dTime);
|
2015-05-19 03:57:13 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
dLengthOfAnim = dMax;
|
2015-05-19 03:48:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
// create output meshes
|
2018-11-30 21:17:42 +00:00
|
|
|
void SMDImporter::CreateOutputMeshes() {
|
|
|
|
if (aszTextures.empty()) {
|
2022-08-23 15:41:49 +00:00
|
|
|
aszTextures.emplace_back();
|
2018-11-30 21:17:42 +00:00
|
|
|
}
|
2015-05-19 03:57:13 +00:00
|
|
|
|
|
|
|
// we need to sort all faces by their material index
|
|
|
|
// in opposition to other loaders we can be sure that each
|
|
|
|
// material is at least used once.
|
|
|
|
pScene->mNumMeshes = (unsigned int) aszTextures.size();
|
|
|
|
pScene->mMeshes = new aiMesh*[pScene->mNumMeshes];
|
|
|
|
|
|
|
|
typedef std::vector<unsigned int> FaceList;
|
2022-08-23 11:15:06 +00:00
|
|
|
std::unique_ptr<FaceList[]> aaiFaces(new FaceList[pScene->mNumMeshes]);
|
2015-05-19 03:57:13 +00:00
|
|
|
|
|
|
|
// approximate the space that will be required
|
|
|
|
unsigned int iNum = (unsigned int)asTriangles.size() / pScene->mNumMeshes;
|
|
|
|
iNum += iNum >> 1;
|
2018-11-30 21:17:42 +00:00
|
|
|
for (unsigned int i = 0; i < pScene->mNumMeshes;++i) {
|
2015-05-19 03:57:13 +00:00
|
|
|
aaiFaces[i].reserve(iNum);
|
2018-11-30 21:17:42 +00:00
|
|
|
}
|
2015-05-19 03:57:13 +00:00
|
|
|
|
|
|
|
// collect all faces
|
|
|
|
iNum = 0;
|
2022-08-23 11:10:00 +00:00
|
|
|
for (const auto &asTriangle : asTriangles) {
|
2022-08-23 11:38:27 +00:00
|
|
|
if (asTriangle.iTexture >= aszTextures.size()) {
|
2018-04-26 12:10:18 +00:00
|
|
|
ASSIMP_LOG_INFO("[SMD/VTA] Material index overflow in face");
|
2022-08-23 11:10:00 +00:00
|
|
|
aaiFaces[asTriangle.iTexture].push_back((unsigned int)aszTextures.size()-1);
|
2018-11-30 21:17:42 +00:00
|
|
|
} else {
|
2022-08-23 11:10:00 +00:00
|
|
|
aaiFaces[asTriangle.iTexture].push_back(iNum);
|
2015-05-19 03:57:13 +00:00
|
|
|
}
|
2022-08-23 11:03:48 +00:00
|
|
|
++iNum;
|
2015-05-19 03:57:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// now create the output meshes
|
2018-11-30 21:17:42 +00:00
|
|
|
for (unsigned int i = 0; i < pScene->mNumMeshes;++i) {
|
2015-05-19 03:57:13 +00:00
|
|
|
aiMesh*& pcMesh = pScene->mMeshes[i] = new aiMesh();
|
|
|
|
ai_assert(!aaiFaces[i].empty()); // should not be empty ...
|
|
|
|
|
|
|
|
pcMesh->mPrimitiveTypes = aiPrimitiveType_TRIANGLE;
|
|
|
|
pcMesh->mNumVertices = (unsigned int)aaiFaces[i].size()*3;
|
|
|
|
pcMesh->mNumFaces = (unsigned int)aaiFaces[i].size();
|
|
|
|
pcMesh->mMaterialIndex = i;
|
|
|
|
|
|
|
|
// storage for bones
|
|
|
|
typedef std::pair<unsigned int,float> TempWeightListEntry;
|
|
|
|
typedef std::vector< TempWeightListEntry > TempBoneWeightList;
|
|
|
|
|
2022-08-23 11:17:56 +00:00
|
|
|
std::unique_ptr<TempBoneWeightList[]> aaiBones(new TempBoneWeightList[asBones.size()]());
|
2015-05-19 03:57:13 +00:00
|
|
|
|
|
|
|
// try to reserve enough memory without wasting too much
|
2018-11-30 21:17:42 +00:00
|
|
|
for (unsigned int iBone = 0; iBone < asBones.size();++iBone) {
|
2015-05-19 03:57:13 +00:00
|
|
|
aaiBones[iBone].reserve(pcMesh->mNumVertices/asBones.size());
|
|
|
|
}
|
|
|
|
|
|
|
|
// allocate storage
|
|
|
|
pcMesh->mFaces = new aiFace[pcMesh->mNumFaces];
|
|
|
|
aiVector3D* pcNormals = pcMesh->mNormals = new aiVector3D[pcMesh->mNumVertices];
|
|
|
|
aiVector3D* pcVerts = pcMesh->mVertices = new aiVector3D[pcMesh->mNumVertices];
|
|
|
|
|
2018-11-30 21:17:42 +00:00
|
|
|
aiVector3D* pcUVs = nullptr;
|
|
|
|
if (bHasUVs) {
|
2015-05-19 03:57:13 +00:00
|
|
|
pcUVs = pcMesh->mTextureCoords[0] = new aiVector3D[pcMesh->mNumVertices];
|
|
|
|
pcMesh->mNumUVComponents[0] = 2;
|
|
|
|
}
|
|
|
|
|
|
|
|
iNum = 0;
|
2018-11-30 21:17:42 +00:00
|
|
|
for (unsigned int iFace = 0; iFace < pcMesh->mNumFaces;++iFace) {
|
2015-05-19 03:57:13 +00:00
|
|
|
pcMesh->mFaces[iFace].mIndices = new unsigned int[3];
|
|
|
|
pcMesh->mFaces[iFace].mNumIndices = 3;
|
|
|
|
|
|
|
|
// fill the vertices
|
|
|
|
unsigned int iSrcFace = aaiFaces[i][iFace];
|
|
|
|
SMD::Face& face = asTriangles[iSrcFace];
|
|
|
|
|
|
|
|
*pcVerts++ = face.avVertices[0].pos;
|
|
|
|
*pcVerts++ = face.avVertices[1].pos;
|
|
|
|
*pcVerts++ = face.avVertices[2].pos;
|
|
|
|
|
|
|
|
// fill the normals
|
|
|
|
*pcNormals++ = face.avVertices[0].nor;
|
|
|
|
*pcNormals++ = face.avVertices[1].nor;
|
|
|
|
*pcNormals++ = face.avVertices[2].nor;
|
|
|
|
|
|
|
|
// fill the texture coordinates
|
2018-11-30 21:17:42 +00:00
|
|
|
if (pcUVs) {
|
2015-05-19 03:57:13 +00:00
|
|
|
*pcUVs++ = face.avVertices[0].uv;
|
|
|
|
*pcUVs++ = face.avVertices[1].uv;
|
|
|
|
*pcUVs++ = face.avVertices[2].uv;
|
|
|
|
}
|
|
|
|
|
2018-11-30 21:17:42 +00:00
|
|
|
for (unsigned int iVert = 0; iVert < 3;++iVert) {
|
2015-05-19 03:57:13 +00:00
|
|
|
float fSum = 0.0f;
|
2018-11-30 21:17:42 +00:00
|
|
|
for (unsigned int iBone = 0;iBone < face.avVertices[iVert].aiBoneLinks.size();++iBone) {
|
2015-05-19 03:57:13 +00:00
|
|
|
TempWeightListEntry& pairval = face.avVertices[iVert].aiBoneLinks[iBone];
|
|
|
|
|
|
|
|
// FIX: The second check is here just to make sure we won't
|
|
|
|
// assign more than one weight to a single vertex index
|
2018-11-30 21:17:42 +00:00
|
|
|
if (pairval.first >= asBones.size() || pairval.first == face.avVertices[iVert].iParentNode) {
|
2018-04-26 12:10:18 +00:00
|
|
|
ASSIMP_LOG_ERROR("[SMD/VTA] Bone index overflow. "
|
2015-05-19 03:57:13 +00:00
|
|
|
"The bone index will be ignored, the weight will be assigned "
|
|
|
|
"to the vertex' parent node");
|
|
|
|
continue;
|
|
|
|
}
|
2022-08-25 16:20:13 +00:00
|
|
|
aaiBones[pairval.first].emplace_back(iNum,pairval.second);
|
2015-05-19 03:57:13 +00:00
|
|
|
fSum += pairval.second;
|
|
|
|
}
|
|
|
|
// ******************************************************************
|
|
|
|
// If the sum of all vertex weights is not 1.0 we must assign
|
|
|
|
// the rest to the vertex' parent node. Well, at least the doc says
|
|
|
|
// we should ...
|
|
|
|
// FIX: We use 0.975 as limit, floating-point inaccuracies seem to
|
|
|
|
// be very strong in some SMD exporters. Furthermore it is possible
|
|
|
|
// that the parent of a vertex is 0xffffffff (if the corresponding
|
|
|
|
// entry in the file was unreadable)
|
|
|
|
// ******************************************************************
|
2018-11-30 21:17:42 +00:00
|
|
|
if (fSum < 0.975f && face.avVertices[iVert].iParentNode != UINT_MAX) {
|
|
|
|
if (face.avVertices[iVert].iParentNode >= asBones.size()) {
|
2018-04-26 12:10:18 +00:00
|
|
|
ASSIMP_LOG_ERROR("[SMD/VTA] Bone index overflow. "
|
2015-05-19 03:57:13 +00:00
|
|
|
"The index of the vertex parent bone is invalid. "
|
|
|
|
"The remaining weights will be normalized to 1.0");
|
|
|
|
|
2018-11-30 21:17:42 +00:00
|
|
|
if (fSum) {
|
2015-05-19 03:57:13 +00:00
|
|
|
fSum = 1 / fSum;
|
2022-08-23 10:59:42 +00:00
|
|
|
for (auto &pairval : face.avVertices[iVert].aiBoneLinks) {
|
2018-11-30 21:17:42 +00:00
|
|
|
if (pairval.first >= asBones.size()) {
|
|
|
|
continue;
|
|
|
|
}
|
2015-05-19 03:57:13 +00:00
|
|
|
aaiBones[pairval.first].back().second *= fSum;
|
|
|
|
}
|
|
|
|
}
|
2018-11-30 21:17:42 +00:00
|
|
|
} else {
|
2022-08-25 16:20:13 +00:00
|
|
|
aaiBones[face.avVertices[iVert].iParentNode].emplace_back(iNum,1.0f-fSum);
|
2015-05-19 03:57:13 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
pcMesh->mFaces[iFace].mIndices[iVert] = iNum++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// now build all bones of the mesh
|
|
|
|
iNum = 0;
|
2018-11-30 21:17:42 +00:00
|
|
|
for (unsigned int iBone = 0; iBone < asBones.size();++iBone) {
|
2015-05-19 03:57:13 +00:00
|
|
|
if (!aaiBones[iBone].empty())++iNum;
|
2018-11-30 21:17:42 +00:00
|
|
|
}
|
2015-05-19 03:57:13 +00:00
|
|
|
|
2018-11-30 21:17:42 +00:00
|
|
|
if (iNum) {
|
2015-05-19 03:57:13 +00:00
|
|
|
pcMesh->mNumBones = iNum;
|
|
|
|
pcMesh->mBones = new aiBone*[pcMesh->mNumBones];
|
|
|
|
iNum = 0;
|
2018-11-30 21:17:42 +00:00
|
|
|
for (unsigned int iBone = 0; iBone < asBones.size();++iBone) {
|
|
|
|
if (aaiBones[iBone].empty()) {
|
|
|
|
continue;
|
|
|
|
}
|
2015-05-19 03:57:13 +00:00
|
|
|
aiBone*& bone = pcMesh->mBones[iNum] = new aiBone();
|
|
|
|
|
|
|
|
bone->mNumWeights = (unsigned int)aaiBones[iBone].size();
|
|
|
|
bone->mWeights = new aiVertexWeight[bone->mNumWeights];
|
|
|
|
bone->mOffsetMatrix = asBones[iBone].mOffsetMatrix;
|
|
|
|
bone->mName.Set( asBones[iBone].mName );
|
|
|
|
|
|
|
|
asBones[iBone].bIsUsed = true;
|
|
|
|
|
2018-11-30 21:17:42 +00:00
|
|
|
for (unsigned int iWeight = 0; iWeight < bone->mNumWeights;++iWeight) {
|
2015-05-19 03:57:13 +00:00
|
|
|
bone->mWeights[iWeight].mVertexId = aaiBones[iBone][iWeight].first;
|
|
|
|
bone->mWeights[iWeight].mWeight = aaiBones[iBone][iWeight].second;
|
|
|
|
}
|
|
|
|
++iNum;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2015-05-19 03:48:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
// add bone child nodes
|
2018-11-30 21:17:42 +00:00
|
|
|
void SMDImporter::AddBoneChildren(aiNode* pcNode, uint32_t iParent) {
|
|
|
|
ai_assert( nullptr != pcNode );
|
2017-08-14 20:20:26 +00:00
|
|
|
ai_assert( 0 == pcNode->mNumChildren );
|
2018-11-30 21:17:42 +00:00
|
|
|
ai_assert( nullptr == pcNode->mChildren);
|
2015-05-19 03:57:13 +00:00
|
|
|
|
|
|
|
// first count ...
|
2022-08-23 10:59:42 +00:00
|
|
|
for (auto &bone : asBones) {
|
2018-11-30 21:17:42 +00:00
|
|
|
if (bone.iParent == iParent) {
|
|
|
|
++pcNode->mNumChildren;
|
|
|
|
}
|
2015-05-19 03:57:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// now allocate the output array
|
|
|
|
pcNode->mChildren = new aiNode*[pcNode->mNumChildren];
|
|
|
|
|
|
|
|
// and fill all subnodes
|
2018-11-30 21:17:42 +00:00
|
|
|
unsigned int qq( 0 );
|
|
|
|
for (unsigned int i = 0; i < asBones.size();++i) {
|
2015-05-19 03:57:13 +00:00
|
|
|
SMD::Bone& bone = asBones[i];
|
2018-11-30 21:17:42 +00:00
|
|
|
if (bone.iParent != iParent) {
|
|
|
|
continue;
|
|
|
|
}
|
2015-05-19 03:57:13 +00:00
|
|
|
|
|
|
|
aiNode* pc = pcNode->mChildren[qq++] = new aiNode();
|
|
|
|
pc->mName.Set(bone.mName);
|
|
|
|
|
|
|
|
// store the local transformation matrix of the bind pose
|
2018-11-30 21:17:42 +00:00
|
|
|
if (bone.sAnim.asKeys.size()) {
|
2018-11-30 06:30:18 +00:00
|
|
|
pc->mTransformation = bone.sAnim.asKeys[0].matrix;
|
2018-11-30 21:17:42 +00:00
|
|
|
}
|
2018-11-30 06:30:18 +00:00
|
|
|
|
2021-07-29 11:28:51 +00:00
|
|
|
if (bone.iParent == static_cast<uint32_t>(-1)) {
|
2018-11-30 06:30:18 +00:00
|
|
|
bone.mOffsetMatrix = pc->mTransformation;
|
2018-11-30 21:17:42 +00:00
|
|
|
} else {
|
2018-11-30 06:30:18 +00:00
|
|
|
bone.mOffsetMatrix = asBones[bone.iParent].mOffsetMatrix * pc->mTransformation;
|
2018-11-30 21:17:42 +00:00
|
|
|
}
|
2018-11-30 06:30:18 +00:00
|
|
|
|
2015-05-19 03:57:13 +00:00
|
|
|
pc->mParent = pcNode;
|
|
|
|
|
|
|
|
// add children to this node, too
|
|
|
|
AddBoneChildren(pc,i);
|
|
|
|
}
|
2015-05-19 03:48:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
// create output nodes
|
2018-11-30 21:17:42 +00:00
|
|
|
void SMDImporter::CreateOutputNodes() {
|
2015-05-19 03:57:13 +00:00
|
|
|
pScene->mRootNode = new aiNode();
|
|
|
|
|
|
|
|
// now add all bones as dummy sub nodes to the graph
|
2018-11-27 05:28:42 +00:00
|
|
|
AddBoneChildren(pScene->mRootNode,(uint32_t)-1);
|
2018-11-30 21:17:42 +00:00
|
|
|
for (auto &bone : asBones) {
|
2018-11-30 06:30:18 +00:00
|
|
|
bone.mOffsetMatrix.Inverse();
|
2018-11-30 21:17:42 +00:00
|
|
|
}
|
2015-05-19 03:57:13 +00:00
|
|
|
|
|
|
|
// if we have only one bone we can even remove the root node
|
2018-11-30 21:17:42 +00:00
|
|
|
if (pScene->mFlags & AI_SCENE_FLAGS_INCOMPLETE && 1 == pScene->mRootNode->mNumChildren) {
|
2015-05-19 03:57:13 +00:00
|
|
|
aiNode* pcOldRoot = pScene->mRootNode;
|
|
|
|
pScene->mRootNode = pcOldRoot->mChildren[0];
|
2018-11-30 21:17:42 +00:00
|
|
|
pcOldRoot->mChildren[0] = nullptr;
|
2015-05-19 03:57:13 +00:00
|
|
|
delete pcOldRoot;
|
|
|
|
|
2018-11-30 21:17:42 +00:00
|
|
|
pScene->mRootNode->mParent = nullptr;
|
2015-05-19 03:57:13 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
::strcpy(pScene->mRootNode->mName.data, "<SMD_root>");
|
|
|
|
pScene->mRootNode->mName.length = 10;
|
|
|
|
}
|
2015-05-19 03:48:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
// create output animations
|
2018-11-30 21:17:42 +00:00
|
|
|
void SMDImporter::CreateOutputAnimations(const std::string &pFile, IOSystem* pIOHandler) {
|
2018-11-30 01:47:29 +00:00
|
|
|
std::vector<std::tuple<std::string, std::string>> animFileList;
|
|
|
|
|
2018-11-30 21:17:42 +00:00
|
|
|
if (bLoadAnimationList) {
|
|
|
|
GetAnimationFileList(pFile, pIOHandler, animFileList);
|
|
|
|
}
|
2019-03-13 13:40:02 +00:00
|
|
|
int animCount = static_cast<int>( animFileList.size() + 1u );
|
2015-05-19 03:57:13 +00:00
|
|
|
pScene->mNumAnimations = 1;
|
2018-11-30 01:47:29 +00:00
|
|
|
pScene->mAnimations = new aiAnimation*[animCount];
|
|
|
|
memset(pScene->mAnimations, 0, sizeof(aiAnimation*)*animCount);
|
|
|
|
CreateOutputAnimation(0, "");
|
|
|
|
|
2018-11-30 21:17:42 +00:00
|
|
|
for (auto &animFile : animFileList) {
|
2018-11-30 01:47:29 +00:00
|
|
|
ReadSmd(std::get<1>(animFile), pIOHandler);
|
2018-11-30 21:17:42 +00:00
|
|
|
if (asBones.empty()) {
|
|
|
|
continue;
|
|
|
|
}
|
2018-11-30 01:47:29 +00:00
|
|
|
|
|
|
|
FixTimeValues();
|
|
|
|
CreateOutputAnimation(pScene->mNumAnimations++, std::get<0>(animFile));
|
|
|
|
}
|
|
|
|
}
|
2015-05-19 03:57:13 +00:00
|
|
|
|
2018-11-30 21:17:42 +00:00
|
|
|
void SMDImporter::CreateOutputAnimation(int index, const std::string &name) {
|
2018-11-30 01:47:29 +00:00
|
|
|
aiAnimation*& anim = pScene->mAnimations[index] = new aiAnimation();
|
|
|
|
|
2018-11-30 21:17:42 +00:00
|
|
|
if (name.length()) {
|
2018-11-30 01:47:29 +00:00
|
|
|
anim->mName.Set(name.c_str());
|
|
|
|
}
|
2015-05-19 03:57:13 +00:00
|
|
|
anim->mDuration = dLengthOfAnim;
|
2019-03-13 13:40:02 +00:00
|
|
|
anim->mNumChannels = static_cast<unsigned int>( asBones.size() );
|
2015-05-19 03:57:13 +00:00
|
|
|
anim->mTicksPerSecond = 25.0; // FIXME: is this correct?
|
|
|
|
|
|
|
|
aiNodeAnim** pp = anim->mChannels = new aiNodeAnim*[anim->mNumChannels];
|
|
|
|
|
|
|
|
// now build valid keys
|
|
|
|
unsigned int a = 0;
|
2022-08-23 10:59:42 +00:00
|
|
|
for (const auto &asBone : asBones) {
|
2015-05-19 03:57:13 +00:00
|
|
|
aiNodeAnim* p = pp[a] = new aiNodeAnim();
|
|
|
|
|
|
|
|
// copy the name of the bone
|
2022-08-23 10:59:42 +00:00
|
|
|
p->mNodeName.Set(asBone.mName);
|
2015-05-19 03:57:13 +00:00
|
|
|
|
2022-08-23 10:59:42 +00:00
|
|
|
p->mNumRotationKeys = (unsigned int)asBone.sAnim.asKeys.size();
|
2018-11-30 21:17:42 +00:00
|
|
|
if (p->mNumRotationKeys){
|
2015-05-19 03:57:13 +00:00
|
|
|
p->mNumPositionKeys = p->mNumRotationKeys;
|
|
|
|
aiVectorKey* pVecKeys = p->mPositionKeys = new aiVectorKey[p->mNumRotationKeys];
|
|
|
|
aiQuatKey* pRotKeys = p->mRotationKeys = new aiQuatKey[p->mNumRotationKeys];
|
|
|
|
|
2022-08-23 11:02:36 +00:00
|
|
|
for (const auto &asKey : asBone.sAnim.asKeys) {
|
|
|
|
pRotKeys->mTime = pVecKeys->mTime = asKey.dTime;
|
2015-05-19 03:57:13 +00:00
|
|
|
|
|
|
|
// compute the rotation quaternion from the euler angles
|
2018-11-29 02:48:13 +00:00
|
|
|
// aiQuaternion: The order of the parameters is yzx?
|
2022-08-23 11:02:36 +00:00
|
|
|
pRotKeys->mValue = aiQuaternion(asKey.vRot.y, asKey.vRot.z, asKey.vRot.x);
|
|
|
|
pVecKeys->mValue = asKey.vPos;
|
2015-05-19 03:57:13 +00:00
|
|
|
|
|
|
|
++pVecKeys; ++pRotKeys;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
++a;
|
|
|
|
|
|
|
|
// there are no scaling keys ...
|
|
|
|
}
|
2015-05-19 03:48:29 +00:00
|
|
|
}
|
|
|
|
|
2018-11-30 21:17:42 +00:00
|
|
|
void SMDImporter::GetAnimationFileList(const std::string &pFile, IOSystem* pIOHandler, std::vector<std::tuple<std::string, std::string>>& outList) {
|
2018-11-30 01:47:29 +00:00
|
|
|
auto base = DefaultIOSystem::absolutePath(pFile);
|
|
|
|
auto name = DefaultIOSystem::completeBaseName(pFile);
|
|
|
|
auto path = base + "/" + name + "_animation.txt";
|
|
|
|
|
|
|
|
std::unique_ptr<IOStream> file(pIOHandler->Open(path.c_str(), "rb"));
|
2022-11-08 16:03:55 +00:00
|
|
|
if (file == nullptr) {
|
2018-11-30 21:17:42 +00:00
|
|
|
return;
|
|
|
|
}
|
2018-11-30 01:47:29 +00:00
|
|
|
|
|
|
|
// Allocate storage and copy the contents of the file to a memory buffer
|
|
|
|
std::vector<char> buf;
|
|
|
|
size_t fileSize = file->FileSize();
|
|
|
|
buf.resize(fileSize + 1);
|
|
|
|
TextFileToBuffer(file.get(), buf);
|
|
|
|
|
|
|
|
/*
|
|
|
|
*_animation.txt format:
|
|
|
|
name path
|
|
|
|
idle idle.smd
|
|
|
|
jump anim/jump.smd
|
|
|
|
walk.smd
|
|
|
|
...
|
|
|
|
*/
|
|
|
|
std::string animName, animPath;
|
|
|
|
char *tok1, *tok2;
|
|
|
|
char *context1, *context2;
|
|
|
|
|
|
|
|
tok1 = strtok_s(&buf[0], "\r\n", &context1);
|
2020-06-23 19:05:42 +00:00
|
|
|
while (tok1 != nullptr) {
|
2018-11-30 01:47:29 +00:00
|
|
|
tok2 = strtok_s(tok1, " \t", &context2);
|
2018-11-30 21:17:42 +00:00
|
|
|
if (tok2) {
|
2018-11-30 01:47:29 +00:00
|
|
|
char *p = tok2;
|
2018-11-30 21:17:42 +00:00
|
|
|
tok2 = strtok_s(nullptr, " \t", &context2);
|
|
|
|
if (tok2) {
|
2018-11-30 01:47:29 +00:00
|
|
|
animPath = tok2;
|
|
|
|
animName = p;
|
2018-11-30 21:17:42 +00:00
|
|
|
} else {
|
|
|
|
// No name
|
2018-11-30 01:47:29 +00:00
|
|
|
animPath = p;
|
|
|
|
animName = DefaultIOSystem::completeBaseName(animPath);
|
|
|
|
}
|
2022-08-23 15:41:49 +00:00
|
|
|
outList.emplace_back(animName, base + "/" + animPath);
|
2018-11-30 01:47:29 +00:00
|
|
|
}
|
2018-11-30 21:17:42 +00:00
|
|
|
tok1 = strtok_s(nullptr, "\r\n", &context1);
|
2018-11-30 01:47:29 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-05-19 03:48:29 +00:00
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
// create output materials
|
2018-11-30 21:17:42 +00:00
|
|
|
void SMDImporter::CreateOutputMaterials() {
|
2017-09-30 08:47:23 +00:00
|
|
|
ai_assert( nullptr != pScene );
|
|
|
|
|
2015-05-19 03:57:13 +00:00
|
|
|
pScene->mNumMaterials = (unsigned int)aszTextures.size();
|
|
|
|
pScene->mMaterials = new aiMaterial*[std::max(1u, pScene->mNumMaterials)];
|
|
|
|
|
2017-09-30 08:47:23 +00:00
|
|
|
for (unsigned int iMat = 0; iMat < pScene->mNumMaterials; ++iMat) {
|
2015-05-19 03:57:13 +00:00
|
|
|
aiMaterial* pcMat = new aiMaterial();
|
2017-09-30 08:47:23 +00:00
|
|
|
ai_assert( nullptr != pcMat );
|
2015-05-19 03:57:13 +00:00
|
|
|
pScene->mMaterials[iMat] = pcMat;
|
|
|
|
|
|
|
|
aiString szName;
|
2016-01-06 18:25:35 +00:00
|
|
|
szName.length = (size_t)ai_snprintf(szName.data,MAXLEN,"Texture_%u",iMat);
|
2015-05-19 03:57:13 +00:00
|
|
|
pcMat->AddProperty(&szName,AI_MATKEY_NAME);
|
|
|
|
|
|
|
|
if (aszTextures[iMat].length())
|
|
|
|
{
|
2016-09-25 13:21:30 +00:00
|
|
|
::strncpy(szName.data, aszTextures[iMat].c_str(),MAXLEN-1);
|
2020-01-16 19:25:47 +00:00
|
|
|
szName.length = static_cast<ai_uint32>( aszTextures[iMat].length() );
|
2015-05-19 03:57:13 +00:00
|
|
|
pcMat->AddProperty(&szName,AI_MATKEY_TEXTURE_DIFFUSE(0));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// create a default material if necessary
|
2018-11-30 21:17:42 +00:00
|
|
|
if (0 == pScene->mNumMaterials) {
|
2015-05-19 03:57:13 +00:00
|
|
|
pScene->mNumMaterials = 1;
|
|
|
|
|
|
|
|
aiMaterial* pcHelper = new aiMaterial();
|
|
|
|
pScene->mMaterials[0] = pcHelper;
|
|
|
|
|
2018-11-30 21:17:42 +00:00
|
|
|
int iMode = static_cast<int>(aiShadingMode_Gouraud);
|
2015-05-19 03:57:13 +00:00
|
|
|
pcHelper->AddProperty<int>(&iMode, 1, AI_MATKEY_SHADING_MODEL);
|
|
|
|
|
|
|
|
aiColor3D clr;
|
|
|
|
clr.b = clr.g = clr.r = 0.7f;
|
|
|
|
pcHelper->AddProperty<aiColor3D>(&clr, 1,AI_MATKEY_COLOR_DIFFUSE);
|
|
|
|
pcHelper->AddProperty<aiColor3D>(&clr, 1,AI_MATKEY_COLOR_SPECULAR);
|
|
|
|
|
|
|
|
clr.b = clr.g = clr.r = 0.05f;
|
|
|
|
pcHelper->AddProperty<aiColor3D>(&clr, 1,AI_MATKEY_COLOR_AMBIENT);
|
|
|
|
|
|
|
|
aiString szName;
|
|
|
|
szName.Set(AI_DEFAULT_MATERIAL_NAME);
|
|
|
|
pcHelper->AddProperty(&szName,AI_MATKEY_NAME);
|
|
|
|
}
|
2015-05-19 03:48:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
// Parse the file
|
2018-11-30 21:17:42 +00:00
|
|
|
void SMDImporter::ParseFile() {
|
2016-09-04 18:40:34 +00:00
|
|
|
const char* szCurrent = &mBuffer[0];
|
2015-05-19 03:57:13 +00:00
|
|
|
|
|
|
|
// read line per line ...
|
2018-11-30 21:17:42 +00:00
|
|
|
for ( ;; ) {
|
|
|
|
if(!SkipSpacesAndLineEnd(szCurrent,&szCurrent)) {
|
|
|
|
break;
|
|
|
|
}
|
2015-05-19 03:57:13 +00:00
|
|
|
|
2017-01-08 16:41:10 +00:00
|
|
|
// "version <n> \n", <n> should be 1 for hl and hl2 SMD files
|
2018-11-30 21:17:42 +00:00
|
|
|
if (TokenMatch(szCurrent,"version",7)) {
|
2015-05-19 03:57:13 +00:00
|
|
|
if(!SkipSpaces(szCurrent,&szCurrent)) break;
|
2018-11-30 21:17:42 +00:00
|
|
|
if (1 != strtoul10(szCurrent,&szCurrent)) {
|
2018-04-19 15:21:21 +00:00
|
|
|
ASSIMP_LOG_WARN("SMD.version is not 1. This "
|
2015-05-19 03:57:13 +00:00
|
|
|
"file format is not known. Continuing happily ...");
|
|
|
|
}
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
// "nodes\n" - Starts the node section
|
2018-11-30 21:17:42 +00:00
|
|
|
if (TokenMatch(szCurrent,"nodes",5)) {
|
2015-05-19 03:57:13 +00:00
|
|
|
ParseNodesSection(szCurrent,&szCurrent);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
// "triangles\n" - Starts the triangle section
|
2018-11-30 21:17:42 +00:00
|
|
|
if (TokenMatch(szCurrent,"triangles",9)) {
|
2015-05-19 03:57:13 +00:00
|
|
|
ParseTrianglesSection(szCurrent,&szCurrent);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
// "vertexanimation\n" - Starts the vertex animation section
|
2018-11-30 21:17:42 +00:00
|
|
|
if (TokenMatch(szCurrent,"vertexanimation",15)) {
|
2015-05-19 03:57:13 +00:00
|
|
|
bHasUVs = false;
|
|
|
|
ParseVASection(szCurrent,&szCurrent);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
// "skeleton\n" - Starts the skeleton section
|
2018-11-30 21:17:42 +00:00
|
|
|
if (TokenMatch(szCurrent,"skeleton",8)) {
|
2015-05-19 03:57:13 +00:00
|
|
|
ParseSkeletonSection(szCurrent,&szCurrent);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
SkipLine(szCurrent,&szCurrent);
|
|
|
|
}
|
2015-05-19 03:48:29 +00:00
|
|
|
}
|
|
|
|
|
2018-11-30 21:17:42 +00:00
|
|
|
void SMDImporter::ReadSmd(const std::string &pFile, IOSystem* pIOHandler) {
|
2018-11-30 01:47:29 +00:00
|
|
|
std::unique_ptr<IOStream> file(pIOHandler->Open(pFile, "rb"));
|
|
|
|
|
|
|
|
// Check whether we can read from the file
|
2022-11-08 16:03:55 +00:00
|
|
|
if (file == nullptr) {
|
2020-08-18 16:35:08 +00:00
|
|
|
throw DeadlyImportError("Failed to open SMD/VTA file ", pFile, ".");
|
2018-11-30 01:47:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
iFileSize = (unsigned int)file->FileSize();
|
|
|
|
|
|
|
|
// Allocate storage and copy the contents of the file to a memory buffer
|
|
|
|
mBuffer.resize(iFileSize + 1);
|
|
|
|
TextFileToBuffer(file.get(), mBuffer);
|
|
|
|
|
|
|
|
iSmallestFrame = INT_MAX;
|
|
|
|
bHasUVs = true;
|
|
|
|
iLineNumber = 1;
|
|
|
|
|
|
|
|
// Reserve enough space for ... hm ... 10 textures
|
|
|
|
aszTextures.reserve(10);
|
|
|
|
|
|
|
|
// Reserve enough space for ... hm ... 1000 triangles
|
|
|
|
asTriangles.reserve(1000);
|
|
|
|
|
|
|
|
// Reserve enough space for ... hm ... 20 bones
|
|
|
|
asBones.reserve(20);
|
|
|
|
|
|
|
|
aszTextures.clear();
|
|
|
|
asTriangles.clear();
|
|
|
|
asBones.clear();
|
|
|
|
|
|
|
|
// parse the file ...
|
|
|
|
ParseFile();
|
|
|
|
}
|
|
|
|
|
2015-05-19 03:48:29 +00:00
|
|
|
// ------------------------------------------------------------------------------------------------
|
2018-11-30 21:17:42 +00:00
|
|
|
unsigned int SMDImporter::GetTextureIndex(const std::string& filename) {
|
2015-05-19 03:57:13 +00:00
|
|
|
unsigned int iIndex = 0;
|
|
|
|
for (std::vector<std::string>::const_iterator
|
2018-11-30 21:17:42 +00:00
|
|
|
i = aszTextures.begin();
|
|
|
|
i != aszTextures.end();++i,++iIndex) {
|
2015-05-19 03:57:13 +00:00
|
|
|
// case-insensitive ... it's a path
|
2018-11-30 21:17:42 +00:00
|
|
|
if (0 == ASSIMP_stricmp ( filename.c_str(),(*i).c_str())) {
|
|
|
|
return iIndex;
|
|
|
|
}
|
2015-05-19 03:57:13 +00:00
|
|
|
}
|
|
|
|
iIndex = (unsigned int)aszTextures.size();
|
|
|
|
aszTextures.push_back(filename);
|
|
|
|
return iIndex;
|
2015-05-19 03:48:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
// Parse the nodes section of the file
|
2018-11-30 21:17:42 +00:00
|
|
|
void SMDImporter::ParseNodesSection(const char* szCurrent, const char** szCurrentOut) {
|
|
|
|
for ( ;; ) {
|
2015-05-19 03:57:13 +00:00
|
|
|
// "end\n" - Ends the nodes section
|
2018-11-30 21:17:42 +00:00
|
|
|
if (0 == ASSIMP_strincmp(szCurrent,"end",3) && IsSpaceOrNewLine(*(szCurrent+3))) {
|
2015-05-19 03:57:13 +00:00
|
|
|
szCurrent += 4;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
ParseNodeInfo(szCurrent,&szCurrent);
|
|
|
|
}
|
|
|
|
SkipSpacesAndLineEnd(szCurrent,&szCurrent);
|
|
|
|
*szCurrentOut = szCurrent;
|
2015-05-19 03:48:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
// Parse the triangles section of the file
|
2018-11-30 21:17:42 +00:00
|
|
|
void SMDImporter::ParseTrianglesSection(const char* szCurrent, const char** szCurrentOut) {
|
2015-05-19 03:57:13 +00:00
|
|
|
// Parse a triangle, parse another triangle, parse the next triangle ...
|
|
|
|
// and so on until we reach a token that looks quite similar to "end"
|
2018-11-30 21:17:42 +00:00
|
|
|
for ( ;; ) {
|
|
|
|
if(!SkipSpacesAndLineEnd(szCurrent,&szCurrent)) {
|
|
|
|
break;
|
|
|
|
}
|
2015-05-19 03:57:13 +00:00
|
|
|
|
|
|
|
// "end\n" - Ends the triangles section
|
2018-11-30 21:17:42 +00:00
|
|
|
if (TokenMatch(szCurrent,"end",3)) {
|
2015-05-19 03:57:13 +00:00
|
|
|
break;
|
2018-11-30 21:17:42 +00:00
|
|
|
}
|
2015-05-19 03:57:13 +00:00
|
|
|
ParseTriangle(szCurrent,&szCurrent);
|
|
|
|
}
|
|
|
|
SkipSpacesAndLineEnd(szCurrent,&szCurrent);
|
|
|
|
*szCurrentOut = szCurrent;
|
2015-05-19 03:48:29 +00:00
|
|
|
}
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
// Parse the vertex animation section of the file
|
2018-11-30 21:17:42 +00:00
|
|
|
void SMDImporter::ParseVASection(const char* szCurrent, const char** szCurrentOut) {
|
2015-05-19 03:57:13 +00:00
|
|
|
unsigned int iCurIndex = 0;
|
2018-11-30 21:17:42 +00:00
|
|
|
for ( ;; ) {
|
|
|
|
if (!SkipSpacesAndLineEnd(szCurrent,&szCurrent)) {
|
|
|
|
break;
|
|
|
|
}
|
2015-05-19 03:57:13 +00:00
|
|
|
|
|
|
|
// "end\n" - Ends the "vertexanimation" section
|
2018-11-30 21:17:42 +00:00
|
|
|
if (TokenMatch(szCurrent,"end",3)) {
|
2015-05-19 03:57:13 +00:00
|
|
|
break;
|
2018-11-30 21:17:42 +00:00
|
|
|
}
|
2015-05-19 03:57:13 +00:00
|
|
|
|
|
|
|
// "time <n>\n"
|
2018-11-30 21:17:42 +00:00
|
|
|
if (TokenMatch(szCurrent,"time",4)) {
|
2015-05-19 03:57:13 +00:00
|
|
|
// NOTE: The doc says that time values COULD be negative ...
|
|
|
|
// NOTE2: this is the shape key -> valve docs
|
|
|
|
int iTime = 0;
|
2018-11-30 21:17:42 +00:00
|
|
|
if(!ParseSignedInt(szCurrent,&szCurrent,iTime) || configFrameID != (unsigned int)iTime) {
|
|
|
|
break;
|
|
|
|
}
|
2015-05-19 03:57:13 +00:00
|
|
|
SkipLine(szCurrent,&szCurrent);
|
2018-11-30 21:17:42 +00:00
|
|
|
} else {
|
|
|
|
if(0 == iCurIndex) {
|
2022-08-23 15:41:49 +00:00
|
|
|
asTriangles.emplace_back();
|
2015-05-19 03:57:13 +00:00
|
|
|
}
|
2018-11-30 21:17:42 +00:00
|
|
|
if (++iCurIndex == 3) {
|
|
|
|
iCurIndex = 0;
|
|
|
|
}
|
2015-05-19 03:57:13 +00:00
|
|
|
ParseVertex(szCurrent,&szCurrent,asTriangles.back().avVertices[iCurIndex],true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-11-30 21:17:42 +00:00
|
|
|
if (iCurIndex != 2 && !asTriangles.empty()) {
|
2015-05-19 03:57:13 +00:00
|
|
|
// we want to no degenerates, so throw this triangle away
|
|
|
|
asTriangles.pop_back();
|
|
|
|
}
|
|
|
|
|
|
|
|
SkipSpacesAndLineEnd(szCurrent,&szCurrent);
|
|
|
|
*szCurrentOut = szCurrent;
|
2015-05-19 03:48:29 +00:00
|
|
|
}
|
2018-11-30 21:17:42 +00:00
|
|
|
|
2015-05-19 03:48:29 +00:00
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
// Parse the skeleton section of the file
|
2018-11-30 21:17:42 +00:00
|
|
|
void SMDImporter::ParseSkeletonSection(const char* szCurrent, const char** szCurrentOut) {
|
2015-05-19 03:57:13 +00:00
|
|
|
int iTime = 0;
|
2018-11-30 21:17:42 +00:00
|
|
|
for ( ;; ) {
|
|
|
|
if (!SkipSpacesAndLineEnd(szCurrent,&szCurrent)) {
|
|
|
|
break;
|
|
|
|
}
|
2015-05-19 03:57:13 +00:00
|
|
|
|
|
|
|
// "end\n" - Ends the skeleton section
|
2018-11-30 21:17:42 +00:00
|
|
|
if (TokenMatch(szCurrent,"end",3)) {
|
2015-05-19 03:57:13 +00:00
|
|
|
break;
|
2018-11-30 21:17:42 +00:00
|
|
|
} else if (TokenMatch(szCurrent,"time",4)) {
|
2015-05-19 03:57:13 +00:00
|
|
|
// "time <n>\n" - Specifies the current animation frame
|
2018-11-30 21:17:42 +00:00
|
|
|
if(!ParseSignedInt(szCurrent,&szCurrent,iTime)) {
|
|
|
|
break;
|
|
|
|
}
|
2015-05-19 03:57:13 +00:00
|
|
|
|
|
|
|
iSmallestFrame = std::min(iSmallestFrame,iTime);
|
|
|
|
SkipLine(szCurrent,&szCurrent);
|
2018-11-30 21:17:42 +00:00
|
|
|
} else {
|
|
|
|
ParseSkeletonElement(szCurrent,&szCurrent,iTime);
|
2015-05-19 03:57:13 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
*szCurrentOut = szCurrent;
|
2015-05-19 03:48:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
#define SMDI_PARSE_RETURN { \
|
2015-05-19 03:57:13 +00:00
|
|
|
SkipLine(szCurrent,&szCurrent); \
|
|
|
|
*szCurrentOut = szCurrent; \
|
|
|
|
return; \
|
2015-05-19 03:48:29 +00:00
|
|
|
}
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
// Parse a node line
|
2018-11-30 21:17:42 +00:00
|
|
|
void SMDImporter::ParseNodeInfo(const char* szCurrent, const char** szCurrentOut) {
|
2015-05-19 03:57:13 +00:00
|
|
|
unsigned int iBone = 0;
|
|
|
|
SkipSpacesAndLineEnd(szCurrent,&szCurrent);
|
2018-11-30 21:17:42 +00:00
|
|
|
if ( !ParseUnsignedInt(szCurrent,&szCurrent,iBone) || !SkipSpaces(szCurrent,&szCurrent)) {
|
2015-05-19 03:57:13 +00:00
|
|
|
LogErrorNoThrow("Unexpected EOF/EOL while parsing bone index");
|
|
|
|
SMDI_PARSE_RETURN;
|
|
|
|
}
|
|
|
|
// add our bone to the list
|
2018-11-30 21:17:42 +00:00
|
|
|
if (iBone >= asBones.size()) {
|
|
|
|
asBones.resize(iBone+1);
|
|
|
|
}
|
2015-05-19 03:57:13 +00:00
|
|
|
SMD::Bone& bone = asBones[iBone];
|
|
|
|
|
|
|
|
bool bQuota = true;
|
2018-11-30 21:17:42 +00:00
|
|
|
if ('\"' != *szCurrent) {
|
2021-10-05 08:59:43 +00:00
|
|
|
LogWarning("Bone name is expected to be enclosed in "
|
2015-05-19 03:57:13 +00:00
|
|
|
"double quotation marks. ");
|
|
|
|
bQuota = false;
|
2018-11-30 21:17:42 +00:00
|
|
|
} else {
|
|
|
|
++szCurrent;
|
2015-05-19 03:57:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
const char* szEnd = szCurrent;
|
2018-11-30 21:17:42 +00:00
|
|
|
for ( ;; ) {
|
|
|
|
if (bQuota && '\"' == *szEnd) {
|
2015-05-19 03:57:13 +00:00
|
|
|
iBone = (unsigned int)(szEnd - szCurrent);
|
|
|
|
++szEnd;
|
|
|
|
break;
|
2018-11-30 21:17:42 +00:00
|
|
|
} else if (!bQuota && IsSpaceOrNewLine(*szEnd)) {
|
2015-05-19 03:57:13 +00:00
|
|
|
iBone = (unsigned int)(szEnd - szCurrent);
|
|
|
|
break;
|
2018-11-30 21:17:42 +00:00
|
|
|
} else if (!(*szEnd)) {
|
2015-05-19 03:57:13 +00:00
|
|
|
LogErrorNoThrow("Unexpected EOF/EOL while parsing bone name");
|
|
|
|
SMDI_PARSE_RETURN;
|
|
|
|
}
|
|
|
|
++szEnd;
|
|
|
|
}
|
|
|
|
bone.mName = std::string(szCurrent,iBone);
|
|
|
|
szCurrent = szEnd;
|
|
|
|
|
|
|
|
// the only negative bone parent index that could occur is -1 AFAIK
|
2018-11-30 21:17:42 +00:00
|
|
|
if(!ParseSignedInt(szCurrent,&szCurrent,(int&)bone.iParent)) {
|
2015-05-19 03:57:13 +00:00
|
|
|
LogErrorNoThrow("Unexpected EOF/EOL while parsing bone parent index. Assuming -1");
|
|
|
|
SMDI_PARSE_RETURN;
|
|
|
|
}
|
|
|
|
|
|
|
|
// go to the beginning of the next line
|
|
|
|
SMDI_PARSE_RETURN;
|
2015-05-19 03:48:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
// Parse a skeleton element
|
2018-11-30 21:17:42 +00:00
|
|
|
void SMDImporter::ParseSkeletonElement(const char* szCurrent, const char** szCurrentOut,int iTime) {
|
2015-05-19 03:57:13 +00:00
|
|
|
aiVector3D vPos;
|
|
|
|
aiVector3D vRot;
|
|
|
|
|
|
|
|
unsigned int iBone = 0;
|
2018-11-30 21:17:42 +00:00
|
|
|
if(!ParseUnsignedInt(szCurrent,&szCurrent,iBone)) {
|
2018-04-26 12:10:18 +00:00
|
|
|
ASSIMP_LOG_ERROR("Unexpected EOF/EOL while parsing bone index");
|
2015-05-19 03:57:13 +00:00
|
|
|
SMDI_PARSE_RETURN;
|
|
|
|
}
|
2018-11-30 21:17:42 +00:00
|
|
|
if (iBone >= asBones.size()) {
|
2015-05-19 03:57:13 +00:00
|
|
|
LogErrorNoThrow("Bone index in skeleton section is out of range");
|
|
|
|
SMDI_PARSE_RETURN;
|
|
|
|
}
|
|
|
|
SMD::Bone& bone = asBones[iBone];
|
|
|
|
|
2022-08-23 15:41:49 +00:00
|
|
|
bone.sAnim.asKeys.emplace_back();
|
2015-05-19 03:57:13 +00:00
|
|
|
SMD::Bone::Animation::MatrixKey& key = bone.sAnim.asKeys.back();
|
|
|
|
|
|
|
|
key.dTime = (double)iTime;
|
2018-11-30 21:17:42 +00:00
|
|
|
if(!ParseFloat(szCurrent,&szCurrent,(float&)vPos.x)) {
|
2015-05-19 03:57:13 +00:00
|
|
|
LogErrorNoThrow("Unexpected EOF/EOL while parsing bone.pos.x");
|
|
|
|
SMDI_PARSE_RETURN;
|
|
|
|
}
|
2018-11-30 21:17:42 +00:00
|
|
|
if(!ParseFloat(szCurrent,&szCurrent,(float&)vPos.y)) {
|
2015-05-19 03:57:13 +00:00
|
|
|
LogErrorNoThrow("Unexpected EOF/EOL while parsing bone.pos.y");
|
|
|
|
SMDI_PARSE_RETURN;
|
|
|
|
}
|
2018-11-30 21:17:42 +00:00
|
|
|
if(!ParseFloat(szCurrent,&szCurrent,(float&)vPos.z)) {
|
2015-05-19 03:57:13 +00:00
|
|
|
LogErrorNoThrow("Unexpected EOF/EOL while parsing bone.pos.z");
|
|
|
|
SMDI_PARSE_RETURN;
|
|
|
|
}
|
2018-11-30 21:17:42 +00:00
|
|
|
if(!ParseFloat(szCurrent,&szCurrent,(float&)vRot.x)) {
|
2015-05-19 03:57:13 +00:00
|
|
|
LogErrorNoThrow("Unexpected EOF/EOL while parsing bone.rot.x");
|
|
|
|
SMDI_PARSE_RETURN;
|
|
|
|
}
|
2018-11-30 21:17:42 +00:00
|
|
|
if(!ParseFloat(szCurrent,&szCurrent,(float&)vRot.y)) {
|
2015-05-19 03:57:13 +00:00
|
|
|
LogErrorNoThrow("Unexpected EOF/EOL while parsing bone.rot.y");
|
|
|
|
SMDI_PARSE_RETURN;
|
|
|
|
}
|
2018-11-30 21:17:42 +00:00
|
|
|
if(!ParseFloat(szCurrent,&szCurrent,(float&)vRot.z)) {
|
2015-05-19 03:57:13 +00:00
|
|
|
LogErrorNoThrow("Unexpected EOF/EOL while parsing bone.rot.z");
|
|
|
|
SMDI_PARSE_RETURN;
|
|
|
|
}
|
|
|
|
// build the transformation matrix of the key
|
2018-11-30 21:17:42 +00:00
|
|
|
key.matrix.FromEulerAnglesXYZ(vRot.x,vRot.y,vRot.z); {
|
2015-05-19 03:57:13 +00:00
|
|
|
aiMatrix4x4 mTemp;
|
|
|
|
mTemp.a4 = vPos.x;
|
|
|
|
mTemp.b4 = vPos.y;
|
|
|
|
mTemp.c4 = vPos.z;
|
2018-11-29 02:48:13 +00:00
|
|
|
key.matrix = mTemp * key.matrix;
|
2015-05-19 03:57:13 +00:00
|
|
|
}
|
2018-11-27 05:28:42 +00:00
|
|
|
key.vPos = vPos;
|
|
|
|
key.vRot = vRot;
|
2015-05-19 03:57:13 +00:00
|
|
|
// go to the beginning of the next line
|
|
|
|
SMDI_PARSE_RETURN;
|
2015-05-19 03:48:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
// Parse a triangle
|
2018-11-30 21:17:42 +00:00
|
|
|
void SMDImporter::ParseTriangle(const char* szCurrent, const char** szCurrentOut) {
|
2022-08-23 15:41:49 +00:00
|
|
|
asTriangles.emplace_back();
|
2015-05-19 03:57:13 +00:00
|
|
|
SMD::Face& face = asTriangles.back();
|
|
|
|
|
2018-11-30 21:17:42 +00:00
|
|
|
if(!SkipSpaces(szCurrent,&szCurrent)) {
|
2015-05-19 03:57:13 +00:00
|
|
|
LogErrorNoThrow("Unexpected EOF/EOL while parsing a triangle");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// read the texture file name
|
|
|
|
const char* szLast = szCurrent;
|
2016-12-12 20:22:03 +00:00
|
|
|
while (!IsSpaceOrNewLine(*++szCurrent));
|
2015-05-19 03:57:13 +00:00
|
|
|
|
|
|
|
// ... and get the index that belongs to this file name
|
|
|
|
face.iTexture = GetTextureIndex(std::string(szLast,(uintptr_t)szCurrent-(uintptr_t)szLast));
|
|
|
|
|
|
|
|
SkipSpacesAndLineEnd(szCurrent,&szCurrent);
|
|
|
|
|
|
|
|
// load three vertices
|
2022-08-23 10:59:42 +00:00
|
|
|
for (auto &avVertex : face.avVertices) {
|
|
|
|
ParseVertex(szCurrent,&szCurrent, avVertex);
|
2015-05-19 03:57:13 +00:00
|
|
|
}
|
|
|
|
*szCurrentOut = szCurrent;
|
2015-05-19 03:48:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
// Parse a float
|
2018-11-30 21:17:42 +00:00
|
|
|
bool SMDImporter::ParseFloat(const char* szCurrent, const char** szCurrentOut, float& out) {
|
|
|
|
if(!SkipSpaces(&szCurrent)) {
|
2015-05-19 03:57:13 +00:00
|
|
|
return false;
|
2018-11-30 21:17:42 +00:00
|
|
|
}
|
2015-05-19 03:48:29 +00:00
|
|
|
|
2015-05-19 03:57:13 +00:00
|
|
|
*szCurrentOut = fast_atoreal_move<float>(szCurrent,out);
|
|
|
|
return true;
|
2015-05-19 03:48:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
// Parse an unsigned int
|
2018-11-30 21:17:42 +00:00
|
|
|
bool SMDImporter::ParseUnsignedInt(const char* szCurrent, const char** szCurrentOut, unsigned int& out) {
|
|
|
|
if(!SkipSpaces(&szCurrent)) {
|
2015-05-19 03:57:13 +00:00
|
|
|
return false;
|
2018-11-30 21:17:42 +00:00
|
|
|
}
|
2015-05-19 03:48:29 +00:00
|
|
|
|
2015-05-19 03:57:13 +00:00
|
|
|
out = strtoul10(szCurrent,szCurrentOut);
|
|
|
|
return true;
|
2015-05-19 03:48:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
// Parse a signed int
|
2018-11-30 21:17:42 +00:00
|
|
|
bool SMDImporter::ParseSignedInt(const char* szCurrent, const char** szCurrentOut, int& out) {
|
|
|
|
if(!SkipSpaces(&szCurrent)) {
|
2015-05-19 03:57:13 +00:00
|
|
|
return false;
|
2018-11-30 21:17:42 +00:00
|
|
|
}
|
2015-05-19 03:48:29 +00:00
|
|
|
|
2015-05-19 03:57:13 +00:00
|
|
|
out = strtol10(szCurrent,szCurrentOut);
|
|
|
|
return true;
|
2015-05-19 03:48:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
// Parse a vertex
|
|
|
|
void SMDImporter::ParseVertex(const char* szCurrent,
|
2018-11-30 21:17:42 +00:00
|
|
|
const char** szCurrentOut, SMD::Vertex& vertex,
|
|
|
|
bool bVASection /*= false*/) {
|
|
|
|
if (SkipSpaces(&szCurrent) && IsLineEnd(*szCurrent)) {
|
2015-05-19 03:57:13 +00:00
|
|
|
SkipSpacesAndLineEnd(szCurrent,&szCurrent);
|
|
|
|
return ParseVertex(szCurrent,szCurrentOut,vertex,bVASection);
|
|
|
|
}
|
2018-11-30 21:17:42 +00:00
|
|
|
if(!ParseSignedInt(szCurrent,&szCurrent,(int&)vertex.iParentNode)) {
|
2015-05-19 03:57:13 +00:00
|
|
|
LogErrorNoThrow("Unexpected EOF/EOL while parsing vertex.parent");
|
|
|
|
SMDI_PARSE_RETURN;
|
|
|
|
}
|
2018-11-30 21:17:42 +00:00
|
|
|
if(!ParseFloat(szCurrent,&szCurrent,(float&)vertex.pos.x)) {
|
2015-05-19 03:57:13 +00:00
|
|
|
LogErrorNoThrow("Unexpected EOF/EOL while parsing vertex.pos.x");
|
|
|
|
SMDI_PARSE_RETURN;
|
|
|
|
}
|
2018-11-30 21:17:42 +00:00
|
|
|
if(!ParseFloat(szCurrent,&szCurrent,(float&)vertex.pos.y)) {
|
2015-05-19 03:57:13 +00:00
|
|
|
LogErrorNoThrow("Unexpected EOF/EOL while parsing vertex.pos.y");
|
|
|
|
SMDI_PARSE_RETURN;
|
|
|
|
}
|
2018-11-30 21:17:42 +00:00
|
|
|
if(!ParseFloat(szCurrent,&szCurrent,(float&)vertex.pos.z)) {
|
2015-05-19 03:57:13 +00:00
|
|
|
LogErrorNoThrow("Unexpected EOF/EOL while parsing vertex.pos.z");
|
|
|
|
SMDI_PARSE_RETURN;
|
|
|
|
}
|
2018-11-30 21:17:42 +00:00
|
|
|
if(!ParseFloat(szCurrent,&szCurrent,(float&)vertex.nor.x)) {
|
2015-05-19 03:57:13 +00:00
|
|
|
LogErrorNoThrow("Unexpected EOF/EOL while parsing vertex.nor.x");
|
|
|
|
SMDI_PARSE_RETURN;
|
|
|
|
}
|
2018-11-30 21:17:42 +00:00
|
|
|
if(!ParseFloat(szCurrent,&szCurrent,(float&)vertex.nor.y)) {
|
2015-05-19 03:57:13 +00:00
|
|
|
LogErrorNoThrow("Unexpected EOF/EOL while parsing vertex.nor.y");
|
|
|
|
SMDI_PARSE_RETURN;
|
|
|
|
}
|
2018-11-30 21:17:42 +00:00
|
|
|
if(!ParseFloat(szCurrent,&szCurrent,(float&)vertex.nor.z)) {
|
2015-05-19 03:57:13 +00:00
|
|
|
LogErrorNoThrow("Unexpected EOF/EOL while parsing vertex.nor.z");
|
|
|
|
SMDI_PARSE_RETURN;
|
|
|
|
}
|
|
|
|
|
2018-11-30 21:17:42 +00:00
|
|
|
if (bVASection) {
|
|
|
|
SMDI_PARSE_RETURN;
|
|
|
|
}
|
2015-05-19 03:57:13 +00:00
|
|
|
|
2018-11-30 21:17:42 +00:00
|
|
|
if(!ParseFloat(szCurrent,&szCurrent,(float&)vertex.uv.x)) {
|
2015-05-19 03:57:13 +00:00
|
|
|
LogErrorNoThrow("Unexpected EOF/EOL while parsing vertex.uv.x");
|
|
|
|
SMDI_PARSE_RETURN;
|
|
|
|
}
|
2018-11-30 21:17:42 +00:00
|
|
|
if(!ParseFloat(szCurrent,&szCurrent,(float&)vertex.uv.y)) {
|
2015-05-19 03:57:13 +00:00
|
|
|
LogErrorNoThrow("Unexpected EOF/EOL while parsing vertex.uv.y");
|
|
|
|
SMDI_PARSE_RETURN;
|
|
|
|
}
|
|
|
|
|
|
|
|
// now read the number of bones affecting this vertex
|
|
|
|
// all elements from now are fully optional, we don't need them
|
|
|
|
unsigned int iSize = 0;
|
2018-11-30 21:17:42 +00:00
|
|
|
if(!ParseUnsignedInt(szCurrent,&szCurrent,iSize)) {
|
|
|
|
SMDI_PARSE_RETURN;
|
|
|
|
}
|
2015-05-19 03:57:13 +00:00
|
|
|
vertex.aiBoneLinks.resize(iSize,std::pair<unsigned int, float>(0,0.0f));
|
|
|
|
|
2022-08-23 10:59:42 +00:00
|
|
|
for (auto &aiBoneLink : vertex.aiBoneLinks) {
|
|
|
|
if(!ParseUnsignedInt(szCurrent,&szCurrent,aiBoneLink.first)) {
|
2015-05-19 03:57:13 +00:00
|
|
|
SMDI_PARSE_RETURN;
|
2018-11-30 21:17:42 +00:00
|
|
|
}
|
2022-08-23 10:59:42 +00:00
|
|
|
if(!ParseFloat(szCurrent,&szCurrent,aiBoneLink.second)) {
|
2015-05-19 03:57:13 +00:00
|
|
|
SMDI_PARSE_RETURN;
|
2018-11-30 21:17:42 +00:00
|
|
|
}
|
2015-05-19 03:57:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// go to the beginning of the next line
|
|
|
|
SMDI_PARSE_RETURN;
|
2015-05-19 03:48:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#endif // !! ASSIMP_BUILD_NO_SMD_IMPORTER
|