Fix includes and compile for GridMap. Still not enabled.

This commit is contained in:
Relintai 2022-10-08 20:42:07 +02:00
parent 0a8cf3cb3f
commit 4fa3ca949e
6 changed files with 187 additions and 148 deletions

View File

@ -41,6 +41,9 @@
#include "servers/navigation_server.h" #include "servers/navigation_server.h"
#include "servers/rendering_server.h" #include "servers/rendering_server.h"
#include "scene/resources/world_3d.h"
#include "scene/resources/navigation_mesh.h"
bool GridMap::_set(const StringName &p_name, const Variant &p_value) { bool GridMap::_set(const StringName &p_name, const Variant &p_value) {
String name = p_name; String name = p_name;
@ -73,13 +76,13 @@ bool GridMap::_set(const StringName &p_name, const Variant &p_value) {
BakedMesh bm; BakedMesh bm;
bm.mesh = meshes[i]; bm.mesh = meshes[i];
ERR_CONTINUE(!bm.mesh.is_valid()); ERR_CONTINUE(!bm.mesh.is_valid());
bm.instance = RID_PRIME(VS::get_singleton()->instance_create()); bm.instance = RID_PRIME(RS::get_singleton()->instance_create());
VS::get_singleton()->instance_set_portal_mode(bm.instance, RenderingServer::InstancePortalMode::INSTANCE_PORTAL_MODE_GLOBAL); RS::get_singleton()->instance_set_portal_mode(bm.instance, RenderingServer::InstancePortalMode::INSTANCE_PORTAL_MODE_GLOBAL);
VS::get_singleton()->get_singleton()->instance_set_base(bm.instance, bm.mesh->get_rid()); RS::get_singleton()->get_singleton()->instance_set_base(bm.instance, bm.mesh->get_rid());
VS::get_singleton()->instance_attach_object_instance_id(bm.instance, get_instance_id()); RS::get_singleton()->instance_attach_object_instance_id(bm.instance, get_instance_id());
if (is_inside_tree()) { if (is_inside_tree()) {
VS::get_singleton()->instance_set_scenario(bm.instance, get_world()->get_scenario()); RS::get_singleton()->instance_set_scenario(bm.instance, get_world_3d()->get_scenario());
VS::get_singleton()->instance_set_transform(bm.instance, get_global_transform()); RS::get_singleton()->instance_set_transform(bm.instance, get_global_transform());
} }
baked_meshes.push_back(bm); baked_meshes.push_back(bm);
} }
@ -357,7 +360,7 @@ void GridMap::set_cell_item(int p_x, int p_y, int p_z, int p_item, int p_rot) {
if (st && st->is_debugging_collisions_hint()) { if (st && st->is_debugging_collisions_hint()) {
g->collision_debug = RID_PRIME(RenderingServer::get_singleton()->mesh_create()); g->collision_debug = RID_PRIME(RenderingServer::get_singleton()->mesh_create());
g->collision_debug_instance = RID_PRIME(RenderingServer::get_singleton()->instance_create()); g->collision_debug_instance = RID_PRIME(RenderingServer::get_singleton()->instance_create());
VS::get_singleton()->instance_set_portal_mode(g->collision_debug_instance, RenderingServer::InstancePortalMode::INSTANCE_PORTAL_MODE_GLOBAL); RS::get_singleton()->instance_set_portal_mode(g->collision_debug_instance, RenderingServer::InstancePortalMode::INSTANCE_PORTAL_MODE_GLOBAL);
RenderingServer::get_singleton()->instance_set_base(g->collision_debug_instance, g->collision_debug); RenderingServer::get_singleton()->instance_set_base(g->collision_debug_instance, g->collision_debug);
} }
@ -436,7 +439,7 @@ void GridMap::_octant_transform(const OctantKey &p_key) {
PhysicsServer::get_singleton()->body_set_state(g.static_body, PhysicsServer::BODY_STATE_TRANSFORM, get_global_transform()); PhysicsServer::get_singleton()->body_set_state(g.static_body, PhysicsServer::BODY_STATE_TRANSFORM, get_global_transform());
if (g.collision_debug_instance.is_valid()) { if (g.collision_debug_instance.is_valid()) {
VS::get_singleton()->instance_set_transform(g.collision_debug_instance, get_global_transform()); RS::get_singleton()->instance_set_transform(g.collision_debug_instance, get_global_transform());
} }
// update transform for NavigationServer regions and navigation debugmesh instances // update transform for NavigationServer regions and navigation debugmesh instances
@ -446,13 +449,13 @@ void GridMap::_octant_transform(const OctantKey &p_key) {
NavigationServer::get_singleton()->region_set_transform(E->get().region, get_global_transform() * E->get().xform); NavigationServer::get_singleton()->region_set_transform(E->get().region, get_global_transform() * E->get().xform);
} }
if (E->get().navmesh_debug_instance.is_valid()) { if (E->get().navmesh_debug_instance.is_valid()) {
VS::get_singleton()->instance_set_transform(E->get().navmesh_debug_instance, get_global_transform() * E->get().xform); RS::get_singleton()->instance_set_transform(E->get().navmesh_debug_instance, get_global_transform() * E->get().xform);
} }
} }
} }
for (int i = 0; i < g.multimesh_instances.size(); i++) { for (int i = 0; i < g.multimesh_instances.size(); i++) {
VS::get_singleton()->instance_set_transform(g.multimesh_instances[i].instance, get_global_transform()); RS::get_singleton()->instance_set_transform(g.multimesh_instances[i].instance, get_global_transform());
} }
} }
@ -468,14 +471,14 @@ bool GridMap::_octant_update(const OctantKey &p_key) {
//erase body shapes debug //erase body shapes debug
if (g.collision_debug.is_valid()) { if (g.collision_debug.is_valid()) {
VS::get_singleton()->mesh_clear(g.collision_debug); RS::get_singleton()->mesh_clear(g.collision_debug);
} }
//erase navigation //erase navigation
for (Map<IndexKey, Octant::NavMesh>::Element *E = g.navmesh_ids.front(); E; E = E->next()) { for (Map<IndexKey, Octant::NavMesh>::Element *E = g.navmesh_ids.front(); E; E = E->next()) {
NavigationServer::get_singleton()->free(E->get().region); NavigationServer::get_singleton()->free(E->get().region);
if (E->get().navmesh_debug_instance.is_valid()) { if (E->get().navmesh_debug_instance.is_valid()) {
VS::get_singleton()->free(E->get().navmesh_debug_instance); RS::get_singleton()->free(E->get().navmesh_debug_instance);
} }
} }
g.navmesh_ids.clear(); g.navmesh_ids.clear();
@ -484,10 +487,10 @@ bool GridMap::_octant_update(const OctantKey &p_key) {
for (int i = 0; i < g.multimesh_instances.size(); i++) { for (int i = 0; i < g.multimesh_instances.size(); i++) {
if (g.multimesh_instances[i].instance.is_valid()) { if (g.multimesh_instances[i].instance.is_valid()) {
VS::get_singleton()->free(g.multimesh_instances[i].instance); RS::get_singleton()->free(g.multimesh_instances[i].instance);
} }
if (g.multimesh_instances[i].multimesh.is_valid()) { if (g.multimesh_instances[i].multimesh.is_valid()) {
VS::get_singleton()->free(g.multimesh_instances[i].multimesh); RS::get_singleton()->free(g.multimesh_instances[i].multimesh);
} }
} }
g.multimesh_instances.clear(); g.multimesh_instances.clear();
@ -564,7 +567,7 @@ bool GridMap::_octant_update(const OctantKey &p_key) {
if (navigation) { if (navigation) {
NavigationServer::get_singleton()->region_set_map(region, navigation->get_rid()); NavigationServer::get_singleton()->region_set_map(region, navigation->get_rid());
} else { } else {
NavigationServer::get_singleton()->region_set_map(region, get_world()->get_navigation_map()); NavigationServer::get_singleton()->region_set_map(region, get_world_3d()->get_navigation_map());
} }
nm.region = region; nm.region = region;
@ -573,13 +576,13 @@ bool GridMap::_octant_update(const OctantKey &p_key) {
if (st && st->is_debugging_navigation_hint()) { if (st && st->is_debugging_navigation_hint()) {
if (!nm.navmesh_debug_instance.is_valid()) { if (!nm.navmesh_debug_instance.is_valid()) {
RID navmesh_debug_rid = navmesh->get_debug_mesh()->get_rid(); RID navmesh_debug_rid = navmesh->get_debug_mesh()->get_rid();
nm.navmesh_debug_instance = VS::get_singleton()->instance_create(); nm.navmesh_debug_instance = RS::get_singleton()->instance_create();
VS::get_singleton()->instance_set_base(nm.navmesh_debug_instance, navmesh_debug_rid); RS::get_singleton()->instance_set_base(nm.navmesh_debug_instance, navmesh_debug_rid);
VS::get_singleton()->mesh_surface_set_material(navmesh_debug_rid, 0, st->get_debug_navigation_material()->get_rid()); RS::get_singleton()->mesh_surface_set_material(navmesh_debug_rid, 0, st->get_debug_navigation_material()->get_rid());
} }
if (is_inside_tree()) { if (is_inside_tree()) {
VS::get_singleton()->instance_set_scenario(nm.navmesh_debug_instance, get_world()->get_scenario()); RS::get_singleton()->instance_set_scenario(nm.navmesh_debug_instance, get_world_3d()->get_scenario());
VS::get_singleton()->instance_set_transform(nm.navmesh_debug_instance, get_global_transform() * nm.xform); RS::get_singleton()->instance_set_transform(nm.navmesh_debug_instance, get_global_transform() * nm.xform);
} }
} }
} }
@ -592,13 +595,13 @@ bool GridMap::_octant_update(const OctantKey &p_key) {
for (Map<int, List<Pair<Transform, IndexKey>>>::Element *E = multimesh_items.front(); E; E = E->next()) { for (Map<int, List<Pair<Transform, IndexKey>>>::Element *E = multimesh_items.front(); E; E = E->next()) {
Octant::MultimeshInstance mmi; Octant::MultimeshInstance mmi;
RID mm = RID_PRIME(VS::get_singleton()->multimesh_create()); RID mm = RID_PRIME(RS::get_singleton()->multimesh_create());
VS::get_singleton()->multimesh_allocate(mm, E->get().size(), VS::MULTIMESH_TRANSFORM_3D, VS::MULTIMESH_COLOR_NONE); RS::get_singleton()->multimesh_allocate(mm, E->get().size(), RS::MULTIMESH_TRANSFORM_3D, RS::MULTIMESH_COLOR_NONE);
VS::get_singleton()->multimesh_set_mesh(mm, mesh_library->get_item_mesh(E->key())->get_rid()); RS::get_singleton()->multimesh_set_mesh(mm, mesh_library->get_item_mesh(E->key())->get_rid());
int idx = 0; int idx = 0;
for (List<Pair<Transform, IndexKey>>::Element *F = E->get().front(); F; F = F->next()) { for (List<Pair<Transform, IndexKey>>::Element *F = E->get().front(); F; F = F->next()) {
VS::get_singleton()->multimesh_instance_set_transform(mm, idx, F->get().first); RS::get_singleton()->multimesh_instance_set_transform(mm, idx, F->get().first);
#ifdef TOOLS_ENABLED #ifdef TOOLS_ENABLED
Octant::MultimeshInstance::Item it; Octant::MultimeshInstance::Item it;
@ -611,13 +614,13 @@ bool GridMap::_octant_update(const OctantKey &p_key) {
idx++; idx++;
} }
RID instance = RID_PRIME(VS::get_singleton()->instance_create()); RID instance = RID_PRIME(RS::get_singleton()->instance_create());
VS::get_singleton()->instance_set_base(instance, mm); RS::get_singleton()->instance_set_base(instance, mm);
VS::get_singleton()->instance_set_portal_mode(instance, RenderingServer::InstancePortalMode::INSTANCE_PORTAL_MODE_GLOBAL); RS::get_singleton()->instance_set_portal_mode(instance, RenderingServer::InstancePortalMode::INSTANCE_PORTAL_MODE_GLOBAL);
if (is_inside_tree()) { if (is_inside_tree()) {
VS::get_singleton()->instance_set_scenario(instance, get_world()->get_scenario()); RS::get_singleton()->instance_set_scenario(instance, get_world_3d()->get_scenario());
VS::get_singleton()->instance_set_transform(instance, get_global_transform()); RS::get_singleton()->instance_set_transform(instance, get_global_transform());
} }
mmi.multimesh = mm; mmi.multimesh = mm;
@ -629,13 +632,13 @@ bool GridMap::_octant_update(const OctantKey &p_key) {
if (col_debug.size()) { if (col_debug.size()) {
Array arr; Array arr;
arr.resize(VS::ARRAY_MAX); arr.resize(RS::ARRAY_MAX);
arr[VS::ARRAY_VERTEX] = col_debug; arr[RS::ARRAY_VERTEX] = col_debug;
VS::get_singleton()->mesh_add_surface_from_arrays(g.collision_debug, VS::PRIMITIVE_LINES, arr); RS::get_singleton()->mesh_add_surface_from_arrays(g.collision_debug, RS::PRIMITIVE_LINES, arr);
SceneTree *st = SceneTree::get_singleton(); SceneTree *st = SceneTree::get_singleton();
if (st) { if (st) {
VS::get_singleton()->mesh_surface_set_material(g.collision_debug, 0, st->get_debug_collision_material()->get_rid()); RS::get_singleton()->mesh_surface_set_material(g.collision_debug, 0, st->get_debug_collision_material()->get_rid());
} }
} }
@ -655,16 +658,16 @@ void GridMap::_octant_enter_world(const OctantKey &p_key) {
ERR_FAIL_COND(!octant_map.has(p_key)); ERR_FAIL_COND(!octant_map.has(p_key));
Octant &g = *octant_map[p_key]; Octant &g = *octant_map[p_key];
PhysicsServer::get_singleton()->body_set_state(g.static_body, PhysicsServer::BODY_STATE_TRANSFORM, get_global_transform()); PhysicsServer::get_singleton()->body_set_state(g.static_body, PhysicsServer::BODY_STATE_TRANSFORM, get_global_transform());
PhysicsServer::get_singleton()->body_set_space(g.static_body, get_world()->get_space()); PhysicsServer::get_singleton()->body_set_space(g.static_body, get_world_3d()->get_space());
if (g.collision_debug_instance.is_valid()) { if (g.collision_debug_instance.is_valid()) {
VS::get_singleton()->instance_set_scenario(g.collision_debug_instance, get_world()->get_scenario()); RS::get_singleton()->instance_set_scenario(g.collision_debug_instance, get_world_3d()->get_scenario());
VS::get_singleton()->instance_set_transform(g.collision_debug_instance, get_global_transform()); RS::get_singleton()->instance_set_transform(g.collision_debug_instance, get_global_transform());
} }
for (int i = 0; i < g.multimesh_instances.size(); i++) { for (int i = 0; i < g.multimesh_instances.size(); i++) {
VS::get_singleton()->instance_set_scenario(g.multimesh_instances[i].instance, get_world()->get_scenario()); RS::get_singleton()->instance_set_scenario(g.multimesh_instances[i].instance, get_world_3d()->get_scenario());
VS::get_singleton()->instance_set_transform(g.multimesh_instances[i].instance, get_global_transform()); RS::get_singleton()->instance_set_transform(g.multimesh_instances[i].instance, get_global_transform());
} }
if (bake_navigation && mesh_library.is_valid()) { if (bake_navigation && mesh_library.is_valid()) {
@ -679,7 +682,7 @@ void GridMap::_octant_enter_world(const OctantKey &p_key) {
if (navigation) { if (navigation) {
NavigationServer::get_singleton()->region_set_map(region, navigation->get_rid()); NavigationServer::get_singleton()->region_set_map(region, navigation->get_rid());
} else { } else {
NavigationServer::get_singleton()->region_set_map(region, get_world()->get_navigation_map()); NavigationServer::get_singleton()->region_set_map(region, get_world_3d()->get_navigation_map());
} }
E->get().region = region; E->get().region = region;
} }
@ -695,11 +698,11 @@ void GridMap::_octant_exit_world(const OctantKey &p_key) {
PhysicsServer::get_singleton()->body_set_space(g.static_body, RID()); PhysicsServer::get_singleton()->body_set_space(g.static_body, RID());
if (g.collision_debug_instance.is_valid()) { if (g.collision_debug_instance.is_valid()) {
VS::get_singleton()->instance_set_scenario(g.collision_debug_instance, RID()); RS::get_singleton()->instance_set_scenario(g.collision_debug_instance, RID());
} }
for (int i = 0; i < g.multimesh_instances.size(); i++) { for (int i = 0; i < g.multimesh_instances.size(); i++) {
VS::get_singleton()->instance_set_scenario(g.multimesh_instances[i].instance, RID()); RS::get_singleton()->instance_set_scenario(g.multimesh_instances[i].instance, RID());
} }
for (Map<IndexKey, Octant::NavMesh>::Element *E = g.navmesh_ids.front(); E; E = E->next()) { for (Map<IndexKey, Octant::NavMesh>::Element *E = g.navmesh_ids.front(); E; E = E->next()) {
@ -708,7 +711,7 @@ void GridMap::_octant_exit_world(const OctantKey &p_key) {
E->get().region = RID(); E->get().region = RID();
} }
if (E->get().navmesh_debug_instance.is_valid()) { if (E->get().navmesh_debug_instance.is_valid()) {
VS::get_singleton()->free(E->get().navmesh_debug_instance); RS::get_singleton()->free(E->get().navmesh_debug_instance);
E->get().navmesh_debug_instance = RID(); E->get().navmesh_debug_instance = RID();
} }
} }
@ -719,12 +722,12 @@ void GridMap::_octant_clean_up(const OctantKey &p_key) {
Octant &g = *octant_map[p_key]; Octant &g = *octant_map[p_key];
if (g.collision_debug.is_valid()) { if (g.collision_debug.is_valid()) {
VS::get_singleton()->free(g.collision_debug); RS::get_singleton()->free(g.collision_debug);
g.collision_debug = RID(); g.collision_debug = RID();
} }
if (g.collision_debug_instance.is_valid()) { if (g.collision_debug_instance.is_valid()) {
VS::get_singleton()->free(g.collision_debug_instance); RS::get_singleton()->free(g.collision_debug_instance);
g.collision_debug_instance = RID(); g.collision_debug_instance = RID();
} }
@ -739,7 +742,7 @@ void GridMap::_octant_clean_up(const OctantKey &p_key) {
NavigationServer::get_singleton()->free(E->get().region); NavigationServer::get_singleton()->free(E->get().region);
} }
if (E->get().navmesh_debug_instance.is_valid()) { if (E->get().navmesh_debug_instance.is_valid()) {
VS::get_singleton()->free(E->get().navmesh_debug_instance); RS::get_singleton()->free(E->get().navmesh_debug_instance);
} }
} }
g.navmesh_ids.clear(); g.navmesh_ids.clear();
@ -748,10 +751,10 @@ void GridMap::_octant_clean_up(const OctantKey &p_key) {
for (int i = 0; i < g.multimesh_instances.size(); i++) { for (int i = 0; i < g.multimesh_instances.size(); i++) {
if (g.multimesh_instances[i].instance.is_valid()) { if (g.multimesh_instances[i].instance.is_valid()) {
VS::get_singleton()->free(g.multimesh_instances[i].instance); RS::get_singleton()->free(g.multimesh_instances[i].instance);
} }
if (g.multimesh_instances[i].multimesh.is_valid()) { if (g.multimesh_instances[i].multimesh.is_valid()) {
VS::get_singleton()->free(g.multimesh_instances[i].multimesh); RS::get_singleton()->free(g.multimesh_instances[i].multimesh);
} }
} }
g.multimesh_instances.clear(); g.multimesh_instances.clear();
@ -777,8 +780,8 @@ void GridMap::_notification(int p_what) {
} }
for (int i = 0; i < baked_meshes.size(); i++) { for (int i = 0; i < baked_meshes.size(); i++) {
VS::get_singleton()->instance_set_scenario(baked_meshes[i].instance, get_world()->get_scenario()); RS::get_singleton()->instance_set_scenario(baked_meshes[i].instance, get_world_3d()->get_scenario());
VS::get_singleton()->instance_set_transform(baked_meshes[i].instance, get_global_transform()); RS::get_singleton()->instance_set_transform(baked_meshes[i].instance, get_global_transform());
} }
} break; } break;
@ -795,7 +798,7 @@ void GridMap::_notification(int p_what) {
last_transform = new_xform; last_transform = new_xform;
for (int i = 0; i < baked_meshes.size(); i++) { for (int i = 0; i < baked_meshes.size(); i++) {
VS::get_singleton()->instance_set_transform(baked_meshes[i].instance, get_global_transform()); RS::get_singleton()->instance_set_transform(baked_meshes[i].instance, get_global_transform());
} }
} break; } break;
@ -810,7 +813,7 @@ void GridMap::_notification(int p_what) {
//_update_octants_callback(); //_update_octants_callback();
//_update_area_instances(); //_update_area_instances();
for (int i = 0; i < baked_meshes.size(); i++) { for (int i = 0; i < baked_meshes.size(); i++) {
VS::get_singleton()->instance_set_scenario(baked_meshes[i].instance, RID()); RS::get_singleton()->instance_set_scenario(baked_meshes[i].instance, RID());
} }
} break; } break;
@ -831,12 +834,12 @@ void GridMap::_update_visibility() {
Octant *octant = e->value(); Octant *octant = e->value();
for (int i = 0; i < octant->multimesh_instances.size(); i++) { for (int i = 0; i < octant->multimesh_instances.size(); i++) {
const Octant::MultimeshInstance &mi = octant->multimesh_instances[i]; const Octant::MultimeshInstance &mi = octant->multimesh_instances[i];
VS::get_singleton()->instance_set_visible(mi.instance, is_visible_in_tree()); RS::get_singleton()->instance_set_visible(mi.instance, is_visible_in_tree());
} }
} }
for (int i = 0; i < baked_meshes.size(); i++) { for (int i = 0; i < baked_meshes.size(); i++) {
VS::get_singleton()->instance_set_visible(baked_meshes[i].instance, is_visible_in_tree()); RS::get_singleton()->instance_set_visible(baked_meshes[i].instance, is_visible_in_tree());
} }
} }
@ -1094,7 +1097,7 @@ Vector3 GridMap::_get_offset() const {
void GridMap::clear_baked_meshes() { void GridMap::clear_baked_meshes() {
for (int i = 0; i < baked_meshes.size(); i++) { for (int i = 0; i < baked_meshes.size(); i++) {
if (baked_meshes[i].instance.is_valid()) { if (baked_meshes[i].instance.is_valid()) {
VS::get_singleton()->free(baked_meshes[i].instance); RS::get_singleton()->free(baked_meshes[i].instance);
} }
} }
baked_meshes.clear(); baked_meshes.clear();
@ -1170,17 +1173,17 @@ void GridMap::make_baked_meshes(bool p_gen_lightmap_uv, float p_lightmap_uv_texe
BakedMesh bm; BakedMesh bm;
bm.mesh = mesh; bm.mesh = mesh;
bm.instance = RID_PRIME(VS::get_singleton()->instance_create()); bm.instance = RID_PRIME(RS::get_singleton()->instance_create());
VS::get_singleton()->instance_set_portal_mode(bm.instance, RenderingServer::InstancePortalMode::INSTANCE_PORTAL_MODE_GLOBAL); RS::get_singleton()->instance_set_portal_mode(bm.instance, RenderingServer::InstancePortalMode::INSTANCE_PORTAL_MODE_GLOBAL);
VS::get_singleton()->get_singleton()->instance_set_base(bm.instance, bm.mesh->get_rid()); RS::get_singleton()->get_singleton()->instance_set_base(bm.instance, bm.mesh->get_rid());
VS::get_singleton()->instance_attach_object_instance_id(bm.instance, get_instance_id()); RS::get_singleton()->instance_attach_object_instance_id(bm.instance, get_instance_id());
if (is_inside_tree()) { if (is_inside_tree()) {
VS::get_singleton()->instance_set_scenario(bm.instance, get_world()->get_scenario()); RS::get_singleton()->instance_set_scenario(bm.instance, get_world_3d()->get_scenario());
VS::get_singleton()->instance_set_transform(bm.instance, get_global_transform()); RS::get_singleton()->instance_set_transform(bm.instance, get_global_transform());
} }
if (p_gen_lightmap_uv) { if (p_gen_lightmap_uv) {
mesh->lightmap_unwrap(get_global_transform(), p_lightmap_uv_texel_size); //mesh->lightmap_unwrap(get_global_transform(), p_lightmap_uv_texel_size);
} }
baked_meshes.push_back(bm); baked_meshes.push_back(bm);
} }

View File

@ -165,10 +165,10 @@ class GridMap : public Spatial {
void _recreate_octant_data(); void _recreate_octant_data();
struct BakeLight { struct BakeLight {
VS::LightType type; RS::LightType type;
Vector3 pos; Vector3 pos;
Vector3 dir; Vector3 dir;
float param[VS::LIGHT_PARAM_MAX]; float param[RS::LIGHT_PARAM_MAX];
}; };
_FORCE_INLINE_ Vector3 _octant_get_offset(const OctantKey &p_key) const { _FORCE_INLINE_ Vector3 _octant_get_offset(const OctantKey &p_key) const {

View File

@ -38,6 +38,22 @@
#include "core/math/geometry.h" #include "core/math/geometry.h"
#include "core/os/keyboard.h" #include "core/os/keyboard.h"
#include "core/object/undo_redo.h"
#include "scene/gui/dialogs.h"
#include "scene/gui/item_list.h"
#include "scene/gui/label.h"
#include "scene/gui/line_edit.h"
#include "scene/gui/menu_button.h"
#include "scene/gui/panel.h"
#include "scene/gui/popup_menu.h"
#include "scene/gui/separator.h"
#include "scene/gui/slider.h"
#include "scene/gui/spin_box.h"
#include "scene/gui/tool_button.h"
#include "scene/main/viewport.h"
#include "scene/resources/world_3d.h"
void GridMapEditor::_node_removed(Node *p_node) { void GridMapEditor::_node_removed(Node *p_node) {
if (p_node == node) { if (p_node == node) {
node = nullptr; node = nullptr;
@ -349,20 +365,20 @@ void GridMapEditor::_set_selection(bool p_active, const Vector3 &p_begin, const
options->get_popup()->set_item_disabled(options->get_popup()->get_item_index(MENU_OPTION_SELECTION_FILL), !selection.active); options->get_popup()->set_item_disabled(options->get_popup()->get_item_index(MENU_OPTION_SELECTION_FILL), !selection.active);
} }
bool GridMapEditor::do_input_action(Camera *p_camera, const Point2 &p_point, bool p_click) { EditorPlugin::AfterGUIInput GridMapEditor::do_input_action(Camera *p_camera, const Point2 &p_point, bool p_click) {
if (!spatial_editor) { if (!spatial_editor) {
return false; return EditorPlugin::AFTER_GUI_INPUT_PASS;
} }
if (selected_palette < 0 && input_action != INPUT_PICK && input_action != INPUT_SELECT && input_action != INPUT_PASTE) { if (selected_palette < 0 && input_action != INPUT_PICK && input_action != INPUT_SELECT && input_action != INPUT_PASTE) {
return false; return EditorPlugin::AFTER_GUI_INPUT_PASS;
} }
Ref<MeshLibrary> mesh_library = node->get_mesh_library(); Ref<MeshLibrary> mesh_library = node->get_mesh_library();
if (mesh_library.is_null()) { if (mesh_library.is_null()) {
return false; return EditorPlugin::AFTER_GUI_INPUT_PASS;
} }
if (input_action != INPUT_PICK && input_action != INPUT_SELECT && input_action != INPUT_PASTE && !mesh_library->has_item(selected_palette)) { if (input_action != INPUT_PICK && input_action != INPUT_SELECT && input_action != INPUT_PASTE && !mesh_library->has_item(selected_palette)) {
return false; return EditorPlugin::AFTER_GUI_INPUT_PASS;
} }
Camera *camera = p_camera; Camera *camera = p_camera;
@ -379,7 +395,7 @@ bool GridMapEditor::do_input_action(Camera *p_camera, const Point2 &p_point, boo
Vector3 inters; Vector3 inters;
if (!p.intersects_segment(from, from + normal * settings_pick_distance->get_value(), &inters)) { if (!p.intersects_segment(from, from + normal * settings_pick_distance->get_value(), &inters)) {
return false; return EditorPlugin::AFTER_GUI_INPUT_PASS;
} }
// Make sure the intersection is inside the frustum planes, to avoid // Make sure the intersection is inside the frustum planes, to avoid
@ -387,7 +403,7 @@ bool GridMapEditor::do_input_action(Camera *p_camera, const Point2 &p_point, boo
for (int i = 0; i < planes.size(); i++) { for (int i = 0; i < planes.size(); i++) {
Plane fp = local_xform.xform(planes[i]); Plane fp = local_xform.xform(planes[i]);
if (fp.is_point_over(inters)) { if (fp.is_point_over(inters)) {
return false; return EditorPlugin::AFTER_GUI_INPUT_PASS;
} }
} }
@ -406,7 +422,7 @@ bool GridMapEditor::do_input_action(Camera *p_camera, const Point2 &p_point, boo
} }
} }
VS::get_singleton()->instance_set_transform(grid_instance[edit_axis], node->get_global_transform() * edit_grid_xform); RS::get_singleton()->instance_set_transform(grid_instance[edit_axis], node->get_global_transform() * edit_grid_xform);
if (cursor_instance.is_valid()) { if (cursor_instance.is_valid()) {
cursor_origin = (Vector3(cell[0], cell[1], cell[2]) + Vector3(0.5 * node->get_center_x(), 0.5 * node->get_center_y(), 0.5 * node->get_center_z())) * node->get_cell_size(); cursor_origin = (Vector3(cell[0], cell[1], cell[2]) + Vector3(0.5 * node->get_center_x(), 0.5 * node->get_center_y(), 0.5 * node->get_center_z())) * node->get_cell_size();
@ -431,7 +447,7 @@ bool GridMapEditor::do_input_action(Camera *p_camera, const Point2 &p_point, boo
selection.active = true; selection.active = true;
_validate_selection(); _validate_selection();
return true; return EditorPlugin::AFTER_GUI_INPUT_STOP;
} else if (input_action == INPUT_PICK) { } else if (input_action == INPUT_PICK) {
int item = node->get_cell_item(cell[0], cell[1], cell[2]); int item = node->get_cell_item(cell[0], cell[1], cell[2]);
if (item >= 0) { if (item >= 0) {
@ -440,7 +456,7 @@ bool GridMapEditor::do_input_action(Camera *p_camera, const Point2 &p_point, boo
update_palette(); update_palette();
_update_cursor_instance(); _update_cursor_instance();
} }
return true; return EditorPlugin::AFTER_GUI_INPUT_STOP;
} }
if (input_action == INPUT_PAINT) { if (input_action == INPUT_PAINT) {
SetItem si; SetItem si;
@ -451,7 +467,7 @@ bool GridMapEditor::do_input_action(Camera *p_camera, const Point2 &p_point, boo
si.old_orientation = node->get_cell_item_orientation(cell[0], cell[1], cell[2]); si.old_orientation = node->get_cell_item_orientation(cell[0], cell[1], cell[2]);
set_items.push_back(si); set_items.push_back(si);
node->set_cell_item(cell[0], cell[1], cell[2], selected_palette, cursor_rot); node->set_cell_item(cell[0], cell[1], cell[2], selected_palette, cursor_rot);
return true; return EditorPlugin::AFTER_GUI_INPUT_STOP;
} else if (input_action == INPUT_ERASE) { } else if (input_action == INPUT_ERASE) {
SetItem si; SetItem si;
si.pos = Vector3(cell[0], cell[1], cell[2]); si.pos = Vector3(cell[0], cell[1], cell[2]);
@ -461,10 +477,10 @@ bool GridMapEditor::do_input_action(Camera *p_camera, const Point2 &p_point, boo
si.old_orientation = node->get_cell_item_orientation(cell[0], cell[1], cell[2]); si.old_orientation = node->get_cell_item_orientation(cell[0], cell[1], cell[2]);
set_items.push_back(si); set_items.push_back(si);
node->set_cell_item(cell[0], cell[1], cell[2], -1); node->set_cell_item(cell[0], cell[1], cell[2], -1);
return true; return EditorPlugin::AFTER_GUI_INPUT_STOP;
} }
return false; return EditorPlugin::AFTER_GUI_INPUT_PASS;
} }
void GridMapEditor::_delete_selection() { void GridMapEditor::_delete_selection() {
@ -534,7 +550,7 @@ void GridMapEditor::_set_clipboard_data() {
item.cell_item = itm; item.cell_item = itm;
item.grid_offset = Vector3(i, j, k) - selection.begin; item.grid_offset = Vector3(i, j, k) - selection.begin;
item.orientation = node->get_cell_item_orientation(i, j, k); item.orientation = node->get_cell_item_orientation(i, j, k);
item.instance = RenderingServer::get_singleton()->instance_create2(mesh->get_rid(), get_tree()->get_root()->get_world()->get_scenario()); item.instance = RenderingServer::get_singleton()->instance_create2(mesh->get_rid(), get_tree()->get_root()->get_world_3d()->get_scenario());
clipboard_items.push_back(item); clipboard_items.push_back(item);
} }
@ -558,7 +574,7 @@ void GridMapEditor::_update_paste_indicator() {
Basis rot; Basis rot;
rot.set_orthogonal_index(paste_indicator.orientation); rot.set_orthogonal_index(paste_indicator.orientation);
xf.basis = rot * xf.basis; xf.basis = rot * xf.basis;
xf.translate((-center * node->get_cell_size()) / scale); xf.translate_local((-center * node->get_cell_size()) / scale);
RenderingServer::get_singleton()->instance_set_transform(paste_instance, node->get_global_transform() * xf); RenderingServer::get_singleton()->instance_set_transform(paste_instance, node->get_global_transform() * xf);
@ -568,7 +584,7 @@ void GridMapEditor::_update_paste_indicator() {
xf = Transform(); xf = Transform();
xf.origin = (paste_indicator.begin + (paste_indicator.current - paste_indicator.click) + center) * node->get_cell_size(); xf.origin = (paste_indicator.begin + (paste_indicator.current - paste_indicator.click) + center) * node->get_cell_size();
xf.basis = rot * xf.basis; xf.basis = rot * xf.basis;
xf.translate(item.grid_offset * node->get_cell_size()); xf.translate_local(item.grid_offset * node->get_cell_size());
Basis item_rot; Basis item_rot;
item_rot.set_orthogonal_index(item.orientation); item_rot.set_orthogonal_index(item.orientation);
@ -611,9 +627,9 @@ void GridMapEditor::_do_paste() {
_clear_clipboard_data(); _clear_clipboard_data();
} }
bool GridMapEditor::forward_spatial_input_event(Camera *p_camera, const Ref<InputEvent> &p_event) { EditorPlugin::AfterGUIInput GridMapEditor::forward_spatial_input_event(Camera *p_camera, const Ref<InputEvent> &p_event) {
if (!node) { if (!node) {
return false; return EditorPlugin::AFTER_GUI_INPUT_PASS;
} }
Ref<InputEventMouseButton> mb = p_event; Ref<InputEventMouseButton> mb = p_event;
@ -624,12 +640,12 @@ bool GridMapEditor::forward_spatial_input_event(Camera *p_camera, const Ref<Inpu
floor->set_value(floor->get_value() + mb->get_factor()); floor->set_value(floor->get_value() + mb->get_factor());
} }
return true; // Eaten. return EditorPlugin::AFTER_GUI_INPUT_STOP; // Eaten.
} else if (mb->get_button_index() == BUTTON_WHEEL_DOWN && (mb->get_command() || mb->get_shift())) { } else if (mb->get_button_index() == BUTTON_WHEEL_DOWN && (mb->get_command() || mb->get_shift())) {
if (mb->is_pressed()) { if (mb->is_pressed()) {
floor->set_value(floor->get_value() - mb->get_factor()); floor->set_value(floor->get_value() - mb->get_factor());
} }
return true; return EditorPlugin::AFTER_GUI_INPUT_STOP;
} }
if (mb->is_pressed()) { if (mb->is_pressed()) {
@ -656,16 +672,16 @@ bool GridMapEditor::forward_spatial_input_event(Camera *p_camera, const Ref<Inpu
_clear_clipboard_data(); _clear_clipboard_data();
input_action = INPUT_NONE; input_action = INPUT_NONE;
_update_paste_indicator(); _update_paste_indicator();
return true; return EditorPlugin::AFTER_GUI_INPUT_STOP;
} else if (selection.active) { } else if (selection.active) {
_set_selection(false); _set_selection(false);
return true; return EditorPlugin::AFTER_GUI_INPUT_STOP;
} else { } else {
input_action = INPUT_ERASE; input_action = INPUT_ERASE;
set_items.clear(); set_items.clear();
} }
} else { } else {
return false; return EditorPlugin::AFTER_GUI_INPUT_PASS;
} }
return do_input_action(p_camera, Point2(mb->get_position().x, mb->get_position().y), true); return do_input_action(p_camera, Point2(mb->get_position().x, mb->get_position().y), true);
@ -686,7 +702,12 @@ bool GridMapEditor::forward_spatial_input_event(Camera *p_camera, const Ref<Inpu
} }
set_items.clear(); set_items.clear();
input_action = INPUT_NONE; input_action = INPUT_NONE;
return set_items.size() > 0;
if (set_items.size() > 0) {
return EditorPlugin::AFTER_GUI_INPUT_STOP;
} else {
return EditorPlugin::AFTER_GUI_INPUT_PASS;
}
} }
if (mb->get_button_index() == BUTTON_LEFT && input_action == INPUT_SELECT) { if (mb->get_button_index() == BUTTON_LEFT && input_action == INPUT_SELECT) {
@ -699,11 +720,11 @@ bool GridMapEditor::forward_spatial_input_event(Camera *p_camera, const Ref<Inpu
if (mb->get_button_index() == BUTTON_LEFT && input_action != INPUT_NONE) { if (mb->get_button_index() == BUTTON_LEFT && input_action != INPUT_NONE) {
set_items.clear(); set_items.clear();
input_action = INPUT_NONE; input_action = INPUT_NONE;
return true; return EditorPlugin::AFTER_GUI_INPUT_STOP;
} }
if (mb->get_button_index() == BUTTON_RIGHT && (input_action == INPUT_ERASE || input_action == INPUT_PASTE)) { if (mb->get_button_index() == BUTTON_RIGHT && (input_action == INPUT_ERASE || input_action == INPUT_PASTE)) {
input_action = INPUT_NONE; input_action = INPUT_NONE;
return true; return EditorPlugin::AFTER_GUI_INPUT_STOP;
} }
} }
} }
@ -723,16 +744,16 @@ bool GridMapEditor::forward_spatial_input_event(Camera *p_camera, const Ref<Inpu
_clear_clipboard_data(); _clear_clipboard_data();
input_action = INPUT_NONE; input_action = INPUT_NONE;
_update_paste_indicator(); _update_paste_indicator();
return true; return EditorPlugin::AFTER_GUI_INPUT_STOP;
} else if (selection.active) { } else if (selection.active) {
_set_selection(false); _set_selection(false);
return true; return EditorPlugin::AFTER_GUI_INPUT_STOP;
} else { } else {
selected_palette = -1; selected_palette = -1;
mesh_library_palette->unselect_all(); mesh_library_palette->unselect_all();
update_palette(); update_palette();
_update_cursor_instance(); _update_cursor_instance();
return true; return EditorPlugin::AFTER_GUI_INPUT_STOP;
} }
} }
@ -740,12 +761,12 @@ bool GridMapEditor::forward_spatial_input_event(Camera *p_camera, const Ref<Inpu
if (k->get_scancode() == options->get_popup()->get_item_accelerator(options->get_popup()->get_item_index(MENU_OPTION_PREV_LEVEL))) { if (k->get_scancode() == options->get_popup()->get_item_accelerator(options->get_popup()->get_item_index(MENU_OPTION_PREV_LEVEL))) {
selection.click[edit_axis]--; selection.click[edit_axis]--;
_validate_selection(); _validate_selection();
return true; return EditorPlugin::AFTER_GUI_INPUT_STOP;
} }
if (k->get_scancode() == options->get_popup()->get_item_accelerator(options->get_popup()->get_item_index(MENU_OPTION_NEXT_LEVEL))) { if (k->get_scancode() == options->get_popup()->get_item_accelerator(options->get_popup()->get_item_index(MENU_OPTION_NEXT_LEVEL))) {
selection.click[edit_axis]++; selection.click[edit_axis]++;
_validate_selection(); _validate_selection();
return true; return EditorPlugin::AFTER_GUI_INPUT_STOP;
} }
} }
} }
@ -764,12 +785,12 @@ bool GridMapEditor::forward_spatial_input_event(Camera *p_camera, const Ref<Inpu
if (step) { if (step) {
floor->set_value(floor->get_value() + step); floor->set_value(floor->get_value() + step);
} }
return true; return EditorPlugin::AFTER_GUI_INPUT_STOP;
} }
} }
accumulated_floor_delta = 0.0; accumulated_floor_delta = 0.0;
return false; return EditorPlugin::AFTER_GUI_INPUT_PASS;
} }
struct _CGMEItemSort { struct _CGMEItemSort {
@ -983,8 +1004,8 @@ void GridMapEditor::_draw_grids(const Vector3 &cell_size) {
Vector3 edited_floor = node->has_meta("_editor_floor_") ? node->get_meta("_editor_floor_") : Variant(); Vector3 edited_floor = node->has_meta("_editor_floor_") ? node->get_meta("_editor_floor_") : Variant();
for (int i = 0; i < 3; i++) { for (int i = 0; i < 3; i++) {
if (VS::get_singleton()->mesh_get_surface_count(grid[i]) > 0) { if (RS::get_singleton()->mesh_get_surface_count(grid[i]) > 0) {
VS::get_singleton()->mesh_remove_surface(grid[i], 0); RS::get_singleton()->mesh_remove_surface(grid[i], 0);
} }
edit_floor[i] = edited_floor[i]; edit_floor[i] = edited_floor[i];
} }
@ -1024,9 +1045,9 @@ void GridMapEditor::_draw_grids(const Vector3 &cell_size) {
} }
Array d; Array d;
d.resize(VS::ARRAY_MAX); d.resize(RS::ARRAY_MAX);
d[VS::ARRAY_VERTEX] = grid_points[i]; d[RS::ARRAY_VERTEX] = grid_points[i];
d[VS::ARRAY_COLOR] = grid_colors[i]; d[RS::ARRAY_COLOR] = grid_colors[i];
RenderingServer::get_singleton()->mesh_add_surface_from_arrays(grid[i], RenderingServer::PRIMITIVE_LINES, d); RenderingServer::get_singleton()->mesh_add_surface_from_arrays(grid[i], RenderingServer::PRIMITIVE_LINES, d);
RenderingServer::get_singleton()->mesh_surface_set_material(grid[i], 0, indicator_mat->get_rid()); RenderingServer::get_singleton()->mesh_surface_set_material(grid[i], 0, indicator_mat->get_rid());
} }
@ -1038,17 +1059,17 @@ void GridMapEditor::_notification(int p_what) {
get_tree()->connect("node_removed", this, "_node_removed"); get_tree()->connect("node_removed", this, "_node_removed");
mesh_library_palette->connect("item_selected", this, "_item_selected_cbk"); mesh_library_palette->connect("item_selected", this, "_item_selected_cbk");
for (int i = 0; i < 3; i++) { for (int i = 0; i < 3; i++) {
grid[i] = RID_PRIME(VS::get_singleton()->mesh_create()); grid[i] = RID_PRIME(RS::get_singleton()->mesh_create());
grid_instance[i] = VS::get_singleton()->instance_create2(grid[i], get_tree()->get_root()->get_world()->get_scenario()); grid_instance[i] = RS::get_singleton()->instance_create2(grid[i], get_tree()->get_root()->get_world_3d()->get_scenario());
VS::get_singleton()->instance_set_layer_mask(grid_instance[i], 1 << SpatialEditorViewport::MISC_TOOL_LAYER); RS::get_singleton()->instance_set_layer_mask(grid_instance[i], 1 << SpatialEditorViewport::MISC_TOOL_LAYER);
selection_level_instance[i] = RenderingServer::get_singleton()->instance_create2(selection_level_mesh[i], get_tree()->get_root()->get_world()->get_scenario()); selection_level_instance[i] = RenderingServer::get_singleton()->instance_create2(selection_level_mesh[i], get_tree()->get_root()->get_world_3d()->get_scenario());
VS::get_singleton()->instance_set_layer_mask(selection_level_instance[i], 1 << SpatialEditorViewport::MISC_TOOL_LAYER); RS::get_singleton()->instance_set_layer_mask(selection_level_instance[i], 1 << SpatialEditorViewport::MISC_TOOL_LAYER);
} }
selection_instance = RenderingServer::get_singleton()->instance_create2(selection_mesh, get_tree()->get_root()->get_world()->get_scenario()); selection_instance = RenderingServer::get_singleton()->instance_create2(selection_mesh, get_tree()->get_root()->get_world_3d()->get_scenario());
VS::get_singleton()->instance_set_layer_mask(selection_instance, 1 << SpatialEditorViewport::MISC_TOOL_LAYER); RS::get_singleton()->instance_set_layer_mask(selection_instance, 1 << SpatialEditorViewport::MISC_TOOL_LAYER);
paste_instance = RenderingServer::get_singleton()->instance_create2(paste_mesh, get_tree()->get_root()->get_world()->get_scenario()); paste_instance = RenderingServer::get_singleton()->instance_create2(paste_mesh, get_tree()->get_root()->get_world_3d()->get_scenario());
VS::get_singleton()->instance_set_layer_mask(paste_instance, 1 << SpatialEditorViewport::MISC_TOOL_LAYER); RS::get_singleton()->instance_set_layer_mask(paste_instance, 1 << SpatialEditorViewport::MISC_TOOL_LAYER);
_update_selection_transform(); _update_selection_transform();
_update_paste_indicator(); _update_paste_indicator();
@ -1060,28 +1081,28 @@ void GridMapEditor::_notification(int p_what) {
for (int i = 0; i < 3; i++) { for (int i = 0; i < 3; i++) {
if (grid_instance[i].is_valid()) { if (grid_instance[i].is_valid()) {
VS::get_singleton()->free(grid_instance[i]); RS::get_singleton()->free(grid_instance[i]);
grid_instance[i] = RID(); grid_instance[i] = RID();
} }
if (grid[i].is_valid()) { if (grid[i].is_valid()) {
VS::get_singleton()->free(grid[i]); RS::get_singleton()->free(grid[i]);
grid[i] = RID(); grid[i] = RID();
} }
if (selection_level_instance[i].is_valid()) { if (selection_level_instance[i].is_valid()) {
VS::get_singleton()->free(selection_level_instance[i]); RS::get_singleton()->free(selection_level_instance[i]);
selection_level_instance[i] = RID(); selection_level_instance[i] = RID();
} }
} }
if (selection_instance.is_valid()) { if (selection_instance.is_valid()) {
VS::get_singleton()->free(selection_instance); RS::get_singleton()->free(selection_instance);
selection_instance = RID(); selection_instance = RID();
} }
if (paste_instance.is_valid()) { if (paste_instance.is_valid()) {
VS::get_singleton()->free(paste_instance); RS::get_singleton()->free(paste_instance);
paste_instance = RID(); paste_instance = RID();
} }
} break; } break;
@ -1095,7 +1116,7 @@ void GridMapEditor::_notification(int p_what) {
if (xf != grid_xform) { if (xf != grid_xform) {
for (int i = 0; i < 3; i++) { for (int i = 0; i < 3; i++) {
VS::get_singleton()->instance_set_transform(grid_instance[i], xf * edit_grid_xform); RS::get_singleton()->instance_set_transform(grid_instance[i], xf * edit_grid_xform);
} }
grid_xform = xf; grid_xform = xf;
} }
@ -1120,8 +1141,8 @@ void GridMapEditor::_notification(int p_what) {
} break; } break;
case NOTIFICATION_THEME_CHANGED: { case NOTIFICATION_THEME_CHANGED: {
options->set_icon(get_icon("GridMap", "EditorIcons")); options->set_icon(get_theme_icon("GridMap", "EditorIcons"));
search_box->set_right_icon(get_icon("Search", "EditorIcons")); search_box->set_right_icon(get_theme_icon("Search", "EditorIcons"));
} break; } break;
case NOTIFICATION_WM_FOCUS_OUT: { case NOTIFICATION_WM_FOCUS_OUT: {
@ -1150,7 +1171,7 @@ void GridMapEditor::_update_cursor_instance() {
if (node && !node->get_mesh_library().is_null()) { if (node && !node->get_mesh_library().is_null()) {
Ref<Mesh> mesh = node->get_mesh_library()->get_item_mesh(selected_palette); Ref<Mesh> mesh = node->get_mesh_library()->get_item_mesh(selected_palette);
if (!mesh.is_null() && mesh->get_rid().is_valid()) { if (!mesh.is_null() && mesh->get_rid().is_valid()) {
cursor_instance = RenderingServer::get_singleton()->instance_create2(mesh->get_rid(), get_tree()->get_root()->get_world()->get_scenario()); cursor_instance = RenderingServer::get_singleton()->instance_create2(mesh->get_rid(), get_tree()->get_root()->get_world_3d()->get_scenario());
RenderingServer::get_singleton()->instance_set_transform(cursor_instance, cursor_transform); RenderingServer::get_singleton()->instance_set_transform(cursor_instance, cursor_transform);
} }
} }
@ -1220,7 +1241,7 @@ GridMapEditor::GridMapEditor(EditorNode *p_editor) {
floor->set_min(-32767); floor->set_min(-32767);
floor->set_max(32767); floor->set_max(32767);
floor->set_step(1); floor->set_step(1);
floor->get_line_edit()->add_constant_override("minimum_spaces", 16); floor->get_line_edit()->add_theme_constant_override("minimum_spaces", 16);
spatial_editor_hb->add_child(floor); spatial_editor_hb->add_child(floor);
floor->connect("value_changed", this, "_floor_changed"); floor->connect("value_changed", this, "_floor_changed");
@ -1298,14 +1319,14 @@ GridMapEditor::GridMapEditor(EditorNode *p_editor) {
mode_thumbnail = memnew(ToolButton); mode_thumbnail = memnew(ToolButton);
mode_thumbnail->set_toggle_mode(true); mode_thumbnail->set_toggle_mode(true);
mode_thumbnail->set_pressed(true); mode_thumbnail->set_pressed(true);
mode_thumbnail->set_icon(p_editor->get_gui_base()->get_icon("FileThumbnail", "EditorIcons")); mode_thumbnail->set_icon(p_editor->get_gui_base()->get_theme_icon("FileThumbnail", "EditorIcons"));
hb->add_child(mode_thumbnail); hb->add_child(mode_thumbnail);
mode_thumbnail->connect("pressed", this, "_set_display_mode", varray(DISPLAY_THUMBNAIL)); mode_thumbnail->connect("pressed", this, "_set_display_mode", varray(DISPLAY_THUMBNAIL));
mode_list = memnew(ToolButton); mode_list = memnew(ToolButton);
mode_list->set_toggle_mode(true); mode_list->set_toggle_mode(true);
mode_list->set_pressed(false); mode_list->set_pressed(false);
mode_list->set_icon(p_editor->get_gui_base()->get_icon("FileList", "EditorIcons")); mode_list->set_icon(p_editor->get_gui_base()->get_theme_icon("FileList", "EditorIcons"));
hb->add_child(mode_list); hb->add_child(mode_list);
mode_list->connect("pressed", this, "_set_display_mode", varray(DISPLAY_LIST)); mode_list->connect("pressed", this, "_set_display_mode", varray(DISPLAY_LIST));
@ -1417,15 +1438,15 @@ GridMapEditor::GridMapEditor(EditorNode *p_editor) {
} }
Array d; Array d;
d.resize(VS::ARRAY_MAX); d.resize(RS::ARRAY_MAX);
inner_mat.instance(); inner_mat.instance();
inner_mat->set_albedo(Color(0.7, 0.7, 1.0, 0.2)); inner_mat->set_albedo(Color(0.7, 0.7, 1.0, 0.2));
inner_mat->set_flag(SpatialMaterial::FLAG_UNSHADED, true); inner_mat->set_flag(SpatialMaterial::FLAG_UNSHADED, true);
inner_mat->set_feature(SpatialMaterial::FEATURE_TRANSPARENT, true); inner_mat->set_feature(SpatialMaterial::FEATURE_TRANSPARENT, true);
d[VS::ARRAY_VERTEX] = triangles; d[RS::ARRAY_VERTEX] = triangles;
RenderingServer::get_singleton()->mesh_add_surface_from_arrays(selection_mesh, VS::PRIMITIVE_TRIANGLES, d); RenderingServer::get_singleton()->mesh_add_surface_from_arrays(selection_mesh, RS::PRIMITIVE_TRIANGLES, d);
RenderingServer::get_singleton()->mesh_surface_set_material(selection_mesh, 0, inner_mat->get_rid()); RenderingServer::get_singleton()->mesh_surface_set_material(selection_mesh, 0, inner_mat->get_rid());
outer_mat.instance(); outer_mat.instance();
@ -1441,22 +1462,22 @@ GridMapEditor::GridMapEditor(EditorNode *p_editor) {
selection_floor_mat->set_flag(SpatialMaterial::FLAG_UNSHADED, true); selection_floor_mat->set_flag(SpatialMaterial::FLAG_UNSHADED, true);
selection_floor_mat->set_line_width(3.0); selection_floor_mat->set_line_width(3.0);
d[VS::ARRAY_VERTEX] = lines; d[RS::ARRAY_VERTEX] = lines;
RenderingServer::get_singleton()->mesh_add_surface_from_arrays(selection_mesh, VS::PRIMITIVE_LINES, d); RenderingServer::get_singleton()->mesh_add_surface_from_arrays(selection_mesh, RS::PRIMITIVE_LINES, d);
RenderingServer::get_singleton()->mesh_surface_set_material(selection_mesh, 1, outer_mat->get_rid()); RenderingServer::get_singleton()->mesh_surface_set_material(selection_mesh, 1, outer_mat->get_rid());
d[VS::ARRAY_VERTEX] = triangles; d[RS::ARRAY_VERTEX] = triangles;
RenderingServer::get_singleton()->mesh_add_surface_from_arrays(paste_mesh, VS::PRIMITIVE_TRIANGLES, d); RenderingServer::get_singleton()->mesh_add_surface_from_arrays(paste_mesh, RS::PRIMITIVE_TRIANGLES, d);
RenderingServer::get_singleton()->mesh_surface_set_material(paste_mesh, 0, inner_mat->get_rid()); RenderingServer::get_singleton()->mesh_surface_set_material(paste_mesh, 0, inner_mat->get_rid());
d[VS::ARRAY_VERTEX] = lines; d[RS::ARRAY_VERTEX] = lines;
RenderingServer::get_singleton()->mesh_add_surface_from_arrays(paste_mesh, VS::PRIMITIVE_LINES, d); RenderingServer::get_singleton()->mesh_add_surface_from_arrays(paste_mesh, RS::PRIMITIVE_LINES, d);
RenderingServer::get_singleton()->mesh_surface_set_material(paste_mesh, 1, outer_mat->get_rid()); RenderingServer::get_singleton()->mesh_surface_set_material(paste_mesh, 1, outer_mat->get_rid());
for (int i = 0; i < 3; i++) { for (int i = 0; i < 3; i++) {
d[VS::ARRAY_VERTEX] = square[i]; d[RS::ARRAY_VERTEX] = square[i];
selection_level_mesh[i] = RID_PRIME(VS::get_singleton()->mesh_create()); selection_level_mesh[i] = RID_PRIME(RS::get_singleton()->mesh_create());
RenderingServer::get_singleton()->mesh_add_surface_from_arrays(selection_level_mesh[i], VS::PRIMITIVE_LINES, d); RenderingServer::get_singleton()->mesh_add_surface_from_arrays(selection_level_mesh[i], RS::PRIMITIVE_LINES, d);
RenderingServer::get_singleton()->mesh_surface_set_material(selection_level_mesh[i], 0, selection_floor_mat->get_rid()); RenderingServer::get_singleton()->mesh_surface_set_material(selection_level_mesh[i], 0, selection_floor_mat->get_rid());
} }
} }

View File

@ -33,9 +33,21 @@
#include "editor/editor_node.h" #include "editor/editor_node.h"
#include "editor/editor_plugin.h" #include "editor/editor_plugin.h"
#include "scene/gui/box_container.h"
#include "editor/pane_drag.h" #include "editor/pane_drag.h"
#include "grid_map.h" #include "grid_map.h"
class UndoRedo;
class Panel;
class MenuButton;
class SpinBox;
class ToolButton;
class LineEdit;
class HSlider;
class ConfirmationDialog;
class Label;
class SpatialEditorPlugin; class SpatialEditorPlugin;
class GridMapEditor : public VBoxContainer { class GridMapEditor : public VBoxContainer {
@ -228,7 +240,7 @@ class GridMapEditor : public VBoxContainer {
void _delete_selection(); void _delete_selection();
void _fill_selection(); void _fill_selection();
bool do_input_action(Camera *p_camera, const Point2 &p_point, bool p_click); EditorPlugin::AfterGUIInput do_input_action(Camera *p_camera, const Point2 &p_point, bool p_click);
friend class GridMapEditorPlugin; friend class GridMapEditorPlugin;
@ -238,7 +250,7 @@ protected:
static void _bind_methods(); static void _bind_methods();
public: public:
bool forward_spatial_input_event(Camera *p_camera, const Ref<InputEvent> &p_event); EditorPlugin::AfterGUIInput forward_spatial_input_event(Camera *p_camera, const Ref<InputEvent> &p_event);
void edit(GridMap *p_gridmap); void edit(GridMap *p_gridmap);
GridMapEditor() {} GridMapEditor() {}
@ -256,7 +268,7 @@ protected:
void _notification(int p_what); void _notification(int p_what);
public: public:
virtual bool forward_spatial_gui_input(Camera *p_camera, const Ref<InputEvent> &p_event) { return grid_map_editor->forward_spatial_input_event(p_camera, p_event); } virtual EditorPlugin::AfterGUIInput forward_spatial_gui_input(Camera *p_camera, const Ref<InputEvent> &p_event) { return grid_map_editor->forward_spatial_input_event(p_camera, p_event); }
virtual String get_name() const { return "GridMap"; } virtual String get_name() const { return "GridMap"; }
bool has_main_screen() const { return false; } bool has_main_screen() const { return false; }
virtual void edit(Object *p_object); virtual void edit(Object *p_object);

View File

@ -30,7 +30,8 @@
#include "mesh_library.h" #include "mesh_library.h"
#include "box_shape.h" #include "scene/resources/box_shape.h"
#include "scene/resources/navigation_mesh.h"
bool MeshLibrary::_set(const StringName &p_name, const Variant &p_value) { bool MeshLibrary::_set(const StringName &p_name, const Variant &p_value) {
String name = p_name; String name = p_name;
@ -100,14 +101,14 @@ bool MeshLibrary::_get(const StringName &p_name, Variant &r_ret) const {
void MeshLibrary::_get_property_list(List<PropertyInfo> *p_list) const { void MeshLibrary::_get_property_list(List<PropertyInfo> *p_list) const {
for (Map<int, Item>::Element *E = item_map.front(); E; E = E->next()) { for (Map<int, Item>::Element *E = item_map.front(); E; E = E->next()) {
String name = vformat("%s/%d/", PNAME("item"), E->key()); String name = vformat("%s/%d/", "item", E->key());
p_list->push_back(PropertyInfo(Variant::STRING, name + PNAME("name"))); p_list->push_back(PropertyInfo(Variant::STRING, name + ("name")));
p_list->push_back(PropertyInfo(Variant::OBJECT, name + PNAME("mesh"), PROPERTY_HINT_RESOURCE_TYPE, "Mesh")); p_list->push_back(PropertyInfo(Variant::OBJECT, name + ("mesh"), PROPERTY_HINT_RESOURCE_TYPE, "Mesh"));
p_list->push_back(PropertyInfo(Variant::TRANSFORM, name + PNAME("mesh_transform"))); p_list->push_back(PropertyInfo(Variant::TRANSFORM, name + ("mesh_transform")));
p_list->push_back(PropertyInfo(Variant::ARRAY, name + PNAME("shapes"))); p_list->push_back(PropertyInfo(Variant::ARRAY, name + ("shapes")));
p_list->push_back(PropertyInfo(Variant::OBJECT, name + PNAME("navmesh"), PROPERTY_HINT_RESOURCE_TYPE, "NavigationMesh")); p_list->push_back(PropertyInfo(Variant::OBJECT, name + ("navmesh"), PROPERTY_HINT_RESOURCE_TYPE, "NavigationMesh"));
p_list->push_back(PropertyInfo(Variant::TRANSFORM, name + PNAME("navmesh_transform"))); p_list->push_back(PropertyInfo(Variant::TRANSFORM, name + ("navmesh_transform")));
p_list->push_back(PropertyInfo(Variant::OBJECT, name + PNAME("preview"), PROPERTY_HINT_RESOURCE_TYPE, "Texture", PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_EDITOR_HELPER)); p_list->push_back(PropertyInfo(Variant::OBJECT, name + ("preview"), PROPERTY_HINT_RESOURCE_TYPE, "Texture", PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_EDITOR_HELPER));
} }
} }

View File

@ -33,9 +33,11 @@
#include "core/containers/map.h" #include "core/containers/map.h"
#include "core/object/resource.h" #include "core/object/resource.h"
#include "scenes/resources/mesh.h" #include "scene/resources/mesh.h"
#include "scene/3d/navigation_mesh_instance.h" #include "scene/3d/navigation_mesh_instance.h"
#include "shape.h" #include "scene/resources/shape.h"
class NavigationMesh;
class MeshLibrary : public Resource { class MeshLibrary : public Resource {
GDCLASS(MeshLibrary, Resource); GDCLASS(MeshLibrary, Resource);