static PrintMeshSO emit_new_print_mesh(DMesh3 mesh, DMeshSO fromParent)
        {
            PrintMeshSO newSO = new PrintMeshSO();

            newSO.Create(mesh, CCMaterials.PrintMeshMaterial);
            CCActions.AddNewPrintMesh(newSO);
            if (fromParent != null)
            {
                newSO.SetLocalScale(fromParent.GetLocalScale());
                newSO.SetLocalFrame(fromParent.GetLocalFrame(CoordSpace.SceneCoords), CoordSpace.SceneCoords);
            }
            else
            {
                throw new NotImplementedException("have not implemented this path yet...");
                // estimate frame??
            }

            return(newSO);
        }
        public static PlaneIntersectionCurveSO CreateFromPlane(DMeshSO TargetSO, Frame3f PlaneS, SOMaterial material, FScene scene, double fNormalOffset = 0.0f)
        {
            Frame3f PlaneO = SceneTransforms.SceneToObject(TargetSO, PlaneS);

            PlaneIntersectionCurves curves = new PlaneIntersectionCurves(TargetSO.Mesh, PlaneO, 1)
            {
                NormalOffset = fNormalOffset
            };

            curves.Compute();

            if (curves.Loops.Length != 1)
            {
                throw new Exception("PlaneIntersectionSO.CreateFromPlane: got more than one cut loop?");
            }
            DCurve3 loop = curves.Loops[0];

            // map loop back into plane frame
            for (int i = 0; i < loop.VertexCount; ++i)
            {
                loop[i] = PlaneO.ToFrameP(loop[i]);
            }


            PlaneIntersectionCurveSO curveSO = new PlaneIntersectionCurveSO()
            {
                Curve = loop
            };

            curveSO.Create(material);
            Frame3f curveFrame = SceneTransforms.ObjectToScene(TargetSO, PlaneO);

            curveSO.SetLocalFrame(curveFrame, CoordSpace.ObjectCoords);

            scene.History.PushChange(
                new AddSOChange()
            {
                scene = scene, so = curveSO, bKeepWorldPosition = false
            });
            scene.History.PushInteractionCheckpoint();

            return(curveSO);
        }
Exemple #3
0
        public ITool Build(FScene scene, List <SceneObject> targets)
        {
            targets = new List <SceneObject>(targets.Where((so) => { return(so is DMeshSO); }));
            var source = new List <DMeshSO>()
            {
                targets[0] as DMeshSO
            };
            DMeshSO       target = targets[1] as DMeshSO;
            ReprojectTool tool   = new ReprojectTool(scene, source, target)
            {
                OnApplyF        = this.OnApplyF,
                PreviewMaterial = this.PreviewMaterial
            };

            if (BuildCustomizeF != null)
            {
                BuildCustomizeF(tool);
            }
            return(tool);
        }
 static void standard_multi_so_tool_handler(Dictionary <DMeshSO, DMeshSO> result, bool replace_input)
 {
     if (replace_input)
     {
         foreach (var pair in result)
         {
             DMeshSO target  = pair.Key;
             DMeshSO preview = pair.Value;
             replace_single(target, preview);
             CC.ActiveScene.RemoveSceneObject(preview, true);
         }
     }
     else
     {
         foreach (var pair in result)
         {
             convert_to_print_mesh(pair.Value);
         }
     }
 }
        override public void Apply()
        {
            float VerticalSpaceFudge = 10.0f;

            DMeshSO TargetMeshSO = TargetSO as DMeshSO;

            Frame3f           curFrameS = TargetSO.GetLocalFrame(CoordSpace.SceneCoords);
            TransformSOChange change    = new TransformSOChange(TargetSO,
                                                                curFrameS, lastPreviewFrameS, CoordSpace.SceneCoords);

            Scene.History.PushChange(change, false);

            Frame3f newFrameS = new Frame3f(SceneTransforms.ObjectToSceneP(TargetSO, meshBounds.Center));
            RepositionPivotChangeOp pivot1 = new RepositionPivotChangeOp(newFrameS, TargetMeshSO);

            Scene.History.PushChange(pivot1, false);

            newFrameS = TargetSO.GetLocalFrame(CoordSpace.SceneCoords);
            AxisAlignedBox3d bounds         = TargetMeshSO.Mesh.CachedBounds;
            float            h              = (float)bounds.Height;
            Vector3f         o              = newFrameS.Origin;
            Vector3f         translate      = new Vector3f(-o.x, h * 0.5f - o.y + VerticalSpaceFudge, -o.z);
            Frame3f          centeredFrameS = newFrameS.Translated(translate);

            TransformSOChange centerChange = new TransformSOChange(TargetSO,
                                                                   newFrameS, centeredFrameS, CoordSpace.SceneCoords);

            Scene.History.PushChange(centerChange, false);

            newFrameS        = TargetSO.GetLocalFrame(CoordSpace.SceneCoords);
            o                = newFrameS.Origin;
            o.y              = 0;
            newFrameS.Origin = o;

            RepositionPivotChangeOp pivot2 = new RepositionPivotChangeOp(newFrameS, TargetMeshSO);

            Scene.History.PushChange(pivot2, false);


            Scene.History.PushInteractionCheckpoint();
        }
        /// <summary>
        /// initialize points w/ known base point and up direction
        /// </summary>
        public void Initialize_KnownBasePoint(Vector3d basePointL, Vector3f upAxis)
        {
            DMeshSO TargetMeshSO = TargetSO as DMeshSO;

            // initialize w/ auto-fit box
            DMesh3         mesh    = TargetMeshSO.Mesh;
            DMeshAABBTree3 spatial = TargetMeshSO.Spatial;

            meshBounds = mesh.CachedBounds;

            create_preview_so();

            /*Frame3f frameO = TargetSO.GetLocalFrame(CoordSpace.ObjectCoords);*/

            // reproject base point onto surface in case somehow it is wrong
            Vector3f basePointUpdatedL = MeshQueries.NearestPointFrame(mesh, spatial, basePointL).Origin;
            Vector3f BasePointS        = SceneTransforms.ObjectToSceneP(TargetSO, basePointUpdatedL);

            Vector3f upAxisL   = Vector3f.AxisY;
            Vector3f topPointL = basePointUpdatedL + upAxisL * (float)meshBounds.Height;

            topPointL = MeshQueries.NearestPointFrame(mesh, spatial, topPointL).Origin;

            Vector3f TopPointS = SceneTransforms.ObjectToSceneP(TargetSO, topPointL);

            // shoot ray forward in scene, to find front point
            Vector3f forwardL = SceneTransforms.SceneToObjectN(TargetSO, -Vector3f.AxisZ);
            Frame3f  fwHitFrameL;
            bool     bHit = MeshQueries.RayHitPointFrame(mesh, spatial, new Ray3d(meshBounds.Center, forwardL), out fwHitFrameL);

            if (!bHit)
            {
                throw new Exception("SocketAlignmentTool.Initialize_KnownBasePoint: ray missed!");
            }

            Vector3f FrontPointS = SceneTransforms.ObjectToSceneP(TargetSO, fwHitFrameL.Origin);

            SetPointPosition(BasePointID, new Frame3f(BasePointS), CoordSpace.SceneCoords);
            SetPointPosition(FrontPointID, new Frame3f(FrontPointS), CoordSpace.SceneCoords);
            SetPointPosition(TopPointID, new Frame3f(TopPointS), CoordSpace.SceneCoords);
        }
Exemple #7
0
        override public void Apply()
        {
            if (OnApplyF != null)
            {
                set_allow_selection_changes(true);

                // pop the history stream we pushed
                pop_history_stream();

                // restore input selection
                Scene.ClearSelection();
                foreach (var so in inputSelection)
                {
                    Scene.Select(so, false);
                }

                //if (InputSOs.Count != 1 || ForceSceneSpaceComputation) {
                //    Frame3f sceneF = estimate_frame();
                //    PreviewSO.RepositionPivot(sceneF);
                //}

                // apply
                if (HoleType == HoleTypes.CavityObject)
                {
                    bake_hole_mesh();
                }
                OnApplyF(this);

                set_allow_selection_changes(false);

                // assume object is consumed...this is not ideal...
                if (HoleType == HoleTypes.CavityObject)
                {
                    CavityPreviewSO = null;
                }
                else
                {
                    CutPreviewSO = null;
                }
            }
        }
Exemple #8
0
        public static void MoveToPrintBed(FScene scene, DMeshSO so, bool bInteractive)
        {
            TransformSequence seq    = SceneTransforms.ObjectToSceneXForm(so);
            AxisAlignedBox3d  bounds = BoundsUtil.Bounds(so.Mesh.Vertices(), seq);

            Frame3f curFrameS = so.GetLocalFrame(CoordSpace.SceneCoords);
            float   dy        = (float)(bounds.Center.y - bounds.Extents.y);

            if (Math.Abs(dy) > MathUtil.ZeroTolerancef)
            {
                Frame3f newFrameS = curFrameS;
                newFrameS.Origin = curFrameS.Origin - dy * Vector3f.AxisY;
                TransformSOChange change = new TransformSOChange(so, curFrameS, newFrameS, CoordSpace.SceneCoords);
                change.Tags.Add("MoveToPrintBed");
                scene.History.PushChange(change, false);
                if (bInteractive)
                {
                    scene.History.PushInteractionCheckpoint();
                }
            }
        }
 public static void OnApply_AddHoleTool(AddHoleTool tool)
 {
     if (tool.HoleType == AddHoleTool.HoleTypes.CavityObject)
     {
         PrintMeshSO printSO = convert_to_print_mesh(tool.GetOutputSO());
         printSO.Name = UniqueNames.GetNext("Hole");
         printSO.Settings.ObjectType = PrintMeshSettings.ObjectTypes.Cavity;
         printSO.AssignSOMaterial(CCMaterials.CavityMeshMaterial);
     }
     else
     {
         bool    replace_input = tool.Parameters.GetValueBool("replace_input");
         DMeshSO previewSO     = tool.GetOutputSO();
         previewSO.EnableSpatial = true;   // required because preview has no spatial DS
         standard_mesh_tool_handler(new List <DMeshSO>()
         {
             tool.TargetSO as DMeshSO
         }, previewSO, replace_input);
     }
     CC.ActiveScene.History.PushInteractionCheckpoint();
 }
Exemple #10
0
        public static void TestMarchingCubes()
        {
            MarchingCubes mc = new MarchingCubes();

            LocalProfiler p = new LocalProfiler();

            p.Start("GENERATE");
            mc.ParallelCompute = true;
            mc.Generate();
            p.Stop("GENERATE");
            DebugUtil.Log(2, p.AllTimes());

            MeshNormals.QuickCompute(mc.Mesh);

            DebugUtil.WriteDebugMesh(mc.Mesh, "c:\\scratch\\MARCHING_CUBES.obj");

            DMeshSO meshSO = new DMeshSO();

            meshSO.Create(mc.Mesh, CC.ActiveScene.DefaultMeshSOMaterial);
            CC.ActiveScene.AddSceneObject(meshSO, false);
        }
        public DMeshSO BuildSO(FScene scene, SOMaterial material)
        {
            DMesh3 revolveMesh = UnityUtil.UnityMeshToDMesh(meshObject.GetSharedMesh(), false);

            // move axis frame to center of bbox of mesh, measured in axis frame
            Frame3f          useF          = OutputFrame;
            AxisAlignedBox3f boundsInFrame = (AxisAlignedBox3f)BoundsUtil.BoundsInFrame(revolveMesh.Vertices(), useF);

            useF.Origin = useF.FromFrameP(boundsInFrame.Center);

            // transform mesh into this frame
            MeshTransforms.ToFrame(revolveMesh, useF);

            // create new so
            DMeshSO meshSO = new DMeshSO();

            meshSO.Create(revolveMesh, material);
            meshSO.SetLocalFrame(useF, CoordSpace.ObjectCoords);

            return(meshSO);
        }
Exemple #12
0
        public FillHolesTool(FScene scene, DMeshSO target)
        {
            this.Scene  = scene;
            this.target = target;

            behaviors = new InputBehaviorSet();

            // TODO is this where we should be doing this??
            behaviors.Add(
                new HoleFillTool_2DInputBehavior(this, scene.Context)
            {
                Priority = 5
            });

            // shut off transform gizmo
            scene.Context.TransformManager.PushOverrideGizmoType(TransformManager.NoGizmoType);

            // set up parameters
            initialize_parameters();

            SceneUtil.SetVisible(Target, false);
        }
Exemple #13
0
        void update_preview(List <DMesh3> meshes)
        {
            if (PreviewSOs != null)
            {
                foreach (var so in PreviewSOs)
                {
                    Scene.RemoveSceneObject(so, true);
                }
                PreviewSOs.Clear();
            }

            foreach (var mesh in meshes)
            {
                var so = new DMeshSO()
                {
                    EnableSpatial = EnablePreviewSpatial
                };
                so.Create(mesh, KeepPreviewMaterial);
                Scene.AddSceneObject(so);
                PreviewSOs.Add(so);
            }
        }
        public void InitializeOnTarget(DMeshSO target, double initial_width)
        {
            AxisAlignedBox3d bounds = target.Mesh.CachedBounds;
            Vector3d         c      = bounds.Center;
            SORayHit         nearestPt;

            target.FindNearest(c, double.MaxValue, out nearestPt, CoordSpace.ObjectCoords);
            c = nearestPt.hitPos;

            Vector3d up = c + initial_width * Vector3d.AxisY;

            target.FindNearest(up, double.MaxValue, out nearestPt, CoordSpace.ObjectCoords);
            up = nearestPt.hitPos;

            Vector3d down = c - initial_width * Vector3d.AxisY;

            target.FindNearest(down, double.MaxValue, out nearestPt, CoordSpace.ObjectCoords);
            down = nearestPt.hitPos;

            SetPointPosition_Internal(StartPointID, new Frame3f(up), CoordSpace.ObjectCoords);
            SetPointPosition_Internal(EndPointID, new Frame3f(down), CoordSpace.ObjectCoords);
        }
Exemple #15
0
        virtual public void Shutdown()
        {
            begin_shutdown();

            // terminate any computes
            if (ComputeOp.IsComputing)
            {
                EditOp.ForceInvalidate();
            }

            pop_history_stream();

            if (PreviewSO != null)
            {
                Scene.RemoveSceneObject(PreviewSO, true);
                PreviewSO = null;
            }

            Scene.Context.TransformManager.PopOverrideGizmoType();

            set_targets_visibility(true);
        }
        public virtual void Shutdown()
        {
            if (PreviewSO != null)
            {
                Scene.RemoveSceneObject(PreviewSO, true);
                PreviewSO = null;
            }
            if (bendPlaneGizmoSO != null)
            {
                allow_selection_changes = true;
                Scene.RemoveSceneObject(bendPlaneGizmoSO, true);
                allow_selection_changes = false;
                bendPlaneGizmoSO        = null;
            }

            Indicators.Disconnect(true);


            TargetSO.PopOverrideMaterial();
            TargetSO.SetLayer(FPlatform.GeometryLayer);

            Scene.Context.TransformManager.PopOverrideGizmoType();
        }
        public void RemoveMesh(DMeshSO sourceSO)
        {
            List <AnalysisViz> found;

            lock (SOToAnalysis) {
                if (SOToAnalysis.TryGetValue(sourceSO, out found))
                {
                    foreach (var analysis in found)
                    {
                        disconnect_analysis(analysis);
                    }
                    SOToAnalysis.Remove(sourceSO);
                }
            }
            lock (DirtyList) {
                if (found != null)
                {
                    foreach (var analysis in found)
                    {
                        DirtyList.Remove(analysis);
                    }
                }
            }
        }
        public void AddMesh(DMeshSO sourceSO)
        {
            // make sure we have this SO
            lock (SOToAnalysis) {
                List <AnalysisViz> l;
                if (SOToAnalysis.TryGetValue(sourceSO, out l) == false)
                {
                    l = new List <AnalysisViz>();
                    SOToAnalysis[sourceSO] = l;
                }
            }

            if (EnableMeshBoundaries)
            {
                AnalysisViz boundaries = new MeshSOBoundaryViz(sourceSO);
                add_new_so_analysis(sourceSO, boundaries);
            }

            if (EnableCavities)
            {
                AnalysisViz interiorCavities = new MeshSOComponentsViz(sourceSO);
                add_new_so_analysis(sourceSO, interiorCavities);
            }
        }
Exemple #19
0
        virtual public void Apply()
        {
            if (OnApplyF != null)
            {
                set_allow_selection_changes(true);

                // pop the history stream we pushed
                pop_history_stream();

                // restore input selection
                Scene.ClearSelection();
                foreach (var so in inputSelection)
                {
                    Scene.Select(so, false);
                }

                // apply
                OnApplyF(this, PreviewSO);

                set_allow_selection_changes(false);

                PreviewSO = null;
            }
        }
Exemple #20
0
        virtual public void Shutdown()
        {
            begin_shutdown();

            // in case we are computing in background (todo: fix)
            cancel_background_task = true;
            is_computing           = false;

            // if we did not Apply(), this history stream is still here...
            pop_history_stream();

            // restore transform gizmo
            Scene.Context.TransformManager.PopOverrideGizmoType();

            boundaryGeom.Clear();

            if (previewSO != null)
            {
                Scene.RemoveSceneObject(previewSO, true);
                previewSO = null;
            }

            SceneUtil.SetVisible(Target, true);
        }
 public MeshSOBoundaryViz(DMeshSO so)
 {
     SO = so;
     SO.OnMeshModified += OnInputMeshModified;
 }
 private void OnInputMeshModified(DMeshSO so)
 {
     OnComputeUpdateRequired?.Invoke(this);
 }
    // Use this for initialization
    public override void Awake()
    {
        base.Awake();

        // if we need to auto-configure Rift vs Vive vs (?) VR, we need
        // to do this before any other F3 setup, because MainCamera will change
        // and we are caching that in a lot of places...
        if (AutoConfigVR)
        {
            VRCameraRig = gs.VRPlatform.AutoConfigureVR();
        }

        // add splash screen
        CCActions.ShowSplashScreen();

        // restore any settings
        SceneGraphConfig.RestorePreferences();
        CCPreferences.RestorePreferences();
        if (CCPreferences.CameraMode == CCPreferences.CameraModes.Orthographic)
        {
            Camera.main.orthographic = true;
        }

        // set up some defaults
        // this will move the ground plane down, but the bunnies will be floating...
        //SceneGraphConfig.InitialSceneTranslate = -4.0f * Vector3f.AxisY;
        SceneGraphConfig.InitialSceneTranslate          = Vector3f.Zero;
        SceneGraphConfig.DefaultSceneCurveVisualDegrees = 0.5f;
        SceneGraphConfig.DefaultPivotVisualDegrees      = 0.5f;
        SceneGraphConfig.DefaultAxisGizmoVisualDegrees  = 7.5f;
        SceneGraphConfig.CameraPivotVisualDegrees       = 0.3f;

        if (FPlatform.InUnityEditor())
        {
            Util.DebugBreakOnDevAssert = false;     // throw exception on gDevAssert
        }
        SceneOptions options = new SceneOptions();

        options.UseSystemMouseCursor  = true;
        options.Use2DCockpit          = true;
        options.ConstantSize2DCockpit = true;
        options.EnableTransforms      = true;
        options.EnableCockpit         = true;
        options.CockpitInitializer    = new SetupPrintCockpit();

        options.EnableDefaultLighting = true;

        options.MouseCameraControls = new MayaExtCameraHotkeys()
        {
            MouseOrbitSpeed = 5.0f, MousePanSpeed = 0.01f, MouseZoomSpeed = 0.1f, UseAdaptive = true
        };
        options.SpatialCameraRig = VRCameraRig;

        options.DefaultGizmoBuilder = new AxisTransformGizmoBuilder()
        {
            ScaleSpeed = 0.03f, TranslateSpeed = 1.0f
        };

        // very verbose
        options.LogLevel = 4;

        CCMaterials.InitializeMaterials();

        context = new FContext();
        CotangentUI.Initialize(context);   // have to do this before cockpit is configured, which currently
                                           // happens automatically on .Start() (which is dumb...)
        context.Start(options);

        CCMaterials.SetupSceneMaterials(context);

        // 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(CotangentTypes.SlicePlaneHeightGizmoType, new SlicePlaneHeightGizmoBuilder() {
        //    Factory = new SlicePlaneHeightGizmoBuilder.WidgetFactory(), GizmoVisualDegrees = 4.0f, GizmoLayer = FPlatform.GeometryLayer
        //});
        //context.TransformManager.AddTypeFilter(SlicePlaneHeightGizmoBuilder.MakeTypeFilter());

        // if you had other tools, you would register them here.
        context.ToolManager.RegisterToolType(DrawPrimitivesTool.Identifier, new DrawPrimitivesToolBuilder());
        context.ToolManager.RegisterToolType(SetZLayerTool.Identifier, new SetZLayerToolBuilder());
        CCActions.InitializeCotangentScene(context);
        CCActions.InitializePrintTools(context);
        CCActions.InitializeRepairTools(context);
        CCActions.InitializeModelTools(context);
        context.ToolManager.SetActiveToolType(DrawPrimitivesTool.Identifier, ToolSide.Right);

        // Set up standard scene lighting if requested
        if (options.EnableDefaultLighting)
        {
            GameObject lighting = GameObject.Find("SceneLighting");
            if (lighting == null)
            {
                lighting = new GameObject("SceneLighting");
            }
            SceneLightingSetup setup = lighting.AddComponent <SceneLightingSetup>();
            setup.Context          = context;
            setup.LightDistance    = 200; // related to total scene scale...
            setup.LightCount       = 4;
            setup.ShadowLightCount = 1;
        }


        //GameObjectFactory.CurveRendererSource = new VectrosityCurveRendererFactory();


        // set up selection material
        context.Scene.SelectedMaterial = CCMaterials.SelectedMaterial;


        /*
         * Import elements of Unity scene that already exist into the FScene
         */

        // set up ground plane geometry (optional)
        GameObject boundsObject = GameObject.Find("PrintBed");

        if (boundsObject != null)
        {
            context.Scene.AddWorldBoundsObject(boundsObject);
            CC.PrinterBed = boundsObject;
        }

        CC.Initialize(context);


        if (StartupPart != null)
        {
            StartupPart.name = "Cylinder";
            DMeshSO startupSO = (DMeshSO)UnitySceneUtil.ImportExistingUnityGO(StartupPart, context.Scene, true, true, false,
                                                                              (mesh, material) => {
                PrintMeshSO so = new PrintMeshSO();
                return(so.Create(mesh, CCMaterials.PrintMeshMaterial));
            }
                                                                              );
            GameObject.Destroy(StartupPart);

            CC.Objects.AddPrintMesh(startupSO as PrintMeshSO);
            CCActions.StartupObjectUUID = CC.Objects.PrintMeshes[0].UUID;
        }


        //if (StartupPrintHead != null) {
        //    SceneObject wrapSO = UnitySceneUtil.WrapAnyGameObject(StartupPrintHead, context, false);
        //    CC.PrintHeadSO = wrapSO;
        //    SceneUtil.SetVisible(wrapSO, false);
        //}

        Context.ActiveCamera.Manipulator().SceneOrbit(Context.Scene, context.ActiveCamera, -25, -25);

        CCActions.SwitchToViewMode(CCPreferences.StartupWorkspace, true);

        // enable drag-drop on windows when not in editor
        StartAnonymousCoroutine(enable_drag_drop());

        // import command-line args
        CCActions.DoArgumentsImport(Environment.GetCommandLineArgs());

        // start auto-update check
        if (FPlatform.InUnityEditor() == false)
        {
            StartAnonymousCoroutine(auto_update_check());
        }

        // set window title
        FPlatform.SetWindowTitle(string.Format("cotangent {0}", CotangentVersion.CurrentVersionString));

        // show privacy dialog soon
        Context.RegisterNthFrameAction(100, CCActions.ShowPrivacyDialogIfRequired);
    }
Exemple #24
0
        public static void OnApply_GenerateGraphSupportsTool(GenerateGraphSupportsTool tool, DMeshSO previewSO)
        {
            if (previewSO.Mesh.TriangleCount == 0)
            {
                return;
            }

            if (tool.Targets.Count() == CC.Objects.PrintMeshes.Count)
            {
                CC.Settings.GenerateSupport = false;
            }

            PrintMeshSO printSO = convert_to_print_mesh(previewSO);

            printSO.Name = UniqueNames.GetNext("Tree Support");
            printSO.Settings.ObjectType = PrintMeshSettings.ObjectTypes.Support;
            printSO.AssignSOMaterial(CCMaterials.SupportMeshMaterial);
            CC.ActiveScene.History.PushInteractionCheckpoint();
        }
Exemple #25
0
 protected virtual FillHolesTool new_tool(FScene scene, DMeshSO target)
 {
     return(new FillHolesTool(scene, target));
 }
Exemple #26
0
 private void PreviewSO_OnMeshModified(DMeshSO so)
 {
     visibility_valid = false;
 }
Exemple #27
0
        public virtual void Setup()
        {
            // push history stream, so that we can do undo/redo internal to tool,
            // that will not end up in external history
            push_history_stream();

            if (OnApplyF == null)
            {
                OnApplyF = this.add_so_to_scene;
            }

            if (PreviewMaterial == null)
            {
                PreviewMaterial = SOMaterial.CreateMesh("tool_generated", Colorf.DimGrey);
            }
            if (ErrorMaterial == null)
            {
                ErrorMaterial = SOMaterial.CreateMesh("tool_generated_error", Colorf.VideoRed);
            }

            // clear selection here so that multi-select GroupSO goes away, otherwise
            // when we copy frmaes below, they are relative to that GroupSO, and things move
            inputSelection = new List <SceneObject>(Scene.Selected);
            set_allow_selection_changes(true);
            Scene.ClearSelection();
            set_allow_selection_changes(false);

            if (InputSOs.Count == 1 && ForceSceneSpaceComputation == false)
            {
                combineMesh         = new DMesh3(InputSOs[0].Mesh);
                sceneToObjUnitScale = SceneTransforms.SceneToObject(InputSOs[0], 1.0f);
            }
            else
            {
                combineMesh = new DMesh3();
                MeshEditor editor = new MeshEditor(combineMesh);
                foreach (var so in InputSOs)
                {
                    TransformSequence xform     = SceneTransforms.ObjectToSceneXForm(so);
                    DMesh3            inputMesh = so.Mesh;
                    int[]             mapV;
                    if (editor.AppendMesh(so.Mesh, out mapV))
                    {
                        MeshTransforms.PerVertexTransform(combineMesh, inputMesh, mapV, (v, old_id, new_id) => {
                            return(xform.TransformP(v));
                        });
                    }
                }
                ;
                sceneToObjUnitScale = 1.0;
            }


            MeshSourceOp = new ConstantMeshSourceOp(combineMesh, true, true);
            EditOp       = edit_op_factory(MeshSourceOp);
            ComputeOp    = new ThreadedMeshComputeOp()
            {
                MeshSource = EditOp
            };

            PreviewSO = new DMeshSO()
            {
                EnableSpatial = EnablePreviewSpatial
            };
            PreviewSO.Create(new DMesh3(), PreviewMaterial);
            if (InputSOs.Count == 1 && ForceSceneSpaceComputation == false)
            {
                PreviewSO.SetLocalFrame(InputSOs[0].GetLocalFrame(CoordSpace.ObjectCoords), CoordSpace.ObjectCoords);
                PreviewSO.SetLocalScale(InputSOs[0].GetLocalScale());
            }
            Scene.AddSceneObject(PreviewSO);

            postprocess_target_objects();
            base_initialize_parameters();
        }
Exemple #28
0
 void add_so_to_scene(T tool, DMeshSO result)
 {
     // already added
 }
    // Use this for initialization
    public override void Awake()
    {
        // if we need to auto-configure Rift vs Vive vs (?) VR, we need
        // to do this before any other F3 setup, because MainCamera will change
        // and we are caching that in a lot of places...
        if (AutoConfigVR)
        {
            VRCameraRig = gs.VRPlatform.AutoConfigureVR();
        }

        // restore any settings
        SceneGraphConfig.RestorePreferences();

        // set up some defaults
        // this will move the ground plane down, but the bunnies will be floating...
        //SceneGraphConfig.InitialSceneTranslate = -4.0f * Vector3f.AxisY;
        SceneGraphConfig.DefaultSceneCurveVisualDegrees = 0.5f;
        SceneGraphConfig.DefaultPivotVisualDegrees      = 1.5f;
        SceneGraphConfig.DefaultAxisGizmoVisualDegrees  = 10.0f;
        SceneGraphConfig.InitialSceneTranslate          = -4 * Vector3f.AxisY;


        SceneOptions options = new SceneOptions();

        options.UseSystemMouseCursor = false;
        options.Use2DCockpit         = false;
        options.EnableTransforms     = true;
        options.EnableCockpit        = true;
        options.CockpitInitializer   = new PhotoToolCockpit();

        options.MouseCameraControls = new MayaCameraHotkeys();
        options.SpatialCameraRig    = VRCameraRig;

        // very verbose
        options.LogLevel = 2;

        context = new FContext();
        context.Start(options);

        // if you had other gizmos, you would register them here
        //context.TransformManager.RegisterGizmoType("snap_drag", new SnapDragGizmoBuilder());
        //controller.TransformManager.SetActiveGizmoType("snap_drag");

        // if you had other tools, you would register them here.
        context.ToolManager.RegisterToolType(DrawPrimitivesTool.Identifier, new DrawPrimitivesToolBuilder());
        context.ToolManager.RegisterToolType(DrawSurfaceCurveTool.Identifier, new DrawSurfaceCurveToolBuilder()
        {
            AttachCurveToSurface = true,
            DefaultSamplingRateS = 0.0025f, DefaultSurfaceOffsetS = 0.0025f,
            CurveMaterialF       = () => { var mat = context.Scene.DefaultCurveSOMaterial.Clone(); mat.RGBColor = Colorf.VideoRed; return(mat); }
        });
        context.ToolManager.SetActiveToolType(DrawSurfaceCurveTool.Identifier, ToolSide.Right);

        // Set up standard scene lighting if requested
        if (options.EnableDefaultLighting)
        {
            GameObject lighting = GameObject.Find("SceneLighting");
            if (lighting == null)
            {
                lighting = new GameObject("SceneLighting");
            }
            SceneLightingSetup setup = lighting.AddComponent <SceneLightingSetup>();
            setup.Context       = context;
            setup.LightDistance = 30.0f; // related to total scene scale...
        }


        Context.Scene.DisableSelectionMaterial = true;


        /*
         * Import elements of Unity scene that already exist into the FScene
         */

        // set up ground plane geometry (optional)
        GameObject groundPlane = GameObject.Find("GroundPlane");

        if (groundPlane != null && groundPlane.IsVisible())
        {
            context.Scene.AddWorldBoundsObject(groundPlane);
        }


        float    fSquareSize = 1.0f;
        Vector3f eyePos      = context.ActiveCamera.GetPosition();

        System.Random rand = new System.Random(31337);

        // [RMS] this path only works in Editor, is relative to top-level project directory
        string sPhotoFolder = "Data\\PhotoSets\\kitchen";

        string[] photos = Directory.GetFiles(sPhotoFolder);
        foreach (string filename in photos)
        {
            Texture2D tex = load_texture(filename);
            if (tex == null)
            {
                continue;
            }

            float fScale = fSquareSize / (float)tex.width;
            if (tex.height > tex.width)
            {
                fScale = fSquareSize / (float)tex.height;
            }

            float w = fScale * (float)tex.width;
            float h = fScale * (float)tex.height;

            TrivialRectGenerator rectgen = new TrivialRectGenerator()
            {
                Width = w, Height = h
            };
            rectgen.Generate();
            DMesh3 mesh = new DMesh3(MeshComponents.VertexUVs);
            rectgen.MakeMesh(mesh);

            SOMaterial material = new SOMaterial()
            {
                Name     = "photomaterial",
                Type     = SOMaterial.MaterialType.TextureMap,
                RGBColor = Colorf.White
            };
            material.MainTexture = tex;

            DMeshSO so = new DMeshSO();
            so.Create(mesh, material);
            context.Scene.AddSceneObject(so);

            float horz = rand.Next(-50, 50);
            float vert = rand.Next(-20, 25);
            int   mult = 1000;
            float dist = (float)(rand.Next(2 * mult, 3 * mult)) / (float)mult;

            Ray3f r = VRUtil.MakeRayFromSphereCenter(horz, vert);
            r.Origin += eyePos;
            float fRayT = 0.0f;
            RayIntersection.Sphere(r.Origin, r.Direction, eyePos, dist, out fRayT);
            Vector3f v = r.Origin + fRayT * r.Direction;
            Frame3f  f = new Frame3f(v, v.Normalized);

            Vector3f toEye = context.ActiveCamera.GetPosition() - f.Origin;
            toEye.Normalize();
            f.AlignAxis(1, toEye);
            f.ConstrainedAlignAxis(2, Vector3f.AxisY, f.Y);

            so.SetLocalFrame(f, CoordSpace.WorldCoords);
        }
    }
 private void on_leg_scan_modified(DMeshSO so)
 {
     // have to do copy in main thread
     SOMeshSource.SetMesh(so.Mesh, true, false);
 }