Exemple #1
0
void ResourceManager::TriggerReload(const std::string& path, EntityManager& em)
{
    RemoveFromNodeCache(path);

    ResourceChangedMessage msg;
    msg.SetPath(path);
    em.EmitMessage(msg);

}
Exemple #2
0
osg::ref_ptr<osg::Node> ResourceManager::GetNode(EntityManager& em, const std::string& path, unsigned int options)
{
    osg::Node* ret = NULL;

    std::string abspath = GetSystemInterface()->FindDataFile(path);

    if(abspath.empty())
    {
        LOG_ERROR("Error loading node, could not find data file: " << path);
        return NULL;
    }

    if((options & ResourceManagerOptions::CopyNodes) != 0)
    {
        NodeStore::iterator i = mNodeStore.find(abspath);
        if(i != mNodeStore.end())
        {
            ret = osg::clone(i->second.get(), osg::CopyOp(
                                 osg::CopyOp::DEEP_COPY_OBJECTS        |
                                 osg::CopyOp::DEEP_COPY_NODES          |
                                 osg::CopyOp::DEEP_COPY_USERDATA
                             ));
        }
    }
    else if((options & ResourceManagerOptions::ShallowCopy) != 0)
    {
        NodeStore::iterator i = mNodeStore.find(abspath);
        if(i != mNodeStore.end())
        {
            ret = osg::clone(i->second.get(), osg::CopyOp(
                                 osg::CopyOp::DEEP_COPY_USERDATA
                             ));
        }
    }
    else if((options & ResourceManagerOptions::CopyHardwareMeshes) != 0)
    {
        NodeStore::iterator i = mNodeStore.find(abspath);
        if(i != mNodeStore.end())
        {
            ret = osg::clone(i->second.get(), osg::CopyOp(
                                 osg::CopyOp::DEEP_COPY_ALL
                                 & ~osg::CopyOp::DEEP_COPY_PRIMITIVES
                                 & ~osg::CopyOp::DEEP_COPY_ARRAYS
                                 & ~osg::CopyOp::DEEP_COPY_TEXTURES
                                 & ~osg::CopyOp::DEEP_COPY_STATEATTRIBUTES
                                 & ~osg::CopyOp::DEEP_COPY_IMAGES
                                 &  ~osg::CopyOp::DEEP_COPY_SHAPES
                                 & ~osg::CopyOp::DEEP_COPY_UNIFORMS
                             ));
        }
    }
    else if((options & ResourceManagerOptions::DeepCopy) != 0)
    {
        NodeStore::iterator i = mNodeStore.find(abspath);
        if(i != mNodeStore.end())
        {
            ret = osg::clone(i->second.get(), osg::CopyOp(
                                 osg::CopyOp::DEEP_COPY_ALL
                             ));
        }
    }

    if(ret != NULL)
    {
        ret->setUserData(NULL);
        return ret;
    }

    osg::Node* node = osgDB::readNodeFile(abspath);

    if(node == NULL)
    {
        LOG_ERROR("Error loading node, could not interpret data file: " << abspath);
        return NULL;
    }

    if((options & ResourceManagerOptions::DoOptimization) != 0)
    {
        osgUtil::Optimizer optimizer;
        optimizer.optimize(node);
    }
    if((options & ResourceManagerOptions::DeepCopy) == 0)
    {
        mNodeStore[abspath] = node;
    }

    ResourceLoadedMessage msg;
    msg.SetPath(abspath);
    em.EmitMessage(msg);

    if((options & ResourceManagerOptions::CopyHardwareMeshes) != 0)
    {
        return osg::clone(node, osg::CopyOp(
                              osg::CopyOp::DEEP_COPY_ALL &
                              ~osg::CopyOp::DEEP_COPY_PRIMITIVES &
                              ~osg::CopyOp::DEEP_COPY_ARRAYS &
                              ~osg::CopyOp::DEEP_COPY_TEXTURES
                          ));
    }
    else
    {
        return node;
    }
}