{
	"$schema": "https://json-schema.org/draft/2020-12/schema",
	"$id": "https://schema.stfform.at/stf.mesh.schema.json",
	"title": "STF Mesh",
	"description": "Represents a skeleton comprised of bones in a 3d hierarchy.",
	"stfLongDescription": {
		"title": "Datamodel",
		"content": "* **Face:** Made up of one or more triangles.\\\nThe Material Index exists at this level.\n* **Triangle:** 3 Face Corners, which can be shared by other triangles of the same face.\n* **Face Corner:** Reference to a Split, which can be shared by other face corners.\n* **Split:** References a vertex, which can be shared by other splits, as long as at least one of their other properties (Normal, UV, Color, ...) is unique.\\\nNormals, UVs and colors exist at this level.\n* **Vertex:** Position\\\nBlendshapes, weights & vertex groups exist at this level."
	},
	"stfImplementations": {
		"blender": {
			"representingType": "bpy.types.Mesh",
			"link": "https://codeberg.org/stf_format/stf_blender/src/branch/master/stfblender/stf_resources/stf/stf_mesh/stf_mesh.py"
		},
		"godot": {
			"representingType": "Mesh",
			"link": "https://codeberg.org/stf_format/stf_godot/src/branch/master/addons/stf_godot/resources/stf/STF_Mesh.gd"
		},
		"unity": {
			"representingType": "Mesh",
			"link": "https://codeberg.org/stf_format/stf_unity/src/branch/master/Runtime/Resources/Resources_STF/STF_Mesh/STF_Mesh.cs",
			"extra_links": {
				"Default Processor": "https://codeberg.org/stf_format/stf_unity/src/branch/master/Runtime/Processors/Processors_STF/STF_Mesh_Processor.cs"
			}
		},
		"three.js": {
			"representingType": "BufferGeometry",
			"link": "https://codeberg.org/stf_format/stf_js/src/branch/master/stf_threejs/src/stf_resources/stf_mesh.ts"
		}
	},
	"allOf": [{ "$ref": "https://schema.stfform.at/stf.schema.json#/$defs/stf_data_resource" }],
	"properties": {
		"type": {
			"const": "stf.mesh"
		},
		"float_width": {
			"type": "integer",
			"minimum": 1,
			"default": 4,
			"description": "Byte-width of float-values."
		},
		"indices_width": {
			"type": "integer",
			"minimum": 1,
			"default": 4,
			"description": "Byte-width of indices."
		},
		"material_slots": {
			"type": "array",
			"items": {
				"$ref": "https://schema.stfform.at/stf.schema.json#resource_ref",
				"type": ["number", "null"],
				"stfType": "Resource-Ref | null"
			},
			"description": "Array of optional resource references representing the default material resource for each material slot. Which face belongs to which material is defined by the `material_indices` buffer. These can be overridden by the meshes instance."
		},
		"vertices": {
			"$ref": "https://schema.stfform.at/stf.schema.json#buffer_ref",
			"description": "Buffer reference. Every three float values describe the XYZ components of a vertex."
		},
		"splits": {
			"$ref": "https://schema.stfform.at/stf.schema.json#buffer_ref",
			"description": "Buffer reference. Vertex index for each unique combination of normals, uvs, colors, etc.."
		},
		"split_normals": {
			"$ref": "https://schema.stfform.at/stf.schema.json#buffer_ref",
			"description": "Buffer reference. Every three float values describe the XYZ components of a splits normal vector."
		},
		"split_colors": {
			"$ref": "https://schema.stfform.at/stf.schema.json#buffer_ref",
			"description": "Buffer reference. Every four float values describe the RGBA color of a split."
		},
		"face_corners": {
			"$ref": "https://schema.stfform.at/stf.schema.json#buffer_ref",
			"description": "Buffer reference. Index of the split for each face corner"
		},
		"tris": {
			"$ref": "https://schema.stfform.at/stf.schema.json#buffer_ref",
			"description": "Buffer reference. Every three values describe the `face_corner` indices that form a triangle."
		},
		"faces": {
			"$ref": "https://schema.stfform.at/stf.schema.json#buffer_ref",
			"description": "Buffer reference. Every uint value describes the number of `tris` that are part of the same face."
		},
		"material_indices": {
			"$ref": "https://schema.stfform.at/stf.schema.json#buffer_ref",
			"description": "Buffer reference. Each value is an index for the `material_indices`, for each face."
		},
		"sharp_edges": {
			"$ref": "https://schema.stfform.at/stf.schema.json#buffer_ref",
			"description": "Buffer reference. Every two values describe indices of two connected vertices that have explicitly set split normals."
		},
		"sharp_face_indices": {
			"$ref": "https://schema.stfform.at/stf.schema.json#buffer_ref",
			"description": "Buffer reference. Every values describes the index of a face that has explicitly set split normals."
		},
		"lines": {
			"$ref": "https://schema.stfform.at/stf.schema.json#buffer_ref",
			"description": "Buffer reference. Every two values describe indices of two vertices that should render as a line."
		},
		"armature": {
			"$ref": "https://schema.stfform.at/stf.schema.json#resource_ref",
			"description": "Resource reference. If the mesh is rigged, it has to reference an armature resource."
		},
		"weight_lens_width": {
			"type": "integer",
			"minimum": 1,
			"default": 1,
			"description": "Byte-width of bone weight float-values."
		},
		"bone_indices_width": {
			"type": "integer",
			"minimum": 1,
			"default": 1,
			"description": "Byte-width of bone indices."
		},
		"bones": {
			"type": "array",
			"items": {
				"$ref": "https://schema.stfform.at/stf.schema.json#resource_id",
				"description": "Resource ID of a bone from the referenced `armature` resource."
			},
			"description": "The Resource-IDs of the `armature`'s bones at the index corresponding to the `bone_indices` buffer."
		},
		"weight_lens": {
			"$ref": "https://schema.stfform.at/stf.schema.json#buffer_ref",
			"description": "Buffer reference. The number of bone-weights for each vertex."
		},
		"bone_indices": {
			"$ref": "https://schema.stfform.at/stf.schema.json#buffer_ref",
			"description": "Buffer reference. The bone index for each weight for each vertex. The bone index corresponds to the `bones` array"
		},
		"weights": {
			"$ref": "https://schema.stfform.at/stf.schema.json#buffer_ref",
			"description": "Buffer reference. The bone weight for each weight for each vertex."
		},
		"uvs": {
			"type": "array",
			"items": {
				"type": "object",
				"title": "UV Channel",
				"properties": {
					"name": {
						"type": "string",
						"description": "The name of the UV channel"
					},
					"uv": {
						"$ref": "https://schema.stfform.at/stf.schema.json#buffer_ref",
						"description": "Buffer reference. Every two float values describe the UV coordinates of a split"
					}
				},
				"required": [
					"uv"
				]
			},
			"description": "An array of objects describing a UV channel.",
			"stfExpand": true
		},
		"blendshapes": {
			"type": "array",
			"items": {
				"type": "object",
				"title": "Blendshape",
				"properties": {
					"name": {
						"type": "string",
						"description": "The name of the blendshape"
					},
					"default_value": {
						"type": "number",
						"default": 0
					},
					"limit_upper": {
						"type": "number",
						"default": 1
					},
					"limit_lower": {
						"type": "number",
						"default": 0
					},
					"indices": {
						"$ref": "https://schema.stfform.at/stf.schema.json#buffer_ref",
						"description": "Buffer reference. If the blendshape doesn't store values for every vertex, this buffer specifies a list of vertex-indices it affects."
					},
					"position_offsets": {
						"$ref": "https://schema.stfform.at/stf.schema.json#buffer_ref",
						"description": "Buffer reference. Every three float values are the XYZ relative offsets for vertex positions. Has offsets for each vertex, of if the `indices` buffer is present, values for each vertex index."
					},
					"split_indices": {
						"$ref": "https://schema.stfform.at/stf.schema.json#buffer_ref",
						"description": "Buffer reference. If the blendshape doesn't store values for every vertex-split, this buffer specifies a list of split-indices it affects."
					},
					"split_normals": {
						"$ref": "https://schema.stfform.at/stf.schema.json#buffer_ref",
						"description": "Buffer reference. Every three float values are the XYZ normals. Has normals for each split, of if the `split_indices` buffer is present, values for each split index."
					}
				},
				"required": [
					"name",
					"position_offsets"
				]
			},
			"description": "Blendshapes",
			"stfExpand": true
		},
		"vertex_groups": {
			"type": "array",
			"items": {
				"type": "object",
				"title": "Vertex Group",
				"properties": {
					"name": {
						"type": "string",
						"description": "The name of the vertex group"
					},
					"indices": {
						"$ref": "https://schema.stfform.at/stf.schema.json#buffer_ref",
						"description": "Buffer reference. If the vertex group doesn't store values for every vertex, this buffer specifies a list of vertex-indices it affects."
					},
					"weights": {
						"$ref": "https://schema.stfform.at/stf.schema.json#buffer_ref",
						"description": "Buffer reference. Each float value is the weight for a vertex. Has weights for each vertex, of if the `indices` buffer is present, weights for each vertex index."
					}
				},
				"required": [
					"weights"
				]
			},
			"description": "Vertex groups",
			"stfExpand": true
		}
	},
	"required": [
		"type",
		"vertices",
		"face_corners",
		"splits",
		"tris",
		"faces"
	],
	"additionalProperties": false,
	"examples": [
		{
			"type": "stf.mesh",
			"name": "Cube",
			"referenced_resources": [
				"ec16a927-1b26-4157-a3f2-71455d05e2bf"
			],
			"material_slots": [
				0
			],
			"float_width": 4,
			"indices_width": 1,
			"referenced_buffers": [
				"a2678730-f63c-4415-85a8-9426bfc7242e",
				"be7acc51-f47c-406c-82f6-c7ea7833ed4d",
				"c29e0d3a-9b4d-444b-93f1-e3163332fdcb",
				"d3329a1a-b79a-4d27-b16d-f7af2420951a",
				"97925952-70a7-4773-96fe-00e44d4cdfee",
				"05039913-1397-4f3c-9b54-d514ace748e7",
				"4d86408e-84f5-4f05-86b2-82f3a8803f9d",
				"6cdbf5c5-e770-4bbf-924f-4c10818826e9",
				"e7b0b03d-c004-4876-97a3-c4a26b7ac3c9",
				"ecb6ef8b-618c-4dcd-a0b0-0a0cf70cf143",
				"42a32c5f-edb6-43c3-a028-fa2a75b46671"
			],
			"vertices": 0,
			"face_corners": 1,
			"splits": 2,
			"split_normals": 3,
			"uvs": [
				{
					"name": "UVMap",
					"uv": 4
				}
			],
			"tris": 5,
			"material_indices_width": 1,
			"faces": 6,
			"material_indices": 7,
			"sharp_face_indices": 8,
			"lines": 9,
			"sharp_edges": 10,
			"components": [
				"5b09c146-b626-4fb4-a4fa-b33b0e5085e2"
			]
		}
	]
}