13 if constexpr (std::is_integral_v<T>)
14 out.emplace_back(
static_cast<std::int64_t
>(
value));
20eve::Value encodeStringMap(
const std::unordered_map<std::string, std::string>&
values) {
27 if (
mesh.empty() ||
mesh.positions().size() % 3u != 0
u ||
mesh.indices().size() % 3u != 0
u)
return false;
28 const std::size_t
vertices =
mesh.positions().size() / 3u;
29 if ((!
mesh.normals().empty() &&
mesh.normals().size() !=
mesh.positions().size()) ||
33 return std::all_of(
mesh.positions().begin(),
mesh.positions().end(),
34 [](
float value) { return std::isfinite(value); }) &&
35 std::all_of(
mesh.normals().begin(),
mesh.normals().end(),
36 [](
float value) { return std::isfinite(value); }) &&
37 std::all_of(
mesh.uvs().begin(),
mesh.uvs().end(), [](
float value) { return std::isfinite(value); }) &&
38 std::all_of(
mesh.colors().begin(),
mesh.colors().end(), [](
float value) { return std::isfinite(value); }) &&
39 std::all_of(
mesh.indices().begin(),
mesh.indices().end(),
40 [
vertices](std::uint32_t
index) { return index < vertices; });
44 result.emplace(
"positions", encodeNumbers(
mesh.positions()));
45 result.emplace(
"normals", encodeNumbers(
mesh.normals()));
46 result.emplace(
"uvs", encodeNumbers(
mesh.uvs()));
47 result.emplace(
"colors", encodeNumbers(
mesh.colors()));
48 result.emplace(
"indices", encodeNumbers(
mesh.indices()));
51 names.reserve(
mesh.groupNames().size());
52 for (
const auto&
name :
mesh.groupNames()) names.emplace_back(
name);
55 result.emplace(
"triangleGroups", encodeNumbers(
mesh.triangleGroups()));
57 result.emplace(
"metadata", encodeStringMap(
mesh.metadata()));
62 auto it =
object.find(
"colors");
70 if (!array || (!array->empty() && array->size() !=
vertices * 4u))
return fail();
71 colors.reserve(array->size());
72 for (
const auto& item : *array) {
74 if (
const auto*
number = item.getIf<
double>())
76 else if (
const auto* integer = item.getIf<std::int64_t>())
77 value =
static_cast<double>(*integer);
80 if (!std::isfinite(
value) || std::abs(
value) > std::numeric_limits<float>::max())
return fail();
ScriptMotionSinkStore< ScriptMotionSink< MotionColorTraits > > colors
std::set< std::string > values
std::array< double, 2 > vertices[3]
static Diagnostic error(DiagnosticCode code, std::string message, std::string path={})
Construct an error diagnostic with the standard error severity.
Move-only operation result carrying either a value or Status.
The canonical owning dynamic value used by data-facing protocols.
std::map< std::string, Value > Object
std::vector< Value > Array
CPU triangle mesh from procedural mesh recipes (e.g. marching cubes). Positions/normals are xyz-packe...
Result< std::vector< float > > decodeColors(const eve::Value::Object &object, std::size_t vertices)
eve::Value encodeMesh(const MeshBuild &mesh)
bool validMesh(const MeshBuild &mesh) noexcept