载入中...
搜索中...
未找到
ClothModel.cpp
浏览该文件的文档.
27bool hasExactFields(const eve::Value::Object& object, std::initializer_list<std::string_view> expected) {
72 candidate.particles_.push_back({positions[i * 3], positions[i * 3 + 1], positions[i * 3 + 2], inverseMass});
84 if (a == b || b == c || c == a) return invalidModel("cloth triangles must reference three distinct particles");
94 if (nx * nx + ny * ny + nz * nz <= 1e-12f) return invalidModel("cloth triangles must have non-zero rest area");
207eve::Result<ClothModel> ClothModel::grid(int cols, int rows, float spacing, float originX, float originY,
214 if (static_cast<size_t>(cols) > static_cast<size_t>(std::numeric_limits<int>::max()) / static_cast<size_t>(rows))
257 if (row + 1 < rows) addGridDistance(particle, particle + cols, ClothConstraintKind::Structural);
260 if (col > 0 && row + 1 < rows) addGridDistance(particle, particle + cols - 1, ClothConstraintKind::Shear);
293 {"cols", eve::Value(gridCols_)}, {"rows", eve::Value(gridRows_)}, {"spacing", eve::Value(gridSpacing_)}};
313 if (!root || !hasExactFields(*root, {"schema", "schemaVersion", "positions", "inverseMasses", "triangles", "grid"}))
324 eve::DiagnosticCode::ParseError, "cloth model schemaVersion must be an integer", "schemaVersion"));
327 eve::DiagnosticCode::UnknownVersion, "cloth model schema version is not supported", "schemaVersion"));
334 encodedMasses->size() != encodedPositions->size() / 3 || !encodedTriangles || encodedTriangles->empty() ||
337 eve::Diagnostic::error(eve::DiagnosticCode::ParseError, "cloth model arrays have invalid sizes", {}));
361 if (!encoded.isInt64() || encoded.asInt() < 0 || encoded.asInt() > std::numeric_limits<int>::max())
363 eve::DiagnosticCode::ParseError, "cloth triangle index must be a non-negative integer", "triangles"));
380 if (!colsValue || !colsValue->isInt64() || !rowsValue || !rowsValue->isInt64() || colsValue->asInt() < 2 ||
385 eve::Diagnostic::error(eve::DiagnosticCode::ParseError, "cloth grid metadata values are invalid", "grid"));
405 if (canonical.value().triangles()[i].vertices[vertex] != decoded.value().triangles()[i].vertices[vertex])
407 eve::DiagnosticCode::Conflict, "cloth grid metadata disagrees with triangle ordering", "grid"));
static Diagnostic error(DiagnosticCode code, std::string message, std::string path={}, DiagnosticDetails details={}, std::string source={})
Construct an error diagnostic with the standard error severity.
Definition Diagnostic.h:125
static Result failure(Status status)
Construct a failed result from a structured status.
Definition Result.h:175
Result< std::string > toJson() const
Serialize this value as deterministic compact JSON.
Definition Value.cpp:67
const std::string & asString() const
Return the string payload; the caller must have checked the kind.
Definition Value.cpp:87
static Result< Value > fromJson(std::string_view json)
Parse one strict JSON value into an owning Value.
Definition Value.cpp:57
std::int64_t asInt() const
Return the Int64 payload; the caller must have checked the kind.
Definition Value.cpp:69
const T * getIf() const noexcept
Return a typed pointer, or nullptr when the kind differs.
Definition Value.h:180
static eve::Result< ClothModel > fromValue(const eve::Value &value)
Decode strict eve.cloth-model/1 data; unknown fields are rejected.
Definition ClothModel.cpp:311
eve::Result< std::string > toJson() const
Serialize deterministic compact eve.cloth-model/1 JSON.
Definition ClothModel.cpp:303
static eve::Result< ClothModel > fromJson(std::string_view json)
Parse and decode strict UTF-8 eve.cloth-model/1 JSON.
Definition ClothModel.cpp:305
std::span< const ClothModelParticle > particles() const noexcept
Read-only particles, valid until this model is destroyed or assigned.
Definition ClothModel.h:119
eve::Value toValue() const
Encode canonical owning eve.cloth-model/1 data.
Definition ClothModel.cpp:271
static eve::Result< ClothModel > fromTriangles(std::span< const float > positions, std::span< const int > triangleIndices, std::span< const float > inverseMasses={})
Bake an arbitrary indexed triangle mesh into a cloth model.
Definition ClothModel.cpp:53
std::span< const ClothModelTriangle > triangles() const noexcept
Read-only triangles, valid until this model is destroyed or assigned.
Definition ClothModel.h:121
static eve::Result< ClothModel > grid(int cols, int rows, float spacing, float originX, float originY, float originZ)
Bake a regular XZ cloth grid with its top row pinned.
Definition ClothModel.cpp:207
ClothConstraintKind
Type of a precomputed distance constraint in a cloth model.
Definition ClothModel.h:17
@ Structural
const EditorValue * field(const EditorValue &value, const char *name)
Definition RoadNetworkEditTarget.cpp:15
@ InvalidArgument
@ UnknownVersion
@ ParseError
@ Conflict
Definition Container.h:602
Immutable rest-space particle stored by a ClothModel.
Definition ClothModel.h:24
Triangle indices into a ClothModel particle array.
Definition ClothModel.h:32