コード例 #1
0
ファイル: BunnyDemo.cs プロジェクト: MuffinTrap/Demo
 private void DrawStarSky(Renderer renderer, bool warp = false)
 {
     renderer.SetActiveSkybox(starSkyboxMaterial);
     renderer.SetSkyboxRotation(starSkyBox.Transform.CreateRotationMatrixFromAxisAngle());
     if (warp)
     {
         CameraComponent cam     = renderer.GetCamera();
         float           prevFOV = cam.FOV;
         cam.FOV = 90 + SyncSystem.GetSingleton().GetTrackValue(warpFOV);
         cam.CreateMatrices();
         renderer.RenderSky(starSkyBox);
         cam.FOV = prevFOV;
         cam.CreateMatrices();
     }
     else
     {
         renderer.RenderSky(starSkyBox);
     }
 }
コード例 #2
0
ファイル: BunnyDemo.cs プロジェクト: MuffinTrap/Demo
        public void Load(AssetManager assetManager, SyncSystem syncSystem)
        {
            TunableManager tm = TunableManager.GetSingleton();

            lightController = new InstanssiLightController(
                tm.GetString("demosettings.light_server_ip")
                , tm.GetString("demosettings.light_server_host_name")
                , tm.GetInt("demosettings.light_server_port")
                , tm.GetInt("bunny_lights.amount")
                , tm.GetInt("demosettings.physical_lights_amount")
                , tm.GetInt("demosettings.light_server_interval"));

            mountainsNumber = tm.GetInt("scene_number.mountains");
            moonNumber      = tm.GetInt("scene_number.moon");
            bunnyNumber     = tm.GetInt("scene_number.bunny");
            warpNumber      = tm.GetInt("scene_number.warp");
            seaNumber       = tm.GetInt("scene_number.sea");
            crystalsNumber  = tm.GetInt("scene_number.crystals");

            // Audio
            Logger.LogInfo("Loading demo audio");
            string audioFileName = tm.GetString("audio.filename");

            music = audioSystem.LoadAudioFile(audioFileName);

            syncSystem.SetAudioProperties(tm.GetInt("audio.bpm"), tm.GetFloat("audio.length_seconds")
                                          , tm.GetInt("audio.rows_per_beat"));
            syncSystem.SetManualSceneAdvanceRate(tm.GetFloat("sync.manual_scene_advance_speed"));

            // Camera
            CameraComponent camera = Renderer.GetSingleton().GetCamera();

            camera.FOV       = tm.GetFloat("camera.fov");
            camera.Speed     = tm.GetFloat("camera.speed");
            camera.SpeedStep = tm.GetFloat("camera.speed_step");
            camera.Near      = tm.GetFloat("camera.near_plane");
            camera.Far       = tm.GetFloat("camera.far_plane");
            camera.CreateMatrices();

            // Camera frames
            Logger.LogInfo("Loading demo frames");
            List <PosAndDir> frames = new List <PosAndDir>();
            int frameAmount         = tm.GetInt("camera_frames.amount");

            for (int frameI = 0; frameI < frameAmount; frameI++)
            {
                Vector3 pos = tm.GetVec3("camera_frames.frame_" + frameI + "_pos");
                Vector3 dir = tm.GetVec3("camera_frames.frame_" + frameI + "_dir");
                frames.Add(new PosAndDir(pos, dir));
            }
            Renderer.GetSingleton().SetCameraFrames(frames);

            // Shaders
            Logger.LogInfo("Loading demo shaders");
            ShaderProgram diamondShader = assetManager.GetShaderProgram("diamond");
            ShaderProgram texShader     = assetManager.GetShaderProgram("texturedobjmesh");
            ShaderProgram gridShader    = assetManager.GetShaderProgram("gridmesh");
            ShaderProgram objShader     = assetManager.GetShaderProgram("litobjmesh");
            ShaderProgram skyboxProgram = assetManager.GetShaderProgram("skybox");
            ShaderProgram starProgram   = assetManager.GetShaderProgram("sky");

            guiShader = assetManager.GetShaderProgram("gui");

            cameraFOV = syncSystem.GetTrack("FOV");
            warpFOV   = syncSystem.GetTrack("W_FOV");


            // Fade
            if (guiShader == null)
            {
                Logger.LogError(Logger.ErrorState.Critical, "Did not get gui shader");
            }
            fadeoutAlpha = syncSystem.GetTrack("FadeOut");

            Material fadeoutMaterial = new Material("blackfadeout");

            fadeoutMaterial.textureMaps.Add(ShaderUniformName.DiffuseMap, MaterialManager.GetSingleton().GetColorTextureByName("black"));
            MaterialManager.GetSingleton().AddNewMaterial(fadeoutMaterial);

            fadeoutQuad = assetManager.CreateMesh("black_overlay"
                                                  , MeshDataGenerator.CreateQuadMesh(false, true)
                                                  , fadeoutMaterial.materialName
                                                  , guiShader
                                                  , tm.GetVec3("fade.position"));

            fadeoutQuad.Transform.Scale = tm.GetFloat("fade.scale");


            // Skybox
            starSkyBox = assetManager.CreateMesh("stars"
                                                 , MeshDataGenerator.CreateSkybox()
                                                 , null
                                                 , skyboxProgram
                                                 , new Vector3(0, 0, 0));

            starSkyboxMaterial = assetManager.GetMaterial(tm.GetString("mountain_scene.skybox_material"));

            starSkyBox.Transform.SetRotationAxis(tm.GetVec3("mountain_scene.star_rotation_axis"));
            skyRotation = syncSystem.GetTrack("Sky_R");

            // Lights

            mountainLight = Light.CreateDirectionalLight(tm.GetVec3("mountain_light.color")
                                                         , tm.GetFloat("mountain_light.ambient"), tm.GetFloat("mountain_light.intensity")
                                                         , tm.GetVec3("mountain_light.direction"));

            // Models
            Logger.LogInfo("Loading demo models");
            Logger.LogInfo(" - Bunny");
            bunnyMesh = assetManager.GetMesh("bunny"
                                             , tm.GetString("bunny.model")
                                             , tm.GetString("bunny.material")
                                             , assetManager.GetShaderProgram(tm.GetString("bunny.shader"))
                                             , tm.GetVec3("bunny.position"));

            bunnyMesh.Transform.Scale = tm.GetFloat("bunny.scale");
            bunnyMesh.Transform.SetRotationAxis(new Vector3(0, 1, 0));
            bunnyRotation = syncSystem.GetTrack("bunny_R");

            bunnyLights = new List <LightMesh>();
            int bunnyLightAmount = tm.GetInt("bunny_lights.amount");

            LoadLightMeshList(tm, assetManager, bunnyMesh.Transform, "bunny_lights", bunnyLightAmount, texShader, ref bunnyLights);

            bunnyLightsSizesLocations = new List <int>();
            for (int i = 0; i < bunnyLights.Count; i++)
            {
                int location = bunnyMesh.ShaderProgram.GetCustomUniformLocation("ucLightSizes[" + i + "]");
                bunnyLightsSizesLocations.Add(location);
            }

            bunnyLightProgress = syncSystem.GetTrack("bunny_L");

            Logger.LogInfo(" - Monolith");
            monolith = assetManager.CreateMesh("monolith"
                                               , MeshDataGenerator.CreateCubeMesh(tm.GetVec3("monolith.size")
                                                                                  , true, true)
                                               , tm.GetString("monolith.material")
                                               , objShader
                                               , tm.GetVec3("monolith.position"));

            monolith.Transform.SetRotationAxis(new Vector3(0, 1, 0));
            monolith.Transform.Scale = tm.GetFloat("monolith.scale");
            monolithRotation         = syncSystem.GetTrack("mono_R");
            monolithElevation        = syncSystem.GetTrack("mono_Y");

            // DEBUG
            monolith_normals = assetManager.CreateMesh("mono_N"
                                                       , MeshDataGenerator.CreateNormalDebug(monolith.Data.positions, monolith.Data.normals)
                                                       , null
                                                       , gridShader
                                                       , monolith.Transform.GetWorldPosition());

            monolith_normals.Transform.Parent = monolith.Transform;

            Logger.LogInfo(" - Telescope");
            telescope = new Telescope();

            telescope.tower = assetManager.GetMesh("tele_tower"
                                                   , tm.GetString("telescope.tower_model")
                                                   , tm.GetString("telescope.material")
                                                   , objShader
                                                   , tm.GetVec3("telescope.tower_position"));

            telescope.tower.Transform.Scale = tm.GetFloat("telescope.tower_scale");
            telescope.tower.Transform.SetRotationAxis(new Vector3(0, 1, 0));

            telescope.antenna = assetManager.GetMesh("tele_antenna"
                                                     , tm.GetString("telescope.antenna_model")
                                                     , tm.GetString("telescope.material")
                                                     , objShader
                                                     , tm.GetVec3("telescope.antenna_position"));
            telescope.antenna.Transform.Scale = tm.GetFloat("telescope.antenna_scale");
            telescope.antenna.Transform.SetRotationAxis(new Vector3(0, 0, 1));

            telescope.antenna.Transform.Parent = telescope.tower.Transform;
            telescopeElevation = syncSystem.GetTrack("Tele_Elev");
            telescopeRotation  = syncSystem.GetTrack("Tele_Rot");

            mainTelescopePosition = tm.GetVec3("telescope.tower_position");

            // Telescope array
            int     teleAmount      = tm.GetInt("telescope_array.amount");
            Vector3 teleArrayCorner = tm.GetVec3("telescope_array.position");
            Vector3 teleArrayDir1   = tm.GetVec3("telescope_array.dir");
            Vector3 teleArrayDir2   = tm.GetVec3("telescope_array.dir2");
            float   spacing         = tm.GetFloat("telescope_array.spacing");

            telescopeArrayPositions = new List <Vector3>();
            for (int t = 0; t < teleAmount; t++)
            {
                telescopeArrayPositions.Add(teleArrayCorner + teleArrayDir1 * spacing * (t + 1));
                telescopeArrayPositions.Add(teleArrayCorner + teleArrayDir2 * spacing * (t + 1));
            }

            // Sea
            Logger.LogInfo(" - Sea");
            seaShader = assetManager.GetShaderProgram("heightMapTerrain");

            Vector2 seaSize             = tm.GetVec2("sea.size");
            float   seaTrianglesDensity = tm.GetFloat("sea.detail_level");
            Vector2 seaUVRepeat         = tm.GetVec2("sea.UV_repeat");

            seaMesh = assetManager.CreateMesh("sea"
                                              , MeshDataGenerator.CreateTerrain(seaSize.X, seaSize.Y, seaTrianglesDensity, true, true
                                                                                , seaUVRepeat.X, seaUVRepeat.Y)
                                              , tm.GetString("sea.material")
                                              , objShader
                                              , tm.GetVec3("sea.position"));

            // Planet mountains
            Logger.LogInfo(" - Planet Mountains");
            planetMountains = assetManager.CreateMesh("planet_mountains"
                                                      , MeshDataGenerator.CreateMountains(
                                                          tm.GetFloat("planet_mountain.size")
                                                          , true, tm.GetInt("planet_mountain.iterations")
                                                          , tm.GetFloat("planet_mountain.height_variation")
                                                          , tm.GetFloat("planet_mountain.flat_start")
                                                          , tm.GetFloat("planet_mountain.flat_end")
                                                          , tm.GetInt("planet_mountain.random_seed"))
                                                      , tm.GetString("planet_mountain.material")
                                                      , objShader
                                                      , tm.GetVec3("planet_mountain.position"));

            planetLight = Light.CreateDirectionalLight(tm.GetVec3("planet_light.color")
                                                       , tm.GetFloat("planet_light.ambient"), tm.GetFloat("planet_light.intensity")
                                                       , tm.GetVec3("planet_light.direction"));

            planetSkyBox = assetManager.CreateMesh("planet_skybox"
                                                   , MeshDataGenerator.CreateSkybox()
                                                   , null
                                                   , skyboxProgram
                                                   , new Vector3(0, 0, 0));

            planetSkyboxMaterial = assetManager.GetMaterial("planet_skybox");


            // Mountains
            Logger.LogInfo(" - Mountains");
            mountains = assetManager.CreateMesh("mountains"
                                                , MeshDataGenerator.CreateMountains(
                                                    tm.GetFloat("mountain.size")
                                                    , true, tm.GetInt("mountain.iterations")
                                                    , tm.GetFloat("mountain.height_variation")
                                                    , tm.GetFloat("mountain.flat_start")
                                                    , tm.GetFloat("mountain.flat_end")
                                                    , tm.GetInt("mountain.random_seed"))
                                                , tm.GetString("mountain.material")
                                                , objShader
                                                , tm.GetVec3("mountain.position"));

            // Crystals
            Logger.LogInfo(" - Crystals");

            crystalMeshes = new List <Crystal>();
            int     crystalAmount = tm.GetInt("crystals.amount");
            Random  randomizer    = new Random(0);
            float   areaSize      = tm.GetFloat("crystals.area_size");
            float   areaTop       = tm.GetFloat("crystals.area_top");
            Vector3 areaPos       = tm.GetVec3("crystals.area_pos");
            float   maxSpeed      = tm.GetFloat("crystals.max_speed");
            float   sizeMin       = tm.GetFloat("crystals.min_size");
            float   sizeMax       = tm.GetFloat("crystals.max_size");

            for (int s = 0; s < crystalAmount; s++)
            {
                Crystal c = new Crystal();

                Vector3 position = new Vector3((float)randomizer.NextDouble() - 0.5f
                                               , (float)randomizer.NextDouble()
                                               , (float)randomizer.NextDouble() - 0.5f);

                position  = position * new Vector3(areaSize, areaSize, areaSize);
                position += areaPos;

                c.mesh = assetManager.CreateMesh("crystal_" + s
                                                 , MeshDataGenerator.CreateStar(new Vector3(1.0f, 0, 0), new Vector3(0, 1, 0)
                                                                                , 1.0f, 2.0f, 0.5f, 0.8f, true)
                                                 , tm.GetString("crystals.material")
                                                 , assetManager.GetShaderProgram(tm.GetString("crystals.shader"))
                                                 , position);

                c.mesh.Transform.Scale = sizeMin + (float)randomizer.NextDouble() * (sizeMax - sizeMin);
                c.mesh.Transform.SetRotationAxis(position.Normalized());
                c.speed = (float)randomizer.NextDouble() * maxSpeed;
                crystalMeshes.Add(c);
            }

            crystalsGravity = tm.GetFloat("crystals.gravity");

            Logger.LogInfo("Creating greetings");
            // Title, Greets and credits
            TextGenerator textgen        = TextGenerator.GetSingleton();
            string        greet_font     = tm.GetString("text.font");
            PixelFont     greetFont      = textgen.GetFont(greet_font);
            string        greet_material = tm.GetString("text.material");
            ShaderProgram greetShader    = assetManager.GetShaderProgram(tm.GetString("text.shader"));
            float         textStep       = tm.GetFloat("text.step");

            // Title
            string titleMaterial = tm.GetString("mountain_text.title_material");
            string groupMaterial = tm.GetString("mountain_text.group_material");

            DrawableMesh groupName = assetManager.CreateMesh("groupText"
                                                             , MeshDataGenerator.CreateQuadMesh(false, true)
                                                             , groupMaterial
                                                             , greetShader
                                                             , tm.GetVec3("mountain_scene.group_name_position"));

            groupName.Transform.Scale = tm.GetFloat("mountain_scene.group_name_scale");

            groupNameGreet          = new Greeting();
            groupNameGreet.textMesh = groupName;
            groupNameGreet.alpha    = 0.0f;
            groupNameGreet.color    = tm.GetVec3("mountain_text.color");


            DrawableMesh demoName = assetManager.CreateMesh("groupText"
                                                            , MeshDataGenerator.CreateQuadMesh(false, true)
                                                            , titleMaterial
                                                            , greetShader
                                                            , tm.GetVec3("mountain_scene.demo_name_position"));

            demoName.Transform.Scale = tm.GetFloat("mountain_scene.demo_name_scale");

            demoNameGreet          = new Greeting();
            demoNameGreet.textMesh = demoName;
            demoNameGreet.alpha    = 0.0f;
            demoNameGreet.color    = tm.GetVec3("mountain_text.color");

            // Greets
            Vector3 greetOffset  = tm.GetVec3("text.offset");
            Vector3 greetSpacing = tm.GetVec3("text.spacing");
            float   greetScale   = tm.GetFloat("text.scale");

            group_greetings = new List <GreetPage>();
            Vector3 monoGreetColor = tm.GetVec3("monolith_greets.color");

            CreateGreets(tm, assetManager, "monolith_greets", greetFont, greet_material, monoGreetColor, greetShader
                         , greetOffset, greetSpacing, greetScale
                         , textStep, monolith.Transform, ref group_greetings);

            // Credits
            credits = new List <GreetPage>();
            Vector3 creditsOffset    = tm.GetVec3("credits.offset");
            Vector3 creditsSpacing   = tm.GetVec3("credits.spacing");
            float   creditsScale     = tm.GetFloat("credits.scale");
            Vector3 creditGreetColor = tm.GetVec3("credits.color");

            CreateGreets(tm, assetManager, "credits", greetFont, greet_material, creditGreetColor, greetShader
                         , creditsOffset, creditsSpacing, creditsScale
                         , textStep, monolith.Transform, ref credits);

            textAlpha = syncSystem.GetTrack("text_A");

            Logger.LogInfo("Creating title and name");
            title = new List <GreetPage>();
            GreetPage titlePage = new GreetPage();

            titlePage.greets.Add(groupNameGreet);
            titlePage.greets.Add(demoNameGreet);

            title.Add(titlePage);

            if (settings.LightServer)
            {
                lightController.StartSync();
            }
            Logger.LogPhase("Bunny demo is loaded");
            syncSystem.PrintEditorRowAmount();
        }