summaryrefslogtreecommitdiff
path: root/Source/Core/VideoCommon/Assets/MeshAsset.h
blob: a678b14ceeaf710c0c49f60074fcbdd816aef13f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
// Copyright 2023 Dolphin Emulator Project
// SPDX-License-Identifier: GPL-2.0-or-later

#pragma once

#include <map>
#include <memory>
#include <span>
#include <string>
#include <string_view>

#include <picojson.h>

#include "Common/CommonTypes.h"
#include "Common/Matrix.h"

#include "VideoCommon/Assets/CustomAsset.h"
#include "VideoCommon/NativeVertexFormat.h"
#include "VideoCommon/RenderState.h"

namespace File
{
class IOFile;
}

namespace VideoCommon
{
struct MeshDataChunk
{
  std::unique_ptr<u8[]> vertex_data;
  u32 vertex_stride;
  u32 num_vertices;
  std::unique_ptr<u16[]> indices;
  u32 num_indices;
  PortableVertexDeclaration vertex_declaration;
  PrimitiveType primitive_type;
  u32 components_available;
  Common::Vec3 minimum_position;
  Common::Vec3 maximum_position;
  Common::Matrix44 transform;
  std::string material_name;
};

struct MeshData
{
  static bool FromJson(const CustomAssetLibrary::AssetID& asset_id, const picojson::object& json,
                       MeshData* data);
  static void ToJson(picojson::object& obj, const MeshData& data);

  static bool FromDolphinMesh(std::span<const u8> raw_data, MeshData* data);

  static bool ToDolphinMesh(File::IOFile* file_data, const MeshData& data);

  static bool FromGLTF(std::string_view gltf_file, MeshData* data);

  std::vector<MeshDataChunk> m_mesh_chunks;
  std::map<std::string, CustomAssetLibrary::AssetID, std::less<>>
      m_mesh_material_to_material_asset_id;
};

class MeshAsset final : public CustomLoadableAsset<MeshData>
{
public:
  using CustomLoadableAsset::CustomLoadableAsset;

private:
  CustomAssetLibrary::LoadInfo LoadImpl(const CustomAssetLibrary::AssetID& asset_id) override;
};
}  // namespace VideoCommon