PageRenderTime 27ms CodeModel.GetById 12ms RepoModel.GetById 1ms app.codeStats 0ms

/CS/migrated/branches/NEW_SHADERSYS/include/imesh/sprite3d.h

#
C++ Header | 487 lines | 152 code | 68 blank | 267 comment | 0 complexity | 6fe25d22e5fc6ada264c8648fc07c321 MD5 | raw file
Possible License(s): GPL-2.0, LGPL-2.1, LGPL-2.0
  1. /*
  2. Copyright (C) 2000-2001 by Jorrit Tyberghein
  3. This library is free software; you can redistribute it and/or
  4. modify it under the terms of the GNU Library General Public
  5. License as published by the Free Software Foundation; either
  6. version 2 of the License, or (at your option) any later version.
  7. This library is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  10. Library General Public License for more details.
  11. You should have received a copy of the GNU Library General Public
  12. License along with this library; if not, write to the Free
  13. Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  14. */
  15. #ifndef __CS_IMESH_SPRITE3D_H__
  16. #define __CS_IMESH_SPRITE3D_H__
  17. #include "csutil/scf.h"
  18. #include "csutil/garray.h"
  19. #include "csutil/cscolor.h"
  20. #include "ivideo/graph3d.h"
  21. class csColor;
  22. struct iMaterialWrapper;
  23. struct iSkeleton;
  24. struct iSkeletonState;
  25. struct iMeshObject;
  26. struct iMeshWrapper;
  27. struct iMeshObjectFactory;
  28. struct iRenderView;
  29. struct iRenderView;
  30. /**
  31. * Macros for the csSprite3D lighting levels.
  32. */
  33. #define CS_SPR_LIGHTING_HQ 0
  34. #define CS_SPR_LIGHTING_LQ 1
  35. #define CS_SPR_LIGHTING_FAST 2
  36. #define CS_SPR_LIGHTING_RANDOM 3
  37. /**
  38. * Use the global value for determining which lighting level is used by the
  39. * sprite.
  40. */
  41. #define CS_SPR_LIGHT_GLOBAL 0
  42. /**
  43. * Use the sprites template lighting quality value for determining which
  44. * lighting level is used by the sprite.
  45. */
  46. #define CS_SPR_LIGHT_TEMPLATE 1
  47. /**
  48. * Use the lighting quality value local to the sprite for determining which
  49. * lighting level is used by the sprite.
  50. */
  51. #define CS_SPR_LIGHT_LOCAL 2
  52. /**
  53. * Use the global value for determining if LOD is used by the
  54. * sprite, and what level it should be used at.
  55. */
  56. #define CS_SPR_LOD_GLOBAL 0
  57. /**
  58. * Use the sprites template lod value.
  59. */
  60. #define CS_SPR_LOD_TEMPLATE 1
  61. /**
  62. * Use the LOD value local to the sprite.
  63. */
  64. #define CS_SPR_LOD_LOCAL 2
  65. // @@@ CONFIG TODO: global_lighting_quality
  66. // @@@ CONFIG TODO: global_lod_level
  67. SCF_VERSION (iSpriteFrame, 0, 0, 2);
  68. /**
  69. * A frame for 3D sprite animation.
  70. */
  71. struct iSpriteFrame : public iBase
  72. {
  73. /// Set the name.
  74. virtual void SetName (char const*) = 0;
  75. /// Get the name.
  76. virtual char const* GetName () const = 0;
  77. ///
  78. virtual int GetAnmIndex () const = 0;
  79. ///
  80. virtual int GetTexIndex () const = 0;
  81. };
  82. SCF_VERSION (iSpriteAction, 0, 0, 1);
  83. /**
  84. * An action frameset for 3D sprite animation.
  85. */
  86. struct iSpriteAction : public iBase
  87. {
  88. /// Set the name.
  89. virtual void SetName (char const*) = 0;
  90. /// Get the name.
  91. virtual char const* GetName () const = 0;
  92. /// Get the number of frames in this action.
  93. virtual int GetFrameCount () = 0;
  94. /// Get the specified frame.
  95. virtual iSpriteFrame* GetFrame (int f) = 0;
  96. /// Get the next frame after the specified one.
  97. virtual iSpriteFrame* GetNextFrame (int f) = 0;
  98. /// Get the delay for the specified frame.
  99. virtual int GetFrameDelay (int f) = 0;
  100. /// Get the displacement for the specified frame.
  101. virtual float GetFrameDisplacement (int f) = 0;
  102. /// Add a frame to this action.
  103. virtual void AddFrame (iSpriteFrame* frame, int delay, float displacement) = 0;
  104. };
  105. SCF_VERSION (iSpriteSocket, 0, 0, 1);
  106. /**
  107. * A socket for specifying where sprites can plug into
  108. * other sprites.
  109. */
  110. struct iSpriteSocket : public iBase
  111. {
  112. /// Set the name.
  113. virtual void SetName (char const*) = 0;
  114. /// Get the name.
  115. virtual char const* GetName () const = 0;
  116. /// Set the attached sprite.
  117. virtual void SetMeshWrapper (iMeshWrapper* mesh) = 0;
  118. /// Get the attached sprite.
  119. virtual iMeshWrapper* GetMeshWrapper () const = 0;
  120. /// Set the index of the triangle for the socket.
  121. virtual void SetTriangleIndex (int tri_index) = 0;
  122. /// Get the index of the triangle for the socket.
  123. virtual int GetTriangleIndex () const = 0;
  124. };
  125. SCF_VERSION (iSprite3DFactoryState, 0, 0, 3);
  126. /**
  127. * This interface describes the API for the 3D sprite factory mesh object.
  128. */
  129. struct iSprite3DFactoryState : public iBase
  130. {
  131. /// Set material of sprite.
  132. virtual void SetMaterialWrapper (iMaterialWrapper* material) = 0;
  133. /// Get material of sprite.
  134. virtual iMaterialWrapper* GetMaterialWrapper () const = 0;
  135. /**
  136. * Reserve space for the given number of vertices. A vertex includes
  137. * information about its position, normal and texel. This function will
  138. * not write any information into the reserved space. <p>
  139. *
  140. * Note that this function requires that at least one frame exists in
  141. * the sprite factory, otherwise this function will fail!
  142. */
  143. virtual void AddVertices (int num) = 0;
  144. /// Return the current number of vertices
  145. virtual int GetVertexCount () const = 0;
  146. /// Get a vertex.
  147. virtual const csVector3& GetVertex (int frame, int vertex) const = 0;
  148. /// Set a vertex.
  149. virtual void SetVertex (int frame, int vertex, const csVector3 &Value) = 0;
  150. /// Get vertex array.
  151. virtual csVector3* GetVertices (int frame) const = 0;
  152. /**
  153. * Set array of vertices. The array is copied. It must contain as many
  154. * vertices as the vertex count of this sprite.
  155. */
  156. virtual void SetVertices (csVector3 const* vert, int frame) = 0;
  157. /// Get a texel.
  158. virtual const csVector2& GetTexel (int frame, int vertex) const = 0;
  159. /// Set a texel.
  160. virtual void SetTexel (int frame, int vertex, const csVector2 &Value) = 0;
  161. /// Get array of texels.
  162. virtual csVector2* GetTexels (int frame) const = 0;
  163. /**
  164. * Set array of texels. The array is copied. It must contain as many texels
  165. * as the vertex count of this sprite.
  166. */
  167. virtual void SetTexels (csVector2 const* tex, int frame) = 0;
  168. /// Get a normal.
  169. virtual const csVector3& GetNormal (int frame, int vertex) const = 0;
  170. /// Set a normal.
  171. virtual void SetNormal (int frame, int vertex, const csVector3 &Value) = 0;
  172. /// Get normal array.
  173. virtual csVector3* GetNormals (int frame) const = 0;
  174. /**
  175. * Set array of normals. The array is copied. It must contain as many normals
  176. * as the vertex count of this sprite.
  177. */
  178. virtual void SetNormals (csVector3 const* norms, int frame) = 0;
  179. /**
  180. * Add a triangle to the normal, texel, and vertex meshes
  181. * a, b and c are indices to texel vertices
  182. */
  183. virtual void AddTriangle (int a, int b, int c) = 0;
  184. /// Returns the texel indices for triangle 'x'
  185. virtual csTriangle GetTriangle (int x) const = 0;
  186. /// Returns the triangles of the texel_mesh
  187. virtual csTriangle* GetTriangles () const = 0;
  188. /// Returns the number of triangles in the sprite
  189. virtual int GetTriangleCount () const = 0;
  190. /// Set the count of triangles.
  191. virtual void SetTriangleCount (int count) = 0;
  192. /// Set array of triangles. The array is copied.
  193. virtual void SetTriangles( csTriangle const* trigs, int count) = 0;
  194. /// Create and add a new frame to the sprite.
  195. virtual iSpriteFrame* AddFrame () = 0;
  196. /// Find a named frame.
  197. virtual iSpriteFrame* FindFrame (const char* name) const = 0;
  198. /// Query the number of frames.
  199. virtual int GetFrameCount () const = 0;
  200. /// Query the frame number f.
  201. virtual iSpriteFrame* GetFrame (int f) const = 0;
  202. /// Create and add a new action frameset to the sprite.
  203. virtual iSpriteAction* AddAction () = 0;
  204. /// Find a named action.
  205. virtual iSpriteAction* FindAction (const char* name) const = 0;
  206. /// Get the first action.
  207. virtual iSpriteAction* GetFirstAction () const = 0;
  208. /// Get number of actions in sprite.
  209. virtual int GetActionCount () const = 0;
  210. /// Get action number No
  211. virtual iSpriteAction* GetAction (int No) const = 0;
  212. /// Create and add a new socket to the sprite.
  213. virtual iSpriteSocket* AddSocket () = 0;
  214. /// find a named socket into the sprite.
  215. virtual iSpriteSocket* FindSocket (const char * name) const = 0;
  216. /// find a socked based on the sprite attached to it.
  217. virtual iSpriteSocket* FindSocket (iMeshWrapper *mesh) const = 0;
  218. /// Query the number of sockets.
  219. virtual int GetSocketCount () const = 0;
  220. /// Query the socket number f.
  221. virtual iSpriteSocket* GetSocket (int f) const = 0;
  222. /// Enable skeletal animation for this factory.
  223. virtual void EnableSkeletalAnimation () = 0;
  224. /**
  225. * Get the skeleton. Will only be valid if skeletal animation
  226. * has been enabled with EnableSkeletalAnimation(). Otherwise
  227. * it will return 0.
  228. */
  229. virtual iSkeleton* GetSkeleton () const = 0;
  230. /// Enable/disable tweening.
  231. virtual void EnableTweening (bool en) = 0;
  232. /// Query state of tweening.
  233. virtual bool IsTweeningEnabled () const = 0;
  234. /// Set lighting quality (one of CS_SPR_LIGHTING_*).
  235. virtual void SetLightingQuality (int qual) = 0;
  236. /// Get lighting quality (one of CS_SPR_LIGHTING_*).
  237. virtual int GetLightingQuality () const = 0;
  238. /**
  239. * Sets which lighting config variable that all new sprites created
  240. * from this template will use.
  241. * The options are:
  242. * <ul>
  243. * <li>CS_SPR_LIGHT_GLOBAL (default)
  244. * <li>CS_SPR_LIGHT_TEMPLATE
  245. * <li>CS_SPR_LIGHT_LOCAL
  246. * </ul>
  247. */
  248. virtual void SetLightingQualityConfig (int qual) = 0;
  249. /// Get the lighting quality config.
  250. virtual int GetLightingQualityConfig () const = 0;
  251. /**
  252. * Sets which lod config variable that all new sprites created
  253. * from this template will use.
  254. * The options are:
  255. * <ul>
  256. * <li>CS_SPR_LOD_GLOBAL (default)
  257. * <li>CS_SPR_LOD_TEMPLATE
  258. * <li>CS_SPR_LOD_LOCAL
  259. * </ul>
  260. */
  261. virtual void SetLodLevelConfig (int config_flag) = 0;
  262. /// Returns what this template is using for determining the lod quality.
  263. virtual int GetLodLevelConfig () const = 0;
  264. /**
  265. * Smooth out the gouraud shading by merging the precalculated
  266. * vertex normals along seams in frame 'frame' based on which
  267. * vertices are very close in frame 'base'
  268. */
  269. virtual void MergeNormals (int base, int frame) = 0;
  270. /**
  271. * Smooth out the gouraud shading by merging the precalculated
  272. * vertex normals along seams in all frames based on which
  273. * vertices are very close in frame 'base'
  274. */
  275. virtual void MergeNormals (int base) = 0;
  276. /**
  277. * Smooth out the gouraud shading by merging the precalculated
  278. * vertex normals along seams in all frames based on which
  279. * vertices are very close in each frame
  280. */
  281. virtual void MergeNormals () = 0;
  282. /// Set default mix mode for new sprites.
  283. virtual void SetMixMode (uint mode) = 0;
  284. /// Get default mix mode for new sprites.
  285. virtual uint GetMixMode () const = 0;
  286. };
  287. SCF_VERSION (iSprite3DState, 0, 0, 6);
  288. /**
  289. * This interface describes the API for the 3D sprite mesh object.
  290. */
  291. struct iSprite3DState : public iBase
  292. {
  293. /// Set material of sprite.
  294. virtual void SetMaterialWrapper (iMaterialWrapper* material) = 0;
  295. /// Get material of sprite.
  296. virtual iMaterialWrapper* GetMaterialWrapper () const = 0;
  297. /// Set mix mode.
  298. virtual void SetMixMode (uint mode) = 0;
  299. /// Get mix mode.
  300. virtual uint GetMixMode () const = 0;
  301. /// Set lighting.
  302. virtual void SetLighting (bool l) = 0;
  303. /// Get lighting.
  304. virtual bool IsLighting () const = 0;
  305. // @@@ TODO: what about convenience functions to set colors for verts?
  306. /**
  307. * Get the skeleton state. Will only be valid if skeletal animation
  308. * has been enabled for the factory that this sprite was created from.
  309. * Otherwise it will return 0.
  310. */
  311. virtual iSkeletonState* GetSkeletonState () const = 0;
  312. /// Go to a specified frame.
  313. virtual void SetFrame (int f) = 0;
  314. /// Get the current frame number.
  315. virtual int GetCurFrame () const = 0;
  316. /// Get the number of frames.
  317. virtual int GetFrameCount () const = 0;
  318. /**
  319. * Select an action by name.
  320. * If 'loop'==false the animation will not loop.
  321. */
  322. virtual bool SetAction (const char * name,
  323. bool loop = true, float speed = 1) = 0;
  324. /**
  325. * Select an action by index.
  326. * If 'loop'==false the animation will not loop.
  327. */
  328. virtual bool SetAction (int index,
  329. bool loop = true, float speed = 1) = 0;
  330. /// Set whether action should run in reverse or not.
  331. virtual void SetReverseAction(bool reverse) = 0;
  332. /// Set single-step frame advance flag on actions
  333. virtual void SetSingleStepAction(bool singlestep) = 0;
  334. /**
  335. * This sets an action to run one time, then the
  336. * sprite reverts to the prior action.
  337. */
  338. virtual bool SetOverrideAction(const char *name,
  339. float speed = 1) = 0;
  340. /**
  341. * This sets an action to run one time, then the
  342. * sprite reverts to the prior action.
  343. */
  344. virtual bool SetOverrideAction(int index,
  345. float speed = 1) = 0;
  346. /// Propogate set action to all children
  347. virtual bool PropagateAction (const char *name) = 0;
  348. /// Get the current action.
  349. virtual iSpriteAction* GetCurAction () const = 0;
  350. /// Get whether the current action is reversed or not
  351. virtual bool GetReverseAction () const = 0;
  352. /// Enable/disable tweening.
  353. virtual void EnableTweening (bool en) = 0;
  354. /// Query state of tweening.
  355. virtual bool IsTweeningEnabled () const = 0;
  356. /// Unset the texture (i.e. use the one from the factory).
  357. virtual void UnsetTexture () = 0;
  358. /**
  359. * Returns the lighting quality level used by this sprite.
  360. * See SPR_LIGHTING_* macros defined in this header for the different types
  361. * of lighting.
  362. */
  363. virtual int GetLightingQuality () = 0;
  364. /**
  365. * Sets the local lighting quality for this sprite. NOTE: you must use
  366. * SetLightingQualityConfig (CS_SPR_LIGHT_LOCAL) for the sprite to use this.
  367. */
  368. virtual void SetLocalLightingQuality (int lighting_quality) = 0;
  369. /**
  370. * Sets which lighting config variable this sprite will use.
  371. * The options are:
  372. * <ul>
  373. * <li>CS_SPR_LIGHT_GLOBAL (default)
  374. * <li>CS_SPR_LIGHT_TEMPLATE
  375. * <li>CS_SPR_LIGHT_LOCAL
  376. * </ul>
  377. */
  378. virtual void SetLightingQualityConfig (int config_flag) = 0;
  379. /**
  380. * Returns what this sprite is using for determining the lighting quality.
  381. */
  382. virtual int GetLightingQualityConfig () const = 0;
  383. /**
  384. * Sets which lighting config variable this sprite will use.
  385. * The options are:
  386. * <ul>
  387. * <li>CS_SPR_LOD_GLOBAL (default)
  388. * <li>CS_SPR_LOD_TEMPLATE
  389. * <li>CS_SPR_LOD_LOCAL
  390. * </ul>
  391. */
  392. virtual void SetLodLevelConfig (int config_flag) = 0;
  393. /**
  394. * Returns what this sprite is using for determining the lighting quality.
  395. */
  396. virtual int GetLodLevelConfig () const = 0;
  397. /**
  398. * Returns true if lod is enabled, else false.
  399. */
  400. virtual bool IsLodEnabled () const = 0;
  401. /**
  402. * Set the base color. This color will be added to the vertex
  403. * colors of the sprite. If no lighting is used then this will
  404. * be the color.
  405. */
  406. virtual void SetBaseColor (const csColor& col) = 0;
  407. /**
  408. * Get the base color.
  409. */
  410. virtual void GetBaseColor (csColor& col) const = 0;
  411. /// find a socked based on the sprite attached to it.
  412. virtual iSpriteSocket* FindSocket (iMeshWrapper *mesh) const = 0;
  413. /// find a named socket into the sprite.
  414. virtual iSpriteSocket* FindSocket (const char * name) const = 0;
  415. };
  416. #endif // __CS_IMESH_SPRITE3D_H__