PageRenderTime 56ms CodeModel.GetById 17ms RepoModel.GetById 0ms app.codeStats 0ms

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

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