void EC_Hydrax::ConfigLoadSucceeded(AssetPtr asset) { PROFILE(EC_Hydrax_ConfigLoadSucceeded); // If we haven't yet initialized, do a full init. if (!impl || !impl->hydrax || !impl->module) Create(); if (!impl || !impl->hydrax || !impl->module) { LogError("EC_Hydrax: Could not apply Hydrax config \"" + asset->Name() + "\", Hydrax could not be initialized!"); return; } std::vector<u8> rawData; asset->SerializeTo(rawData); QString configData = QString::fromAscii((const char*)&rawData[0], (int)rawData.size()); if (configData.isEmpty()) { LogInfo("EC_Hydrax: Downloaded config is empty!"); return; } try { // Update the noise module if (configData.contains("noise=fft", Qt::CaseInsensitive)) { /// \note Using the FFT noise plugin seems to crash somewhere after we leave this function. /// FFT looks better so would be nice to investigate further! if (impl->module->getNoise()->getName() != "FFT") impl->module->setNoise(new Hydrax::Noise::FFT()); } else if (configData.contains("noise=perlin", Qt::CaseInsensitive)) { if (impl->module->getNoise()->getName() != "Perlin") impl->module->setNoise(new Hydrax::Noise::Perlin()); } else { LogError("EC_Hydrax: Unknown noise param in loaded config, acceptable = FFT/Perlin."); SAFE_DELETE(impl); return; } // Load config from the asset data string. impl->hydrax->remove(); impl->hydrax->loadCfgString(configData.toStdString()); // Override the shader mode specified in the config - OpenGL should always use GLSL, D3D HLSL. // (Cg is never used, for compatibility, since it requires an extra install and some Linux systems don't always have it enabled) if (QString(Ogre::Root::getSingleton().getRenderSystem()->getName().c_str()).contains("OpenGL")) impl->hydrax->setShaderMode(Hydrax::MaterialManager::SM_GLSL); else impl->hydrax->setShaderMode(Hydrax::MaterialManager::SM_HLSL); impl->hydrax->create(); // The position attribute is always authoritative from the component attribute. if (visible.Get()) impl->hydrax->setPosition(position.Get()); } catch (const Ogre::Exception &e) { LogError(std::string("EC_Hydrax: Ogre threw exception while loading new config: ") + e.what()); if (impl && impl->hydrax) impl->hydrax->remove(); SAFE_DELETE(impl); } }
QString AssetCache::StoreAsset(AssetPtr asset) { std::vector<u8> data; asset->SerializeTo(data); return StoreAsset(&data[0], data.size(), asset->Name()); }