PolySceneMesh.h 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  1. /*
  2. Copyright (C) 2011 by Ivan Safrin
  3. Permission is hereby granted, free of charge, to any person obtaining a copy
  4. of this software and associated documentation files (the "Software"), to deal
  5. in the Software without restriction, including without limitation the rights
  6. to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  7. copies of the Software, and to permit persons to whom the Software is
  8. furnished to do so, subject to the following conditions:
  9. The above copyright notice and this permission notice shall be included in
  10. all copies or substantial portions of the Software.
  11. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  12. IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  13. FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  14. AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  15. LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  16. OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  17. THE SOFTWARE.
  18. */
  19. #pragma once
  20. #include "PolyGlobals.h"
  21. #include "PolyEntity.h"
  22. #include "PolyShader.h"
  23. namespace Polycode {
  24. class Material;
  25. class Mesh;
  26. class Texture;
  27. class Skeleton;
  28. class Image;
  29. /**
  30. * 3D polygonal mesh instance. The SceneMesh is the base for all polygonal 3d geometry. It can have simple textures or complex materials applied to it.
  31. */
  32. class _PolyExport SceneMesh : public Entity {
  33. public:
  34. /**
  35. * Construct a scene mesh from a mesh file.
  36. * @param fileName Path to mesh file to load.
  37. */
  38. SceneMesh(const String& fileName);
  39. /**
  40. * Construct an empty scene mesh with the specified type.
  41. * @param meshType Mesh type to create. See Mesh for possible values.
  42. */
  43. SceneMesh(int meshType);
  44. /**
  45. * Construct scene mesh from an existing Mesh instance.
  46. */
  47. SceneMesh(Mesh *mesh);
  48. /**
  49. * Construct scene mesh from an existing Mesh instance.
  50. */
  51. static SceneMesh *SceneMeshFromMesh(Mesh *mesh);
  52. /**
  53. * Construct an empty scene mesh with the specified type.
  54. * @param meshType Mesh type to create. See Mesh for possible values.
  55. */
  56. static SceneMesh *SceneMeshWithType(int meshType);
  57. virtual ~SceneMesh();
  58. void Render();
  59. ShaderBinding *getLocalShaderOptions();
  60. /**
  61. * Returns the Mesh instance of the actual mesh.
  62. */
  63. Mesh *getMesh();
  64. /**
  65. * Returns the texture applied.
  66. */
  67. Texture *getTexture() const;
  68. /**
  69. * Returns the material applied.
  70. */
  71. Material *getMaterial();
  72. /**
  73. * Loads a simple texture from a file name and applies it to the mesh.
  74. * @param fileName Filename to load the mesh from.
  75. * @param clamp If true, clamps the texture to edges. See Texture for details on that.
  76. */
  77. void loadTexture(const String& fileName);
  78. void loadTextureFromImage(Image *image);
  79. /**
  80. * Loads a skeleton from a file and applies it to the scene mesh.
  81. * @param fileName Filename to load the skeleton from.
  82. */
  83. void loadSkeleton(const String& fileName);
  84. /**
  85. * Sets the texture from an existing Texture instance.
  86. * @param texture Texture to set.
  87. */
  88. void setTexture(Texture *texture);
  89. /**
  90. * Clears the currently applied material
  91. */
  92. void clearMaterial();
  93. /**
  94. * Set material from existing Material instance.
  95. * @param material Material to apply.
  96. */
  97. void setMaterial(Material *material);
  98. /**
  99. * Set material by name. You can create materials in material files and name them there, then use this to set a material by name to a scene mesh.
  100. * @param materialName Name of material to apply.
  101. */
  102. void setMaterialByName(const String& materialName);
  103. /**
  104. * Set the mesh this scene mesh renders.
  105. * @param mesh Set a new mesh to render.
  106. */
  107. void setMesh(Mesh *mesh);
  108. /**
  109. * Sets a skeleton from an existing skeleton instance.
  110. * @param skeleton Skeleton to set to this mesh.
  111. */
  112. void setSkeleton(Skeleton *skeleton);
  113. /**
  114. * Returns the skeleton applied to this scene mesh.
  115. */
  116. Skeleton *getSkeleton();
  117. void renderMeshLocally();
  118. /**
  119. * If this is set to true, the mesh will be cached to a hardware vertex buffer if those are available. This can dramatically speed up rendering.
  120. */
  121. void cacheToVertexBuffer(bool cache);
  122. unsigned int lightmapIndex;
  123. bool showVertexNormals;
  124. void setLineWidth(Number newWidth);
  125. Number lineWidth;
  126. bool lineSmooth;
  127. /**
  128. * If true, will delete its Mesh upon destruction. (defaults to true)
  129. */
  130. bool ownsMesh;
  131. /**
  132. * If true, will delete its Skeleton upon destruction. (defaults to true)
  133. */
  134. bool ownsSkeleton;
  135. protected:
  136. bool useVertexBuffer;
  137. Mesh *mesh;
  138. Texture *texture;
  139. Material *material;
  140. Skeleton *skeleton;
  141. ShaderBinding *localShaderOptions;
  142. };
  143. }