4 #ifndef tools_sg_primitive_visitor
5 #define tools_sg_primitive_visitor
12 #include "../lina/vec2f"
13 #include "../lina/vec3f"
15 #include "../lina/geom2"
22 virtual bool project(
float& a_x,
float& a_y,
float& a_z,
float& a_w) = 0;
24 virtual bool add_point(
float,
float,
float,
float) = 0;
26 float,
float,
float,
float) = 0;
29 float,
float,
float,
float) = 0;
30 virtual bool add_line(
float,
float,
float,
float,
float,
float,
float,
float,
31 float,
float,
float,
float,
float,
float,
float,
float) = 0;
34 float,
float,
float,
float,
35 float,
float,
float,
float) = 0;
36 virtual bool add_triangle(
float,
float,
float,
float,
float,
float,
float,
float,
37 float,
float,
float,
float,
float,
float,
float,
float,
38 float,
float,
float,
float,
float,
float,
float,
float) = 0;
42 float,
float,
float) = 0;
45 float,
float,
float,
float) = 0;
47 float,
float,
float,
float,
float,
float,
float) = 0;
48 virtual bool add_line_normal(
float,
float,
float,
float,
float,
float,
float,
float,
float,
float,
float,
49 float,
float,
float,
float,
float,
float,
float,
float,
float,
float,
float) = 0;
51 float,
float,
float,
float,
float,
float,
float,
52 float,
float,
float,
float,
float,
float,
float) = 0;
53 virtual bool add_triangle_normal(
float,
float,
float,
float,
float,
float,
float,
float,
float,
float,
float,
54 float,
float,
float,
float,
float,
float,
float,
float,
float,
float,
float,
55 float,
float,
float,
float,
float,
float,
float,
float,
float,
float,
float) = 0;
68 void add_one_point(
float a_x,
float a_y,
float a_z,
float a_r,
float a_g,
float a_b,
float a_a) {
75 size_t num = a_floatn/3;
76 if(num<3)
return false;
80 float p1x,p1y,p1z,w1=1;
81 float p2x,p2y,p2z,w2=1;
82 float p3x,p3y,p3z,w3=1;
84 const float* pos1 = a_xyzs+3*0;
90 const float* pos2 = a_xyzs+3*1;
96 for(
size_t index=2;index<num;index++) {
97 const float* pos = a_xyzs+3*index;
106 if(a_stop)
return false;
118 size_t num = a_floatn/3;
119 if(num<3)
return false;
123 float p1x,p1y,p1z,w1=1;
124 float p2x,p2y,p2z,w2=1;
125 float p3x,p3y,p3z,w3=1;
127 const float* pos1 = a_xyzs+3*0;
133 const float* pos2 = a_xyzs+3*1;
143 const float* nos1 = a_nms+3*0;
149 const float* nos2 = a_nms+3*1;
155 for(
size_t index=2;index<num;index++) {
156 const float* pos = a_xyzs+3*index;
162 const float* nos = a_nms+3*index;
169 p2x,p2y,p2z,w2, n2x,n2y,n2z,
170 p3x,p3y,p3z,w3, n3x,n3y,n3z)) {
171 if(a_stop)
return false;
187 size_t num = a_floatn/3;
188 if(num<3)
return false;
192 float p1x,p1y,p1z,w1=1;
193 float p2x,p2y,p2z,w2=1;
194 float p3x,p3y,p3z,w3=1;
200 const float* pos1 = a_xyzs+3*0;
206 const float* pos2 = a_xyzs+3*1;
216 const float* nos1 = a_nms+3*0;
222 const float* nos2 = a_nms+3*1;
228 const float* ros1 = a_rgbas+4*0;
234 const float* ros2 = a_rgbas+4*1;
240 for(
size_t index=2;index<num;index++) {
241 const float* pos = a_xyzs+3*index;
247 const float* nos = a_nms+3*index;
253 const float* ros = a_rgbas+4*index;
259 if(!
add_triangle_normal(p1x,p1y,p1z,w1, n1x,n1y,n1z, r1,b1,g1,a1,
260 p2x,p2y,p2z,w2, n2x,n2y,n2z, r2,b2,g2,a2,
261 p3x,p3y,p3z,w3, n3x,n3y,n3z, r3,b3,g3,a3)) {
262 if(a_stop)
return false;
283 size_t num = a_floatn/3;
284 if(num<3)
return false;
288 float p1x,p1y,p1z,w1=1;
289 float p2x,p2y,p2z,w2=1;
290 float p3x,p3y,p3z,w3=1;
292 const float* pos1 = a_xyzs+3*0;
298 const float* pos2 = a_xyzs+3*1;
305 for(
size_t index=2;index<num;index++) {
306 const float* pos = a_xyzs+3*index;
316 if(a_stop)
return false;
322 if(a_stop)
return false;
336 flip = flip?
false:
true;
341 bool add_triangles(
size_t a_floatn,
const float* a_xyzs,
bool a_stop =
false){
342 size_t num = a_floatn/3;
343 if(num<3)
return false;
347 float p1x,p1y,p1z,w1=1;
348 float p2x,p2y,p2z,w2=1;
349 float p3x,p3y,p3z,w3=1;
351 for(
size_t index=0;index<num;index+=3) {
353 const float* pos = a_xyzs+3*index;
373 if(a_stop)
return false;
380 size_t num = a_floatn/3;
381 if(num<3)
return false;
385 float p1x,p1y,p1z,w1=1;
386 float p2x,p2y,p2z,w2=1;
387 float p3x,p3y,p3z,w3=1;
389 const float* pos1 = a_xyzs+3*0;
395 const float* pos2 = a_xyzs+3*1;
405 const float* nos1 = a_nms+3*0;
411 const float* nos2 = a_nms+3*1;
418 for(
size_t index=2;index<num;index++) {
419 const float* pos = a_xyzs+3*index;
425 const float* nos = a_nms+3*index;
433 p3x,p3y,p3z,w3, n3x,n3y,n3z,
434 p2x,p2y,p2z,w2, n2x,n2y,n2z)) {
435 if(a_stop)
return false;
439 p2x,p2y,p2z,w2, n2x,n2y,n2z,
440 p3x,p3y,p3z,w3, n3x,n3y,n3z)) {
441 if(a_stop)
return false;
463 flip = flip?
false:
true;
469 size_t num = a_floatn/3;
470 if(num<3)
return false;
474 float p1x,p1y,p1z,w1=1;
475 float p2x,p2y,p2z,w2=1;
476 float p3x,p3y,p3z,w3=1;
482 const float* pos1 = a_xyzs+3*0;
488 const float* pos2 = a_xyzs+3*1;
498 const float* nos1 = a_nms+3*0;
504 const float* nos2 = a_nms+3*1;
510 const float* ros1 = a_rgbas+4*0;
516 const float* ros2 = a_rgbas+4*1;
523 for(
size_t index=2;index<num;index++) {
524 const float* pos = a_xyzs+3*index;
530 const float* nos = a_nms+3*index;
536 const float* ros = a_rgbas+4*index;
543 if(!
add_triangle_normal(p1x,p1y,p1z,w1, n1x,n1y,n1z, r1,g1,b1,a1,
544 p3x,p3y,p3z,w3, n3x,n3y,n3z, r3,g3,b3,a3,
545 p2x,p2y,p2z,w2, n2x,n2y,n2z, r2,g2,b2,a2)) {
546 if(a_stop)
return false;
549 if(!
add_triangle_normal(p1x,p1y,p1z,w1, n1x,n1y,n1z, r1,g1,b1,a1,
550 p2x,p2y,p2z,w2, n2x,n2y,n2z, r2,g2,b2,a2,
551 p3x,p3y,p3z,w3, n3x,n3y,n3z, r3,g3,b3,a3)) {
552 if(a_stop)
return false;
584 flip = flip?
false:
true;
590 size_t num = a_floatn/3;
591 if(num<3)
return false;
595 float p1x,p1y,p1z,w1=1;
596 float p2x,p2y,p2z,w2=1;
597 float p3x,p3y,p3z,w3=1;
603 for(
size_t index=0;index<num;index+=3) {
605 const float* pos = a_xyzs+3*index;
622 const float* nos = a_nms+3*index;
640 p2x,p2y,p2z,w2, n2x,n2y,n2z,
641 p3x,p3y,p3z,w3, n3x,n3y,n3z)) {
642 if(a_stop)
return false;
648 bool add_triangles_rgba(
size_t a_floatn,
const float* a_xyzs,
const float* a_rgbas,
bool a_stop =
false){
649 size_t num = a_floatn/3;
650 if(num<3)
return false;
654 float p1x,p1y,p1z,w1=1;
655 float p2x,p2y,p2z,w2=1;
656 float p3x,p3y,p3z,w3=1;
662 for(
size_t index=0;index<num;index+=3) {
664 const float* pos = a_xyzs+3*index;
681 const float* ros = a_rgbas+4*index;
699 p2x,p2y,p2z,w2,r2,g2,b2,a2,
700 p3x,p3y,p3z,w3,r3,g3,b3,a3)) {
701 if(a_stop)
return false;
708 size_t num = a_floatn/3;
709 if(num<3)
return false;
713 float p1x,p1y,p1z,w1=1;
714 float p2x,p2y,p2z,w2=1;
715 float p3x,p3y,p3z,w3=1;
725 for(
size_t index=0;index<num;index+=3) {
727 const float* pos = a_xyzs+3*index;
744 const float* nos = a_nms+3*index;
761 const float* ros = a_rgbas+4*index;
778 if(!
add_triangle_normal(p1x,p1y,p1z,w1, n1x,n1y,n1z, r1,g1,b1,a1,
779 p2x,p2y,p2z,w2, n2x,n2y,n2z, r2,g2,b2,a2,
780 p3x,p3y,p3z,w3, n3x,n3y,n3z, r3,g3,b3,a3)) {
781 if(a_stop)
return false;
788 size_t num = a_floatn/3;
789 if(num<=1)
return false;
794 float xb,yb,zb,wb,xe,ye,ze,we;
796 for(
size_t iseg = 0;iseg<nseg;iseg++) {
797 pos = (
float*)(a_xyzs+3*iseg);
808 if(!
add_line(xb,yb,zb,wb, xe,ye,ze,we)) {
if(a_stop)
return false;}
814 size_t num = a_floatn/3;
815 if(num<=1)
return false;
820 float xb,yb,zb,wb,xe,ye,ze,we;
821 float rb,gb,bb,ab,re,
ge,be,ae;
824 for(
size_t iseg = 0;iseg<nseg;iseg++) {
825 pos = (
float*)(a_xyzs+3*iseg);
836 ros = (
float*)(a_rgbas+4*iseg);
847 if(!
add_line(xb,yb,zb,wb,rb,gb,bb,ab,
848 xe,ye,ze,we,re,
ge,be,ae)) {
849 if(a_stop)
return false;
856 size_t num = a_floatn/3;
857 if(num<=1)
return false;
862 float xb,yb,zb,wb,xe,ye,ze,we;
863 float nxb,nyb,nzb,nxe,nye,nze;
866 for(
size_t iseg = 0;iseg<nseg;iseg++) {
867 pos = (
float*)(a_xyzs+3*iseg);
878 nos = (
float*)(a_nms+3*iseg);
890 xe,ye,ze,we, nxe,nye,nze)) {
if(a_stop)
return false;}
896 size_t num = a_floatn/3;
897 if(num<=1)
return false;
902 float xb,yb,zb,wb,xe,ye,ze,we;
903 float nxb,nyb,nzb,nxe,nye,nze;
904 float rb,gb,bb,ab,re,
ge,be,ae;
908 for(
size_t iseg = 0;iseg<nseg;iseg++) {
909 pos = (
float*)(a_xyzs+3*iseg);
920 nos = (
float*)(a_nms+3*iseg);
931 ros = (
float*)(a_rgbas+4*iseg);
942 if(!
add_line_normal(xb,yb,zb,wb, nxb,nyb,nzb, rb,gb,bb,ab,
943 xe,ye,ze,we, nxe,nye,nze, re,
ge,be,ae)) {
944 if(a_stop)
return false;
950 bool add_line_loop(
size_t a_floatn,
const float* a_xyzs,
bool a_stop =
false) {
951 size_t num = a_floatn/3;
952 if(num<=1)
return false;
957 float xb,yb,zb,wb,xe,ye,ze,we;
959 for(
size_t iseg = 0;iseg<nseg;iseg++) {
960 pos = (
float*)(a_xyzs+3*iseg);
971 if(!
add_line(xb,yb,zb,wb, xe,ye,ze,we)) {
if(a_stop)
return false;}
975 {pos = (
float*)(a_xyzs+3*(nseg-1)+3);
981 pos = (
float*)(a_xyzs);
987 if(!
add_line(xb,yb,zb,wb, xe,ye,ze,we)){
if(a_stop)
return false;}
993 bool add_line_loop_rgba(
size_t a_floatn,
const float* a_xyzs,
const float* a_rgbas,
bool a_stop =
false) {
994 size_t num = a_floatn/3;
995 if(num<=1)
return false;
1000 float xb,yb,zb,wb,xe,ye,ze,we;
1001 float rb,gb,bb,ab,re,
ge,be,ae;
1004 for(
size_t iseg = 0;iseg<nseg;iseg++) {
1005 pos = (
float*)(a_xyzs+3*iseg);
1016 ros = (
float*)(a_rgbas+4*iseg);
1027 if(!
add_line(xb,yb,zb,wb,rb,gb,bb,ab,
1028 xe,ye,ze,we,re,
ge,be,ae)) {
1029 if(a_stop)
return false;
1034 {pos = (
float*)(a_xyzs+3*nseg);
1040 pos = (
float*)(a_xyzs);
1046 ros = (
float*)(a_rgbas+4*nseg);
1052 ros = (
float*)(a_rgbas);
1058 if(!
add_line(xb,yb,zb,wb,rb,gb,bb,ab,
1059 xe,ye,ze,we,re,
ge,be,ae)){
if(a_stop)
return false;}
1066 size_t num = a_floatn/3;
1067 if(num<=1)
return false;
1068 size_t nseg = num-1;
1072 float xb,yb,zb,wb,xe,ye,ze,we;
1073 float nxb,nyb,nzb,nxe,nye,nze;
1076 for(
size_t iseg = 0;iseg<nseg;iseg++) {
1077 pos = (
float*)(a_xyzs+3*iseg);
1088 nos = (
float*)(a_nms+3*iseg);
1100 xe,ye,ze,we, nxe,nye,nze)) {
if(a_stop)
return false;}
1104 {pos = (
float*)(a_xyzs+3*(nseg-1)+3);
1110 pos = (
float*)(a_xyzs);
1116 nos = (
float*)(a_nms+3*(nseg-1)+3);
1122 nos = (
float*)(a_nms);
1129 xe,ye,ze,we, nxe,nye,nze)) {
if(a_stop)
return false;}
1137 size_t num = a_floatn/3;
1138 if(num<=1)
return false;
1139 size_t nseg = num-1;
1143 float xb,yb,zb,wb,xe,ye,ze,we;
1144 float nxb,nyb,nzb,nxe,nye,nze;
1145 float rb,gb,bb,ab,re,
ge,be,ae;
1149 for(
size_t iseg = 0;iseg<nseg;iseg++) {
1150 pos = (
float*)(a_xyzs+3*iseg);
1161 nos = (
float*)(a_nms+3*iseg);
1172 ros = (
float*)(a_rgbas+4*iseg);
1183 if(!
add_line_normal(xb,yb,zb,wb, nxb,nyb,nzb, rb,gb,bb,ab,
1184 xe,ye,ze,we, nxe,nye,nze, re,
ge,be,ae)) {
1185 if(a_stop)
return false;
1190 {pos = (
float*)(a_xyzs+3*nseg);
1196 pos = (
float*)(a_xyzs);
1202 nos = (
float*)(a_nms+3*nseg);
1208 nos = (
float*)(a_nms);
1214 ros = (
float*)(a_rgbas+4*nseg);
1220 ros = (
float*)(a_rgbas);
1226 if(!
add_line_normal(xb,yb,zb,wb, nxb,nyb,nzb, rb,gb,bb,ab,
1227 xe,ye,ze,we, nxe,nye,nze, re,
ge,be,ae)) {
1228 if(a_stop)
return false;
1236 bool add_lines(
size_t a_floatn,
const float* a_xyzs,
bool a_stop =
false) {
1238 size_t num = a_floatn/3;
1240 size_t nseg = num/2;
1241 if(!nseg)
return false;
1245 float xb,yb,zb,wb,xe,ye,ze,we;
1247 for(
size_t iseg = 0;iseg<nseg;iseg++) {
1248 pos = (
float*)(a_xyzs+6*iseg);
1259 if(!
add_line(xb,yb,zb,wb, xe,ye,ze,we)) {
if(a_stop)
return false;}
1264 bool add_lines_rgba(
size_t a_floatn,
const float* a_xyzs,
const float* a_rgbas,
bool a_stop =
false) {
1266 size_t num = a_floatn/3;
1268 size_t nseg = num/2;
1269 if(!nseg)
return false;
1273 float xb,yb,zb,wb,xe,ye,ze,we;
1274 float rb,gb,bb,ab,re,
ge,be,ae;
1277 for(
size_t iseg = 0;iseg<nseg;iseg++) {
1278 pos = (
float*)(a_xyzs+6*iseg);
1289 ros = (
float*)(a_rgbas+8*iseg);
1300 if(!
add_line(xb,yb,zb,wb,rb,gb,bb,ab, xe,ye,ze,we,re,
ge,be,ae)) {
if(a_stop)
return false;}
1305 bool add_lines_normal(
size_t a_floatn,
const float* a_xyzs,
const float* a_nms,
bool a_stop =
false) {
1307 size_t num = a_floatn/3;
1309 size_t nseg = num/2;
1310 if(!nseg)
return false;
1314 float xb,yb,zb,wb,xe,ye,ze,we;
1315 float nxb,nyb,nzb,nxe,nye,nze;
1320 for(
size_t iseg = 0;iseg<nseg;iseg++) {
1321 pos = (
float*)(a_xyzs+6*iseg);
1332 nos = (
float*)(a_nms+6*iseg);
1344 xe,ye,ze,we, nxe,nye,nze)) {
if(a_stop)
return false;}
1349 bool add_lines_normal_rgba(
size_t a_floatn,
const float* a_xyzs,
const float* a_nms,
const float* a_rgbas,
bool a_stop =
false) {
1351 size_t num = a_floatn/3;
1353 size_t nseg = num/2;
1354 if(!nseg)
return false;
1358 float xb,yb,zb,wb,xe,ye,ze,we;
1359 float nxb,nyb,nzb,nxe,nye,nze;
1360 float rb,gb,bb,ab,re,
ge,be,ae;
1365 for(
size_t iseg = 0;iseg<nseg;iseg++) {
1366 pos = (
float*)(a_xyzs+6*iseg);
1377 nos = (
float*)(a_nms+6*iseg);
1388 ros = (
float*)(a_rgbas+8*iseg);
1399 if(!
add_line_normal(xb,yb,zb,wb, nxb,nyb,nzb, rb,gb,bb,ab,
1400 xe,ye,ze,we, nxe,nye,nze, re,
ge,be,ae)) {
if(a_stop)
return false;}
1405 bool add_points(
size_t a_floatn,
const float* a_xyzs,
bool a_stop =
false){
1406 size_t num = a_floatn/3;
1412 for(
size_t ipt=0;ipt<num;ipt++) {
1413 pos = (
float*)(a_xyzs+3*ipt);
1419 if(!
add_point(x,y,z,w)) {
if(a_stop)
return false;}
1424 bool add_points_rgba(
size_t a_floatn,
const float* a_xyzs,
const float* a_rgbas,
bool a_stop =
false){
1425 size_t num = a_floatn/3;
1435 for(
size_t ipt=0;ipt<num;ipt++) {
1436 pos = (
float*)(a_xyzs+3*ipt);
1442 ros = (
float*)(a_rgbas+4*ipt);
1448 if(!
add_point(x,y,z,w,r,g,b,a)) {
if(a_stop)
return false;}
1454 size_t num = a_floatn/3;
1463 for(
size_t ipt=0;ipt<num;ipt++) {
1464 pos = (
float*)(a_xyzs+3*ipt);
1470 nos = (
float*)(a_nms+3*ipt);
1481 bool add_points_normal_rgba(
size_t a_floatn,
const float* a_xyzs,
const float* a_nms,
const float* a_rgbas,
bool a_stop =
false){
1482 size_t num = a_floatn/3;
1494 for(
size_t ipt=0;ipt<num;ipt++) {
1495 pos = (
float*)(a_xyzs+3*ipt);
1501 nos = (
float*)(a_nms+3*ipt);
1507 ros = (
float*)(a_rgbas+4*ipt);
1513 if(!
add_point_normal(x,y,z,w,nx,ny,nz,r,g,b,a)) {
if(a_stop)
return false;}
1524 return add_lines(a_floatn,a_xyzs,a_stop);
1637 size_t num = a_floatn/2;
1643 for(
size_t ipt=0;ipt<num;ipt++) {
1644 pos = (
float*)(a_xys+2*ipt);
1651 if(!
add_point(x,y,z,w)) {
if(a_stop)
return false;}
1657 bool a_stop =
false,
1658 bool a_triangle_revert =
false){
1659 size_t num = a_floatn/2;
1660 if(num<3)
return false;
1664 float p1x,p1y,p1z,w1=1;
1665 float p2x,p2y,p2z,w2=1;
1666 float p3x,p3y,p3z,w3=1;
1668 const float* pos1 = a_xys+2*0;
1674 const float* pos2 = a_xys+2*1;
1680 for(
size_t index=2;index<num;index++) {
1681 const float* pos = a_xys+2*index;
1687 if(a_triangle_revert) {
1691 if(a_stop)
return false;
1697 if(a_stop)
return false;
1711 bool a_stop =
false,
1712 bool a_triangle_revert =
false){
1713 size_t num = a_floatn/2;
1714 if(num<3)
return false;
1718 float p1x,p1y,p1z,w1=1;
1719 float p2x,p2y,p2z,w2=1;
1720 float p3x,p3y,p3z,w3=1;
1722 const float* pos1 = a_xys+2*0;
1728 const float* pos2 = a_xys+2*1;
1735 for(
size_t index=2;index<num;index++) {
1736 const float* pos = a_xys+2*index;
1742 if(a_triangle_revert) {
1748 if(a_stop)
return false;
1754 if(a_stop)
return false;
1764 if(a_stop)
return false;
1770 if(a_stop)
return false;
1786 flip = flip?
false:
true;
1791 bool add_triangles_xy(
size_t a_floatn,
const float* a_xys,
bool a_stop =
false,
bool a_triangle_revert =
false){
1792 size_t num = a_floatn/2;
1793 if(num<3)
return false;
1797 float p1x,p1y,p1z,w1=1;
1798 float p2x,p2y,p2z,w2=1;
1799 float p3x,p3y,p3z,w3=1;
1801 for(
size_t index=0;index<num;index+=3) {
1803 const float* pos1 = a_xys+2*index;
1809 const float* pos2 = a_xys+2*(index+1);
1815 const float* pos3 = a_xys+2*(index+2);
1821 if(a_triangle_revert) {
1825 if(a_stop)
return false;
1831 if(a_stop)
return false;
1839 size_t num = a_floatn/2;
1840 if(num<=1)
return false;
1841 size_t nseg = num-1;
1845 float xb,yb,zb,wb,xe,ye,ze,we;
1847 for(
size_t iseg = 0;iseg<nseg;iseg++) {
1848 pos = (
float*)(a_xys+2*iseg);
1859 if(!
add_line(xb,yb,zb,wb, xe,ye,ze,we)) {
if(a_stop)
return false;}
1863 {pos = (
float*)(a_xys+2*(nseg-1)+2);
1869 pos = (
float*)(a_xys);
1875 if(!
add_line(xb,yb,zb,wb, xe,ye,ze,we)){
if(a_stop)
return false;}
1882 size_t num = a_floatn/2;
1883 if(num<=1)
return false;
1884 size_t nseg = num-1;
1888 float xb,yb,zb,wb,xe,ye,ze,we;
1890 for(
size_t iseg = 0;iseg<nseg;iseg++) {
1891 pos = (
float*)(a_xys+2*iseg);
1902 if(!
add_line(xb,yb,zb,wb, xe,ye,ze,we)) {
if(a_stop)
return false;}
1911 size_t num = a_floatn/2;
1913 size_t nseg = num/2;
1914 if(!nseg)
return false;
1918 float xb,yb,zb,wb,xe,ye,ze,we;
1920 for(
size_t iseg = 0;iseg<nseg;iseg++) {
1921 pos = (
float*)(a_xys+4*iseg);
1932 if(!
add_line(xb,yb,zb,wb, xe,ye,ze,we)) {
if(a_stop)
return false;}
1967 const float* _xyzs = vec_data<float>(a_xyzs);
1971 const float* _xys = vec_data<float>(a_xys);
1972 return add_primitive_xy(a_mode,a_xys.size(),_xys,a_stop,a_triangle_revert);
1975 const float* _xyzs = vec_data<float>(a_xyzs);
1979 const float* _xyzs = vec_data<float>(a_xyzs);
1982 bool add_lines(
const std::vector<float>& a_xyzs,
bool a_stop =
false){
1983 const float* _xyzs = vec_data<float>(a_xyzs);
1984 return add_lines(a_xyzs.size(),_xyzs,a_stop);
1986 bool add_points(
const std::vector<float>& a_xyzs,
bool a_stop =
false){
1987 const float* _xyzs = vec_data<float>(a_xyzs);
1988 return add_points(a_xyzs.size(),_xyzs,a_stop);
1992 const float* _xyzs = vec_data<float>(a_xyzs);
1997 const float* _xys = vec_data<float>(a_xys);
2001 const float* _xys = vec_data<float>(a_xys);
2005 const float* _xys = vec_data<float>(a_xys);
2047 void add_texture(std::ostream& a_out,
size_t a_xyzn,
const float* a_xyzs,
const img_byte& a_img,
const float* a_tcs) {
2050 unsigned int imw = a_img.
width();
2051 unsigned int imh = a_img.
height();
2052 unsigned int imn = a_img.
bpp();
2053 if((imn!=3)&&(imn!=4)) {
2054 a_out <<
"tools::sg::primitive_visitor::add_texture :"
2055 <<
" not a 3 or 4 bytes per pixel image."
2061 a_out <<
"tools::sg::primitive_visitor::add_texture :"
2062 <<
" primitive has not four points."
2070 vec3f p1(a_xyzs[0],a_xyzs[ 1],a_xyzs[ 2]);
2071 vec3f p2(a_xyzs[3],a_xyzs[ 4],a_xyzs[ 5]);
2073 vec3f p4(a_xyzs[9],a_xyzs[10],a_xyzs[11]);
2078 vec2f t1(a_tcs[0],a_tcs[1]);
2079 vec2f t2(a_tcs[2],a_tcs[3]);
2080 vec2f t3(a_tcs[4],a_tcs[5]);
2081 vec2f t4(a_tcs[6],a_tcs[7]);
2085 a_out <<
"tools::sg::primitive_visitor::add_texture :"
2091 a_out <<
"tools::sg::primitive_visitor::add_texture :"
2096 std::vector<vec2f> poly;
2103 {
float r,g,b,a,tx,ty;
2106 unsigned char* pos = (
unsigned char*)a_img.
buffer();
2107 for(
unsigned int row=0;row<imh;row++) {
2108 for(
unsigned int col=0;col<imw;col++) {
2109 r = (*pos)/255.0f;pos++;
2110 g = (*pos)/255.0f;pos++;
2111 b = (*pos)/255.0f;pos++;
2114 a = (*pos)/255.0f;pos++;
2117 tx = float(col)/float(imw-1);
2118 ty = float(row)/float(imh-1);