예제 #1
0
        public void Reset()
        {
            curveSegments = kDefaultCurveSegments;
            path          = new ChiselPath(ChiselPath.Default);
            shape         = new Curve2D(kDefaultShape);

            if (surfaceDefinition != null)
            {
                surfaceDefinition.Reset();
            }
        }
예제 #2
0
 public static ChiselBlobAssetReference <ChiselPathBlob> Convert(ChiselPath path, Allocator allocator)
 {
     path.UpgradeIfNecessary();
     using (var builder = new ChiselBlobBuilder(Allocator.Temp))
     {
         ref var root             = ref builder.ConstructRoot <ChiselPathBlob>();
         var     srcControlPoints = path.segments;
         var     dstControlPoints = builder.Allocate(ref root.segments, srcControlPoints.Length);
         for (int i = 0; i < srcControlPoints.Length; i++)
         {
             dstControlPoints[i] = Convert(srcControlPoints[i]);
         }
         return(builder.CreateBlobAssetReference <ChiselPathBlob>(allocator));
     }
        public void OnEdit(IChiselHandles handles)
        {
            var baseColor    = handles.color;
            var noZTestcolor = handles.GetStateColor(baseColor, false, true);
            var zTestcolor   = handles.GetStateColor(baseColor, false, false);

            path.UpgradeIfNecessary();

            for (int i = 0; i < path.segments.Length; i++)
            {
                var pathPoint  = path.segments[i];
                var currMatrix = pathPoint.ToMatrix();

                handles.color = baseColor;
                handles.DoShapeHandle(ref shape, currMatrix);

                if (i == 0)
                {
                    if (handles.DoDirectionHandle(ref pathPoint.position, -(pathPoint.rotation * Vector3.forward)))
                    {
                        path.segments[i] = pathPoint;
                        path             = new ChiselPath(path);
                    }
                }
                else
                if (i == path.segments.Length - 1)
                {
                    if (handles.DoDirectionHandle(ref pathPoint.position, (pathPoint.rotation * Vector3.forward)))
                    {
                        path.segments[i] = pathPoint;
                        path             = new ChiselPath(path);
                    }
                }


                // Draw lines between different segments
                if (i + 1 < path.segments.Length)
                {
                    var nextPoint     = path.segments[i + 1];
                    var nextMatrix    = nextPoint.ToMatrix();
                    var controlPoints = shape.controlPoints;

                    for (int c = 0; c < controlPoints.Length; c++)
                    {
                        var controlPoint = controlPoints[c].position;
                        var pointA       = currMatrix.MultiplyPoint(controlPoint);
                        var pointB       = nextMatrix.MultiplyPoint(controlPoint);
                        handles.color = noZTestcolor;
                        handles.DrawLine(pointA, pointB, lineMode: LineMode.NoZTest, thickness: kCapLineThickness, dashSize: kLineDash);

                        handles.color = zTestcolor;
                        handles.DrawLine(pointA, pointB, lineMode: LineMode.ZTest, thickness: kCapLineThickness, dashSize: kLineDash);
                    }

                    {
                        var pointA = currMatrix.MultiplyPoint(Vector3.zero);
                        var pointB = nextMatrix.MultiplyPoint(Vector3.zero);
                        handles.color = zTestcolor;
                        handles.DrawLine(pointA, pointB, lineMode: LineMode.NoZTest, thickness: kCapLineThickness, dashSize: kLineDash);

                        handles.color = zTestcolor;
                        handles.DrawLine(pointA, pointB, lineMode: LineMode.ZTest, thickness: kCapLineThickness, dashSize: kLineDash);
                    }

                    handles.color = baseColor;
                }

                // TODO: cannot rotate so far that one path plane intersects with shape on another plane
                //			... or just fail when it's wrong?
            }

            for (int i = 0; i < path.segments.Length; i++)
            {
                var pathPoint = path.segments[i];
                if (handles.DoPathPointHandle(ref pathPoint))
                {
                    var originalSegments = path.segments;
                    var newPath          = new ChiselPath(new ChiselPathPoint[originalSegments.Length]);
                    System.Array.Copy(originalSegments, newPath.segments, originalSegments.Length);
                    newPath.segments[i] = pathPoint;
                    path = newPath;
                }
            }

            // TODO: draw curved path
        }
예제 #4
0
 public ChiselPath(ChiselPath other)
 {
     this.segments = other.segments.ToArray();
 }