------------------------------------------------------------------------------------------------ read an array of float3 tuples
| 599 | // ------------------------------------------------------------------------------------------------ |
| 600 | // read an array of float3 tuples |
| 601 | void ParseVectorDataArray(std::vector<aiVector3D>& out, const Element& el) |
| 602 | { |
| 603 | out.resize( 0 ); |
| 604 | |
| 605 | const TokenList& tok = el.Tokens(); |
| 606 | if(tok.empty()) { |
| 607 | ParseError("unexpected empty element",&el); |
| 608 | } |
| 609 | |
| 610 | if(tok[0]->IsBinary()) { |
| 611 | const char* data = tok[0]->begin(), *end = tok[0]->end(); |
| 612 | |
| 613 | char type; |
| 614 | uint32_t count; |
| 615 | ReadBinaryDataArrayHead(data, end, type, count, el); |
| 616 | |
| 617 | if(count % 3 != 0) { |
| 618 | ParseError("number of floats is not a multiple of three (3) (binary)",&el); |
| 619 | } |
| 620 | |
| 621 | if(!count) { |
| 622 | return; |
| 623 | } |
| 624 | |
| 625 | if (type != 'd' && type != 'f') { |
| 626 | ParseError("expected float or double array (binary)",&el); |
| 627 | } |
| 628 | |
| 629 | std::vector<char> buff; |
| 630 | ReadBinaryDataArray(type, count, data, end, buff, el); |
| 631 | |
| 632 | ai_assert(data == end); |
| 633 | uint64_t dataToRead = static_cast<uint64_t>(count) * (type == 'd' ? 8 : 4); |
| 634 | if (dataToRead != buff.size()) { |
| 635 | ParseError("Invalid read size (binary)",&el); |
| 636 | } |
| 637 | |
| 638 | const uint32_t count3 = count / 3; |
| 639 | out.reserve(count3); |
| 640 | |
| 641 | if (type == 'd') { |
| 642 | const double* d = reinterpret_cast<const double*>(&buff[0]); |
| 643 | for (unsigned int i = 0; i < count3; ++i, d += 3) { |
| 644 | BE_NCONST double val1 = d[0]; |
| 645 | BE_NCONST double val2 = d[1]; |
| 646 | BE_NCONST double val3 = d[2]; |
| 647 | AI_SWAP8(val1); |
| 648 | AI_SWAP8(val2); |
| 649 | AI_SWAP8(val3); |
| 650 | out.emplace_back(static_cast<ai_real>(val1), |
| 651 | static_cast<ai_real>(val2), |
| 652 | static_cast<ai_real>(val3)); |
| 653 | } |
| 654 | // for debugging |
| 655 | /*for ( size_t i = 0; i < out.size(); i++ ) { |
| 656 | aiVector3D vec3( out[ i ] ); |
| 657 | std::stringstream stream; |
| 658 | stream << " vec3.x = " << vec3.x << " vec3.y = " << vec3.y << " vec3.z = " << vec3.z << std::endl; |
no test coverage detected