diff --git a/Editor/ProjectCreatorWindow.cpp b/Editor/ProjectCreatorWindow.cpp index bf91b10bf..24fe7591e 100644 --- a/Editor/ProjectCreatorWindow.cpp +++ b/Editor/ProjectCreatorWindow.cpp @@ -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 exes; exes.insert(wi::helper::BackslashToForwardSlash(wi::helper::GetExecutablePath())); exes.insert(wi::helper::BackslashToForwardSlash(wi::helper::GetCurrentPath() + "/Editor_Windows.exe")); diff --git a/WickedEngine/wiApplication.cpp b/WickedEngine/wiApplication.cpp index 83d9a8b99..5228ff2d8 100644 --- a/WickedEngine/wiApplication.cpp +++ b/WickedEngine/wiApplication.cpp @@ -224,16 +224,18 @@ namespace wi if (!startup_script) { startup_script = true; - if (wi::helper::FileExists(rewriteable_startup_script_text)) + const std::string workingdir = wi::helper::GetCurrentPath() + "/"; + const std::string rewriteable_script_filename = workingdir + rewriteable_startup_script_text; + if (wi::helper::FileExists(rewriteable_script_filename)) { - if (wi::lua::RunFile(rewriteable_startup_script_text)) + if (wi::lua::RunFile(rewriteable_script_filename)) { - wi::backlog::post("Executed startup file: " + rewriteable_startup_script_text); + wi::backlog::post("Executed startup file: " + rewriteable_script_filename); } } else { - std::string startup_lua_filename = wi::helper::GetCurrentPath() + "/startup.lua"; + const std::string startup_lua_filename = workingdir + "startup.lua"; if (wi::helper::FileExists(startup_lua_filename)) { if (wi::lua::RunFile(startup_lua_filename)) @@ -241,7 +243,7 @@ namespace wi wi::backlog::post("Executed startup file: " + startup_lua_filename); } } - std::string startup_luab_filename = wi::helper::GetCurrentPath() + "/startup.luab"; + const std::string startup_luab_filename = workingdir + "startup.luab"; if (wi::helper::FileExists(startup_luab_filename)) { if (wi::lua::RunBinaryFile(startup_luab_filename))