Example #1
0
        public float Evaluate(Vector3 point)
        {
            float sum = 0;

            for (int i = 0; i < metaballs.Length; i++)
            {
                Metaball3D m = metaballs[i];

                float d     = (point - m.center).magnitude;
                float r     = m.radius;
                float value = r / d;

                sum += value;
            }

            return(sum);
        }
Example #2
0
        public Function(Vector3 _center, int nMetaballs, Vector3 _bounds, Vector2 sizeRange, Vector2 speedRange, List <Color> palette)
        {
            center = _center;
            bounds = _bounds;

            metaballs = new Metaball3D[nMetaballs];

            for (int i = 0; i < nMetaballs; i++)
            {
                Metaball3D m = new Metaball3D();
                m.radius = Random.Range(sizeRange.x, sizeRange.y);
                m.center = new Vector3(
                    Random.Range(-bounds.x * 0.5f + m.radius, bounds.x * 0.5f - m.radius),
                    Random.Range(-bounds.y * 0.5f + m.radius, bounds.y * 0.5f - m.radius),
                    Random.Range(-bounds.z * 0.5f + m.radius, bounds.z * 0.5f - m.radius)
                    );
                m.velocity = Random.insideUnitSphere * Random.Range(speedRange.x, speedRange.y);
                m.color    = palette[Random.Range(0, palette.Count - 1)];

                metaballs[i] = m;
            }
        }
Example #3
0
        public Vector3 Normal(Vector3 point)
        {
            Vector3 netNormal = Vector3.zero;

            for (int i = 0; i < metaballs.Length; i++)
            {
                Metaball3D m = metaballs[i];

                float r = m.radius;
                float d = (point - m.center).magnitude;

                Vector3 normal = new Vector3();

                float value = r / d;
                normal = r * (point - m.center) / d;

                netNormal += normal * value;
            }

            netNormal = netNormal / Evaluate(point);

            return(netNormal.normalized);
        }