MCPcopy Create free account
hub / github.com/ImageEngine/cortex / createPlane

Method createPlane

src/IECoreScene/MeshPrimitive.cpp:736–805  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

734}
735
736MeshPrimitivePtr MeshPrimitive::createPlane( const Box2f &b, const Imath::V2i &divisions, const Canceller *canceller )
737{
738 V3fVectorDataPtr pData = new V3fVectorData;
739 std::vector<V3f> &p = pData->writable();
740
741 V2fVectorDataPtr uvData = new V2fVectorData;
742 uvData->setInterpretation( GeometricData::UV );
743 std::vector<Imath::V2f> &uvs = uvData->writable();
744
745 // add vertices
746
747 const float xStep = b.size().x / (float)divisions.x;
748 const float yStep = b.size().y / (float)divisions.y;
749 const float uStep = 1.0f / (float)divisions.x;
750 const float vStep = 1.0f / (float)divisions.y;
751 for ( int i = 0; i <= divisions.y; ++i )
752 {
753 Canceller::check( canceller );
754 for ( int j = 0; j <= divisions.x; ++j )
755 {
756 p.push_back( V3f( b.min.x + j * xStep, b.min.y + i * yStep, 0 ) );
757 uvs.push_back( V2f( j * uStep, i * vStep ) );
758 }
759 }
760
761 IntVectorDataPtr vertexIds = new IntVectorData;
762 IntVectorDataPtr verticesPerFace = new IntVectorData;
763 std::vector<int> &vpf = verticesPerFace->writable();
764 std::vector<int> &vIds = vertexIds->writable();
765
766 // add faces
767 int v0, v1, v2, v3;
768 for ( int i = 0; i < divisions.y; ++i )
769 {
770 for ( int j = 0; j < divisions.x; ++j )
771 {
772 Canceller::check( canceller );
773 v0 = j + (divisions.x+1) * i;
774 v1 = j + 1 + (divisions.x+1) * i;;
775 v2 = j + 1 + (divisions.x+1) * (i+1);
776 v3 = j + (divisions.x+1) * (i+1);
777
778 vpf.push_back( 4 );
779 vIds.push_back( v0 );
780 vIds.push_back( v1 );
781 vIds.push_back( v2 );
782 vIds.push_back( v3 );
783 }
784 }
785
786 MeshPrimitivePtr result = new MeshPrimitive( verticesPerFace, vertexIds, "linear", pData );
787 // We could use Vertex interpolation here, since that's logicaly the same
788 // as FaceVarying interpolation using `vertexIds` as the indices. We don't
789 // do that for a few reasons :
790 //
791 // - Most DCCs represent UVs using explicit indices anyway
792 // - Some of our code is currently incompatible with Vertex UVs
793 // - This gives us extra test coverage for indexed UVs "for free",

Calls 4

PrimitiveVariableFunction · 0.85
writableMethod · 0.45
sizeMethod · 0.45
resizeMethod · 0.45