protected ResizeRectangleGizmoComponent(IInputHandler inputHandler, IEmbeddedResources embeddedResources, IUndoRedoService undoRedo) { visualElement = ModelVisualElement.New() .SetModel(embeddedResources.CubeModel()) .SetMaterial(StandardMaterial.New() .SetNoSpecular(true) .FromGlobalCache()) .SetTransform(Transform.Scaling(0.025f)); interactionElement = new ResizeRectangleInteractionElement <ResizeRectangleGizmoComponent>( this, x => x.GetRectAspect(), x => x.GetChildSpace(), x => x.Place, inputHandler, undoRedo); hittable = new SphereHittable <ResizeRectangleGizmoComponent>(this, x => { var globalTransform = Node.GlobalTransform; return(new Sphere(globalTransform.Offset, 0.025f * globalTransform.Scale)); }); }
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); } }) }