upgraded to stb image resize 2; fixed some issues when compiling with clang on windows
This commit is contained in:
parent
fe87e5a347
commit
3d5d805846
1
external/imgui/imgui_user.inl
vendored
1
external/imgui/imgui_user.inl
vendored
|
@ -1299,7 +1299,6 @@ namespace ImGuiEx {
|
||||||
bool changed = false;
|
bool changed = false;
|
||||||
SetNextItemWidth(width);
|
SetNextItemWidth(width);
|
||||||
BeginGroup();
|
BeginGroup();
|
||||||
float w = CalcItemWidth();
|
|
||||||
SetNextItemWidth(width - CalcTextSize(ICON_FA_TIMES).x - 1);
|
SetNextItemWidth(width - CalcTextSize(ICON_FA_TIMES).x - 1);
|
||||||
SetNextItemAllowOverlap();
|
SetNextItemAllowOverlap();
|
||||||
if (set_keyboard_focus) SetKeyboardFocusHere();
|
if (set_keyboard_focus) SetKeyboardFocusHere();
|
||||||
|
|
2634
external/stb/stb_image_resize.h
vendored
2634
external/stb/stb_image_resize.h
vendored
File diff suppressed because it is too large
Load diff
10303
external/stb/stb_image_resize2.h
vendored
Normal file
10303
external/stb/stb_image_resize2.h
vendored
Normal file
File diff suppressed because it is too large
Load diff
|
@ -57,7 +57,7 @@ struct AnimationSampler {
|
||||||
if (anim.m_max_accessed_bone_index >= pose.count) return; // can happen if skeletons do not match
|
if (anim.m_max_accessed_bone_index >= pose.count) return; // can happen if skeletons do not match
|
||||||
const Model& model = *ctx.model;
|
const Model& model = *ctx.model;
|
||||||
const Time time = ctx.time;
|
const Time time = ctx.time;
|
||||||
const BoneMask* mask = ctx.mask;
|
//const BoneMask* mask = ctx.mask;
|
||||||
const float weight = ctx.weight;
|
const float weight = ctx.weight;
|
||||||
|
|
||||||
ASSERT(!pose.is_absolute);
|
ASSERT(!pose.is_absolute);
|
||||||
|
|
|
@ -52,9 +52,6 @@ struct AnimationAssetBrowserPlugin : AssetBrowser::IPlugin {
|
||||||
{
|
{
|
||||||
m_resource = app.getEngine().getResourceManager().load<Animation>(path);
|
m_resource = app.getEngine().getResourceManager().load<Animation>(path);
|
||||||
|
|
||||||
Engine& engine = m_app.getEngine();
|
|
||||||
|
|
||||||
|
|
||||||
m_viewer.m_world->createComponent(ANIMABLE_TYPE, *m_viewer.m_mesh);
|
m_viewer.m_world->createComponent(ANIMABLE_TYPE, *m_viewer.m_mesh);
|
||||||
|
|
||||||
auto* anim_module = static_cast<AnimationModule*>(m_viewer.m_world->getModule(ANIMABLE_TYPE));
|
auto* anim_module = static_cast<AnimationModule*>(m_viewer.m_world->getModule(ANIMABLE_TYPE));
|
||||||
|
@ -212,8 +209,6 @@ struct AnimationAssetBrowserPlugin : AssetBrowser::IPlugin {
|
||||||
|
|
||||||
if ((!rotations.empty() || !const_rotations.empty()) && ImGui::TreeNode("Rotations")) {
|
if ((!rotations.empty() || !const_rotations.empty()) && ImGui::TreeNode("Rotations")) {
|
||||||
for (const Animation::RotationTrack& track : rotations) {
|
for (const Animation::RotationTrack& track : rotations) {
|
||||||
u32 track_idx = u32(&track - rotations.begin());
|
|
||||||
|
|
||||||
const Model::Bone& bone = m_model->getBone(track.bone_index);
|
const Model::Bone& bone = m_model->getBone(track.bone_index);
|
||||||
ImGuiTreeNodeFlags flags = m_selected_bone == track.bone_index ? ImGuiTreeNodeFlags_Selected : 0;
|
ImGuiTreeNodeFlags flags = m_selected_bone == track.bone_index ? ImGuiTreeNodeFlags_Selected : 0;
|
||||||
flags |= ImGuiTreeNodeFlags_OpenOnArrow;
|
flags |= ImGuiTreeNodeFlags_OpenOnArrow;
|
||||||
|
|
|
@ -236,8 +236,7 @@ struct ControllerEditorImpl : ControllerEditor, AssetBrowser::IPlugin, AssetComp
|
||||||
{
|
{
|
||||||
FileSystem& fs = m_app.getEngine().getFileSystem();
|
FileSystem& fs = m_app.getEngine().getFileSystem();
|
||||||
OutputMemoryStream data(m_allocator);
|
OutputMemoryStream data(m_allocator);
|
||||||
ResourceManagerHub& rm = m_app.getEngine().getResourceManager();
|
if (fs.getContentSync(path, data)) {
|
||||||
if (fs.getContentSync(Path(path), data)) {
|
|
||||||
InputMemoryStream str(data);
|
InputMemoryStream str(data);
|
||||||
if (m_controller.deserialize(str)) {
|
if (m_controller.deserialize(str)) {
|
||||||
checkSkeleton();
|
checkSkeleton();
|
||||||
|
@ -329,7 +328,6 @@ struct ControllerEditorImpl : ControllerEditor, AssetBrowser::IPlugin, AssetComp
|
||||||
if (ImGui::IsKeyPressed(ImGuiKey_Escape)) ImGui::CloseCurrentPopup();
|
if (ImGui::IsKeyPressed(ImGuiKey_Escape)) ImGui::CloseCurrentPopup();
|
||||||
if (ImGui::IsWindowAppearing()) m_node_filter_selection = 0;
|
if (ImGui::IsWindowAppearing()) m_node_filter_selection = 0;
|
||||||
if (m_node_filter.gui("Filter", 150, ImGui::IsWindowAppearing())) m_node_filter_selection = 0;
|
if (m_node_filter.gui("Filter", 150, ImGui::IsWindowAppearing())) m_node_filter_selection = 0;
|
||||||
Node* n = nullptr;
|
|
||||||
if (m_node_filter.isActive()) {
|
if (m_node_filter.isActive()) {
|
||||||
struct : INodeTypeVisitor {
|
struct : INodeTypeVisitor {
|
||||||
bool beginCategory(const char* _category) override {
|
bool beginCategory(const char* _category) override {
|
||||||
|
@ -346,7 +344,7 @@ struct ControllerEditorImpl : ControllerEditor, AssetBrowser::IPlugin, AssetComp
|
||||||
|
|
||||||
StaticString<128> label(category, _label);
|
StaticString<128> label(category, _label);
|
||||||
if (shortcut) label.append(" (LMB + ", shortcut, ")");
|
if (shortcut) label.append(" (LMB + ", shortcut, ")");
|
||||||
if (ImGui::Selectable(label, selected) || insert_enter && selected) {
|
if (ImGui::Selectable(label, selected) || (insert_enter && selected)) {
|
||||||
n = creator.create(*win);
|
n = creator.create(*win);
|
||||||
ImGui::CloseCurrentPopup();
|
ImGui::CloseCurrentPopup();
|
||||||
}
|
}
|
||||||
|
@ -588,7 +586,7 @@ struct ControllerEditorImpl : ControllerEditor, AssetBrowser::IPlugin, AssetComp
|
||||||
float weight = blob.read<float>();
|
float weight = blob.read<float>();
|
||||||
Time time = blob.read<Time>();
|
Time time = blob.read<Time>();
|
||||||
bool looped = blob.read<bool>();
|
bool looped = blob.read<bool>();
|
||||||
ImGui::Text("slot = %d, weight = %f, time = %f", slot, weight, time.seconds());
|
ImGui::Text("slot = %d, weight = %f, time = %f, looped = %s", slot, weight, time.seconds(), looped ? "true" : "false");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -836,7 +834,6 @@ struct ControllerEditorImpl : ControllerEditor, AssetBrowser::IPlugin, AssetComp
|
||||||
StringView subres = Path::getSubresource(path);
|
StringView subres = Path::getSubresource(path);
|
||||||
if (Path::hasExtension(subres, "ani")) {
|
if (Path::hasExtension(subres, "ani")) {
|
||||||
Controller::AnimationEntry& entry = m_controller.m_animation_entries.emplace();
|
Controller::AnimationEntry& entry = m_controller.m_animation_entries.emplace();
|
||||||
ResourceManagerHub& res_manager = m_app.getEngine().getResourceManager();
|
|
||||||
entry.animation = path;
|
entry.animation = path;
|
||||||
entry.set = 0;
|
entry.set = 0;
|
||||||
entry.slot = m_controller.m_animation_slots.size();
|
entry.slot = m_controller.m_animation_slots.size();
|
||||||
|
@ -852,7 +849,6 @@ struct ControllerEditorImpl : ControllerEditor, AssetBrowser::IPlugin, AssetComp
|
||||||
StringView subres = Path::getSubresource(path);
|
StringView subres = Path::getSubresource(path);
|
||||||
if (Path::hasExtension(subres, "ani")) {
|
if (Path::hasExtension(subres, "ani")) {
|
||||||
Controller::AnimationEntry& entry = m_controller.m_animation_entries.emplace();
|
Controller::AnimationEntry& entry = m_controller.m_animation_entries.emplace();
|
||||||
ResourceManagerHub& res_manager = m_app.getEngine().getResourceManager();
|
|
||||||
entry.animation = path;
|
entry.animation = path;
|
||||||
entry.set = 0;
|
entry.set = 0;
|
||||||
entry.slot = m_controller.m_animation_slots.size();
|
entry.slot = m_controller.m_animation_slots.size();
|
||||||
|
@ -1020,8 +1016,6 @@ struct ControllerEditorImpl : ControllerEditor, AssetBrowser::IPlugin, AssetComp
|
||||||
}
|
}
|
||||||
|
|
||||||
void windowGUI() override {
|
void windowGUI() override {
|
||||||
const CommonActions& actions = m_app.getCommonActions();
|
|
||||||
|
|
||||||
if (!m_to_fix_skeleton.empty()) {
|
if (!m_to_fix_skeleton.empty()) {
|
||||||
ImGui::OpenPopup(ICON_FA_EXCLAMATION_TRIANGLE " Fix skeleton");
|
ImGui::OpenPopup(ICON_FA_EXCLAMATION_TRIANGLE " Fix skeleton");
|
||||||
}
|
}
|
||||||
|
@ -1184,7 +1178,6 @@ struct ControllerEditorImpl : ControllerEditor, AssetBrowser::IPlugin, AssetComp
|
||||||
}
|
}
|
||||||
|
|
||||||
void createResource(OutputMemoryStream& blob) override {
|
void createResource(OutputMemoryStream& blob) override {
|
||||||
ResourceManager* rm = m_app.getEngine().getResourceManager().get(anim::Controller::TYPE);
|
|
||||||
anim_editor::Controller controller(Path("new controller"), m_app.getAllocator());
|
anim_editor::Controller controller(Path("new controller"), m_app.getAllocator());
|
||||||
controller.serialize(blob);
|
controller.serialize(blob);
|
||||||
}
|
}
|
||||||
|
|
|
@ -252,7 +252,7 @@ void Blend2DNode::dataChanged() {
|
||||||
u32 a, b;
|
u32 a, b;
|
||||||
bool valid = true;
|
bool valid = true;
|
||||||
bool operator ==(const Edge& rhs) {
|
bool operator ==(const Edge& rhs) {
|
||||||
return a == rhs.a && b == rhs.b || a == rhs.b && b == rhs.a;
|
return (a == rhs.a && b == rhs.b) || (a == rhs.b && b == rhs.a);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -368,7 +368,6 @@ bool Blend1DNode::propertiesGUI(Model& skeleton) {
|
||||||
|
|
||||||
ImGui::TableNextColumn();
|
ImGui::TableNextColumn();
|
||||||
ImGui::SetNextItemWidth(-1);
|
ImGui::SetNextItemWidth(-1);
|
||||||
static i32 selected = -1;
|
|
||||||
res = editSlot(m_controller, "##anim", &child.slot) || res;
|
res = editSlot(m_controller, "##anim", &child.slot) || res;
|
||||||
|
|
||||||
ImGui::PopID();
|
ImGui::PopID();
|
||||||
|
@ -431,7 +430,6 @@ anim::Node* AnimationNode::compile(anim::Controller& controller) {
|
||||||
|
|
||||||
bool AnimationNode::propertiesGUI(Model& skeleton) {
|
bool AnimationNode::propertiesGUI(Model& skeleton) {
|
||||||
ImGuiEx::Label("Slot");
|
ImGuiEx::Label("Slot");
|
||||||
static i32 selected = -1;
|
|
||||||
bool res = editSlot(m_controller, "##slot", &m_slot);
|
bool res = editSlot(m_controller, "##slot", &m_slot);
|
||||||
ImGuiEx::Label("Looping");
|
ImGuiEx::Label("Looping");
|
||||||
bool loop = m_flags & Flags::LOOPED;
|
bool loop = m_flags & Flags::LOOPED;
|
||||||
|
|
|
@ -746,8 +746,6 @@ struct AssetCompilerImpl : AssetCompiler {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
StringView ext = Path::getExtension(path_obj);
|
|
||||||
|
|
||||||
auto dep_iter = m_dependencies.find(path_obj);
|
auto dep_iter = m_dependencies.find(path_obj);
|
||||||
if (dep_iter.isValid()) {
|
if (dep_iter.isValid()) {
|
||||||
for (const Path& p : dep_iter.value()) {
|
for (const Path& p : dep_iter.value()) {
|
||||||
|
|
|
@ -8,7 +8,6 @@ EntityFolders::EntityFolders(World& world, IAllocator& allocator)
|
||||||
: m_entities(allocator)
|
: m_entities(allocator)
|
||||||
, m_world(world)
|
, m_world(world)
|
||||||
, m_folders(allocator)
|
, m_folders(allocator)
|
||||||
, m_allocator(allocator)
|
|
||||||
{
|
{
|
||||||
ASSERT(!world.getFirstEntity().isValid());
|
ASSERT(!world.getFirstEntity().isValid());
|
||||||
world.entityDestroyed().bind<&EntityFolders::onEntityDestroyed>(this);
|
world.entityDestroyed().bind<&EntityFolders::onEntityDestroyed>(this);
|
||||||
|
|
|
@ -58,7 +58,6 @@ private:
|
||||||
void unlink(Folder& folder);
|
void unlink(Folder& folder);
|
||||||
FolderHandle generateUniqueID();
|
FolderHandle generateUniqueID();
|
||||||
|
|
||||||
IAllocator& m_allocator;
|
|
||||||
World& m_world;
|
World& m_world;
|
||||||
Array<Entity> m_entities;
|
Array<Entity> m_entities;
|
||||||
Array<Folder> m_folders;
|
Array<Folder> m_folders;
|
||||||
|
|
|
@ -269,7 +269,6 @@ struct ProfilerUIImpl final : StudioApp::GUIPlugin {
|
||||||
|
|
||||||
void timeline(float from_x, float to_x, float top, float bottom, u64 start_t) {
|
void timeline(float from_x, float to_x, float top, float bottom, u64 start_t) {
|
||||||
const float view_length_us = (float)1'000'000 * float(m_range / double(profiler::frequency()));
|
const float view_length_us = (float)1'000'000 * float(m_range / double(profiler::frequency()));
|
||||||
const float timeline_height = ImGui::GetTextLineHeightWithSpacing();
|
|
||||||
const ImColor border_color(ImGui::GetStyle().Colors[ImGuiCol_FrameBg]);
|
const ImColor border_color(ImGui::GetStyle().Colors[ImGuiCol_FrameBg]);
|
||||||
|
|
||||||
ImDrawList* dl = ImGui::GetWindowDrawList();
|
ImDrawList* dl = ImGui::GetWindowDrawList();
|
||||||
|
@ -1348,7 +1347,6 @@ struct ProfilerUIImpl final : StudioApp::GUIPlugin {
|
||||||
}
|
}
|
||||||
ImGui::EndChild();
|
ImGui::EndChild();
|
||||||
|
|
||||||
ImDrawList* dl = ImGui::GetWindowDrawList();
|
|
||||||
timeline(from_x, to_x, timeline_y, before_gpu_y, timeline_start_t);
|
timeline(from_x, to_x, timeline_y, before_gpu_y, timeline_start_t);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1367,7 +1367,6 @@ struct StudioAppImpl final : StudioApp
|
||||||
if (selected) {
|
if (selected) {
|
||||||
char filename[MAX_PATH];
|
char filename[MAX_PATH];
|
||||||
Path::normalize(m_file_selector.getPath(), filename);
|
Path::normalize(m_file_selector.getPath(), filename);
|
||||||
const char* base_path = m_engine->getFileSystem().getBasePath();
|
|
||||||
EntityRef entity = selected_entities[0];
|
EntityRef entity = selected_entities[0];
|
||||||
m_editor->getPrefabSystem().savePrefab(entity, Path(filename));
|
m_editor->getPrefabSystem().savePrefab(entity, Path(filename));
|
||||||
ImGui::CloseCurrentPopup();
|
ImGui::CloseCurrentPopup();
|
||||||
|
@ -1845,7 +1844,6 @@ struct StudioAppImpl final : StudioApp
|
||||||
node_open = ImGui::TreeNodeEx((void*)folder, flags, "%s%s", ICON_FA_FOLDER, folder->name);
|
node_open = ImGui::TreeNodeEx((void*)folder, flags, "%s%s", ICON_FA_FOLDER, folder->name);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
const ImGuiID node_id = ImGui::GetItemID();
|
|
||||||
|
|
||||||
if (ImGui::BeginDragDropTarget()) {
|
if (ImGui::BeginDragDropTarget()) {
|
||||||
if (auto* payload = ImGui::AcceptDragDropPayload("entity")) {
|
if (auto* payload = ImGui::AcceptDragDropPayload("entity")) {
|
||||||
|
@ -3001,7 +2999,7 @@ struct StudioAppImpl final : StudioApp
|
||||||
LuaWrapper::push(L, world); // [Entity.new, Lumix.Entity, world]
|
LuaWrapper::push(L, world); // [Entity.new, Lumix.Entity, world]
|
||||||
LuaWrapper::push(L, entity.index); // [Entity.new, Lumix.Entity, world, entity_index]
|
LuaWrapper::push(L, entity.index); // [Entity.new, Lumix.Entity, world, entity_index]
|
||||||
const bool error = !LuaWrapper::pcall(L, 3, 1); // [entity]
|
const bool error = !LuaWrapper::pcall(L, 3, 1); // [entity]
|
||||||
return 1;
|
return error ? 0 : 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int LUA_getResources(lua_State* L)
|
static int LUA_getResources(lua_State* L)
|
||||||
|
|
|
@ -45,7 +45,7 @@ enum class TokenType : u8 {
|
||||||
};
|
};
|
||||||
|
|
||||||
static bool isWordChar(char c) {
|
static bool isWordChar(char c) {
|
||||||
return c >= 'a' && c <= 'z' || c >= 'A' && c <= 'Z' || c >= '0' && c <= '9' || c == '_';
|
return (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') || (c >= '0' && c <= '9') || c == '_';
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool tokenize(const char* str, u32& token_len, u8& token_type, u8 prev_token_type) {
|
static bool tokenize(const char* str, u32& token_len, u8& token_type, u8 prev_token_type) {
|
||||||
|
@ -196,7 +196,7 @@ static bool tokenize(const char* str, u32& token_len, u8& token_type, u8 prev_to
|
||||||
return *c;
|
return *c;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (*c >= 'a' && *c <= 'z' || *c >= 'A' && *c <= 'Z' || *c == '_') {
|
if ((*c >= 'a' && *c <= 'z') || (*c >= 'A' && *c <= 'Z') || *c == '_') {
|
||||||
token_type = (u8)TokenType::IDENTIFIER;
|
token_type = (u8)TokenType::IDENTIFIER;
|
||||||
while (isWordChar(*c)) ++c;
|
while (isWordChar(*c)) ++c;
|
||||||
token_len = u32(c - str);
|
token_len = u32(c - str);
|
||||||
|
@ -246,7 +246,7 @@ enum class TokenType : u8 {
|
||||||
};
|
};
|
||||||
|
|
||||||
static bool isWordChar(char c) {
|
static bool isWordChar(char c) {
|
||||||
return c >= 'a' && c <= 'z' || c >= 'A' && c <= 'Z' || c >= '0' && c <= '9' || c == '_';
|
return (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') || (c >= '0' && c <= '9') || c == '_';
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool tokenize(const char* str, u32& token_len, u8& token_type, u8 prev_token_type) {
|
static bool tokenize(const char* str, u32& token_len, u8& token_type, u8 prev_token_type) {
|
||||||
|
@ -381,7 +381,7 @@ static bool tokenize(const char* str, u32& token_len, u8& token_type, u8 prev_to
|
||||||
return *c;
|
return *c;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (*c >= 'a' && *c <= 'z' || *c >= 'A' && *c <= 'Z' || *c == '_') {
|
if ((*c >= 'a' && *c <= 'z') || (*c >= 'A' && *c <= 'Z') || *c == '_') {
|
||||||
token_type = (u8)TokenType::IDENTIFIER;
|
token_type = (u8)TokenType::IDENTIFIER;
|
||||||
while (isWordChar(*c)) ++c;
|
while (isWordChar(*c)) ++c;
|
||||||
token_len = u32(c - str);
|
token_len = u32(c - str);
|
||||||
|
@ -417,8 +417,8 @@ struct CodeEditorImpl final : CodeEditor {
|
||||||
i32 line = 0;
|
i32 line = 0;
|
||||||
bool operator !=(const TextPoint& rhs) const { return col != rhs.col || line != rhs.line; }
|
bool operator !=(const TextPoint& rhs) const { return col != rhs.col || line != rhs.line; }
|
||||||
bool operator ==(const TextPoint& rhs) const { return col == rhs.col && line == rhs.line; }
|
bool operator ==(const TextPoint& rhs) const { return col == rhs.col && line == rhs.line; }
|
||||||
bool operator < (const TextPoint& rhs) const { return line < rhs.line || line == rhs.line && col < rhs.col; }
|
bool operator < (const TextPoint& rhs) const { return line < rhs.line || (line == rhs.line && col < rhs.col); }
|
||||||
bool operator > (const TextPoint& rhs) const { return line > rhs.line || line == rhs.line && col > rhs.col; }
|
bool operator > (const TextPoint& rhs) const { return line > rhs.line || (line == rhs.line && col > rhs.col); }
|
||||||
};
|
};
|
||||||
|
|
||||||
struct Cursor : TextPoint {
|
struct Cursor : TextPoint {
|
||||||
|
@ -641,7 +641,6 @@ struct CodeEditorImpl final : CodeEditor {
|
||||||
}
|
}
|
||||||
|
|
||||||
ImVec2 toScreenPosition(u32 line, u32 col) {
|
ImVec2 toScreenPosition(u32 line, u32 col) {
|
||||||
ImVec2 v = m_text_area_screen_pos;
|
|
||||||
float y = line * ImGui::GetTextLineHeight();
|
float y = line * ImGui::GetTextLineHeight();
|
||||||
const char* line_str = m_lines[line].value.c_str();
|
const char* line_str = m_lines[line].value.c_str();
|
||||||
float x = ImGui::CalcTextSize(line_str, line_str + col).x;
|
float x = ImGui::CalcTextSize(line_str, line_str + col).x;
|
||||||
|
@ -810,9 +809,7 @@ struct CodeEditorImpl final : CodeEditor {
|
||||||
|
|
||||||
void moveCursorDown(Cursor& cursor, u32 line_count = 1) {
|
void moveCursorDown(Cursor& cursor, u32 line_count = 1) {
|
||||||
const char* line_str = m_lines[cursor.line].value.c_str();
|
const char* line_str = m_lines[cursor.line].value.c_str();
|
||||||
float old_x = ImGui::CalcTextSize(line_str, line_str + cursor.col).x;
|
|
||||||
|
|
||||||
ImVec2 cursor_pos = toScreenPosition(cursor.line, cursor.col);
|
|
||||||
cursor.line = minimum(m_lines.size() - 1, cursor.line + line_count);
|
cursor.line = minimum(m_lines.size() - 1, cursor.line + line_count);
|
||||||
|
|
||||||
u32 num_chars_in_line = m_lines[cursor.line].length();
|
u32 num_chars_in_line = m_lines[cursor.line].length();
|
||||||
|
@ -1056,7 +1053,7 @@ struct CodeEditorImpl final : CodeEditor {
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool isWordChar(char c) {
|
static bool isWordChar(char c) {
|
||||||
return c >= 'a' && c <= 'z' || c >= 'A' && c <= 'Z' || c >= '0' && c <= '9' || c == '_';
|
return (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') || (c >= '0' && c <= '9') || c == '_';
|
||||||
}
|
}
|
||||||
|
|
||||||
Cursor getWord(TextPoint& point) const {
|
Cursor getWord(TextPoint& point) const {
|
||||||
|
@ -1090,7 +1087,7 @@ struct CodeEditorImpl final : CodeEditor {
|
||||||
Cursor& getBottomCursor() {
|
Cursor& getBottomCursor() {
|
||||||
Cursor* bottom = &m_cursors[0];
|
Cursor* bottom = &m_cursors[0];
|
||||||
for (Cursor& cursor : m_cursors) {
|
for (Cursor& cursor : m_cursors) {
|
||||||
if (bottom->line < cursor.line || bottom->line == cursor.line && bottom->col < cursor.col) {
|
if (bottom->line < cursor.line || (bottom->line == cursor.line && bottom->col < cursor.col)) {
|
||||||
bottom = &cursor;
|
bottom = &cursor;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1151,7 +1148,6 @@ struct CodeEditorImpl final : CodeEditor {
|
||||||
r.to = to;
|
r.to = to;
|
||||||
r.execute(*this, false);
|
r.execute(*this, false);
|
||||||
|
|
||||||
i32 line = from.line;
|
|
||||||
for (Cursor& cursor : m_cursors) {
|
for (Cursor& cursor : m_cursors) {
|
||||||
if (cursor < from) continue;
|
if (cursor < from) continue;
|
||||||
|
|
||||||
|
@ -1343,9 +1339,6 @@ struct CodeEditorImpl final : CodeEditor {
|
||||||
p.x += text_area_size.x - 350;
|
p.x += text_area_size.x - 350;
|
||||||
p.x = maximum(p.x, text_area_pos.x);
|
p.x = maximum(p.x, text_area_pos.x);
|
||||||
ImGui::SetCursorScreenPos(p);
|
ImGui::SetCursorScreenPos(p);
|
||||||
float w = text_area_pos.x + text_area_size.x - p.x;
|
|
||||||
float h = ImGui::GetTextLineHeightWithSpacing();
|
|
||||||
ImGui::SetCursorScreenPos(p);
|
|
||||||
ImGui::SetNextItemWidth(-1);
|
ImGui::SetNextItemWidth(-1);
|
||||||
if (m_focus_search) ImGui::SetKeyboardFocusHere();
|
if (m_focus_search) ImGui::SetKeyboardFocusHere();
|
||||||
m_focus_search = false;
|
m_focus_search = false;
|
||||||
|
@ -1358,7 +1351,7 @@ struct CodeEditorImpl final : CodeEditor {
|
||||||
else if (ImGui::InputTextWithHint("##findtext", ICON_FA_SEARCH " Find Text", m_search_text, sizeof(m_search_text), flags)) {
|
else if (ImGui::InputTextWithHint("##findtext", ICON_FA_SEARCH " Find Text", m_search_text, sizeof(m_search_text), flags)) {
|
||||||
find(m_search_from);
|
find(m_search_from);
|
||||||
}
|
}
|
||||||
if (ImGui::IsItemActive() && ImGui::IsKeyPressed(ImGuiKey_Enter) || ImGui::IsKeyPressed(ImGuiKey_F3)) {
|
if ((ImGui::IsItemActive() && ImGui::IsKeyPressed(ImGuiKey_Enter)) || ImGui::IsKeyPressed(ImGuiKey_F3)) {
|
||||||
find(m_cursors[0]);
|
find(m_cursors[0]);
|
||||||
}
|
}
|
||||||
if (font) ImGui::PopFont();
|
if (font) ImGui::PopFont();
|
||||||
|
@ -1472,7 +1465,7 @@ struct CodeEditorImpl final : CodeEditor {
|
||||||
ImGui::ItemAdd(bb, id);
|
ImGui::ItemAdd(bb, id);
|
||||||
const bool hovered = ImGui::ItemHoverable(bb, id, 0);
|
const bool hovered = ImGui::ItemHoverable(bb, id, 0);
|
||||||
const bool clicked = hovered && ImGui::IsItemClicked();
|
const bool clicked = hovered && ImGui::IsItemClicked();
|
||||||
if (m_focus_editor || clicked && !ImGui::IsItemActive()) {
|
if (m_focus_editor || (clicked && !ImGui::IsItemActive())) {
|
||||||
m_focus_editor = false;
|
m_focus_editor = false;
|
||||||
ImGuiWindow* window = ImGui::GetCurrentWindow();
|
ImGuiWindow* window = ImGui::GetCurrentWindow();
|
||||||
ImGui::SetActiveID(id, window);
|
ImGui::SetActiveID(id, window);
|
||||||
|
|
|
@ -2199,7 +2199,6 @@ public:
|
||||||
ASSERT(entities);
|
ASSERT(entities);
|
||||||
if (count <= 0) return;
|
if (count <= 0) return;
|
||||||
|
|
||||||
World* world = getWorld();
|
|
||||||
UniquePtr<IEditorCommand> command = UniquePtr<LocalRotateEntityCommand>::create(m_allocator, *this, entities, local_rotations, count, m_allocator);
|
UniquePtr<IEditorCommand> command = UniquePtr<LocalRotateEntityCommand>::create(m_allocator, *this, entities, local_rotations, count, m_allocator);
|
||||||
executeCommand(command.move());
|
executeCommand(command.move());
|
||||||
}
|
}
|
||||||
|
|
|
@ -152,7 +152,7 @@ static struct Instance
|
||||||
}
|
}
|
||||||
|
|
||||||
static EVENT_TRACE_LOGFILE trace = {};
|
static EVENT_TRACE_LOGFILE trace = {};
|
||||||
trace.LoggerName = KERNEL_LOGGER_NAME;
|
trace.LoggerName = (decltype(trace.LoggerName))KERNEL_LOGGER_NAME;
|
||||||
trace.ProcessTraceMode = PROCESS_TRACE_MODE_RAW_TIMESTAMP | PROCESS_TRACE_MODE_REAL_TIME | PROCESS_TRACE_MODE_EVENT_RECORD;
|
trace.ProcessTraceMode = PROCESS_TRACE_MODE_RAW_TIMESTAMP | PROCESS_TRACE_MODE_REAL_TIME | PROCESS_TRACE_MODE_EVENT_RECORD;
|
||||||
trace.EventRecordCallback = TraceTask::callback;
|
trace.EventRecordCallback = TraceTask::callback;
|
||||||
trace_task.open_handle = OpenTrace(&trace);
|
trace_task.open_handle = OpenTrace(&trace);
|
||||||
|
|
|
@ -249,7 +249,6 @@ Span<u8> OutputPagedStream::reserve(u32 size) {
|
||||||
}
|
}
|
||||||
|
|
||||||
bool OutputPagedStream::write(const void* data, u64 size) {
|
bool OutputPagedStream::write(const void* data, u64 size) {
|
||||||
const u8* src = (const u8*)data;
|
|
||||||
while (size > 0) {
|
while (size > 0) {
|
||||||
Span<u8> dst = reserve((u32)size);
|
Span<u8> dst = reserve((u32)size);
|
||||||
memcpy(dst.begin(), data, dst.length());
|
memcpy(dst.begin(), data, dst.length());
|
||||||
|
|
|
@ -138,7 +138,7 @@ struct LUMIX_ENGINE_API String {
|
||||||
u32 length() const { return m_size; }
|
u32 length() const { return m_size; }
|
||||||
const char* c_str() const { return isSmall() ? m_small : m_big; }
|
const char* c_str() const { return isSmall() ? m_small : m_big; }
|
||||||
template <typename... T>
|
template <typename... T>
|
||||||
void append(T... args) { int tmp[] = { 0, (add(args), 0)... }; }
|
void append(T... args) { int tmp[] = { 0, (add(args), 0)... }; (void)tmp; }
|
||||||
void insert(u32 position, const char* value);
|
void insert(u32 position, const char* value);
|
||||||
void insert(u32 position, StringView value);
|
void insert(u32 position, StringView value);
|
||||||
void eraseAt(u32 position);
|
void eraseAt(u32 position);
|
||||||
|
|
|
@ -1550,6 +1550,7 @@ struct NetworkStream* listen(const char* ip, u16 port, IAllocator& allocator) {
|
||||||
if (retVal == SOCKET_ERROR) return nullptr;
|
if (retVal == SOCKET_ERROR) return nullptr;
|
||||||
|
|
||||||
i32 res = ::listen(listen_socket, 10);
|
i32 res = ::listen(listen_socket, 10);
|
||||||
|
if (res != 0) return nullptr;
|
||||||
|
|
||||||
SOCKET socket = ::accept(listen_socket, nullptr, nullptr);
|
SOCKET socket = ::accept(listen_socket, nullptr, nullptr);
|
||||||
closesocket(listen_socket);
|
closesocket(listen_socket);
|
||||||
|
|
|
@ -16,7 +16,7 @@
|
||||||
#include "renderer/renderer.h"
|
#include "renderer/renderer.h"
|
||||||
#include "stb/stb_image.h"
|
#include "stb/stb_image.h"
|
||||||
#include <math.h>
|
#include <math.h>
|
||||||
#include <stb/stb_image_resize.h>
|
#include <stb/stb_image_resize2.h>
|
||||||
|
|
||||||
namespace Lumix {
|
namespace Lumix {
|
||||||
|
|
||||||
|
@ -886,9 +886,7 @@ struct ResizeNode final : CompositeTexture::Node {
|
||||||
const u32 h = type == Type::PIXELS ? size.y : u32(in.h * scale.y * 0.01f + 0.5f);
|
const u32 h = type == Type::PIXELS ? size.y : u32(in.h * scale.y * 0.01f + 0.5f);
|
||||||
CompositeTexture::Image& out = m_outputs.emplace(w, h, in.channels, m_allocator);
|
CompositeTexture::Image& out = m_outputs.emplace(w, h, in.channels, m_allocator);
|
||||||
|
|
||||||
const i32 res = stbir_resize_float(in.pixels.data(), in.w, in.h, 0, out.pixels.data(), w, h, 0, out.channels);
|
return nullptr != stbir_resize_float_linear(in.pixels.data(), in.w, in.h, 0, out.pixels.data(), w, h, 0, (stbir_pixel_layout)out.channels);
|
||||||
if (res != 1) return error("Failed to resize image");
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool gui() override {
|
bool gui() override {
|
||||||
|
@ -3374,7 +3372,7 @@ struct CompositeTextureEditorImpl : CompositeTextureEditor, NodeEditor {
|
||||||
Renderer* renderer = (Renderer*)m_resource.m_app.getEngine().getSystemManager().getSystem("renderer");
|
Renderer* renderer = (Renderer*)m_resource.m_app.getEngine().getSystemManager().getSystem("renderer");
|
||||||
if (renderer) {
|
if (renderer) {
|
||||||
const CompositeTexture::Image& pd = preview_node->m_outputs[0];
|
const CompositeTexture::Image& pd = preview_node->m_outputs[0];
|
||||||
gpu::TextureFormat format;
|
gpu::TextureFormat format = gpu::TextureFormat::RGBA32F;
|
||||||
switch (pd.channels) {
|
switch (pd.channels) {
|
||||||
case 1: format = gpu::TextureFormat::R32F; break;
|
case 1: format = gpu::TextureFormat::R32F; break;
|
||||||
case 2: format = gpu::TextureFormat::RG32F; break;
|
case 2: format = gpu::TextureFormat::RG32F; break;
|
||||||
|
|
|
@ -827,7 +827,6 @@ void FBXImporter::postprocessMeshes(const ImportConfig& cfg, const Path& path)
|
||||||
VertexLayout vertex_layout;
|
VertexLayout vertex_layout;
|
||||||
|
|
||||||
const bool compute_tangents = !tangents.values && uvs.values;
|
const bool compute_tangents = !tangents.values && uvs.values;
|
||||||
const int packed_vertex_size = getVertexSize(*mesh, import_mesh.is_skinned, cfg);
|
|
||||||
|
|
||||||
vertex_layout.size = sizeof(Vec3); // position
|
vertex_layout.size = sizeof(Vec3); // position
|
||||||
vertex_layout.normal_offset = vertex_layout.size;
|
vertex_layout.normal_offset = vertex_layout.size;
|
||||||
|
@ -942,7 +941,6 @@ void FBXImporter::gatherMeshes()
|
||||||
for (int mesh_idx = 0; mesh_idx < c; ++mesh_idx) {
|
for (int mesh_idx = 0; mesh_idx < c; ++mesh_idx) {
|
||||||
const ofbx::Mesh* fbx_mesh = (const ofbx::Mesh*)m_scene->getMesh(mesh_idx);
|
const ofbx::Mesh* fbx_mesh = (const ofbx::Mesh*)m_scene->getMesh(mesh_idx);
|
||||||
const int mat_count = fbx_mesh->getMaterialCount();
|
const int mat_count = fbx_mesh->getMaterialCount();
|
||||||
const i32 meshes_offset = m_meshes.size();
|
|
||||||
for (int j = 0; j < mat_count; ++j) {
|
for (int j = 0; j < mat_count; ++j) {
|
||||||
ImportMesh& mesh = m_meshes.emplace(m_allocator);
|
ImportMesh& mesh = m_meshes.emplace(m_allocator);
|
||||||
mesh.is_skinned = false;
|
mesh.is_skinned = false;
|
||||||
|
|
|
@ -72,7 +72,6 @@ private:
|
||||||
int width;
|
int width;
|
||||||
int height;
|
int height;
|
||||||
} m_forced_viewport;
|
} m_forced_viewport;
|
||||||
int m_captured_mouse_x, m_captured_mouse_y;
|
|
||||||
Action m_toggle_ui;
|
Action m_toggle_ui;
|
||||||
Action m_fullscreen_action;
|
Action m_fullscreen_action;
|
||||||
};
|
};
|
||||||
|
|
|
@ -218,7 +218,6 @@ struct Node : NodeEditorNode {
|
||||||
bool nodeGUI() override {
|
bool nodeGUI() override {
|
||||||
m_input_counter = 0;
|
m_input_counter = 0;
|
||||||
m_output_counter = 0;
|
m_output_counter = 0;
|
||||||
const ImVec2 old_pos = m_pos;
|
|
||||||
ImGuiEx::BeginNode(m_id, m_pos, &m_selected);
|
ImGuiEx::BeginNode(m_id, m_pos, &m_selected);
|
||||||
bool res = onGUI();
|
bool res = onGUI();
|
||||||
if (m_error.length() > 0) {
|
if (m_error.length() > 0) {
|
||||||
|
@ -3379,7 +3378,6 @@ struct ParticleEditorWindow : AssetEditorWindow, NodeEditor {
|
||||||
|
|
||||||
for (u32 emitter_idx = 0, c = system->getEmitters().size(); emitter_idx < c; ++emitter_idx) {
|
for (u32 emitter_idx = 0, c = system->getEmitters().size(); emitter_idx < c; ++emitter_idx) {
|
||||||
ASSERT(c == m_resource.m_emitters.size());
|
ASSERT(c == m_resource.m_emitters.size());
|
||||||
const ParticleSystem::Emitter& emitter = system->getEmitters()[emitter_idx];
|
|
||||||
const UniquePtr<ParticleEmitterEditorResource>& editor_emitter = m_resource.m_emitters[emitter_idx];
|
const UniquePtr<ParticleEmitterEditorResource>& editor_emitter = m_resource.m_emitters[emitter_idx];
|
||||||
OutputMemoryStream instructions(m_allocator);
|
OutputMemoryStream instructions(m_allocator);
|
||||||
instructions.resize(editor_emitter->m_update.size() + editor_emitter->m_emit.size() + editor_emitter->m_output.size());
|
instructions.resize(editor_emitter->m_update.size() + editor_emitter->m_emit.size() + editor_emitter->m_output.size());
|
||||||
|
|
|
@ -55,22 +55,16 @@
|
||||||
#include "renderer/texture.h"
|
#include "renderer/texture.h"
|
||||||
#include "renderer/terrain.h"
|
#include "renderer/terrain.h"
|
||||||
#include "scene_view.h"
|
#include "scene_view.h"
|
||||||
#include "stb/stb_image.h"
|
|
||||||
#include "stb/stb_image_resize.h"
|
|
||||||
#include "terrain_editor.h"
|
#include "terrain_editor.h"
|
||||||
#include "world_viewer.h"
|
#include "world_viewer.h"
|
||||||
|
|
||||||
#define RGBCX_IMPLEMENTATION
|
#define RGBCX_IMPLEMENTATION
|
||||||
#include <rgbcx/rgbcx.h>
|
#include <rgbcx/rgbcx.h>
|
||||||
#include <stb/stb_image_resize.h>
|
#include "stb/stb_image.h"
|
||||||
|
#include <stb/stb_image_resize2.h>
|
||||||
|
|
||||||
|
|
||||||
using namespace Lumix;
|
using namespace Lumix;
|
||||||
static AtomicI32 xx = 0;
|
|
||||||
|
|
||||||
static Animation::Flags operator | (Animation::Flags a, Animation::Flags b) {
|
|
||||||
return Animation::Flags(u32(a) | u32(b));
|
|
||||||
}
|
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
|
|
||||||
|
@ -220,12 +214,12 @@ static void computeMip(Span<const u8> src, Span<u8> dst, u32 w, u32 h, u32 dst_w
|
||||||
downsampleNormal(src, dst, w, h, dst_w, dst_h);
|
downsampleNormal(src, dst, w, h, dst_w, dst_h);
|
||||||
}
|
}
|
||||||
else if (is_srgb) {
|
else if (is_srgb) {
|
||||||
i32 res = stbir_resize_uint8_srgb(src.begin(), w, h, 0, dst.begin(), dst_w, dst_h, 0, 4, 3, STBIR_ALPHA_CHANNEL_NONE);
|
u8* res = stbir_resize_uint8_srgb(src.begin(), w, h, 0, dst.begin(), dst_w, dst_h, 0, STBIR_RGBA);
|
||||||
ASSERT(res == 1);
|
ASSERT(res);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
i32 res = stbir_resize_uint8(src.begin(), w, h, 0, dst.begin(), dst_w, dst_h, 0, 4);
|
u8* res = stbir_resize_uint8_linear(src.begin(), w, h, 0, dst.begin(), dst_w, dst_h, 0, STBIR_RGBA);
|
||||||
ASSERT(res == 1);
|
ASSERT(res);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1523,7 +1517,7 @@ struct TexturePlugin final : AssetBrowser::IPlugin, AssetCompiler::IPlugin {
|
||||||
const CompositeTexture::Image& layer0 = res.layers[0];
|
const CompositeTexture::Image& layer0 = res.layers[0];
|
||||||
if (layer0.channels != 4) return;
|
if (layer0.channels != 4) return;
|
||||||
|
|
||||||
stbir_resize_uint8(layer0.asU8().data(),
|
stbir_resize_uint8_linear(layer0.asU8().data(),
|
||||||
layer0.w,
|
layer0.w,
|
||||||
layer0.h,
|
layer0.h,
|
||||||
0,
|
0,
|
||||||
|
@ -1531,7 +1525,7 @@ struct TexturePlugin final : AssetBrowser::IPlugin, AssetCompiler::IPlugin {
|
||||||
AssetBrowser::TILE_SIZE,
|
AssetBrowser::TILE_SIZE,
|
||||||
AssetBrowser::TILE_SIZE,
|
AssetBrowser::TILE_SIZE,
|
||||||
0,
|
0,
|
||||||
4);
|
STBIR_RGBA);
|
||||||
|
|
||||||
applyTint();
|
applyTint();
|
||||||
|
|
||||||
|
@ -1548,7 +1542,7 @@ struct TexturePlugin final : AssetBrowser::IPlugin, AssetCompiler::IPlugin {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
stbir_resize_uint8(data,
|
stbir_resize_uint8_linear(data,
|
||||||
w,
|
w,
|
||||||
h,
|
h,
|
||||||
0,
|
0,
|
||||||
|
@ -1556,7 +1550,7 @@ struct TexturePlugin final : AssetBrowser::IPlugin, AssetCompiler::IPlugin {
|
||||||
AssetBrowser::TILE_SIZE,
|
AssetBrowser::TILE_SIZE,
|
||||||
AssetBrowser::TILE_SIZE,
|
AssetBrowser::TILE_SIZE,
|
||||||
0,
|
0,
|
||||||
4);
|
STBIR_RGBA);
|
||||||
stbi_image_free(data);
|
stbi_image_free(data);
|
||||||
|
|
||||||
applyTint();
|
applyTint();
|
||||||
|
|
|
@ -6,4 +6,4 @@
|
||||||
#pragma warning(disable : 4312)
|
#pragma warning(disable : 4312)
|
||||||
#endif
|
#endif
|
||||||
#include "stb/stb_image.h"
|
#include "stb/stb_image.h"
|
||||||
#include "stb/stb_image_resize.h"
|
#include "stb/stb_image_resize2.h"
|
||||||
|
|
|
@ -791,162 +791,6 @@ Terrain* TerrainEditor::getTerrain() const {
|
||||||
return module->getTerrain(selected_entities[0]);
|
return module->getTerrain(selected_entities[0]);
|
||||||
}
|
}
|
||||||
|
|
||||||
struct PrefabProbability {
|
|
||||||
PrefabResource* resource;
|
|
||||||
Vec4 distances;
|
|
||||||
Vec2 scale;
|
|
||||||
Vec2 y_offset;
|
|
||||||
float multiplier = 1.f;
|
|
||||||
};
|
|
||||||
|
|
||||||
struct ModelProbability {
|
|
||||||
Model* resource;
|
|
||||||
Vec4 distances;
|
|
||||||
Vec2 scale;
|
|
||||||
Vec2 y_offset;
|
|
||||||
float multiplier = 1.f;
|
|
||||||
};
|
|
||||||
|
|
||||||
static void getPrefabs(StudioApp& app, lua_State* L, i32 idx, const char* key, Array<PrefabProbability>& prefabs) {
|
|
||||||
const int type = LuaWrapper::getField(L, idx, key);
|
|
||||||
if (type == LUA_TNIL) luaL_error(L, "missing `%s`", key);
|
|
||||||
if (type != LUA_TTABLE) luaL_error(L, "`%s` is not a table", key);
|
|
||||||
|
|
||||||
WorldEditor& editor = app.getWorldEditor();
|
|
||||||
ResourceManagerHub& rm = editor.getEngine().getResourceManager();
|
|
||||||
|
|
||||||
const i32 n = (int)lua_objlen(L, -1);
|
|
||||||
for (i32 i = 0; i < n; ++i) {
|
|
||||||
lua_rawgeti(L, -1, i + 1);
|
|
||||||
if(lua_istable(L, -1)) {
|
|
||||||
if (LuaWrapper::getField(L, -1, "prefab") != LUA_TSTRING) {
|
|
||||||
lua_pop(L, 1);
|
|
||||||
luaL_argerror(L, idx, "'prefab' is not string or is missing");
|
|
||||||
}
|
|
||||||
const char* prefab_path = LuaWrapper::toType<const char*>(L, -1);
|
|
||||||
PrefabResource* res = rm.load<PrefabResource>(Path(prefab_path));
|
|
||||||
lua_pop(L, 1);
|
|
||||||
lua_getfield(L, -1, "distances");
|
|
||||||
if (!LuaWrapper::isType<Vec4>(L, -1)) {
|
|
||||||
lua_pop(L, 1);
|
|
||||||
res->decRefCount();
|
|
||||||
luaL_argerror(L, idx, "'distances' is not vec4 or is missing");
|
|
||||||
}
|
|
||||||
const Vec4 distances = LuaWrapper::toType<Vec4>(L, -1);
|
|
||||||
lua_pop(L, 1);
|
|
||||||
|
|
||||||
Vec2 scale = Vec2(1, 1);
|
|
||||||
LuaWrapper::getOptionalField(L, -1, "scale", &scale);
|
|
||||||
Vec2 y_offset = Vec2(0, 0);
|
|
||||||
LuaWrapper::getOptionalField(L, -1, "y_offset", &y_offset);
|
|
||||||
|
|
||||||
PrefabProbability& prob = prefabs.emplace();
|
|
||||||
LuaWrapper::getOptionalField(L, -1, "multiplier", &prob.multiplier);
|
|
||||||
prob.resource = res;
|
|
||||||
prob.distances = distances;
|
|
||||||
prob.scale = scale;
|
|
||||||
prob.y_offset = y_offset;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
lua_pop(L, 1);
|
|
||||||
luaL_argerror(L, idx, "table of prefabs expected");
|
|
||||||
}
|
|
||||||
lua_pop(L, 1);
|
|
||||||
}
|
|
||||||
|
|
||||||
lua_pop(L, 1);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void getModels(StudioApp& app, lua_State* L, i32 idx, const char* key, Array<ModelProbability>& prefabs) {
|
|
||||||
const int type = LuaWrapper::getField(L, idx, key);
|
|
||||||
if (type == LUA_TNIL) luaL_error(L, "missing `%s`", key);
|
|
||||||
if (type != LUA_TTABLE) luaL_error(L, "`%s` is not a table", key);
|
|
||||||
|
|
||||||
WorldEditor& editor = app.getWorldEditor();
|
|
||||||
ResourceManagerHub& rm = editor.getEngine().getResourceManager();
|
|
||||||
|
|
||||||
const i32 n = (int)lua_objlen(L, -1);
|
|
||||||
for (i32 i = 0; i < n; ++i) {
|
|
||||||
lua_rawgeti(L, -1, i + 1);
|
|
||||||
if(lua_istable(L, -1)) {
|
|
||||||
if (LuaWrapper::getField(L, -1, "model") != LUA_TSTRING) {
|
|
||||||
lua_pop(L, 1);
|
|
||||||
luaL_argerror(L, idx, "'model' is not string or is missing");
|
|
||||||
}
|
|
||||||
const char* prefab_path = LuaWrapper::toType<const char*>(L, -1);
|
|
||||||
Model* res = rm.load<Model>(Path(prefab_path));
|
|
||||||
lua_pop(L, 1);
|
|
||||||
lua_getfield(L, -1, "distances");
|
|
||||||
if (!LuaWrapper::isType<Vec4>(L, -1)) {
|
|
||||||
lua_pop(L, 1);
|
|
||||||
res->decRefCount();
|
|
||||||
luaL_argerror(L, idx, "'distances' is not vec4 or is missing");
|
|
||||||
}
|
|
||||||
const Vec4 distances = LuaWrapper::toType<Vec4>(L, -1);
|
|
||||||
lua_pop(L, 1);
|
|
||||||
if (distances.x > distances.w) {
|
|
||||||
res->decRefCount();
|
|
||||||
luaL_argerror(L, idx, "'distances' are not sorted");
|
|
||||||
}
|
|
||||||
|
|
||||||
Vec2 scale = Vec2(1, 1);
|
|
||||||
LuaWrapper::getOptionalField(L, -1, "scale", &scale);
|
|
||||||
Vec2 y_offset = Vec2(0, 0);
|
|
||||||
LuaWrapper::getOptionalField(L, -1, "y_offset", &y_offset);
|
|
||||||
|
|
||||||
ModelProbability& prob = prefabs.emplace();
|
|
||||||
LuaWrapper::getOptionalField(L, -1, "multiplier", &prob.multiplier);
|
|
||||||
prob.resource = res;
|
|
||||||
prob.distances = distances;
|
|
||||||
prob.scale = scale;
|
|
||||||
prob.y_offset = y_offset;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
lua_pop(L, 1);
|
|
||||||
luaL_argerror(L, idx, "table of models expected");
|
|
||||||
}
|
|
||||||
lua_pop(L, 1);
|
|
||||||
}
|
|
||||||
|
|
||||||
lua_pop(L, 1);
|
|
||||||
}
|
|
||||||
|
|
||||||
template <typename T>
|
|
||||||
static u32 getRandomItem(float distance, const Array<T>& probs) {
|
|
||||||
float sum = 0;
|
|
||||||
|
|
||||||
auto get = [](float distance, const T& prob){
|
|
||||||
if (distance < prob.distances.x) return 0.f;
|
|
||||||
if (distance > prob.distances.w) return 0.f;
|
|
||||||
|
|
||||||
if (distance < prob.distances.y) {
|
|
||||||
return prob.multiplier * (distance - prob.distances.x) / (prob.distances.y - prob.distances.x);
|
|
||||||
}
|
|
||||||
else if (distance < prob.distances.z) {
|
|
||||||
return prob.multiplier;
|
|
||||||
}
|
|
||||||
return prob.multiplier * (1 - (distance - prob.distances.z) / (prob.distances.w - prob.distances.z));
|
|
||||||
};
|
|
||||||
|
|
||||||
for (const T& prob : probs) {
|
|
||||||
sum += get(distance, prob);
|
|
||||||
}
|
|
||||||
if (sum == 0) return 0xffFFffFF;
|
|
||||||
|
|
||||||
float r = randFloat() * sum;
|
|
||||||
|
|
||||||
for (i32 i = 0; i < probs.size(); ++i) {
|
|
||||||
const T& prob = probs[i];
|
|
||||||
float p = get(distance, prob);
|
|
||||||
if (r < p) return i;
|
|
||||||
r -= p;
|
|
||||||
}
|
|
||||||
|
|
||||||
ASSERT(false);
|
|
||||||
return 0xffFFffFF;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void TerrainEditor::increaseBrushSize()
|
void TerrainEditor::increaseBrushSize()
|
||||||
{
|
{
|
||||||
if (m_terrain_brush_size < 10)
|
if (m_terrain_brush_size < 10)
|
||||||
|
|
|
@ -336,7 +336,6 @@ int import(lua_State* L)
|
||||||
{
|
{
|
||||||
const char* path = LuaWrapper::checkArg<const char*>(L, 1);
|
const char* path = LuaWrapper::checkArg<const char*>(L, 1);
|
||||||
Shader* shader = getShader(L);
|
Shader* shader = getShader(L);
|
||||||
FileSystem& fs = shader->m_renderer.getEngine().getFileSystem();
|
|
||||||
|
|
||||||
OutputMemoryStream content(shader->m_allocator);
|
OutputMemoryStream content(shader->m_allocator);
|
||||||
ResourceManagerHub& rm = shader->getResourceManager().getOwner();
|
ResourceManagerHub& rm = shader->getResourceManager().getOwner();
|
||||||
|
@ -359,7 +358,6 @@ int include(lua_State* L)
|
||||||
|
|
||||||
Shader* shader = getShader(L);
|
Shader* shader = getShader(L);
|
||||||
|
|
||||||
FileSystem& fs = shader->m_renderer.getEngine().getFileSystem();
|
|
||||||
ResourceManagerHub& rm = shader->getResourceManager().getOwner();
|
ResourceManagerHub& rm = shader->getResourceManager().getOwner();
|
||||||
|
|
||||||
OutputMemoryStream content(shader->m_allocator);
|
OutputMemoryStream content(shader->m_allocator);
|
||||||
|
|
Loading…
Reference in a new issue