//---------------------------------------------------------------------
    size_t SkeletonSerializer::calcAnimationSize(const Skeleton* pSkel, const Animation* pAnim, SkeletonVersion ver)
    {
        size_t size = SSTREAM_OVERHEAD_SIZE;

        // Name, including terminator
        size += calcStringSize(pAnim->getName());
        // length
        size += sizeof(float);

        if ((int)ver > (int)SKELETON_VERSION_1_0)
        {
            if (pAnim->getUseBaseKeyFrame())
            {
                size += SSTREAM_OVERHEAD_SIZE;
                // char* baseAnimationName (including terminator)
                size += calcStringSize(pAnim->getBaseKeyFrameAnimationName());
                // float baseKeyFrameTime
                size += sizeof(float);
            }
        }

        // Nested animation tracks
        Animation::NodeTrackIterator trackIt = pAnim->getNodeTrackIterator();
        while(trackIt.hasMoreElements())
        {
            size += calcAnimationTrackSize(pSkel, trackIt.getNext());
        }

        return size;
    }
	size_t LodConfigSerializer::calcLodBasicInfoSize()
	{
		size_t size = calcChunkHeaderSize();

		size += calcStringSize(mLodConfig->mesh->getGroup());
		size += calcStringSize(mLodConfig->mesh->getName());
		size += calcStringSize(mLodConfig->strategy->getName());

		return size;
	}
    //---------------------------------------------------------------------
    void SkeletonSerializer::readBone(DataStreamPtr& stream, Skeleton* pSkel)
    {
        // char* name
        String name = readString(stream);
        // unsigned short handle            : handle of the bone, should be contiguous & start at 0
        unsigned short handle;
        readShorts(stream, &handle, 1);

        // Create new bone
        Bone* pBone = pSkel->createBone(name, handle);

        // Vector3 position                 : position of this bone relative to parent 
        Vector3 pos;
        readObject(stream, pos);
        pBone->setPosition(pos);
        // Quaternion orientation           : orientation of this bone relative to parent 
        Quaternion q;
        readObject(stream, q);
        pBone->setOrientation(q);

#if OGRE_SERIALIZER_VALIDATE_CHUNKSIZE
        // Hack to fix chunk size validation:
        mChunkSizeStack.back() += calcStringSize(name);
#endif
        // TODO: don't depend on mCurrentstreamLen in next skeleton format!
        // Currently we use wrong chunk sizes, but we can't fix it, because we depend on mCurrentstreamLen
        // Do we have scale?
        if (mCurrentstreamLen > calcBoneSizeWithoutScale(pSkel, pBone))
        {
            Vector3 scale;
            readObject(stream, scale);
            pBone->setScale(scale);
        }
        
    }
Example #4
0
  temp<String> String::create(const char* text, int length)
  {
    if (length == -1) length = strlen(text);

    // Allocate enough memory for the string and its character array.
    void* mem = Memory::allocate(calcStringSize(length));
    // Construct it by calling global placement new.
    return Memory::makeTemp(::new(mem) String(text, length));
  }
    //---------------------------------------------------------------------
    void SkeletonSerializer::writeAnimation(const Skeleton* pSkel, 
        const Animation* anim, SkeletonVersion ver)
    {
        writeChunkHeader(SKELETON_ANIMATION, calcAnimationSize(pSkel, anim, ver));

        // char* name                       : Name of the animation
        writeString(anim->getName());
        // float length                      : Length of the animation in seconds
        float len = anim->getLength();
        writeFloats(&len, 1);
        pushInnerChunk(mStream);
        {
        if ((int)ver > (int)SKELETON_VERSION_1_0)
        {
            if (anim->getUseBaseKeyFrame())
            {
                size_t size = SSTREAM_OVERHEAD_SIZE;
                // char* baseAnimationName (including terminator)
                    size += calcStringSize(anim->getBaseKeyFrameAnimationName());
                // float baseKeyFrameTime
                size += sizeof(float);
                
                writeChunkHeader(SKELETON_ANIMATION_BASEINFO, size);
                
                // char* baseAnimationName (blank for self)
                writeString(anim->getBaseKeyFrameAnimationName());
                
                // float baseKeyFrameTime
                float t = (float)anim->getBaseKeyFrameTime();
                writeFloats(&t, 1);
            }
        }

        // Write all tracks
        Animation::NodeTrackIterator trackIt = anim->getNodeTrackIterator();
        while(trackIt.hasMoreElements())
        {
            writeAnimationTrack(pSkel, trackIt.getNext());
        }
        }
        popInnerChunk(mStream);

    }
    //---------------------------------------------------------------------
    void SkeletonSerializer::writeBone(const Skeleton* pSkel, const Bone* pBone)
    {
        writeChunkHeader(SKELETON_BONE, calcBoneSize(pSkel, pBone));

        unsigned short handle = pBone->getHandle();
        // char* name
        writeString(pBone->getName());
#if OGRE_SERIALIZER_VALIDATE_CHUNKSIZE
        // Hack to fix chunk size validation:
        mChunkSizeStack.back() += calcStringSize(pBone->getName());
#endif
        // unsigned short handle            : handle of the bone, should be contiguous & start at 0
        writeShorts(&handle, 1);
        // Vector3 position                 : position of this bone relative to parent 
        writeObject(pBone->getPosition());
        // Quaternion orientation           : orientation of this bone relative to parent 
        writeObject(pBone->getOrientation());
        // Vector3 scale                    : scale of this bone relative to parent 
        if (pBone->getScale() != Vector3::UNIT_SCALE)
        {
            writeObject(pBone->getScale());
        }
    }
	size_t LodConfigSerializer::calcLodLevelsSize()
	{
		//lodLevel.distance
		size_t levelSize = sizeof(float);

		//lodLevel.reductionMethod;
		levelSize += sizeof(Ogre::uint32);

		//lodLevel.reductionValue;
		levelSize += sizeof(float);

		size_t size = calcChunkHeaderSize();

		// mLodConfig->levels.size()
		size += sizeof(Ogre::uint32);

		size += levelSize * mLodConfig->levels.size();

		for(size_t i = 0; i < mLodConfig->levels.size(); i++) {
			size += calcStringSize(mLodConfig->levels[i].manualMeshName);
		}

		return size;
	}