Example #1
0
    public void ComputeCube()
    {
        cubeIndex = 0;
        if (nodes[0].weight > 0)
        {
            cubeIndex += 1;
        }
        if (nodes[1].weight > 0)
        {
            cubeIndex += 2;
        }
        if (nodes[2].weight > 0)
        {
            cubeIndex += 4;
        }
        if (nodes[3].weight > 0)
        {
            cubeIndex += 8;
        }
        if (nodes[4].weight > 0)
        {
            cubeIndex += 16;
        }
        if (nodes[5].weight > 0)
        {
            cubeIndex += 32;
        }
        if (nodes[6].weight > 0)
        {
            cubeIndex += 64;
        }
        if (nodes[7].weight > 0)
        {
            cubeIndex += 128;
        }
        if (cubeIndex > 0 && cubeIndex <= 255)
        {
            active = true;
        }

        if (active)
        {
            // Using the nodes compute the antinodes (The antinodes are going to be the vertex positions of the mesh)...
            antiNodes    = new AntiNode[12];
            antiNodes[0] = new AntiNode(Vector3.Lerp(nodes[0].pos, nodes[1].pos, Interpolate(nodes[0], nodes[1])));
            antiNodes[1] = new AntiNode(Vector3.Lerp(nodes[1].pos, nodes[2].pos, Interpolate(nodes[1], nodes[2])));
            antiNodes[2] = new AntiNode(Vector3.Lerp(nodes[2].pos, nodes[3].pos, Interpolate(nodes[2], nodes[3])));
            antiNodes[3] = new AntiNode(Vector3.Lerp(nodes[3].pos, nodes[0].pos, Interpolate(nodes[3], nodes[0])));

            antiNodes[4] = new AntiNode(Vector3.Lerp(nodes[4].pos, nodes[5].pos, Interpolate(nodes[4], nodes[5])));
            antiNodes[5] = new AntiNode(Vector3.Lerp(nodes[5].pos, nodes[6].pos, Interpolate(nodes[5], nodes[6])));
            antiNodes[6] = new AntiNode(Vector3.Lerp(nodes[6].pos, nodes[7].pos, Interpolate(nodes[6], nodes[7])));
            antiNodes[7] = new AntiNode(Vector3.Lerp(nodes[7].pos, nodes[4].pos, Interpolate(nodes[7], nodes[4])));

            antiNodes[8]  = new AntiNode(Vector3.Lerp(nodes[0].pos, nodes[4].pos, Interpolate(nodes[0], nodes[4])));
            antiNodes[9]  = new AntiNode(Vector3.Lerp(nodes[1].pos, nodes[5].pos, Interpolate(nodes[1], nodes[5])));
            antiNodes[10] = new AntiNode(Vector3.Lerp(nodes[2].pos, nodes[6].pos, Interpolate(nodes[2], nodes[6])));
            antiNodes[11] = new AntiNode(Vector3.Lerp(nodes[3].pos, nodes[7].pos, Interpolate(nodes[3], nodes[7])));
        }
    }
Example #2
0
    public void ComputeCube()
    {
        // Using the nodes compute the antinodes (The antinodes are going to be the vertex positions of the mesh)...
        antiNodes    = new AntiNode[12];
        antiNodes[0] = new AntiNode(Vector3.Lerp(nodes[0].pos, nodes[1].pos, Mathf.Clamp01(-nodes[0].weight / (nodes[1].weight - nodes[0].weight))));
        antiNodes[1] = new AntiNode(Vector3.Lerp(nodes[1].pos, nodes[2].pos, Mathf.Clamp01(-nodes[1].weight / (nodes[2].weight - nodes[1].weight))));
        antiNodes[2] = new AntiNode(Vector3.Lerp(nodes[2].pos, nodes[3].pos, Mathf.Clamp01(-nodes[2].weight / (nodes[3].weight - nodes[2].weight))));
        antiNodes[3] = new AntiNode(Vector3.Lerp(nodes[3].pos, nodes[0].pos, Mathf.Clamp01(-nodes[3].weight / (nodes[0].weight - nodes[3].weight))));

        antiNodes[4] = new AntiNode(Vector3.Lerp(nodes[4].pos, nodes[5].pos, Mathf.Clamp01(-nodes[4].weight / (nodes[5].weight - nodes[4].weight))));
        antiNodes[5] = new AntiNode(Vector3.Lerp(nodes[5].pos, nodes[6].pos, Mathf.Clamp01(-nodes[5].weight / (nodes[6].weight - nodes[5].weight))));
        antiNodes[6] = new AntiNode(Vector3.Lerp(nodes[6].pos, nodes[7].pos, Mathf.Clamp01(-nodes[6].weight / (nodes[7].weight - nodes[6].weight))));
        antiNodes[7] = new AntiNode(Vector3.Lerp(nodes[7].pos, nodes[4].pos, Mathf.Clamp01(-nodes[7].weight / (nodes[4].weight - nodes[7].weight))));

        antiNodes[8]  = new AntiNode(Vector3.Lerp(nodes[0].pos, nodes[4].pos, Mathf.Clamp01(-nodes[0].weight / (nodes[4].weight - nodes[0].weight))));
        antiNodes[9]  = new AntiNode(Vector3.Lerp(nodes[1].pos, nodes[5].pos, Mathf.Clamp01(-nodes[1].weight / (nodes[5].weight - nodes[1].weight))));
        antiNodes[10] = new AntiNode(Vector3.Lerp(nodes[2].pos, nodes[6].pos, Mathf.Clamp01(-nodes[2].weight / (nodes[6].weight - nodes[2].weight))));
        antiNodes[11] = new AntiNode(Vector3.Lerp(nodes[3].pos, nodes[7].pos, Mathf.Clamp01(-nodes[3].weight / (nodes[7].weight - nodes[3].weight))));

        // Finally compute the cubes cubeIndex
        cubeIndex = 0;
        if (nodes[0].weight > 0)
        {
            cubeIndex += 1;
        }
        if (nodes[1].weight > 0)
        {
            cubeIndex += 2;
        }
        if (nodes[2].weight > 0)
        {
            cubeIndex += 4;
        }
        if (nodes[3].weight > 0)
        {
            cubeIndex += 8;
        }
        if (nodes[4].weight > 0)
        {
            cubeIndex += 16;
        }
        if (nodes[5].weight > 0)
        {
            cubeIndex += 32;
        }
        if (nodes[6].weight > 0)
        {
            cubeIndex += 64;
        }
        if (nodes[7].weight > 0)
        {
            cubeIndex += 128;
        }
    }