//------------------------------
	bool LibraryEffectsLoader::begin__sampler2D____fx_sampler2D_common()
	{
        mInSampler2D = true;
		mCurrentSampler = new COLLADAFW::Sampler( createUniqueId (COLLADAFW::Sampler::ID()));
		mCurrentSampler->setSamplerType( COLLADAFW::Sampler::SAMPLER_TYPE_2D );
		return true;
	}
Exemplo n.º 2
0
// create a game with its kind and its provider
Game::Game( const GameDefinition& gameDefinition,
            ClientConnectionPtr provider )
:
   gameDefinition( gameDefinition ),
   id( createUniqueId( gameDefinition.kind ) ),
   provider( provider ),
   consumers()
{
   provider->incLoad();
}
Exemplo n.º 3
0
SessionData* SessionManager::startSession( uint32 token )
{
   SessionData* sd = 0;
   Falcon::String sSID;

   // No one can possibly use this SD as no one can know it.
   sd = createUniqueId( sSID );
   m_mtx.lock();
   m_susers[token].push_back( sd->getWeakRef() );
   // assign the session
   sd->assign( token );
   m_mtx.unlock();

   return sd;
}
	//-----------------------------
	void PostProcessor::createMissingAnimationList( const Loader::AnimationSidAddressBinding& binding )
	{
		const SidTreeNode* sidTreeNode = resolveSid( binding.sidAddress);
		if ( sidTreeNode )
		{
			if ( sidTreeNode->getTargetType() == SidTreeNode::TARGETTYPECLASS_ANIMATABLE )
			{
				COLLADAFW::Animatable* animatable = sidTreeNode->getAnimatableTarget();
				COLLADAFW::UniqueId animationListUniqueId = animatable->getAnimationList();
				if ( !animationListUniqueId.isValid() )
				{
					animationListUniqueId = createUniqueId( COLLADAFW::AnimationList::ID() );
					animatable->setAnimationList( animationListUniqueId );
				}
				COLLADAFW::AnimationList*& animationList = getAnimationListByUniqueId(animationListUniqueId);

				if ( !animationList )
				{
					animationList = new COLLADAFW::AnimationList( animationListUniqueId );
				}

				// TODO handle this for arrays
				COLLADAFW::AnimationList::AnimationBinding animationBinding;
				animationBinding.animation = binding.animationInfo.uniqueId;
				animationBinding.animationClass = binding.animationInfo.animationClass;

				switch ( binding.sidAddress.getMemberSelection() )
				{
				case SidAddress::MEMBER_SELECTION_ONE_INDEX:
					animationBinding.firstIndex = binding.sidAddress.getFirstIndex();
					animationBinding.secondIndex = 0;
					animationBinding.animationClass = COLLADAFW::AnimationList::ARRAY_ELEMENT_1D;
					break;
				case SidAddress::MEMBER_SELECTION_TWO_INDICES:
					animationBinding.firstIndex = binding.sidAddress.getFirstIndex();
					animationBinding.secondIndex = binding.sidAddress.getSecondIndex();
					animationBinding.animationClass = COLLADAFW::AnimationList::ARRAY_ELEMENT_2D;
					break;
				default:
					animationBinding.firstIndex = 0;
					animationBinding.secondIndex = 0;
				}

				animationList->getAnimationBindings().append( animationBinding );
			}
		}

	}
	//------------------------------
	bool LibraryEffectsLoader::handleTexture( const texture__AttributeData& attributeData )
	{
		bool success = true;
		switch ( mCurrentProfile )
		{
		case PROFILE_COMMON:
			{
                // Get the current color or texture element.
				COLLADAFW::ColorOrTexture* colorOrTexture = getCurrentColorOrTexture ( true );

                // Check if the texture is referenced.
                String textureSid = (const char *)attributeData.texture;
				SidSamplerInfoMap::const_iterator it = mEffectProfileSidSamplerInfoMap.find(textureSid);
				if ( it == mEffectProfileSidSamplerInfoMap.end() )
                {
                    it = mEffectSidSamplerInfoMap.find((const char*)attributeData.texture);
                    if ( it == mEffectSidSamplerInfoMap.end() )
                    {
						String msg("Texture with sid \"" + textureSid + "\" not found");
						if ( mCurrentEffect )
						{
							msg += " in effect with id \"" + mCurrentEffect->getOriginalId() + "\"";
						}
						msg += ".";
                        success = handleFWLError ( SaxFWLError::ERROR_UNRESOLVED_REFERENCE, msg );
                        break;
                    }
                }

				// Push the texture sid of the current sampler in the list of used samplers
				// of the current effect profile. 
				size_t samplerIndex = 0;
				StringIndexMap::const_iterator samplerIt = mEffectProfileSamplersMap.find(textureSid);
				if ( samplerIt == mEffectProfileSamplersMap.end() )
				{
					// This sid has not been used before. Add to map with next index
					samplerIndex = mNextSamplerIndex;
					mEffectProfileSamplersMap.insert(std::make_pair(textureSid, mNextSamplerIndex++));
				}
				else
				{
					// This sid is already in the map. Use its index
					samplerIndex = samplerIt->second;
				}

				// Initialize the texture element.
				/* const SamplerInfo& samplerInfo = it->second; */ /* UNUSED */
				colorOrTexture->setType(COLLADAFW::ColorOrTexture::TEXTURE);
				COLLADAFW::Texture& texture = colorOrTexture->getTexture();
                texture.setUniqueId ( createUniqueId(COLLADAFW::Texture::ID()) );
				texture.setSamplerId( samplerIndex );
				if ( attributeData.texcoord )
				{
					texture.setTextureMapId( getTextureMapIdBySematic( attributeData.texcoord) );
                    texture.setTexcoord(attributeData.texcoord);
                }

				break;
			}
            /*
                PROFILE_BRIDGE,
                PROFILE_CG,
                PROFILE_GLES,
                PROFILE_GLES2,
                PROFILE_GLSL,
                PROFILE_COMMON,
                PROFILE_NONE
              */
            default:
                break;
		}
		return success;

	}
//-----------------------------
bool DocumentProcessor::createAndWriteSkinController( const Loader::InstanceControllerData& instanceControllerData,
        const COLLADAFW::UniqueId& controllerDataUniqueId,
        const COLLADAFW::UniqueId& sourceUniqueId,
        const StringList& sidsOrIds,
        bool resolveIds)
{
    if ( !controllerDataUniqueId.isValid() )
        return false;

    const URIList& skeletonRoots = instanceControllerData.skeletonRoots;

    NodeList joints;

    for ( StringList::const_iterator it = sidsOrIds.begin(); it != sidsOrIds.end(); ++it)
    {
        const String sidOrId = *it;

        bool jointFound = false;

        if ( resolveIds )
        {
            const SidTreeNode* joint = resolveSid( sidOrId );
            if ( joint )
            {
                // the joint could be found
                if ( joint->getTargetType() == SidTreeNode::TARGETTYPECLASS_OBJECT )
                {
                    const COLLADAFW::Object* object = joint->getObjectTarget();

                    if ( object->getClassId() == COLLADAFW::Node::ID() )
                    {
                        joints.push_back( (COLLADAFW::Node*)object );

                        jointFound = true;
                        //search for the next joint
                    }
                    else
                    {
                        // we could resolve the sid, but is not a joint/node
                    }
                }
                else
                {
                    // we could resolve the sid, but is not a joint/node
                }
            }
        }
        else
        {
            for ( URIList::const_iterator skeletonIt = skeletonRoots.begin(); skeletonIt != skeletonRoots.end(); ++skeletonIt)
            {
                const COLLADABU::URI& skeletonUri = *skeletonIt;

                SidAddress sidAddress( skeletonUri, sidOrId );
                const SidTreeNode* joint = resolveSid( sidAddress );
                if ( joint )
                {
                    // the joint could be found
                    if ( joint->getTargetType() != SidTreeNode::TARGETTYPECLASS_OBJECT )
                    {
                        // we could resolve the sid, but is not a joint/node
                        break;
                    }

                    const COLLADAFW::Object* object = joint->getObjectTarget();

                    if ( object->getClassId() != COLLADAFW::Node::ID() )
                    {
                        // we could resolve the sid, but is not a joint/node
                        break;
                    }

                    joints.push_back( (COLLADAFW::Node*)object );

                    jointFound = true;
                    //search for the next joint
                    break;
                }
            }
        }


        if ( !jointFound )
        {
            std::stringstream msg;
            msg << "Could not resolve " << (resolveIds ? "id" : "sid") << " \"";
            msg << sidOrId << "\" referenced in skin controller.";
            if ( handleFWLError( SaxFWLError::ERROR_UNRESOLVED_REFERENCE, msg.str() ))
            {
                return false;
            }
        }
    }

    COLLADAFW::SkinController skinController( createUniqueId(COLLADAFW::SkinController::ID()));

    COLLADAFW::UniqueIdArray &jointsUniqueIds = skinController.getJoints();
    jointsUniqueIds.allocMemory( joints.size() );
    jointsUniqueIds.setCount(joints.size());

    size_t i = 0;
    NodeList::const_iterator it = joints.begin();
    for ( ; it != joints.end(); ++it, ++i )
    {
        const COLLADAFW::Node* node = *it;
        jointsUniqueIds[i] = node->getUniqueId();
    }

    skinController.setSkinControllerData(controllerDataUniqueId);
    skinController.setSource(sourceUniqueId);

    bool success = true;
    // Check if we have already wrote a skin controller that describes the same controller, i.e. has same
    // source, skin data and joints. If so, do not write it again and reference the previously used in the
    // scene graph
    const COLLADAFW::SkinController* skinControllerToWrite = 0;
    Loader::SkinControllerSet::const_iterator skinControllerIt = mSkinControllerSet.find( skinController );
    if ( skinControllerIt == mSkinControllerSet.end() )
    {
        skinControllerToWrite = &skinController;
        success = writer()->writeController(skinControllerToWrite);
        mSkinControllerSet.insert( skinController );
    }
    else
    {
        skinControllerToWrite = &(*skinControllerIt);
    }

    instanceControllerData.instanceController->setInstanciatedObjectId( skinControllerToWrite->getUniqueId() );

    return success;
}
Exemplo n.º 7
0
web::json::value gltfWriter::WriteTechnique (FbxNode *pNode, FbxSurfaceMaterial *pMaterial, web::json::value &techniqueParameters) {
	web::json::value commonProfile =web::json::value::object () ;
	// The FBX SDK does not have such attribute. At best, it is an attribute of a Shader FX, CGFX or HLSL.
	commonProfile [U("extras")] =web::json::value::object ({{ U("doubleSided"), web::json::value::boolean (false) }}) ;
	commonProfile [U("lightingModel")] =web::json::value::string (LighthingModel (pMaterial)) ;
	commonProfile [U("parameters")] =web::json::value::array () ;
	if ( _uvSets.size () ) {
		commonProfile [U("texcoordBindings")] =web::json::value::object () ;
		for ( auto iter : _uvSets ) {
			utility::string_t key (iter.first) ;
			std::string::size_type i =key.find (U("Color")) ;
			if ( i != std::string::npos )
				key.erase (i, 5) ;
			std::transform (key.begin (), key.end (), key.begin (), ::tolower) ;
			commonProfile [U("texcoordBindings")] [key] =web::json::value::string (iter.second) ;
		}
	}
	for ( const auto &iter : techniqueParameters.as_object () ) {
		if (   (  utility::details::limitedCompareTo (iter.first, U("position")) != 0
			   && utility::details::limitedCompareTo (iter.first, U("normal")) != 0
			   && utility::details::limitedCompareTo (iter.first, U("texcoord")) != 0)
			|| iter.first == U("normalMatrix")
			)
			commonProfile [U("parameters")] [commonProfile [U("parameters")].size ()] =web::json::value::string (iter.first) ;

		web::json::value param =iter.second ;
		if ( param [U("type")].as_integer () == IOglTF::SAMPLER_2D ) {

		}
	}

	web::json::value details =web::json::value::object () ;
	details [U("commonProfile")] =commonProfile ;
	details [U("type")] =web::json::value::string (FBX_GLTF_COMMONPROFILE) ;

	web::json::value attributes =web::json::value::object () ;
	for ( const auto &iter : techniqueParameters.as_object () ) {
		if (   utility::details::limitedCompareTo (iter.first, U("position")) == 0
			|| (utility::details::limitedCompareTo (iter.first, U("normal")) == 0 && iter.first != U("normalMatrix"))
			|| utility::details::limitedCompareTo (iter.first, U("texcoord")) == 0 )
			attributes [utility::string_t (U("a_")) + iter.first] =web::json::value::string (iter.first) ;
	}

	web::json::value instanceProgram=web::json::value::object () ;
	instanceProgram [U("attributes")] =attributes ;
	instanceProgram [U("program")] =web::json::value::string (createUniqueId (utility::string_t (U("program")), 0)) ;
	instanceProgram [U("uniforms")] =web::json::value::object () ;
	for ( const auto &iter : techniqueParameters.as_object () ) {
		if (   (  utility::details::limitedCompareTo (iter.first, U("position")) != 0
			   && utility::details::limitedCompareTo (iter.first, U("normal")) != 0
			   && utility::details::limitedCompareTo (iter.first, U("texcoord")) != 0)
			|| iter.first == U("normalMatrix") )
			instanceProgram [U("uniforms")] [utility::string_t (U("u_")) + iter.first] =web::json::value::string (iter.first) ;
	}

	web::json::value techStatesEnable =web::json::value::array () ;
	if ( pNode->mCullingType != FbxNode::ECullingType::eCullingOff )
		techStatesEnable [techStatesEnable.size ()] =web::json::value::number ((int)IOglTF::CULL_FACE) ;
	// TODO: should it always be this way?
	techStatesEnable [techStatesEnable.size ()] =web::json::value::number ((int)IOglTF::DEPTH_TEST) ;

	web::json::value techStates =web::json::value::object () ;
	techStates [U("enable")] =techStatesEnable ;
	// TODO: needs to be implemented
	//techStates [U("functions")] =

	web::json::value techniquePass =web::json::value::object () ;
	techniquePass [U("details")] =details ;
	techniquePass [U("instanceProgram")] =instanceProgram ;
	techniquePass [U("states")] =techStates ;

	web::json::value technique =web::json::value::object () ;
	technique [U("parameters")] =techniqueParameters ;
	technique [U("pass")] =web::json::value::string (U("defaultPass")) ;
	technique [U("passes")] =web::json::value::object ({{ U("defaultPass"), techniquePass }}) ;

	return (technique) ;
}