35#include <libFreeWRL.h>
37#include "../vrml_parser/Structs.h"
38#include "../vrml_parser/CRoutes.h"
39#include "../main/headers.h"
41#include "LinearAlgebra.h"
44#include "Component_Geospatial.h"
58extern void Elev_Tri (
int vertex_ind,
int this_face,
int A,
int D,
int E,
int NONORMALS,
struct X3D_PolyRep *this_Elev,
struct SFVec3f *facenormals,
int *pointfaces,
int ccw);
59extern void verify_global_IFS_Coords(
int max);
61extern void Extru_check_normal(
struct SFVec3f *facenormals,
int this_face,
int dire,
struct X3D_PolyRep *rep_,
int ccw);
65static int returnIndexedFanStripIndexSize (
struct Multi_Int32 index ) {
72 for (xx=0; xx<index.n; xx++) {
74 if ((index.p[xx] <=-1) || (xx == (index.n-1))) {
78 if ((index.p[xx] > -1) && (xx == (index.n-1))) {
82 IndexSize += (zz-2) *4;
85 printf (
"IndexedTriangle[Fan|Strip]Set, index %d is less than 3\n",zz);
101 if (this_->coord == 0) {
103 printf (
"checkX3DIFS - have an IFS (%d) with no coords...\n",this_);
107 if (this_->coordIndex.n == 0) {
109 printf (
"checkX3DIFS - have an IFS (%d) with no coordIndex, pointer is %d offset is %d\n",this_,
118int checkX3DElevationGridFields (
struct X3D_ElevationGrid *this_,
float **points,
int *npoints) {
120 int nx = (this_->xDimension);
121 float xSp = (this_->xSpacing);
122 int nz = (this_->zDimension);
123 float zSp = (this_->zSpacing);
124 float *height = ((this_->height).p);
125 int ntri = (nx && nz ? 2 * (nx-1) * (nz-1) : 0);
126 int nh = ((this_->height).n);
134 float *tcoord = NULL;
139 printf (
"Elevationgrid: warning: x,y vs. height: %d * %d ne %d:\n", nx,nz,nh);
141 printf (
"Elevationgrid: error: x,y vs. height: %d * %d ne %d:\n", nx,nz,nh);
147 if ((nx < 2) || (nz < 2)) {
148 printf (
"ElevationGrid: xDimension and zDimension less than 2 %d %d\n", nx,nz);
153 if (!(this_->texCoord)) {
155 FREE_IF_NZ(rep->GeneratedTexCoords[0]);
158 tcoord = rep->GeneratedTexCoords[0] = MALLOC (
float *,
sizeof (
float) * nquads * 12);
162 ConsoleMessage (
"even though we have a texCoord node here, we need to generate");
167 newpoints = MALLOC (
float *,
sizeof (
float) * nz * nx * 3);
169 FREE_IF_NZ(rep->actualCoord);
170 rep->actualCoord = (
float *)newpoints;
173 if (this_->_coordIndex.n > 0) {FREE_IF_NZ(this_->_coordIndex.p);}
174 this_->_coordIndex.p = MALLOC (
int *,
sizeof(
int) * nquads * 5);
175 cindexptr = this_->_coordIndex.p;
177 this_->_coordIndex.n = nquads * 5;
180 *npoints = this_->_coordIndex.n;
182 for (j = 0; j < (nz -1); j++) {
183 for (i=0; i < (nx-1) ; i++) {
190 *cindexptr = j*nx+i; cindexptr++;
191 *cindexptr = j*nx+i+nx; cindexptr++;
192 *cindexptr = j*nx+i+nx+1; cindexptr++;
193 *cindexptr = j*nx+i+1; cindexptr++;
194 *cindexptr = -1; cindexptr++;
201 if (!(this_->texCoord)) {
202 for (j = 0; j < (nz -1); j++) {
203 for (i=0; i < (nx-1) ; i++) {
206 *tcoord = ((float) (i+0)/(nx-1)); tcoord++;
207 *tcoord = ((float)(j+0)/(nz-1)); tcoord ++;
209 *tcoord = ((float) (i+0)/(nx-1)); tcoord++;
210 *tcoord = ((float)(j+1)/(nz-1)); tcoord ++;
212 *tcoord = ((float) (i+1)/(nx-1)); tcoord++;
213 *tcoord = ((float)(j+1)/(nz-1)); tcoord ++;
216 *tcoord = ((float) (i+0)/(nx-1)); tcoord++;
217 *tcoord = ((float)(j+0)/(nz-1)); tcoord ++;
219 *tcoord = ((float) (i+1)/(nx-1)); tcoord++;
220 *tcoord = ((float)(j+1)/(nz-1)); tcoord ++;
222 *tcoord = ((float) (i+1)/(nx-1)); tcoord++;
223 *tcoord = ((float)(j+0)/(nz-1)); tcoord ++;
231 for (j=0; j<nz; j++) {
232 for (i=0; i < nx; i++) {
244 newPoint[0] = xSp * i; newPoint[1] = height[i+(j*nx)]; newPoint[2]=zSp*j;
245 memcpy(newpoints,newPoint,
sizeof(
float)*3);
262 IndexSize = returnIndexedFanStripIndexSize(node->index);
263 if (IndexSize == 0) {
268 newIndex = MALLOC (
int *,
sizeof(
int) * IndexSize);
273 while (xx < (node->index.n-1)) {
276 while ((xx<node->index.n) && (node->index.p[xx] > -1)) xx++;
280 if (xx >= IndexSize) {
281 printf (
"ITFS - index size error... IndexSize < index value \n");
287 for (zz=fanVertex; zz<(xx-2); zz++) {
288 if (windingOrder==0) {
289 newIndex[yy] = node->index.p[zz]; yy++;
290 newIndex[yy] = node->index.p[zz+1]; yy++;
291 newIndex[yy] = node->index.p[zz+2]; yy++;
294 newIndex[yy] = node->index.p[zz]; yy++;
295 newIndex[yy] = node->index.p[zz+2]; yy++;
296 newIndex[yy] = node->index.p[zz+1]; yy++;
299 newIndex[yy] = -1; yy++;
303 if (xx < (node->index.n-1)) {
315 node->_coordIndex.p = newIndex;
316 node->_coordIndex.n = IndexSize;
326 IndexSize = returnIndexedFanStripIndexSize(node->index);
327 if (IndexSize == 0) {
332 newIndex = MALLOC (
int *,
sizeof(
int) * IndexSize);
337 while (xx < (node->index.n-1)) {
340 while ((xx<node->index.n) && (node->index.p[xx] > -1)) xx++;
344 if (xx >= IndexSize) {
345 printf (
"ITFS - index size error... IndexSize < index value \n");
349 for (zz=fanVertex+1; zz<(xx-1); zz++) {
351 newIndex[yy] = node->index.p[fanVertex]; yy++;
352 newIndex[yy] = node->index.p[zz]; yy++;
353 newIndex[yy] = node->index.p[zz+1]; yy++;
354 newIndex[yy] = -1; yy++;
358 if (xx < (node->index.n-1)) {
369 node->_coordIndex.p = newIndex;
370 node->_coordIndex.n = IndexSize;
379 IndexSize = ((node->index.n) * 4) / 3;
380 if (IndexSize <= 0) {
385 newIndex = MALLOC (
int *,
sizeof(
int) * IndexSize);
388 for (xx = 0; xx < node->index.n; xx++) {
389 newIndex[zz] = node->index.p[xx];
405 node->_coordIndex.p = newIndex;
406 node->_coordIndex.n = IndexSize;
415 if ((node->fanCount).n < 1) {
416 ConsoleMessage(
"TriangleFanSet, need at least one fanCount element");
417 node->fanCount.n = 0;
421 for (xx=0; xx<(node->fanCount).n; xx++) {
423 IndexSize += ((node->fanCount).p[xx]-2) * 4;
425 if ((node->fanCount).p[xx] < 3) {
426 printf (
"TriangleFanSet, fanCount index %d is less than 3\n", (node->fanCount).p[xx]);
431 node->_coordIndex.p = MALLOC (
int *,
sizeof(
int) * IndexSize);
432 node->_coordIndex.n = IndexSize;
437 for (xx=0; xx<(node->fanCount).n; xx++) {
441 for (yy=0; yy< ((node->fanCount).p[xx]-2); yy++) {
444 node->_coordIndex.p[IndexSize++] = fanVertex;
445 node->_coordIndex.p[IndexSize++] = zz;
446 node->_coordIndex.p[IndexSize++] = zz+1;
447 node->_coordIndex.p[IndexSize++] = -1;
460 IndexSize = ((node->index.n) /4) * 4;
461 if (IndexSize <= 0) {
468 if (IndexSize != node->index.n) ConsoleMessage (
"IndexedQuadSet using %d of %d indexes according to spec",IndexSize,node->index.n);
473 newIndex = MALLOC (
int *,
sizeof(
int) * IndexSize * 5 / 4);
474 newIndexPtr = newIndex;
477 for (xx = 0; xx < IndexSize; xx++) {
478 *newIndexPtr = node->index.p[xx];
495 FREE_IF_NZ (node->index.p);
496 node->_coordIndex.p = newIndex;
497 node->_coordIndex.n = IndexSize * 5 / 4;
500static void checkQuadSetFields(
struct X3D_QuadSet *node) {
507 dtmp = getCoordinate (node->coord,
"QuadSet");
512 if (((npoints/4)*4) != npoints) {
513 ConsoleMessage (
"Warning, in QuadSet, Coordinates not a multiple of 4\n");
514 npoints = ((npoints/4)*4);
521 IndexSize = (npoints * 8) / 4;
523 node->_coordIndex.p = MALLOC (
int *,
sizeof(
int) * IndexSize);
524 node->_coordIndex.n = IndexSize;
529 for (xx=0; xx<npoints; xx+=4) {
531 node->_coordIndex.p[IndexSize++] = xx;
532 node->_coordIndex.p[IndexSize++] = xx+1;
533 node->_coordIndex.p[IndexSize++] = xx+2;
534 node->_coordIndex.p[IndexSize++] = -1;
535 node->_coordIndex.p[IndexSize++] = xx+2;
536 node->_coordIndex.p[IndexSize++] = xx+3;
537 node->_coordIndex.p[IndexSize++] = xx;
538 node->_coordIndex.p[IndexSize++] = -1;
554 if ((node->stripCount).n < 1) {
555 ConsoleMessage (
"TriangleStripSet, need at least one stripCount element");
556 node->stripCount.n=0;
560 for (xx=0; xx<(node->stripCount).n; xx++) {
562 IndexSize += ((node->stripCount).p[xx]-2) * 4;
564 if ((node->stripCount).p[xx] < 3) {
565 printf (
"TriangleStripSet, index %d is less than 3\n",
566 (node->stripCount).p[xx]);
571 node->_coordIndex.p = MALLOC (
int *,
sizeof(
int) * IndexSize);
572 node->_coordIndex.n = IndexSize;
577 for (xx=0; xx<(node->stripCount).n; xx++) {
580 for (yy=0; yy< ((node->stripCount).p[xx]-2); yy++) {
581 if (windingOrder==0) {
583 node->_coordIndex.p[IndexSize++] = zz;
584 node->_coordIndex.p[IndexSize++] = zz+1;
585 node->_coordIndex.p[IndexSize++] = zz+2;
589 node->_coordIndex.p[IndexSize++] = zz+1;
590 node->_coordIndex.p[IndexSize++] = zz;
591 node->_coordIndex.p[IndexSize++] = zz+2;
594 node->_coordIndex.p[IndexSize++] = -1;
610 dtmp = getCoordinate (node->coord,
"TriangleSet");
615 if (((npoints/3)*3) != npoints) {
616 printf (
"Warning, in TriangleSet, Coordinates not a multiple of 3\n");
617 npoints = ((npoints/3)*3);
624 IndexSize = (npoints * 4) / 3;
626 node->_coordIndex.p = MALLOC (
int *,
sizeof(
int) * IndexSize);
627 node->_coordIndex.n = IndexSize;
632 for (xx=0; xx<npoints; xx+=3) {
634 node->_coordIndex.p[IndexSize++] = xx;
635 node->_coordIndex.p[IndexSize++] = xx+1;
636 node->_coordIndex.p[IndexSize++] = xx+2;
637 node->_coordIndex.p[IndexSize++] = -1;
655 float creaseAngle = (float) PI * 2;
664 int calc_normind = 0;
669 float *fogdepths = NULL;
683 int normalArraySize = INT_ID_UNDEFINED;
690 int *pointfaces = NULL;
698 int this_face, this_coord;
707 if (node->_nodeType == NODE_IndexedFaceSet) {
708 if (!checkX3DIndexedFaceSetFields(node)) {
714 }
else if (node->_nodeType == NODE_ElevationGrid) {
715 if (!checkX3DElevationGridFields(X3D_ELEVATIONGRID(node),
716 (
float **)&points, &npoints)) {
720 }
else if (node->_nodeType == NODE_GeoElevationGrid) {
721 if (!checkX3DGeoElevationGridFields(X3D_GEOELEVATIONGRID(node),
722 (
float **)&points, &npoints)) {
728 switch (node->_nodeType) {
729 case NODE_IndexedFaceSet:
730 convex = node->convex;
732 cpv = node->colorPerVertex;
733 npv = node->normalPerVertex;
735 orig_texCoordIndex = &node->texCoordIndex;
736 orig_colorIndex = &node->colorIndex;
737 orig_normalIndex = &node->normalIndex;
738 creaseAngle = node->creaseAngle;
739 orig_coordIndex = &node->coordIndex;
754 case NODE_ElevationGrid:
755 orig_coordIndex= &X3D_ELEVATIONGRID(node)->_coordIndex;
756 cpv = X3D_ELEVATIONGRID(node)->colorPerVertex;
757 npv = X3D_ELEVATIONGRID(node)->normalPerVertex;
758 creaseAngle = X3D_ELEVATIONGRID(node)->creaseAngle;
759 cc = (
struct X3D_Color *) X3D_ELEVATIONGRID(node)->color;
760 nc = (
struct X3D_Normal *) X3D_ELEVATIONGRID(node)->normal;
770 case NODE_GeoElevationGrid:
771 orig_coordIndex= &X3D_GEOELEVATIONGRID(node)->_coordIndex;
772 cpv = X3D_GEOELEVATIONGRID(node)->colorPerVertex;
773 npv = X3D_GEOELEVATIONGRID(node)->normalPerVertex;
774 creaseAngle = (float) X3D_GEOELEVATIONGRID(node)->creaseAngle;
775 cc = (
struct X3D_Color *) X3D_GEOELEVATIONGRID(node)->color;
776 nc = (
struct X3D_Normal *) X3D_GEOELEVATIONGRID(node)->normal;
783 case NODE_IndexedTriangleFanSet:
784 checkIndexedTriangleFanSetFields(X3D_INDEXEDTRIANGLEFANSET(node));
785 orig_coordIndex= &X3D_INDEXEDTRIANGLEFANSET(node)->_coordIndex;
786 cpv = X3D_INDEXEDTRIANGLEFANSET(node)->colorPerVertex;
787 npv = X3D_INDEXEDTRIANGLEFANSET(node)->normalPerVertex;
788 ccw = X3D_INDEXEDTRIANGLEFANSET(node)->ccw;
789 cc = (
struct X3D_Color *) X3D_INDEXEDTRIANGLEFANSET(node)->color;
790 nc = (
struct X3D_Normal *) X3D_INDEXEDTRIANGLEFANSET(node)->normal;
792 co = (
struct X3D_Coordinate *) X3D_INDEXEDTRIANGLEFANSET(node)->coord;
794 if(!npv) creaseAngle = 0.0;
804 case NODE_IndexedTriangleSet:
805 checkIndexedTriangleSetFields(X3D_INDEXEDTRIANGLESET(node));
806 orig_coordIndex= &X3D_INDEXEDTRIANGLESET(node)->_coordIndex;
807 cpv = X3D_INDEXEDTRIANGLESET(node)->colorPerVertex;
808 npv = X3D_INDEXEDTRIANGLESET(node)->normalPerVertex;
809 ccw = X3D_INDEXEDTRIANGLESET(node)->ccw;
810 cc = (
struct X3D_Color *) X3D_INDEXEDTRIANGLESET(node)->color;
811 nc = (
struct X3D_Normal *) X3D_INDEXEDTRIANGLESET(node)->normal;
813 co = (
struct X3D_Coordinate *) X3D_INDEXEDTRIANGLESET(node)->coord;
815 if(!npv) creaseAngle = 0.0;
825 case NODE_IndexedTriangleStripSet:
826 checkIndexedTriangleStripSetFields(X3D_INDEXEDTRIANGLESTRIPSET(node));
827 orig_coordIndex= &X3D_INDEXEDTRIANGLESTRIPSET(node)->_coordIndex;
828 cpv = X3D_INDEXEDTRIANGLESTRIPSET(node)->colorPerVertex;
829 npv = X3D_INDEXEDTRIANGLESTRIPSET(node)->normalPerVertex;
830 ccw = X3D_INDEXEDTRIANGLESTRIPSET(node)->ccw;
831 cc = (
struct X3D_Color *) X3D_INDEXEDTRIANGLESTRIPSET(node)->color;
832 nc = (
struct X3D_Normal *) X3D_INDEXEDTRIANGLESTRIPSET(node)->normal;
834 co = (
struct X3D_Coordinate *) X3D_INDEXEDTRIANGLESTRIPSET(node)->coord;
836 if(!npv) creaseAngle = 0.0;
846 case NODE_TriangleFanSet:
847 checkTriangleFanSetFields(X3D_TRIANGLEFANSET(node));
848 orig_coordIndex= &X3D_TRIANGLEFANSET(node)->_coordIndex;
849 cpv = X3D_TRIANGLEFANSET(node)->colorPerVertex;
850 npv = X3D_TRIANGLEFANSET(node)->normalPerVertex;
851 ccw = X3D_TRIANGLEFANSET(node)->ccw;
852 cc = (
struct X3D_Color *) X3D_TRIANGLEFANSET(node)->color;
853 nc = (
struct X3D_Normal *) X3D_TRIANGLEFANSET(node)->normal;
857 if(!nc && !npv) creaseAngle = 0.0;
866 case NODE_TriangleSet:
867 checkTriangleSetFields(X3D_TRIANGLESET(node));
868 orig_coordIndex= &X3D_TRIANGLESET(node)->_coordIndex;
869 cpv = X3D_TRIANGLESET(node)->colorPerVertex;
870 npv = X3D_TRIANGLESET(node)->normalPerVertex;
871 ccw = X3D_TRIANGLESET(node)->ccw;
872 cc = (
struct X3D_Color *) X3D_TRIANGLESET(node)->color;
873 nc = (
struct X3D_Normal *) X3D_TRIANGLESET(node)->normal;
877 MARK_EVENT (X3D_NODE(node), offsetof (
struct X3D_TriangleSet, attrib));
880 MARK_EVENT (X3D_NODE(node), offsetof (
struct X3D_TriangleSet, fogCoord));
881 MARK_EVENT (X3D_NODE(node), offsetof (
struct X3D_TriangleSet, metadata));
882 MARK_EVENT (X3D_NODE(node), offsetof (
struct X3D_TriangleSet, normal));
883 MARK_EVENT (X3D_NODE(node), offsetof (
struct X3D_TriangleSet, texCoord));
885 case NODE_TriangleStripSet:
886 checkTriangleStripSetFields(X3D_TRIANGLESTRIPSET(node));
887 orig_coordIndex= &X3D_TRIANGLESTRIPSET(node)->_coordIndex;
888 cpv = X3D_TRIANGLESTRIPSET(node)->colorPerVertex;
889 npv = X3D_TRIANGLESTRIPSET(node)->normalPerVertex;
890 ccw = X3D_TRIANGLESTRIPSET(node)->ccw;
891 cc = (
struct X3D_Color *) X3D_TRIANGLESTRIPSET(node)->color;
892 nc = (
struct X3D_Normal *) X3D_TRIANGLESTRIPSET(node)->normal;
896 if(!nc && !npv) creaseAngle = 0.0;
906 case NODE_IndexedQuadSet:
907 checkIndexedQuadSetFields(X3D_INDEXEDQUADSET(node));
908 orig_coordIndex= &X3D_INDEXEDQUADSET(node)->_coordIndex;
909 cpv = X3D_INDEXEDQUADSET(node)->colorPerVertex;
910 npv = X3D_INDEXEDQUADSET(node)->normalPerVertex;
911 ccw = X3D_INDEXEDQUADSET(node)->ccw;
912 cc = (
struct X3D_Color *) X3D_INDEXEDQUADSET(node)->color;
913 nc = (
struct X3D_Normal *) X3D_INDEXEDQUADSET(node)->normal;
928 checkQuadSetFields(X3D_QUADSET(node));
929 orig_coordIndex= &X3D_QUADSET(node)->_coordIndex;
930 cpv = X3D_QUADSET(node)->colorPerVertex;
931 npv = X3D_QUADSET(node)->normalPerVertex;
932 ccw = X3D_QUADSET(node)->ccw;
933 cc = (
struct X3D_Color *) X3D_QUADSET(node)->color;
934 nc = (
struct X3D_Normal *) X3D_QUADSET(node)->normal;
938 MARK_EVENT (X3D_NODE(node), offsetof (
struct X3D_QuadSet, attrib));
939 MARK_EVENT (X3D_NODE(node), offsetof (
struct X3D_QuadSet, color));
940 MARK_EVENT (X3D_NODE(node), offsetof (
struct X3D_QuadSet, coord));
941 MARK_EVENT (X3D_NODE(node), offsetof (
struct X3D_QuadSet, fogCoord));
942 MARK_EVENT (X3D_NODE(node), offsetof (
struct X3D_QuadSet, metadata));
943 MARK_EVENT (X3D_NODE(node), offsetof (
struct X3D_QuadSet, normal));
944 MARK_EVENT (X3D_NODE(node), offsetof (
struct X3D_QuadSet, texCoord));
948 ConsoleMessage (
"unknown type for make_genericfaceset, %d\n",node->_nodeType);
953 if (orig_coordIndex != NULL) cin= orig_coordIndex->n;
else cin = 0;
954 if (orig_texCoordIndex != NULL) tcin= orig_texCoordIndex->n;
else tcin = 0;
955 if (orig_colorIndex != NULL) colin= orig_colorIndex->n;
else colin = 0;
956 if (orig_normalIndex != NULL) norin= orig_normalIndex->n;
else norin = 0;
959 printf (
"cin %d tcin %d colin %d norin %d\n",cin,tcin,colin,norin);
960 printf (
"start of make_indexedfaceset for node %p, cin %d tcin %d colin %d norin %d\n",node, cin, tcin, colin, norin);
968 printf (
"NOW, the IFS has a cin of %d ca %f\n",cin,creaseAngle);
974 printf (
"Null IFS found, returing ntri0\n");
984 if((orig_coordIndex->p[cin-1]) == -1) { cin--; }
990 dtmp = getCoordinate (X3D_NODE(co),
"make FacedSet");
1000 if(fc2->depth.n < npoints){
1001 fc2->depth.p = REALLOC(fc2->depth.p, npoints *
sizeof(
float));
1002 for(i=fc2->depth.n; i<npoints; i++){
1003 fc2->depth.p[i] = fc2->depth.p[fc->depth.n-1];
1005 fc2->depth.n = npoints;
1007 fogdepths = fc2->depth.p;
1014 if ((cc->_nodeType != NODE_Color) && (cc->_nodeType != NODE_ColorRGBA)) {
1015 printf (
"make_IFS, expected %d got %d\n", NODE_Color, cc->_nodeType);
1017 ncolors = cc->color.n;
1022 if (nc->_nodeType != NODE_Normal) {
1023 printf (
"make_IFS, normal expected %d, got %d\n",NODE_Normal, nc->_nodeType);
1025 nnormals = nc->vector.n;
1033 rep_->tcoordtype=tc->_nodeType;
1039 faces = count_IFS_faces (cin,orig_coordIndex);
1041 printf (
"faces %d, cin %d npoints %d\n",faces,cin,npoints);
1056 facenormals = MALLOC(
struct SFVec3f *,
sizeof(
struct SFVec3f)*faces);
1057 faceok = MALLOC(
int *,
sizeof(
int)*faces);
1058 pointfaces = MALLOC(
int *,
sizeof(
int)*npoints*POINT_FACES);
1062 if (!IFS_face_normals (facenormals,faceok,pointfaces,faces,npoints,cin,points,orig_coordIndex,ccw)) {
1064 FREE_IF_NZ (facenormals);
1065 FREE_IF_NZ (faceok);
1066 FREE_IF_NZ (pointfaces);
1072 for(i=0; i<cin; i++) {
1073 if((orig_coordIndex->p[i]) == -1) {
1080 if(nvert>2) {ntri += nvert-2;}
1084 printf (
"vert %d ntri %d\n",nvert,ntri);
1088 if(!convex) { ntri =ntri*2; }
1093 FREE_IF_NZ(rep_->cindex);
1094 FREE_IF_NZ(rep_->colindex);
1095 FREE_IF_NZ(rep_->norindex);
1097 cindex = rep_->cindex = MALLOC(GLuint *,
sizeof(*(rep_->cindex))*3*(ntri));
1098 colindex = rep_->colindex = MALLOC(GLuint *,
sizeof(*(rep_->colindex))*3*(ntri));
1099 norindex = rep_->norindex = MALLOC(GLuint *,
sizeof(*(rep_->norindex))*3*ntri);
1102 bzero (colindex,
sizeof(*(rep_->colindex))*3*(ntri));
1103 bzero (norindex,
sizeof(*(rep_->colindex))*3*(ntri));
1105 FREE_IF_NZ(rep_->normal);
1108 normalArraySize = 3*3*ntri;
1109 rep_->normal = MALLOC(
float *,
sizeof(*(rep_->normal))*normalArraySize * 2 );
1111 rep_->normal = MALLOC(
float *, 1);
1114 FREE_IF_NZ(rep_->tcindex);
1116 tcindex = rep_->tcindex = MALLOC(GLuint*,
sizeof(*(rep_->tcindex))*3*(ntri));
1119 tess_vs=MALLOC(
int *,
sizeof(*(tess_vs))*(ntri)*3);
1123 for (this_face=0; this_face<faces; this_face++) {
1125 int tess_contour_start;
1129 tg->Tess.global_IFS_Coord_count = 0;
1131 tess_contour_start = 0;
1134 if (!faceok[this_face]) {
1136 printf (
"in generate of faces, face %d is invalid, skipping...\n",this_face);
1142 while ((this_coord < cin) && ((orig_coordIndex->p[this_coord]) != -1)) this_coord++;
1145 if ((this_coord < (cin-1)) && ((orig_coordIndex->p[this_coord]) == -1)) this_coord++;
1149 printf (
"working on face %d coord %d total coords %d coordIndex %d\n",
1150 this_face,this_coord,cin,(orig_coordIndex->p[ this_coord]));
1169 gluTessBeginPolygon( tg->Tess.global_tessobj, &cbdata);
1170 gluTessBeginContour( tg->Tess.global_tessobj );
1172 initind = relative_coord++;
1173 lastind = relative_coord++;
1176 i = (orig_coordIndex->p[ relative_coord + this_coord]);
1181 int foundContour = FALSE;
1185 for (ind=tess_contour_start; ind<relative_coord; ind++) {
1192 if ( orig_coordIndex->p[relative_coord + this_coord] ==
1193 orig_coordIndex->p[ind + this_coord]) {
1195 tess_contour_start = relative_coord+1;
1196 FW_GLU_NEXT_CONTOUR(tg->Tess.global_tessobj,GLU_UNKNOWN);
1197 foundContour = TRUE;
1202 if (!foundContour) {
1204 tess_v[0] = c1->c[0];
1205 tess_v[1] = c1->c[1];
1206 tess_v[2] = c1->c[2];
1207 tess_vs[relative_coord] = relative_coord;
1211 FW_GLU_TESS_VERTEX(tg->Tess.global_tessobj,tess_v,&tess_vs[relative_coord]);
1217 tg->Tess.global_IFS_Coords[tg->Tess.global_IFS_Coord_count++] = initind;
1218 tg->Tess.global_IFS_Coords[tg->Tess.global_IFS_Coord_count++] = lastind;
1219 tg->Tess.global_IFS_Coords[tg->Tess.global_IFS_Coord_count++] = relative_coord;
1221 lastind = relative_coord++;
1224 if (relative_coord + this_coord == cin) {
1227 i = (orig_coordIndex->p[ relative_coord + this_coord]);
1233 gluTessEndContour( tg->Tess.global_tessobj );
1234 gluTessEndPolygon( tg->Tess.global_tessobj );
1239 verify_global_IFS_Coords(cin);
1241 IFS_check_normal (facenormals,this_face,points, this_coord, orig_coordIndex, ccw);
1246 for (i=0; i<tg->Tess.global_IFS_Coord_count; i++) {
1248 cindex [vert_ind] = (orig_coordIndex->p[this_coord+tg->Tess.global_IFS_Coords[i]]);
1257 norindex[vert_ind] = orig_normalIndex->p[this_coord+tg->Tess.global_IFS_Coords[i]];
1260 norindex[vert_ind] = orig_normalIndex->p[this_face];
1266 norindex[vert_ind] = (orig_coordIndex->p[this_coord+tg->Tess.global_IFS_Coords[i]]);
1269 norindex[vert_ind] = this_face;
1275 if (fabs(creaseAngle) > 0.00001) {
1277 if (normalArraySize != INT_ID_UNDEFINED) {
1278 if (calc_normind*3 > normalArraySize) {
1279 printf (
"HMMM _ NORMAL OVERFLOW\n");
1283 normalize_ifs_face (&rep_->normal[calc_normind*3],
1284 facenormals, pointfaces, cindex[vert_ind],
1285 this_face, creaseAngle);
1286 rep_->norindex[vert_ind] = calc_normind++;
1292 veccopy3f(&rep_->normal[vert_ind*3+0],facenormals[this_face].c);
1293 rep_->norindex[vert_ind] = vert_ind;
1306 if (cpv) tmpI = this_coord+tg->Tess.global_IFS_Coords[i];
1307 else tmpI = this_face;
1309 if (tmpI >= orig_colorIndex->n) {
1310 printf (
"faceSet, colorIndex problem, %d >= %d\n", tmpI,orig_colorIndex->n);
1311 colindex[vert_ind] = 0;
1313 colindex[vert_ind] = orig_colorIndex->p[tmpI];
1320 colindex[vert_ind] = (orig_coordIndex->p[this_coord+tg->Tess.global_IFS_Coords[i]]);
1323 colindex[vert_ind] = this_face;
1334 if ((this_coord+tg->Tess.global_IFS_Coords[i]) < tcin) {
1335 tcindex[vert_ind] = orig_texCoordIndex->p[this_coord+tg->Tess.global_IFS_Coords[i]];
1337 tcindex[vert_ind] = 0;
1342 tcindex[vert_ind] = (orig_coordIndex->p[this_coord+tg->Tess.global_IFS_Coords[i]]);
1348 if (vert_ind < (ntri*3-1)) vert_ind++;
1352 this_coord += relative_coord;
1355 if (this_coord < cin)
1356 if ((orig_coordIndex->p[this_coord]) == -1) {this_coord++;}
1361 rep_->ntri = vert_ind/3;
1363 printf (
"make_indededfaceset, end, ntri %d\n",rep_->ntri);
1366 FREE_IF_NZ (tess_vs);
1367 FREE_IF_NZ (facenormals);
1368 FREE_IF_NZ (faceok);
1369 FREE_IF_NZ (pointfaces);
1377double getAlpha(
float ang) {
1378 if (ang >= 0.99999)
return asin(0.9999);
1379 else if (ang <= -0.99999)
return asin(-0.9999);
1380 return asin((
double)ang);
1384double getGamma(
double alpha,
double minor) {
1387 if(APPROX(cos(alpha),0))
1390 gamma=acos(minor / cos(alpha));
1391 if(fabs(sin(gamma)-(-minor/cos(alpha)))>fabs(sin(gamma))) gamma=-gamma;
1408 struct point_XYZ spp1 = {0.0, 0.0, 0.0};
1417 for(spi=1;spi<nspi;spi++) {
1418 VEC_FROM_CDIFF(spine[spi],spine[0],spp1);
1419 if(!APPROX(VECSQ(spp1),0))
1424 spylen=1/(float) sqrt(VECSQ(spp1)); VECSCALE(spp1,spylen);
1426 printf(
"Reference vector along spine=[%f,%f,%f]\n", spp1.x,spp1.y,spp1.z);
1431 if ((fabs(spp1.x) >= fabs(spp1.y)) && (fabs(spp1.x) >= fabs(spp1.z))) {majorX = TRUE;}
1432 else if ((fabs(spp1.y) >= fabs(spp1.x)) && (fabs(spp1.y) >= fabs(spp1.z))) { }
1434 if ((fabs(spp1.x) <= fabs(spp1.y)) && (fabs(spp1.x) <= fabs(spp1.z))) {minorX = TRUE;}
1435 else if ((fabs(spp1.y) <= fabs(spp1.x)) && (fabs(spp1.y) <= fabs(spp1.z))) minorY = TRUE;
1439 printf (
"major axis %d %d %d\n",majorX, majorY, majorZ);
1440 printf (
"minor axis %d %d %d\n",minorX, minorY, minorZ);
1447 alpha = getAlpha((
float)spp1.x);
1448 gamma = getGamma(alpha,minorY?spp1.y:spp1.z);
1451 printf(
"majorX: alpha=%f gamma=%f\n",alpha,gamma);
1456 spy->y=-(cos(alpha)*(-sin(gamma)));
1457 spy->z=cos(alpha)*cos(gamma);
1459 spz->y=-(sin(alpha)*sin(gamma));
1460 spz->z=(-sin(alpha))*cos(gamma);
1465 alpha = getAlpha((
float)spp1.z);
1466 gamma = getGamma(alpha,minorX?spp1.x:spp1.y);
1469 printf(
"majorZ: alpha=%f gamma=%f\n",alpha,gamma);
1472 spy->y=-(cos(alpha)*(-sin(gamma)));
1473 spy->x=cos(alpha)*cos(gamma);
1475 spz->y=-(sin(alpha)*sin(gamma));
1476 spz->x=(-sin(alpha))*cos(gamma);
1484 VECCP(*spy,spp1,crossp);
1485 if( veclengthd((
double*)&crossp) < .001 )
return;
1487 alpha = getAlpha((
float)spp1.y);
1488 gamma = getGamma(alpha,minorX?spp1.x:spp1.z);
1491 printf(
"majorY: lpha=%f gamma=%f\n",alpha,gamma);
1494 spy->x=-(cos(alpha)*(-sin(gamma)));
1495 spy->z=cos(alpha)*cos(gamma);
1497 spz->x=-(sin(alpha)*sin(gamma));
1498 spz->z=(-sin(alpha))*cos(gamma);
1513void stream_extrusion_texture_coords (
struct X3D_PolyRep *rep_,
1524 rep_->GeneratedTexCoords[0] = MALLOC (
float *,
sizeof(
float) * 2 * 3 * rep_->ntri);
1526 nc = rep_->GeneratedTexCoords[0];
1534 for (count = 0; count < rep_->ntri*3; count++) {
1535 ind = tcindex[count];
1538 *nc = tcoord[ind*3]; nc++; *nc = tcoord[ind*3+2]; nc++;
1551 int beginCap = node->beginCap;
1552 int endCap = node->endCap;
1554 int nspi = node->spine.n;
1555 int nsec = node->crossSection.n;
1559 int nori = node->orientation.n;
1562 int nsca = node->scale.n;
1564 struct SFVec3f *spine =node->spine.p;
1565 struct SFVec2f *curve =node->crossSection.p;
1566 struct SFRotation *orientation=node->orientation.p;
1587 int max_ncoord_add=0;
1591 int ncolinear_at_begin=0;
1594 int ncolinear_at_end=0;
1598 int spi,sec,triind,pos_of_last_zvalue;
1599 int next_spi, prev_spi;
1603 int circular = FALSE;
1605 int spine_is_one_vertex;
1607 float spxlen,spylen,spzlen;
1627 struct SFVec3f *facenormals = NULL;
1628 int *pointfaces = 0;
1629 int *defaultface = 0;
1632 float creaseAngle = node->creaseAngle;
1633 int ccw = node->ccw;
1644 printf (
"VRMLExtrusion.pm start\n");
1657 if (nspi < 1)
return;
1664 int tmp1, temp_indx;
1665 int increment, currentlocn;
1667 crossSection = MALLOC(
struct SFVec2f *,
sizeof(crossSection)*nsec*2);
1671 for (tmp1=0; tmp1<nsec; tmp1++) {
1673 crossSection[currentlocn].c[0] = curve[tmp1].c[0];
1674 crossSection[currentlocn].c[1] = curve[tmp1].c[1];
1679 for (temp_indx=0; temp_indx<currentlocn; temp_indx++) {
1680 if ((APPROX(crossSection[currentlocn].c[0],crossSection[temp_indx].c[0])) &&
1681 (APPROX(crossSection[currentlocn].c[1],crossSection[temp_indx].c[1]))) {
1683 if ((temp_indx != 0) && (tmp1 != (nsec-1))) {
1694 currentlocn += increment;
1698 printf (
"we had nsec %d coords, but now we have %d\n",nsec,currentlocn);
1706 ntri = 2 * (nspi-1) * (nsec-1);
1709 printf (
"so, we have ntri %d nspi %d nsec %d\n",ntri,nspi,nsec);
1714 circular = APPROX(spine[0].c[0], spine[nspi-1].c[0]) &&
1715 APPROX(spine[0].c[1], spine[nspi-1].c[1]) &&
1716 APPROX(spine[0].c[2], spine[nspi-1].c[2]);
1719 printf (
"tubular %d circular %d\n",tubular, circular);
1728 if (circular && tubular) {
1732 printf (
"Extrusion, turning off caps \n");
1736 if(beginCap||endCap) {
1737 if(tubular?nsec<4:nsec<3) {
1738 freewrlDie(
"Only two real vertices in crossSection. Caps not possible!");
1741 if(tubular) nctri=nsec-2;
1745 printf (
"nsec = %d, ntri = %d nctri = %d\n",nsec, ntri,nctri);
1751 while(sec+2<=nsec-1 &&
1755 APPROX(0, (crossSection[sec+1].c[0]-crossSection[0].c[0])
1756 *(crossSection[sec+2].c[1]-crossSection[0].c[1])
1757 - (crossSection[sec+1].c[1]-crossSection[0].c[1])
1758 *(crossSection[sec+2].c[0]-crossSection[0].c[0]))
1759 ) ncolinear_at_begin++, sec++;
1764 sec=tubular?(nsec-2):(nsec-1);
1766 APPROX(0, (crossSection[sec ].c[0]-crossSection[0].c[0])
1767 *(crossSection[sec-1].c[1]-crossSection[0].c[1])
1768 - (crossSection[sec ].c[1]-crossSection[0].c[1])
1769 *(crossSection[sec-1].c[0]-crossSection[0].c[0]))
1770 ) ncolinear_at_end++,sec--;
1772 nctri-= ncolinear_at_begin+ncolinear_at_end;
1776 freewrlDie(
"All in crossSection points colinear. Caps not possible!");
1780 nctri= ((beginCap)?nctri:0) + ((endCap)?nctri:0) ;
1787 max_ncoord_add=(nspi-1)*(nsec-1)
1798 rep_->ntri = ntri + nctri;
1802 cindex = rep_->cindex = MALLOC(GLuint *,
sizeof(*(rep_->cindex))*3*(rep_->ntri));
1803 coord = rep_->actualCoord = MALLOC(
float *,
sizeof(*(rep_->actualCoord))*(nspi*nsec+max_ncoord_add)*3);
1804 rep_->normal = MALLOC(
float *,
sizeof(*(rep_->normal))*3*(rep_->ntri)*3);
1805 rep_->norindex = MALLOC(GLuint *,
sizeof(*(rep_->norindex))*3*(rep_->ntri));
1812 facenormals = MALLOC(
struct SFVec3f *,
sizeof(
struct SFVec3f)*(rep_->ntri+1)/2);
1815 pointfaces = MALLOC(
int *,
sizeof(*pointfaces)*POINT_FACES*3*rep_->ntri);
1818 defaultface = MALLOC(
int *,
sizeof(*defaultface)*rep_->ntri);
1822 SCP = MALLOC(
struct SCP *,
sizeof(
struct SCP)*nspi);
1827 tcoordsize = (nctri + (ntri*2))*3;
1830 printf (
"tcoordsize is %d\n",tcoordsize);
1833 FREE_IF_NZ (rep_->GeneratedTexCoords[0]);
1834 FREE_IF_NZ (rep_->tcindex);
1836 tcoord = MALLOC(
float *,
sizeof(*(rep_->GeneratedTexCoords[0]))*tcoordsize);
1838 tcindexsize = rep_->ntri*3;
1840 printf (
"tcindexsize %d\n",tcindexsize);
1843 tcindex = MALLOC(GLuint *,
sizeof(*(rep_->tcindex))*tcindexsize);
1846 beginVals = MALLOC(
float *,
sizeof(
float) * 2 * (nsec+1)*100);
1847 endVals = MALLOC(
float *,
sizeof(
float) * 2 * (nsec+1)*100);
1849 memset((
void *)tcindex,0,tcindexsize*
sizeof(*(rep_->tcindex)));
1854 HAVETOSMOOTH = (fabs(creaseAngle)>0.0001);
1855 for (tmp = 0; tmp < 3*rep_->ntri; tmp++) {
1856 pointfaces[tmp*POINT_FACES]=0;
1864 spine_is_one_vertex=0;
1880 for(spi=0; spi<nspi;spi++){
1881 for(next_spi=spi+1;next_spi<nspi;next_spi++) {
1882 VEC_FROM_CDIFF(spine[spi],spine[next_spi],spp1);
1883 if(!APPROX(VECSQ(spp1),0))
1886 if(next_spi<nspi) SCP[next_spi].prev=next_spi-1;
1889 printf(
"spi=%d next_spi=%d\n",spi,next_spi);
1893 SCP[spi].next=next_spi;
1894 SCP[spi].prev=prev_spi;
1896 while(next_spi>spi+1) {
1898 SCP[spi].next=next_spi;
1899 SCP[spi].prev=prev_spi;
1909 printf (
" SCP[0].next = %d, nspi = %d\n",SCP[0].next,nspi);
1914 if(SCP[0].next==nspi) {
1915 spine_is_one_vertex=1;
1917 printf(
"All spine vertices are the same!\n");
1922 SCP[0].z.x=0; SCP[0].z.y=0; SCP[0].z.z=0;
1924 for(spi=1;spi<nspi;spi++) {
1925 SCP[spi].y=SCP[0].y;
1926 SCP[spi].z=SCP[0].z;
1930 for(spi=0;spi<nspi;spi++) {
1931 printf(
"SCP[%d].next=%d, SCP[%d].prev=%d\n",
1932 spi,SCP[spi].next,spi,SCP[spi].prev);
1938 while(SCP[spi].prev==-1) spi++;
1942 while(SCP[t].next==nspi) t--;
1945 printf (
"now, spi = %d, t = %d\n",spi,t);
1954 VEC_FROM_CDIFF(spine[1],spine[0],SCP[0].y);
1956 VEC_FROM_CDIFF(spine[1],spine[0],spp1);
1958 VEC_FROM_CDIFF(spine[1],spine[0],spm1);
1959 VECCP(spp1,spm1,SCP[1].z);
1973 VECCP(spp1,Yaxis,SCP[1].z);
1976 dlen_cp = veclengthd((
double*)&(SCP[1].z));
1977 if( dlen_cp < .001 )
1985 printf (
"just calculated z for spi 0\n");
1986 printf(
"SCP[0].y=[%f,%f,%f], SCP[1].z=[%f,%f,%f]\n",
1987 SCP[0].y.x,SCP[0].y.y,SCP[0].y.z,
1988 SCP[1].z.x,SCP[1].z.y,SCP[1].z.z);
1993 for(; spi<=t; spi++) {
1995 VEC_FROM_CDIFF(spine[SCP[spi].next],spine[SCP[spi].prev],SCP[spi].y);
1997 VEC_FROM_CDIFF(spine[SCP[spi].next],spine[spi],spp1);
1998 VEC_FROM_CDIFF(spine[SCP[spi].prev],spine[spi],spm1);
1999 VECCP(spp1,spm1,SCP[spi].z);
2001 printf (
"just calculated z for spi %d\n",spi);
2008 printf (
"we are circular\n");
2011 VEC_FROM_CDIFF(spine[SCP[0].next],spine[SCP[nspi-1].prev],SCP[0].y);
2013 SCP[nspi-1].y=SCP[0].y;
2016 VEC_FROM_CDIFF(spine[SCP[0].next],spine[0],spp1);
2017 VEC_FROM_CDIFF(spine[SCP[nspi-1].prev],spine[0],spm1);
2018 VECCP(spp1,spm1,SCP[0].z);
2020 SCP[nspi-1].z=SCP[0].z;
2024 printf (
"we are not circular\n");
2028 VEC_FROM_CDIFF(spine[SCP[0].next],spine[0],SCP[0].y);
2032 VEC_FROM_CDIFF(spine[nspi-1],spine[SCP[nspi-1].prev],SCP[nspi-1].y);
2035 SCP[0].z=SCP[SCP[0].next].z;
2037 SCP[nspi-1].z=SCP[SCP[nspi-1].prev].z;
2040 printf(
"SCP[0].y=[%f,%f,%f], SCP[0].z=[%f,%f,%f]\n",
2041 SCP[0].y.x,SCP[0].y.y,SCP[0].y.z,
2042 SCP[0].z.x,SCP[0].z.y,SCP[0].z.z);
2043 printf(
"SCP[1].y=[%f,%f,%f], SCP[1].z=[%f,%f,%f]\n",
2044 SCP[1].y.x,SCP[1].y.y,SCP[1].y.z,
2045 SCP[1].z.x,SCP[1].z.y,SCP[1].z.z);
2051 while(SCP[spi].prev==-1) {
2052 SCP[spi].y=SCP[0].y;
2053 SCP[spi].z=SCP[0].z;
2058 while(SCP[t].next==nspi) {
2059 SCP[t].y=SCP[nspi-1].y;
2060 SCP[t].z=SCP[nspi-1].z;
2068 pos_of_last_zvalue=-1;
2069 for(spi=0;spi<nspi;spi++) {
2070 if(pos_of_last_zvalue>=0) {
2071 if(APPROX(VECSQ(SCP[spi].z),0))
2072 SCP[spi].z= SCP[pos_of_last_zvalue].z;
2074 pos_of_last_zvalue=spi;
2076 if(!APPROX(VECSQ(SCP[spi].z),0)) {
2079 printf(
"Found z-Value!\n");
2082 for(t=spi-1; t>-1; t--)
2083 SCP[t].z=SCP[spi].z;
2084 pos_of_last_zvalue=spi;
2089 printf(
"pos_of_last_zvalue=%d\n",pos_of_last_zvalue);
2095 for(spi=(circular?2:1);spi<nspi;spi++) {
2096 if(VECPT(SCP[spi].z,SCP[spi-1].z)<0) {
2097 VECSCALE(SCP[spi].z,-1);
2099 printf(
"Extrusion.GenPloyRep: Flipped axis spi=%d\n",spi);
2105 if(pos_of_last_zvalue==-1) {
2108 printf(
"Extrusion.GenPloyRep:Whole spine is colinear!\n");
2112 spy.x=0; spy.y=1; spy.z=0;
2113 spz.x=0; spz.y=0; spz.z=1;
2115 if(!spine_is_one_vertex) {
2116 compute_spy_spz(&spy,&spz,spine,nspi);
2120 printf (
"so, spy [%f %f %f], spz [%f %f %f]\n", spy.x, spy.y,spy.z, spz.x, spz.y, spz.z);
2124 for(spi=0;spi<nspi;spi++) {
2132 for(spi=0;spi<nspi;spi++) {
2133 printf(
"SCP[%d].y=[%f,%f,%f], SCP[%d].z=[%f,%f,%f]\n",
2134 spi,SCP[spi].y.x,SCP[spi].y.y,SCP[spi].y.z,
2135 spi,SCP[spi].z.x,SCP[spi].z.y,SCP[spi].z.z);
2145 if(nsca>1 && nsca <nspi)
2146 printf(
"Extrusion.GenPolyRep: Warning!\n"
2147 "\tNumber of scaling parameters do not match the number of spines!\n"
2148 "\tWill revert to using only the first scale value.\n");
2150 if(nori>1 && nori <nspi)
2151 printf(
"Extrusion.GenPolyRep: Warning!\n"
2152 "\tNumber of orientation parameters "
2153 "do not match the number of spines!\n"
2154 "\tWill revert to using only the first orientation value.\n");
2157 for(spi = 0; spi<nspi; spi++) {
2162 spylen = 1/(float)sqrt(VECSQ(spy)); VECSCALE(spy, spylen);
2163 spzlen = 1/(float)sqrt(VECSQ(spz)); VECSCALE(spz, spzlen);
2164 spxlen = 1/(float)sqrt(VECSQ(spx)); VECSCALE(spx, spxlen);
2168 int ori = (nori==nspi ? spi : 0);
2170 if(IS_ROTATION_VEC_NOT_NORMAL(orientation[ori]))
2171 printf(
"Extrusion.GenPolyRep: Warning!\n"
2172 "\tRotationvector #%d not normal!\n"
2173 "\tWon`t correct it, because it is bad VRML`97.\n",
2176 MATRIX_FROM_ROTATION(orientation[ori],m);
2182 for(sec = 0; sec<nsec; sec++) {
2184 float ptx = crossSection[sec].c[0];
2185 float ptz = crossSection[sec].c[1];
2187 int sca = (nsca==nspi ? spi : 0);
2188 ptx *= node->scale.p[sca].c[0];
2189 ptz *= node->scale.p[sca].c[1];
2202 beginVals[sec*2+0] = ptx;
2203 beginVals[sec*2+1] = ptz;
2204 }
else if (spi == (nspi-1)) {
2206 endVals[(sec*2)+0]=ptx;
2207 endVals[(sec*2)+1]=ptz;
2213 coord[(sec+spi*nsec)*3+0] =
2214 (
float)(spx.x * point.x + spy.x * point.y + spz.x * point.z)
2215 + node->spine.p[spi].c[0];
2216 coord[(sec+spi*nsec)*3+1] =
2217 (
float)(spx.y * point.x + spy.y * point.y + spz.y * point.z)
2218 + node->spine.p[spi].c[1];
2219 coord[(sec+spi*nsec)*3+2] =
2220 (
float)(spx.z * point.x + spy.z * point.y + spz.z * point.z)
2221 + node->spine.p[spi].c[2];
2248 int Atex, Btex, Ctex, Dtex, Etex, Ftex;
2258 printf(
"Coords: \n");
2260 for(x=0; x<nsec; x++) {
2261 for(z=0; z<nspi; z++) {
2262 int xxx = 3*(x+z*nsec);
2263 printf(
"coord: %d [%f %f %f] ",(x+z*nsec),
2264 coord[xxx], coord[xxx+1], coord[xxx+2]);
2275 for(x=0; x<nsec-1; x++) {
2276 for(z=0; z<nspi-1; z++) {
2283 Atex = A; Btex = B; Ctex = C; Dtex = D;
2308 VEC_FROM_COORDDIFF(coord,C,coord,A,ac);
2309 VEC_FROM_COORDDIFF(coord,D,coord,B,bd);
2311 if(sqrt(VECSQ(ac))>sqrt(VECSQ(bd))) {
2312 E=B; F=D; Etex=Btex; Ftex=Dtex;
2314 E=C; F=A; Etex=Ctex; Ftex=Atex;
2320 VEC_FROM_COORDDIFF(coord,B,coord,A,ab);
2321 VEC_FROM_COORDDIFF(coord,D,coord,C,cd);
2324 printf(
"ab=[%f,%f,%f],cd=[%f,%f,%f]\n",
2325 ab.x,ab.y,ab.z,cd.x,cd.y,cd.z);
2326 printf(
"Orig: %d %d [%f %f %f] [%f %f %f] (%d, %d, %d) \n",
2328 coord[D*3], coord[D*3+1], coord[D*3+2],
2329 coord[C*3], coord[C*3+1], coord[C*3+2],
2334 denominator= ab.y*cd.x-ab.x*cd.y;
2335 numerator = (-ac.x)*cd.y-(-ac.y)*cd.x;
2338 if(!APPROX(denominator,0)) {
2339 u=numerator/denominator;
2340 r=((-ac.x)*ab.y-(-ac.y)*ab.x)/denominator;
2343 if(APPROX(numerator,0)) {
2345 denominator=ab.z*cd.x-ab.x*cd.z;
2346 numerator = (-ac.x)*cd.z-(-ac.z)*cd.x;
2347 if(!APPROX(denominator,0)) {
2348 u=numerator/denominator;
2349 r=((-ac.x)*ab.y-(-ac.y)*ab.x)/denominator;
2354 printf(
"u=%f, r=%f\n",u,r);
2357 if(u>=0 && u<=1 && r>=0 && r<=1
2358 && APPROX((-ac.x)+u*ab.x,r*cd.x)
2359 && APPROX((-ac.y)+u*ab.y,r*cd.y)
2360 && APPROX((-ac.z)+u*ab.z,r*cd.z)) {
2363 printf(
"Intersection found at P=[%f,%f,%f]!\n",
2365 coord[A*3+1]+u*ab.y,
2370 coord[(ncoord)*3 ]=coord[A*3 ]+(
float)(u*ab.x);
2371 coord[(ncoord)*3+1]=coord[A*3+1]+(
float)(u*ab.y);
2372 coord[(ncoord)*3+2]=coord[A*3+2]+(
float)(u*ab.z);
2384 Elev_Tri(triind*3, this_face, D,A,E, TRUE , rep_, facenormals, pointfaces,ccw);
2386 tcindex[triind*3] = (GLuint)Dtex;
2387 tcindex[triind*3+2] = (GLuint)Etex;
2388 tcindex[triind*3+1] = (GLuint)Atex;
2390 defaultface[triind] = this_face;
2395 Elev_Tri(triind*3, this_face, B, C, F, TRUE, rep_, facenormals, pointfaces,ccw);
2397 tcindex[triind*3] = (GLuint)Btex;
2398 tcindex[triind*3+1] = (GLuint)Ctex;
2399 tcindex[triind*3+2] = (GLuint)Ftex;
2401 if ((triind*3+2) >= tcindexsize)
2402 printf (
"INTERNAL ERROR: Extrusion - tcindex size too small!\n");
2403 defaultface[triind] = this_face;
2411 for (tmp=0; tmp<(triind*3); tmp++) {
2413 normalize_ifs_face (&rep_->normal[tmp*3],
2414 facenormals, pointfaces, cindex[tmp],
2415 defaultface[tmp/3], creaseAngle);
2417 int iiface = defaultface[tmp/3];
2418 veccopy3f(&rep_->normal[tmp*3+0],facenormals[iiface].c);
2423 rep_->norindex[tmp] = (GLuint)tmp;
2426 end_of_sides = triind*3;
2438 if (tubular) endpoint = nsec-3-ncolinear_at_end;
2439 else endpoint = nsec-2-ncolinear_at_end;
2446 triind_start = triind;
2448 for(x=0+ncolinear_at_begin; x<endpoint; x++) {
2449 Elev_Tri(triind*3, this_face, 0, x+2, x+1, TRUE , rep_, facenormals, pointfaces,ccw);
2450 defaultface[triind] = this_face;
2451 Extru_tex(triind*3, tci_ct, 0 , +x+2, x+1, tcindex ,ccw,tcindexsize);
2455 Extru_ST_map(triind_start,0+ncolinear_at_begin,endpoint,
2456 beginVals,nsec,tcindex, cindex, tcoord, tcoordsize);
2457 tci_ct+=endpoint-(0+ncolinear_at_begin);
2458 triind_start+=endpoint-(0+ncolinear_at_begin);
2463 triind_start = triind;
2465 for(x=0+ncolinear_at_begin; x<endpoint; x++) {
2466 Elev_Tri(triind*3, this_face, 0 +(nspi-1)*nsec,
2467 x+1+(nspi-1)*nsec,x+2+(nspi-1)*nsec,
2468 TRUE , rep_, facenormals, pointfaces,ccw);
2469 defaultface[triind] = this_face;
2470 Extru_tex(triind*3, tci_ct, 0+(nspi-1)*nsec,
2473 tcindex,ccw,tcindexsize);
2477 Extru_ST_map(triind_start,0+ncolinear_at_begin,endpoint,
2478 endVals, nsec, tcindex, cindex, tcoord, tcoordsize);
2483 if(beginCap || endCap) {
2495 tess_vs=MALLOC(
int *,
sizeof(*(tess_vs)) * (nsec - 3 - ncolinear_at_end) * 3);
2498 if (tubular) endpoint = nsec-1-ncolinear_at_end;
2499 else endpoint = nsec-ncolinear_at_end;
2503 tg->Tess.global_IFS_Coord_count = 0;
2505 gluTessBeginPolygon( tg->Tess.global_tessobj, NULL);
2506 gluTessBeginContour( tg->Tess.global_tessobj );
2508 for(x=0+ncolinear_at_begin; x<endpoint; x++) {
2510 c1 = (
struct SFVec3f *) &rep_->actualCoord[3*x];
2514 tess_v[0] = c1->c[0]; tess_v[1] = c1->c[1]; tess_v[2] = c1->c[2];
2516 FW_GLU_TESS_VERTEX(tg->Tess.global_tessobj,tess_v,&tess_vs[x]);
2519 gluTessEndContour( tg->Tess.global_tessobj );
2520 gluTessEndPolygon( tg->Tess.global_tessobj );
2522 verify_global_IFS_Coords(ntri*3);
2524 for (x=0; x<tg->Tess.global_IFS_Coord_count; x+=3) {
2527 Elev_Tri(triind*3, this_face, tg->Tess.global_IFS_Coords[x],
2528 tg->Tess.global_IFS_Coords[x+2], tg->Tess.global_IFS_Coords[x+1],
2529 TRUE , rep_, facenormals, pointfaces,ccw);
2530 defaultface[triind] = this_face;
2534 Extru_check_normal (facenormals,this_face,-1,rep_,ccw);
2540 tg->Tess.global_IFS_Coord_count = 0;
2542 gluTessBeginPolygon( tg->Tess.global_tessobj, NULL);
2543 gluTessBeginContour( tg->Tess.global_tessobj );
2545 for(x=0+ncolinear_at_begin; x<endpoint; x++) {
2546 c1 = (
struct SFVec3f *) &rep_->actualCoord[3*(x+(nspi-1)*nsec)];
2547 tess_v[0] = c1->c[0]; tess_v[1] = c1->c[1]; tess_v[2] = c1->c[2];
2548 tess_vs[x] = x+(nspi-1)*nsec;
2549 FW_GLU_TESS_VERTEX(tg->Tess.global_tessobj,tess_v,&tess_vs[x]);
2552 gluTessEndContour( tg->Tess.global_tessobj );
2553 gluTessEndPolygon( tg->Tess.global_tessobj );
2555 verify_global_IFS_Coords(ntri*3);
2557 for (x=0; x<tg->Tess.global_IFS_Coord_count; x+=3) {
2558 Elev_Tri(triind*3, this_face, tg->Tess.global_IFS_Coords[x],
2559 tg->Tess.global_IFS_Coords[x+1], tg->Tess.global_IFS_Coords[x+2],
2560 TRUE , rep_, facenormals, pointfaces,ccw);
2561 defaultface[triind] = this_face;
2565 Extru_check_normal (facenormals,this_face,1,rep_,ccw);
2571 FREE_IF_NZ (tess_vs);
2581 for (tmp=end_of_sides; tmp<(triind*3); tmp++) {
2582 int iiface = defaultface[tmp/3];
2583 veccopy3f(&rep_->normal[tmp*3+0],facenormals[iiface].c);
2587 rep_->norindex[tmp] = (GLuint)tmp;
2592 if (tcoordsize <= ((nsec-1)+(nspi-1)*(nsec-1)*3+2)) {
2593 printf (
"INTERNAL ERROR: Extrusion side tcoord calcs nspi %d nsec %d tcoordsize %d\n",
2594 nspi,nsec,tcoordsize);
2596 for(sec=0; sec<nsec; sec++) {
2597 for(spi=0; spi<nspi; spi++) {
2601 tcoord[(sec+spi*nsec)*3+0] = (
float) sec/(nsec-1);
2602 tcoord[(sec+spi*nsec)*3+1] = 0;
2603 tcoord[(sec+spi*nsec)*3+2] = (
float) spi/(nspi-1);
2609 printf (
"done, lets free\n");
2613 FREE_IF_NZ (defaultface);
2614 FREE_IF_NZ (pointfaces);
2615 FREE_IF_NZ (facenormals);
2616 FREE_IF_NZ (crossSection);
2618 FREE_IF_NZ (beginVals);
2619 FREE_IF_NZ (endVals);
2623 stream_extrusion_texture_coords (rep_, tcoord, tcindex);
2626 FREE_IF_NZ (tcoord);
2627 FREE_IF_NZ (tcindex);
2631 printf(
"Extrusion.GenPloyRep: triind=%d ntri=%d nctri=%d "
2632 "ncolinear_at_begin=%d ncolinear_at_end=%d\n",
2633 triind,ntri,nctri,ncolinear_at_begin,ncolinear_at_end);
2635 printf (
"end VRMLExtrusion.pm\n");