Skip to content

Commit

Permalink
Destructible mesh optimization too
Browse files Browse the repository at this point in the history
  • Loading branch information
mik14a committed Feb 4, 2018
1 parent f70c81f commit db812a4
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 14 deletions.
22 changes: 11 additions & 11 deletions Source/VOX4UEditor/Private/MonotoneMesh.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,35 +57,35 @@ void MonotoneMesh::CreatePolygons(TArray<FPolygon>& OutPolygons, const FIntVecto
auto NextFrontier = TArray<int>();
auto FrontierIndex = 0, FaceIndex = 0;
while (FrontierIndex < Frontier.Num() && FaceIndex < Faces.Num()) {
const auto PolygonIndex = Frontier[FrontierIndex];
const auto& Polygon = OutPolygons[PolygonIndex];
auto& Polygon = OutPolygons[Frontier[FrontierIndex]];
const auto& Color = Polygon.Color;
const auto& Left = Polygon.Left.Last().X;
const auto& Right = Polygon.Right.Last().X;
const auto& Face = Faces[FaceIndex];
if (Left < Face.Right && Face.Left < Right && Face.Color == Color) {
OutPolygons[PolygonIndex].Merge(Face.Left, Face.Right, P[Axis.Y], P[Axis.Z]);
NextFrontier.Add(PolygonIndex);
Polygon.Merge(Face.Left, Face.Right, P[Axis.Y], P[Axis.Z]);
NextFrontier.Add(Frontier[FrontierIndex]);
++FrontierIndex, ++FaceIndex;
} else {
if (Right <= Face.Right) {
Polygon.CloseOff(P[Axis.Y], P[Axis.Z]);
++FrontierIndex;
}
if (Face.Right <= Right) {
NextFrontier.Add(OutPolygons.Num());
OutPolygons.Add(FPolygon(Face.Color, Face.Left, Face.Right, P[Axis.Y], P[Axis.Z]));
++FaceIndex;
}
if (Right <= Face.Right) {
OutPolygons[PolygonIndex].CloseOff(P[Axis.Y], P[Axis.Z]);
++FrontierIndex;
}
}
}
while (FrontierIndex < Frontier.Num()) {
OutPolygons[Frontier[FrontierIndex++]].CloseOff(P[Axis.Y], P[Axis.Z]);
auto& Polygon = OutPolygons[Frontier[FrontierIndex++]];
Polygon.CloseOff(P[Axis.Y], P[Axis.Z]);
}
while (FaceIndex < Faces.Num()) {
NextFrontier.Add(OutPolygons.Num());
const auto& Line = Faces[FaceIndex++];
OutPolygons.Add(FPolygon(Line.Color, Line.Left, Line.Right, P[Axis.Y], P[Axis.Z]));
const auto& Face = Faces[FaceIndex++];
OutPolygons.Add(FPolygon(Face.Color, Face.Left, Face.Right, P[Axis.Y], P[Axis.Z]));
}
Frontier = NextFrontier;
}
Expand Down
4 changes: 2 additions & 2 deletions Source/VOX4UEditor/Private/Vox.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -278,8 +278,8 @@ bool FVox::CreateRawMesh(FRawMesh& OutRawMesh, const UVoxImportOption* ImportOpt
*/
bool FVox::CreateOptimizedRawMesh(FRawMesh& OutRawMesh, const UVoxImportOption* ImportOption) const
{
MonotoneMesh mesher(this);
return mesher.CreateRawMesh(OutRawMesh, ImportOption);
MonotoneMesh Mesher(this);
return Mesher.CreateRawMesh(OutRawMesh, ImportOption);
}

/**
Expand Down
9 changes: 8 additions & 1 deletion Source/VOX4UEditor/Private/VoxelFactory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -106,12 +106,19 @@ USkeletalMesh* UVoxelFactory::CreateSkeletalMesh(UObject* InParent, FName InName
return SkeletalMesh;
}

/**
* CreateDestructibleMesh
* @param InParent Import package
* @param InName Package name
* @param Flags Import flags
* @param Vox Voxel file data
*/
UDestructibleMesh* UVoxelFactory::CreateDestructibleMesh(UObject* InParent, FName InName, EObjectFlags Flags, const FVox* Vox) const
{
UDestructibleMesh* DestructibleMesh = NewObject<UDestructibleMesh>(InParent, InName, Flags | RF_Public);

FRawMesh RawMesh;
Vox->CreateRawMesh(RawMesh, ImportOption);
Vox->CreateOptimizedRawMesh(RawMesh, ImportOption);
UMaterialInterface* Material = CreateMaterial(InParent, InName, Flags, Vox);
UStaticMesh* RootMesh = NewObject<UStaticMesh>();
RootMesh->StaticMaterials.Add(FStaticMaterial(Material));
Expand Down

0 comments on commit db812a4

Please sign in to comment.