PageRenderTime 31ms CodeModel.GetById 8ms RepoModel.GetById 6ms app.codeStats 0ms

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

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