11 "invalid closed convex fracture mesh or budget",
"geometry"));
14 std::size_t total = 0;
16 const auto count =
f.positions.size() / 3;
17 if (
f.positions.size() % 3 || count < 4 || count > 254 ||
f.indices.empty() ||
f.indices.size() % 3 ||
18 f.indices.size() > 8192 ||
f.materials.size() !=
f.indices.size() / 3)
20 total +=
f.positions.size() +
f.indices.size() +
f.materials.size();
21 if (total > 4000000)
return fail();
23 for (
float v :
f.positions) {
24 if (!std::isfinite(
v))
return fail();
25 scale = std::max(
scale, std::abs(
static_cast<double>(
v)));
27 const double epsilon = std::max(1e-9,
scale * 1e-6);
28 auto point = [&](std::uint32_t i) {
29 return std::array<double, 3>{
f.positions[3 * i],
f.positions[3 * i + 1],
f.positions[3 * i + 2]};
31 std::map<std::pair<std::uint32_t, std::uint32_t>, std::pair<int, int>>
edges;
33 for (std::size_t
t = 0;
t <
f.indices.size();
t += 3) {
34 const auto ia =
f.indices[
t], ib =
f.indices[
t + 1], ic =
f.indices[
t + 2];
35 if (ia >=
count || ib >=
count || ic >=
count || ia == ib || ib == ic || ia == ic ||
f.materials[
t / 3] > 1)
38 const std::array<double, 3>
ab{
b[0] -
a[0],
b[1] -
a[1],
b[2] -
a[2]},
39 ac{
c[0] -
a[0],
c[1] -
a[1],
c[2] -
a[2]};
40 const std::array<double, 3>
n{
ab[1] *
ac[2] -
ab[2] *
ac[1],
ab[2] *
ac[0] -
ab[0] *
ac[2],
42 const double length = std::sqrt(
n[0] *
n[0] +
n[1] *
n[1] +
n[2] *
n[2]);
43 if (
length < epsilon * epsilon)
46 for (std::uint32_t i = 0; i <
count; ++i) {
48 if (
n[0] * (
q[0] -
a[0]) +
n[1] * (
q[1] -
a[1]) +
n[2] * (
q[2] -
a[2]) > epsilon *
length * 4)
52 volume += (
a[0] * (
b[1] *
c[2] -
b[2] *
c[1]) +
a[1] * (
b[2] *
c[0] -
b[0] *
c[2]) +
53 a[2] * (
b[0] *
c[1] -
b[1] *
c[0])) /
55 const std::uint32_t
ids[] = {ia, ib, ic, ia};
56 for (
int k = 0; k < 3; ++k) {
57 const auto x =
ids[k],
y =
ids[k + 1];
60 edge.second +=
x <
y ? 1 : -1;
63 if (!std::isfinite(
volume) ||
volume <= epsilon * epsilon * epsilon)
return fail();
69 "fracture mesh has open or inconsistently oriented edges",
"geometry"));
std::array< double, 10 > q
std::array< float, 3 > scale
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.
static Result success(T value)
Construct a successful result owning value.
static Result failure(Status status)
Construct a failed result from a structured status.
Optional physics backend for vehicle mobility and body attach.
Result< void > validate() const
Validate budgets, closed outward convex meshes, indices, finite coordinates and tags....
std::vector< FractureFragment > fragments