public MainViewModel() { MeshBuilder builder = new MeshBuilder(); builder.AddCylinder(new SharpDX.Vector3(0, 0, 0), new SharpDX.Vector3(0, 0, 10), 5); MeshNode node = new MeshNode(); node.Geometry = builder.ToMesh(); node.Material = DiffuseMaterials.Blue; GroupModel.AddNode(node); // EffectsManager = new DefaultEffectsManager(); Camera = new OrthographicCamera() { LookDirection = new SharpDX.Vector3(0, -10, -10), Position = new SharpDX.Vector3(0, 10, 10), UpDirection = new SharpDX.Vector3(0, 1, 0), FarPlaneDistance = 5000, NearPlaneDistance = 0.1f }; }
public void LoadModel(string fileName) { var dialogViewModel = new DialogViewModel(); HelixToolkitScene scene = null; dialogViewModel.AddTask ( (taskContext) => { taskContext.UpdateMessage($"Loading model {Path.GetFileNameWithoutExtension(fileName)}"); var loader = new Importer(); scene = loader.Load(fileName); taskContext.UpdateProgress(100); } ); this.windowManager.ShowDialog(dialogViewModel); GroupModel.Clear(); if (scene != null) { this.sceneNode = scene.Root; GroupModel.AddNode(this.sceneNode); this.SetSceneMaterials(); } }
public void ImportModel() { if (IsLoading) { return; } string selectedFilePath = OpenFileDialogWithFilter(MainViewModel.SUPPORTED_3D_FILE_FILTER); if (selectedFilePath == null) { return; } //TODO StopAnimation here IsLoading = true; Task.Run(() => { Importer importer = new Importer(); //true로 설정하면 뼈대가 보인다 importer.Configuration.CreateSkeletonForBoneSkinningMesh = true; //importer.Configuration.SkeletonSizeScale = 0.04f; //importer.Configuration.GlobalScale = 0.1f; //Importer의 Load 메소드는 선택된 파일의 유효성 (호환성)을 검사한다. //내부에서 BuildScene이라는 Node를 조립하는 메소드를 호출한다. return(importer.Load(selectedFilePath)); }).ContinueWith((resultScene) => { IsLoading = false; if (resultScene.IsCompleted) { scene = resultScene.Result; Animations.Clear(); GroupModel.Clear(); if (scene != null) { GroupModel.AddNode(scene.Root); if (scene.HasAnimation) { foreach (var ani in scene.Animations) { Animations.Add(ani); } } if (scene.Root != null) { foreach (var node in scene.Root.Traverse()) { if (node is BoneSkinMeshNode boneNode) { if (boneNode.IsSkeletonNode) { skeletonNodes.Add(boneNode); boneNode.Visible = false; } else { boneNode.IsThrowingShadow = true; boneNode.WireframeColor = new SharpDX.Color4(0, 0, 1, 1); boneSkinNodes.Add(boneNode); //boneNode.MouseDown += OnMouseDown_Model; } } node.Tag = new CustomDataModel(node); } } } } else if (resultScene.IsFaulted && resultScene.Exception != null) { MessageBox.Show(resultScene.Exception.Message); } }, TaskScheduler.FromCurrentSynchronizationContext()); return; }
//--------------------------------------------------------------------------------------------------------- /// <summary> /// Открытие файла /// </summary> //--------------------------------------------------------------------------------------------------------- public void OpenFile(TreeView model_tree_view) { if (mIsLoading) { return; } String path = XFileDialog.OpenUseExtension("Открыть 3D файл", OpenFileFilter); if (path == null) { return; } StopAnimation(); // Create the FBX SDK manager FbxManager lSdkManager = FbxManager.Create(); // Create an IOSettings object. FbxIOSettings ios = FbxIOSettings.Create(lSdkManager, Globals.IOSROOT); lSdkManager.SetIOSettings(ios); // ... Configure the FbxIOSettings object ... // Create an importer. FbxImporter lImporter = FbxImporter.Create(lSdkManager, ""); // Initialize the importer. bool lImportStatus = lImporter.Initialize(path, -1, lSdkManager.GetIOSettings()); mIsLoading = true; Task.Run(() => { var loader = new Importer(); //loader.Configuration.AssimpPostProcessSteps = //loader.Configuration.AssimpPostProcessSteps | //Assimp.PostProcessSteps.OptimizeGraph; return(loader.Load(path)); }).ContinueWith((result) => { mIsLoading = false; if (result.IsCompleted) { HelixToolkitScene helix_toolkit_scene = result.Result; if (helix_toolkit_scene == null) { return; } mSceneRoot = helix_toolkit_scene.Root; mSceneAnimations = helix_toolkit_scene.Animations; Animations.Clear(); GroupModel.Clear(); if (helix_toolkit_scene != null) { if (helix_toolkit_scene.Root != null) { foreach (var node in helix_toolkit_scene.Root.Traverse()) { if (node is MaterialGeometryNode m) { if (m.Material is PBRMaterialCore pbr) { pbr.RenderEnvironmentMap = RenderEnvironmentMap; } else if (m.Material is PhongMaterialCore phong) { phong.RenderEnvironmentMap = RenderEnvironmentMap; } } } } GroupModel.AddNode(helix_toolkit_scene.Root); if (helix_toolkit_scene.HasAnimation) { var dict = helix_toolkit_scene.Animations.CreateAnimationUpdaters(); foreach (var animation in dict.Values) { Animations.Add(animation); } } foreach (var node in helix_toolkit_scene.Root.Traverse()) { //node.Tag = new AttachedNodeViewModel(node); } } Boolean is_y_up = threeViewer.IsModelUpDirectionY(); checkBoxYUpModel.IsChecked = is_y_up; if (is_y_up) { } model_tree_view.ItemsSource = mSceneRoot.Items; //Scene = new CScene3D() } else if (result.IsFaulted && result.Exception != null) { MessageBox.Show(result.Exception.Message); } }, TaskScheduler.FromCurrentSynchronizationContext()); }