载入中...
搜索中...
未找到
DeformTopology.cpp
浏览该文件的文档.
2#include <bit>
3#include <cmath>
4#include <string>
5#include <utility>
7namespace eve::physics {
10 std::size_t vertexCount;
11 std::vector<std::uint32_t> indices;
12 std::vector<DeformUV> uv;
13 std::string key;
14};
15DeformTopology::DeformTopology(std::shared_ptr<const Data> data) : data_(std::move(data)) {}
17 std::vector<std::uint32_t> indices, std::vector<DeformUV> uv) {
18 auto failure = [] {
20 Diagnostic::error(DiagnosticCode::InvalidArgument, "invalid deformation topology", "deformTopology"));
21 };
23 const std::size_t arity = primitive == DeformPrimitive::Segments ? 2 : 3;
24 if (vertexCount == 0 || vertexCount > 1048576 || indices.empty() || indices.size() > 6291456 ||
25 indices.size() % arity != 0 || (!uv.empty() && uv.size() != vertexCount))
26 return failure();
27 for (std::size_t offset = 0; offset < indices.size(); offset += arity) {
28 for (std::size_t corner = 0; corner < arity; ++corner) {
29 if (indices[offset + corner] >= vertexCount) return failure();
30 for (std::size_t prior = 0; prior < corner; ++prior)
31 if (indices[offset + prior] == indices[offset + corner]) return failure();
32 }
33 }
34 for (auto& coordinate : uv) {
35 if (!std::isfinite(coordinate.u) || !std::isfinite(coordinate.v)) return failure();
36 if (coordinate.u == 0) coordinate.u = 0; // Normalize signed zero in canonical identity.
37 if (coordinate.v == 0) coordinate.v = 0;
38 }
39 std::string bytes = "EVEDEFT1";
40 bytes.reserve(24 + indices.size() * 4 + uv.size() * 8);
41 auto word = [&](std::uint32_t value) {
42 for (unsigned shift = 0; shift < 32; shift += 8) bytes.push_back(static_cast<char>((value >> shift) & 255));
43 };
44 word(static_cast<std::uint32_t>(arity));
45 word(static_cast<std::uint32_t>(vertexCount));
46 word(static_cast<std::uint32_t>(indices.size()));
47 word(static_cast<std::uint32_t>(uv.size()));
48 for (auto index : indices) word(index);
49 for (auto coordinate : uv) {
50 word(std::bit_cast<std::uint32_t>(coordinate.u));
51 word(std::bit_cast<std::uint32_t>(coordinate.v));
52 }
55 std::make_shared<const Data>(Data{primitive, vertexCount, std::move(indices), std::move(uv), std::move(key)})));
56}
57DeformPrimitive DeformTopology::primitive() const noexcept { return data_->primitive; }
58std::size_t DeformTopology::vertexCount() const noexcept { return data_->vertexCount; }
59std::span<const std::uint32_t> DeformTopology::indices() const noexcept { return data_->indices; }
60std::span<const DeformUV> DeformTopology::uv() const noexcept { return data_->uv; }
61std::string_view DeformTopology::key() const noexcept { return data_->key; }
62} // namespace eve::physics
size_t offset
std::uint64_t bytes
Object::Ptr value
uint32_t index
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.
Definition Result.h:176
static Result success(T value)
Construct a successful result owning value.
Definition Result.h:185
static Result failure(Status status)
Construct a failed result from a structured status.
Definition Result.h:196
Immutable connectivity and UV ownership for fixed-topology deformation playback. @ownership Copies sh...
static Result< DeformTopology > prepare(DeformPrimitive primitive, std::size_t vertexCount, std::vector< std::uint32_t > indices, std::vector< DeformUV > uv)
Validate bounded connectivity and freeze it with a deterministic content identity.
std::string_view key() const noexcept
Borrow the precomputed noncryptographic content key; no per-frame hashing or allocation.
std::span< const DeformUV > uv() const noexcept
Borrow immutable UVs; empty means no UV channel.
DeformPrimitive primitive() const noexcept
Primitive interpretation of the index stream.
std::size_t vertexCount() const noexcept
Number of stable vertex slots.
std::span< const std::uint32_t > indices() const noexcept
Borrow immutable ordered connectivity, bounded by this shared storage lifetime.
std::string word
Optional physics backend for vehicle mobility and body attach.
Definition Climbing.h:36
DeformPrimitive
Explicit primitive arity; connectivity retains order and triangle winding.
std::string bakedAssetContentKey(std::string_view source)
Stable noncryptographic 128-bit content digest, encoded as 32 lowercase hexadecimal bytes....
std::vector< std::uint32_t > indices