PageRenderTime 64ms CodeModel.GetById 29ms RepoModel.GetById 0ms app.codeStats 0ms

/CS/migrated/branches/R0_90/plugins/mesh/spr3d/object/spr3d.h

#
C++ Header | 1572 lines | 905 code | 172 blank | 495 comment | 16 complexity | 0c838a78e364cd5c6613dcf4d8da32bd MD5 | raw file
Possible License(s): GPL-2.0, LGPL-2.1, LGPL-2.0
  1. /*
  2. Copyright (C) 1998-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_SPR3D_H__
  16. #define __CS_SPR3D_H__
  17. #include "csutil/cscolor.h"
  18. #include "csutil/typedvec.h"
  19. #include "csutil/rng.h"
  20. #include "csgeom/math3d.h"
  21. #include "csgeom/math2d.h"
  22. #include "csgeom/poly2d.h"
  23. #include "csgeom/poly3d.h"
  24. #include "csgeom/box.h"
  25. #include "plugins/mesh/spr3d/object/sprtri.h"
  26. #include "plugins/mesh/spr3d/object/skel3d.h"
  27. #include "ivideo/graph3d.h"
  28. #include "ivaria/polymesh.h"
  29. #include "imesh/sprite3d.h"
  30. #include "ivideo/material.h"
  31. #include "iengine/material.h"
  32. #include "iengine/lod.h"
  33. #include "imesh/object.h"
  34. #include "iutil/config.h"
  35. #include "iutil/eventh.h"
  36. #include "iutil/comp.h"
  37. #include "ivideo/vbufmgr.h"
  38. #include "qint.h"
  39. #define ALL_LOD_FEATURES (CS_LOD_TRIANGLE_REDUCTION|CS_LOD_DISTANCE_REDUCTION)
  40. struct iObjectRegistry;
  41. /**
  42. * A frame for 3D sprite animation.
  43. */
  44. class csSpriteFrame : public iSpriteFrame
  45. {
  46. private:
  47. int animation_index;
  48. int texturing_index;
  49. char* name;
  50. /// If true then normals are already calculated for this frame.
  51. bool normals_calculated;
  52. /// Bounding box in object space for this frame.
  53. csBox3 box;
  54. /// Radius in object space for this frame.
  55. csVector3 radius;
  56. public:
  57. ///
  58. csSpriteFrame (int anm_idx, int tex_idx);
  59. ///
  60. virtual ~csSpriteFrame ();
  61. ///
  62. void SetTexIndex (int tex_idx) { texturing_index = tex_idx; }
  63. /// Return true if normals are already calculated.
  64. bool NormalsCalculated () const { return normals_calculated; }
  65. /// Set normals calculated to value.
  66. void SetNormalsCalculated (bool n) { normals_calculated = n; }
  67. /// Set the name.
  68. virtual void SetName (char const*);
  69. /// Get the name.
  70. virtual char const* GetName () const { return name; }
  71. ///
  72. virtual int GetAnmIndex () const { return animation_index; }
  73. ///
  74. virtual int GetTexIndex () const { return texturing_index; }
  75. /**
  76. * Compute the object space bounding box for this frame.
  77. * This has to be called after setting up the frame and before
  78. * using it.
  79. */
  80. void SetBoundingBox (const csBox3& b) { box = b; }
  81. /**
  82. * Get the bounding box in object space.
  83. */
  84. void GetBoundingBox (csBox3& b) const { b = box; }
  85. /**
  86. * Set the radius of this frame in object space.
  87. */
  88. void SetRadius (const csVector3& r) { radius = r; }
  89. /**
  90. * Get the radius of this frame in object space.
  91. */
  92. void GetRadius (csVector3& r) const { r = radius; }
  93. SCF_DECLARE_IBASE;
  94. };
  95. /**
  96. * An action frameset for a 3D sprite animation.
  97. */
  98. class csSpriteAction2 : public iSpriteAction
  99. {
  100. public:
  101. /// Initialize a action object
  102. csSpriteAction2 ();
  103. /// Destroy this action object
  104. virtual ~csSpriteAction2 ();
  105. /// Add a frame to this action.
  106. void AddCsFrame (csSpriteFrame* frame, int delay);
  107. /// Add a frame to this action
  108. virtual void AddFrame (iSpriteFrame* frame, int delay);
  109. /// Set action name
  110. virtual void SetName (char const*);
  111. /// Get action name
  112. virtual char const* GetName () const
  113. { return name; }
  114. /// Get total number of frames in this action
  115. virtual int GetFrameCount () { return frames.Length (); }
  116. /// Query the frame number f.
  117. csSpriteFrame* GetCsFrame (int f)
  118. { return (f < frames.Length ()) ? (csSpriteFrame *)frames [f] : (csSpriteFrame*)NULL; }
  119. /// Returns the looping frame after frame number f.
  120. csSpriteFrame* GetCsNextFrame (int f)
  121. { f++; return f<frames.Length() ? (csSpriteFrame*)frames[f]:(csSpriteFrame*)frames[0]; }
  122. /// Query the frame number f.
  123. virtual iSpriteFrame* GetFrame (int f)
  124. { return (iSpriteFrame*)((f < frames.Length ()) ? (csSpriteFrame *)frames [f] : (csSpriteFrame*)NULL); }
  125. /// Returns the looping frame after frame number f.
  126. virtual iSpriteFrame* GetNextFrame (int f)
  127. { f++; return (iSpriteFrame*)(f<frames.Length() ? (csSpriteFrame*)frames[f]:(csSpriteFrame*)frames[0]); }
  128. /// Get delay for frame number f
  129. virtual int GetFrameDelay (int f)
  130. { return (int)delays [f]; }
  131. SCF_DECLARE_IBASE;
  132. private:
  133. char *name;
  134. csVector frames;
  135. csVector delays;
  136. };
  137. /**
  138. * A vector for frames which knows how to clean them up.
  139. */
  140. class csSpriteFrameVector : public csVector
  141. {
  142. public:
  143. /// Delete all inserted objects before deleting the object itself.
  144. virtual ~csSpriteFrameVector ();
  145. /// Free a item as a frame.
  146. virtual bool FreeItem (csSome Item);
  147. };
  148. /**
  149. * A vector for actions which knows how to clean them up.
  150. */
  151. class csSpriteActionVector : public csVector
  152. {
  153. public:
  154. /// Delete all inserted objects before deleting the object itself.
  155. virtual ~csSpriteActionVector ();
  156. /// Free a item as an action.
  157. virtual bool FreeItem (csSome Item);
  158. };
  159. class csSprite3DMeshObject;
  160. /**
  161. * A 3D sprite based on a triangle mesh with a single texture.
  162. * Animation is done with frames.
  163. * This class represents a template from which a csSprite3D
  164. * class can be made.
  165. */
  166. class csSprite3DMeshObjectFactory : public iMeshObjectFactory
  167. {
  168. private:
  169. friend class csSprite3DMeshObject;
  170. /// Material handle as returned by iTextureManager.
  171. iMaterialWrapper* cstxt;
  172. /// An optional skeleton.
  173. csSkel* skeleton;
  174. /**
  175. * The order in which to introduce levels in order to get to a higher LOD.
  176. * The index of this array is the vertex number which is introduced.
  177. * The vertices of this template were reordered (by GenerateLOD()) so that
  178. * the first vertices are used in low-detail. The contents of this array
  179. * is the vertex number to emerge from.
  180. */
  181. int* emerge_from;
  182. /// The frames
  183. csSpriteFrameVector frames;
  184. /// The actions (a vector of csSpriteAction2 objects)
  185. csSpriteActionVector actions;
  186. /// Enable tweening.
  187. bool do_tweening;
  188. /// The lighting_quality for this template. See macros CS_SPR_LIGHTING_*
  189. int lighting_quality;
  190. /**
  191. * The lighting_quality_config for this template.
  192. * See macros CS_SPR_LIGHT_*
  193. * This is used to set new sprites lighting_quality_config to this one.
  194. */
  195. int lighting_quality_config;
  196. /*
  197. * Configuration value for template LOD. 0 is lowest detail, 1 is maximum.
  198. * If 1 then the base mesh is used and no LOD reduction/computation
  199. * is done.
  200. */
  201. float lod_level;
  202. /*
  203. * Current LOD features.
  204. */
  205. uint32 current_features;
  206. /**
  207. * The lod_level_config for this template.
  208. * See macros CS_SPR_LOD_*
  209. * This is used to set new sprites lod_level_config to this one.
  210. */
  211. int lod_level_config;
  212. /// The base mesh is also the texture alignment mesh.
  213. csTriangleMesh2* texel_mesh;
  214. /// The array of texels
  215. CS_DECLARE_TYPED_VECTOR (csTexelsVector,csPoly2D) texels;
  216. /// The vertices
  217. CS_DECLARE_TYPED_VECTOR (csVerticesVector,csPoly3D) vertices;
  218. /// The normals
  219. CS_DECLARE_TYPED_VECTOR (csNormalsVector,csPoly3D) normals;
  220. /**
  221. * Connectivity information for this sprite template.
  222. * Also contains temporary vertex position information
  223. * for one sprite (@@@this should be avoided!!!!)
  224. */
  225. csTriangleVertices2* tri_verts;
  226. /// The default mixing mode for new sprites
  227. int MixMode;
  228. /// If true then this factory has been initialized.
  229. bool initialized;
  230. public:
  231. iObjectRegistry* object_reg;
  232. public:
  233. /// Create the sprite template
  234. csSprite3DMeshObjectFactory (iBase *pParent);
  235. /// Destroy the template
  236. virtual ~csSprite3DMeshObjectFactory ();
  237. void Report (int severity, const char* msg, ...);
  238. /// Set the skeleton for this sprite template.
  239. void SetSkeleton (csSkel* sk);
  240. /// Get the skeleton for this sprite template.
  241. csSkel* GetSkeleton () const { return skeleton; }
  242. /// Get the 'emerge_from' array from which you can construct triangles.
  243. int* GetEmergeFrom () const { return emerge_from; }
  244. /// Enable or disable tweening frames (default false).
  245. void EnableTweening (bool en) { do_tweening = en; }
  246. /// Is tweening enabled?
  247. bool IsTweeningEnabled () const { return do_tweening; }
  248. /// Returns the lighting quality for this template.
  249. int GetLightingQuality() const { return lighting_quality; }
  250. /// Sets the lighting quality for this template. See CS_SPR_LIGHTING_* defs.
  251. void SetLightingQuality(int quality) {lighting_quality = quality; }
  252. /**
  253. * Sets which lighting config variable that all new sprites created
  254. * from this template will use.
  255. * The options are:
  256. * <ul>
  257. * <li>CS_SPR_LIGHT_GLOBAL (default)
  258. * <li>CS_SPR_LIGHT_TEMPLATE
  259. * <li>CS_SPR_LIGHT_LOCAL
  260. * </ul>
  261. */
  262. void SetLightingQualityConfig (int config_flag)
  263. { lighting_quality_config = config_flag; };
  264. /**
  265. * Returns what this template is using for determining the lighting quality.
  266. */
  267. int GetLightingQualityConfig () const
  268. { return lighting_quality_config; };
  269. /**
  270. * Sets which lod config variable that all new sprites created
  271. * from this template will use.
  272. * The options are:
  273. * <ul>
  274. * <li>CS_SPR_LOD_GLOBAL (default)
  275. * <li>CS_SPR_LOD_TEMPLATE
  276. * <li>CS_SPR_LOD_LOCAL
  277. * </ul>
  278. */
  279. void SetLodLevelConfig (int config_flag)
  280. { lod_level_config = config_flag; };
  281. /**
  282. * Returns what this template is using for determining the lighting quality.
  283. */
  284. int GetLodLevelConfig () const
  285. { return lod_level_config; };
  286. /**
  287. * Generate the collapse order.
  288. * This function will also reorder all the vertices in the template.
  289. * So be careful!
  290. */
  291. void GenerateLOD ();
  292. /**
  293. * Compute the object space bounding box and radius for all frames in this
  294. * template. This has to be called after setting up the template and before
  295. * using it.
  296. */
  297. void ComputeBoundingBox ();
  298. ///
  299. csTriangleMesh2* GetTexelMesh () const {return texel_mesh;}
  300. /// Add some vertices, normals, and texels
  301. void AddVertices (int num);
  302. /// Add a vertex, normal, and texel
  303. void AddVertex () { AddVertices (1); }
  304. /// Query the number of vertices.
  305. int GetVertexCount () const { return vertices.Get (0)->GetVertexCount (); }
  306. /// Get a texel.
  307. csVector2& GetTexel (int frame, int vertex) const
  308. { return (*texels.Get(frame)) [vertex]; }
  309. /// Get array of texels.
  310. csVector2* GetTexels (int frame) const
  311. { return (*texels.Get(frame)).GetVertices (); }
  312. /// Set texel array. The array is copied.
  313. void SetTexels(csVector2 const* tex, int frame)
  314. { (*texels.Get(frame)).SetVertices(tex, GetVertexCount ()); }
  315. /// Get a vertex.
  316. csVector3& GetVertex (int frame, int vertex) const
  317. { return (*vertices.Get(frame)) [vertex]; }
  318. /// Get vertex array.
  319. csVector3* GetVertices (int frame) const
  320. { return (*vertices.Get(frame)).GetVertices (); }
  321. /// Set vertex array. The array is copied.
  322. void SetVertices(csVector3 const* verts, int frame)
  323. { (*vertices.Get(frame)).SetVertices(verts, GetVertexCount ()); }
  324. /// Get a normal.
  325. csVector3& GetNormal (int frame, int vertex) const
  326. { return (*normals.Get(frame)) [vertex]; }
  327. /// Get normal array.
  328. csVector3* GetNormals (int frame) const
  329. { return (*normals.Get(frame)).GetVertices (); }
  330. /// Set normal array. The array is copied.
  331. void SetNormals(csVector3 const* norms, int frame)
  332. { (*normals.Get(frame)).SetVertices(norms, GetVertexCount ()); }
  333. /**
  334. * Add a triangle to the normal, texel, and vertex meshes
  335. * a, b and c are indices to texel vertices
  336. */
  337. void AddTriangle (int a, int b, int c);
  338. /// returns the texel indices for triangle 'x'
  339. csTriangle GetTriangle (int x) const { return texel_mesh->GetTriangle (x); }
  340. /// returns the triangles of the texel_mesh
  341. csTriangle* GetTriangles () const { return texel_mesh->GetTriangles (); }
  342. /// returns the number of triangles in the sprite
  343. int GetTriangleCount () const { return texel_mesh->GetTriangleCount (); }
  344. /// Size triangle buffer size
  345. void SetTriangleCount (int count) { texel_mesh->SetSize (count); }
  346. /// Set a bank of triangles. The bank is copied.
  347. void SetTriangles (csTriangle const* trig, int count)
  348. { texel_mesh->SetTriangles(trig, count); }
  349. /// Create and add a new frame to the sprite.
  350. csSpriteFrame* AddFrame ();
  351. /// find a named frame into the sprite.
  352. csSpriteFrame* FindFrame (const char * name);
  353. /// Query the number of frames
  354. int GetFrameCount () const { return frames.Length (); }
  355. /// Query the frame number f
  356. csSpriteFrame* GetFrame (int f) const
  357. {
  358. return (f < frames.Length ())
  359. ? (csSpriteFrame *)frames [f]
  360. : (csSpriteFrame*)NULL;
  361. }
  362. /// Create and add a new action frameset to the sprite.
  363. csSpriteAction2* AddAction ();
  364. /// find a named action into the sprite.
  365. csSpriteAction2* FindAction (const char * name) const;
  366. /// Get the first action.
  367. csSpriteAction2* GetFirstAction () const
  368. { return (csSpriteAction2 *)actions [0]; }
  369. /// Get number of actions in sprite
  370. int GetActionCount () const
  371. { return actions.Length (); }
  372. /// Get action number No
  373. csSpriteAction2* GetAction (int No) const
  374. { return (csSpriteAction2 *)actions [No]; }
  375. /// Get the material
  376. iMaterialWrapper* GetMaterial () const
  377. { return cstxt; }
  378. /// Get the material handle.
  379. iMaterialHandle* GetMaterialHandle () const
  380. { return cstxt->GetMaterialHandle (); }
  381. /// Set the material used for this sprite
  382. void SetMaterial (iMaterialWrapper *material);
  383. /**
  384. * Compute all normals in a frame.
  385. */
  386. void ComputeNormals (csSpriteFrame* frame);
  387. /**
  388. * Smooth out the gouraud shading by merging the precalculated
  389. * vertex normals along seams in frame 'frame' based on which
  390. * vertices are very close in frame 'base'
  391. */
  392. void MergeNormals (int base, int frame);
  393. /**
  394. * Smooth out the gouraud shading by merging the precalculated
  395. * vertex normals along seams in all frames based on which
  396. * vertices are very close in frame 'base'
  397. */
  398. void MergeNormals (int base);
  399. /**
  400. * Smooth out the gouraud shading by merging the precalculated
  401. * vertex normals along seams in all frames based on which
  402. * vertices are very close in each frame
  403. */
  404. void MergeNormals ();
  405. void SetMixMode (UInt mode)
  406. { MixMode = mode; }
  407. UInt GetMixMode () const
  408. { return MixMode; }
  409. /// For LOD.
  410. int GetLODPolygonCount (float lod) const;
  411. /// Default LOD level for this factory.
  412. float GetLodLevel () const { return lod_level; }
  413. //------------------------ iMeshObjectFactory implementation --------------
  414. SCF_DECLARE_IBASE;
  415. virtual iMeshObject* NewInstance ();
  416. virtual void HardTransform (const csReversibleTransform& t);
  417. virtual bool SupportsHardTransform () const { return true; }
  418. //--------------------- iSprite3DFactoryState implementation -------------//
  419. struct Sprite3DFactoryState : public iSprite3DFactoryState
  420. {
  421. SCF_DECLARE_EMBEDDED_IBASE (csSprite3DMeshObjectFactory);
  422. virtual void SetMaterialWrapper (iMaterialWrapper* material)
  423. {
  424. scfParent->SetMaterial (material);
  425. }
  426. virtual iMaterialWrapper* GetMaterialWrapper () const
  427. {
  428. return scfParent->GetMaterial ();
  429. }
  430. virtual void AddVertices (int num)
  431. {
  432. scfParent->AddVertices (num);
  433. }
  434. virtual int GetVertexCount () const
  435. {
  436. return scfParent->GetVertexCount ();
  437. }
  438. virtual const csVector3& GetVertex (int frame, int vertex) const
  439. {
  440. return scfParent->GetVertex (frame, vertex);
  441. }
  442. virtual void SetVertex (int frame, int vertex, const csVector3 &val)
  443. {
  444. scfParent->GetVertex (frame, vertex) = val;
  445. }
  446. virtual csVector3* GetVertices (int frame) const
  447. {
  448. return scfParent->GetVertices (frame);
  449. }
  450. virtual void SetVertices(csVector3 const* verts, int frame)
  451. {
  452. scfParent->SetVertices(verts, frame);
  453. }
  454. virtual const csVector2& GetTexel (int frame, int vertex) const
  455. {
  456. return scfParent->GetTexel (frame, vertex);
  457. }
  458. virtual void SetTexel (int frame, int vertex, const csVector2 &val)
  459. {
  460. scfParent->GetTexel (frame, vertex) = val;
  461. }
  462. virtual csVector2* GetTexels (int frame) const
  463. {
  464. return scfParent->GetTexels (frame);
  465. }
  466. virtual void SetTexels(csVector2 const* tex, int frame)
  467. {
  468. scfParent->SetTexels(tex, frame);
  469. }
  470. virtual const csVector3& GetNormal (int frame, int vertex) const
  471. {
  472. return scfParent->GetNormal (frame, vertex);
  473. }
  474. virtual void SetNormal (int frame, int vertex, const csVector3 &val)
  475. {
  476. scfParent->GetNormal (frame, vertex) = val;
  477. }
  478. virtual csVector3* GetNormals (int frame) const
  479. {
  480. return scfParent->GetNormals (frame);
  481. }
  482. virtual void SetNormals(csVector3 const* norms, int frame)
  483. {
  484. scfParent->SetNormals(norms, frame);
  485. }
  486. virtual void AddTriangle (int a, int b, int c)
  487. {
  488. scfParent->AddTriangle (a, b, c);
  489. }
  490. virtual csTriangle GetTriangle (int x) const
  491. {
  492. return scfParent->GetTriangle (x);
  493. }
  494. virtual csTriangle* GetTriangles () const
  495. {
  496. return scfParent->GetTriangles ();
  497. }
  498. virtual int GetTriangleCount () const
  499. {
  500. return scfParent->GetTriangleCount ();
  501. }
  502. virtual void SetTriangleCount( int count )
  503. {
  504. scfParent->SetTriangleCount(count);
  505. }
  506. virtual void SetTriangles( csTriangle const* trig, int count)
  507. {
  508. scfParent->SetTriangles(trig, count);
  509. }
  510. virtual iSpriteFrame* AddFrame ()
  511. {
  512. iSpriteFrame* ifr = SCF_QUERY_INTERFACE_SAFE (scfParent->AddFrame (),
  513. iSpriteFrame);
  514. if (ifr) ifr->DecRef ();
  515. return ifr;
  516. }
  517. virtual iSpriteFrame* FindFrame (const char* name) const
  518. {
  519. iSpriteFrame* ifr = SCF_QUERY_INTERFACE_SAFE (
  520. scfParent->FindFrame (name), iSpriteFrame);
  521. if (ifr) ifr->DecRef ();
  522. return ifr;
  523. }
  524. virtual int GetFrameCount () const
  525. {
  526. return scfParent->GetFrameCount ();
  527. }
  528. virtual iSpriteFrame* GetFrame (int f) const
  529. {
  530. iSpriteFrame* ifr = SCF_QUERY_INTERFACE_SAFE (scfParent->GetFrame (f),
  531. iSpriteFrame);
  532. if (ifr) ifr->DecRef ();
  533. return ifr;
  534. }
  535. virtual iSpriteAction* AddAction ()
  536. {
  537. iSpriteAction* ia = SCF_QUERY_INTERFACE_SAFE (scfParent->AddAction (),
  538. iSpriteAction);
  539. if (ia) ia->DecRef ();
  540. return ia;
  541. }
  542. virtual iSpriteAction* FindAction (const char* name) const
  543. {
  544. iSpriteAction* ia = SCF_QUERY_INTERFACE_SAFE (
  545. scfParent->FindAction (name), iSpriteAction);
  546. if (ia) ia->DecRef ();
  547. return ia;
  548. }
  549. virtual iSpriteAction* GetFirstAction () const
  550. {
  551. iSpriteAction* ia = SCF_QUERY_INTERFACE_SAFE (
  552. scfParent->GetFirstAction (), iSpriteAction);
  553. if (ia) ia->DecRef ();
  554. return ia;
  555. }
  556. virtual int GetActionCount () const
  557. {
  558. return scfParent->GetActionCount ();
  559. }
  560. virtual iSpriteAction* GetAction (int No) const
  561. {
  562. iSpriteAction* ia = SCF_QUERY_INTERFACE_SAFE (scfParent->GetAction (No),
  563. iSpriteAction);
  564. if (ia) ia->DecRef ();
  565. return ia;
  566. }
  567. virtual void EnableSkeletalAnimation ();
  568. virtual iSkeleton* GetSkeleton () const;
  569. virtual void EnableTweening (bool en)
  570. {
  571. scfParent->EnableTweening (en);
  572. }
  573. virtual bool IsTweeningEnabled () const
  574. {
  575. return scfParent->IsTweeningEnabled ();
  576. }
  577. virtual void SetLightingQuality (int qual)
  578. {
  579. scfParent->SetLightingQuality (qual);
  580. }
  581. virtual int GetLightingQuality () const
  582. {
  583. return scfParent->GetLightingQuality ();
  584. }
  585. virtual void SetLightingQualityConfig (int qual)
  586. {
  587. scfParent->SetLightingQualityConfig (qual);
  588. }
  589. virtual int GetLightingQualityConfig () const
  590. {
  591. return scfParent->GetLightingQualityConfig ();
  592. }
  593. virtual void SetLodLevelConfig (int config_flag)
  594. {
  595. scfParent->SetLodLevelConfig (config_flag);
  596. }
  597. virtual int GetLodLevelConfig () const
  598. {
  599. return scfParent->GetLodLevelConfig ();
  600. }
  601. virtual void MergeNormals (int base, int frame)
  602. {
  603. scfParent->MergeNormals (base, frame);
  604. }
  605. virtual void MergeNormals (int base)
  606. {
  607. scfParent->MergeNormals (base);
  608. }
  609. virtual void MergeNormals ()
  610. {
  611. scfParent->MergeNormals ();
  612. }
  613. virtual void SetMixMode (UInt mode)
  614. { scfParent->SetMixMode (mode); }
  615. virtual UInt GetMixMode () const
  616. { return scfParent->GetMixMode (); }
  617. } scfiSprite3DFactoryState;
  618. //--------------------- iLODControl implementation -------------//
  619. struct LODControl : public iLODControl
  620. {
  621. SCF_DECLARE_EMBEDDED_IBASE (csSprite3DMeshObjectFactory);
  622. virtual uint32 GetLODFeatures () const
  623. {
  624. return scfParent->current_features;
  625. }
  626. virtual void SetLODFeatures (uint32 mask, uint32 value)
  627. {
  628. mask &= ALL_LOD_FEATURES;
  629. scfParent->current_features = (scfParent->current_features & ~mask)
  630. | (value & mask);
  631. }
  632. virtual void SetLOD (float lod) { scfParent->lod_level = lod; }
  633. virtual float GetLOD () const { return scfParent->lod_level; }
  634. virtual int GetLODPolygonCount (float lod) const
  635. {
  636. return scfParent->GetLODPolygonCount (lod);
  637. }
  638. virtual uint32 GetAvailableLODFeatures () const
  639. {
  640. return ALL_LOD_FEATURES;
  641. }
  642. virtual uint32 GetAvailableDistanceFeatures () const
  643. {
  644. return CS_LOD_TRIANGLE_REDUCTION;
  645. }
  646. virtual uint32 GetDistanceReduction () const
  647. {
  648. return CS_LOD_TRIANGLE_REDUCTION;
  649. }
  650. virtual void SetDistanceReduction (uint32 mask, uint32 value)
  651. {
  652. (void)mask; (void)value;
  653. // @@@ TODO
  654. }
  655. virtual void SetLODPriority (uint16 group)
  656. {
  657. (void)group;
  658. // @@@ TODO
  659. }
  660. virtual uint16 GetLODPriority () const
  661. {
  662. return 0;
  663. }
  664. virtual void SetMinLODThreshold (float level, bool turnOff)
  665. {
  666. (void)level; (void)turnOff;
  667. // @@@ TODO
  668. }
  669. } scfiLODControl;
  670. friend struct LODControl;
  671. };
  672. /**
  673. * A 3D sprite based on a triangle mesh with a single texture.
  674. * Animation is done with frames (a frame may be controlled by
  675. * a skeleton).
  676. */
  677. class csSprite3DMeshObject : public iMeshObject
  678. {
  679. private:
  680. /// Set the size of internally used tables
  681. static void UpdateWorkTables (int max_size);
  682. public:
  683. /**
  684. * Configuration value for global LOD. 0 is lowest detail, 1 is maximum.
  685. * If 1 then the base mesh is used and no LOD reduction/computation
  686. * is done.
  687. */
  688. static float global_lod_level;
  689. private:
  690. /**
  691. * Used to determine where to look for the lod detail level.
  692. * The possible values are:
  693. * <ul>
  694. * <li>CS_SPR_LOD_GLOBAL (default)
  695. * <li>CS_SPR_LOD_TEMPLATE
  696. * <li>CS_SPR_LOD_LOCAL
  697. * </ul>
  698. */
  699. int lod_level_config;
  700. /**
  701. * Configuration value for an individuals LOD. 0 is lowest detail,
  702. * 1 is maximum. If 1 then the base mesh is used and no LOD
  703. * reduction/computation is done.
  704. */
  705. float local_lod_level;
  706. /**
  707. * Quality setting for sprite lighting.
  708. * See the CS_SPR_LIGHTING_* macros defined in this header file for the
  709. * different types of lighting. This is the local setting. It overrides the
  710. * template, and global lighting settings.
  711. */
  712. int local_lighting_quality;
  713. /**
  714. * Used to determine where to look for the quality setting of the lighting.
  715. * The possible values are:
  716. * <ul>
  717. * <li>CS_SPR_LIGHT_GLOBAL (default)
  718. * <li>CS_SPR_LIGHT_TEMPLATE
  719. * <li>CS_SPR_LIGHT_LOCAL
  720. * </ul>
  721. */
  722. int lighting_quality_config;
  723. uint32 current_features;
  724. public:
  725. /**
  726. * Quality setting for sprite lighting.
  727. * See the CS_SPR_LIGHTING_* macros defined in this header file for the
  728. * different types of lighting. This is the global setting that is used for
  729. * all csSprite3Ds(unless the template or the individual sprite overrides
  730. * it).
  731. */
  732. static int global_lighting_quality;
  733. /**
  734. * Returns the lighting quality level used by this sprite.
  735. * See SPT_LIGHTING_* macros defined in this header for the different types
  736. * of lighting.
  737. */
  738. int GetLightingQuality ()
  739. {
  740. switch (lighting_quality_config)
  741. {
  742. case CS_SPR_LIGHT_GLOBAL: return global_lighting_quality; break;
  743. case CS_SPR_LIGHT_TEMPLATE: return factory->GetLightingQuality(); break;
  744. case CS_SPR_LIGHT_LOCAL: return local_lighting_quality; break;
  745. default:
  746. {
  747. lighting_quality_config = factory->GetLightingQualityConfig();
  748. return factory->GetLightingQuality();
  749. }
  750. }
  751. }
  752. /**
  753. * Sets the local lighting quality for this sprite. NOTE: you must use
  754. * SetLightingQualityConfig (CS_SPR_LIGHT_LOCAL) for the sprite to use this.
  755. */
  756. void SetLocalLightingQuality(int lighting_quality)
  757. { local_lighting_quality = lighting_quality; }
  758. /**
  759. * Sets the global lighting quality for all csSprite3Ds.
  760. * NOTE: You must use SetLightingQualityConfig(CS_SPR_LIGHT_GLOBAL) for the
  761. * sprite to use this.
  762. */
  763. void SetGlobalLightingQuality (int lighting_quality)
  764. { global_lighting_quality = lighting_quality; }
  765. /**
  766. * Sets which lighting config variable this sprite will use.
  767. * The options are:
  768. * <ul>
  769. * <li>CS_SPR_LIGHT_GLOBAL (default)
  770. * <li>CS_SPR_LIGHT_TEMPLATE
  771. * <li>CS_SPR_LIGHT_LOCAL
  772. * </ul>
  773. */
  774. void SetLightingQualityConfig (int config_flag)
  775. { lighting_quality_config = config_flag; }
  776. /**
  777. * Returns what this sprite is using for determining the lighting quality.
  778. */
  779. int GetLightingQualityConfig () const
  780. { return lighting_quality_config; }
  781. /**
  782. * Returns the lod level used by this sprite.
  783. */
  784. float GetLodLevel () const
  785. {
  786. switch (lod_level_config)
  787. {
  788. case CS_SPR_LOD_GLOBAL: return global_lod_level; break;
  789. case CS_SPR_LOD_TEMPLATE: return factory->GetLodLevel(); break;
  790. case CS_SPR_LOD_LOCAL: return local_lod_level; break;
  791. default:
  792. return factory->GetLodLevel();
  793. }
  794. }
  795. /**
  796. * Sets the local lod level for this sprite. NOTE: you must use
  797. * SetLodLevelConfig (CS_SPR_LOD_LOCAL) for the sprite to use this.
  798. */
  799. void SetLocalLodLevel (float lod_level)
  800. { local_lod_level = lod_level; }
  801. /**
  802. * Sets the global lod level for all csSprite3Ds. NOTE: you must use
  803. * SetLodLevelConfig(CS_SPR_LOD_GLOBAL) for the sprite to use this.
  804. */
  805. void SetGlobalLodLevel (float lod_level)
  806. { global_lod_level = lod_level; }
  807. /**
  808. * Sets which lighting config variable this sprite will use.
  809. * The options are:
  810. * <ul>
  811. * <li>CS_SPR_LOD_GLOBAL (default)
  812. * <li>CS_SPR_LOD_TEMPLATE
  813. * <li>CS_SPR_LOD_LOCAL
  814. * </ul>
  815. */
  816. void SetLodLevelConfig (int config_flag)
  817. { lod_level_config = config_flag; }
  818. /**
  819. * Returns what this sprite is using for determining the lighting quality.
  820. */
  821. int GetLodLevelConfig () const
  822. { return lod_level_config; }
  823. /**
  824. * GetVertexToLightCount returns the number of vertices to light based on LOD.
  825. */
  826. int GetVertexToLightCount ();
  827. private:
  828. /**
  829. * num_verts_for_lod represents the number of lights that are used by lod.
  830. * If -1 means that it is not used.
  831. */
  832. int num_verts_for_lod;
  833. /**
  834. * A mesh which contains a number of triangles as generated
  835. * by the LOD algorithm. This is static since it will likely
  836. * change every frame anyway. We hold it static also since
  837. * we don't want to allocate it again every time.
  838. */
  839. static csTriangleMesh2 mesh;
  840. /// Mixmode for the triangles/polygons of the sprite.
  841. UInt MixMode;
  842. /**
  843. * Array of colors for the vertices. If not set then this
  844. * sprite does not have colored vertices.
  845. */
  846. csColor* vertex_colors;
  847. /**
  848. * Base color that will be added to the sprite colors.
  849. */
  850. csColor base_color;
  851. /// The parent.
  852. csSprite3DMeshObjectFactory* factory;
  853. /// The material handle as returned by iTextureManager.
  854. iMaterialWrapper* cstxt;
  855. /// The current frame number.
  856. int cur_frame;
  857. /// The current action.
  858. csSpriteAction2* cur_action;
  859. /// The last frame time action.
  860. csTicks last_time;
  861. /// Animation tweening ratio: next frame / this frame.
  862. float tween_ratio;
  863. /// Enable tweening.
  864. bool do_tweening;
  865. /// Enable or disable lighting.
  866. bool do_lighting;
  867. ///
  868. bool force_otherskin;
  869. /// Skeleton state (optional).
  870. csSkelState* skeleton_state;
  871. iMeshObjectDrawCallback* vis_cb;
  872. long shapenr;
  873. /**
  874. * Camera space bounding box is cached here.
  875. * GetCameraBoundingBox() will check the current camera number
  876. * to see if it needs to recalculate this.
  877. */
  878. csBox3 camera_bbox;
  879. /// Current camera number.
  880. long cur_cameranr;
  881. /// Current movable number.
  882. long cur_movablenr;
  883. // Remembered info between DrawTest and Draw.
  884. G3DTriangleMesh g3dmesh;
  885. bool initialized;
  886. /**
  887. * Our vertex buffer.
  888. * This is only temporarily here. I suppose it is better to
  889. * origanize this so that the vertex buffer is shared accross several
  890. * sprites using the same factory. On the other hand there are lots
  891. * of frames. Do we create a vertex buffer for every frame?
  892. * @@@
  893. */
  894. iVertexBufferManager* vbufmgr;
  895. iVertexBuffer* vbuf;
  896. /// Vertex buffer for tweening.
  897. iVertexBuffer* vbuf_tween;
  898. /// Data for vertex buffer (initialize by DrawTest, needed by Draw).
  899. csVector3* vbuf_verts, * vbuf_tween_verts;
  900. csVector2* vbuf_texels, * vbuf_tween_texels;
  901. csColor* vbuf_colors, * vbuf_tween_colors;
  902. int vbuf_num_vertices;
  903. /// Setup this object.
  904. void SetupObject ();
  905. /// interface to receive state of vertexbuffermanager
  906. struct eiVertexBufferManagerClient : public iVertexBufferManagerClient
  907. {
  908. SCF_DECLARE_EMBEDDED_IBASE (csSprite3DMeshObject);
  909. virtual void ManagerClosing ();
  910. }scfiVertexBufferManagerClient;
  911. friend struct eiVertexBufferManagerClient;
  912. private:
  913. /**
  914. * High quality version of UpdateLighting() which recalculates
  915. * the distance between the light and every vertex.
  916. * This version can use tweening of the normals and vertices
  917. */
  918. void UpdateLightingHQ (iLight** lights, int num_lights, iMovable* movable);
  919. /**
  920. * Low quality version of UpdateLighting() which only
  921. * calculates the distance once (from the center of the sprite.)
  922. * This method can use tweening of the normals.
  923. */
  924. void UpdateLightingLQ (iLight** lights, int num_lights, iMovable* movable);
  925. /**
  926. * Low quality Fast version of UpdateLighting() which only
  927. * calculates the distance once (from the center of the sprite.)
  928. * This version can NOT use any tweening.
  929. */
  930. void UpdateLightingFast (iLight** lights, int num_lights, iMovable* movable);
  931. /**
  932. * A fairly fast :P totally inaccurate(usually) lighting method.
  933. * Intended for use for things like powerups.
  934. */
  935. void UpdateLightingRandom ();
  936. /// random number generator used for random lighting.
  937. csRandomGen *rand_num;
  938. public:
  939. /// Constructor.
  940. csSprite3DMeshObject ();
  941. /// Destructor.
  942. virtual ~csSprite3DMeshObject ();
  943. /// Set the factory.
  944. void SetFactory (csSprite3DMeshObjectFactory* factory);
  945. /// Get the factory.
  946. csSprite3DMeshObjectFactory* GetFactory3D () const { return factory; }
  947. /// Get the skeleton state for this sprite.
  948. csSkelState* GetSkeletonState () const { return skeleton_state; }
  949. /// Force a new material skin other than default
  950. void SetMaterial (iMaterialWrapper *material);
  951. /// Get the material for this sprite.
  952. iMaterialWrapper* GetMaterial () const { return cstxt; }
  953. /// Sets the mode that is used, when drawing that sprite.
  954. void SetMixMode (UInt m) { MixMode = m; }
  955. /// Gets the mode that is used, when drawing that sprite.
  956. UInt GetMixMode () const { return MixMode; }
  957. /// Enable or disable tweening frames (default false).
  958. void EnableTweening (bool en) { do_tweening = en; }
  959. /// Is tweening enabled?
  960. bool IsTweeningEnabled () const { return do_tweening; }
  961. /// Set lighting.
  962. void SetLighting (bool l)
  963. {
  964. do_lighting = l;
  965. ResetVertexColors ();
  966. }
  967. /// Is lighting enabled?
  968. bool IsLighting () const
  969. {
  970. return do_lighting;
  971. }
  972. /// Set base color.
  973. void SetBaseColor (const csColor& col)
  974. {
  975. delete[] vertex_colors;
  976. vertex_colors = NULL;
  977. base_color = col;
  978. ResetVertexColors ();
  979. }
  980. /// Get base color.
  981. void GetBaseColor (csColor& col) const
  982. {
  983. col = base_color;
  984. }
  985. /**
  986. * Add a color for a vertex.
  987. * As soon as you use this function this sprite will be rendered
  988. * using gouraud shading. Calling this function for the first time
  989. * will initialize all colors to black.
  990. */
  991. void AddVertexColor (int i, const csColor& col);
  992. /**
  993. * Reset the color list. If you call this function then the
  994. * sprite will no longer use gouraud shading.
  995. */
  996. void ResetVertexColors ();
  997. /**
  998. * Clamp all vertice colors to 2.0. This is called inside
  999. * csSprite3D::UpdateLighting() so that 3D renderer doesn't have
  1000. * to deal with brightness lighter than 2.0
  1001. */
  1002. void FixVertexColors ();
  1003. /// Unset the texture.
  1004. void UnsetTexture ()
  1005. { force_otherskin = false; }
  1006. /**
  1007. * Fill the static mesh with the current sprite
  1008. * for a given LOD level.
  1009. */
  1010. void GenerateSpriteLOD (int num_vts);
  1011. /**
  1012. * Go to the next frame depending on the current time in milliseconds.
  1013. */
  1014. bool OldNextFrame (csTicks current_time, bool onestep = false,
  1015. bool stoptoend = false);
  1016. /**
  1017. * Go to a specified frame.
  1018. */
  1019. void SetFrame (int f)
  1020. {
  1021. if (cur_action && f < cur_action->GetFrameCount ()) cur_frame = f;
  1022. //@@@!!! WHAT DO WE DO HERE!!! UpdateInPolygonTrees ();
  1023. }
  1024. /**
  1025. * Get the current frame number.
  1026. */
  1027. int GetCurFrame () const { return cur_frame; }
  1028. /**
  1029. * Get the current frame number.
  1030. */
  1031. csSpriteAction2* GetCurAction () const { return cur_action; }
  1032. /**
  1033. * Get the number of frames.
  1034. */
  1035. int GetFrameCount () const { return cur_action->GetFrameCount (); }
  1036. /**
  1037. * Select an action.
  1038. */
  1039. bool SetAction (const char * name)
  1040. {
  1041. csSpriteAction2 *act;
  1042. if ((act = factory->FindAction (name)) != NULL)
  1043. {
  1044. cur_action = act;
  1045. SetFrame (0);
  1046. return true;
  1047. }
  1048. return false;
  1049. }
  1050. /**
  1051. * Initialize a sprite. This function is called automatically
  1052. * from within 'load'. However you should call it directly
  1053. * if you created the sprite on the fly (without 'load').
  1054. */
  1055. void InitSprite ();
  1056. /**
  1057. * Get an array of object vertices which is valid for the given frame.
  1058. * This function correcty acounts for sprites which use skeletons. In
  1059. * that case it will use the current transformation state of the skeleton
  1060. * to compute object space vertices.<br>
  1061. * Warning! The returned array should be used immediatelly or copied. It
  1062. * points to a private static array in the sprite class and can be reused
  1063. * if other calls to the sprite happen.
  1064. */
  1065. csVector3* GetObjectVerts (csSpriteFrame* fr);
  1066. /// Get the bounding box in transformed space.
  1067. void GetTransformedBoundingBox (long cameranr, long movablenr,
  1068. const csReversibleTransform& trans, csBox3& cbox);
  1069. /**
  1070. * Get the coordinates of the sprite in screen coordinates.
  1071. * Fills in the boundingBox with the X and Y locations of the cube.
  1072. * Returns the max Z location of the sprite, or -1 if not
  1073. * on-screen. If the sprite is not on-screen, the X and Y values are not
  1074. * valid.
  1075. */
  1076. float GetScreenBoundingBox (long cameranr, long movablenr,
  1077. float fov, float sx, float sy,
  1078. const csReversibleTransform& trans, csBox2& sbox, csBox3& cbox);
  1079. /// For LOD.
  1080. int GetLODPolygonCount (float lod) const;
  1081. ///------------------------ iMeshObject implementation ----------------------
  1082. SCF_DECLARE_IBASE;
  1083. virtual iMeshObjectFactory* GetFactory () const
  1084. {
  1085. iMeshObjectFactory* ifact = SCF_QUERY_INTERFACE (factory,
  1086. iMeshObjectFactory);
  1087. ifact->DecRef ();
  1088. return ifact;
  1089. }
  1090. virtual bool DrawTest (iRenderView* rview, iMovable* movable);
  1091. virtual void UpdateLighting (iLight** lights, int num_lights,
  1092. iMovable* movable);
  1093. virtual bool Draw (iRenderView* rview, iMovable* movable, csZBufMode mode);
  1094. virtual void SetVisibleCallback (iMeshObjectDrawCallback* cb)
  1095. {
  1096. if (cb) cb->IncRef ();
  1097. if (vis_cb) vis_cb->DecRef ();
  1098. vis_cb = cb;
  1099. }
  1100. virtual iMeshObjectDrawCallback* GetVisibleCallback () const
  1101. {
  1102. return vis_cb;
  1103. }
  1104. virtual void GetObjectBoundingBox (csBox3& bbox, int type = CS_BBOX_NORMAL);
  1105. virtual void GetRadius (csVector3& rad, csVector3 &cent);
  1106. virtual void NextFrame (csTicks current_time)
  1107. {
  1108. OldNextFrame (current_time);
  1109. }
  1110. virtual bool WantToDie () const { return false; }
  1111. virtual void HardTransform (const csReversibleTransform&) { }
  1112. virtual bool SupportsHardTransform () const { return false; }
  1113. virtual bool HitBeamOutline (const csVector3& start, const csVector3& end,
  1114. csVector3& intersect, float* pr);
  1115. virtual bool HitBeamObject (const csVector3& start, const csVector3& end,
  1116. csVector3& intersect, float* pr);
  1117. virtual long GetShapeNumber () const { return shapenr; }
  1118. //------------------ iPolygonMesh interface implementation ----------------//
  1119. struct PolyMesh : public iPolygonMesh
  1120. {
  1121. SCF_DECLARE_EMBEDDED_IBASE (csSprite3DMeshObject);
  1122. /// Get the number of vertices for this mesh.
  1123. virtual int GetVertexCount ()
  1124. {
  1125. csSprite3DMeshObjectFactory* fact = scfParent->GetFactory3D ();
  1126. return fact->GetVertexCount ();
  1127. }
  1128. /// Get the pointer to the array of vertices.
  1129. virtual csVector3* GetVertices ()
  1130. {
  1131. csSprite3DMeshObjectFactory* fact = scfParent->GetFactory3D ();
  1132. return fact->GetVertices (0);
  1133. }
  1134. /// Get the number of polygons for this mesh.
  1135. virtual int GetPolygonCount ()
  1136. {
  1137. csSprite3DMeshObjectFactory* fact = scfParent->GetFactory3D ();
  1138. return fact->GetTriangleCount ();
  1139. }
  1140. /// Get the pointer to the array of polygons.
  1141. virtual csMeshedPolygon* GetPolygons ();
  1142. /// Cleanup.
  1143. virtual void Cleanup () { delete[] polygons; polygons = NULL; }
  1144. PolyMesh () : polygons (NULL) { }
  1145. virtual ~PolyMesh () { Cleanup (); }
  1146. csMeshedPolygon* polygons;
  1147. } scfiPolygonMesh;
  1148. friend struct PolyMesh;
  1149. //--------------------- iSprite3DState implementation -------------//
  1150. struct Sprite3DState : public iSprite3DState
  1151. {
  1152. SCF_DECLARE_EMBEDDED_IBASE (csSprite3DMeshObject);
  1153. virtual void SetMaterialWrapper (iMaterialWrapper* material)
  1154. {
  1155. scfParent->SetMaterial (material);
  1156. }
  1157. virtual iMaterialWrapper* GetMaterialWrapper () const
  1158. {
  1159. return scfParent->GetMaterial ();
  1160. }
  1161. virtual void SetMixMode (UInt mode)
  1162. {
  1163. scfParent->SetMixMode (mode);
  1164. }
  1165. virtual UInt GetMixMode () const
  1166. {
  1167. return scfParent->GetMixMode ();
  1168. }
  1169. virtual void SetLighting (bool l)
  1170. {
  1171. scfParent->SetLighting (l);
  1172. }
  1173. virtual bool IsLighting () const
  1174. {
  1175. return scfParent->IsLighting ();
  1176. }
  1177. virtual iSkeletonState* GetSkeletonState () const;
  1178. virtual void SetFrame (int f)
  1179. {
  1180. scfParent->SetFrame (f);
  1181. }
  1182. virtual int GetCurFrame () const
  1183. {
  1184. return scfParent->GetCurFrame ();
  1185. }
  1186. virtual int GetFrameCount () const
  1187. {
  1188. return scfParent->GetFrameCount ();
  1189. }
  1190. virtual bool SetAction (const char * name)
  1191. {
  1192. return scfParent->SetAction (name);
  1193. }
  1194. virtual iSpriteAction* GetCurAction () const
  1195. {
  1196. iSpriteAction* ia = SCF_QUERY_INTERFACE_SAFE (scfParent->GetCurAction (),
  1197. iSpriteAction);
  1198. if (ia) ia->DecRef ();
  1199. return ia;
  1200. }
  1201. virtual void EnableTweening (bool en)
  1202. {
  1203. scfParent->EnableTweening (en);
  1204. }
  1205. virtual bool IsTweeningEnabled () const
  1206. {
  1207. return scfParent->IsTweeningEnabled ();
  1208. }
  1209. virtual void UnsetTexture ()
  1210. {
  1211. scfParent->UnsetTexture ();
  1212. }
  1213. virtual int GetLightingQuality ()
  1214. {
  1215. return scfParent->GetLightingQuality ();
  1216. }
  1217. virtual void SetLocalLightingQuality (int lighting_quality)
  1218. {
  1219. scfParent->SetLocalLightingQuality (lighting_quality);
  1220. }
  1221. virtual void SetLightingQualityConfig (int config_flag)
  1222. {
  1223. scfParent->SetLightingQualityConfig (config_flag);
  1224. }
  1225. virtual int GetLightingQualityConfig () const
  1226. {
  1227. return scfParent->GetLightingQualityConfig ();
  1228. }
  1229. virtual void SetLodLevelConfig (int config_flag)
  1230. {
  1231. scfParent->SetLodLevelConfig (config_flag);
  1232. }
  1233. virtual int GetLodLevelConfig () const
  1234. {
  1235. return scfParent->GetLodLevelConfig ();
  1236. }
  1237. virtual bool IsLodEnabled () const
  1238. {
  1239. return scfParent->GetLodLevel () < .99;
  1240. }
  1241. virtual void SetBaseColor (const csColor& col)
  1242. {
  1243. scfParent->SetBaseColor (col);
  1244. }
  1245. virtual void GetBaseColor (csColor& col) const
  1246. {
  1247. scfParent->GetBaseColor (col);
  1248. }
  1249. } scfiSprite3DState;
  1250. //--------------------- iLODControl implementation -------------//
  1251. struct LODControl : public iLODControl
  1252. {
  1253. SCF_DECLARE_EMBEDDED_IBASE (csSprite3DMeshObject);
  1254. virtual uint32 GetLODFeatures () const
  1255. {
  1256. return scfParent->current_features;
  1257. }
  1258. virtual void SetLODFeatures (uint32 mask, uint32 value)
  1259. {
  1260. mask &= ALL_LOD_FEATURES;
  1261. scfParent->current_features = (scfParent->current_features & ~mask)
  1262. | (value & mask);
  1263. }
  1264. virtual void SetLOD (float lod) { scfParent->local_lod_level = lod; }
  1265. virtual float GetLOD () const { return scfParent->local_lod_level; }
  1266. virtual int GetLODPolygonCount (float lod) const
  1267. {
  1268. return scfParent->GetLODPolygonCount (lod);
  1269. }
  1270. virtual uint32 GetAvailableLODFeatures () const
  1271. {
  1272. return ALL_LOD_FEATURES;
  1273. }
  1274. virtual uint32 GetAvailableDistanceFeatures () const
  1275. {
  1276. return CS_LOD_TRIANGLE_REDUCTION;
  1277. }
  1278. virtual uint32 GetDistanceReduction () const
  1279. {
  1280. return CS_LOD_TRIANGLE_REDUCTION;
  1281. }
  1282. virtual void SetDistanceReduction (uint32 mask, uint32 value)
  1283. {
  1284. (void)mask; (void)value;
  1285. // @@@ TODO
  1286. }
  1287. virtual void SetLODPriority (uint16 group)
  1288. {
  1289. (void)group;
  1290. // @@@ TODO
  1291. }
  1292. virtual uint16 GetLODPriority () const
  1293. {
  1294. return 0;
  1295. }
  1296. virtual void SetMinLODThreshold (float level, bool turnOff)
  1297. {
  1298. (void)level; (void)turnOff;
  1299. // @@@ TODO
  1300. }
  1301. } scfiLODControl;
  1302. friend struct LODControl;
  1303. };
  1304. /**
  1305. * Sprite 3D type. This is the plugin you have to use to create instances
  1306. * of csSprite3DMeshObjectFactory.
  1307. */
  1308. class csSprite3DMeshObjectType : public iMeshObjectType
  1309. {
  1310. private:
  1311. iObjectRegistry* object_reg;
  1312. public:
  1313. /// Constructor.
  1314. csSprite3DMeshObjectType (iBase*);
  1315. /// Destructor.
  1316. virtual ~csSprite3DMeshObjectType ();
  1317. //------------------------ iMeshObjectType implementation --------------
  1318. SCF_DECLARE_IBASE;
  1319. /// New Factory.
  1320. virtual iMeshObjectFactory* NewFactory ();
  1321. //------------------- iConfig interface implementation -------------------
  1322. struct csSprite3DConfig : public iConfig
  1323. {
  1324. SCF_DECLARE_EMBEDDED_IBASE (csSprite3DMeshObjectType);
  1325. virtual bool GetOptionDescription (int idx, csOptionDescription *option);
  1326. virtual bool SetOption (int id, csVariant* value);
  1327. virtual bool GetOption (int id, csVariant* value);
  1328. } scfiConfig;
  1329. friend struct csSprite3DConfig;
  1330. //--------------------- iComponent interface implementation
  1331. struct eiComponent : public iComponent
  1332. {
  1333. SCF_DECLARE_EMBEDDED_IBASE(csSprite3DMeshObjectType);
  1334. virtual bool Initialize (iObjectRegistry* p)
  1335. { scfParent->object_reg = p; return true; }
  1336. } scfiComponent;
  1337. friend struct eiComponent;
  1338. //--------------------- iLODControl implementation -------------//
  1339. struct LODControl : public iLODControl
  1340. {
  1341. SCF_DECLARE_EMBEDDED_IBASE (csSprite3DMeshObjectType);
  1342. virtual uint32 GetLODFeatures () const
  1343. {
  1344. return ALL_LOD_FEATURES;
  1345. }
  1346. virtual void SetLODFeatures (uint32 mask, uint32 value)
  1347. {
  1348. (void)mask; (void)value;
  1349. // @@@ TODO
  1350. }
  1351. virtual void SetLOD (float lod)
  1352. {
  1353. csSprite3DMeshObject::global_lod_level = lod;
  1354. }
  1355. virtual float GetLOD () const
  1356. {
  1357. return csSprite3DMeshObject::global_lod_level;
  1358. }
  1359. virtual int GetLODPolygonCount (float /*lod*/) const
  1360. {
  1361. return 0;
  1362. }
  1363. virtual uint32 GetAvailableLODFeatures () const
  1364. {
  1365. return ALL_LOD_FEATURES;
  1366. }
  1367. virtual uint32 GetAvailableDistanceFeatures () const
  1368. {
  1369. return CS_LOD_TRIANGLE_REDUCTION;
  1370. }
  1371. virtual uint32 GetDistanceReduction () const
  1372. {
  1373. return CS_LOD_TRIANGLE_REDUCTION;
  1374. }
  1375. virtual void SetDistanceReduction (uint32 mask, uint32 value)
  1376. {
  1377. (void)mask; (void)value;
  1378. // @@@ TODO
  1379. }
  1380. virtual void SetLODPriority (uint16 group)
  1381. {
  1382. (void)group;
  1383. // @@@ TODO
  1384. }
  1385. virtual uint16 GetLODPriority () const
  1386. {
  1387. return 0;
  1388. }
  1389. virtual void SetMinLODThreshold (float level, bool turnOff)
  1390. {
  1391. (void)level; (void)turnOff;
  1392. // @@@ TODO
  1393. }
  1394. } scfiLODControl;
  1395. friend struct LODControl;
  1396. };
  1397. #endif // __CS_SPR3D_H__