OpenGothic
Open source reimplementation of Gothic I and II
Loading...
Searching...
No Matches
protomesh.h
Go to the documentation of this file.
1#pragma once
2
3#include <Tempest/VertexBuffer>
4#include <Tempest/IndexBuffer>
5#include <Tempest/Device>
6#include <Tempest/Matrix4x4>
7
8#include <zenkit/Model.hh>
9#include <zenkit/ModelMesh.hh>
10#include <zenkit/ModelHierarchy.hh>
11#include <zenkit/MorphMesh.hh>
12
15
16#include "resources.h"
17
18class PackedMesh;
19class PhysicMeshShape;
20
21class ProtoMesh {
22 public:
24
25 ProtoMesh(PackedMesh&& pm, std::string_view fname);
26 ProtoMesh(PackedMesh&& pm, const std::vector<zenkit::MorphAnimation>& aniList, std::string_view fname);
27 ProtoMesh(const zenkit::Model& lib, std::unique_ptr<Skeleton>&& sk, std::string_view fname);
28 ProtoMesh(const zenkit::ModelHierarchy& lib, std::unique_ptr<Skeleton>&& sk, std::string_view fname);
29 ProtoMesh(const zenkit::ModelMesh& lib, std::unique_ptr<Skeleton>&& sk, std::string_view fname);
30 ProtoMesh(const Material& mat, std::vector<Resources::Vertex> vbo, std::vector<uint32_t> ibo); //decals
33 ~ProtoMesh();
34
35 struct SubMesh final {
37 Tempest::IndexBuffer<uint32_t> ibo;
38 std::unique_ptr<PhysicMeshShape> shape;
39 };
40
41 struct SubMeshId final {
42 size_t id = 0;
43 size_t subId = 0;
44 };
45
46 struct Node {
47 size_t attachId = size_t(-1);
48 size_t parentId = size_t(-1);
49 bool hasChild = false;
50 Tempest::Matrix4x4 transform;
51
52 size_t submeshIdB = 0;
53 size_t submeshIdE = 0;
54 };
55
56 struct Attach : StaticMesh {
58 Attach(Attach&&)=default;
59 Attach& operator=(Attach&&)=default;
60 ~Attach();
61
62 std::string name;
63 bool hasNode=false;
64 std::unique_ptr<PhysicMeshShape> shape;
65 };
66
67 struct Pos {
68 std::string name;
69 Tempest::Matrix4x4 transform;
70 size_t node=0;
71 };
72
74
75 // animation
76 std::unique_ptr<Skeleton> skeleton;
77 std::vector<AnimMesh> skined;
78 std::vector<Morph> morph;
79 Tempest::StorageBuffer morphIndex;
80 Tempest::StorageBuffer morphSamples;
81
82 std::vector<Attach> attach;
83 std::vector<Node> nodes;
84 std::vector<SubMeshId> submeshId;
85
86 std::vector<Pos> pos;
87 Tempest::Vec3 bbox[2];
88
89 std::string scheme, fname;
90
91 size_t skinedNodesCount() const;
92 Tempest::Matrix4x4 mapToRoot(size_t node) const;
93 size_t findNode(std::string_view name,size_t def=size_t(-1)) const;
94
95 private:
96 void setupScheme(std::string_view s);
97 void remap(const zenkit::MorphAnimation& a,
98 const std::vector<uint32_t>& vertId,
99 std::vector<int32_t>& remapId,
100 std::vector<Tempest::Vec4>& samples,
101 size_t idOffset);
102
103 Morph mkAnimation(const zenkit::MorphAnimation& a);
104 };
std::unique_ptr< Skeleton > skeleton
Definition protomesh.h:76
std::string fname
Definition protomesh.h:89
ProtoMesh & operator=(ProtoMesh &&)=delete
std::string scheme
Definition protomesh.h:89
std::vector< AnimMesh > skined
Definition protomesh.h:77
Tempest::StorageBuffer morphSamples
Definition protomesh.h:80
std::vector< Attach > attach
Definition protomesh.h:82
std::vector< Pos > pos
Definition protomesh.h:86
std::vector< Node > nodes
Definition protomesh.h:83
std::vector< Morph > morph
Definition protomesh.h:78
Tempest::Vec3 bbox[2]
Definition protomesh.h:87
size_t skinedNodesCount() const
std::vector< SubMeshId > submeshId
Definition protomesh.h:84
Tempest::StorageBuffer morphIndex
Definition protomesh.h:79
size_t findNode(std::string_view name, size_t def=size_t(-1)) const
Tempest::Matrix4x4 mapToRoot(size_t node) const
ProtoMesh(ProtoMesh &&)=delete
StaticMesh(const PackedMesh &data)
Definition staticmesh.cpp:8
Attach & operator=(Attach &&)=default
std::unique_ptr< PhysicMeshShape > shape
Definition protomesh.h:64
std::string name
Definition protomesh.h:62
Attach(Attach &&)=default
size_t submeshIdE
Definition protomesh.h:53
Tempest::Matrix4x4 transform
Definition protomesh.h:50
size_t parentId
Definition protomesh.h:48
size_t submeshIdB
Definition protomesh.h:52
size_t attachId
Definition protomesh.h:47
std::string name
Definition protomesh.h:68
Tempest::Matrix4x4 transform
Definition protomesh.h:69
Material material
Definition protomesh.h:36
std::unique_ptr< PhysicMeshShape > shape
Definition protomesh.h:38
Tempest::IndexBuffer< uint32_t > ibo
Definition protomesh.h:37