EC_HoveringText::EC_HoveringText(Scene* scene) : IComponent(scene), font_(QFont("Arial", 100)), textColor_(Qt::black), billboardSet_(0), billboard_(0), usingGrad(this, "Use Gradient", false), text(this, "Text"), font(this, "Font", "Arial"), fontColor(this, "Font Color"), fontSize(this, "Font Size", 100), backgroundColor(this, "Background Color", Color(1.0f,1.0f,1.0f,0.0f)), position(this, "Position", float3(0.0f, 0.0f, 0.0f)), gradStart(this, "Gradient Start", Color(0.0f,0.0f,0.0f,1.0f)), gradEnd(this, "Gradient End", Color(1.0f,1.0f,1.0f,1.0f)), borderColor(this, "Border Color", Color(0.0f,0.0f,0.0f,0.0f)), borderThickness(this, "Border Thickness", 0.0), overlayAlpha(this, "Overlay Alpha", 1.0), width(this, "Width", 1.0), height(this, "Height", 1.0), texWidth(this, "Texture Width", 256), texHeight(this, "Texture Height", 256), cornerRadius(this, "Corner Radius", float2(20.0, 20.0)), enableMipmapping(this, "Enable Mipmapping", true), material(this, "Material", AssetReference("local://HoveringText.material", "")) { if (scene) world_ = scene->GetWorld<OgreWorld>(); connect(&materialAsset, SIGNAL(Loaded(AssetPtr)), this, SLOT(OnMaterialAssetLoaded(AssetPtr)), Qt::UniqueConnection); connect(&materialAsset, SIGNAL(TransferFailed(IAssetTransfer*, QString)), this, SLOT(OnMaterialAssetFailed(IAssetTransfer*, QString)), Qt::UniqueConnection); }
void AssetRefListListener::HandleChange(const AssetReferenceList &refs) { if (!assetAPI_) return; // Does a size check and compares each element with case-sensitive compare. if (refs == current_) return; AssetReferenceList prev = current_; // Set current internal refs current_ = refs; uint numRefs = current_.Size(); // Trim and resolve internal refs for (uint i=0; i<numRefs; ++i) { AssetReference &ref = current_[i]; ref.ref = ref.ref.Trimmed(); if (!ref.ref.Empty()) ref.ref = assetAPI_->ResolveAssetRef("", ref.ref); } // Changed Changed.Emit(current_); // Cleared for (uint i=0; i<numRefs; ++i) { const AssetReference &ref = current_[i]; const AssetReference &prevRef = (i < prev.Size() ? prev[i] : AssetReference()); if (ref.ref.Empty() && !prevRef.ref.Empty()) Cleared.Emit(i); } for(uint i = numRefs; i < prev.Size(); ++i) { if (!prev[i].ref.Empty()) Cleared.Emit(i); } // Request while(listeners_.Size() > numRefs) listeners_.Pop(); while(listeners_.Size() < numRefs) { // Connect to signals once on creation. AssetRefListeners // are reusable for multiple refs/requests. AssetRefListenerPtr listener(new AssetRefListener()); listener->TransferFailed.Connect(this, &AssetRefListListener::OnAssetFailed); listener->Loaded.Connect(this, &AssetRefListListener::OnAssetLoaded); listeners_.Push(listener); } for (uint i=0; i<numRefs; ++i) { const AssetReference &ref = current_[i]; if (!ref.ref.Empty()) listeners_[i]->HandleAssetRefChange(assetAPI_, ref.ref, ref.type); } }
EC_Hydrax::EC_Hydrax(Scene* scene) : IComponent(scene), INIT_ATTRIBUTE_VALUE(configRef, "Config ref", AssetReference(cDefaultConfig)), INIT_ATTRIBUTE_VALUE(visible, "Visible", true), INIT_ATTRIBUTE_VALUE(position, "Position", float3(0.0, 0.0, 0.0)), // INIT_ATTRIBUTE_VALUE(noiseModule, "Noise module", 0), // INIT_ATTRIBUTE_VALUE(noiseType, "Noise type", 0), // INIT_ATTRIBUTE_VALUE(normalMode, "Normal mode", 0), impl(0) { /* static AttributeMetadata noiseTypeMetadata; static AttributeMetadata normalModeMetadata; static bool metadataInitialized = false; if (!metadataInitialized) { noiseTypeMetadata.enums[Perlin] = "Perlin"; noiseTypeMetadata.enums[FFT] = "FFT"; normalModeMetadata.enums[Texture] = "Texture"; normalModeMetadata.enums[Vertex] = "Vertex"; normalModeMetadata.enums[RTT] = "RTT"; metadataInitialized = true; } noiseType.SetMetadata(&noiseTypeMetadata); normalMode.SetMetadata(&normalModeMetadata); */ connect(this, SIGNAL(ParentEntitySet()), SLOT(Create())); connect(&configRefListener, SIGNAL(Loaded(AssetPtr)), this, SLOT(ConfigLoadSucceeded(AssetPtr))); }
/// \todo Use Asset API for fetching sky resources. EC_SkyBox::EC_SkyBox(IModule *module) : IComponent(module->GetFramework()), materialRef(this, "Material", AssetReference("RexSkyBox")), ///< \todo Add "orge://" when AssetAPI can handle it. textureRefs(this, "Texture"), orientation(this, "Orientation", Quaternion(f32(M_PI/2.0), Vector3df(1.0,0.0,0.0))), 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.GetName(), "V", "View")); materialRefMetadata.buttons = materialRefButtons; materialRef.SetMetadata(&materialRefMetadata); // Find out default textures. renderer_ = module->GetFramework()->GetServiceManager()->GetService<OgreRenderer::Renderer>(); 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; if (names.size() == cSkyBoxTextureCount) { // This code block is not currently working, but if for some reason GetTextureNamesFromMaterialn 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(); lastTextures_ = textureRefs.Get(); }
template<> void TUNDRACORE_API Attribute<AssetReferenceList>::FromBinary(kNet::DataDeserializer& source, AttributeChange::Type change) { AssetReferenceList value; u8 numValues = source.Read<u8>(); for(u32 i = 0; i < numValues; ++i) value.Append(AssetReference(source.ReadString().c_str())); Set(value, change); }
std::vector<AssetReference> QtUiAsset::FindReferences() const { std::vector<AssetReference> assetRefs; for(size_t i = 0; i < refs.size(); ++i) { assetRefs.push_back(AssetReference(refs[i].parsedRef)); } return assetRefs; }
template<> void TUNDRACORE_API Attribute<AssetReferenceList>::FromString(const std::string& str, AttributeChange::Type change) { AssetReferenceList value; QString strValue = QString::fromStdString(str); QStringList components = strValue.split(';'); for(int i = 0; i < components.size(); i++) value.Append(AssetReference(components[i])); if (value.Size() == 1 && value[0].ref.trimmed().isEmpty()) value.RemoveLast(); Set(value, change); }
void TerrainWeightEditor::SetUseWeights(bool val) { if(!GetSceneManager()) return; Scene::EntityList list = scene_manager_->GetEntitiesWithComponent("EC_Terrain"); Scene::EntityList::const_iterator it = list.begin(); //Quick fix, we will clone a new material copy for each terrain and assume there does not exist previous material clones int i = 0; Ogre::String mat_name; while(it!= list.end()) { boost::shared_ptr<EC_Terrain> ptr = (*it)->GetComponent<EC_Terrain>(); if (val) ptr->material.Set(AssetReference("Rex/TerrainPCF_weighted"/*, "OgreMaterial"*/), AttributeChange::Disconnected); else ptr->material.Set(AssetReference("Rex/TerrainPCF"/*, "OgreMaterial"*/), AttributeChange::Disconnected); Ogre::MaterialPtr mat = Ogre::MaterialManager::getSingleton().getByName(mat_name); if(mat.get()) { if(i>0) //So we have several terrains, need to create more materials mat_name += Ogre::StringConverter::toString(i); Ogre::MaterialPtr new_mat =Ogre::MaterialManager::getSingleton().getByName(mat_name); if(!new_mat.get()) new_mat = mat->clone(mat_name); if(new_mat.get()) ptr->material.Set(QString(new_mat->getName().c_str()),AttributeChange::Default); } it++; i++; } }
EC_MeshmoonCulling::EC_MeshmoonCulling(Scene *scene) : IComponent(scene), LC("EC_MeshmoonCulling: "), INIT_ATTRIBUTE_VALUE(tomeRef, "Tome ref", AssetReference("", "Binary")), INIT_ATTRIBUTE_VALUE(id, "Id", 0), INIT_ATTRIBUTE_VALUE(smallestOccluder, "Smallest occluder", 3), INIT_ATTRIBUTE_VALUE(smallestHole, "Smallest hole", 0.25f), INIT_ATTRIBUTE_VALUE(backfaceLimit, "Backface limit", 100), INIT_ATTRIBUTE_VALUE(tileSize, "Tile size", 24), INIT_ATTRIBUTE_VALUE(drawDebug, "Draw debug", false), umbraScene_(0), umbraTome_(0), umbraObjectList_(0), umbraQuery_(0), umbraDebugRenderer_(0), freezeOcclusionCamera_(false), tomePath_(""), maxWaitingTime_(10.0), lastVisibleObjects_(0), lastVisibleObjectsSize_(0) { if (!framework) { LogError(LC + "TODO: Make EC_MeshmoonCulling work when created as unparented!"); return; } if (framework->IsHeadless()) return; tomeListener_ = MAKE_SHARED(AssetRefListener); connect(tomeListener_.get(), SIGNAL(Loaded(AssetPtr)), this, SLOT(OnLoadTome(AssetPtr))); connect(tomeListener_.get(), SIGNAL(TransferFailed(IAssetTransfer *, QString)), this, SLOT(OnTomeLoadingFailed(IAssetTransfer *, QString))); connect(framework->Input()->TopLevelInputContext(), SIGNAL(KeyPressed(KeyEvent*)), this, SLOT(OnKeyPress(KeyEvent*))); OgreRenderer::OgreRenderingModule* renderingModule = framework->GetModule<OgreRenderer::OgreRenderingModule>(); if(!renderingModule) return; renderer_ = renderingModule->GetRenderer(); if(!renderer_.get()) return; connect(renderer_.get(), SIGNAL(MainCameraChanged(Entity *)), this, SLOT(OnActiveCameraChanged(Entity *)), Qt::UniqueConnection); }
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); }
void TerrainWeightEditor::ApplyWeightTexture() { if(!GetSceneManager()) return; QImage map = CreateImageFromCanvases(); if(map.isNull()) return; if(map.format() != QImage::Format_ARGB32) { map = map.convertToFormat(QImage::Format_ARGB32/*,Qt::NoOpaqueDetection*/); } Ogre::Box bounds(0, 0, map.width(), map.height()); Ogre::PixelBox bufbox(bounds, Ogre::PF_A8R8G8B8, (void *)map.bits()); Scene::EntityList list = scene_manager_->GetEntitiesWithComponent("EC_Terrain"); Scene::EntityList::const_iterator it = list.begin(); while(it!= list.end()) { boost::shared_ptr<EC_Terrain> ptr = (*it)->GetComponent<EC_Terrain>(); QString texname; texname += (*it)->GetName(); texname += ptr->TypeName(); texname += ptr->Name(); texname += ".png"; Ogre::String str(texname.toStdString()); Ogre::TextureManager::getSingleton().remove(str); Ogre::TexturePtr tex = Ogre::TextureManager::getSingleton().createManual(str, "General", Ogre::TEX_TYPE_2D, bufbox.getWidth(), bufbox.getHeight(),bufbox.getDepth(),0,bufbox.format,Ogre::TU_DYNAMIC_WRITE_ONLY); if(tex.get()) { tex->getBuffer()->blitFromMemory(bufbox); } ptr->texture0.Set(AssetReference(texname/*, "OgreTexture"*/), AttributeChange::Disconnected); it++; ///For now we just save this to assets folder. Later on, this should be replicated to server/clients etc. QImageWriter writer("data/assets/" + texname); writer.setCompression(0); writer.write(map); } }
RigidBody::RigidBody(Urho3D::Context* context, Scene* scene) : IComponent(context, scene), INIT_ATTRIBUTE_VALUE(mass, "Mass", 0.0f), INIT_ATTRIBUTE_VALUE(shapeType, "Shape type", (int)Box), INIT_ATTRIBUTE_VALUE(size, "Size", float3(1,1,1)), INIT_ATTRIBUTE_VALUE(collisionMeshRef, "Collision mesh ref", AssetReference("", "OgreMesh")), INIT_ATTRIBUTE_VALUE(friction, "Friction", 0.5f), INIT_ATTRIBUTE_VALUE(restitution, "Restitution", 0.0f), INIT_ATTRIBUTE_VALUE(linearDamping, "Linear damping", 0.0f), INIT_ATTRIBUTE_VALUE(angularDamping, "Angular damping", 0.0f), INIT_ATTRIBUTE_VALUE(linearFactor, "Linear factor", float3(1,1,1)), INIT_ATTRIBUTE_VALUE(angularFactor, "Angular factor", float3(1,1,1)), INIT_ATTRIBUTE_VALUE(linearVelocity, "Linear velocity", float3(0,0,0)), INIT_ATTRIBUTE_VALUE(angularVelocity, "Angular velocity", float3(0,0,0)), INIT_ATTRIBUTE_VALUE(kinematic, "Kinematic", false), INIT_ATTRIBUTE_VALUE(phantom, "Phantom", false), INIT_ATTRIBUTE_VALUE(drawDebug, "Draw Debug", false), INIT_ATTRIBUTE_VALUE(collisionLayer, "Collision Layer", -1), INIT_ATTRIBUTE_VALUE(collisionMask, "Collision Mask", -1), INIT_ATTRIBUTE_VALUE(rollingFriction, "Rolling friction", 0.5f), INIT_ATTRIBUTE_VALUE(useGravity, "Use gravity", true), impl(new Impl(this)) { static AttributeMetadata shapemetadata; static bool metadataInitialized = false; if(!metadataInitialized) { shapemetadata.enums[Box] = "Box"; shapemetadata.enums[Sphere] = "Sphere"; shapemetadata.enums[Cylinder] = "Cylinder"; shapemetadata.enums[Capsule] = "Capsule"; shapemetadata.enums[TriMesh] = "TriMesh"; shapemetadata.enums[HeightField] = "HeightField"; shapemetadata.enums[ConvexHull] = "ConvexHull"; shapemetadata.enums[Cone] = "Cone"; metadataInitialized = true; } shapeType.SetMetadata(&shapemetadata); ParentEntitySet.Connect(this, &RigidBody::UpdateSignals); }
EC_MediaPlayer::EC_MediaPlayer(Scene* scene) : IComponent(scene), mediaPlayer_(0), componentPrepared_(false), pendingMediaDownload_(false), sourceRef(this, "Media Source", AssetReference("", "")), renderSubmeshIndex(this, "Render Submesh", 0), interactive(this, "Interactive", false), illuminating(this, "Illuminating", true), streamingAllowed(this, "Streaming Allowed", true), enabled(this, "Enabled", true) { if (!ViewEnabled() || GetFramework()->IsHeadless()) return; // Set metadata min/max/step static AttributeMetadata submeshMetaData; static bool metadataInitialized = false; if (!metadataInitialized) { submeshMetaData.minimum = "0"; submeshMetaData.step = "1"; metadataInitialized = true; } renderSubmeshIndex.SetMetadata(&submeshMetaData); // Init our internal media player mediaPlayer_ = new VlcMediaPlayer(); connect(mediaPlayer_, SIGNAL(FrameUpdate(QImage)), SLOT(OnFrameUpdate(QImage)), Qt::UniqueConnection); // Connect signals from IComponent connect(this, SIGNAL(ParentEntitySet()), SLOT(PrepareComponent()), Qt::UniqueConnection); // Connect window size changes to update rendering as the ogre textures go black. if (GetFramework()->Ui()->MainWindow()) connect(GetFramework()->Ui()->MainWindow(), SIGNAL(WindowResizeEvent(int,int)), SLOT(RenderWindowResized()), Qt::UniqueConnection); resizeRenderTimer_ = new QTimer(this); resizeRenderTimer_->setSingleShot(true); connect(resizeRenderTimer_, SIGNAL(timeout()), mediaPlayer_, SLOT(ForceUpdateImage()), Qt::UniqueConnection); // Prepare scene interactions SceneInteract *sceneInteract = GetFramework()->GetModule<SceneInteract>(); if (sceneInteract) { connect(sceneInteract, SIGNAL(EntityClicked(Entity*, Qt::MouseButton, RaycastResult*)), SLOT(EntityClicked(Entity*, Qt::MouseButton, RaycastResult*))); } // Prepare media downloader mediaDownloader_ = new AssetRefListener(); connect(mediaDownloader_, SIGNAL(Loaded(AssetPtr)), SLOT(OnMediaLoaded(AssetPtr))); connect(mediaDownloader_, SIGNAL(TransferFailed(IAssetTransfer*, QString)), SLOT(OnMediaFailed(IAssetTransfer*, QString))); // Construct loading image downloadingLogo_ = QImage(500, 300, QImage::Format_ARGB32); downloadingLogo_.fill(Qt::black); QPixmap bufferingIcon(":/images/buffering.png"); QPoint centerPos = downloadingLogo_.rect().center(); QRect target(centerPos.x() - (bufferingIcon.width()/2), centerPos.y() - (bufferingIcon.height()/2), bufferingIcon.width(), bufferingIcon.height()); QPainter p(&downloadingLogo_); p.setPen(Qt::white); p.drawPixmap(target, bufferingIcon, bufferingIcon.rect()); p.drawText(5, 12, "Downloading media..."); p.end(); }
template<> AssetReference TUNDRACORE_API Attribute<AssetReference>::DefaultValue() const { return AssetReference(); }
template<> void TUNDRACORE_API Attribute<AssetReference>::FromString(const std::string& str, AttributeChange::Type change) { Set(AssetReference(str.c_str()), change); }
/// \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); } }