/*
* Copyright (c) 2006, Second Life Reverse Engineering Team
* All rights reserved.
*
* - Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* - Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
* - Neither the name of the Second Life Reverse Engineering Team nor the names
* of its contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
using System;
namespace libsecondlife
{
///
///
///
public class PrimObject
{
///
public int PathTwistBegin = 0;
///
public float PathEnd = 0;
///
public float ProfileBegin = 0;
///
public float PathRadiusOffset = 0;
///
public float PathSkew = 0;
///
public LLVector3 Position = new LLVector3();
///
public uint ProfileCurve = 0;
///
public float PathScaleX = 0;
///
public float PathScaleY = 0;
///
public LLUUID ID = new LLUUID();
///
public uint LocalID = 0;
///
public uint ParentID = 0;
///
public LLUUID GroupID = new LLUUID();
///
public uint Material = 0;
///
public string Name = "";
///
public string Description;
///
public float PathShearX = 0;
///
public float PathShearY = 0;
///
public float PathTaperX = 0;
///
public float PathTaperY = 0;
///
public float ProfileEnd = 0;
///
public float PathBegin = 0;
///
public uint PathCurve = 0;
///
public LLVector3 Scale = new LLVector3();
///
public int PathTwist = 0;
///
public PCode PCode;
///
public TextureEntry Textures;
///
public TextureAnimation TextureAnim;
///
public uint ProfileHollow = 0;
///
public float PathRevolutions = 0;
///
public LLQuaternion Rotation = new LLQuaternion();
///
public uint State;
///
public string Text;
///
public PrimFlexibleData Flexible;
///
public PrimLightData Light;
///
public ParticleSystem ParticleSys;
private SecondLife Client;
///
///
///
public PrimObject(SecondLife client)
{
Client = client;
PCode = PCode.Prim;
Textures = new TextureEntry();
}
///
///
///
///
public PrimObject(SecondLife client, LLUUID texture)
{
Client = client;
PCode = PCode.Prim;
Textures = new TextureEntry();
Textures.DefaultTexture.TextureID = texture;
}
///
///
///
///
///
public static byte PathScaleByte(float pathScale)
{
// Y = 100 + 100X
return (byte)(100 + Convert.ToInt16(100.0F * pathScale));
}
///
///
///
///
///
public static float PathScaleFloat(byte pathScale)
{
// Y = -1 + 0.01X
return (float)pathScale * 0.01F - 1.0F;
}
///
///
///
///
///
public static sbyte PathTwistByte(float pathTwist)
{
// Y = 256 + ceil (X / 1.8)
ushort temp = Convert.ToUInt16(256 + Math.Ceiling(pathTwist / 1.8F));
return (sbyte)(temp % 256);
}
/*///
///
///
///
///
public static float PathTwistFloat(sbyte pathTwist)
{
// Y = 0.5556X
return (float)pathTwist * 0.5556F;
}*/
///
///
///
///
///
public static byte PathShearByte(float pathShear)
{
// Y = 256 + 100X
ushort temp = Convert.ToUInt16(100.0F * pathShear);
temp += 256;
return (byte)(temp % 256);
}
///
///
///
///
///
public static float PathShearFloat(byte pathShear)
{
// Y = (X - 256) / 100
if (pathShear > 150)
{
return ((float)pathShear - 256.0F) / 100.0F;
}
else
{
return (float)pathShear / 100.0F;
} }
///
///
///
///
///
public static byte ProfileBeginByte(float profileBegin)
{
// Y = ceil (200X)
return (byte)Convert.ToInt16(200.0F * profileBegin);
}
///
///
///
///
///
public static float ProfileBeginFloat(byte profileBegin)
{
// Y = 0.005X
return (float)profileBegin * 0.005F;
}
///
///
///
///
///
public static byte ProfileEndByte(float profileEnd)
{
// Y = 200 - ceil (200X)
return (byte)(200 - (200.0F * profileEnd));
}
///
///
///
///
///
public static float ProfileEndFloat(byte profileEnd)
{
// Y = 1 - 0.005X
return 1.0F - (float)profileEnd * 0.005F;
}
///
///
///
///
///
public static byte PathBeginByte(float pathBegin)
{
// Y = 100X
return (byte)Convert.ToInt16(100.0F * pathBegin);
}
///
///
///
///
///
public static float PathBeginFloat(byte pathBegin)
{
// Y = X / 100
return (float)pathBegin / 100.0F;
}
///
///
///
///
///
public static byte PathEndByte(float pathEnd)
{
// Y = 100 - 100X
return (byte)(100 - Convert.ToInt16(100.0F * pathEnd));
}
///
///
///
///
///
public static float PathEndFloat(byte pathEnd)
{
// Y = 1 - X / 100
return 1.0F - (float)pathEnd / 100;
}
///
///
///
///
///
public static sbyte PathRadiusOffsetByte(float pathRadiusOffset)
{
// Y = 256 + 100X
return (sbyte)PathShearByte(pathRadiusOffset);
}
///
///
///
///
///
public static float PathRadiusOffsetFloat(sbyte pathRadiusOffset)
{
// Y = X / 100
return (float)pathRadiusOffset / 100.0F;
}
///
///
///
///
///
public static byte PathRevolutionsByte(float pathRevolutions)
{
// Y = ceil (66X) - 66
return (byte)(Convert.ToInt16(Math.Ceiling(66.0F * pathRevolutions)) - 66);
}
///
///
///
///
///
public static float PathRevolutionsFloat(byte pathRevolutions)
{
// Y = 1 + 0.015X
return 1.0F + (float)pathRevolutions * 0.015F;
}
///
///
///
///
///
public static sbyte PathSkewByte(float pathSkew)
{
return PathTaperByte(pathSkew);
}
///
///
///
///
///
public static float PathSkewFloat(byte pathSkew)
{
return PathTaperFloat(pathSkew);
}
///
///
///
///
///
public static sbyte PathTaperByte(float pathTaper)
{
// Y = 256 + 100X
return (sbyte)PathShearByte(pathTaper);
}
///
///
///
///
///
public static float PathTaperFloat(byte pathTaper)
{
if (pathTaper > 100)
{
return (float)(256 - pathTaper) * 0.01F;
}
else
{
return (float)pathTaper * 0.01F;
}
}
///
///
///
///
///
///
public int SetExtraParamsFromBytes(byte[] data, int pos)
{
int i = pos;
int totalLength = 1;
if (data.Length == 0)
return 0;
byte extraParamCount = data[i++];
for (int k = 0; k < extraParamCount; k++)
{
ExtraParamType type = (ExtraParamType)(data[i++] + (data[i++] << 8));
uint paramLength = (uint)(data[i++] + (data[i++] << 8) +
(data[i++] << 16) + (data[i++] << 24));
if (type == ExtraParamType.Flexible)
{
Flexible = new PrimFlexibleData(data, i);
}
else if (type == ExtraParamType.Light)
{
Light = new PrimLightData(data, i);
}
i += (int)paramLength;
totalLength += (int)paramLength + 6;
}
return totalLength;
}
}
///
///
///
public enum ExtraParamType : ushort
{
Flexible = 0x10,
Light = 0x20
}
///
///
///
public class PrimFlexibleData
{
///
public int Softness;
///
public float Gravity;
///
public float Drag;
///
public float Wind;
///
public float Tension;
///
public LLVector3 Force;
///
///
///
///
///
public PrimFlexibleData(byte[] data, int pos)
{
FromBytes(data, pos);
}
///
///
///
///
public byte[] ToBytes()
{
byte[] data = new byte[16];
int i = 0;
data[i] = (byte)((Softness & 2) << 6);
data[i + 1] = (byte)((Softness & 1) << 7);
data[i++] |= (byte)((byte)(Tension * 10.0f) & 0x7F);
data[i++] |= (byte)((byte)(Drag * 10.0f) & 0x7F);
data[i++] = (byte)((Gravity + 10.0f) * 10.0f);
data[i++] = (byte)(Wind * 10.0f);
Force.GetBytes().CopyTo(data, i);
return data;
}
private void FromBytes(byte[] data, int pos)
{
int i = pos;
Softness = ((data[i] & 0x80) >> 6) | ((data[i + 1] & 0x80) >> 7);
Tension = (data[i++] & 0x7F) / 10.0f;
Drag = (data[i++] & 0x7F) / 10.0f;
Gravity = (data[i++] / 10.0f) - 10.0f;
Wind = data[i++] / 10.0f;
Force = new LLVector3(data, i);
}
}
///
///
///
public class PrimLightData
{
///
public byte R, G, B;
///
public float Intensity;
///
public float Radius;
///
public float Falloff;
///
///
///
///
///
public PrimLightData(byte[] data, int pos)
{
FromBytes(data, pos);
}
///
///
///
///
public byte[] ToBytes()
{
byte[] data = new byte[16];
int i = 0;
data[i++] = R;
data[i++] = G;
data[i++] = B;
data[i++] = (byte)(Intensity * 255.0f);
BitConverter.GetBytes(Radius).CopyTo(data, i);
BitConverter.GetBytes(Falloff).CopyTo(data, i + 8);
if (!BitConverter.IsLittleEndian)
{
Array.Reverse(data, i, 4);
Array.Reverse(data, i + 8, 4);
}
return data;
}
private void FromBytes(byte[] data, int pos)
{
int i = pos;
R = data[i++];
G = data[i++];
B = data[i++];
Intensity = data[i++] / 255.0f;
if (!BitConverter.IsLittleEndian)
{
Array.Reverse(data, i, 4);
Array.Reverse(data, i + 8, 4);
}
Radius = BitConverter.ToSingle(data, i);
Falloff = BitConverter.ToSingle(data, i + 8);
}
}
}