aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim.Framework/PrimData.cs
blob: ee4188d39c4430cd8ae0302be7e65de0d4a56654 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
using System;
using System.Collections.Generic;
using System.Text;
using libsecondlife;

namespace OpenSim.Framework.Assets
{
    public class PrimData
    {
        private const uint FULL_MASK_PERMISSIONS = 2147483647;

        public LLUUID OwnerID;
        public byte PCode;
        public byte PathBegin;
        public byte PathEnd;
        public byte PathScaleX;
        public byte PathScaleY;
        public byte PathShearX;
        public byte PathShearY;
        public sbyte PathSkew;
        public byte ProfileBegin;
        public byte ProfileEnd;
        public LLVector3 Scale;
        public byte PathCurve;
        public byte ProfileCurve;
        public uint ParentID = 0;
        public byte ProfileHollow;
        public sbyte PathRadiusOffset;
        public byte PathRevolutions;
        public sbyte PathTaperX;
        public sbyte PathTaperY;
        public sbyte PathTwist;
        public sbyte PathTwistBegin;
        public byte[] Texture;
       

        public Int32 CreationDate;
        public uint OwnerMask = FULL_MASK_PERMISSIONS;
        public uint NextOwnerMask = FULL_MASK_PERMISSIONS;
        public uint GroupMask = FULL_MASK_PERMISSIONS;
        public uint EveryoneMask = FULL_MASK_PERMISSIONS;
        public uint BaseMask = FULL_MASK_PERMISSIONS;

        //following only used during prim storage
        public LLVector3 Position;
        public LLQuaternion Rotation = new LLQuaternion(0,1,0,0);
        public uint LocalID;
        public LLUUID FullID;

        public PrimData()
        {

        }

        public PrimData(byte[] data)
        {
            int i =0;

            this.OwnerID = new LLUUID(data, i); i += 16;
            this.PCode = data[i++];
            this.PathBegin = data[i++];
            this.PathEnd = data[i++];
            this.PathScaleX = data[i++];
            this.PathScaleY = data[i++];
            this.PathShearX = data[i++];
            this.PathShearY = data[i++];
            this.PathSkew = (sbyte)data[i++];
            this.ProfileBegin = data[i++];
            this.ProfileEnd = data[i++];
            this.Scale = new LLVector3(data, i); i += 12;
            this.PathCurve = data[i++];
            this.ProfileCurve = data[i++];
            this.ParentID = (uint)(data[i++] + (data[i++] << 8) + (data[i++] << 16) + (data[i++] << 24));
            this.ProfileHollow = data[i++];
            this.PathRadiusOffset = (sbyte)data[i++];
            this.PathRevolutions = data[i++];
            this.PathTaperX = (sbyte)data[i++];
            this.PathTaperY =(sbyte) data[i++];
            this.PathTwist = (sbyte) data[i++];
            this.PathTwistBegin = (sbyte) data[i++];
            ushort length = (ushort)(data[i++] + (data[i++] << 8));
            this.Texture = new byte[length];
            Array.Copy(data, i, Texture, 0, length); i += length;
            this.CreationDate = (Int32)(data[i++] + (data[i++] << 8) + (data[i++] << 16) + (data[i++] << 24));
            this.OwnerMask = (uint)(data[i++] + (data[i++] << 8) + (data[i++] << 16) + (data[i++] << 24));
            this.NextOwnerMask = (uint)(data[i++] + (data[i++] << 8) + (data[i++] << 16) + (data[i++] << 24));
            this.GroupMask = (uint)(data[i++] + (data[i++] << 8) + (data[i++] << 16) + (data[i++] << 24));
            this.EveryoneMask = (uint)(data[i++] + (data[i++] << 8) + (data[i++] << 16) + (data[i++] << 24));
            this.BaseMask = (uint)(data[i++] + (data[i++] << 8) + (data[i++] << 16) + (data[i++] << 24));
            this.Position = new LLVector3(data, i); i += 12;
            this.Rotation = new LLQuaternion(data,i, true); i += 12;
            this.LocalID = (uint)(data[i++] + (data[i++] << 8) + (data[i++] << 16) + (data[i++] << 24));
            this.FullID = new LLUUID(data, i); i += 16;

        }

        public byte[] ToBytes()
        {
            int i = 0;
            byte[] bytes = new byte[121 + Texture.Length];
            Array.Copy(OwnerID.GetBytes(), 0, bytes, i, 16); i += 16;
            bytes[i++] = this.PCode;
            bytes[i++] = this.PathBegin;
            bytes[i++] = this.PathEnd;
            bytes[i++] = this.PathScaleX;
            bytes[i++] = this.PathScaleY;
            bytes[i++] = this.PathShearX;
            bytes[i++] = this.PathShearY;
            bytes[i++] = (byte)this.PathSkew;
            bytes[i++] = this.ProfileBegin;
            bytes[i++] = this.ProfileEnd;
            Array.Copy(Scale.GetBytes(), 0, bytes, i, 12); i += 12;
            bytes[i++] = this.PathCurve;
            bytes[i++] = this.ProfileCurve;
            bytes[i++] = (byte)(ParentID % 256);
            bytes[i++] = (byte)((ParentID >> 8) % 256);
            bytes[i++] = (byte)((ParentID >> 16) % 256);
            bytes[i++] = (byte)((ParentID >> 24) % 256);
            bytes[i++] = this.ProfileHollow;
            bytes[i++] = ((byte)this.PathRadiusOffset);
            bytes[i++] = this.PathRevolutions;
            bytes[i++] = ((byte) this.PathTaperX);
            bytes[i++] = ((byte) this.PathTaperY);
            bytes[i++] = ((byte) this.PathTwist);
            bytes[i++] = ((byte) this.PathTwistBegin);
            bytes[i++] = (byte)(Texture.Length % 256);
            bytes[i++] = (byte)((Texture.Length >> 8) % 256);
            Array.Copy(Texture, 0, bytes, i, Texture.Length); i += Texture.Length;
            bytes[i++] = (byte)(this.CreationDate % 256);
            bytes[i++] = (byte)((this.CreationDate >> 8) % 256);
            bytes[i++] = (byte)((this.CreationDate >> 16) % 256);
            bytes[i++] = (byte)((this.CreationDate >> 24) % 256);
            bytes[i++] = (byte)(this.OwnerMask % 256);
            bytes[i++] = (byte)((this.OwnerMask >> 8) % 256);
            bytes[i++] = (byte)((this.OwnerMask >> 16) % 256);
            bytes[i++] = (byte)((this.OwnerMask >> 24) % 256);
            bytes[i++] = (byte)(this.NextOwnerMask % 256);
            bytes[i++] = (byte)((this.NextOwnerMask >> 8) % 256);
            bytes[i++] = (byte)((this.NextOwnerMask >> 16) % 256);
            bytes[i++] = (byte)((this.NextOwnerMask >> 24) % 256);
            bytes[i++] = (byte)(this.GroupMask % 256);
            bytes[i++] = (byte)((this.GroupMask >> 8) % 256);
            bytes[i++] = (byte)((this.GroupMask >> 16) % 256);
            bytes[i++] = (byte)((this.GroupMask >> 24) % 256);
            bytes[i++] = (byte)(this.EveryoneMask % 256);
            bytes[i++] = (byte)((this.EveryoneMask >> 8) % 256);
            bytes[i++] = (byte)((this.EveryoneMask >> 16) % 256);
            bytes[i++] = (byte)((this.EveryoneMask >> 24) % 256);
            bytes[i++] = (byte)(this.BaseMask % 256);
            bytes[i++] = (byte)((this.BaseMask >> 8) % 256);
            bytes[i++] = (byte)((this.BaseMask >> 16) % 256);
            bytes[i++] = (byte)((this.BaseMask >> 24) % 256);
            Array.Copy(this.Position.GetBytes(), 0, bytes, i, 12); i += 12;
            if (this.Rotation == new LLQuaternion(0,0,0,0))
            {
                this.Rotation = new LLQuaternion(0, 1, 0, 0);
            }
            Array.Copy(this.Rotation.GetBytes(), 0, bytes, i, 12); i += 12;
            bytes[i++] = (byte)(this.LocalID % 256);
            bytes[i++] = (byte)((this.LocalID >> 8) % 256);
            bytes[i++] = (byte)((this.LocalID >> 16) % 256);
            bytes[i++] = (byte)((this.LocalID >> 24) % 256);
            Array.Copy(FullID.GetBytes(), 0, bytes, i, 16); i += 16;

            return bytes;
        }
    }
}