- Timestamp:
- 10/24/04 16:42:40 (9 years ago)
- Files:
-
- 1 modified
Legend:
- Unmodified
- Added
- Removed
-
OpenSceneGraph/trunk/include/osgUtil/TangentSpaceGenerator
r3432 r3526 25 25 { 26 26 27 /**28 This class generates three arrays containing tangent-space basis vectors. It takes29 a texture-mapped Geometry object as input, traverses its primitive sets and computes30 Tangent, Normal and Binormal vectors for each vertex, storing them into arrays.31 The resulting arrays can be used as vertex program varying (per-vertex) parameters,32 enabling advanced effects like bump-mapping.33 To use this class, simply call the generate() method specifying the Geometry object34 you want to process and the texture unit that contains UV mapping for the normal map;35 then you can retrieve the TBN arrays by calling getTangentArray(), getNormalArray()36 and getBinormalArray() methods.37 */38 class OSGUTIL_EXPORT TangentSpaceGenerator: public osg::Referenced {39 public:40 TangentSpaceGenerator();41 TangentSpaceGenerator(const TangentSpaceGenerator ©, const osg::CopyOp ©op = osg::CopyOp::SHALLOW_COPY);27 /** 28 The TangentSpaceGenerator class generates three arrays containing tangent-space basis vectors. 29 It takes a texture-mapped Geometry object as input, traverses its primitive sets and computes 30 Tangent, Normal and Binormal vectors for each vertex, storing them into arrays. 31 The resulting arrays can be used as vertex program varying (per-vertex) parameters, 32 enabling advanced effects like bump-mapping. 33 To use this class, simply call the generate() method specifying the Geometry object 34 you want to process and the texture unit that contains UV mapping for the normal map; 35 then you can retrieve the TBN arrays by calling getTangentArray(), getNormalArray() 36 and getBinormalArray() methods. 37 */ 38 class OSGUTIL_EXPORT TangentSpaceGenerator: public osg::Referenced { 39 public: 40 TangentSpaceGenerator(); 41 TangentSpaceGenerator(const TangentSpaceGenerator ©, const osg::CopyOp ©op = osg::CopyOp::SHALLOW_COPY); 42 42 43 void generate(osg::Geometry *geo, int normal_map_tex_unit = 0);43 void generate(osg::Geometry *geo, int normal_map_tex_unit = 0); 44 44 45 inline osg::Vec4Array *getTangentArray() { return T_.get(); }46 inline const osg::Vec4Array *getTangentArray() const { return T_.get(); }47 inline void setTangentArray(osg::Vec4Array *array) { T_ = array; }45 inline osg::Vec4Array *getTangentArray() { return T_.get(); } 46 inline const osg::Vec4Array *getTangentArray() const { return T_.get(); } 47 inline void setTangentArray(osg::Vec4Array *array) { T_ = array; } 48 48 49 inline osg::Vec4Array *getNormalArray() { return N_.get(); }50 inline const osg::Vec4Array *getNormalArray() const { return N_.get(); }51 inline void setNormalArray(osg::Vec4Array *array) { N_ = array; }49 inline osg::Vec4Array *getNormalArray() { return N_.get(); } 50 inline const osg::Vec4Array *getNormalArray() const { return N_.get(); } 51 inline void setNormalArray(osg::Vec4Array *array) { N_ = array; } 52 52 53 inline osg::Vec4Array *getBinormalArray() { return B_.get(); }54 inline const osg::Vec4Array *getBinormalArray() const { return B_.get(); }55 inline void setBinormalArray(osg::Vec4Array *array) { B_ = array; }53 inline osg::Vec4Array *getBinormalArray() { return B_.get(); } 54 inline const osg::Vec4Array *getBinormalArray() const { return B_.get(); } 55 inline void setBinormalArray(osg::Vec4Array *array) { B_ = array; } 56 56 57 protected:58 virtual ~TangentSpaceGenerator() {}59 TangentSpaceGenerator &operator=(const TangentSpaceGenerator &) { return *this; }57 protected: 58 virtual ~TangentSpaceGenerator() {} 59 TangentSpaceGenerator &operator=(const TangentSpaceGenerator &) { return *this; } 60 60 61 void compute_basis_vectors(osg::PrimitiveSet *pset, const osg::Array *vx, const osg::Array *nx, const osg::Array *tx, int iA, int iB, int iC);61 void compute_basis_vectors(osg::PrimitiveSet *pset, const osg::Array *vx, const osg::Array *nx, const osg::Array *tx, int iA, int iB, int iC); 62 62 63 private:64 osg::ref_ptr<osg::Vec4Array> T_;65 osg::ref_ptr<osg::Vec4Array> B_;66 osg::ref_ptr<osg::Vec4Array> N_;67 };63 private: 64 osg::ref_ptr<osg::Vec4Array> T_; 65 osg::ref_ptr<osg::Vec4Array> B_; 66 osg::ref_ptr<osg::Vec4Array> N_; 67 }; 68 68 69 69 }
