/// \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(); }
EC_Mesh::EC_Mesh(IModule* module) : IComponent(module->GetFramework()), // Note: we put the opensim haxor adjust right here in the defaults, instead of hardcoding it in code. nodeTransformation(this, "Transform", Transform(Vector3df(0,0,0),Vector3df(90,0,180),Vector3df(1,1,1))), meshRef(this, "Mesh ref"), skeletonRef(this, "Skeleton ref"), meshMaterial(this, "Mesh materials"), drawDistance(this, "Draw distance", 0.0f), castShadows(this, "Cast shadows", false), renderer_(checked_static_cast<OgreRenderingModule*>(module)->GetRenderer()), entity_(0), bone_tagpoint_(0), bone_parent_mesh_(0), bone_attached_mesh_(0), attached_(false), attached_to_bone_(false) { static AttributeMetadata drawDistanceData("", "0", "10000"); drawDistance.SetMetadata(&drawDistanceData); static AttributeMetadata materialMetadata; materialMetadata.elementType = "assetreference"; meshMaterial.SetMetadata(&materialMetadata); static AttributeMetadata meshRefMetadata; AttributeMetadata::ButtonInfoList meshRefButtons; meshRefButtons.push_back(AttributeMetadata::ButtonInfo(meshRef.GetName(), "V", "View")); meshRefMetadata.buttons = meshRefButtons; meshRef.SetMetadata(&meshRefMetadata); RendererPtr renderer = renderer_.lock(); Ogre::SceneManager* scene_mgr = renderer->GetSceneManager(); adjustment_node_ = scene_mgr->createSceneNode(renderer->GetUniqueObjectName("EC_Mesh_adjustment_node")); connect(this, SIGNAL(ParentEntitySet()), SLOT(UpdateSignals())); connect(this, SIGNAL(AttributeChanged(IAttribute*, AttributeChange::Type)), SLOT(OnAttributeUpdated(IAttribute*))); meshAsset = AssetRefListenerPtr(new AssetRefListener()); connect(meshAsset.get(), SIGNAL(Loaded(AssetPtr)), this, SLOT(OnMeshAssetLoaded(AssetPtr)), Qt::UniqueConnection); skeletonAsset = AssetRefListenerPtr(new AssetRefListener()); connect(skeletonAsset.get(), SIGNAL(Loaded(AssetPtr)), this, SLOT(OnSkeletonAssetLoaded(AssetPtr)), Qt::UniqueConnection); }
EC_Mesh::EC_Mesh(Scene* scene) : IComponent(scene), nodeTransformation(this, "Transform", Transform(float3(0,0,0),float3(0,0,0),float3(1,1,1))), meshRef(this, "Mesh ref"), skeletonRef(this, "Skeleton ref"), meshMaterial(this, "Mesh materials", AssetReferenceList("OgreMaterial")), drawDistance(this, "Draw distance", 0.0f), castShadows(this, "Cast shadows", false), entity_(0), attached_(false) { if (scene) world_ = scene->GetWorld<OgreWorld>(); static AttributeMetadata drawDistanceData("", "0", "10000"); drawDistance.SetMetadata(&drawDistanceData); static AttributeMetadata materialMetadata; materialMetadata.elementType = "assetreference"; meshMaterial.SetMetadata(&materialMetadata); static AttributeMetadata meshRefMetadata; AttributeMetadata::ButtonInfoList meshRefButtons; meshRefButtons.push_back(AttributeMetadata::ButtonInfo(meshRef.Name(), "V", "View")); meshRefMetadata.buttons = meshRefButtons; meshRef.SetMetadata(&meshRefMetadata); meshAsset = AssetRefListenerPtr(new AssetRefListener()); skeletonAsset = AssetRefListenerPtr(new AssetRefListener()); OgreWorldPtr world = world_.lock(); if (world) { Ogre::SceneManager* sceneMgr = world->GetSceneManager(); adjustment_node_ = sceneMgr->createSceneNode(world->GetUniqueObjectName("EC_Mesh_adjustment_node")); connect(this, SIGNAL(ParentEntitySet()), SLOT(UpdateSignals())); connect(this, SIGNAL(AttributeChanged(IAttribute*, AttributeChange::Type)), SLOT(OnAttributeUpdated(IAttribute*))); connect(meshAsset.get(), SIGNAL(Loaded(AssetPtr)), this, SLOT(OnMeshAssetLoaded(AssetPtr)), Qt::UniqueConnection); connect(skeletonAsset.get(), SIGNAL(Loaded(AssetPtr)), this, SLOT(OnSkeletonAssetLoaded(AssetPtr)), Qt::UniqueConnection); } }
/// \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); } }