~ubuntu-branches/ubuntu/vivid/emscripten/vivid

« back to all changes in this revision

Viewing changes to tests/bullet/src/BulletMultiThreaded/GpuSoftBodySolvers/CPU/btSoftBodySolverData.h

  • Committer: Package Import Robot
  • Author(s): Sylvestre Ledru
  • Date: 2013-05-02 13:11:51 UTC
  • Revision ID: package-import@ubuntu.com-20130502131151-q8dvteqr1ef2x7xz
Tags: upstream-1.4.1~20130504~adb56cb
ImportĀ upstreamĀ versionĀ 1.4.1~20130504~adb56cb

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
Bullet Continuous Collision Detection and Physics Library
 
3
Copyright (c) 2003-2006 Erwin Coumans  http://continuousphysics.com/Bullet/
 
4
 
 
5
This software is provided 'as-is', without any express or implied warranty.
 
6
In no event will the authors be held liable for any damages arising from the use of this software.
 
7
Permission is granted to anyone to use this software for any purpose, 
 
8
including commercial applications, and to alter it and redistribute it freely, 
 
9
subject to the following restrictions:
 
10
 
 
11
1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required.
 
12
2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software.
 
13
3. This notice may not be removed or altered from any source distribution.
 
14
*/
 
15
 
 
16
#ifndef BT_SOFT_BODY_SOLVER_DATA_H
 
17
#define BT_SOFT_BODY_SOLVER_DATA_H
 
18
 
 
19
#include "BulletCollision/CollisionShapes/btTriangleIndexVertexArray.h"
 
20
#include "vectormath/vmInclude.h"
 
21
 
 
22
 
 
23
class btSoftBodyLinkData
 
24
{
 
25
public:
 
26
        /**
 
27
         * Class representing a link as a set of three indices into the vertex array.
 
28
         */
 
29
        class LinkNodePair
 
30
        {
 
31
        public:
 
32
                int vertex0;
 
33
                int vertex1;
 
34
 
 
35
                LinkNodePair()
 
36
                {
 
37
                        vertex0 = 0;
 
38
                        vertex1 = 0;
 
39
                }
 
40
 
 
41
                LinkNodePair( int v0, int v1 )
 
42
                {
 
43
                        vertex0 = v0;
 
44
                        vertex1 = v1;
 
45
                }
 
46
        };
 
47
 
 
48
        /**
 
49
         * Class describing a link for input into the system.
 
50
         */
 
51
        class LinkDescription
 
52
        {
 
53
        protected:
 
54
                int m_vertex0;
 
55
                int m_vertex1;
 
56
                float m_linkLinearStiffness;
 
57
                float m_linkStrength;
 
58
 
 
59
        public:
 
60
 
 
61
                LinkDescription()
 
62
                {
 
63
                        m_vertex0 = 0;
 
64
                        m_vertex1 = 0;
 
65
                        m_linkLinearStiffness = 1.0;
 
66
                        m_linkStrength = 1.0;
 
67
                }
 
68
 
 
69
                LinkDescription( int newVertex0, int newVertex1, float linkLinearStiffness )
 
70
                {
 
71
                        m_vertex0 = newVertex0;
 
72
                        m_vertex1 = newVertex1;
 
73
                        m_linkLinearStiffness = linkLinearStiffness;
 
74
                        m_linkStrength = 1.0;
 
75
                }
 
76
 
 
77
                LinkNodePair getVertexPair() const
 
78
                {
 
79
                        LinkNodePair nodes;
 
80
                        nodes.vertex0 = m_vertex0;
 
81
                        nodes.vertex1 = m_vertex1;
 
82
                        return nodes;
 
83
                }
 
84
 
 
85
                void setVertex0( int vertex )
 
86
                {
 
87
                        m_vertex0 = vertex;
 
88
                }
 
89
 
 
90
                void setVertex1( int vertex )
 
91
                {
 
92
                        m_vertex1 = vertex;
 
93
                }
 
94
 
 
95
                void setLinkLinearStiffness( float linearStiffness )
 
96
                {
 
97
                        m_linkLinearStiffness = linearStiffness;
 
98
                }
 
99
 
 
100
                void setLinkStrength( float strength )
 
101
                {
 
102
                        m_linkStrength = strength;
 
103
                }
 
104
 
 
105
                int getVertex0() const
 
106
                {
 
107
                        return m_vertex0;
 
108
                }
 
109
 
 
110
                int getVertex1() const
 
111
                {
 
112
                        return m_vertex1;
 
113
                }
 
114
 
 
115
                float getLinkStrength() const
 
116
                {
 
117
                        return m_linkStrength;
 
118
                }
 
119
 
 
120
                float getLinkLinearStiffness() const
 
121
                {
 
122
                        return m_linkLinearStiffness;
 
123
                }
 
124
        };
 
125
 
 
126
 
 
127
protected:
 
128
        // NOTE:
 
129
        // Vertex reference data is stored relative to global array, not relative to individual cloth.
 
130
        // Values must be correct if being passed into single-cloth VBOs or when migrating from one solver
 
131
        // to another.
 
132
 
 
133
        btAlignedObjectArray< LinkNodePair > m_links; // Vertex pair for the link
 
134
        btAlignedObjectArray< float >                                                           m_linkStrength; // Strength of each link
 
135
        // (inverseMassA + inverseMassB)/ linear stiffness coefficient
 
136
        btAlignedObjectArray< float >                                                           m_linksMassLSC; 
 
137
        btAlignedObjectArray< float >                                                           m_linksRestLengthSquared; 
 
138
        // Current vector length of link
 
139
        btAlignedObjectArray< Vectormath::Aos::Vector3 >                        m_linksCLength;
 
140
        // 1/(current length * current length * massLSC)
 
141
        btAlignedObjectArray< float >                                                           m_linksLengthRatio; 
 
142
        btAlignedObjectArray< float >                                                           m_linksRestLength;
 
143
        btAlignedObjectArray< float >                                                           m_linksMaterialLinearStiffnessCoefficient;
 
144
 
 
145
public:
 
146
        btSoftBodyLinkData()
 
147
        {
 
148
        }
 
149
 
 
150
        virtual ~btSoftBodyLinkData()
 
151
        {
 
152
        }
 
153
 
 
154
        virtual void clear()
 
155
        {
 
156
                m_links.resize(0);
 
157
                m_linkStrength.resize(0);
 
158
                m_linksMassLSC.resize(0);
 
159
                m_linksRestLengthSquared.resize(0);
 
160
                m_linksLengthRatio.resize(0);
 
161
                m_linksRestLength.resize(0);
 
162
                m_linksMaterialLinearStiffnessCoefficient.resize(0);
 
163
        }
 
164
 
 
165
        int getNumLinks()
 
166
        {
 
167
                return m_links.size();
 
168
        }
 
169
 
 
170
        /** Allocate enough space in all link-related arrays to fit numLinks links */
 
171
        virtual void createLinks( int numLinks )
 
172
        {
 
173
                int previousSize = m_links.size();
 
174
                int newSize = previousSize + numLinks;
 
175
 
 
176
                // Resize all the arrays that store link data
 
177
                m_links.resize( newSize );
 
178
                m_linkStrength.resize( newSize );
 
179
                m_linksMassLSC.resize( newSize );
 
180
                m_linksRestLengthSquared.resize( newSize );
 
181
                m_linksCLength.resize( newSize );
 
182
                m_linksLengthRatio.resize( newSize );
 
183
                m_linksRestLength.resize( newSize );
 
184
                m_linksMaterialLinearStiffnessCoefficient.resize( newSize );
 
185
        }
 
186
        
 
187
        /** Insert the link described into the correct data structures assuming space has already been allocated by a call to createLinks */
 
188
        virtual void setLinkAt( const LinkDescription &link, int linkIndex )
 
189
        {
 
190
                m_links[linkIndex] = link.getVertexPair();
 
191
                m_linkStrength[linkIndex] = link.getLinkStrength();
 
192
                m_linksMassLSC[linkIndex] = 0.f;
 
193
                m_linksRestLengthSquared[linkIndex] = 0.f;
 
194
                m_linksCLength[linkIndex] = Vectormath::Aos::Vector3(0.f, 0.f, 0.f);
 
195
                m_linksLengthRatio[linkIndex] = 0.f;
 
196
                m_linksRestLength[linkIndex] = 0.f;
 
197
                m_linksMaterialLinearStiffnessCoefficient[linkIndex] = link.getLinkLinearStiffness();
 
198
        }
 
199
 
 
200
 
 
201
        /**
 
202
         * Return true if data is on the accelerator.
 
203
         * The CPU version of this class will return true here because
 
204
         * the CPU is the same as the accelerator.
 
205
         */
 
206
        virtual bool onAccelerator()
 
207
        {
 
208
                return true;
 
209
        }
 
210
        
 
211
        /**
 
212
         * Move data from host memory to the accelerator.
 
213
         * The CPU version will always return that it has moved it.
 
214
         */
 
215
        virtual bool moveToAccelerator()
 
216
        {
 
217
                return true;
 
218
        }
 
219
 
 
220
        /**
 
221
         * Move data from host memory from the accelerator.
 
222
         * The CPU version will always return that it has moved it.
 
223
         */
 
224
        virtual bool moveFromAccelerator()
 
225
        {
 
226
                return true;
 
227
        }
 
228
 
 
229
 
 
230
 
 
231
        /**
 
232
         * Return reference to the vertex index pair for link linkIndex as stored on the host.
 
233
         */
 
234
        LinkNodePair &getVertexPair( int linkIndex )
 
235
        {
 
236
                return m_links[linkIndex];
 
237
        }
 
238
 
 
239
        /** 
 
240
         * Return reference to strength of link linkIndex as stored on the host.
 
241
         */
 
242
        float &getStrength( int linkIndex )
 
243
        {
 
244
                return m_linkStrength[linkIndex];
 
245
        }
 
246
 
 
247
        /**
 
248
         * Return a reference to the strength of the link corrected for link sorting.
 
249
         * This is important if we are using data on an accelerator which has the data sorted in some fashion.
 
250
         */
 
251
        virtual float &getStrengthCorrected( int linkIndex )
 
252
        {
 
253
                return getStrength( linkIndex );
 
254
        }
 
255
 
 
256
        /**
 
257
         * Return reference to the rest length of link linkIndex as stored on the host.
 
258
         */
 
259
        float &getRestLength( int linkIndex )
 
260
        {
 
261
                return m_linksRestLength[linkIndex];
 
262
        }
 
263
 
 
264
        /**
 
265
         * Return reference to linear stiffness coefficient for link linkIndex as stored on the host.
 
266
         */
 
267
        float &getLinearStiffnessCoefficient( int linkIndex )
 
268
        {
 
269
                return m_linksMaterialLinearStiffnessCoefficient[linkIndex];
 
270
        }
 
271
 
 
272
        /**
 
273
         * Return reference to the MassLSC value for link linkIndex as stored on the host.
 
274
         */
 
275
        float &getMassLSC( int linkIndex )
 
276
        {
 
277
                return m_linksMassLSC[linkIndex];
 
278
        }
 
279
 
 
280
        /**
 
281
         * Return reference to rest length squared for link linkIndex as stored on the host.
 
282
         */
 
283
        float &getRestLengthSquared( int linkIndex )
 
284
        {
 
285
                return m_linksRestLengthSquared[linkIndex];
 
286
        }
 
287
 
 
288
        /**
 
289
         * Return reference to current length of link linkIndex as stored on the host.
 
290
         */
 
291
        Vectormath::Aos::Vector3 &getCurrentLength( int linkIndex )
 
292
        {
 
293
                return m_linksCLength[linkIndex];
 
294
        }
 
295
 
 
296
         /**
 
297
          * Return the link length ratio from for link linkIndex as stored on the host.
 
298
          */
 
299
         float &getLinkLengthRatio( int linkIndex )
 
300
         {
 
301
                 return m_linksLengthRatio[linkIndex];
 
302
         }
 
303
};
 
304
 
 
305
 
 
306
 
 
307
/**
 
308
 * Wrapper for vertex data information.
 
309
 * By wrapping it like this we stand a good chance of being able to optimise for storage format easily.
 
310
 * It should also help us make sure all the data structures remain consistent.
 
311
 */
 
312
class btSoftBodyVertexData
 
313
{
 
314
public:
 
315
        /**
 
316
         * Class describing a vertex for input into the system.
 
317
         */
 
318
        class VertexDescription
 
319
        {
 
320
        private:
 
321
                Vectormath::Aos::Point3 m_position;
 
322
                /** Inverse mass. If this is 0f then the mass was 0 because that simplifies calculations. */
 
323
                float m_inverseMass;
 
324
 
 
325
        public:
 
326
                VertexDescription()
 
327
                {       
 
328
                        m_position = Vectormath::Aos::Point3( 0.f, 0.f, 0.f );
 
329
                        m_inverseMass = 0.f;
 
330
                }
 
331
 
 
332
                VertexDescription( const Vectormath::Aos::Point3 &position, float mass )
 
333
                {
 
334
                        m_position = position;
 
335
                        if( mass > 0.f )
 
336
                                m_inverseMass = 1.0f/mass;
 
337
                        else
 
338
                                m_inverseMass = 0.f;
 
339
                }
 
340
 
 
341
                void setPosition( const Vectormath::Aos::Point3 &position )
 
342
                {
 
343
                        m_position = position;
 
344
                }
 
345
 
 
346
                void setInverseMass( float inverseMass )
 
347
                {
 
348
                        m_inverseMass = inverseMass;
 
349
                }
 
350
 
 
351
                void setMass( float mass )
 
352
                {
 
353
                        if( mass > 0.f )
 
354
                                m_inverseMass = 1.0f/mass;
 
355
                        else
 
356
                                m_inverseMass = 0.f;
 
357
                }
 
358
 
 
359
                Vectormath::Aos::Point3 getPosition() const
 
360
                {
 
361
                        return m_position;
 
362
                }
 
363
 
 
364
                float getInverseMass() const
 
365
                {
 
366
                        return m_inverseMass;
 
367
                }
 
368
 
 
369
                float getMass() const
 
370
                {
 
371
                        if( m_inverseMass == 0.f )
 
372
                                return 0.f;
 
373
                        else
 
374
                                return 1.0f/m_inverseMass;
 
375
                }
 
376
        };
 
377
protected:
 
378
 
 
379
        // identifier for the individual cloth
 
380
        // For the CPU we don't really need this as we can grab the cloths and iterate over only their vertices
 
381
        // For a parallel accelerator knowing on a per-vertex basis which cloth we're part of will help for obtaining
 
382
        // per-cloth data
 
383
        // For sorting etc it might also be helpful to be able to use in-array data such as this.
 
384
        btAlignedObjectArray< int >                                                     m_clothIdentifier;
 
385
        btAlignedObjectArray< Vectormath::Aos::Point3 >         m_vertexPosition;                       // vertex positions
 
386
        btAlignedObjectArray< Vectormath::Aos::Point3 >         m_vertexPreviousPosition;       // vertex positions
 
387
        btAlignedObjectArray< Vectormath::Aos::Vector3 >        m_vertexVelocity;                       // Velocity
 
388
        btAlignedObjectArray< Vectormath::Aos::Vector3 >        m_vertexForceAccumulator;       // Force accumulator
 
389
        btAlignedObjectArray< Vectormath::Aos::Vector3 >        m_vertexNormal;                         // Normals
 
390
        btAlignedObjectArray< float >                                           m_vertexInverseMass;            // Inverse mass
 
391
        btAlignedObjectArray< float >                                           m_vertexArea;                           // Area controlled by the vertex
 
392
        btAlignedObjectArray< int >                                                     m_vertexTriangleCount;          // Number of triangles touching this vertex
 
393
 
 
394
public:
 
395
        btSoftBodyVertexData()
 
396
        {
 
397
        }
 
398
 
 
399
        virtual ~btSoftBodyVertexData()
 
400
        {
 
401
        }
 
402
 
 
403
        virtual void clear()
 
404
        {
 
405
                m_clothIdentifier.resize(0);
 
406
                m_vertexPosition.resize(0);
 
407
                m_vertexPreviousPosition.resize(0);
 
408
                m_vertexVelocity.resize(0);
 
409
                m_vertexForceAccumulator.resize(0);
 
410
                m_vertexNormal.resize(0);
 
411
                m_vertexInverseMass.resize(0);
 
412
                m_vertexArea.resize(0);
 
413
                m_vertexTriangleCount.resize(0);
 
414
        }
 
415
 
 
416
        int getNumVertices()
 
417
        {
 
418
                return m_vertexPosition.size();
 
419
        }
 
420
 
 
421
        int getClothIdentifier( int vertexIndex )
 
422
        {
 
423
                return m_clothIdentifier[vertexIndex];
 
424
        }
 
425
 
 
426
        void setVertexAt( const VertexDescription &vertex, int vertexIndex )
 
427
        {
 
428
                m_vertexPosition[vertexIndex] = vertex.getPosition();
 
429
                m_vertexPreviousPosition[vertexIndex] = vertex.getPosition();
 
430
                m_vertexVelocity[vertexIndex] = Vectormath::Aos::Vector3(0.f, 0.f, 0.f);
 
431
                m_vertexForceAccumulator[vertexIndex] = Vectormath::Aos::Vector3(0.f, 0.f, 0.f);
 
432
                m_vertexNormal[vertexIndex] = Vectormath::Aos::Vector3(0.f, 0.f, 0.f);
 
433
                m_vertexInverseMass[vertexIndex] = vertex.getInverseMass();
 
434
                m_vertexArea[vertexIndex] = 0.f;
 
435
                m_vertexTriangleCount[vertexIndex] = 0;
 
436
        }
 
437
 
 
438
        /** 
 
439
         * Create numVertices new vertices for cloth clothIdentifier 
 
440
         * maxVertices allows a buffer zone of extra vertices for alignment or tearing reasons.
 
441
         */
 
442
        void createVertices( int numVertices, int clothIdentifier, int maxVertices = 0 )
 
443
        {
 
444
                int previousSize = m_vertexPosition.size();
 
445
                if( maxVertices == 0 )
 
446
                        maxVertices = numVertices;
 
447
                int newSize = previousSize + maxVertices;
 
448
 
 
449
                // Resize all the arrays that store vertex data
 
450
                m_clothIdentifier.resize( newSize );
 
451
                m_vertexPosition.resize( newSize );
 
452
                m_vertexPreviousPosition.resize( newSize );
 
453
                m_vertexVelocity.resize( newSize );
 
454
                m_vertexForceAccumulator.resize( newSize );
 
455
                m_vertexNormal.resize( newSize );
 
456
                m_vertexInverseMass.resize( newSize );
 
457
                m_vertexArea.resize( newSize );
 
458
                m_vertexTriangleCount.resize( newSize );
 
459
 
 
460
                for( int vertexIndex = previousSize; vertexIndex < newSize; ++vertexIndex )
 
461
                        m_clothIdentifier[vertexIndex] = clothIdentifier;
 
462
                for( int vertexIndex = (previousSize + numVertices); vertexIndex < newSize; ++vertexIndex )
 
463
                        m_clothIdentifier[vertexIndex] = -1;
 
464
        }
 
465
 
 
466
        // Get and set methods in header so they can be inlined
 
467
 
 
468
        /**
 
469
         * Return a reference to the position of vertex vertexIndex as stored on the host.
 
470
         */
 
471
        Vectormath::Aos::Point3 &getPosition( int vertexIndex )
 
472
        {
 
473
                return m_vertexPosition[vertexIndex];
 
474
        }
 
475
 
 
476
        Vectormath::Aos::Point3 getPosition( int vertexIndex ) const
 
477
        {
 
478
                return m_vertexPosition[vertexIndex];
 
479
        }
 
480
 
 
481
        /**
 
482
         * Return a reference to the previous position of vertex vertexIndex as stored on the host.
 
483
         */
 
484
        Vectormath::Aos::Point3 &getPreviousPosition( int vertexIndex )
 
485
        {
 
486
                return m_vertexPreviousPosition[vertexIndex];
 
487
        }
 
488
 
 
489
        /**
 
490
         * Return a reference to the velocity of vertex vertexIndex as stored on the host.
 
491
         */
 
492
        Vectormath::Aos::Vector3 &getVelocity( int vertexIndex )
 
493
        {
 
494
                return m_vertexVelocity[vertexIndex];
 
495
        }
 
496
 
 
497
        /**
 
498
         * Return a reference to the force accumulator of vertex vertexIndex as stored on the host.
 
499
         */
 
500
        Vectormath::Aos::Vector3 &getForceAccumulator( int vertexIndex )
 
501
        {
 
502
                return m_vertexForceAccumulator[vertexIndex];
 
503
        }
 
504
 
 
505
        /**
 
506
         * Return a reference to the normal of vertex vertexIndex as stored on the host.
 
507
         */
 
508
        Vectormath::Aos::Vector3 &getNormal( int vertexIndex )
 
509
        {
 
510
                return m_vertexNormal[vertexIndex];
 
511
        }
 
512
 
 
513
        Vectormath::Aos::Vector3 getNormal( int vertexIndex ) const
 
514
        {
 
515
                return m_vertexNormal[vertexIndex];
 
516
        }
 
517
 
 
518
        /**
 
519
         * Return a reference to the inverse mass of vertex vertexIndex as stored on the host.
 
520
         */
 
521
        float &getInverseMass( int vertexIndex )
 
522
        {
 
523
                return m_vertexInverseMass[vertexIndex];
 
524
        }
 
525
 
 
526
        /**
 
527
         * Get access to the area controlled by this vertex.
 
528
         */
 
529
        float &getArea( int vertexIndex )
 
530
        {
 
531
                return m_vertexArea[vertexIndex];
 
532
        }
 
533
 
 
534
        /**
 
535
         * Get access to the array of how many triangles touch each vertex.
 
536
         */
 
537
        int &getTriangleCount( int vertexIndex )
 
538
        {
 
539
                return m_vertexTriangleCount[vertexIndex];
 
540
        }
 
541
 
 
542
 
 
543
 
 
544
        /**
 
545
         * Return true if data is on the accelerator.
 
546
         * The CPU version of this class will return true here because
 
547
         * the CPU is the same as the accelerator.
 
548
         */
 
549
        virtual bool onAccelerator()
 
550
        {
 
551
                return true;
 
552
        }
 
553
        
 
554
        /**
 
555
         * Move data from host memory to the accelerator.
 
556
         * The CPU version will always return that it has moved it.
 
557
         */
 
558
        virtual bool moveToAccelerator()
 
559
        {
 
560
                return true;
 
561
        }
 
562
 
 
563
        /**
 
564
         * Move data from host memory from the accelerator.
 
565
         * The CPU version will always return that it has moved it.
 
566
         */
 
567
        virtual bool moveFromAccelerator()
 
568
        {
 
569
                return true;
 
570
        }
 
571
 
 
572
        btAlignedObjectArray< Vectormath::Aos::Point3 > &getVertexPositions()
 
573
        {
 
574
                return m_vertexPosition;
 
575
        }
 
576
};
 
577
 
 
578
 
 
579
class btSoftBodyTriangleData
 
580
{
 
581
public:
 
582
        /**
 
583
         * Class representing a triangle as a set of three indices into the
 
584
         * vertex array.
 
585
         */
 
586
        class TriangleNodeSet
 
587
        {
 
588
        public:
 
589
                int vertex0;
 
590
                int vertex1;
 
591
                int vertex2;
 
592
                int _padding;
 
593
 
 
594
                TriangleNodeSet( )
 
595
                {
 
596
                        vertex0 = 0;
 
597
                        vertex1 = 0;
 
598
                        vertex2 = 0;
 
599
                        _padding = -1;
 
600
                }
 
601
 
 
602
                TriangleNodeSet( int newVertex0, int newVertex1, int newVertex2 )
 
603
                {
 
604
                        vertex0 = newVertex0;
 
605
                        vertex1 = newVertex1;
 
606
                        vertex2 = newVertex2;
 
607
                }
 
608
        };
 
609
 
 
610
        class TriangleDescription
 
611
        {
 
612
        protected:
 
613
                int m_vertex0;
 
614
                int m_vertex1;
 
615
                int m_vertex2;
 
616
 
 
617
        public:
 
618
                TriangleDescription()
 
619
                {
 
620
                        m_vertex0 = 0;
 
621
                        m_vertex1 = 0;
 
622
                        m_vertex2 = 0;
 
623
                }
 
624
 
 
625
                TriangleDescription( int newVertex0, int newVertex1, int newVertex2 )
 
626
                {
 
627
                        m_vertex0 = newVertex0;
 
628
                        m_vertex1 = newVertex1;
 
629
                        m_vertex2 = newVertex2;
 
630
                }
 
631
 
 
632
                TriangleNodeSet getVertexSet() const
 
633
                {
 
634
                        btSoftBodyTriangleData::TriangleNodeSet nodes;
 
635
                        nodes.vertex0 = m_vertex0;
 
636
                        nodes.vertex1 = m_vertex1;
 
637
                        nodes.vertex2 = m_vertex2;
 
638
                        return nodes;
 
639
                }
 
640
        };
 
641
 
 
642
protected:
 
643
        // NOTE:
 
644
        // Vertex reference data is stored relative to global array, not relative to individual cloth.
 
645
        // Values must be correct if being passed into single-cloth VBOs or when migrating from one solver
 
646
        // to another.
 
647
        btAlignedObjectArray< TriangleNodeSet > m_vertexIndices;
 
648
        btAlignedObjectArray< float > m_area;
 
649
        btAlignedObjectArray< Vectormath::Aos::Vector3 > m_normal;
 
650
 
 
651
public:
 
652
        btSoftBodyTriangleData()
 
653
        {
 
654
        }
 
655
 
 
656
        virtual ~btSoftBodyTriangleData()
 
657
        {
 
658
 
 
659
        }
 
660
 
 
661
        virtual void clear()
 
662
        {
 
663
                m_vertexIndices.resize(0);
 
664
                m_area.resize(0);
 
665
                m_normal.resize(0);
 
666
        }
 
667
 
 
668
        int getNumTriangles()
 
669
        {
 
670
                return m_vertexIndices.size();
 
671
        }
 
672
 
 
673
        virtual void setTriangleAt( const TriangleDescription &triangle, int triangleIndex )
 
674
        {
 
675
                m_vertexIndices[triangleIndex] = triangle.getVertexSet();
 
676
        }
 
677
 
 
678
        virtual void createTriangles( int numTriangles )                
 
679
        {
 
680
                int previousSize = m_vertexIndices.size();
 
681
                int newSize = previousSize + numTriangles;
 
682
 
 
683
                // Resize all the arrays that store triangle data
 
684
                m_vertexIndices.resize( newSize );
 
685
                m_area.resize( newSize );
 
686
                m_normal.resize( newSize );
 
687
        }
 
688
 
 
689
        /**
 
690
         * Return the vertex index set for triangle triangleIndex as stored on the host.
 
691
         */
 
692
        const TriangleNodeSet &getVertexSet( int triangleIndex )
 
693
        {
 
694
                return m_vertexIndices[triangleIndex];
 
695
        }
 
696
 
 
697
        /**
 
698
         * Get access to the triangle area.
 
699
         */
 
700
        float &getTriangleArea( int triangleIndex )
 
701
        {
 
702
                return m_area[triangleIndex];
 
703
        }
 
704
 
 
705
        /**
 
706
         * Get access to the normal vector for this triangle.
 
707
         */
 
708
        Vectormath::Aos::Vector3 &getNormal( int triangleIndex )
 
709
        {
 
710
                return m_normal[triangleIndex];
 
711
        }
 
712
 
 
713
        /**
 
714
         * Return true if data is on the accelerator.
 
715
         * The CPU version of this class will return true here because
 
716
         * the CPU is the same as the accelerator.
 
717
         */
 
718
        virtual bool onAccelerator()
 
719
        {
 
720
                return true;
 
721
        }
 
722
        
 
723
        /**
 
724
         * Move data from host memory to the accelerator.
 
725
         * The CPU version will always return that it has moved it.
 
726
         */
 
727
        virtual bool moveToAccelerator()
 
728
        {
 
729
                return true;
 
730
        }
 
731
 
 
732
        /**
 
733
         * Move data from host memory from the accelerator.
 
734
         * The CPU version will always return that it has moved it.
 
735
         */
 
736
        virtual bool moveFromAccelerator()
 
737
        {
 
738
                return true;
 
739
        }
 
740
};
 
741
 
 
742
 
 
743
#endif // #ifndef BT_SOFT_BODY_SOLVER_DATA_H
 
744