13#include "flutter/fml/logging.h"
15#include "impeller/scene/importer/scene_flatbuffers.h"
26 return std::make_unique<UnskinnedVerticesBuilder>();
30 return std::make_unique<SkinnedVerticesBuilder>();
40template <
typename SourceType>
45 constexpr SourceType divisor = std::is_integral_v<SourceType>
64 *(destination + component_i) =
76 for (
int i = 0;
i < 4;
i++) {
81std::map<VerticesBuilder::AttributeType, VerticesBuilder::AttributeProperties>
82 VerticesBuilder::kAttributeTypes = {
103 .component_count = 2,
108 .component_count = 4,
113 .component_count = 4,
118 .component_count = 4,
122 VerticesBuilder::ComponentProperties>
125 {.size_bytes =
sizeof(int8_t), .convert_proc = ToScalar<int8_t>}},
127 {.size_bytes =
sizeof(int8_t), .convert_proc = ToScalar<uint8_t>}},
129 {.size_bytes =
sizeof(int16_t), .convert_proc = ToScalar<int16_t>}},
131 {.size_bytes =
sizeof(int16_t), .convert_proc = ToScalar<uint16_t>}},
133 {.size_bytes =
sizeof(int32_t), .convert_proc = ToScalar<int32_t>}},
135 {.size_bytes =
sizeof(int32_t), .convert_proc = ToScalar<uint32_t>}},
137 {.size_bytes =
sizeof(
float), .convert_proc = ToScalar<float>}},
141 size_t destination_stride_bytes,
145 size_t attribute_stride_bytes,
146 size_t attribute_count) {
149 for (
size_t i = 0;
i < attribute_count;
i++) {
151 reinterpret_cast<const uint8_t*
>(
source) + attribute_stride_bytes *
i;
152 uint8_t*
dst =
reinterpret_cast<uint8_t*
>(destination) +
156 component_props, attribute_props);
169 fb::MeshPrimitiveT& primitive)
const {
170 auto vertex_buffer = fb::UnskinnedVertexBufferT();
171 vertex_buffer.vertices.resize(0);
172 for (
auto& v : vertices_) {
177 primitive.vertices.Set(std::move(vertex_buffer));
183 const void* buffer_start,
184 size_t attribute_stride_bytes,
185 size_t attribute_count) {
186 if (attribute_count > vertices_.size()) {
187 vertices_.resize(attribute_count,
Vertex());
194 attribute_stride_bytes,
207 fb::MeshPrimitiveT& primitive)
const {
208 auto vertex_buffer = fb::SkinnedVertexBufferT();
209 vertex_buffer.vertices.resize(0);
210 for (
auto& v : vertices_) {
215 vertex_buffer.vertices.push_back(fb::SkinnedVertex(
218 primitive.vertices.Set(std::move(vertex_buffer));
224 const void* buffer_start,
225 size_t attribute_stride_bytes,
226 size_t attribute_count) {
227 if (attribute_count > vertices_.size()) {
228 vertices_.resize(attribute_count,
Vertex());
235 attribute_stride_bytes,
GrTriangulator::Vertex Vertex
virtual ~SkinnedVerticesBuilder() override
void WriteFBVertices(fb::MeshPrimitiveT &primitive) const override
void SetAttributeFromBuffer(AttributeType attribute, ComponentType component_type, const void *buffer_start, size_t attribute_stride_bytes, size_t attribute_count) override
void SetAttributeFromBuffer(AttributeType attribute, ComponentType component_type, const void *buffer_start, size_t attribute_stride_bytes, size_t attribute_count) override
virtual ~UnskinnedVerticesBuilder() override
UnskinnedVerticesBuilder()
void WriteFBVertices(fb::MeshPrimitiveT &primitive) const override
virtual ~VerticesBuilder()
static std::unique_ptr< VerticesBuilder > MakeUnskinned()
static std::unique_ptr< VerticesBuilder > MakeSkinned()
static void WriteAttribute(void *destination, size_t destination_stride_bytes, AttributeType attribute, ComponentType component_type, const void *source, size_t attribute_stride_bytes, size_t attribute_count)
#define FML_DCHECK(condition)
static float max(float r, float g, float b)
fb::Vec3 ToFBVec3(const Vector3 v)
fb::Vec4 ToFBVec4(const Vector4 v)
static Scalar ToScalar(const void *source, size_t index, bool normalized)
Reads a numeric component from source and returns a 32bit float. If normalized is true,...
fb::Vec2 ToFBVec2(const Vector2 v)
fb::Color ToFBColor(const Color c)
static std::map< VerticesBuilder::ComponentType, VerticesBuilder::ComponentProperties > kComponentTypes
static void PassthroughAttributeWriter(Scalar *destination, const void *source, const VerticesBuilder::ComponentProperties &component, const VerticesBuilder::AttributeProperties &attribute)
A ComponentWriter which simply converts all of an attribute's components to normalized scalar form.
static void JointsAttributeWriter(Scalar *destination, const void *source, const VerticesBuilder::ComponentProperties &component, const VerticesBuilder::AttributeProperties &attribute)
A ComponentWriter which converts four vertex indices to scalars.
SI auto map(std::index_sequence< I... >, Fn &&fn, const Args &... args) -> skvx::Vec< sizeof...(I), decltype(fn(args[0]...))>
AttributeWriter write_proc
ComponentConverter convert_proc