ucsProcess.proto 5.19 KB
syntax = "proto3";

package ucsProcess;

option go_package = "./golang/avvyprotocol";
option csharp_namespace = "AvvyProtocol";

import "avvyprotocol/ucsmodel.proto";

service UCSProcess {
    rpc Process(UCSProcessRequest) returns (UCSProcessResponse);
}

message UCSProcessRequest {
  // Batch request, one may supply a list of instructions
  repeated UCSWorkerInstruction ucsWorkerInstruction = 1;
}

message UCSProcessResponse {
  // Batch reply, one for each worker instruction supplied in UCSProcessRequest
  repeated UCSProcessInstructionResponse ucsProcessInstructionResponse = 1;
}

message UCSProcessInstructionResponse {
  oneof response {
    string error = 1;
    UCSWorkerResult result = 2;
  }
}

/*
This message is serialized and passed directly to worker subprocess.
*/
message UCSWorkerInstruction {
  oneof instruction {
    ModelImportInstruction modelImportInstruction = 1;
    ImageCompressionInstruction imageCompressionInstruction = 2;
    BlockCellsCalculationInstruction blockCellsCalculationInstruction = 3;
  }
}

/*
This message is created in worker subprocess.
*/
message UCSWorkerResult {
    repeated UCSWorkerResultElement elements = 1;
}

message UCSWorkerResultElement {
    ucs.UCSObjectId contentId = 1;
    ucs.StaticContent content = 2;
}


/*
Files should be passed as RawFile messages to ensure their format is recognized correctly.
*/
message RawFile {
  // Only supported input file formats
  FileFormats fileFormat = 1;
  // File binary data
  bytes file = 3;
}

/*
Supported file formats
*/
enum FileFormats {
  // Image
  FMT_PNG = 0;
  // 3D model
  FMT_GLB = 1;
}

// INSTRUCTIONS

/*
ModelImportInstruction - upload a 3D model and get SceneObject with materials back, important options:
1. Compress textures in place or leave them as PNG.
*/
message ModelImportInstruction {
  // Model itself, at the moment only glb is supported
  RawFile model = 1;
  // Texture compression options. PNG is useful for wizard first step (texture compression takes a lot of time).
  InstrTextureImportOption textureImportOption = 2;
  // Do you need block cells calculation?
  InstrBlockCellsOption blockCellsOption = 3;

  // Should we convert to gpu formats right away?
  enum InstrTextureImportOption {
    // Convert all exported textures into GPU formats
    TXTIMP_COMPRESS_TO_GPU_FORMATS = 0;
    // Export textures only as PNG
    TXTIMP_IMPORT_ONLY_PNG = 1;
  }

  // Should we calculate block cells?
  enum InstrBlockCellsOption {
    // Calculate block cells as regular
    BC_CALCULATE_BLOCK_CELLS = 0;
    // Skip block cells calculation
    BC_SKIP_BLOCK_CELLS_CALCULATION = 1;
  }

}

/*
ImageCompressionInstruction - compress an image from PNG to GPU formats. Important options:
1. flipImage options - for model textures we should flip everything, for previews PNG should remain not flipped.
2. textureResizeOption options - should we resize images (useful for previews).
3. createMipmaps - we do not need mipmaps for previews.
4. textureColorSpaceOption - enforce colorspace RGBA8 (useful for previews).
*/
message ImageCompressionInstruction {
  // Image itself, only PNG is supported
  RawFile image = 1;
  // Should we flip image over Y axis?
  InstrFlipImageOption flipImage = 2;
  // Should we resize image? If so, small (256*256) or large (512*512) target?
  InstrTextureResizeOption textureResizeOption = 3;
  // Should we create mipmaps (set false for previews, true for textures)
  InstrMipmapsOption mipmapOption = 4;
  // Does any additional post-processing needed (e.g. cropping a circle)?
  InstrPostprocessingOption postprocessingOption = 5;

  // Should we resize image? If so, small (256*256) or large (512*512) target?
  enum InstrTextureResizeOption {
    // Downscale to 1024*1024 or other smaller closest power of 2
    TXT_POWER_OF_TWO = 0;
    // No size reduction, use with caution
    TXT_NO_RESIZE = 1;
    // Create both small 256*256 and large 512*512 previews
    TXT_SMALL_AND_LARGE_PREVIEW = 2;
    // Small 256*256 preview only
    TXT_SMALL_PREVIEW = 3;
    // Large 512*512 preview only
    TXT_LARGE_PREVIEW = 4;
  }

  // Should we flip image over Y axis?
  enum InstrFlipImageOption {
    // Flip all formats, suitable for textures themselves.
    FLP_FLIP_ALL = 0;
    // Flip only gpu formats (dxt / etc2 / basis / ...), leave PNG with original export. Suitable for previews.
    FLP_FLIP_ONLY_GPU_TEX = 1;
    // No flip, use with caution
    FLP_NO_FLIP = 2;
  }

  // Should we create mipmaps
  enum InstrMipmapsOption {
    // Calculate all mipmaps down to 1px - suitable for material textures
    MM_ALL_MIPMAPS = 0;
    // No mipmaps - suitable for previews
    MM_NO_MIPMAPS = 1;
  }

  // Should we do something special about the image?
  enum InstrPostprocessingOption {
    // No post-processing
    PP_NO_POSTPROCESS = 0;
    // Crop a circle - suitable for textures previews
    PP_CROP_CIRCLE = 1;
  }

}


/*
BlockCellsCalculationInstructions - calculate block cells for an imported mesh model (useful for wizard editor)
*/
message BlockCellsCalculationInstruction {
  // Add all meshes here with applied transforms
  repeated PositionedMesh positionedMeshes = 1;

  message PositionedMesh {
    // 4*4 matrix
    repeated float transform = 1;
    // Provide vertices and faces
    ucs.Mesh mesh = 2;
  }

}