示例#1
0
    void MakeMetaballs(float d)
    {
        /*
         * Vector3 tempPt = points [points.Count - 1];
         * Vector3 tempDiff = points [points.Count - 1] - points [points.Count - 2];
         * int numPt = d / 0.1f;
         * Debug.Log (numPt);
         * Vector3[] midPts = new Vector3[numPt];
         * midPts [numPt-1] = tempPt;
         *
         * for (int i = 0; i < numPt; i++)
         * {
         *      Vector3 midPt = prevPt + ((1f / 1f) * (i + 1) * tempDiff);
         *      // update sketch point
         *      points.Add (midPt);
         *      // update line width
         *      lineWidthList.Add (Random.Range(0.1f, 0.1f * 2f));
         *      // update mesh
         *      offsetsQuat.Add (Quaternion.FromToRotation (Vector3.forward, points [points.Count - 2] - points [points.Count - 1]));
         *      UpdateMeshThree ();
         *      RecalculateMesh ();
         * }*/


        int   ballNum = 10;
        float dist    = 0.1f;

        Vector3[] randomDist = new Vector3[ballNum];
        Vector3   temp;
        Vector3   pt = points [points.Count - 1];

        // create metaballs
        for (int i = 0; i < ballNum; i++)
        {
            randomDist [i] = new Vector3(Random.Range(-dist, dist), Random.Range(-dist / 2, dist / 2), Random.Range(0, dist));
            temp           = new Vector3(pt.x + randomDist [i].x, pt.y + randomDist[i].y, pt.z + randomDist[i].z);
            GameObject child = new GameObject("MetaballNode");
            child.transform.parent        = line.transform.Find("SourceRoot").transform;
            child.transform.position      = temp;
            child.transform.localScale    = Vector3.one;
            child.transform.localRotation = Quaternion.identity;
            MetaballNode newNode = child.AddComponent <MetaballNode> ();
            newNode.baseRadius = Random.Range(0.4f, 0.6f);
        }

        // rebuild mesh
        seed.CreateMesh();
    }
示例#2
0
    public void AddCell(Vector3 position, float size)
    {
        audioSource.Play();

        GameObject child = new GameObject("MetaballNode");

        child.transform.parent        = metaball.sourceRoot.transform;
        child.transform.position      = position;
        child.transform.localScale    = Vector3.one;
        child.transform.localRotation = Quaternion.identity;

        MetaballNode newNode = child.AddComponent <MetaballNode>();

        newNode.baseRadius = size;

        metaball.CreateMesh();

        MeshCollider mc = metaball.GetComponent <MeshCollider>();

        if (mc != null)
        {
            mc.sharedMesh = metaball.Mesh;
        }

        Instantiate(hitPS.gameObject, position, Quaternion.identity);
    }