ruby-procedural 0.0.1-x86-linux

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (72) hide show
  1. data/Gemfile +4 -0
  2. data/README.md +29 -0
  3. data/Rakefile +65 -0
  4. data/bindings/procedural/interface/ProceduralBoxGenerator.i +12 -0
  5. data/bindings/procedural/interface/ProceduralCapsuleGenerator.i +12 -0
  6. data/bindings/procedural/interface/ProceduralConeGenerator.i +12 -0
  7. data/bindings/procedural/interface/ProceduralCylinderGenerator.i +12 -0
  8. data/bindings/procedural/interface/ProceduralExtruder.i +8 -0
  9. data/bindings/procedural/interface/ProceduralGeometryHelpers.i +15 -0
  10. data/bindings/procedural/interface/ProceduralHeader.i +8 -0
  11. data/bindings/procedural/interface/ProceduralIcoSphereGenerator.i +12 -0
  12. data/bindings/procedural/interface/ProceduralLathe.i +8 -0
  13. data/bindings/procedural/interface/ProceduralMeshGenerator.i +9 -0
  14. data/bindings/procedural/interface/ProceduralMultiShape.i +8 -0
  15. data/bindings/procedural/interface/ProceduralPath.i +8 -0
  16. data/bindings/procedural/interface/ProceduralPathGenerators.i +10 -0
  17. data/bindings/procedural/interface/ProceduralPlaneGenerator.i +12 -0
  18. data/bindings/procedural/interface/ProceduralPlatform.i +8 -0
  19. data/bindings/procedural/interface/ProceduralRoot.i +23 -0
  20. data/bindings/procedural/interface/ProceduralRoundedBoxGenerator.i +12 -0
  21. data/bindings/procedural/interface/ProceduralShape.i +8 -0
  22. data/bindings/procedural/interface/ProceduralShapeGenerators.i +10 -0
  23. data/bindings/procedural/interface/ProceduralSphereGenerator.i +11 -0
  24. data/bindings/procedural/interface/ProceduralSplines.i +8 -0
  25. data/bindings/procedural/interface/ProceduralStableHeaders.i +8 -0
  26. data/bindings/procedural/interface/ProceduralTorusGenerator.i +12 -0
  27. data/bindings/procedural/interface/ProceduralTorusKnotGenerator.i +12 -0
  28. data/bindings/procedural/interface/ProceduralTrack.i +8 -0
  29. data/bindings/procedural/interface/ProceduralTriangleBuffer.i +13 -0
  30. data/bindings/procedural/interface/ProceduralTriangulator.i +8 -0
  31. data/bindings/procedural/interface/ProceduralTubeGenerator.i +12 -0
  32. data/bindings/procedural/interface/ProceduralUtils.i +8 -0
  33. data/bindings/procedural/interface/Rakefile +22 -0
  34. data/bindings/procedural/interface/procedural.i +41 -0
  35. data/bindings/procedural/interface/procedural_wrap.cpp +36079 -0
  36. data/bindings/procedural/interface/procedural_wrap.h +19 -0
  37. data/bindings/procedural/interface/procedural_wrap.o +0 -0
  38. data/deps/include/OgreProcedural/Procedural.h +54 -0
  39. data/deps/include/OgreProcedural/ProceduralBoxGenerator.h +110 -0
  40. data/deps/include/OgreProcedural/ProceduralCapsuleGenerator.h +103 -0
  41. data/deps/include/OgreProcedural/ProceduralConeGenerator.h +90 -0
  42. data/deps/include/OgreProcedural/ProceduralCylinderGenerator.h +99 -0
  43. data/deps/include/OgreProcedural/ProceduralExtruder.h +131 -0
  44. data/deps/include/OgreProcedural/ProceduralGeometryHelpers.h +171 -0
  45. data/deps/include/OgreProcedural/ProceduralIcoSphereGenerator.h +76 -0
  46. data/deps/include/OgreProcedural/ProceduralLathe.h +129 -0
  47. data/deps/include/OgreProcedural/ProceduralMeshGenerator.h +286 -0
  48. data/deps/include/OgreProcedural/ProceduralMultiShape.h +126 -0
  49. data/deps/include/OgreProcedural/ProceduralPath.h +322 -0
  50. data/deps/include/OgreProcedural/ProceduralPathGenerators.h +281 -0
  51. data/deps/include/OgreProcedural/ProceduralPlaneGenerator.h +93 -0
  52. data/deps/include/OgreProcedural/ProceduralPlatform.h +54 -0
  53. data/deps/include/OgreProcedural/ProceduralRoot.h +65 -0
  54. data/deps/include/OgreProcedural/ProceduralRoundedBoxGenerator.h +118 -0
  55. data/deps/include/OgreProcedural/ProceduralShape.h +532 -0
  56. data/deps/include/OgreProcedural/ProceduralShapeGenerators.h +362 -0
  57. data/deps/include/OgreProcedural/ProceduralSphereGenerator.h +80 -0
  58. data/deps/include/OgreProcedural/ProceduralSplines.h +168 -0
  59. data/deps/include/OgreProcedural/ProceduralStableHeaders.h +28 -0
  60. data/deps/include/OgreProcedural/ProceduralTorusGenerator.h +88 -0
  61. data/deps/include/OgreProcedural/ProceduralTorusKnotGenerator.h +106 -0
  62. data/deps/include/OgreProcedural/ProceduralTrack.h +122 -0
  63. data/deps/include/OgreProcedural/ProceduralTriangleBuffer.h +328 -0
  64. data/deps/include/OgreProcedural/ProceduralTriangulator.h +173 -0
  65. data/deps/include/OgreProcedural/ProceduralTubeGenerator.h +96 -0
  66. data/deps/include/OgreProcedural/ProceduralUtils.h +185 -0
  67. data/deps/lib/libOgreProcedural.so +0 -0
  68. data/lib/procedural.so +0 -0
  69. data/lib/ruby-procedural/version.rb +5 -0
  70. data/lib/ruby-procedural.rb +27 -0
  71. data/ruby-procedural.gemspec +33 -0
  72. metadata +138 -0
@@ -0,0 +1,28 @@
1
+ /*
2
+ -----------------------------------------------------------------------------
3
+ This source file is part of ogre-procedural
4
+
5
+ For the latest info, see http://code.google.com/p/ogre-procedural/
6
+
7
+ Copyright (c) 2010 Michael Broutin
8
+
9
+ Permission is hereby granted, free of charge, to any person obtaining a copy
10
+ of this software and associated documentation files (the "Software"), to deal
11
+ in the Software without restriction, including without limitation the rights
12
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13
+ copies of the Software, and to permit persons to whom the Software is
14
+ furnished to do so, subject to the following conditions:
15
+
16
+ The above copyright notice and this permission notice shall be included in
17
+ all copies or substantial portions of the Software.
18
+
19
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
25
+ THE SOFTWARE.
26
+ -----------------------------------------------------------------------------
27
+ */
28
+ #include "Ogre.h"
@@ -0,0 +1,88 @@
1
+ /*
2
+ -----------------------------------------------------------------------------
3
+ This source file is part of ogre-procedural
4
+
5
+ For the latest info, see http://code.google.com/p/ogre-procedural/
6
+
7
+ Copyright (c) 2010 Michael Broutin
8
+
9
+ Permission is hereby granted, free of charge, to any person obtaining a copy
10
+ of this software and associated documentation files (the "Software"), to deal
11
+ in the Software without restriction, including without limitation the rights
12
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13
+ copies of the Software, and to permit persons to whom the Software is
14
+ furnished to do so, subject to the following conditions:
15
+
16
+ The above copyright notice and this permission notice shall be included in
17
+ all copies or substantial portions of the Software.
18
+
19
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
25
+ THE SOFTWARE.
26
+ -----------------------------------------------------------------------------
27
+ */
28
+ #ifndef PROCEDURAL_TORUS_GENERATOR_INCLUDED
29
+ #define PROCEDURAL_TORUS_GENERATOR_INCLUDED
30
+
31
+ #include "ProceduralMeshGenerator.h"
32
+ #include "ProceduralPlatform.h"
33
+
34
+ namespace Procedural
35
+ {
36
+ /** Builds a torus mesh whose axis is Y
37
+ */
38
+ class _ProceduralExport TorusGenerator : public MeshGenerator<TorusGenerator>
39
+ {
40
+ int mNumSegSection;
41
+ int mNumSegCircle;
42
+ Ogre::Real mRadius;
43
+ Ogre::Real mSectionRadius;
44
+ public:
45
+ /// Constructor with arguments
46
+ TorusGenerator(Ogre::Real radius=1.f, Ogre::Real sectionRadius=.2f, int numSegSection=16, int numSegCircle=16) :
47
+ mNumSegSection(numSegSection),
48
+ mNumSegCircle(numSegCircle),
49
+ mRadius(radius),
50
+ mSectionRadius(sectionRadius) {}
51
+
52
+ /**
53
+ * Builds the mesh into the given TriangleBuffer
54
+ * @param buffer The TriangleBuffer on where to append the mesh.
55
+ */
56
+ void addToTriangleBuffer(TriangleBuffer& buffer) const;
57
+
58
+ /** Sets the number of segments on the section circle */
59
+ inline TorusGenerator & setNumSegSection(int numSegSection)
60
+ {
61
+ mNumSegSection = numSegSection;
62
+ return *this;
63
+ }
64
+
65
+ /** Sets the number of segments along the guiding circle */
66
+ inline TorusGenerator & setNumSegCircle(int numSegCircle)
67
+ {
68
+ mNumSegCircle = numSegCircle;
69
+ return *this;
70
+ }
71
+
72
+ /** Sets the radius of the guiding circle */
73
+ inline TorusGenerator & setRadius(Ogre::Real radius)
74
+ {
75
+ mRadius = radius;
76
+ return *this;
77
+ }
78
+
79
+ /** Sets the radius of the section circle */
80
+ inline TorusGenerator & setSectionRadius(Ogre::Real sectionRadius)
81
+ {
82
+ mSectionRadius = sectionRadius;
83
+ return *this;
84
+ }
85
+
86
+ };
87
+ }
88
+ #endif
@@ -0,0 +1,106 @@
1
+ /*
2
+ -----------------------------------------------------------------------------
3
+ This source file is part of ogre-procedural
4
+
5
+ For the latest info, see http://code.google.com/p/ogre-procedural/
6
+
7
+ Copyright (c) 2010 Michael Broutin
8
+
9
+ Permission is hereby granted, free of charge, to any person obtaining a copy
10
+ of this software and associated documentation files (the "Software"), to deal
11
+ in the Software without restriction, including without limitation the rights
12
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13
+ copies of the Software, and to permit persons to whom the Software is
14
+ furnished to do so, subject to the following conditions:
15
+
16
+ The above copyright notice and this permission notice shall be included in
17
+ all copies or substantial portions of the Software.
18
+
19
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
25
+ THE SOFTWARE.
26
+ -----------------------------------------------------------------------------
27
+ */
28
+ #ifndef PROCEDURAL_TORUS_KNOT_GENERATOR_INCLUDED
29
+ #define PROCEDURAL_TORUS_KNOT_GENERATOR_INCLUDED
30
+
31
+ #include "ProceduralMeshGenerator.h"
32
+ #include "ProceduralPlatform.h"
33
+
34
+ namespace Procedural
35
+ {
36
+ /** Builds a torus knot mesh
37
+ */
38
+ class _ProceduralExport TorusKnotGenerator : public MeshGenerator<TorusKnotGenerator>
39
+ {
40
+ int mNumSegSection;
41
+ int mNumSegCircle;
42
+ Ogre::Real mRadius;
43
+ Ogre::Real mSectionRadius;
44
+ int mP;
45
+ int mQ;
46
+ public:
47
+ /// Constructor with arguments
48
+ TorusKnotGenerator(Ogre::Real radius=1.f, Ogre::Real sectionRadius=.2f, int p=2, int q=3, int numSegSection=8, int numSegCircle=16) :
49
+ mNumSegSection(numSegSection),
50
+ mNumSegCircle(numSegCircle),
51
+ mRadius(radius),
52
+ mSectionRadius(sectionRadius),
53
+ mP(p),
54
+ mQ(q) {}
55
+
56
+ /**
57
+ * Builds the mesh into the given TriangleBuffer
58
+ * @param buffer The TriangleBuffer on where to append the mesh.
59
+ */
60
+ void addToTriangleBuffer(TriangleBuffer& buffer) const;
61
+
62
+ /** Sets the number of segments along the section (default=8) */
63
+ inline TorusKnotGenerator & setNumSegSection(int numSegSection)
64
+ {
65
+ mNumSegSection = numSegSection;
66
+ return *this;
67
+ }
68
+
69
+ /** Sets the number of segments along the circle (default=16) */
70
+ inline TorusKnotGenerator & setNumSegCircle(int numSegCircle)
71
+ {
72
+ mNumSegCircle = numSegCircle;
73
+ return *this;
74
+ }
75
+
76
+ /** Sets the main radius of the knot (default=1) */
77
+ inline TorusKnotGenerator & setRadius(Ogre::Real radius)
78
+ {
79
+ mRadius = radius;
80
+ return *this;
81
+ }
82
+
83
+ /** Sets the section radius (default=0.2) */
84
+ inline TorusKnotGenerator & setSectionRadius(Ogre::Real sectionRadius)
85
+ {
86
+ mSectionRadius = sectionRadius;
87
+ return *this;
88
+ }
89
+
90
+ /** Sets the p parameter of the knot (default=2) */
91
+ inline TorusKnotGenerator & setP(int p)
92
+ {
93
+ mP = p;
94
+ return *this;
95
+ }
96
+
97
+ /** Sets the q parameter of the knot (default=3) */
98
+ inline TorusKnotGenerator & setQ(int q)
99
+ {
100
+ mQ = q;
101
+ return *this;
102
+ }
103
+
104
+ };
105
+ }
106
+ #endif
@@ -0,0 +1,122 @@
1
+ /*
2
+ -----------------------------------------------------------------------------
3
+ This source file is part of ogre-procedural
4
+
5
+ For the latest info, see http://code.google.com/p/ogre-procedural/
6
+
7
+ Copyright (c) 2010 Michael Broutin
8
+
9
+ Permission is hereby granted, free of charge, to any person obtaining a copy
10
+ of this software and associated documentation files (the "Software"), to deal
11
+ in the Software without restriction, including without limitation the rights
12
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13
+ copies of the Software, and to permit persons to whom the Software is
14
+ furnished to do so, subject to the following conditions:
15
+
16
+ The above copyright notice and this permission notice shall be included in
17
+ all copies or substantial portions of the Software.
18
+
19
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
25
+ THE SOFTWARE.
26
+ -----------------------------------------------------------------------------
27
+ */
28
+ #ifndef PROCEDURAL_TRACK_INCLUDED
29
+ #define PROCEDURAL_TRACK_INCLUDED
30
+
31
+ #include "ProceduralPlatform.h"
32
+ #include "OgreMath.h"
33
+
34
+ namespace Procedural
35
+ {
36
+ /**
37
+ * Represents a curve by interpolating between a list of key/values.
38
+ * It always refers to a "principal" curve (a path, atm), so the keys to either its point index or lineic position.
39
+ */
40
+ class _ProceduralExport Track
41
+ {
42
+ public:
43
+ /// Defines addressing mode for the track
44
+ /// ABSOLUTE_LINEIC : use the distance from the start of the principal curve
45
+ /// RELATIVE_LINEIC : use the relative distance from the start of the principal curve, considering the total length of main curve is 1.
46
+ /// POINT : right on the principal curve's key
47
+ enum AddressingMode
48
+ {
49
+ AM_ABSOLUTE_LINEIC, AM_RELATIVE_LINEIC, AM_POINT
50
+ };
51
+ protected:
52
+ /// Adressing mode of the track (see the enum definition for more details)
53
+ AddressingMode mAddressingMode;
54
+
55
+ /// Tells whether we should add new points to principal curve if a key is defined here but not on principal curve
56
+ bool mInsertPoint;
57
+
58
+ /// Key frames
59
+ std::map<Ogre::Real, Ogre::Real> mKeyFrames;
60
+ public:
61
+ /// Default constructor.
62
+ /// Point insertion default to true, and addressing to relative lineic
63
+ Track(AddressingMode addressingMode=AM_RELATIVE_LINEIC, bool insertPoint=true) : mAddressingMode(addressingMode), mInsertPoint(insertPoint) {}
64
+
65
+ /// Gets addressing mode of the curve
66
+ AddressingMode getAddressingMode() const
67
+ {
68
+ return mAddressingMode;
69
+ }
70
+
71
+ /// Inserts a new Key/Value couple anywhere on the track (it is auto-sorted anyway)
72
+ inline Track& addKeyFrame(Ogre::Real pos, Ogre::Real value)
73
+ {
74
+ mKeyFrames[pos] = value;
75
+ return *this;
76
+ }
77
+
78
+ /// @copydoc Track::mInsertPoint
79
+ inline bool isInsertPoint() const
80
+ {
81
+ return mInsertPoint;
82
+ }
83
+
84
+ /// Gets the value on the current point, taking into account the addressing mode
85
+ Ogre::Real getValue(Ogre::Real absPos, Ogre::Real relPos, unsigned int index) const;
86
+
87
+ /// Gets the value on the current point
88
+ Ogre::Real getValue(Ogre::Real pos) const;
89
+
90
+ /// Get the key value couple before current point, taking into account addressing mode.
91
+ /// If current point is below minimum key, issues minimum key
92
+ std::map<Ogre::Real, Ogre::Real>::const_iterator _getKeyValueBefore(Ogre::Real absPos, Ogre::Real relPos, unsigned int index) const;
93
+
94
+ /// Get the key value couple before current point.
95
+ /// If current point is below minimum key, issues minimum key/value
96
+ std::map<Ogre::Real, Ogre::Real>::const_iterator _getKeyValueBefore(Ogre::Real pos) const;
97
+
98
+ /// Get the key value couple after current point, taking into account addressing mode.
99
+ /// If current point is above maximum key, issues maximum key/value
100
+ std::map<Ogre::Real, Ogre::Real>::const_iterator _getKeyValueAfter(Ogre::Real absPos, Ogre::Real relPos, unsigned int index) const;
101
+
102
+ /// Get the key value couple after current point.
103
+ /// If current point is above maximum key, issues maximum key/value
104
+ std::map<Ogre::Real, Ogre::Real>::const_iterator _getKeyValueAfter(Ogre::Real pos) const;
105
+
106
+ /// Gets the first value in the track
107
+ Ogre::Real getFirstValue()
108
+ {
109
+ return mKeyFrames.begin()->second;
110
+ }
111
+
112
+ /// Gets the last value in the track
113
+ Ogre::Real getLastValue()
114
+ {
115
+ return (--mKeyFrames.end())->second;
116
+ }
117
+ };
118
+ //---------------------------------------------------
119
+
120
+
121
+ }
122
+ #endif
@@ -0,0 +1,328 @@
1
+ /*
2
+ -----------------------------------------------------------------------------
3
+ This source file is part of ogre-procedural
4
+
5
+ For the latest info, see http://code.google.com/p/ogre-procedural/
6
+
7
+ Copyright (c) 2010 Michael Broutin
8
+
9
+ Permission is hereby granted, free of charge, to any person obtaining a copy
10
+ of this software and associated documentation files (the "Software"), to deal
11
+ in the Software without restriction, including without limitation the rights
12
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13
+ copies of the Software, and to permit persons to whom the Software is
14
+ furnished to do so, subject to the following conditions:
15
+
16
+ The above copyright notice and this permission notice shall be included in
17
+ all copies or substantial portions of the Software.
18
+
19
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
25
+ THE SOFTWARE.
26
+ -----------------------------------------------------------------------------
27
+ */
28
+ #ifndef PROCEDURAL_TRIANGLEBUFFER_INCLUDED
29
+ #define PROCEDURAL_TRIANGLEBUFFER_INCLUDED
30
+
31
+ #include "OgreManualObject.h"
32
+ #include "OgreMesh.h"
33
+ #include "OgreSceneManager.h"
34
+ #include "ProceduralUtils.h"
35
+ #include "ProceduralRoot.h"
36
+ #include <fstream>
37
+
38
+ namespace Procedural
39
+ {
40
+ /** This is ogre-procedural's temporary mesh buffer.
41
+ * It stores all the info needed to build an Ogre Mesh, yet is intented to be more flexible, since
42
+ * there is no link towards hardware.
43
+ */
44
+ class TriangleBuffer
45
+ {
46
+ public:
47
+ struct Vertex
48
+ {
49
+ Ogre::Vector3 mPosition;
50
+ Ogre::Vector3 mNormal;
51
+ Ogre::Vector2 mUV;
52
+ };
53
+ protected:
54
+
55
+ std::vector<int> mIndices;
56
+
57
+ std::vector<Vertex> mVertices;
58
+ //std::vector<Vertex>::iterator mCurrentVertex;
59
+ int globalOffset;
60
+ int mEstimatedVertexCount;
61
+ int mEstimatedIndexCount;
62
+ Vertex* mCurrentVertex;
63
+
64
+
65
+ public:
66
+ TriangleBuffer() : globalOffset(0), mEstimatedVertexCount(0), mEstimatedIndexCount(0), mCurrentVertex(0)
67
+ {}
68
+
69
+ /// Gets a modifiable reference to vertices
70
+ std::vector<Vertex>& getVertices()
71
+ {
72
+ return mVertices;
73
+ }
74
+
75
+ /// Gets a non-modifiable reference to vertices
76
+ const std::vector<Vertex>& getVertices() const
77
+ {
78
+ return mVertices;
79
+ }
80
+
81
+ /// Gets a modifiable reference to vertices
82
+ std::vector<int>& getIndices()
83
+ {
84
+ return mIndices;
85
+ }
86
+
87
+ /// Gets a non-modifiable reference to indices
88
+ const std::vector<int>& getIndices() const
89
+ {
90
+ return mIndices;
91
+ }
92
+
93
+ /**
94
+ * Rebase index offset : call that function before you add a new mesh to the triangle buffer
95
+ */
96
+ void rebaseOffset()
97
+ {
98
+ globalOffset = mVertices.size();
99
+ }
100
+
101
+ /**
102
+ * Builds an Ogre Mesh from this buffer.
103
+ */
104
+ Ogre::MeshPtr transformToMesh(const std::string& name,
105
+ const Ogre::String& group = Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME)
106
+ {
107
+ Ogre::SceneManager* sceneMgr = Ogre::Root::getSingleton().getSceneManagerIterator().begin()->second;
108
+ Ogre::ManualObject * manual = sceneMgr->createManualObject();
109
+ manual->begin("BaseWhiteNoLighting", Ogre::RenderOperation::OT_TRIANGLE_LIST);
110
+
111
+ for (std::vector<Vertex>::iterator it = mVertices.begin(); it != mVertices.end();it++)
112
+ {
113
+ manual->position(it->mPosition);
114
+ manual->textureCoord(it->mUV);
115
+ manual->normal(it->mNormal);
116
+ }
117
+ for (std::vector<int>::iterator it = mIndices.begin(); it!=mIndices.end();it++)
118
+ {
119
+ manual->index(*it);
120
+ }
121
+ manual->end();
122
+ Ogre::MeshPtr mesh = manual->convertToMesh(name, group);
123
+
124
+ unsigned short src, dest;
125
+ if (!mesh->suggestTangentVectorBuildParams(Ogre::VES_TANGENT, src, dest))
126
+ {
127
+ mesh->buildTangentVectors(Ogre::VES_TANGENT, src, dest);
128
+ }
129
+
130
+ sceneMgr->destroyManualObject(manual);
131
+
132
+ return mesh;
133
+ }
134
+
135
+ /** Adds a new vertex to the buffer */
136
+ inline TriangleBuffer& position(const Ogre::Vector3& pos)
137
+ {
138
+ Vertex v;
139
+ v.mPosition = pos;
140
+ mVertices.push_back(v);
141
+ mCurrentVertex = &mVertices.back();
142
+ return *this;
143
+ }
144
+
145
+ /** Adds a new vertex to the buffer */
146
+ inline TriangleBuffer& position(Ogre::Real x, Ogre::Real y, Ogre::Real z)
147
+ {
148
+ Vertex v;
149
+ v.mPosition = Ogre::Vector3(x,y,z);
150
+ mVertices.push_back(v);
151
+ mCurrentVertex = &mVertices.back();
152
+ return *this;
153
+ }
154
+
155
+ /** Sets the normal of the current vertex */
156
+ inline TriangleBuffer& normal(const Ogre::Vector3& normal)
157
+ {
158
+ mCurrentVertex->mNormal = normal;
159
+ return *this;
160
+ }
161
+
162
+ /** Sets the texture coordinates of the current vertex */
163
+ inline TriangleBuffer& textureCoord(float u, float v)
164
+ {
165
+ mCurrentVertex->mUV = Ogre::Vector2(u,v);
166
+ return *this;
167
+ }
168
+
169
+ /** Sets the texture coordinates of the current vertex */
170
+ inline TriangleBuffer& textureCoord(const Ogre::Vector2& vec)
171
+ {
172
+ mCurrentVertex->mUV = vec;
173
+ return *this;
174
+ }
175
+
176
+ /**
177
+ * Adds an index to the index buffer.
178
+ * Index is relative to the latest rebaseOffset().
179
+ */
180
+ inline TriangleBuffer& index(int i)
181
+ {
182
+ mIndices.push_back(globalOffset+i);
183
+ return *this;
184
+ }
185
+
186
+ /**
187
+ * Adds a triangle to the index buffer.
188
+ * Index is relative to the latest rebaseOffset().
189
+ */
190
+ inline TriangleBuffer& triangle(int i1, int i2, int i3)
191
+ {
192
+ mIndices.push_back(globalOffset+i1);
193
+ mIndices.push_back(globalOffset+i2);
194
+ mIndices.push_back(globalOffset+i3);
195
+ return *this;
196
+ }
197
+
198
+ /// Applies a matrix to transform all vertices inside the triangle buffer
199
+ TriangleBuffer& applyTransform(const Ogre::Matrix4& matrix)
200
+ {
201
+ for (std::vector<Vertex>::iterator it = mVertices.begin(); it!=mVertices.end(); it++)
202
+ {
203
+ it->mPosition = matrix * it->mPosition;
204
+ it->mNormal = matrix * it->mNormal;
205
+ it->mNormal.normalise();
206
+ }
207
+ return *this;
208
+ }
209
+
210
+ /// Applies the translation immediately to all the points contained in that triangle buffer
211
+ /// @arg amount translation vector
212
+ TriangleBuffer& translate(const Ogre::Vector3& amount)
213
+ {
214
+ for (std::vector<Vertex>::iterator it = mVertices.begin(); it!=mVertices.end(); it++)
215
+ {
216
+ it->mPosition += amount;
217
+ }
218
+ return *this;
219
+ }
220
+
221
+ /// Applies the translation immediately to all the points contained in that triangle buffer
222
+ TriangleBuffer& translate(Ogre::Real x, Ogre::Real y, Ogre::Real z)
223
+ {
224
+ return translate(Ogre::Vector3(x, y, z));
225
+ }
226
+
227
+ /// Applies the rotation immediately to all the points contained in that triangle buffer
228
+ /// @arg quat the rotation quaternion to apply
229
+ TriangleBuffer& rotate(Ogre::Quaternion quat)
230
+ {
231
+ for (std::vector<Vertex>::iterator it = mVertices.begin(); it!=mVertices.end(); it++)
232
+ {
233
+ it->mPosition = quat * it->mPosition;
234
+ it->mNormal = quat * it->mNormal;
235
+ it->mNormal.normalise();
236
+ }
237
+ return *this;
238
+ }
239
+
240
+ /// Applies an immediate scale operation to that triangle buffer
241
+ /// @arg scale Scale vector
242
+ TriangleBuffer& scale(const Ogre::Vector3& scale)
243
+ {
244
+ for (std::vector<Vertex>::iterator it = mVertices.begin(); it!=mVertices.end(); it++)
245
+ {
246
+ it->mPosition = scale * it->mPosition;
247
+ }
248
+ return *this;
249
+ }
250
+
251
+ /// Applies an immediate scale operation to that triangle buffer
252
+ /// @arg x X scale component
253
+ /// @arg y Y scale component
254
+ /// @arg z Z scale component
255
+ TriangleBuffer& scale(Ogre::Real x, Ogre::Real y, Ogre::Real z)
256
+ {
257
+ return scale(Ogre::Vector3(x,y,z));
258
+ }
259
+
260
+ /// Applies normal inversion on the triangle buffer
261
+ TriangleBuffer& invertNormals()
262
+ {
263
+ for (std::vector<Vertex>::iterator it = mVertices.begin(); it!=mVertices.end();it++)
264
+ {
265
+ it->mNormal = -it->mNormal;
266
+ }
267
+ for (unsigned int i=0; i < mIndices.size(); ++i)
268
+ {
269
+ if (i%3==1)
270
+ {
271
+ std::swap(mIndices[i], mIndices[i-1]);
272
+ }
273
+ }
274
+ return *this;
275
+ }
276
+
277
+ /**
278
+ * Gives an estimation of the number of vertices need for this triangle buffer.
279
+ * If this function is called several times, it means an extra vertices count, not an absolute measure.
280
+ */
281
+ void estimateVertexCount(unsigned int vertexCount)
282
+ {
283
+ mEstimatedVertexCount += vertexCount;
284
+ mVertices.reserve(mEstimatedVertexCount);
285
+ }
286
+
287
+ /**
288
+ * Gives an estimation of the number of indices needed for this triangle buffer.
289
+ * If this function is called several times, it means an extra indices count, not an absolute measure.
290
+ */
291
+ void estimateIndexCount(unsigned int indexCount)
292
+ {
293
+ mEstimatedIndexCount += indexCount;
294
+ mIndices.reserve(mEstimatedIndexCount);
295
+ }
296
+
297
+ /**
298
+ * For debugging purposes, outputs the content of this buffer to a YAML styled file.
299
+ */
300
+ void _dumpContentsToFile(const std::string& fileName)
301
+ {
302
+ std::ofstream outFile;
303
+ outFile.open(fileName.c_str());
304
+
305
+ outFile<< "Number of vertices : "<< Ogre::StringConverter::toString(mVertices.size()) <<std::endl;
306
+ outFile<< "Estimated number of vertices : "<< Ogre::StringConverter::toString(mEstimatedVertexCount) <<std::endl;
307
+ outFile<< "Vertices :"<<std::endl;
308
+ for (std::vector<Vertex>::iterator it = mVertices.begin(); it!=mVertices.end();it++)
309
+ {
310
+ outFile<<" - {";
311
+ outFile<<" Position: ["<<Ogre::StringConverter::toString(it->mPosition.x)<<", "<<Ogre::StringConverter::toString(it->mPosition.y)<<", "<<Ogre::StringConverter::toString(it->mPosition.z)<<"]";
312
+ outFile<<", Normal: ["<<Ogre::StringConverter::toString(it->mNormal.x)<<", "<<Ogre::StringConverter::toString(it->mNormal.y)<<", "<<Ogre::StringConverter::toString(it->mNormal.z)<<"]";
313
+ outFile<<", UV: ["<<Ogre::StringConverter::toString(it->mUV.x)<<", "<<Ogre::StringConverter::toString(it->mUV.y)<<"]";
314
+ outFile<<"}"<<std::endl;
315
+ }
316
+ outFile<< "Number of indices : "<< Ogre::StringConverter::toString(mIndices.size()) <<std::endl;
317
+ outFile<< "Estimated number of indices : "<< Ogre::StringConverter::toString(mEstimatedIndexCount) <<std::endl;
318
+ outFile<< "Indices :"<< std::endl;
319
+ for (size_t i = 0; i<mIndices.size()/3; i++)
320
+ {
321
+ outFile<<" - ["<<Ogre::StringConverter::toString(mIndices[i*3])<<", "<<Ogre::StringConverter::toString(mIndices[i*3+1])<<", "<<Ogre::StringConverter::toString(mIndices[i*3+2])<<"]"<<std::endl;
322
+ }
323
+
324
+ outFile.close();
325
+ }
326
+ };
327
+ }
328
+ #endif