[sldev] [PATCH] Export Prims

Jürgen Lehmann lnxhkr at gmail.com
Tue Sep 25 20:46:49 PDT 2007


I saw a post earlier by Callum about working on an export/import prims
function, no sense in duplicating work so here is what I have so far.
Only export and it just writes very basic data to a hardcoded
filename, needs work. Patch was created against the 1.18.1.2 branch in
SVN.

Index: llviewermenu.cpp
===================================================================
--- llviewermenu.cpp    (revision 106)
+++ llviewermenu.cpp    (working copy)
@@ -1946,6 +1946,123 @@
     }
 };

+class LLObjectEnableExport : public view_listener_t
+{
+    bool handleEvent(LLPointer<LLEvent> event, const LLSD& userdata)
+    {
+        LLViewerObject* object = gViewerWindow->lastObjectHit();
+        bool new_value = (object != NULL);
+        if (new_value)
+        {
+            // Disable for avatars, we can only export prims
+            LLVOAvatar* avatar = find_avatar_from_object(object);
+            new_value = (avatar == NULL);
+        }
+        gMenuHolder->findControl(userdata["control"].asString())->setValue(new_value);
+        return true;
+    }
+};
+
+class LLObjectExport : public view_listener_t
+{
+    bool handleEvent(LLPointer<LLEvent> event, const LLSD& userdata)
+    {
+        LLViewerObject* object = gViewerWindow->lastObjectHit();
+        if (!object) return true;
+
+        LLVOAvatar* avatar = find_avatar_from_object(object);
+
+        // Can't export avatars (at least not yet...)
+        if (!avatar)
+        {
+            export_object();
+        }
+
+        return true;
+    }
+};
+
+void export_object()
+{
+    LLObjectSelectionHandle selection = gSelectMgr->getSelection();
+    LLViewerObject* root_object = NULL;
+    LLViewerObject* object = NULL;
+    LLSelectNode* node = selection->getFirstRootNode();
+    if(!node) return;
+
+    object = root_object = node->getObject();
+    if(!object) return;
+    if (object->isAvatar())
+    {
+        // ...don't export avatars
+        llwarns << "Exporting avatars is currently unsupported" << llendl;
+        return;
+    }
+
+    // Build a list of everything that we'll actually be exporting
+    LLDynamicArray<LLViewerObject*> export_objects;
+
+    // Add the root object to the export list
+    export_objects.put(object);
+
+    // Iterate over all of this objects children
+    LLViewerObject::child_list_t child_list = object->getChildren();
+
+    for (LLViewerObject::child_list_t::iterator i =
child_list.begin(); i != child_list.end(); ++i)
+    {
+        LLViewerObject* child = *i;
+
+        // Put the child objects on the export list
+        export_objects.put(child);
+    }
+
+    // FIXME: Open a save dialog instead of hardcoding this
+    std::ostringstream exportSaveName;
+    exportSaveName <<
gDirUtilp->getExpandedFilename(LL_PATH_PER_SL_ACCOUNT, "export.xml");
+    llofstream exportFile(exportSaveName.str().c_str());
+
+    // Create an LLSD object that will hold the entire tree structure
+    LLSD llsd;
+
+    S32 object_index = 0;
+
+    while((object_index < export_objects.count()))
+    {
+        object = export_objects.get(object_index++);
+        LLUUID id = object->getID();
+
+        llinfos << "Exporting prim " << object->getID().asString() << llendl;
+
+        // Create an LLSD object that represents this prim. It will
be injected in to the LLSD
+        // tree structure
+        LLSD prim_llsd;
+
+        prim_llsd["uuid"] = object->getID();
+        prim_llsd["localid"] = (int)object->getLocalID();
+        // FIXME: What is the proper protocol for storing vectors in LLSD?
+        //prim_llsd["position"] = object->getPosition();
+        //prim_llsd["scale"] = object->getScale();
+        // FIXME: What is the proper protocol for storing quaternions in LLSD?
+        //prim_llsd["rotation"] = object->getRotation();
+
+        LLVolumeParams params = object->getVolume()->getParams();
+        prim_llsd["volume"] = params.asLLSD();
+
+        // FIXME: Textures
+        // FIXME: Flex
+        // FIXME: Light
+        // FIXME: Sculpt
+
+        // TODO: Is this the best way to convert the localID integer
to a string?
+        std::stringstream ss;
+        ss << object->getLocalID();
+        llsd[ss.str().c_str()] = prim_llsd;
+    }
+
+    LLSDSerialize::toPrettyXML(llsd, exportFile);
+    exportFile.close();
+}
+
 bool handle_go_to()
 {
     // JAMESDEBUG try simulator autopilot
@@ -7767,6 +7884,7 @@
     addMenu(new LLObjectAttachToAvatar(), "Object.AttachToAvatar");
     addMenu(new LLObjectReturn(), "Object.Return");
     addMenu(new LLObjectReportAbuse(), "Object.ReportAbuse");
+    addMenu(new LLObjectExport(), "Object.Export");
     addMenu(new LLObjectMute(), "Object.Mute");
     addMenu(new LLObjectBuy(), "Object.Buy");
     addMenu(new LLObjectEdit(), "Object.Edit");
@@ -7779,6 +7897,7 @@
     addMenu(new LLObjectEnableWear(), "Object.EnableWear");
     addMenu(new LLObjectEnableReturn(), "Object.EnableReturn");
     addMenu(new LLObjectEnableReportAbuse(), "Object.EnableReportAbuse");
+    addMenu(new LLObjectEnableExport(), "Object.EnableExport");
     addMenu(new LLObjectEnableMute(), "Object.EnableMute");
     addMenu(new LLObjectEnableBuy(), "Object.EnableBuy");

Index: llviewermenu.h
===================================================================
--- llviewermenu.h    (revision 106)
+++ llviewermenu.h    (working copy)
@@ -104,6 +104,8 @@
 bool handle_object_open();
 bool handle_go_to();

+void export_object();
+
 // Export to XML or Collada
 void handle_export_selected( void * );

Index: skins/xui/en-us/menu_pie_object.xml
===================================================================
--- skins/xui/en-us/menu_pie_object.xml    (revision 106)
+++ skins/xui/en-us/menu_pie_object.xml    (working copy)
@@ -57,8 +57,12 @@
                 <on_enable function="Object.EnableReportAbuse" />
             </menu_item_call>
             <menu_item_separator />
+      <menu_item_call enabled="false" hidden="false" label="Export"
mouse_opaque="true"
+           name="Export">
+        <on_click function="Object.Export" />
+        <on_enable function="Object.EnableExport" />
+      </menu_item_call>
             <menu_item_separator />
-            <menu_item_separator />
             <menu_item_call enabled="false" hidden="false"
label="Mute" mouse_opaque="true"
                  name="Object Mute">
                 <on_click function="Object.Mute" />


More information about the SLDev mailing list