RavEngine
Loading...
Searching...
No Matches
SnXmlVisitorWriter.h
1// Redistribution and use in source and binary forms, with or without
2// modification, are permitted provided that the following conditions
3// are met:
4// * Redistributions of source code must retain the above copyright
5// notice, this list of conditions and the following disclaimer.
6// * Redistributions in binary form must reproduce the above copyright
7// notice, this list of conditions and the following disclaimer in the
8// documentation and/or other materials provided with the distribution.
9// * Neither the name of NVIDIA CORPORATION nor the names of its
10// contributors may be used to endorse or promote products derived
11// from this software without specific prior written permission.
12//
13// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ''AS IS'' AND ANY
14// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16// PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
17// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
18// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
19// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
20// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
21// OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
23// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24//
25// Copyright (c) 2008-2022 NVIDIA Corporation. All rights reserved.
26// Copyright (c) 2004-2008 AGEIA Technologies, Inc. All rights reserved.
27// Copyright (c) 2001-2004 NovodeX AG. All rights reserved.
28
29#ifndef SN_XML_VISITOR_WRITER_H
30#define SN_XML_VISITOR_WRITER_H
31
32#include "foundation/PxInlineArray.h"
33#include "RepXMetaDataPropertyVisitor.h"
34#include "SnPxStreamOperators.h"
35#include "SnXmlMemoryPoolStreams.h"
36#include "SnXmlWriter.h"
37#include "SnXmlImpl.h"
38#include "foundation/PxStrideIterator.h"
39
40namespace physx { namespace Sn {
41
42 template<typename TDataType>
43 inline void writeReference( XmlWriter& writer, PxCollection& inCollection, const char* inPropName, const TDataType* inDatatype )
44 {
45 const PxBase* s = static_cast<const PxBase*>( inDatatype ) ;
46 if( inDatatype && !inCollection.contains( *const_cast<PxBase*>(s) ))
47 {
48 PxGetFoundation().error(PxErrorCode::eINTERNAL_ERROR, __FILE__, __LINE__,
49 "PxSerialization::serializeCollectionToXml: Reference \"%s\" could not be resolved.", inPropName);
50 }
51
52 PxSerialObjectId theId = 0;
53 if( s )
54 {
55 theId = inCollection.getId( *s );
56 if( theId == 0 )
57 theId = static_cast<uint64_t>(size_t(inDatatype));
58 }
59
60 writer.write( inPropName, PxCreateRepXObject( inDatatype, theId ) );
61 }
62
63 inline void writeProperty( XmlWriter& inWriter, MemoryBuffer& inBuffer, const char* inProp )
64 {
65 PxU8 data = 0;
66 inBuffer.write( &data, sizeof(PxU8) );
67 inWriter.write( inProp, reinterpret_cast<const char*>( inBuffer.mBuffer ) );
68 inBuffer.clear();
69 }
70
71 template<typename TDataType>
72 inline void writeProperty( XmlWriter& inWriter, PxCollection&, MemoryBuffer& inBuffer, const char* inPropName, TDataType inValue )
73 {
74 inBuffer << inValue;
75 writeProperty( inWriter, inBuffer, inPropName );
76 }
77
78 inline void writeProperty( XmlWriter& writer, PxCollection& inCollection, MemoryBuffer& /*inBuffer*/, const char* inPropName, const PxConvexMesh* inDatatype )
79 {
80 writeReference( writer, inCollection, inPropName, inDatatype );
81 }
82
83 inline void writeProperty( XmlWriter& writer, PxCollection& inCollection, MemoryBuffer& /*inBuffer*/, const char* inPropName, PxConvexMesh* inDatatype )
84 {
85 writeReference( writer, inCollection, inPropName, inDatatype );
86 }
87
88 inline void writeProperty( XmlWriter& writer, PxCollection& inCollection, MemoryBuffer& /*inBuffer*/, const char* inPropName, const PxTriangleMesh* inDatatype )
89 {
90 if (inDatatype->getConcreteType() == PxConcreteType::eTRIANGLE_MESH_BVH33)
91 {
92 const PxBVH33TriangleMesh* dataType = inDatatype->is<PxBVH33TriangleMesh>();
93 writeReference(writer, inCollection, inPropName, dataType);
94 }
95 else if (inDatatype->getConcreteType() == PxConcreteType::eTRIANGLE_MESH_BVH34)
96 {
97 const PxBVH34TriangleMesh* dataType = inDatatype->is<PxBVH34TriangleMesh>();
98 writeReference(writer, inCollection, inPropName, dataType);
99 }
100 else
101 {
102 PX_ASSERT(0);
103 }
104 }
105
106 inline void writeProperty( XmlWriter& writer, PxCollection& inCollection, MemoryBuffer& /*inBuffer*/, const char* inPropName, PxTriangleMesh* inDatatype )
107 {
108 if (inDatatype->getConcreteType() == PxConcreteType::eTRIANGLE_MESH_BVH33)
109 {
110 PxBVH33TriangleMesh* dataType = inDatatype->is<PxBVH33TriangleMesh>();
111 writeReference(writer, inCollection, inPropName, dataType);
112 }
113 else if (inDatatype->getConcreteType() == PxConcreteType::eTRIANGLE_MESH_BVH34)
114 {
115 PxBVH34TriangleMesh* dataType = inDatatype->is<PxBVH34TriangleMesh>();
116 writeReference(writer, inCollection, inPropName, dataType);
117 }
118 else
119 {
120 PX_ASSERT(0);
121 }
122 }
123
124 inline void writeProperty( XmlWriter& writer, PxCollection& inCollection, MemoryBuffer& /*inBuffer*/, const char* inPropName, const PxBVH33TriangleMesh* inDatatype )
125 {
126 writeReference( writer, inCollection, inPropName, inDatatype );
127 }
128
129 inline void writeProperty( XmlWriter& writer, PxCollection& inCollection, MemoryBuffer& /*inBuffer*/, const char* inPropName, PxBVH33TriangleMesh* inDatatype )
130 {
131 writeReference( writer, inCollection, inPropName, inDatatype );
132 }
133
134 inline void writeProperty( XmlWriter& writer, PxCollection& inCollection, MemoryBuffer& /*inBuffer*/, const char* inPropName, const PxBVH34TriangleMesh* inDatatype )
135 {
136 writeReference( writer, inCollection, inPropName, inDatatype );
137 }
138
139 inline void writeProperty( XmlWriter& writer, PxCollection& inCollection, MemoryBuffer& /*inBuffer*/, const char* inPropName, PxBVH34TriangleMesh* inDatatype )
140 {
141 writeReference( writer, inCollection, inPropName, inDatatype );
142 }
143
144 inline void writeProperty( XmlWriter& writer, PxCollection& inCollection, MemoryBuffer& /*inBuffer*/, const char* inPropName, const PxHeightField* inDatatype )
145 {
146 writeReference( writer, inCollection, inPropName, inDatatype );
147 }
148
149 inline void writeProperty( XmlWriter& writer, PxCollection& inCollection, MemoryBuffer& /*inBuffer*/, const char* inPropName, PxHeightField* inDatatype )
150 {
151 writeReference( writer, inCollection, inPropName, inDatatype );
152 }
153
154 inline void writeProperty( XmlWriter& writer, PxCollection& inCollection, MemoryBuffer& /*inBuffer*/, const char* inPropName, const PxRigidActor* inDatatype )
155 {
156 writeReference( writer, inCollection, inPropName, inDatatype );
157 }
158
159 inline void writeProperty(XmlWriter& writer, PxCollection& inCollection, MemoryBuffer& /*inBuffer*/, const char* inPropName, PxArticulationReducedCoordinate* inDatatype)
160 {
161 writeReference(writer, inCollection, inPropName, inDatatype);
162 }
163
164 inline void writeProperty( XmlWriter& writer, PxCollection& inCollection, MemoryBuffer& /*inBuffer*/, const char* inPropName, PxRigidActor* inDatatype )
165 {
166 writeReference( writer, inCollection, inPropName, inDatatype );
167 }
168
169 inline void writeFlagsProperty( XmlWriter& inWriter, MemoryBuffer& tempBuf, const char* inPropName, PxU32 inFlags, const PxU32ToName* inTable )
170 {
171 if ( inTable )
172 {
173 PxU32 flagValue( inFlags );
174 if ( flagValue )
175 {
176 for ( PxU32 idx =0; inTable[idx].mName != NULL; ++idx )
177 {
178 if ( (inTable[idx].mValue & flagValue) == inTable[idx].mValue )
179 {
180 if ( tempBuf.mWriteOffset != 0 )
181 tempBuf << "|";
182 tempBuf << inTable[idx].mName;
183 }
184 }
185 writeProperty( inWriter, tempBuf, inPropName );
186 }
187 else
188 {
189 if ( tempBuf.mWriteOffset != 0 )
190 tempBuf << "|";
191 tempBuf << "0";
192 writeProperty( inWriter, tempBuf, inPropName );
193 }
194 }
195 }
196
197 inline void writeFlagsBuffer( MemoryBuffer& tempBuf, PxU32 flagValue, const PxU32ToName* inTable )
198 {
199 PX_ASSERT(inTable);
200 bool added = false;
201
202 if ( flagValue )
203 {
204 for ( PxU32 item =0; inTable[item].mName != NULL; ++item )
205 {
206 if ( (inTable[item].mValue & flagValue) != 0 )
207 {
208 if ( added )
209 tempBuf << "|";
210 tempBuf << inTable[item].mName;
211 added = true;
212 }
213 }
214 }
215 }
216
217 inline void writePxVec3( PxOutputStream& inStream, const PxVec3& inVec ) { inStream << inVec; }
218
219
220 template<typename TDataType>
221 inline const TDataType& PtrAccess( const TDataType* inPtr, PxU32 inIndex )
222 {
223 return inPtr[inIndex];
224 }
225
226 template<typename TDataType>
227 inline void BasicDatatypeWrite( PxOutputStream& inStream, const TDataType& item ) { inStream << item; }
228
229 template<typename TObjType, typename TAccessOperator, typename TWriteOperator>
230 inline void writeBuffer( XmlWriter& inWriter, MemoryBuffer& inTempBuffer
231 , PxU32 inObjPerLine, const TObjType* inObjType, TAccessOperator inAccessOperator
232 , PxU32 inBufSize, const char* inPropName, TWriteOperator inOperator )
233 {
234 if ( inBufSize && inObjType )
235 {
236 for ( PxU32 idx = 0; idx < inBufSize; ++idx )
237 {
238 if ( idx && ( idx % inObjPerLine == 0 ) )
239 inTempBuffer << "\n\t\t\t";
240 else
241 inTempBuffer << " ";
242 inOperator( inTempBuffer, inAccessOperator( inObjType, idx ) );
243 }
244 writeProperty( inWriter, inTempBuffer, inPropName );
245 }
246 }
247
248 template<typename TDataType, typename TAccessOperator, typename TWriteOperator>
249 inline void writeStrideBuffer( XmlWriter& inWriter, MemoryBuffer& inTempBuffer
250 , PxU32 inObjPerLine, PxStrideIterator<const TDataType>& inData, TAccessOperator inAccessOperator
251 , PxU32 inBufSize, const char* inPropName, PxU32 /*inStride*/, TWriteOperator inOperator )
252 {
253#if PX_SWITCH
254 const auto *dat = &inData[0];
255 if (inBufSize && dat != NULL)
256#else
257 if ( inBufSize && &inData[0])
258#endif
259 {
260 for ( PxU32 idx = 0; idx < inBufSize; ++idx )
261 {
262 if ( idx && ( idx % inObjPerLine == 0 ) )
263 inTempBuffer << "\n\t\t\t";
264 else
265 inTempBuffer << " ";
266
267 inOperator( inTempBuffer, inAccessOperator( &inData[idx], 0 ) );
268 }
269 writeProperty( inWriter, inTempBuffer, inPropName );
270 }
271 }
272
273
274 template<typename TDataType, typename TAccessOperator>
275 inline void writeStrideFlags( XmlWriter& inWriter, MemoryBuffer& inTempBuffer
276 , PxU32 inObjPerLine, PxStrideIterator<const TDataType>& inData, TAccessOperator /*inAccessOperator*/
277 , PxU32 inBufSize, const char* inPropName, const PxU32ToName* inTable)
278 {
279#if PX_SWITCH
280 const auto *dat = &inData[0];
281 if (inBufSize && dat != NULL)
282#else
283 if ( inBufSize && &inData[0])
284#endif
285 {
286 for ( PxU32 idx = 0; idx < inBufSize; ++idx )
287 {
288 writeFlagsBuffer(inTempBuffer, inData[idx], inTable);
289
290 if ( idx && ( idx % inObjPerLine == 0 ) )
291 inTempBuffer << "\n\t\t\t";
292 else
293 inTempBuffer << " ";
294 }
295 writeProperty( inWriter, inTempBuffer, inPropName );
296 }
297 }
298
299 template<typename TDataType, typename TWriteOperator>
300 inline void writeBuffer( XmlWriter& inWriter, MemoryBuffer& inTempBuffer
301 , PxU32 inObjPerLine, const TDataType* inBuffer
302 , PxU32 inBufSize, const char* inPropName, TWriteOperator inOperator )
303 {
304 writeBuffer( inWriter, inTempBuffer, inObjPerLine, inBuffer, PtrAccess<TDataType>, inBufSize, inPropName, inOperator );
305 }
306
307 template<typename TEnumType>
308 inline void writeEnumProperty( XmlWriter& inWriter, const char* inPropName, TEnumType inEnumValue, const PxU32ToName* inConversions )
309 {
310 PxU32 theValue = static_cast<PxU32>( inEnumValue );
311 for ( const PxU32ToName* conv = inConversions; conv->mName != NULL; ++conv )
312 if ( conv->mValue == theValue ) inWriter.write( inPropName, conv->mName );
313 }
314
315
316
317 template<typename TObjType, typename TWriterType, typename TInfoType>
318 inline void handleComplexObj( TWriterType& oldVisitor, const TObjType* inObj, const TInfoType& info);
319
320 template<typename TCollectionType, typename TVisitor, typename TPropType, typename TInfoType >
321 void handleComplexCollection( TVisitor& visitor, const TPropType& inProp, const char* childName, TInfoType& inInfo )
322 {
323 PxU32 count( inProp.size( visitor.mObj ) );
324 if ( count )
325 {
326 PxInlineArray<TCollectionType*,5> theData;
327 theData.resize( count );
328 inProp.get( visitor.mObj, theData.begin(), count );
329 for( PxU32 idx =0; idx < count; ++idx )
330 {
331 visitor.pushName( childName );
332 handleComplexObj( visitor, theData[idx], inInfo );
333 visitor.popName();
334 }
335 }
336 }
337
338 template<typename TCollectionType, typename TVisitor, typename TPropType, typename TInfoType >
339 void handleBufferCollection( TVisitor& visitor, const TPropType& inProp, const char* childName, TInfoType& inInfo )
340 {
341 PxU32 count( inProp.size( visitor.mObj ) );
342 if ( count )
343 {
344 PxInlineArray<TCollectionType*,5> theData;
345 theData.resize( count );
346 inProp.get( visitor.mObj, theData.begin());
347
348 for( PxU32 idx =0; idx < count; ++idx )
349 {
350 visitor.pushName( childName );
351 handleComplexObj( visitor, theData[idx], inInfo );
352 visitor.popName();
353 }
354 }
355 }
356
357 template<typename TVisitor>
358 void handleShapes( TVisitor& visitor, const PxRigidActorShapeCollection& inProp )
359 {
360 PxShapeGeneratedInfo theInfo;
361
362 PxU32 count( inProp.size( visitor.mObj ) );
363 if ( count )
364 {
365 PxInlineArray<PxShape*,5> theData;
366 theData.resize( count );
367 inProp.get( visitor.mObj, theData.begin(), count );
368 for( PxU32 idx = 0; idx < count; ++idx )
369 {
370 const PxShape* shape = theData[idx];
371 visitor.pushName( "PxShape" );
372
373 if( !shape->isExclusive() )
374 {
375 writeReference( visitor.mWriter, visitor.mCollection, "PxShapeRef", shape );
376 }
377 else
378 {
379 handleComplexObj( visitor, shape, theInfo );
380 }
381 visitor.popName();
382 }
383 }
384 }
385
386 template<typename TVisitor>
387 void handleShapeMaterials( TVisitor& visitor, const PxShapeMaterialsProperty& inProp )
388 {
389 PxU32 count( inProp.size( visitor.mObj ) );
390 if ( count )
391 {
392 PxInlineArray<PxMaterial*,5> theData;
393 theData.resize( count );
394 inProp.get( visitor.mObj, theData.begin(), count );
395 visitor.pushName( "PxMaterialRef" );
396
397 for( PxU32 idx =0; idx < count; ++idx )
398 writeReference( visitor.mWriter, visitor.mCollection, "PxMaterialRef", theData[idx] );
399 visitor.popName();
400 }
401 }
402
403 template<typename TObjType>
405 {
406 TNameStack& mNameStack;
407 XmlWriter& mWriter;
408 const TObjType* mObj;
409 MemoryBuffer& mTempBuffer;
410 PxCollection& mCollection;
411
412 RepXVisitorWriterBase( TNameStack& ns, XmlWriter& writer, const TObjType* obj, MemoryBuffer& buf, PxCollection& collection )
413 : mNameStack( ns )
414 , mWriter( writer )
415 , mObj( obj )
416 , mTempBuffer( buf )
417 , mCollection( collection )
418 {
419 }
420
422 : mNameStack( other.mNameStack )
423 , mWriter( other.mWriter )
424 , mObj( other.mObj )
425 , mTempBuffer( other.mTempBuffer )
426 , mCollection( other.mCollection )
427 {
428 }
429
430 RepXVisitorWriterBase& operator=( const RepXVisitorWriterBase& ){ PX_ASSERT( false ); return *this; }
431
432 void gotoTopName()
433 {
434 if ( mNameStack.size() && mNameStack.back().mOpen == false )
435 {
436 mWriter.addAndGotoChild( mNameStack.back().mName );
437 mNameStack.back().mOpen = true;
438 }
439 }
440
441 void pushName( const char* inName )
442 {
443 gotoTopName();
444 mNameStack.pushBack( inName );
445 }
446
447 void pushBracketedName( const char* inName ) { pushName( inName ); }
448 void popName()
449 {
450 if ( mNameStack.size() )
451 {
452 if ( mNameStack.back().mOpen )
453 mWriter.leaveChild();
454 mNameStack.popBack();
455 }
456 }
457
458 const char* topName() const
459 {
460 if ( mNameStack.size() ) return mNameStack.back().mName;
461 PX_ASSERT( false );
462 return "bad__repx__name";
463 }
464
465 template<typename TAccessorType>
466 void simpleProperty( PxU32 /*key*/, TAccessorType& inProp )
467 {
468 typedef typename TAccessorType::prop_type TPropertyType;
469 TPropertyType propVal = inProp.get( mObj );
470 writeProperty( mWriter, mCollection, mTempBuffer, topName(), propVal );
471 }
472
473 template<typename TAccessorType>
474 void enumProperty( PxU32 /*key*/, TAccessorType& inProp, const PxU32ToName* inConversions )
475 {
476 writeEnumProperty( mWriter, topName(), inProp.get( mObj ), inConversions );
477 }
478
479 template<typename TAccessorType>
480 void flagsProperty( PxU32 /*key*/, const TAccessorType& inProp, const PxU32ToName* inConversions )
481 {
482 writeFlagsProperty( mWriter, mTempBuffer, topName(), inProp.get( mObj ), inConversions );
483 }
484
485 template<typename TAccessorType, typename TInfoType>
486 void complexProperty( PxU32* /*key*/, const TAccessorType& inProp, TInfoType& inInfo )
487 {
488 typedef typename TAccessorType::prop_type TPropertyType;
489 TPropertyType propVal = inProp.get( mObj );
490 handleComplexObj( *this, &propVal, inInfo );
491 }
492
493 template<typename TAccessorType, typename TInfoType>
494 void bufferCollectionProperty( PxU32* /*key*/, const TAccessorType& inProp, TInfoType& inInfo )
495 {
496 typedef typename TAccessorType::prop_type TPropertyType;
497
498 PxU32 count( inProp.size( mObj ) );
500 theData.resize( count );
501
503 PX_UNUSED(theTraits);
504 PxU32 numItems = inProp.get( mObj, theData.begin(), count );
505 PX_ASSERT( numItems == count );
506 for( PxU32 idx =0; idx < numItems; ++idx )
507 {
508 pushName( inProp.name() );
509 handleComplexObj( *this, &theData[idx], inInfo );
510 popName();
511 }
512 }
513
514 template<typename TAccessorType, typename TInfoType>
515 void extendedIndexedProperty( PxU32* /*key*/, const TAccessorType& inProp, TInfoType& /*inInfo */)
516 {
517 typedef typename TAccessorType::prop_type TPropertyType;
518
519 PxU32 count( inProp.size( mObj ) );
521 theData.resize( count );
522
523 for(PxU32 i = 0; i < count; ++i)
524 {
525 char buffer[32] = { 0 };
526 sprintf( buffer, "id_%u", i );
527 pushName( buffer );
528
529 TPropertyType propVal = inProp.get( mObj, i );
530 TInfoType& infoType = PxClassInfoTraits<TPropertyType>().Info;
531 handleComplexObj(*this, &propVal, infoType);
532 popName();
533 }
534 }
535
536 template<typename TAccessorType, typename TInfoType>
537 void PxFixedSizeLookupTableProperty( PxU32* /*key*/, TAccessorType& inProp, TInfoType& /*inInfo */)
538 {
539 typedef typename TAccessorType::prop_type TPropertyType;
540 PxU32 count( inProp.size( mObj ) );
541
542 PxU32 index = 0;
543 for(PxU32 i = 0; i < count; ++i)
544 {
545 char buffer[32] = { 0 };
546 sprintf( buffer, "id_%u", index++ );
547 pushName( buffer );
548 TPropertyType propVal = inProp.getX( mObj , i);
549 writeProperty( mWriter, mCollection, mTempBuffer, topName(), propVal );
550 popName();
551
552 sprintf( buffer, "id_%u", index++ );
553 pushName( buffer );
554 propVal = inProp.getY( mObj , i);
555 writeProperty( mWriter, mCollection, mTempBuffer, topName(), propVal );
556 popName();
557 }
558 }
559
560 void handleShapes( const PxRigidActorShapeCollection& inProp )
561 {
562 physx::Sn::handleShapes( *this, inProp );
563 }
564
565 void handleShapeMaterials( const PxShapeMaterialsProperty& inProp )
566 {
567 physx::Sn::handleShapeMaterials( *this, inProp );
568 }
569
570 void handleRigidActorGlobalPose(const PxRigidActorGlobalPosePropertyInfo& inProp)
571 {
573 simpleProperty(PxPropertyInfoName::PxRigidActor_GlobalPose, theAccessor);
574 }
575
576 };
577
578 template<typename TObjType>
580 {
581 RepXVisitorWriter( TNameStack& ns, XmlWriter& writer, const TObjType* obj, MemoryBuffer& buf, PxCollection& collection )
582 : RepXVisitorWriterBase<TObjType>( ns, writer, obj, buf, collection )
583 {
584 }
585
588 {
589 }
590 };
591
592 template<>
594 {
595 RepXVisitorWriter( TNameStack& ns, XmlWriter& writer, const PxArticulationLink* obj, MemoryBuffer& buf, PxCollection& collection )
596 : RepXVisitorWriterBase<PxArticulationLink>( ns, writer, obj, buf, collection )
597 {
598 }
599
602 {
603 }
604
605 void handleIncomingJoint( const TIncomingJointPropType& prop )
606 {
607 const PxArticulationJointReducedCoordinate* joint( prop.get( mObj ) );
608 if (joint)
609 {
610 pushName( "Joint" );
611
612 handleComplexObj( *this, joint, PxArticulationJointReducedCoordinateGeneratedInfo());
613
614 popName();
615 }
616 }
617 };
618
620
621 static void recurseAddLinkAndChildren( const PxArticulationLink* inLink, PxInlineArray<const PxArticulationLink*, 64>& ioLinks )
622 {
623 ioLinks.pushBack( inLink );
625 PxU32 childCount( inLink->getNbChildren() );
626 theChildren.resize( childCount );
627 inLink->getChildren( theChildren.begin(), childCount );
628 for ( PxU32 idx = 0; idx < childCount; ++idx )
629 recurseAddLinkAndChildren( theChildren[idx], ioLinks );
630 }
631
632 template<>
634 {
635 TArticulationLinkLinkMap& mArticulationLinkParents;
636
637 RepXVisitorWriter(TNameStack& ns, XmlWriter& writer, const PxArticulationReducedCoordinate* inArticulation, MemoryBuffer& buf, PxCollection& collection, TArticulationLinkLinkMap* artMap = NULL)
638 : RepXVisitorWriterBase<PxArticulationReducedCoordinate>(ns, writer, inArticulation, buf, collection)
639 , mArticulationLinkParents(*artMap)
640 {
642 PxU32 numLinks = inArticulation->getNbLinks();
643 linkList.resize(numLinks);
644 inArticulation->getLinks(linkList.begin(), numLinks);
645 for (PxU32 idx = 0; idx < numLinks; ++idx)
646 {
647 const PxArticulationLink* theLink(linkList[idx]);
648
650 PxU32 numChildren = theLink->getNbChildren();
651 theChildList.resize(numChildren);
652 theLink->getChildren(theChildList.begin(), numChildren);
653 for (PxU32 childIdx = 0; childIdx < numChildren; ++childIdx)
654 mArticulationLinkParents.insert(static_cast<uint64_t>(size_t(theChildList[childIdx])), theLink);
655 }
656 }
657
660 , mArticulationLinkParents(other.mArticulationLinkParents)
661 {
662 }
663 template<typename TAccessorType, typename TInfoType>
664 void complexProperty(PxU32* /*key*/, const TAccessorType& inProp, TInfoType& inInfo)
665 {
666 typedef typename TAccessorType::prop_type TPropertyType;
667 TPropertyType propVal = inProp.get(mObj);
668 handleComplexObj(*this, &propVal, inInfo);
669 }
670
671 void writeArticulationLink(const PxArticulationLink* inLink)
672 {
673 pushName("PxArticulationLink");
674 gotoTopName();
675
676 const TArticulationLinkLinkMap::Entry* theParentPtr = mArticulationLinkParents.find(static_cast<uint64_t>(size_t(inLink)));
677 if (theParentPtr != NULL)
678 writeProperty(mWriter, mCollection, mTempBuffer, "Parent", theParentPtr->second);
679 writeProperty(mWriter, mCollection, mTempBuffer, "Id", inLink);
680
682 handleComplexObj(*this, inLink, info);
683 popName();
684 }
685
686 void handleArticulationLinks(const PxArticulationLinkCollectionProp& inProp)
687 {
688 //topologically sort the links as per my discussion with Dilip because
689 //links aren't guaranteed to have the parents before the children in the
690 //overall link list and it is unlikely to be done by beta 1.
691 PxU32 count(inProp.size(mObj));
692 if (count)
693 {
695 theLinks.resize(count);
696 inProp.get(mObj, theLinks.begin(), count);
697
699 for (PxU32 idx = 0; idx < count; ++idx)
700 {
701 const PxArticulationLink* theLink(theLinks[idx]);
702 if (mArticulationLinkParents.find(static_cast<uint64_t>(size_t(theLink))) == NULL)
703 recurseAddLinkAndChildren(theLink, theSortedLinks);
704 }
705 PX_ASSERT(theSortedLinks.size() == count);
706 for (PxU32 idx = 0; idx < count; ++idx)
707 writeArticulationLink(theSortedLinks[idx]);
708 popName();
709 }
710 }
711 private:
713 };
714
715 template<>
717 {
718 RepXVisitorWriter( TNameStack& ns, XmlWriter& writer, const PxShape* obj, MemoryBuffer& buf, PxCollection& collection )
719 : RepXVisitorWriterBase<PxShape>( ns, writer, obj, buf, collection )
720 {
721 }
722
725 {
726 }
727
728 template<typename GeometryType>
729 inline void writeGeomProperty( const PxShapeGeomProperty& inProp, const char* inTypeName )
730 {
731 pushName( "Geometry" );
732 pushName( inTypeName );
733 GeometryType theType;
734 inProp.getGeometry( mObj, theType );
736 PxU32 count = theTraits.Info.totalPropertyCount();
737 if(count)
738 {
739 handleComplexObj( *this, &theType, theTraits.Info);
740 }
741 else
742 {
743 writeProperty(mWriter, mTempBuffer, inTypeName);
744 }
745 popName();
746 popName();
747 }
748
749 void handleGeomProperty( const PxShapeGeomProperty& inProp )
750 {
751 switch( mObj->getGeometryType() )
752 {
753 case PxGeometryType::eSPHERE: writeGeomProperty<PxSphereGeometry>( inProp, "PxSphereGeometry" ); break;
754 case PxGeometryType::ePLANE: writeGeomProperty<PxPlaneGeometry>( inProp, "PxPlaneGeometry" ); break;
755 case PxGeometryType::eCAPSULE: writeGeomProperty<PxCapsuleGeometry>( inProp, "PxCapsuleGeometry" ); break;
756 case PxGeometryType::eBOX: writeGeomProperty<PxBoxGeometry>( inProp, "PxBoxGeometry" ); break;
757 case PxGeometryType::eCONVEXMESH: writeGeomProperty<PxConvexMeshGeometry>( inProp, "PxConvexMeshGeometry" ); break;
758 case PxGeometryType::eTRIANGLEMESH: writeGeomProperty<PxTriangleMeshGeometry>( inProp, "PxTriangleMeshGeometry" ); break;
759 case PxGeometryType::eHEIGHTFIELD: writeGeomProperty<PxHeightFieldGeometry>( inProp, "PxHeightFieldGeometry" ); break;
760 case PxGeometryType::eTETRAHEDRONMESH: writeGeomProperty<PxTetrahedronMeshGeometry>( inProp, "PxTetrahedronMeshGeometry" ); break;
761 default:
762 PX_ASSERT( false );
763 }
764 }
765 };
766
767 template<typename TObjType>
768 inline void writeAllProperties( TNameStack& inNameStack, const TObjType* inObj, XmlWriter& writer, MemoryBuffer& buffer, PxCollection& collection )
769 {
770 RepXVisitorWriter<TObjType> newVisitor( inNameStack, writer, inObj, buffer, collection );
773 info.Info.visitBaseProperties( theOp );
774 info.Info.visitInstanceProperties( theOp );
775 }
776
777 template<typename TObjType>
778 inline void writeAllProperties( TNameStack& inNameStack, TObjType* inObj, XmlWriter& writer, MemoryBuffer& buffer, PxCollection& collection )
779 {
780 RepXVisitorWriter<TObjType> newVisitor( inNameStack, writer, inObj, buffer, collection );
783 info.Info.visitBaseProperties( theOp );
784 info.Info.visitInstanceProperties( theOp );
785 }
786
787 template<typename TObjType>
788 inline void writeAllProperties( const TObjType* inObj, XmlWriter& writer, MemoryBuffer& buffer, PxCollection& collection )
789 {
790 TNameStack theNames( buffer.mManager->getWrapper() );
791 writeAllProperties( theNames, inObj, writer, buffer, collection );
792 }
793
794 template<typename TObjType, typename TWriterType, typename TInfoType>
795 inline void handleComplexObj( TWriterType& oldVisitor, const TObjType* inObj, const TInfoType& /*info*/)
796 {
797 writeAllProperties( oldVisitor.mNameStack, inObj, oldVisitor.mWriter, oldVisitor.mTempBuffer, oldVisitor.mCollection );
798 }
799
800 template<typename TObjType, typename TWriterType>
801 inline void handleComplexObj( TWriterType& oldVisitor, const TObjType* inObj, const PxUnknownClassInfo& /*info*/)
802 {
803 writeProperty( oldVisitor.mWriter, oldVisitor.mCollection, oldVisitor.mTempBuffer, oldVisitor.topName(), *inObj );
804 }
805
806} }
807#endif
Definition SnXmlMemoryPoolStreams.h:165
PX_NOINLINE void resize(const uint32_t size, const T &a=T())
Definition PxArray.h:637
PX_FORCE_INLINE uint32_t size() const
Definition PxArray.h:242
PX_FORCE_INLINE ConstIterator begin() const
Definition PxArray.h:176
PX_FORCE_INLINE T & pushBack(const T &a)
Definition PxArray.h:296
PX_INLINE T popBack()
Definition PxArray.h:311
PX_FORCE_INLINE const T & back() const
Definition PxArray.h:224
A joint between two links in an articulation.
Definition PxArticulationJointReducedCoordinate.h:49
A tree structure of bodies connected by joints that is treated as a unit by the dynamics solver....
Definition PxArticulationReducedCoordinate.h:448
virtual PxU32 getLinks(PxArticulationLink **userBuffer, PxU32 bufferSize, PxU32 startIndex=0) const =0
Returns the set of links in the articulation in the order that they were added to the articulation us...
virtual PxU32 getNbLinks() const =0
Returns the number of links in the articulation.
Collection class for serialization.
Definition PxCollection.h:104
Definition PxInlineArray.h:43
Definition PxBasicTemplates.h:67
Abstract class for collision shapes.
Definition PxShape.h:146
Definition SnXmlSimpleXmlWriter.h:37
Helper class to encapsulate the reflection allocator.
Definition PxProfileAllocatorWrapper.h:71
PX_INLINE physx::PxRepXObject PxCreateRepXObject(const TDataType *inType, const physx::PxSerialObjectId inId)
Inline helper template function to create PxRepXObject from TDataType type supporting PxTypeInfo<TDat...
Definition PxRepXSerializer.h:111
PX_C_EXPORT PX_FOUNDATION_API physx::PxFoundation &PX_CALL_CONV PxGetFoundation()
Retrieves the Foundation SDK after it has been created.
Definition FdFoundation.cpp:279
uint64 uint64_t
Definition fwd.hpp:145
Sorts an array of objects in ascending order, assuming that the predicate implements the < operator:
Definition PxBoxController.h:39
PxU64 PxSerialObjectId
ID type for PxBase objects in a PxCollection.
Definition PxSerialFramework.h:61
Definition PxAutoGeneratedMetaDataObjects.h:1188
Definition PxAutoGeneratedMetaDataObjects.h:1058
Definition PxAutoGeneratedMetaDataObjects.h:1595
Definition PxMetaDataObjects.h:575
Definition PxMetaDataObjects.h:478
@ eINTERNAL_ERROR
The library failed for some reason. Possibly you have passed invalid values like NaNs,...
Definition PxErrors.h:73
Definition PxMetaDataObjects.h:173
Definition PxMetaDataObjects.h:149
Definition RepXMetaDataPropertyVisitor.h:37
Definition PxMetaDataObjects.h:559
Definition PxMetaDataObjects.h:520
Definition PxMetaDataObjects.h:540
Definition PxMetaDataObjects.h:124
Definition RepXMetaDataPropertyVisitor.h:84
Definition SnXmlVisitorWriter.h:405
Definition SnXmlVisitorWriter.h:580
Helper struct to encapsulate the array.
Definition PxProfileAllocatorWrapper.h:152
Helper struct to encapsulate the array.
Definition PxProfileAllocatorWrapper.h:171