コード例 #1
0
    void writeExtendedBlock(int x, int y, int z, int primitiveType, int rotation, int extendDir, int length, byte materialType)
    {
        B45Block b0, b1;

        B45Block.MakeExtendableBlock(primitiveType, rotation, extendDir, length, (int)materialType, out b0, out b1);

        chunkData[B45Block.Block45Size * B45ChunkData.OneIndex(x, y, z)]     = b0.blockType;
        chunkData[B45Block.Block45Size * B45ChunkData.OneIndex(x, y, z) + 1] = b0.materialType;

        int idx = B45Block.Block45Size * B45ChunkData.OneIndex(
            x + Block45Kernel._2BitToExDir[extendDir * 3],
            y + Block45Kernel._2BitToExDir[extendDir * 3 + 1],
            z + Block45Kernel._2BitToExDir[extendDir * 3 + 2]);

        chunkData[idx]     = b1.blockType;
        chunkData[1 + idx] = b1.materialType;

        for (int i = 2; i < length; i++)
        {
            idx = B45Block.Block45Size * B45ChunkData.OneIndex(
                x + Block45Kernel._2BitToExDir[extendDir * 3] * i,
                y + Block45Kernel._2BitToExDir[extendDir * 3 + 1] * i,
                z + Block45Kernel._2BitToExDir[extendDir * 3 + 2] * i);

            chunkData[idx]     = (byte)extendDir;
            chunkData[1 + idx] = (byte)(length - 2);
        }
    }
コード例 #2
0
    void test1()
    {
        chunkData[B45Block.Block45Size * B45ChunkData.OneIndex(0, 0, 0)]     = B45Block.MakeBlockType(1, 0);
        chunkData[B45Block.Block45Size * B45ChunkData.OneIndex(0, 0, 0) + 1] = 0;

        chunkData[B45Block.Block45Size * B45ChunkData.OneIndex(0, 0, 1)]     = B45Block.MakeBlockType(2, 0);
        chunkData[B45Block.Block45Size * B45ChunkData.OneIndex(0, 0, 1) + 1] = 1;
        chunkData[B45Block.Block45Size * B45ChunkData.OneIndex(0, 0, 2)]     = B45Block.MakeBlockType(4, 0);
        chunkData[B45Block.Block45Size * B45ChunkData.OneIndex(0, 0, 2) + 1] = 2;
        chunkData[B45Block.Block45Size * B45ChunkData.OneIndex(0, 0, 3)]     = B45Block.MakeBlockType(3, 0);
        chunkData[B45Block.Block45Size * B45ChunkData.OneIndex(0, 0, 3) + 1] = 3;
    }
コード例 #3
0
    void test2()
    {
        UnityEngine.Random.seed = 1223;
        for (int z = 0; z < Block45Constants._numVoxelsPerAxis; z++)
        {
//			for(int y =0; y < Block45Constants._numVoxelsPerAxis;y++)
            {
                for (int x = 0; x < Block45Constants._numVoxelsPerAxis; x++)
                {
                    int rot = (Mathf.RoundToInt(UnityEngine.Random.value * 256)) % 4;
                    chunkData[B45Block.Block45Size * B45ChunkData.OneIndex(x, 0, z)] =
                        B45Block.MakeBlockType(((x + z * Block45Constants._numVoxelsPerAxis + 0
                                                 * Block45Constants._numVoxelsPerAxis * Block45Constants._numVoxelsPerAxis) % 6) + 1, rot);

                    rot = (Mathf.RoundToInt(UnityEngine.Random.value * 256)) % 4;
                    chunkData[B45Block.Block45Size * B45ChunkData.OneIndex(x, 1, z)] =
                        B45Block.MakeBlockType(((x + z * Block45Constants._numVoxelsPerAxis + 0
                                                 * Block45Constants._numVoxelsPerAxis * Block45Constants._numVoxelsPerAxis) % 6) + 1, rot);
                }
            }
        }
    }
コード例 #4
0
    void test3()
    {
        UnityEngine.Random.seed = 1223;
        for (int z = 0; z < Block45Constants._numVoxelsPerAxis; z++)
        {
//			for(int y =0; y < Block45Constants._numVoxelsPerAxis;y++)
            {
                for (int x = 0; x < Block45Constants._numVoxelsPerAxis; x++)
                {
                    int rot = (Mathf.RoundToInt(UnityEngine.Random.value * 256)) % 4;
                    chunkData[B45Block.Block45Size * B45ChunkData.OneIndex(x, 0, z)] =
                        B45Block.MakeBlockType(((x + z * Block45Constants._numVoxelsPerAxis + 0
                                                 * Block45Constants._numVoxelsPerAxis * Block45Constants._numVoxelsPerAxis) % 6) + 1, rot);

                    chunkData[B45Block.Block45Size * B45ChunkData.OneIndex(x, 0, z) + 1] = (byte)(x % 3);

                    rot = (Mathf.RoundToInt(UnityEngine.Random.value * 256)) % 4;
                    chunkData[B45Block.Block45Size * B45ChunkData.OneIndex(x, 1, z)] =
                        B45Block.MakeBlockType(((x + z * Block45Constants._numVoxelsPerAxis + 0
                                                 * Block45Constants._numVoxelsPerAxis * Block45Constants._numVoxelsPerAxis) % 6) + 1, rot);
                    chunkData[B45Block.Block45Size * B45ChunkData.OneIndex(x, 1, z) + 1] = (byte)(z % 3);
                }
            }
        }
//		chunkData[B45Block.Block45Size*B45ChunkData.OneIndex(0,0,0)] = B45Block.MakeBlockType(1,0);
//		chunkData[B45Block.Block45Size*B45ChunkData.OneIndex(0,0,0)+1] = 0;
//
//		chunkData[B45Block.Block45Size*B45ChunkData.OneIndex(0,0,1)] = B45Block.MakeBlockType(1,0);
//		chunkData[B45Block.Block45Size*B45ChunkData.OneIndex(0,0,1)+1] = 1;
//		chunkData[B45Block.Block45Size*B45ChunkData.OneIndex(0,0,2)] = B45Block.MakeBlockType(1,0);
//		chunkData[B45Block.Block45Size*B45ChunkData.OneIndex(0,0,2)+1] = 2;
//		chunkData[B45Block.Block45Size*B45ChunkData.OneIndex(0,0,3)] = B45Block.MakeBlockType(1,0);
//		chunkData[B45Block.Block45Size*B45ChunkData.OneIndex(0,0,3)+1] = 0;
//
//		chunkData[B45Block.Block45Size*B45ChunkData.OneIndex(0,0,3)] = B45Block.MakeBlockType(1,0);
//		chunkData[B45Block.Block45Size*B45ChunkData.OneIndex(0,0,3)+1] = 3;
    }
コード例 #5
0
    void ComputeOne(byte[] LODChunkData, List <byte[]> srcChunkData, int cid, IntVector3 destChunkOfs)
    {
        byte[] eightTypes = new byte[8];
        byte[] eightMat   = new byte[8];

        byte[] eightOccu = new byte[8];

        for (int z = 0; z < Block45Constants._numVoxelsPerAxis; z += 2)
        {
            for (int y = 0; y < Block45Constants._numVoxelsPerAxis; y += 2)
            {
                for (int x = 0; x < Block45Constants._numVoxelsPerAxis; x += 2)
                {
                    eightTypes[0] = (byte)(srcChunkData[cid][B45Block.Block45Size * B45ChunkData.OneIndex(x, y, z)]);
                    eightTypes[1] = (byte)(srcChunkData[cid][B45Block.Block45Size * B45ChunkData.OneIndex(x, y, z + 1)]);
                    eightTypes[2] = (byte)(srcChunkData[cid][B45Block.Block45Size * B45ChunkData.OneIndex(x + 1, y, z + 1)]);
                    eightTypes[3] = (byte)(srcChunkData[cid][B45Block.Block45Size * B45ChunkData.OneIndex(x + 1, y, z)]);

                    eightTypes[4] = (byte)(srcChunkData[cid][B45Block.Block45Size * B45ChunkData.OneIndex(x, y + 1, z)]);
                    eightTypes[5] = (byte)(srcChunkData[cid][B45Block.Block45Size * B45ChunkData.OneIndex(x, y + 1, z + 1)]);
                    eightTypes[6] = (byte)(srcChunkData[cid][B45Block.Block45Size * B45ChunkData.OneIndex(x + 1, y + 1, z + 1)]);
                    eightTypes[7] = (byte)(srcChunkData[cid][B45Block.Block45Size * B45ChunkData.OneIndex(x + 1, y + 1, z)]);

                    eightMat[0] = (byte)(srcChunkData[cid][B45Block.Block45Size * B45ChunkData.OneIndex(x, y, z) + 1]);
                    eightMat[1] = (byte)(srcChunkData[cid][B45Block.Block45Size * B45ChunkData.OneIndex(x, y, z + 1) + 1]);
                    eightMat[2] = (byte)(srcChunkData[cid][B45Block.Block45Size * B45ChunkData.OneIndex(x + 1, y, z + 1) + 1]);
                    eightMat[3] = (byte)(srcChunkData[cid][B45Block.Block45Size * B45ChunkData.OneIndex(x + 1, y, z) + 1]);

                    eightMat[4] = (byte)(srcChunkData[cid][B45Block.Block45Size * B45ChunkData.OneIndex(x, y + 1, z) + 1]);
                    eightMat[5] = (byte)(srcChunkData[cid][B45Block.Block45Size * B45ChunkData.OneIndex(x, y + 1, z + 1) + 1]);
                    eightMat[6] = (byte)(srcChunkData[cid][B45Block.Block45Size * B45ChunkData.OneIndex(x + 1, y + 1, z + 1) + 1]);
                    eightMat[7] = (byte)(srcChunkData[cid][B45Block.Block45Size * B45ChunkData.OneIndex(x + 1, y + 1, z) + 1]);

                    eightOccu[0] = TypeToOccupancy[eightTypes[0] >> 2];
                    eightOccu[1] = TypeToOccupancy[eightTypes[1] >> 2];
                    eightOccu[2] = TypeToOccupancy[eightTypes[2] >> 2];
                    eightOccu[3] = TypeToOccupancy[eightTypes[3] >> 2];

                    eightOccu[4] = TypeToOccupancy[eightTypes[4] >> 2];
                    eightOccu[5] = TypeToOccupancy[eightTypes[5] >> 2];
                    eightOccu[6] = TypeToOccupancy[eightTypes[6] >> 2];
                    eightOccu[7] = TypeToOccupancy[eightTypes[7] >> 2];

                    int sum = eightOccu[0] + eightOccu[1] + eightOccu[2] + eightOccu[3] +
                              eightOccu[4] + eightOccu[5] + eightOccu[6] + eightOccu[7];

                    ///if( sum > 0){
                    ///	int sdl= 0;
                    ///}
                    List <int> indices = GetSimilarIndices(sum, 3);
                    int        smallestError = 255;
                    int        bestMatchI = -1, bestMatchR = -1;
                    for (int i = 0; i < indices.Count; i++)
                    {
                        int errorSum = CalculateError(eightOccu, indices[i], 0);
                        if (smallestError > errorSum)
                        {
                            smallestError = errorSum;
                            bestMatchI    = indices[i];
                            bestMatchR    = 3;
                        }
                        errorSum = CalculateError(eightOccu, indices[i], 1);
                        if (smallestError > errorSum)
                        {
                            smallestError = errorSum;
                            bestMatchI    = indices[i];
                            bestMatchR    = 2;
                        }
                        errorSum = CalculateError(eightOccu, indices[i], 2);
                        if (smallestError > errorSum)
                        {
                            smallestError = errorSum;
                            bestMatchI    = indices[i];
                            bestMatchR    = 1;
                        }
                        errorSum = CalculateError(eightOccu, indices[i], 3);
                        if (smallestError > errorSum)
                        {
                            smallestError = errorSum;
                            bestMatchI    = indices[i];
                            bestMatchR    = 0;
                        }
                    }
                    B45Block blk;
                    blk.blockType    = B45Block.MakeBlockType(bestMatchI, bestMatchR);
                    blk.materialType = 0;

                    // determine the material type for this lod block.
                    byte largestOccu = 0;
                    for (int i = 0; i < 8; i++)
                    {
                        if (eightOccu[i] > largestOccu)
                        {
                            largestOccu      = eightOccu[i];
                            blk.materialType = eightMat[i];
                        }
                    }
                    int tmpIdx = B45Block.Block45Size * B45ChunkData.OneIndex(
                        destChunkOfs.x * Block45Constants._numVoxelsPerAxis / 2 + x / 2,
                        destChunkOfs.y * Block45Constants._numVoxelsPerAxis / 2 + y / 2,
                        destChunkOfs.z * Block45Constants._numVoxelsPerAxis / 2 + z / 2
                        );
                    LODChunkData[tmpIdx]     = blk.blockType;
                    LODChunkData[tmpIdx + 1] = blk.materialType;
                }
            }
        }
    }
コード例 #6
0
    void test4()
    {
        IntVector3 bPos = new IntVector3(0, 0, 0);
        int        rot  = 0;

        chunkData[B45Block.Block45Size * B45ChunkData.OneIndex(bPos.x + 0, bPos.y + 0, bPos.z + 0)]     = B45Block.MakeBlockType(1, 0);
        chunkData[B45Block.Block45Size * B45ChunkData.OneIndex(bPos.x + 0, bPos.y + 0, bPos.z + 0) + 1] = 0;
        chunkData[B45Block.Block45Size * B45ChunkData.OneIndex(bPos.x + 0, bPos.y + 0, bPos.z + 1)]     = B45Block.MakeBlockType(1, 0);
        chunkData[B45Block.Block45Size * B45ChunkData.OneIndex(bPos.x + 0, bPos.y + 0, bPos.z + 1) + 1] = 0;

        chunkData[B45Block.Block45Size * B45ChunkData.OneIndex(bPos.x + 1, bPos.y + 0, bPos.z + 1)]     = B45Block.MakeBlockType(1, 0);
        chunkData[B45Block.Block45Size * B45ChunkData.OneIndex(bPos.x + 1, bPos.y + 0, bPos.z + 1) + 1] = 0;
        chunkData[B45Block.Block45Size * B45ChunkData.OneIndex(bPos.x + 1, bPos.y + 0, bPos.z + 0)]     = B45Block.MakeBlockType(1, 0);
        chunkData[B45Block.Block45Size * B45ChunkData.OneIndex(bPos.x + 1, bPos.y + 0, bPos.z + 0) + 1] = 0;

        chunkData[B45Block.Block45Size * B45ChunkData.OneIndex(bPos.x + 0, bPos.y + 1, bPos.z + 0)]     = B45Block.MakeBlockType(1, 0);
        chunkData[B45Block.Block45Size * B45ChunkData.OneIndex(bPos.x + 0, bPos.y + 1, bPos.z + 0) + 1] = 0;
        chunkData[B45Block.Block45Size * B45ChunkData.OneIndex(bPos.x + 0, bPos.y + 1, bPos.z + 1)]     = B45Block.MakeBlockType(1, 0);
        chunkData[B45Block.Block45Size * B45ChunkData.OneIndex(bPos.x + 0, bPos.y + 1, bPos.z + 1) + 1] = 0;

        chunkData[B45Block.Block45Size * B45ChunkData.OneIndex(bPos.x + 1, bPos.y + 1, bPos.z + 1)]     = B45Block.MakeBlockType(1, 0);
        chunkData[B45Block.Block45Size * B45ChunkData.OneIndex(bPos.x + 1, bPos.y + 1, bPos.z + 1) + 1] = 0;
        chunkData[B45Block.Block45Size * B45ChunkData.OneIndex(bPos.x + 1, bPos.y + 1, bPos.z + 0)]     = B45Block.MakeBlockType(1, 0);
        chunkData[B45Block.Block45Size * B45ChunkData.OneIndex(bPos.x + 1, bPos.y + 1, bPos.z + 0) + 1] = 0;

        ////
        bPos = new IntVector3(2, 0, 0);
        rot  = 3;

        chunkData[B45Block.Block45Size * B45ChunkData.OneIndex(bPos.x + 0, bPos.y + 0, bPos.z + 0)]     = B45Block.MakeBlockType(1, rot);
        chunkData[B45Block.Block45Size * B45ChunkData.OneIndex(bPos.x + 0, bPos.y + 0, bPos.z + 0) + 1] = 1;
        chunkData[B45Block.Block45Size * B45ChunkData.OneIndex(bPos.x + 0, bPos.y + 0, bPos.z + 1)]     = B45Block.MakeBlockType(2, rot);
        chunkData[B45Block.Block45Size * B45ChunkData.OneIndex(bPos.x + 0, bPos.y + 0, bPos.z + 1) + 1] = 1;

        chunkData[B45Block.Block45Size * B45ChunkData.OneIndex(bPos.x + 1, bPos.y + 0, bPos.z + 1)]     = B45Block.MakeBlockType(2, rot);
        chunkData[B45Block.Block45Size * B45ChunkData.OneIndex(bPos.x + 1, bPos.y + 0, bPos.z + 1) + 1] = 1;
        chunkData[B45Block.Block45Size * B45ChunkData.OneIndex(bPos.x + 1, bPos.y + 0, bPos.z + 0)]     = B45Block.MakeBlockType(1, rot);
        chunkData[B45Block.Block45Size * B45ChunkData.OneIndex(bPos.x + 1, bPos.y + 0, bPos.z + 0) + 1] = 1;

        chunkData[B45Block.Block45Size * B45ChunkData.OneIndex(bPos.x + 0, bPos.y + 1, bPos.z + 0)]     = B45Block.MakeBlockType(2, rot);
        chunkData[B45Block.Block45Size * B45ChunkData.OneIndex(bPos.x + 0, bPos.y + 1, bPos.z + 0) + 1] = 1;
        chunkData[B45Block.Block45Size * B45ChunkData.OneIndex(bPos.x + 0, bPos.y + 1, bPos.z + 1)]     = B45Block.MakeBlockType(0, rot);
        chunkData[B45Block.Block45Size * B45ChunkData.OneIndex(bPos.x + 0, bPos.y + 1, bPos.z + 1) + 1] = 1;

        chunkData[B45Block.Block45Size * B45ChunkData.OneIndex(bPos.x + 1, bPos.y + 1, bPos.z + 1)]     = B45Block.MakeBlockType(0, rot);
        chunkData[B45Block.Block45Size * B45ChunkData.OneIndex(bPos.x + 1, bPos.y + 1, bPos.z + 1) + 1] = 1;
        chunkData[B45Block.Block45Size * B45ChunkData.OneIndex(bPos.x + 1, bPos.y + 1, bPos.z + 0)]     = B45Block.MakeBlockType(2, rot);
        chunkData[B45Block.Block45Size * B45ChunkData.OneIndex(bPos.x + 1, bPos.y + 1, bPos.z + 0) + 1] = 1;

        /////////////////
        bPos = new IntVector3(4, 0, 0);
        rot  = 0;

        chunkData[B45Block.Block45Size * B45ChunkData.OneIndex(bPos.x + 0, bPos.y + 0, bPos.z + 0)]     = B45Block.MakeBlockType(1, rot);
        chunkData[B45Block.Block45Size * B45ChunkData.OneIndex(bPos.x + 0, bPos.y + 0, bPos.z + 0) + 1] = 1;
        chunkData[B45Block.Block45Size * B45ChunkData.OneIndex(bPos.x + 0, bPos.y + 0, bPos.z + 1)]     = B45Block.MakeBlockType(1, rot);
        chunkData[B45Block.Block45Size * B45ChunkData.OneIndex(bPos.x + 0, bPos.y + 0, bPos.z + 1) + 1] = 1;

        chunkData[B45Block.Block45Size * B45ChunkData.OneIndex(bPos.x + 1, bPos.y + 0, bPos.z + 1)]     = B45Block.MakeBlockType(2, rot);
        chunkData[B45Block.Block45Size * B45ChunkData.OneIndex(bPos.x + 1, bPos.y + 0, bPos.z + 1) + 1] = 1;
        chunkData[B45Block.Block45Size * B45ChunkData.OneIndex(bPos.x + 1, bPos.y + 0, bPos.z + 0)]     = B45Block.MakeBlockType(2, rot);
        chunkData[B45Block.Block45Size * B45ChunkData.OneIndex(bPos.x + 1, bPos.y + 0, bPos.z + 0) + 1] = 1;

        chunkData[B45Block.Block45Size * B45ChunkData.OneIndex(bPos.x + 0, bPos.y + 1, bPos.z + 0)]     = B45Block.MakeBlockType(2, rot);
        chunkData[B45Block.Block45Size * B45ChunkData.OneIndex(bPos.x + 0, bPos.y + 1, bPos.z + 0) + 1] = 1;
        chunkData[B45Block.Block45Size * B45ChunkData.OneIndex(bPos.x + 0, bPos.y + 1, bPos.z + 1)]     = B45Block.MakeBlockType(2, rot);
        chunkData[B45Block.Block45Size * B45ChunkData.OneIndex(bPos.x + 0, bPos.y + 1, bPos.z + 1) + 1] = 1;

        chunkData[B45Block.Block45Size * B45ChunkData.OneIndex(bPos.x + 1, bPos.y + 1, bPos.z + 1)]     = B45Block.MakeBlockType(0, rot);
        chunkData[B45Block.Block45Size * B45ChunkData.OneIndex(bPos.x + 1, bPos.y + 1, bPos.z + 1) + 1] = 1;
        chunkData[B45Block.Block45Size * B45ChunkData.OneIndex(bPos.x + 1, bPos.y + 1, bPos.z + 0)]     = B45Block.MakeBlockType(0, rot);
        chunkData[B45Block.Block45Size * B45ChunkData.OneIndex(bPos.x + 1, bPos.y + 1, bPos.z + 0) + 1] = 1;
    }