Show
Ignore:
Timestamp:
03/10/09 11:56:00 (6 years ago)
Author:
robert
Message:

From David Callu, "Problem:

osgText::Text and osgText::Text3D use the same font file.
The first really load the file and obtain an osgText::Font object,
the second use the cache created during the first load of the
font file, and so obtain an osgText::Font object instead of
osgText::Font3D object. To obtain an osgText::Font3D object,
osgText::Text3D call osgDB::readObjectFile(...) with an option
to specify the plugin we want an osgText::Font3D instead of
osgText::Font.

Generalised Problem:

In osgDB::Registry, loaded file cache is referenced by the name
of this file, so if I load a file with some options, and the cache
already contain object for this filename, I obtain an object
potentially not loaded with my options.

Behaviours:

Cache management is delegate to osgDB::Registry, but cache
coherence (load a file with option then reuse it, deactivate the
cache when load a specific file or don't cached the loaded file)
is user's responsibility.

Text3D solution:

Postfix the font file name by .text3d or something similar and then have the freetype plugin return
osgText::Font3D when it detects this.
This operation is done by osgText::readFont3DFile() which unsure the filename have .text3d as extension.
This is totaly transparent for user, and backward compatible.

BTW, I fix the bug about the Normal of 3D text. Currently, the front and wall face have
the same normal (0,0,1) in the Text3D object coordinate. Now the wall face have its own
normal array computed by the plugin.

BTW 2, I implement
- void Text3D::accept(osg::Drawable::ConstAttributeFunctor?& af) const
- void Text3D::accept(osg::PrimitiveFunctor?& pf) const
so now statistics are well reported.
"

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • OpenSceneGraph/trunk/include/osgText/Font3D

    r7874 r9881  
    1 /* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield  
     1/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield 
    22 * 
    3  * This library is open source and may be redistributed and/or modified under   
    4  * the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or  
     3 * This library is open source and may be redistributed and/or modified under 
     4 * the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or 
    55 * (at your option) any later version.  The full license is in LICENSE file 
    66 * included with this distribution, and on the openscenegraph.org website. 
    7  *  
     7 * 
    88 * This library is distributed in the hope that it will be useful, 
    99 * but WITHOUT ANY WARRANTY; without even the implied warranty of 
    10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the  
     10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the 
    1111 * OpenSceneGraph Public License for more details. 
    1212*/ 
     
    3232 
    3333/** Read a font from specified file. The filename may contain a path. 
    34   * It will search for the font file in the following places in this order:  
     34  * It will search for the font file in the following places in this order: 
    3535  * - In the current directory 
    3636  * - All paths defined in OSG_FILE_PATH or OSGFILEPATH environment variable 
     
    4646  * - Other OS: In /usr/share/fonts/ttf/western 
    4747  * - Other OS: In /usr/share/fonts/ttf/decoratives 
    48   *  
     48  * 
    4949  * If the given file could not be found, the path part will be stripped and 
    5050  * the file will be searched again in the OS specific directories. 
     
    6868// declare the interface to a font. 
    6969public: 
    70      
     70 
    7171    // forward declare nested classes. 
    7272    class Glyph3D; 
     
    9393    /** Get a Glyph for specified charcode, and the font size nearest to the current font size hint.*/ 
    9494    virtual Glyph3D* getGlyph(unsigned int charcode); 
    95      
     95 
    9696    /** Return true if this font provides vertical alignments and spacing or glyphs.*/ 
    9797    virtual bool hasVertical() const; 
     
    9999    /** Return the scale to apply on the glyph to have a charactere size equal to 1 */ 
    100100    virtual float getScale() const { return _implementation->getScale(); }; 
    101      
     101 
    102102    // make Text a friend to allow it add and remove its entry in the Font's _textList. 
    103103    friend class Font3DImplementation; 
     
    110110    /** Set whether to use a mutex to ensure ref() and unref() */ 
    111111    virtual void setThreadSafeRefUnref(bool threadSafe); 
    112      
     112 
    113113    typedef OpenThreads::Mutex Font3DMutex; 
    114114 
     
    116116 
    117117    virtual ~Font3D(); 
    118      
     118 
    119119//    void addGlyph(unsigned int width, unsigned int height, unsigned int charcode, Glyph* glyph); 
    120120    void addGlyph(unsigned int charcode, Glyph3D* glyph); 
    121      
     121 
    122122    // current active size of font 
    123123    unsigned int                        _depth; 
     
    128128 
    129129    typedef std::map<char, osg::ref_ptr<Glyph3D> > Glyph3DMap; 
    130     Glyph3DMap _glyph3DMap;  
    131      
     130    Glyph3DMap _glyph3DMap; 
     131 
    132132    osg::ref_ptr<Font3DImplementation> _implementation; 
    133133 
    134      
     134 
    135135// declare the nested classes. 
    136136public: 
     
    139139    { 
    140140    public: 
    141      
     141 
    142142        Font3DImplementation(): 
    143143            osg::Referenced(true), 
    144144            _facade(0) {} 
    145      
     145 
    146146        virtual std::string getFileName() const = 0; 
    147147 
     
    154154        /** Return true if this font provides vertical alignments and spacing or glyphs.*/ 
    155155        virtual bool hasVertical() const = 0; 
    156          
     156 
    157157        virtual float getScale() const = 0; 
    158    
     158 
    159159        void setFontWidth(unsigned int width) { _facade->_width = width; } 
    160160 
    161161        void setFontHeight(unsigned int height) { _facade->_height = height; } 
    162          
     162 
    163163        void setFontDepth(unsigned int depth) { _facade->_depth = depth; } 
    164          
     164 
    165165//        void addGlyph(unsigned int width, unsigned int height, unsigned int charcode, Glyph3D* glyph) 
    166166//        { 
    167167//            _facade->addGlyph(width, height, charcode, glyph); 
    168168//        } 
    169 //         
     169// 
    170170//        void addGlyph(unsigned int charcode, Glyph3D* glyph) 
    171171//        { 
     
    182182        Glyph3D(unsigned int glyphCode): 
    183183            osg::Referenced(true), 
    184             _glyphCode(glyphCode),  
     184            _glyphCode(glyphCode), 
    185185            _horizontalBearing(0,0), 
    186186            _horizontalAdvance(0), 
     
    188188            _verticalAdvance(0) 
    189189            {} 
    190          
     190 
    191191 
    192192        /** return -1 if *this < *rhs, 0 if *this==*rhs, 1 if *this>*rhs.*/ 
    193193//        virtual int compare(const osg::StateAttribute& rhs) const; 
    194 //         
     194// 
    195195//        virtual void apply(osg::State& state) const; 
    196196 
    197          
    198          
     197 
     198 
    199199        unsigned int getGlyphCode() const { return _glyphCode; } 
    200          
     200 
    201201        void setHorizontalBearing(const osg::Vec2& bearing) { _horizontalBearing=bearing; } 
    202202        const osg::Vec2 & getHorizontalBearing() const { return _horizontalBearing; } 
    203          
     203 
    204204        void setHorizontalAdvance(float advance) { _horizontalAdvance=advance; } 
    205205        float getHorizontalAdvance() const { return _horizontalAdvance; } 
     
    210210        void setVerticalAdvance(float advance) { _verticalAdvance=advance; } 
    211211        float getVerticalAdvance() const { return _verticalAdvance; } 
    212                  
     212 
    213213        void setBoundingBox(osg::BoundingBox & bb) { _bb=bb; } 
    214214        const osg::BoundingBox & getBoundingBox() const { return _bb; } 
    215          
    216          
     215 
     216 
    217217        /** Set whether to use a mutex to ensure ref() and unref() are thread safe.*/ 
    218218        virtual void setThreadSafeRefUnref(bool threadSafe); 
    219219 
    220          
     220 
    221221        /** Get the PrimitiveSetList for the front face. */ 
    222222        osg::Geometry::PrimitiveSetList & getFrontPrimitiveSetList() { return _frontPrimitiveSetList; } 
     
    225225        /** Get et the PrimitiveSetList for the back face. */ 
    226226        osg::Geometry::PrimitiveSetList & getBackPrimitiveSetList() { return _backPrimitiveSetList; } 
    227          
     227 
    228228        /** Set the VertexArray of the glyph. */ 
    229229        void setVertexArray(osg::Vec3Array * va) { _vertexArray = va; } 
    230230        /** Get the VertexArray of the glyph. */ 
    231231        osg::Vec3Array * getVertexArray() { return _vertexArray.get(); } 
     232        /** Set the VertexArray of the glyph. */ 
     233        void setNormalArray(osg::Vec3Array * na) { _normalArray = na; } 
    232234        /** Get the NormalArray for the wall face. */ 
    233235        osg::Vec3Array * getNormalArray() { return _normalArray.get(); } 
    234          
     236 
    235237        float getHorizontalWidth() { return (-_horizontalBearing.x() + _horizontalAdvance); } 
    236238        float getHorizontalHeight() { return (-_horizontalBearing.y() + _bb.yMax()); } 
    237239        float getVerticalWidth() { return (-_verticalBearing.x() + _bb.xMax()); } 
    238240        float getVerticalHeight() { return (-_verticalBearing.y() + _verticalAdvance); } 
    239          
     241 
    240242        void setWidth(float width) { _width = width; } 
    241243        float getWidth() { return _width; } 
    242          
     244 
    243245        void setHeight(float height) { _height = height; } 
    244246        float getHeight() { return _height; } 
    245          
     247 
    246248    protected: 
    247      
     249 
    248250        virtual ~Glyph3D() {} 
    249251 
     
    256258        float                       _verticalAdvance; 
    257259 
    258         osg::BoundingBox            _bb;         
     260        osg::BoundingBox            _bb; 
    259261//        osg::Vec2                   _advance; 
    260          
     262 
    261263        float _width; 
    262264        float _height; 
    263          
    264          
     265 
     266 
    265267        osg::ref_ptr<osg::Vec3Array> _vertexArray; 
    266268        osg::ref_ptr<osg::Vec3Array> _normalArray; 
    267          
     269 
    268270        osg::Geometry::PrimitiveSetList _frontPrimitiveSetList; 
    269271        osg::Geometry::PrimitiveSetList _wallPrimitiveSetList; 
    270272        osg::Geometry::PrimitiveSetList _backPrimitiveSetList; 
    271          
    272          
     273 
     274 
    273275    }; 
    274276