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 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598
|
// This work is licensed under the Creative Commons Attribution-ShareAlike 3.0 Unported License.
// To view a copy of this license, visit http://creativecommons.org/licenses/by-sa/3.0/ or send a
// letter to Creative Commons, 444 Castro Street, Suite 900, Mountain View, California, 94041, USA.
/* Persistence Of Vision Raytracer sample file.
Mesh Camera macros for use with the new mesh_camera.
These macros help to create and place the grid-like meshes needed to simulate
a camera with the new mesh_camera feature:
+ meshcam_pinhole() creates a convex mesh simulating a perspective camera, for use with distrib.#0,1,2
+ meshcam_lens() creates a convex mesh like above, but adding simulated lens distortion, for use with distrib.#0,1,2
+ meshcam_pinhole_uv() is a uv mapped version of meshcam_pinhole(), for use with distrib.#3
+ meshcam_placement() helps to place the mesh cameras created by the other macros.
--
Jaime Vives Piqueres, Jan. 2011 <jaime@ignorancia.org> */
/***************************************************************************************
* $File: //depot/povray/smp/distribution/scenes/camera/mesh_camera/meshcam_macros.inc $
* $Revision: #2 $
* $Change: 5377 $
* $DateTime: 2011/01/09 19:56:00 $
* $Author: jholsenback $
**************************************************************************************/
#include "math.inc"
#include "transforms.inc"
/*
Convex grid-like mesh for pinhole perspective projection
*/
#macro meshcam_pinhole(res_x, res_y, c_angle, c_file)
#local c_up=1*y;
#local c_right=(res_x/res_y)*x;
#local c_direction=0.5*vlength(c_right)/tan(radians(c_angle)/2);
#local sph_lens=sphere{0,c_direction}
#local px_inc=(res_x/res_y)/res_x;
#local centering=<-res_x*.5*px_inc+px_inc*.5,res_y*.5*px_inc-px_inc-px_inc*2/3,0>;
#local tr_base_1=< 0,2*px_inc/3,0>;
#local tr_base_2=< px_inc/2, -px_inc/3,0>;
#local tr_base_3=<-px_inc/2, -px_inc/3,0>;
#if (c_file!="")
#fopen fmesh c_file write
#write (fmesh, "mesh{", "\n")
#end
mesh{
#local row_count=0;
#while (row_count<res_y)
#local col_count=0;
#local d_y=row_count*px_inc;
#while (col_count<res_x)
#local d_x=col_count*px_inc;
#local Norm=<0,0,0>;
#local tr_vertex_1=trace(sph_lens,0,tr_base_1+<d_x,-d_y,c_direction>+centering, Norm);
#local tr_vertex_2=trace(sph_lens,0,tr_base_2+<d_x,-d_y,c_direction>+centering, Norm);
#local tr_vertex_3=trace(sph_lens,0,tr_base_3+<d_x,-d_y,c_direction>+centering, Norm);
triangle{tr_vertex_1,tr_vertex_2,tr_vertex_3}
#if (c_file!="")
#write (fmesh, "triangle{",
"<",str(tr_vertex_1.x,0,16),",",str(tr_vertex_1.y,0,16),",",str(tr_vertex_1.z,0,16),">", ",",
"<",str(tr_vertex_2.x,0,16),",",str(tr_vertex_2.y,0,16),",",str(tr_vertex_2.z,0,16),">", ",",
"<",str(tr_vertex_3.x,0,16),",",str(tr_vertex_3.y,0,16),",",str(tr_vertex_3.z,0,16),">", "}", "\n")
#end
#local col_count=col_count+1;
#end
#local row_count=row_count+1;
#end
}
#if (c_file!="")
#write (fmesh, "}", "\n")
#fclose fmesh
#end
#end
/*
Convex grid-like mesh for pinhole perspective projection
--
Version simulating lens distortion: use positive values for barrel, negative for pincushion
*/
#macro meshcam_lens(res_x, res_y, c_angle, c_distort, c_file)
#local c_up=1*y;
#local c_right=(res_x/res_y)*x;
#local c_direction=0.5*vlength(c_right)/tan(radians(c_angle)/2);
#local sph_lens=sphere{0,c_direction}
#local px_inc=(res_x/res_y)/res_x;
#local centering=<-res_x*.5*px_inc+px_inc*.5,res_y*.5*px_inc-px_inc-px_inc*2/3,0>;
#local tr_base_1=< 0,2*px_inc/3,0>;
#local tr_base_2=< px_inc/2, -px_inc/3,0>;
#local tr_base_3=<-px_inc/2, -px_inc/3,0>;
#if (c_file!="")
#fopen fmesh c_file write
#write (fmesh, "mesh{", "\n")
#end
mesh{
#local row_count=0;
#while (row_count<res_y)
#local col_count=0;
#local d_y=row_count*px_inc;
#while (col_count<res_x)
#local d_x=col_count*px_inc;
#local Norm=<0,0,0>;
#local tr_vertex_1=trace(sph_lens,0,tr_base_1+<d_x,-d_y,c_direction>+centering, Norm);
#local tr_vertex_2=trace(sph_lens,0,tr_base_2+<d_x,-d_y,c_direction>+centering, Norm);
#local tr_vertex_3=trace(sph_lens,0,tr_base_3+<d_x,-d_y,c_direction>+centering, Norm);
#if (c_distort!=0)
#local tr_vertex_1=tr_vertex_1-c_distort*pow(abs(tr_vertex_1.x)*abs(tr_vertex_1.y),2)*z;
#local tr_vertex_2=tr_vertex_2-c_distort*pow(abs(tr_vertex_2.x)*abs(tr_vertex_2.y),2)*z;
#local tr_vertex_3=tr_vertex_3-c_distort*pow(abs(tr_vertex_3.x)*abs(tr_vertex_3.y),2)*z;
#end
triangle{tr_vertex_1,tr_vertex_2,tr_vertex_3}
#if (c_file!="")
#write (fmesh, "triangle{",
"<",str(tr_vertex_1.x,0,16),",",str(tr_vertex_1.y,0,16),",",str(tr_vertex_1.z,0,16),">", ",",
"<",str(tr_vertex_2.x,0,16),",",str(tr_vertex_2.y,0,16),",",str(tr_vertex_2.z,0,16),">", ",",
"<",str(tr_vertex_3.x,0,16),",",str(tr_vertex_3.y,0,16),",",str(tr_vertex_3.z,0,16),">", "}", "\n")
#end
#local col_count=col_count+1;
#end
#local row_count=row_count+1;
#end
}
#if (c_file!="")
#write (fmesh, "}", "\n")
#fclose fmesh
#end
#end
/*
Flat grid-like mesh for pure orthographic projection
*/
#macro meshcam_orthographic(res_x, res_y, c_up_length, c_file)
#local c_direction=1;
#local px_inc=c_up_length*(res_x/res_y)/res_x;
#local centering=<-res_x*.5*px_inc+px_inc*.5,res_y*.5*px_inc-px_inc-px_inc*2/3,0>;
#local tr_base_1=< 0,px_inc*2/3,0>;
#local tr_base_2=< px_inc/2, -px_inc/3,0>;
#local tr_base_3=<-px_inc/2, -px_inc/3,0>;
#if (c_file!="")
#fopen fmesh c_file write
#write (fmesh, "mesh{", "\n")
#end
mesh{
#local row_count=0;
#while (row_count<res_y)
#local col_count=0;
#local d_y=row_count*px_inc;
#while (col_count<res_x)
#local d_x=col_count*px_inc;
#local tr_vertex_1=tr_base_1+<d_x,-d_y,c_direction>+centering;
#local tr_vertex_2=tr_base_2+<d_x,-d_y,c_direction>+centering;
#local tr_vertex_3=tr_base_3+<d_x,-d_y,c_direction>+centering;
triangle{tr_vertex_1,tr_vertex_2,tr_vertex_3}
#if (c_file!="")
#write (fmesh, "triangle{",
"<",str(tr_vertex_1.x,0,16),",",str(tr_vertex_1.y,0,16),",",str(tr_vertex_1.z,0,16),">", ",",
"<",str(tr_vertex_2.x,0,16),",",str(tr_vertex_2.y,0,16),",",str(tr_vertex_2.z,0,16),">", ",",
"<",str(tr_vertex_3.x,0,16),",",str(tr_vertex_3.y,0,16),",",str(tr_vertex_3.z,0,16),">", "}", "\n")
#end
#local col_count=col_count+1;
#end
#local row_count=row_count+1;
#end
}
#if (c_file!="")
#write (fmesh, "}", "\n")
#fclose fmesh
#end
#end
/*
Convex grid-like mesh for pinhole perspective projection
--
Version with UV mapping for use with distrib.#3 and the "smooth" modifier.
*/
#macro meshcam_pinhole_uv(res_x, res_y, c_angle, c_file)
#local c_up=1*y;
#local c_right=(res_x/res_y)*x;
#local c_direction=0.5*vlength(c_right)/tan(radians(c_angle)/2);
#local sph_lens=sphere{0,c_direction}
#local px_inc=(res_x/res_y)/res_x;
#local centering=<-res_x*.5*px_inc,res_y*.5*px_inc,0>;
#local tr_base_1=<px_inc/2,-px_inc/2,0>;
#local tr_base_2=<0,0,0>;
#local tr_base_3=<px_inc,0,0>;
#local tr_base_4=<px_inc,-px_inc,0>;
#local tr_base_5=<0,-px_inc,0>;
#if (c_file!="")
#fopen fmesh c_file write
#write (fmesh, "mesh{", "\n")
#end
mesh{
#local row_count=0;
#while (row_count<res_y)
#local col_count=0;
#local d_y=row_count*px_inc;
#while (col_count<res_x)
#local d_x=col_count*px_inc;
#local Norm=<0,0,0>;
#local tr_vertex_1=trace(sph_lens,0,tr_base_1+<d_x,-d_y,c_direction>+centering, Norm);
#local tr_normal_1=Norm;
#local tr_vertex_2=trace(sph_lens,0,tr_base_2+<d_x,-d_y,c_direction>+centering, Norm);
#local tr_normal_2=Norm;
#local tr_vertex_3=trace(sph_lens,0,tr_base_3+<d_x,-d_y,c_direction>+centering, Norm);
#local tr_normal_3=Norm;
#local tr_vertex_4=trace(sph_lens,0,tr_base_4+<d_x,-d_y,c_direction>+centering, Norm);
#local tr_normal_4=Norm;
#local tr_vertex_5=trace(sph_lens,0,tr_base_5+<d_x,-d_y,c_direction>+centering, Norm);
#local tr_normal_5=Norm;
smooth_triangle{tr_vertex_1, tr_normal_1, tr_vertex_2, tr_normal_2, tr_vertex_3, tr_normal_3
uv_vectors
<(tr_base_1.x+d_x)/(res_x*px_inc),1-abs(tr_base_1.y-d_y)/(res_y*px_inc)>,
<(tr_base_2.x+d_x)/(res_x*px_inc),1-abs(tr_base_2.y-d_y)/(res_y*px_inc)>,
<(tr_base_3.x+d_x)/(res_x*px_inc),1-abs(tr_base_3.y-d_y)/(res_y*px_inc)>
}
smooth_triangle{tr_vertex_1, tr_normal_1, tr_vertex_3, tr_normal_3, tr_vertex_4, tr_normal_4
uv_vectors
<(tr_base_1.x+d_x)/(res_x*px_inc),1-abs(tr_base_1.y-d_y)/(res_y*px_inc)>,
<(tr_base_3.x+d_x)/(res_x*px_inc),1-abs(tr_base_3.y-d_y)/(res_y*px_inc)>,
<(tr_base_4.x+d_x)/(res_x*px_inc),1-abs(tr_base_4.y-d_y)/(res_y*px_inc)>
}
smooth_triangle{tr_vertex_1, tr_normal_1, tr_vertex_4, tr_normal_4, tr_vertex_5, tr_normal_5
uv_vectors
<(tr_base_1.x+d_x)/(res_x*px_inc),1-abs(tr_base_1.y-d_y)/(res_y*px_inc)>,
<(tr_base_4.x+d_x)/(res_x*px_inc),1-abs(tr_base_4.y-d_y)/(res_y*px_inc)>,
<(tr_base_5.x+d_x)/(res_x*px_inc),1-abs(tr_base_5.y-d_y)/(res_y*px_inc)>
}
smooth_triangle{tr_vertex_1, tr_normal_1, tr_vertex_5, tr_normal_5, tr_vertex_2, tr_normal_2
uv_vectors
<(tr_base_1.x+d_x)/(res_x*px_inc),1-abs(tr_base_1.y-d_y)/(res_y*px_inc)>,
<(tr_base_5.x+d_x)/(res_x*px_inc),1-abs(tr_base_5.y-d_y)/(res_y*px_inc)>,
<(tr_base_2.x+d_x)/(res_x*px_inc),1-abs(tr_base_2.y-d_y)/(res_y*px_inc)>
}
#if (c_file!="")
#write (fmesh, "smooth_triangle{",
"<",str(tr_vertex_1.x,0,16),",",str(tr_vertex_1.y,0,16),",",str(tr_vertex_1.z,0,16),">", ",",
"<",str(tr_normal_1.x,0,16),",",str(tr_normal_1.y,0,16),",",str(tr_normal_1.z,0,16),">", ",",
"<",str(tr_vertex_2.x,0,16),",",str(tr_vertex_2.y,0,16),",",str(tr_vertex_2.z,0,16),">", ",",
"<",str(tr_normal_2.x,0,16),",",str(tr_normal_2.y,0,16),",",str(tr_normal_2.z,0,16),">", ",",
"<",str(tr_vertex_3.x,0,16),",",str(tr_vertex_3.y,0,16),",",str(tr_vertex_3.z,0,16),">", ",",
"<",str(tr_normal_3.x,0,16),",",str(tr_normal_3.y,0,16),",",str(tr_normal_3.z,0,16),">",
"uv_vectors ",
"<", str((tr_base_1.x+d_x)/(res_x*px_inc),0,16), ",", str(1-abs(tr_base_1.y-d_y)/(res_y*px_inc),0,16), ">,",
"<", str((tr_base_2.x+d_x)/(res_x*px_inc),0,16), ",", str(1-abs(tr_base_2.y-d_y)/(res_y*px_inc),0,16), ">,",
"<", str((tr_base_3.x+d_x)/(res_x*px_inc),0,16), ",", str(1-abs(tr_base_3.y-d_y)/(res_y*px_inc),0,16), ">}",
"\n")
#write (fmesh, "smooth_triangle{",
"<",str(tr_vertex_1.x,0,16),",",str(tr_vertex_1.y,0,16),",",str(tr_vertex_1.z,0,16),">", ",",
"<",str(tr_normal_1.x,0,16),",",str(tr_normal_1.y,0,16),",",str(tr_normal_1.z,0,16),">", ",",
"<",str(tr_vertex_3.x,0,16),",",str(tr_vertex_3.y,0,16),",",str(tr_vertex_3.z,0,16),">", ",",
"<",str(tr_normal_3.x,0,16),",",str(tr_normal_3.y,0,16),",",str(tr_normal_3.z,0,16),">",
"<",str(tr_vertex_4.x,0,16),",",str(tr_vertex_4.y,0,16),",",str(tr_vertex_4.z,0,16),">", ",",
"<",str(tr_normal_4.x,0,16),",",str(tr_normal_4.y,0,16),",",str(tr_normal_4.z,0,16),">",
"uv_vectors ",
"<", str((tr_base_1.x+d_x)/(res_x*px_inc),0,16), ",", str(1-abs(tr_base_1.y-d_y)/(res_y*px_inc),0,16), ">,",
"<", str((tr_base_3.x+d_x)/(res_x*px_inc),0,16), ",", str(1-abs(tr_base_3.y-d_y)/(res_y*px_inc),0,16), ">,",
"<", str((tr_base_4.x+d_x)/(res_x*px_inc),0,16), ",", str(1-abs(tr_base_4.y-d_y)/(res_y*px_inc),0,16), ">}",
"\n")
#write (fmesh, "smooth_triangle{",
"<",str(tr_vertex_1.x,0,16),",",str(tr_vertex_1.y,0,16),",",str(tr_vertex_1.z,0,16),">", ",",
"<",str(tr_normal_1.x,0,16),",",str(tr_normal_1.y,0,16),",",str(tr_normal_1.z,0,16),">", ",",
"<",str(tr_vertex_4.x,0,16),",",str(tr_vertex_4.y,0,16),",",str(tr_vertex_4.z,0,16),">", ",",
"<",str(tr_normal_4.x,0,16),",",str(tr_normal_4.y,0,16),",",str(tr_normal_4.z,0,16),">", ",",
"<",str(tr_vertex_5.x,0,16),",",str(tr_vertex_5.y,0,16),",",str(tr_vertex_5.z,0,16),">", ",",
"<",str(tr_normal_5.x,0,16),",",str(tr_normal_5.y,0,16),",",str(tr_normal_5.z,0,16),">",
"uv_vectors ",
"<", str((tr_base_1.x+d_x)/(res_x*px_inc),0,16), ",", str(1-abs(tr_base_1.y-d_y)/(res_y*px_inc),0,16), ">,",
"<", str((tr_base_4.x+d_x)/(res_x*px_inc),0,16), ",", str(1-abs(tr_base_4.y-d_y)/(res_y*px_inc),0,16), ">,",
"<", str((tr_base_5.x+d_x)/(res_x*px_inc),0,16), ",", str(1-abs(tr_base_5.y-d_y)/(res_y*px_inc),0,16), ">}",
"\n")
#write (fmesh, "smooth_triangle{",
"<",str(tr_vertex_1.x,0,16),",",str(tr_vertex_1.y,0,16),",",str(tr_vertex_1.z,0,16),">", ",",
"<",str(tr_normal_1.x,0,16),",",str(tr_normal_1.y,0,16),",",str(tr_normal_1.z,0,16),">", ",",
"<",str(tr_vertex_5.x,0,16),",",str(tr_vertex_5.y,0,16),",",str(tr_vertex_5.z,0,16),">", ",",
"<",str(tr_normal_5.x,0,16),",",str(tr_normal_5.y,0,16),",",str(tr_normal_5.z,0,16),">", ",",
"<",str(tr_vertex_2.x,0,16),",",str(tr_vertex_2.y,0,16),",",str(tr_vertex_2.z,0,16),">", ",",
"<",str(tr_normal_2.x,0,16),",",str(tr_normal_2.y,0,16),",",str(tr_normal_2.z,0,16),">",
"uv_vectors ",
"<", str((tr_base_1.x+d_x)/(res_x*px_inc),0,16), ",", str(1-abs(tr_base_1.y-d_y)/(res_y*px_inc),0,16), ">,",
"<", str((tr_base_5.x+d_x)/(res_x*px_inc),0,16), ",", str(1-abs(tr_base_5.y-d_y)/(res_y*px_inc),0,16), ">,",
"<", str((tr_base_2.x+d_x)/(res_x*px_inc),0,16), ",", str(1-abs(tr_base_2.y-d_y)/(res_y*px_inc),0,16), ">}",
"\n")
#end
#local col_count=col_count+1;
#end
#local row_count=row_count+1;
#end
}
#if (c_file!="")
#write (fmesh, "}", "\n")
#fclose fmesh
#end
#end
/*
Convex grid-like mesh for pinhole perspective projection
--
Version simulating lens distortion: use positive values for barrel, negative for pincushion
Version with UV mapping for use with distrib.#3 and the "smooth" modifier.
*/
#macro meshcam_lens_uv(res_x, res_y, c_angle, c_distort, c_file)
#local c_up=1*y;
#local c_right=(res_x/res_y)*x;
#local c_direction=0.5*vlength(c_right)/tan(radians(c_angle)/2);
#local sph_lens=sphere{0,c_direction}
#local px_inc=(res_x/res_y)/res_x;
#local centering=<-res_x*.5*px_inc,res_y*.5*px_inc,0>;
#local tr_base_1=<px_inc/2,-px_inc/2,0>;
#local tr_base_2=<0,0,0>;
#local tr_base_3=<px_inc,0,0>;
#local tr_base_4=<px_inc,-px_inc,0>;
#local tr_base_5=<0,-px_inc,0>;
#if (c_file!="")
#fopen fmesh c_file write
#write (fmesh, "mesh{", "\n")
#end
mesh{
#local row_count=0;
#while (row_count<res_y)
#local col_count=0;
#local d_y=row_count*px_inc;
#while (col_count<res_x)
#local d_x=col_count*px_inc;
#local Norm=<0,0,0>;
#local tr_tmp_1=tr_base_1+<d_x,-d_y,c_direction>+centering;
#local tr_tmp_2=tr_base_2+<d_x,-d_y,c_direction>+centering;
#local tr_tmp_3=tr_base_3+<d_x,-d_y,c_direction>+centering;
#local tr_tmp_4=tr_base_4+<d_x,-d_y,c_direction>+centering;
#local tr_tmp_5=tr_base_5+<d_x,-d_y,c_direction>+centering;
#if (c_distort!=0) // had to multiply it by 10 to obtain the same result as the non-uvmapped version?!?!
#local tr_tmp_1=tr_tmp_1-c_distort*10*pow(abs(tr_tmp_1.x)*abs(tr_tmp_1.y),2)*z;
#local tr_tmp_2=tr_tmp_2-c_distort*10*pow(abs(tr_tmp_2.x)*abs(tr_tmp_2.y),2)*z;
#local tr_tmp_3=tr_tmp_3-c_distort*10*pow(abs(tr_tmp_3.x)*abs(tr_tmp_3.y),2)*z;
#local tr_tmp_4=tr_tmp_4-c_distort*10*pow(abs(tr_tmp_4.x)*abs(tr_tmp_4.y),2)*z;
#local tr_tmp_5=tr_tmp_5-c_distort*10*pow(abs(tr_tmp_5.x)*abs(tr_tmp_5.y),2)*z;
#end
#local tr_vertex_1=trace(sph_lens,0,tr_tmp_1, Norm);
#local tr_normal_1=Norm;
#local tr_vertex_2=trace(sph_lens,0,tr_tmp_2, Norm);
#local tr_normal_2=Norm;
#local tr_vertex_3=trace(sph_lens,0,tr_tmp_3, Norm);
#local tr_normal_3=Norm;
#local tr_vertex_4=trace(sph_lens,0,tr_tmp_4, Norm);
#local tr_normal_4=Norm;
#local tr_vertex_5=trace(sph_lens,0,tr_tmp_5, Norm);
#local tr_normal_5=Norm;
smooth_triangle{tr_vertex_1, tr_normal_1, tr_vertex_2, tr_normal_2, tr_vertex_3, tr_normal_3
uv_vectors
<(tr_base_1.x+d_x)/(res_x*px_inc),1-abs(tr_base_1.y-d_y)/(res_y*px_inc)>,
<(tr_base_2.x+d_x)/(res_x*px_inc),1-abs(tr_base_2.y-d_y)/(res_y*px_inc)>,
<(tr_base_3.x+d_x)/(res_x*px_inc),1-abs(tr_base_3.y-d_y)/(res_y*px_inc)>
}
smooth_triangle{tr_vertex_1, tr_normal_1, tr_vertex_3, tr_normal_3, tr_vertex_4, tr_normal_4
uv_vectors
<(tr_base_1.x+d_x)/(res_x*px_inc),1-abs(tr_base_1.y-d_y)/(res_y*px_inc)>,
<(tr_base_3.x+d_x)/(res_x*px_inc),1-abs(tr_base_3.y-d_y)/(res_y*px_inc)>,
<(tr_base_4.x+d_x)/(res_x*px_inc),1-abs(tr_base_4.y-d_y)/(res_y*px_inc)>
}
smooth_triangle{tr_vertex_1, tr_normal_1, tr_vertex_4, tr_normal_4, tr_vertex_5, tr_normal_5
uv_vectors
<(tr_base_1.x+d_x)/(res_x*px_inc),1-abs(tr_base_1.y-d_y)/(res_y*px_inc)>,
<(tr_base_4.x+d_x)/(res_x*px_inc),1-abs(tr_base_4.y-d_y)/(res_y*px_inc)>,
<(tr_base_5.x+d_x)/(res_x*px_inc),1-abs(tr_base_5.y-d_y)/(res_y*px_inc)>
}
smooth_triangle{tr_vertex_1, tr_normal_1, tr_vertex_5, tr_normal_5, tr_vertex_2, tr_normal_2
uv_vectors
<(tr_base_1.x+d_x)/(res_x*px_inc),1-abs(tr_base_1.y-d_y)/(res_y*px_inc)>,
<(tr_base_5.x+d_x)/(res_x*px_inc),1-abs(tr_base_5.y-d_y)/(res_y*px_inc)>,
<(tr_base_2.x+d_x)/(res_x*px_inc),1-abs(tr_base_2.y-d_y)/(res_y*px_inc)>
}
#if (c_file!="")
#write (fmesh, "smooth_triangle{",
"<",str(tr_vertex_1.x,0,16),",",str(tr_vertex_1.y,0,16),",",str(tr_vertex_1.z,0,16),">", ",",
"<",str(tr_normal_1.x,0,16),",",str(tr_normal_1.y,0,16),",",str(tr_normal_1.z,0,16),">", ",",
"<",str(tr_vertex_2.x,0,16),",",str(tr_vertex_2.y,0,16),",",str(tr_vertex_2.z,0,16),">", ",",
"<",str(tr_normal_2.x,0,16),",",str(tr_normal_2.y,0,16),",",str(tr_normal_2.z,0,16),">", ",",
"<",str(tr_vertex_3.x,0,16),",",str(tr_vertex_3.y,0,16),",",str(tr_vertex_3.z,0,16),">", ",",
"<",str(tr_normal_3.x,0,16),",",str(tr_normal_3.y,0,16),",",str(tr_normal_3.z,0,16),">",
"uv_vectors ",
"<", str((tr_base_1.x+d_x)/(res_x*px_inc),0,16), ",", str(1-abs(tr_base_1.y-d_y)/(res_y*px_inc),0,16), ">,",
"<", str((tr_base_2.x+d_x)/(res_x*px_inc),0,16), ",", str(1-abs(tr_base_2.y-d_y)/(res_y*px_inc),0,16), ">,",
"<", str((tr_base_3.x+d_x)/(res_x*px_inc),0,16), ",", str(1-abs(tr_base_3.y-d_y)/(res_y*px_inc),0,16), ">}",
"\n")
#write (fmesh, "smooth_triangle{",
"<",str(tr_vertex_1.x,0,16),",",str(tr_vertex_1.y,0,16),",",str(tr_vertex_1.z,0,16),">", ",",
"<",str(tr_normal_1.x,0,16),",",str(tr_normal_1.y,0,16),",",str(tr_normal_1.z,0,16),">", ",",
"<",str(tr_vertex_3.x,0,16),",",str(tr_vertex_3.y,0,16),",",str(tr_vertex_3.z,0,16),">", ",",
"<",str(tr_normal_3.x,0,16),",",str(tr_normal_3.y,0,16),",",str(tr_normal_3.z,0,16),">",
"<",str(tr_vertex_4.x,0,16),",",str(tr_vertex_4.y,0,16),",",str(tr_vertex_4.z,0,16),">", ",",
"<",str(tr_normal_4.x,0,16),",",str(tr_normal_4.y,0,16),",",str(tr_normal_4.z,0,16),">",
"uv_vectors ",
"<", str((tr_base_1.x+d_x)/(res_x*px_inc),0,16), ",", str(1-abs(tr_base_1.y-d_y)/(res_y*px_inc),0,16), ">,",
"<", str((tr_base_3.x+d_x)/(res_x*px_inc),0,16), ",", str(1-abs(tr_base_3.y-d_y)/(res_y*px_inc),0,16), ">,",
"<", str((tr_base_4.x+d_x)/(res_x*px_inc),0,16), ",", str(1-abs(tr_base_4.y-d_y)/(res_y*px_inc),0,16), ">}",
"\n")
#write (fmesh, "smooth_triangle{",
"<",str(tr_vertex_1.x,0,16),",",str(tr_vertex_1.y,0,16),",",str(tr_vertex_1.z,0,16),">", ",",
"<",str(tr_normal_1.x,0,16),",",str(tr_normal_1.y,0,16),",",str(tr_normal_1.z,0,16),">", ",",
"<",str(tr_vertex_4.x,0,16),",",str(tr_vertex_4.y,0,16),",",str(tr_vertex_4.z,0,16),">", ",",
"<",str(tr_normal_4.x,0,16),",",str(tr_normal_4.y,0,16),",",str(tr_normal_4.z,0,16),">", ",",
"<",str(tr_vertex_5.x,0,16),",",str(tr_vertex_5.y,0,16),",",str(tr_vertex_5.z,0,16),">", ",",
"<",str(tr_normal_5.x,0,16),",",str(tr_normal_5.y,0,16),",",str(tr_normal_5.z,0,16),">",
"uv_vectors ",
"<", str((tr_base_1.x+d_x)/(res_x*px_inc),0,16), ",", str(1-abs(tr_base_1.y-d_y)/(res_y*px_inc),0,16), ">,",
"<", str((tr_base_4.x+d_x)/(res_x*px_inc),0,16), ",", str(1-abs(tr_base_4.y-d_y)/(res_y*px_inc),0,16), ">,",
"<", str((tr_base_5.x+d_x)/(res_x*px_inc),0,16), ",", str(1-abs(tr_base_5.y-d_y)/(res_y*px_inc),0,16), ">}",
"\n")
#write (fmesh, "smooth_triangle{",
"<",str(tr_vertex_1.x,0,16),",",str(tr_vertex_1.y,0,16),",",str(tr_vertex_1.z,0,16),">", ",",
"<",str(tr_normal_1.x,0,16),",",str(tr_normal_1.y,0,16),",",str(tr_normal_1.z,0,16),">", ",",
"<",str(tr_vertex_5.x,0,16),",",str(tr_vertex_5.y,0,16),",",str(tr_vertex_5.z,0,16),">", ",",
"<",str(tr_normal_5.x,0,16),",",str(tr_normal_5.y,0,16),",",str(tr_normal_5.z,0,16),">", ",",
"<",str(tr_vertex_2.x,0,16),",",str(tr_vertex_2.y,0,16),",",str(tr_vertex_2.z,0,16),">", ",",
"<",str(tr_normal_2.x,0,16),",",str(tr_normal_2.y,0,16),",",str(tr_normal_2.z,0,16),">",
"uv_vectors ",
"<", str((tr_base_1.x+d_x)/(res_x*px_inc),0,16), ",", str(1-abs(tr_base_1.y-d_y)/(res_y*px_inc),0,16), ">,",
"<", str((tr_base_5.x+d_x)/(res_x*px_inc),0,16), ",", str(1-abs(tr_base_5.y-d_y)/(res_y*px_inc),0,16), ">,",
"<", str((tr_base_2.x+d_x)/(res_x*px_inc),0,16), ",", str(1-abs(tr_base_2.y-d_y)/(res_y*px_inc),0,16), ">}",
"\n")
#end
#local col_count=col_count+1;
#end
#local row_count=row_count+1;
#end
}
#if (c_file!="")
#write (fmesh, "}", "\n")
#fclose fmesh
#end
#end
/*
Flat grid-like mesh for pure orthographic projection
--
Version with UV mapping for use with distrib.#3
*/
#macro meshcam_orthographic_uv(res_x, res_y, c_up_length, c_file)
#local c_direction=1;
#local px_inc=c_up_length*(res_x/res_y)/res_x;
#local centering=<-res_x*.5*px_inc,res_y*.5*px_inc,0>;
#local tr_base_1=<px_inc/2,-px_inc/2,0>;
#local tr_base_2=<0,0,0>;
#local tr_base_3=<px_inc,0,0>;
#local tr_base_4=<px_inc,-px_inc,0>;
#local tr_base_5=<0,-px_inc,0>;
#if (c_file!="")
#fopen fmesh c_file write
#write (fmesh, "mesh{", "\n")
#end
mesh{
#local row_count=0;
#while (row_count<res_y)
#local col_count=0;
#local d_y=row_count*px_inc;
#while (col_count<res_x)
#local d_x=col_count*px_inc;
#local tr_vertex_1=tr_base_1+<d_x,-d_y,c_direction>+centering;
#local tr_vertex_2=tr_base_2+<d_x,-d_y,c_direction>+centering;
#local tr_vertex_3=tr_base_3+<d_x,-d_y,c_direction>+centering;
#local tr_vertex_4=tr_base_4+<d_x,-d_y,c_direction>+centering;
#local tr_vertex_5=tr_base_5+<d_x,-d_y,c_direction>+centering;
#local Norm=z;
smooth_triangle{tr_vertex_1, Norm, tr_vertex_2, Norm, tr_vertex_3, Norm
uv_vectors
<(tr_base_1.x+d_x)/(res_x*px_inc),1-abs(tr_base_1.y-d_y)/(res_y*px_inc)>,
<(tr_base_2.x+d_x)/(res_x*px_inc),1-abs(tr_base_2.y-d_y)/(res_y*px_inc)>,
<(tr_base_3.x+d_x)/(res_x*px_inc),1-abs(tr_base_3.y-d_y)/(res_y*px_inc)>
}
smooth_triangle{tr_vertex_1, Norm, tr_vertex_3, Norm, tr_vertex_4, Norm
uv_vectors
<(tr_base_1.x+d_x)/(res_x*px_inc),1-abs(tr_base_1.y-d_y)/(res_y*px_inc)>,
<(tr_base_3.x+d_x)/(res_x*px_inc),1-abs(tr_base_3.y-d_y)/(res_y*px_inc)>,
<(tr_base_4.x+d_x)/(res_x*px_inc),1-abs(tr_base_4.y-d_y)/(res_y*px_inc)>
}
smooth_triangle{tr_vertex_1, Norm, tr_vertex_4, Norm, tr_vertex_5, Norm
uv_vectors
<(tr_base_1.x+d_x)/(res_x*px_inc),1-abs(tr_base_1.y-d_y)/(res_y*px_inc)>,
<(tr_base_4.x+d_x)/(res_x*px_inc),1-abs(tr_base_4.y-d_y)/(res_y*px_inc)>,
<(tr_base_5.x+d_x)/(res_x*px_inc),1-abs(tr_base_5.y-d_y)/(res_y*px_inc)>
}
smooth_triangle{tr_vertex_1, Norm, tr_vertex_5, Norm, tr_vertex_2, Norm
uv_vectors
<(tr_base_1.x+d_x)/(res_x*px_inc),1-abs(tr_base_1.y-d_y)/(res_y*px_inc)>,
<(tr_base_5.x+d_x)/(res_x*px_inc),1-abs(tr_base_5.y-d_y)/(res_y*px_inc)>,
<(tr_base_2.x+d_x)/(res_x*px_inc),1-abs(tr_base_2.y-d_y)/(res_y*px_inc)>
}
#if (c_file!="")
#write (fmesh, "smooth_triangle{",
"<",str(tr_vertex_1.x,0,16),",",str(tr_vertex_1.y,0,16),",",str(tr_vertex_1.z,0,16),">", ",",
"<",str(Norm.x,0,16),",",str(Norm.y,0,16),",",str(Norm.z,0,16),">", ",",
"<",str(tr_vertex_2.x,0,16),",",str(tr_vertex_2.y,0,16),",",str(tr_vertex_2.z,0,16),">", ",",
"<",str(Norm.x,0,16),",",str(Norm.y,0,16),",",str(Norm.z,0,16),">", ",",
"<",str(tr_vertex_3.x,0,16),",",str(tr_vertex_3.y,0,16),",",str(tr_vertex_3.z,0,16),">", ",",
"<",str(Norm.x,0,16),",",str(Norm.y,0,16),",",str(Norm.z,0,16),">",
"uv_vectors ",
"<", str((tr_base_1.x+d_x)/(res_x*px_inc),0,16), ",", str(1-abs(tr_base_1.y-d_y)/(res_y*px_inc),0,16), ">,",
"<", str((tr_base_2.x+d_x)/(res_x*px_inc),0,16), ",", str(1-abs(tr_base_2.y-d_y)/(res_y*px_inc),0,16), ">,",
"<", str((tr_base_3.x+d_x)/(res_x*px_inc),0,16), ",", str(1-abs(tr_base_3.y-d_y)/(res_y*px_inc),0,16), ">}",
"\n")
#write (fmesh, "smooth_triangle{",
"<",str(tr_vertex_1.x,0,16),",",str(tr_vertex_1.y,0,16),",",str(tr_vertex_1.z,0,16),">", ",",
"<",str(Norm.x,0,16),",",str(Norm.y,0,16),",",str(Norm.z,0,16),">", ",",
"<",str(tr_vertex_3.x,0,16),",",str(tr_vertex_3.y,0,16),",",str(tr_vertex_3.z,0,16),">", ",",
"<",str(Norm.x,0,16),",",str(Norm.y,0,16),",",str(Norm.z,0,16),">",
"<",str(tr_vertex_4.x,0,16),",",str(tr_vertex_4.y,0,16),",",str(tr_vertex_4.z,0,16),">", ",",
"<",str(Norm.x,0,16),",",str(Norm.y,0,16),",",str(Norm.z,0,16),">",
"uv_vectors ",
"<", str((tr_base_1.x+d_x)/(res_x*px_inc),0,16), ",", str(1-abs(tr_base_1.y-d_y)/(res_y*px_inc),0,16), ">,",
"<", str((tr_base_3.x+d_x)/(res_x*px_inc),0,16), ",", str(1-abs(tr_base_3.y-d_y)/(res_y*px_inc),0,16), ">,",
"<", str((tr_base_4.x+d_x)/(res_x*px_inc),0,16), ",", str(1-abs(tr_base_4.y-d_y)/(res_y*px_inc),0,16), ">}",
"\n")
#write (fmesh, "smooth_triangle{",
"<",str(tr_vertex_1.x,0,16),",",str(tr_vertex_1.y,0,16),",",str(tr_vertex_1.z,0,16),">", ",",
"<",str(Norm.x,0,16),",",str(Norm.y,0,16),",",str(Norm.z,0,16),">", ",",
"<",str(tr_vertex_4.x,0,16),",",str(tr_vertex_4.y,0,16),",",str(tr_vertex_4.z,0,16),">", ",",
"<",str(Norm.x,0,16),",",str(Norm.y,0,16),",",str(Norm.z,0,16),">", ",",
"<",str(tr_vertex_5.x,0,16),",",str(tr_vertex_5.y,0,16),",",str(tr_vertex_5.z,0,16),">", ",",
"<",str(Norm.x,0,16),",",str(Norm.y,0,16),",",str(Norm.z,0,16),">",
"uv_vectors ",
"<", str((tr_base_1.x+d_x)/(res_x*px_inc),0,16), ",", str(1-abs(tr_base_1.y-d_y)/(res_y*px_inc),0,16), ">,",
"<", str((tr_base_4.x+d_x)/(res_x*px_inc),0,16), ",", str(1-abs(tr_base_4.y-d_y)/(res_y*px_inc),0,16), ">,",
"<", str((tr_base_5.x+d_x)/(res_x*px_inc),0,16), ",", str(1-abs(tr_base_5.y-d_y)/(res_y*px_inc),0,16), ">}",
"\n")
#write (fmesh, "smooth_triangle{",
"<",str(tr_vertex_1.x,0,16),",",str(tr_vertex_1.y,0,16),",",str(tr_vertex_1.z,0,16),">", ",",
"<",str(Norm.x,0,16),",",str(Norm.y,0,16),",",str(Norm.z,0,16),">", ",",
"<",str(tr_vertex_5.x,0,16),",",str(tr_vertex_5.y,0,16),",",str(tr_vertex_5.z,0,16),">", ",",
"<",str(Norm.x,0,16),",",str(Norm.y,0,16),",",str(Norm.z,0,16),">", ",",
"<",str(tr_vertex_2.x,0,16),",",str(tr_vertex_2.y,0,16),",",str(tr_vertex_2.z,0,16),">", ",",
"<",str(Norm.x,0,16),",",str(Norm.y,0,16),",",str(Norm.z,0,16),">",
"uv_vectors ",
"<", str((tr_base_1.x+d_x)/(res_x*px_inc),0,16), ",", str(1-abs(tr_base_1.y-d_y)/(res_y*px_inc),0,16), ">,",
"<", str((tr_base_5.x+d_x)/(res_x*px_inc),0,16), ",", str(1-abs(tr_base_5.y-d_y)/(res_y*px_inc),0,16), ">,",
"<", str((tr_base_2.x+d_x)/(res_x*px_inc),0,16), ",", str(1-abs(tr_base_2.y-d_y)/(res_y*px_inc),0,16), ">}",
"\n")
#end
#local col_count=col_count+1;
#end
#local row_count=row_count+1;
#end
}
#if (c_file!="")
#write (fmesh, "}", "\n")
#fclose fmesh
#end
#end
/*
Creates a transform to place the mesh camera at the "location", looking at the "look_at ".
*/
#macro meshcam_placement(c_lo, c_la)
transform{
transform{Reorient_Trans(z,<c_la.x,0,c_la.z>-<c_lo.x,0,c_lo.z>)}
transform{Reorient_Trans(<c_la.x,0,c_la.z>-<c_lo.x,0,c_lo.z>,c_la-c_lo)}
translate c_lo
}
#end
|