// (c) 2025 ANSYS, Inc. Unauthorized use, distribution, or duplication is prohibited. ANSYS Confidential Information
syntax = "proto3";

package ansys.api.speos.face.v1;

// Face definition with meshing information
message Face
{
	string name = 1;
	string description = 2;
	map<string, string> metadata = 3; // user defined metadata
	repeated float vertices = 10; // coordinates of all points (p1x p1y p1z p2x p2y p2z ...)
	repeated uint32 facets = 11; // indexes of points for all triangles (t1_1 t1_2 t1_3 t2_1 t2_2 t2_3 ...)
	repeated float normals = 12; // normal vector for all points (n1x n1y n1z n2x n2y n2z ...)

	message TextureCoordinates
	{
		repeated float uv = 1; // coordinates (u_1 v_1 ... u_NbPoints v_NbPoints) representating bridge between vertices and point on texture 
	}

	repeated TextureCoordinates texture_coordinates_channels = 13; // if we want apply textures on this face, we have to set a TextureCoordinates per texture

	// tangents ?
	// bitangents ?
	// custom data on vertex ?
}

service FacesManager {
	// Create a new face
	rpc Create(Create_Request) returns (Create_Response) {}
	// Read a face
	rpc Read(Read_Request) returns (Read_Response) {}
	// Update a face
	rpc Update(Update_Request) returns (Update_Response) {}
	// Delete a face
	rpc Delete(Delete_Request) returns (Delete_Response) {}
	// List all faces in manager
	rpc List(List_Request) returns (List_Response) {}
}


// Request to create a face
message Create_Request {
    Face face = 1; // face to create
}
// Response to create a face
message Create_Response {
	string guid = 1; // Guid of the created face
}

// Request to read a face
message Read_Request {
	string guid = 1; // Guid of the face to be read
}
// Response to read a face
message Read_Response {
	Face face = 1; // face corresponding to the guid given in Read_Request
}

// Request to update a face
message Update_Request {
	string guid = 1; // Guid of the face to be updated
	Face face = 2; // New face that will be used for the update
}
// Response to update a face
message Update_Response {
}

// Request to delete a face
message Delete_Request {
	string guid = 1; // Guid of the face to be deleted
}
// Response to delete a face
message Delete_Response {}

// Request to list all faces
message List_Request {}
// Response to list all faces
message List_Response {
	repeated string guids = 1; // Guids of all faces
}

// Chunk of a Face
message Chunk {
	oneof data {
		FaceHeader face_header = 1; // Common face data - Field used only in first Chunk (to take advantage of vectors sizes) - If several faces are uploaded/downloaded, then this message determines the start of a new face streaming.
		Vertices vertices = 2; // coordinates of all points (p1x p1y p1z p2x p2y p2z ...)
		Facets facets = 3; // indexes of points for all triangles (t1_1 t1_2 t1_3 t2_1 t2_2 t2_3 ...)
		Normals normals = 4; // normal vector for all points (n1x n1y n1z n2x n2y n2z ...)
		TextureCoordinatesChannels texture_coordinates_channels = 5;
	}

	message FaceHeader {
		string guid = 1; // Guid of a FacesManager element - Used for FaceActions.Upload rpc
		string name = 2;
		string description = 3;
		map<string, string> metadata = 4;
		repeated int32 sizes = 5; // total sizes for vectors: (vertices_normals_size, facets_size, texture_coordinates_channels_size) - vertices and normals vectors have same size, that's why it is gathered in vertices_normals_size
	}
	
	message Vertices {
		repeated float data = 1;
	}
	
	message Facets {
		repeated uint32 data = 1;
	}
	
	message Normals {
		repeated float data = 1;
	}

	message TextureCoordinatesChannels {
		repeated Face.TextureCoordinates data = 1;
	}
}
message Upload_Response {
}
message Download_Request {
	string guid = 1; // Guid of a FacesManager element
	repeated string guids = 2; // Guids of FacesManager elements to download.
	optional bool only_face_header = 3; // If this optional boolean is set to true, only the FaceHeader will be returned in answer stream.
}
message ReserveFace_Response{
	repeated string guids = 1; // guids of the created faces, in the order sent
}

message ReserveFace_Request{
	repeated Face faces = 1; // repeated face headers
}

// Actions available on a face
service FaceActions {
	// allocate faces before uploading them.
	// to have maximum benefit, only the name, description and metadata should be filled
	rpc ReserveFaces(stream ReserveFace_Request) returns(stream ReserveFace_Response){}
	// Update a face via streaming
	rpc Upload(stream Chunk) returns (Upload_Response) {}
	// Read a face via streaming
	rpc Download(Download_Request) returns (stream Chunk) {}
}
