void ABranchingLinesActor::GenerateMesh() { // ------------------------------------------------------- // Setup the random number generator and create the branching structure RngStream = FRandomStream::FRandomStream(RandomSeed); CreateSegments(); // The number of vertices or polygons wont change at runtime, so we'll just allocate the arrays once if (!bHaveBuffersBeenInitialized) { SetupMeshBuffers(); bHaveBuffersBeenInitialized = true; } // ------------------------------------------------------- // Now lets loop through all the defined segments and create a cylinder for each int32 VertexIndex = 0; int32 TriangleIndex = 0; for (int32 i = 0; i < Segments.Num(); i++) { GenerateCylinder(Vertices, Triangles, Segments[i].Start, Segments[i].End, Segments[i].Width, RadialSegmentCount, VertexIndex, TriangleIndex, bSmoothNormals); } MeshComponent->ClearAllMeshSections(); MeshComponent->CreateMeshSection(0, Vertices, Triangles, GetBounds(), false, EUpdateFrequency::Infrequent); MeshComponent->SetMaterial(0, Material); }
void ASimpleCylinderActor::GenerateMesh() { if (Height <= 0) { MeshComponent->ClearAllMeshSections(); return; } // The number of vertices or polygons wont change at runtime, so we'll just allocate the arrays once if (!bHaveBuffersBeenInitialized) { SetupMeshBuffers(); bHaveBuffersBeenInitialized = true; } FBox BoundingBox = FBox(FVector(-Radius, -Radius, 0), FVector(Radius, Radius, Height)); GenerateCylinder(Vertices, Triangles, Height, Radius, RadialSegmentCount, bCapEnds, bDoubleSided, bSmoothNormals); MeshComponent->ClearAllMeshSections(); MeshComponent->CreateMeshSection(0, Vertices, Triangles, BoundingBox, false, EUpdateFrequency::Infrequent); MeshComponent->SetMaterial(0, Material); }
void ASimpleCylinderActor::PostEditChangeProperty(FPropertyChangedEvent& PropertyChangedEvent) { Super::PostEditChangeProperty(PropertyChangedEvent); FName MemberPropertyChanged = (PropertyChangedEvent.MemberProperty ? PropertyChangedEvent.MemberProperty->GetFName() : NAME_None); if ((MemberPropertyChanged == GET_MEMBER_NAME_CHECKED(ASimpleCylinderActor, Radius)) || (MemberPropertyChanged == GET_MEMBER_NAME_CHECKED(ASimpleCylinderActor, Height)) || (MemberPropertyChanged == GET_MEMBER_NAME_CHECKED(ASimpleCylinderActor, bSmoothNormals))) { // Same vert count, so just regen mesh with same buffers GenerateMesh(); } else if ((MemberPropertyChanged == GET_MEMBER_NAME_CHECKED(ASimpleCylinderActor, RadialSegmentCount)) || (MemberPropertyChanged == GET_MEMBER_NAME_CHECKED(ASimpleCylinderActor, bCapEnds)) || (MemberPropertyChanged == GET_MEMBER_NAME_CHECKED(ASimpleCylinderActor, bDoubleSided))) { // Vertice count has changed, so reset buffer and then regen mesh Vertices.Empty(); Triangles.Empty(); SetupMeshBuffers(); GenerateMesh(); } else if ((MemberPropertyChanged == GET_MEMBER_NAME_CHECKED(ASimpleCylinderActor, Material))) { MeshComponent->SetMaterial(0, Material); } }