Ejemplo n.º 1
0
void EC_Hydrax::Create()
{
    PROFILE(EC_Hydrax_Create);
    SAFE_DELETE(impl);

    if (!framework || framework->IsHeadless())
        return;

    try
    {
        if (!ParentScene())
        {
            LogError("EC_Hydrax: no parent scene. Cannot be created.");
            return;
        }

        OgreWorldPtr w = ParentScene()->Subsystem<OgreWorld>();
        assert(w);

        connect(w->Renderer(), SIGNAL(MainCameraChanged(Entity *)), SLOT(OnActiveCameraChanged(Entity *)), Qt::UniqueConnection);
        Entity *mainCamera = w->Renderer()->MainCamera();
        if (!mainCamera)
        {
            // Can't create Hydrax just yet, no main camera set (Hydrax needs a valid camera to initialize).
            // This error is benign, and Hydrax will now postpone its initialization to until a camera is set.
            // (see OnActiveCameraChanged()).
            LogDebug("Cannot create EC_Hydrax: No main camera set!");
            return;
        }

        Ogre::Camera *cam = mainCamera->GetComponent<EC_Camera>()->GetCamera();
        impl = new EC_HydraxImpl();
        impl->hydrax = new Hydrax::Hydrax(w->OgreSceneManager(), cam, w->Renderer()->MainViewport());

        // Using projected grid module by default
        Hydrax::Module::ProjectedGrid *module = new Hydrax::Module::ProjectedGrid(impl->hydrax, new Hydrax::Noise::Perlin(),
            Ogre::Plane(Ogre::Vector3::UNIT_Y, Ogre::Vector3::ZERO), Hydrax::MaterialManager::NM_VERTEX);
        impl->hydrax->setModule(module);
        impl->module = module;

        // Load all parameters from config file, but position attribute is always authoritative for the position.
        RequestConfigAsset();

        connect(framework->Frame(), SIGNAL(PostFrameUpdate(float)), SLOT(Update(float)), Qt::UniqueConnection);
    }
    catch(const Ogre::Exception &e)
    {
        // Currently if we try to create more than one Hydrax component we end up here due to Ogre internal name collision.
        LogError("Could not create EC_Hydrax: " + std::string(e.what()));
    }
}
void EC_MeshmoonWater::RemoveSkyReflectionArtifacts(IComponent *component)
{
    if (!reflectionsEnabled.Get())
        return;

    // Disable sky draw distance if reflections are enabled
    if (component)
    {
        if (component->TypeId() == EC_Sky::TypeIdStatic())
        {
            EC_Sky *sky = dynamic_cast<EC_Sky*>(component);
            if (sky)
            {
                LogWarning(LC + "EC_Sky cannot be rendered into EC_MeshmoonWater reflections, disabling sky artifacts locally.");
                sky->distance.Set(1.0, AttributeChange::LocalOnly);
            }
        }
        return;
    }
    
    // No input was given, loop the whole scene and recursively call this function.
    EntityList ents = ParentScene()->EntitiesWithComponent(EC_Sky::TypeIdStatic());
    for (EntityList::iterator iter = ents.begin(); iter != ents.end(); ++iter)
    {
        IComponent *comp = (*iter)->Component(EC_Sky::TypeIdStatic()).get();
        if (comp) RemoveSkyReflectionArtifacts(comp);
    }
}
Ejemplo n.º 3
0
void EC_SkyX::Create()
{
    if (framework->IsHeadless())
        return;

    if (!ParentScene())
    {
        LogError("EC_SkyX: Aborting creation, parent scene is null!");
        return;
    }

    // Return if main camera is not set
    OgreWorldPtr w = ParentScene()->GetWorld<OgreWorld>();
    if (!w || !w->Renderer())
        return;
    if (!w->Renderer()->MainCamera())
    {
        connect(w->Renderer(), SIGNAL(MainCameraChanged(Entity*)), this, SLOT(Create()), Qt::UniqueConnection);
        return;
    }
Ejemplo n.º 4
0
void Sky::AttributesChanged()
{
    if (!ViewEnabled() || !ParentScene())
        return;

    if (materialRef.ValueChanged() && materialAsset_)
        materialAsset_->HandleAssetRefChange(&materialRef);

    if (textureRefs.ValueChanged() && textureRefListListener_)
        textureRefListListener_->HandleChange(textureRefs.Get());

    if (distance.ValueChanged())
    {
        if (urhoNode_)
            urhoNode_->SetScale(distance.Get());
    }
}
Ejemplo n.º 5
0
void EC_DynamicComponent::RemoveAllAttributes(AttributeChange::Type change)
{
    for(unsigned i = attributes.size() - 1; i < attributes.size(); --i)
    {
        // Trigger scenemanager signal
        Scene* scene = ParentScene();
        if (scene)
            scene->EmitAttributeRemoved(this, attributes[i], change);

        QString name(attributes[i]->Name());

        // Trigger internal signal(s)
        emit AttributeAboutToBeRemoved(attributes[i]);
        SAFE_DELETE(attributes[i]);
        attributes.erase(attributes.begin() + i);
    }
}
void EC_MeshmoonWater::OnUpdate(float elapsedTime)
{
#ifdef MESHMOON_TRITON
    if (!visible.Get() || !ParentScene() || !state_.environment || !state_.ocean)
        return;

    PROFILE(EC_MeshmoonWater_Update);

    if (!windConditionsComp_.expired())
    {
        if (windConditionsComp_.lock().get()->TypeId() == EC_MeshmoonSky::TypeIdStatic())
        {
            EC_MeshmoonSky *meshmoonSky = dynamic_cast<EC_MeshmoonSky*>(windConditionsComp_.lock().get());
            if (meshmoonSky)
            {
                float windDirFloored = Floor(fmod(meshmoonSky->windDirection.Get() + 180.0f, 360.0f));
                float windSpeedFloored = Floor(meshmoonSky->windSpeed.Get());
                if (windSpeedFloored != state_.windSpeedPerSec || windDirFloored != Floor(state_.windDirDegrees))
                {
                    state_.windDirDegrees = windDirFloored;
                    state_.windSpeedPerSec = windSpeedFloored;
                    UpdateWeatherConditions();
                }
            }
        }
        else if (windConditionsComp_.lock().get()->TypeId() == EC_SkyX::TypeIdStatic())
        {
            EC_SkyX *skyx = dynamic_cast<EC_SkyX*>(windConditionsComp_.lock().get());
            if (skyx)
            {
                /// SkyX-To-Triton wind direction needs a small adjustment for them to align properly.
                /// (-skyxDir + 90 deg) and we round the float + modulo with 360 degrees to get [0,359] range.
                float tritonWindDir = fmod(Floor(-skyx->windDirection.Get() + 90.0f), 360.0f);
                if (skyx->windSpeed.Get() != state_.windSpeedPerSec || tritonWindDir != Floor(state_.windDirDegrees))
                {
                    state_.windDirDegrees = tritonWindDir;
                    state_.windSpeedPerSec = skyx->windSpeed.Get();
                    UpdateWeatherConditions();
                }
            }
        }
    }
#endif
}
Ejemplo n.º 7
0
void EC_Hydrax::OnActiveCameraChanged(Entity *newActiveCamera)
{
    PROFILE(EC_Hydrax_OnActiveCameraChanged);

    // If no active camera or the new active camera is observing another Ogre scene than the one this EC_Hydrax component is in, 
    // don't initialize Hydrax to that scene.
    if (!newActiveCamera || newActiveCamera->ParentScene() != ParentScene())
    {
        SAFE_DELETE(impl);
        return;
    }

    // If we haven't yet initialized, do a full init.
    if (!impl)
        Create();
    else // Otherwise, update the camera to an existing initialized Hydrax instance.
        if (impl && impl->hydrax)
            impl->hydrax->setCamera(newActiveCamera->GetComponent<EC_Camera>()->GetCamera());
}
Ejemplo n.º 8
0
void EC_DynamicComponent::RemoveAttribute(const QString &name, AttributeChange::Type change)
{
    for(AttributeVector::iterator iter = attributes.begin(); iter != attributes.end(); iter++)
    {
        if((*iter)->Name() == name)
        {
            // Trigger scenemanager signal
            Scene* scene = ParentScene();
            if (scene)
                scene->EmitAttributeRemoved(this, *iter, change);
            
            // Trigger internal signal(s)
            emit AttributeAboutToBeRemoved(*iter);
            SAFE_DELETE(*iter);
            attributes.erase(iter);
            break;
        }
    }
}
void EC_MeshmoonWater::OnParentEntitySet()
{
    if (!framework || framework->IsHeadless())
        return;

    OgreRendererPtr renderer = Renderer();
    if (!renderer)
    {
        // Try to resolve the renderer now. Might have not been done in ctor if constructed as unparented!
        OgreRenderingModule* renderingModule = framework->Module<OgreRenderingModule>();
        if (!renderingModule)
            return;
        renderer_ = renderingModule->Renderer();
        if (renderer_.expired())
            return;
        renderer = renderer_.lock();
    }
        
    if (world_.expired() && ParentScene())
        world_ = ParentScene()->GetWorld<OgreWorld>();

    connect(renderer.get(), SIGNAL(DeviceCreated()), this, SLOT(RecreateOcean()), Qt::UniqueConnection);
    connect(renderer.get(), SIGNAL(MainCameraChanged(Entity *)), this, SLOT(OnActiveCameraChanged(Entity *)), Qt::UniqueConnection);
    connect(framework->Frame(), SIGNAL(Updated(float)), this, SLOT(OnUpdate(float)), Qt::UniqueConnection);

    OnActiveCameraChanged(renderer->MainCamera());

    // Detect sky components if already in scene, otherwise will be detected via ComponentAdded signal
    EntityList ents = ParentScene()->EntitiesWithComponent(EC_MeshmoonSky::TypeIdStatic());
    for (EntityList::iterator iter = ents.begin(); iter != ents.end(); ++iter)
    {
        IComponent *comp = (*iter)->Component(EC_MeshmoonSky::TypeIdStatic()).get();
        if (comp) OnComponentAdded(0, comp, AttributeChange::LocalOnly);
    }
    ents = (windConditionsComp_.expired() ? ParentScene()->EntitiesWithComponent(EC_SkyX::TypeIdStatic()) : EntityList());
    for (EntityList::iterator iter = ents.begin(); iter != ents.end(); ++iter)
    {
        IComponent *comp = (*iter)->Component(EC_SkyX::TypeIdStatic()).get();
        if (comp) OnComponentAdded(0, comp, AttributeChange::LocalOnly);
    }

    connect(ParentScene(), SIGNAL(ComponentAdded(Entity*, IComponent*, AttributeChange::Type)), 
        this, SLOT(OnComponentAdded(Entity*, IComponent*, AttributeChange::Type)), Qt::UniqueConnection);
    connect(ParentScene(), SIGNAL(ComponentRemoved(Entity*, IComponent*, AttributeChange::Type)), 
        this, SLOT(OnComponentRemoved(Entity*, IComponent*, AttributeChange::Type)), Qt::UniqueConnection);

    CreateOcean();
}
Ejemplo n.º 10
0
IAttribute *EC_DynamicComponent::CreateAttribute(const QString &typeName, const QString &id, AttributeChange::Type change)
{
    if (ContainsAttribute(id))
        return IComponent::AttributeById(id);

    IAttribute *attribute = SceneAPI::CreateAttribute(typeName, id);
    if (!attribute)
    {
        LogError("Failed to create new attribute of type \"" + typeName + "\" with ID \"" + id + "\" to dynamic component \"" + Name() + "\".");
        return 0;
    }

    IComponent::AddAttribute(attribute);

    Scene* scene = ParentScene();
    if (scene)
        scene->EmitAttributeAdded(this, attribute, change);

    emit AttributeAdded(attribute);
    EmitAttributeChanged(attribute, change);
    return attribute;
}
Ejemplo n.º 11
0
IAttribute *EC_DynamicComponent::CreateAttribute(const QString &typeName, const QString &name, AttributeChange::Type change)
{
    if(ContainsAttribute(name))
        return IComponent::GetAttribute(name);

    IAttribute *attribute = framework->Scene()->CreateAttribute(this, typeName, name);
    if(!attribute)
    {
        LogError("Failed to create new attribute:" + name + " in dynamic component:" + Name());
        return 0;
    }

    // Trigger scenemanager signal
    Scene* scene = ParentScene();
    if (scene)
        scene->EmitAttributeAdded(this, attribute, change);
    
    // Trigger internal signal
    emit AttributeAdded(attribute);
    EmitAttributeChanged(attribute, change);
    return attribute;
}
    if(!renderingModule)
        return;

    renderer_ = renderingModule->GetRenderer();
    if(!renderer_.get())
        return;

    connect(renderer_.get(), SIGNAL(MainCameraChanged(Entity *)), this, SLOT(OnActiveCameraChanged(Entity *)), Qt::UniqueConnection);
}

EC_MeshmoonCulling::~EC_MeshmoonCulling()
{
    disconnect(framework->Frame(), SIGNAL(Updated(float)), this, SLOT(OnUpdate(float)));
    disconnect(renderer_.get(), SIGNAL(MainCameraChanged(Entity *)), this, SLOT(OnActiveCameraChanged(Entity *)));

    Scene *tundraScene = ParentScene();
    if(tundraScene)
        disconnect(tundraScene, SIGNAL(OnComponentRemoved(Entity*, IComponent*, AttributeChange::Type)), this, SLOT(OnComponentRemoved(Entity*, IComponent*, AttributeChange::Type)));

    Umbra::TomeLoader::freeTome(umbraTome_);
    umbraTome_ = 0;
    if(umbraDebugRenderer_)
        SAFE_DELETE(umbraDebugRenderer_);
    if(umbraQuery_)
        SAFE_DELETE(umbraQuery_);
    if(umbraObjectList_)
        SAFE_DELETE_ARRAY(umbraObjectList_);
    if(lastVisibleObjects_)
        SAFE_DELETE_ARRAY(lastVisibleObjects_);

    occluders_.clear();
Ejemplo n.º 13
0
Entity *Placeable::ParentPlaceableEntity() const
{
    return parentRef.Get().Lookup(ParentScene()).Get();
}