Esempio n. 1
0
bool CSkeletonCandidate::CreateFromSkeletonFile(const std::string& strFilename)
{
	// clear current content
	Clear();

	m_strFilename = strFilename;

	// create a core model instance
	CalCoreModel * coreModel = new CalCoreModel;

	if(!coreModel->createInternal("dummy"))
	{
		theExporter.SetLastErrorFromCal(__FILE__, __LINE__);
		return false;
	}

	// load the core skeleton instance
	if(!coreModel->loadCoreSkeleton(m_strFilename))
	{
		theExporter.SetLastErrorFromCal(__FILE__, __LINE__);
		coreModel->destroy();
		return false;
	}

	// get core skeleton
	CalCoreSkeleton *pCoreSkeleton;
	pCoreSkeleton = coreModel->getCoreSkeleton();
	
	// get core bone vector
	std::vector<CalCoreBone *>& vectorCoreBone = pCoreSkeleton->getVectorCoreBone();

	// loop through all root core bones
	std::list<int>::iterator iteratorRootCoreBoneId;
	for(iteratorRootCoreBoneId = pCoreSkeleton->getListRootCoreBoneId().begin(); iteratorRootCoreBoneId != pCoreSkeleton->getListRootCoreBoneId().end(); ++iteratorRootCoreBoneId)
	{
		// recursively add the core bone to the skeleton candidate
		if(!AddNode(pCoreSkeleton, vectorCoreBone[*iteratorRootCoreBoneId], -1))
		{
			coreModel->destroy();
			return false;
		}
	}

	// destroy core model
	m_coreModel = coreModel;
	return true;
}
Esempio n. 2
0
CalCoreModel *CharacterModel::loadConfig(std::string filename)
{
    PathHandler ph;
    std::string pfile;
    
    ph.setBaseFile(filename.c_str());
    
    // open the model configuration file
    std::ifstream file;
    file.open(filename.c_str(), std::ios::in | std::ios::binary);
    if(!file)
    {
        SWARNING << "Failed to open model configuration file '" 
                 << filename << "'." << endLog;
        return NULL;
    }

    CalCoreModel *model = new CalCoreModel("dummy");
    
    // parse all lines from the model configuration file
    int line;
    for(line = 1; ; line++)
    {
        // read the next model configuration line
        std::string strBuffer;
        std::getline(file, strBuffer);

        // stop if we reached the end of file
        if(file.eof()) break;

        // check if an error happend while reading from the file
        if(!file)
        {
            SWARNING << "Error while reading from the model configuration file '" 
                     << filename << "'." << endLog;
            return NULL;
        }

        // find the first non-whitespace character
        std::string::size_type pos;
        pos = strBuffer.find_first_not_of(" \t");

        // check for empty lines
        if((pos == std::string::npos) || (strBuffer[pos] == '\n') || 
           (strBuffer[pos] == '\r') || (strBuffer[pos] == 0)) 
            continue;

        // check for comment lines
        if(strBuffer[pos] == '#') continue;

        // get the key
        std::string strKey;
        strKey = strBuffer.substr(pos, strBuffer.find_first_of(" =\t\n\r", pos) - pos);
        pos += strKey.size();

        // get the '=' character
        pos = strBuffer.find_first_not_of(" \t", pos);
        if((pos == std::string::npos) || (strBuffer[pos] != '='))
        {
            SWARNING << filename << "(" << line << "): Invalid syntax." 
                     << endLog;
            return false;
        }

        // find the first non-whitespace character after the '=' character
        pos = strBuffer.find_first_not_of(" \t", pos + 1);

        // get the data
        std::string strData;
        strData = strBuffer.substr(pos, 
                            strBuffer.find_first_of("\n\r", pos) - pos);

        // handle the model creation
        if(strKey == "scale")
        {
            // set rendering scale factor
            //m_scale = atof(strData.c_str());
        }
        else if(strKey == "skeleton")
        {
            pfile = ph.findFile(strData.c_str());

            // load core skeleton
            SINFO << "Loading skeleton '" << pfile << "'..." << endLog;
            
            if(!model->loadCoreSkeleton(pfile.c_str()))
            {
                CalError::printLastError();
                return false;
            }
        }
        else if(strKey == "animation")
        {
            pfile = ph.findFile(strData.c_str());
            
            // load core animation
            SINFO << "Loading animation '" << pfile 
                  << "'..." << endLog;
            if(model->loadCoreAnimation(pfile.c_str()) == -1)
            {
                CalError::printLastError();
                return false;
            }
        }
        else if(strKey == "mesh")
        {
            pfile = ph.findFile(strData.c_str());

            // load core mesh
            SINFO << "Loading mesh '" << pfile << "'..." << endLog;
            if(model->loadCoreMesh(pfile.c_str()) == -1)
            {
                CalError::printLastError();
                return false;
            }
        }
        else if(strKey == "material")
        {
            pfile = ph.findFile(strData.c_str());

            // load core material
            SINFO << "Loading material '" << pfile << "'..." << endLog;
            if(model->loadCoreMaterial(pfile.c_str()) == -1)
            {
                CalError::printLastError();
                return false;
            }
        }
        else
        {
            // everything else triggers an error message, but is ignored
            SWARNING << filename << "(" << line << "): Invalid syntax." 
                     << endLog;
        }
    }

    // create material threads
    int mid;
    for(mid = 0; mid < model->getCoreMaterialCount(); mid++)
    {
        model->createCoreMaterialThread(mid);
        model->setCoreMaterialId(mid, 0, mid);
    }

    file.close();

    return model;
}