DYTSrouce/src/scene/OsgScene.h
2025-01-04 12:12:51 +08:00

138 lines
3.5 KiB
C++

#pragma once
#if 0
#include <osg/Switch>
#include <osg/TextureCubeMap>
#include <osgText/Text>
#include <osgOcean/OceanScene>
#include <osgOcean/FFTOceanSurface>
#include <osgOcean/FFTOceanSurfaceVBO>
#include "scene/SkyDome.h"
class OsgView;
enum DrawMask {
CAST_SHADOW = (0x1 << 30),
RECEIVE_SHADOW = (0x1 << 29),
};
class OsgScene : public osg::Referenced {
public:
enum SCENE_TYPE {
CLEAR, DUSK, CLOUDY
};
public:
OsgScene(
const osg::Vec2f& windDirection = osg::Vec2f(1.0f, 1.0f),
float windSpeed = 12.f,
float depth = 10000.f,
float reflectionDamping = 0.35f,
float scale = 1e-8,
bool isChoppy = true,
float choppyFactor = -2.5f,
float crestFoamHeight = 2.2f,
double oceanSurfaceHeight = 0.0f,
bool testCollision = false,
bool disableShaders = false,
bool useVBO = false,
bool useShadows = false,
const std::string& terrain_shader_basename = "terrain");
void Build(
const osg::Vec2f& windDirection,
float windSpeed,
float depth,
float reflectionDamping,
float waveScale,
bool isChoppy,
float choppyFactor,
float crestFoamHeight,
double oceanSurfaceHeight,
bool testCollision,
bool disableShaders,
bool useVBO,
bool useShadows,
const std::string& terrain_shader_basename);
void ChangeScene(SCENE_TYPE type);
void UseShadows(bool useDebugDraw);
void InitEventHandle(OsgView* view);
void AttachView(OsgView* view);
void DetachView(OsgView* view);
osg::Node* LoadIslands(const std::string& terrain_shader_basename);
osg::ref_ptr<osg::TextureCubeMap> LoadCubeMapTextures(const std::string& dir);
osg::Geode* SunDebug(const osg::Vec3f& position);
inline osg::Vec4f IntColor(unsigned r, unsigned g, unsigned b, unsigned a = 255) {
float div = 1.f / 255.f;
return osg::Vec4f(div * (float)r, div * (float)g, div * float(b), div * (float)a);
}
inline osgOcean::OceanScene::EventHandler* GetOceanSceneEventHandler() {
return oceanScene_->getEventHandler();
}
inline osgOcean::OceanTechnique* GetOceanSurface(void) {
return FFToceanSurface_.get();
}
osg::Group* GetData();
inline osg::Group* GetScene(void) {
return scene_.get();
}
inline osgOcean::OceanScene* GetOceanScene() {
return oceanScene_.get();
}
void AddToOceanScene(osg::Node* node);
osg::Light* GetLight() {
return light_.get();
}
void TestBuildModel();
private:
SCENE_TYPE sceneType_;
bool useVBO_{ true };
bool disableShaders_{ false };
bool useShadows_{ false };
double oceanSurfaceHeight_{ 0.0 };
osg::ref_ptr<osgText::Text> modeText_;
osg::ref_ptr<osg::Group> scene_;
osg::ref_ptr<osg::Group> entityRoot_;
osg::ref_ptr<osgOcean::OceanScene> oceanScene_;
osg::ref_ptr<osgOcean::FFTOceanTechnique> FFToceanSurface_;
osg::ref_ptr<osg::TextureCubeMap> cubemap_;
osg::ref_ptr<SkyDome> skyDome_;
std::vector<std::string> cubemapDirs_;
std::vector<osg::Vec4f> lightColors_;
std::vector<osg::Vec4f> fogColors_;
std::vector<osg::Vec3f> underwaterAttenuations_;
std::vector<osg::Vec4f> underwaterDiffuse_;
osg::ref_ptr<osg::Light> light_;
std::vector<osg::Vec3f> sunPositions_;
std::vector<osg::Vec4f> sunDiffuse_;
std::vector<osg::Vec4f> waterFogColors_;
osg::ref_ptr<osg::Switch> islandSwitch_;
};
#endif