Beispiel #1
0
// creates a node tree that matches the current scene and animation
AnimationNode* Animator::CreateNodeTree(aiNode* node, AnimationNode* parent)
{
    //create a node
    AnimationNode* internalNode = new AnimationNode(node->mName.data);
    internalNode->parent = parent;
    mapNodesByName[node] = internalNode;
    
    //copy its transformation
    internalNode->localTransform = node->mTransformation;
    CalculateGlobalTransform(internalNode);
    
    //find the index of the animation track affecting this node, if any
    if (currentAnimationIndex < mainScene->mNumAnimations)
    {
        internalNode->channelIndex = -1;
        
        for (unsigned int i = 0; i < currentAnimation->mNumChannels; i++)
        {
            if (currentAnimation->mChannels[i]->mNodeName.data == internalNode->name)
            {
                internalNode->channelIndex = i;
                break;
            }
        }
    }
    
    //continue for all child nodes and assign the created internal nodes as our children
    for (unsigned int i = 0; i < node->mNumChildren; i++)
    {
        AnimationNode* childNode = CreateNodeTree(node->mChildren[i], internalNode);
        internalNode->children.push_back(childNode);
    }
    
    return internalNode;
}
// ------------------------------------------------------------------------------------------------
// Recursively creates an internal node structure matching the current scene and animation.
SceneAnimNode* SceneAnimator::CreateNodeTree(aiNode* pNode, SceneAnimNode* pParent)
{
	// create a node
	SceneAnimNode* internalNode = new SceneAnimNode(pNode->mName.data);
	internalNode->mParent = pParent;
	mNodesByName[pNode] = internalNode;

	// copy its transformation
	internalNode->mLocalTransform = pNode->mTransformation;
	CalculateGlobalTransform(internalNode);

	// find the index of the animation track affecting this node, if any
	if (mCurrentAnimIndex < mScene->mNumAnimations)
	{
		internalNode->mChannelIndex = -1;
		const aiAnimation* currentAnim = mScene->mAnimations[mCurrentAnimIndex];
		for (unsigned int a = 0; a < currentAnim->mNumChannels; a++)
		{
			if (currentAnim->mChannels[a]->mNodeName.data == internalNode->mName)
			{
				internalNode->mChannelIndex = a;
				break;
			}
		}
	}

	// continue for all child nodes and assign the created internal nodes as our children
	for (unsigned int a = 0; a < pNode->mNumChildren; a++)
	{
		SceneAnimNode* childNode = CreateNodeTree(pNode->mChildren[a], internalNode);
		internalNode->mChildren.push_back(childNode);
	}

	return internalNode;
}
Beispiel #3
0
// ------------------------------------------------------------------------------------------------
// Sets the animation to use for playback. 
void SceneAnim::SetAnimIndex( size_t pAnimIndex)
{
	// no change
	if( pAnimIndex == mCurrentAnimIndex)
		return;

	// kill data of the previous anim
	delete mRootNode;  mRootNode = NULL;
	delete mAnimEvaluator;  mAnimEvaluator = NULL;
	mNodesByName.clear();

	mCurrentAnimIndex = pAnimIndex;

	// create the internal node tree. Do this even in case of invalid animation index
	// so that the transformation matrices are properly set up to mimic the current scene
	mRootNode = CreateNodeTree( mScene->mRootNode, NULL);

	// invalid anim index
	if( mCurrentAnimIndex >= mScene->mNumAnimations)
		return;

	// create an evaluator for this animation
	//mAnimEvaluator = new AnimEval(mScene->mAnimations[mCurrentAnimIndex]);
	mAnimEvaluator = new AnimEval;
	mAnimEvaluator->init(mScene->mAnimations[mCurrentAnimIndex]);
}
Beispiel #4
0
NodeTree* CreateBinaryTree()
 {
     NodeTree* p;
     char* data=(char*)malloc(sizeof(char)*100);
     scanf("%s",data);
     if (strcmp(data,"*")==0)
     {
         return NULL;
     }
     else {
          p=CreateNodeTree(atoi(data));
          p->left=CreateBinaryTree();
          p->right=CreateBinaryTree();
     }
     return p;
 }
Beispiel #5
0
// sets the animation to use for playback
void Animator::SetAnimationIndex(int animIndex)
{
    if (animIndex == currentAnimationIndex)
    {
        return;
    }
    
    // kill data of the previous animation
    if (rootNode != NULL)
    {
        delete rootNode;
        rootNode = NULL;
    }
    
    if (lastFramePosition != NULL)
    {
        delete[] lastFramePosition;
        lastFramePosition = NULL;
    }
    
    mapNodesByName.clear();
    currentAnimation = NULL;
    
    currentAnimationIndex = animIndex;
    currentAnimation = mainScene->mAnimations[currentAnimationIndex];
    
    // create the internal node tree. Do this even in case of invalid animation index
    // so that the transformation matrices are properly set up to mimic the current scene
    rootNode = CreateNodeTree(mainScene->mRootNode, NULL);
    
    // invalid animation index
    if (animIndex >= mainScene->mNumAnimations)
    {
        currentAnimationIndex = 0;
        currentAnimation = mainScene->mAnimations[currentAnimationIndex];
    }
    
    lastFramePosition = new glm::uvec3[currentAnimation->mNumChannels];
}
// NodeTree
Offset<NodeTree> FlatBuffersSerialize::createNodeTree(const tinyxml2::XMLElement *objectData,
                                                      std::string classType)
{
    std::string classname = classType.substr(0, classType.find("ObjectData"));
    CCLOG("classname = %s", classname.c_str());
    
    std::string name = "";
    
    Offset<Options> options;
    std::vector<Offset<NodeTree>> children;
    
    if (classname == "ProjectNode")
    {
        auto reader = ProjectNodeReader::getInstance();
        options = CreateOptions(*_builder, reader->createOptionsWithFlatBuffers(objectData, _builder));
    }
    else if (classname == "SimpleAudio")
    {
        auto reader = ComAudioReader::getInstance();
        options = CreateOptions(*_builder, reader->createOptionsWithFlatBuffers(objectData, _builder));
    }
    else
    {
        std::string readername = getGUIClassName(classname);
        readername.append("Reader");
        
        NodeReaderProtocol* reader = dynamic_cast<NodeReaderProtocol*>(ObjectFactory::getInstance()->createObject(readername));
        options = CreateOptions(*_builder, reader->createOptionsWithFlatBuffers(objectData, _builder));
    }
    
    
    // children
    bool containChildrenElement = false;
    const tinyxml2::XMLElement* child = objectData->FirstChildElement();
    
    while (child)
    {
        CCLOG("child name = %s", child->Name());
        
        if (strcmp("Children", child->Name()) == 0)
        {
            containChildrenElement = true;
            break;
        }
        
        child = child->NextSiblingElement();
    }
    
    if (containChildrenElement)
    {
        child = child->FirstChildElement();
        CCLOG("element name = %s", child->Name());
        
        while (child)
        {
            const tinyxml2::XMLAttribute* attribute = child->FirstAttribute();
            bool bHasType = false;
            while (attribute)
            {
                std::string attriname = attribute->Name();
                std::string value = attribute->Value();
                
                if (attriname == "ctype")
                {
                    children.push_back(createNodeTree(child, value));
                    
                    bHasType = true;
                    break;
                }
                
                attribute = attribute->Next();
            }
            
            if(!bHasType)
            {
                children.push_back(createNodeTree(child, "NodeObjectData"));
            }
            
            child = child->NextSiblingElement();
        }
    }
    //
    
    std::string customClassName = "";
    const tinyxml2::XMLAttribute* attribute = objectData->FirstAttribute();
    while (attribute)
    {
        std::string attriname = attribute->Name();
        std::string value = attribute->Value();
        
        if (attriname == "CustomClassName")
        {
            customClassName = value;
            break;
        }
        
        attribute = attribute->Next();
    }
    
    return CreateNodeTree(*_builder,
                          _builder->CreateString(classname),
                          _builder->CreateVector(children),
                          options,
                          _builder->CreateString(customClassName));
}
Beispiel #7
0
// Static
DARKSDK void GFCreateNodeTree						( float fX, float fY, float fZ )
{
	CreateNodeTree ( fX, fY, fZ );
}