test(render): cover scene render sync camera light and matrix snapshot
This commit is contained in:
parent
04cff527e3
commit
5f0690580b
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -1,4 +1,4 @@
|
|||||||
#include "MetaCoreEditor/MetaCoreBuiltinModules.h"
|
#include "MetaCoreEditor/MetaCoreBuiltinModules.h"
|
||||||
#include "MetaCoreEditor/MetaCoreEditorAssetTypes.h"
|
#include "MetaCoreEditor/MetaCoreEditorAssetTypes.h"
|
||||||
#include "MetaCoreEditor/MetaCoreEditorContext.h"
|
#include "MetaCoreEditor/MetaCoreEditorContext.h"
|
||||||
#include "MetaCoreEditor/MetaCoreEditorModule.h"
|
#include "MetaCoreEditor/MetaCoreEditorModule.h"
|
||||||
@ -10,6 +10,8 @@
|
|||||||
#include "MetaCoreRender/MetaCoreEditorViewportRenderer.h"
|
#include "MetaCoreRender/MetaCoreEditorViewportRenderer.h"
|
||||||
#include "MetaCoreRender/MetaCoreRenderDevice.h"
|
#include "MetaCoreRender/MetaCoreRenderDevice.h"
|
||||||
#include "MetaCoreRender/MetaCoreSceneRenderSync.h"
|
#include "MetaCoreRender/MetaCoreSceneRenderSync.h"
|
||||||
|
#include "MetaCoreRender/MetaCoreFilamentSceneBridge.h"
|
||||||
|
#include <glm/gtc/matrix_transform.hpp>
|
||||||
#include "MetaCoreRuntimeData/MetaCoreRuntimeDataDispatcher.h"
|
#include "MetaCoreRuntimeData/MetaCoreRuntimeDataDispatcher.h"
|
||||||
#include "MetaCoreRuntimeData/MetaCoreRuntimeDataSource.h"
|
#include "MetaCoreRuntimeData/MetaCoreRuntimeDataSource.h"
|
||||||
#include "MetaCoreRuntimeData/MetaCoreRuntimeDataProject.h"
|
#include "MetaCoreRuntimeData/MetaCoreRuntimeDataProject.h"
|
||||||
@ -2422,6 +2424,106 @@ void MetaCoreTestUiDocumentSerialization() {
|
|||||||
MetaCoreExpectVec3Near(roundTrip.Nodes[0].Style.BackgroundColor, glm::vec3(0.05F, 0.08F, 0.12F), "Ui 背景色应保持");
|
MetaCoreExpectVec3Near(roundTrip.Nodes[0].Style.BackgroundColor, glm::vec3(0.05F, 0.08F, 0.12F), "Ui 背景色应保持");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void MetaCoreTestDecoupledSnapshotSync() {
|
||||||
|
// 1. 创建默认场景并收集核心对象 ID
|
||||||
|
MetaCore::MetaCoreScene scene = MetaCore::MetaCoreCreateDefaultScene();
|
||||||
|
MetaCore::MetaCoreId cubeId = 0;
|
||||||
|
MetaCore::MetaCoreId lightId = 0;
|
||||||
|
MetaCore::MetaCoreId cameraId = 0;
|
||||||
|
for (const MetaCore::MetaCoreGameObject& object : scene.GetGameObjects()) {
|
||||||
|
if (object.GetName() == "box1.glb") {
|
||||||
|
cubeId = object.GetId();
|
||||||
|
}
|
||||||
|
if (object.GetName() == "Directional Light") {
|
||||||
|
lightId = object.GetId();
|
||||||
|
}
|
||||||
|
if (object.GetName() == "Main Camera") {
|
||||||
|
cameraId = object.GetId();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
MetaCoreExpect(cubeId != 0, "默认场景应包含网格渲染器 Cube");
|
||||||
|
MetaCoreExpect(lightId != 0, "默认场景应包含光源 Light");
|
||||||
|
MetaCoreExpect(cameraId != 0, "默认场景应包含相机 Camera");
|
||||||
|
|
||||||
|
// 2. 生成快照数据
|
||||||
|
MetaCore::MetaCoreSceneRenderSync renderSync;
|
||||||
|
MetaCore::MetaCoreSceneRenderSyncSnapshot snapshot = renderSync.BuildSnapshot(scene);
|
||||||
|
|
||||||
|
// 3. 修改快照中的参数以测试解耦逻辑和 Enabled 属性过滤
|
||||||
|
glm::mat4 customLocalMatrix = glm::translate(glm::mat4(1.0F), glm::vec3(15.0F, -5.0F, 3.5F));
|
||||||
|
snapshot.LocalMatrices[cubeId] = customLocalMatrix;
|
||||||
|
snapshot.WorldMatrices[cubeId] = customLocalMatrix;
|
||||||
|
|
||||||
|
// 禁用所有光源和相机以测试过滤和默认光源自动起降
|
||||||
|
for (auto& light : snapshot.Lights) {
|
||||||
|
light.Enabled = false;
|
||||||
|
}
|
||||||
|
for (auto& camera : snapshot.Cameras) {
|
||||||
|
camera.Enabled = false;
|
||||||
|
}
|
||||||
|
snapshot.PrimaryCamera = std::nullopt;
|
||||||
|
|
||||||
|
// 4. 初始化窗口和 FilamentSceneBridge
|
||||||
|
MetaCore::MetaCoreWindow window;
|
||||||
|
bool winOk = window.Initialize(800, 600, "DecoupledSnapshotSyncTestWindow");
|
||||||
|
MetaCoreExpect(winOk, "测试窗口初始化应成功");
|
||||||
|
|
||||||
|
MetaCore::MetaCoreFilamentSceneBridge bridge;
|
||||||
|
bridge.SetProjectRootPath("d:/MetaCore/SandboxProject");
|
||||||
|
bool bridgeOk = bridge.Initialize(window);
|
||||||
|
MetaCoreExpect(bridgeOk, "测试桥接器初始化应成功");
|
||||||
|
|
||||||
|
// 5. 在 scene == nullptr 的快照渲染模式下执行同步
|
||||||
|
bridge.SyncScene(snapshot, nullptr, false, false);
|
||||||
|
|
||||||
|
// 6. 验证映射重建和变换同步
|
||||||
|
glm::mat4 cubeWorldMatrix;
|
||||||
|
bool hasCube = bridge.TryGetObjectWorldMatrix(cubeId, cubeWorldMatrix);
|
||||||
|
MetaCoreExpect(hasCube, "无 scene 模式下重建映射后应包含 Cube 变换");
|
||||||
|
|
||||||
|
bool transOk = bridge.VerifyTransformForTesting(cubeId, customLocalMatrix);
|
||||||
|
MetaCoreExpect(transOk, "快照中的自定义局部变换应正确同步到 Filament");
|
||||||
|
|
||||||
|
// 7. 验证 Enabled 状态为 false 的光源被过滤排除,且默认灯光起降机制生效 (自动亮起)
|
||||||
|
bool hasLight = bridge.VerifyLightExistsForTesting(lightId);
|
||||||
|
MetaCoreExpect(!hasLight, "Enabled 为 false 的自定义光源不应被实例化");
|
||||||
|
|
||||||
|
float defaultLightIntensity = bridge.GetDefaultLightIntensityForTesting();
|
||||||
|
MetaCoreExpect(defaultLightIntensity > 99000.0F, "无有效自定义光源时,默认灯光应起飞作为兜底");
|
||||||
|
|
||||||
|
// 8. 动态开启光源属性,验证默认灯光动态变暗
|
||||||
|
for (auto& light : snapshot.Lights) {
|
||||||
|
if (light.ObjectId == lightId) {
|
||||||
|
light.Enabled = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
bridge.SyncScene(snapshot, nullptr, false, false);
|
||||||
|
|
||||||
|
bool hasLightNow = bridge.VerifyLightExistsForTesting(lightId);
|
||||||
|
MetaCoreExpect(hasLightNow, "启用光源后自定义光源应被实例化");
|
||||||
|
|
||||||
|
float defaultLightIntensityNow = bridge.GetDefaultLightIntensityForTesting();
|
||||||
|
MetaCoreExpect(defaultLightIntensityNow < 1.0F, "启用自定义光源时,默认灯光强度应自动降为 0");
|
||||||
|
|
||||||
|
// 9. 再次禁用光源,验证自定义光源被销毁并且默认灯光复亮
|
||||||
|
for (auto& light : snapshot.Lights) {
|
||||||
|
if (light.ObjectId == lightId) {
|
||||||
|
light.Enabled = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
bridge.SyncScene(snapshot, nullptr, false, false);
|
||||||
|
|
||||||
|
bool hasLightFinal = bridge.VerifyLightExistsForTesting(lightId);
|
||||||
|
MetaCoreExpect(!hasLightFinal, "再次禁用光源后自定义光源实体应被正确销毁移出");
|
||||||
|
|
||||||
|
float defaultLightIntensityFinal = bridge.GetDefaultLightIntensityForTesting();
|
||||||
|
MetaCoreExpect(defaultLightIntensityFinal > 99000.0F, "再次无激活光源时,默认灯光应重新亮起兜底");
|
||||||
|
|
||||||
|
// 10. 资源清理
|
||||||
|
bridge.Shutdown();
|
||||||
|
window.Shutdown();
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
||||||
int main() {
|
int main() {
|
||||||
@ -2541,6 +2643,9 @@ int main() {
|
|||||||
std::cout << "[RUN] MetaCoreTestUiDocumentSerialization..." << std::endl;
|
std::cout << "[RUN] MetaCoreTestUiDocumentSerialization..." << std::endl;
|
||||||
MetaCoreTestUiDocumentSerialization();
|
MetaCoreTestUiDocumentSerialization();
|
||||||
|
|
||||||
|
std::cout << "[RUN] MetaCoreTestDecoupledSnapshotSync..." << std::endl;
|
||||||
|
MetaCoreTestDecoupledSnapshotSync();
|
||||||
|
|
||||||
std::cout << "MetaCoreSmokeTests passed\n";
|
std::cout << "MetaCoreSmokeTests passed\n";
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user