/* osgEarth
* Copyright 2025 Pelican Mapping
* MIT License
*/
#ifndef OSGEARTH_ANNO_MODEL_NODE_H
#define OSGEARTH_ANNO_MODEL_NODE_H 1

#include <osgEarth/GeoPositionNode>
#include <osgEarth/URI>
#include <osgEarth/CachePolicy>
#include <osgEarth/ShaderUtils>
#include <osgDB/ReaderWriter>

namespace osgEarth
{
    /**
     * Annotation node that loads a 3D model from a URI and places it
     * at a geo location.
     */
    class OSGEARTH_EXPORT ModelNode : public GeoPositionNode
    {
    public:
        /**
         * Constructs a model node; the style must contain an InstanceSymbol
         * (ModelSymbol or IconSymbol) to produce a valid node.
         */
        ModelNode(
            MapNode*              mapNode,
            const Style&          style,
            const osgDB::Options* readOptoins =0L );

        /**
         * Sets a new style and rebuilds the node.
         */
        void setStyle( const Style& style );

        /**
         * Gets the style last used to build this node.
         */
        const Style& getStyle() const { return _style; }

        //! Whether to generate shaders on the model and its children
        //! Default = GENERATE. Set to INHERIT to use the default one-texture
        //! shader for better performance.
        void setShaderPolicy(const ShaderPolicy& value) { _shaderPolicy = value; }
        const ShaderPolicy& getShaderPolicy() const { return _shaderPolicy.get(); }

    public:

        /**
         * Constructs a model node from a serialized Config.
         * (internal method).
         */
        ModelNode(
            const Config&         conf,
            const osgDB::Options* readOptions );

        virtual Config getConfig() const;

    protected:

        Style _style;
        osg::ref_ptr<const osgDB::Options> _readOptions;
        optional<ShaderPolicy> _shaderPolicy;

        void compileModel();

        virtual ~ModelNode() { }

    private:

        void construct();
    };

}

#endif // OSGEARTH_ANNO_LOCAL_GEOMETRY_NODE_H
