Actually, I want to implement a UI similar to Unity's, which is adding a special node Cesium3DTileset and a CesiumGeoreferece node will be add automatic to its' parent node, and it has a resouce type default value like EarthCenterEarthFixed value. But now it gets lots of warnings about default value.
header:

#pragma once

#include <CesiumGeospatial/LocalHorizontalCoordinateSystem.h>
#include <glm/mat4x4.hpp>
#include <godot_cpp/classes/node3d.hpp>
#include <godot_cpp/classes/resource.hpp>
#include <optional>

using namespace godot;

namespace CesiumForGodot
{

    class CesiumGeoreference : public Node3D
    {
        GDCLASS( CesiumGeoreference, Node3D )

    private:
        Ref<Resource> originAuthority;
        double scale = 1.0f;
        std::optional<CesiumGeospatial::LocalHorizontalCoordinateSystem> coordinateSystem;
        glm::dmat4 localToEcef = glm::dmat4( 1.0f );
        glm::dmat4 ecefToLocal = glm::dmat4( 1.0f );

    protected:
        static void _bind_methods();

    public:
        CesiumGeoreference();
        ~CesiumGeoreference();
        // void _process(double delta) override;

        void set_originAuthority( const Ref<Resource> p_originAuthority );
        Ref<Resource> get_originAuthority() const;

        void set_scale( const double p_scale );
        double get_scale() const;

        CesiumGeospatial::LocalHorizontalCoordinateSystem CesiumGeoreference::
            createCoordinateSystem() const;

        const CesiumGeospatial::LocalHorizontalCoordinateSystem &getCoordinateSystem();

        void computeLocalToEarthCenteredEarthFixedTransformation();

        void updateGeoreference();
    };

} // namespace CesiumForGodot

definition:

#include "CesiumGeoreference.h"
#include "CesiumOriginAuthority.h"
#include <CesiumGeospatial/LocalHorizontalCoordinateSystem.h>
#include <CesiumUtility/Math.h>
#include <godot_cpp/core/class_db.hpp>
#include <godot_cpp/variant/utility_functions.hpp>

using namespace CesiumGeospatial;
using namespace CesiumUtility;
using namespace CesiumForGodot;

void CesiumGeoreference::_bind_methods()
{
    ClassDB::bind_method( D_METHOD( "get_scale" ), &CesiumGeoreference::get_scale );
    ClassDB::bind_method( D_METHOD( "set_scale", "p_scale" ), &CesiumGeoreference::set_scale );
    ClassDB::add_property( "CesiumGeoreference", PropertyInfo( Variant::FLOAT, "scale" ),
                           "set_scale", "get_scale" );

    ClassDB::bind_method( D_METHOD( "get_originAuthority" ),
                          &CesiumGeoreference::get_originAuthority );
    ClassDB::bind_method( D_METHOD( "set_originAuthority", "p_originAuthority" ),
                          &CesiumGeoreference::set_originAuthority );
    ClassDB::add_property( "CesiumGeoreference",
                           PropertyInfo( Variant::OBJECT, "originAuthority",
                                         PROPERTY_HINT_RESOURCE_TYPE,
                                         "LongitudeLatitudeHeight, EarthCenteredEarthFixed" ),
                           "set_originAuthority", "get_originAuthority" );
    ClassDB::bind_method( D_METHOD( "updateGeoreference" ),
                          &CesiumGeoreference::updateGeoreference );

    ADD_SIGNAL( MethodInfo( "scale_changed", PropertyInfo( Variant::OBJECT, "node" ),
                            PropertyInfo( Variant::FLOAT, "scale" ) ) );
}

CesiumGeoreference::CesiumGeoreference()
{
    Ref<EarthCenteredEarthFixed> originAuthority;
    originAuthority.instantiate();
    this->set_originAuthority( originAuthority );
    this->scale = 1.0;
}

CesiumGeoreference::~CesiumGeoreference()
{
    // Add your cleanup here.
}

void CesiumGeoreference::set_originAuthority( const Ref<Resource> p_originAuthority )
{
    if ( originAuthority != p_originAuthority )
    {
        if ( originAuthority != nullptr )
        {
            String type_name = originAuthority->get_name();
            if ( type_name == "LongitudeLatitudeHeight" )
            {
                originAuthority->disconnect( "lngLatH_changed",
                                             Callable( this, "updateGeoreference" ) );
            }
            else
            {
                originAuthority->disconnect( "ecef_changed",
                                             Callable( this, "updateGeoreference" ) );
            }
        }
        originAuthority = p_originAuthority;
        if ( originAuthority != nullptr )
        {
            String type_name = originAuthority->get_name();
            if ( type_name == "LongitudeLatitudeHeight" )
            {
                p_originAuthority->connect( "lngLatH_changed",
                                            Callable( this, "updateGeoreference" ) );
            }
            else
            {
                p_originAuthority->connect( "ecef_changed",
                                            Callable( this, "updateGeoreference" ) );
            }
        }
    }
}

Ref<Resource> CesiumGeoreference::get_originAuthority() const
{
    return originAuthority;
}

void CesiumGeoreference::set_scale( const double p_scale )
{
    if ( scale != p_scale )
    {
        scale = p_scale;
        emit_signal( "scale_changed" );
        this->updateGeoreference();
    }
}

double CesiumGeoreference::get_scale() const
{
    return scale;
}

LocalHorizontalCoordinateSystem CesiumGeoreference::createCoordinateSystem() const
{
    if ( originAuthority.is_valid() )
    {
        String type_name = originAuthority->get_name();
        if ( type_name == "LongitudeLatitudeHeight" )
        {
            Ref<CesiumForGodot::LongitudeLatitudeHeight> lngLatH =
                Ref<LongitudeLatitudeHeight>( originAuthority.ptr() );
            return LocalHorizontalCoordinateSystem(
                Cartographic::fromDegrees( lngLatH->get_longitude(), lngLatH->get_latitude(),
                                           lngLatH->get_height() ),
                LocalDirection::East, LocalDirection::Up, LocalDirection::North, 1.0 / scale );
        }
        else
        {
            Ref<CesiumForGodot::EarthCenteredEarthFixed> p_ecef =
                Ref<EarthCenteredEarthFixed>( originAuthority.ptr() );
            return LocalHorizontalCoordinateSystem(
                glm::dvec3( p_ecef->get_ecefX(), p_ecef->get_ecefY(), p_ecef->get_ecefZ() ),
                LocalDirection::East, LocalDirection::Up, LocalDirection::North, 1.0 / scale );
        }
    }
}

const CesiumGeospatial::LocalHorizontalCoordinateSystem &CesiumGeoreference::getCoordinateSystem()
{
    if ( !coordinateSystem )
    {
        this->computeLocalToEarthCenteredEarthFixedTransformation();
    }
    return *coordinateSystem;
}

void CesiumGeoreference::computeLocalToEarthCenteredEarthFixedTransformation()
{
    this->coordinateSystem = this->createCoordinateSystem();
    this->localToEcef = this->coordinateSystem->getLocalToEcefTransformation();
    this->ecefToLocal = this->coordinateSystem->getEcefToLocalTransformation();
}

void CesiumGeoreference::updateGeoreference()
{
    UtilityFunctions::print( "---updateGeoreference-----" );
    this->computeLocalToEarthCenteredEarthFixedTransformation();
}

  • xyz replied to this.
    xuwzen2024 changed the title to godot-cpp UI encountering numerous warnings when setting default Values .

    xuwzen2024 Not enough information. Post the complete code for both classes, including headers.

    I have posted the full code for the CesiumGeoreference class, which I believe is sufficient for addressing the issue.

    • xyz replied to this.

      xuwzen2024 Knowing how EarthCenteredEarthFixed looks like would be useful as well.

      xuwzen2024 If I understood the warning correctly, it complains that an instantiated object is assigned in the constructor. Maybe try to declare a non-refed EarthCenteredEarthFixed as a class member and assign that in the constructor. You also use the same variable name originAuthority for the class member as well as local variable in the constructor, which just adds to the confusion. And last, if originAuthority is always supposed to be of type EarthCenteredEarthFixed then declare it as a reference to that exact type instead of reference to the base class Resource.

      I need the originAuthority to be of two possible types: EarthCenteredEarthFixed and LongitudeLatitudeHeight, with the default value being EarthCenteredEarthFixed . Thx, I will try out your suggestions.
      CesiumOriginAuthority code:
      header:

      #pragma once
      
      #include <godot_cpp/variant/string.hpp>
      #include <godot_cpp/classes/resource.hpp>
      
      using namespace godot;
      
      namespace CesiumForGodot {
          /*
          *<summary>
              Sets the origin of the coordinate system to a particular <see cref="longitude"/>,
              <see cref="latitude"/>, and <see cref="height"/>.
              </summary>
              <remarks>
              Calling this method is more efficient than setting the properties individually.
              </remarks>
              <param name="longitude">The longitude in degrees, in the range -180 to 180.</param>
              <param name="latitude">The latitude in degrees, in the range -90 to 90.</param>
              <param name="height">
              The height in meters above the ellipsoid. Do not confuse this with a geoid height
              or height above mean sea level, which can be tens of meters higher or lower
              depending on where in the world the object is located.
              </param>
          */
          class LongitudeLatitudeHeight : public Resource {
              GDCLASS(LongitudeLatitudeHeight, Resource)
      
          private:
              double longitude;
              double latitude;
              double height;
      
          protected:
              static void _bind_methods();
      
          public:
              LongitudeLatitudeHeight();
              ~LongitudeLatitudeHeight();
      
              void set_longitude(const double p_longitude);
              double get_longitude() const;
      
              void set_latitude(const double p_latitude);
              double get_latitude() const;
      
              void set_height(const double p_height);
              double get_height() const;
          };
      
          /*
          * The Earth-Centered, Earth-Fixed coordinate of the origin of the coordinate system
          */
          class EarthCenteredEarthFixed : public Resource {
              GDCLASS(EarthCenteredEarthFixed, Resource)
      
          private:
              double ecefX = 6378137.0;
              double ecefY = 0.0;
              double ecefZ = 0.0;
      
          protected:
              static void _bind_methods();
      
          public:
              EarthCenteredEarthFixed();
              ~EarthCenteredEarthFixed();
      
              void set_ecefX(const double p_ecefX);
              double get_ecefX() const;
      
              void set_ecefY(const double p_ecefY);
              double get_ecefY() const;
      
              void set_ecefZ(const double p_ecefZ);
              double get_ecefZ() const;
          };
      
      } // namespace CesiumForGodot

      definition:

      #include "CesiumOriginAuthority.h"
      
      #include <godot_cpp/core/class_db.hpp>
      #include <godot_cpp/variant/string.hpp>
      
      using namespace godot;
      using namespace CesiumForGodot;
      
      void LongitudeLatitudeHeight::_bind_methods()
      {
          ClassDB::bind_method( D_METHOD( "get_longitude" ), &LongitudeLatitudeHeight::get_longitude );
          ClassDB::bind_method( D_METHOD( "set_longitude", "p_longitude" ),
                                &LongitudeLatitudeHeight::set_longitude );
          ClassDB::add_property( "LongitudeLatitudeHeight", PropertyInfo( Variant::FLOAT, "longitude" ),
                                 "set_longitude", "get_longitude" );
      
          ClassDB::bind_method( D_METHOD( "get_latitude" ), &LongitudeLatitudeHeight::get_latitude );
          ClassDB::bind_method( D_METHOD( "set_latitude", "p_latitude" ),
                                &LongitudeLatitudeHeight::set_latitude );
          ClassDB::add_property( "LongitudeLatitudeHeight", PropertyInfo( Variant::FLOAT, "latitude" ),
                                 "set_latitude", "get_latitude" );
      
          ClassDB::bind_method( D_METHOD( "get_height" ), &LongitudeLatitudeHeight::get_height );
          ClassDB::bind_method( D_METHOD( "set_height", "p_height" ),
                                &LongitudeLatitudeHeight::set_height );
          ClassDB::add_property( "LongitudeLatitudeHeight", PropertyInfo( Variant::FLOAT, "height" ),
                                 "set_height", "get_height" );
      
          ADD_SIGNAL( MethodInfo( "lngLatH_changed" ) );
      }
      
      LongitudeLatitudeHeight::LongitudeLatitudeHeight()
      {
          longitude = 0.0;
          latitude = 0.0;
          height = 0.0;
      }
      
      LongitudeLatitudeHeight::~LongitudeLatitudeHeight()
      {
          // Add your cleanup here.
      }
      
      void LongitudeLatitudeHeight::set_longitude( const double p_longitude )
      {
          if ( longitude != p_longitude )
          {
              longitude = p_longitude;
              emit_signal( "lngLatH_changed" );
          }
      }
      
      double LongitudeLatitudeHeight::get_longitude() const
      {
          return longitude;
      }
      
      void LongitudeLatitudeHeight::set_latitude( const double p_latitude )
      {
          if ( latitude != p_latitude )
          {
              latitude = p_latitude;
              emit_signal( "lngLatH_changed" );
          }
      }
      
      double LongitudeLatitudeHeight::get_latitude() const
      {
          return latitude;
      }
      
      void LongitudeLatitudeHeight::set_height( const double p_height )
      {
          if ( height != p_height )
          {
              height = p_height;
              emit_signal( "lngLatH_changed" );
          }
      }
      
      double LongitudeLatitudeHeight::get_height() const
      {
          return height;
      }
      
      void EarthCenteredEarthFixed::_bind_methods()
      {
          ClassDB::bind_method( D_METHOD( "get_ecefX" ), &EarthCenteredEarthFixed::get_ecefX );
          ClassDB::bind_method( D_METHOD( "set_ecefX", "p_ecefX" ), &EarthCenteredEarthFixed::set_ecefX );
          ClassDB::add_property( "EarthCenteredEarthFixed", PropertyInfo( Variant::FLOAT, "ecefX" ),
                                 "set_ecefX", "get_ecefX" );
      
          ClassDB::bind_method( D_METHOD( "get_ecefY" ), &EarthCenteredEarthFixed::get_ecefY );
          ClassDB::bind_method( D_METHOD( "set_ecefY", "p_ecefY" ), &EarthCenteredEarthFixed::set_ecefY );
          ClassDB::add_property( "EarthCenteredEarthFixed", PropertyInfo( Variant::FLOAT, "ecefY" ),
                                 "set_ecefY", "get_ecefY" );
      
          ClassDB::bind_method( D_METHOD( "get_ecefZ" ), &EarthCenteredEarthFixed::get_ecefZ );
          ClassDB::bind_method( D_METHOD( "set_ecefZ", "p_ecefZ" ), &EarthCenteredEarthFixed::set_ecefZ );
          ClassDB::add_property( "EarthCenteredEarthFixed", PropertyInfo( Variant::FLOAT, "ecefZ" ),
                                 "set_ecefZ", "get_ecefZ" );
          ADD_SIGNAL( MethodInfo( "ecef_changed" ) );
      }
      
      EarthCenteredEarthFixed::EarthCenteredEarthFixed()
      {
          ecefX = 6378137.0;
          ecefY = 0.0;
          ecefZ = 0.0;
      }
      
      EarthCenteredEarthFixed::~EarthCenteredEarthFixed()
      {
          // Add your cleanup here.
      }
      
      void EarthCenteredEarthFixed::set_ecefX( const double p_ecefX )
      {
          if ( ecefX != p_ecefX )
          {
              ecefX = p_ecefX;
              emit_signal( "ecef_changed" );
          }
      }
      
      double EarthCenteredEarthFixed::get_ecefX() const
      {
          return ecefX;
      }
      
      void EarthCenteredEarthFixed::set_ecefY( const double p_ecefY )
      {
          if ( ecefY != p_ecefY )
          {
              ecefY = p_ecefY;
              emit_signal( "ecef_changed" );
          }
      }
      
      double EarthCenteredEarthFixed::get_ecefY() const
      {
          return ecefY;
      }
      
      void EarthCenteredEarthFixed::set_ecefZ( const double p_ecefZ )
      {
          if ( ecefZ != p_ecefZ )
          {
              ecefZ = p_ecefZ;
              emit_signal( "ecef_changed" );
          }
      }
      
      double EarthCenteredEarthFixed::get_ecefZ() const
      {
          return ecefZ;
      }