Ejemplo n.º 1
0
    void OnMouseOver()
    {
        GetComponent <Renderer>().material.color = Color.yellow;
        if (Input.GetMouseButtonDown(1))
        {
            Vector3 p = Input.mousePosition;
            p.z = 10;
            p   = Camera.main.ScreenToWorldPoint(p);



            Destroy(this.gameObject);
            pubvar.ball--;
            //mSpline.RefreshImmediately();



            //remove the oldest segment, if it's no longer used
            if (RemoveUnusedSegments)
            {
                var seg = mSpline.DistanceToSegment(Walker.Distance);
                if (seg != mSpline[0])
                {
                    Walker.Distance -= mSpline[0].Length;
                    mSpline.Delete(mSpline[0]);
                }
            }
        }
    }
 // Update is called once per frame
 void Update()
 {
     // Add Control Point by mouseclick
     if (Input.GetMouseButtonDown(0))
     {
         Vector3 p = Input.mousePosition;
         p.z = 10;
         p   = Camera.main.ScreenToWorldPoint(p);
         mSpline.Add(p);
         // remove the oldest segment, if it's no longer used
         if (RemoveUnusedSegments)
         {
             var seg = mSpline.DistanceToSegment(Walker.Distance);
             if (seg != mSpline[0])
             {
                 Walker.Distance -= mSpline[0].Length;
                 mSpline.Delete(mSpline[0]);
             }
         }
     }
 }
Ejemplo n.º 3
0
        /// <summary>
        /// Rasterization Helper class
        /// </summary>
        public static List <ControlPointOption> GetControlPointsWithOptions(CGDataRequestMetaCGOptions options, CurvySpline shape, float startDist, float endDist, bool optimize, out int initialMaterialID, out float initialMaxStep)
        {
            var res = new List <ControlPointOption>();

            initialMaterialID = 0;
            initialMaxStep    = float.MaxValue;
            CurvySplineSegment startSeg = shape.DistanceToSegment(startDist);

            float clampedEndDist = shape.ClampDistance(endDist, shape.IsClosed ? CurvyClamping.Loop : CurvyClamping.Clamp);

            if (clampedEndDist == 0)
            {
                clampedEndDist = endDist;
            }
            CurvySplineSegment finishSeg = (clampedEndDist == shape.Length) ? shape.LastVisibleControlPoint : shape.DistanceToSegment(clampedEndDist);

            if (endDist != shape.Length && endDist > finishSeg.Distance)
            {
                finishSeg = finishSeg.NextControlPoint;
            }
            MetaCGOptions cgOptions;

            float loopOffset = 0;

            if (startSeg)
            {
                cgOptions      = startSeg.GetMetadata <MetaCGOptions>(true);
                initialMaxStep = (cgOptions.MaxStepDistance == 0) ? float.MaxValue : cgOptions.MaxStepDistance;
                if (options.CheckMaterialID)
                {
                    initialMaterialID = cgOptions.MaterialID;
                }
                int currentMaterialID = initialMaterialID;

                float maxDist = cgOptions.MaxStepDistance;

                /*
                 * if ((options.CheckMaterialID && cgOptions.MaterialID != 0) ||
                 *     (optimize && cgOptions.MaxStepDistance != 0))
                 *  res.Add(new ControlPointOption(startSeg.LocalFToTF(0),
                 *                                 startSeg.Distance,
                 *                                 true,
                 *                                 cgOptions.MaterialID,
                 *                                 options.CheckHardEdges && cgOptions.HardEdge,
                 *                                 initialMaxStep,
                 *                                 (options.CheckExtendedUV && cgOptions.UVEdge),
                 *                                 options.CheckExtendedUV && cgOptions.ExplicitU,
                 *                                 cgOptions.FirstU,
                 *                                 cgOptions.SecondU));
                 */


                var seg = startSeg.NextSegment ?? startSeg.NextControlPoint;
                do
                {
                    cgOptions = seg.GetMetadata <MetaCGOptions>(true);
                    if (seg.ControlPointIndex < startSeg.ControlPointIndex)
                    {
                        loopOffset = shape.Length;
                    }
                    if (options.IncludeControlPoints ||
                        (options.CheckHardEdges && cgOptions.HardEdge) ||
                        (options.CheckMaterialID && cgOptions.MaterialID != currentMaterialID) ||
                        (optimize && cgOptions.MaxStepDistance != maxDist) ||
                        (options.CheckExtendedUV && (cgOptions.UVEdge || cgOptions.ExplicitU))
                        )
                    {
                        bool matDiff = cgOptions.MaterialID != currentMaterialID;
                        maxDist           = (cgOptions.MaxStepDistance == 0) ? float.MaxValue : cgOptions.MaxStepDistance;
                        currentMaterialID = options.CheckMaterialID ? cgOptions.MaterialID : initialMaterialID;
                        res.Add(new ControlPointOption(seg.LocalFToTF(0) + Mathf.FloorToInt(loopOffset / shape.Length),
                                                       seg.Distance + loopOffset,
                                                       options.IncludeControlPoints,
                                                       currentMaterialID,
                                                       options.CheckHardEdges && cgOptions.HardEdge,
                                                       cgOptions.MaxStepDistance,
                                                       (options.CheckExtendedUV && cgOptions.UVEdge) || matDiff,
                                                       options.CheckExtendedUV && cgOptions.ExplicitU,
                                                       cgOptions.FirstU,
                                                       cgOptions.SecondU));
                    }
                    seg = seg.NextSegment;
                } while (seg && seg != finishSeg);
                // Check UV settings of last cp (not a segment if open spline!)
                if (options.CheckExtendedUV && !seg && finishSeg.IsLastVisibleControlPoint)
                {
                    cgOptions = finishSeg.GetMetadata <MetaCGOptions>(true);
                    if (cgOptions.ExplicitU)
                    {
                        res.Add(new ControlPointOption(1,
                                                       finishSeg.Distance + loopOffset,
                                                       options.IncludeControlPoints,
                                                       currentMaterialID,
                                                       options.CheckHardEdges && cgOptions.HardEdge,
                                                       cgOptions.MaxStepDistance,
                                                       (options.CheckExtendedUV && cgOptions.UVEdge) || (options.CheckMaterialID && cgOptions.MaterialID != currentMaterialID),
                                                       options.CheckExtendedUV && cgOptions.ExplicitU,
                                                       cgOptions.FirstU,
                                                       cgOptions.SecondU));
                    }
                }
            }

            return(res);
        }
Ejemplo n.º 4
0
    void OnMouseOver()
    {
        //Vector3 yoho = GameObject  transform.GetChild(1).position - transform.GetChild(0).position;


        movenum = gameObject.name;



        if (GetComponent <Renderer>())
        {
            GetComponent <Renderer>().material.color = Color.green;
        }

        if (Input.GetMouseButton(0))
        {//鼠标按着左键移动
         //Vector3 vect = Vector3.Normalize(GameObject.Find("eave1").transform.GetChild(6).transform.position - GameObject.Find("eave1").transform.GetChild(7).transform.position);


            //yy = Input.GetAxis("Mouse X") * Time.deltaTime * speed;
            xx = Input.GetAxis("Mouse Y") * Time.deltaTime * speed;

            //transform.Translate(yy * vect.x, 0, yy * vect.z);
            transform.Translate(0, xx, 0);


            //Vector3 initial = new Vector3(GameObject.Find("DynamicSpline").transform.GetChild(pubvar.ball - 1).transform.position.x - GameObject.Find("DynamicSpline").transform.GetChild(0).transform.position.x, 0, GameObject.Find("DynamicSpline").transform.GetChild(pubvar.ball - 1).transform.position.z - GameObject.Find("DynamicSpline").transform.GetChild(0).transform.position.z);
            //Vector3 now = new Vector3(transform.position.x - GameObject.Find("DynamicSpline").transform.GetChild(0).transform.position.x, 0, transform.position.z - GameObject.Find("DynamicSpline").transform.GetChild(0).transform.position.z);



            //float leg = Vector3.Angle(initial, now);

            //transform.RotateAround(GameObject.Find("DynamicSpline").transform.GetChild(0).transform.position, Vector3.up, leg);
        }
        else
        {
            xx = 0;
            yy = 0;
            zz = 0;
        }



        if (Input.GetMouseButtonDown(1))
        {
            Vector3 p = Input.mousePosition;
            p.z = 10;
            p   = Camera.main.ScreenToWorldPoint(p);


            pubvar.PUBnum = 0;
            print(pubvar.PUBnum + "~~~");
            Destroy(this.gameObject.GetComponent <mice1>());

            //mSpline.RefreshImmediately();



            //remove the oldest segment, if it's no longer used
            if (RemoveUnusedSegments)
            {
                var seg = mSpline.DistanceToSegment(Walker.Distance);
                if (seg != mSpline[0])
                {
                    Walker.Distance -= mSpline[0].Length;
                    mSpline.Delete(mSpline[0]);
                }
            }
        }
    }
Ejemplo n.º 5
0
        /// <summary>
        /// Rasterization Helper class
        /// </summary>
        public static List<ControlPointOption> GetControlPointsWithOptions(CGDataRequestMetaCGOptions options, CurvySpline shape, float startDist, float endDist, bool optimize, out int initialMaterialID, out float initialMaxStep)
        {
            var res = new List<ControlPointOption>();
            initialMaterialID = 0;
            initialMaxStep = float.MaxValue;
            CurvySplineSegment startSeg = shape.DistanceToSegment(startDist);
            
            float clampedEndDist = shape.ClampDistance(endDist, shape.IsClosed ? CurvyClamping.Loop : CurvyClamping.Clamp);
            if (clampedEndDist == 0)
                clampedEndDist = endDist;
            CurvySplineSegment finishSeg = (clampedEndDist==shape.Length) ? shape.LastVisibleControlPoint : shape.DistanceToSegment(clampedEndDist);
            if (endDist!=shape.Length && endDist > finishSeg.Distance)
                finishSeg = finishSeg.NextControlPoint;
            MetaCGOptions cgOptions;

            float loopOffset = 0;
            if (startSeg)
            {
                cgOptions = startSeg.GetMetadata<MetaCGOptions>(true);
                initialMaxStep = (cgOptions.MaxStepDistance == 0) ? float.MaxValue : cgOptions.MaxStepDistance;
                if (options.CheckMaterialID)
                    initialMaterialID = cgOptions.MaterialID;
                int currentMaterialID = initialMaterialID;
                
                float maxDist = cgOptions.MaxStepDistance;
                /*
                if ((options.CheckMaterialID && cgOptions.MaterialID != 0) ||
                       (optimize && cgOptions.MaxStepDistance != 0))
                    res.Add(new ControlPointOption(startSeg.LocalFToTF(0),
                                                   startSeg.Distance,
                                                   true,
                                                   cgOptions.MaterialID,
                                                   options.CheckHardEdges && cgOptions.HardEdge,
                                                   initialMaxStep,
                                                   (options.CheckExtendedUV && cgOptions.UVEdge),
                                                   options.CheckExtendedUV && cgOptions.ExplicitU,
                                                   cgOptions.FirstU,
                                                   cgOptions.SecondU));
                */


                var seg = startSeg.NextSegment ?? startSeg.NextControlPoint;
                do
                {
                    cgOptions = seg.GetMetadata<MetaCGOptions>(true);
                    if (seg.ControlPointIndex < startSeg.ControlPointIndex)
                        loopOffset = shape.Length;
                    if (options.IncludeControlPoints ||
                       (options.CheckHardEdges && cgOptions.HardEdge) ||
                       (options.CheckMaterialID && cgOptions.MaterialID != currentMaterialID) ||
                       (optimize && cgOptions.MaxStepDistance != maxDist) ||
                       (options.CheckExtendedUV && (cgOptions.UVEdge || cgOptions.ExplicitU))
                        )
                    {
                        bool matDiff = cgOptions.MaterialID != currentMaterialID;
                        maxDist = (cgOptions.MaxStepDistance == 0) ? float.MaxValue : cgOptions.MaxStepDistance;
                        currentMaterialID = options.CheckMaterialID ? cgOptions.MaterialID : initialMaterialID;
                        res.Add(new ControlPointOption(seg.LocalFToTF(0) + Mathf.FloorToInt(loopOffset / shape.Length),
                                                       seg.Distance + loopOffset, 
                                                       options.IncludeControlPoints,
                                                       currentMaterialID,
                                                       options.CheckHardEdges && cgOptions.HardEdge,
                                                       cgOptions.MaxStepDistance,
                                                       (options.CheckExtendedUV && cgOptions.UVEdge) || matDiff,
                                                       options.CheckExtendedUV && cgOptions.ExplicitU,
                                                       cgOptions.FirstU,
                                                       cgOptions.SecondU));

                    }
                    seg = seg.NextSegment;
                } while (seg && seg != finishSeg);
                // Check UV settings of last cp (not a segment if open spline!)
                if (options.CheckExtendedUV && !seg && finishSeg.IsLastVisibleControlPoint) 
                {
                    cgOptions = finishSeg.GetMetadata<MetaCGOptions>(true);
                    if (cgOptions.ExplicitU)
                        res.Add(new ControlPointOption(1,
                                                       finishSeg.Distance + loopOffset,
                                                       options.IncludeControlPoints,
                                                       currentMaterialID,
                                                       options.CheckHardEdges && cgOptions.HardEdge,
                                                       cgOptions.MaxStepDistance,
                                                       (options.CheckExtendedUV && cgOptions.UVEdge) || (options.CheckMaterialID && cgOptions.MaterialID != currentMaterialID),
                                                       options.CheckExtendedUV && cgOptions.ExplicitU,
                                                       cgOptions.FirstU,
                                                       cgOptions.SecondU));
                }
            }
            
            return res;
        }