PageRenderTime 25ms CodeModel.GetById 37ms RepoModel.GetById 0ms app.codeStats 0ms

/Tools/ColladaConverter/Collada15/FCollada/FCDocument/FCDGeometrySource.h

https://bitbucket.org/ardalanaz/dava.framework
C Header | 188 lines | 53 code | 30 blank | 105 comment | 1 complexity | 25d8b2ac55b673c5cc8e76bacad382c5 MD5 | raw file
  1. /*
  2. Copyright (C) 2005-2007 Feeling Software Inc.
  3. Portions of the code are:
  4. Copyright (C) 2005-2007 Sony Computer Entertainment America
  5. MIT License: http://www.opensource.org/licenses/mit-license.php
  6. */
  7. /**
  8. @file FCDGeometrySource.h
  9. This file contains the FCDGeometrySource class.
  10. */
  11. #ifndef _FCD_GEOMETRY_SOURCE_H_
  12. #define _FCD_GEOMETRY_SOURCE_H_
  13. #ifndef __FCD_OBJECT_WITH_ID_H_
  14. #include "FCDocument/FCDObjectWithId.h"
  15. #endif // __FCD_OBJECT_WITH_ID_H_
  16. #ifndef _FU_DAE_ENUM_H_
  17. #include "FUtils/FUDaeEnum.h"
  18. #endif // _FU_DAE_ENUM_H_
  19. #ifndef _FCD_PARAMETER_ANIMATABLE_H_
  20. #include "FCDocument/FCDParameterAnimatable.h"
  21. #endif // _FCD_PARAMETER_ANIMATABLE_H_
  22. class FCDExtra;
  23. /**
  24. A COLLADA data source for geometric meshes.
  25. A COLLADA data source for geometric meshes contains a list of floating-point values and the information
  26. to parse these floating-point values into meaningful content: the stride of the list and the type of data
  27. that the floating-point values represent. When the floating-point values are split according to the stride,
  28. you get the individual source values of the given type. A data source may also have a user-generated name to
  29. identify the data within. The name is optional and is used to keep
  30. around the user-friendly name for texture coordinate sets or color sets.
  31. Each source values of the COLLADA data source may be animated individually, or together: as an element.
  32. @ingroup FCDGeometry
  33. */
  34. class FCOLLADA_EXPORT FCDGeometrySource : public FCDObjectWithId
  35. {
  36. private:
  37. DeclareObjectType(FCDObjectWithId);
  38. DeclareParameter(fstring, FUParameterQualifiers::SIMPLE, name, FC("Name"));
  39. DeclareParameterListAnimatable(float, FUParameterQualifiers::SIMPLE, sourceData, FC("Data"))
  40. DeclareParameter(uint32, FUParameterQualifiers::SIMPLE, stride, FC("Stride"));
  41. DeclareParameter(uint32, FUParameterQualifiers::SIMPLE, sourceType, FC("Value Type")); // FUDaeGeometryInput::Semantic sourceType;
  42. DeclareParameterRef(FCDExtra, extra, FC("Extra Tree"));
  43. public:
  44. /** Constructor: do not use directly.
  45. Use FCDGeometryMesh::AddSource or FCDGeometryMesh::AddValueSource instead.
  46. @param document The COLLADA document which owns the data source. */
  47. FCDGeometrySource(FCDocument* document);
  48. /** Destructor. */
  49. virtual ~FCDGeometrySource();
  50. /** Copies the data source into a clone.
  51. The clone may reside in another document.
  52. @param clone The empty clone. If this pointer is NULL, a new data source
  53. will be created and you will need to release the returned pointer manually.
  54. @return The clone. */
  55. FCDGeometrySource* Clone(FCDGeometrySource* clone = NULL) const;
  56. /** Retrieves the name of the data source. The name is optional and is used to
  57. keep around a user-friendly name for texture coordinate sets or color sets.
  58. @return The name of the data source. */
  59. inline const fstring& GetName() const { return name; }
  60. /** Retrieves the pure data of the data source. This is a dynamically-sized array of
  61. floating-point values that contains all the data of the source.
  62. @return The pure data of the data source. */
  63. inline float* GetData() { return !sourceData.empty() ? &sourceData.front() : NULL; }
  64. inline const float* GetData() const { return !sourceData.empty() ? &sourceData.front() : NULL; } /**< See above. */
  65. /** [INTERNAL] Retrieve the reference to the source data.
  66. @return The reference to the source data.
  67. */
  68. inline FCDParameterListAnimatableFloat& GetSourceData(){ return sourceData; }
  69. inline const FCDParameterListAnimatableFloat& GetSourceData() const { return sourceData; }
  70. /** Retrieves a ptr to the data of the data source. This allows external objects to
  71. store pointers to our data even when the data memory is reallocated
  72. @return The ptr to the pure data of the data source. */
  73. inline float** GetDataPtr() { return (float**) sourceData.GetDataPtr(); }
  74. inline const float** GetDataPtr() const { return (const float**) sourceData.GetDataPtr(); } /**< See above. */
  75. /** Retrieves the amount of data inside the source.
  76. @return The number of data entries in the source. */
  77. inline size_t GetDataCount() const { return sourceData.size(); }
  78. /** Sets the amount of data contained inside the source.
  79. It is preferable to set the stride and to use SetValueCount.
  80. No initialization of new values is done.
  81. @param count The amount of data for the source to contain. */
  82. void SetDataCount(size_t count);
  83. /** Retrieves the stride of the data within the source.
  84. There is no guarantee that the number of data values within the source is a multiple of the stride,
  85. yet you should always verify that the stride is at least the wanted dimension. For example, there is
  86. no guarantee that your vertex position data source has a stride of 3. 3dsMax is known to always
  87. export 3D texture coordinate positions.
  88. @return The stride of the data. */
  89. inline uint32 GetStride() const { return stride; }
  90. /** Retrieves the number of individual source values contained in the source.
  91. @return The number of source values. */
  92. inline size_t GetValueCount() const { return sourceData.size() / stride; }
  93. /** Retrieves the max number of values this input can handle before memory is reallocated.
  94. @return The number of source values. */
  95. inline size_t GetValueReserved() const { return sourceData.capacity() / stride; }
  96. /** Sets the number of individual source values contained in the source.
  97. No initialization of new values is done.
  98. @param count The number of individual source values to contain in this source. */
  99. inline void SetValueCount(size_t count) { FUAssert(stride > 0, return); SetDataCount(count * stride); }
  100. /** Retrieves one source value out of this source.
  101. @param index The index of the source value.
  102. @return The source value. */
  103. inline const float* GetValue(size_t index) const { FUAssert(index < GetValueCount(), return NULL); return &sourceData.at(index * stride); } /**< See above. */
  104. /** Sets one source value out of this source.
  105. @param index The index of the source value.
  106. @param value The new value. */
  107. inline void SetValue(size_t index, const float* value) { FUAssert(index < GetValueCount(), return); for (size_t i = 0; i < stride; ++i) sourceData.set(stride * index + i, value[i]); }
  108. /** Retrieves the type of data contained within the source.
  109. Common values for the type of data are POSITION, NORMAL, COLOR and TEXCOORD.
  110. Please see FUDaeGeometryInput for more information.
  111. @see FUDaeGeometryInput.
  112. @return The type of data contained within the source. */
  113. inline FUDaeGeometryInput::Semantic GetType() const { return (FUDaeGeometryInput::Semantic) *sourceType; }
  114. /** Sets the type of data contained within the source.
  115. Modifying the source type of an existing source is not recommended.
  116. Common values for the type of data are POSITION, NORMAL, COLOR and TEXCOORD.
  117. Please see FUDaeGeometryInput for more information.
  118. @see FUDaeGeometryInput.
  119. @param type The type of data to be contained within the source. */
  120. inline void SetType(FUDaeGeometryInput::Semantic type) { sourceType = type; }
  121. /** Retrieves the list of animated values for the data of the source.
  122. @return The list of animated values. */
  123. inline FUObjectContainer<FCDAnimated>& GetAnimatedValues() { return sourceData.GetAnimatedValues(); }
  124. inline const FUObjectContainer<FCDAnimated>& GetAnimatedValues() const { return sourceData.GetAnimatedValues(); } /**< See above. */
  125. /** Sets the user-friendly name of the data source. The name is optional and is used to
  126. keep around a user-friendly name for texture coordinate sets or color sets.
  127. @param _name The user-friendly name of the data source. */
  128. inline void SetName(const fstring& _name) { name = _name; SetDirtyFlag(); }
  129. /** Overwrites the data contained within the data source.
  130. @param _sourceData The new data for this source.
  131. @param _sourceStride The stride for the new data.
  132. @param offset The offset at which to start retrieving the new data.
  133. This argument defaults at 0 to indicate that the data copy should start from the beginning.
  134. @param count The number of data entries to copy into the data source.
  135. This argument defaults at 0 to indicate that the data copy should include everything. */
  136. void SetData(const FloatList& _sourceData, uint32 _sourceStride, size_t count=0, size_t offset=0);
  137. /** Sets the stride for the source data.
  138. @param _stride The stride for the source data. */
  139. inline void SetStride(uint32 _stride) { stride = _stride; SetDirtyFlag(); }
  140. /** [INTERNAL] Set the source type.
  141. @param type The source type. */
  142. void SetSourceType(FUDaeGeometryInput::Semantic type) { sourceType = type; }
  143. /** Retrieves the extra information contained by this data source.
  144. @return The extra tree. This pointer will be NULL,
  145. in the const-version of this function, if there is no extra information.
  146. In the modifiable-version of this function:
  147. you will always get a valid extra tree that you can fill in. */
  148. FCDExtra* GetExtra();
  149. inline const FCDExtra* GetExtra() const { return extra; } /**< See above. */
  150. /** [INTERNAL] Clones this data source. You will need to release the returned pointer manually.
  151. @return An identical copy of the data source. */
  152. FCDGeometrySource* Clone() const;
  153. };
  154. #endif // _FCD_GEOMETRY_SOURCE_H_