载入中...
搜索中...
未找到
VoronoiCook.cpp
浏览该文件的文档.
21Vec cross(Vec a, Vec b) { return {a.y * b.z - a.z * b.y, a.z * b.x - a.x * b.z, a.x * b.y - a.y * b.x}; }
28Diagnostic bad(const char* message) { return Diagnostic::error(DiagnosticCode::InvalidArgument, message, "voronoi"); }
41 f.positions.insert(f.positions.end(), {static_cast<float>(p.x), static_cast<float>(p.y), static_cast<float>(p.z)});
58 while (hull.size() >= 2 && turn(hull[hull.size() - 2], hull.back(), p) <= eps * eps) hull.pop_back();
64 while (hull.size() > lower && turn(hull[hull.size() - 2], hull.back(), p) <= eps * eps) hull.pop_back();
141Result<FractureFragment> sourceMesh(const eve::asset::CanonicalMeshData& mesh, Vec& origin, Vec& lo, Vec& hi,
145 return Result<FractureFragment>::failure(bad("source mesh exceeds convex cook budget or is incomplete"));
159 if (!(eps > 0) || eps > 1000) return Result<FractureFragment>::failure(bad("unsupported source scale"));
162 if (i >= mesh.positions.size() / 3) return Result<FractureFragment>::failure(bad("invalid triangle index"));
169 volume += dot(point(f, f.indices[t]), cross(point(f, f.indices[t + 1]), point(f, f.indices[t + 2]))) / 6;
171 for (std::size_t t = 0; t < f.indices.size(); t += 3) std::swap(f.indices[t + 1], f.indices[t + 2]);
180 m.positions = {-x, -y, -z, x, -y, -z, x, y, -z, -x, y, -z, -x, -y, z, x, -y, z, x, y, z, -x, y, z};
186Result<FracturedCollection> cookVoronoi(const eve::asset::CanonicalMeshData& mesh, const FractureRecipe& recipe) {
189 if ((recipe.mode != FractureMode::UniformVoronoi && recipe.mode != FractureMode::ClusteredVoronoi) ||
203 static_cast<int>(rng.next() % static_cast<std::uint64_t>(recipe.siteCountMax - recipe.siteCountMin + 1));
228 if (!found) return Result<FracturedCollection>::failure(bad("cannot place cluster center inside source"));
238 p = c + Vec{(rng.unit() * 2 - 1) * recipe.clusterRadius, (rng.unit() * 2 - 1) * recipe.clusterRadius,
255 return Result<FracturedCollection>::failure(bad("cannot place distinct Voronoi sites inside source"));
266 const double d = dot(n, (sites[static_cast<std::size_t>(i)] + sites[static_cast<std::size_t>(j)]) * .5);
268 if (cell.empty()) return Result<FracturedCollection>::failure(bad("Voronoi produced empty cell"));
291 const auto ia = vertex(fragment, a, eps), ib = vertex(fragment, b, eps), ic = vertex(fragment, c, eps);
297 if (face.neighbor >= 0 && i < face.neighbor && area > eps * eps * 10) contacts[{i, face.neighbor}] = area;
334Result<FracturedCollection> cookVoronoiAssembly(const GeometryCollectionAsset& assembly, const FractureRecipe& recipe) {
348 if (auto g = settings.groups.find(assembly.bones[i].clusterId); g != settings.groups.end()) policy = g->second;
349 if (auto c = settings.components.find(static_cast<int>(i)); c != settings.components.end()) policy = c->second;
376 auto cooked = cookVoronoi(box(original.halfExtentX, original.halfExtentY, original.halfExtentZ), r);
393 for (auto& mesh : part.geometry.fragments) result.geometry.fragments.push_back(std::move(mesh));
static Diagnostic error(DiagnosticCode code, std::string message, std::string path={})
Construct an error diagnostic with the standard error severity.
Definition Diagnostic.cpp:21
static Result failure(Status status)
Construct a failed result from a structured status.
Definition Result.h:196
constexpr HexDirection next(HexDirection d) noexcept
The next direction clockwise (NW wraps to NE).
Definition HexMetrics.h:76
Result< FracturedCollection > cookVoronoi(const eve::asset::CanonicalMeshData &mesh, const FractureRecipe &recipe)
Intersect a closed convex source mesh with seeded Voronoi half-spaces.
Definition VoronoiCook.cpp:186
Result< FracturedCollection > cookVoronoiAssembly(const GeometryCollectionAsset &assembly, const FractureRecipe &recipe)
Prefracture each box in an authored assembly and preserve declared parent supports....
Definition VoronoiCook.cpp:334
@ UniformVoronoi
@ ClusteredVoronoi
@ Group
@ InvalidArgument
Owning CPU mesh snapshot; UV arrays are packed ST pairs indexed by source set number....
Definition CanonicalMesh.h:18
Owning closed convex fragment in body-local metres; outward triangle winding. Each triangle has mater...
Definition FractureGeometry.h:11
std::vector< std::uint32_t > indices
Definition FractureGeometry.h:13
std::vector< std::uint32_t > materials
Definition FractureGeometry.h:14
std::vector< float > positions
Definition FractureGeometry.h:12
Versioned cook recipe for Chaos-style pre-fracture (schema v1).
Definition FractureRecipe.h:29
Immutable cooked/authored geometry-collection asset.
Definition GeometryCollectionAsset.h:48
std::vector< GeometryCollectionEdge > edges
Definition GeometryCollectionAsset.h:54
std::vector< GeometryCollectionBone > bones
Definition GeometryCollectionAsset.h:53
eve::Result< void > validate() const
Validate bone/edge topology and numeric ranges.
Definition GeometryCollectionAsset.cpp:181
One pre-authored leaf bone (box collision proxy) inside a geometry collection.
Definition GeometryCollectionAsset.h:16
Offline assembly settings; per-component policy overrides its authored cluster policy....
Definition AssemblyFractureSettings.h:18
FractureRecipe recipe
Definition AssemblyFractureSettings.h:19
Independent controls for mesh granularity, internal cohesion and parent-joint strength.
Definition AssemblyFractureSettings.h:8
Complete owning fracture asset: graph, body origins and exact convex geometry.
Definition VoronoiCook.h:16