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
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
|
/**
* @file llvolumemessage.cpp
* @brief LLVolumeMessage base class
*
* $LicenseInfo:firstyear=2001&license=viewerlgpl$
* Second Life Viewer Source Code
* Copyright (C) 2010, Linden Research, Inc.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation;
* version 2.1 of the License only.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
* Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA
* $/LicenseInfo$
*/
#include "linden_common.h"
#include "message.h"
#include "llvolumemessage.h"
#include "lldatapacker.h"
//============================================================================
// LLVolumeMessage is just a wrapper class; all members are static
//============================================================================
bool LLVolumeMessage::packProfileParams(
const LLProfileParams* params,
LLMessageSystem *mesgsys)
{
// Default to cylinder
static LLProfileParams defaultparams(LL_PCODE_PROFILE_CIRCLE, U16(0), U16(0), U16(0));
if (!params)
params = &defaultparams;
U8 tempU8;
U16 tempU16;
tempU8 = params->getCurveType();
mesgsys->addU8Fast(_PREHASH_ProfileCurve, tempU8);
tempU16 = (U16) llround( params->getBegin() / CUT_QUANTA);
mesgsys->addU16Fast(_PREHASH_ProfileBegin, tempU16);
tempU16 = 50000 - (U16) llround(params->getEnd() / CUT_QUANTA);
mesgsys->addU16Fast(_PREHASH_ProfileEnd, tempU16);
tempU16 = (U16) llround(params->getHollow() / HOLLOW_QUANTA);
mesgsys->addU16Fast(_PREHASH_ProfileHollow, tempU16);
return true;
}
bool LLVolumeMessage::packProfileParams(
const LLProfileParams* params,
LLDataPacker &dp)
{
// Default to cylinder
static LLProfileParams defaultparams(LL_PCODE_PROFILE_CIRCLE, U16(0), U16(0), U16(0));
if (!params)
params = &defaultparams;
U8 tempU8;
U16 tempU16;
tempU8 = params->getCurveType();
dp.packU8(tempU8, "Curve");
tempU16 = (U16) llround( params->getBegin() / CUT_QUANTA);
dp.packU16(tempU16, "Begin");
tempU16 = 50000 - (U16) llround(params->getEnd() / CUT_QUANTA);
dp.packU16(tempU16, "End");
tempU16 = (U16) llround(params->getHollow() / HOLLOW_QUANTA);
dp.packU16(tempU16, "Hollow");
return true;
}
bool LLVolumeMessage::unpackProfileParams(
LLProfileParams* params,
LLMessageSystem* mesgsys,
char const* block_name,
S32 block_num)
{
bool ok = true;
U8 temp_u8;
U16 temp_u16;
F32 temp_f32;
mesgsys->getU8Fast(block_name, _PREHASH_ProfileCurve, temp_u8, block_num);
params->setCurveType(temp_u8);
mesgsys->getU16Fast(block_name, _PREHASH_ProfileBegin, temp_u16, block_num);
temp_f32 = temp_u16 * CUT_QUANTA;
if (temp_f32 > 1.f)
{
llwarns << "Profile begin out of range: " << temp_f32
<< ". Clamping to 0.0." << llendl;
temp_f32 = 0.f;
ok = false;
}
params->setBegin(temp_f32);
mesgsys->getU16Fast(block_name, _PREHASH_ProfileEnd, temp_u16, block_num);
temp_f32 = temp_u16 * CUT_QUANTA;
if (temp_f32 > 1.f)
{
llwarns << "Profile end out of range: " << 1.f - temp_f32
<< ". Clamping to 1.0." << llendl;
temp_f32 = 1.f;
ok = false;
}
params->setEnd(1.f - temp_f32);
mesgsys->getU16Fast(block_name, _PREHASH_ProfileHollow, temp_u16, block_num);
temp_f32 = temp_u16 * HOLLOW_QUANTA;
if (temp_f32 > 1.f)
{
llwarns << "Profile hollow out of range: " << temp_f32
<< ". Clamping to 0.0." << llendl;
temp_f32 = 0.f;
ok = false;
}
params->setHollow(temp_f32);
/*
llinfos << "Unpacking Profile Block " << block_num << llendl;
llinfos << "Curve: " << (U32)getCurve() << llendl;
llinfos << "Begin: " << getBegin() << llendl;
llinfos << "End: " << getEnd() << llendl;
llinfos << "Hollow: " << getHollow() << llendl;
*/
return ok;
}
bool LLVolumeMessage::unpackProfileParams(
LLProfileParams* params,
LLDataPacker &dp)
{
bool ok = true;
U8 temp_u8;
U16 temp_u16;
F32 temp_f32;
dp.unpackU8(temp_u8, "Curve");
params->setCurveType(temp_u8);
dp.unpackU16(temp_u16, "Begin");
temp_f32 = temp_u16 * CUT_QUANTA;
if (temp_f32 > 1.f)
{
llwarns << "Profile begin out of range: " << temp_f32 << llendl;
llwarns << "Clamping to 0.0" << llendl;
temp_f32 = 0.f;
ok = false;
}
params->setBegin(temp_f32);
dp.unpackU16(temp_u16, "End");
temp_f32 = temp_u16 * CUT_QUANTA;
if (temp_f32 > 1.f)
{
llwarns << "Profile end out of range: " << 1.f - temp_f32 << llendl;
llwarns << "Clamping to 1.0" << llendl;
temp_f32 = 1.f;
ok = false;
}
params->setEnd(1.f - temp_f32);
dp.unpackU16(temp_u16, "Hollow");
temp_f32 = temp_u16 * HOLLOW_QUANTA;
if (temp_f32 > 1.f)
{
llwarns << "Profile hollow out of range: " << temp_f32 << llendl;
llwarns << "Clamping to 0.0" << llendl;
temp_f32 = 0.f;
ok = false;
}
params->setHollow(temp_f32);
return ok;
}
//============================================================================
// Quantization:
// For cut begin, range is 0 to 1, quanta is 0.005, 0 maps to 0
// For cut end, range is 0 to 1, quanta is 0.005, 1 maps to 0
// For scale, range is 0 to 1, quanta is 0.01, 0 maps to 0, 1 maps to 100
// For shear, range is -0.5 to 0.5, quanta is 0.01, 0 maps to 0
// For taper, range is -1 to 1, quanta is 0.01, 0 maps to 0
bool LLVolumeMessage::packPathParams(
const LLPathParams* params,
LLMessageSystem *mesgsys)
{
// Default to cylinder with no cut, top same size as bottom, no shear, no twist
static LLPathParams defaultparams(LL_PCODE_PATH_LINE, U8(0), U8(0), U8(0), U8(0), U8(0), U8(0), U8(0), U8(0), U8(0), U8(0), U8(0), U8(0), 0);
if (!params)
params = &defaultparams;
U8 curve = params->getCurveType();
mesgsys->addU8Fast(_PREHASH_PathCurve, curve);
U16 begin = (U16) llround(params->getBegin() / CUT_QUANTA);
mesgsys->addU16Fast(_PREHASH_PathBegin, begin);
U16 end = 50000 - (U16) llround(params->getEnd() / CUT_QUANTA);
mesgsys->addU16Fast(_PREHASH_PathEnd, end);
// Avoid truncation problem with direct F32->U8 cast.
// (e.g., (U8) (0.50 / 0.01) = (U8) 49.9999999 = 49 not 50.
U8 pack_scale_x = 200 - (U8) llround(params->getScaleX() / SCALE_QUANTA);
mesgsys->addU8Fast(_PREHASH_PathScaleX, pack_scale_x );
U8 pack_scale_y = 200 - (U8) llround(params->getScaleY() / SCALE_QUANTA);
mesgsys->addU8Fast(_PREHASH_PathScaleY, pack_scale_y );
U8 pack_shear_x = (U8) llround(params->getShearX() / SHEAR_QUANTA);
mesgsys->addU8Fast(_PREHASH_PathShearX, pack_shear_x );
U8 pack_shear_y = (U8) llround(params->getShearY() / SHEAR_QUANTA);
mesgsys->addU8Fast(_PREHASH_PathShearY, pack_shear_y );
S8 twist = (S8) llround(params->getTwist() / SCALE_QUANTA);
mesgsys->addS8Fast(_PREHASH_PathTwist, twist);
S8 twist_begin = (S8) llround(params->getTwistBegin() / SCALE_QUANTA);
mesgsys->addS8Fast(_PREHASH_PathTwistBegin, twist_begin);
S8 radius_offset = (S8) llround(params->getRadiusOffset() / SCALE_QUANTA);
mesgsys->addS8Fast(_PREHASH_PathRadiusOffset, radius_offset);
S8 taper_x = (S8) llround(params->getTaperX() / TAPER_QUANTA);
mesgsys->addS8Fast(_PREHASH_PathTaperX, taper_x);
S8 taper_y = (S8) llround(params->getTaperY() / TAPER_QUANTA);
mesgsys->addS8Fast(_PREHASH_PathTaperY, taper_y);
U8 revolutions = (U8) llround( (params->getRevolutions() - 1.0f) / REV_QUANTA);
mesgsys->addU8Fast(_PREHASH_PathRevolutions, revolutions);
S8 skew = (S8) llround(params->getSkew() / SCALE_QUANTA);
mesgsys->addS8Fast(_PREHASH_PathSkew, skew);
return true;
}
bool LLVolumeMessage::packPathParams(
const LLPathParams* params,
LLDataPacker &dp)
{
// Default to cylinder with no cut, top same size as bottom, no shear, no twist
static LLPathParams defaultparams(LL_PCODE_PATH_LINE, U8(0), U8(0), U8(0), U8(0), U8(0), U8(0), U8(0), U8(0), U8(0), U8(0), U8(0), U8(0), 0);
if (!params)
params = &defaultparams;
U8 curve = params->getCurveType();
dp.packU8(curve, "Curve");
U16 begin = (U16) llround(params->getBegin() / CUT_QUANTA);
dp.packU16(begin, "Begin");
U16 end = 50000 - (U16) llround(params->getEnd() / CUT_QUANTA);
dp.packU16(end, "End");
// Avoid truncation problem with direct F32->U8 cast.
// (e.g., (U8) (0.50 / 0.01) = (U8) 49.9999999 = 49 not 50.
U8 pack_scale_x = 200 - (U8) llround(params->getScaleX() / SCALE_QUANTA);
dp.packU8(pack_scale_x, "ScaleX");
U8 pack_scale_y = 200 - (U8) llround(params->getScaleY() / SCALE_QUANTA);
dp.packU8(pack_scale_y, "ScaleY");
S8 pack_shear_x = (S8) llround(params->getShearX() / SHEAR_QUANTA);
dp.packU8(*(U8 *)&pack_shear_x, "ShearX");
S8 pack_shear_y = (S8) llround(params->getShearY() / SHEAR_QUANTA);
dp.packU8(*(U8 *)&pack_shear_y, "ShearY");
S8 twist = (S8) llround(params->getTwist() / SCALE_QUANTA);
dp.packU8(*(U8 *)&twist, "Twist");
S8 twist_begin = (S8) llround(params->getTwistBegin() / SCALE_QUANTA);
dp.packU8(*(U8 *)&twist_begin, "TwistBegin");
S8 radius_offset = (S8) llround(params->getRadiusOffset() / SCALE_QUANTA);
dp.packU8(*(U8 *)&radius_offset, "RadiusOffset");
S8 taper_x = (S8) llround(params->getTaperX() / TAPER_QUANTA);
dp.packU8(*(U8 *)&taper_x, "TaperX");
S8 taper_y = (S8) llround(params->getTaperY() / TAPER_QUANTA);
dp.packU8(*(U8 *)&taper_y, "TaperY");
U8 revolutions = (U8) llround( (params->getRevolutions() - 1.0f) / REV_QUANTA);
dp.packU8(*(U8 *)&revolutions, "Revolutions");
S8 skew = (S8) llround(params->getSkew() / SCALE_QUANTA);
dp.packU8(*(U8 *)&skew, "Skew");
return true;
}
bool LLVolumeMessage::unpackPathParams(
LLPathParams* params,
LLMessageSystem* mesgsys,
char const* block_name,
S32 block_num)
{
U8 curve;
mesgsys->getU8Fast(block_name, _PREHASH_PathCurve, curve, block_num);
params->setCurveType(curve);
U16 begin;
mesgsys->getU16Fast(block_name, _PREHASH_PathBegin, begin, block_num);
params->setBegin((F32)(begin * CUT_QUANTA));
U16 end;
mesgsys->getU16Fast(block_name, _PREHASH_PathEnd, end, block_num);
params->setEnd((F32)((50000 - end) * CUT_QUANTA));
U8 pack_scale_x, pack_scale_y;
mesgsys->getU8Fast(block_name, _PREHASH_PathScaleX, pack_scale_x, block_num);
mesgsys->getU8Fast(block_name, _PREHASH_PathScaleY, pack_scale_y, block_num);
F32 x = (F32) (200 - pack_scale_x) * SCALE_QUANTA;
F32 y = (F32) (200 - pack_scale_y) * SCALE_QUANTA;
params->setScale( x, y );
S8 shear_x_quant, shear_y_quant;
mesgsys->getS8Fast(block_name, _PREHASH_PathShearX, shear_x_quant, block_num);
mesgsys->getS8Fast(block_name, _PREHASH_PathShearY, shear_y_quant, block_num);
F32 shear_x = (F32) shear_x_quant * SHEAR_QUANTA;
F32 shear_y = (F32) shear_y_quant * SHEAR_QUANTA;
params->setShear( shear_x, shear_y );
S8 twist;
mesgsys->getS8Fast(block_name, _PREHASH_PathTwist, twist, block_num );
params->setTwist((F32)(twist * SCALE_QUANTA));
S8 twist_begin;
mesgsys->getS8Fast(block_name, _PREHASH_PathTwistBegin, twist_begin, block_num );
params->setTwistBegin((F32)(twist_begin * SCALE_QUANTA));
S8 radius_offset;
mesgsys->getS8Fast(block_name, _PREHASH_PathRadiusOffset, radius_offset, block_num );
params->setRadiusOffset((F32)(radius_offset * SCALE_QUANTA));
S8 taper_x_quant, taper_y_quant;
mesgsys->getS8Fast(block_name, _PREHASH_PathTaperX, taper_x_quant, block_num );
mesgsys->getS8Fast(block_name, _PREHASH_PathTaperY, taper_y_quant, block_num );
F32 taper_x = (F32)(taper_x_quant * TAPER_QUANTA);
F32 taper_y = (F32)(taper_y_quant * TAPER_QUANTA);
params->setTaper( taper_x, taper_y );
U8 revolutions;
mesgsys->getU8Fast(block_name, _PREHASH_PathRevolutions, revolutions, block_num );
params->setRevolutions((F32)(revolutions * REV_QUANTA + 1.0f));
S8 skew;
mesgsys->getS8Fast(block_name, _PREHASH_PathSkew, skew, block_num );
params->setSkew((F32)(skew * SCALE_QUANTA));
/*
llinfos << "Unpacking Path Block " << block_num << llendl;
llinfos << "Curve: " << (U32)params->getCurve() << llendl;
llinfos << "Begin: " << params->getBegin() << llendl;
llinfos << "End: " << params->getEnd() << llendl;
llinfos << "Scale: " << params->getScale() << llendl;
llinfos << "Twist: " << params->getTwist() << llendl;
*/
return true;
}
bool LLVolumeMessage::unpackPathParams(LLPathParams* params, LLDataPacker &dp)
{
U8 value;
S8 svalue;
U16 temp_u16;
dp.unpackU8(value, "Curve");
params->setCurveType( value );
dp.unpackU16(temp_u16, "Begin");
params->setBegin((F32)(temp_u16 * CUT_QUANTA));
dp.unpackU16(temp_u16, "End");
params->setEnd((F32)((50000 - temp_u16) * CUT_QUANTA));
dp.unpackU8(value, "ScaleX");
F32 x = (F32) (200 - value) * SCALE_QUANTA;
dp.unpackU8(value, "ScaleY");
F32 y = (F32) (200 - value) * SCALE_QUANTA;
params->setScale( x, y );
dp.unpackU8(value, "ShearX");
svalue = *(S8 *)&value;
F32 shear_x = (F32) svalue * SHEAR_QUANTA;
dp.unpackU8(value, "ShearY");
svalue = *(S8 *)&value;
F32 shear_y = (F32) svalue * SHEAR_QUANTA;
params->setShear( shear_x, shear_y );
dp.unpackU8(value, "Twist");
svalue = *(S8 *)&value;
params->setTwist((F32)(svalue * SCALE_QUANTA));
dp.unpackU8(value, "TwistBegin");
svalue = *(S8 *)&value;
params->setTwistBegin((F32)(svalue * SCALE_QUANTA));
dp.unpackU8(value, "RadiusOffset");
svalue = *(S8 *)&value;
params->setRadiusOffset((F32)(svalue * SCALE_QUANTA));
dp.unpackU8(value, "TaperX");
svalue = *(S8 *)&value;
params->setTaperX((F32)(svalue * TAPER_QUANTA));
dp.unpackU8(value, "TaperY");
svalue = *(S8 *)&value;
params->setTaperY((F32)(svalue * TAPER_QUANTA));
dp.unpackU8(value, "Revolutions");
params->setRevolutions((F32)(value * REV_QUANTA + 1.0f));
dp.unpackU8(value, "Skew");
svalue = *(S8 *)&value;
params->setSkew((F32)(svalue * SCALE_QUANTA));
return true;
}
//============================================================================
// static
bool LLVolumeMessage::constrainVolumeParams(LLVolumeParams& params)
{
U32 bad = 0;
// This is called immediately after an unpack. feed the raw data
// through the checked setters to constraint it to a valid set of
// volume params.
bad |= params.setType(params.getProfileParams().getCurveType(),
params.getPathParams().getCurveType()) ? 0 : 1;
bad |= params.setBeginAndEndS(params.getProfileParams().getBegin(),
params.getProfileParams().getEnd()) ? 0 : 2;
bad |= params.setBeginAndEndT(params.getPathParams().getBegin(),
params.getPathParams().getEnd()) ? 0 : 4;
bad |= params.setHollow(params.getProfileParams().getHollow()) ? 0 : 8;
bad |= params.setTwistBegin(params.getPathParams().getTwistBegin()) ? 0 : 0x10;
bad |= params.setTwistEnd(params.getPathParams().getTwistEnd()) ? 0 : 0x20;
bad |= params.setRatio(params.getPathParams().getScaleX(),
params.getPathParams().getScaleY()) ? 0 : 0x40;
bad |= params.setShear(params.getPathParams().getShearX(),
params.getPathParams().getShearY()) ? 0 : 0x80;
bad |= params.setTaper(params.getPathParams().getTaperX(),
params.getPathParams().getTaperY()) ? 0 : 0x100;
bad |= params.setRevolutions(params.getPathParams().getRevolutions()) ? 0 : 0x200;
bad |= params.setRadiusOffset(params.getPathParams().getRadiusOffset()) ? 0 : 0x400;
bad |= params.setSkew(params.getPathParams().getSkew()) ? 0 : 0x800;
if(bad)
{
llwarns << "LLVolumeMessage::constrainVolumeParams() - "
<< "forced to constrain incoming volume params: "
<< llformat("0x%04x",bad) << llendl;
}
return bad ? false : true;
}
bool LLVolumeMessage::packVolumeParams(const LLVolumeParams* params, LLMessageSystem *mesgsys)
{
// llinfos << "pack volume" << llendl;
if (params)
{
packPathParams(¶ms->getPathParams(), mesgsys);
packProfileParams(¶ms->getProfileParams(), mesgsys);
}
else
{
packPathParams(0, mesgsys);
packProfileParams(0, mesgsys);
}
return true;
}
bool LLVolumeMessage::packVolumeParams(const LLVolumeParams* params, LLDataPacker &dp)
{
// llinfos << "pack volume" << llendl;
if (params)
{
packPathParams(¶ms->getPathParams(), dp);
packProfileParams(¶ms->getProfileParams(), dp);
}
else
{
packPathParams(0, dp);
packProfileParams(0, dp);
}
return true;
}
bool LLVolumeMessage::unpackVolumeParams(
LLVolumeParams* params,
LLMessageSystem* mesgsys,
char const* block_name,
S32 block_num)
{
bool ok = true;
ok &= unpackPathParams(
¶ms->getPathParams(),
mesgsys,
block_name,
block_num);
ok &= unpackProfileParams(
¶ms->getProfileParams(),
mesgsys,
block_name,
block_num);
ok &= constrainVolumeParams(*params);
return ok;
}
bool LLVolumeMessage::unpackVolumeParams(
LLVolumeParams* params,
LLDataPacker &dp)
{
bool ok = true;
ok &= unpackPathParams(¶ms->getPathParams(), dp);
ok &= unpackProfileParams(¶ms->getProfileParams(), dp);
ok &= constrainVolumeParams(*params);
return ok;
}
//============================================================================
|