<commit_before>// Fill out your copyright notice in the Description page of Project Settings.

#include "MeshGenerator.h"
#include "MeshImporter.h"
#include "StabiloMesh.h"


// Sets default values
AStabiloMesh::AStabiloMesh()
{	
	PrimaryActorTick.bCanEverTick = true;

	RuntimeMesh = CreateDefaultSubobject<URuntimeMeshComponent>(TEXT("Runtime Mesh"));
	RootComponent = RuntimeMesh;
 	// Set this actor to call Tick() every frame.  You can turn this off to improve performance if you don't need it.
	PrimaryActorTick.bCanEverTick = true;



	TArray<FVector> Vertices;
	TArray<FVector> Normals;
	TArray<FRuntimeMeshTangent> Tangents;
	TArray<FColor> VertexColors;
	TArray<FVector2D> TextureCoordinates;
	TArray<int32> Triangles;

	MeshImporter import("c:/users/tobias/mesh/stabilo.ply");
	//TODO dont copy -> pointer or refs
	std::vector<float> vertices =  import.GetVertices();
	std::vector<float> normals =  import.GetNormals();
	std::vector<uint32_t> faces =  import.GetFaces();
	std::vector<uint8_t> colors =  import.GetColors();

	for (int i = 0; i < vertices.size() - 3; i += 3) {
		Vertices.Add(FVector(vertices[i], vertices[i + 1], vertices[i + 2]));
		VertexColors.Add(FColor(colors[i], colors[i+1], colors[i+2], 1));
	}

	for (int i = 0; i < faces.size(); ++i) {
		Triangles.Add(faces[i]);
	}

	//// First vertex
	//Vertices.Add(FVector(0, 100, 100));
	//Normals.Add(FVector(0, 0, 1));
	//Tangents.Add(FRuntimeMeshTangent(0, -1, 0));
	//VertexColors.Add(FColor::White);
	//TextureCoordinates.Add(FVector2D(0, 0));

	//// Second vertex
	//Vertices.Add(FVector(100, 100, 0));
	//Normals.Add(FVector(0, 0, 1));
	//Tangents.Add(FRuntimeMeshTangent(0, -1, 0));
	//VertexColors.Add(FColor::White);
	//TextureCoordinates.Add(FVector2D(0, 1));

	//// Third vertex
	//Vertices.Add(FVector(100, 0, 0));
	//Normals.Add(FVector(0, 0, 1));
	//Tangents.Add(FRuntimeMeshTangent(0, -1, 0));
	//VertexColors.Add(FColor::White);
	//TextureCoordinates.Add(FVector2D(1, 1));

	//// Fourth vertex
	//Vertices.Add(FVector(0, 0, 0));
	//Normals.Add(FVector(0, 0, 1));
	//Tangents.Add(FRuntimeMeshTangent(0, -1, 0));
	//VertexColors.Add(FColor::White);
	//TextureCoordinates.Add(FVector2D(1, 0));

	//Triangles.Add(0);
	//Triangles.Add(1);
	//Triangles.Add(2);
	//Triangles.Add(0);
	//Triangles.Add(2);
	//Triangles.Add(3);

	RuntimeMesh->CreateMeshSection(0, Vertices, Triangles, Normals, TextureCoordinates, VertexColors, Tangents);
}

// Called when the game starts or when spawned
void AStabiloMesh::BeginPlay()
{
	Super::BeginPlay();
	
}

// Called every frame<commit_msg>set vertex color material on creation<commit_after>// Fill out your copyright notice in the Description page of Project Settings.

#include "MeshGenerator.h"
#include "MeshImporter.h"
#include "StabiloMesh.h"


UPROPERTY(EditAnywhere)
UMaterialInterface* Material;

// Sets default values
AStabiloMesh::AStabiloMesh()
{	
	PrimaryActorTick.bCanEverTick = true;

	RuntimeMesh = CreateDefaultSubobject<URuntimeMeshComponent>(TEXT("Runtime Mesh"));
	RootComponent = RuntimeMesh;
 	// Set this actor to call Tick() every frame.  You can turn this off to improve performance if you don't need it.
	PrimaryActorTick.bCanEverTick = true;



	TArray<FVector> Vertices;
	TArray<FVector> Normals;
	TArray<FRuntimeMeshTangent> Tangents;
	TArray<FColor> VertexColors;
	TArray<FVector2D> TextureCoordinates;
	TArray<int32> Triangles;

	MeshImporter import("c:/users/tobias/mesh/stabilo.ply");
	//TODO dont copy -> pointer or refs
	std::vector<float> vertices =  import.GetVertices();
	std::vector<float> normals =  import.GetNormals();
	std::vector<uint32_t> faces =  import.GetFaces();
	std::vector<uint8_t> colors =  import.GetColors();

	for (int i = 0; i < vertices.size() - 3; i += 3) {
		Vertices.Add(FVector(vertices[i], vertices[i + 1], vertices[i + 2]));
		VertexColors.Add(FColor(colors[i], colors[i+1], colors[i+2]));
	}

	for (int i = 0; i < faces.size(); ++i) {
		Triangles.Add(faces[i]);
	}


	static ConstructorHelpers::FObjectFinder<UMaterial> Material(TEXT("Material'/Game/VirtualReality/Materials/VertexColor.VertexColor'"));

	UMaterial* vertex_color_material = NULL;
	if (Material.Object != NULL)
	{
		vertex_color_material = (UMaterial*)Material.Object;
	}
	// Maybe later use for dynamic materials
	//UMaterialInstanceDynamic* dynamic_vertex_color_material = UMaterialInstanceDynamic::Create(vertex_color_material, NULL);

	RuntimeMesh->CreateMeshSection(0, Vertices, Triangles, Normals, TextureCoordinates, VertexColors, Tangents);
	RuntimeMesh->SetMaterial(0, vertex_color_material);
}

// Called when the game starts or when spawned
void AStabiloMesh::BeginPlay()
{
	Super::BeginPlay();
	
}

// Called every frame
{'fraction_non_alphanumeric': 0.15425645402176233, 'fraction_numerical': 0.02048218476637508, 'mean_word_length': 5.176548089591567, 'pattern_counts': {'":': 0, '<': 30, '<?xml version=': 0, '>': 31, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5268873', 'n_tokens_mistral': 1761, 'n_tokens_neox': 1668, 'n_words': 355}