Example #1
0
    /*Return the interpolated position of point on an Axis*/
    private Vector3 mPos(mcPoint a, mcPoint b, int axisI)
    {
        float   mu  = (isoLevel - a.i()) / (b.i() - a.i());
        Vector3 tmp = tada[tadac++];

        tmp[0]     = a[0]; tmp[1] = a[1]; tmp[2] = a[2];
        tmp[axisI] = a[axisI] + (mu * (b[axisI] - a[axisI]));
        return(tmp);
    }
Example #2
0
 public mcCube(  )
 {
     cntr  = 0;
     edges = new mcEdge[12];
     for (int i = 0; i < 12; i++)
     {
         edges[i] = null;
     }
     points = new mcPoint[8];
 }
Example #3
0
    /*Generate the Cube Lattice
     * All shared vertices and edges are connected across cubes,
     * it's not perfect in that the edges along the lower index borders
     * are not connected, but all the rest are, this shouldn't make any
     * noticeable visual impact, and have no performance impact unless
     * a blob lies along those borders*/
    private void startObjs(  )
    {
        int   i;
        float jx, jy, jz;
        int   ijx, ijy, ijz;
        int   pointCount = ((dimX + 1) * (dimY + 1) * (dimZ + 1));
        int   cubeCount  = (dimX * dimY * dimZ);
        int   edgeCount  = (cubeCount * 3) + ((2 * dimX * dimY) + (2 * dimX * dimZ) + (2 * dimY * dimZ)) + dimX + dimY + dimZ; //Ideal Edge Count
        int   edgeNow    = edgeCount + ((dimX * dimY) + (dimY * dimZ) + (dimZ * dimX)) * 2;                                    //Haven't combined the edges of the 0 index borders
        //Should be a pretty safe amount
        int tmpv = (int)(dimX * dimY * dimZ / 7);

        tadam = tmpv * 4;
        fv    = new Vector3[tmpv];
        fn    = new Vector3[tmpv];
        fuv   = new Vector2[tmpv];
        //Pretty save amount of Tris as well
        ft        = new int[(int)(cubeCount * .75)];
        newVertex = new Vector3[300000];
        newTri    = new int[300000];
        newNormal = new Vector3[300000];
        tada      = new Vector3[tadam * 2];
        tada2     = new Vector2[tadam * 2];
        //newUV=new Vector2[300000];
        _cubes  = new mcCube[cubeCount];
        _points = new mcPoint[pointCount];
        _edges  = new mcEdge[edgeNow];
        for (i = 0; i < tadam * 2; i++)
        {
            tada[i]  = new Vector3(0, 0, 0);
            tada2[i] = new Vector2(0, 0);
        }
        for (i = 0; i < edgeNow; i++)
        {
            _edges[i] = new mcEdge(-1);
        }
        i = 0;
        for (jx = 0.0f; jx <= dimX; jx++)
        {
            for (jy = 0.0f; jy <= dimY; jy++)
            {
                for (jz = 0.0f; jz <= dimZ; jz++)
                {
                    _points[i] = new mcPoint((jx / dimX) - .5f, (jy / dimY) - .5f, (jz / dimZ) - .5f, (int)jx, (int)jy, (int)jz, this);
                    i++;
                }
            }
        }
        for (i = 0; i < cubeCount; i++)
        {
            _cubes[i] = new mcCube();
        }
        int    ep = 0;
        mcCube c;
        mcCube tc;

        i = 0;
        int topo = 0;

        for (ijx = 0; ijx < dimX; ijx++)
        {
            for (ijy = 0; ijy < dimY; ijy++)
            {
                for (ijz = 0; ijz < dimZ; ijz++)
                {
                    c = _cubes[i];
                    i++;
                    c.px = ijx; c.py = ijy; c.pz = ijz;
                    mcPoint[] cpt = c.points;
                    cpt[0] = getPoint(ijx, ijy, ijz);
                    cpt[1] = getPoint(ijx + 1, ijy, ijz);
                    cpt[2] = getPoint(ijx + 1, ijy + 1, ijz);
                    cpt[3] = getPoint(ijx, ijy + 1, ijz);
                    cpt[4] = getPoint(ijx, ijy, ijz + 1);
                    cpt[5] = getPoint(ijx + 1, ijy, ijz + 1);
                    cpt[6] = getPoint(ijx + 1, ijy + 1, ijz + 1);
                    cpt[7] = getPoint(ijx, ijy + 1, ijz + 1);
                    mcEdge[] e = c.edges;
                    e[5]  = _edges[ep++]; e[5].axisI = 1;
                    e[6]  = _edges[ep++]; e[6].axisI = 0;
                    e[10] = _edges[ep++]; e[10].axisI = 2;
                    tc    = getCube(ijx + 1, ijy, ijz);
                    if (tc != null)
                    {
                        tc.edges[11] = e[10]; tc.edges[7] = e[5];
                    }

                    tc = getCube(ijx, ijy + 1, ijz);
                    if (tc != null)
                    {
                        tc.edges[4] = c.edges[6]; tc.edges[9] = c.edges[10];
                    }

                    tc = getCube(ijx, ijy + 1, ijz + 1);
                    if (tc != null)
                    {
                        tc.edges[0] = c.edges[6];
                    }

                    tc = getCube(ijx + 1, ijy, ijz + 1);
                    if (tc != null)
                    {
                        tc.edges[3] = c.edges[5];
                    }

                    tc = getCube(ijx + 1, ijy + 1, ijz);
                    if (tc != null)
                    {
                        tc.edges[8] = c.edges[10];
                    }

                    tc = getCube(ijx, ijy, ijz + 1);
                    if (tc != null)
                    {
                        tc.edges[1] = c.edges[5]; tc.edges[2] = c.edges[6];
                    }

                    if (e[0] == null)
                    {
                        e[0] = _edges[ep++]; e[0].axisI = 0;
                    }
                    if (e[1] == null)
                    {
                        e[1] = _edges[ep++]; e[1].axisI = 1;
                    }
                    if (e[2] == null)
                    {
                        e[2] = _edges[ep++]; e[2].axisI = 0;
                    }
                    else
                    {
                        topo++;
                    }
                    if (e[3] == null)
                    {
                        e[3] = _edges[ep++]; e[3].axisI = 1;
                    }
                    if (e[4] == null)
                    {
                        e[4] = _edges[ep++]; e[4].axisI = 0;
                    }
                    if (e[7] == null)
                    {
                        e[7] = _edges[ep++]; e[7].axisI = 1;
                    }
                    if (e[8] == null)
                    {
                        e[8] = _edges[ep++]; e[8].axisI = 2;
                    }
                    if (e[9] == null)
                    {
                        e[9] = _edges[ep++]; e[9].axisI = 2;
                    }
                    if (e[11] == null)
                    {
                        e[11] = _edges[ep++]; e[11].axisI = 2;
                    }
                }
            }
        }
    }
Example #4
0
    /*Generate the Cube Lattice
      All shared vertices and edges are connected across cubes,
      it's not perfect in that the edges along the lower index borders
      are not connected, but all the rest are, this shouldn't make any
      noticeable visual impact, and have no performance impact unless
      a blob lies along those borders*/
    private void startObjs(  )
    {
        int i;
        float  jx,jy,jz;
        int ijx,ijy,ijz;
        int pointCount=((dimX+1)*(dimY+1)*(dimZ+1));
        int cubeCount=(dimX*dimY*dimZ);
        int edgeCount=(cubeCount*3)+((2*dimX*dimY)+(2*dimX*dimZ)+(2*dimY*dimZ))+dimX+dimY+dimZ; //Ideal Edge Count
        int edgeNow=edgeCount+((dimX*dimY)+(dimY*dimZ)+(dimZ*dimX))*2; //Haven't combined the edges of the 0 index borders
        //Should be a pretty safe amount
        int tmpv=(int)(dimX*dimY*dimZ/7);
        tadam=tmpv*4;
        fv=new Vector3[tmpv];
        fn=new Vector3[tmpv];
        fuv=new Vector2[tmpv];
        //Pretty save amount of Tris as well
        ft=new int[(int)(cubeCount*.75)];
        newVertex=new Vector3[300000];
        newTri=new int[300000];
        newNormal=new Vector3[300000];
        tada=new Vector3[tadam*2];
        tada2=new Vector2[tadam*2];
        //newUV=new Vector2[300000];
        _cubes=new mcCube[cubeCount];
        _points=new mcPoint[pointCount];
        _edges=new mcEdge[edgeNow];
        for (i=0;i<tadam*2;i++) {
            tada[i]=new Vector3(0,0,0);
            tada2[i]=new Vector2(0,0);
        }
        for (i=0;i<edgeNow;i++) {
            _edges[i]=new mcEdge(-1);
        }
        i=0;
        for(jx=0.0f;jx<=dimX;jx++) {
            for(jy=0.0f;jy<=dimY;jy++) {
                for(jz=0.0f;jz<=dimZ;jz++){
                    _points[i]=new mcPoint((jx/dimX)-.5f,(jy/dimY)-.5f,(jz/dimZ)-.5f,(int)jx,(int)jy,(int)jz,this);
                    i++;
                }
            }
        }
        for(i=0;i<cubeCount;i++) _cubes[i]=new mcCube();
        int ep=0;
        mcCube c;
        mcCube tc;
        i=0;
        int topo=0;
        for(ijx=0;ijx<dimX;ijx++){
            for(ijy=0;ijy<dimY;ijy++) {
                for(ijz=0;ijz<dimZ;ijz++) {
                    c=_cubes[i];
                    i++;
                    c.px=ijx; c.py=ijy; c.pz=ijz;
                    mcPoint[] cpt=c.points;
                    cpt[0]=getPoint(ijx,ijy,ijz);
                    cpt[1]=getPoint(ijx+1,ijy,ijz);
                    cpt[2]=getPoint(ijx+1,ijy+1,ijz);
                    cpt[3]=getPoint(ijx,ijy+1,ijz);
                    cpt[4]=getPoint(ijx,ijy,ijz+1);
                    cpt[5]=getPoint(ijx+1,ijy,ijz+1);
                    cpt[6]=getPoint(ijx+1,ijy+1,ijz+1);
                    cpt[7]=getPoint(ijx,ijy+1,ijz+1);
                    mcEdge[] e=c.edges;
                    e[5]=_edges[ep++];e[5].axisI=1;
                    e[6]=_edges[ep++];e[6].axisI=0;
                    e[10]=_edges[ep++];e[10].axisI=2;
                    tc=getCube(ijx+1,ijy,ijz);
                    if(tc!=null) {tc.edges[11]=e[10];tc.edges[7]=e[5];}

                    tc=getCube(ijx,ijy+1,ijz);
                    if(tc!=null) {tc.edges[4]=c.edges[6];tc.edges[9]=c.edges[10];}

                    tc=getCube(ijx,ijy+1,ijz+1);
                    if(tc!=null) {tc.edges[0]=c.edges[6];}

                    tc=getCube(ijx+1,ijy,ijz+1);
                    if(tc!=null) {tc.edges[3]=c.edges[5];}

                    tc=getCube(ijx+1,ijy+1,ijz);
                    if(tc!=null) {tc.edges[8]=c.edges[10];}

                    tc=getCube(ijx,ijy,ijz+1);
                    if(tc!=null) {tc.edges[1]=c.edges[5];tc.edges[2]=c.edges[6];}

                    if(e[0]==null) {
                        e[0]=_edges[ep++];e[0].axisI=0;
                    }
                    if(e[1]==null) {
                        e[1]=_edges[ep++];e[1].axisI=1;
                    }
                    if(e[2]==null) {
                        e[2]=_edges[ep++];e[2].axisI=0;
                    } else { topo++; }
                    if(e[3]==null) {
                        e[3]=_edges[ep++];e[3].axisI=1;
                    }
                    if(e[4]==null) {
                        e[4]=_edges[ep++];e[4].axisI=0;
                    }
                    if(e[7]==null) {
                        e[7]=_edges[ep++];e[7].axisI=1;
                    }
                    if(e[8]==null) {
                        e[8]=_edges[ep++];e[8].axisI=2;
                    }
                    if(e[9]==null) {
                        e[9]=_edges[ep++];e[9].axisI=2;
                    }
                    if(e[11]==null) {
                        e[11]=_edges[ep++];e[11].axisI=2;
                    }

                }
            }
        }
    }
Example #5
0
 /*Return the interpolated position of point on an Axis*/
 private Vector3 mPos(mcPoint a,mcPoint b,int axisI)
 {
     float mu = (isoLevel - a.i()) / (b.i() - a.i());
     Vector3 tmp=tada[tadac++];
     tmp[0]=a[0];tmp[1]=a[1];tmp[2]=a[2];
     tmp[axisI]=a[axisI]+(mu*(b[axisI]-a[axisI]));
     return tmp;
 }
Example #6
0
 public mcCube()
 {
     cntr = 0;
     edges = new mcEdge[12];
     for (int i = 0; i < 12; i++)
     {
         edges[i] = null;
     }
     points = new mcPoint[8];
 }