AzerothCore 3.3.5a
OpenSource WoW Emulator
Loading...
Searching...
No Matches
Doodad Namespace Reference

Functions

void Extract (ADT::MDDF const &doodadDef, char const *ModelInstName, uint32 mapID, uint32 tileX, uint32 tileY, FILE *pDirfile)
 
void ExtractSet (WMODoodadData const &doodadData, ADT::MODF const &wmo, uint32 mapID, uint32 tileX, uint32 tileY, FILE *pDirfile)
 

Function Documentation

◆ Extract()

void Doodad::Extract ( ADT::MDDF const &  doodadDef,
char const *  ModelInstName,
uint32  mapID,
uint32  tileX,
uint32  tileY,
FILE *  pDirfile 
)
139{
140 char tempname[1036];
141 sprintf(tempname, "%s/%s", szWorkDirWmo, ModelInstName);
142 FILE* input = fopen(tempname, "r+b");
143
144 if (!input)
145 return;
146
147 fseek(input, 8, SEEK_SET); // get the correct no of vertices
148 int nVertices;
149 int count = fread(&nVertices, sizeof (int), 1, input);
150 fclose(input);
151
152 if (count != 1 || nVertices == 0)
153 return;
154
155 // scale factor - divide by 1024. blizzard devs must be on crack, why not just use a float?
156 float sc = doodadDef.Scale / 1024.0f;
157
158 Vec3D position = fixCoords(doodadDef.Position);
159
160 uint16 nameSet = 0;// not used for models
161 uint32 uniqueId = GenerateUniqueObjectId(doodadDef.UniqueId, 0);
162 uint32 tcflags = MOD_M2;
163 if (tileX == 65 && tileY == 65)
164 tcflags |= MOD_WORLDSPAWN;
165
166 //write mapID, tileX, tileY, Flags, NameSet, UniqueId, Pos, Rot, Scale, name
167 fwrite(&mapID, sizeof(uint32), 1, pDirfile);
168 fwrite(&tileX, sizeof(uint32), 1, pDirfile);
169 fwrite(&tileY, sizeof(uint32), 1, pDirfile);
170 fwrite(&tcflags, sizeof(uint32), 1, pDirfile);
171 fwrite(&nameSet, sizeof(uint16), 1, pDirfile);
172 fwrite(&uniqueId, sizeof(uint32), 1, pDirfile);
173 fwrite(&position, sizeof(Vec3D), 1, pDirfile);
174 fwrite(&doodadDef.Rotation, sizeof(Vec3D), 1, pDirfile);
175 fwrite(&sc, sizeof(float), 1, pDirfile);
176 uint32 nlen = strlen(ModelInstName);
177 fwrite(&nlen, sizeof(uint32), 1, pDirfile);
178 fwrite(ModelInstName, sizeof(char), nlen, pDirfile);
179}
std::uint32_t uint32
Definition: Define.h:107
std::uint16_t uint16
Definition: Define.h:108
@ MOD_M2
Definition: vmapexport.h:33
@ MOD_WORLDSPAWN
Definition: vmapexport.h:34
static Vec3D fixCoords(const Vec3D &v)
Definition: wmo.h:68
uint32 GenerateUniqueObjectId(uint32 clientId, uint16 clientDoodadId)
Definition: vmapexport.cpp:72
char const * szWorkDirWmo
Definition: vmapexport.cpp:68
Definition: vec3d.h:25

References fixCoords(), GenerateUniqueObjectId(), MOD_M2, MOD_WORLDSPAWN, ADT::MDDF::Position, ADT::MDDF::Rotation, ADT::MDDF::Scale, szWorkDirWmo, and ADT::MDDF::UniqueId.

Referenced by ADTFile::init().

◆ ExtractSet()

void Doodad::ExtractSet ( WMODoodadData const &  doodadData,
ADT::MODF const &  wmo,
uint32  mapID,
uint32  tileX,
uint32  tileY,
FILE *  pDirfile 
)
182{
183 if (wmo.DoodadSet >= doodadData.Sets.size())
184 return;
185
186 G3D::Vector3 wmoPosition(wmo.Position.z, wmo.Position.x, wmo.Position.y);
187 G3D::Matrix3 wmoRotation = G3D::Matrix3::fromEulerAnglesZYX(G3D::toRadians(wmo.Rotation.y), G3D::toRadians(wmo.Rotation.x), G3D::toRadians(wmo.Rotation.z));
188
189 uint16 doodadId = 0;
190 WMO::MODS const& doodadSetData = doodadData.Sets[wmo.DoodadSet];
191 for (uint16 doodadIndex : doodadData.References)
192 {
193 if (doodadIndex < doodadSetData.StartIndex ||
194 doodadIndex >= doodadSetData.StartIndex + doodadSetData.Count)
195 continue;
196
197 WMO::MODD const& doodad = doodadData.Spawns[doodadIndex];
198
199 char ModelInstName[1024];
200 sprintf(ModelInstName, "%s", GetPlainName(&doodadData.Paths[doodad.NameIndex]));
201 uint32 nlen = strlen(ModelInstName);
202 fixnamen(ModelInstName, nlen);
203 fixname2(ModelInstName, nlen);
204 if (nlen > 3)
205 {
206 char const* extension = &ModelInstName[nlen - 4];
207 if (!strcmp(extension, ".mdx") || !strcmp(extension, ".mdl"))
208 {
209 ModelInstName[nlen - 2] = '2';
210 ModelInstName[nlen - 1] = '\0';
211 }
212 }
213
214 char tempname[1036];
215 sprintf(tempname, "%s/%s", szWorkDirWmo, ModelInstName);
216 FILE* input = fopen(tempname, "r+b");
217 if (!input)
218 continue;
219
220 fseek(input, 8, SEEK_SET); // get the correct no of vertices
221 int nVertices;
222 int count = fread(&nVertices, sizeof(int), 1, input);
223 fclose(input);
224
225 if (count != 1 || nVertices == 0)
226 continue;
227
228 assert(doodadId < std::numeric_limits<uint16>::max());
229 ++doodadId;
230
231 G3D::Vector3 position = wmoPosition + (wmoRotation * G3D::Vector3(doodad.Position.x, doodad.Position.y, doodad.Position.z));
232
233 Vec3D rotation;
234 (G3D::Quat(doodad.Rotation.X, doodad.Rotation.Y, doodad.Rotation.Z, doodad.Rotation.W)
235 .toRotationMatrix() * wmoRotation)
236 .toEulerAnglesXYZ(rotation.z, rotation.x, rotation.y);
237
238 rotation.z = G3D::toDegrees(rotation.z);
239 rotation.x = G3D::toDegrees(rotation.x);
240 rotation.y = G3D::toDegrees(rotation.y);
241
242 uint16 nameSet = 0; // not used for models
243 uint32 uniqueId = GenerateUniqueObjectId(wmo.UniqueId, doodadId);
244 uint32 tcflags = MOD_M2;
245 if (tileX == 65 && tileY == 65)
246 tcflags |= MOD_WORLDSPAWN;
247
248 //write mapID, tileX, tileY, Flags, NameSet, UniqueId, Pos, Rot, Scale, name
249 fwrite(&mapID, sizeof(uint32), 1, pDirfile);
250 fwrite(&tileX, sizeof(uint32), 1, pDirfile);
251 fwrite(&tileY, sizeof(uint32), 1, pDirfile);
252 fwrite(&tcflags, sizeof(uint32), 1, pDirfile);
253 fwrite(&nameSet, sizeof(uint16), 1, pDirfile);
254 fwrite(&uniqueId, sizeof(uint32), 1, pDirfile);
255 fwrite(&position, sizeof(Vec3D), 1, pDirfile);
256 fwrite(&rotation, sizeof(Vec3D), 1, pDirfile);
257 fwrite(&doodad.Scale, sizeof(float), 1, pDirfile);
258 fwrite(&nlen, sizeof(uint32), 1, pDirfile);
259 fwrite(ModelInstName, sizeof(char), nlen, pDirfile);
260 }
261}
char const * GetPlainName(char const *FileName)
Definition: adtfile.cpp:26
void fixnamen(char *name, std::size_t len)
Definition: adtfile.cpp:44
void fixname2(char *name, std::size_t len)
Definition: adtfile.cpp:62
float x
Definition: vec3d.h:27
float y
Definition: vec3d.h:27
float z
Definition: vec3d.h:27
float X
Definition: vec3d.h:256
float Z
Definition: vec3d.h:256
float Y
Definition: vec3d.h:256
float W
Definition: vec3d.h:256
Definition: wmo.h:50
uint32 StartIndex
Definition: wmo.h:52
uint32 Count
Definition: wmo.h:53
Definition: wmo.h:58
Quaternion Rotation
Definition: wmo.h:61
uint32 NameIndex
Definition: wmo.h:59
float Scale
Definition: wmo.h:62
Vec3D Position
Definition: wmo.h:60

References WMO::MODS::Count, ADT::MODF::DoodadSet, fixname2(), fixnamen(), GenerateUniqueObjectId(), GetPlainName(), MOD_M2, MOD_WORLDSPAWN, WMO::MODD::NameIndex, WMODoodadData::Paths, ADT::MODF::Position, WMO::MODD::Position, WMODoodadData::References, ADT::MODF::Rotation, WMO::MODD::Rotation, WMO::MODD::Scale, WMODoodadData::Sets, WMODoodadData::Spawns, WMO::MODS::StartIndex, szWorkDirWmo, ADT::MODF::UniqueId, Quaternion::W, Vec3D::x, Quaternion::X, Vec3D::y, Quaternion::Y, Vec3D::z, and Quaternion::Z.

Referenced by ADTFile::init(), and WDTFile::init().