root/OpenSceneGraph/trunk/src/osgPlugins/fbx/fbxMaterialToOsgStateSet.h @ 13466

Revision 13466, 2.8 kB (checked in by robert, 2 hours ago)

Added DragCallback? class to help dialog dragging support.
Introduced a new Widget::computeExtentsPositionInLocalCoordinates() method that intersects with a ray through mouse pointer and the extents of the widget.

  • Property svn:eol-style set to native
Line 
1#ifndef FBXMATERIALTOOSGSTATESET_H
2#define FBXMATERIALTOOSGSTATESET_H
3
4#include <map>
5#include <memory>
6#include <osg/Material>
7#include <osg/StateSet>
8#include <osgDB/Options>
9#include <osg/Texture2D>
10
11#if defined(_MSC_VER)
12#pragma warning( disable : 4505 )
13#pragma warning( default : 4996 )
14#endif
15#include <fbxsdk.h>
16
17//The only things we need to create a new StateSet are texture and materials. So we store that in a pair.
18//We Don't store directly in stateSet because getOrCreateStateSet function set some parameters.
19
20struct StateSetContent
21{
22    StateSetContent()
23        : diffuseFactor(1.0),
24        reflectionFactor(1.0),
25        emissiveFactor(1.0)
26    {
27    }
28
29    osg::ref_ptr<osg::Material> material;
30
31    // textures objects...
32    osg::ref_ptr<osg::Texture2D> diffuseTexture;
33    osg::ref_ptr<osg::Texture2D> opacityTexture;
34    osg::ref_ptr<osg::Texture2D> reflectionTexture;
35    osg::ref_ptr<osg::Texture2D> emissiveTexture;
36    // more textures types here...
37
38    // textures maps channels names...
39    std::string diffuseChannel;
40    std::string opacityChannel;
41    std::string reflectionChannel;
42    std::string emissiveChannel;
43    // more channels names here...
44
45    // combining factors...
46    double diffuseFactor;
47    double reflectionFactor;
48    double emissiveFactor;
49    // more combining factors here...
50
51    double diffuseScaleU;
52    double diffuseScaleV;
53    double opacityScaleU;
54    double opacityScaleV;
55    double emissiveScaleU;
56    double emissiveScaleV;
57
58    // texture units (eventually used for each texture map)...
59    enum TextureUnit
60    {
61        DIFFUSE_TEXTURE_UNIT = 0,
62        OPACITY_TEXTURE_UNIT,
63        REFLECTION_TEXTURE_UNIT,
64        EMISSIVE_TEXTURE_UNIT
65        // more texture units here...
66    };
67};
68
69//We use the pointers set by the importer to not duplicate materials and textures.
70typedef std::map<const FbxSurfaceMaterial *, StateSetContent> FbxMaterialMap;
71
72//This map is used to not load the same image more than 1 time.
73typedef std::map<std::string, osg::Texture2D *> ImageMap;
74
75class FbxMaterialToOsgStateSet
76{
77public:
78    //Convert a FbxSurfaceMaterial to a osgMaterial and an osgTexture.
79    StateSetContent convert(const FbxSurfaceMaterial* pFbxMat);
80
81    //dir is the directory where fbx is stored (for relative path).
82    FbxMaterialToOsgStateSet(const std::string& dir, const osgDB::Options* options, bool lightmapTextures) :
83        _options(options),
84        _dir(dir),
85        _lightmapTextures(lightmapTextures){}
86
87    void checkInvertTransparency();
88private:
89    //Convert a texture fbx to an osg texture.
90    osg::ref_ptr<osg::Texture2D>
91    fbxTextureToOsgTexture(const FbxFileTexture* pOsgTex);
92    FbxMaterialMap       _fbxMaterialMap;
93    ImageMap              _imageMap;
94    const osgDB::Options* _options;
95    const std::string     _dir;
96    bool                  _lightmapTextures;
97};
98
99
100#endif //FBXMATERIALTOOSGSTATESET_H
Note: See TracBrowser for help on using the browser.