From 92c03978e19ef3423ad71bc4668071340a8b27a9 Mon Sep 17 00:00:00 2001 From: Teravus Ovares Date: Thu, 8 May 2008 04:58:44 +0000 Subject: * Fixes Prim ExtraParams * Fixes Sculpty handling * Fixes Light handling * Fixes Flexi handling * Fixes Sculpty + Flexi handling * Fixes handling of Flexi type * Fixes Changing prim type after changing to sculpty corrupting prim. * Ugly code. --- OpenSim/Framework/PrimitiveBaseShape.cs | 358 ++++++++++++++++++++- .../Region/Environment/Scenes/SceneObjectPart.cs | 13 +- 2 files changed, 358 insertions(+), 13 deletions(-) (limited to 'OpenSim') diff --git a/OpenSim/Framework/PrimitiveBaseShape.cs b/OpenSim/Framework/PrimitiveBaseShape.cs index 6607c4b..aabd69d 100644 --- a/OpenSim/Framework/PrimitiveBaseShape.cs +++ b/OpenSim/Framework/PrimitiveBaseShape.cs @@ -71,7 +71,7 @@ namespace OpenSim.Framework public class PrimitiveBaseShape { private static readonly LLObject.TextureEntry m_defaultTexture; - public byte[] ExtraParams; + private byte[] m_textureEntry; public ushort PathBegin; @@ -97,6 +97,33 @@ namespace OpenSim.Framework public ushort ProfileHollow; public LLVector3 Scale; public byte State; + // Sculpted + [XmlIgnore] public LLUUID SculptTexture = LLUUID.Zero; + [XmlIgnore] public byte SculptType = (byte)0; + + // Flexi + [XmlIgnore] public int FlexiSoftness = 0; + [XmlIgnore] public float FlexiTension = 0f; + [XmlIgnore] public float FlexiDrag = 0f; + [XmlIgnore] public float FlexiGravity = 0f; + [XmlIgnore] public float FlexiWind= 0f; + [XmlIgnore] public float FlexiForceX = 0f; + [XmlIgnore] public float FlexiForceY = 0f; + [XmlIgnore] public float FlexiForceZ = 0f; + + //Bright n sparkly + [XmlIgnore] public float LightColorR = 0f; + [XmlIgnore] public float LightColorG = 0f; + [XmlIgnore] public float LightColorB = 0f; + [XmlIgnore] public float LightColorA = 1f; + [XmlIgnore] public float LightRadius = 0f; + [XmlIgnore] public float LightCutoff = 0f; + [XmlIgnore] public float LightFalloff = 0f; + [XmlIgnore] public float LightIntensity = 1f; + [XmlIgnore] public bool FlexiEntry = false; + [XmlIgnore] public bool LightEntry = false; + [XmlIgnore] public bool SculptEntry = false; + static PrimitiveBaseShape() { @@ -231,10 +258,339 @@ namespace OpenSim.Framework PathEnd = LLObject.PackEndCut(pathRange.Y); } + public void SetSculptData(byte sculptType, LLUUID SculptTextureUUID) + { + SculptType = sculptType; + SculptTexture = SculptTextureUUID; + } + public void SetProfileRange(LLVector3 profileRange) { ProfileBegin = LLObject.PackBeginCut(profileRange.X); ProfileEnd = LLObject.PackEndCut(profileRange.Y); } + public byte[] ExtraParams + { + get + { + return ExtraParamsToBytes(); + } + set + { + ReadInExtraParamsBytes(value); + } + } + + public byte[] ExtraParamsToBytes() + { + ushort FlexiEP = 0x10; + ushort LightEP = 0x20; + ushort SculptEP = 0x30; + + int i = 0; + uint TotalBytesLength = 5; + + uint ExtraParamsNum = 0; + if (FlexiEntry) + { + ExtraParamsNum++; + TotalBytesLength += 16;// data + TotalBytesLength += 4; // type + } + if (LightEntry) + { + ExtraParamsNum++; + TotalBytesLength += 16;// data + TotalBytesLength += 4; // type + } + if (SculptEntry) + { + ExtraParamsNum++; + TotalBytesLength += 17;// data + TotalBytesLength += 4; // type + } + + byte[] returnbytes = new byte[TotalBytesLength]; + + + uint paramlength = ExtraParamsNum; + + // Stick in the number of parameters + returnbytes[i++] = (byte)ExtraParamsNum; + + if (FlexiEntry) + { + byte[] FlexiData = GetFlexiBytes(); + + returnbytes[i++] = (byte)(FlexiEP % 256); + returnbytes[i++] = (byte)((FlexiEP >> 8) % 256); + + returnbytes[i++] = (byte)(FlexiData.Length % 256); + returnbytes[i++] = (byte)((FlexiData.Length >> 8) % 256); + returnbytes[i++] = (byte)((FlexiData.Length >> 16) % 256); + returnbytes[i++] = (byte)((FlexiData.Length >> 24) % 256); + Array.Copy(FlexiData, 0, returnbytes, i, FlexiData.Length); + i += FlexiData.Length; + } + if (LightEntry) + { + byte[] LightData = GetLightBytes(); + + returnbytes[i++] = (byte)(LightEP % 256); + returnbytes[i++] = (byte)((LightEP >> 8) % 256); + + returnbytes[i++] = (byte)(LightData.Length % 256); + returnbytes[i++] = (byte)((LightData.Length >> 8) % 256); + returnbytes[i++] = (byte)((LightData.Length >> 16) % 256); + returnbytes[i++] = (byte)((LightData.Length >> 24) % 256); + Array.Copy(LightData, 0, returnbytes, i, LightData.Length); + i += LightData.Length; + } + if (SculptEntry) + { + byte[] SculptData = GetSculptBytes(); + + returnbytes[i++] = (byte)(SculptEP % 256); + returnbytes[i++] = (byte)((SculptEP >> 8) % 256); + + returnbytes[i++] = (byte)(SculptData.Length % 256); + returnbytes[i++] = (byte)((SculptData.Length >> 8) % 256); + returnbytes[i++] = (byte)((SculptData.Length >> 16) % 256); + returnbytes[i++] = (byte)((SculptData.Length >> 24) % 256); + Array.Copy(SculptData, 0, returnbytes, i, SculptData.Length); + i += SculptData.Length; + } + + if (!FlexiEntry && !LightEntry && !SculptEntry) + { + byte[] returnbyte = new byte[1]; + returnbyte[0] = 0; + return returnbyte; + } + + + return returnbytes; + //m_log.Info("[EXTRAPARAMS]: Length = " + m_shape.ExtraParams.Length.ToString()); + + } + + public void ReadInUpdateExtraParam(ushort type, bool inUse, byte[] data) + { + const ushort FlexiEP = 0x10; + const ushort LightEP = 0x20; + const ushort SculptEP = 0x30; + + switch (type) + { + case FlexiEP: + if (!inUse) + { + FlexiEntry = false; + return; + } + ReadFlexiData(data, 0); + break; + + case LightEP: + if (!inUse) + { + LightEntry = false; + return; + } + ReadLightData(data, 0); + break; + + case SculptEP: + if (!inUse) + { + SculptEntry = false; + return; + } + ReadSculptData(data, 0); + break; + } + } + + public void ReadInExtraParamsBytes(byte[] data) + { + const ushort FlexiEP = 0x10; + const ushort LightEP = 0x20; + const ushort SculptEP = 0x30; + + bool lGotFlexi = false; + bool lGotLight = false; + bool lGotSculpt = false; + + int i = 0; + int totalLength = 1; + byte extraParamCount = data[i++]; + + if (extraParamCount > 0) + { + int foo = 0; + } + for (int k = 0; k < extraParamCount; k++) + { + ushort epType = Helpers.BytesToUInt16(data, i); + + i += 2; + uint paramLength = Helpers.BytesToUIntBig(data, i); + + i += 4; + switch (epType) + { + case FlexiEP: + ReadFlexiData(data, i); + lGotFlexi = true; + break; + + case LightEP: + ReadLightData(data, i); + lGotLight = true; + break; + + case SculptEP: + ReadSculptData(data, i); + lGotSculpt = true; + break; + } + } + + if (!lGotFlexi) + FlexiEntry = false; + if (!lGotLight) + LightEntry = false; + if (!lGotSculpt) + SculptEntry = false; + + } + + public void ReadSculptData(byte[] data, int pos) + { + byte[] SculptTextureUUID = new byte[16]; + LLUUID SculptUUID = LLUUID.Zero; + byte SculptTypel = data[16+pos]; + + if (data.Length+pos >= 17) + { + SculptEntry = true; + SculptTextureUUID = new byte[16]; + SculptTypel = data[16]; + Array.Copy(data, pos, SculptTextureUUID,0, 16); + SculptUUID = new LLUUID(SculptTextureUUID, 0); + } + else + { + SculptEntry = false; + SculptUUID = LLUUID.Zero; + SculptTypel = 0x00; + } + + + SculptTexture = SculptUUID; + SculptType = SculptTypel; + //m_log.Info("[SCULPT]:" + SculptUUID.ToString()); + } + + public byte[] GetSculptBytes() + { + byte[] data = new byte[17]; + + SculptTexture.GetBytes().CopyTo(data, 0); + data[16] = (byte)SculptType; + + return data; + } + public void ReadFlexiData(byte[] data, int pos) + { + if (data.Length-pos >= 5) + { + FlexiEntry = true; + FlexiSoftness = ((data[pos] & 0x80) >> 6) | ((data[pos + 1] & 0x80) >> 7); + + FlexiTension = (float)(data[pos++] & 0x7F) / 10.0f; + FlexiDrag = (float)(data[pos++] & 0x7F) / 10.0f; + FlexiGravity = (float)(data[pos++] / 10.0f) - 10.0f; + FlexiWind = (float)data[pos++] / 10.0f; + LLVector3 lForce = new LLVector3(data, pos); + FlexiForceX = lForce.X; + FlexiForceY = lForce.Y; + FlexiForceZ = lForce.Z; + } + else + { + FlexiEntry = false; + FlexiSoftness = 0; + + FlexiTension = 0.0f; + FlexiDrag = 0.0f; + FlexiGravity = 0.0f; + FlexiWind = 0.0f; + FlexiForceX = 0f; + FlexiForceY = 0f; + FlexiForceZ = 0f; + } + } + public byte[] GetFlexiBytes() + { + byte[] data = new byte[16]; + int i = 0; + + // Softness is packed in the upper bits of tension and drag + data[i] = (byte)((FlexiSoftness & 2) << 6); + data[i + 1] = (byte)((FlexiSoftness & 1) << 7); + + data[i++] |= (byte)((byte)(FlexiTension * 10.01f) & 0x7F); + data[i++] |= (byte)((byte)(FlexiDrag * 10.01f) & 0x7F); + data[i++] = (byte)((FlexiGravity + 10.0f) * 10.01f); + data[i++] = (byte)(FlexiWind * 10.01f); + LLVector3 lForce = new LLVector3(FlexiForceX, FlexiForceY, FlexiForceZ); + lForce.GetBytes().CopyTo(data, i); + + return data; + } + public void ReadLightData(byte[] data, int pos) + { + if (data.Length - pos >= 16) + { + LightEntry = true; + LLColor lColor = new LLColor(data, pos, false); + LightIntensity = lColor.A; + LightColorA = 1f; + LightColorR = lColor.R; + LightColorG = lColor.G; + LightColorB = lColor.B; + + LightRadius = Helpers.BytesToFloat(data, pos + 4); + LightCutoff = Helpers.BytesToFloat(data, pos + 8); + LightFalloff = Helpers.BytesToFloat(data, pos + 12); + } + else + { + LightEntry = false; + LightColorA = 1f; + LightColorR = 0f; + LightColorG = 0f; + LightColorB = 0f; + LightRadius = 0f; + LightCutoff = 0f; + LightFalloff = 0f; + LightIntensity = 0f; + } + } + public byte[] GetLightBytes() + { + byte[] data = new byte[16]; + + // Alpha channel in color is intensity + LLColor tmpColor = new LLColor(LightColorR,LightColorG,LightColorB,LightIntensity); + + tmpColor.GetBytes().CopyTo(data, 0); + Helpers.FloatToBytes(LightRadius).CopyTo(data, 4); + Helpers.FloatToBytes(LightCutoff).CopyTo(data, 8); + Helpers.FloatToBytes(LightFalloff).CopyTo(data, 12); + + return data; + } } } \ No newline at end of file diff --git a/OpenSim/Region/Environment/Scenes/SceneObjectPart.cs b/OpenSim/Region/Environment/Scenes/SceneObjectPart.cs index adcd646..22753de 100644 --- a/OpenSim/Region/Environment/Scenes/SceneObjectPart.cs +++ b/OpenSim/Region/Environment/Scenes/SceneObjectPart.cs @@ -1920,18 +1920,7 @@ namespace OpenSim.Region.Environment.Scenes public void UpdateExtraParam(ushort type, bool inUse, byte[] data) { - m_shape.ExtraParams = new byte[data.Length + 7]; - int i = 0; - uint length = (uint) data.Length; - m_shape.ExtraParams[i++] = 1; - m_shape.ExtraParams[i++] = (byte) (type%256); - m_shape.ExtraParams[i++] = (byte) ((type >> 8)%256); - - m_shape.ExtraParams[i++] = (byte) (length%256); - m_shape.ExtraParams[i++] = (byte) ((length >> 8)%256); - m_shape.ExtraParams[i++] = (byte) ((length >> 16)%256); - m_shape.ExtraParams[i++] = (byte) ((length >> 24)%256); - Array.Copy(data, 0, m_shape.ExtraParams, i, data.Length); + m_shape.ReadInUpdateExtraParam(type, inUse, data); ScheduleFullUpdate(); } -- cgit v1.1