void DiMeshSerializerImpl::WriteSubMesh( DiSubMesh* pMesh ) { WriteChunkHeader(DI_SUBMESH, CalcSubMeshSize(pMesh)); WriteString(pMesh->GetMaterialName()); unsigned int indexCount = pMesh->GetIndexNum(); WriteInts(&indexCount,1); bool u32 = pMesh->GetIndexSize() == 32; WriteBools(&u32,1); uint16 primitive = (uint16)pMesh->GetPrimitiveType(); WriteShorts(&primitive,1); WriteData(pMesh->GetIndexData(), (pMesh->GetIndexSize() / 8) * pMesh->GetIndexNum(), 1); WriteGeometry(pMesh); if (!pMesh->mBoneWeights.empty()) { WriteSubMeshBoneWeights(pMesh); } }
void DiMotionSerializerImpl::WriteBones( const DiSkeleton* pSkeleton ) { WriteChunkHeader(DI_BONES,CalcBonesSize(pSkeleton)); uint16 numBones = (uint16)pSkeleton->GetNumBones(); WriteShorts(&numBones,1); for (size_t i = 0; i < numBones; ++i) { const DiBone* pBone = pSkeleton->GetBone(i); // name WriteString(pBone->GetName()); // handle uint16 handle = (uint16)pBone->GetHandle(); WriteShorts(&handle,1); // position WriteObject(pBone->GetPosition()); // orientation WriteObject(pBone->GetOrientation()); // �Ƿ���scale bool hasscale = pBone->GetScale() != DiVec3::UNIT_SCALE; WriteBools(&hasscale,1); if (hasscale) { // scale WriteObject(pBone->GetScale()); } } }
void DiMotionSerializerImpl::WriteAttachClip( const DiNodeClip* clip ) { DiAttachNode * attach = (DiAttachNode *)clip->GetTargetNode(); if (!attach) { DI_WARNING("No target node!"); return; } WriteChunkHeader(DI_CLIPS_ATTACH,CalcAttachClipSize(clip)); WriteString(attach->GetName()); uint16 keyFrameNum = (uint16) clip->GetNumFrames(); WriteShorts(&keyFrameNum,1); for (uint16 i = 0; i < keyFrameNum; ++i) { DiTransformKeyFrame* key = clip->GetNodeKeyFrame(i); float time = key->GetTime(); WriteFloats(&time, 1); WriteObject(key->GetTranslate()); WriteObject(key->GetRotation()); bool hasScale = key->GetScale() != DiVec3::UNIT_SCALE; WriteBools(&hasScale,1); if (hasScale) { WriteObject(key->GetScale()); } } }
void DiMotionSerializerImpl::WriteNodeClip( const DiNodeClip* pClip ) { DiBone* bone = (DiBone*)pClip->GetTargetNode(); if (!bone) { return; } WriteChunkHeader(DI_CLIPS_NODE,CalcNodeClipSize(pClip)); uint16 boneid = (uint16)bone->GetHandle(); WriteShorts(&boneid, 1); uint16 keyFrameNum = (uint16) pClip->GetNumFrames(); WriteShorts(&keyFrameNum,1); for (uint16 i = 0; i < keyFrameNum; ++i) { DiTransformKeyFrame* key = pClip->GetNodeKeyFrame(i); float time = key->GetTime(); WriteFloats(&time, 1); WriteObject(key->GetTranslate()); WriteObject(key->GetRotation()); bool hasScale = key->GetScale() != DiVec3::UNIT_SCALE; WriteBools(&hasScale,1); if (hasScale) { WriteObject(key->GetScale()); } } }