Open Inventor Release 2024.1.0
 
Loading...
Searching...
No Matches
SoTangentBundle.h
Go to the documentation of this file.
1/*=================================================================================
2*** THE CONTENT OF THIS WORK IS PROPRIETARY TO FEI S.A.S, (FEI S.A.S.), ***
3*** AND IS DISTRIBUTED UNDER A LICENSE AGREEMENT. ***
4*** ***
5*** REPRODUCTION, DISCLOSURE, OR USE, IN WHOLE OR IN PART, OTHER THAN AS ***
6*** SPECIFIED IN THE LICENSE ARE NOT TO BE UNDERTAKEN EXCEPT WITH PRIOR ***
7*** WRITTEN AUTHORIZATION OF FEI S.A.S. ***
8*** ***
9*** RESTRICTED RIGHTS LEGEND ***
10*** USE, DUPLICATION, OR DISCLOSURE BY THE GOVERNMENT OF THE CONTENT OF THIS ***
11*** WORK OR RELATED DOCUMENTATION IS SUBJECT TO RESTRICTIONS AS SET FORTH IN ***
12*** SUBPARAGRAPH (C)(1) OF THE COMMERCIAL COMPUTER SOFTWARE RESTRICTED RIGHT ***
13*** CLAUSE AT FAR 52.227-19 OR SUBPARAGRAPH (C)(1)(II) OF THE RIGHTS IN ***
14*** TECHNICAL DATA AND COMPUTER SOFTWARE CLAUSE AT DFARS 52.227-7013. ***
15*** ***
16*** COPYRIGHT (C) 1996-2019 BY FEI S.A.S, ***
17*** BORDEAUX, FRANCE ***
18*** ALL RIGHTS RESERVED ***
19=================================================================================*/
20
21#pragma once
22
27
28class SoTangentCache;
29
40{
41public:
42 SoTangentBundle( SoAction* action );
43
45
46 // Returns true if tangents need to be generated.
47 bool shouldGenerate( int numNeeded );
48
49 // Initializes generation in the case where shouldGenerate() is
50 // not called. (shouldGenerate() does this automatically).
51 void initGenerator( int initialNum = 100 );
52
54 //
55 // If shouldGenerate() returns TRUE, these methods can be used by
56 // shapes to specify the geometry to generate tangents for. They
57 // are front-ends to methods on the SoTangentGenerator class:
58 //
59
60 // Send a line strip's worth of vertices. Begin a strip, send as
61 // many vertices as you want, and then end the strip.
63 {
64 m_generator->beginLineStrip();
65 }
66
67 void lineStripVertex( const SbVec3f& point )
68 {
69 m_generator->lineStripVertex( point );
70 }
71
73 {
74 m_generator->endLineStrip();
75 }
76
77 // See SoTangentGenerator for details.
78 void setupIndexedVertexArray( const SbVec3f* pointArray )
79 {
80 m_generator->setupIndexedVertexArray( pointArray );
81 }
82
83 void lineStripVertex( const int32_t index )
84 {
85 m_generator->lineStripVertex( index );
86 }
87
88 void setupApproxShapeSize( const int32_t numVert )
89 {
90 m_generator->setupApproxShapeSize( numVert );
91 }
92
93 // Calculates the tangents once all vertices have been sent. The
94 // tangents are stored by the bundle so the caller does not have to
95 // deal with them directly. The startIndex argument specifies the
96 // index at which the generated tangents will begin-- it can be
97 // used by shapes that allow the coordinates and tangents to be
98 // offset (non-indexed shapes). If addToState is TRUE, the
99 // state will be pushed, the tangents will be added to the
100 // state; otherwise, you can just use
101 // getGeneratedTangents/getNumGeneratedTangents to get the generated
102 // tangents.
103 //
104 // The tangent bundle DOES NOT FREE the generated tangents! It is
105 // expected that tangents will be added to a tangent cache, and the
106 // tangent cache will free the tangents.
107 //
108 void generate( int startIndex = 0, bool addToState = true );
109
110 // Returns the generated tangents.
112 {
113 return m_generator->getTangents();
114 }
115
117 {
118 return m_generator->getNumTangents();
119 }
120
122 {
123 return m_generator->getBinding();
124 }
125
126
127 // This allows shapes that generate their own tangents (for
128 // efficiency) to store the resulting tangents in the state. The
129 // bundle takes care of pushing/popping the state.
130 // Note: This method only adds the tangents to the state, it does
131 // NOT store a pointer to them (so you cannot call the
132 // getGenerated() routines)
133 void set(
134 int32_t numTangents,
135 const SbVec3f* tangents,
136 SoTangentBindingElement::Binding binding /*= SoTangentBindingElement::PER_VERTEX */,
137 int startIndex = 0
138 );
139
140 // to set the SoTangentBundle from a SoTangentCache
141 void set( SoTangentCache* tc );
142
143 // Returns indexed tangent. This can be used for primitive
144 // generation or during rendering
145 const SbVec3f& get( int index ) const
146 {
147 return m_tangElt->getNum() != 0 ? m_tangElt->get( index - m_startIndex ) : s_zVers;
148 }
149
150 int getStartIndex() const
151 {
152 return m_startIndex;
153 }
154
155private:
156 SoTangentGenerator* m_generator;
157
158private:
159 // Tangent elements:
160 const SoTangentElement* m_tangElt;
161 bool m_pushedState; // We pushed state to set tangents
162 SoNode* m_currentNode; // Node that created the bundle
163 static const SbVec3f s_zVers;
164 int m_startIndex; // this the offset used in indexing the tangents WITHOUT allocating useless memory
165 bool m_tangSetOrGen;
166};
void generate()
Calculate the normals once all vertices have been sent.
void beginLineStrip()
Send a line strip's worth of vertices.
void lineStripVertex(const SbVec3f &point)
SoTangentBindingElement::Binding getTangentBinding() const
virtual ~SoTangentBundle()
Class: SoTangentBundle.
void endLineStrip()
bool shouldGenerate(int numNeeded)
void initGenerator(int initialNum=100)
void setupApproxShapeSize(const int32_t numVert)
Resets the approximative number of vertices that we have to generate tangents for.
const SbVec3f & get(int index) const
void set(int32_t numTangents, const SbVec3f *tangents, SoTangentBindingElement::Binding binding, int startIndex=0)
int getStartIndex() const
int getNumGeneratedTangents() const
void setupIndexedVertexArray(const SbVec3f *pointArray)
Specifies a pointer to the array of points that will be used in subsequent calls to polygonVertex(ind...
const SbVec3f * getGeneratedTangents() const
3D vector class.
Definition SbVec.h:932
Abstract base class for all actions.
Definition SoAction.h:132
Abstract base class for all database nodes.
Definition SoNode.h:145
Binding
The choice of values is for compatibility with Open Inventor 2.0 binary format files:
Allows read-only access to the top element in the state.
int32_t getNum() const
Returns the number of tangent vectors in an instance.
const SbVec3f & get(int index) const
Returns the indexed tangent from an element.