-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathZenResources.cpp
152 lines (116 loc) · 3.71 KB
/
ZenResources.cpp
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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
#include "ZenResources.hpp"
#include <Mesh/BsMesh.h>
#include <Resources/BsResources.h>
using namespace BsZenLib::Res;
bs::RTTITypeBase* ZAnimationClip::getRTTIStatic() { return ZAnimationClipRTTI::instance(); }
bs::SPtr<ZAnimationClip> ZAnimationClip::createEmpty()
{
using namespace bs;
SPtr<ZAnimationClip> sptr =
bs_core_ptr<ZAnimationClip>(new (bs_alloc<ZAnimationClip>()) ZAnimationClip());
sptr->_setThisPtr(sptr);
return sptr;
}
HZAnimation ZAnimationClip::create()
{
using namespace bs;
SPtr<ZAnimationClip> sptr = createEmpty();
sptr->initialize();
// Create a handle
return static_resource_cast<ZAnimationClip>(bs::gResources()._createResourceHandle(sptr));
}
HModelScriptFile ModelScriptFile::create(bs::Vector<HMeshWithMaterials> meshes,
bs::Vector<HZAnimation> animations)
{
HModelScriptFile h = create();
h->mMeshes = meshes;
h->mAnimations = animations;
for (auto m : meshes)
{
h->addResourceDependency(m);
}
for (auto a : animations)
{
h->addResourceDependency(a);
}
// Needs to be also called after deserialization!
h->_buildMeshesByNameMap();
return h;
}
void ModelScriptFile::_buildMeshesByNameMap()
{
// These are set again
for (auto& m : mMeshes)
{
if (!m || !m.isLoaded())
{
BS_LOG(Warning, Uncategorized,
"[ZenResources] Empty mesh found while loading ModelScript " + getName());
continue;
}
bs::String nameUpperCase = m->getName();
bs::StringUtil::toUpperCase(nameUpperCase);
bs::String noExtension = nameUpperCase.substr(0, nameUpperCase.find_first_of('.'));
mMeshesByName[noExtension] = m;
}
}
HModelScriptFile ModelScriptFile::create()
{
using namespace bs;
SPtr<ModelScriptFile> sptr = bs_core_ptr<ModelScriptFile>(bs_new<ModelScriptFile>());
sptr->_setThisPtr(sptr);
sptr->initialize();
// Create a handle
return static_resource_cast<ModelScriptFile>(bs::gResources()._createResourceHandle(sptr));
}
bs::SPtr<ModelScriptFile> ModelScriptFile::createEmpty()
{
using namespace bs;
SPtr<ModelScriptFile> sptr =
bs_core_ptr<ModelScriptFile>(new (bs_alloc<ModelScriptFile>()) ModelScriptFile());
sptr->_setThisPtr(sptr);
return sptr;
}
bs::RTTITypeBase* ModelScriptFile::getRTTIStatic() { return ModelScriptFileRTTI::instance(); }
HMeshWithMaterials MeshWithMaterials::create(bs::HMesh mesh, bs::Vector<bs::HMaterial> materials)
{
HMeshWithMaterials h = create();
h->mMesh = mesh;
h->mMaterials = materials;
h->setName(mesh->getName());
for (auto m : materials)
{
h->addResourceDependency(m);
}
return h;
}
HMeshWithMaterials MeshWithMaterials::create(bs::HMesh mesh, bs::Vector<bs::HMaterial> materials,
bs::Map<bs::String, HMeshWithMaterials> attachments)
{
HMeshWithMaterials h = create(mesh, materials);
for (const auto& a : attachments)
{
h->mAttachmentNodeNames.push_back(a.first);
h->mNodeAttachments.push_back(a.second);
h->addResourceDependency(a.second);
}
return h;
}
bs::SPtr<MeshWithMaterials> MeshWithMaterials::createEmpty()
{
using namespace bs;
SPtr<MeshWithMaterials> sptr =
bs_core_ptr<MeshWithMaterials>(new (bs_alloc<MeshWithMaterials>()) MeshWithMaterials());
sptr->_setThisPtr(sptr);
return sptr;
}
HMeshWithMaterials MeshWithMaterials::create()
{
using namespace bs;
SPtr<MeshWithMaterials> sptr = bs_core_ptr<MeshWithMaterials>(bs_new<MeshWithMaterials>());
sptr->_setThisPtr(sptr);
sptr->initialize();
// Create a handle
return static_resource_cast<MeshWithMaterials>(bs::gResources()._createResourceHandle(sptr));
}
bs::RTTITypeBase* MeshWithMaterials::getRTTIStatic() { return MeshWithMaterialsRTTI::instance(); }