diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 6a8ee6ee..b227ba86 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -36,6 +36,18 @@ jobs: echo "Generated schemas are up to date!" fi + - name: Validate Flatbuffer definitions + run: | + curl -LO https://github.com/google/flatbuffers/releases/download/v22.10.26/Linux.flatc.binary.clang++-12.zip + echo "0821af82a3a736b0ba9235c02219df24d1f042dd Linux.flatc.binary.clang++-12.zip" | shasum -a 1 -c + unzip Linux.flatc.binary.clang++-12.zip + output=$(./flatc --ts -o /dev/null ./schemas/flatbuffer/*.fbs) + if [ -n "$output" ]; then + echo "::error::Flatbuffer schema compilation had warnings or errors. Fix them to proceed:" + echo "$output" + exit 1 + fi + - name: Validate protobuf definitions run: protoc --proto_path=schemas/proto schemas/proto/**/*.proto --descriptor_set_out=/dev/null diff --git a/internal/generateFlatbufferSchema.test.ts b/internal/generateFlatbufferSchema.test.ts new file mode 100644 index 00000000..c9fa3fa9 --- /dev/null +++ b/internal/generateFlatbufferSchema.test.ts @@ -0,0 +1,118 @@ +import { generateFlatbuffers } from "./generateFlatbufferSchema"; +import { exampleEnum, exampleMessage } from "./testFixtures"; + +describe("generateFlatbuffers", () => { + it("generates Message .fbs files", () => { + expect(generateFlatbuffers(exampleMessage, [exampleEnum])).toMatchInlineSnapshot(` + "// Generated by https://github.com/foxglove/schemas + + include "ByteVector.fbs"; + include "Duration.fbs"; + include "NestedMessage.fbs"; + include "Time.fbs"; + + namespace foxglove; + + /// An example enum + enum ExampleEnum : ubyte { + /// Value A + A = 1, + + /// Value B + B = 2, + } + /// An example type + table ExampleMessage { + /// duration field + field_duration:Duration; + + /// time field + field_time:Time; + + /// boolean field + field_boolean:bool = true; + + /// bytes field + field_bytes:[uint8]; + + /// float64 field + field_float64:double = 1.0; + + /// uint32 field + field_uint32:uint32 = 5; + + /// string field + field_string:string = "string-type"; + + /// duration array field + field_duration_array:[Duration]; + + /// time array field + field_time_array:[Time]; + + /// boolean array field + field_boolean_array:[bool]; + + /// bytes array field + field_bytes_array:[ByteVector]; + + /// float64 array field + field_float64_array:[double]; + + /// uint32 array field + field_uint32_array:[uint32]; + + /// string array field + field_string_array:[string]; + + /// duration fixed-length array field + /// length 3 + field_duration_fixed_array:[Duration]; + + /// time fixed-length array field + /// length 3 + field_time_fixed_array:[Time]; + + /// boolean fixed-length array field + /// length 3 + field_boolean_fixed_array:[bool]; + + /// bytes fixed-length array field + /// length 3 + field_bytes_fixed_array:[ByteVector]; + + /// float64 fixed-length array field + /// length 3 + field_float64_fixed_array:[double]; + + /// uint32 fixed-length array field + /// length 3 + field_uint32_fixed_array:[uint32]; + + /// string fixed-length array field + /// length 3 + field_string_fixed_array:[string]; + + /// An enum field + field_enum:ExampleEnum; + + /// An enum array field + field_enum_array:[ExampleEnum]; + + /// A nested field + field_nested:foxglove.NestedMessage; + + /// A nested array field + /// With + /// a + /// very + /// long + /// description + field_nested_array:[foxglove.NestedMessage]; + } + + root_type ExampleMessage; + " + `); + }); +}); diff --git a/internal/generateFlatbufferSchema.ts b/internal/generateFlatbufferSchema.ts new file mode 100644 index 00000000..149ea493 --- /dev/null +++ b/internal/generateFlatbufferSchema.ts @@ -0,0 +1,189 @@ +import { FoxgloveEnumSchema, FoxglovePrimitive, FoxgloveSchema } from "./types"; + +// Flatbuffers only supports nested vectors via table +export const BYTE_VECTOR_FB = ` +namespace foxglove; + +/// Used for nesting byte vectors +table ByteVector { + data:[uint8]; +} +root_type ByteVector; +`; + +// Same as protobuf wellknown types +export const TIME_FB = ` +namespace foxglove; + +struct Time { + /// Represents seconds of UTC time since Unix epoch 1970-01-01T00:00:00Z + sec:uint32; + /// Nano-second fractions from 0 to 999,999,999 inclusive + nsec:uint32; +} +`; + +export const DURATION_FB = ` +namespace foxglove; + +struct Duration { + /// Signed seconds of the span of time. Must be from -315,576,000,000 to +315,576,000,000 inclusive. + sec:int32; + /// if sec === 0 : -999,999,999 <= nsec <= +999,999,999 + /// otherwise sign of sec must match sign of nsec or be 0 and abs(nsec) <= 999,999,999 + nsec:int32; +} +`; + +function primitiveToFlatbuffers(type: Exclude) { + switch (type) { + case "uint32": + return "uint32"; + case "bytes": + return "[uint8]"; + case "string": + return "string"; + case "boolean": + return "bool"; + case "float64": + return "double"; + } +} + +export function generateFlatbuffers( + schema: FoxgloveSchema, + nestedEnums: FoxgloveEnumSchema[], +): string { + const enumDefinitions: string[] = []; + for (const enumSchema of nestedEnums) { + const fields = enumSchema.values.map(({ name, value, description }) => { + if (description != undefined) { + return `/// ${description}\n ${name} = ${value},`; + } else { + return `${name} = ${value},`; + } + }); + enumDefinitions.push( + // `///` comments required to show up in compiled flatbuffer schemas + `/// ${enumSchema.description}\nenum ${enumSchema.name} : ubyte {\n ${fields.join( + "\n\n ", + )}\n}\n`, + ); + } + + let definition; + const imports = new Set(); + switch (schema.type) { + case "enum": { + const fields = schema.values.map(({ name, value, description }) => { + if (description != undefined) { + return `/// ${description}\n ${name} = ${value},`; + } else { + return `${name} = ${value},`; + } + }); + + // `///` comments required to show up in compiled flatbuffer schemas + definition = `/// ${schema.description}\nenum ${schema.name} : ubyte {\n ${fields.join( + "\n\n ", + )}\n}\n`; + break; + } + case "message": { + const fields = schema.fields.map((field) => { + const isArray = field.array != undefined; + + let type; + switch (field.type.type) { + case "enum": + type = field.type.enum.name; + break; + case "nested": + type = `foxglove.${field.type.schema.name}`; + imports.add(field.type.schema.name); + break; + case "primitive": + if (field.type.name === "time") { + type = "Time"; + imports.add(`Time`); + } else if (field.type.name === "duration") { + type = "Duration"; + imports.add(`Duration`); + } else if (field.type.name === "bytes" && isArray) { + type = "ByteVector"; + imports.add("ByteVector"); + } else { + type = primitiveToFlatbuffers(field.type.name); + } + break; + } + let lengthComment; + + if (typeof field.array === "number") { + // can't specify length of vector outside of struct, all of these are tables + lengthComment = ` /// length ${field.array}\n`; + } + let defaultValue; + if (field.defaultValue != undefined && !isArray) { + if ( + field.type.type === "primitive" && + !(field.type.name === "duration" || field.type.name === "time") + ) { + if (typeof field.defaultValue === "string") { + defaultValue = `"${field.defaultValue}"`; + } else if (typeof field.defaultValue === "number") { + if (Number.isInteger(field.defaultValue) && field.type.name === "float64") { + // if it is a floating point number that is an integer, we need to add a decimal point + defaultValue = `${field.defaultValue}.0`; + } else { + defaultValue = field.defaultValue.toString(); + } + } else if (typeof field.defaultValue === "boolean") { + // uses same 'false'/'true' as js + defaultValue = field.defaultValue.toString(); + } + } else if (field.type.type === "enum") { + // default enums are just the enum string of the enum and don't require other formatting + // ie: type numericType: NumericType = INT32; + defaultValue = field.defaultValue as string; + } + } + if (field.defaultValue != undefined && defaultValue == undefined) { + throw new Error("Flatbuffers does not support non-scalar default values"); + } + + return `${field.description + .trim() + .split("\n") + .map((line) => ` /// ${line}\n`) + .join("")}${ + // can't have inline comments, so the lengthComment needs to be above + lengthComment ?? "" + // convert field.name to lowercase for flatbuffer compilation compliance + } ${field.name.toLowerCase()}:${isArray ? `[${type}]` : type}${ + defaultValue ? ` = ${defaultValue}` : "" + };`; + }); + + definition = `${enumDefinitions.join("\n\n")}/// ${schema.description}\ntable ${ + schema.name + } {\n${fields.join("\n\n")}\n}\n\nroot_type ${schema.name};`; + break; + } + } + + const outputSections = [ + `// Generated by https://github.com/foxglove/schemas`, + + Array.from(imports) + .sort() + .map((name) => `include "${name}.fbs";`) + .join("\n"), + + `namespace foxglove;`, + + definition, + ].filter(Boolean); + + return outputSections.join("\n\n") + "\n"; +} diff --git a/internal/generateProto.test.ts b/internal/generateProto.test.ts index dbcecdf6..79b55554 100644 --- a/internal/generateProto.test.ts +++ b/internal/generateProto.test.ts @@ -117,7 +117,7 @@ describe("generateProto", () => { root.addJSON(protobufjs.common.get("google/protobuf/duration.proto")!.nested!); for (const schema of Object.values(foxgloveMessageSchemas)) { const enums = Object.values(foxgloveEnumSchemas).filter( - (enumSchema) => enumSchema.protobufParentMessageName === schema.name, + (enumSchema) => enumSchema.parentSchemaName === schema.name, ); root.add(protobufjs.parse(generateProto(schema, enums)).root); } diff --git a/internal/schemas.test.ts b/internal/schemas.test.ts index 99172dde..90c3d1b0 100644 --- a/internal/schemas.test.ts +++ b/internal/schemas.test.ts @@ -8,7 +8,7 @@ describe("schemas", () => { } for (const [key, value] of Object.entries(foxgloveEnumSchemas)) { expect(key).toEqual(value.name); - expect(value.protobufParentMessageName in foxgloveMessageSchemas).toBe(true); + expect(value.parentSchemaName in foxgloveMessageSchemas).toBe(true); } }); diff --git a/internal/schemas.ts b/internal/schemas.ts index e93b39c3..edded046 100644 --- a/internal/schemas.ts +++ b/internal/schemas.ts @@ -9,21 +9,25 @@ const Color: FoxgloveMessageSchema = { name: "r", type: { type: "primitive", name: "float64" }, description: "Red value between 0 and 1", + defaultValue: 1.0, }, { name: "g", type: { type: "primitive", name: "float64" }, description: "Green value between 0 and 1", + defaultValue: 1.0, }, { name: "b", type: { type: "primitive", name: "float64" }, description: "Blue value between 0 and 1", + defaultValue: 1.0, }, { name: "a", type: { type: "primitive", name: "float64" }, description: "Alpha value between 0 and 1", + defaultValue: 1.0, }, ], }; @@ -37,11 +41,13 @@ const Vector2: FoxgloveMessageSchema = { name: "x", type: { type: "primitive", name: "float64" }, description: "x coordinate length", + defaultValue: 1.0, }, { name: "y", type: { type: "primitive", name: "float64" }, description: "y coordinate length", + defaultValue: 1.0, }, ], }; @@ -56,16 +62,19 @@ const Vector3: FoxgloveMessageSchema = { name: "x", type: { type: "primitive", name: "float64" }, description: "x coordinate length", + defaultValue: 1.0, }, { name: "y", type: { type: "primitive", name: "float64" }, description: "y coordinate length", + defaultValue: 1.0, }, { name: "z", type: { type: "primitive", name: "float64" }, description: "z coordinate length", + defaultValue: 1.0, }, ], }; @@ -137,6 +146,7 @@ const Quaternion: FoxgloveMessageSchema = { name: "w", type: { type: "primitive", name: "float64" }, description: "w value", + defaultValue: 1.0, }, ], }; @@ -181,7 +191,7 @@ const KeyValuePair: FoxgloveMessageSchema = { const SceneEntityDeletionType: FoxgloveEnumSchema = { type: "enum", name: "SceneEntityDeletionType", - protobufParentMessageName: "SceneEntityDeletion", + parentSchemaName: "SceneEntityDeletion", protobufEnumName: "Type", description: "An enumeration indicating which entities should match a SceneEntityDeletion command", @@ -343,7 +353,7 @@ const CylinderPrimitive: FoxgloveMessageSchema = { const LineType: FoxgloveEnumSchema = { type: "enum", name: "LineType", - protobufParentMessageName: "LinePrimitive", + parentSchemaName: "LinePrimitive", protobufEnumName: "Type", description: "An enumeration indicating how input points should be interpreted to create lines", values: [ @@ -919,7 +929,7 @@ const NumericType: FoxgloveEnumSchema = { type: "enum", name: "NumericType", description: "Numeric type", - protobufParentMessageName: "PackedElementField", + parentSchemaName: "PackedElementField", protobufEnumName: "NumericType", values: [ { name: "UNKNOWN", value: 0 }, @@ -1054,7 +1064,7 @@ const PointsAnnotationType: FoxgloveEnumSchema = { type: "enum", name: "PointsAnnotationType", description: "Type of points annotation", - protobufParentMessageName: "PointsAnnotation", + parentSchemaName: "PointsAnnotation", protobufEnumName: "Type", values: [ { name: "UNKNOWN", value: 0 }, @@ -1135,7 +1145,7 @@ const PositionCovarianceType: FoxgloveEnumSchema = { type: "enum", name: "PositionCovarianceType", description: "Type of position covariance", - protobufParentMessageName: "LocationFix", + parentSchemaName: "LocationFix", protobufEnumName: "PositionCovarianceType", values: [ { name: "UNKNOWN", value: 0 }, @@ -1185,7 +1195,7 @@ const LogLevel: FoxgloveEnumSchema = { type: "enum", name: "LogLevel", description: "Log level", - protobufParentMessageName: "Log", + parentSchemaName: "Log", protobufEnumName: "Level", values: [ { name: "UNKNOWN", value: 0 }, diff --git a/internal/testFixtures.ts b/internal/testFixtures.ts index 62de11d9..cf949a2c 100644 --- a/internal/testFixtures.ts +++ b/internal/testFixtures.ts @@ -14,7 +14,7 @@ export const exampleEnum: FoxgloveEnumSchema = { type: "enum", name: "ExampleEnum", protobufEnumName: "ExampleProtoEnum", - protobufParentMessageName: "ExampleMessage", + parentSchemaName: "ExampleMessage", description: "An example enum", values: [ { name: "A", value: 1, description: "Value A" }, @@ -44,6 +44,17 @@ export const exampleMessage: FoxgloveMessageSchema = { name: `field_${name}`, description: `${name} field`, type: { type: "primitive", name }, + defaultValue: + name === "boolean" + ? true + : name === "string" + ? "string-type" + : name === "uint32" + ? 5 + : name === "float64" + ? 1.0 + : // time and duration and bytes + undefined, })), ...allPrimitives.map((name): FoxgloveMessageSchema["fields"][0] => ({ name: `field_${name}_array`, diff --git a/internal/types.ts b/internal/types.ts index b3f05cd2..73f7e868 100644 --- a/internal/types.ts +++ b/internal/types.ts @@ -11,7 +11,7 @@ export type FoxgloveEnumSchema = { type: "enum"; name: string; description: string; - protobufParentMessageName: string; + parentSchemaName: string; protobufEnumName: string; values: ReadonlyArray<{ value: number; @@ -30,6 +30,7 @@ export type FoxgloveMessageField = { required?: true; description: string; protobufFieldNumber?: number; + defaultValue?: string | number | boolean; }; export type FoxgloveMessageSchema = { diff --git a/schemas/flatbuffer/ArrowPrimitive.fbs b/schemas/flatbuffer/ArrowPrimitive.fbs new file mode 100644 index 00000000..7a7f1049 --- /dev/null +++ b/schemas/flatbuffer/ArrowPrimitive.fbs @@ -0,0 +1,29 @@ +// Generated by https://github.com/foxglove/schemas + +include "Color.fbs"; +include "Pose.fbs"; + +namespace foxglove; + +/// A primitive representing an arrow +table ArrowPrimitive { + /// Position of the arrow's tail and orientation of the arrow. Identity orientation means the arrow points in the +x direction. + pose:foxglove.Pose; + + /// Length of the arrow shaft + shaft_length:double; + + /// Diameter of the arrow shaft + shaft_diameter:double; + + /// Length of the arrow head + head_length:double; + + /// Diameter of the arrow head + head_diameter:double; + + /// Color of the arrow + color:foxglove.Color; +} + +root_type ArrowPrimitive; diff --git a/schemas/flatbuffer/ByteVector.fbs b/schemas/flatbuffer/ByteVector.fbs new file mode 100644 index 00000000..513df430 --- /dev/null +++ b/schemas/flatbuffer/ByteVector.fbs @@ -0,0 +1,8 @@ + +namespace foxglove; + +/// Used for nesting byte vectors +table ByteVector { + data:[uint8]; +} +root_type ByteVector; diff --git a/schemas/flatbuffer/CameraCalibration.fbs b/schemas/flatbuffer/CameraCalibration.fbs new file mode 100644 index 00000000..18d76d94 --- /dev/null +++ b/schemas/flatbuffer/CameraCalibration.fbs @@ -0,0 +1,78 @@ +// Generated by https://github.com/foxglove/schemas + +include "Time.fbs"; + +namespace foxglove; + +/// Camera calibration parameters +table CameraCalibration { + /// Timestamp of calibration data + timestamp:Time; + + /// Frame of reference for the camera. The origin of the frame is the optical center of the camera. +x points to the right in the image, +y points down, and +z points into the plane of the image. + frame_id:string; + + /// Image width + width:uint32; + + /// Image height + height:uint32; + + /// Name of distortion model + /// + /// Supported values: `plumb_bob` and `rational_polynomial` + distortion_model:string; + + /// Distortion parameters + d:[double]; + + /// Intrinsic camera matrix (3x3 row-major matrix) + /// + /// A 3x3 row-major matrix for the raw (distorted) image. + /// + /// Projects 3D points in the camera coordinate frame to 2D pixel coordinates using the focal lengths (fx, fy) and principal point (cx, cy). + /// + /// ``` + /// [fx 0 cx] + /// K = [ 0 fy cy] + /// [ 0 0 1] + /// ``` + /// length 9 + k:[double]; + + /// Rectification matrix (stereo cameras only, 3x3 row-major matrix) + /// + /// A rotation matrix aligning the camera coordinate system to the ideal stereo image plane so that epipolar lines in both stereo images are parallel. + /// length 9 + r:[double]; + + /// Projection/camera matrix (3x4 row-major matrix) + /// + /// ``` + /// [fx' 0 cx' Tx] + /// P = [ 0 fy' cy' Ty] + /// [ 0 0 1 0] + /// ``` + /// + /// By convention, this matrix specifies the intrinsic (camera) matrix of the processed (rectified) image. That is, the left 3x3 portion is the normal camera intrinsic matrix for the rectified image. + /// + /// It projects 3D points in the camera coordinate frame to 2D pixel coordinates using the focal lengths (fx', fy') and principal point (cx', cy') - these may differ from the values in K. + /// + /// For monocular cameras, Tx = Ty = 0. Normally, monocular cameras will also have R = the identity and P[1:3,1:3] = K. + /// + /// For a stereo pair, the fourth column [Tx Ty 0]' is related to the position of the optical center of the second camera in the first camera's frame. We assume Tz = 0 so both cameras are in the same stereo image plane. The first camera always has Tx = Ty = 0. For the right (second) camera of a horizontal stereo pair, Ty = 0 and Tx = -fx' * B, where B is the baseline between the cameras. + /// + /// Given a 3D point [X Y Z]', the projection (x, y) of the point onto the rectified image is given by: + /// + /// ``` + /// [u v w]' = P * [X Y Z 1]' + /// x = u / w + /// y = v / w + /// ``` + /// + /// This holds for both images of a stereo pair. + /// length 12 + p:[double]; +} + +root_type CameraCalibration; diff --git a/schemas/flatbuffer/CircleAnnotation.fbs b/schemas/flatbuffer/CircleAnnotation.fbs new file mode 100644 index 00000000..de2a6cba --- /dev/null +++ b/schemas/flatbuffer/CircleAnnotation.fbs @@ -0,0 +1,30 @@ +// Generated by https://github.com/foxglove/schemas + +include "Color.fbs"; +include "Point2.fbs"; +include "Time.fbs"; + +namespace foxglove; + +/// A circle annotation on a 2D image +table CircleAnnotation { + /// Timestamp of circle + timestamp:Time; + + /// Center of the circle in 2D image coordinates + position:foxglove.Point2; + + /// Circle diameter + diameter:double; + + /// Line thickness + thickness:double; + + /// Fill color + fill_color:foxglove.Color; + + /// Outline color + outline_color:foxglove.Color; +} + +root_type CircleAnnotation; diff --git a/schemas/flatbuffer/Color.fbs b/schemas/flatbuffer/Color.fbs new file mode 100644 index 00000000..9c48fed9 --- /dev/null +++ b/schemas/flatbuffer/Color.fbs @@ -0,0 +1,20 @@ +// Generated by https://github.com/foxglove/schemas + +namespace foxglove; + +/// A color in RGBA format +table Color { + /// Red value between 0 and 1 + r:double = 1.0; + + /// Green value between 0 and 1 + g:double = 1.0; + + /// Blue value between 0 and 1 + b:double = 1.0; + + /// Alpha value between 0 and 1 + a:double = 1.0; +} + +root_type Color; diff --git a/schemas/flatbuffer/CompressedImage.fbs b/schemas/flatbuffer/CompressedImage.fbs new file mode 100644 index 00000000..f22b81de --- /dev/null +++ b/schemas/flatbuffer/CompressedImage.fbs @@ -0,0 +1,24 @@ +// Generated by https://github.com/foxglove/schemas + +include "Time.fbs"; + +namespace foxglove; + +/// A compressed image +table CompressedImage { + /// Timestamp of image + timestamp:Time; + + /// Frame of reference for the image. The origin of the frame is the optical center of the camera. +x points to the right in the image, +y points down, and +z points into the plane of the image. + frame_id:string; + + /// Compressed image data + data:[uint8]; + + /// Image format + /// + /// Supported values: `webp`, `jpeg`, `png` + format:string; +} + +root_type CompressedImage; diff --git a/schemas/flatbuffer/CubePrimitive.fbs b/schemas/flatbuffer/CubePrimitive.fbs new file mode 100644 index 00000000..01148723 --- /dev/null +++ b/schemas/flatbuffer/CubePrimitive.fbs @@ -0,0 +1,21 @@ +// Generated by https://github.com/foxglove/schemas + +include "Color.fbs"; +include "Pose.fbs"; +include "Vector3.fbs"; + +namespace foxglove; + +/// A primitive representing a cube or rectangular prism +table CubePrimitive { + /// Position of the center of the cube and orientation of the cube + pose:foxglove.Pose; + + /// Size of the cube along each axis + size:foxglove.Vector3; + + /// Color of the arrow + color:foxglove.Color; +} + +root_type CubePrimitive; diff --git a/schemas/flatbuffer/CylinderPrimitive.fbs b/schemas/flatbuffer/CylinderPrimitive.fbs new file mode 100644 index 00000000..0b5391ad --- /dev/null +++ b/schemas/flatbuffer/CylinderPrimitive.fbs @@ -0,0 +1,27 @@ +// Generated by https://github.com/foxglove/schemas + +include "Color.fbs"; +include "Pose.fbs"; +include "Vector3.fbs"; + +namespace foxglove; + +/// A primitive representing a cylinder, elliptic cylinder, or truncated cone +table CylinderPrimitive { + /// Position of the center of the cylinder and orientation of the cylinder. The flat face(s) are perpendicular to the z-axis. + pose:foxglove.Pose; + + /// Size of the cylinder's bounding box + size:foxglove.Vector3; + + /// 0-1, ratio of the diameter of the cylinder's bottom face (min z) to the bottom of the bounding box + bottom_scale:double; + + /// 0-1, ratio of the diameter of the cylinder's top face (max z) to the top of the bounding box + top_scale:double; + + /// Color of the cylinder + color:foxglove.Color; +} + +root_type CylinderPrimitive; diff --git a/schemas/flatbuffer/Duration.fbs b/schemas/flatbuffer/Duration.fbs new file mode 100644 index 00000000..72c0a024 --- /dev/null +++ b/schemas/flatbuffer/Duration.fbs @@ -0,0 +1,10 @@ + +namespace foxglove; + +struct Duration { + /// Signed seconds of the span of time. Must be from -315,576,000,000 to +315,576,000,000 inclusive. + sec:int32; + /// if sec === 0 : -999,999,999 <= nsec <= +999,999,999 + /// otherwise sign of sec must match sign of nsec or be 0 and abs(nsec) <= 999,999,999 + nsec:int32; +} diff --git a/schemas/flatbuffer/FrameTransform.fbs b/schemas/flatbuffer/FrameTransform.fbs new file mode 100644 index 00000000..129a85a4 --- /dev/null +++ b/schemas/flatbuffer/FrameTransform.fbs @@ -0,0 +1,27 @@ +// Generated by https://github.com/foxglove/schemas + +include "Quaternion.fbs"; +include "Time.fbs"; +include "Vector3.fbs"; + +namespace foxglove; + +/// A transform between two reference frames in 3D space +table FrameTransform { + /// Timestamp of transform + timestamp:Time; + + /// Name of the parent frame + parent_frame_id:string; + + /// Name of the child frame + child_frame_id:string; + + /// Translation component of the transform + translation:foxglove.Vector3; + + /// Rotation component of the transform + rotation:foxglove.Quaternion; +} + +root_type FrameTransform; diff --git a/schemas/flatbuffer/GeoJSON.fbs b/schemas/flatbuffer/GeoJSON.fbs new file mode 100644 index 00000000..c571c483 --- /dev/null +++ b/schemas/flatbuffer/GeoJSON.fbs @@ -0,0 +1,11 @@ +// Generated by https://github.com/foxglove/schemas + +namespace foxglove; + +/// GeoJSON data for annotating maps +table GeoJSON { + /// GeoJSON data encoded as a UTF-8 string + geojson:string; +} + +root_type GeoJSON; diff --git a/schemas/flatbuffer/Grid.fbs b/schemas/flatbuffer/Grid.fbs new file mode 100644 index 00000000..62d128d6 --- /dev/null +++ b/schemas/flatbuffer/Grid.fbs @@ -0,0 +1,40 @@ +// Generated by https://github.com/foxglove/schemas + +include "PackedElementField.fbs"; +include "Pose.fbs"; +include "Time.fbs"; +include "Vector2.fbs"; + +namespace foxglove; + +/// A 2D grid of data +table Grid { + /// Timestamp of grid + timestamp:Time; + + /// Frame of reference + frame_id:string; + + /// Origin of grid's corner relative to frame of reference; grid is positioned in the x-y plane relative to this origin + pose:foxglove.Pose; + + /// Number of grid columns + column_count:uint32; + + /// Size of single grid cell along x and y axes, relative to `pose` + cell_size:foxglove.Vector2; + + /// Number of bytes between rows in `data` + row_stride:uint32; + + /// Number of bytes between cells within a row in `data` + cell_stride:uint32; + + /// Fields in `data` + fields:[foxglove.PackedElementField]; + + /// Grid cell data, interpreted using `fields`, in row-major (y-major) order + data:[uint8]; +} + +root_type Grid; diff --git a/schemas/flatbuffer/ImageAnnotations.fbs b/schemas/flatbuffer/ImageAnnotations.fbs new file mode 100644 index 00000000..8c91711d --- /dev/null +++ b/schemas/flatbuffer/ImageAnnotations.fbs @@ -0,0 +1,17 @@ +// Generated by https://github.com/foxglove/schemas + +include "CircleAnnotation.fbs"; +include "PointsAnnotation.fbs"; + +namespace foxglove; + +/// Array of annotations for a 2D image +table ImageAnnotations { + /// Circle annotations + circles:[foxglove.CircleAnnotation]; + + /// Points annotations + points:[foxglove.PointsAnnotation]; +} + +root_type ImageAnnotations; diff --git a/schemas/flatbuffer/KeyValuePair.fbs b/schemas/flatbuffer/KeyValuePair.fbs new file mode 100644 index 00000000..3c248301 --- /dev/null +++ b/schemas/flatbuffer/KeyValuePair.fbs @@ -0,0 +1,14 @@ +// Generated by https://github.com/foxglove/schemas + +namespace foxglove; + +/// A key with its associated value +table KeyValuePair { + /// Key + key:string; + + /// Value + value:string; +} + +root_type KeyValuePair; diff --git a/schemas/flatbuffer/LaserScan.fbs b/schemas/flatbuffer/LaserScan.fbs new file mode 100644 index 00000000..2a7e6513 --- /dev/null +++ b/schemas/flatbuffer/LaserScan.fbs @@ -0,0 +1,32 @@ +// Generated by https://github.com/foxglove/schemas + +include "Pose.fbs"; +include "Time.fbs"; + +namespace foxglove; + +/// A single scan from a planar laser range-finder +table LaserScan { + /// Timestamp of scan + timestamp:Time; + + /// Frame of reference + frame_id:string; + + /// Origin of scan relative to frame of reference; points are positioned in the x-y plane relative to this origin; angles are interpreted as counterclockwise rotations around the z axis with 0 rad being in the +x direction + pose:foxglove.Pose; + + /// Bearing of first point, in radians + start_angle:double; + + /// Bearing of last point, in radians + end_angle:double; + + /// Distance of detections from origin; assumed to be at equally-spaced angles between `start_angle` and `end_angle` + ranges:[double]; + + /// Intensity of detections + intensities:[double]; +} + +root_type LaserScan; diff --git a/schemas/flatbuffer/LinePrimitive.fbs b/schemas/flatbuffer/LinePrimitive.fbs new file mode 100644 index 00000000..a7ced772 --- /dev/null +++ b/schemas/flatbuffer/LinePrimitive.fbs @@ -0,0 +1,49 @@ +// Generated by https://github.com/foxglove/schemas + +include "Color.fbs"; +include "Point3.fbs"; +include "Pose.fbs"; + +namespace foxglove; + +/// An enumeration indicating how input points should be interpreted to create lines +enum LineType : ubyte { + /// 0-1, 1-2, ..., (n-1)-n + LINE_STRIP = 0, + + /// 0-1, 1-2, ..., (n-1)-n, n-0 + LINE_LOOP = 1, + + /// 0-1, 2-3, 4-5, ... + LINE_LIST = 2, +} +/// A primitive representing a series of points connected by lines +table LinePrimitive { + /// Drawing primitive to use for lines + type:LineType; + + /// Origin of lines relative to reference frame + pose:foxglove.Pose; + + /// Line thickness + thickness:double; + + /// Indicates whether `thickness` is a fixed size in screen pixels (true), or specified in world coordinates and scales with distance from the camera (false) + scale_invariant:bool; + + /// Points along the line + points:[foxglove.Point3]; + + /// Solid color to use for the whole line. One of `color` or `colors` must be provided. + color:foxglove.Color; + + /// Per-point colors (if specified, must have the same length as `points`). One of `color` or `colors` must be provided. + colors:[foxglove.Color]; + + /// Indices into the `points` and `colors` attribute arrays, which can be used to avoid duplicating attribute data. + /// + /// If omitted or empty, indexing will not be used. This default behavior is equivalent to specifying [0, 1, ..., N-1] for the indices (where N is the number of `points` provided). + indices:[uint32]; +} + +root_type LinePrimitive; diff --git a/schemas/flatbuffer/LocationFix.fbs b/schemas/flatbuffer/LocationFix.fbs new file mode 100644 index 00000000..68a6011a --- /dev/null +++ b/schemas/flatbuffer/LocationFix.fbs @@ -0,0 +1,34 @@ +// Generated by https://github.com/foxglove/schemas + +namespace foxglove; + +/// Type of position covariance +enum PositionCovarianceType : ubyte { + UNKNOWN = 0, + + APPROXIMATED = 1, + + DIAGONAL_KNOWN = 2, + + KNOWN = 3, +} +/// A navigation satellite fix for any Global Navigation Satellite System +table LocationFix { + /// Latitude in degrees + latitude:double; + + /// Longitude in degrees + longitude:double; + + /// Altitude in meters + altitude:double; + + /// Position covariance (m^2) defined relative to a tangential plane through the reported position. The components are East, North, and Up (ENU), in row-major order. + /// length 9 + position_covariance:[double]; + + /// If `position_covariance` is available, `position_covariance_type` must be set to indicate the type of covariance. + position_covariance_type:PositionCovarianceType; +} + +root_type LocationFix; diff --git a/schemas/flatbuffer/Log.fbs b/schemas/flatbuffer/Log.fbs new file mode 100644 index 00000000..d1f2f196 --- /dev/null +++ b/schemas/flatbuffer/Log.fbs @@ -0,0 +1,42 @@ +// Generated by https://github.com/foxglove/schemas + +include "Time.fbs"; + +namespace foxglove; + +/// Log level +enum LogLevel : ubyte { + UNKNOWN = 0, + + DEBUG = 1, + + INFO = 2, + + WARNING = 3, + + ERROR = 4, + + FATAL = 5, +} +/// A log message +table Log { + /// Timestamp of log message + timestamp:Time; + + /// Log level + level:LogLevel; + + /// Log message + message:string; + + /// Process or node name + name:string; + + /// Filename + file:string; + + /// Line number in the file + line:uint32; +} + +root_type Log; diff --git a/schemas/flatbuffer/ModelPrimitive.fbs b/schemas/flatbuffer/ModelPrimitive.fbs new file mode 100644 index 00000000..c6493f86 --- /dev/null +++ b/schemas/flatbuffer/ModelPrimitive.fbs @@ -0,0 +1,33 @@ +// Generated by https://github.com/foxglove/schemas + +include "Color.fbs"; +include "Pose.fbs"; +include "Vector3.fbs"; + +namespace foxglove; + +/// A primitive representing a 3D model file loaded from an external URL or embedded data +table ModelPrimitive { + /// Origin of model relative to reference frame + pose:foxglove.Pose; + + /// Scale factor to apply to the model along each axis + scale:foxglove.Vector3; + + /// Solid color to use for the whole model if `override_color` is true. + color:foxglove.Color; + + /// Whether to use the color specified in `color` instead of any materials embedded in the original model. + override_color:bool; + + /// URL pointing to model file. One of `url` or `data` should be provided. + url:string; + + /// [Media type](https://developer.mozilla.org/en-US/docs/Web/HTTP/Basics_of_HTTP/MIME_types) of embedded model (e.g. `model/gltf-binary`). Required if `data` is provided instead of `url`. Overrides the inferred media type if `url` is provided. + media_type:string; + + /// Embedded model. One of `url` or `data` should be provided. If `data` is provided, `media_type` must be set to indicate the type of the data. + data:[uint8]; +} + +root_type ModelPrimitive; diff --git a/schemas/flatbuffer/PackedElementField.fbs b/schemas/flatbuffer/PackedElementField.fbs new file mode 100644 index 00000000..a25f5a95 --- /dev/null +++ b/schemas/flatbuffer/PackedElementField.fbs @@ -0,0 +1,37 @@ +// Generated by https://github.com/foxglove/schemas + +namespace foxglove; + +/// Numeric type +enum NumericType : ubyte { + UNKNOWN = 0, + + UINT8 = 1, + + INT8 = 2, + + UINT16 = 3, + + INT16 = 4, + + UINT32 = 5, + + INT32 = 6, + + FLOAT32 = 7, + + FLOAT64 = 8, +} +/// A field present within each element in a byte array of packed elements. +table PackedElementField { + /// Name of the field + name:string; + + /// Byte offset from start of data buffer + offset:uint32; + + /// Type of data in the field. Integers are stored using little-endian byte order. + type:NumericType; +} + +root_type PackedElementField; diff --git a/schemas/flatbuffer/Point2.fbs b/schemas/flatbuffer/Point2.fbs new file mode 100644 index 00000000..17dd9802 --- /dev/null +++ b/schemas/flatbuffer/Point2.fbs @@ -0,0 +1,14 @@ +// Generated by https://github.com/foxglove/schemas + +namespace foxglove; + +/// A point representing a position in 2D space +table Point2 { + /// x coordinate position + x:double; + + /// y coordinate position + y:double; +} + +root_type Point2; diff --git a/schemas/flatbuffer/Point3.fbs b/schemas/flatbuffer/Point3.fbs new file mode 100644 index 00000000..c497bd1c --- /dev/null +++ b/schemas/flatbuffer/Point3.fbs @@ -0,0 +1,17 @@ +// Generated by https://github.com/foxglove/schemas + +namespace foxglove; + +/// A point representing a position in 3D space +table Point3 { + /// x coordinate position + x:double; + + /// y coordinate position + y:double; + + /// z coordinate position + z:double; +} + +root_type Point3; diff --git a/schemas/flatbuffer/PointCloud.fbs b/schemas/flatbuffer/PointCloud.fbs new file mode 100644 index 00000000..d153fd66 --- /dev/null +++ b/schemas/flatbuffer/PointCloud.fbs @@ -0,0 +1,30 @@ +// Generated by https://github.com/foxglove/schemas + +include "PackedElementField.fbs"; +include "Pose.fbs"; +include "Time.fbs"; + +namespace foxglove; + +/// A collection of N-dimensional points, which may contain additional fields with information like normals, intensity, etc. +table PointCloud { + /// Timestamp of point cloud + timestamp:Time; + + /// Frame of reference + frame_id:string; + + /// The origin of the point cloud relative to the frame of reference + pose:foxglove.Pose; + + /// Number of bytes between points in the `data` + point_stride:uint32; + + /// Fields in the `data` + fields:[foxglove.PackedElementField]; + + /// Point data, interpreted using `fields` + data:[uint8]; +} + +root_type PointCloud; diff --git a/schemas/flatbuffer/PointsAnnotation.fbs b/schemas/flatbuffer/PointsAnnotation.fbs new file mode 100644 index 00000000..883ddfe0 --- /dev/null +++ b/schemas/flatbuffer/PointsAnnotation.fbs @@ -0,0 +1,45 @@ +// Generated by https://github.com/foxglove/schemas + +include "Color.fbs"; +include "Point2.fbs"; +include "Time.fbs"; + +namespace foxglove; + +/// Type of points annotation +enum PointsAnnotationType : ubyte { + UNKNOWN = 0, + + POINTS = 1, + + LINE_LOOP = 2, + + LINE_STRIP = 3, + + LINE_LIST = 4, +} +/// An array of points on a 2D image +table PointsAnnotation { + /// Timestamp of annotation + timestamp:Time; + + /// Type of points annotation to draw + type:PointsAnnotationType; + + /// Points in 2D image coordinates + points:[foxglove.Point2]; + + /// Outline color + outline_color:foxglove.Color; + + /// Per-point colors, if `type` is `POINTS`, or per-segment stroke colors, if `type` is `LINE_LIST`. + outline_colors:[foxglove.Color]; + + /// Fill color + fill_color:foxglove.Color; + + /// Stroke thickness + thickness:double; +} + +root_type PointsAnnotation; diff --git a/schemas/flatbuffer/Pose.fbs b/schemas/flatbuffer/Pose.fbs new file mode 100644 index 00000000..688a80c2 --- /dev/null +++ b/schemas/flatbuffer/Pose.fbs @@ -0,0 +1,17 @@ +// Generated by https://github.com/foxglove/schemas + +include "Quaternion.fbs"; +include "Vector3.fbs"; + +namespace foxglove; + +/// A position and orientation for an object or reference frame in 3D space +table Pose { + /// Point denoting position in 3D space + position:foxglove.Vector3; + + /// Quaternion denoting orientation in 3D space + orientation:foxglove.Quaternion; +} + +root_type Pose; diff --git a/schemas/flatbuffer/PoseInFrame.fbs b/schemas/flatbuffer/PoseInFrame.fbs new file mode 100644 index 00000000..06425648 --- /dev/null +++ b/schemas/flatbuffer/PoseInFrame.fbs @@ -0,0 +1,20 @@ +// Generated by https://github.com/foxglove/schemas + +include "Pose.fbs"; +include "Time.fbs"; + +namespace foxglove; + +/// A timestamped pose for an object or reference frame in 3D space +table PoseInFrame { + /// Timestamp of pose + timestamp:Time; + + /// Frame of reference for pose position and orientation + frame_id:string; + + /// Pose in 3D space + pose:foxglove.Pose; +} + +root_type PoseInFrame; diff --git a/schemas/flatbuffer/PosesInFrame.fbs b/schemas/flatbuffer/PosesInFrame.fbs new file mode 100644 index 00000000..b98e64a0 --- /dev/null +++ b/schemas/flatbuffer/PosesInFrame.fbs @@ -0,0 +1,20 @@ +// Generated by https://github.com/foxglove/schemas + +include "Pose.fbs"; +include "Time.fbs"; + +namespace foxglove; + +/// An array of timestamped poses for an object or reference frame in 3D space +table PosesInFrame { + /// Timestamp of pose + timestamp:Time; + + /// Frame of reference for pose position and orientation + frame_id:string; + + /// Poses in 3D space + poses:[foxglove.Pose]; +} + +root_type PosesInFrame; diff --git a/schemas/flatbuffer/Quaternion.fbs b/schemas/flatbuffer/Quaternion.fbs new file mode 100644 index 00000000..409d24f6 --- /dev/null +++ b/schemas/flatbuffer/Quaternion.fbs @@ -0,0 +1,20 @@ +// Generated by https://github.com/foxglove/schemas + +namespace foxglove; + +/// A [quaternion](https://eater.net/quaternions) representing a rotation in 3D space +table Quaternion { + /// x value + x:double; + + /// y value + y:double; + + /// z value + z:double; + + /// w value + w:double = 1.0; +} + +root_type Quaternion; diff --git a/schemas/flatbuffer/RawImage.fbs b/schemas/flatbuffer/RawImage.fbs new file mode 100644 index 00000000..686cc260 --- /dev/null +++ b/schemas/flatbuffer/RawImage.fbs @@ -0,0 +1,33 @@ +// Generated by https://github.com/foxglove/schemas + +include "Time.fbs"; + +namespace foxglove; + +/// A raw image +table RawImage { + /// Timestamp of image + timestamp:Time; + + /// Frame of reference for the image. The origin of the frame is the optical center of the camera. +x points to the right in the image, +y points down, and +z points into the plane of the image. + frame_id:string; + + /// Image width + width:uint32; + + /// Image height + height:uint32; + + /// Encoding of the raw image data + /// + /// Supported values: `8UC1`, `8UC3`, `16UC1`, `32FC1`, `bayer_bggr8`, `bayer_gbrg8`, `bayer_grbg8`, `bayer_rggb8`, `bgr8`, `bgra8`, `mono8`, `mono16`, `rgb8`, `rgba8`, `yuv422` + encoding:string; + + /// Byte length of a single row + step:uint32; + + /// Raw image data + data:[uint8]; +} + +root_type RawImage; diff --git a/schemas/flatbuffer/SceneEntity.fbs b/schemas/flatbuffer/SceneEntity.fbs new file mode 100644 index 00000000..d2f1cfc9 --- /dev/null +++ b/schemas/flatbuffer/SceneEntity.fbs @@ -0,0 +1,62 @@ +// Generated by https://github.com/foxglove/schemas + +include "ArrowPrimitive.fbs"; +include "CubePrimitive.fbs"; +include "CylinderPrimitive.fbs"; +include "Duration.fbs"; +include "KeyValuePair.fbs"; +include "LinePrimitive.fbs"; +include "ModelPrimitive.fbs"; +include "SpherePrimitive.fbs"; +include "TextPrimitive.fbs"; +include "Time.fbs"; +include "TriangleListPrimitive.fbs"; + +namespace foxglove; + +/// A visual element in a 3D scene. An entity may be composed of multiple primitives which all share the same frame of reference. +table SceneEntity { + /// Timestamp of the entity + timestamp:Time; + + /// Frame of reference + frame_id:string; + + /// Identifier for the entity. A entity will replace any prior entity on the same topic with the same `id`. + id:string; + + /// Length of time (relative to `timestamp`) after which the entity should be automatically removed. Zero value indicates the entity should remain visible until it is replaced or deleted. + lifetime:Duration; + + /// Whether the entity should keep its location in the fixed frame (false) or follow the frame specified in `frame_id` as it moves relative to the fixed frame (true) + frame_locked:bool; + + /// Additional user-provided metadata associated with the entity. Keys must be unique. + metadata:[foxglove.KeyValuePair]; + + /// Arrow primitives + arrows:[foxglove.ArrowPrimitive]; + + /// Cube primitives + cubes:[foxglove.CubePrimitive]; + + /// Sphere primitives + spheres:[foxglove.SpherePrimitive]; + + /// Cylinder primitives + cylinders:[foxglove.CylinderPrimitive]; + + /// Line primitives + lines:[foxglove.LinePrimitive]; + + /// Triangle list primitives + triangles:[foxglove.TriangleListPrimitive]; + + /// Text primitives + texts:[foxglove.TextPrimitive]; + + /// Model primitives + models:[foxglove.ModelPrimitive]; +} + +root_type SceneEntity; diff --git a/schemas/flatbuffer/SceneEntityDeletion.fbs b/schemas/flatbuffer/SceneEntityDeletion.fbs new file mode 100644 index 00000000..8cec7165 --- /dev/null +++ b/schemas/flatbuffer/SceneEntityDeletion.fbs @@ -0,0 +1,27 @@ +// Generated by https://github.com/foxglove/schemas + +include "Time.fbs"; + +namespace foxglove; + +/// An enumeration indicating which entities should match a SceneEntityDeletion command +enum SceneEntityDeletionType : ubyte { + /// Delete the existing entity on the same topic that has the provided `id` + MATCHING_ID = 0, + + /// Delete all existing entities on the same topic + ALL = 1, +} +/// Command to remove previously published entities +table SceneEntityDeletion { + /// Timestamp of the deletion. Only matching entities earlier than this timestamp will be deleted. + timestamp:Time; + + /// Type of deletion action to perform + type:SceneEntityDeletionType; + + /// Identifier which must match if `type` is `MATCHING_ID`. + id:string; +} + +root_type SceneEntityDeletion; diff --git a/schemas/flatbuffer/SceneUpdate.fbs b/schemas/flatbuffer/SceneUpdate.fbs new file mode 100644 index 00000000..8d7dbe60 --- /dev/null +++ b/schemas/flatbuffer/SceneUpdate.fbs @@ -0,0 +1,17 @@ +// Generated by https://github.com/foxglove/schemas + +include "SceneEntity.fbs"; +include "SceneEntityDeletion.fbs"; + +namespace foxglove; + +/// An update to the entities displayed in a 3D scene +table SceneUpdate { + /// Scene entities to delete + deletions:[foxglove.SceneEntityDeletion]; + + /// Scene entities to add or replace + entities:[foxglove.SceneEntity]; +} + +root_type SceneUpdate; diff --git a/schemas/flatbuffer/SpherePrimitive.fbs b/schemas/flatbuffer/SpherePrimitive.fbs new file mode 100644 index 00000000..5f514995 --- /dev/null +++ b/schemas/flatbuffer/SpherePrimitive.fbs @@ -0,0 +1,21 @@ +// Generated by https://github.com/foxglove/schemas + +include "Color.fbs"; +include "Pose.fbs"; +include "Vector3.fbs"; + +namespace foxglove; + +/// A primitive representing a sphere or ellipsoid +table SpherePrimitive { + /// Position of the center of the sphere and orientation of the sphere + pose:foxglove.Pose; + + /// Size (diameter) of the sphere along each axis + size:foxglove.Vector3; + + /// Color of the sphere + color:foxglove.Color; +} + +root_type SpherePrimitive; diff --git a/schemas/flatbuffer/TextPrimitive.fbs b/schemas/flatbuffer/TextPrimitive.fbs new file mode 100644 index 00000000..742affcc --- /dev/null +++ b/schemas/flatbuffer/TextPrimitive.fbs @@ -0,0 +1,29 @@ +// Generated by https://github.com/foxglove/schemas + +include "Color.fbs"; +include "Pose.fbs"; + +namespace foxglove; + +/// A primitive representing a text label +table TextPrimitive { + /// Position of the center of the text box and orientation of the text. Identity orientation means the text is oriented in the xy-plane and flows from -x to +x. + pose:foxglove.Pose; + + /// Whether the text should respect `pose.orientation` (false) or always face the camera (true) + billboard:bool; + + /// Font size (height of one line of text) + font_size:double; + + /// Indicates whether `font_size` is a fixed size in screen pixels (true), or specified in world coordinates and scales with distance from the camera (false) + scale_invariant:bool; + + /// Color of the text + color:foxglove.Color; + + /// Text + text:string; +} + +root_type TextPrimitive; diff --git a/schemas/flatbuffer/Time.fbs b/schemas/flatbuffer/Time.fbs new file mode 100644 index 00000000..6bfc35e1 --- /dev/null +++ b/schemas/flatbuffer/Time.fbs @@ -0,0 +1,9 @@ + +namespace foxglove; + +struct Time { + /// Represents seconds of UTC time since Unix epoch 1970-01-01T00:00:00Z + sec:uint32; + /// Nano-second fractions from 0 to 999,999,999 inclusive + nsec:uint32; +} diff --git a/schemas/flatbuffer/TriangleListPrimitive.fbs b/schemas/flatbuffer/TriangleListPrimitive.fbs new file mode 100644 index 00000000..f0233ac6 --- /dev/null +++ b/schemas/flatbuffer/TriangleListPrimitive.fbs @@ -0,0 +1,29 @@ +// Generated by https://github.com/foxglove/schemas + +include "Color.fbs"; +include "Point3.fbs"; +include "Pose.fbs"; + +namespace foxglove; + +/// A primitive representing a set of triangles or a surface tiled by triangles +table TriangleListPrimitive { + /// Origin of triangles relative to reference frame + pose:foxglove.Pose; + + /// Vertices to use for triangles, interpreted as a list of triples (0-1-2, 3-4-5, ...) + points:[foxglove.Point3]; + + /// Solid color to use for the whole shape. One of `color` or `colors` must be provided. + color:foxglove.Color; + + /// Per-vertex colors (if specified, must have the same length as `points`). One of `color` or `colors` must be provided. + colors:[foxglove.Color]; + + /// Indices into the `points` and `colors` attribute arrays, which can be used to avoid duplicating attribute data. + /// + /// If omitted or empty, indexing will not be used. This default behavior is equivalent to specifying [0, 1, ..., N-1] for the indices (where N is the number of `points` provided). + indices:[uint32]; +} + +root_type TriangleListPrimitive; diff --git a/schemas/flatbuffer/Vector2.fbs b/schemas/flatbuffer/Vector2.fbs new file mode 100644 index 00000000..0c21dca1 --- /dev/null +++ b/schemas/flatbuffer/Vector2.fbs @@ -0,0 +1,14 @@ +// Generated by https://github.com/foxglove/schemas + +namespace foxglove; + +/// A vector in 2D space that represents a direction only +table Vector2 { + /// x coordinate length + x:double = 1.0; + + /// y coordinate length + y:double = 1.0; +} + +root_type Vector2; diff --git a/schemas/flatbuffer/Vector3.fbs b/schemas/flatbuffer/Vector3.fbs new file mode 100644 index 00000000..1555c31e --- /dev/null +++ b/schemas/flatbuffer/Vector3.fbs @@ -0,0 +1,17 @@ +// Generated by https://github.com/foxglove/schemas + +namespace foxglove; + +/// A vector in 3D space that represents a direction only +table Vector3 { + /// x coordinate length + x:double = 1.0; + + /// y coordinate length + y:double = 1.0; + + /// z coordinate length + z:double = 1.0; +} + +root_type Vector3; diff --git a/scripts/updateGeneratedFiles.ts b/scripts/updateGeneratedFiles.ts index 3e1d9f72..a905aa25 100644 --- a/scripts/updateGeneratedFiles.ts +++ b/scripts/updateGeneratedFiles.ts @@ -5,6 +5,12 @@ import rimraf from "rimraf"; import { promisify } from "util"; import { generateRosMsg, generateRosMsgDefinition } from "../internal"; +import { + BYTE_VECTOR_FB, + DURATION_FB, + generateFlatbuffers, + TIME_FB, +} from "../internal/generateFlatbufferSchema"; import { generateJsonSchema } from "../internal/generateJsonSchema"; import { generateMarkdown } from "../internal/generateMarkdown"; import { generateProto } from "../internal/generateProto"; @@ -63,7 +69,7 @@ async function main({ outDir, rosOutDir }: { outDir: string; rosOutDir: string } await fs.mkdir(path.join(outDir, "proto", "foxglove"), { recursive: true }); for (const schema of Object.values(foxgloveMessageSchemas)) { const enums = Object.values(foxgloveEnumSchemas).filter( - (enumSchema) => enumSchema.protobufParentMessageName === schema.name, + (enumSchema) => enumSchema.parentSchemaName === schema.name, ); await fs.writeFile( path.join(outDir, "proto", "foxglove", `${schema.name}.proto`), @@ -72,6 +78,24 @@ async function main({ outDir, rosOutDir }: { outDir: string; rosOutDir: string } } }); + await logProgress("Generating FlatBuffer definitions", async () => { + await fs.mkdir(path.join(outDir, "flatbuffer"), { recursive: true }); + await fs.writeFile(path.join(outDir, "flatbuffer", "ByteVector.fbs"), BYTE_VECTOR_FB); + await fs.writeFile(path.join(outDir, "flatbuffer", "Time.fbs"), TIME_FB); + await fs.writeFile(path.join(outDir, "flatbuffer", "Duration.fbs"), DURATION_FB); + + for (const schema of Object.values(foxgloveMessageSchemas)) { + // want enums with their corresponding parent tables for usage + const enums = Object.values(foxgloveEnumSchemas).filter( + (enumSchema) => enumSchema.parentSchemaName === schema.name, + ); + await fs.writeFile( + path.join(outDir, "flatbuffer", `${schema.name}.fbs`), + generateFlatbuffers(schema, enums), + ); + } + }); + await logProgress("Generating TypeScript definitions", async () => { await fs.mkdir(path.join(outDir, "typescript"), { recursive: true }); await fs.writeFile(path.join(outDir, "typescript", "Time.ts"), TIME_TS);