protected StoryFlowchartNodeGizmoComponent(IEmbeddedResources embeddedResources, IViewService viewService)
        {
            this.viewService = viewService;

            GlobalRectangle = new AaRectangle2(Vector2.Zero, 1, 1);

            var squareModel = embeddedResources.SimplePlaneXyModel();

            var material = StandardMaterial.New(this)
                           .SetDiffuseColor(x => x.DiffuseColorToUse())
                           .SetDiffuseMap(x => x.DiffuseMapToUse())
                           .SetIgnoreLighting(true)
                           .SetHighlightEffect(x =>
                                               x.viewService.SelectedNode == ReferencedNode ? HighlightEffect.RainbowBorder :
                                               x.viewService.ClosestStoryNode == ReferencedNode ? HighlightEffect.Pulsating :
                                               HighlightEffect.None);

            visualElement = new ModelVisualElement <StoryFlowchartNodeGizmoComponent>(this)
                            .SetModel(squareModel)
                            .SetMaterial(material)
                            .SetTransform(x => Transform.Translation(new Vector3(x.GlobalRectangle.Center, x.Depth * 0.1f)))
                            .SetNonUniformScale(x => new Vector3(x.GlobalRectangle.HalfWidth, -/*todo: correct text-coords*/ x.GlobalRectangle.HalfHeight, 1));

            hittable = new RectangleHittable <StoryFlowchartNodeGizmoComponent>(this,
                                                                                Transform.Identity,
                                                                                x => new AaRectangle2(Vector2.Zero, x.GlobalRectangle.HalfWidth, x.GlobalRectangle.HalfHeight),
                                                                                x => - x.Depth);
        }
示例#2
0
 protected ModelComponent(IViewService viewService, Lazy <IAppModeService> appModeServiceLazy)
 {
     this.appModeServiceLazy  = appModeServiceLazy;
     SingleColor              = true;
     selectInteractionELement = new SelectOnClickInteractionElement(this, viewService);
     hittable = new SphereHittable <IModelComponent>(this, c => c.Model.BoundingSphere * c.Node.GlobalTransform);
 }
示例#3
0
 public DragAlongAxisGizmoComponent(IEmbeddedResources embeddedResources)
 {
     model         = embeddedResources.LineModel();
     visualElement = new ModelVisualElement <DragAlongAxisGizmoComponent>(this)
                     .SetModel(model)
                     .SetMaterial(x => x.material)
                     .SetTransform(x => x.transform);
     hittable = new LineHittable <DragAlongAxisGizmoComponent>(this, x => x.GetGlobalLine(), PixelLineWidth);
 }
 protected SpherePackingComponent(IEmbeddedResources embeddedResources, IViewService viewService, Lazy <IAppModeService> appModeServiceLazy)
 {
     this.embeddedResources  = embeddedResources;
     this.viewService        = viewService;
     this.appModeServiceLazy = appModeServiceLazy;
     Radius = 0.05f;
     Color  = Color4.Red;
     selectInteractionELement = new SelectOnClickInteractionElement(this, viewService);
     hittable = new SphereHittable <SpherePackingComponent>(this, x => x.LocalBoundingSphere * x.Node.GlobalTransform);
 }
 protected DragRectangleGizmoComponent(IInputHandler inputHandler, IUndoRedoService undoRedo)
 {
     hittable = new RectangleHittable <DragRectangleGizmoComponent>(
         this,
         Transform.Identity,
         x => x.GetRectComponent()?.Rectangle ?? DefaultRect,
         x => - 1f / (1 << 18));
     interactionElement = new DragRectangleInteractionElement <DragRectangleGizmoComponent>(this,
                                                                                            x => x.GetRectComponent(), x => x.GetChildSpace(), inputHandler, undoRedo);
 }
示例#6
0
 public void SetDynamicParts(StoryNodeDynamicParts dynamicParts)
 {
     DefaultViewpointMechanism = dynamicParts.DefaultViewpointMechanism;
     visualElems        = dynamicParts.VisualElements;
     getVisualEffects   = dynamicParts.GetVisualEffects;
     hittable           = dynamicParts.Hittable;
     onUpdate           = dynamicParts.OnUpdate;
     onUpdateClosure    = dynamicParts.OnUpdateClosure;
     PlacementSurface2D = dynamicParts.PlacementSurface2D ?? new DummyPlacementSurface();
     PlacementSurface3D = dynamicParts.PlacementSurface3D ?? new DummyPlacementSurface();
 }
        protected UserQuerySceneComponent(IUserQueryService queryService, IEmbeddedResources embeddedResources, IRtImageBuilder textImageBuilder)
        {
            this.queryService     = queryService;
            this.textImageBuilder = textImageBuilder;
            planeModel            = embeddedResources.SimplePlaneXyModel();

            optionRects    = new List <AaRectangle2>();
            visualElements = new List <IVisualElement>();
            hittable       = new RectangleHittable <UserQuerySceneComponent>(this,
                                                                             Transform.Identity, x => new AaRectangle2(Vector2.Zero, 1f, 1f), x => 0);
        }
        protected RectangleComponent(ICommonNodeFactory commonNodeFactory, Lazy <IAppModeService> appModeServiceLazy, IViewService viewService)
        {
            this.appModeServiceLazy = appModeServiceLazy;
            hittable = new RectangleHittable <RectangleComponent>(this, Transform.Identity,
                                                                  c => c.Rectangle, c => 0);

            editInteractionElems = new IInteractionElement[]
            {
                new SelectOnClickInteractionElement(this, viewService),
                new EditRectangleInteractionElement(this, commonNodeFactory),
            };
        }
        protected FluidSimulationComponent(IEmbeddedResources embeddedResources)
        {
            this.embeddedResources = embeddedResources;
            //var size = new IntSize3(20, 20, 1);
            //var cellSize = 0.40f;
            //var particleRadius = 0.25f;
            fluidSimulation = new FluidSimulation(1f, 1f, 0.25f);

            visualElements   = new List <IVisualElement>();
            interactionElems = new IInteractionElement[]
            {
                //new SelectOnClickInteractionElement(this, viewService),
                new ActionOnEventInteractionElement(
                    args => args is IMouseEvent m && m.IsRightClickEvent() && m.KeyModifiers == KeyModifiers.None,
                    () =>
                {
                    if (simulationRunning)
                    {
                        fluidSimulation.Stop();
                    }
                    else
                    {
                        if (firstTime)
                        {
                            fluidSimulation.Reset(CreateConfig());
                            Reset();
                            firstTime = false;
                        }
                        prevFrame = nextFrame = null;
                        fluidSimulation.Run(simulationTimestamp + 5);
                    }
                    simulationRunning = !simulationRunning;
                }),
                new ActionOnEventInteractionElement(
                    args => args is IMouseEvent m && m.IsRightClickEvent() && m.KeyModifiers == KeyModifiers.Shift,
                    () =>
                {
                    Reset();
                }),
            };

            hittable = new SphereHittable <FluidSimulationComponent>(this, c => c.model.BoundingSphere * c.Node.GlobalTransform);

            Width         = 20;
            Height        = 20;
            CellSize      = 0.8f;
            LevelSetScale = 16;
            SurfaceType   = FluidSurfaceType.Hybrid;
            Reset();
        }
 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));
     });
 }
        protected CirclePackingAutoComponent(IEmbeddedResources embeddedResources, IViewService viewService, ICoroutineService coroutineService)
        {
            this.embeddedResources = embeddedResources;
            this.coroutineService  = coroutineService;

            solver = new CirclePackingSolver();
            Reset();

            borderModel = new ExplicitModel(ResourceVolatility.Stable)
            {
                IndexSubranges = new ExplicitModelIndexSubrange[1],
                Topology       = ExplicitModelPrimitiveTopology.LineStrip
            };
            backgroundVisualElement = ModelVisualElement.New(this)
                                      .SetModel(embeddedResources.SimplePlaneXyModel())
                                      .SetMaterial(StandardMaterial.New()
                                                   .SetIgnoreLighting(true)
                                                   .SetDiffuseColor(Color4.Black)
                                                   .FromGlobalCache())
                                      .SetRenderState(StandardRenderState.New()
                                                      .SetZOffset(-GraphicsHelper.MinZOffset))
                                      .SetTransform(x => Transform.Translation(new Vector3(x.border.BoundingRect.Center, 0)))
                                      .SetNonUniformScale(x => new Vector3(
                                                              x.border.BoundingRect.HalfWidth,
                                                              x.border.BoundingRect.HalfHeight,
                                                              1));
            borderVisualElement = ModelVisualElement.New(this)
                                  .SetModel(x => x.GetRelevantBorderModel())
                                  .SetMaterial(StandardMaterial.New()
                                               .SetDiffuseColor(Color4.Yellow)
                                               .SetIgnoreLighting(true)
                                               .FromGlobalCache());
            circleVisualElements           = new List <IVisualElement>();
            selectOnClickInterationElement = new SelectOnClickInteractionElement(this, viewService);
            // todo: make precise
            hittable = new RectangleHittable <CirclePackingAutoComponent>(this, Transform.Identity,
                                                                          x => x.border.BoundingRect,
                                                                          x => 0);
        }
 public override void AmOnAttached()
 {
     hittable = new SphereHittable <ISceneNode>(Node, x => new Sphere(x.GlobalTransform.Offset, 0.02f));
 }
示例#13
0
        protected MovieRectangleComponent(Lazy <IMoviePlayer> moviePlayerLazy, Lazy <IAppModeService> appModeServiceLazy,
                                          IEmbeddedResources embeddedResources, IViewService viewService)
        {
            this.moviePlayerLazy    = moviePlayerLazy;
            this.appModeServiceLazy = appModeServiceLazy;

            var model        = embeddedResources.SimplePlaneXyModel();
            var mainMaterial = StandardMaterial.New(this)
                               .SetDiffuseColor(x => x.moviePlayback?.FrameImage != null ? Color4.White : Color4.Black)
                               .SetDiffuseMap(x => x.moviePlayback?.FrameImage)
                               .SetIgnoreLighting(true);

            visualElem = new ModelVisualElement <MovieRectangleComponent>(this)
                         .SetModel(model)
                         .SetMaterial(mainMaterial)
                         .SetTransform(x => Transform.Translation(new Vector3(x.Rectangle.Center, 0)))
                         .SetNonUniformScale(x => new Vector3(x.Rectangle.HalfWidth, x.Rectangle.HalfHeight, 1));

            progressBar = new ModelVisualElement <MovieRectangleComponent>(this)
                          .SetModel(model)
                          .SetMaterial(StandardMaterial.New()
                                       .SetDiffuseColor(Color4.Red)
                                       .SetIgnoreLighting(true)
                                       .FromGlobalCache())
                          .SetRenderState(StandardRenderState.New()
                                          .SetZOffset(GraphicsHelper.MinZOffset)
                                          .FromGlobalCache())
                          .SetTransform(x => Transform.Translation(new Vector3(
                                                                       x.Rectangle.MinX + x.Rectangle.HalfWidth * MovieRelativeLocation(),
                                                                       x.Rectangle.MinY + x.Rectangle.HalfHeight / BarHeightFactor, 0)))
                          .SetNonUniformScale(x => new Vector3(
                                                  x.Rectangle.HalfWidth * MovieRelativeLocation(),
                                                  x.Rectangle.HalfHeight / BarHeightFactor, 1))
                          .SetHide(x => !x.showMovieGui);

            var movieButtonTextures = AllButtonTextureNames
                                      .Select(x => embeddedResources.Image(GetMovieButtonTextureFileName(x.ToString())))
                                      .ToArray();

            movieButtonsMaterials = AllButtonTextureNames.Select(x =>
                                                                 StandardMaterial.New()
                                                                 .SetDiffuseMap(movieButtonTextures[(int)x])
                                                                 .SetIgnoreLighting(true))
                                    .Cast <IStandardMaterial>()
                                    .ToArray();

            movieButtonVisualElems = AllMovieButtons.Select(b => new ModelVisualElement <MovieRectangleComponent>(this)
                                                            .SetModel(model)
                                                            .SetMaterial(x => x.movieButtonsMaterials[(int)GetButtonTextureName(b)])
                                                            .SetRenderState(StandardRenderState.New()
                                                                            .SetZOffset(GraphicsHelper.MinZOffset)
                                                                            .FromGlobalCache())
                                                            .SetTransform(x => GetMovieButtonTransform((int)b, x.Rectangle))
                                                            .SetHide(x => !x.showMovieGui));

            movieSpeedTextures = StandardMoviePlayback.MovieSpeeds.Select(x =>
                                                                          embeddedResources.Image(GetMovieSpeedTextureFileName(x))).ToArray();

            movieSpeedVisualElem = new ModelVisualElement <MovieRectangleComponent>(this)
                                   .SetModel(model)
                                   .SetMaterial(StandardMaterial.New(this)
                                                .SetDiffuseMap(x => x.movieSpeedTextures[GetSpeedIndex(moviePlayback.GetVideoSpeed())]))
                                   .SetRenderState(StandardRenderState.New()
                                                   .SetZOffset(GraphicsHelper.MinZOffset))
                                   .SetTransform(x => GetMovieSpeedTransform(x.Rectangle))
                                   .SetHide(x => !x.showMovieGui);

            presentationInteractionElems = new IInteractionElement[]
            {
                new MoviePlaybackInteractionElement <MovieRectangleComponent>(this, x => x.moviePlayback),
                new LambdaInteractionElement(args =>
                {
                    if (!(args is MouseEvent mouseArgs))
                    {
                        return(true);
                    }
                    lastMouseEventTime = lastUpdateTime;

                    if (!mouseArgs.IsLeftClickEvent())
                    {
                        return(true);
                    }
                    if (!TryGetButton(mouseArgs, out var button))
                    {
                        return(true);
                    }
                    switch (button)
                    {
                    case MovieButton.Start:
                        moviePlayback.GoToStart();
                        break;

                    case MovieButton.FBwrd:
                        moviePlayback.PlaySlower();
                        break;

                    case MovieButton.Bwrd:
                        moviePlayback.ReverseDirection();
                        break;

                    case MovieButton.Play:
                        moviePlayback.UpdatePlayStatus();
                        break;

                    case MovieButton.FFrwd:
                        moviePlayback.PlayFaster();
                        break;

                    case MovieButton.End:
                        moviePlayback.GoToEnd();
                        break;

                    default:
                        throw new ArgumentOutOfRangeException();
                    }

                    // Process button click
                    return(true);
                })
            };

            hittable = new RectangleHittable <MovieRectangleComponent>(this, Transform.Identity,
                                                                       c => c.GetHittableRectangle(), c => 0);

            visualElems = new List <IVisualElement> {
                visualElem
            };
        }