private void Rebuild() { if (SpherePackingResult == null) { return; } var material = StandardMaterial.New(this) .SetDiffuseColor(x => x.Color); visualElems = SpherePackingResult.Points.Select(p => ModelVisualElement.New(this) .SetModel(embeddedResources.SphereModel(64)) .SetTransform(x => new Transform(x.Radius, Quaternion.Identity, p)) .SetMaterial(material)) .Cast <IVisualElement>() .ToArray(); LocalBoundingSphere = Sphere.BoundingSphere(SpherePackingResult.Points); }
public NestedSpheresStoryLayout(IEmbeddedResources embeddedResources, ICoroutineService coroutineService, Lazy <IViewService> viewServiceLazy) { this.coroutineService = coroutineService; this.viewServiceLazy = viewServiceLazy; focusVisualEffect = new FocusVisualEffect(); mainModel = embeddedResources.SphereModel(64, true); lineModel = embeddedResources.LineModel(); sphereMaterials = new IMaterial[] { StandardMaterial.New().SetDiffuseColor(new Color4(new Color3(1.0f, 0.5f, 0.5f) * 1.0f, 0.5f)).FromGlobalCache(), StandardMaterial.New().SetDiffuseColor(new Color4(new Color3(0.5f, 1.0f, 0.5f) * 1.0f, 0.5f)).FromGlobalCache(), StandardMaterial.New().SetDiffuseColor(new Color4(new Color3(0.5f, 0.5f, 1.0f) * 1.0f, 0.5f)).FromGlobalCache(), StandardMaterial.New().SetDiffuseColor(new Color4(new Color3(1.0f, 1.0f, 0.5f) * 1.0f, 0.5f)).FromGlobalCache(), StandardMaterial.New().SetDiffuseColor(new Color4(new Color3(1.0f, 0.5f, 1.0f) * 1.0f, 0.5f)).FromGlobalCache(), StandardMaterial.New().SetDiffuseColor(new Color4(new Color3(0.5f, 1.0f, 1.0f) * 1.0f, 0.5f)).FromGlobalCache(), }; sphereRenderState = StandardRenderState.New().SetCullFace(CullFace.Back).FromGlobalCache(); lineMaterial = StandardMaterial.New().SetDiffuseColor(Color4.Red).FromGlobalCache(); lineMaterialExternal = StandardMaterial.New().SetDiffuseColor(0.7f * Color4.Red); lineRenderState = StandardRenderState.New().SetLineWidth(3).FromGlobalCache(); }
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); } }) }