Ejemplo n.º 1
0
            public static TextureEntryFace FromLLSD(LLSD llsd, TextureEntryFace defaultFace, out int faceNumber)
            {
                LLSDMap map = (LLSDMap)llsd;

                TextureEntryFace face = new TextureEntryFace(defaultFace);

                faceNumber = (map.ContainsKey("face_number")) ? map["face_number"].AsInteger() : -1;
                LLColor rgba = face.RGBA;

                rgba.FromLLSD(map["colors"]);
                face.RGBA       = rgba;
                face.RepeatU    = (float)map["scales"].AsReal();
                face.RepeatV    = (float)map["scalet"].AsReal();
                face.OffsetU    = (float)map["offsets"].AsReal();
                face.OffsetV    = (float)map["offsett"].AsReal();
                face.Rotation   = (float)map["imagerot"].AsReal();
                face.Bump       = (Bumpiness)map["bump"].AsInteger();
                face.Shiny      = (Shininess)map["shiny"].AsInteger();
                face.Fullbright = map["fullbright"].AsBoolean();
                face.MediaFlags = map["media_flags"].AsBoolean();
                face.TexMapType = (MappingType)map["mapping"].AsInteger();
                face.Glow       = (float)map["glow"].AsReal();
                face.TextureID  = map["imageid"].AsUUID();

                return(face);
            }
Ejemplo n.º 2
0
            /// <summary>
            ///
            /// </summary>
            /// <returns></returns>
            public byte[] GetBytes()
            {
                byte[] data = new byte[16];

                // Alpha channel in color is intensity
                LLColor tmpColor = Color;

                tmpColor.A = Intensity;
                tmpColor.GetBytes().CopyTo(data, 0);
                Helpers.FloatToBytes(Radius).CopyTo(data, 4);
                Helpers.FloatToBytes(Cutoff).CopyTo(data, 8);
                Helpers.FloatToBytes(Falloff).CopyTo(data, 12);

                return(data);
            }
Ejemplo n.º 3
0
            public static LightData FromLLSD(LLSD llsd)
            {
                LightData light = new LightData();

                if (llsd.Type == LLSDType.Map)
                {
                    LLSDMap map = (LLSDMap)llsd;

                    light.Color     = LLColor.FromLLSD(map["color"]);
                    light.Intensity = (float)map["intensity"].AsReal();
                    light.Radius    = (float)map["radius"].AsReal();
                    light.Cutoff    = (float)map["cutoff"].AsReal();
                    light.Falloff   = (float)map["falloff"].AsReal();
                }

                return(light);
            }
Ejemplo n.º 4
0
            /// <summary>
            ///
            /// </summary>
            /// <param name="data"></param>
            /// <param name="pos"></param>
            public LightData(byte[] data, int pos)
            {
                if (data.Length - pos >= 16)
                {
                    Color   = new LLColor(data, pos, false);
                    Radius  = Helpers.BytesToFloat(data, pos + 4);
                    Cutoff  = Helpers.BytesToFloat(data, pos + 8);
                    Falloff = Helpers.BytesToFloat(data, pos + 12);

                    // Alpha in color is actually intensity
                    Intensity = Color.A;
                    Color.A   = 1f;
                }
                else
                {
                    Color     = LLColor.Black;
                    Radius    = 0f;
                    Cutoff    = 0f;
                    Falloff   = 0f;
                    Intensity = 0f;
                }
            }
Ejemplo n.º 5
0
            private void FromBytes(byte[] data, int pos, int length)
            {
                if (length <= 0)
                {
                    // No TextureEntry to process
                    DefaultTexture = null;
                    return;
                }
                else
                {
                    DefaultTexture = new TextureEntryFace(null);
                }

                uint bitfieldSize = 0;
                uint faceBits     = 0;
                int  i            = pos;

                #region Texture
                DefaultTexture.TextureID = new LLUUID(data, i);
                i += 16;

                while (ReadFaceBitfield(data, ref i, ref faceBits, ref bitfieldSize))
                {
                    LLUUID tmpUUID = new LLUUID(data, i);
                    i += 16;

                    for (uint face = 0, bit = 1; face < bitfieldSize; face++, bit <<= 1)
                    {
                        if ((faceBits & bit) != 0)
                        {
                            CreateFace(face).TextureID = tmpUUID;
                        }
                    }
                }
                #endregion Texture

                #region Color
                DefaultTexture.RGBA = new LLColor(data[i], data[i + 1], data[i + 2], data[i + 3]);
                i += 4;

                while (ReadFaceBitfield(data, ref i, ref faceBits, ref bitfieldSize))
                {
                    LLColor tmpColor = new LLColor(data[i], data[i + 1], data[i + 2], data[i + 3]);
                    i += 4;

                    for (uint face = 0, bit = 1; face < bitfieldSize; face++, bit <<= 1)
                    {
                        if ((faceBits & bit) != 0)
                        {
                            CreateFace(face).RGBA = tmpColor;
                        }
                    }
                }
                #endregion Color

                #region RepeatU
                DefaultTexture.RepeatU = Helpers.BytesToFloat(data, i);
                i += 4;

                while (ReadFaceBitfield(data, ref i, ref faceBits, ref bitfieldSize))
                {
                    float tmpFloat = Helpers.BytesToFloat(data, i);
                    i += 4;

                    for (uint face = 0, bit = 1; face < bitfieldSize; face++, bit <<= 1)
                    {
                        if ((faceBits & bit) != 0)
                        {
                            CreateFace(face).RepeatU = tmpFloat;
                        }
                    }
                }
                #endregion RepeatU

                #region RepeatV
                DefaultTexture.RepeatV = Helpers.BytesToFloat(data, i);
                i += 4;

                while (ReadFaceBitfield(data, ref i, ref faceBits, ref bitfieldSize))
                {
                    float tmpFloat = Helpers.BytesToFloat(data, i);
                    i += 4;

                    for (uint face = 0, bit = 1; face < bitfieldSize; face++, bit <<= 1)
                    {
                        if ((faceBits & bit) != 0)
                        {
                            CreateFace(face).RepeatV = tmpFloat;
                        }
                    }
                }
                #endregion RepeatV

                #region OffsetU
                DefaultTexture.OffsetU = Helpers.TEOffsetFloat(data, i);
                i += 2;

                while (ReadFaceBitfield(data, ref i, ref faceBits, ref bitfieldSize))
                {
                    float tmpFloat = Helpers.TEOffsetFloat(data, i);
                    i += 2;

                    for (uint face = 0, bit = 1; face < bitfieldSize; face++, bit <<= 1)
                    {
                        if ((faceBits & bit) != 0)
                        {
                            CreateFace(face).OffsetU = tmpFloat;
                        }
                    }
                }
                #endregion OffsetU

                #region OffsetV
                DefaultTexture.OffsetV = Helpers.TEOffsetFloat(data, i);
                i += 2;

                while (ReadFaceBitfield(data, ref i, ref faceBits, ref bitfieldSize))
                {
                    float tmpFloat = Helpers.TEOffsetFloat(data, i);
                    i += 2;

                    for (uint face = 0, bit = 1; face < bitfieldSize; face++, bit <<= 1)
                    {
                        if ((faceBits & bit) != 0)
                        {
                            CreateFace(face).OffsetV = tmpFloat;
                        }
                    }
                }
                #endregion OffsetV

                #region Rotation
                DefaultTexture.Rotation = Helpers.TERotationFloat(data, i);
                i += 2;

                while (ReadFaceBitfield(data, ref i, ref faceBits, ref bitfieldSize))
                {
                    float tmpFloat = Helpers.TERotationFloat(data, i);
                    i += 2;

                    for (uint face = 0, bit = 1; face < bitfieldSize; face++, bit <<= 1)
                    {
                        if ((faceBits & bit) != 0)
                        {
                            CreateFace(face).Rotation = tmpFloat;
                        }
                    }
                }
                #endregion Rotation

                #region Material
                DefaultTexture.material = data[i];
                i++;

                while (ReadFaceBitfield(data, ref i, ref faceBits, ref bitfieldSize))
                {
                    byte tmpByte = data[i];
                    i++;

                    for (uint face = 0, bit = 1; face < bitfieldSize; face++, bit <<= 1)
                    {
                        if ((faceBits & bit) != 0)
                        {
                            CreateFace(face).material = tmpByte;
                        }
                    }
                }
                #endregion Material

                #region Media
                DefaultTexture.media = data[i];
                i++;

                while (i - pos < length && ReadFaceBitfield(data, ref i, ref faceBits, ref bitfieldSize))
                {
                    byte tmpByte = data[i];
                    i++;

                    for (uint face = 0, bit = 1; face < bitfieldSize; face++, bit <<= 1)
                    {
                        if ((faceBits & bit) != 0)
                        {
                            CreateFace(face).media = tmpByte;
                        }
                    }
                }
                #endregion Media

                #region Glow
                DefaultTexture.Glow = Helpers.TEGlowFloat(data, i);
                i++;

                while (ReadFaceBitfield(data, ref i, ref faceBits, ref bitfieldSize))
                {
                    float tmpFloat = Helpers.TEGlowFloat(data, i);
                    i++;

                    for (uint face = 0, bit = 1; face < bitfieldSize; face++, bit <<= 1)
                    {
                        if ((faceBits & bit) != 0)
                        {
                            CreateFace(face).Glow = tmpFloat;
                        }
                    }
                }
                #endregion Glow
            }
Ejemplo n.º 6
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="data"></param>
 public void PackColor(LLColor data)
 {
     byte[] bytes = data.GetBytes();
     PackBitArray(bytes, 32);
 }
Ejemplo n.º 7
0
            /// <summary>
            /// Decodes a byte[] array into a ParticleSystem Object
            /// </summary>
            /// <param name="data">ParticleSystem object</param>
            /// <param name="pos">Start position for BitPacker</param>
            public ParticleSystem(byte[] data, int pos)
            {
                // TODO: Not sure exactly how many bytes we need here, so partial
                // (truncated) data will cause an exception to be thrown
                if (data.Length > 0)
                {
                    BitPack pack = new BitPack(data, pos);

                    CRC            = pack.UnpackUBits(32);
                    PartFlags      = pack.UnpackUBits(32);
                    Pattern        = (SourcePattern)pack.UnpackByte();
                    MaxAge         = pack.UnpackFixed(false, 8, 8);
                    StartAge       = pack.UnpackFixed(false, 8, 8);
                    InnerAngle     = pack.UnpackFixed(false, 3, 5);
                    OuterAngle     = pack.UnpackFixed(false, 3, 5);
                    BurstRate      = pack.UnpackFixed(false, 8, 8);
                    BurstRadius    = pack.UnpackFixed(false, 8, 8);
                    BurstSpeedMin  = pack.UnpackFixed(false, 8, 8);
                    BurstSpeedMax  = pack.UnpackFixed(false, 8, 8);
                    BurstPartCount = pack.UnpackByte();
                    float x = pack.UnpackFixed(true, 8, 7);
                    float y = pack.UnpackFixed(true, 8, 7);
                    float z = pack.UnpackFixed(true, 8, 7);
                    AngularVelocity = new LLVector3(x, y, z);
                    x = pack.UnpackFixed(true, 8, 7);
                    y = pack.UnpackFixed(true, 8, 7);
                    z = pack.UnpackFixed(true, 8, 7);
                    PartAcceleration = new LLVector3(x, y, z);
                    Texture          = pack.UnpackUUID();
                    Target           = pack.UnpackUUID();

                    PartDataFlags = (ParticleDataFlags)pack.UnpackUBits(32);
                    PartMaxAge    = pack.UnpackFixed(false, 8, 8);
                    byte r = pack.UnpackByte();
                    byte g = pack.UnpackByte();
                    byte b = pack.UnpackByte();
                    byte a = pack.UnpackByte();
                    PartStartColor = new LLColor(r, g, b, a);
                    r               = pack.UnpackByte();
                    g               = pack.UnpackByte();
                    b               = pack.UnpackByte();
                    a               = pack.UnpackByte();
                    PartEndColor    = new LLColor(r, g, b, a);
                    PartStartScaleX = pack.UnpackFixed(false, 3, 5);
                    PartStartScaleY = pack.UnpackFixed(false, 3, 5);
                    PartEndScaleX   = pack.UnpackFixed(false, 3, 5);
                    PartEndScaleY   = pack.UnpackFixed(false, 3, 5);
                }
                else
                {
                    CRC               = PartFlags = 0;
                    Pattern           = SourcePattern.None;
                    MaxAge            = StartAge = InnerAngle = OuterAngle = BurstRate = BurstRadius = BurstSpeedMin =
                        BurstSpeedMax = 0.0f;
                    BurstPartCount    = 0;
                    AngularVelocity   = PartAcceleration = LLVector3.Zero;
                    Texture           = Target = LLUUID.Zero;
                    PartDataFlags     = ParticleDataFlags.None;
                    PartMaxAge        = 0.0f;
                    PartStartColor    = PartEndColor = LLColor.Black;
                    PartStartScaleX   = PartStartScaleY = PartEndScaleX = PartEndScaleY = 0.0f;
                }
            }