Exemple #1
0
Sky::Sky(Urho3D::Context* context, Scene* scene) :
    IComponent(context, scene),
    INIT_ATTRIBUTE_VALUE(materialRef, "Material", AssetReference("", "Material")),
    INIT_ATTRIBUTE_VALUE(textureRefs, "Texture", AssetReferenceList("Texture")),
    INIT_ATTRIBUTE_VALUE(distance, "Distance", 500),
    INIT_ATTRIBUTE_VALUE(orientation, "Orientation", Quat::identity),
    INIT_ATTRIBUTE_VALUE(drawFirst, "Draw first", true),
    INIT_ATTRIBUTE_VALUE(enabled, "Enabled", true),
    texturesLoaded(0)
{
    materialAsset_ = new AssetRefListener();

    static AttributeMetadata texturesMetadata;
    texturesMetadata.elementType = "AssetReference";
    textureRefs.SetMetadata(&texturesMetadata);

    ParentEntitySet.Connect(this, &Sky::UpdateSignals);   
}
Exemple #2
0
template<> AssetReferenceList TUNDRACORE_API Attribute<AssetReferenceList>::DefaultValue() const { return AssetReferenceList(); }
Exemple #3
0
/// \todo Use Asset API for fetching sky resources.
EC_Sky::EC_Sky(Scene* scene) :
    IComponent(scene),
    materialRef(this, "Material", AssetReference("RexSkyBox")), ///< \todo Add "ogre://" when AssetAPI can handle it.
    textureRefs(this, "Texture", AssetReferenceList("Texture")),
    orientation(this, "Orientation", Quat::identity),
    distance(this, "Distance",50.0),
    drawFirst(this, "Draw first", true)
{
    connect(this, SIGNAL(AttributeChanged(IAttribute*, AttributeChange::Type)), SLOT(OnAttributeUpdated(IAttribute*)));

    static AttributeMetadata materialRefMetadata;
    AttributeMetadata::ButtonInfoList materialRefButtons;
    materialRefButtons.push_back(AttributeMetadata::ButtonInfo(materialRef.Name(), "V", "View"));
    materialRefMetadata.buttons = materialRefButtons;
    materialRef.SetMetadata(&materialRefMetadata);

    // Find out default textures.
    if (scene)
        world_ = scene->GetWorld<OgreWorld>();

    StringVector names;
    Ogre::MaterialPtr materialPtr = Ogre::MaterialManager::getSingleton().getByName(materialRef.Get().ref.toStdString().c_str());
    if (materialPtr.get() != 0)
    {
        OgreRenderer::GetTextureNamesFromMaterial(materialPtr, names);
        AssetReferenceList lst("Texture");
        if (names.size() == cSkyBoxTextureCount)
        {
            // This code block is not currently working, but if for some reason GetTextureNamesFromMaterial understands cubic_textures this codeblock is runned
            for(int i = 0; i < cSkyBoxTextureCount; ++i)
                lst.Append(AssetReference(names[i].c_str()));
        }
        else
        {
            // Add default values, hardcoded
            /// HACK use hardcoded-values because ogre textureunit state class cannot find out texture names for cubic_texture type.
            lst.Append(AssetReference(names[0].c_str()));
            lst.Append(AssetReference("rex_sky_back.dds"));
            lst.Append(AssetReference("rex_sky_left.dds"));
            lst.Append(AssetReference("rex_sky_right.dds"));
            lst.Append(AssetReference("rex_sky_top.dds"));
            lst.Append(AssetReference("rex_sky_bot.dds"));
    }

    textureRefs.Set(lst, AttributeChange::LocalOnly);
    }

    // Disable old sky.
    // DisableSky();
    CreateSky();

    lastMaterial_ = materialRef.Get().ref;
    lastOrientation_ = orientation.Get();
    lastDistance_ = distance.Get();
    lastDrawFirst_ = drawFirst.Get();

    while(textureAssets.size() < cSkyBoxTextureCount)
    textureAssets.push_back(boost::shared_ptr<AssetRefListener>(new AssetRefListener));

    for(int i = 0; i < cSkyBoxTextureCount; ++i)
    {
        connect(textureAssets[i].get(), SIGNAL(Loaded(AssetPtr)), this, SLOT(OnTextureAssetLoaded(AssetPtr)), Qt::UniqueConnection);
        //materialAssets[i]->HandleAssetRefChange(framework->Asset(), materials[i].ref);
    }
}