project creator: updated script with sample model loading (#1129)

This commit is contained in:
Turánszki János
2025-06-13 07:16:19 +02:00
committed by GitHub
parent 9e6fd9f3c3
commit 8a1b27dd2c
2 changed files with 75 additions and 12 deletions
+68 -7
View File
@@ -211,7 +211,7 @@ void ProjectCreatorWindow::Create(EditorComponent* _editor)
wilog("Project creator: created directory %s", directory.c_str());
static const std::string script_header = R"(
-- This script was generated by Wicked Editor Project Creator.
-- This script was generated by Wicked Editor Project Creator, you can modify it to your needs.
-- Read the scripting API documentation here: https://github.com/turanszkij/WickedEngine/blob/master/Content/Documentation/ScriptingAPI-Documentation.md
)";
@@ -220,17 +220,33 @@ input.SetCursorFromFile(CURSOR_DEFAULT, script_dir() .. "cursor.cur")
)";
static const std::string script_process = R"(
-- by running the script as a process, we can use engine events like update() in it to halt the script while the event doesn't arrive
runProcess(function()
-- retrieve the global scene and camera objects that will be used for rendering
-- retrieve the global scene and camera objects that will be used for 3D rendering
local scene = GetScene()
local camera = GetCamera()
-- load a sample model simply into the current global scene from an asset file:
local cube_root_entity = LoadModel(script_dir() .. "/cube.wiscene")
-- create a point light to be able to see the cube:
local light_entity = CreateEntity()
local light = scene.Component_CreateLight(light_entity)
light.SetType(POINT)
light.SetIntensity(10)
local light_transform = scene.Component_CreateTransform(light_entity)
light_transform.Translate(Vector(2,2,-2))
-- put camera back a bit so we can see the cube in the origin (note that the camera is updated with this transform every frame when TransformCamera() is called):
local cam_transform = TransformComponent()
cam_transform.Translate(Vector(0, 2, -8))
-- set up a 3D render path, so if you load a model it will be displayed
local renderpath = RenderPath3D()
application.SetActivePath(renderpath, 1.0, 0, 0, 0, FadeType.CrossFade) -- 1 sec cross fade
-- set up a simple text that will dynamically change every frame
-- set up a simple 2D text that will dynamically change every frame
local counter = 0
local font = SpriteFont()
renderpath.AddFont(font)
@@ -239,12 +255,33 @@ runProcess(function()
while true do
update() -- blocks this process until next update() is signaled from Wicked Engine
-- every frame the text is positioned to the center of the screen and display the value of the frame counter
local dt = getDeltaTime() -- get delta time (elapsed time since last update())
-- every frame the text is positioned to the upper center of the screen and display the value of the frame counter
font.SetText("Hello World! Current frame counter = " .. counter)
font.SetSize(12) -- the true render size of the font (larger can increase memory usage, but improves appearance)
font.SetScale(3) -- upscaling the font by a factor of 3 without increasing the true font resolution
font.SetPos(Vector(GetScreenWidth() * 0.5, GetScreenHeight() * 0.5)) -- put to center of the screen
font.SetSize(24) -- the true render size of the font (larger can increase memory usage, but improves appearance)
font.SetScale(2) -- upscaling the font without increasing the true font resolution
font.SetPos(Vector(GetScreenWidth() * 0.5, GetScreenHeight() * 0.25)) -- put to upper center of the screen
font.SetAlign(WIFALIGN_CENTER, WIFALIGN_CENTER) -- horizontal and vertical text align
-- WASD camera movement:
local camspeed = 10 * dt
if input.Down(string.byte('W')) then
cam_transform.Translate(Vector(0,0,camspeed))
elseif input.Down(string.byte('S')) then
cam_transform.Translate(Vector(0,0,-camspeed))
elseif input.Down(string.byte('A')) then
cam_transform.Translate(Vector(-camspeed,0))
elseif input.Down(string.byte('D')) then
cam_transform.Translate(Vector(camspeed,0))
end
cam_transform.UpdateTransform()
camera.TransformCamera(cam_transform)
camera.UpdateCamera()
-- rotate the cube every frame by a bit with the amount of delta time since last frame:
local cube_transform = scene.Component_GetTransform(cube_root_entity)
cube_transform.Rotate(Vector(0, dt * math.pi, 0))
counter = counter + 1
@@ -293,6 +330,30 @@ end)
wi::helper::FileWrite(directory + "cursor.cur", cursordata.data(), cursordata.size());
}
// Create a sample cube model for the project:
{
wi::scene::Scene samplescene;
samplescene.Entity_CreateCube("cube");
wi::Archive samplescene_archive;
samplescene.Serialize(samplescene_archive);
samplescene_archive.SaveFile(directory + "cube.wiscene");
}
if (wi::renderer::GetShaderDumpCount() == 0)
{
// If not using shader dump, try to copy shader compiler dlls into the project:
std::string dxcompiler_dll_path = wi::helper::GetDirectoryFromPath(wi::helper::GetExecutablePath()) + "dxcompiler.dll";
std::string dxcompiler_so_path = wi::helper::GetDirectoryFromPath(wi::helper::GetExecutablePath()) + "libdxcompiler.so";
if (wi::helper::FileExists(dxcompiler_dll_path))
{
wi::helper::FileCopy(dxcompiler_dll_path, directory + "dxcompiler.dll");
}
if (wi::helper::FileExists(dxcompiler_so_path))
{
wi::helper::FileCopy(dxcompiler_so_path, directory + "libdxcompiler.so");
}
}
wi::unordered_set<std::string> exes;
exes.insert(wi::helper::BackslashToForwardSlash(wi::helper::GetExecutablePath()));
exes.insert(wi::helper::BackslashToForwardSlash(wi::helper::GetCurrentPath() + "/Editor_Windows.exe"));