/* * private void ExecLayoutHere(object sender, EventArgs args) * { * var focusedLayout = ViewService.Viewport.FocusedLayout; * var newLayout = new ScreenPlaneLayout(); * var parentGlobalTransform = focusedLayout.ChildPlacementComponent.GetParentGlobalTransformForNewChild3D(); * var globalFrame = ViewService.Viewport.Camera.GetGlobalFrame(); * var scale = parentGlobalTransform.Scale; * var rotation = Quaternion.RotationToFrame(globalFrame.Right, globalFrame.Forward); * var pos = globalFrame.Eye; * var globalTransform = new Transform(scale, rotation, pos); * var localTransform = globalTransform * parentGlobalTransform.Invert(); * newLayout.Name = "FloatingLayout"; * newLayout.LocalTransform = localTransform; * focusedLayout.ChildNodes.Add(newLayout); * }*/ private void ExecMove() { var entity = ViewService.SelectedNode; if (!entity?.HasComponent <ITransformable3DComponent>() ?? false) { return; } var tool = toolFactory.MoveEntity(entity, false); toolService.CurrentTool = tool; }
public DefaultMainForm(IUndoRedoService undoRedoService, IToolFactory toolFactory, IToolService toolService, RenderControl renderControl, IAppModesCommands appModesCommands, ISaveLoadGuiCommands saveLoadGuiCommands, ISceneTreeGui sceneTreeGui, /*IPropsGui propsGui,*/ IFluentGuiService fluentGuiService, IAmDiBasedObjectFactory objectFactory, IAssetService assetService, IEmbeddedResources embeddedResources, IResourceExplorerGui resourceExplorerGui, IReadOnlyList <IToolMenuItem> toolMenuItems, IStoryGraphGui storyGraphGui, IReadOnlyList <IAssetLoader> assetLoaders, IViewService viewService, ICommonGuiObjects commonGuiObjects, ISceneNodeContextMenuBuilder sceneNodeContextMenuBuilder) { this.storyGraphGui = storyGraphGui; ClientSize = new Size(1280, 720); Title = "Clarity Worlds"; var assetOpenFileDialog = new OpenFileDialog(); assetOpenFileDialog.Filters.Add(new FileDialogFilter("All Assets", assetLoaders.SelectMany(x => x.FileExtensions).Distinct().ToArray())); foreach (var assetLoader in assetLoaders) { assetOpenFileDialog.Filters.Add(new FileDialogFilter(assetLoader.AssetTypeString, assetLoader.FileExtensions.ToArray())); } var toolCommands = new Command[] { new ToolCommand("Cube", toolService, () => { var entity = objectFactory.Create <SceneNode>(); entity.Name = "NewCube"; entity.Components.Add(PresentationComponent.Create()); var modelComponent = objectFactory.Create <ModelComponent>(); modelComponent.Model = embeddedResources.CubeModel(); modelComponent.Color = GetRandomSaturatedColor(); entity.Components.Add(modelComponent); return(toolFactory.MoveEntity(entity, true)); }), new ToolCommand("Sphere", toolService, () => { var entity = objectFactory.Create <SceneNode>(); entity.Name = "NewSphere"; entity.Components.Add(PresentationComponent.Create()); var modelComponent = objectFactory.Create <ModelComponent>(); modelComponent.Model = embeddedResources.SphereModel(64); modelComponent.Color = GetRandomSaturatedColor(); entity.Components.Add(modelComponent); return(toolFactory.MoveEntity(entity, true)); }), new ToolCommand("Rectangle", toolService, toolFactory.AddRectangle), new ToolCommand("Text", toolService, toolFactory.AddText), new ToolCommand("Asset", toolService, () => { assetOpenFileDialog.ShowDialog(this); var loadPath = assetOpenFileDialog.FileName; if (loadPath == null) { return(null); } var loadInfo = new AssetLoadInfo { FileSystem = ActualFileSystem.Singleton, LoadPath = loadPath, ReferencePath = loadPath, StorageType = AssetStorageType.CopyLocal }; var assetLoadResult = assetService.Load(loadInfo); if (!assetLoadResult.Successful) { MessageBox.Show(assetLoadResult.Message); return(null); } var asset = assetLoadResult.Asset; IResource resource; if (asset.Resource == null) { MessageBox.Show($"The asset contains no resource."); return(null); } if (asset.Resource is ResourcePack pack) { resource = pack.MainSubresource; if (resource == null) { MessageBox.Show($"The asset is a pack with no main subresource."); return(null); } } else { resource = asset.Resource; } switch (resource) { case IImage image: return(toolFactory.AddImage(image)); case IMovie movie: return(toolFactory.AddMovie(movie)); case IFlexibleModel fModel: { var entity = AmFactory.Create <SceneNode>(); entity.Name = "NewModel"; entity.Components.Add(PresentationComponent.Create()); var modelComponent = AmFactory.Create <ModelComponent>(); modelComponent.Model = fModel; modelComponent.Color = GetRandomSaturatedColor(); entity.Components.Add(modelComponent); return(toolFactory.MoveEntity(entity, true)); } case SpherePackingResult spherePackingResult: { var entity = AmFactory.Create <SceneNode>(); entity.Name = "NewModel"; entity.Components.Add(PresentationComponent.Create()); var modelComponent = AmFactory.Create <SpherePackingComponent>(); modelComponent.SpherePackingResult = spherePackingResult; modelComponent.Color = GetRandomSaturatedColor(); entity.Components.Add(modelComponent); return(toolFactory.MoveEntity(entity, true)); } default: MessageBox.Show($"Unable to instantiate an asset of type '{resource.GetType().Name}'."); return(null); } }) }