diff options
author | mingchen | 2007-06-07 15:13:24 +0000 |
---|---|---|
committer | mingchen | 2007-06-07 15:13:24 +0000 |
commit | 2c4dacc1d6d8ddb57bdecdce163622934bdc43bf (patch) | |
tree | c55751c326fbea6fccd88ac457b45412180b2192 /OpenSim/OpenSim.RegionServer/Simulator/Primitive.cs | |
parent | Fixing SVN: Re-adding Types folder (with correct capitalization) ( 2 / 3 ) (diff) | |
download | opensim-SC_OLD-2c4dacc1d6d8ddb57bdecdce163622934bdc43bf.zip opensim-SC_OLD-2c4dacc1d6d8ddb57bdecdce163622934bdc43bf.tar.gz opensim-SC_OLD-2c4dacc1d6d8ddb57bdecdce163622934bdc43bf.tar.bz2 opensim-SC_OLD-2c4dacc1d6d8ddb57bdecdce163622934bdc43bf.tar.xz |
Fixing SVN: Adding hopefully everything else (2.5 / 3)
Diffstat (limited to 'OpenSim/OpenSim.RegionServer/Simulator/Primitive.cs')
-rw-r--r-- | OpenSim/OpenSim.RegionServer/Simulator/Primitive.cs | 598 |
1 files changed, 598 insertions, 0 deletions
diff --git a/OpenSim/OpenSim.RegionServer/Simulator/Primitive.cs b/OpenSim/OpenSim.RegionServer/Simulator/Primitive.cs new file mode 100644 index 0000000..f1417d0 --- /dev/null +++ b/OpenSim/OpenSim.RegionServer/Simulator/Primitive.cs | |||
@@ -0,0 +1,598 @@ | |||
1 | /* | ||
2 | * Copyright (c) Contributors, http://www.openmetaverse.org/ | ||
3 | * See CONTRIBUTORS.TXT for a full list of copyright holders. | ||
4 | * | ||
5 | * Redistribution and use in source and binary forms, with or without | ||
6 | * modification, are permitted provided that the following conditions are met: | ||
7 | * * Redistributions of source code must retain the above copyright | ||
8 | * notice, this list of conditions and the following disclaimer. | ||
9 | * * Redistributions in binary form must reproduce the above copyright | ||
10 | * notice, this list of conditions and the following disclaimer in the | ||
11 | * documentation and/or other materials provided with the distribution. | ||
12 | * * Neither the name of the OpenSim Project nor the | ||
13 | * names of its contributors may be used to endorse or promote products | ||
14 | * derived from this software without specific prior written permission. | ||
15 | * | ||
16 | * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS AND ANY | ||
17 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | ||
18 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
19 | * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY | ||
20 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | ||
21 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
22 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | ||
23 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
26 | * | ||
27 | */ | ||
28 | using System; | ||
29 | using System.Collections.Generic; | ||
30 | using System.Text; | ||
31 | using OpenSim.RegionServer.Types; | ||
32 | using libsecondlife; | ||
33 | using libsecondlife.Packets; | ||
34 | using OpenSim.Framework.Interfaces; | ||
35 | using OpenSim.Physics.Manager; | ||
36 | using OpenSim.Framework.Types; | ||
37 | using OpenSim.RegionServer.Client; | ||
38 | |||
39 | namespace OpenSim.RegionServer.Simulator | ||
40 | { | ||
41 | public class Primitive : Entity | ||
42 | { | ||
43 | protected float mesh_cutbegin; | ||
44 | protected float mesh_cutend; | ||
45 | protected PrimData primData; | ||
46 | protected bool newPrimFlag = false; | ||
47 | protected bool updateFlag = false; | ||
48 | protected bool dirtyFlag = false; | ||
49 | private ObjectUpdatePacket OurPacket; | ||
50 | private bool physicsEnabled = false; | ||
51 | private bool physicstest = false; | ||
52 | private LLVector3 positionLastFrame = new LLVector3(0, 0, 0); | ||
53 | private Dictionary<uint, ClientView> m_clientThreads; | ||
54 | private ulong m_regionHandle; | ||
55 | private const uint FULL_MASK_PERMISSIONS = 2147483647; | ||
56 | |||
57 | public bool PhysicsEnabled | ||
58 | { | ||
59 | get | ||
60 | { | ||
61 | return physicsEnabled; | ||
62 | } | ||
63 | set | ||
64 | { | ||
65 | physicsEnabled = value; | ||
66 | } | ||
67 | } | ||
68 | public bool UpdateFlag | ||
69 | { | ||
70 | get | ||
71 | { | ||
72 | return updateFlag; | ||
73 | } | ||
74 | set | ||
75 | { | ||
76 | updateFlag = value; | ||
77 | } | ||
78 | } | ||
79 | public LLVector3 Scale | ||
80 | { | ||
81 | set | ||
82 | { | ||
83 | LLVector3 offset = (value - primData.Scale); | ||
84 | offset.X /= 2; | ||
85 | offset.Y /= 2; | ||
86 | offset.Z /= 2; | ||
87 | |||
88 | this.primData.Position += offset; | ||
89 | this.primData.Scale = value; | ||
90 | |||
91 | this.dirtyFlag = true; | ||
92 | } | ||
93 | get | ||
94 | { | ||
95 | return this.primData.Scale; | ||
96 | } | ||
97 | } | ||
98 | public PhysicsActor PhysActor | ||
99 | { | ||
100 | set | ||
101 | { | ||
102 | this._physActor = value; | ||
103 | } | ||
104 | } | ||
105 | |||
106 | public Primitive(Dictionary<uint, ClientView> clientThreads, ulong regionHandle, World world) | ||
107 | { | ||
108 | mesh_cutbegin = 0.0f; | ||
109 | mesh_cutend = 1.0f; | ||
110 | |||
111 | m_clientThreads = clientThreads; | ||
112 | m_regionHandle = regionHandle; | ||
113 | m_world = world; | ||
114 | } | ||
115 | |||
116 | public override Mesh getMesh() | ||
117 | { | ||
118 | Mesh mesh = new Mesh(); | ||
119 | Triangle tri = new Triangle( | ||
120 | new Axiom.MathLib.Vector3(0.0f, 1.0f, 1.0f), | ||
121 | new Axiom.MathLib.Vector3(1.0f, 0.0f, 1.0f), | ||
122 | new Axiom.MathLib.Vector3(1.0f, 1.0f, 0.0f)); | ||
123 | |||
124 | mesh.AddTri(tri); | ||
125 | mesh += base.getMesh(); | ||
126 | |||
127 | return mesh; | ||
128 | } | ||
129 | |||
130 | public byte[] GetByteArray() | ||
131 | { | ||
132 | return this.primData.ToBytes(); | ||
133 | } | ||
134 | |||
135 | public void GetProperites(ClientView client) | ||
136 | { | ||
137 | ObjectPropertiesPacket proper = new ObjectPropertiesPacket(); | ||
138 | proper.ObjectData = new ObjectPropertiesPacket.ObjectDataBlock[1]; | ||
139 | proper.ObjectData[0] = new ObjectPropertiesPacket.ObjectDataBlock(); | ||
140 | proper.ObjectData[0].ItemID = LLUUID.Zero; // this.uuid; | ||
141 | proper.ObjectData[0].CreationDate = (ulong) this.primData.CreationDate; | ||
142 | proper.ObjectData[0].CreatorID = this.primData.OwnerID; | ||
143 | proper.ObjectData[0].FolderID = LLUUID.Zero; | ||
144 | proper.ObjectData[0].FromTaskID = LLUUID.Zero; | ||
145 | proper.ObjectData[0].GroupID = LLUUID.Zero; | ||
146 | proper.ObjectData[0].InventorySerial = 0; | ||
147 | proper.ObjectData[0].LastOwnerID = LLUUID.Zero; | ||
148 | proper.ObjectData[0].ObjectID = this.uuid; | ||
149 | proper.ObjectData[0].OwnerID = primData.OwnerID; | ||
150 | proper.ObjectData[0].TouchName = new byte[0]; | ||
151 | proper.ObjectData[0].TextureID = new byte[0]; | ||
152 | proper.ObjectData[0].SitName = new byte[0]; | ||
153 | proper.ObjectData[0].Name = new byte[0]; | ||
154 | proper.ObjectData[0].Description = new byte[0]; | ||
155 | proper.ObjectData[0].OwnerMask = this.primData.OwnerMask; | ||
156 | proper.ObjectData[0].NextOwnerMask = this.primData.NextOwnerMask; | ||
157 | proper.ObjectData[0].GroupMask = this.primData.GroupMask; | ||
158 | proper.ObjectData[0].EveryoneMask = this.primData.EveryoneMask; | ||
159 | proper.ObjectData[0].BaseMask = this.primData.BaseMask; | ||
160 | |||
161 | client.OutPacket(proper); | ||
162 | } | ||
163 | |||
164 | public void UpdatePosition(LLVector3 pos) | ||
165 | { | ||
166 | this.Pos = pos; | ||
167 | if (this._physActor != null) // && this.physicsEnabled) | ||
168 | { | ||
169 | try | ||
170 | { | ||
171 | lock (m_world.LockPhysicsEngine) | ||
172 | { | ||
173 | this._physActor.Position = new PhysicsVector(pos.X, pos.Y, pos.Z); | ||
174 | } | ||
175 | } | ||
176 | catch (Exception e) | ||
177 | { | ||
178 | Console.WriteLine(e.Message); | ||
179 | } | ||
180 | } | ||
181 | this.updateFlag = true; | ||
182 | } | ||
183 | |||
184 | public override void update() | ||
185 | { | ||
186 | LLVector3 pos2 = new LLVector3(0, 0, 0); | ||
187 | if (this._physActor != null && this.physicsEnabled) | ||
188 | { | ||
189 | |||
190 | PhysicsVector pPos = this._physActor.Position; | ||
191 | pos2 = new LLVector3(pPos.X, pPos.Y, pPos.Z); | ||
192 | } | ||
193 | if (this.newPrimFlag) | ||
194 | { | ||
195 | foreach (ClientView client in m_clientThreads.Values) | ||
196 | { | ||
197 | client.OutPacket(OurPacket); | ||
198 | } | ||
199 | this.newPrimFlag = false; | ||
200 | } | ||
201 | else if (this.updateFlag) | ||
202 | { | ||
203 | ImprovedTerseObjectUpdatePacket terse = new ImprovedTerseObjectUpdatePacket(); | ||
204 | terse.RegionData.RegionHandle = m_regionHandle; // FIXME | ||
205 | terse.RegionData.TimeDilation = 64096; | ||
206 | terse.ObjectData = new ImprovedTerseObjectUpdatePacket.ObjectDataBlock[1]; | ||
207 | terse.ObjectData[0] = this.CreateImprovedBlock(); | ||
208 | foreach (ClientView client in m_clientThreads.Values) | ||
209 | { | ||
210 | client.OutPacket(terse); | ||
211 | } | ||
212 | this.updateFlag = false; | ||
213 | } | ||
214 | else if (this.dirtyFlag) | ||
215 | { | ||
216 | foreach (ClientView client in m_clientThreads.Values) | ||
217 | { | ||
218 | UpdateClient(client); | ||
219 | } | ||
220 | this.dirtyFlag = false; | ||
221 | } | ||
222 | else | ||
223 | { | ||
224 | if (this._physActor != null && this.physicsEnabled) | ||
225 | { | ||
226 | if (pos2 != this.positionLastFrame) | ||
227 | { | ||
228 | ImprovedTerseObjectUpdatePacket terse = new ImprovedTerseObjectUpdatePacket(); | ||
229 | terse.RegionData.RegionHandle = m_regionHandle; // FIXME | ||
230 | terse.RegionData.TimeDilation = 64096; | ||
231 | terse.ObjectData = new ImprovedTerseObjectUpdatePacket.ObjectDataBlock[1]; | ||
232 | terse.ObjectData[0] = this.CreateImprovedBlock(); | ||
233 | foreach (ClientView client in m_clientThreads.Values) | ||
234 | { | ||
235 | client.OutPacket(terse); | ||
236 | } | ||
237 | } | ||
238 | this.positionLastFrame = pos2; | ||
239 | } | ||
240 | } | ||
241 | |||
242 | if (this.physicstest) | ||
243 | { | ||
244 | LLVector3 pos = this.Pos; | ||
245 | pos.Z += 0.0001f; | ||
246 | this.UpdatePosition(pos); | ||
247 | this.physicstest = false; | ||
248 | } | ||
249 | } | ||
250 | |||
251 | public void UpdateClient(ClientView RemoteClient) | ||
252 | { | ||
253 | |||
254 | LLVector3 lPos; | ||
255 | if (this._physActor != null && this.physicsEnabled) | ||
256 | { | ||
257 | PhysicsVector pPos = this._physActor.Position; | ||
258 | lPos = new LLVector3(pPos.X, pPos.Y, pPos.Z); | ||
259 | } | ||
260 | else | ||
261 | { | ||
262 | lPos = this.Pos; | ||
263 | } | ||
264 | byte[] pb = lPos.GetBytes(); | ||
265 | Array.Copy(pb, 0, OurPacket.ObjectData[0].ObjectData, 0, pb.Length); | ||
266 | |||
267 | // OurPacket should be update with the follwing in updateShape() rather than having to do it here | ||
268 | OurPacket.ObjectData[0].OwnerID = this.primData.OwnerID; | ||
269 | OurPacket.ObjectData[0].PCode = this.primData.PCode; | ||
270 | OurPacket.ObjectData[0].PathBegin = this.primData.PathBegin; | ||
271 | OurPacket.ObjectData[0].PathEnd = this.primData.PathEnd; | ||
272 | OurPacket.ObjectData[0].PathScaleX = this.primData.PathScaleX; | ||
273 | OurPacket.ObjectData[0].PathScaleY = this.primData.PathScaleY; | ||
274 | OurPacket.ObjectData[0].PathShearX = this.primData.PathShearX; | ||
275 | OurPacket.ObjectData[0].PathShearY = this.primData.PathShearY; | ||
276 | OurPacket.ObjectData[0].PathSkew = this.primData.PathSkew; | ||
277 | OurPacket.ObjectData[0].ProfileBegin = this.primData.ProfileBegin; | ||
278 | OurPacket.ObjectData[0].ProfileEnd = this.primData.ProfileEnd; | ||
279 | OurPacket.ObjectData[0].Scale = this.primData.Scale; | ||
280 | OurPacket.ObjectData[0].PathCurve = this.primData.PathCurve; | ||
281 | OurPacket.ObjectData[0].ProfileCurve = this.primData.ProfileCurve; | ||
282 | OurPacket.ObjectData[0].ParentID = this.primData.ParentID ; | ||
283 | OurPacket.ObjectData[0].ProfileHollow = this.primData.ProfileHollow; | ||
284 | //finish off copying rest of shape data | ||
285 | OurPacket.ObjectData[0].PathRadiusOffset = this.primData.PathRadiusOffset; | ||
286 | OurPacket.ObjectData[0].PathRevolutions = this.primData.PathRevolutions; | ||
287 | OurPacket.ObjectData[0].PathTaperX = this.primData.PathTaperX; | ||
288 | OurPacket.ObjectData[0].PathTaperY = this.primData.PathTaperY; | ||
289 | OurPacket.ObjectData[0].PathTwist = this.primData.PathTwist; | ||
290 | OurPacket.ObjectData[0].PathTwistBegin = this.primData.PathTwistBegin; | ||
291 | |||
292 | RemoteClient.OutPacket(OurPacket); | ||
293 | } | ||
294 | |||
295 | public void UpdateShape(ObjectShapePacket.ObjectDataBlock addPacket) | ||
296 | { | ||
297 | this.primData.PathBegin = addPacket.PathBegin; | ||
298 | this.primData.PathEnd = addPacket.PathEnd; | ||
299 | this.primData.PathScaleX = addPacket.PathScaleX; | ||
300 | this.primData.PathScaleY = addPacket.PathScaleY; | ||
301 | this.primData.PathShearX = addPacket.PathShearX; | ||
302 | this.primData.PathShearY = addPacket.PathShearY; | ||
303 | this.primData.PathSkew = addPacket.PathSkew; | ||
304 | this.primData.ProfileBegin = addPacket.ProfileBegin; | ||
305 | this.primData.ProfileEnd = addPacket.ProfileEnd; | ||
306 | this.primData.PathCurve = addPacket.PathCurve; | ||
307 | this.primData.ProfileCurve = addPacket.ProfileCurve; | ||
308 | this.primData.ProfileHollow = addPacket.ProfileHollow; | ||
309 | this.primData.PathRadiusOffset = addPacket.PathRadiusOffset; | ||
310 | this.primData.PathRevolutions = addPacket.PathRevolutions; | ||
311 | this.primData.PathTaperX = addPacket.PathTaperX; | ||
312 | this.primData.PathTaperY = addPacket.PathTaperY; | ||
313 | this.primData.PathTwist = addPacket.PathTwist; | ||
314 | this.primData.PathTwistBegin = addPacket.PathTwistBegin; | ||
315 | this.dirtyFlag = true; | ||
316 | } | ||
317 | |||
318 | public void UpdateTexture(byte[] tex) | ||
319 | { | ||
320 | this.OurPacket.ObjectData[0].TextureEntry = tex; | ||
321 | this.primData.Texture = tex; | ||
322 | this.dirtyFlag = true; | ||
323 | } | ||
324 | |||
325 | public void UpdateObjectFlags(ObjectFlagUpdatePacket pack) | ||
326 | { | ||
327 | if (this._physActor != null) | ||
328 | { | ||
329 | if (this._physActor.Kinematic == pack.AgentData.UsePhysics) | ||
330 | { | ||
331 | this._physActor.Kinematic = !pack.AgentData.UsePhysics; //if Usephysics = true, then Kinematic should = false | ||
332 | } | ||
333 | this.physicsEnabled = pack.AgentData.UsePhysics; | ||
334 | if (this._physActor.Kinematic == false) | ||
335 | { | ||
336 | LLVector3 pos = this.Pos; | ||
337 | this.UpdatePosition(pos); | ||
338 | pos.Z += 0.000001f; | ||
339 | this.UpdatePosition(pos); | ||
340 | this.physicstest = true; | ||
341 | } | ||
342 | else | ||
343 | { | ||
344 | PhysicsVector vec = this._physActor.Position; | ||
345 | LLVector3 pos = new LLVector3(vec.X, vec.Y, vec.Z); | ||
346 | this.Pos = pos; | ||
347 | this.updateFlag = true; | ||
348 | } | ||
349 | } | ||
350 | } | ||
351 | |||
352 | public void MakeParent(Primitive prim) | ||
353 | { | ||
354 | this.primData.ParentID = prim.localid; | ||
355 | this.Pos -= prim.Pos; | ||
356 | this.dirtyFlag = true; | ||
357 | } | ||
358 | |||
359 | public void CreateFromPacket(ObjectAddPacket addPacket, LLUUID ownerID, uint localID) | ||
360 | { | ||
361 | ObjectUpdatePacket objupdate = new ObjectUpdatePacket(); | ||
362 | objupdate.RegionData.RegionHandle = m_regionHandle; | ||
363 | objupdate.RegionData.TimeDilation = 64096; | ||
364 | |||
365 | objupdate.ObjectData = new libsecondlife.Packets.ObjectUpdatePacket.ObjectDataBlock[1]; | ||
366 | PrimData PData = new PrimData(); | ||
367 | this.primData = PData; | ||
368 | this.primData.CreationDate = (Int32)(DateTime.UtcNow - new DateTime(1970, 1, 1)).TotalSeconds; | ||
369 | |||
370 | objupdate.ObjectData[0] = new ObjectUpdatePacket.ObjectDataBlock(); | ||
371 | objupdate.ObjectData[0].PSBlock = new byte[0]; | ||
372 | objupdate.ObjectData[0].ExtraParams = new byte[1]; | ||
373 | objupdate.ObjectData[0].MediaURL = new byte[0]; | ||
374 | objupdate.ObjectData[0].NameValue = new byte[0]; | ||
375 | objupdate.ObjectData[0].Text = new byte[0]; | ||
376 | objupdate.ObjectData[0].TextColor = new byte[4]; | ||
377 | objupdate.ObjectData[0].JointAxisOrAnchor = new LLVector3(0, 0, 0); | ||
378 | objupdate.ObjectData[0].JointPivot = new LLVector3(0, 0, 0); | ||
379 | objupdate.ObjectData[0].Material = 3; | ||
380 | objupdate.ObjectData[0].UpdateFlags = 32 + 65536 + 131072 + 256 + 4 + 8 + 2048 + 524288 + 268435456; | ||
381 | objupdate.ObjectData[0].TextureAnim = new byte[0]; | ||
382 | objupdate.ObjectData[0].Sound = LLUUID.Zero; | ||
383 | LLObject.TextureEntry ntex = new LLObject.TextureEntry(new LLUUID("00000000-0000-0000-5005-000000000005")); | ||
384 | this.primData.Texture = objupdate.ObjectData[0].TextureEntry = ntex.ToBytes(); | ||
385 | objupdate.ObjectData[0].State = 0; | ||
386 | objupdate.ObjectData[0].Data = new byte[0]; | ||
387 | PData.OwnerID = objupdate.ObjectData[0].OwnerID = ownerID; | ||
388 | PData.PCode = objupdate.ObjectData[0].PCode = addPacket.ObjectData.PCode; | ||
389 | PData.PathBegin = objupdate.ObjectData[0].PathBegin = addPacket.ObjectData.PathBegin; | ||
390 | PData.PathEnd = objupdate.ObjectData[0].PathEnd = addPacket.ObjectData.PathEnd; | ||
391 | PData.PathScaleX = objupdate.ObjectData[0].PathScaleX = addPacket.ObjectData.PathScaleX; | ||
392 | PData.PathScaleY = objupdate.ObjectData[0].PathScaleY = addPacket.ObjectData.PathScaleY; | ||
393 | PData.PathShearX = objupdate.ObjectData[0].PathShearX = addPacket.ObjectData.PathShearX; | ||
394 | PData.PathShearY = objupdate.ObjectData[0].PathShearY = addPacket.ObjectData.PathShearY; | ||
395 | PData.PathSkew = objupdate.ObjectData[0].PathSkew = addPacket.ObjectData.PathSkew; | ||
396 | PData.ProfileBegin = objupdate.ObjectData[0].ProfileBegin = addPacket.ObjectData.ProfileBegin; | ||
397 | PData.ProfileEnd = objupdate.ObjectData[0].ProfileEnd = addPacket.ObjectData.ProfileEnd; | ||
398 | PData.Scale = objupdate.ObjectData[0].Scale = addPacket.ObjectData.Scale; | ||
399 | PData.PathCurve = objupdate.ObjectData[0].PathCurve = addPacket.ObjectData.PathCurve; | ||
400 | PData.ProfileCurve = objupdate.ObjectData[0].ProfileCurve = addPacket.ObjectData.ProfileCurve; | ||
401 | PData.ParentID = objupdate.ObjectData[0].ParentID = 0; | ||
402 | PData.ProfileHollow = objupdate.ObjectData[0].ProfileHollow = addPacket.ObjectData.ProfileHollow; | ||
403 | PData.PathRadiusOffset = objupdate.ObjectData[0].PathRadiusOffset = addPacket.ObjectData.PathRadiusOffset; | ||
404 | PData.PathRevolutions = objupdate.ObjectData[0].PathRevolutions = addPacket.ObjectData.PathRevolutions; | ||
405 | PData.PathTaperX = objupdate.ObjectData[0].PathTaperX = addPacket.ObjectData.PathTaperX; | ||
406 | PData.PathTaperY = objupdate.ObjectData[0].PathTaperY = addPacket.ObjectData.PathTaperY; | ||
407 | PData.PathTwist = objupdate.ObjectData[0].PathTwist = addPacket.ObjectData.PathTwist; | ||
408 | PData.PathTwistBegin = objupdate.ObjectData[0].PathTwistBegin = addPacket.ObjectData.PathTwistBegin; | ||
409 | |||
410 | objupdate.ObjectData[0].ID = (uint)(localID); | ||
411 | objupdate.ObjectData[0].FullID = new LLUUID("edba7151-5857-acc5-b30b-f01efef" + (localID - 702000).ToString("00000")); | ||
412 | objupdate.ObjectData[0].ObjectData = new byte[60]; | ||
413 | objupdate.ObjectData[0].ObjectData[46] = 128; | ||
414 | objupdate.ObjectData[0].ObjectData[47] = 63; | ||
415 | LLVector3 pos1 = addPacket.ObjectData.RayEnd; | ||
416 | //update position | ||
417 | byte[] pb = pos1.GetBytes(); | ||
418 | Array.Copy(pb, 0, objupdate.ObjectData[0].ObjectData, 0, pb.Length); | ||
419 | this.newPrimFlag = true; | ||
420 | this.primData.FullID = this.uuid = objupdate.ObjectData[0].FullID; | ||
421 | this.localid = objupdate.ObjectData[0].ID; | ||
422 | this.primData.Position = this.Pos = pos1; | ||
423 | this.OurPacket = objupdate; | ||
424 | } | ||
425 | |||
426 | public void CreateFromStorage(PrimData store) | ||
427 | { | ||
428 | this.CreateFromStorage(store, store.Position, store.LocalID, false); | ||
429 | } | ||
430 | |||
431 | public void CreateFromStorage(PrimData store, LLVector3 posi, uint localID, bool newprim) | ||
432 | { | ||
433 | //need to clean this up as it shares a lot of code with CreateFromPacket() | ||
434 | ObjectUpdatePacket objupdate = new ObjectUpdatePacket(); | ||
435 | objupdate.RegionData.RegionHandle = m_regionHandle; | ||
436 | objupdate.RegionData.TimeDilation = 64096; | ||
437 | objupdate.ObjectData = new libsecondlife.Packets.ObjectUpdatePacket.ObjectDataBlock[1]; | ||
438 | |||
439 | this.primData = store; | ||
440 | objupdate.ObjectData[0] = new ObjectUpdatePacket.ObjectDataBlock(); | ||
441 | objupdate.ObjectData[0].PSBlock = new byte[0]; | ||
442 | objupdate.ObjectData[0].ExtraParams = new byte[1]; | ||
443 | objupdate.ObjectData[0].MediaURL = new byte[0]; | ||
444 | objupdate.ObjectData[0].NameValue = new byte[0]; | ||
445 | objupdate.ObjectData[0].Text = new byte[0]; | ||
446 | objupdate.ObjectData[0].TextColor = new byte[4]; | ||
447 | objupdate.ObjectData[0].JointAxisOrAnchor = new LLVector3(0, 0, 0); | ||
448 | objupdate.ObjectData[0].JointPivot = new LLVector3(0, 0, 0); | ||
449 | objupdate.ObjectData[0].Material = 3; | ||
450 | objupdate.ObjectData[0].UpdateFlags = 32 + 65536 + 131072 + 256 + 4 + 8 + 2048 + 524288 + 268435456; | ||
451 | objupdate.ObjectData[0].TextureAnim = new byte[0]; | ||
452 | objupdate.ObjectData[0].Sound = LLUUID.Zero; | ||
453 | |||
454 | if (store.Texture == null) | ||
455 | { | ||
456 | LLObject.TextureEntry ntex = new LLObject.TextureEntry(new LLUUID("00000000-0000-0000-5005-000000000005")); | ||
457 | objupdate.ObjectData[0].TextureEntry = ntex.ToBytes(); | ||
458 | } | ||
459 | else | ||
460 | { | ||
461 | objupdate.ObjectData[0].TextureEntry = store.Texture; | ||
462 | } | ||
463 | |||
464 | objupdate.ObjectData[0].State = 0; | ||
465 | objupdate.ObjectData[0].Data = new byte[0]; | ||
466 | objupdate.ObjectData[0].OwnerID = this.primData.OwnerID; | ||
467 | objupdate.ObjectData[0].PCode = this.primData.PCode; | ||
468 | objupdate.ObjectData[0].PathBegin = this.primData.PathBegin; | ||
469 | objupdate.ObjectData[0].PathEnd = this.primData.PathEnd; | ||
470 | objupdate.ObjectData[0].PathScaleX = this.primData.PathScaleX; | ||
471 | objupdate.ObjectData[0].PathScaleY = this.primData.PathScaleY; | ||
472 | objupdate.ObjectData[0].PathShearX = this.primData.PathShearX; | ||
473 | objupdate.ObjectData[0].PathShearY = this.primData.PathShearY; | ||
474 | objupdate.ObjectData[0].PathSkew = this.primData.PathSkew; | ||
475 | objupdate.ObjectData[0].ProfileBegin = this.primData.ProfileBegin; | ||
476 | objupdate.ObjectData[0].ProfileEnd = this.primData.ProfileEnd; | ||
477 | objupdate.ObjectData[0].Scale = this.primData.Scale; | ||
478 | objupdate.ObjectData[0].PathCurve = this.primData.PathCurve; | ||
479 | objupdate.ObjectData[0].ProfileCurve = this.primData.ProfileCurve; | ||
480 | objupdate.ObjectData[0].ParentID = 0; | ||
481 | objupdate.ObjectData[0].ProfileHollow = this.primData.ProfileHollow; | ||
482 | //finish off copying rest of shape data | ||
483 | objupdate.ObjectData[0].PathRadiusOffset = this.primData.PathRadiusOffset; | ||
484 | objupdate.ObjectData[0].PathRevolutions = this.primData.PathRevolutions; | ||
485 | objupdate.ObjectData[0].PathTaperX = this.primData.PathTaperX; | ||
486 | objupdate.ObjectData[0].PathTaperY = this.primData.PathTaperY; | ||
487 | objupdate.ObjectData[0].PathTwist = this.primData.PathTwist; | ||
488 | objupdate.ObjectData[0].PathTwistBegin = this.primData.PathTwistBegin; | ||
489 | |||
490 | objupdate.ObjectData[0].ID = localID; // (uint)store.LocalID; | ||
491 | objupdate.ObjectData[0].FullID = store.FullID; | ||
492 | |||
493 | objupdate.ObjectData[0].ObjectData = new byte[60]; | ||
494 | objupdate.ObjectData[0].ObjectData[46] = 128; | ||
495 | objupdate.ObjectData[0].ObjectData[47] = 63; | ||
496 | LLVector3 pos1 = posi; // store.Position; | ||
497 | //update position | ||
498 | byte[] pb = pos1.GetBytes(); | ||
499 | Array.Copy(pb, 0, objupdate.ObjectData[0].ObjectData, 0, pb.Length); | ||
500 | |||
501 | this.uuid = objupdate.ObjectData[0].FullID; | ||
502 | this.localid = objupdate.ObjectData[0].ID; | ||
503 | this.Pos = pos1; | ||
504 | this.OurPacket = objupdate; | ||
505 | if (newprim) | ||
506 | { | ||
507 | this.newPrimFlag = true; | ||
508 | } | ||
509 | } | ||
510 | |||
511 | public ImprovedTerseObjectUpdatePacket.ObjectDataBlock CreateImprovedBlock() | ||
512 | { | ||
513 | uint ID = this.localid; | ||
514 | byte[] bytes = new byte[60]; | ||
515 | |||
516 | int i = 0; | ||
517 | ImprovedTerseObjectUpdatePacket.ObjectDataBlock dat = new ImprovedTerseObjectUpdatePacket.ObjectDataBlock(); | ||
518 | //dat.TextureEntry = this.OurPacket.ObjectData[0].TextureEntry; | ||
519 | dat.TextureEntry = new byte[0]; | ||
520 | bytes[i++] = (byte)(ID % 256); | ||
521 | bytes[i++] = (byte)((ID >> 8) % 256); | ||
522 | bytes[i++] = (byte)((ID >> 16) % 256); | ||
523 | bytes[i++] = (byte)((ID >> 24) % 256); | ||
524 | bytes[i++] = 0; | ||
525 | bytes[i++] = 0; | ||
526 | |||
527 | LLVector3 lPos; | ||
528 | Axiom.MathLib.Quaternion lRot; | ||
529 | if (this._physActor != null && this.physicsEnabled) | ||
530 | { | ||
531 | PhysicsVector pPos = this._physActor.Position; | ||
532 | lPos = new LLVector3(pPos.X, pPos.Y, pPos.Z); | ||
533 | lRot = this._physActor.Orientation; | ||
534 | } | ||
535 | else | ||
536 | { | ||
537 | lPos = this.Pos; | ||
538 | lRot = this.rotation; | ||
539 | } | ||
540 | byte[] pb = lPos.GetBytes(); | ||
541 | Array.Copy(pb, 0, bytes, i, pb.Length); | ||
542 | i += 12; | ||
543 | ushort ac = 32767; | ||
544 | |||
545 | //vel | ||
546 | bytes[i++] = (byte)(ac % 256); | ||
547 | bytes[i++] = (byte)((ac >> 8) % 256); | ||
548 | bytes[i++] = (byte)(ac % 256); | ||
549 | bytes[i++] = (byte)((ac >> 8) % 256); | ||
550 | bytes[i++] = (byte)(ac % 256); | ||
551 | bytes[i++] = (byte)((ac >> 8) % 256); | ||
552 | |||
553 | //accel | ||
554 | bytes[i++] = (byte)(ac % 256); | ||
555 | bytes[i++] = (byte)((ac >> 8) % 256); | ||
556 | bytes[i++] = (byte)(ac % 256); | ||
557 | bytes[i++] = (byte)((ac >> 8) % 256); | ||
558 | bytes[i++] = (byte)(ac % 256); | ||
559 | bytes[i++] = (byte)((ac >> 8) % 256); | ||
560 | |||
561 | ushort rw, rx, ry, rz; | ||
562 | rw = (ushort)(32768 * (lRot.w + 1)); | ||
563 | rx = (ushort)(32768 * (lRot.x + 1)); | ||
564 | ry = (ushort)(32768 * (lRot.y + 1)); | ||
565 | rz = (ushort)(32768 * (lRot.z + 1)); | ||
566 | |||
567 | //rot | ||
568 | bytes[i++] = (byte)(rx % 256); | ||
569 | bytes[i++] = (byte)((rx >> 8) % 256); | ||
570 | bytes[i++] = (byte)(ry % 256); | ||
571 | bytes[i++] = (byte)((ry >> 8) % 256); | ||
572 | bytes[i++] = (byte)(rz % 256); | ||
573 | bytes[i++] = (byte)((rz >> 8) % 256); | ||
574 | bytes[i++] = (byte)(rw % 256); | ||
575 | bytes[i++] = (byte)((rw >> 8) % 256); | ||
576 | |||
577 | //rotation vel | ||
578 | bytes[i++] = (byte)(ac % 256); | ||
579 | bytes[i++] = (byte)((ac >> 8) % 256); | ||
580 | bytes[i++] = (byte)(ac % 256); | ||
581 | bytes[i++] = (byte)((ac >> 8) % 256); | ||
582 | bytes[i++] = (byte)(ac % 256); | ||
583 | bytes[i++] = (byte)((ac >> 8) % 256); | ||
584 | |||
585 | dat.Data = bytes; | ||
586 | return dat; | ||
587 | } | ||
588 | |||
589 | public override void BackUp() | ||
590 | { | ||
591 | this.primData.FullID = this.uuid; | ||
592 | this.primData.LocalID = this.localid; | ||
593 | this.primData.Position = this.Pos; | ||
594 | this.primData.Rotation = new LLQuaternion(this.rotation.x, this.rotation.y, this.rotation.z, this.rotation.w); | ||
595 | this.m_world.localStorage.StorePrim(this.primData); | ||
596 | } | ||
597 | } | ||
598 | } | ||