Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- UObject* UMyFactory::ParseTexture(UObject* InParent, const FName& InName,const FString& Filename, EObjectFlags Flags)
- {
- int W, H;
- TArray<FString> Lines;
- TArray<FVector> ControlPoint;
- ControlPoint.SetNumZeroed(4);
- FFileHelper::LoadFileToStringArray(Lines, *Filename);
- for (const FString& Line : Lines)
- {
- TArray<FString> Tokens;
- Line.ParseIntoArray(Tokens, TEXT(" "), true);
- if (Tokens[0] == "Width")
- {
- W = FCString::Atoi(*Tokens[1]);
- }
- else if (Tokens[0] == "Height")
- {
- H = FCString::Atoi(*Tokens[1]);
- }
- else if (Tokens[0] == "P1")
- {
- TArray<FString> Coord;
- Tokens[1].ParseIntoArray(Coord, TEXT(","), true);
- ControlPoint[0] = FVector(FCString::Atoi(*(Coord[0])), FCString::Atoi(*(Coord[1])),0);
- }
- else if (Tokens[0] == "P2")
- {
- TArray<FString> Coord;
- Tokens[1].ParseIntoArray(Coord, TEXT(","), true);
- ControlPoint[2] = FVector(FCString::Atoi(*(Coord[0])), FCString::Atoi(*(Coord[1])),0);
- }
- else if (Tokens[0] == "C1")
- {
- TArray<FString> Coord;
- Tokens[1].ParseIntoArray(Coord, TEXT(","), true);
- ControlPoint[1] = FVector(FCString::Atoi(*(Coord[0])), FCString::Atoi(*(Coord[1])), 0);
- }
- else if (Tokens[0] == "C2")
- {
- TArray<FString> Coord;
- Tokens[1].ParseIntoArray(Coord, TEXT(","), true);
- ControlPoint[3] = FVector(FCString::Atoi(*(Coord[0])), FCString::Atoi(*(Coord[1])), 0);
- }
- }
- TArray<FVector> BeizerPoint;
- FVector::EvaluateBezier(ControlPoint.GetData(),700, BeizerPoint);
- TArray<FColor>Pixels;
- Pixels.AddZeroed(H * W);
- FCreateTexture2DParameters Params;
- for(const FVector& Point : BeizerPoint)
- {
- int X = FMath::RoundToInt(Point.X);
- int Y = FMath::RoundToInt(Point.Y);
- if (X >= 0 && X < W && Y >= 0 && Y < H)
- {
- Pixels[Y * W + X] = FColor(255, 0, 0, 255);
- }
- }
- return FImageUtils::CreateTexture2D(W, H, Pixels, InParent, InName.ToString(), Flags, Params);
- }
Advertisement
Add Comment
Please, Sign In to add comment