bool SceneSerializer::SerializeScene(const IScene* scene, std::string rootNodeName, const std::string& fileName, const std::string& refCollection/* = std::string("")*/) { //PxDataManSerializeOptions serialOptions = PxDataManSerializeOptions(PxDataManSerializeOptions::ALL, //PxDataCollection, true, fileName); StartID = PhysXSerializerWrapper::GetHighestIDInCollection(ActorCollection); pxDataRefCollection = refCollection; if(StartID < 1) StartID = 1; long long otherCollectionID = PhysXSerializerWrapper::GetHighestIDInCollection(refCollection); if(otherCollectionID < 1) otherCollectionID = 1; if(otherCollectionID > StartID) StartID = otherCollectionID + 1; if(PhysXSerializerWrapper::CreateSerializer() )//&& //PhysXDataManager::GetSingletonPtr()->SerializeData(serialOptions)) { XMLWriter writer; rootNodeName.erase(std::remove_if(rootNodeName.begin(), rootNodeName.end(), isspace), rootNodeName.end()); if( PhysXSerializerWrapper::CreateCollection(ActorCollection, true)) { writer.CreateNode(rootNodeName, std::string(""), false);//Root node which is scene name for (GameObjectList::iterator start = scene->gameObjectList.begin(); start != scene->gameObjectList.end(); ++start) { if(start->get()->IsSerializable())//if serializable, serialize SerializeGameObject(writer, *start); } //PhysXSerializerWrapper::CompleteCollection(ActorCollection, refCollection); bool serialize = PhysXSerializerWrapper::SerializeToBinary(fileName + "Actors.pbd", ActorCollection, refCollection); bool xml = writer.WriteFile(fileName + "Actors.xml"); PhysXSerializerWrapper::ReleaseCollection(ActorCollection); PhysXSerializerWrapper::DestroySerializer(); return serialize && xml; } } return false; }
GameObject *Scene::SearchGameObject(const std::string &objectName) { GameObject *result = NULL; for (GameObjectList::iterator it = _gameObjects.begin(); it != _gameObjects.end(); it++) { if ((*it)->Name() == objectName) { result = it->get(); break; } } if (!result) { for (GameObjectList::iterator it = _gameObjects.begin(); it != _gameObjects.end(); it++) { Transform *transform = (*it)->Transform()->Find(objectName); if (transform) { result = transform->GameObject(); break; } } } return result; }