public string[] tag; /* array of strings */ /// <summary> /// Read tag strings from a TAGS chunk in an LWO2 file. The tags are /// added to the lwTagList array. /// </summary> /// <param name="fp"></param> /// <param name="cksize"></param> /// <param name="tlist"></param> /// <param name="flen"></param> /// <returns></returns> public static bool GetTags(BinaryReader fp, int cksize, ref lwTagList tlist, ref int flen) { byte[] buf; int len, ntags; if (cksize == 0) { return(true); } /* read the whole chunk */ flen = 0; buf = lwio.getbytes(fp, cksize, ref flen); if (buf == null) { return(false); } /* count the strings */ ntags = 0; int bp = 0; while (bp < cksize) { string s = BitConverter.ToString(buf, bp); len = s.Length + 1; len += len & 1; bp += len; ++ntags; } /* expand the string array to hold the new tags */ tlist.offset = tlist.count; tlist.count += ntags; tlist.tag = new string[tlist.count]; if (tlist.tag == null) { goto Fail; } //memset( &tlist->tag[ tlist->offset ], 0, ntags * sizeof( char * )); /* copy the new tags to the tag array */ bp = 0; for (int i = 0; i < ntags; i++) { tlist.tag[i + tlist.offset] = lwio.sgetS0(buf, ref bp, ref flen); } return(true); Fail: return(false); }
/// <summary> /// Convert tag indexes into actual lwSurface pointers. If any polygons /// point to tags for which no corresponding surface can be found, a /// default surface is created. /// </summary> public bool ResolvePolySurfaces(ref lwTagList tlist, ref LinkedList <lwSurface> surf, ref int nsurfs) { //lwSurface st; lwSurface[] s; int index; if (tlist.count == 0) { return(true); } s = new lwSurface[tlist.count]; for (int i = 0; i < tlist.count; i++) { LinkedListNode <lwSurface> st = surf.First; while (st != null) { if (st.Value.name.CompareTo(tlist.tag[i]) == 0) { s[i] = st.Value; break; } st = st.Next; } } //for (int i = 0; i < count; i++) //{ // index = (int)pol[i].surf; // if (index < 0 || index > tlist.count) // return false; // if (!s[ index ]) // { // s[ index ] = lwDefaultSurface(); // if ( !s[ index ] ) // return false; // s[ index ]->name = malloc( strlen( tlist->tag[ index ] ) + 1 ); // if ( !s[ index ]->name ) // return false; // strcpy( s[ index ]->name, tlist->tag[ index ] ); // lwListAdd( surf, s[ index ] ); // *nsurfs = *nsurfs + 1; // } // polygon->pol[ i ].surf = s[ index ]; //} s = null; return(true); }
public string[] tag; /* array of strings */ /// <summary> /// Read tag strings from a TAGS chunk in an LWO2 file. The tags are /// added to the lwTagList array. /// </summary> /// <param name="fp"></param> /// <param name="cksize"></param> /// <param name="tlist"></param> /// <param name="flen"></param> /// <returns></returns> public static bool GetTags(BinaryReader fp, int cksize, ref lwTagList tlist, ref int flen) { byte[] buf; int len, ntags; if (cksize == 0) return true; /* read the whole chunk */ flen = 0; buf = lwio.getbytes(fp, cksize, ref flen); if (buf == null) return false; /* count the strings */ ntags = 0; int bp = 0; while (bp < cksize) { string s = BitConverter.ToString(buf, bp); len = s.Length + 1; len += len & 1; bp += len; ++ntags; } /* expand the string array to hold the new tags */ tlist.offset = tlist.count; tlist.count += ntags; tlist.tag = new string[tlist.count]; if (tlist.tag == null) goto Fail; //memset( &tlist->tag[ tlist->offset ], 0, ntags * sizeof( char * )); /* copy the new tags to the tag array */ bp = 0; for (int i = 0; i < ntags; i++) tlist.tag[i + tlist.offset] = lwio.sgetS0(buf, ref bp, ref flen); return true; Fail: return false; }
/// <summary> /// Convert tag indexes into actual lwSurface pointers. If any polygons /// point to tags for which no corresponding surface can be found, a /// default surface is created. /// </summary> public bool ResolvePolySurfaces(ref lwTagList tlist, ref LinkedList<lwSurface> surf, ref int nsurfs) { //lwSurface st; lwSurface[] s; int index; if (tlist.count == 0) return true; s = new lwSurface[tlist.count]; for (int i = 0; i < tlist.count; i++) { LinkedListNode<lwSurface> st = surf.First; while (st != null) { if (st.Value.name.CompareTo(tlist.tag[i]) == 0) { s[i] = st.Value; break; } st = st.Next; } } //for (int i = 0; i < count; i++) //{ // index = (int)pol[i].surf; // if (index < 0 || index > tlist.count) // return false; // if (!s[ index ]) // { // s[ index ] = lwDefaultSurface(); // if ( !s[ index ] ) // return false; // s[ index ]->name = malloc( strlen( tlist->tag[ index ] ) + 1 ); // if ( !s[ index ]->name ) // return false; // strcpy( s[ index ]->name, tlist->tag[ index ] ); // lwListAdd( surf, s[ index ] ); // *nsurfs = *nsurfs + 1; // } // polygon->pol[ i ].surf = s[ index ]; //} s = null; return true; }