Added a helper method to get the editor's camera.

This commit is contained in:
Relintai 2022-02-19 11:09:24 +01:00
parent 9c580fce42
commit a78d41bf37
2 changed files with 30 additions and 0 deletions

View File

@ -41,6 +41,11 @@ SOFTWARE.
#include "../../mesh_data_resource/props/prop_data_mesh_data.h" #include "../../mesh_data_resource/props/prop_data_mesh_data.h"
#endif #endif
#if TOOLS_ENABLED
#include "editor/plugins/spatial_editor_plugin.h"
#include "scene/3d/camera.h"
#endif
const String TerrainWorld::BINDING_STRING_CHANNEL_TYPE_INFO = "Type,Isolevel,Liquid,Liquid Level"; const String TerrainWorld::BINDING_STRING_CHANNEL_TYPE_INFO = "Type,Isolevel,Liquid,Liquid Level";
bool TerrainWorld::get_active() const { bool TerrainWorld::get_active() const {
@ -820,6 +825,27 @@ int TerrainWorld::get_channel_index_info(const TerrainWorld::ChannelTypeInfo cha
RETURN_CALLP(int, _get_channel_index_info, channel_type); RETURN_CALLP(int, _get_channel_index_info, channel_type);
} }
Spatial *TerrainWorld::get_editor_camera() {
#if TOOLS_ENABLED
SpatialEditor *se = SpatialEditor::get_singleton();
if (!se) {
return nullptr;
}
SpatialEditorViewport *wp = se->get_editor_viewport(0);
if (!wp) {
return nullptr;
}
return wp->get_camera();
#else
return nullptr;
#endif
}
TerrainWorld::TerrainWorld() { TerrainWorld::TerrainWorld() {
_active = true; _active = true;
_editable = false; _editable = false;
@ -1172,6 +1198,8 @@ void TerrainWorld::_bind_methods() {
ClassDB::bind_method(D_METHOD("get_channel_index_info", "channel_type"), &TerrainWorld::get_channel_index_info); ClassDB::bind_method(D_METHOD("get_channel_index_info", "channel_type"), &TerrainWorld::get_channel_index_info);
ClassDB::bind_method(D_METHOD("_get_channel_index_info", "channel_type"), &TerrainWorld::_get_channel_index_info); ClassDB::bind_method(D_METHOD("_get_channel_index_info", "channel_type"), &TerrainWorld::_get_channel_index_info);
ClassDB::bind_method(D_METHOD("get_editor_camera"), &TerrainWorld::get_editor_camera);
#if VERSION_MAJOR < 4 #if VERSION_MAJOR < 4
BIND_VMETHOD(MethodInfo("_set_voxel_with_tool", BIND_VMETHOD(MethodInfo("_set_voxel_with_tool",
PropertyInfo(Variant::BOOL, "mode_add"), PropertyInfo(Variant::BOOL, "mode_add"),

View File

@ -192,6 +192,8 @@ public:
int get_channel_index_info(const ChannelTypeInfo channel_type); int get_channel_index_info(const ChannelTypeInfo channel_type);
Spatial *get_editor_camera();
#if VERSION_MAJOR >= 4 #if VERSION_MAJOR >= 4
GDVIRTUAL1(_chunk_added, Ref<TerrainChunk>); GDVIRTUAL1(_chunk_added, Ref<TerrainChunk>);