44
55namespace impeller.fb;
66
7+ //-----------------------------------------------------------------------------
8+ /// Materials.
9+ ///
10+
11+ struct Color {
12+ r: float;
13+ g: float;
14+ b: float;
15+ a: float;
16+ }
17+
18+ /// A compressed texture for Flutter to decode. The `bytes` field takes
19+ /// precedent over the `uri` field.
20+ table Texture {
21+ /// A Flutter asset URI for an image file to import and decode.
22+ uri: string;
23+ /// Compressed image bytes for Flutter to decode. If this field is not empty,
24+ /// it takes precedent over the `uri` field for sourcing the texture.
25+ bytes: [ubyte];
26+ }
27+
28+ enum MaterialType:byte {
29+ kUnlit,
30+ kPhysicallyBased,
31+ }
32+
33+ /// The final color of each material component is the texture color multiplied
34+ /// by the factor of the component.
35+ /// Texture fields are indices into the `Scene`->`textures` array. All textures
36+ /// are optional -- a texture index value of -1 indicates no texture.
37+ table Material {
38+ // When the `MaterialType` is `kUnlit`, only the `base_color` fields are used.
39+ type: MaterialType;
40+
41+ base_color_factor: Color;
42+ base_color_texture: int = -1;
43+
44+ metallic_factor: float = 0;
45+ roughness_factor: float = 0.5;
46+ metallic_roughness_texture: int = -1; // Red=Metallic, Green=Roughness.
47+
48+ normal_texture: int = -1; // Tangent space normal map.
49+
50+ occlusion_texture: int = -1;
51+ }
52+
53+ //-----------------------------------------------------------------------------
54+ /// Geometry.
55+ ///
56+
757struct Vec2 {
858 x: float;
959 y: float;
@@ -22,17 +72,6 @@ struct Vec4 {
2272 w: float;
2373}
2474
25- struct Color {
26- r: float;
27- g: float;
28- b: float;
29- a: float;
30- }
31-
32- struct Matrix {
33- m: [float:16];
34- }
35-
3675// This attribute layout is expected to be identical to that within
3776// `impeller/scene/shaders/geometry.vert`.
3877struct Vertex {
@@ -43,6 +82,27 @@ struct Vertex {
4382 color: Color;
4483}
4584
85+ table UnskinnedVertexBuffer {
86+ vertices: [Vertex];
87+ }
88+
89+ struct SkinnedVertex {
90+ vertex: Vertex;
91+ /// Four joint indices corresponding to this mesh's skin transforms. These
92+ /// are floats instead of ints because this vertex data is uploaded directly
93+ /// to the GPU, and float attributes work for all Impeller backends.
94+ joints: Vec4;
95+ /// Four weight values that specify the influence of the corresponding
96+ /// joints.
97+ weights: Vec4;
98+ }
99+
100+ table SkinnedVertexBuffer {
101+ vertices: [SkinnedVertex];
102+ }
103+
104+ union VertexBuffer { UnskinnedVertexBuffer, SkinnedVertexBuffer }
105+
46106enum IndexType:byte {
47107 k16Bit,
48108 k32Bit,
@@ -54,31 +114,69 @@ table Indices {
54114 type: IndexType;
55115}
56116
57- table Texture {
58- // TODO(bdero): Allow optional image data embedding.
59- uri: string;
117+ table MeshPrimitive {
118+ vertices: VertexBuffer;
119+ indices: Indices;
120+ material: Material;
60121}
61122
62- table Material {
63- base_color_factor: Color;
64- base_color_texture: Texture;
65- // TODO(bdero): PBR textures.
123+ //-----------------------------------------------------------------------------
124+ /// Animations.
125+ ///
126+
127+ table TranslationKeyframes {
128+ values: [Vec3];
66129}
67130
68- table MeshPrimitive {
69- vertices: [Vertex];
70- indices: Indices;
71- material: Material;
131+ table RotationKeyframes {
132+ values: [Vec4];
133+ }
134+
135+ table ScaleKeyframes {
136+ values: [Vec3];
137+ }
138+
139+ union Keyframes { TranslationKeyframes, RotationKeyframes, ScaleKeyframes }
140+
141+ table Channel {
142+ node: int; // Index into `Scene`->`nodes`.
143+ timeline: [float];
144+ keyframes: Keyframes;
145+ }
146+
147+ table Animation {
148+ name: string;
149+ channels: [Channel];
150+ }
151+
152+ table Skin {
153+ joints: [int]; // Index into `Scene`->`nodes`.
154+ inverse_bind_matrices: [Matrix];
155+ /// The root joint of the skeleton.
156+ skeleton: int; // Index into `Scene`->`nodes`.
157+ }
158+
159+ //-----------------------------------------------------------------------------
160+ /// Scene graph.
161+ ///
162+
163+ struct Matrix {
164+ m: [float:16];
72165}
73166
74167table Node {
75- children: [Node];
168+ name: string;
169+ children: [int]; // Index into `Scene`->`nodes`.
76170 transform: Matrix;
77171 mesh_primitives: [MeshPrimitive];
172+ skin: Skin;
78173}
79174
80175table Scene {
81- children: [Node];
176+ children: [int]; // Index into `Scene`->`nodes`.
177+ nodes: [Node];
178+ textures: [Texture]; // Textures may be reused across different materials.
179+ animations: [Animation];
82180}
83181
84182root_type Scene;
0 commit comments