| 656 | } |
| 657 | |
| 658 | MeshPrimitivePtr MeshPrimitive::createBox( const Box3f &b ) |
| 659 | { |
| 660 | std::string interpolation = "linear"; |
| 661 | vector< V3f > p; |
| 662 | std::vector<int> verticesPerFace { |
| 663 | 4, 4, 4, 4, 4, 4 |
| 664 | }; |
| 665 | std::vector<int> vertexIds { |
| 666 | 3,2,1,0, |
| 667 | 1,2,5,4, |
| 668 | 4,5,7,6, |
| 669 | 6,7,3,0, |
| 670 | 2,3,7,5, |
| 671 | 0,1,4,6 |
| 672 | }; |
| 673 | |
| 674 | p.push_back( V3f( b.min.x, b.min.y, b.min.z ) ); // 0 |
| 675 | p.push_back( V3f( b.max.x, b.min.y, b.min.z ) ); // 1 |
| 676 | p.push_back( V3f( b.max.x, b.max.y, b.min.z ) ); // 2 |
| 677 | p.push_back( V3f( b.min.x, b.max.y, b.min.z ) ); // 3 |
| 678 | p.push_back( V3f( b.max.x, b.min.y, b.max.z ) ); // 4 |
| 679 | p.push_back( V3f( b.max.x, b.max.y, b.max.z ) ); // 5 |
| 680 | p.push_back( V3f( b.min.x, b.min.y, b.max.z ) ); // 6 |
| 681 | p.push_back( V3f( b.min.x, b.max.y, b.max.z ) ); // 7 |
| 682 | |
| 683 | MeshPrimitivePtr result = new MeshPrimitive( new IntVectorData(verticesPerFace), new IntVectorData(vertexIds), interpolation, new V3fVectorData(p) ); |
| 684 | |
| 685 | |
| 686 | V2fVectorDataPtr uvData = new V2fVectorData; |
| 687 | uvData->setInterpretation( GeometricData::UV ); |
| 688 | std::vector<Imath::V2f> &uvs = uvData->writable(); |
| 689 | |
| 690 | for( int i = 0; i < 5; i++ ) |
| 691 | { |
| 692 | uvs.push_back( Imath::V2f( 0.375f, 0.25f * i ) ); |
| 693 | uvs.push_back( Imath::V2f( 0.625f, 0.25f * i ) ); |
| 694 | } |
| 695 | |
| 696 | for( int i = 0; i < 2; i++ ) |
| 697 | { |
| 698 | uvs.push_back( Imath::V2f( 0.125f, 0.25f * i ) ); |
| 699 | uvs.push_back( Imath::V2f( 0.875f, 0.25f * i ) ); |
| 700 | } |
| 701 | |
| 702 | std::vector<int> uvIndices { |
| 703 | 4,5,7,6, |
| 704 | 11,13,3,1, |
| 705 | 1,3,2,0, |
| 706 | 0,2,12,10, |
| 707 | 5,4,2,3, |
| 708 | 6,7,9,8, |
| 709 | }; |
| 710 | |
| 711 | result->variables["uv"] = PrimitiveVariable( PrimitiveVariable::FaceVarying, uvData, new IntVectorData ( uvIndices ) ); |
| 712 | |
| 713 | std::vector<Imath::V3f> normals { |
| 714 | Imath::V3f( 0, 0, 1 ), |
| 715 | Imath::V3f( 0, 0, -1 ), |