return (ptr-output);\r
}\r
\r
+/* Calculate the coordIndex property of the IndexedLineSet for a multipolygon \r
+ This is not ideal -- would be really nice to just share this function with psurf, \r
+ but I'm not smart enough to do that yet*/\r
+static size_t\r
+asx3d3_mpoly_coordindex(const LWMPOLY *psur, char *output)\r
+{\r
+ char *ptr=output;\r
+ LWPOLY *patch;\r
+ int i, j, k, si;\r
+ POINTARRAY *pa;\r
+ int np;\r
+ \r
+ ptr += sprintf(ptr, "");\r
+ j = 0;\r
+ for (i=0; i<psur->ngeoms; i++)\r
+ {\r
+ patch = (LWPOLY *) psur->geoms[i];\r
+ np = patch->rings[0]->npoints - 1;\r
+ for(k=0; k < np ; k++){\r
+ if (k) {\r
+ ptr += sprintf(ptr, " "); \r
+ }\r
+ ptr += sprintf(ptr, "%d", (j + k));\r
+ }\r
+ if (i < (psur->ngeoms - 1) ){\r
+ ptr += sprintf(ptr, " -1 "); //separator for each subgeom\r
+ }\r
+ j += k;\r
+ }\r
+ return (ptr-output);\r
+}\r
+\r
/* Return the linestring as an X3D LineSet */\r
static char *\r
asx3d3_line(const LWLINE *line, char *srs, int precision, int opts, const char *defid)\r
asx3d3_multi_buf(const LWCOLLECTION *col, char *srs, char *output, int precision, int opts, const char *defid)\r
{\r
int type = col->type;\r
- char *ptr, *x3dtype, *coordIndex;\r
+ char *ptr, *x3dtype;\r
int i;\r
- //int numvertices;\r
LWGEOM *subgeom;\r
POINTARRAY *pa;\r
\r
ptr = output;\r
x3dtype="";\r
- coordIndex = lwalloc(1000);\r
\r
- for (i=0; i<col->ngeoms; i++){\r
- /** TODO: This is wrong, but haven't quite figured out how to correct. Involves ring order and bunch of other stuff **/\r
- coordIndex += sprintf(coordIndex, "-1 ");\r
- }\r
\r
if (type == MULTIPOINTTYPE) {\r
x3dtype = "PointSet";\r
}\r
else if (type == MULTIPOLYGONTYPE) {\r
x3dtype = "IndexedFaceSet";\r
- ptr += sprintf(ptr, "<%s %s coordIndex='%s'>", x3dtype, defid, coordIndex);\r
+ ptr += sprintf(ptr, "<%s %s coordIndex='", x3dtype, defid);\r
+ ptr += asx3d3_mpoly_coordindex(col,ptr);\r
+ ptr += sprintf(ptr, "'>");\r
}\r
\r
ptr += sprintf(ptr, "<Coordinate point='");\r