LLSD LLObjectBackup::primsToLLSD(LLViewerObject::child_list_t child_list,
								 bool is_attachment)
{
	LLViewerObject* object;
	LLSD llsd;
	char localid[16];
	LLUUID t_id;

	for (LLViewerObject::child_list_t::iterator i = child_list.begin();
		 i != child_list.end(); ++i)
	{
		object = (*i);
		LLUUID id = object->getID();

		LL_INFOS() << "Exporting prim " << object->getID().asString() << LL_ENDL;

		// Create an LLSD object that represents this prim. It will be injected
		// in to the overall LLSD tree structure
		LLSD prim_llsd;

		if (!object->isRoot())
		{
			// Parent id
			snprintf(localid, sizeof(localid), "%u",
					 object->getSubParent()->getLocalID());
			prim_llsd["parent"] = localid;
		}

		// Name and description
		LLSelectNode* node = LLSelectMgr::getInstance()->getSelection()->findNode(object);
		if (node)
		{
			prim_llsd["name"] = node->mName;
			prim_llsd["description"] = node->mDescription;
		}

		// Transforms
		if (is_attachment)
		{
			prim_llsd["position"] = object->getPositionEdit().getValue();
			prim_llsd["rotation"] = ll_sd_from_quaternion(object->getRotationEdit());
		}
		else
		{
			prim_llsd["position"] = object->getPosition().getValue();
			prim_llsd["rotation"] = ll_sd_from_quaternion(object->getRotation());
		}
		prim_llsd["scale"] = object->getScale().getValue();

		// Flags
		prim_llsd["phantom"] = object->flagPhantom();		// legacy
		prim_llsd["physical"] = object->flagUsePhysics();	// legacy
		prim_llsd["flags"] = (S32)object->getFlags();		// new way

		// Extra physics flags
		if (mGotExtraPhysics)
		{
			LLSD& physics = prim_llsd["ExtraPhysics"];
			physics["PhysicsShapeType"] = object->getPhysicsShapeType();
			physics["Gravity"] = object->getPhysicsGravity();
			physics["Friction"] = object->getPhysicsFriction();
			physics["Density"] = object->getPhysicsDensity();
			physics["Restitution"] = object->getPhysicsRestitution();
		}

		// Click action
		if (S32 action = object->getClickAction()) // Non-zero
			prim_llsd["clickaction"] = action;

		// Prim material
		prim_llsd["material"] = object->getMaterial();

		// Volume params
		LLVolumeParams params = object->getVolume()->getParams();
		prim_llsd["volume"] = params.asLLSD();

		// Extra paramsb6fab961-af18-77f8-cf08-f021377a7244

		if (object->isFlexible())
		{
			// Flexible
			LLFlexibleObjectData* flex;
			flex = (LLFlexibleObjectData*)object->getParameterEntry(LLNetworkData::PARAMS_FLEXIBLE);
			prim_llsd["flexible"] = flex->asLLSD();
		}

		if (object->getParameterEntryInUse(LLNetworkData::PARAMS_LIGHT))
		{
			// Light
			LLLightParams* light;
			light = (LLLightParams*)object->getParameterEntry(LLNetworkData::PARAMS_LIGHT);
			prim_llsd["light"] = light->asLLSD();
		}
		if (object->getParameterEntryInUse(LLNetworkData::PARAMS_LIGHT_IMAGE))
		{
			// Light image
			LLLightImageParams* light_param;
			light_param = (LLLightImageParams*)object->getParameterEntry(LLNetworkData::PARAMS_LIGHT_IMAGE);
			t_id = validateTextureID(light_param->getLightTexture());
			if (mTexturesList.count(t_id) == 0)
			{
				LL_INFOS() << "Found a light texture, adding to list " << t_id
						<< LL_ENDL;
				mTexturesList.insert(t_id);
			}
			prim_llsd["light_texture"] = light_param->asLLSD();
		}

		if (object->getParameterEntryInUse(LLNetworkData::PARAMS_SCULPT))
		{
			// Sculpt
			LLSculptParams* sculpt;
			sculpt = (LLSculptParams*)object->getParameterEntry(LLNetworkData::PARAMS_SCULPT);
			prim_llsd["sculpt"] = sculpt->asLLSD();
			if ((sculpt->getSculptType() & LL_SCULPT_TYPE_MASK) != LL_SCULPT_TYPE_MESH)
			{
				LLUUID sculpt_texture = sculpt->getSculptTexture();
				if (sculpt_texture == validateTextureID(sculpt_texture))
				{
					if (mTexturesList.count(sculpt_texture) == 0)
					{
						LL_INFOS() << "Found a sculpt texture, adding to list "
								<< sculpt_texture << LL_ENDL;
						mTexturesList.insert(sculpt_texture);
					}
				}
				else
				{
					LL_WARNS() << "Incorrect permission to export a sculpt texture."
							<< LL_ENDL;
					mExportState = EXPORT_FAILED;
				}
			}
		}

		// Textures and materials
		LLSD te_llsd;
		LLSD this_te_llsd;
		LLSD te_mat_llsd;
		LLSD this_te_mat_llsd;
		bool has_materials = false;
		for (U8 i = 0, count = object->getNumTEs(); i < count; ++i)
		{
			LLTextureEntry* te = object->getTE(i);
			if (!te) continue;	// Paranoia

			// Normal texture/diffuse map
			t_id = validateTextureID(te->getID());
			this_te_llsd = te->asLLSD();
			this_te_llsd["imageid"] = t_id;
			te_llsd.append(this_te_llsd);
			// Do not export non-existent default textures
			if (t_id != LL_TEXTURE_BLANK && t_id != LL_TEXTURE_INVISIBLE)
			{
				if (mTexturesList.count(t_id) == 0)
				{
					mTexturesList.insert(t_id);
				}
			}

			// Materials
			LLMaterial* mat = te->getMaterialParams().get();
			if (mat)
			{
				has_materials = true;
				this_te_mat_llsd = mat->asLLSD();

				t_id = validateTextureID(mat->getNormalID());
				this_te_mat_llsd["NormMap"] = t_id;
				if (mTexturesList.count(t_id) == 0)
				{
					mTexturesList.insert(t_id);
				}

				t_id = validateTextureID(mat->getSpecularID());
				this_te_mat_llsd["SpecMap"] = t_id;
				if (mTexturesList.count(t_id) == 0)
				{
					mTexturesList.insert(t_id);
				}

				te_mat_llsd.append(this_te_mat_llsd);
			}
		}
		prim_llsd["textures"] = te_llsd;
		if (has_materials)
		{
			prim_llsd["materials"] = te_mat_llsd;
		}

		// The keys in the primitive maps do not have to be localids, they can
		// be any string. We simply use localids because they are a unique
		// identifier
		snprintf(localid, sizeof(localid), "%u", object->getLocalID());
		llsd[(const char*)localid] = prim_llsd;
	}

	updateExportNumbers();

	return llsd;
}
void ImportTracker::get_update(S32 newid, BOOL justCreated, BOOL createSelected)
{
	switch (state)
	{
		//lgg crap to change remaining prim parameters from the ascent system build preferences subtab
		case WAND:
			if(justCreated && createSelected)
			{
				numberExpected--;
				if(numberExpected<=0)
					state=IDLE;
				LLMessageSystem* msg = gMessageSystem;
				msg->newMessageFast(_PREHASH_ObjectImage);
				msg->nextBlockFast(_PREHASH_AgentData);
				msg->addUUIDFast(_PREHASH_AgentID, gAgent.getID());
				msg->addUUIDFast(_PREHASH_SessionID, gAgent.getSessionID());	
				msg->nextBlockFast(_PREHASH_ObjectData);				
				msg->addU32Fast(_PREHASH_ObjectLocalID,  (U32)newid);
				msg->addStringFast(_PREHASH_MediaURL, NULL);
//sets texture stuff
				LLPrimitive obj;
				obj.setNumTEs(U8(10));	
				S32 shinnyLevel = 0;
				static LLCachedControl<std::string> sshinystr(gSavedSettings, "EmeraldBuildPrefs_Shiny");
				std::string shinystr = sshinystr;
				//if(shinystr == "None") shinnyLevel = 0; //We're already 0.
				if(shinystr == "Low") shinnyLevel = 1;
				else if(shinystr == "Medium") shinnyLevel = 2;
				else if(shinystr == "High") shinnyLevel = 3;
				
				for (int i = 0; i < 10; i++)
				{
					LLTextureEntry tex =  LLTextureEntry(LLUUID(gSavedSettings.getString("EmeraldBuildPrefs_Texture")));
					tex.setColor(gSavedSettings.getColor4("EmeraldBuildPrefs_Color"));
					tex.setAlpha(1.0 - ((gSavedSettings.getF32("EmeraldBuildPrefs_Alpha")) / 100.0));
					tex.setGlow(gSavedSettings.getF32("EmeraldBuildPrefs_Glow"));
					if(gSavedSettings.getBOOL("EmeraldBuildPrefs_FullBright"))
					{
						tex.setFullbright(TEM_FULLBRIGHT_MASK);
					}
									
					tex.setShiny((U8) shinnyLevel & TEM_SHINY_MASK);
					
					obj.setTE(U8(i), tex);
				}
	
				obj.packTEMessage(gMessageSystem);
	
				msg->sendReliable(gAgent.getRegion()->getHost());
//sets some object parameters
				msg->newMessage("ObjectFlagUpdate");
				msg->nextBlockFast(_PREHASH_AgentData);
				msg->addUUIDFast(_PREHASH_AgentID, gAgent.getID() );
				msg->addUUIDFast(_PREHASH_SessionID, gAgent.getSessionID());
				msg->addU32Fast(_PREHASH_ObjectLocalID, (U32)newid );
				msg->addBOOLFast(_PREHASH_UsePhysics, gSavedSettings.getBOOL("EmeraldBuildPrefs_Physical"));
				msg->addBOOLFast(_PREHASH_IsTemporary, gSavedSettings.getBOOL("EmeraldBuildPrefs_Temporary"));
				msg->addBOOLFast(_PREHASH_IsPhantom, gSavedSettings.getBOOL("EmeraldBuildPrefs_Phantom") );
				msg->addBOOL("CastsShadows", false );
				msg->sendReliable(gAgent.getRegion()->getHost());

				if(gSavedSettings.getBOOL("EmeraldBuildPrefs_EmbedItem"))
				{
					LLViewerInventoryItem* item = (LLViewerInventoryItem*)gInventory.getItem((LLUUID)gSavedPerAccountSettings.getString("EmeraldBuildPrefs_Item"));
					LLViewerObject* objectp = find((U32)newid);
					if(objectp)
						if(item)
						{
							if(item->getType()==LLAssetType::AT_LSL_TEXT)
							{
								LLToolDragAndDrop::dropScript(objectp,
									item,
									TRUE,
									LLToolDragAndDrop::SOURCE_AGENT,
									gAgent.getID());
							}else
							{
								LLToolDragAndDrop::dropInventory(objectp,item,LLToolDragAndDrop::SOURCE_AGENT,gAgent.getID());
							}
						}
				}
				
				msg->newMessageFast(_PREHASH_ObjectPermissions);
				msg->nextBlockFast(_PREHASH_AgentData);
				msg->addUUIDFast(_PREHASH_AgentID, gAgent.getID());
				msg->addUUIDFast(_PREHASH_SessionID, gAgent.getSessionID());
				msg->nextBlockFast(_PREHASH_HeaderData);
				msg->addBOOLFast(_PREHASH_Override, FALSE);
				msg->nextBlockFast(_PREHASH_ObjectData);
				msg->addU32Fast(_PREHASH_ObjectLocalID, (U32)newid);
				msg->addU8Fast(_PREHASH_Field,	PERM_NEXT_OWNER);
				msg->addU8Fast(_PREHASH_Set, PERM_SET_TRUE);
				U32 flags = 0;
				if ( gSavedSettings.getBOOL("NextOwnerCopy") )
				{
					flags |= PERM_COPY;
				}
				if ( gSavedSettings.getBOOL("NextOwnerModify") )
				{
					flags |= PERM_MODIFY;
				}
				bool next_owner_trans;
				if ( next_owner_trans = gSavedSettings.getBOOL("NextOwnerTransfer") )
				{
					flags |= PERM_TRANSFER;
				}
				msg->addU32Fast(_PREHASH_Mask, flags);
				msg->sendReliable(gAgent.getRegion()->getHost());
				if (!next_owner_trans) // Workaround transfer being true by default.
				{
					msg->newMessageFast(_PREHASH_ObjectPermissions);
					msg->nextBlockFast(_PREHASH_AgentData);
					msg->addUUIDFast(_PREHASH_AgentID, gAgentID);
					msg->addUUIDFast(_PREHASH_SessionID, gAgentSessionID);
					msg->nextBlockFast(_PREHASH_HeaderData);
					msg->addBOOLFast(_PREHASH_Override, false);
					msg->nextBlockFast(_PREHASH_ObjectData);
					msg->addU32Fast(_PREHASH_ObjectLocalID, (U32)newid);
					msg->addU8Fast(_PREHASH_Field,	PERM_NEXT_OWNER);
					msg->addU8Fast(_PREHASH_Set, PERM_SET_FALSE);
					msg->addU32Fast(_PREHASH_Mask, PERM_TRANSFER);
					msg->sendReliable(gAgent.getRegion()->getHost());
				}
				//llinfos << "LGG SENDING CUBE TEXTURE.." << llendl;
			}
		break;
/*		case BUILDING:
			
			if (justCreated && (int)localids.size() < linkset.size())
			{
				localids.push_back(newid);
				localids.sort();
				localids.unique();

				linkset[localids.size() -1]["LocalID"] = newid;
				LLSD prim = linkset[localids.size() -1];

				//MAKERIGHT
				if (!(prim).has("Updated"))
				{
					++updated;
					send_shape(prim);
					send_image(prim);
					send_extras(prim);
					send_namedesc(prim);
					send_vectors(prim,updated);
					send_properties(prim, updated);
					send_inventory(prim);
					(prim)["Updated"] = true;
				}
				if ((int)localids.size() < linkset.size())
				{
					plywood_above_head();
					return;
				}
				else
				{
					if (updated >= linkset.size())
					{
						updated=0;
						llinfos << "FINISHED BUILDING, LINKING.." << llendl;
						state = LINKING;
						link();
					}
				}
			}
		break;
		case LINKING:
			link();
		break;*/
	}
}
void LLObjectBackup::importObject_continued(AIFilePicker* filepicker)
{
	if (!filepicker->hasFilename())
	{
		// User canceled save.
		return;
	}

	std::string file_name = filepicker->getFilename();
	mFolder = gDirUtilp->getDirName(file_name);
	llifstream import_file(file_name);
	LLSDSerialize::fromXML(mLLSD, import_file);
	import_file.close();
	if (!mLLSD.has("data"))
	{
		LLNotificationsUtil::add("ImportFailed");
		destroy();
		return;
	}

	showFloater(false);

	mAgentPos = gAgent.getPositionAgent();
	mAgentRot = LLQuaternion(gAgent.getAtAxis(), gAgent.getLeftAxis(),
							 gAgent.getUpAxis());

	// Get the texture map

	mCurObject = 1;
	mCurPrim = 1;
	mObjects = mLLSD["data"].size();
	mPrims = 0;
	mRezCount = 0;
	updateImportNumbers();

	for (LLSD::array_const_iterator prim_arr_it = mLLSD["data"].beginArray(),
									prim_arr_end = mLLSD["data"].endArray();
		 prim_arr_it != prim_arr_end; ++prim_arr_it)
	{
		LLSD llsd2 = (*prim_arr_it)["group_body"];

		for (LLSD::map_const_iterator prim_it = llsd2.beginMap(),
									  prim_end = llsd2.endMap();
			 prim_it != prim_end; ++prim_it)
		{
			LLSD prim_llsd = llsd2[prim_it->first];
			if (prim_llsd.has("sculpt"))
			{
				LLSculptParams sculpt;
				sculpt.fromLLSD(prim_llsd["sculpt"]);
				if ((sculpt.getSculptType() & LL_SCULPT_TYPE_MASK) != LL_SCULPT_TYPE_MESH)
				{
					LLUUID orig = sculpt.getSculptTexture();
					if (mTexturesList.count(orig) == 0)
					{
						LL_INFOS() << "Found a new SCULPT texture to upload "
								<< orig << LL_ENDL;
						mTexturesList.insert(orig);
					}
				}
			}

			if (prim_llsd.has("light_texture"))
			{
				LLLightImageParams lightimg;
				lightimg.fromLLSD(prim_llsd["light_texture"]);
				LLUUID t_id = lightimg.getLightTexture();
				if (!is_default_texture(t_id) &&
					mTexturesList.count(t_id) == 0)
				{
					LL_INFOS() << "Found a new light texture to upload: " << t_id
							<< LL_ENDL;
					mTexturesList.insert(t_id);
				}
			}

			// Check both for "textures" and "texture" since the second (buggy)
			// case has already been seen in some exported prims XML files...
			LLSD& te_llsd = prim_llsd.has("textures") ? prim_llsd["textures"]
													  : prim_llsd["texture"];
			for (LLSD::array_iterator it = te_llsd.beginArray();
				 it != te_llsd.endArray(); ++it)
			{
				LLSD the_te = *it;
				LLTextureEntry te;
				te.fromLLSD(the_te);

				LLUUID t_id = te.getID();
				if (!is_default_texture(t_id) &&
					mTexturesList.count(t_id) == 0)
				{
					LL_INFOS() << "Found a new texture to upload: " << t_id
							<< LL_ENDL;
						mTexturesList.insert(t_id);
				}
			}

			if (prim_llsd.has("materials"))
			{
				LLSD mat_llsd = prim_llsd["materials"];
				for (LLSD::array_iterator it = mat_llsd.beginArray();
					 it != mat_llsd.endArray(); ++it)
				{
					LLSD the_mat = *it;
					LLMaterial mat;
					mat.fromLLSD(the_mat);

					LLUUID t_id = mat.getNormalID();
					if (!is_default_texture(t_id) &&
						mTexturesList.count(t_id) == 0)
					{
						LL_INFOS() << "Found a new normal map to upload: "
								<< t_id << LL_ENDL;
						mTexturesList.insert(t_id);
					}

					t_id = mat.getSpecularID();
					if (!is_default_texture(t_id) &&
						mTexturesList.count(t_id) == 0)
					{
						LL_INFOS() << "Found a new specular map to upload: "
								<< t_id << LL_ENDL;
						mTexturesList.insert(t_id);
					}
				}
			}
		}
	}

	if (mRetexture)
	{
		uploadNextAsset();
	}
	else
	{
		importFirstObject();
	}
}
// This function takes a pointer to a viewerobject and applies the prim
// definition that prim_llsd has
void LLObjectBackup::xmlToPrim(LLSD prim_llsd, LLViewerObject* object)
{
	LLUUID id = object->getID();
	mExpectingUpdate = object->getID();
	LLSelectMgr::getInstance()->selectObjectAndFamily(object);

	if (prim_llsd.has("name"))
	{
		LLSelectMgr::getInstance()->selectionSetObjectName(prim_llsd["name"]);
	}

	if (prim_llsd.has("description"))
	{
		LLSelectMgr::getInstance()->selectionSetObjectDescription(prim_llsd["description"]);
	}

	if (prim_llsd.has("material"))
	{
		LLSelectMgr::getInstance()->selectionSetMaterial(prim_llsd["material"].asInteger());
	}

	if (prim_llsd.has("clickaction"))
	{
		LLSelectMgr::getInstance()->selectionSetClickAction(prim_llsd["clickaction"].asInteger());
	}

	if (prim_llsd.has("parent"))
	{
		//we are not the root node.
		LLVector3 pos = LLVector3(prim_llsd["position"]);
		LLQuaternion rot = ll_quaternion_from_sd(prim_llsd["rotation"]);
		object->setPositionRegion(pos * mRootRot + mRootPos + mGroupOffset);
		object->setRotation(rot * mRootRot);
	}
	else
	{
		object->setPositionRegion(mRootPos + mGroupOffset);
		LLQuaternion rot=ll_quaternion_from_sd(prim_llsd["rotation"]);
		object->setRotation(rot);
	}

	object->setScale(LLVector3(prim_llsd["scale"]));

	if (prim_llsd.has("flags"))
	{
		U32 flags = (U32)prim_llsd["flags"].asInteger();
		object->setFlags(flags, true);
	}
	else	// Kept for backward compatibility
	{
		/*if (prim_llsd.has("shadows"))
			if (prim_llsd["shadows"].asInteger() == 1)
				object->setFlags(FLAGS_CAST_SHADOWS, true);*/

		if (prim_llsd.has("phantom") && prim_llsd["phantom"].asInteger() == 1)
		{
				object->setFlags(FLAGS_PHANTOM, true);
		}

		if (prim_llsd.has("physical") &&
			prim_llsd["physical"].asInteger() == 1)
		{
			object->setFlags(FLAGS_USE_PHYSICS, true);
		}
	}

	if (mGotExtraPhysics && prim_llsd.has("ExtraPhysics"))
	{
		const LLSD& physics = prim_llsd["ExtraPhysics"];
		object->setPhysicsShapeType(physics["PhysicsShapeType"].asInteger());
		F32 gravity = physics.has("Gravity") ? physics["Gravity"].asReal()
											 : physics["GravityMultiplier"].asReal();
		object->setPhysicsGravity(gravity);
		object->setPhysicsFriction(physics["Friction"].asReal());
		object->setPhysicsDensity(physics["Density"].asReal());
		object->setPhysicsRestitution(physics["Restitution"].asReal());
		object->updateFlags(true);
	}

	// Volume params
	LLVolumeParams volume_params = object->getVolume()->getParams();
	volume_params.fromLLSD(prim_llsd["volume"]);
	object->updateVolume(volume_params);

	if (prim_llsd.has("sculpt"))
	{
		LLSculptParams sculpt;
		sculpt.fromLLSD(prim_llsd["sculpt"]);

		// TODO: check if map is valid and only set texture if map is valid and
		// changes
		LLUUID t_id = sculpt.getSculptTexture();
		if (mAssetMap.count(t_id))
		{
			sculpt.setSculptTexture(mAssetMap[t_id], sculpt.getSculptType());
		}

		object->setParameterEntry(LLNetworkData::PARAMS_SCULPT, sculpt, true);
	}
		
	if (prim_llsd.has("light"))
	{
		LLLightParams light;
		light.fromLLSD(prim_llsd["light"]);
		object->setParameterEntry(LLNetworkData::PARAMS_LIGHT, light, true);
	}
	if (prim_llsd.has("light_texture"))
	{
		// Light image
		LLLightImageParams lightimg;
		lightimg.fromLLSD(prim_llsd["light_texture"]);
		LLUUID t_id = lightimg.getLightTexture();
		if (mAssetMap.count(t_id))
		{
			lightimg.setLightTexture(mAssetMap[t_id]);
		}
		object->setParameterEntry(LLNetworkData::PARAMS_LIGHT_IMAGE, lightimg,
								  true);
	}

	if (prim_llsd.has("flexible"))
	{
		LLFlexibleObjectData flex;
		flex.fromLLSD(prim_llsd["flexible"]);
		object->setParameterEntry(LLNetworkData::PARAMS_FLEXIBLE, flex, true);
	}

	// Textures
	// Check both for "textures" and "texture" since the second (buggy) case
	// has already been seen in some exported prims XML files...
	LL_INFOS() << "Processing textures for prim" << id << LL_ENDL;
	LLSD& te_llsd = prim_llsd.has("textures") ? prim_llsd["textures"]
											  : prim_llsd["texture"];
	U8 i = 0;
	for (LLSD::array_iterator it =  te_llsd.beginArray();
		 it != te_llsd.endArray(); ++it)
	{
	    LLSD the_te = *it;
	    LLTextureEntry te;
	    te.fromLLSD(the_te);
		LLUUID t_id = te.getID();
		if (mAssetMap.count(t_id))
		{
			te.setID(mAssetMap[t_id]);
		}

	    object->setTE(i++, te);
	}
	LL_INFOS() << "Textures done !" << LL_ENDL;

	// Materials
	if (prim_llsd.has("materials"))
	{
		LL_INFOS() << "Processing materials for prim " << id << LL_ENDL;
		te_llsd = prim_llsd["materials"];
		i = 0;
		for (LLSD::array_iterator it = te_llsd.beginArray();
			 it != te_llsd.endArray(); ++it)
		{
		    LLSD the_mat = *it;
			LLMaterialPtr mat = new LLMaterial(the_mat);

			LLUUID t_id = mat->getNormalID();
			if (id.notNull() && mAssetMap.count(t_id))
			{
				mat->setNormalID(mAssetMap[t_id]);
			}

			t_id = mat->getSpecularID();
			if (id.notNull() && mAssetMap.count(t_id))
			{
				mat->setSpecularID(mAssetMap[t_id]);
			}

			LLMaterialMgr::getInstance()->put(id, i++, *mat);
		}
		LL_INFOS() << "Materials done !" << LL_ENDL;
	}

	object->sendRotationUpdate();
	object->sendTEUpdate();	
	object->sendShapeUpdate();
	LLSelectMgr::getInstance()->sendMultipleUpdate(UPD_SCALE | UPD_POSITION);

	LLSelectMgr::getInstance()->deselectAll();
}
Beispiel #5
0
// This function takes a pointer to a viewerobject and applies the prim definition that prim_llsd has
void LLObjectBackup::xmlToPrim(LLSD prim_llsd, LLViewerObject* object)
{
	LLUUID id = object->getID();
	mExpectingUpdate = object->getID();
	LLSelectMgr::getInstance()->selectObjectAndFamily(object);

	if (prim_llsd.has("name"))
	{
		LLSelectMgr::getInstance()->selectionSetObjectName(prim_llsd["name"]);
	}

	if (prim_llsd.has("description"))
	{
		LLSelectMgr::getInstance()->selectionSetObjectDescription(prim_llsd["description"]);
	}

	if (prim_llsd.has("parent"))
	{
		//we are not the root node.
		LLVector3 pos = prim_llsd["position"];
		LLQuaternion rot = ll_quaternion_from_sd(prim_llsd["rotation"]);
		object->setPositionRegion(pos * mRootRot + mRootPos + mGroupOffset);
		object->setRotation(rot * mRootRot);
	}
	else
	{
		object->setPositionRegion(mRootPos + mGroupOffset);
		LLQuaternion rot=ll_quaternion_from_sd(prim_llsd["rotation"]);
		object->setRotation(rot);
	}

	object->setScale(prim_llsd["scale"]);

	if (prim_llsd.has("shadows"))
		if (prim_llsd["shadows"].asInteger() == 1)
			object->setFlags(FLAGS_CAST_SHADOWS, true);

	if (prim_llsd.has("phantom"))
		if (prim_llsd["phantom"].asInteger() == 1)
			object->setFlags(FLAGS_PHANTOM, true);

	if (prim_llsd.has("physical"))
		if (prim_llsd["physical"].asInteger() == 1)
			object->setFlags(FLAGS_USE_PHYSICS, true);

	// Volume params
	LLVolumeParams volume_params = object->getVolume()->getParams();
	volume_params.fromLLSD(prim_llsd["volume"]);
	object->updateVolume(volume_params);

	if (prim_llsd.has("sculpt"))
	{
		LLSculptParams* sculpt = new LLSculptParams();
		sculpt->fromLLSD(prim_llsd["sculpt"]);

		// TODO: check if map is valid and only set texture if map is valid and changes

		if (mAssetMap[sculpt->getSculptTexture()].notNull())
		{
			LLUUID replacment = mAssetMap[sculpt->getSculptTexture()];
			sculpt->setSculptTexture(replacment);
		}

		object->setParameterEntry(LLNetworkData::PARAMS_SCULPT,(LLNetworkData&)(*sculpt), true);
	}
		
	if (prim_llsd.has("light"))
	{
		LLLightParams* light = new LLLightParams();
		light->fromLLSD(prim_llsd["light"]);
		object->setParameterEntry(LLNetworkData::PARAMS_LIGHT,(LLNetworkData&)(*light), true);
	}

	if (prim_llsd.has("flexible"))
	{
		LLFlexibleObjectData* flex = new LLFlexibleObjectData();
		flex->fromLLSD(prim_llsd["flexible"]);
		object->setParameterEntry(LLNetworkData::PARAMS_FLEXIBLE,(LLNetworkData&)(*flex), true);
	}

	// Textures
	llinfos << "Processing textures for prim" << llendl;
	LLSD te_llsd = prim_llsd["textures"];
	LLSD::array_iterator text_it;
	U8 i = 0;

	for (text_it = te_llsd.beginArray(); text_it != te_llsd.endArray(); text_it++)
	{
	    LLSD the_te = (*text_it);
	    LLTextureEntry te;
	    te.fromLLSD(the_te);

		if (mAssetMap[te.getID()].notNull())
		{
			LLUUID replacment = mAssetMap[te.getID()];
			te.setID(replacment);
		}

	    object->setTE(i++, te);
	}

	llinfos << "Textures done !" << llendl;

	//bump the iterator now so the callbacks hook together nicely
	//if (mPrimImportIter != mThisGroup.endMap())
	//	mPrimImportIter++;

	object->sendRotationUpdate();
	object->sendTEUpdate();	
	object->sendShapeUpdate();
	LLSelectMgr::getInstance()->sendMultipleUpdate(UPD_SCALE | UPD_POSITION);

	LLSelectMgr::getInstance()->deselectAll();
}
Beispiel #6
0
void LLObjectBackup::importObject(bool upload)
{
	mTexturesList.clear();
	mAssetMap.clear();
	mCurrentAsset = LLUUID::null;

	mRetexture = upload;

	// Open the file open dialog
	LLFilePicker& file_picker = LLFilePicker::instance();
	if (!file_picker.getOpenFile(LLFilePicker::FFLOAD_XML))
	{
		// User canceled save.
		return;
	}

	std::string file_name = file_picker.getFirstFile().c_str();
	mFolder = gDirUtilp->getDirName(file_name);
	llifstream import_file(file_name);
	LLSDSerialize::fromXML(mLLSD, import_file);
	import_file.close();

	mAgentPos = gAgent.getPositionAgent();
	mAgentRot = LLQuaternion(gAgent.getAtAxis(), gAgent.getLeftAxis(), gAgent.getUpAxis());

	// Get the texture map
	
	LLSD::map_const_iterator prim_it;
	LLSD::array_const_iterator prim_arr_it;
		
	mCurObject = 1;
	mCurPrim = 1;
	mObjects = mLLSD["data"].size();
	mPrims = 0;
	mRezCount = 0;

	if (mObjects <= 0) {
		LLSD args;
		args["MESSAGE"] = std::string("Object import failed.\nThe XML file has an incompatble format or does not contain any objects.");
		LLNotifications::instance().add("GenericAlert", args);
		llwarns << "Trying to import illegal XML object file." << llendl;
		return;
	}

	show(false);

	updateImportNumbers();

	for (prim_arr_it = mLLSD["data"].beginArray(); prim_arr_it != mLLSD["data"].endArray(); prim_arr_it++)
	{
		LLSD llsd2 = (*prim_arr_it)["group_body"];

		for (prim_it = llsd2.beginMap(); prim_it != llsd2.endMap(); prim_it++)
		{
			LLSD prim_llsd = llsd2[prim_it->first];
			LLSD::array_iterator text_it;
			std::list<LLUUID>::iterator iter;

			if (prim_llsd.has("sculpt"))
			{
				LLSculptParams* sculpt = new LLSculptParams();
				sculpt->fromLLSD(prim_llsd["sculpt"]);
				LLUUID orig = sculpt->getSculptTexture();
				bool alreadyseen = false;
				for (iter = mTexturesList.begin(); iter != mTexturesList.end(); iter++)
				{
					if ((*iter) == orig)
						alreadyseen = true;
				}
				if (alreadyseen == false)
				{
					llinfos << "Found a new SCULPT texture to upload " << orig << llendl;			
					mTexturesList.push_back(orig);
				}
			}

			LLSD te_llsd = prim_llsd["textures"];

			for (text_it = te_llsd.beginArray(); text_it != te_llsd.endArray(); text_it++)
			{
				LLSD the_te = (*text_it);
				LLTextureEntry te;
				te.fromLLSD(the_te);

				te.getID();
				bool alreadyseen = false;

				for (iter = mTexturesList.begin(); iter != mTexturesList.end(); iter++)
				{
					if ((*iter) == te.getID())
						alreadyseen = true;
				}
				if (alreadyseen == false)
				{
					llinfos << "Found a new texture to upload "<< te.getID() << llendl;			
					mTexturesList.push_back(te.getID());
				}	     
			}
		}
	}

	if (mRetexture == TRUE)
		uploadNextAsset();
	else
		importFirstObject();
}
void ImportTracker::get_update(S32 newid, BOOL justCreated, BOOL createSelected)
{
	switch (state)
	{
		//lgg crap
		case WAND:
			if(justCreated && createSelected)
			{
				numberExpected--;
				if(numberExpected<=0)
					state=IDLE;
				LLMessageSystem* msg = gMessageSystem;
				msg->newMessageFast(_PREHASH_ObjectImage);
				msg->nextBlockFast(_PREHASH_AgentData);
				msg->addUUIDFast(_PREHASH_AgentID, gAgent.getID());
				msg->addUUIDFast(_PREHASH_SessionID, gAgent.getSessionID());	
				msg->nextBlockFast(_PREHASH_ObjectData);				
				msg->addU32Fast(_PREHASH_ObjectLocalID,  (U32)newid);
				msg->addStringFast(_PREHASH_MediaURL, NULL);
	
				LLPrimitive obj;
				obj.setNumTEs(U8(10));	
				S32 shinnyLevel = 0;
				static std::string* shinystr = rebind_llcontrol<std::string>("EmeraldBuildPrefs_Shiny", &gSavedSettings, true);
				if(*shinystr == "None") shinnyLevel = 0;
				if(*shinystr == "Low") shinnyLevel = 1;
				if(*shinystr == "Medium") shinnyLevel = 2;
				if(*shinystr == "High") shinnyLevel = 3;
				
				for (int i = 0; i < 10; i++)
				{
					static std::string* buildpreftex = rebind_llcontrol<std::string>("EmeraldBuildPrefs_Texture", &gSavedSettings, true);

					LLTextureEntry tex =  LLTextureEntry(LLUUID(*buildpreftex));
					tex.setColor(gSavedSettings.getColor4("EmeraldBuildPrefs_Color"));
					tex.setAlpha(1.0 - ((gSavedSettings.getF32("EmeraldBuildPrefs_Alpha")) / 100.0));
					tex.setGlow(gSavedSettings.getF32("EmeraldBuildPrefs_Glow"));
					if(gSavedSettings.getBOOL("EmeraldBuildPrefs_FullBright"))
					{
						tex.setFullbright(TEM_FULLBRIGHT_MASK);
					}
									
					tex.setShiny((U8) shinnyLevel & TEM_SHINY_MASK);
					
					obj.setTE(U8(i), tex);
				}
	
				obj.packTEMessage(gMessageSystem);
	
				msg->sendReliable(gAgent.getRegion()->getHost());
				
				msg->newMessage("ObjectFlagUpdate");
				msg->nextBlockFast(_PREHASH_AgentData);
				msg->addUUIDFast(_PREHASH_AgentID, gAgent.getID() );
				msg->addUUIDFast(_PREHASH_SessionID, gAgent.getSessionID());
				msg->addU32Fast(_PREHASH_ObjectLocalID, (U32)newid );
				msg->addBOOLFast(_PREHASH_UsePhysics, gSavedSettings.getBOOL("EmeraldBuildPrefs_Physical"));
				msg->addBOOL("IsTemporary", gSavedSettings.getBOOL("EmeraldBuildPrefs_Temporary"));
				msg->addBOOL("IsPhantom", gSavedSettings.getBOOL("EmeraldBuildPrefs_Phantom") );
				msg->addBOOL("CastsShadows", true );
				msg->sendReliable(gAgent.getRegion()->getHost());

				if(gSavedSettings.getBOOL("EmeraldBuildPrefs_EmbedItem"))
				{
					LLViewerInventoryItem* item = (LLViewerInventoryItem*)gInventory.getItem((LLUUID)gSavedSettings.getString("EmeraldBuildPrefs_Item"));
					LLViewerObject* objectp = find((U32)newid);
					if(objectp)
						if(item)
						{
							if(item->getType()==LLAssetType::AT_LSL_TEXT)
							{
								LLToolDragAndDrop::dropScript(objectp,
									item,
									TRUE,
									LLToolDragAndDrop::SOURCE_AGENT,
									gAgent.getID());
							}else
							{
								LLToolDragAndDrop::dropInventory(objectp,item,LLToolDragAndDrop::SOURCE_AGENT,gAgent.getID());
							}
						}
				}
				
				//llinfos << "LGG SENDING CUBE TEXTURE.." << llendl;
			}
		break;
		case BUILDING:
			
			if (justCreated && (int)localids.size() < linkset.size())
			{
				localids.push_back(newid);
				localids.sort();
				localids.unique();

				linkset[localids.size() -1]["LocalID"] = newid;
				LLSD prim = linkset[localids.size() -1];

				//MAKERIGHT
				if (!(prim).has("Updated"))
				{
					++updated;
					send_shape(prim);
					send_image(prim);
					send_extras(prim);
					send_namedesc(prim);
					send_vectors(prim,updated);
					send_properties(prim, updated);
					send_inventory(prim);
					(prim)["Updated"] = true;
				}
				if ((int)localids.size() < linkset.size())
				{
					plywood_above_head();
					return;
				}
				else
				{
					if (updated >= linkset.size())
					{
						updated=0;
						llinfos << "FINISHED BUILDING, LINKING.." << llendl;
						state = LINKING;
						link();
					}
				}
			}
		break;
		case LINKING:
			link();
		break;
	}
}
Beispiel #8
0
void LLViewerMediaFocus::setFocusFace(LLPointer<LLViewerObject> objectp, S32 face, viewer_media_t media_impl, LLVector3 pick_normal)
{	
	LLParcel *parcel = LLViewerParcelMgr::getInstance()->getAgentParcel();
	
	LLViewerMediaImpl *old_media_impl = getFocusedMediaImpl();
	if(old_media_impl)
	{
		old_media_impl->focus(false);
	}
	
	// Always clear the current selection.  If we're setting focus on a face, we'll reselect the correct object below.
	LLSelectMgr::getInstance()->deselectAll();
	mSelection = NULL;

	if (media_impl.notNull() && objectp.notNull())
	{
		bool face_auto_zoom = false;

		mFocusedImplID = media_impl->getMediaTextureID();
		mFocusedObjectID = objectp->getID();
		mFocusedObjectFace = face;
		mFocusedObjectNormal = pick_normal;
		
		// Set the selection in the selection manager so we can draw the focus ring.
		mSelection = LLSelectMgr::getInstance()->selectObjectOnly(objectp, face);

		// Focusing on a media face clears its disable flag.
		media_impl->setDisabled(false);

		LLTextureEntry* tep = objectp->getTE(face);
		if(tep->hasMedia())
		{
			LLMediaEntry* mep = tep->getMediaData();
			face_auto_zoom = mep->getAutoZoom();
			if(!media_impl->hasMedia())
			{
				std::string url = mep->getCurrentURL().empty() ? mep->getHomeURL() : mep->getCurrentURL();
				media_impl->navigateTo(url, "", true);
			}
		}
		else
		{
			// This should never happen.
			llwarns << "Can't find media entry for focused face" << llendl;
		}

		media_impl->focus(true);
		gFocusMgr.setKeyboardFocus(this);
		
		// We must do this before  processing the media HUD zoom, or it may zoom to the wrong face. 
		update();

		if(mMediaControls.get())
		{
			if(face_auto_zoom && ! parcel->getMediaPreventCameraZoom())
			{
				// Zoom in on this face
				mMediaControls.get()->resetZoomLevel(false);
				mMediaControls.get()->nextZoomLevel();
			}
			else
			{
				// Reset the controls' zoom level without moving the camera.
				// This fixes the case where clicking focus between two non-autozoom faces doesn't change the zoom-out button back to a zoom-in button.
				mMediaControls.get()->resetZoomLevel(false);
			}
		}
	}
	else
	{
		if(hasFocus())
		{
			gFocusMgr.setKeyboardFocus(NULL);
		}
		
		mFocusedImplID = LLUUID::null;
		if (objectp.notNull())
		{
			// Still record the focused object...it may mean we need to load media data.
			// This will aid us in determining this object is "important enough"
			mFocusedObjectID = objectp->getID();
			mFocusedObjectFace = face;
		}
		else {
			mFocusedObjectID = LLUUID::null;
			mFocusedObjectFace = 0;
		}
	}
}
void primbackup::import_object(bool upload)
{
	textures.clear();
	assetmap.clear();
	current_asset=LLUUID::null;

	this->m_retexture=upload;

	// Open the file open dialog
	LLFilePicker& file_picker = LLFilePicker::instance();
	if( !file_picker.getOpenFile( LLFilePicker::FFLOAD_XML ) )
	{
		// User canceled save.
		return;
	}
	std::string file_name = file_picker.getFirstFile().c_str();
	folder = gDirUtilp->getDirName(file_name);

	llifstream import_file(file_name);
	LLSDSerialize::fromXML(llsd, import_file);
	import_file.close();

	show();

	//Get the texture map
	
	LLSD::map_const_iterator prim_it;
	LLSD::array_const_iterator prim_arr_it;
		
	this->m_curobject=1;
	this->m_curprim=1;
	this->m_objects=llsd["data"].size();
	this->m_prims=0;
	rezcount=0;

	updateimportnumbers();

	for( prim_arr_it = llsd["data"].beginArray(); prim_arr_it != llsd["data"].endArray(); prim_arr_it++)
	{

		LLSD llsd2;
		llsd2=(*prim_arr_it)["group_body"];

		for( prim_it = llsd2.beginMap(); prim_it != llsd2.endMap(); prim_it++)
		{
			LLSD prim_llsd;
			prim_llsd=llsd2[prim_it->first];
			LLSD::array_iterator text_it;
			std::list<LLUUID>::iterator iter;

			if(prim_llsd.has("sculpt"))
			{
				LLSculptParams* sculpt=new LLSculptParams();
				sculpt->fromLLSD(prim_llsd["sculpt"]);
				LLUUID orig=sculpt->getSculptTexture();
				bool alreadyseen=false;
				for(iter = textures.begin(); iter != textures.end() ; iter++) 
				{
					if( (*iter)==orig)
						alreadyseen=true;
				}
				if(alreadyseen==false)
				{
					llinfos << "Found a new SCULPT texture to upload "<<orig<<llendl;			
					textures.push_back(orig);
				}
			}


			LLSD te_llsd;
			te_llsd=prim_llsd["textures"];

		
			for(text_it=te_llsd.beginArray(); text_it !=te_llsd.endArray(); text_it++)
			{
				LLSD the_te;
				the_te=(*text_it);
				LLTextureEntry te;
				te.fromLLSD(the_te);

				te.getID();
				bool alreadyseen=false;

				for(iter = textures.begin(); iter != textures.end() ; iter++) 
				{
					if( (*iter)==te.getID())
						alreadyseen=true;
				}
				if(alreadyseen==false)
				{
					llinfos << "Found a new texture to upload "<<te.getID()<<llendl;			
					textures.push_back(te.getID());
				}	     
			}

		}
	}

	if(m_retexture==TRUE)
		upload_next_asset();
	else
		import_object1a();
}