2026-03-02 04:50:28 +08:00
|
|
|
-- ==============================================
|
|
|
|
|
-- 场景图示例 - Xmake 构建脚本
|
|
|
|
|
-- 演示 Extra2D 场景图系统的核心功能
|
|
|
|
|
-- 支持平台: MinGW (Windows), Nintendo Switch
|
|
|
|
|
-- ==============================================
|
|
|
|
|
|
|
|
|
|
-- 获取当前脚本所在目录(示例根目录)
|
|
|
|
|
local example_dir = os.scriptdir()
|
|
|
|
|
|
|
|
|
|
-- 可执行文件目标
|
|
|
|
|
target("scene_graph_demo")
|
|
|
|
|
set_kind("binary")
|
2026-03-03 03:48:55 +08:00
|
|
|
add_files("main.cpp", "game_scene.cpp", "instanced_test.cpp")
|
2026-03-02 04:50:28 +08:00
|
|
|
add_includedirs("../../include", ".")
|
|
|
|
|
add_deps("extra2d")
|
|
|
|
|
|
|
|
|
|
-- 使用与主项目相同的平台配置
|
|
|
|
|
if is_plat("switch") then
|
|
|
|
|
set_targetdir("../../build/examples/scene_graph_demo")
|
|
|
|
|
|
|
|
|
|
-- 构建后生成 NRO 文件
|
|
|
|
|
after_build(function (target)
|
|
|
|
|
local devkitPro = os.getenv("DEVKITPRO") or "C:/devkitPro"
|
|
|
|
|
local elf_file = target:targetfile()
|
|
|
|
|
local output_dir = path.directory(elf_file)
|
|
|
|
|
local nacp_file = path.join(output_dir, "scene_graph_demo.nacp")
|
|
|
|
|
local nro_file = path.join(output_dir, "scene_graph_demo.nro")
|
|
|
|
|
local nacptool = path.join(devkitPro, "tools/bin/nacptool.exe")
|
|
|
|
|
local elf2nro = path.join(devkitPro, "tools/bin/elf2nro.exe")
|
|
|
|
|
|
2026-03-03 03:57:19 +08:00
|
|
|
-- 确保 romfs 目录存在
|
|
|
|
|
local romfs = path.join(example_dir, "romfs")
|
|
|
|
|
if not os.isdir(romfs) then
|
|
|
|
|
os.mkdir(romfs)
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
-- 复制着色器文件到 romfs/shader 目录
|
|
|
|
|
local shader_source = path.join(example_dir, "../../shader")
|
|
|
|
|
local shader_target = path.join(romfs, "shader")
|
|
|
|
|
if os.isdir(shader_source) then
|
|
|
|
|
if not os.isdir(shader_target) then
|
|
|
|
|
os.mkdir(shader_target)
|
|
|
|
|
end
|
|
|
|
|
os.cp(path.join(shader_source, "*"), shader_target)
|
|
|
|
|
print("Copied shaders to romfs: " .. shader_target)
|
|
|
|
|
end
|
|
|
|
|
|
2026-03-02 04:50:28 +08:00
|
|
|
if os.isfile(nacptool) and os.isfile(elf2nro) then
|
|
|
|
|
os.vrunv(nacptool, {"--create", "Scene Graph Demo", "Extra2D Team", "1.0.0", nacp_file})
|
|
|
|
|
if os.isdir(romfs) then
|
|
|
|
|
os.vrunv(elf2nro, {elf_file, nro_file, "--nacp=" .. nacp_file, "--romfsdir=" .. romfs})
|
|
|
|
|
else
|
|
|
|
|
os.vrunv(elf2nro, {elf_file, nro_file, "--nacp=" .. nacp_file})
|
|
|
|
|
end
|
|
|
|
|
print("Generated NRO: " .. nro_file)
|
|
|
|
|
end
|
|
|
|
|
end)
|
|
|
|
|
|
|
|
|
|
-- 打包时将 NRO 文件复制到 package 目录
|
|
|
|
|
after_package(function (target)
|
|
|
|
|
local nro_file = path.join(target:targetdir(), "scene_graph_demo.nro")
|
|
|
|
|
local package_dir = target:packagedir()
|
|
|
|
|
if os.isfile(nro_file) and package_dir then
|
|
|
|
|
os.cp(nro_file, package_dir)
|
|
|
|
|
print("Copied NRO to package: " .. package_dir)
|
|
|
|
|
end
|
|
|
|
|
end)
|
|
|
|
|
|
|
|
|
|
elseif is_plat("mingw") then
|
|
|
|
|
set_targetdir("../../build/examples/scene_graph_demo")
|
|
|
|
|
|
|
|
|
|
-- 复制资源到输出目录
|
|
|
|
|
after_build(function (target)
|
|
|
|
|
local target_dir = path.directory(target:targetfile())
|
|
|
|
|
|
|
|
|
|
-- 复制 romfs 资源
|
|
|
|
|
local romfs = path.join(example_dir, "romfs")
|
|
|
|
|
if os.isdir(romfs) then
|
|
|
|
|
local assets_dir = path.join(target_dir, "assets")
|
|
|
|
|
|
|
|
|
|
-- 创建 assets 目录
|
|
|
|
|
if not os.isdir(assets_dir) then
|
|
|
|
|
os.mkdir(assets_dir)
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
-- 复制所有资源文件(包括子目录)
|
|
|
|
|
os.cp(path.join(romfs, "assets/**"), assets_dir)
|
|
|
|
|
print("Copied assets from " .. romfs .. " to " .. assets_dir)
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
-- 复制着色器文件
|
|
|
|
|
local shader_source = path.join(example_dir, "../../shader")
|
|
|
|
|
local shader_target = path.join(target_dir, "shader")
|
|
|
|
|
if os.isdir(shader_source) then
|
|
|
|
|
if not os.isdir(shader_target) then
|
|
|
|
|
os.mkdir(shader_target)
|
|
|
|
|
end
|
|
|
|
|
os.cp(path.join(shader_source, "*"), shader_target)
|
|
|
|
|
print("Copied shaders from " .. shader_source .. " to " .. shader_target)
|
|
|
|
|
end
|
|
|
|
|
end)
|
|
|
|
|
end
|
|
|
|
|
target_end()
|