public static FinalMeshVerts_t New()
                {
                    var verts = new FinalMeshVerts_t {
                        positions       = AllocatePersistentNoInit <Vector3>(ushort.MaxValue),
                        normals         = AllocatePersistentNoInit <Vector3>(ushort.MaxValue),
                        colors          = AllocatePersistentNoInit <Color32>(ushort.MaxValue),
                        textureBlending = AllocatePersistentNoInit <Vector4>(ushort.MaxValue),
                        indices         = AllocatePersistentNoInit <int>(ushort.MaxValue),
                        counts          = AllocatePersistentNoInit <int>(3 * MAX_CHUNK_LAYERS),
                        submeshes       = AllocatePersistentNoInit <int>(MAX_CHUNK_SUBMESHES * MAX_CHUNK_LAYERS),
                        submeshTextures = AllocatePersistentNoInit <TexBlend_t>(MAX_CHUNK_SUBMESHES * MAX_CHUNK_LAYERS),
                    };

                    return(verts);
                }
Exemplo n.º 2
0
    public static unsafe PinnedChunkData_t DecompressChunkData(byte *ptr, int len, PinnedChunkData_t chunk, FinalMeshVerts_t verts)
    {
        var src = ptr;

        {
            var decorationCount = *((int *)src);
            src += 4;

            for (int i = 0; i < decorationCount; ++i)
            {
                var d = default(Decoration_t);
                d.pos.x = *((float *)src);
                src    += 4;
                d.pos.y = *((float *)src);
                src    += 4;
                d.pos.z = *((float *)src);
                src    += 4;
                d.type  = (EDecorationType)(*((int *)src));
                src    += 4;

                chunk.AddDecoration(d);
            }
        }

        if ((chunk.flags & EChunkFlags.SOLID) == 0)
        {
            // empty chunk
            chunk.voxeldata.Broadcast(EVoxelBlockType.Air);

            for (int i = 0; i < verts.counts.Length; ++i)
            {
                verts.counts[i] = 0;
            }

            for (int i = 0; i < verts.submeshes.Length; ++i)
            {
                verts.submeshes[i] = 0;
            }

            return(chunk);
        }

        {
            var voxeldata = chunk.voxeldata;
            var count     = chunk.voxeldata.length;
            for (int i = 0; i < count; ++i)
            {
                voxeldata[i] = new Voxel_t(src[i]);
            }
        }

        src += chunk.voxeldata.length;

        for (int i = 0; i < verts.counts.Length; ++i)
        {
            verts.counts[i] = *((int *)src);
            src            += 4;
        }
        for (int i = 0; i < verts.submeshes.Length; ++i)
        {
            verts.submeshes[i] = *((int *)src);
            src += 4;
        }

        int totalVerts = *((int *)src);

        src += 4;
        int totalIndices = *((int *)src);

        src += 4;

        for (int i = 0; i < totalVerts; ++i)
        {
            Vector3 v3;
            v3.x = *((float *)src);
            src += 4;
            v3.y = *((float *)src);
            src += 4;
            v3.z = *((float *)src);
            src += 4;
            verts.positions[i] = v3;
        }
        for (int i = 0; i < totalVerts; ++i)
        {
            Vector3 v3;
            v3.x             = *((float *)src);
            src             += 4;
            v3.y             = *((float *)src);
            src             += 4;
            v3.z             = *((float *)src);
            src             += 4;
            verts.normals[i] = v3;
        }
        for (int i = 0; i < totalVerts; ++i)
        {
            uint c = *((uint *)src);
            src            += 4;
            verts.colors[i] = Utils.GetColor32FromUIntRGBA(c);
        }
        for (int i = 0; i < totalIndices; ++i)
        {
            verts.indices[i] = *((int *)src);
            src += 4;
        }

        return(chunk);
    }
 public unsafe static GenerateFinalVertices_t New(SmoothingVertsIn_t inVerts, FinalMeshVerts_t outVerts, ChunkTimingData_t *timing)
 {
     return(new GenerateFinalVertices_t {
         _smoothVerts = inVerts,
         _finalVerts = outVerts,
         _timing = timing
     });
 }