@@ -662,6 +662,72 @@ core::smart_refctd_ptr<ICPUPolygonGeometry> CGeometryCreator::createCone(
662662 return retval;
663663}
664664
665+ core::smart_refctd_ptr<ICPUPolygonGeometry> CGeometryCreator::createPrism (
666+ float radius, float length, uint16_t sideCount) const
667+ {
668+ using namespace hlsl ;
669+
670+ if (sideCount < 3 ) return nullptr ;
671+
672+ const auto halfIx = sideCount;
673+ const uint32_t u32_vertexCount = 2 * sideCount;
674+ if (u32_vertexCount > std::numeric_limits<uint16_t >::max ())
675+ return nullptr ;
676+ const auto vertexCount = static_cast <uint16_t >(u32_vertexCount);
677+
678+ auto retval = core::make_smart_refctd_ptr<ICPUPolygonGeometry>();
679+ retval->setIndexing (IPolygonGeometryBase::TriangleList ());
680+
681+ // Create indices
682+ using index_t = uint16_t ;
683+ {
684+ constexpr uint32_t RowCount = 2u ;
685+ const auto IndexCount = RowCount * 3 * sideCount;
686+ auto indexView = createIndexView<index_t >(IndexCount, vertexCount - 1 );
687+ auto u = reinterpret_cast <index_t *>(indexView.src .buffer ->getPointer ());
688+
689+ for (uint16_t i = 0u , j = 0u ; i < halfIx; ++i)
690+ {
691+ u[j++] = i;
692+ u[j++] = (i + 1u ) != halfIx ? (i + 1u ):0u ;
693+ u[j++] = i + halfIx;
694+ u[j++] = i + halfIx;
695+ u[j++] = (i + 1u )!= halfIx ? (i + 1u ):0u ;
696+ u[j++] = (i + 1u )!= halfIx ? (i + 1u + halfIx) : halfIx;
697+ }
698+
699+ retval->setIndexView (std::move (indexView));
700+ }
701+
702+ // Create vertex attributes with NONE usage because we have no clue how they'll be used
703+ hlsl::float32_t3* positions;
704+
705+ {
706+ shapes::AABB<4 , float32_t > aabb;
707+ aabb.maxVx = float32_t4 (radius, radius, length, 0 .0f );
708+ aabb.minVx = float32_t4 (-radius, -radius, 0 .0f , 0 .0f );
709+ auto positionView = createPositionView (vertexCount, aabb);
710+ positions = reinterpret_cast <decltype (positions)>(positionView.src .buffer ->getPointer ());
711+ retval->setPositionView (std::move (positionView));
712+ }
713+
714+ const float invSideCount = 1 .f / static_cast <float >(sideCount);
715+ const float step = 2 .f * numbers::pi<float32_t > * invSideCount;
716+ for (uint32_t i = 0u ; i < sideCount; ++i)
717+ {
718+ const auto f_i = static_cast <float >(i);
719+ hlsl::float32_t3 p (std::cos (f_i * step), std::sin (f_i * step), 0 .f );
720+ p *= radius;
721+
722+ positions[i] = { p.x , p.y , p.z };
723+
724+ positions[i + halfIx] = { p.x , p.y , length };
725+ }
726+
727+ CPolygonGeometryManipulator::recomputeContentHashes (retval.get ());
728+ return retval;
729+ }
730+
665731core::smart_refctd_ptr<ICPUGeometryCollection> CGeometryCreator::createArrow (
666732 const uint16_t tesselationCylinder,
667733 const uint16_t tesselationCone,
0 commit comments