refactor(physics): rename isSensor to isTrigger (Unity/UE terminology)

UE calls it Trigger (Overlap Events / Trigger preset) and Unity's UI
says "Is Trigger"; "sensor" is the physics-backend term (Jolt sensor,
Box2D sensor). Rename the component/record flag and the Inspector
label. Scene files now persist "IsTrigger" with backward-compatible
read of the old "IsSensor" key.
This commit is contained in:
2026-10-03 18:53:38 +08:00
parent b6d0868e15
commit 29c413579d
5 changed files with 12 additions and 9 deletions
+3 -2
View File
@@ -232,8 +232,9 @@ namespace Engine::ECS {
f32 friction = 0.5f;
f32 restitution = 0.2f;
// 传感器(Unity isTrigger 语义):只产生 Added/Removed 事件,无碰撞解算
bool isSensor = false;
// 触发器(Unity isTrigger / UE Overlap Events 语义):只产生
// Added/Removed 事件,无碰撞解算;底层 Jolt sensor
bool isTrigger = false;
// 运行时(PhysicsWorld 维护,勿手改)
u32 bodyId = 0; // JPH::BodyID 裸位
+1 -1
View File
@@ -110,7 +110,7 @@ namespace Engine {
f32 halfHeight = 0.0f; // Capsule/Cylinder 圆柱段半高
std::vector<ECS::RigidBodyComponent::CompoundChild> compound; // 子形状快照
f32 mass = 0.0f;
bool isSensor = false; // 传感器标记(变更 → 重建 body)
bool isTrigger = false; // 触发器标记(变更 → 重建 body)
glm::vec3 lastPos{0.0f}; // 静态/运动体编辑器拖动检测
glm::quat lastRot{1.0f, 0.0f, 0.0f, 0.0f}; // 同上(quat 直比,无欧拉往返)
// 加速度箭头用:上一步速度(定步长差分)与平滑后的加速度
+3 -3
View File
@@ -390,7 +390,7 @@ namespace Engine {
rec.halfHeight != halfHeight ||
rec.compound != rb.compound ||
rec.mass != rb.mass ||
rec.isSensor != rb.isSensor) {
rec.isTrigger != rb.isTrigger) {
// 类型/碰撞体/质量变更 → 重建(简单正确,重置速度可接受)
bi.RemoveBody(rec.id);
bi.DestroyBody(rec.id);
@@ -860,7 +860,7 @@ namespace Engine {
settings.mFriction = rb.friction;
settings.mRestitution = rb.restitution;
settings.mUserData = entityBits; // 事件回调:Body → 实体位模式反查
settings.mIsSensor = rb.isSensor; // 传感器:只收 Added/Removed,不解算
settings.mIsSensor = rb.isTrigger; // 触发器:只收 Added/Removed,不解算
const JPH::BodyID id = bi.CreateAndAddBody(
settings, dynamic ? JPH::EActivation::Activate : JPH::EActivation::DontActivate);
@@ -873,7 +873,7 @@ namespace Engine {
ExtractShapeParams(rb, rec.radius, rec.halfHeight);
rec.compound = rb.compound;
rec.mass = rb.mass;
rec.isSensor = rb.isSensor;
rec.isTrigger = rb.isTrigger;
rec.lastPos = tr.GetPosition();
rec.lastRot = tr.GetRotationQuat();
m_Bodies[entityBits] = rec;
+4 -2
View File
@@ -306,7 +306,7 @@ namespace Engine::Serialization {
out << YAML::Key << "Friction" << YAML::Value << rb->friction;
out << YAML::Key << "Restitution" << YAML::Value
<< rb->restitution;
out << YAML::Key << "IsSensor" << YAML::Value << rb->isSensor;
out << YAML::Key << "IsTrigger" << YAML::Value << rb->isTrigger;
// bodyId/bodyValid/velocity 由 PhysicsWorld 对账重建,不存
out << YAML::Key << "Active" << YAML::Value << rb->active;
out << YAML::EndMap;
@@ -616,7 +616,9 @@ namespace Engine::Serialization {
rb.gravityScale = n["GravityScale"].as<f32>(rb.gravityScale);
rb.friction = n["Friction"].as<f32>(rb.friction);
rb.restitution = n["Restitution"].as<f32>(rb.restitution);
rb.isSensor = n["IsSensor"].as<bool>(rb.isSensor);
// 新键 IsTrigger;旧场景 IsSensor 兼容读(缺键 as 返回 fallback 安全)
rb.isTrigger = n["IsTrigger"].as<bool>(
n["IsSensor"].as<bool>(rb.isTrigger));
rb.active = n["Active"].as<bool>(true);
// bodyId/bodyValid/velocity 保持默认(对账重建)
}