void ActorSet::load(const PropertyBag &objects, World *_world) { ASSERT(_world!=0, "world was null"); world = _world; for(size_t i=0, n=objects.getNumInstances("object"); i<n; ++i) { const tuple<OBJECT_ID, ActorPtr> t = create(); const ActorPtr object = t.get<1>(); const PropertyBag decl = objects.getBag("object", i); const FileName templateFile = decl.getFileName("template"); const vec3 initialPosition = decl.getVec3("position"); const PropertyBag templateData = PropertyBag::fromFile(templateFile); const PropertyBag base = templateData.getBag("components"); ComponentDataSet s = ComponentDataSet::load(base, decl); // get actor name object->actorName = "(no name)"; templateData.get("name", object->actorName); object->load(s, initialPosition, vec3(0,0,0), world); object->setParentBlackBoard(this); } }
void ParticleSystem::loadParticleEmitters(const PropertyBag &data) { const size_t nEmitters = data.getNumInstances("emitter"); ASSERT(nEmitters>0, "particle system does not specify any emitters"); for(size_t i=0; i<nEmitters; ++i) { const PropertyBag emitterData = data.getBag("emitter", i); ParticleEmitter *emitter = new ParticleEmitter(emitterData, this); emitters.push_back(emitter); } }
void ParticleSystem::loadParticleTemplates(const PropertyBag &data) { const size_t n = data.getNumInstances("template"); for(size_t i=0; i<n; ++i) { const PropertyBag templateData = data.getBag("template", i); const string templateName = templateData.getString("name"); const string materialName = templateData.getString("material"); Material *material = getMaterialPtr(materialName); ParticleElement element(templateData, material); templatesByName.insert(make_pair(templateName, element)); } }
void ParticleSystem::loadParticleMaterials(const PropertyBag &data, TextureFactory &textureFactory) { const size_t nMaterials = data.getNumInstances("material"); ASSERT(nMaterials>0, "particle system does not specify any materials"); for(size_t i=0; i<nMaterials; ++i) { PropertyBag MatBag = data.getBag("material", i); Material material; const string name = MatBag.getString("name"); const FileName fileName = MatBag.getString("image"); material.setTexture(textureFactory.load(fileName, false)); material.glow = MatBag.getBool("glow"); materials.insert(make_pair(name, material)); } ASSERT(!materials.empty(), "after loading, there are no particle materials in system"); }
AnimationController* ModelLoaderSingle::loadFromFile(const FileName &fileName, TextureFactory &textureFactory) const { PropertyBag xml = PropertyBag::fromFile(fileName); const FileName directory = fileName.getPath(); // Winding of polygons, either "CCW" or "CW" string polygonWinding = "CW"; xml.get("polygonWinding", polygonWinding); // Allocate a blank animation controller AnimationController *controller = new AnimationController(); // Get key frames from the first source PropertyBag fileBag = xml.getBag("model", 0); const FileName file = directory.append(fileBag.getFileName("file")); FileName skinName; if(fileBag.get("skin", skinName)) { skinName = directory.append(skinName); } vector<KeyFrame> keyFrames = loadKeyFrames(file, skinName, textureFactory); // Get the rest of the key frames for(size_t i = 1, numMD3 = xml.getNumInstances("model"); i<numMD3; ++i) { PropertyBag fileBag = xml.getBag("model", i); const FileName file = directory.append(fileBag.getFileName("file")); FileName skinName; if(fileBag.get("skin", skinName)) { skinName = directory.append(skinName); } vector<KeyFrame> k = loadKeyFrames(file, skinName, textureFactory); for(size_t i=0; i<k.size(); ++i) { KeyFrame &keyFrame = keyFrames[i]; keyFrame.merge(k[i]); // set polygon windings according to data file setPolygonWinding(keyFrame, polygonWinding); } } // Build the animations from these keyframes for(size_t i = 0, numAnimations = xml.getNumInstances("animation"); i<numAnimations; ++i) { PropertyBag animation; string name; bool looping=false; int start=0; float priority=0; int length=0; float fps=0; xml.get("animation", animation, i); animation.get("name", name); animation.get("priority", priority); animation.get("looping", looping); animation.get("start", start); animation.get("length", length); animation.get("fps", fps); // Add it to the controller AnimationSequence animationSequence(keyFrames, name, priority, looping, start, length, fps); controller->addAnimation(animationSequence); } return controller; }