WriteColourBlock3() public static method

public static WriteColourBlock3 ( Vec3 start, Vec3 end, byte indices, byte block ) : void
start Vec3
end Vec3
indices byte
block byte
return void
Beispiel #1
0
 protected override unsafe void Compress3(byte *block)
 {
     //
     // build the table of lookups
     //
     SingleColourLookup[][] lookups =
     {
         SingleColourLookups.Lookup_5_3,
         SingleColourLookups.Lookup_6_3,
         SingleColourLookups.Lookup_5_3
     };
     //
     // find the best end-points and index
     //
     computeEndPoints(lookups);
     //
     // build the block if we win
     //
     if (error < bestError)
     {
         //
         // remap the indices
         //
         byte[] indices = new byte[16];
         //
         // The c++ passed a pointer to index and that pointer was used as an array.  If the RemapIndices method
         // throws an IndexOutOfRangeException, then it was definitely a bug in the c++.
         //
         colours.RemapIndices(new byte[] { index }, indices);
         //
         // save the block
         //
         ColourBlock.WriteColourBlock3(start, end, indices, block);
         //
         // save the error
         //
         bestError = error;
     }
 }
Beispiel #2
0
        protected override unsafe void Compress3(byte *block)
        {
            //
            // cache some values
            //
            int count = colours.Count;

            Vec3[] values = colours.Points;
            //
            // create a codebook
            //
            Vec3[] codes = new Vec3[3];

            codes[0] = start;
            codes[1] = end;
            codes[2] = 0.5f * start + 0.5f * end;
            //
            // match each point to the closest code
            //
            byte[] closest = new byte[16];

            float error = 0.0f;

            for (int i = 0; i < count; ++i)
            {
                //
                // find the closest code
                //
                float dist = Single.MaxValue;

                int idx = 0;

                for (int j = 0; j < 3; ++j)
                {
                    float d = Vec3.LengthSquared(metric * (values[i] - codes[j]));

                    if (d < dist)
                    {
                        dist = d;

                        idx = j;
                    }
                }
                //
                // save the index
                //
                closest[i] = (byte)idx;
                //
                // accumulate the error
                //
                error += dist;
            }
            //
            // save this scheme if it wins
            //
            if (error < bestError)
            {
                //
                // remap the indices
                //
                byte[] indices = new byte[16];

                colours.RemapIndices(closest, indices);
                //
                // save the block
                //
                ColourBlock.WriteColourBlock3(start, end, indices, block);
                //
                // save the error
                //
                bestError = error;
            }
        }