资产系统侧线第一波:ResolveProcedural 提为公共静态(键格式唯一定义点);Inspector 程序化模型入口;修 Prefab hover 误导性 not loaded;Content Browser 模型拖拽 → Outliner 创建实体
This commit is contained in:
@@ -49,6 +49,30 @@ namespace {
|
||||
*ctx.scene, *ctx.assets, path);
|
||||
}
|
||||
|
||||
// 模型拖入落点:创建带 MeshRenderer 的单实体(名字 = 文件名
|
||||
// stem,默认位姿;模型句柄 = LoadModel 磁盘路径)。拖到节点下 =
|
||||
// SetParent keepWorld;空白区 = 场景根。加载失败不建空实体
|
||||
entt::entity SpawnModelDrop(const EditorContext& ctx, const char* path)
|
||||
{
|
||||
if (!ctx.scene || !ctx.assets || !path) {
|
||||
return entt::null;
|
||||
}
|
||||
const auto model = ctx.assets->LoadModel(path);
|
||||
if (!model.Valid()) {
|
||||
return entt::null;
|
||||
}
|
||||
std::string name =
|
||||
std::filesystem::path(path).stem().string();
|
||||
if (name.empty()) {
|
||||
name = "model entity";
|
||||
}
|
||||
auto e = ctx.scene->CreateEntity(name);
|
||||
e.AddComponent<Engine::ECS::MeshRendererComponent>().model = model;
|
||||
ENGINE_INFO("Hierarchy: model entity '{}' created from '{}'",
|
||||
name, path);
|
||||
return static_cast<entt::entity>(e);
|
||||
}
|
||||
|
||||
// 实体名 → 合法文件名(路径分隔符/保留符净化;空名兜底)
|
||||
std::string PrefabFileName(std::string name)
|
||||
{
|
||||
@@ -136,6 +160,15 @@ namespace {
|
||||
selected = root;
|
||||
}
|
||||
}
|
||||
if (const ImGuiPayload* pl =
|
||||
ImGui::AcceptDragDropPayload(kModelDragPayload)) {
|
||||
if (const entt::entity me = SpawnModelDrop(
|
||||
ctx, static_cast<const char*>(pl->Data));
|
||||
me != entt::null) {
|
||||
ctx.scene->SetParent(me, e); // keepWorld 默认 true
|
||||
selected = me;
|
||||
}
|
||||
}
|
||||
ImGui::EndDragDropTarget();
|
||||
}
|
||||
|
||||
@@ -273,6 +306,14 @@ void HierarchyPanel::Draw(const EditorContext& ctx, entt::entity& selected)
|
||||
selected = root;
|
||||
}
|
||||
}
|
||||
if (const ImGuiPayload* pl =
|
||||
ImGui::AcceptDragDropPayload(kModelDragPayload)) {
|
||||
if (const entt::entity me = SpawnModelDrop(
|
||||
ctx, static_cast<const char*>(pl->Data));
|
||||
me != entt::null) {
|
||||
selected = me;
|
||||
}
|
||||
}
|
||||
ImGui::EndDragDropTarget();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user