SkeletonAnimation* SkeletonAnimation::createWithData (spSkeletonData* skeletonData, bool ownsSkeletonData) {
	skeletonData->refCount++;
	skeletonData->ifRefed = 1;
	SkeletonAnimation* node = new SkeletonAnimation(skeletonData, ownsSkeletonData);
	node->autorelease();
	return node;
}
Example #2
0
bool CSmeltArmor::init()
{
	if (BaseLayer::init())
	{
		m_ui = LoadComponent("RinseItem.xaml");  //  
		m_ui->setPosition(VCENTER);
		this->addChild(m_ui);
		this->setIsShowBlack(false);
		
		m_attr = (CLayout*)m_ui->findWidgetById("attr");

		//获取cell
		m_pCellInfo = (CLayout*)m_ui->findWidgetById("cell_info");
		CC_SAFE_RETAIN(m_pCellInfo);
		m_pCellInfo->removeFromParentAndCleanup(false);

		CCPoint pBasePos = ccp(1281, 160);
		//初始化基础属性四条
		initItemInfo(pBasePos, m_pBaseInfo, 4);

		//添加动画
		SkeletonAnimation *pSkeletonAnimation = SkeletonAnimation::createWithFile("strengthen/5002.json", "strengthen/5002.atlas", 1);
		pSkeletonAnimation->setPosition(ccp(887, -2));
		pSkeletonAnimation->setAnimation(0, "stand", true);
		m_ui->addChild(pSkeletonAnimation, 3);
		m_pSpineHero = pSkeletonAnimation;

		return true;
	}
	return false;

}
Example #3
0
void MeshExporter::_dumpAnimation(IGameControl * pGameControl, int boneId)
{
	int start = ExportConfig::Instance()->GetFrameRange().x;
	int end = ExportConfig::Instance()->GetFrameRange().y;
	start *= GetTicksPerFrame();
	end *= GetTicksPerFrame();

	if ((pGameControl->IsAnimated(IGAME_POS)) || pGameControl->IsAnimated(IGAME_ROT) || pGameControl->IsAnimated(IGAME_SCALE))
	{
		IGameKeyTab Key;
		if(pGameControl->GetFullSampledKeys(Key, 1, IGAME_TM, true) )
		{
			SkeletonAnimation * skelAnim = new SkeletonAnimation(boneId);

			int count = Key.Count();
			for(int i=0;i<count;i++)
			{
				if (Key[i].t >= start && Key[i].t <= end)
				{
					float time = (float)Key[i].t / (float)GetTicksPerFrame() / (float)GetFrameRate();
					SkeletonAnimation::KeyFrame * kf = skelAnim->CreateKeyFrame(time);

					kf->position = Utility::ToFloat3(Key[i].sampleKey.gval.Translation());
					kf->rotation = Utility::ToQuat(Key[i].sampleKey.gval.Rotation());
					kf->scale = Utility::ToFloat3(Key[i].sampleKey.gval.Scaling());
				}
			}

			skelAnim->Optimize();
			_getAnimation()->AddSkeletonAnimation(skelAnim);
		}
	}
}
Example #4
0
SkeletonAnimation* SkeletonAnimation::createWithJsonFile (const std::string& skeletonJsonFile, const std::string& atlasFile, float scale) {
	SkeletonAnimation* node = new SkeletonAnimation();
	spAtlas* atlas = spAtlas_createFromFile(atlasFile.c_str(), 0);
	node->initWithJsonFile(skeletonJsonFile, atlas, scale);
	node->autorelease();
	return node;
}
Example #5
0
void SpineTest::testSimple(Object *sender)
{
	log("testSimple");
	
	SkeletonAnimation *node = SkeletonAnimation::createWithFile("player.json", "player.atlas");
    node->setAnimation(0, "walk", true);
	
	node->setPosition(Point(200, 200));

	addChild(node);
}
	bool BinaryParser< SkeletonAnimation >::doParse( SkeletonAnimation & obj )
	{
		bool result = true;
		SkeletonAnimationNodeSPtr node;
		SkeletonAnimationObjectSPtr object;
		SkeletonAnimationBoneSPtr bone;
		SkeletonAnimationKeyFrameUPtr keyFrame;
		String name;
		BinaryChunk chunk;

		while ( result && doGetSubChunk( chunk ) )
		{
			switch ( chunk.getChunkType() )
			{
			case ChunkType::eSkeletonAnimationNode:
				node = std::make_shared< SkeletonAnimationNode >( obj );
				result = BinaryParser< SkeletonAnimationNode >{}.parse( *node, chunk );

				if ( result )
				{
					obj.addObject( node, nullptr );
				}

				break;

			case ChunkType::eSkeletonAnimationBone:
				bone = std::make_shared< SkeletonAnimationBone >( obj );
				result = BinaryParser< SkeletonAnimationBone >{}.parse( *bone, chunk );

				if ( result )
				{
					obj.addObject( bone, nullptr );
				}

				break;

			case ChunkType::eSkeletonAnimationKeyFrame:
				keyFrame = std::make_unique< SkeletonAnimationKeyFrame >( obj );
				result = BinaryParser< SkeletonAnimationKeyFrame >{}.parse( *keyFrame, chunk );

				if ( result )
				{
					obj.addKeyFrame( std::move( keyFrame ) );
				}

				break;
			}
		}

		return result;
	}
Example #7
0
void Skeleton::playAnimation(const String& animName, bool once) {
	SkeletonAnimation *anim = getAnimation(animName);
	if(!anim)
		return;
	
	if(anim == currentAnimation && !once)
		return;
	
	if(currentAnimation)
		currentAnimation->Stop();
		
	currentAnimation = anim;
	anim->Play(once);
}
Example #8
0
	void TrapObject::initSpineTrap()
	{
		SpineData* tData = SpineManage->getSpineData(ToString(mData->getTrapModel()));
		if (!tData)
		{
			tData = SpineManage->getSpineData("10000");
			CCLOG("[ *ERROR ]  TrapObject::init Spine Model=%d IS NULL",mData->getTrapModel()); 
		}
		SkeletonAnimation*  Animation = SkeletonAnimation::createWithData(tData->first);
		CCAssert(Animation,"TrapObject::init Spine NULL");
		Animation->setAnimation(0,"standby",true);
		Animation->setRotation(mData->getRotation());
		mTrapNode = Animation;
		this->addChild(mTrapNode);
	}
		void SkeletonAnimationManager::ReloadAssets()
		{
			Engine *eng = Engine::Get();

			const ResourcePool<SkeletonAnimation>::Iterator end = resPool->End();
			for(ResourcePool<SkeletonAnimation>::Iterator iter = resPool->Begin(); iter != end; ++iter) {
				SkeletonAnimation *skelAnim = iter.Ptr();
				Rid rid = skelAnim->rid;
				if(rid != RID_NONE) {
					skelAnim->~SkeletonAnimation();
					new(skelAnim) SkeletonAnimation();
					skelAnim->Load(rid);
				}
			}
		}
		bool SkeletonAnimationManager::ReloadAsset(Rid rid)
		{
			Handle handle = resPool->Match(Resource::FindPredicate<SkeletonAnimation>(rid)) | managerId;
			if(handle == HANDLE_NONE) {
				return false;
			}
			SkeletonAnimation *skelAnim = resPool->Get(handle & HANDLE_VALUE_MASK);
			resPool->Free(handle & HANDLE_VALUE_MASK);

			if(rid != RID_NONE) {
				skelAnim->~SkeletonAnimation();
				new(skelAnim) SkeletonAnimation();
				return skelAnim->Load(rid);
			}
			return true;
		}
Example #11
0
// draw all children to batch. Recursive iteration not support yet.
void SpineBatchNode::onDrawSkeletonBatch(const Mat4 &transform, uint32_t transformFlags) {
    getGLProgramState()->apply(transform);
    
    if (Configuration::getInstance()->supportsShareableVAO())
    {
        _batch->setupVBOAndVAO();
    }
    
    for (auto child : _children) {
        SkeletonAnimation *skeletonNode = static_cast<SkeletonAnimation*>(child);
        if (skeletonNode) {
            skeletonNode->onDrawSkeleton(_batch);
        }
    }
    _batch->flush();
}
Example #12
0
void Skeleton::playAnimationByIndex(int index, bool once) {
	if(index > animations.size()-1)
		return;
		
	SkeletonAnimation *anim = animations[index];
	if(!anim)
		return;
	
	if(anim == currentAnimation && !once)
		return;
	
	if(currentAnimation)
		currentAnimation->Stop();
	
	currentAnimation = anim;
	anim->Play(once);	
}
		Handle SkeletonAnimationManager::Load(Rid rid)
		{
			Handle handle = resPool->Match(Resource::FindPredicate<SkeletonAnimation>(rid)) | managerId;
			if(handle != HANDLE_NONE) {
				return handle;
			}

			handle = resPool->Alloc() | managerId;
			SkeletonAnimation *skelAnim = resPool->Get(handle & HANDLE_VALUE_MASK);
			new(skelAnim) SkeletonAnimation();
		
			if(!skelAnim->Load(rid)) {
				resPool->Free(handle & HANDLE_VALUE_MASK);
				return HANDLE_NONE;
			}
			return handle;
		}
Example #14
0
void SpineTest::testChangeAnimation(Object *sender)
{
	log("testChangeAnimation");
	
	// Setting the Animation
	SkeletonAnimation *node = SkeletonAnimation::createWithFile("player.json", "player.atlas");
    node->setAnimation(0, "walk", true);
	node->setPosition(Point(200, 120));
	node->setTag(kTagSpinePlayer);
	addChild(node);
	mAnime = node;
	
	// Setting the buttons
	std::vector<Node *> nodeArray;
	ControlButton *button;
	
	button = GUIHelper::createButton("Walk", this, cccontrol_selector(SpineTest::changeAnime), Point(0, 0));
	button->setTag(kTagButtonWalk);
	nodeArray.push_back(button);
	
	button = GUIHelper::createButton("Jump", this, cccontrol_selector(SpineTest::changeAnime), Point(0, 0));
	button->setTag(kTagButtonJump);
	nodeArray.push_back(button);

	button = GUIHelper::createButton("Hurt", this, cccontrol_selector(SpineTest::changeAnime), Point(0, 0));
	button->setTag(kTagButtonHurt);
	nodeArray.push_back(button);

	button = GUIHelper::createButton("Idle", this, cccontrol_selector(SpineTest::changeAnime), Point(0, 0));
	button->setTag(kTagButtonIdle);
	nodeArray.push_back(button);

	GUIHelper::addNodesToParent(this, nodeArray, 0, 50, 480, 10);
	
	
	// hide the menu
	hideMenu();
}
bool BatchingExample::init () {
	if (!LayerColor::initWithColor(Color4B(128, 128, 128, 255))) return false;

	// To avoid the SkeletonBatch buffer from being resized, set this to the number of vertices ever rendered in one frame.
	// BatchingExample needs ~3200, but let's set it low to test the buffer resizing.
	SkeletonBatch::setBufferSize(512);

	// Load the texture atlas.
	_atlas = spAtlas_createFromFile("spineboy.atlas", 0);
	CCASSERT(_atlas, "Error reading atlas file.");

	// This attachment loader configures attachments with data needed for cocos2d-x rendering.
	// Do not dispose the attachment loader until the skeleton data is disposed!
	_attachmentLoader = (spAttachmentLoader*)Cocos2dAttachmentLoader_create(_atlas);

	// Load the skeleton data.
	spSkeletonJson* json = spSkeletonJson_createWithLoader(_attachmentLoader);
	json->scale = 0.6f; // Resizes skeleton data to 60% of the size it was in Spine.
	_skeletonData = spSkeletonJson_readSkeletonDataFile(json, "spineboy.json");
	CCASSERT(_skeletonData, json->error ? json->error : "Error reading skeleton data file.");
	spSkeletonJson_dispose(json);

	// Setup mix times.
	_stateData = spAnimationStateData_create(_skeletonData);
	spAnimationStateData_setMixByName(_stateData, "walk", "jump", 0.2f);
	spAnimationStateData_setMixByName(_stateData, "jump", "run", 0.2f);

	int xMin = _contentSize.width * 0.10f, xMax = _contentSize.width * 0.90f;
	int yMin = 0, yMax = _contentSize.height * 0.7f;
	for (int i = 0; i < 50; i++) {
		// Each skeleton node shares the same atlas, skeleton data, and mix times.
		SkeletonAnimation* skeletonNode = SkeletonAnimation::createWithData(_skeletonData, false);
		skeletonNode->setAnimationStateData(_stateData);

		skeletonNode->setAnimation(0, "walk", true);
		skeletonNode->addAnimation(0, "jump", false, 3);
		skeletonNode->addAnimation(0, "run", true);

		skeletonNode->setPosition(Vec2(
			RandomHelper::random_int(xMin, xMax),
			RandomHelper::random_int(yMin, yMax)
		));
		addChild(skeletonNode);
	}

	scheduleUpdate();

	EventListenerTouchOneByOne* listener = EventListenerTouchOneByOne::create();
	listener->onTouchBegan = [this] (Touch* touch, Event* event) -> bool {
		Director::getInstance()->replaceScene(SpineboyExample::scene());
		return true;
	};
	_eventDispatcher->addEventListenerWithSceneGraphPriority(listener, this);

	return true;
}
void SkeletonAnimationKeysChart::setAnimation( SkeletonAnimation& animation )
{
   // clear the charts
   for ( ChartsMap::iterator it = m_charts.begin(); it != m_charts.end(); ++it )
   {
      delete it->second;
   }
   m_charts.clear();

   // set the new animation
   m_animation = &animation;

   // set the time range
   float animLength = animation.getAnimationLength();
   float maxVal = 100.0f * ANIMATION_VALUE_SCALE; // we can edit an animation up to 100 meters - should be more than enough
   setSceneRect( 0, -maxVal, animLength * ANIMATION_TIME_SCALE, 2.0f * maxVal );
}
Example #17
0
SkeletonAnimation* SkeletonAnimation::createWithFile (const std::string& skeletonDataFile, const std::string& atlasFile, float scale) {
	SkeletonAnimation* node = new SkeletonAnimation(skeletonDataFile, atlasFile, scale);
	node->autorelease();
	return node;
}
Example #18
0
SkeletonAnimation* SkeletonAnimation::createWithData (spSkeletonData* skeletonData) {
	SkeletonAnimation* node = new SkeletonAnimation(skeletonData);
	node->autorelease();
	return node;
}
Example #19
0
void Skeleton::addAnimation(const String& name, const String& fileName) {

    OSFILE *inFile = OSBasics::open(fileName.c_str(), "rb");
    
    if(!inFile) {
		return;
	}
	
    unsigned int activeBones,numPoints,numCurves, curveType;
    float length;
    OSBasics::read(&length, 1, sizeof(float), inFile);

    SkeletonAnimation *newAnimation = new SkeletonAnimation(name, length);
    OSBasics::read(&activeBones, sizeof(unsigned int), 1, inFile);
    
    unsigned short boneNameLen;
    char boneNameBuffer[1024];

    for(int j=0; j < activeBones; j++) {
        
        OSBasics::read(&boneNameLen, sizeof(unsigned short), 1, inFile);
        OSBasics::read(boneNameBuffer, 1, boneNameLen, inFile);
        boneNameBuffer[boneNameLen] = '\0';
        
        Bone *trackBone = getBoneByName(boneNameBuffer);
        if(!trackBone) {
            printf("WARNING, INVALID BONE NAME: %s\n", boneNameBuffer);
            continue;
        }
        
        BoneTrack *newTrack = new BoneTrack(trackBone, length);
        
        BezierCurve *curve;
        float vec1[2];
        
        OSBasics::read(&numCurves, sizeof(unsigned int), 1, inFile);
        for(int l=0; l < numCurves; l++) {
            curve = new BezierCurve();
            OSBasics::read(&curveType, sizeof(unsigned int), 1, inFile);
            OSBasics::read(&numPoints, sizeof(unsigned int), 1, inFile);
            
            for(int k=0; k < numPoints; k++) {
                OSBasics::read(vec1, sizeof(float), 2, inFile);					
                curve->addControlPoint2d(vec1[1], vec1[0]);
            }
            switch(curveType) {
                case 0:
                    newTrack->scaleX = curve;
                    break;
                case 1:
                    newTrack->scaleY = curve;
                    break;
                case 2:
                    newTrack->scaleZ = curve;					
                    break;
                case 3:
                    newTrack->QuatW = curve;					
                    break;
                case 4:
                    newTrack->QuatX = curve;					
                    break;
                case 5:
                    newTrack->QuatY = curve;					
                    break;
                case 6:
                    newTrack->QuatZ = curve;					
                    break;
                case 7:;
                    newTrack->LocX = curve;					
                    break;
                case 8:
                    newTrack->LocY = curve;					
                    break;
                case 9:
                    newTrack->LocZ = curve;					
                    break;
            }
        }
        newAnimation->addBoneTrack(newTrack);
    }
    
    animations.push_back(newAnimation);
	OSBasics::close(inFile);	
}
Example #20
0
SkeletonAnimation* SkeletonAnimation::createWithFile (const char* skeletonDataFile, spAtlas* atlas, float scale) {
	SkeletonAnimation* node = new SkeletonAnimation(skeletonDataFile, atlas, scale);
	node->autorelease();
	return node;
}
Example #21
0
	bool AnimationController::Update(Mesh * mesh, float elapsedTime)
	{
		float lastPosition = mPosition;

		mPosition += elapsedTime * mBlendInfo.Speed;

		if (!IsBlendOut())
		{
			if (mWeightBlendInDelta == 0)
			{
				mWeight = 1;
			}
			else
			{
				mWeight += elapsedTime * mWeightBlendInDelta;

				if (mWeight >= 1)
				{
					mWeight = 1;
					mWeightBlendInDelta = 0;
				}
			}
		}
		else
		{
			if (mWeight == 0)
				return false;

			if (mWeightBlendOutDelta > 0)
			{
				mWeight -= elapsedTime * mWeightBlendOutDelta;
				mWeight = Max(0.0f, mWeight);
			}
		}
		
		//
		if (mCatchedAnim == NULL && mesh->GetSource() != NULL)
		{
			mCatchedAnim = mesh->GetSource()->GetAnimation(mName.c_str());
			if (mCatchedAnim == NULL)
				return true;

			mSkelAnimLastKeys.Resize(mCatchedAnim->GetSkeletonAnimationCount());
			for (int i = 0; i < mSkelAnimLastKeys.Size(); ++i)
				mSkelAnimLastKeys[i] = -1;
		}

		if (mCatchedAnim != NULL)
		{
			float length = mCatchedAnim->GetLength();

			if (mPosition >= length)
			{
				if (mBlendInfo.Looped)
				{
					while (mPosition > length)
						mPosition -= length;

					for (int i = 0; i < mSkelAnimLastKeys.Size(); ++i)
						mSkelAnimLastKeys[i] = -1;
				}
				else
				{
					mPosition = length;
					return false;
				}
			}

			for (int i = 0; i < mCatchedAnim->GetEventCount(); ++i)
			{
				Animation::Event * e = mCatchedAnim->GetEvent(i);
				if (e->time > lastPosition && e->time <= mPosition)
					E_Event(e);
			}

			Skeleton * skel = mesh->GetSkeleton().c_ptr();
			if (skel != NULL && !mesh->IsSkeletonShared())
			{
				for (int i = 0; i < mCatchedAnim->GetSkeletonAnimationCount(); ++i)
				{
					SkeletonAnimation * skelAnim = mCatchedAnim->GetSkeletonAnimation(i);

					skelAnim->Update(skel, this, mSkelAnimLastKeys[i]);
				}
			}
		}

		return true;
	}
Example #22
0
void Skeleton::addAnimation(const String& name, const String& fileName) {
	OSFILE *inFile = OSBasics::open(fileName.c_str(), "rb");
	if(!inFile) {
		return;
	}
	
		unsigned int activeBones,boneIndex,numPoints,numCurves, curveType;	
		float length;
		OSBasics::read(&length, 1, sizeof(float), inFile);
		SkeletonAnimation *newAnimation = new SkeletonAnimation(name, length);
		
		OSBasics::read(&activeBones, sizeof(unsigned int), 1, inFile);
		
		//	Logger::log("activeBones: %d\n", activeBones);		
		for(int j=0; j < activeBones; j++) {
			OSBasics::read(&boneIndex, sizeof(unsigned int), 1, inFile);
			BoneTrack *newTrack = new BoneTrack(bones[boneIndex], length);
			
			BezierCurve *curve;
			float vec1[2]; //,vec2[2],vec3[2];
			
			OSBasics::read(&numCurves, sizeof(unsigned int), 1, inFile);
			//			Logger::log("numCurves: %d\n", numCurves);					
			for(int l=0; l < numCurves; l++) {
				curve = new BezierCurve();
				OSBasics::read(&curveType, sizeof(unsigned int), 1, inFile);
				OSBasics::read(&numPoints, sizeof(unsigned int), 1, inFile);
				for(int k=0; k < numPoints; k++) {					
					OSBasics::read(vec1, sizeof(float), 2, inFile);					
					curve->addControlPoint2d(vec1[1], vec1[0]);
					//					curve->addControlPoint(vec1[1]-10, vec1[0], 0, vec1[1], vec1[0], 0, vec1[1]+10, vec1[0], 0);
				}
				switch(curveType) {
					case 0:
						newTrack->scaleX = curve;
						break;
					case 1:
						newTrack->scaleY = curve;
						break;
					case 2:
						newTrack->scaleZ = curve;					
						break;
					case 3:
						newTrack->QuatW = curve;					
						break;
					case 4:
						newTrack->QuatX = curve;					
						break;
					case 5:
						newTrack->QuatY = curve;					
						break;
					case 6:
						newTrack->QuatZ = curve;					
						break;
					case 7:;
						newTrack->LocX = curve;					
						break;
					case 8:
						newTrack->LocY = curve;					
						break;
					case 9:
						newTrack->LocZ = curve;					
						break;
				}
			}
			
			newAnimation->addBoneTrack(newTrack);
		}
		animations.push_back(newAnimation);
	
	
	OSBasics::close(inFile);	
}
Example #23
0
SkeletonAnimation* SkeletonAnimation::createWithBinaryFile (const std::string& skeletonBinaryFile, spAtlas* atlas, float scale) {
	SkeletonAnimation* node = new SkeletonAnimation();
	node->initWithBinaryFile(skeletonBinaryFile, atlas, scale);
	node->autorelease();
	return node;
}