DKGL2 sample codes

ObjImportUtil.h 923B

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. // Simple Obj Loader from https://www.dkscript.com/wiki/SampleCodes/ObjLoader
  2. // but using tinyObjLoader for MTL convenience
  3. #pragma once
  4. #include <DK.h>
  5. class ObjImportUtil
  6. {
  7. public:
  8. struct ObjVertex
  9. {
  10. DKVector3 inPos;
  11. DKVector3 inColor;
  12. DKVector3 inNormal;
  13. DKVector2 inTexCoord;
  14. int Compare(const ObjVertex& Other) const;
  15. inline bool operator > (const ObjVertex& Other) const
  16. {
  17. return Compare(Other) > 0;
  18. }
  19. inline bool operator < (const ObjVertex& Other) const
  20. {
  21. return Compare(Other) < 0;
  22. }
  23. };
  24. struct ObjImportedMeshData
  25. {
  26. DKArray<ObjVertex> vertices;
  27. DKArray<uint32_t> indices;
  28. DKAabb aabb;
  29. uint32_t vertexSize;
  30. };
  31. static ObjImportedMeshData LoadFromObjFile(
  32. const DKString& inPath
  33. , DKResourcePool& inDKResourcePool);
  34. };