// ************************************************************************************************* void CSky::init(UDriver *drv, const CSkySheet &sheet, bool forceFallbackVersion /*= false*/, float numHourInDay /*= 24.f*/, std::vector<std::string> *unsupportedObjects /*= NULL*/) { release(); if(!drv) return; _Driver = drv; // create a new scene for the sky _Scene = _Driver->createScene(true); _Scene->setupTransparencySorting(99, 1); // only sort by priority (99 of them) _AnimLengthInSeconds = sheet.AnimLengthInSeconds; // create animation set if (!sheet.AnimationName.empty()) { _PlayListManager = _Scene->createPlayListManager(); if (_PlayListManager) { _AnimationSet = _Driver->createAnimationSet(); _PlayList = _PlayListManager->createPlayList(_AnimationSet); if (_AnimationSet && _PlayList) { uint animationID = _AnimationSet->addAnimation(sheet.AnimationName.c_str(), sheet.AnimationName.c_str()); if (animationID != UAnimationSet::NotFound) { _AnimationSet->build(); _PlayList->setAnimation(0, animationID); _PlayList->setTimeOrigin(0, 0); _PlayList->setWrapMode(0, UPlayList::Repeat); } else { // no animation loaded _PlayListManager->deletePlayList(_PlayList); _Scene->deletePlayListManager(_PlayListManager); _Driver->deleteAnimationSet(_AnimationSet); _PlayListManager = NULL; _PlayList = NULL; _AnimationSet = NULL; } } } } // load instance group of sky _IG = UInstanceGroup::createInstanceGroup(sheet.InstanceGroupName); if (!_IG) { nlwarning("Couldn't load sky ig : %s", sheet.InstanceGroupName.c_str()); release(); return; } _IG->addToScene(*_Scene, drv); _Objects.reserve(sheet.Objects.size()); // dump name of objects in the scene //nlinfo("Sky scene objects : "); for(uint k = 0; k < _IG->getNumInstance(); ++k) { //nlinfo(_IG->getInstanceName(k).c_str()); UInstance i = _IG->getInstance(k); // hide all instances by default if (!i.empty()) i.hide(); } if (unsupportedObjects) unsupportedObjects->clear(); // map name of a bitmap to the actual bitmap (for reuse of bitmaps) std::map<std::string, CBitmap *> buildShareBitmapByName; // for(uint k = 0; k < sheet.Objects.size(); ++k) { UInstance instance; instance = _IG->getByName(sheet.Objects[k].Std.ShapeName); // should main instance if driver supports its rendering // hide all the instance at start if (!instance.empty() && !instance.supportMaterialRendering(*drv, forceFallbackVersion)) { if (unsupportedObjects) { unsupportedObjects->push_back(sheet.Objects[k].Std.ShapeName); } instance.hide(); // build fallbacks for(uint l = 0; l < 2; ++l) { UInstance fallbackInstance = _IG->getByName(sheet.Objects[k].FallbackPass[l].ShapeName); if (!fallbackInstance.empty()) { fallbackInstance.hide(); CSkyObject so; so.init(sheet.Objects[k].FallbackPass[l], fallbackInstance, buildShareBitmapByName, _Bitmaps, sheet.Objects[k].VisibleInMainScene, sheet.Objects[k].VisibleInEnvMap); _Objects.push_back(so); if (_PlayList) { _PlayList->registerTransform(fallbackInstance, (sheet.Objects[k].FallbackPass[l].ShapeName + ".").c_str()); } } } } else if (!instance.empty()) { instance.hide(); // uses main instance and hides fallback instances CSkyObject so; so.init(sheet.Objects[k].Std, instance, buildShareBitmapByName, _Bitmaps, sheet.Objects[k].VisibleInMainScene, sheet.Objects[k].VisibleInEnvMap); _Objects.push_back(so); for(uint l = 0; l < 2; ++l) { UInstance fallbackInstance = _IG->getByName(sheet.Objects[k].FallbackPass[l].ShapeName); if (!fallbackInstance.empty()) fallbackInstance.hide(); } if (_PlayList) { _PlayList->registerTransform(instance, (sheet.Objects[k].Std.ShapeName + ".").c_str()); } } else { nlwarning("Object not found in scene : %s", sheet.Objects[k].Std.ShapeName.c_str()); } } // get gradient that gives sun light color bool alreadyBuilt; _AmbientSunLight = buildSharedBitmap(sheet.AmbientSunLightBitmap, buildShareBitmapByName, _Bitmaps, alreadyBuilt); _DiffuseSunLight = buildSharedBitmap(sheet.DiffuseSunLightBitmap, buildShareBitmapByName, _Bitmaps, alreadyBuilt); // _FogColor = buildSharedBitmap(sheet.FogColorBitmap, buildShareBitmapByName, _Bitmaps, alreadyBuilt); // _NumHourInDay = numHourInDay; _WaterEnvMapCameraHeight = sheet.WaterEnvMapCameraHeight; _WaterEnvMapAlpha= sheet.WaterEnvMapAlpha; }