Example #1
0
        protected override SDFNode GenerateNode()
        {
            var inverse = _cachedNode as Inverse;
            var offset  = _cachedNode as Offset;

            switch (Type)
            {
            case UnaryType.Inverse:
                if (inverse == null)
                {
                    _cachedNode = inverse = new Inverse();
                }
                break;

            case UnaryType.Offset:
                if (offset == null)
                {
                    _cachedNode = offset = new Offset();
                }
                offset.Operation.Offset = Offset;
                break;
            }

            return(_cachedNode);
        }
Example #2
0
        protected override SDFNode GenerateNode()
        {
            var intersection = _cachedNode as Intersection;
            var union        = _cachedNode as Union;
            var smoothUnion  = _cachedNode as UnionSmooth;

            switch (Type)
            {
            case BinaryType.Intersection:
                if (intersection == null)
                {
                    _cachedNode = intersection = new Intersection();
                }
                break;

            case BinaryType.Union:
                if (union == null)
                {
                    _cachedNode = union = new Union();
                }
                break;

            case BinaryType.SmoothUnion:
                if (smoothUnion == null)
                {
                    _cachedNode = smoothUnion = new UnionSmooth();
                }
                smoothUnion.Operation.K = K;
                break;
            }

            return(_cachedNode);
        }
Example #3
0
        private void linkUpChildren(SDFNode node, Transform t)
        {
            for (int i = 0; i < t.childCount; i++)
            {
                var child = t.GetChild(i);
                if (!child.gameObject.activeInHierarchy)
                {
                    continue;
                }

                t.GetChild(i).GetComponents(_tmpList);

                bool foundChild = false;
                for (int j = 0; j < _tmpList.Count; j++)
                {
                    if (_tmpList[j].isActiveAndEnabled)
                    {
                        node.Add(_tmpList[j].GetNode());
                        foundChild = true;
                        break;
                    }
                }

                if (foundChild)
                {
                    continue;
                }

                linkUpChildren(node, t.GetChild(i));
            }
        }
Example #4
0
        protected override SDFNode GenerateNode()
        {
            var sphere = _cachedNode as Sphere;
            var box    = _cachedNode as Box;

            switch (Type)
            {
            case ShapeType.Sphere:
                if (sphere == null)
                {
                    _cachedNode = sphere = new Sphere();
                }
                sphere.Operation = new Sphere.Op()
                {
                    Center = transform.position,
                    Radius = transform.lossyScale.x
                };
                break;

            case ShapeType.Box:
                if (box == null)
                {
                    _cachedNode = box = new Box();
                }
                box.Operation = new Box.Op()
                {
                    ToLocalSpace = Matrix4x4.TRS(transform.position, transform.rotation, Vector3.one).inverse,
                    Extents      = transform.lossyScale
                };
                break;
            }

            return(_cachedNode);
        }
Example #5
0
        public SDFNode GetNode()
        {
            SDFNode node = GenerateNode();

            node.ClearChildren();
            linkUpChildren(node, transform);

            return(node);
        }
Example #6
0
 private void linkUpChildren(SDFNode node, Transform t)
 {
     for (int i = 0; i < t.childCount; i++)
     {
         t.GetChild(i).GetComponents(_tmpList);
         if (_tmpList.Count > 0)
         {
             node.Add(_tmpList[0].GetNode());
         }
         else
         {
             linkUpChildren(node, t.GetChild(i));
         }
     }
 }
Example #7
0
        private SDFNode GenerateNode()
        {
            //Shapes
            var sphere = _cachedNode as Sphere;
            var box    = _cachedNode as Box;

            //Binaries
            var intersection = _cachedNode as Intersection;
            var union        = _cachedNode as Union;
            var smoothUnion  = _cachedNode as UnionSmooth;

            //Unaries
            var inverse = _cachedNode as Inverse;
            var offset  = _cachedNode as Offset;

            //Domains
            var modSimple = _cachedNode as ModSimple;

            switch (Type)
            {
            //Shapes
            case NodeType.Sphere:
                if (sphere == null)
                {
                    _cachedNode = sphere = new Sphere();
                }
                sphere.Center = transform.position;
                sphere.Radius = transform.lossyScale.x * 0.5f;
                break;

            case NodeType.Box:
                if (box == null)
                {
                    _cachedNode = box = new Box();
                }
                box.ToLocalSpace = Matrix4x4.TRS(transform.position, transform.rotation, Vector3.one).inverse;
                box.Extents      = transform.lossyScale * 0.5f;
                break;

            //Binaries
            case NodeType.Intersection:
                if (intersection == null)
                {
                    _cachedNode = intersection = new Intersection();
                }
                break;

            case NodeType.Union:
                if (union == null)
                {
                    _cachedNode = union = new Union();
                }
                break;

            case NodeType.SmoothUnion:
                if (smoothUnion == null)
                {
                    _cachedNode = smoothUnion = new UnionSmooth();
                }
                smoothUnion.K = K;
                break;

            //Unaries
            case NodeType.Inverse:
                if (inverse == null)
                {
                    _cachedNode = inverse = new Inverse();
                }
                break;

            case NodeType.Offset:
                if (offset == null)
                {
                    _cachedNode = offset = new Offset();
                }
                offset.Value = Offset;
                break;

            //Domains
            case NodeType.ModSimple:
                if (modSimple == null)
                {
                    _cachedNode = modSimple = new ModSimple();
                }
                modSimple.CellSize = CellSize;
                modSimple.ModX     = X;
                modSimple.ModY     = Y;
                modSimple.ModZ     = Z;
                break;
            }

            return(_cachedNode);
        }
Example #8
0
        private SDFNode GenerateNode()
        {
            _cachedNode = GetNodeFromEnum();

            float4x4 toLocal = math.inverse(float4x4.TRS(transform.position, transform.rotation, Vector3.one));
            float    xLength = transform.TransformVector(Vector3.right).magnitude;
            float    yLength = transform.TransformVector(Vector3.up).magnitude;
            float    zLength = transform.TransformVector(Vector3.forward).magnitude;
            float3   size    = new float3(xLength, yLength, zLength);
            float3   extent  = size / 2;

            if (_cachedNode is Box box)
            {
                box.ToLocalSpace = toLocal;
                box.Extents      = extent;
            }
            else if (_cachedNode is Capsule capsule)
            {
                capsule.PointA = transform.TransformPoint(Vector3.up);
                capsule.PointB = transform.TransformPoint(Vector3.down);
                capsule.Radius = RadiusA;
            }
            else if (_cachedNode is Cone cone)
            {
                cone.ToLocalSpace = toLocal;
                cone.Height       = extent.y;
                cone.Radius       = math.length(extent.xz);
            }
            else if (_cachedNode is Cylinder cylinder)
            {
                cylinder.ToLocalSpace = toLocal;
                cylinder.Height       = extent.y;
                cylinder.Radius       = math.length(extent.xz);
            }
            else if (_cachedNode is Plane plane)
            {
                UnityEngine.Plane p = new UnityEngine.Plane(transform.up, transform.position);
                plane.Normal         = p.normal;
                plane.DistFromOrigin = p.distance;
            }
            else if (_cachedNode is Sphere sphere)
            {
                sphere.Center = transform.position;
                sphere.Radius = math.length(extent.xyz);
            }
            else if (_cachedNode is Torus torus)
            {
                torus.ToLocalSpace = toLocal;
                torus.SmallRadius  = RadiusA * math.length(extent);
                torus.LargeRadius  = RadiusB * math.length(extent);
            }
            else if (_cachedNode is IChamferOp chamfer)
            {
                chamfer.Radius = RadiusA;
            }
            else if (_cachedNode is IColumnsOp columns)
            {
                columns.Radius = RadiusA;
                columns.N      = N;
            }
            else if (_cachedNode is IRoundOp round)
            {
                round.Radius = RadiusA;
            }
            else if (_cachedNode is IStairsOp stairs)
            {
                stairs.Radius = RadiusA;
                stairs.N      = N;
            }
            else if (_cachedNode is Engrave engrave)
            {
                engrave.Radius = RadiusA;
            }
            else if (_cachedNode is Groove groove)
            {
                groove.RadiusA = RadiusA;
                groove.RadiusB = RadiusB;
            }
            else if (_cachedNode is Pipe pipe)
            {
                pipe.Radius = RadiusA;
            }
            else if (_cachedNode is Tongue tongue)
            {
                tongue.RadiusA = RadiusA;
                tongue.RadiusB = RadiusB;
            }
            else if (_cachedNode is Offset offset)
            {
                offset.Value = Offset;
            }
            else if (_cachedNode is ModSimple modSimple)
            {
                modSimple.CellSize = CellSize;
                modSimple.ModX     = X;
                modSimple.ModY     = Y;
                modSimple.ModZ     = Z;
            }
            else if (_cachedNode is Rotate45 rot45)
            {
                rot45.Axis = Axis;
            }

            return(_cachedNode);
        }