3 Copyright (c) 2006-2009 Charlie C & Erwin Coumans http://gamekit.googlecode.com
5 This software is provided 'as-is', without any express or implied warranty.
6 In no event will the authors be held liable for any damages arising from the use of this software.
7 Permission is granted to anyone to use this software for any purpose,
8 including commercial applications, and to alter it and redistribute it freely,
9 subject to the following restrictions:
11 1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required.
12 2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software.
13 3. This notice may not be removed or altered from any source distribution.
17 #include "bBlenderFile.h"
22 using namespace bParse;
25 // ----------------------------------------------------- //
26 bMain::bMain(bBlenderFile *filePtr, const char *baseName, int fileVersion)
28 mVersion(fileVersion),
31 mData.insert(ID_SCE,bListBasePtr());
32 mData.insert(ID_LI,bListBasePtr());
33 mData.insert(ID_OB,bListBasePtr());
34 mData.insert(ID_ME,bListBasePtr());
35 mData.insert(ID_CU,bListBasePtr());
36 mData.insert(ID_MB,bListBasePtr());
37 mData.insert(ID_MA,bListBasePtr());
38 mData.insert(ID_TE,bListBasePtr());
39 mData.insert(ID_IM,bListBasePtr());
40 mData.insert(ID_WV,bListBasePtr());
41 mData.insert(ID_LT,bListBasePtr());
42 mData.insert(ID_LA,bListBasePtr());
43 mData.insert(ID_CA,bListBasePtr());
44 mData.insert(ID_IP,bListBasePtr());
45 mData.insert(ID_KE,bListBasePtr());
46 mData.insert(ID_WO,bListBasePtr());
47 mData.insert(ID_SCR,bListBasePtr());
48 mData.insert(ID_VF,bListBasePtr());
49 mData.insert(ID_TXT,bListBasePtr());
50 mData.insert(ID_SO,bListBasePtr());
51 mData.insert(ID_GR,bListBasePtr());
52 mData.insert(ID_AR,bListBasePtr());
53 mData.insert(ID_AC,bListBasePtr());
54 mData.insert(ID_NT,bListBasePtr());
55 mData.insert(ID_BR,bListBasePtr());
56 mData.insert(ID_SCRIPT, bListBasePtr());
60 // ----------------------------------------------------- //
63 // allocated data blocks!
65 int sz = mPool.size();
66 for (int i=0;i<sz;i++)
72 // ----------------------------------------------------- //
73 int bMain::getVersion()
78 // ----------------------------------------------------- //
79 const char *bMain::getName()
84 // ----------------------------------------------------- //
85 void bMain::addDatablock(void *allocated)
88 mPool.push_back((bStructHandle*)allocated);
94 // ------------------------------------------------------------//
95 void bMain::linkList(void *listBasePtr)
98 struct ListBase // local Blender::ListBase
104 struct Link // local Blender::Link
111 ListBase *base = (ListBase*)listBasePtr;
113 if (!base || !base->first)
116 base->first = mFP->findLibPointer(base->first);
124 Link *l = (Link*)base->first;
127 l->next = mFP->findLibPointer(l->next);
134 // ------------------------------------------------------------//
135 bListBasePtr* bMain::getListBasePtr(int listBaseCode)
137 bListBasePtr *ptr = _findCode(listBaseCode);
143 // ------------------------------------------------------------//
144 bListBasePtr *bMain::_findCode(int code)
147 bListBasePtr* lbPtr = mData.find(code);
152 // ------------------------------------------------------------//
153 bListBasePtr *bMain::getScene()
155 bListBasePtr *ptr = _findCode(ID_SCE);
161 // ------------------------------------------------------------//
162 bListBasePtr *bMain::getLibrary()
164 bListBasePtr *ptr = _findCode(ID_LI);
169 // ------------------------------------------------------------//
170 bListBasePtr *bMain::getObject()
172 bListBasePtr *ptr = _findCode(ID_OB);
178 // ------------------------------------------------------------//
179 bListBasePtr *bMain::getMesh()
181 bListBasePtr *ptr = _findCode(ID_ME);
187 // ------------------------------------------------------------//
188 bListBasePtr *bMain::getCurve()
190 bListBasePtr *ptr = _findCode(ID_CU);
198 // ------------------------------------------------------------//
199 bListBasePtr *bMain::getMball()
201 bListBasePtr *ptr = _findCode(ID_MB);
207 // ------------------------------------------------------------//
208 bListBasePtr *bMain::getMat()
210 bListBasePtr *ptr = _findCode(ID_MA);
216 // ------------------------------------------------------------//
217 bListBasePtr *bMain::getTex()
219 bListBasePtr *ptr = _findCode(ID_TE);
226 // ------------------------------------------------------------//
227 bListBasePtr *bMain::getImage()
229 bListBasePtr *ptr = _findCode(ID_IM);
235 // ------------------------------------------------------------//
236 bListBasePtr *bMain::getWave()
238 bListBasePtr *ptr = _findCode(ID_WV);
244 // ------------------------------------------------------------//
245 bListBasePtr *bMain::getLatt()
247 bListBasePtr *ptr = _findCode(ID_LT);
253 // ------------------------------------------------------------//
254 bListBasePtr *bMain::getLamp()
256 bListBasePtr *ptr = _findCode(ID_LA);
262 // ------------------------------------------------------------//
263 bListBasePtr *bMain::getCamera()
265 bListBasePtr *ptr = _findCode(ID_CA);
271 // ------------------------------------------------------------//
272 bListBasePtr *bMain::getIpo()
274 bListBasePtr *ptr = _findCode(ID_IP);
280 // ------------------------------------------------------------//
281 bListBasePtr *bMain::getKey()
283 bListBasePtr *ptr = _findCode(ID_KE);
289 // ------------------------------------------------------------//
290 bListBasePtr *bMain::getWorld()
292 bListBasePtr *ptr = _findCode(ID_WO);
299 // ------------------------------------------------------------//
300 bListBasePtr *bMain::getScreen()
302 bListBasePtr *ptr = _findCode(ID_SCR);
308 // ------------------------------------------------------------//
309 bListBasePtr *bMain::getScript()
311 bListBasePtr *ptr = _findCode(ID_SCRIPT);
317 // ------------------------------------------------------------//
318 bListBasePtr *bMain::getVfont()
320 bListBasePtr *ptr = _findCode(ID_VF);
326 // ------------------------------------------------------------//
327 bListBasePtr *bMain::getText()
329 bListBasePtr *ptr = _findCode(ID_TXT);
335 // ------------------------------------------------------------//
336 bListBasePtr *bMain::getSound()
338 bListBasePtr *ptr = _findCode(ID_SO);
344 // ------------------------------------------------------------//
345 bListBasePtr *bMain::getGroup()
347 bListBasePtr *ptr = _findCode(ID_GR);
353 // ------------------------------------------------------------//
354 bListBasePtr *bMain::getArmature()
356 bListBasePtr *ptr = _findCode(ID_AR);
362 // ------------------------------------------------------------//
363 bListBasePtr *bMain::getAction()
365 bListBasePtr *ptr = _findCode(ID_AC);
372 // ------------------------------------------------------------//
373 bListBasePtr *bMain::getNodetree()
375 bListBasePtr *ptr = _findCode(ID_NT);
381 // ------------------------------------------------------------//
382 bListBasePtr *bMain::getBrush()
384 bListBasePtr *ptr = _findCode(ID_BR);