public void OutputVoxels(Vector3 offset, OnOutputVoxel output_function)
    {
        if (ISO == null)
        {
            return;
        }
        if (output_function == null)
        {
            return;
        }
        foreach (KeyValuePair <int, VCVoxel> kvp in ISO.m_Voxels)
        {
            Vector3 lpos = new Vector3(kvp.Key & 0x3ff, kvp.Key >> 20, (kvp.Key >> 10) & 0x3ff);
            Vector3 wpos = OriginTransform.position
                           + lpos.x * OriginTransform.right
                           + lpos.y * OriginTransform.up
                           + lpos.z * OriginTransform.forward;
            wpos += offset;

            INTVECTOR3 wpos_floor = new INTVECTOR3(Mathf.FloorToInt(wpos.x), Mathf.FloorToInt(wpos.y), Mathf.FloorToInt(wpos.z));
            INTVECTOR3 wpos_ceil  = new INTVECTOR3(Mathf.CeilToInt(wpos.x), Mathf.CeilToInt(wpos.y), Mathf.CeilToInt(wpos.z));

            if (wpos_floor == wpos_ceil)
            {
                output_function(wpos_floor.x, wpos_floor.y, wpos_floor.z, kvp.Value);
            }
            else
            {
                for (int x = wpos_floor.x; x <= wpos_ceil.x; ++x)
                {
                    for (int y = wpos_floor.y; y <= wpos_ceil.y; ++y)
                    {
                        for (int z = wpos_floor.z; z <= wpos_ceil.z; ++z)
                        {
                            float deltax = 1 - Mathf.Abs(wpos.x - x);
                            float deltay = 1 - Mathf.Abs(wpos.y - y);
                            float deltaz = 1 - Mathf.Abs(wpos.z - z);
                            float u      = deltax * deltay * deltaz;
                            if (u < 0.5f)
                            {
                                u = u / (0.5f + u);
                            }
                            else
                            {
                                u = 0.5f / (1.5f - u);
                            }
                            VCVoxel voxel = kvp.Value;
                            voxel.Volume = (byte)Mathf.CeilToInt(voxel.Volume * u);
                            if (voxel.Volume > 1)
                            {
                                output_function(x, y, z, voxel);
                            }
                        }
                    }
                }
            }
        }
    }
示例#2
0
    public void OutputVoxels(Vector3 offset, OnOutputVoxel output_function)
    {
        if (ISO == null)
        {
            return;
        }

        if (output_function == null)
        {
            return;
        }

        output_function(ISO.m_Voxels, OriginTransform.position);
    }