Added Wavefront OBJ format exporter
Exporter written by Apelsin: https://github.com/Apelsin TODO: Hookup avatar export
This commit is contained in:
@@ -171,6 +171,7 @@
|
||||
#include "shfloatermediaticker.h"
|
||||
#include "llpacketring.h"
|
||||
#include "aihttpview.h"
|
||||
#include "awavefront.h"
|
||||
// </edit>
|
||||
|
||||
#include "scriptcounter.h"
|
||||
@@ -488,6 +489,11 @@ void handle_mesh_save_obj(void*);
|
||||
void handle_mesh_load_obj(void*);
|
||||
void handle_morph_save_obj(void*);
|
||||
void handle_morph_load_obj(void*);
|
||||
void save_avatar_to_obj(LLVOAvatar *avatar);
|
||||
void save_selected_avatar_to_obj();
|
||||
void save_selected_objects_to_obj();
|
||||
void save_wavefront_continued(WavefrontSaver* wfsaver, AIFilePicker* filepicker);
|
||||
void handle_save_current_avatar_obj(void*);
|
||||
void handle_debug_avatar_textures(void*);
|
||||
void handle_dump_region_object_cache(void*);
|
||||
|
||||
@@ -700,7 +706,6 @@ void init_menus()
|
||||
gAttachSubMenu = gMenuBarView->getChildMenuByName("Attach Object", TRUE);
|
||||
gDetachSubMenu = gMenuBarView->getChildMenuByName("Detach Object", TRUE);
|
||||
|
||||
// TomY TODO convert these two
|
||||
LLMenuGL*menu;
|
||||
|
||||
// <dogmode>
|
||||
@@ -6132,6 +6137,24 @@ class LLAvatarInviteToGroup : public view_listener_t
|
||||
}
|
||||
};
|
||||
|
||||
class LLAvatarSaveAsOBJ : public view_listener_t
|
||||
{
|
||||
bool handleEvent(LLPointer<LLEvent> event, const LLSD& userdata)
|
||||
{
|
||||
save_selected_avatar_to_obj();
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
||||
class LLSelectionSaveAsOBJ : public view_listener_t
|
||||
{
|
||||
bool handleEvent(LLPointer<LLEvent> event, const LLSD& userdata)
|
||||
{
|
||||
save_selected_objects_to_obj();
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
||||
class LLAvatarAddFriend : public view_listener_t
|
||||
{
|
||||
bool handleEvent(LLPointer<LLEvent> event, const LLSD& userdata)
|
||||
@@ -8515,6 +8538,104 @@ static void handle_morph_load_obj_continued(void* data, AIFilePicker* filepicker
|
||||
morph_data->setMorphFromMesh(&mesh);
|
||||
}
|
||||
|
||||
void handle_save_current_avatar_obj(void* data)
|
||||
{
|
||||
if(gAgentAvatarp)
|
||||
save_avatar_to_obj(gAgentAvatarp);
|
||||
}
|
||||
|
||||
void save_selected_avatar_to_obj()
|
||||
{
|
||||
LLVOAvatar* avatar = find_avatar_from_object( LLSelectMgr::getInstance()->getSelection()->getPrimaryObject() );
|
||||
if(avatar)
|
||||
save_avatar_to_obj(avatar);
|
||||
}
|
||||
|
||||
void save_avatar_to_obj(LLVOAvatar *avatar)
|
||||
{
|
||||
std::string file_name = llformat("%s.obj", avatar->getFullname().c_str());
|
||||
std::string full_path = gDirUtilp->getExpandedFilename(LL_PATH_NONE, file_name);
|
||||
|
||||
WavefrontSaver* wfsaver = new WavefrontSaver();
|
||||
wfsaver->Add((LLVOAvatar*)avatar);
|
||||
|
||||
AIFilePicker* filepicker = AIFilePicker::create();
|
||||
filepicker->open(full_path);
|
||||
filepicker->run(boost::bind(&save_wavefront_continued, wfsaver, filepicker));
|
||||
}
|
||||
|
||||
void save_selected_objects_to_obj()
|
||||
{
|
||||
struct ff : public LLSelectedNodeFunctor
|
||||
{
|
||||
virtual bool apply(LLSelectNode* node)
|
||||
{
|
||||
return LLObjectBackup::getInstance()->validatePerms(node->mPermissions);
|
||||
}
|
||||
} func;
|
||||
|
||||
LLObjectSelectionHandle selection = LLSelectMgr::getInstance()->getSelection();
|
||||
|
||||
if(!selection)
|
||||
return;
|
||||
|
||||
if (!selection->applyToNodes(&func, false))
|
||||
{
|
||||
llwarns << "Incorrect permissions: Wavefront OBJ export aborted" << llendl;
|
||||
LLSD args;
|
||||
args["REASON"] = "Insufficient Permissions";
|
||||
LLNotificationsUtil::add("WavefrontExportFailed", args);
|
||||
return;
|
||||
}
|
||||
|
||||
std::string file_name = llformat("%s.obj", selection->getFirstNode()->mName.c_str());
|
||||
std::string full_path = gDirUtilp->getExpandedFilename(LL_PATH_NONE, file_name);
|
||||
|
||||
WavefrontSaver* wfsaver = new WavefrontSaver();
|
||||
LLSelectNode* root_one = (LLSelectNode *)*selection->root_begin();
|
||||
wfsaver->offset = -root_one->getObject()->getRenderPosition();
|
||||
for (LLObjectSelection::iterator iter = selection->begin();
|
||||
iter != selection->end(); iter++)
|
||||
{
|
||||
LLSelectNode* node = *iter;
|
||||
LLViewerObject* object = node->getObject();
|
||||
wfsaver->Add(object);
|
||||
}
|
||||
|
||||
AIFilePicker* filepicker = AIFilePicker::create();
|
||||
filepicker->open(full_path);
|
||||
filepicker->run(boost::bind(&save_wavefront_continued, wfsaver, filepicker));
|
||||
}
|
||||
|
||||
void save_wavefront_continued(WavefrontSaver* wfsaver, AIFilePicker* filepicker)
|
||||
{
|
||||
if (!filepicker->hasFilename())
|
||||
{
|
||||
llwarns << "No file; bailing" << llendl;
|
||||
return;
|
||||
}
|
||||
std::string selected_filename = filepicker->getFilename();
|
||||
LLFILE* fp = LLFile::fopen(selected_filename, "wb");
|
||||
if (!fp)
|
||||
{
|
||||
llerrs << "can't open: " << selected_filename << llendl;
|
||||
return;
|
||||
}
|
||||
try
|
||||
{
|
||||
wfsaver->saveFile(fp);
|
||||
}
|
||||
catch(int e)
|
||||
{
|
||||
llwarns << "An exception occurred while generating / saving OBJ file. Exception #" << e << llendl;
|
||||
}
|
||||
llinfos << "OBJ file saved to " << selected_filename << llendl;
|
||||
LLSD args;
|
||||
args["FILENAME"] = selected_filename;
|
||||
LLNotificationsUtil::add("WavefrontExportSuccess", args);
|
||||
fclose(fp);
|
||||
}
|
||||
|
||||
// Returns a pointer to the avatar give the UUID of the avatar OR of an attachment the avatar is wearing.
|
||||
// Returns NULL on failure.
|
||||
LLVOAvatar* find_avatar_from_object( LLViewerObject* object )
|
||||
@@ -9388,6 +9509,7 @@ void initialize_menus()
|
||||
addMenu(new LLAvatarEnableFreezeEject(), "Avatar.EnableFreezeEject");
|
||||
addMenu(new LLAvatarCopyUUID(), "Avatar.CopyUUID");
|
||||
addMenu(new LLAvatarClientUUID(), "Avatar.ClientID");
|
||||
addMenu(new LLAvatarSaveAsOBJ(), "Avatar.SaveAsOBJ");
|
||||
|
||||
// Object pie menu
|
||||
addMenu(new LLObjectOpen(), "Object.Open");
|
||||
@@ -9419,7 +9541,8 @@ void initialize_menus()
|
||||
addMenu(new LLObjectExport(), "Object.Export");
|
||||
addMenu(new LLObjectImport(), "Object.Import");
|
||||
addMenu(new LLObjectImportUpload(), "Object.ImportUpload");
|
||||
|
||||
addMenu(new LLSelectionSaveAsOBJ(), "Object.SaveAsOBJ");
|
||||
|
||||
|
||||
addMenu(new LLObjectEnableOpen(), "Object.EnableOpen");
|
||||
addMenu(new LLObjectEnableTouch(), "Object.EnableTouch");
|
||||
|
||||
Reference in New Issue
Block a user