Update mesh export code, cause why not.

This commit is contained in:
Liru Færs
2020-04-07 15:30:13 -04:00
parent ae17f76bb4
commit c4af22481c
3 changed files with 112 additions and 139 deletions

View File

@@ -163,10 +163,11 @@ Wavefront::Wavefront(LLFace* face, LLPolyMesh* mesh, const LLXform* transform, c
if (transform_normals) Transform(normals, transform_normals); if (transform_normals) Transform(normals, transform_normals);
const U32 pcount = mesh ? mesh->getNumFaces() : (vb->getNumIndices()/3); //indices const U32 pcount = mesh ? mesh->getNumFaces() : (vb->getNumIndices()/3); //indices
const U16 offset = face->getIndicesStart(); //indices const U32 offset = face->getIndicesStart(); //indices
for (U32 i = 0; i < pcount; ++i) for (U32 i = 0; i < pcount; ++i)
{ {
triangles.push_back(tri(getIndices[i * 3 + offset] + start, getIndices[i * 3 + 1 + offset] + start, getIndices[i * 3 + 2 + offset] + start)); const auto off = i * 3 + offset;
triangles.push_back(tri(getIndices[off] + start, getIndices[off + 1] + start, getIndices[off + 2] + start));
} }
} }
@@ -174,9 +175,9 @@ void Wavefront::Transform(vert_t& v, const LLXform* x) //recursive
{ {
LLMatrix4 m; LLMatrix4 m;
x->getLocalMat4(m); x->getLocalMat4(m);
for (vert_t::iterator iterv = v.begin(); iterv != v.end(); ++iterv) for (auto& i : v)
{ {
iterv->first = iterv->first * m; i.first = i.first * m;
} }
if (const LLXform* xp = x->getParent()) Transform(v, xp); if (const LLXform* xp = x->getParent()) Transform(v, xp);
@@ -186,9 +187,9 @@ void Wavefront::Transform(vec3_t& v, const LLXform* x) //recursive
{ {
LLMatrix4 m; LLMatrix4 m;
x->getLocalMat4(m); x->getLocalMat4(m);
for (vec3_t::iterator iterv = v.begin(); iterv != v.end(); ++iterv) for (auto& i : v)
{ {
*iterv = *iterv * m; i = i * m;
} }
if (const LLXform* xp = x->getParent()) Transform(v, xp); if (const LLXform* xp = x->getParent()) Transform(v, xp);
@@ -252,9 +253,9 @@ namespace
asset_id_matches); asset_id_matches);
// See if any of the inventory items matching this sculpt id are exportable // See if any of the inventory items matching this sculpt id are exportable
for (U32 i = 0; i < items.size(); i++) for (const auto& item : items)
{ {
const LLPermissions item_permissions = items[i]->getPermissions(); const LLPermissions item_permissions = item->getPermissions();
if (item_permissions.allowExportBy(gAgentID, LFSimFeatureHandler::instance().exportPolicy())) if (item_permissions.allowExportBy(gAgentID, LFSimFeatureHandler::instance().exportPolicy()))
{ {
return true; return true;
@@ -269,9 +270,9 @@ namespace
} }
} }
class LFSaveSelectedObjects : public view_listener_t class LFSaveSelectedObjects final : public view_listener_t
{ {
bool handleEvent(LLPointer<LLOldEvents::LLEvent> event, const LLSD& userdata) bool handleEvent(LLPointer<LLOldEvents::LLEvent> event, const LLSD& userdata) override
{ {
if (LLObjectSelectionHandle selection = LLSelectMgr::getInstance()->getSelection()) if (LLObjectSelectionHandle selection = LLSelectMgr::getInstance()->getSelection())
{ {
@@ -288,10 +289,10 @@ namespace
S32 included = 0; S32 included = 0;
for (LLObjectSelection::iterator iter = selection->begin(); iter != selection->end(); ++iter) for (LLObjectSelection::iterator iter = selection->begin(); iter != selection->end(); ++iter)
{ {
total++; ++total;
LLSelectNode* node = *iter; LLSelectNode* node = *iter;
if (!can_export_node(node)) continue; if (!can_export_node(node)) continue;
included++; ++included;
wfsaver->Add(node->getObject()); wfsaver->Add(node->getObject());
} }
if (wfsaver->obj_v.empty()) if (wfsaver->obj_v.empty())
@@ -322,12 +323,12 @@ void WavefrontSaver::Add(const LLVOAvatar* av_vo) //adds attachments, too!
{ {
offset = -av_vo->getRenderPosition(); offset = -av_vo->getRenderPosition();
avatar_joint_list_t vjv = av_vo->mMeshLOD; avatar_joint_list_t vjv = av_vo->mMeshLOD;
for (avatar_joint_list_t::const_iterator itervj = vjv.begin(); itervj != vjv.end(); ++itervj) for (const auto& itervj : vjv)
{ {
const LLViewerJoint* vj = dynamic_cast<LLViewerJoint*>(*itervj); const auto* vj = dynamic_cast<const LLViewerJoint*>(itervj);
if (!vj || vj->mMeshParts.empty()) continue; if (!vj || vj->mMeshParts.empty()) continue;
LLViewerJointMesh* vjm = dynamic_cast<LLViewerJointMesh*>(vj->mMeshParts[0]); //highest LOD auto* vjm = dynamic_cast<LLViewerJointMesh*>(vj->mMeshParts[0]); //highest LOD
if (!vjm) continue; if (!vjm) continue;
vjm->updateJointGeometry(); vjm->updateJointGeometry();
@@ -355,21 +356,19 @@ void WavefrontSaver::Add(const LLVOAvatar* av_vo) //adds attachments, too!
Add(Wavefront(face, pm, NULL, &normfix)); Add(Wavefront(face, pm, NULL, &normfix));
} }
for (LLVOAvatar::attachment_map_t::const_iterator iter = av_vo->mAttachmentPoints.begin(); iter != av_vo->mAttachmentPoints.end(); ++iter) for (const auto& ap : av_vo->mAttachmentPoints)
{ {
LLViewerJointAttachment* ja = iter->second; LLViewerJointAttachment* ja = ap.second;
if (!ja) continue; if (!ja) continue;
for (LLViewerJointAttachment::attachedobjs_vec_t::iterator itero = ja->mAttachedObjects.begin(); itero != ja->mAttachedObjects.end(); ++itero) for (const auto& o : ja->mAttachedObjects)
{ {
LLViewerObject* o = *itero;
if (!o) continue; if (!o) continue;
std::vector<LLViewerObject*> prims; std::vector<LLViewerObject*> prims;
o->addThisAndAllChildren(prims); o->addThisAndAllChildren(prims);
for (std::vector<LLViewerObject* >::iterator iterc = prims.begin(); iterc != prims.end(); ++iterc) for (const auto& c : prims)
{ {
const LLViewerObject* c = *iterc;
if (!c) continue; if (!c) continue;
if (LLSelectNode* n = LLSelectMgr::getInstance()->getSelection()->findNode(const_cast<LLViewerObject*>(c))) if (LLSelectNode* n = LLSelectMgr::getInstance()->getSelection()->findNode(const_cast<LLViewerObject*>(c)))
{ {
@@ -400,9 +399,9 @@ void WavefrontSaver::Add(const LLVOAvatar* av_vo) //adds attachments, too!
} }
namespace namespace
{ {
class LFSaveSelectedAvatar : public view_listener_t class LFSaveSelectedAvatar final : public view_listener_t
{ {
bool handleEvent(LLPointer<LLOldEvents::LLEvent> event, const LLSD& userdata) bool handleEvent(LLPointer<LLOldEvents::LLEvent> event, const LLSD& userdata) override
{ {
if (const LLVOAvatar* avatar = find_avatar_from_object(LLSelectMgr::getInstance()->getSelection()->getPrimaryObject())) if (const LLVOAvatar* avatar = find_avatar_from_object(LLSelectMgr::getInstance()->getSelection()->getPrimaryObject()))
{ {
@@ -446,49 +445,48 @@ bool WavefrontSaver::saveFile(LLFILE* fp)
int num = 0; int num = 0;
int index = 0; int index = 0;
for (std::vector<Wavefront>::iterator w_iter = obj_v.begin(); w_iter != obj_v.end(); ++w_iter) for (const auto& obj : obj_v)
{ {
int count = 0; int count = 0;
std::string name = (*w_iter).name; std::string name = obj.name;
if (name.empty()) name = llformat("%d", num++); if (name.empty()) name = llformat("%d", num++);
vert_t vertices = (*w_iter).vertices; auto& vertices = obj.vertices;
vec3_t normals = (*w_iter).normals; auto& normals = obj.normals;
tri_t triangles = (*w_iter).triangles; auto& triangles = obj.triangles;
//Write Object //Write Object
write_or_bust(fp, "o " + name + "\n"); write_or_bust(fp, "o " + name + '\n');
//Write vertices; swap axes if necessary //Write vertices; swap axes if necessary
static const LLCachedControl<bool> swapYZ("OBJExportSwapYZ", false); static const LLCachedControl<bool> swapYZ("OBJExportSwapYZ", false);
const double xm = swapYZ ? -1.0 : 1.0; const double xm = swapYZ ? -1.0 : 1.0;
const int y = swapYZ ? 2 : 1; const int y = swapYZ ? 2 : 1;
const int z = swapYZ ? 1 : 2; const int z = swapYZ ? 1 : 2;
for (vert_t::iterator v_iter = vertices.begin(); v_iter != vertices.end(); ++v_iter) for (const auto& vert : vertices)
{ {
++count; ++count;
const LLVector3 v = v_iter->first + offset; const LLVector3 v = vert.first + offset;
write_or_bust(fp, llformat("v %f %f %f\n",v[0] * xm, v[y], v[z])); write_or_bust(fp, llformat("v %f %f %f\n",v[0] * xm, v[y], v[z]));
} }
for (vec3_t::iterator n_iter = normals.begin(); n_iter != normals.end(); ++n_iter) for (const auto& n : normals)
{ {
const LLVector3 n = *n_iter;
write_or_bust(fp, llformat("vn %f %f %f\n",n[0] * xm, n[y], n[z])); write_or_bust(fp, llformat("vn %f %f %f\n",n[0] * xm, n[y], n[z]));
} }
for (vert_t::iterator v_iter = vertices.begin(); v_iter != vertices.end(); ++v_iter) for (const auto& vert : vertices)
{ {
write_or_bust(fp, llformat("vt %f %f\n", v_iter->second[0], v_iter->second[1])); write_or_bust(fp, llformat("vt %f %f\n", vert.second[0], vert.second[1]));
} }
//Write triangles //Write triangles
for (tri_t::iterator t_iter = triangles.begin(); t_iter != triangles.end(); ++t_iter) for (const auto& triangle : triangles)
{ {
const int f1 = t_iter->v0 + index + 1; const int f1 = triangle.v0 + index + 1;
const int f2 = t_iter->v1 + index + 1; const int f2 = triangle.v1 + index + 1;
const int f3 = t_iter->v2 + index + 1; const int f3 = triangle.v2 + index + 1;
write_or_bust(fp, llformat("f %d/%d/%d %d/%d/%d %d/%d/%d\n", write_or_bust(fp, llformat("f %d/%d/%d %d/%d/%d %d/%d/%d\n",
f1,f1,f1,f2,f2,f2,f3,f3,f3)); f1,f1,f1,f2,f2,f2,f3,f3,f3));
} }

View File

@@ -32,16 +32,18 @@
// library includes // library includes
#include "aifilepicker.h" #include "aifilepicker.h"
#include "llavatarnamecache.h"
#include "llnotificationsutil.h" #include "llnotificationsutil.h"
// newview includes // newview includes
#include "lfsimfeaturehandler.h" #include "lfsimfeaturehandler.h"
#include "llface.h"
#include "llvovolume.h"
#include "llviewerinventory.h"
#include "llinventorymodel.h" #include "llinventorymodel.h"
#include "llinventoryfunctions.h" #include "llinventoryfunctions.h"
#include "llface.h"
#include "llversioninfo.h"
#include "llviewerinventory.h"
#include "llviewertexturelist.h" #include "llviewertexturelist.h"
#include "llvovolume.h"
// menu includes // menu includes
#include "llevent.h" #include "llevent.h"
@@ -74,11 +76,11 @@ typedef LLMemberListener<LLView> view_listener_t;
namespace DAEExportUtil namespace DAEExportUtil
{ {
static LLUUID LL_TEXTURE_PLYWOOD = LLUUID("89556747-24cb-43ed-920b-47caed15465f"); const auto LL_TEXTURE_PLYWOOD = LLUUID("89556747-24cb-43ed-920b-47caed15465f");
static LLUUID LL_TEXTURE_BLANK = LLUUID("5748decc-f629-461c-9a36-a35a221fe21f"); const auto LL_TEXTURE_BLANK = LLUUID("5748decc-f629-461c-9a36-a35a221fe21f");
static LLUUID LL_TEXTURE_INVISIBLE = LLUUID("38b86f85-2575-52a9-a531-23108d8da837"); const auto LL_TEXTURE_INVISIBLE = LLUUID("38b86f85-2575-52a9-a531-23108d8da837");
static LLUUID LL_TEXTURE_TRANSPARENT = LLUUID("8dcd4a48-2d37-4909-9f78-f7a9eb4ef903"); const auto LL_TEXTURE_TRANSPARENT = LLUUID("8dcd4a48-2d37-4909-9f78-f7a9eb4ef903");
static LLUUID LL_TEXTURE_MEDIA = LLUUID("8b5fec65-8d8d-9dc5-cda8-8fdf2716e361"); const auto LL_TEXTURE_MEDIA = LLUUID("8b5fec65-8d8d-9dc5-cda8-8fdf2716e361");
enum image_format_type enum image_format_type
{ {
@@ -105,23 +107,17 @@ namespace DAEExportUtil
// See if any of the inventory items matching this texture id are exportable // See if any of the inventory items matching this texture id are exportable
ExportPolicy policy = LFSimFeatureHandler::instance().exportPolicy(); ExportPolicy policy = LFSimFeatureHandler::instance().exportPolicy();
for (size_t i = 0; i < items.size(); i++) for (const auto& item : items)
{ {
const LLPermissions item_permissions = items[i]->getPermissions(); const LLPermissions item_permissions = item->getPermissions();
if (item_permissions.allowExportBy(gAgentID, policy)) if (item_permissions.allowExportBy(gAgentID, policy))
{ {
if (name != NULL) if (name) *name = item->getName();
{
(*name) = items[i]->getName();
}
return true; return true;
} }
} }
if (name != NULL) if (name) *name = id.getString();
{
(*name) = id.getString();
}
return (policy & ep_full_perm) == ep_full_perm; return (policy & ep_full_perm) == ep_full_perm;
} }
@@ -206,7 +202,7 @@ public:
} }
} }
BOOL postBuild() BOOL postBuild() override
{ {
mFileName = getChildView("file name editor"); mFileName = getChildView("file name editor");
mExportBtn = getChildView("export button"); mExportBtn = getChildView("export button");
@@ -306,14 +302,9 @@ public:
S32 getNumExportableTextures() S32 getNumExportableTextures()
{ {
S32 res = 0; S32 res = 0;
for (const auto& name : mSaver.mTextureNames)
for (DAESaver::string_list_t::const_iterator t = mSaver.mTextureNames.begin(); t != mSaver.mTextureNames.end(); ++t)
{ {
std::string name = *t; if (!name.empty()) ++res;
if (!name.empty())
{
++res;
}
} }
return res; return res;
@@ -365,7 +356,7 @@ public:
gIdleCallbacks.addFunction(saveTexturesWorker, this); gIdleCallbacks.addFunction(saveTexturesWorker, this);
} }
class CacheReadResponder : public LLTextureCache::ReadResponder class CacheReadResponder final : public LLTextureCache::ReadResponder
{ {
private: private:
LLPointer<LLImageFormatted> mFormattedImage; LLPointer<LLImageFormatted> mFormattedImage;
@@ -413,7 +404,7 @@ public:
mImageLocal = imagelocal; mImageLocal = imagelocal;
} }
virtual void completed(bool success) void completed(bool success) override
{ {
if (success && mFormattedImage.notNull() && mImageSize > 0) if (success && mFormattedImage.notNull() && mImageSize > 0)
{ {
@@ -546,10 +537,8 @@ void DAESaver::updateTextureInfo()
{ {
LLTextureEntry* te = obj->getTE(face_num); LLTextureEntry* te = obj->getTE(face_num);
const LLUUID id = te->getID(); const LLUUID id = te->getID();
if (std::find(mTextures.begin(), mTextures.end(), id) != mTextures.end()) if (std::find(mTextures.begin(), mTextures.end(), id) != mTextures.end()) continue;
{
continue;
}
mTextures.push_back(id); mTextures.push_back(id);
std::string name; std::string name;
if (id != DAEExportUtil::LL_TEXTURE_BLANK && DAEExportUtil::canExportTexture(id, &name)) if (id != DAEExportUtil::LL_TEXTURE_BLANK && DAEExportUtil::canExportTexture(id, &name))
@@ -566,7 +555,6 @@ void DAESaver::updateTextureInfo()
} }
} }
class v4adapt class v4adapt
{ {
private: private:
@@ -579,7 +567,7 @@ public:
} }
}; };
void DAESaver::addSource(daeElement* mesh, const char* src_id, std::string params, const std::vector<F32> &vals) void DAESaver::addSource(daeElement* mesh, const char* src_id, const std::string& params, const std::vector<F32> &vals)
{ {
daeElement* source = mesh->add("source"); daeElement* source = mesh->add("source");
source->setAttribute("id", src_id); source->setAttribute("id", src_id);
@@ -588,9 +576,9 @@ void DAESaver::addSource(daeElement* mesh, const char* src_id, std::string param
src_array->setAttribute("id", llformat("%s-%s", src_id, "array").c_str()); src_array->setAttribute("id", llformat("%s-%s", src_id, "array").c_str());
src_array->setAttribute("count", llformat("%d", vals.size()).c_str()); src_array->setAttribute("count", llformat("%d", vals.size()).c_str());
for (U32 i = 0; i < vals.size(); i++) for (const auto& val : vals)
{ {
((domFloat_array*)src_array)->getValue().append(vals[i]); static_cast<domFloat_array*>(src_array)->getValue().append(val);
} }
domAccessor* acc = daeSafeCast<domAccessor>(source->add("technique_common accessor")); domAccessor* acc = daeSafeCast<domAccessor>(source->add("technique_common accessor"));
@@ -598,10 +586,10 @@ void DAESaver::addSource(daeElement* mesh, const char* src_id, std::string param
acc->setCount(vals.size() / params.size()); acc->setCount(vals.size() / params.size());
acc->setStride(params.size()); acc->setStride(params.size());
for (std::string::iterator p_iter = params.begin(); p_iter != params.end(); ++p_iter) for (const auto& param : params)
{ {
domElement* pX = acc->add("param"); domElement* pX = acc->add("param");
pX->setAttribute("name", llformat("%c", *p_iter).c_str()); pX->setAttribute("name", (LLStringUtil::null + param).c_str());
pX->setAttribute("type", "float"); pX->setAttribute("type", "float");
} }
} }
@@ -650,7 +638,7 @@ void DAESaver::addPolygons(daeElement* mesh, const char* geomID, const char* mat
{ {
for (S32 i = 0; i < face->mNumIndices; i++) for (S32 i = 0; i < face->mNumIndices; i++)
{ {
U16 index = index_offset + face->mIndices[i]; U32 index = index_offset + face->mIndices[i];
(p->getValue()).append(index); (p->getValue()).append(index);
if (i % 3 == 0) if (i % 3 == 0)
{ {
@@ -710,11 +698,21 @@ void DAESaver::transformTexCoord(S32 num_vert, LLVector2* coord, LLVector3* posi
bool DAESaver::saveDAE(std::string filename) bool DAESaver::saveDAE(std::string filename)
{ {
// Collada expects file and folder names to be escaped
// Note: cdom::nativePathToUri()
// Same as in LLDAELoader::OpenFile()
const char* allowed =
"ABCDEFGHIJKLMNOPQRSTUVWXYZ"
"abcdefghijklmnopqrstuvwxyz"
"0123456789"
"%-._~:\"|\\/";
std::string uri_filename = LLURI::escape(filename, allowed);
mAllMaterials.clear(); mAllMaterials.clear();
mTotalNumMaterials = 0; mTotalNumMaterials = 0;
DAE dae; DAE dae;
// First set the filename to save // First set the filename to save
daeElement* root = dae.add(filename); daeElement* root = dae.add(uri_filename);
// Obligatory elements in header // Obligatory elements in header
daeElement* asset = root->add("asset"); daeElement* asset = root->add("asset");
@@ -734,9 +732,13 @@ bool DAESaver::saveDAE(std::string filename)
up_axis->setCharData("Z_UP"); up_axis->setCharData("Z_UP");
// File creator // File creator
std::string author;
if (!LLAvatarNameCache::getNSName(gAgentID, author))
author = "Unknown";
daeElement* contributor = asset->add("contributor"); daeElement* contributor = asset->add("contributor");
contributor->add("author")->setCharData(LLAppViewer::instance()->getSecondLifeTitle() + " User"); contributor->add("author")->setCharData(author);
contributor->add("authoring_tool")->setCharData(LLAppViewer::instance()->getSecondLifeTitle() + " Collada Export"); contributor->add("authoring_tool")->setCharData(LLVersionInfo::getChannelAndVersion() + " Collada Export");
daeElement* images = root->add("library_images"); daeElement* images = root->add("library_images");
daeElement* geomLib = root->add("library_geometries"); daeElement* geomLib = root->add("library_geometries");
@@ -825,7 +827,6 @@ bool DAESaver::saveDAE(std::string filename)
} }
} }
addSource(mesh, llformat("%s-%s", geomID, "positions").c_str(), "XYZ", position_data); addSource(mesh, llformat("%s-%s", geomID, "positions").c_str(), "XYZ", position_data);
addSource(mesh, llformat("%s-%s", geomID, "normals").c_str(), "XYZ", normal_data); addSource(mesh, llformat("%s-%s", geomID, "normals").c_str(), "XYZ", normal_data);
addSource(mesh, llformat("%s-%s", geomID, "map0").c_str(), "ST", uv_data); addSource(mesh, llformat("%s-%s", geomID, "map0").c_str(), "ST", uv_data);
@@ -845,12 +846,11 @@ bool DAESaver::saveDAE(std::string filename)
// Add triangles // Add triangles
if (gSavedSettings.getBOOL("DAEExportConsolidateMaterials")) if (gSavedSettings.getBOOL("DAEExportConsolidateMaterials"))
{ {
for (U32 objMaterial = 0; objMaterial < objMaterials.size(); objMaterial++) for (const auto& objMaterial : objMaterials)
{ {
int_list_t faces; int_list_t faces;
getFacesWithMaterial(obj, objMaterials[objMaterial], &faces); getFacesWithMaterial(obj, objMaterial, &faces);
std::string matName = objMaterials[objMaterial].name; addPolygons(mesh, geomID, (objMaterial.name + "-material").c_str(), obj, &faces);
addPolygons(mesh, geomID, (matName + "-material").c_str(), obj, &faces);
} }
} }
else else
@@ -888,12 +888,12 @@ bool DAESaver::saveDAE(std::string filename)
// Bind materials // Bind materials
daeElement* tq = nodeGeometry->add("bind_material technique_common"); daeElement* tq = nodeGeometry->add("bind_material technique_common");
for (U32 objMaterial = 0; objMaterial < objMaterials.size(); objMaterial++) for (const auto& objMaterial : objMaterials)
{ {
std::string matName = objMaterials[objMaterial].name;
daeElement* instanceMaterial = tq->add("instance_material"); daeElement* instanceMaterial = tq->add("instance_material");
instanceMaterial->setAttribute("symbol", (matName + "-material").c_str()); std::string matName = objMaterial.name + "-material";
instanceMaterial->setAttribute("target", ("#" + matName + "-material").c_str()); instanceMaterial->setAttribute("symbol", matName.c_str());
instanceMaterial->setAttribute("target", ('#' + matName).c_str());
} }
nodeGeometry->setAttribute("url", llformat("#%s-%s", geomID, "mesh").c_str()); nodeGeometry->setAttribute("url", llformat("#%s-%s", geomID, "mesh").c_str());
@@ -904,12 +904,12 @@ bool DAESaver::saveDAE(std::string filename)
generateEffects(effects); generateEffects(effects);
// Materials // Materials
for (U32 objMaterial = 0; objMaterial < mAllMaterials.size(); objMaterial++) for (const auto& objMaterial : mAllMaterials)
{ {
daeElement* mat = materials->add("material"); daeElement* mat = materials->add("material");
mat->setAttribute("id", (mAllMaterials[objMaterial].name + "-material").c_str()); mat->setAttribute("id", (objMaterial.name + "-material").c_str());
daeElement* matEffect = mat->add("instance_effect"); daeElement* matEffect = mat->add("instance_effect");
matEffect->setAttribute("url", ("#" + mAllMaterials[objMaterial].name + "-fx").c_str()); matEffect->setAttribute("url", ('#' + objMaterial.name + "-fx").c_str());
} }
root->add("scene instance_visual_scene")->setAttribute("url", "#Scene"); root->add("scene instance_visual_scene")->setAttribute("url", "#Scene");
@@ -930,11 +930,11 @@ DAESaver::MaterialInfo DAESaver::getMaterial(LLTextureEntry* te)
{ {
if (gSavedSettings.getBOOL("DAEExportConsolidateMaterials")) if (gSavedSettings.getBOOL("DAEExportConsolidateMaterials"))
{ {
for (U32 i=0; i < mAllMaterials.size(); i++) for (const auto& mat : mAllMaterials)
{ {
if (mAllMaterials[i].matches(te)) if (mat.matches(te))
{ {
return mAllMaterials[i]; return mat;
} }
} }
} }
@@ -944,7 +944,7 @@ DAESaver::MaterialInfo DAESaver::getMaterial(LLTextureEntry* te)
ret.color = te->getColor(); ret.color = te->getColor();
ret.name = llformat("Material%d", mAllMaterials.size()); ret.name = llformat("Material%d", mAllMaterials.size());
mAllMaterials.push_back(ret); mAllMaterials.push_back(ret);
return mAllMaterials[mAllMaterials.size() - 1]; return ret;
} }
void DAESaver::getMaterials(LLViewerObject* obj, material_list_t* ret) void DAESaver::getMaterials(LLViewerObject* obj, material_list_t* ret)
@@ -954,10 +954,7 @@ void DAESaver::getMaterials(LLViewerObject* obj, material_list_t* ret)
{ {
LLTextureEntry* te = obj->getTE(face_num); LLTextureEntry* te = obj->getTE(face_num);
if (skipFace(te)) if (skipFace(te)) continue;
{
continue;
}
MaterialInfo mat = getMaterial(te); MaterialInfo mat = getMaterial(te);
@@ -968,7 +965,7 @@ void DAESaver::getMaterials(LLViewerObject* obj, material_list_t* ret)
} }
} }
void DAESaver::getFacesWithMaterial(LLViewerObject* obj, MaterialInfo& mat, int_list_t* ret) void DAESaver::getFacesWithMaterial(LLViewerObject* obj, const MaterialInfo& mat, int_list_t* ret)
{ {
S32 num_faces = obj->getVolume()->getNumVolumeFaces(); S32 num_faces = obj->getVolume()->getNumVolumeFaces();
for (S32 face_num = 0; face_num < num_faces; ++face_num) for (S32 face_num = 0; face_num < num_faces; ++face_num)
@@ -985,11 +982,11 @@ void DAESaver::generateEffects(daeElement *effects)
// Effects (face color, alpha) // Effects (face color, alpha)
bool export_textures = gSavedSettings.getBOOL("DAEExportTextures"); bool export_textures = gSavedSettings.getBOOL("DAEExportTextures");
for (U32 mat = 0; mat < mAllMaterials.size(); mat++) for (const auto& mat : mAllMaterials)
{ {
LLColor4 color = mAllMaterials[mat].color; LLColor4 color = mat.color;
domEffect* effect = (domEffect*)effects->add("effect"); domEffect* effect = (domEffect*)effects->add("effect");
effect->setId((mAllMaterials[mat].name + "-fx").c_str()); effect->setId((mat.name + "-fx").c_str());
daeElement* profile = effect->add("profile_COMMON"); daeElement* profile = effect->add("profile_COMMON");
std::string colladaName; std::string colladaName;
@@ -999,7 +996,7 @@ void DAESaver::generateEffects(daeElement *effects)
U32 i = 0; U32 i = 0;
for (; i < mTextures.size(); i++) for (; i < mTextures.size(); i++)
{ {
if (mAllMaterials[mat].textureID == mTextures[i]) if (mat.textureID == mTextures[i])
{ {
textID = mTextures[i]; textID = mTextures[i];
break; break;
@@ -1043,19 +1040,18 @@ void DAESaver::generateEffects(daeElement *effects)
void DAESaver::generateImagesSection(daeElement* images) void DAESaver::generateImagesSection(daeElement* images)
{ {
for (U32 i=0; i < mTextureNames.size(); i++) for (const auto& name : mTextureNames)
{ {
std::string name = mTextureNames[i];
if (name.empty()) continue; if (name.empty()) continue;
std::string colladaName = name + "_" + mImageFormat; std::string colladaName = name + '_' + mImageFormat;
daeElement* image = images->add("image"); daeElement* image = images->add("image");
image->setAttribute("id", colladaName.c_str()); image->setAttribute("id", colladaName.c_str());
image->setAttribute("name", colladaName.c_str()); image->setAttribute("name", colladaName.c_str());
image->add("init_from")->setCharData(LLURI::escape(name + "." + mImageFormat)); image->add("init_from")->setCharData(LLURI::escape(name + '.' + mImageFormat));
} }
} }
class DAESaveSelectedObjects : public view_listener_t class DAESaveSelectedObjects final : public view_listener_t
{ {
bool handleEvent(LLPointer<LLOldEvents::LLEvent> event, const LLSD& userdata) bool handleEvent(LLPointer<LLOldEvents::LLEvent> event, const LLSD& userdata)
{ {

View File

@@ -33,50 +33,29 @@ class LLViewerObject;
class DAESaver class DAESaver
{ {
public: public:
class MaterialInfo struct MaterialInfo
{ {
public:
LLUUID textureID; LLUUID textureID;
LLColor4 color; LLColor4 color;
std::string name; std::string name;
bool matches(LLTextureEntry* te) bool matches(LLTextureEntry* te) const
{ {
return (textureID == te->getID()) && (color == te->getColor()); return (textureID == te->getID()) && (color == te->getColor());
} }
bool operator== (const MaterialInfo& rhs) bool operator== (const MaterialInfo& rhs) const
{ {
return (textureID == rhs.textureID) && (color == rhs.color) && (name == rhs.name); return (textureID == rhs.textureID) && (color == rhs.color) && (name == rhs.name);
} }
bool operator!= (const MaterialInfo& rhs) bool operator!= (const MaterialInfo& rhs) const
{ {
return !(*this == rhs); return !(*this == rhs);
} }
MaterialInfo()
{
}
MaterialInfo(const MaterialInfo& rhs)
{
textureID = rhs.textureID;
color = rhs.color;
name = rhs.name;
}
MaterialInfo& operator= (const MaterialInfo& rhs)
{
textureID = rhs.textureID;
color = rhs.color;
name = rhs.name;
return *this;
}
}; };
typedef std::vector<std::pair<LLViewerObject*,std::string> > obj_info_t; typedef std::vector<std::pair<LLViewerObject*,std::string>> obj_info_t;
typedef uuid_vec_t id_list_t; typedef uuid_vec_t id_list_t;
typedef std::vector<std::string> string_list_t; typedef std::vector<std::string> string_list_t;
typedef std::vector<S32> int_list_t; typedef std::vector<S32> int_list_t;
@@ -97,12 +76,12 @@ public:
private: private:
void transformTexCoord(S32 num_vert, LLVector2* coord, LLVector3* positions, LLVector3* normals, LLTextureEntry* te, LLVector3 scale); void transformTexCoord(S32 num_vert, LLVector2* coord, LLVector3* positions, LLVector3* normals, LLTextureEntry* te, LLVector3 scale);
void addSource(daeElement* mesh, const char* src_id, std::string params, const std::vector<F32> &vals); void addSource(daeElement* mesh, const char* src_id, const std::string& params, const std::vector<F32> &vals);
void addPolygons(daeElement* mesh, const char* geomID, const char* materialID, LLViewerObject* obj, int_list_t* faces_to_include); void addPolygons(daeElement* mesh, const char* geomID, const char* materialID, LLViewerObject* obj, int_list_t* faces_to_include);
bool skipFace(LLTextureEntry *te); bool skipFace(LLTextureEntry *te);
MaterialInfo getMaterial(LLTextureEntry* te); MaterialInfo getMaterial(LLTextureEntry* te);
void getMaterials(LLViewerObject* obj, material_list_t* ret); void getMaterials(LLViewerObject* obj, material_list_t* ret);
void getFacesWithMaterial(LLViewerObject* obj, MaterialInfo& mat, int_list_t* ret); void getFacesWithMaterial(LLViewerObject* obj, const MaterialInfo& mat, int_list_t* ret);
void generateEffects(daeElement *effects); void generateEffects(daeElement *effects);
void generateImagesSection(daeElement* images); void generateImagesSection(daeElement* images);
}; };