generated from asmaloney/GDExtensionTemplate
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
15 changed files
with
566 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,115 @@ | ||
#include "CesiumTileset.h" | ||
|
||
#include "godot_cpp/classes/gltf_document.hpp" | ||
#include "godot_cpp/classes/gltf_state.hpp" | ||
#include "godot_cpp/classes/file_access.hpp" | ||
#include "godot_cpp/classes/engine.hpp" | ||
#include "godot_cpp/classes/node.hpp" | ||
#include "godot_cpp/classes/gltf_document_extension_convert_importer_mesh.hpp" | ||
|
||
#include "godot_cpp/classes/scene_tree.hpp" | ||
#include "godot_cpp/classes/dir_access.hpp" | ||
|
||
#include "godot_cpp/variant/utility_functions.hpp" | ||
|
||
namespace CesiumGodot | ||
{ | ||
void _recursive_change_owner(godot::Node* node, godot::Node* owner) | ||
{ | ||
godot::Callable chown_callable = callable_mp_static(_recursive_change_owner); | ||
node->get_children().map(chown_callable.bind(owner)); | ||
} | ||
|
||
CesiumTileset::CesiumTileset() | ||
{ | ||
m_assetId = -1; | ||
m_gltfNode = nullptr; | ||
} | ||
|
||
CesiumTileset::~CesiumTileset() | ||
{ | ||
} | ||
|
||
godot::String CesiumTileset::getAccessToken() const | ||
{ | ||
return m_accessToken; | ||
} | ||
|
||
void CesiumTileset::setAccessToken( const godot::String &inToken ) | ||
{ | ||
|
||
m_accessToken = inToken; | ||
} | ||
|
||
|
||
int32_t CesiumTileset::getAssetId() const | ||
{ | ||
return m_assetId; | ||
} | ||
|
||
void CesiumTileset::setAssetId( int32_t id ) | ||
{ | ||
m_assetId = id; | ||
} | ||
|
||
void CesiumTileset::loadGltfPath(const godot::String& gltfPath) | ||
{ | ||
godot::UtilityFunctions::print("Loading GLTF model: ", gltfPath); | ||
|
||
if (!godot::FileAccess::file_exists(gltfPath)) | ||
{ | ||
godot::UtilityFunctions::print("File ", gltfPath, " does not exist"); | ||
return; | ||
} | ||
|
||
if (m_gltfNode != nullptr) | ||
{ | ||
if (get_children().has(m_gltfNode)) remove_child(m_gltfNode); | ||
memdelete(m_gltfNode); | ||
} | ||
|
||
godot::GLTFDocument* gltfDoc = memnew(godot::GLTFDocument); | ||
|
||
// Register convert extension. Apparently needed for correct editor runtime mesh import | ||
godot::Ref<godot::GLTFDocumentExtensionConvertImporterMesh> gltfConvertExt; | ||
gltfConvertExt.instantiate(); | ||
gltfDoc->register_gltf_document_extension(gltfConvertExt); | ||
|
||
godot::Ref<godot::GLTFState> gltfState; | ||
gltfState.instantiate(); | ||
gltfState->set_handle_binary_image(godot::GLTFState::HANDLE_BINARY_EMBED_AS_UNCOMPRESSED); | ||
|
||
godot::Error err = gltfDoc->append_from_file(gltfPath, gltfState, 0, "base_path?"); | ||
godot::UtilityFunctions::print("Load result: ", err); | ||
|
||
m_gltfNode = gltfDoc->generate_scene(gltfState); | ||
add_child(m_gltfNode); | ||
_recursive_change_owner(m_gltfNode, get_owner()); | ||
|
||
memdelete(gltfDoc); | ||
} | ||
|
||
void CesiumTileset::loadGltf() | ||
{ | ||
const godot::String& path = m_accessToken; | ||
loadGltfPath(path); | ||
} | ||
|
||
void CesiumTileset::_bind_methods() | ||
{ | ||
godot::ClassDB::bind_method( godot::D_METHOD("set_access_token"), &CesiumTileset::setAccessToken ); | ||
godot::ClassDB::bind_method( godot::D_METHOD("get_access_token"), &CesiumTileset::getAccessToken ); | ||
godot::ClassDB::bind_method( godot::D_METHOD("set_asset_id"), &CesiumTileset::setAssetId ); | ||
godot::ClassDB::bind_method( godot::D_METHOD("get_asset_id"), &CesiumTileset::getAssetId ); | ||
godot::ClassDB::bind_method( godot::D_METHOD("load_gltf"), &CesiumTileset::loadGltf ); | ||
|
||
ADD_GROUP("Cesium", "cesium_"); | ||
ADD_SUBGROUP("Asset Data", "cesium_assetData_"); | ||
|
||
ADD_PROPERTY( godot::PropertyInfo( godot::Variant::STRING, "cesium_assetData_access_token" ), | ||
"set_access_token", "get_access_token"); | ||
ADD_PROPERTY( godot::PropertyInfo( godot::Variant::INT, "cesium_assetData_asset_id" ), | ||
"set_asset_id", "get_asset_id"); | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
#pragma once | ||
|
||
#include "godot_cpp/classes/node3d.hpp" | ||
#include "godot_cpp/classes/node.hpp" | ||
#include "godot_cpp/classes/gltf_state.hpp" | ||
#include "godot_cpp/classes/gltf_document.hpp" | ||
|
||
#include "Cesium3DTilesSelection/Tileset.h" | ||
|
||
#include <memory> | ||
|
||
|
||
#include "godot_cpp/classes/sphere_mesh.hpp" | ||
#include "godot_cpp/classes/mesh_instance3d.hpp" | ||
|
||
namespace CesiumGodot | ||
{ | ||
/// @brief Godot object representing cesium tileset | ||
class CesiumTileset : public godot::Node3D | ||
{ | ||
GDCLASS( CesiumTileset, godot::Node3D ) | ||
|
||
public: | ||
CesiumTileset(); | ||
~CesiumTileset(); | ||
|
||
godot::String getAccessToken() const; | ||
void setAccessToken(const godot::String& inToken); | ||
int32_t getAssetId() const; | ||
void setAssetId(int32_t id); | ||
|
||
/// @brief Load glTF model at gltfPath and add it to this node's children | ||
/// @param gltfPath model path | ||
void loadGltfPath(const godot::String& gltfPath); | ||
void loadGltf(); | ||
|
||
protected: | ||
static void _bind_methods(); | ||
|
||
private: | ||
godot::Node* m_gltfNode; | ||
|
||
std::shared_ptr<Cesium3DTilesSelection::Tileset> m_tileset; | ||
|
||
godot::String m_accessToken; | ||
int32_t m_assetId; | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
#include "CesiumTilesetInspector.h" | ||
|
||
#include "godot_cpp/variant/utility_functions.hpp" | ||
#include "godot_cpp/core/memory.hpp" | ||
#include "godot_cpp/classes/thread.hpp" | ||
#include "godot_cpp/classes/label.hpp" | ||
#include "godot_cpp/classes/button.hpp" | ||
#include "godot_cpp/variant/callable.hpp" | ||
|
||
#include "CesiumTileset.h" | ||
|
||
namespace CesiumGodot | ||
{ | ||
|
||
|
||
CesiumTilesetInspector::CesiumTilesetInspector() | ||
{ | ||
godot::UtilityFunctions::print("Initializing tileset inspector plugin"); | ||
} | ||
|
||
CesiumTilesetInspector::~CesiumTilesetInspector() | ||
{ | ||
godot::UtilityFunctions::print("Deinitializing tileset inspector plugin"); | ||
} | ||
|
||
bool CesiumTilesetInspector::_can_handle(godot::Object * object) const | ||
{ | ||
godot::UtilityFunctions::print(object->get_class()); | ||
return object->is_class("CesiumTileset"); | ||
} | ||
|
||
void memfree_helper(void* ptr) | ||
{ | ||
godot::Memory::free_static(ptr); | ||
} | ||
|
||
void CesiumTilesetInspector::_parse_begin( godot::Object *object ) | ||
{ | ||
godot::Label* pLabel = memnew(godot::Label); | ||
add_custom_control(pLabel); | ||
} | ||
|
||
void CesiumTilesetInspector::_parse_category( godot::Object *object, | ||
const godot::String &category ) | ||
{ | ||
godot::UtilityFunctions::print("Parsing category: ", category); | ||
|
||
if (category == "CesiumTileset") | ||
{ | ||
godot::Button* pAddButton = memnew(godot::Button); | ||
pAddButton->set_text("Add GLTF"); | ||
pAddButton->set_action_mode(godot::BaseButton::ACTION_MODE_BUTTON_PRESS); | ||
pAddButton->connect("pressed", callable_mp(godot::Object::cast_to<CesiumTileset>(object), &CesiumTileset::loadGltf), godot::Object::ConnectFlags::CONNECT_DEFERRED); | ||
add_custom_control(pAddButton); | ||
} | ||
} | ||
|
||
void CesiumTilesetInspector::_parse_group( godot::Object *object, const godot::String &group ) | ||
{ | ||
godot::UtilityFunctions::print("Parsing group: ", group); | ||
|
||
if (group == "Cesium/Asset Data") | ||
{ | ||
} | ||
} | ||
|
||
void CesiumTilesetInspector::_bind_methods() | ||
{ | ||
} | ||
|
||
void CesiumTilesetInspector::add_gltf_helper() | ||
{ | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
#pragma once | ||
|
||
#include "godot_cpp/classes/editor_inspector_plugin.hpp" | ||
|
||
#include <memory> | ||
|
||
namespace godot | ||
{ | ||
class Label; | ||
class Button; | ||
} // namespace godot | ||
|
||
|
||
namespace CesiumGodot | ||
{ | ||
/// @brief Godot editor inspector plugin for cesium tileset node | ||
class CesiumTilesetInspector : public godot::EditorInspectorPlugin | ||
{ | ||
GDCLASS( CesiumTilesetInspector, godot::EditorInspectorPlugin ) | ||
|
||
public: | ||
CesiumTilesetInspector(); | ||
~CesiumTilesetInspector(); | ||
|
||
bool _can_handle(godot::Object* object) const override; | ||
void _parse_begin(godot::Object* object) override; | ||
void _parse_category(godot::Object* object, const godot::String& category) override; | ||
void _parse_group(godot::Object* object, const godot::String& group) override; | ||
|
||
static void _bind_methods(); | ||
|
||
private: | ||
void add_gltf_helper(); | ||
|
||
// std::shared_ptr<godot::Label> m_pLabel; | ||
godot::Label* m_pLabel; | ||
godot::Button* m_pAddGlftButton; | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
#include "CesiumTilesetPlugin.h" | ||
|
||
#include "godot_cpp/variant/utility_functions.hpp" | ||
#include "godot_cpp/classes/button.hpp" | ||
#include "godot_cpp/core/memory.hpp" | ||
#include "godot_cpp/classes/editor_inspector_plugin.hpp" | ||
#include "godot_cpp/variant/callable.hpp" | ||
|
||
#include "CesiumTilesetPlugin.h" | ||
|
||
namespace CesiumGodot | ||
{ | ||
CesiumTilesetPlugin::CesiumTilesetPlugin() | ||
{ | ||
godot::UtilityFunctions::print("CesiumTilesetPlugin initialized."); | ||
} | ||
|
||
CesiumTilesetPlugin::~CesiumTilesetPlugin() | ||
{ | ||
godot::UtilityFunctions::print("CesiumTilesetPlugin deinitialized."); | ||
} | ||
|
||
bool CesiumTilesetPlugin::_has_main_screen() const | ||
{ | ||
return true; | ||
} | ||
|
||
godot::String CesiumTilesetPlugin::_get_plugin_name() const | ||
{ | ||
return m_pluginName; | ||
} | ||
|
||
void CesiumTilesetPlugin::_enter_tree() | ||
{ | ||
godot::UtilityFunctions::print("CesiumTilesetPlugin entered"); | ||
|
||
// godot::Ref<godot::Button> button; | ||
// button.instantiate(); | ||
|
||
m_rTilesetInspectorPlugin.instantiate(); | ||
add_inspector_plugin(m_rTilesetInspectorPlugin); | ||
godot::UtilityFunctions::print("Inspector plugin is valid: ", m_rTilesetInspectorPlugin.is_valid()); | ||
} | ||
|
||
void CesiumTilesetPlugin::_exit_tree() | ||
{ | ||
godot::UtilityFunctions::print("CesiumTilesetPlugin exited"); | ||
|
||
remove_inspector_plugin(m_rTilesetInspectorPlugin); | ||
m_rTilesetInspectorPlugin.unref(); | ||
} | ||
|
||
void CesiumTilesetPlugin::_bind_methods() | ||
{ | ||
} | ||
|
||
void CesiumTilesetPlugin::print_helper() | ||
{ | ||
godot::UtilityFunctions::print("Test button pressed"); | ||
} | ||
} |
Oops, something went wrong.