コード例 #1
0
ArmatureData *DataReaderHelper::decodeArmature(TiXmlElement *_armatureXML)
{
    const char*	_name = _armatureXML->Attribute(A_NAME);
    
    
    ArmatureData *_armatureData = ArmatureData::create();
    _armatureData->setName(_name);
    //m_pArmarureDatas->setObject(_armatureData, _name);
    
    
    TiXmlElement* _boneXML = _armatureXML->FirstChildElement(BONE);
    
    while( _boneXML )
    {
        /*
         *  If this bone have parent, then get the parent bone xml
         */
        const char *_parentName = _boneXML->Attribute(A_PARENT);
        TiXmlElement *_parentXML = NULL;
        if (_parentName)
        {
            _parentXML = _armatureXML->FirstChildElement(BONE);
            std::string _name = _parentName;
            while (_parentXML)
            {
                if (_name.compare(_parentXML->Attribute(A_NAME)) == 0)
                {
                    break;
                }
                _parentXML = _parentXML->NextSiblingElement(BONE);
            }
        }
        
        BoneData *_boneData = decodeBone(_boneXML, _parentXML);
        _armatureData->addBoneData(_boneData);
        
        _boneXML = _boneXML->NextSiblingElement(BONE);
    }
  
    return _armatureData;
}
コード例 #2
0
CCArmatureData *CCDataReaderHelper::decodeArmature(tinyxml2::XMLElement *armatureXML)
{
    const char	*name = armatureXML->Attribute(A_NAME);


    CCArmatureData *armatureData = CCArmatureData::create();
    armatureData->name = name;


    tinyxml2::XMLElement *boneXML = armatureXML->FirstChildElement(BONE);

    while( boneXML )
    {
        /*
        *  If this bone have parent, then get the parent bone xml
        */
        const char *parentName = boneXML->Attribute(A_PARENT);
        tinyxml2::XMLElement *parentXML = NULL;
        if (parentName)
        {
            parentXML = armatureXML->FirstChildElement(BONE);
            std::string name = parentName;
            while (parentXML)
            {
                if (name.compare(parentXML->Attribute(A_NAME)) == 0)
                {
                    break;
                }
                parentXML = parentXML->NextSiblingElement(BONE);
            }
        }

        CCBoneData *boneData = decodeBone(boneXML, parentXML);
        armatureData->addBoneData(boneData);

        boneXML = boneXML->NextSiblingElement(BONE);
    }

    return armatureData;
}
コード例 #3
0
CCArmatureData *CCDataReaderHelper::decodeArmature(cs::CSJsonDictionary &json)
{
    CCArmatureData *armatureData = CCArmatureData::create();

    const char *name = json.getItemStringValue(A_NAME);
    if(name != NULL)
    {
        armatureData->name = name;
    }

	s_CocoStudioVersion = armatureData->dataVersion = json.getItemFloatValue(VERSION, 0.1f);

    int length = json.getArrayItemCount(BONE_DATA);
    for (int i = 0; i < length; i++)
    {
        cs::CSJsonDictionary *dic = json.getSubItemFromArray(BONE_DATA, i);
        armatureData->addBoneData(decodeBone(*dic));

        delete dic;
    }

    return armatureData;
}
コード例 #4
0
ファイル: Mz.cpp プロジェクト: cpzhang/zen
bool Mz::load( const std::string& fileName )
{
	//
	destroy();

	mzFileName_ = fileName;
	std::string mziFileName(fileName + "i");
	mziFileName = FileSystem::standardFilePath(mziFileName);
	loadMzI(mziFileName);
	//
	std::ifstream f(fileName.c_str(), std::ios::binary);
	if (!f.good())
	{
		return NULL;
	}

	//	[Tag Size Data]
	int t;
	int s;
	while(f.good())
	{
		t = 0;
		s = 0;
		f.read((char*)&t, sizeof(int));
		f.read((char*)&s, sizeof(int));

		if (s <= 0)
		{
			continue;
		}

		char c[5];
		c[0] = *((char*)&t + 3);
		c[1] = *((char*)&t + 2);
		c[2] = *((char*)&t + 1);
		c[3] = *((char*)&t + 0);
		c[4] = 0;

		switch (t)
		{
		case 'MVER':
			{
				decodeVersion(f, s);
			}
			break;

		case 'MSUB':
			{
				decodeSubMesh(f, s);
			}
			break;
		case 'MVTX':
			{
				decodeVertices(f, s);
			}
			break;
		case 'MFAC':
			{
				decodeFaces(f, s);
			}
			break;
		case 'MMTX': // 模型的材质
			{
				decodeMaterial(f, s);
			}
			break;
		case 'MANM':
			{
				decodeAnimation(f, s);
			}
			break;
		case 'MWRD': 
			{
				//废弃
				u32 numBones;
				f.read((char*)&numBones,sizeof(numBones));

				struct tranMatrix
				{
					float m_mat[4][3];
				};
				for(int i = 0;i < numBones;i++)
				{
					tranMatrix tm;
					f.read((char*)&tm,sizeof(tm));
				}
			}
			break;
		case 'MBON': // 模型骨骼信息
			{
				decodeBone(f, s);
			}
			break;
		default:
			{
				f.ignore(s);
				//Error("遇到无法识别的数据块");
			}
			break;
		}
	}
	f.close();
	//
	if (!mParticleEmitter.empty())
	{
		tstring n = FileSystem::removeParent(mzFileName_);
		n = FileSystem::removeFileExtension(n);
		tstring fn = FileSystem::getDataDirectory();
		std::ostringstream ss;
		for (size_t i = 0; i != mParticleEmitter.size(); ++i)
		{
			ss.str("");
			ss.clear();
			ss<<fn<<"\\particle\\"<<n<<"_"<<i<<".particle";
			mParticleEmitter[i].save(ss.str());
		}
	}
	return true;
}