| 26 |
|
|
| 27 |
|
/* the current contexts */ |
| 28 |
|
C_COLOR *c_ccolor = &c_uncolor; |
| 29 |
+ |
char *c_ccname = NULL; |
| 30 |
|
C_MATERIAL *c_cmaterial = &c_unmaterial; |
| 31 |
+ |
char *c_cmname = NULL; |
| 32 |
|
C_VERTEX *c_cvertex = &c_unvertex; |
| 33 |
+ |
char *c_cvname = NULL; |
| 34 |
|
|
| 35 |
|
static LUTAB clr_tab = LU_SINIT(free,free); /* color lookup table */ |
| 36 |
|
static LUTAB mat_tab = LU_SINIT(free,free); /* material lookup table */ |
| 61 |
|
if (ac == 1) { /* set unnamed color context */ |
| 62 |
|
c_uncolor = c_dfcolor; |
| 63 |
|
c_ccolor = &c_uncolor; |
| 64 |
+ |
c_ccname = NULL; |
| 65 |
|
return(MG_OK); |
| 66 |
|
} |
| 67 |
|
lp = lu_find(&clr_tab, av[1]); /* lookup context */ |
| 68 |
|
if (lp == NULL) |
| 69 |
|
return(MG_EMEM); |
| 70 |
+ |
c_ccname = lp->key; |
| 71 |
+ |
c_ccolor = (C_COLOR *)lp->data; |
| 72 |
|
if (ac == 2) { /* reestablish previous context */ |
| 73 |
< |
if (lp->data == NULL) |
| 73 |
> |
if (c_ccolor == NULL) |
| 74 |
|
return(MG_EUNDEF); |
| 69 |
– |
c_ccolor = (C_COLOR *)lp->data; |
| 75 |
|
return(MG_OK); |
| 76 |
|
} |
| 77 |
|
if (av[2][0] != '=' || av[2][1]) |
| 78 |
|
return(MG_ETYPE); |
| 79 |
< |
if (lp->key == NULL) { /* create new color context */ |
| 79 |
> |
if (c_ccolor == NULL) { /* create new color context */ |
| 80 |
|
lp->key = (char *)malloc(strlen(av[1])+1); |
| 81 |
|
if (lp->key == NULL) |
| 82 |
|
return(MG_EMEM); |
| 84 |
|
lp->data = (char *)malloc(sizeof(C_COLOR)); |
| 85 |
|
if (lp->data == NULL) |
| 86 |
|
return(MG_EMEM); |
| 87 |
+ |
c_ccname = lp->key; |
| 88 |
+ |
c_ccolor = (C_COLOR *)lp->data; |
| 89 |
+ |
c_ccolor->clock = 0; |
| 90 |
|
} |
| 91 |
< |
c_ccolor = (C_COLOR *)lp->data; |
| 91 |
> |
i = c_ccolor->clock; |
| 92 |
|
if (ac == 3) { /* use default template */ |
| 93 |
|
*c_ccolor = c_dfcolor; |
| 94 |
+ |
c_ccolor->clock = i + 1; |
| 95 |
|
return(MG_OK); |
| 96 |
|
} |
| 97 |
|
lp = lu_find(&clr_tab, av[3]); /* lookup template */ |
| 100 |
|
if (lp->data == NULL) |
| 101 |
|
return(MG_EUNDEF); |
| 102 |
|
*c_ccolor = *(C_COLOR *)lp->data; |
| 103 |
< |
if (ac > 4) |
| 95 |
< |
return(MG_EARGC); |
| 103 |
> |
c_ccolor->clock = i + 1; |
| 104 |
|
return(MG_OK); |
| 105 |
|
case MG_E_CXY: /* assign CIE XY value */ |
| 106 |
|
if (ac != 3) |
| 113 |
|
if (c_ccolor->cx < 0. | c_ccolor->cy < 0. | |
| 114 |
|
c_ccolor->cx + c_ccolor->cy > 1.) |
| 115 |
|
return(MG_EILL); |
| 116 |
+ |
c_ccolor->clock++; |
| 117 |
|
return(MG_OK); |
| 118 |
|
case MG_E_CSPEC: /* assign spectral values */ |
| 119 |
|
if (ac < 5) |
| 149 |
|
w, (C_COLOR *)lp->data); |
| 150 |
|
wsum += w; |
| 151 |
|
} |
| 152 |
+ |
c_ccolor->clock++; |
| 153 |
|
return(MG_OK); |
| 154 |
|
} |
| 155 |
|
return(MG_EUNK); |
| 161 |
|
int ac; |
| 162 |
|
register char **av; |
| 163 |
|
{ |
| 164 |
+ |
int i; |
| 165 |
|
register LUENT *lp; |
| 166 |
|
|
| 167 |
|
switch (mg_entity(av[0])) { |
| 171 |
|
if (ac == 1) { /* set unnamed material context */ |
| 172 |
|
c_unmaterial = c_dfmaterial; |
| 173 |
|
c_cmaterial = &c_unmaterial; |
| 174 |
+ |
c_cmname = NULL; |
| 175 |
|
return(MG_OK); |
| 176 |
|
} |
| 177 |
|
lp = lu_find(&mat_tab, av[1]); /* lookup context */ |
| 178 |
|
if (lp == NULL) |
| 179 |
|
return(MG_EMEM); |
| 180 |
+ |
c_cmname = lp->key; |
| 181 |
+ |
c_cmaterial = (C_MATERIAL *)lp->data; |
| 182 |
|
if (ac == 2) { /* reestablish previous context */ |
| 183 |
< |
if (lp->data == NULL) |
| 183 |
> |
if (c_cmaterial == NULL) |
| 184 |
|
return(MG_EUNDEF); |
| 171 |
– |
c_cmaterial = (C_MATERIAL *)lp->data; |
| 185 |
|
return(MG_OK); |
| 186 |
|
} |
| 187 |
|
if (av[2][0] != '=' || av[2][1]) |
| 188 |
|
return(MG_ETYPE); |
| 189 |
< |
if (lp->key == NULL) { /* create new material context */ |
| 189 |
> |
if (c_cmaterial == NULL) { /* create new material */ |
| 190 |
|
lp->key = (char *)malloc(strlen(av[1])+1); |
| 191 |
|
if (lp->key == NULL) |
| 192 |
|
return(MG_EMEM); |
| 194 |
|
lp->data = (char *)malloc(sizeof(C_MATERIAL)); |
| 195 |
|
if (lp->data == NULL) |
| 196 |
|
return(MG_EMEM); |
| 197 |
+ |
c_cmname = lp->key; |
| 198 |
+ |
c_cmaterial = (C_MATERIAL *)lp->data; |
| 199 |
+ |
c_cmaterial->clock = 0; |
| 200 |
|
} |
| 201 |
< |
c_cmaterial = (C_MATERIAL *)lp->data; |
| 201 |
> |
i = c_cmaterial->clock; |
| 202 |
|
if (ac == 3) { /* use default template */ |
| 203 |
|
*c_cmaterial = c_dfmaterial; |
| 204 |
< |
c_cmaterial->name = lp->key; |
| 204 |
> |
c_cmaterial->clock = i + 1; |
| 205 |
|
return(MG_OK); |
| 206 |
|
} |
| 207 |
|
lp = lu_find(&mat_tab, av[3]); /* lookup template */ |
| 210 |
|
if (lp->data == NULL) |
| 211 |
|
return(MG_EUNDEF); |
| 212 |
|
*c_cmaterial = *(C_MATERIAL *)lp->data; |
| 213 |
< |
c_cmaterial->name = lp->key; |
| 198 |
< |
c_cmaterial->clock = 1; |
| 199 |
< |
if (ac > 4) |
| 200 |
< |
return(MG_EARGC); |
| 213 |
> |
c_cmaterial->clock = i + 1; |
| 214 |
|
return(MG_OK); |
| 215 |
|
case MG_E_RD: /* set diffuse reflectance */ |
| 216 |
|
if (ac != 2) |
| 243 |
|
if (c_cmaterial->td < 0. | c_cmaterial->td > 1.) |
| 244 |
|
return(MG_EILL); |
| 245 |
|
c_cmaterial->td_c = *c_ccolor; |
| 246 |
+ |
c_cmaterial->clock++; |
| 247 |
|
return(MG_OK); |
| 248 |
|
case MG_E_RS: /* set specular reflectance */ |
| 249 |
|
if (ac != 3) |
| 271 |
|
c_cmaterial->ts_c = *c_ccolor; |
| 272 |
|
c_cmaterial->clock++; |
| 273 |
|
return(MG_OK); |
| 274 |
+ |
case MG_E_SIDES: /* set number of sides */ |
| 275 |
+ |
if (ac != 2) |
| 276 |
+ |
return(MG_EARGC); |
| 277 |
+ |
if (!isint(av[1])) |
| 278 |
+ |
return(MG_ETYPE); |
| 279 |
+ |
i = atoi(av[1]); |
| 280 |
+ |
if (i == 1) |
| 281 |
+ |
c_cmaterial->sided = 1; |
| 282 |
+ |
else if (i == 2) |
| 283 |
+ |
c_cmaterial->sided = 0; |
| 284 |
+ |
else |
| 285 |
+ |
return(MG_EILL); |
| 286 |
+ |
c_cmaterial->clock++; |
| 287 |
+ |
return(MG_OK); |
| 288 |
|
} |
| 289 |
|
return(MG_EUNK); |
| 290 |
|
} |
| 295 |
|
int ac; |
| 296 |
|
register char **av; |
| 297 |
|
{ |
| 298 |
+ |
int i; |
| 299 |
|
register LUENT *lp; |
| 300 |
|
|
| 301 |
|
switch (mg_entity(av[0])) { |
| 305 |
|
if (ac == 1) { /* set unnamed vertex context */ |
| 306 |
|
c_unvertex = c_dfvertex; |
| 307 |
|
c_cvertex = &c_unvertex; |
| 308 |
+ |
c_cvname = NULL; |
| 309 |
|
return(MG_OK); |
| 310 |
|
} |
| 311 |
|
lp = lu_find(&vtx_tab, av[1]); /* lookup context */ |
| 312 |
|
if (lp == NULL) |
| 313 |
|
return(MG_EMEM); |
| 314 |
+ |
c_cvname = lp->key; |
| 315 |
+ |
c_cvertex = (C_VERTEX *)lp->data; |
| 316 |
|
if (ac == 2) { /* reestablish previous context */ |
| 317 |
< |
if (lp->data == NULL) |
| 317 |
> |
if (c_cvertex == NULL) |
| 318 |
|
return(MG_EUNDEF); |
| 287 |
– |
c_cvertex = (C_VERTEX *)lp->data; |
| 319 |
|
return(MG_OK); |
| 320 |
|
} |
| 321 |
|
if (av[2][0] != '=' || av[2][1]) |
| 322 |
|
return(MG_ETYPE); |
| 323 |
< |
if (lp->key == NULL) { /* create new vertex context */ |
| 323 |
> |
if (c_cvertex == NULL) { /* create new vertex context */ |
| 324 |
|
lp->key = (char *)malloc(strlen(av[1])+1); |
| 325 |
|
if (lp->key == NULL) |
| 326 |
|
return(MG_EMEM); |
| 328 |
|
lp->data = (char *)malloc(sizeof(C_VERTEX)); |
| 329 |
|
if (lp->data == NULL) |
| 330 |
|
return(MG_EMEM); |
| 331 |
+ |
c_cvname = lp->key; |
| 332 |
+ |
c_cvertex = (C_VERTEX *)lp->data; |
| 333 |
|
} |
| 334 |
< |
c_cvertex = (C_VERTEX *)lp->data; |
| 334 |
> |
i = c_cvertex->clock; |
| 335 |
|
if (ac == 3) { /* use default template */ |
| 336 |
|
*c_cvertex = c_dfvertex; |
| 337 |
+ |
c_cvertex->clock = i + 1; |
| 338 |
|
return(MG_OK); |
| 339 |
|
} |
| 340 |
|
lp = lu_find(&vtx_tab, av[3]); /* lookup template */ |
| 343 |
|
if (lp->data == NULL) |
| 344 |
|
return(MG_EUNDEF); |
| 345 |
|
*c_cvertex = *(C_VERTEX *)lp->data; |
| 346 |
< |
if (ac > 4) |
| 313 |
< |
return(MG_EARGC); |
| 346 |
> |
c_cvertex->clock = i + 1; |
| 347 |
|
return(MG_OK); |
| 348 |
|
case MG_E_POINT: /* set point */ |
| 349 |
|
if (ac != 4) |
| 353 |
|
c_cvertex->p[0] = atof(av[1]); |
| 354 |
|
c_cvertex->p[1] = atof(av[2]); |
| 355 |
|
c_cvertex->p[2] = atof(av[3]); |
| 356 |
+ |
c_cvertex->clock++; |
| 357 |
|
return(MG_OK); |
| 358 |
|
case MG_E_NORMAL: /* set normal */ |
| 359 |
|
if (ac != 4) |
| 364 |
|
c_cvertex->n[1] = atof(av[2]); |
| 365 |
|
c_cvertex->n[2] = atof(av[3]); |
| 366 |
|
(void)normalize(c_cvertex->n); |
| 367 |
+ |
c_cvertex->clock++; |
| 368 |
|
return(MG_OK); |
| 369 |
|
} |
| 370 |
|
return(MG_EUNK); |
| 386 |
|
} |
| 387 |
|
|
| 388 |
|
|
| 389 |
+ |
C_MATERIAL * |
| 390 |
+ |
c_getmaterial(name) /* get a named material */ |
| 391 |
+ |
char *name; |
| 392 |
+ |
{ |
| 393 |
+ |
register LUENT *lp; |
| 394 |
+ |
|
| 395 |
+ |
if ((lp = lu_find(&mat_tab, name)) == NULL) |
| 396 |
+ |
return(NULL); |
| 397 |
+ |
return((C_MATERIAL *)lp->data); |
| 398 |
+ |
} |
| 399 |
+ |
|
| 400 |
+ |
|
| 401 |
|
C_VERTEX * |
| 402 |
|
c_getvert(name) /* get a named vertex */ |
| 403 |
|
char *name; |
| 426 |
|
c_isgrey(clr) /* check if color is grey */ |
| 427 |
|
register C_COLOR *clr; |
| 428 |
|
{ |
| 429 |
< |
if (!clr->flags) |
| 429 |
> |
if (!(clr->flags & (C_CSXY|C_CSSPEC))) |
| 430 |
|
return(1); /* no settings == grey */ |
| 431 |
|
c_ccvt(clr, C_CSXY); |
| 432 |
|
return(clr->cx >= .323 && clr->cx <= .343 && |
| 444 |
|
|
| 445 |
|
if (clr->flags & fl) /* already done */ |
| 446 |
|
return; |
| 447 |
< |
if (!(clr->flags & (C_CSXY|C_CSSPEC))) /* nothing set */ |
| 447 |
> |
if (!(clr->flags & (C_CSXY|C_CSSPEC))) /* nothing set! */ |
| 448 |
|
*clr = c_dfcolor; |
| 449 |
|
else if (fl & C_CSXY) { /* cspec -> cxy */ |
| 450 |
|
x = y = z = 0.; |
| 524 |
|
clr->ssum += clr->ssamp[i]; |
| 525 |
|
} |
| 526 |
|
clr->flags = C_CDSPEC|C_CSSPEC; |
| 527 |
+ |
clr->clock++; |
| 528 |
|
free((MEM_PTR)va); |
| 529 |
|
return(MG_OK); |
| 530 |
|
} |