diff options
Diffstat (limited to 'OpenSim/Region/Environment/Scenes/SceneObjectPart.cs')
-rw-r--r-- | OpenSim/Region/Environment/Scenes/SceneObjectPart.cs | 527 |
1 files changed, 527 insertions, 0 deletions
diff --git a/OpenSim/Region/Environment/Scenes/SceneObjectPart.cs b/OpenSim/Region/Environment/Scenes/SceneObjectPart.cs new file mode 100644 index 0000000..d0730d7 --- /dev/null +++ b/OpenSim/Region/Environment/Scenes/SceneObjectPart.cs | |||
@@ -0,0 +1,527 @@ | |||
1 | using System.Collections.Generic; | ||
2 | using System.Text; | ||
3 | using System; | ||
4 | using Axiom.Math; | ||
5 | using libsecondlife; | ||
6 | using libsecondlife.Packets; | ||
7 | using OpenSim.Framework.Interfaces; | ||
8 | using OpenSim.Framework.Types; | ||
9 | |||
10 | namespace OpenSim.Region.Environment.Scenes | ||
11 | { | ||
12 | |||
13 | public class SceneObjectPart | ||
14 | { | ||
15 | private const uint FULL_MASK_PERMISSIONS = 2147483647; | ||
16 | |||
17 | public LLUUID CreatorID; | ||
18 | public LLUUID OwnerID; | ||
19 | public LLUUID GroupID; | ||
20 | public LLUUID LastOwnerID; | ||
21 | public Int32 CreationDate; | ||
22 | public uint ParentID = 0; | ||
23 | |||
24 | public uint OwnerMask = FULL_MASK_PERMISSIONS; | ||
25 | public uint NextOwnerMask = FULL_MASK_PERMISSIONS; | ||
26 | public uint GroupMask = FULL_MASK_PERMISSIONS; | ||
27 | public uint EveryoneMask = FULL_MASK_PERMISSIONS; | ||
28 | public uint BaseMask = FULL_MASK_PERMISSIONS; | ||
29 | |||
30 | protected byte[] m_particleSystem = new byte[0]; | ||
31 | |||
32 | protected SceneObjectGroup m_parentGroup; | ||
33 | |||
34 | /// <summary> | ||
35 | /// Only used internally to schedule client updates | ||
36 | /// </summary> | ||
37 | private byte m_updateFlag; | ||
38 | |||
39 | #region Properties | ||
40 | |||
41 | protected LLUUID m_uuid; | ||
42 | public LLUUID UUID | ||
43 | { | ||
44 | get { return m_uuid; } | ||
45 | set { m_uuid = value ; } | ||
46 | } | ||
47 | |||
48 | protected uint m_localID; | ||
49 | public uint LocalID | ||
50 | { | ||
51 | get { return m_localID; } | ||
52 | set { m_localID = value; } | ||
53 | } | ||
54 | |||
55 | protected string m_partName; | ||
56 | public virtual string PartName | ||
57 | { | ||
58 | get { return m_partName; } | ||
59 | set { m_partName = value; } | ||
60 | } | ||
61 | |||
62 | protected LLObject.ObjectFlags m_flags = (LLObject.ObjectFlags)32 + 65536 + 131072 + 256 + 4 + 8 + 2048 + 524288 + 268435456 + 128; | ||
63 | public uint ObjectFlags | ||
64 | { | ||
65 | get { return (uint)m_flags; } | ||
66 | set { m_flags = (LLObject.ObjectFlags)value; } | ||
67 | } | ||
68 | |||
69 | protected LLObject.MaterialType m_material; | ||
70 | public byte Material | ||
71 | { | ||
72 | get { return (byte)m_material; } | ||
73 | set { m_material = (LLObject.MaterialType)value; } | ||
74 | } | ||
75 | |||
76 | protected ulong m_regionHandle; | ||
77 | public ulong RegionHandle | ||
78 | { | ||
79 | get { return m_regionHandle; } | ||
80 | set { m_regionHandle = value; } | ||
81 | } | ||
82 | |||
83 | //unkown if this will be kept, added as a way of removing the group position from the group class | ||
84 | protected LLVector3 m_groupPosition; | ||
85 | public LLVector3 GroupPosition | ||
86 | { | ||
87 | get { return m_groupPosition; } | ||
88 | set { m_groupPosition = value; } | ||
89 | } | ||
90 | |||
91 | protected LLVector3 m_offset; | ||
92 | public LLVector3 OffsetPosition | ||
93 | { | ||
94 | get { return m_offset; } | ||
95 | set { m_offset = value; } | ||
96 | } | ||
97 | |||
98 | protected LLQuaternion m_rotationOffset; | ||
99 | public LLQuaternion RotationOffset | ||
100 | { | ||
101 | get { return m_rotationOffset; } | ||
102 | set { m_rotationOffset = value; } | ||
103 | } | ||
104 | |||
105 | protected LLVector3 m_velocity; | ||
106 | /// <summary></summary> | ||
107 | public LLVector3 Velocity | ||
108 | { | ||
109 | get { return m_velocity; } | ||
110 | set { m_velocity = value; } | ||
111 | } | ||
112 | |||
113 | protected LLVector3 m_angularVelocity; | ||
114 | /// <summary></summary> | ||
115 | public LLVector3 AngularVelocity | ||
116 | { | ||
117 | get { return m_angularVelocity; } | ||
118 | set { m_angularVelocity = value; } | ||
119 | } | ||
120 | |||
121 | protected LLVector3 m_acceleration; | ||
122 | /// <summary></summary> | ||
123 | public LLVector3 Acceleration | ||
124 | { | ||
125 | get { return m_acceleration; } | ||
126 | set { m_acceleration = value; } | ||
127 | } | ||
128 | |||
129 | private string m_description = ""; | ||
130 | public string Description | ||
131 | { | ||
132 | get { return this.m_description; } | ||
133 | set { this.m_description = value; } | ||
134 | } | ||
135 | |||
136 | private string m_text = ""; | ||
137 | public string Text | ||
138 | { | ||
139 | get { return m_text; } | ||
140 | set | ||
141 | { | ||
142 | m_text = value; | ||
143 | ScheduleFullUpdate(); | ||
144 | } | ||
145 | } | ||
146 | |||
147 | private string m_sitName = ""; | ||
148 | public string SitName | ||
149 | { | ||
150 | get { return m_sitName; } | ||
151 | set { m_sitName = value; } | ||
152 | } | ||
153 | |||
154 | private string m_touchName = ""; | ||
155 | public string TouchName | ||
156 | { | ||
157 | get { return m_touchName; } | ||
158 | set { m_touchName = value; } | ||
159 | } | ||
160 | |||
161 | protected PrimitiveBaseShape m_shape; | ||
162 | public PrimitiveBaseShape Shape | ||
163 | { | ||
164 | get { return this.m_shape; } | ||
165 | set { m_shape = value; } | ||
166 | } | ||
167 | |||
168 | public LLVector3 Scale | ||
169 | { | ||
170 | set { this.m_shape.Scale = value; } | ||
171 | get { return this.m_shape.Scale; } | ||
172 | } | ||
173 | #endregion | ||
174 | |||
175 | #region Constructors | ||
176 | /// <summary> | ||
177 | /// | ||
178 | /// </summary> | ||
179 | public SceneObjectPart() | ||
180 | { | ||
181 | |||
182 | } | ||
183 | |||
184 | /// <summary> | ||
185 | /// Create a completely new SceneObjectPart (prim) | ||
186 | /// </summary> | ||
187 | /// <param name="regionHandle"></param> | ||
188 | /// <param name="parent"></param> | ||
189 | /// <param name="ownerID"></param> | ||
190 | /// <param name="localID"></param> | ||
191 | /// <param name="shape"></param> | ||
192 | /// <param name="position"></param> | ||
193 | public SceneObjectPart(ulong regionHandle, SceneObjectGroup parent, LLUUID ownerID, uint localID, PrimitiveBaseShape shape, LLVector3 groupPosition, LLVector3 offsetPosition) | ||
194 | { | ||
195 | this.m_partName = "Primitive"; | ||
196 | this.m_regionHandle = regionHandle; | ||
197 | this.m_parentGroup = parent; | ||
198 | |||
199 | this.CreationDate = (Int32)(DateTime.UtcNow - new DateTime(1970, 1, 1)).TotalSeconds; | ||
200 | this.OwnerID = ownerID; | ||
201 | this.CreatorID = this.OwnerID; | ||
202 | this.LastOwnerID = LLUUID.Zero; | ||
203 | this.UUID = LLUUID.Random(); | ||
204 | this.LocalID = (uint)(localID); | ||
205 | this.Shape = shape; | ||
206 | |||
207 | this.GroupPosition = groupPosition; | ||
208 | this.OffsetPosition = offsetPosition; | ||
209 | this.RotationOffset = LLQuaternion.Identity; | ||
210 | this.Velocity = new LLVector3(0, 0, 0); | ||
211 | this.AngularVelocity = new LLVector3(0, 0, 0); | ||
212 | this.Acceleration = new LLVector3(0, 0, 0); | ||
213 | |||
214 | //temporary code just so the m_flags field doesn't give a compiler warning | ||
215 | if (m_flags == LLObject.ObjectFlags.AllowInventoryDrop) | ||
216 | { | ||
217 | |||
218 | } | ||
219 | ScheduleFullUpdate(); | ||
220 | } | ||
221 | |||
222 | /// <summary> | ||
223 | /// Re/create a SceneObjectPart (prim) | ||
224 | /// </summary> | ||
225 | /// <param name="regionHandle"></param> | ||
226 | /// <param name="parent"></param> | ||
227 | /// <param name="ownerID"></param> | ||
228 | /// <param name="localID"></param> | ||
229 | /// <param name="shape"></param> | ||
230 | /// <param name="position"></param> | ||
231 | public SceneObjectPart(ulong regionHandle, SceneObjectGroup parent, int creationDate, LLUUID ownerID, LLUUID creatorID, LLUUID lastOwnerID, uint localID, PrimitiveBaseShape shape, LLVector3 position, LLQuaternion rotation, uint flags) | ||
232 | { | ||
233 | this.m_regionHandle = regionHandle; | ||
234 | this.m_parentGroup = parent; | ||
235 | |||
236 | this.CreationDate = creationDate; | ||
237 | this.OwnerID = ownerID; | ||
238 | this.CreatorID = creatorID; | ||
239 | this.LastOwnerID = lastOwnerID; | ||
240 | this.UUID = LLUUID.Random(); | ||
241 | this.LocalID = (uint)(localID); | ||
242 | this.Shape = shape; | ||
243 | |||
244 | this.OffsetPosition = position; | ||
245 | this.RotationOffset = rotation; | ||
246 | this.ObjectFlags = flags; | ||
247 | } | ||
248 | #endregion | ||
249 | |||
250 | #region Copying | ||
251 | /// <summary> | ||
252 | /// | ||
253 | /// </summary> | ||
254 | /// <returns></returns> | ||
255 | public SceneObjectPart Copy(uint localID) | ||
256 | { | ||
257 | SceneObjectPart dupe = (SceneObjectPart)this.MemberwiseClone(); | ||
258 | dupe.m_shape = m_shape.Copy(); | ||
259 | dupe.m_regionHandle = m_regionHandle; | ||
260 | dupe.UUID = LLUUID.Random(); | ||
261 | dupe.LocalID = localID; | ||
262 | dupe.GroupPosition = new LLVector3(GroupPosition.X, GroupPosition.Y, GroupPosition.Z); | ||
263 | dupe.OffsetPosition = new LLVector3(OffsetPosition.X, OffsetPosition.Y, OffsetPosition.Z); | ||
264 | dupe.RotationOffset = new LLQuaternion(RotationOffset.X, RotationOffset.Y, RotationOffset.Z, RotationOffset.W); | ||
265 | dupe.Velocity = new LLVector3(0, 0, 0); | ||
266 | dupe.Acceleration = new LLVector3(0, 0, 0); | ||
267 | dupe.AngularVelocity = new LLVector3(0, 0, 0); | ||
268 | dupe.ObjectFlags = this.ObjectFlags; | ||
269 | //TODO copy extraparams data and anything else not currently copied | ||
270 | return dupe; | ||
271 | } | ||
272 | #endregion | ||
273 | |||
274 | #region Update Scheduling | ||
275 | /// <summary> | ||
276 | /// | ||
277 | /// </summary> | ||
278 | private void ClearUpdateSchedule() | ||
279 | { | ||
280 | m_updateFlag = 0; | ||
281 | } | ||
282 | |||
283 | /// <summary> | ||
284 | /// | ||
285 | /// </summary> | ||
286 | public void ScheduleFullUpdate() | ||
287 | { | ||
288 | m_updateFlag = 2; | ||
289 | } | ||
290 | |||
291 | /// <summary> | ||
292 | /// | ||
293 | /// </summary> | ||
294 | public void ScheduleTerseUpdate() | ||
295 | { | ||
296 | if (m_updateFlag < 1) | ||
297 | { | ||
298 | m_updateFlag = 1; | ||
299 | } | ||
300 | } | ||
301 | |||
302 | /// <summary> | ||
303 | /// | ||
304 | /// </summary> | ||
305 | public void SendScheduledUpdates() | ||
306 | { | ||
307 | if (m_updateFlag == 1) //some change has been made so update the clients | ||
308 | { | ||
309 | SendTerseUpdateToAllClients(); | ||
310 | ClearUpdateSchedule(); | ||
311 | } | ||
312 | else | ||
313 | { | ||
314 | if (m_updateFlag == 2) // is a new prim, just created/reloaded or has major changes | ||
315 | { | ||
316 | SendFullUpdateToAllClients(); | ||
317 | ClearUpdateSchedule(); | ||
318 | } | ||
319 | } | ||
320 | } | ||
321 | #endregion | ||
322 | |||
323 | #region Shape | ||
324 | /// <summary> | ||
325 | /// | ||
326 | /// </summary> | ||
327 | /// <param name="shapeBlock"></param> | ||
328 | public void UpdateShape(ObjectShapePacket.ObjectDataBlock shapeBlock) | ||
329 | { | ||
330 | this.m_shape.PathBegin = shapeBlock.PathBegin; | ||
331 | this.m_shape.PathEnd = shapeBlock.PathEnd; | ||
332 | this.m_shape.PathScaleX = shapeBlock.PathScaleX; | ||
333 | this.m_shape.PathScaleY = shapeBlock.PathScaleY; | ||
334 | this.m_shape.PathShearX = shapeBlock.PathShearX; | ||
335 | this.m_shape.PathShearY = shapeBlock.PathShearY; | ||
336 | this.m_shape.PathSkew = shapeBlock.PathSkew; | ||
337 | this.m_shape.ProfileBegin = shapeBlock.ProfileBegin; | ||
338 | this.m_shape.ProfileEnd = shapeBlock.ProfileEnd; | ||
339 | this.m_shape.PathCurve = shapeBlock.PathCurve; | ||
340 | this.m_shape.ProfileCurve = shapeBlock.ProfileCurve; | ||
341 | this.m_shape.ProfileHollow = shapeBlock.ProfileHollow; | ||
342 | this.m_shape.PathRadiusOffset = shapeBlock.PathRadiusOffset; | ||
343 | this.m_shape.PathRevolutions = shapeBlock.PathRevolutions; | ||
344 | this.m_shape.PathTaperX = shapeBlock.PathTaperX; | ||
345 | this.m_shape.PathTaperY = shapeBlock.PathTaperY; | ||
346 | this.m_shape.PathTwist = shapeBlock.PathTwist; | ||
347 | this.m_shape.PathTwistBegin = shapeBlock.PathTwistBegin; | ||
348 | ScheduleFullUpdate(); | ||
349 | } | ||
350 | #endregion | ||
351 | |||
352 | #region Inventory | ||
353 | public void GetInventory(IClientAPI client, uint localID) | ||
354 | { | ||
355 | if (localID == this.m_localID) | ||
356 | { | ||
357 | client.SendTaskInventory(this.m_uuid, 0, new byte[0]); | ||
358 | } | ||
359 | } | ||
360 | #endregion | ||
361 | |||
362 | #region ExtraParams | ||
363 | public void UpdateExtraParam(ushort type, bool inUse, byte[] data) | ||
364 | { | ||
365 | this.m_shape.ExtraParams = new byte[data.Length + 7]; | ||
366 | int i = 0; | ||
367 | uint length = (uint)data.Length; | ||
368 | this.m_shape.ExtraParams[i++] = 1; | ||
369 | this.m_shape.ExtraParams[i++] = (byte)(type % 256); | ||
370 | this.m_shape.ExtraParams[i++] = (byte)((type >> 8) % 256); | ||
371 | |||
372 | this.m_shape.ExtraParams[i++] = (byte)(length % 256); | ||
373 | this.m_shape.ExtraParams[i++] = (byte)((length >> 8) % 256); | ||
374 | this.m_shape.ExtraParams[i++] = (byte)((length >> 16) % 256); | ||
375 | this.m_shape.ExtraParams[i++] = (byte)((length >> 24) % 256); | ||
376 | Array.Copy(data, 0, this.m_shape.ExtraParams, i, data.Length); | ||
377 | |||
378 | this.ScheduleFullUpdate(); | ||
379 | } | ||
380 | #endregion | ||
381 | |||
382 | #region Texture | ||
383 | /// <summary> | ||
384 | /// | ||
385 | /// </summary> | ||
386 | /// <param name="textureEntry"></param> | ||
387 | public void UpdateTextureEntry(byte[] textureEntry) | ||
388 | { | ||
389 | this.m_shape.TextureEntry = textureEntry; | ||
390 | ScheduleFullUpdate(); | ||
391 | } | ||
392 | #endregion | ||
393 | |||
394 | #region ParticleSystem | ||
395 | public void AddNewParticleSystem(libsecondlife.Primitive.ParticleSystem pSystem) | ||
396 | { | ||
397 | this.m_particleSystem = pSystem.GetBytes(); | ||
398 | } | ||
399 | #endregion | ||
400 | |||
401 | #region Position | ||
402 | /// <summary> | ||
403 | /// | ||
404 | /// </summary> | ||
405 | /// <param name="pos"></param> | ||
406 | public void UpdateOffSet(LLVector3 pos) | ||
407 | { | ||
408 | LLVector3 newPos = new LLVector3(pos.X, pos.Y, pos.Z); | ||
409 | this.OffsetPosition = newPos; | ||
410 | ScheduleTerseUpdate(); | ||
411 | } | ||
412 | #endregion | ||
413 | |||
414 | #region rotation | ||
415 | public void UpdateRotation(LLQuaternion rot) | ||
416 | { | ||
417 | this.RotationOffset = new LLQuaternion(rot.X, rot.Y, rot.Z, rot.W); | ||
418 | ScheduleTerseUpdate(); | ||
419 | } | ||
420 | #endregion | ||
421 | |||
422 | #region Resizing/Scale | ||
423 | /// <summary> | ||
424 | /// | ||
425 | /// </summary> | ||
426 | /// <param name="scale"></param> | ||
427 | public void Resize(LLVector3 scale) | ||
428 | { | ||
429 | this.m_shape.Scale = scale; | ||
430 | ScheduleFullUpdate(); | ||
431 | } | ||
432 | #endregion | ||
433 | |||
434 | #region Client Update Methods | ||
435 | /// <summary> | ||
436 | /// | ||
437 | /// </summary> | ||
438 | public void SendFullUpdateToAllClients() | ||
439 | { | ||
440 | List<ScenePresence> avatars = this.m_parentGroup.RequestSceneAvatars(); | ||
441 | for (int i = 0; i < avatars.Count; i++) | ||
442 | { | ||
443 | m_parentGroup.SendPartFullUpdate(avatars[i].ControllingClient, this); | ||
444 | } | ||
445 | } | ||
446 | |||
447 | /// <summary> | ||
448 | /// | ||
449 | /// </summary> | ||
450 | /// <param name="remoteClient"></param> | ||
451 | public void SendFullUpdate(IClientAPI remoteClient) | ||
452 | { | ||
453 | m_parentGroup.SendPartFullUpdate( remoteClient, this ); | ||
454 | } | ||
455 | |||
456 | /// <summary> | ||
457 | /// | ||
458 | /// </summary> | ||
459 | /// <param name="remoteClient"></param> | ||
460 | public void SendFullUpdateToClient(IClientAPI remoteClient) | ||
461 | { | ||
462 | LLVector3 lPos; | ||
463 | lPos = OffsetPosition; | ||
464 | SendFullUpdateToClient(remoteClient, lPos); | ||
465 | } | ||
466 | |||
467 | /// <summary> | ||
468 | /// | ||
469 | /// </summary> | ||
470 | /// <param name="remoteClient"></param> | ||
471 | /// <param name="lPos"></param> | ||
472 | public void SendFullUpdateToClient(IClientAPI remoteClient, LLVector3 lPos) | ||
473 | { | ||
474 | LLQuaternion lRot; | ||
475 | lRot = RotationOffset; | ||
476 | |||
477 | remoteClient.SendPrimitiveToClient(m_regionHandle, 64096, LocalID, m_shape, lPos, this.ObjectFlags, m_uuid, OwnerID, | ||
478 | m_text, ParentID, this.m_particleSystem, lRot); | ||
479 | } | ||
480 | |||
481 | /// <summary> | ||
482 | /// | ||
483 | /// </summary> | ||
484 | public void SendTerseUpdateToAllClients() | ||
485 | { | ||
486 | List<ScenePresence> avatars = this.m_parentGroup.RequestSceneAvatars(); | ||
487 | for (int i = 0; i < avatars.Count; i++) | ||
488 | { | ||
489 | m_parentGroup.SendPartTerseUpdate(avatars[i].ControllingClient, this); | ||
490 | } | ||
491 | } | ||
492 | |||
493 | /// <summary> | ||
494 | /// | ||
495 | /// </summary> | ||
496 | /// <param name="remoteClient"></param> | ||
497 | public void SendTerseUpdate(IClientAPI remoteClient) | ||
498 | { | ||
499 | m_parentGroup.SendPartTerseUpdate(remoteClient, this); | ||
500 | } | ||
501 | |||
502 | /// <summary> | ||
503 | /// | ||
504 | /// </summary> | ||
505 | /// <param name="RemoteClient"></param> | ||
506 | public void SendTerseUpdateToClient(IClientAPI remoteClient) | ||
507 | { | ||
508 | LLVector3 lPos; | ||
509 | lPos = this.OffsetPosition; | ||
510 | LLQuaternion mRot = this.RotationOffset; | ||
511 | remoteClient.SendPrimTerseUpdate(m_regionHandle, 64096, LocalID, lPos, mRot); | ||
512 | } | ||
513 | |||
514 | /// <summary> | ||
515 | /// | ||
516 | /// </summary> | ||
517 | /// <param name="remoteClient"></param> | ||
518 | /// <param name="lPos"></param> | ||
519 | public void SendTerseUpdateToClient(IClientAPI remoteClient, LLVector3 lPos) | ||
520 | { | ||
521 | LLQuaternion mRot = this.RotationOffset; | ||
522 | remoteClient.SendPrimTerseUpdate(m_regionHandle, 64096, LocalID, lPos, mRot); | ||
523 | } | ||
524 | #endregion | ||
525 | } | ||
526 | } | ||
527 | |||