WoW Model Viewer
Your premiere tool for viewing, equipping and animating World of Warcraft models.
Loading...
Searching...
No Matches
Attachment.cpp
Go to the documentation of this file.
1#include "Attachment.h"
2
3#include <string>
4#include <glad/gl.h>
5
6#include "displayable.h"
7#include "Game.h"
8#include "video.h"
9#include "WoWModel.h"
10
11#include "Logger.h"
12
13Attachment::Attachment(Attachment* parent, Displayable* model, int id, int slot)
14 : parent(parent), id(id), slot(slot), model_(nullptr)
15{
17}
18
20{
22
23 parent = nullptr;
24
25 if (model_)
26 model_->attachment = nullptr;
27}
28
30{
31 glPushMatrix();
32 if (model_)
33 {
34 setup();
35 model_->draw();
36 }
37
38 // children
39 for (const auto& c : children)
40 c->draw();
41
42 glPopMatrix();
43}
44
46{
47 glPushMatrix();
48
49 if (model_)
50 {
51 auto* m = dynamic_cast<WoWModel*>(model_);
52 if (!m)
53 {
54 glPopMatrix();
55 return;
56 }
57
58 model_->reset();
60
61 m->drawParticles();
62 }
63
64 // children:
65 for (const auto& i : children)
66 i->drawParticles();
67
68 glPopMatrix();
69}
70
71void Attachment::tick(float dt)
72{
73 if (model_)
74 model_->update(dt);
75 for (const auto& i : children)
76 i->tick(dt);
77}
78
80{
81 if (parent == nullptr)
82 return;
83 if (parent->model_)
85}
86
88{
89 if (parent == nullptr)
90 return;
91 if (parent->model_)
93}
94
95Attachment* Attachment::addChild(std::string modelfn, int Id, int Slot)
96{
97 if (modelfn.length() == 0 || Id < 0)
98 return nullptr;
99
100 auto* m = new WoWModel(GAMEDIRECTORY.getFile(modelfn.c_str()), true);
101
102 if (m->ok)
103 return addChild(m, Id, Slot);
104
105 delete m;
106 return nullptr;
107}
108
110{
111 LOG_INFO << "Attach on id" << Id << "slot" << Slot;
112 auto* att = new Attachment(this, disp, Id, Slot);
113 children.push_back(att);
114 return att;
115}
116
118{
119 for (auto& i : children)
120 {
121 i->delChildren();
122 delete i;
123 i = nullptr;
124 }
125
126 children.clear();
127}
128
130{
131 for (size_t i = 0; i < children.size(); i++)
132 {
133 if (children[i]->slot == Slot)
134 children.erase(children.begin() + i);
135 }
136}
137
139{
140 if (model_)
141 model_->attachment = nullptr;
142
143 model_ = newmodel;
144
145 if (model_)
146 model_->attachment = this;
147}
#define GAMEDIRECTORY
Definition Game.h:9
#define LOG_INFO
Definition Logger.h:10
Scene-graph node that attaches a Displayable to a parent bone slot.
Definition Attachment.h:21
void setupParticle()
std::vector< Attachment * > children
Definition Attachment.h:42
void delSlot(int slot)
Displayable * model_
Definition Attachment.h:48
Attachment * parent
Definition Attachment.h:40
void setModel(Displayable *newmodel)
Displayable * model() const
Definition Attachment.h:38
Attachment * addChild(std::string fn, int id, int slot)
void setup()
void tick(float dt)
void delChildren()
void drawParticles()
void draw()
Attachment(Attachment *parent, Displayable *model, int id, int slot)
Interface for objects that can be drawn and animated in the scene.
Definition displayable.h:9
virtual void update(int)
Definition displayable.h:31
virtual void draw()
Definition displayable.h:23
Attachment * attachment
Definition displayable.h:34
virtual void reset()
Definition displayable.h:27
virtual void setupAtt2(int)
Definition displayable.h:19
virtual void setupAtt(int)
Definition displayable.h:15
Core WoW .m2 model: geometry, animation, textures, and character data.
Definition WoWModel.h:50