コード例 #1
0
        async static Task Main(string[] args)
        {
            try
            {
                ConsoleHelper.Initialize();

                // Print identity.
                Console.WriteLine("Tugas Kelompok Teknik Visualisasi Grafis - Transformasi 3D");
                Console.WriteLine("Identitas Anggota Kelompok :");
                Console.WriteLine("Daffa Bil Nadzary                19/439811/TK/48541");
                Console.WriteLine("Firdaus Bisma Suryakusuma        19/444051/TK/49247");
                Console.WriteLine("Hafizh Aradhana Harimurti        19/444053/TK/49249");
                Console.WriteLine("Please wait a while.");
                Console.WriteLine();
                await Task.Delay(3000);

                // Start up renderer
                _renderer = new RendererServer();

                Console.WriteLine();

                // Load default model
                Console.WriteLine("Loading default model(cube)...");
                var modelFileContent = File.ReadAllText($"./Models/default-cube.txt");
                _model         = ModelData.Deserialize(modelFileContent);
                _originalModel = _model.Clone();
                await _renderer.RenderAwaitableAsync(_originalModel);

                // Load default scene
                Console.WriteLine("Loading default scene...");
                var sceneFileContent = File.ReadAllText($"./Scenes/default-scene.txt");
                _scene = SceneData.Deserialize(sceneFileContent);
                await _renderer.SetSceneAwaitableAsync(_scene);

                Console.WriteLine();

                // Prompt action
                while (true)
                {
                    Console.WriteLine("Select an action :");
                    Console.WriteLine("[0] Load model");
                    Console.WriteLine("[1] Load scene");
                    Console.WriteLine("[2] Save model");
                    Console.WriteLine("[3] Save scene");
                    Console.WriteLine("[4] Perform a single transformation");
                    Console.WriteLine("[5] Chain multiple transformations");
                    Console.WriteLine("[6] Inspect model");
                    Console.WriteLine("[7] Stop inspecting model");
                    Console.WriteLine("[8] Reset model");
                    Console.WriteLine("[9] Exit");
                    Console.Write("Select : ");
                    var ans = Console.ReadLine();
                    Console.WriteLine();

                    if (ans == "9")
                    {
                        break;
                    }

                    switch (ans)
                    {
                    case "0":
                        if (_inspectionCancellation != null)
                        {
                            _inspectionCancellation.Cancel();
                        }
                        await LoadModel();

                        break;

                    case "1":
                        if (_inspectionCancellation != null)
                        {
                            _inspectionCancellation.Cancel();
                        }
                        await LoadScene();

                        break;

                    case "2":
                        if (_inspectionCancellation != null)
                        {
                            _inspectionCancellation.Cancel();
                        }
                        _model.Serialize();
                        Console.Write("Input desired model name without .txt extension : ");
                        var _modelName = Console.ReadLine();
                        SaveModel($"./Models/{_modelName}.txt", _model);
                        break;

                    case "3":
                        if (_inspectionCancellation != null)
                        {
                            _inspectionCancellation.Cancel();
                        }
                        _scene.Serialize();
                        Console.WriteLine("Input desired scene name without .txt extension : ");
                        var _sceneName = Console.ReadLine();
                        SaveScene($"./Models/{_sceneName}.txt", _scene);
                        break;

                    case "4":
                        if (_inspectionCancellation != null)
                        {
                            _inspectionCancellation.Cancel();
                        }
                        _preTransformedModel = _model.Clone();
                        BeginTransformation(false);
                        await _renderer.RenderAwaitableAsync(_model);

                        break;

                    case "5":
                        if (_inspectionCancellation != null)
                        {
                            _inspectionCancellation.Cancel();
                        }
                        _preTransformedModel = _model.Clone();
                        BeginTransformation(true);
                        await _renderer.RenderAwaitableAsync(_model);

                        break;

                    case "6":
                        if (_inspectionCancellation != null)
                        {
                            _inspectionCancellation.Cancel();
                        }
                        _inspectionCancellation = new CancellationTokenSource();
                        InspectModel(_inspectionCancellation.Token);
                        break;

                    case "7":
                        _inspectionCancellation.Cancel();
                        _inspectionCancellation = null;
                        break;

                    case "8":
                        _model = _originalModel.Clone();
                        await _renderer.RenderAwaitableAsync(_model);

                        if (_inspectionCancellation != null)
                        {
                            _inspectionCancellation.Cancel();
                        }
                        break;

                    default:
                        if (_inspectionCancellation != null)
                        {
                            _inspectionCancellation.Cancel();
                        }
                        WriteError("Action not recognized.");
                        break;
                    }

                    Console.WriteLine();
                }

                Console.WriteLine("Press any key to exit...");
                Console.ReadKey();

                _renderer.Close();
            }
            catch (Exception e)
            {
                WriteError(e.Message);
            }
        }
コード例 #2
0
 private static void SaveScene(string path, SceneData scene)
 {
     File.WriteAllText(path, scene.Serialize());
 }