Ejemplo n.º 1
0
 public void CancelDraw()
 {
     if (preview != null)
     {
         preview.Destroy();
         preview = null;
     }
 }
Ejemplo n.º 2
0
        void CreateNewCurve()
        {
            preview = new CurvePreview();
            preview.Create(scene.NewSOMaterial, scene.RootGameObject);

            smoother = new InPlaceIterativeCurveSmooth()
            {
                Curve = preview.Curve,
                Alpha = 0.2f
            };
        }
Ejemplo n.º 3
0
        /// <summary>
        /// this is set as result action in draw-surface-loop tool, converts curve preview into a TrimLoopSO
        /// </summary>
        public static void EmitTrimCurveFromPreview(CurvePreview preview)
        {
            TrimLoopSO curveSO = TrimLoopSO.CreateFromPreview(preview, OrthogenMaterials.TrimLoopMaterial, OG.Scene);

            AddNewTrimCurve(curveSO);

            // next frame, transition, and select the curve
            OG.Context.RegisterNextFrameAction(() => {
                OG.Transition(OGWorkflow.DrawTrimlineExitT);
                OG.Scene.Select(curveSO, true);
            });
        }
Ejemplo n.º 4
0
        public void EndDraw()
        {
            if (preview.Curve.ArcLength > 2 * Width)
            {
                // store undo/redo record for new primitive
                PolyCurveSO CurveSO = preview.BuildSO(scene.DefaultCurveSOMaterial, 1.0f);
                scene.History.PushChange(
                    new AddSOChange()
                {
                    scene = scene, so = CurveSO, bKeepWorldPosition = false
                });
                scene.History.PushInteractionCheckpoint();
            }

            preview.Destroy();
            preview = null;

            SavedSettings.Save("DrawCurveTool_width", width);
        }
Ejemplo n.º 5
0
        public static TrimLoopSO CreateFromPreview(CurvePreview preview, SOMaterial material, FScene scene)
        {
            TrimLoopSO curveSO = (TrimLoopSO)preview.BuildSO(
                (curve) => {
                TrimLoopSO so = new TrimLoopSO()
                {
                    Curve = curve
                };
                so.Create(material);
                return(so);
            }, material, 1.0f);

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

            return(curveSO);
        }
Ejemplo n.º 6
0
        /// <summary>
        /// this is set as DrawSurfaceCurveTool.EmitNewCurveF, which is called automatically when user
        /// releases mouse, so we need to exit the tool here.
        /// </summary>
        public static void EmitRegionDeformationFromCurvePreview(CurvePreview preview)
        {
            if (preview.Closed == false)
            {
                preview.Closed = true;
                DrawSurfaceCurveTool tool = OG.Context.ToolManager.ActiveRightTool as DrawSurfaceCurveTool;
                if (tool != null)
                {
                    tool.Closed = true;
                }
            }
            EnclosedPatchSO curveSO = EnclosedPatchSO.CreateFromPreview(preview, OrthogenMaterials.OffsetRegionMaterial, OG.Scene);

            AddNewRegionDeformation(curveSO, CurrentLegDeformType);

            // [RMS] this is called at end
            OG.Context.RegisterNextFrameAction(() => {
                OG.Transition(OGWorkflow.DrawAreaExitT);
                OG.Scene.Select(curveSO, true);
            });
        }
Ejemplo n.º 7
0
        public void smooth_append(CurvePreview preview, Vector3f newPos, float fDistThresh)
        {
            // empty curve, always append
            if (preview.VertexCount == 0)
            {
                preview.AppendVertex(newPos);
                last_append          = newPos;
                appended_last_update = true;
                have_temp_append     = false;
                return;
            }

            double d = (newPos - last_append).Length;

            if (d < fDistThresh)
            {
                // have not gone far enough for a real new vertex!

                Vector3f usePos = new Vector3f(newPos);
                bool     bValid = false;

                // do we have enough vertices to do a good job?
                if (preview.VertexCount > 3)
                {
                    int      nLast = (have_temp_append) ? preview.VertexCount - 2 : preview.VertexCount - 1;
                    Vector3d tan   = preview.Tangent(nLast);
                    double   fDot  = tan.Dot((usePos - preview[nLast]).Normalized);
                    if (fDot > 0.9f)        // cos(25) ~= 0.9f
                    // new vtx is aligned with tangent of last "real" vertex
                    {
                        bValid = true;
                    }
                    else
                    {
                        // not aligned, try projection onto tangent
                        Line3d l = new Line3d(preview[nLast], tan);
                        double t = l.Project(newPos);
                        if (t > 0)
                        {
                            // projection of new vtx is 'ahead' so we can use it
                            usePos = (Vector3f)l.PointAt(t);
                            bValid = true;
                        }
                    }
                }

                if (bValid)
                {
                    if (appended_last_update)
                    {
                        preview.AppendVertex(usePos);
                        have_temp_append = true;
                    }
                    else if (have_temp_append)
                    {
                        preview[preview.VertexCount - 1] = usePos;
                    }
                }

                appended_last_update = false;
            }
            else
            {
                // ok we drew far enough, add this position

                if (have_temp_append)
                {
                    // re-use temp vertex
                    preview[preview.VertexCount - 1] = newPos;
                    have_temp_append = false;
                }
                else
                {
                    preview.AppendVertex(newPos);
                }
                last_append          = newPos;
                appended_last_update = true;

                // do smoothing pass
                smoother.End   = preview.VertexCount - 1;
                smoother.Start = MathUtil.Clamp(smoother.End - 5, 0, smoother.End);
                smoother.UpdateDeformation(2);
            }
        }