Ejemplo n.º 1
0
    void DiMotionSerializerImpl::WriteAnimation( const DiAnimation* pkAnimation )
    {
        WriteChunkHeader(DI_ANIMATION,CalcAnimationSize(pkAnimation));

        // name
        WriteString(pkAnimation->GetName());

        // length
        float len = pkAnimation->GetLength();
        WriteFloats(&len, 1);

        auto trackIt = pkAnimation->GetNodeClipsIterator();
        while(trackIt.HasMoreElements())
        {
            WriteNodeClip(trackIt.GetNext());
        }

        auto attachIt = pkAnimation->GetAttachClipsIterator();
        while(attachIt.HasMoreElements())
        {
            DiNodeClip * pAttach = attachIt.GetNext();
            WriteAttachClip(pAttach);
        }

    }
Ejemplo n.º 2
0
    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);
        }
    }
Ejemplo n.º 3
0
    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());
            }
        }
    }
Ejemplo n.º 4
0
    void DiMotionSerializerImpl::WriteBoneParent( uint16 b0, uint16 bparent )
    {
        WriteChunkHeader(DI_BONES_PARENT,sizeof(uint16)*2 + MSTREAM_OVERHEAD_SIZE);

        WriteShorts(&b0, 1);

        WriteShorts(&bparent, 1);
    }
Ejemplo n.º 5
0
    void DiMeshSerializerImpl::WriteGeometry( DiSubMesh* pMesh )
    {
        WriteChunkHeader(DI_GEOMETRY, CalcGeometrySize(pMesh));

        uint32 vnum = pMesh->GetVerticeNum();
        WriteInts(&vnum,1);

        uint32 faces = pMesh->GetPrimitiveCount();
        WriteInts(&faces,1);

        WriteGeometryVertexDeclaration(pMesh);

        WriteGeometryVertexBuffer(pMesh);
    }
Ejemplo n.º 6
0
    void DiMeshSerializerImpl::WriteGeometryVertexBuffer( DiSubMesh* pMesh )
    {
        DiSubMesh::SourceDataIterator it = pMesh->GetSourceDataIterator();
        while (it.HasMoreElements())
        {
            DiSubMesh::SourceData sd = it.GetNext();

            size_t size = MSTREAM_OVERHEAD_SIZE;
            size += sizeof(uint16);
            size += sizeof(uint16);
            size += sd.GetSize();    

            WriteChunkHeader(DI_GEOMETRY_VERTEX_BUFFER,size);
            WriteShorts(&sd.stream,1);
            WriteShorts(&sd.stride,1);
            WriteData(sd.data,sd.GetSize(),1);
        }
    }
Ejemplo n.º 7
0
    void DiMeshSerializerImpl::WriteBoundsInfo( const DiMesh* pMesh )
    {
        unsigned long size = MSTREAM_OVERHEAD_SIZE;

        size += sizeof(float) * 6;
        WriteChunkHeader(DI_MESH_BOUNDS, size);

        const DiVec3& min = pMesh->GetBounds().GetMinimum();
        const DiVec3& max = pMesh->GetBounds().GetMaximum();

        WriteFloats(&min.x, 1);
        WriteFloats(&min.y, 1);
        WriteFloats(&min.z, 1);

        WriteFloats(&max.x, 1);
        WriteFloats(&max.y, 1);
        WriteFloats(&max.z, 1);
    }
Ejemplo n.º 8
0
    void DiMeshSerializerImpl::WriteSubMeshBoneWeights( DiSubMesh* pMesh )
    {
        const DiSubMesh::BoneWeightList& weights = pMesh->GetBoneWeights();

        uint32 weightsSize = weights.size();
        size_t chunkSize = MSTREAM_OVERHEAD_SIZE + sizeof(uint32) + weightsSize * sizeof(DiBoneWeight);
        
        WriteChunkHeader(DI_MESH_WEIGHTS, chunkSize);

        WriteInts(&weightsSize,1);

        DiSubMesh::BoneWeightList::const_iterator it;
        DiSubMesh::BoneWeightList::const_iterator itEnd = weights.end();

        for (it = weights.begin(); it != itEnd; ++it)
        {
            WriteInts(&it->second.vertexIndex,1);
            WriteShorts(&it->second.boneIndex,1);
            WriteFloats(&it->second.weight,1);
        }
    }
Ejemplo n.º 9
0
    void DiMeshSerializerImpl::WriteGeometryVertexDeclaration( DiSubMesh* pMesh )
    {
        DiVertexElements& ele = pMesh->GetVertexElements();

        uint32 elementNums = ele.GetNumVertexElements();

        WriteChunkHeader(DI_GEOMETRY_VERTEX_DECLARATION, MSTREAM_OVERHEAD_SIZE +
            4 * sizeof(uint16) * elementNums);

        for (uint32 i=0; i<elementNums; i++)
        {
            DiVertexElements::Element ve = ele.GetElement(i);
            UINT16 temp = ve.Stream;
            WriteShorts(&temp,1);
            temp = ve.Type;
            WriteShorts(&temp,1);
            temp = ve.Usage;
            WriteShorts(&temp,1);
            temp = ve.UsageIndex;
            WriteShorts(&temp,1);
        }
    }
Ejemplo n.º 10
0
    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());
            }
        }
    }
Ejemplo n.º 11
0
    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());
            }
        }
    }
Ejemplo n.º 12
0
    void DiMotionSerializerImpl::WriteSkeleton( const DiSkeleton* pSkeleton )
    {
        WriteChunkHeader(DI_SKELETON,sizeof(uint16) + MSTREAM_OVERHEAD_SIZE);

        uint16 blendmode = (uint16)pSkeleton->GetBlendMode();
        WriteShorts(&blendmode,1);

        if (pSkeleton->GetNumBones() > 0)
        {
            WriteBones(pSkeleton);
        }

        size_t numBones = pSkeleton->GetNumBones();
        for (size_t i = 0; i < numBones; ++i)
        {
            const DiBone* pBone = pSkeleton->GetBone(i);
            unsigned short handle = (uint16)pBone->GetHandle();
            DiBone* pParent = (DiBone*)pBone->GetParent(); 
            if (pParent != NULL) 
            {
                WriteBoneParent((uint16)handle, (uint16)pParent->GetHandle());             
            }
        }
    }