예제 #1
0
        static void Main(string[] args)
        {
            Raylib.InitWindow(1366, 768, "Foam Test");
            Raylib.SetTargetFPS(60);

            //args = new string[] { "C:/Projekti/Foam/bin/mapfoam/sample/test.mapfoam" };
            //args = new[] { "C:/Projekti/Ray/build/bin/sample/light_test.mapfoam" };

            Cam3D = new Camera3D(new Vector3(1, 1, 1), Vector3.Zero, Vector3.UnitY);
            Raylib.SetCameraMode(Cam3D, CameraMode.CAMERA_FREE);

            Model[]   Models    = null;
            FoamModel FoamModel = null;

            bool DrawText        = true;
            bool DrawWireframe   = false;
            bool DrawSkeleton    = true;
            bool UpdateAnimation = true;

            while (!Raylib.WindowShouldClose())
            {
                if (Raylib.IsKeyPressed(KeyboardKey.KEY_F1))
                {
                    DrawText = !DrawText;
                }

                if (Raylib.IsKeyPressed(KeyboardKey.KEY_F2))
                {
                    DrawWireframe = !DrawWireframe;
                }

                if (Raylib.IsKeyPressed(KeyboardKey.KEY_F3))
                {
                    DrawSkeleton = !DrawSkeleton;
                }

                if (Raylib.IsKeyPressed(KeyboardKey.KEY_F4))
                {
                    UpdateAnimation = !UpdateAnimation;
                }

                if (Raylib.IsFileDropped() || (args != null && args.Length > 0))
                {
                    string DroppedFile = null;

                    if (args != null && args.Length > 0)
                    {
                        DroppedFile = args[0];
                        args        = null;
                    }
                    else
                    {
                        DroppedFile = Raylib.GetDroppedFiles()[0];
                    }

                    Model[] NewModels = LoadModels(DroppedFile, out float Scale, out FoamModel NewFoamModel);

                    if (NewModels != null && NewFoamModel != null)
                    {
                        if (NewModels.Length == 0 && NewFoamModel.Animations != null && FoamModel != null)
                        {
                            foreach (var NewAnim in NewFoamModel.Animations)
                            {
                                Utils.Append(ref FoamModel.Animations, NewAnim);
                            }
                        }
                        else
                        {
                            if (Models != null)
                            {
                                foreach (var M in Models)
                                {
                                    Raylib.UnloadModel(M);
                                }
                            }

                            Models    = NewModels;
                            FoamModel = NewFoamModel;

                            //Cam3D.position = new Vector3(0.5f, 0.25f, 0.5f) * Scale;
                            //Cam3D.target = new Vector3(0, 0.25f, 0) * Scale;
                        }
                    }

                    Raylib.ClearDroppedFiles();
                }

                /*if (Models != null)
                 *      UpdateModel(FoamModel, FrameIndex);*/

                Raylib.BeginDrawing();
                Raylib.ClearBackground(new Color(50, 50, 50));
                //Raylib.ClearBackground(new Color(0, 0, 0));

                if (Models != null)
                {
                    Raylib.UpdateCamera(ref Cam3D);
                    Raylib.BeginMode3D(Cam3D);


                    for (int i = 0; i < Models.Length; i++)
                    {
                        if (DrawWireframe)
                        {
                            Raylib.DrawModelWires(Models[i], Vector3.Zero, 1, Color.White);
                        }
                        else
                        {
                            Raylib.DrawModel(Models[i], Vector3.Zero, 1, Color.White);
                        }
                    }

                    if (UpdateAnimation)
                    {
                        UpdateModelAnimation(FoamModel);
                    }

                    if (FoamModel != null && DrawSkeleton)
                    {
                        DrawBones(FoamModel);
                    }

                    Raylib.EndMode3D();

                    if (DrawText)
                    {
                        if (WorldTexts != null)
                        {
                            foreach (var KV in WorldTexts)
                            {
                                Raylib.DrawText(KV.Value, (int)KV.Key.X, (int)KV.Key.Y, 10, Color.White);
                            }
                        }
                    }
                }

                DrawTextLine("F1 - Toggle bone names", 0);
                DrawTextLine("F2 - Toggle wireframe", 1);
                DrawTextLine("F3 - Toggle skeleton", 2);
                DrawTextLine("F4 - Toggle animations", 3);

                Raylib.DrawFPS(5, 5);
                Raylib.EndDrawing();
            }
        }