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
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
|
using System;
using System.Collections.Generic;
using System.Text;
using OpenSim.types;
using libsecondlife;
using libsecondlife.Packets;
using OpenSim.Framework.Interfaces;
using OpenSim.Physics.Manager;
using OpenSim.Framework.Assets;
namespace OpenSim.world
{
public class Primitive : Entity
{
protected float mesh_cutbegin;
protected float mesh_cutend;
protected PrimData primData;
protected bool newPrimFlag = false;
protected bool updateFlag = false;
protected bool dirtyFlag = false;
private ObjectUpdatePacket OurPacket;
private PhysicsActor _physActor;
private bool physicsEnabled = false;
private bool physicstest = false; //just added for testing
public bool PhysicsEnabled
{
get
{
return physicsEnabled;
}
set
{
physicsEnabled = value;
}
}
public bool UpdateFlag
{
get
{
return updateFlag;
}
set
{
updateFlag = value;
}
}
public LLVector3 Scale
{
set
{
this.primData.Scale = value;
this.dirtyFlag = true;
}
get
{
return this.primData.Scale;
}
}
public PhysicsActor PhysActor
{
set
{
this._physActor = value;
}
}
public Primitive()
{
mesh_cutbegin = 0.0f;
mesh_cutend = 1.0f;
}
public override Mesh getMesh()
{
Mesh mesh = new Mesh();
Triangle tri = new Triangle(
new Axiom.MathLib.Vector3(0.0f, 1.0f, 1.0f),
new Axiom.MathLib.Vector3(1.0f, 0.0f, 1.0f),
new Axiom.MathLib.Vector3(1.0f, 1.0f, 0.0f));
mesh.AddTri(tri);
mesh += base.getMesh();
return mesh;
}
public void UpdatePosition(LLVector3 pos)
{
this.position = pos;
if (this._physActor != null) // && this.physicsEnabled)
{
this._physActor.Position = new PhysicsVector(pos.X, pos.Y, pos.Z);
}
this.updateFlag = true;
}
public override void update()
{
if (this.newPrimFlag)
{
foreach (SimClient client in OpenSimRoot.Instance.ClientThreads.Values)
{
client.OutPacket(OurPacket);
}
this.newPrimFlag = false;
}
else if (this.updateFlag)
{
ImprovedTerseObjectUpdatePacket terse = new ImprovedTerseObjectUpdatePacket();
terse.RegionData.RegionHandle = OpenSimRoot.Instance.Cfg.RegionHandle; // FIXME
terse.RegionData.TimeDilation = 64096;
terse.ObjectData = new ImprovedTerseObjectUpdatePacket.ObjectDataBlock[1];
terse.ObjectData[0] = this.CreateImprovedBlock();
foreach (SimClient client in OpenSimRoot.Instance.ClientThreads.Values)
{
client.OutPacket(terse);
}
this.updateFlag = false;
}
else if (this.dirtyFlag)
{
foreach (SimClient client in OpenSimRoot.Instance.ClientThreads.Values)
{
UpdateClient(client);
}
this.dirtyFlag = false;
}
else
{
if (this._physActor != null && this.physicsEnabled)
{
ImprovedTerseObjectUpdatePacket terse = new ImprovedTerseObjectUpdatePacket();
terse.RegionData.RegionHandle = OpenSimRoot.Instance.Cfg.RegionHandle; // FIXME
terse.RegionData.TimeDilation = 64096;
terse.ObjectData = new ImprovedTerseObjectUpdatePacket.ObjectDataBlock[1];
terse.ObjectData[0] = this.CreateImprovedBlock();
foreach (SimClient client in OpenSimRoot.Instance.ClientThreads.Values)
{
client.OutPacket(terse);
}
}
}
if (this.physicstest)
{
LLVector3 pos = this.position;
pos.Z += 0.0001f;
this.UpdatePosition(pos);
this.physicstest = false;
}
}
public void UpdateClient(SimClient RemoteClient)
{
LLVector3 lPos;
if (this._physActor != null && this.physicsEnabled)
{
PhysicsVector pPos = this._physActor.Position;
lPos = new LLVector3(pPos.X, pPos.Y, pPos.Z);
}
else
{
lPos = this.position;
}
byte[] pb = lPos.GetBytes();
Array.Copy(pb, 0, OurPacket.ObjectData[0].ObjectData, 0, pb.Length);
// OurPacket should be update with the follwing in updateShape() rather than having to do it here
OurPacket.ObjectData[0].OwnerID = this.primData.OwnerID;
OurPacket.ObjectData[0].PCode = this.primData.PCode;
OurPacket.ObjectData[0].PathBegin = this.primData.PathBegin;
OurPacket.ObjectData[0].PathEnd = this.primData.PathEnd;
OurPacket.ObjectData[0].PathScaleX = this.primData.PathScaleX;
OurPacket.ObjectData[0].PathScaleY = this.primData.PathScaleY;
OurPacket.ObjectData[0].PathShearX = this.primData.PathShearX;
OurPacket.ObjectData[0].PathShearY = this.primData.PathShearY;
OurPacket.ObjectData[0].PathSkew = this.primData.PathSkew;
OurPacket.ObjectData[0].ProfileBegin = this.primData.ProfileBegin;
OurPacket.ObjectData[0].ProfileEnd = this.primData.ProfileEnd;
OurPacket.ObjectData[0].Scale = this.primData.Scale;
OurPacket.ObjectData[0].PathCurve = this.primData.PathCurve;
OurPacket.ObjectData[0].ProfileCurve = this.primData.ProfileCurve;
OurPacket.ObjectData[0].ParentID = 0;
OurPacket.ObjectData[0].ProfileHollow = this.primData.ProfileHollow;
//finish off copying rest of shape data
OurPacket.ObjectData[0].PathRadiusOffset = this.primData.PathRadiusOffset;
OurPacket.ObjectData[0].PathRevolutions = this.primData.PathRevolutions;
OurPacket.ObjectData[0].PathTaperX = this.primData.PathTaperX;
OurPacket.ObjectData[0].PathTaperY = this.primData.PathTaperY;
OurPacket.ObjectData[0].PathTwist = this.primData.PathTwist;
OurPacket.ObjectData[0].PathTwistBegin = this.primData.PathTwistBegin;
RemoteClient.OutPacket(OurPacket);
}
public void UpdateShape(ObjectShapePacket.ObjectDataBlock addPacket)
{
this.primData.PathBegin = addPacket.PathBegin;
this.primData.PathEnd = addPacket.PathEnd;
this.primData.PathScaleX = addPacket.PathScaleX;
this.primData.PathScaleY = addPacket.PathScaleY;
this.primData.PathShearX = addPacket.PathShearX;
this.primData.PathShearY = addPacket.PathShearY;
this.primData.PathSkew = addPacket.PathSkew;
this.primData.ProfileBegin = addPacket.ProfileBegin;
this.primData.ProfileEnd = addPacket.ProfileEnd;
this.primData.PathCurve = addPacket.PathCurve;
this.primData.ProfileCurve = addPacket.ProfileCurve;
this.primData.ProfileHollow = addPacket.ProfileHollow;
this.primData.PathRadiusOffset = addPacket.PathRadiusOffset;
this.primData.PathRevolutions = addPacket.PathRevolutions;
this.primData.PathTaperX = addPacket.PathTaperX;
this.primData.PathTaperY = addPacket.PathTaperY;
this.primData.PathTwist = addPacket.PathTwist;
this.primData.PathTwistBegin = addPacket.PathTwistBegin;
this.dirtyFlag = true;
}
public void UpdateTexture(byte[] tex)
{
this.primData.Texture = this.OurPacket.ObjectData[0].TextureEntry = tex;
this.dirtyFlag = true;
}
public void UpdateObjectFlags(ObjectFlagUpdatePacket pack)
{
if (this._physActor != null)
{
if (this._physActor.Kinematic == pack.AgentData.UsePhysics)
{
this._physActor.Kinematic = !pack.AgentData.UsePhysics; //if Usephysics = true, then Kinematic should = false
}
this.physicsEnabled = pack.AgentData.UsePhysics;
if (this._physActor.Kinematic == false)
{
LLVector3 pos = this.position;
this.UpdatePosition(pos);
pos.Z += 0.000001f;
this.UpdatePosition(pos);
this.physicstest = true;
}
else
{
PhysicsVector vec = this._physActor.Position;
LLVector3 pos = new LLVector3(vec.X, vec.Y, vec.Z);
this.position = pos;
this.updateFlag = true;
}
}
}
public void CreateFromPacket(ObjectAddPacket addPacket, LLUUID agentID, uint localID)
{
ObjectUpdatePacket objupdate = new ObjectUpdatePacket();
objupdate.RegionData.RegionHandle = OpenSimRoot.Instance.Cfg.RegionHandle;
objupdate.RegionData.TimeDilation = 64096;
objupdate.ObjectData = new libsecondlife.Packets.ObjectUpdatePacket.ObjectDataBlock[1];
PrimData PData = new PrimData();
this.primData = PData;
objupdate.ObjectData[0] = new ObjectUpdatePacket.ObjectDataBlock();
objupdate.ObjectData[0].PSBlock = new byte[0];
objupdate.ObjectData[0].ExtraParams = new byte[1];
objupdate.ObjectData[0].MediaURL = new byte[0];
objupdate.ObjectData[0].NameValue = new byte[0];
objupdate.ObjectData[0].Text = new byte[0];
objupdate.ObjectData[0].TextColor = new byte[4];
objupdate.ObjectData[0].JointAxisOrAnchor = new LLVector3(0, 0, 0);
objupdate.ObjectData[0].JointPivot = new LLVector3(0, 0, 0);
objupdate.ObjectData[0].Material = 3;
objupdate.ObjectData[0].UpdateFlags = 32 + 65536 + 131072 + 256 + 4 + 8 + 2048 + 524288 + 268435456;
objupdate.ObjectData[0].TextureAnim = new byte[0];
objupdate.ObjectData[0].Sound = LLUUID.Zero;
LLObject.TextureEntry ntex = new LLObject.TextureEntry(new LLUUID("00000000-0000-0000-5005-000000000005"));
objupdate.ObjectData[0].TextureEntry = ntex.ToBytes();
objupdate.ObjectData[0].State = 0;
objupdate.ObjectData[0].Data = new byte[0];
PData.OwnerID = objupdate.ObjectData[0].OwnerID = agentID;
PData.PCode = objupdate.ObjectData[0].PCode = addPacket.ObjectData.PCode;
PData.PathBegin = objupdate.ObjectData[0].PathBegin = addPacket.ObjectData.PathBegin;
PData.PathEnd = objupdate.ObjectData[0].PathEnd = addPacket.ObjectData.PathEnd;
PData.PathScaleX = objupdate.ObjectData[0].PathScaleX = addPacket.ObjectData.PathScaleX;
PData.PathScaleY = objupdate.ObjectData[0].PathScaleY = addPacket.ObjectData.PathScaleY;
PData.PathShearX = objupdate.ObjectData[0].PathShearX = addPacket.ObjectData.PathShearX;
PData.PathShearY = objupdate.ObjectData[0].PathShearY = addPacket.ObjectData.PathShearY;
PData.PathSkew = objupdate.ObjectData[0].PathSkew = addPacket.ObjectData.PathSkew;
PData.ProfileBegin = objupdate.ObjectData[0].ProfileBegin = addPacket.ObjectData.ProfileBegin;
PData.ProfileEnd = objupdate.ObjectData[0].ProfileEnd = addPacket.ObjectData.ProfileEnd;
PData.Scale = objupdate.ObjectData[0].Scale = addPacket.ObjectData.Scale;
PData.PathCurve = objupdate.ObjectData[0].PathCurve = addPacket.ObjectData.PathCurve;
PData.ProfileCurve = objupdate.ObjectData[0].ProfileCurve = addPacket.ObjectData.ProfileCurve;
PData.ParentID = objupdate.ObjectData[0].ParentID = 0;
PData.ProfileHollow = objupdate.ObjectData[0].ProfileHollow = addPacket.ObjectData.ProfileHollow;
PData.PathRadiusOffset = objupdate.ObjectData[0].PathRadiusOffset = addPacket.ObjectData.PathRadiusOffset;
PData.PathRevolutions = objupdate.ObjectData[0].PathRevolutions = addPacket.ObjectData.PathRevolutions;
PData.PathTaperX = objupdate.ObjectData[0].PathTaperX = addPacket.ObjectData.PathTaperX;
PData.PathTaperY = objupdate.ObjectData[0].PathTaperY = addPacket.ObjectData.PathTaperY;
PData.PathTwist = objupdate.ObjectData[0].PathTwist = addPacket.ObjectData.PathTwist;
PData.PathTwistBegin = objupdate.ObjectData[0].PathTwistBegin = addPacket.ObjectData.PathTwistBegin;
objupdate.ObjectData[0].ID = (uint)(localID);
objupdate.ObjectData[0].FullID = new LLUUID("edba7151-5857-acc5-b30b-f01efef" + (localID - 702000).ToString("00000"));
objupdate.ObjectData[0].ObjectData = new byte[60];
objupdate.ObjectData[0].ObjectData[46] = 128;
objupdate.ObjectData[0].ObjectData[47] = 63;
LLVector3 pos1 = addPacket.ObjectData.RayEnd;
//update position
byte[] pb = pos1.GetBytes();
Array.Copy(pb, 0, objupdate.ObjectData[0].ObjectData, 0, pb.Length);
this.newPrimFlag = true;
this.uuid = objupdate.ObjectData[0].FullID;
this.localid = objupdate.ObjectData[0].ID;
this.position = pos1;
this.OurPacket = objupdate;
}
public void CreateFromStorage(PrimData store)
{
//need to clean this up as it shares a lot of code with CreateFromPacket()
ObjectUpdatePacket objupdate = new ObjectUpdatePacket();
objupdate.RegionData.RegionHandle = OpenSimRoot.Instance.Cfg.RegionHandle;
objupdate.RegionData.TimeDilation = 64096;
objupdate.ObjectData = new libsecondlife.Packets.ObjectUpdatePacket.ObjectDataBlock[1];
this.primData = store;
objupdate.ObjectData[0] = new ObjectUpdatePacket.ObjectDataBlock();
objupdate.ObjectData[0].PSBlock = new byte[0];
objupdate.ObjectData[0].ExtraParams = new byte[1];
objupdate.ObjectData[0].MediaURL = new byte[0];
objupdate.ObjectData[0].NameValue = new byte[0];
objupdate.ObjectData[0].Text = new byte[0];
objupdate.ObjectData[0].TextColor = new byte[4];
objupdate.ObjectData[0].JointAxisOrAnchor = new LLVector3(0, 0, 0);
objupdate.ObjectData[0].JointPivot = new LLVector3(0, 0, 0);
objupdate.ObjectData[0].Material = 3;
objupdate.ObjectData[0].UpdateFlags = 32 + 65536 + 131072 + 256 + 4 + 8 + 2048 + 524288 + 268435456;
objupdate.ObjectData[0].TextureAnim = new byte[0];
objupdate.ObjectData[0].Sound = LLUUID.Zero;
if (store.Texture == null)
{
LLObject.TextureEntry ntex = new LLObject.TextureEntry(new LLUUID("00000000-0000-0000-5005-000000000005"));
objupdate.ObjectData[0].TextureEntry = ntex.ToBytes();
}
else
{
objupdate.ObjectData[0].TextureEntry = store.Texture;
}
objupdate.ObjectData[0].State = 0;
objupdate.ObjectData[0].Data = new byte[0];
objupdate.ObjectData[0].OwnerID = this.primData.OwnerID;
objupdate.ObjectData[0].PCode = this.primData.PCode;
objupdate.ObjectData[0].PathBegin = this.primData.PathBegin;
objupdate.ObjectData[0].PathEnd = this.primData.PathEnd;
objupdate.ObjectData[0].PathScaleX = this.primData.PathScaleX;
objupdate.ObjectData[0].PathScaleY = this.primData.PathScaleY;
objupdate.ObjectData[0].PathShearX = this.primData.PathShearX;
objupdate.ObjectData[0].PathShearY = this.primData.PathShearY;
objupdate.ObjectData[0].PathSkew = this.primData.PathSkew;
objupdate.ObjectData[0].ProfileBegin = this.primData.ProfileBegin;
objupdate.ObjectData[0].ProfileEnd = this.primData.ProfileEnd;
objupdate.ObjectData[0].Scale = this.primData.Scale;
objupdate.ObjectData[0].PathCurve = this.primData.PathCurve;
objupdate.ObjectData[0].ProfileCurve = this.primData.ProfileCurve;
objupdate.ObjectData[0].ParentID = 0;
objupdate.ObjectData[0].ProfileHollow = this.primData.ProfileHollow;
//finish off copying rest of shape data
objupdate.ObjectData[0].PathRadiusOffset = this.primData.PathRadiusOffset;
objupdate.ObjectData[0].PathRevolutions = this.primData.PathRevolutions;
objupdate.ObjectData[0].PathTaperX = this.primData.PathTaperX;
objupdate.ObjectData[0].PathTaperY = this.primData.PathTaperY;
objupdate.ObjectData[0].PathTwist = this.primData.PathTwist;
objupdate.ObjectData[0].PathTwistBegin = this.primData.PathTwistBegin;
objupdate.ObjectData[0].ID = (uint)store.LocalID;
objupdate.ObjectData[0].FullID = store.FullID;
objupdate.ObjectData[0].ObjectData = new byte[60];
objupdate.ObjectData[0].ObjectData[46] = 128;
objupdate.ObjectData[0].ObjectData[47] = 63;
LLVector3 pos1 = store.Position;
//update position
byte[] pb = pos1.GetBytes();
Array.Copy(pb, 0, objupdate.ObjectData[0].ObjectData, 0, pb.Length);
this.uuid = objupdate.ObjectData[0].FullID;
this.localid = objupdate.ObjectData[0].ID;
this.position = pos1;
this.OurPacket = objupdate;
}
public ImprovedTerseObjectUpdatePacket.ObjectDataBlock CreateImprovedBlock()
{
uint ID = this.localid;
byte[] bytes = new byte[60];
int i = 0;
ImprovedTerseObjectUpdatePacket.ObjectDataBlock dat = new ImprovedTerseObjectUpdatePacket.ObjectDataBlock();
dat.TextureEntry = this.OurPacket.ObjectData[0].TextureEntry;
bytes[i++] = (byte)(ID % 256);
bytes[i++] = (byte)((ID >> 8) % 256);
bytes[i++] = (byte)((ID >> 16) % 256);
bytes[i++] = (byte)((ID >> 24) % 256);
bytes[i++] = 0;
bytes[i++] = 0;
LLVector3 lPos;
Axiom.MathLib.Quaternion lRot;
if (this._physActor != null && this.physicsEnabled)
{
PhysicsVector pPos = this._physActor.Position;
lPos = new LLVector3(pPos.X, pPos.Y, pPos.Z);
lRot = this._physActor.Orientation;
}
else
{
lPos = this.position;
lRot = this.rotation;
}
byte[] pb = lPos.GetBytes();
Array.Copy(pb, 0, bytes, i, pb.Length);
i += 12;
ushort ac = 32767;
//vel
bytes[i++] = (byte)(ac % 256);
bytes[i++] = (byte)((ac >> 8) % 256);
bytes[i++] = (byte)(ac % 256);
bytes[i++] = (byte)((ac >> 8) % 256);
bytes[i++] = (byte)(ac % 256);
bytes[i++] = (byte)((ac >> 8) % 256);
//accel
bytes[i++] = (byte)(ac % 256);
bytes[i++] = (byte)((ac >> 8) % 256);
bytes[i++] = (byte)(ac % 256);
bytes[i++] = (byte)((ac >> 8) % 256);
bytes[i++] = (byte)(ac % 256);
bytes[i++] = (byte)((ac >> 8) % 256);
ushort rw, rx, ry, rz;
rw = (ushort)(32768 * (lRot.w + 1));
rx = (ushort)(32768 * (lRot.x + 1));
ry = (ushort)(32768 * (lRot.y + 1));
rz = (ushort)(32768 * (lRot.z + 1));
//rot
bytes[i++] = (byte)(rx % 256);
bytes[i++] = (byte)((rx >> 8) % 256);
bytes[i++] = (byte)(ry % 256);
bytes[i++] = (byte)((ry >> 8) % 256);
bytes[i++] = (byte)(rz % 256);
bytes[i++] = (byte)((rz >> 8) % 256);
bytes[i++] = (byte)(rw % 256);
bytes[i++] = (byte)((rw >> 8) % 256);
//rotation vel
bytes[i++] = (byte)(ac % 256);
bytes[i++] = (byte)((ac >> 8) % 256);
bytes[i++] = (byte)(ac % 256);
bytes[i++] = (byte)((ac >> 8) % 256);
bytes[i++] = (byte)(ac % 256);
bytes[i++] = (byte)((ac >> 8) % 256);
dat.Data = bytes;
return dat;
}
public override void BackUp()
{
this.primData.FullID = this.uuid;
this.primData.LocalID = this.localid;
this.primData.Position = this.position;
this.primData.Rotation = new LLQuaternion(this.rotation.x, this.rotation.y, this.rotation.z, this.rotation.w);
OpenSimRoot.Instance.LocalWorld.localStorage.StorePrim(this.primData);
}
}
}
|