Пример #1
0
        /// <summary>
        /// Set up materials and gizmos
        /// </summary>
        public static void InitializeF3Scene(FContext context)
        {
            // initialize materials and selection-materials
            context.Scene.DisableSelectionMaterial = false;

            context.Scene.SelectedMaterial = MaterialUtil.CreateStandardVertexColorMaterialF(Colorf.VideoYellow);

            context.Scene.PerTypeSelectionMaterial.Add(
                BodyModelSOTypes.Scan, MaterialUtil.ToUnityMaterial(OrthogenMaterials.ScanMaterial));
            context.Scene.PerTypeSelectionMaterial.Add(
                BodyModelSOTypes.Leg, MaterialUtil.ToUnityMaterial(OrthogenMaterials.LegMaterial));
            fMaterial selectedCurveMat = MaterialUtil.CreateFlatMaterialF(Colorf.Gold, 1);

            context.Scene.PerTypeSelectionMaterial.Add(BodyModelSOTypes.PlaneIntersectionCurve, selectedCurveMat);
            context.Scene.PerTypeSelectionMaterial.Add(BodyModelSOTypes.TrimLoop, selectedCurveMat);
            context.Scene.PerTypeSelectionMaterial.Add(BodyModelSOTypes.EnclosedPatch, selectedCurveMat);


            // if you had other gizmos, you would register them here
            //context.TransformManager.RegisterGizmoType("snap_drag", new SnapDragGizmoBuilder());
            //controller.TransformManager.SetActiveGizmoType("snap_drag");
            context.TransformManager.RegisterGizmoType(AxisTransformGizmo.DefaultName, new AxisTransformGizmoBuilder());
            context.TransformManager.RegisterGizmoType(LenthenMovePivotGizmoType, new MoveLengthenPivotGizmoBuilder()
            {
                WidgetScale = 0.5f * Vector3f.One
            });

            context.TransformManager.SetActiveGizmoType(TransformManager.NoGizmoType);


            BodyModelSOTypes.RegisterSocketGenTypes(context.Scene.TypeRegistry);
        }
Пример #2
0
        void compute_slice_polylines()
        {
            fMaterial mat1 = MaterialUtil.CreateFlatMaterialF(Colorf.Black);
            fMaterial mat2 = MaterialUtil.CreateFlatMaterialF(Colorf.BlueMetal);

            // [TODO] do we need to hold data_lock here? seems like no since main thread is blocked,
            //  then it would never be the case that we are setting SliceSet = null

            // create geometry
            int slice_i = 0;

            SlicePolylines = new List <fPolylineGameObject>();
            foreach (PlanarSlice slice in SliceSet.Slices)
            {
                //DebugUtil.Log(2, "Slice has {0} solids", slice.Solids.Count);
                Colorf    slice_color = (slice_i % 2 == 0) ? Colorf.Black : Colorf.BlueMetal;
                fMaterial slice_mat   = (slice_i % 2 == 0) ? mat1 : mat2;
                slice_i++;
                foreach (GeneralPolygon2d poly in slice.Solids)
                {
                    List <Vector3f> polyLine = new List <Vector3f>();
                    for (int pi = 0; pi <= poly.Outer.VertexCount; ++pi)
                    {
                        int      i  = pi % poly.Outer.VertexCount;
                        Vector2d v2 = poly.Outer[i];
                        Vector2d n2 = poly.Outer.GetTangent(i).Perp;

                        Vector3d v3 = new Vector3d(v2.x, v2.y, slice.Z);
                        v3 = MeshTransforms.ConvertZUpToYUp(v3);
                        v3 = MeshTransforms.FlipLeftRightCoordSystems(v3);
                        Vector3d n3 = MeshTransforms.ConvertZUpToYUp(new Vector3d(n2.x, n2.y, 0));
                        n3 = MeshTransforms.FlipLeftRightCoordSystems(n3);
                        n3.Normalize();
                        v3 += 0.1f * n3;

                        polyLine.Add((Vector3f)v3);
                    }

                    //DebugUtil.Log(2, "Polyline has {0} vertiecs", polyLine.Count);
                    fPolylineGameObject go = GameObjectFactory.CreatePolylineGO(
                        "slice_outer", polyLine, slice_color, 0.1f, LineWidthType.World);
                    go.SetMaterial(slice_mat, true);
                    CC.ActiveScene.RootGameObject.AddChild(go, false);
                    SlicePolylines.Add(go);
                }
            }
        }
Пример #3
0
        public void Initialize(Cockpit cockpit)
        {
            cockpit.Name = "modelCockpit";


            // Configure how the cockpit moves

            //cockpit.PositionMode = Cockpit.MovementMode.TrackPosition;
            // [RMS] use orientation mode to make cockpit follow view orientation.
            //  (however default widgets below are off-screen!)
            cockpit.PositionMode = Cockpit.MovementMode.TrackOrientation;



            BoxContainer screenContainer           = new BoxContainer(new Cockpit2DContainerProvider(cockpit));
            PinnedBoxes2DLayoutSolver screenLayout = new PinnedBoxes2DLayoutSolver(screenContainer);
            PinnedBoxesLayout         layout       = new PinnedBoxesLayout(cockpit, screenLayout)
            {
                StandardDepth = 2.0f
            };

            cockpit.AddLayout(layout, "2D", true);



            Func <string, float, HUDLabel> MakeButtonF = (label, buttonW) => {
                HUDLabel button = new HUDLabel()
                {
                    Shape           = CotangentUI.MakeMenuButtonRect(buttonW, CotangentUI.MenuButtonHeight),
                    TextHeight      = CotangentUI.MenuButtonTextHeight,
                    AlignmentHorz   = HorizontalAlignment.Center,
                    BackgroundColor = CotangentUI.ButtonBGColor, TextColor = CotangentUI.ButtonTextColor, Text = label,
                    EnableBorder    = true, BorderWidth = CotangentUI.StandardButtonBorderWidth, BorderColor = CotangentUI.ButtonTextColor
                };
                button.Create();
                button.Name    = label;
                button.Enabled = true;
                return(button);
            };



            Vector2f          progressOffsetY = 4 * CotangentUI.PixelScale * Vector2f.AxisY;
            HUDRadialProgress slicerProgress  = new HUDRadialProgress()
            {
                Radius = 18 * CotangentUI.PixelScale
            };

            slicerProgress.Create();
            slicerProgress.Name = "slicer_progress";
            int MAX_PROGRESS = 1000;

            slicerProgress.MaxProgress = MAX_PROGRESS;
            CC.SlicingProgressEvent   += (status) => {
                if (status.bFailed)
                {
                    double t = 0.5 * (double)status.curProgress / (double)status.maxProgress;
                    slicerProgress.Progress       = (int)(t * MAX_PROGRESS);
                    slicerProgress.CompletedColor = Colorf.VideoRed;
                }
                else
                {
                    double t = 0.5 * (double)status.curProgress / (double)status.maxProgress;
                    slicerProgress.Progress       = (int)(t * MAX_PROGRESS);
                    slicerProgress.CompletedColor = Colorf.BlueMetal;
                }
            };
            CC.ToolpathProgressEvent += (status) => {
                if (status.bFailed)
                {
                    double t = 0.5 + 0.5 * (double)status.curProgress / (double)status.maxProgress;
                    slicerProgress.Progress       = (int)(t * MAX_PROGRESS);
                    slicerProgress.CompletedColor = Colorf.VideoRed;
                }
                else
                {
                    double t = 0.5 + 0.5 * (double)status.curProgress / (double)status.maxProgress;
                    if (status.curProgress == 0 && status.maxProgress == 1)
                    {
                        t = 0;
                    }
                    slicerProgress.Progress       = (int)(t * MAX_PROGRESS);
                    slicerProgress.CompletedColor = (status.curProgress == status.maxProgress) ? Colorf.LightGreen : Colorf.BlueMetal;
                }
            };
            layout.Add(slicerProgress, new LayoutOptions()
            {
                Flags            = LayoutFlags.None,
                PinSourcePoint2D = LayoutUtil.BoxPointF(slicerProgress, BoxPosition.CenterBottom),
                PinTargetPoint2D = LayoutUtil.BoxPointF(screenContainer, BoxPosition.CenterBottom, progressOffsetY)
            });



            HUDButton progressClick = new HUDButton()
            {
                Shape = new HUDShape(HUDShapeType.Disc, slicerProgress.Radius)
            };
            fMaterial normalMaterial = MaterialUtil.CreateFlatMaterialF(Colorf.White, 0);
            fMaterial pauseMaterial  = MaterialUtil.CreateTransparentImageMaterialF("icons/progress_pause");
            fMaterial pausedMaterial = MaterialUtil.CreateTransparentImageMaterialF("icons/progress_play");

            if (CCPreferences.ActiveSlicingUpdateMode == CCPreferences.SlicingUpdateModes.ImmediateSlicing)
            {
                progressClick.Create(normalMaterial, null, pauseMaterial);
            }
            else
            {
                progressClick.Create(pausedMaterial, null, null);
            }
            progressClick.Name = "progress_click";
            layout.Add(progressClick, new LayoutOptions()
            {
                Flags            = LayoutFlags.None,
                DepthShift       = -0.1f,
                PinSourcePoint2D = LayoutUtil.BoxPointF(progressClick, BoxPosition.CenterBottom),
                PinTargetPoint2D = LayoutUtil.BoxPointF(screenContainer, BoxPosition.CenterBottom, progressOffsetY)
            });
            progressClick.OnClicked += (o, e) => {
                if (CCPreferences.ActiveSlicingUpdateMode == CCPreferences.SlicingUpdateModes.ImmediateSlicing)
                {
                    CCPreferences.ActiveSlicingUpdateMode = CCPreferences.SlicingUpdateModes.SliceOnDemand;
                    progressClick.StandardMaterial        = pausedMaterial;
                    progressClick.HoverMaterial           = null;
                }
                else
                {
                    CCPreferences.ActiveSlicingUpdateMode = CCPreferences.SlicingUpdateModes.ImmediateSlicing;
                    progressClick.StandardMaterial        = normalMaterial;
                    progressClick.HoverMaterial           = pauseMaterial;
                }
                if (CC.Toolpather.ToolpathsValid == false)
                {
                    // not sure why we have to invalidate slicing here, but if we don't toolpath
                    // computation will not stop when we pause...
                    CC.Slicer.InvalidateSlicing();
                    //CC.InvalidateToolPaths();
                }
            };


            CotangentUI.PrintViewHUDItems = new List <HUDStandardItem>()
            {
                slicerProgress, progressClick
            };

            screenLayout.RecomputeLayout();


            // Configure interaction behaviors
            //   - below we add behaviors for mouse, gamepad, and spatial devices (oculus touch, etc)
            //   - keep in mind that Tool objects will register their own behaviors when active

            // setup key handlers (need to move to behavior...)
            cockpit.AddKeyHandler(new CotangentKeyHandler(cockpit.Context));

            // these behaviors let us interact with UIElements (ie left-click/trigger, or either triggers for Touch)
            cockpit.InputBehaviors.Add(new Mouse2DCockpitUIBehavior(cockpit.Context)
            {
                Priority = 0
            });
            cockpit.InputBehaviors.Add(new VRMouseUIBehavior(cockpit.Context)
            {
                Priority = 1
            });

            // selection / multi-selection behaviors
            // Note: this custom behavior implements some selection redirects that we use in various parts of Archform
            cockpit.InputBehaviors.Add(new MouseMultiSelectBehavior(cockpit.Context)
            {
                Priority = 10
            });

            // left click-drag to tumble, and left click-release to de-select
            cockpit.InputBehaviors.Add(new MouseClickDragSuperBehavior()
            {
                Priority     = 100,
                DragBehavior = new MouseViewRotateBehavior(cockpit.Context)
                {
                    Priority = 100, RotateSpeed = 3.0f
                },
                ClickBehavior = new MouseDeselectBehavior(cockpit.Context)
                {
                    Priority = 999
                }
            });

            // also right-click-drag to tumble
            cockpit.InputBehaviors.Add(new MouseViewRotateBehavior(cockpit.Context)
            {
                Priority  = 100, RotateSpeed = 3.0f,
                ActivateF = MouseBehaviors.RightButtonPressedF, ContinueF = MouseBehaviors.RightButtonDownF
            });

            // middle-click-drag to pan
            cockpit.InputBehaviors.Add(new MouseViewPanBehavior(cockpit.Context)
            {
                Priority  = 100, PanSpeed = 0.01f, Adaptive = true,
                ActivateF = MouseBehaviors.MiddleButtonPressedF, ContinueF = MouseBehaviors.MiddleButtonDownF
            });


            cockpit.OverrideBehaviors.Add(new MouseWheelZoomBehavior(cockpit)
            {
                Priority = 100, ZoomScale = 0.2f, Adaptive = true
            });

            // touch input
            cockpit.InputBehaviors.Add(new TouchUIBehavior(cockpit.Context)
            {
                Priority = 1
            });
            cockpit.InputBehaviors.Add(new Touch2DCockpitUIBehavior(cockpit.Context)
            {
                Priority = 0
            });
            cockpit.InputBehaviors.Add(new TouchViewManipBehavior(cockpit.Context)
            {
                Priority = 999, TouchZoomSpeed = 0.1f, TouchPanSpeed = 0.03f
            });
        }