UDocumentation UE5.7 10.02.2026 (Source)
API documentation for Unreal Engine 5.7
BoxSphereGenerator.h
Go to the documentation of this file.
1// Copyright Epic Games, Inc. All Rights Reserved.
2
3// Port of geometry3Sharp SphereGenerators
4
5#pragma once
6
8#include "OrientedBoxTypes.h"
9#include "Util/IndexUtil.h"
10
12
13namespace UE
14{
15namespace Geometry
16{
17
18
22class /*GEOMETRYCORE_API*/ FBoxSphereGenerator : public FGridBoxMeshGenerator
23{
24public:
25
27 float Radius = 1;
28
31 {
33 CubeMapping // produces more even distribution of quads
34 // see http://catlikecoding.com/unity/tutorials/cube-sphere/
35 // or http://mathproofs.blogspot.ca/2005/07/mapping-cube-to-sphere.html
36 };
38
40 {
42
44 FVector3d AxX = Box.AxisX(), AxY = Box.AxisY(), AxZ = Box.AxisZ();
45 for (int32 VertIdx = 0; VertIdx < Vertices.Num(); VertIdx++)
46 {
49 double x = V.Dot(AxX) / Box.Extents.X;
50 double y = V.Dot(AxY) / Box.Extents.Y;
51 double z = V.Dot(AxZ) / Box.Extents.Z;
52 double x2 = x * x, y2 = y * y, z2 = z * z;
53 double sx = x * FMathd::Sqrt(1.0 - y2*0.5 - z2*0.5 + y2*z2/3.0);
54 double sy = y * FMathd::Sqrt(1.0 - x2*0.5 - z2*0.5 + x2*z2/3.0);
55 double sz = z * FMathd::Sqrt(1.0 - x2*0.5 - y2*0.5 + x2*y2/3.0);
56 V = sx*AxX + sy*AxY + sz*AxZ;
57 }
58 Normalize(V);
59 Vertices[VertIdx] = V;
60 }
61
62 for (int32 NormalIdx = 0; NormalIdx < Normals.Num(); NormalIdx++)
63 {
65 }
66
67 for (int32 VertIdx = 0; VertIdx < Vertices.Num(); VertIdx++)
68 {
70 }
71
72 return *this;
73 }
74
75};
76
77
78
79} // end namespace UE::Geometry
80} // end namespace UE
FPlatformTypes::int32 int32
A 32-bit signed integer.
Definition Platform.h:1125
UE_FORCEINLINE_HINT TSharedRef< CastToType, Mode > StaticCastSharedRef(TSharedRef< CastFromType, Mode > const &InSharedRef)
Definition SharedPointer.h:127
UE::Math::TVector< float > FVector3f
Definition MathFwd.h:73
static RealType Sqrt(const RealType Value)
Definition MathUtil.h:342
Definition BoxSphereGenerator.h:23
FMeshShapeGenerator & Generate() override
Definition BoxSphereGenerator.h:39
ESphereProjectionMethod
Definition BoxSphereGenerator.h:31
float Radius
Definition BoxSphereGenerator.h:27
ESphereProjectionMethod SphereProjectionMethod
Definition BoxSphereGenerator.h:37
Definition GridBoxMeshGenerator.h:19
FOrientedBox3d Box
Definition GridBoxMeshGenerator.h:22
virtual FMeshShapeGenerator & Generate() override
Definition GridBoxMeshGenerator.h:35
Definition MeshShapeGenerator.h:19
TArray< FVector3d > Vertices
Definition MeshShapeGenerator.h:22
TArray< FVector3f > Normals
Definition MeshShapeGenerator.h:30
TArray< int > NormalParentVertex
Definition MeshShapeGenerator.h:32
T Normalize(UE::Math::TVector2< T > &Vector, const T Epsilon=0)
Definition VectorTypes.h:46
Definition AdvancedWidgetsModule.cpp:13
TVector< RealType > Extents
Definition OrientedBoxTypes.h:32
TVector< RealType > Center() const
Definition OrientedBoxTypes.h:92
TVector< RealType > AxisY() const
Definition OrientedBoxTypes.h:98
TVector< RealType > AxisZ() const
Definition OrientedBoxTypes.h:101
TVector< RealType > AxisX() const
Definition OrientedBoxTypes.h:95
T Z
Definition Vector.h:68
T Y
Definition Vector.h:65
T X
Definition Vector.h:62
UE_FORCEINLINE_HINT T Dot(const TVector< T > &V) const
Definition Vector.h:1553