#N canvas 464 45 968 636 10;
#X declare -lib Gem;
#X text 58 45 Class: geometric object;
#X obj 13 64 cnv 15 450 100 empty empty empty 20 12 0 14 #e0e0e0 #404040 0;
#X obj 13 212 cnv 15 450 280 empty empty empty 20 12 0 14 #e0e0e0 #404040 0;
#X text 17 214 Inlets:;
#X obj 13 173 cnv 15 450 30 empty empty empty 20 12 0 14 #bcbcbc #404040 0;
#X text 22 172 Arguments:;
#X text 32 229 Inlet 1: gemlist;
#X text 16 448 Outlets:;
#X text 30 460 Outlet 1: gemlist;
#X obj 475 63 cnv 15 480 560 empty empty empty 20 12 0 14 #e0e0e0 #404040 0;
#X obj 796 74 cnv 15 150 170 empty empty empty 20 12 0 14 #14e814 #404040 0;
#X obj 796 254 cnv 15 150 130 empty empty empty 20 12 0 14 #14e814 #404040 0;
#X obj 486 74 cnv 15 300 290 empty empty empty 20 12 0 14 #14e814 #404040 0;
#X msg 523 153 draw line;
#X msg 523 174 draw fill;
#X msg 523 132 draw point;
#X msg 534 287 width 1;
#X msg 534 308 width 4;
#X msg 523 195 draw line1;
#X msg 523 216 draw line2;
#X msg 523 237 draw line3;
#X msg 523 258 draw line4;
#X msg 657 189 draw control_line;
#X msg 657 231 draw control_line1;
#X msg 657 252 draw control_line2;
#X msg 657 210 draw control_fill;
#X text 592 82 draw style;
#X obj 486 378 cnv 15 300 230 empty empty empty 20 12 0 14 #14e814 #404040 0;
#X obj 494 387 gemhead;
#X floatatom 522 430 5 0 0 0 - - - 0;
#X floatatom 557 430 5 0 0 0 - - - 0;
#X floatatom 593 430 5 0 0 0 - - - 0;
#X floatatom 562 388 5 0 0 0 - - - 0;
#X floatatom 610 388 5 0 0 0 - - - 0;
#X floatatom 659 388 5 0 0 0 - - - 0;
#X obj 494 451 rotateXYZ 0 0 0;
#X text 28 430 Inlet 2: not used;
#X text 32 243 Inlet 1: message: draw [line|fill|point|...];
#X obj 13 503 cnv 15 450 120 empty empty empty 20 12 0 14 #bcbcbc #404040 0;
#X text 31 336 Inlet 1 : message: set Mx My X Y Z;
#X text 31 296 Inlet 1: message: grid X Y;
#X text 31 259 Inlet 1: message: res X Y;
#X text 59 28 Synopsis: [surface3d];
#X text 31 388 Inlet 1: normal 0/1;
#X obj 795 399 cnv 15 150 110 empty empty empty 20 12 0 14 #14e814 #404040 0;
#X msg 812 434 normal \$1;
#X obj 812 415 tgl 15 1 empty empty empty 17 7 0 10 #fcfcfc #000000 #000000 1 1;
#X text 33 146 This object is related to curve3d;
#N canvas 484 243 450 300 META 0;
#X obj 10 25 declare -lib Gem;
#X text 10 65 KEYWORDS Gem openGL shape;
#X text 20 85 INLET_0 gemlist draw res grid set normal;
#X text 20 105 OUTLET_0 gemlist;
#X text 10 125 AUTHOR IOhannes m zmölnig;
#X text 10 145 LICENSE GPL-2.0-or-later;
#X text 10 45 DESCRIPTION Renders a 3d bicubic surface.;
#X restore 848 8 pd META;
#X obj 821 582 gemhead;
#X obj 821 602 world_light;
#X obj 815 515 _gemwin \; 0 \; 0 \; lighting 1;
#X msg 657 273 draw default;
#X text 271 4 Create a 3d bicubic surface \, using a matrix of control points, f 61;
#X obj 810 218 s surface3d;
#X obj 807 356 s surface3d;
#X obj 627 333 s surface3d_control;
#X obj 494 334 s surface3d_render;
#X obj 504 558 r surface3d;
#X obj 504 478 r surface3d;
#X obj 812 455 s surface3d_render;
#X msg 834 131 res 4 4;
#X msg 834 152 res 5 5;
#X text 653 103 draw control grid of the surface, f 17;
#X text 517 103 draw the surface;
#X text 806 110 (resets positions);
#X text 804 78 resolution of the control matrix, f 17;
#X text 805 260 resolution of the surface grid, f 17;
#X text 51 399 since computing normals uses a lot of processing power \, you can disable normals with this message (default: 1), f 55;
#X obj 112 548 bng 16 250 50 0 empty empty randomize\ z 0 -8 0 10 #fcfcfc #000000 #000000;
#X obj 31 590 s surface3d;
#X text 21 507 Example:;
#N canvas 716 211 865 683 set_surface 0;
#X obj 64 156 until;
#X obj 64 126 t f b;
#X msg 104 156 0;
#X obj 64 189 f;
#X obj 91 189 + 1;
#X obj 64 241 mod;
#X obj 107 241 div;
#X obj 64 262 t f f;
#X obj 107 262 t f f;
#X obj 120 345 /;
#X obj 185 345 /;
#X obj 149 263 - 3;
#X obj 220 263 - 3;
#X obj 120 304 - 1;
#X obj 185 304 - 1;
#X obj 120 366 * 4;
#X obj 185 366 * 4;
#X obj 120 387 - 2;
#X obj 185 387 - 2;
#X obj 265 42 inlet;
#X obj 64 548 pack f f f f f;
#X msg 64 569 set \$1 \$2 \$3 \$4 \$5;
#X obj 540 585 loadbang;
#X obj 355 42 inlet;
#X obj 64 623 outlet;
#X obj 505 207 *;
#X msg 653 567 resize \$1;
#X obj 505 228 s \$0-size;
#X obj 653 544 r \$0-size;
#X obj 74 71 r \$0-size;
#X obj 265 133 s \$0-randomz;
#X obj 654 428 line;
#X obj 654 458 t b f;
#X obj 149 188 r \$0-resx;
#X obj 220 188 r \$0-resy;
#X obj 532 130 unpack;
#X obj 532 172 s \$0-resx;
#X obj 565 151 s \$0-resy;
#X obj 64 101 f;
#X obj 705 86 array get \$0-zto;
#X obj 705 107 array set \$0-zfrom;
#X obj 686 135 r \$0-size;
#X obj 671 207 until;
#X obj 671 177 t f b;
#X msg 711 207 0;
#X obj 671 234 f;
#X obj 698 234 + 1;
#X obj 671 156 f;
#X obj 671 265 t b f;
#X obj 671 370 tabwrite \$0-zto;
#X obj 730 489 s \$0-interp;
#X obj 276 490 r \$0-interp;
#X obj 246 511 *;
#X obj 64 214 t f f f, f 15;
#X obj 246 427 t a a, f 7;
#X obj 285 448 tabread \$0-zfrom;
#X obj 246 469 tabread \$0-zto;
#X obj 246 490 -;
#X obj 246 532 +, f 7;
#X obj 671 349 *, f 8;
#X obj 654 42 r \$0-randomz;
#X obj 670 604 array define \$0-zfrom 6;
#X obj 670 625 array define \$0-zto 6;
#X msg 654 406 0 \, 1 1000;
#X obj 64 46 r \$0-setall;
#X obj 654 489 s \$0-setall;
#X msg 382 107 1;
#X obj 354 133 s \$0-randomz-tgl;
#X obj 671 286 random 201;
#X obj 671 307 / 100;
#X obj 671 328 - 1;
#X text 256 224 n points create n-1 divisions. the outer points are used for interpolation only. so the actual surface only covers the inner points (n-3 divisions)., f 33;
#X text 259 299 offset to position point (1 1) at (0 \, 0), f 21;
#X text 258 369 scale and position to (-2 \, -2)..(2 \, 2), f 21;
#X obj 505 42 r surface3d;
#X obj 505 63 route res;
#X obj 654 63 t b b b b;
#X obj 716 327 r \$0-randomz-tgl;
#X msg 354 107 0;
#X obj 265 63 t b f;
#X obj 355 63 t b f;
#X obj 505 100 t a a;
#X obj 540 627 s surface3d;
#X msg 540 606 res 5 5;
#X connect 0 0 3 0;
#X connect 1 0 0 0;
#X connect 1 1 2 0;
#X connect 2 0 3 1;
#X connect 3 0 4 0;
#X connect 3 0 53 0;
#X connect 4 0 3 1;
#X connect 5 0 7 0;
#X connect 6 0 8 0;
#X connect 7 0 20 0;
#X connect 7 1 13 0;
#X connect 8 0 20 1;
#X connect 8 1 14 0;
#X connect 9 0 15 0;
#X connect 10 0 16 0;
#X connect 11 0 9 1;
#X connect 12 0 10 1;
#X connect 13 0 9 0;
#X connect 14 0 10 0;
#X connect 15 0 17 0;
#X connect 16 0 18 0;
#X connect 17 0 20 2;
#X connect 18 0 20 3;
#X connect 19 0 79 0;
#X connect 20 0 21 0;
#X connect 21 0 24 0;
#X connect 22 0 83 0;
#X connect 23 0 80 0;
#X connect 25 0 27 0;
#X connect 26 0 61 0;
#X connect 26 0 62 0;
#X connect 28 0 26 0;
#X connect 29 0 38 0;
#X connect 31 0 32 0;
#X connect 32 0 65 0;
#X connect 32 1 50 0;
#X connect 33 0 11 0;
#X connect 33 0 6 1;
#X connect 33 0 5 1;
#X connect 34 0 12 0;
#X connect 35 0 36 0;
#X connect 35 1 37 0;
#X connect 38 0 1 0;
#X connect 39 0 40 0;
#X connect 41 0 47 1;
#X connect 42 0 45 0;
#X connect 43 0 42 0;
#X connect 43 1 44 0;
#X connect 44 0 45 1;
#X connect 45 0 46 0;
#X connect 45 0 48 0;
#X connect 46 0 45 1;
#X connect 47 0 43 0;
#X connect 48 0 68 0;
#X connect 48 1 49 1;
#X connect 51 0 52 1;
#X connect 52 0 58 0;
#X connect 53 0 5 0;
#X connect 53 1 6 0;
#X connect 53 2 54 0;
#X connect 54 0 56 0;
#X connect 54 1 55 0;
#X connect 55 0 57 1;
#X connect 55 0 58 1;
#X connect 56 0 57 0;
#X connect 57 0 52 0;
#X connect 58 0 20 4;
#X connect 59 0 49 0;
#X connect 60 0 76 0;
#X connect 63 0 31 0;
#X connect 64 0 38 0;
#X connect 66 0 67 0;
#X connect 68 0 69 0;
#X connect 69 0 70 0;
#X connect 70 0 59 0;
#X connect 74 0 75 0;
#X connect 75 0 81 0;
#X connect 76 0 63 0;
#X connect 76 1 47 0;
#X connect 76 3 39 0;
#X connect 77 0 59 1;
#X connect 78 0 67 0;
#X connect 79 0 30 0;
#X connect 79 1 78 0;
#X connect 80 0 30 0;
#X connect 80 1 66 0;
#X connect 81 0 25 0;
#X connect 81 1 35 0;
#X connect 83 0 82 0;
#X restore 31 569 pd set_surface;
#X text 13 68 Description: Renders a 3d bicubic surface;
#X text 52 310 This message is used for changing the subdivision of the displayed surface (X Y are ints);
#X text 53 272 This message is used for changing the size of the control matrix (X \, Y are ints);
#X text 53 349 This message can be used to set the position of a control point. (Mx \, My: index of the point in the control matrix. X \, Y \, Z: actual position of this point, f 57;
#X text 33 85 The surface3d object renders a surface at the current position with current color or texture. The shape of the surface is controlled by a matrix. The surface goes through all control points between index (1 1) and (resX-1 resY-1)., f 62;
#X msg 829 290 grid 2 2;
#X text 67 182 size of the control matrix (default and minimum: 4 4);
#X text 129 569 <-- draws the surface from (-2 \, -2 \, z) to (2 \, 2 \, z);
#X obj 494 408 translateXYZ 0 0 0;
#X obj 580 478 r surface3d_render;
#X obj 580 558 r surface3d_control;
#X msg 657 147 draw control_point;
#X obj 494 531 color 0 1 0;
#X obj 667 168 loadbang;
#X text 154 582 check subpatch for more explanations;
#X obj 494 502 surface3d 5 5;
#X obj 494 582 surface3d 5 5;
#X obj 31 548 bng 16 250 50 0 empty empty flat 0 -8 0 10 #fcfcfc #000000 #000000;
#X msg 834 173 res 8 8;
#X msg 834 194 res 12 12;
#X msg 829 332 grid 60 60;
#X msg 829 311 grid 4 30;
#X connect 13 0 57 0;
#X connect 14 0 57 0;
#X connect 15 0 57 0;
#X connect 16 0 57 0;
#X connect 17 0 57 0;
#X connect 18 0 57 0;
#X connect 19 0 57 0;
#X connect 20 0 57 0;
#X connect 21 0 57 0;
#X connect 22 0 56 0;
#X connect 23 0 56 0;
#X connect 24 0 56 0;
#X connect 25 0 56 0;
#X connect 28 0 81 0;
#X connect 29 0 35 1;
#X connect 30 0 35 2;
#X connect 31 0 35 3;
#X connect 32 0 81 1;
#X connect 33 0 81 2;
#X connect 34 0 81 3;
#X connect 35 0 88 0;
#X connect 45 0 60 0;
#X connect 46 0 45 0;
#X connect 49 0 50 0;
#X connect 52 0 56 0;
#X connect 58 0 89 0;
#X connect 59 0 88 0;
#X connect 61 0 54 0;
#X connect 62 0 54 0;
#X connect 69 0 72 1;
#X connect 72 0 70 0;
#X connect 78 0 55 0;
#X connect 81 0 35 0;
#X connect 82 0 88 0;
#X connect 83 0 89 0;
#X connect 84 0 56 0;
#X connect 85 0 89 0;
#X connect 86 0 22 0;
#X connect 88 0 85 0;
#X connect 90 0 72 0;
#X connect 91 0 54 0;
#X connect 92 0 54 0;
#X connect 93 0 55 0;
#X connect 94 0 55 0;
