OSG使用Plugin PLY插件来完成PLY文件的读写。在OSG 3.0.0中,这个插件存在一个bug,即无法读取由Windows应用产生的PLY格式文件。
我们需要对“src\osgPlugins\ply\plyfile.cpp”文件进行一些修改,完成de-bug工作。具体说来就是将文件中的get_words()函数用下面的内容替换:
char **get_words(FILE *fp, int *nwords, char **orig_line)
{
#define BIG_STRING 4096
static char str[BIG_STRING];
static char str_copy[BIG_STRING];
char **words;
int max_words = 10;
int num_words = 0;
char *ptr,*ptr2;
char *result;
fpos_t pos; //keep track of file pointer
int nbytes;
int nonUNIX;
nonUNIX=0;
nbytes=0;
fgetpos(fp, &pos);
words = (char **) myalloc (sizeof (char *) * max_words);
/* read in a line */
result = fgets (str, BIG_STRING, fp);
if (result == NULL) {
*nwords = 0;
*orig_line = NULL;
return (NULL);
}
/* convert line-feed and tabs into spaces */
/* (this guarentees that there will be a space before the */
/* null character at the end of the string) */
str[BIG_STRING-2] = ' ';
str[BIG_STRING-1] = '\0';
for (ptr = str, ptr2 = str_copy; *ptr != '\0'; ptr++, ptr2++) {
*ptr2 = *ptr;
nbytes++;
if (*ptr == '\t') {
*ptr = ' ';
*ptr2 = ' ';
}
else if (*ptr == '\n') {
*ptr = ' '; //has to have a space, to be caught later when grouping words
*ptr2 = '\0';
break;
}
else if (*ptr == '\r')
{ //MAC line break
nonUNIX=1;
if(*(ptr+1)=='\n') //actuall PC line break
{
nbytes++;
}
*ptr = ' ';
*(ptr+1) = '\0'; //when reading mac, best end string here
*ptr2 = '\0'; //note a pc \r is followed by \n
break;
}
}
/* find the words in the line */
ptr = str;
while (*ptr != '\0') {
/* jump over leading spaces */
while (*ptr == ' ')
ptr++;
/* break if we reach the end */
if (*ptr == '\0')
break;
/* save pointer to beginning of word */
if (num_words >= max_words) {
max_words += 10;
words = (char **) realloc (words, sizeof (char *) * max_words);
}
words[num_words++] = ptr;
/* jump over non-spaces */
while (*ptr != ' ')
ptr++;
/* place a null character here to mark the end of the word */
*ptr++ = '\0';
}
/* return the list of words */
*nwords = num_words;
*orig_line = str_copy;
return (words);
}