Changeset 13041 for OpenSceneGraph/trunk/src/osgPlugins/lwo/old_Lwo2.cpp
- Timestamp:
- 03/21/12 18:36:20 (14 months ago)
- Files:
-
- 1 modified
Legend:
- Unmodified
- Added
- Removed
-
OpenSceneGraph/trunk/src/osgPlugins/lwo/old_Lwo2.cpp
r11517 r13041 19 19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 20 20 * 21 * The Open Scene Graph (OSG) is a cross platform C++/OpenGL library for 22 * real-time rendering of large 3D photo-realistic models. 21 * The Open Scene Graph (OSG) is a cross platform C++/OpenGL library for 22 * real-time rendering of large 3D photo-realistic models. 23 23 * The OSG homepage is http://www.openscenegraph.org/ 24 24 */ … … 65 65 } 66 66 67 bool 67 bool 68 68 Lwo2::ReadFile( const string& filename ) 69 69 { … … 79 79 // checking EA-IFF85 format 80 80 // http://www.lightwave3d.com/developer/75lwsdk/docs/filefmts/eaiff85.html 81 if (_read_uint() != tag_FORM) 81 if (_read_uint() != tag_FORM) 82 82 { 83 83 OSG_INFO << "File '" << filename << "' is not IFF format file." << std::endl; … … 85 85 return false; 86 86 } 87 else 87 else 88 88 { 89 89 OSG_INFO << "Detected EA-IFF85 format" << std::endl; … … 93 93 OSG_INFO << "Form size: " << form_size << std::endl; 94 94 95 // checking LWO2 format 95 // checking LWO2 format 96 96 // http://www.lightwave3d.com/developer/75lwsdk/docs/filefmts/lwo2.html 97 if (_read_uint() != tag_LWO2) 97 if (_read_uint() != tag_LWO2) 98 98 { 99 99 unsigned long make_id(const char*); … … 102 102 return false; 103 103 } 104 else 104 else 105 105 { 106 106 OSG_INFO << "Detected LWO2 format" << std::endl; … … 120 120 _print_tag(current_tag_name, current_tag_size); 121 121 122 if (current_tag_name == tag_TAGS) 122 if (current_tag_name == tag_TAGS) 123 123 { 124 124 _read_tag_strings(current_tag_size); 125 } 126 else if (current_tag_name == tag_LAYR) 125 } 126 else if (current_tag_name == tag_LAYR) 127 127 { 128 128 _read_layer(current_tag_size); 129 129 } 130 else if (current_tag_name == tag_PNTS) 130 else if (current_tag_name == tag_PNTS) 131 131 { 132 132 _read_points(current_tag_size); 133 133 } 134 else if (current_tag_name == tag_VMAP) 134 else if (current_tag_name == tag_VMAP) 135 135 { 136 136 _read_vertex_mapping(current_tag_size); 137 137 } 138 else if (current_tag_name == tag_VMAD) 138 else if (current_tag_name == tag_VMAD) 139 139 { 140 140 _read_polygons_mapping(current_tag_size); 141 141 } 142 else if (current_tag_name == tag_POLS) 142 else if (current_tag_name == tag_POLS) 143 143 { 144 144 _read_polygons(current_tag_size); 145 145 } 146 else if (current_tag_name == tag_PTAG) 146 else if (current_tag_name == tag_PTAG) 147 147 { 148 148 _read_polygon_tag_mapping(current_tag_size); 149 149 } 150 else if (current_tag_name == tag_CLIP) 150 else if (current_tag_name == tag_CLIP) 151 151 { 152 152 _read_image_definition(current_tag_size); 153 153 } 154 else if (current_tag_name == tag_SURF) 154 else if (current_tag_name == tag_SURF) 155 155 { 156 156 _read_surface(current_tag_size); 157 } 158 else 157 } 158 else 159 159 { 160 160 _fin.seekg(current_tag_size + current_tag_size % 2, ios::cur); … … 167 167 } 168 168 169 unsigned char 169 unsigned char 170 170 Lwo2::_read_char() 171 171 { … … 178 178 } 179 179 180 unsigned int 180 unsigned int 181 181 Lwo2::_read_uint() 182 182 { 183 183 return 184 (_read_char() << 24) | 185 (_read_char() << 16) | 186 (_read_char() << 8) | 184 (_read_char() << 24) | 185 (_read_char() << 16) | 186 (_read_char() << 8) | 187 187 _read_char(); 188 188 } 189 189 190 unsigned short 190 unsigned short 191 191 Lwo2::_read_short() 192 192 { 193 193 return 194 (_read_char() << 8) | 194 (_read_char() << 8) | 195 195 _read_char(); 196 196 } 197 197 198 float 198 float 199 199 Lwo2::_read_float() 200 200 { … … 202 202 } 203 203 204 // read null terminated string 204 // read null terminated string 205 205 206 206 string& … … 213 213 } while (c != 0); 214 214 215 // if length of string (including \0) is odd skip another byte 215 // if length of string (including \0) is odd skip another byte 216 216 if (str.length() % 2) { 217 217 _read_char(); … … 223 223 // print 4-char tag to debug out 224 224 225 void 225 void 226 226 Lwo2::_print_tag(unsigned int tag, unsigned int size) { 227 OSG_DEBUG << "Found tag " 228 << char(tag >> 24) 229 << char(tag >> 16) 230 << char(tag >> 8) 231 << char(tag) 232 << " size " << size << " bytes" 227 OSG_DEBUG << "Found tag " 228 << char(tag >> 24) 229 << char(tag >> 16) 230 << char(tag >> 8) 231 << char(tag) 232 << " size " << size << " bytes" 233 233 << std::endl; 234 234 } 235 235 236 236 // print 4-char type 237 void 237 void 238 238 Lwo2::_print_type(unsigned int type) { 239 OSG_DEBUG << " type \t" 240 << char(type >> 24) 241 << char(type >> 16) 242 << char(type >> 8) 243 << char(type) 239 OSG_DEBUG << " type \t" 240 << char(type >> 24) 241 << char(type >> 16) 242 << char(type >> 8) 243 << char(type) 244 244 << std::endl; 245 245 } … … 247 247 // read TAGS info 248 248 249 void 249 void 250 250 Lwo2::_read_tag_strings(unsigned long size) 251 251 { … … 254 254 string name; 255 255 _read_string(name); 256 size -= name.length() + name.length() % 2; 256 size -= name.length() + name.length() % 2; 257 257 _tags.push_back(name); 258 258 … … 263 263 // read LAYR info 264 264 265 void Lwo2::_read_layer(unsigned long size) 265 void Lwo2::_read_layer(unsigned long size) 266 266 { 267 267 unsigned short number = _read_short(); … … 283 283 284 284 _read_string(layer->_name); 285 size -= layer->_name.length() + layer->_name.length() % 2; 286 287 if (size > 2) 285 size -= layer->_name.length() + layer->_name.length() % 2; 286 287 if (size > 2) 288 288 { 289 289 layer->_parent = _read_short(); … … 296 296 // read PNTS info 297 297 298 void Lwo2::_read_points(unsigned long size) 298 void Lwo2::_read_points(unsigned long size) 299 299 { 300 300 int count = size / 12; … … 310 310 point.coord = Vec3(x, y, z); 311 311 _current_layer->_points.push_back(point); 312 } 312 } 313 313 } 314 314 315 315 // read VMAP info 316 316 317 void Lwo2::_read_vertex_mapping(unsigned long size) 317 void Lwo2::_read_vertex_mapping(unsigned long size) 318 318 { 319 319 unsigned int type = _read_uint(); … … 329 329 string name; 330 330 _read_string(name); 331 size -= name.length() + name.length() % 2; 331 size -= name.length() + name.length() % 2; 332 332 OSG_DEBUG << " name \t'" << name.c_str() << "'" << std::endl; 333 333 334 if (type == tag_TXUV && dimension == 2) 334 if (type == tag_TXUV && dimension == 2) 335 335 { 336 336 int count = size / 10; … … 351 351 } 352 352 } 353 else 353 else 354 354 { 355 355 … … 362 362 // read POLS info 363 363 364 void 365 Lwo2::_read_polygons(unsigned long size) 364 void 365 Lwo2::_read_polygons(unsigned long size) 366 366 { 367 367 unsigned int type = _read_uint(); … … 370 370 _print_type(type); 371 371 372 if (type == tag_FACE) 372 if (type == tag_FACE) 373 373 { 374 374 unsigned short vertex_count; … … 391 391 points_list.push_back(point); 392 392 size -= 2; 393 } 393 } 394 394 395 395 _current_layer->_polygons.push_back(points_list); 396 396 } 397 397 } 398 else 398 else 399 399 { 400 400 … … 407 407 // read PTAG info 408 408 409 void Lwo2::_read_polygon_tag_mapping(unsigned long size) 409 void Lwo2::_read_polygon_tag_mapping(unsigned long size) 410 410 { 411 411 unsigned int type = _read_uint(); … … 414 414 _print_type(type); 415 415 416 if (type == tag_SURF) 416 if (type == tag_SURF) 417 417 { 418 418 int count = size / 4; … … 429 429 } 430 430 } 431 else 431 else 432 432 { 433 433 … … 440 440 // read VMAD info 441 441 442 void Lwo2::_read_polygons_mapping(unsigned long size) 442 void Lwo2::_read_polygons_mapping(unsigned long size) 443 443 { 444 444 unsigned int type = _read_uint(); … … 454 454 string name; 455 455 _read_string(name); 456 size -= name.length() + name.length() % 2; 456 size -= name.length() + name.length() % 2; 457 457 OSG_DEBUG << " name \t'" << name.c_str() << "'" << std::endl; 458 458 459 if (type == tag_TXUV && dimension == 2) 459 if (type == tag_TXUV && dimension == 2) 460 460 { 461 461 OSG_DEBUG << " polygons mappings:" << endl; … … 478 478 OSG_DEBUG << " \t" << point_index << "\t" << polygon_index << "\t" << Vec2(u, v) << endl; 479 479 480 // apply texture coordinates 480 // apply texture coordinates 481 481 PointsList& points_list = _current_layer->_polygons[polygon_index]; 482 482 for (unsigned int i = 0; i < points_list.size(); i++) … … 489 489 } 490 490 } 491 else 491 else 492 492 { 493 493 … … 501 501 // read CLIP info 502 502 503 void 503 void 504 504 Lwo2::_read_image_definition(unsigned long size) 505 505 { … … 523 523 string name; 524 524 _read_string(name); 525 size -= name.length() + name.length() % 2; 525 size -= name.length() + name.length() % 2; 526 526 527 527 if (index + 1 > _images.size()) … … 529 529 _images.resize(index + 1); 530 530 } 531 531 532 532 _images[index] = name.c_str(); 533 533 … … 545 545 546 546 _read_string(surface->name); 547 size -= surface->name.length() + surface->name.length() % 2; 547 size -= surface->name.length() + surface->name.length() % 2; 548 548 OSG_DEBUG << " name \t'" << surface->name.c_str() << "'" << std::endl; 549 549 550 550 string source; 551 551 _read_string(source); 552 size -= source.length() + source.length() % 2; 552 size -= source.length() + source.length() % 2; 553 553 OSG_DEBUG << " source \t'" << source.c_str() << "'" << std::endl; 554 554 … … 556 556 unsigned short current_tag_size; 557 557 558 while (size > 0 && !_fin.eof()) 558 while (size > 0 && !_fin.eof()) 559 559 { 560 560 current_tag_name = _read_uint(); … … 565 565 _print_tag(current_tag_name, current_tag_size); 566 566 567 if (current_tag_name == tag_BLOK) 567 if (current_tag_name == tag_BLOK) 568 568 { 569 569 … … 571 571 int blok_size = current_tag_size; 572 572 size -= blok_size; 573 while (blok_size > 0) 573 while (blok_size > 0) 574 574 { 575 575 current_tag_name = _read_uint(); … … 586 586 blok_size -= 2; 587 587 } 588 else if (current_tag_name == tag_IMAP) 588 else if (current_tag_name == tag_IMAP) 589 589 { 590 590 … … 595 595 string ordinal; 596 596 _read_string(ordinal); 597 imap_size -= ordinal.length() + ordinal.length() % 2; 597 imap_size -= ordinal.length() + ordinal.length() % 2; 598 598 OSG_DEBUG << " ordinal \t'" << ordinal.c_str() << "'" << std::endl; 599 599 … … 611 611 } 612 612 } 613 else 613 else 614 614 { 615 615 _fin.seekg(current_tag_size + current_tag_size % 2, ios::cur); … … 632 632 size -= current_tag_size + current_tag_size % 2; 633 633 } 634 else 634 else 635 635 { 636 636 _fin.seekg(current_tag_size + current_tag_size % 2, ios::cur); … … 644 644 // Generation OSG Geode object from parsed LWO2 file 645 645 646 bool 646 bool 647 647 Lwo2::GenerateGroup( Group& group ) 648 648 { … … 706 706 707 707 // check if exist texture image for this surface 708 if (surface->image_index >= 0) 708 if (surface->image_index >= 0) 709 709 { 710 710 osg::ref_ptr<Image> image = osgDB::readRefImageFile(_images[surface->image_index]); … … 716 716 Texture2D* texture = new osg::Texture2D; 717 717 texture->setImage(image.get()); 718 state_set->setTextureAttributeAndModes(0, texture, StateAttribute::ON); 718 state_set->setTextureAttributeAndModes(0, texture, StateAttribute::ON); 719 719 720 720 // setup texture wrapping … … 735 735 736 736 // check alpha 737 if (*data < 255) 737 if (*data < 255) 738 738 { 739 739 use_blending = true; … … 774 774 } 775 775 776 // makes 4-byte integer tag from four chars 776 // makes 4-byte integer tag from four chars 777 777 // used in IFF standard 778 778 779 unsigned long make_id(const char* tag) 779 unsigned long make_id(const char* tag) 780 780 { 781 781 unsigned long result = 0; … … 786 786 } 787 787 return result; 788 } 788 }
