summaryrefslogtreecommitdiff
path: root/indra
diff options
context:
space:
mode:
Diffstat (limited to 'indra')
-rwxr-xr-xindra/newview/llfloatermodelpreview.cpp1279
1 files changed, 640 insertions, 639 deletions
diff --git a/indra/newview/llfloatermodelpreview.cpp b/indra/newview/llfloatermodelpreview.cpp
index 1050e86060..adf8302e9d 100755
--- a/indra/newview/llfloatermodelpreview.cpp
+++ b/indra/newview/llfloatermodelpreview.cpp
@@ -1,25 +1,25 @@
-/**
+/**
* @file llfloatermodelpreview.cpp
* @brief LLFloaterModelPreview class implementation
*
* $LicenseInfo:firstyear=2004&license=viewerlgpl$
* Second Life Viewer Source Code
* Copyright (C) 2010, Linden Research, Inc.
- *
+ *
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation;
* version 2.1 of the License only.
- *
+ *
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
- *
+ *
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
- *
+ *
* Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA
* $/LicenseInfo$
*/
@@ -111,7 +111,7 @@ const S32 PREVIEW_TEXTURE_HEIGHT = 300;
void drawBoxOutline(const LLVector3& pos, const LLVector3& size);
-std::string lod_name[NUM_LOD+1] =
+std::string lod_name[NUM_LOD+1] =
{
"lowest",
"low",
@@ -119,7 +119,7 @@ std::string lod_name[NUM_LOD+1] =
"high",
"I went off the end of the lod_name array. Me so smart."
};
-
+
std::string lod_triangles_name[NUM_LOD+1] =
{
"lowest_triangles",
@@ -147,7 +147,7 @@ std::string lod_status_name[NUM_LOD+1] =
"I went off the end of the lod_status_name array. Me so smart."
};
-std::string lod_icon_name[NUM_LOD+1] =
+std::string lod_icon_name[NUM_LOD+1] =
{
"status_icon_lowest",
"status_icon_low",
@@ -156,7 +156,7 @@ std::string lod_icon_name[NUM_LOD+1] =
"I went off the end of the lod_status_name array. Me so smart."
};
-std::string lod_status_image[NUM_LOD+1] =
+std::string lod_status_image[NUM_LOD+1] =
{
"ModelImport_Status_Good",
"ModelImport_Status_Warning",
@@ -184,7 +184,7 @@ bool validate_face(const LLVolumeFace& face)
return false;
}
}
-
+
return true;
}
@@ -195,7 +195,7 @@ bool validate_model(const LLModel* mdl)
llwarns << "Model has no faces!" << llendl;
return false;
}
-
+
for (S32 i = 0; i < mdl->getNumVolumeFaces(); ++i)
{
if (mdl->getVolumeFace(i).mNumVertices == 0)
@@ -203,36 +203,36 @@ bool validate_model(const LLModel* mdl)
llwarns << "Face has no vertices." << llendl;
return false;
}
-
+
if (mdl->getVolumeFace(i).mNumIndices == 0)
{
llwarns << "Face has no indices." << llendl;
return false;
}
-
+
if (!validate_face(mdl->getVolumeFace(i)))
{
return false;
}
}
-
+
return true;
}
BOOL stop_gloderror()
{
GLuint error = glodGetError();
-
+
if (error != GLOD_NO_ERROR)
{
llwarns << "GLOD error detected, cannot generate LOD: " << std::hex << error << llendl;
return TRUE;
}
-
+
return FALSE;
}
-
+
LLMeshFilePicker::LLMeshFilePicker(LLModelPreview* mp, S32 lod)
: LLFilePickerThread(LLFilePicker::FFLOAD_COLLADA)
{
@@ -249,7 +249,7 @@ void LLMeshFilePicker::notify(const std::string& filename)
//-----------------------------------------------------------------------------
// LLFloaterModelPreview()
//-----------------------------------------------------------------------------
-LLFloaterModelPreview::LLFloaterModelPreview(const LLSD& key) :
+LLFloaterModelPreview::LLFloaterModelPreview(const LLSD& key) :
LLFloater(key)
{
sInstance = this;
@@ -268,14 +268,14 @@ BOOL LLFloaterModelPreview::postBuild()
{
return FALSE;
}
-
+
setViewOption("show_textures", true);
-
+
childSetAction("lod_browse", onBrowseLOD, this);
-
+
childSetCommitCallback("crease_angle", onGenerateNormalsCommit, this);
childSetCommitCallback("generate_normals", onGenerateNormalsCommit, this);
-
+
childSetCommitCallback("lod_generate", onAutoFillCommit, this);
childSetCommitCallback("lod_mode", onLODParamCommit, this);
@@ -285,51 +285,51 @@ BOOL LLFloaterModelPreview::postBuild()
childSetCommitCallback("queue_mode", onLODParamCommit, this);
childSetCommitCallback("border_mode", onLODParamCommit, this);
childSetCommitCallback("share_tolerance", onLODParamCommit, this);
-
+
childSetTextArg("status", "[STATUS]", getString("status_idle"));
-
+
//childSetLabelArg("ok_btn", "[AMOUNT]", llformat("%d",sUploadAmount));
childSetAction("ok_btn", onUpload, this);
childDisable("ok_btn");
-
+
childSetAction("clear_materials", onClearMaterials, this);
-
+
childSetCommitCallback("preview_lod_combo", onPreviewLODCommit, this);
-
+
childSetCommitCallback("upload_skin", onUploadSkinCommit, this);
childSetCommitCallback("upload_joints", onUploadJointsCommit, this);
-
+
childSetCommitCallback("import_scale", onImportScaleCommit, this);
childSetCommitCallback("lod_file_or_limit", refresh, this);
childSetCommitCallback("physics_load_radio", refresh, this);
//childSetCommitCallback("physics_optimize", refresh, this);
//childSetCommitCallback("physics_use_hull", refresh, this);
-
+
childDisable("upload_skin");
childDisable("upload_joints");
- childDisable("ok_btn");
-
+ childDisable("ok_btn");
+
mViewOptionMenuButton = getChild<LLMenuButton>("options_gear_btn");
mCommitCallbackRegistrar.add("ModelImport.ViewOption.Action", boost::bind(&LLFloaterModelPreview::onViewOptionChecked, this, _2));
mEnableCallbackRegistrar.add("ModelImport.ViewOption.Check", boost::bind(&LLFloaterModelPreview::isViewOptionChecked, this, _2));
mEnableCallbackRegistrar.add("ModelImport.ViewOption.Enabled", boost::bind(&LLFloaterModelPreview::isViewOptionEnabled, this, _2));
-
-
+
+
mViewOptionMenu = LLUICtrlFactory::getInstance()->createFromFile<LLToggleableMenu>("menu_model_import_gear_default.xml", gMenuHolder, LLViewerMenuHolderGL::child_registry_t::instance());
mViewOptionMenuButton->setMenu(mViewOptionMenu, LLMenuButton::MP_BOTTOM_LEFT);
initDecompControls();
-
+
LLView* preview_panel = getChild<LLView>("preview_panel");
mPreviewRect = preview_panel->getRect();
-
+
mModelPreview = new LLModelPreview(512, 512, this);
mModelPreview->setPreviewTarget(16.f);
-
+
//set callbacks for left click on line editor rows
for (U32 i = 0; i <= LLModel::LOD_HIGH; i++)
{
@@ -357,7 +357,7 @@ BOOL LLFloaterModelPreview::postBuild()
text->setMouseDownCallback(boost::bind(&LLModelPreview::setPreviewLOD, mModelPreview, i));
}
}
-
+
return TRUE;
}
@@ -367,14 +367,14 @@ BOOL LLFloaterModelPreview::postBuild()
LLFloaterModelPreview::~LLFloaterModelPreview()
{
sInstance = NULL;
-
+
if ( mModelPreview->containsRiggedAsset() )
{
gAgentAvatarp->resetJointPositions();
}
-
+
delete mModelPreview;
-
+
if (mGLName)
{
LLImageGL::deleteTextures(1, &mGLName );
@@ -423,47 +423,47 @@ void LLFloaterModelPreview::setViewOption(const std::string& option, bool value)
void LLFloaterModelPreview::loadModel(S32 lod)
{
mModelPreview->mLoading = true;
-
+
(new LLMeshFilePicker(mModelPreview, lod))->getFile();
}
-//static
+//static
void LLFloaterModelPreview::onImportScaleCommit(LLUICtrl*,void* userdata)
{
LLFloaterModelPreview *fp =(LLFloaterModelPreview *)userdata;
-
+
if (!fp->mModelPreview)
{
return;
}
-
+
fp->mModelPreview->calcResourceCost();
fp->mModelPreview->refresh();
}
-//static
+//static
void LLFloaterModelPreview::onUploadJointsCommit(LLUICtrl*,void* userdata)
{
LLFloaterModelPreview *fp =(LLFloaterModelPreview *)userdata;
-
+
if (!fp->mModelPreview)
{
return;
}
-
+
fp->mModelPreview->refresh();
}
-//static
+//static
void LLFloaterModelPreview::onUploadSkinCommit(LLUICtrl*,void* userdata)
{
LLFloaterModelPreview *fp =(LLFloaterModelPreview *)userdata;
-
+
if (!fp->mModelPreview)
{
return;
}
-
+
fp->mModelPreview->refresh();
fp->mModelPreview->resetPreviewTarget();
fp->mModelPreview->clearBuffers();
@@ -473,16 +473,16 @@ void LLFloaterModelPreview::onUploadSkinCommit(LLUICtrl*,void* userdata)
void LLFloaterModelPreview::onPreviewLODCommit(LLUICtrl* ctrl, void* userdata)
{
LLFloaterModelPreview *fp =(LLFloaterModelPreview *)userdata;
-
+
if (!fp->mModelPreview)
{
return;
}
-
+
S32 which_mode = 0;
-
+
LLComboBox* combo = (LLComboBox*) ctrl;
-
+
which_mode = (NUM_LOD-1)-combo->getFirstSelectedIndex(); // combo box list of lods is in reverse order
fp->mModelPreview->setPreviewLOD(which_mode);
@@ -492,7 +492,7 @@ void LLFloaterModelPreview::onPreviewLODCommit(LLUICtrl* ctrl, void* userdata)
void LLFloaterModelPreview::onGenerateNormalsCommit(LLUICtrl* ctrl, void* userdata)
{
LLFloaterModelPreview* fp = (LLFloaterModelPreview*) userdata;
-
+
fp->mModelPreview->generateNormals();
}
@@ -500,19 +500,19 @@ void LLFloaterModelPreview::onGenerateNormalsCommit(LLUICtrl* ctrl, void* userda
void LLFloaterModelPreview::onExplodeCommit(LLUICtrl* ctrl, void* userdata)
{
LLFloaterModelPreview* fp = LLFloaterModelPreview::sInstance;
-
+
fp->mModelPreview->refresh();
}
-//static
+//static
void LLFloaterModelPreview::onAutoFillCommit(LLUICtrl* ctrl, void* userdata)
{
LLFloaterModelPreview* fp = (LLFloaterModelPreview*) userdata;
-
+
fp->mModelPreview->genLODs();
}
-//static
+//static
void LLFloaterModelPreview::onLODParamCommit(LLUICtrl* ctrl, void* userdata)
{
LLFloaterModelPreview* fp = (LLFloaterModelPreview*) userdata;
@@ -529,38 +529,38 @@ void LLFloaterModelPreview::draw()
{
LLFloater::draw();
LLRect r = getRect();
-
+
mModelPreview->update();
-
+
if (!mModelPreview->mLoading)
{
childSetTextArg("status", "[STATUS]", getString("status_idle"));
}
-
+
childSetTextArg("prim_cost", "[PRIM_COST]", llformat("%d", mModelPreview->mResourceCost));
childSetTextArg("description_label", "[TEXTURES]", llformat("%d", mModelPreview->mTextureSet.size()));
-
+
if (!mCurRequest.empty())
{
LLMutexLock lock(mStatusLock);
childSetTextArg("status", "[STATUS]", mStatusMessage);
}
-
+
U32 resource_cost = mModelPreview->mResourceCost*10;
-
+
if (childGetValue("upload_textures").asBoolean())
{
resource_cost += mModelPreview->mTextureSet.size()*10;
}
-
+
childSetLabelArg("ok_btn", "[AMOUNT]", llformat("%d", resource_cost));
-
+
if (mModelPreview)
{
gGL.color3f(1.f, 1.f, 1.f);
-
+
gGL.getTexUnit(0)->bind(mModelPreview);
-
+
LLView* preview_panel = getChild<LLView>("preview_panel");
@@ -570,7 +570,7 @@ void LLFloaterModelPreview::draw()
mModelPreview->refresh();
mPreviewRect = preview_panel->getRect();
}
-
+
gGL.begin( LLRender::QUADS );
{
gGL.texCoord2f(0.f, 1.f);
@@ -583,7 +583,7 @@ void LLFloaterModelPreview::draw()
gGL.vertex2i(mPreviewRect.mRight, mPreviewRect.mTop);
}
gGL.end();
-
+
gGL.getTexUnit(0)->unbind(LLTexUnit::TT_TEXTURE);
}
}
@@ -602,7 +602,7 @@ BOOL LLFloaterModelPreview::handleMouseDown(S32 x, S32 y, MASK mask)
mLastMouseY = y;
return TRUE;
}
-
+
return LLFloater::handleMouseDown(x, y, mask);
}
@@ -622,7 +622,7 @@ BOOL LLFloaterModelPreview::handleMouseUp(S32 x, S32 y, MASK mask)
BOOL LLFloaterModelPreview::handleHover (S32 x, S32 y, MASK mask)
{
MASK local_mask = mask & ~MASK_ALT;
-
+
if (mModelPreview && hasMouseCapture())
{
if (local_mask == MASK_PAN)
@@ -634,25 +634,25 @@ BOOL LLFloaterModelPreview::handleHover (S32 x, S32 y, MASK mask)
{
F32 yaw_radians = (F32)(x - mLastMouseX) * -0.01f;
F32 pitch_radians = (F32)(y - mLastMouseY) * 0.02f;
-
+
mModelPreview->rotate(yaw_radians, pitch_radians);
}
- else
+ else
{
-
+
F32 yaw_radians = (F32)(x - mLastMouseX) * -0.01f;
F32 zoom_amt = (F32)(y - mLastMouseY) * 0.02f;
-
+
mModelPreview->rotate(yaw_radians, 0.f);
mModelPreview->zoom(zoom_amt);
}
-
-
+
+
mModelPreview->refresh();
-
+
LLUI::setMousePositionLocal(this, mLastMouseX, mLastMouseY);
}
-
+
if (!mPreviewRect.pointInRect(x, y) || !mModelPreview)
{
return LLFloater::handleHover(x, y, mask);
@@ -669,7 +669,7 @@ BOOL LLFloaterModelPreview::handleHover (S32 x, S32 y, MASK mask)
{
gViewerWindow->setCursor(UI_CURSOR_TOOLZOOMIN);
}
-
+
return TRUE;
}
@@ -683,7 +683,7 @@ BOOL LLFloaterModelPreview::handleScrollWheel(S32 x, S32 y, S32 clicks)
mModelPreview->zoom((F32)clicks * -0.2f);
mModelPreview->refresh();
}
-
+
return TRUE;
}
@@ -695,7 +695,7 @@ void LLFloaterModelPreview::onPhysicsParamCommit(LLUICtrl* ctrl, void* data)
llinfos << "convex decomposition tool is a stub on this platform. cannot get decomp." << llendl;
return;
}
-
+
if (sInstance)
{
LLCDParam* param = (LLCDParam*) data;
@@ -722,7 +722,7 @@ void LLFloaterModelPreview::onPhysicsParamCommit(LLUICtrl* ctrl, void* data)
void LLFloaterModelPreview::onPhysicsStageExecute(LLUICtrl* ctrl, void* data)
{
LLCDStageData* stage = (LLCDStageData*) data;
-
+
if (sInstance)
{
if (!sInstance->mCurRequest.empty())
@@ -730,7 +730,7 @@ void LLFloaterModelPreview::onPhysicsStageExecute(LLUICtrl* ctrl, void* data)
llinfos << "Decomposition request still pending." << llendl;
return;
}
-
+
if (sInstance->mModelPreview)
{
for (S32 i = 0; i < sInstance->mModelPreview->mModel[LLModel::LOD_PHYSICS].size(); ++i)
@@ -744,13 +744,13 @@ void LLFloaterModelPreview::onPhysicsStageExecute(LLUICtrl* ctrl, void* data)
}
}
-//static
+//static
void LLFloaterModelPreview::onPhysicsBrowse(LLUICtrl* ctrl, void* userdata)
{
sInstance->loadModel(LLModel::LOD_PHYSICS);
}
-//static
+//static
void LLFloaterModelPreview::onPhysicsUseLOD(LLUICtrl* ctrl, void* userdata)
{
S32 which_mode = 3;
@@ -759,10 +759,10 @@ void LLFloaterModelPreview::onPhysicsUseLOD(LLUICtrl* ctrl, void* userdata)
{
which_mode = iface->getFirstSelectedIndex();
}
-
+
sInstance->mModelPreview->setPhysicsFromLOD(which_mode);
}
-
+
//static
void LLFloaterModelPreview::onPhysicsStageCancel(LLUICtrl* ctrl, void*data)
{
@@ -771,68 +771,69 @@ void LLFloaterModelPreview::onPhysicsStageCancel(LLUICtrl* ctrl, void*data)
for (std::set<LLPointer<DecompRequest> >::iterator iter = sInstance->mCurRequest.begin();
iter != sInstance->mCurRequest.end(); ++iter)
{
- (*iter)->mContinue = 0;
+ DecompRequest* req = *iter;
+ req->mContinue = 0;
}
}
}
-
+
void LLFloaterModelPreview::initDecompControls()
{
LLSD key;
-
+
childSetCommitCallback("cancel_btn", onPhysicsStageCancel, NULL);
childSetCommitCallback("physics_lod_combo", onPhysicsUseLOD, NULL);
childSetCommitCallback("physics_browse", onPhysicsBrowse, NULL);
-
+
static const LLCDStageData* stage = NULL;
static S32 stage_count = 0;
-
+
if (!stage && LLConvexDecomposition::getInstance() != NULL)
{
stage_count = LLConvexDecomposition::getInstance()->getStages(&stage);
}
-
+
static const LLCDParam* param = NULL;
static S32 param_count = 0;
if (!param && LLConvexDecomposition::getInstance() != NULL)
{
param_count = LLConvexDecomposition::getInstance()->getParameters(&param);
}
-
+
for (S32 j = stage_count-1; j >= 0; --j)
{
LLButton* button = getChild<LLButton>(stage[j].mName);
if (button)
{
- button->setCommitCallback(onPhysicsStageExecute, (void*) &stage[j]);
+ button->setCommitCallback(onPhysicsStageExecute, (void*) &stage[j]);
}
gMeshRepo.mDecompThread->mStageID[stage[j].mName] = j;
// protected against stub by stage_count being 0 for stub above
LLConvexDecomposition::getInstance()->registerCallback(j, LLPhysicsDecomp::llcdCallback);
-
+
//llinfos << "Physics decomp stage " << stage[j].mName << " (" << j << ") parameters:" << llendl;
//llinfos << "------------------------------------" << llendl;
-
+
for (S32 i = 0; i < param_count; ++i)
{
if (param[i].mStage != j)
{
continue;
}
-
+
std::string name(param[i].mName ? param[i].mName : "");
std::string description(param[i].mDescription ? param[i].mDescription : "");
-
+
std::string type = "unknown";
-
+
llinfos << name << " - " << description << llendl;
-
+
if (param[i].mType == LLCDParam::LLCD_FLOAT)
{
mDecompParams[param[i].mName] = LLSD(param[i].mDefault.mFloat);
//llinfos << "Type: float, Default: " << param[i].mDefault.mFloat << llendl;
-
+
LLSliderCtrl* slider = getChild<LLSliderCtrl>(name);
if (slider)
{
@@ -847,7 +848,7 @@ void LLFloaterModelPreview::initDecompControls()
{
mDecompParams[param[i].mName] = LLSD(param[i].mDefault.mIntOrEnumValue);
//llinfos << "Type: integer, Default: " << param[i].mDefault.mIntOrEnumValue << llendl;
-
+
LLSliderCtrl* slider = getChild<LLSliderCtrl>(name);
if (slider)
{
@@ -862,7 +863,7 @@ void LLFloaterModelPreview::initDecompControls()
{
mDecompParams[param[i].mName] = LLSD(param[i].mDefault.mBool);
//llinfos << "Type: boolean, Default: " << (param[i].mDefault.mBool ? "True" : "False") << llendl;
-
+
LLCheckBoxCtrl* check_box = getChild<LLCheckBoxCtrl>(name);
if (check_box)
{
@@ -874,29 +875,29 @@ void LLFloaterModelPreview::initDecompControls()
{
mDecompParams[param[i].mName] = LLSD(param[i].mDefault.mIntOrEnumValue);
//llinfos << "Type: enum, Default: " << param[i].mDefault.mIntOrEnumValue << llendl;
-
+
{ //plug into combo box
-
+
//llinfos << "Accepted values: " << llendl;
LLComboBox* combo_box = getChild<LLComboBox>(name);
for (S32 k = 0; k < param[i].mDetails.mEnumValues.mNumEnums; ++k)
{
- //llinfos << param[i].mDetails.mEnumValues.mEnumsArray[k].mValue
+ //llinfos << param[i].mDetails.mEnumValues.mEnumsArray[k].mValue
// << " - " << param[i].mDetails.mEnumValues.mEnumsArray[k].mName << llendl;
-
- combo_box->add(param[i].mDetails.mEnumValues.mEnumsArray[k].mName,
+
+ combo_box->add(param[i].mDetails.mEnumValues.mEnumsArray[k].mName,
LLSD::Integer(param[i].mDetails.mEnumValues.mEnumsArray[k].mValue));
}
combo_box->setValue(param[i].mDefault.mIntOrEnumValue);
combo_box->setCommitCallback(onPhysicsParamCommit, (void*) &param[i]);
}
-
+
//llinfos << "----" << llendl;
}
//llinfos << "-----------------------------" << llendl;
}
}
-
+
childSetCommitCallback("physics_explode", LLFloaterModelPreview::onExplodeCommit, this);
}
@@ -941,7 +942,7 @@ LLModelLoader::LLModelLoader(std::string filename, S32 lod, LLModelPreview* prev
mJointMap["mAnkleLeft"] = "mAnkleLeft";
mJointMap["mFootLeft"] = "mFootLeft";
mJointMap["mToeLeft"] = "mToeLeft";
-
+
mJointMap["avatar_mPelvis"] = "mPelvis";
mJointMap["avatar_mTorso"] = "mTorso";
mJointMap["avatar_mChest"] = "mChest";
@@ -968,8 +969,8 @@ LLModelLoader::LLModelLoader(std::string filename, S32 lod, LLModelPreview* prev
mJointMap["avatar_mAnkleLeft"] = "mAnkleLeft";
mJointMap["avatar_mFootLeft"] = "mFootLeft";
mJointMap["avatar_mToeLeft"] = "mToeLeft";
-
-
+
+
mJointMap["hip"] = "mPelvis";
mJointMap["abdomen"] = "mTorso";
mJointMap["chest"] = "mChest";
@@ -994,7 +995,7 @@ LLModelLoader::LLModelLoader(std::string filename, S32 lod, LLModelPreview* prev
void stretch_extents(LLModel* model, LLMatrix4a& mat, LLVector4a& min, LLVector4a& max, BOOL& first_transform)
{
- LLVector4a box[] =
+ LLVector4a box[] =
{
LLVector4a(-1, 1,-1),
LLVector4a(-1, 1, 1),
@@ -1005,28 +1006,28 @@ void stretch_extents(LLModel* model, LLMatrix4a& mat, LLVector4a& min, LLVector4
LLVector4a( 1,-1,-1),
LLVector4a( 1,-1, 1),
};
-
+
for (S32 j = 0; j < model->getNumVolumeFaces(); ++j)
{
const LLVolumeFace& face = model->getVolumeFace(j);
-
+
LLVector4a center;
center.setAdd(face.mExtents[0], face.mExtents[1]);
center.mul(0.5f);
LLVector4a size;
size.setSub(face.mExtents[1],face.mExtents[0]);
size.mul(0.5f);
-
+
for (U32 i = 0; i < 8; i++)
{
LLVector4a t;
t.setMul(size, box[i]);
t.add(center);
-
+
LLVector4a v;
-
- mat.affineTransform(t, v);
-
+
+ mat.affineTransform(t, v);
+
if (first_transform)
{
first_transform = FALSE;
@@ -1044,13 +1045,13 @@ void stretch_extents(LLModel* model, LLMatrix4& mat, LLVector3& min, LLVector3&
{
LLVector4a mina, maxa;
LLMatrix4a mata;
-
+
mata.loadu(mat);
mina.load3(min.mV);
maxa.load3(max.mV);
-
+
stretch_extents(model, mata, mina, maxa, first_transform);
-
+
min.set(mina.getF32ptr());
max.set(maxa.getF32ptr());
}
@@ -1059,32 +1060,32 @@ void LLModelLoader::run()
{
DAE dae;
domCOLLADA* dom = dae.open(mFilename);
-
+
if (dom)
{
daeDatabase* db = dae.getDatabase();
-
+
daeInt count = db->getElementCount(NULL, COLLADA_TYPE_MESH);
-
+
daeDocument* doc = dae.getDoc(mFilename);
if (!doc)
{
llwarns << "can't find internal doc" << llendl;
return;
}
-
+
daeElement* root = doc->getDomRoot();
if (!root)
{
llwarns << "document has no root" << llendl;
return;
}
-
+
//get unit scale
mTransform.setIdentity();
-
+
domAsset::domUnit* unit = daeSafeCast<domAsset::domUnit>(root->getDescendant(daeElement::matchType(domAsset::domUnit::ID())));
-
+
if (unit)
{
F32 meter = unit->getMeter();
@@ -1092,19 +1093,19 @@ void LLModelLoader::run()
mTransform.mMatrix[1][1] = meter;
mTransform.mMatrix[2][2] = meter;
}
-
+
//get up axis rotation
LLMatrix4 rotation;
-
+
domUpAxisType up = UPAXISTYPE_Y_UP; // default is Y_UP
domAsset::domUp_axis* up_axis =
daeSafeCast<domAsset::domUp_axis>(root->getDescendant(daeElement::matchType(domAsset::domUp_axis::ID())));
-
+
if (up_axis)
{
up = up_axis->getValue();
}
-
+
if (up == UPAXISTYPE_X_UP)
{
rotation.initRotation(0.0f, 90.0f * DEG_TO_RAD, 0.0f);
@@ -1113,20 +1114,20 @@ void LLModelLoader::run()
{
rotation.initRotation(90.0f * DEG_TO_RAD, 0.0f, 0.0f);
}
-
+
rotation *= mTransform;
mTransform = rotation;
-
-
+
+
for (daeInt idx = 0; idx < count; ++idx)
{ //build map of domEntities to LLModel
domMesh* mesh = NULL;
db->getElement((daeElement**) &mesh, idx, NULL, COLLADA_TYPE_MESH);
-
+
if (mesh)
{
LLPointer<LLModel> model = LLModel::loadModelFromDomMesh(mesh);
-
+
if (model.notNull() && validate_model(model))
{
mModelList.push_back(model);
@@ -1134,17 +1135,17 @@ void LLModelLoader::run()
}
}
}
-
+
count = db->getElementCount(NULL, COLLADA_TYPE_SKIN);
for (daeInt idx = 0; idx < count; ++idx)
{ //add skinned meshes as instances
domSkin* skin = NULL;
db->getElement((daeElement**) &skin, idx, NULL, COLLADA_TYPE_SKIN);
-
+
if (skin)
- {
+ {
domGeometry* geom = daeSafeCast<domGeometry>(skin->getSource().getElement());
-
+
if (geom)
{
domMesh* mesh = geom->getMesh();
@@ -1156,25 +1157,25 @@ void LLModelLoader::run()
LLVector3 mesh_scale_vector;
LLVector3 mesh_translation_vector;
model->getNormalizedScaleTranslation(mesh_scale_vector, mesh_translation_vector);
-
+
LLMatrix4 normalized_transformation;
normalized_transformation.setTranslation(mesh_translation_vector);
-
+
LLMatrix4 mesh_scale;
mesh_scale.initScale(mesh_scale_vector);
mesh_scale *= normalized_transformation;
normalized_transformation = mesh_scale;
-
+
glh::matrix4f inv_mat((F32*) normalized_transformation.mMatrix);
inv_mat = inv_mat.inverse();
- LLMatrix4 inverse_normalized_transformation(inv_mat.m);
-
+ LLMatrix4 inverse_normalized_transformation(inv_mat.m);
+
domSkin::domBind_shape_matrix* bind_mat = skin->getBind_shape_matrix();
-
+
if (bind_mat)
{ //get bind shape matrix
domFloat4x4& dom_value = bind_mat->getValue();
-
+
for (int i = 0; i < 4; i++)
{
for(int j = 0; j < 4; j++)
@@ -1182,26 +1183,26 @@ void LLModelLoader::run()
model->mBindShapeMatrix.mMatrix[i][j] = dom_value[i + j*4];
}
}
-
+
LLMatrix4 trans = normalized_transformation;
trans *= model->mBindShapeMatrix;
model->mBindShapeMatrix = trans;
-
+
}
-
-
+
+
//The joint transfom map that we'll populate below
std::map<std::string,LLMatrix4> jointTransforms;
jointTransforms.clear();
-
+
//Some collada setup for accessing the skeleton
daeElement* pElement = 0;
dae.getDatabase()->getElement( &pElement, 0, 0, "skeleton" );
-
+
//Try to get at the skeletal instance controller
domInstance_controller::domSkeleton* pSkeleton = daeSafeCast<domInstance_controller::domSkeleton>( pElement );
bool missingSkeletonOrScene = false;
-
+
//If no skeleton, do a breadth-first search to get at specific joints
if ( !pSkeleton )
{
@@ -1216,7 +1217,7 @@ void LLModelLoader::run()
//Get the children at this level
daeTArray< daeSmartRef<daeElement> > children = pScene->getChildren();
S32 childCount = children.getCount();
-
+
//Process any children that are joints
//Not all children are joints, some code be ambient lights, cameras, geometry etc..
for (S32 i = 0; i < childCount; ++i)
@@ -1225,45 +1226,45 @@ void LLModelLoader::run()
if ( isNodeAJoint( pNode ) )
{
processJointNode( pNode, jointTransforms );
- }
+ }
}
- }
+ }
}
- else
+ else
//Has Skeleton
- {
+ {
//Get the root node of the skeleton
daeElement* pSkeletonRootNode = pSkeleton->getValue().getElement();
if ( pSkeletonRootNode )
- {
- //Once we have the root node - start acccessing it's joint components
+ {
+ //Once we have the root node - start acccessing it's joint components
const int jointCnt = mJointMap.size();
std::map<std::string, std::string> :: const_iterator jointIt = mJointMap.begin();
-
+
//Loop over all the possible joints within the .dae - using the allowed joint list in the ctor.
for ( int i=0; i<jointCnt; ++i, ++jointIt )
{
//Build a joint for the resolver to work with
- char str[64]={0};
- sprintf(str,"./%s",(*jointIt).second.c_str() );
+ char str[64]={0};
+ sprintf(str,"./%s",(*jointIt).second.c_str() );
//llwarns<<"Joint "<< str <<llendl;
-
+
//Setup the resolver
daeSIDResolver resolver( pSkeletonRootNode, str );
-
+
//Look for the joint
domNode* pJoint = daeSafeCast<domNode>( resolver.getElement() );
if ( pJoint )
- {
+ {
//Pull out the translate id and store it in the jointTranslations map
- daeSIDResolver jointResolver( pJoint, "./translate" );
+ daeSIDResolver jointResolver( pJoint, "./translate" );
domTranslate* pTranslate = daeSafeCast<domTranslate>( jointResolver.getElement() );
-
+
LLMatrix4 workingTransform;
-
+
//Translation via SID
if ( pTranslate )
- {
+ {
extractTranslation( pTranslate, workingTransform );
}
else
@@ -1276,16 +1277,16 @@ void LLModelLoader::run()
missingSkeletonOrScene = true;
}
else
- {
+ {
extractTranslationViaElement( pTranslateElement, workingTransform );
}
}
-
+
//Store the joint transform w/respect to it's name.
- jointTransforms[(*jointIt).second.c_str()] = workingTransform;
+ jointTransforms[(*jointIt).second.c_str()] = workingTransform;
}
}
-
+
//If anything failed in regards to extracting the skeleton, joints or translation id,
//mention it
if ( missingSkeletonOrScene )
@@ -1294,7 +1295,7 @@ void LLModelLoader::run()
}
}//got skeleton?
}
-
+
if ( !missingSkeletonOrScene )
{
//Set the joint translations on the avatar
@@ -1305,12 +1306,12 @@ void LLModelLoader::run()
{
std::string lookingForJoint = (*jointIt).first.c_str();
if ( jointTransforms.find( lookingForJoint ) != jointTransforms.end() )
- {
+ {
LLMatrix4 jointTransform = jointTransforms[lookingForJoint];
LLJoint* pJoint = gAgentAvatarp->getJoint( lookingForJoint );
if ( pJoint )
- {
- pJoint->storeCurrentXform( jointTransform.getTranslation() );
+ {
+ pJoint->storeCurrentXform( jointTransform.getTranslation() );
}
else
{
@@ -1319,39 +1320,39 @@ void LLModelLoader::run()
}
//Reposition the avatars pelvis (avPos+offset)
//if ( lookingForJoint == "mPelvis" )
- //{
+ //{
// const LLVector3& pos = gAgentAvatarp->getCharacterPosition();
// gAgentAvatarp->setPelvisOffset( true, jointTransform.getTranslation() );
- // gAgentAvatarp->setPosition( pos + jointTransform.getTranslation() );
+ // gAgentAvatarp->setPosition( pos + jointTransform.getTranslation() );
//}
}
}
} //missingSkeletonOrScene
-
+
domSkin::domJoints* joints = skin->getJoints();
-
+
domInputLocal_Array& joint_input = joints->getInput_array();
-
+
for (size_t i = 0; i < joint_input.getCount(); ++i)
{
domInputLocal* input = joint_input.get(i);
xsNMTOKEN semantic = input->getSemantic();
-
+
if (strcmp(semantic, COMMON_PROFILE_INPUT_JOINT) == 0)
{ //found joint source, fill model->mJointMap and model->mJointList
daeElement* elem = input->getSource().getElement();
-
+
domSource* source = daeSafeCast<domSource>(elem);
if (source)
- {
-
-
+ {
+
+
domName_array* names_source = source->getName_array();
-
+
if (names_source)
{
- domListOfNames &names = names_source->getValue();
-
+ domListOfNames &names = names_source->getValue();
+
for (size_t j = 0; j < names.getCount(); ++j)
{
std::string name(names.get(j));
@@ -1361,7 +1362,7 @@ void LLModelLoader::run()
}
model->mJointList.push_back(name);
model->mJointMap[name] = j;
- }
+ }
}
else
{
@@ -1369,7 +1370,7 @@ void LLModelLoader::run()
if (names_source)
{
xsIDREFS& names = names_source->getValue();
-
+
for (size_t j = 0; j < names.getCount(); ++j)
{
std::string name(names.get(j).getID());
@@ -1394,11 +1395,11 @@ void LLModelLoader::run()
{
domListOfFloats& transform = t->getValue();
S32 count = transform.getCount()/16;
-
+
for (S32 k = 0; k < count; ++k)
{
LLMatrix4 mat;
-
+
for (int i = 0; i < 4; i++)
{
for(int j = 0; j < 4; j++)
@@ -1406,19 +1407,19 @@ void LLModelLoader::run()
mat.mMatrix[i][j] = transform[k*16 + i + j*4];
}
}
-
+
model->mInvBindMatrix.push_back(mat);
}
}
}
}
}
-
+
//We need to construct the alternate bind matrix (which contains the new joint positions)
//in the same order as they were stored in the joint buffer. The joints associated
//with the skeleton are not stored in the same order as they are in the exported joint buffer.
//This remaps the skeletal joints to be in the same order as the joints stored in the model.
- std::vector<std::string> :: const_iterator jointIt = model->mJointList.begin();
+ std::vector<std::string> :: const_iterator jointIt = model->mJointList.begin();
const int jointCnt = model->mJointList.size();
for ( int i=0; i<jointCnt; ++i, ++jointIt )
{
@@ -1426,20 +1427,20 @@ void LLModelLoader::run()
//Look for the joint xform that we extracted from the skeleton, using the jointIt as the key
//and store it in the alternate bind matrix
if ( jointTransforms.find( lookingForJoint ) != jointTransforms.end() )
- {
+ {
LLMatrix4 jointTransform = jointTransforms[lookingForJoint];
LLMatrix4 newInverse = model->mInvBindMatrix[i];
newInverse.setTranslation( jointTransforms[lookingForJoint].getTranslation() );
- model->mAlternateBindMatrix.push_back( newInverse );
+ model->mAlternateBindMatrix.push_back( newInverse );
}
else
{
llwarns<<"Possibly misnamed/missing joint [" <<lookingForJoint.c_str()<<" ] "<<llendl;
}
- }
-
+ }
+
//grab raw position array
-
+
domVertices* verts = mesh->getVertices();
if (verts)
{
@@ -1455,19 +1456,19 @@ void LLModelLoader::run()
if (pos_array)
{
domListOfFloats& pos = pos_array->getValue();
-
+
for (size_t j = 0; j < pos.getCount(); j += 3)
{
if (pos.getCount() <= j+2)
{
llerrs << "WTF?" << llendl;
}
-
+
LLVector3 v(pos[j], pos[j+1], pos[j+2]);
-
+
//transform from COLLADA space to volume space
v = v * inverse_normalized_transformation;
-
+
model->mPosition.push_back(v);
}
}
@@ -1475,7 +1476,7 @@ void LLModelLoader::run()
}
}
}
-
+
//grab skin weights array
domSkin::domVertex_weights* weights = skin->getVertex_weights();
if (weights)
@@ -1493,44 +1494,44 @@ void LLModelLoader::run()
}
}
}
-
+
if (vertex_weights)
{
domListOfFloats& w = vertex_weights->getValue();
domListOfUInts& vcount = weights->getVcount()->getValue();
domListOfInts& v = weights->getV()->getValue();
-
+
U32 c_idx = 0;
for (size_t vc_idx = 0; vc_idx < vcount.getCount(); ++vc_idx)
{ //for each vertex
daeUInt count = vcount[vc_idx];
-
+
//create list of weights that influence this vertex
LLModel::weight_list weight_list;
-
+
for (daeUInt i = 0; i < count; ++i)
{ //for each weight
daeInt joint_idx = v[c_idx++];
daeInt weight_idx = v[c_idx++];
-
+
if (joint_idx == -1)
{
//ignore bindings to bind_shape_matrix
continue;
}
-
+
F32 weight_value = w[weight_idx];
-
- weight_list.push_back(LLModel::JointWeight(joint_idx, weight_value));
+
+ weight_list.push_back(LLModel::JointWeight(joint_idx, weight_value));
}
-
+
//sort by joint weight
std::sort(weight_list.begin(), weight_list.end(), LLModel::CompareWeightGreater());
-
+
std::vector<LLModel::JointWeight> wght;
-
+
F32 total = 0.f;
-
+
for (U32 i = 0; i < llmin((U32) 4, (U32) weight_list.size()); ++i)
{ //take up to 4 most significant weights
if (weight_list[i].mWeight > 0.f)
@@ -1539,21 +1540,21 @@ void LLModelLoader::run()
total += weight_list[i].mWeight;
}
}
-
+
F32 scale = 1.f/total;
if (scale != 1.f)
{ //normalize weights
for (U32 i = 0; i < wght.size(); ++i)
- {
+ {
wght[i].mWeight *= scale;
}
}
-
+
model->mSkinWeights[model->mPosition[vc_idx]] = wght;
}
-
+
//add instance to scene for this model
-
+
LLMatrix4 transform;
std::vector<LLImportMaterial> materials;
materials.resize(model->getNumVolumeFaces());
@@ -1566,23 +1567,23 @@ void LLModelLoader::run()
}
}
}
-
+
daeElement* scene = root->getDescendant("visual_scene");
-
+
if (!scene)
{
llwarns << "document has no visual_scene" << llendl;
setLoadState( ERROR_PARSING );
return;
}
-
+
processElement(scene);
doOnIdleOneTime(boost::bind(&LLModelPreview::loadModelCallback,mPreview,mLod));
}
}
-bool LLModelLoader::isNodeAJoint( domNode* pNode )
+bool LLModelLoader::isNodeAJoint( domNode* pNode )
{
if ( pNode->getName() == NULL)
{
@@ -1593,7 +1594,7 @@ bool LLModelLoader::isNodeAJoint( domNode* pNode )
{
return true;
}
-
+
return false;
}
@@ -1601,7 +1602,7 @@ void LLModelLoader::extractTranslation( domTranslate* pTranslate, LLMatrix4& tra
{
domFloat3 jointTrans = pTranslate->getValue();
LLVector3 singleJointTranslation( jointTrans[0], jointTrans[1], jointTrans[2] );
- transform.setTranslation( singleJointTranslation );
+ transform.setTranslation( singleJointTranslation );
}
void LLModelLoader::extractTranslationViaElement( daeElement* pTranslateElement, LLMatrix4& transform )
@@ -1609,7 +1610,7 @@ void LLModelLoader::extractTranslationViaElement( daeElement* pTranslateElement,
domTranslate* pTranslateChild = dynamic_cast<domTranslate*>( pTranslateElement );
domFloat3 translateChild = pTranslateChild->getValue();
LLVector3 singleJointTranslation( translateChild[0], translateChild[1], translateChild[2] );
- transform.setTranslation( singleJointTranslation );
+ transform.setTranslation( singleJointTranslation );
}
void LLModelLoader::processJointNode( domNode* pNode, std::map<std::string,LLMatrix4>& jointTransforms )
@@ -1621,18 +1622,18 @@ void LLModelLoader::processJointNode( domNode* pNode, std::map<std::string,LLMat
}
//llwarns<<"ProcessJointNode# Node:" <<pNode->getName()<<llendl;
-
+
//1. handle the incoming node - extract out translation via SID or element
-
+
LLMatrix4 workingTransform;
-
+
//Pull out the translate id and store it in the jointTranslations map
- daeSIDResolver jointResolver( pNode, "./translate" );
+ daeSIDResolver jointResolver( pNode, "./translate" );
domTranslate* pTranslate = daeSafeCast<domTranslate>( jointResolver.getElement() );
-
+
//Translation via SID was successful
if ( pTranslate )
- {
+ {
extractTranslation( pTranslate, workingTransform );
}
else
@@ -1644,88 +1645,88 @@ void LLModelLoader::processJointNode( domNode* pNode, std::map<std::string,LLMat
llwarns<< "The found element is not a translate node" <<llendl;
}
else
- {
+ {
extractTranslationViaElement( pTranslateElement, workingTransform );
}
}
-
+
//Store the working transform relative to the nodes name.
- jointTransforms[ pNode->getName() ] = workingTransform;
-
+ jointTransforms[ pNode->getName() ] = workingTransform;
+
//2. handle the nodes children
-
+
//Gather and handle the incoming nodes children
daeTArray< daeSmartRef<daeElement> > childOfChild = pNode->getChildren();
S32 childOfChildCount = childOfChild.getCount();
-
+
for (S32 i = 0; i < childOfChildCount; ++i)
{
domNode* pChildNode = daeSafeCast<domNode>( childOfChild[i] );
if ( pChildNode )
{
processJointNode( pChildNode, jointTransforms );
- }
+ }
}
}
daeElement* LLModelLoader::getChildFromElement( daeElement* pElement, std::string const & name )
-{
+{
daeElement* pChildOfElement = pElement->getChild( name.c_str() );
if ( pChildOfElement )
{
return pChildOfElement;
- }
+ }
llwarns<< "Could not find a child [" << name << "] for the element: \"" << pElement->getAttribute("id") << "\"" << llendl;
- return NULL;
+ return NULL;
}
void LLModelLoader::processElement(daeElement* element)
{
LLMatrix4 saved_transform = mTransform;
-
+
domTranslate* translate = daeSafeCast<domTranslate>(element);
if (translate)
{
domFloat3 dom_value = translate->getValue();
-
+
LLMatrix4 translation;
translation.setTranslation(LLVector3(dom_value[0], dom_value[1], dom_value[2]));
-
+
translation *= mTransform;
mTransform = translation;
}
-
+
domRotate* rotate = daeSafeCast<domRotate>(element);
if (rotate)
{
domFloat4 dom_value = rotate->getValue();
-
+
LLMatrix4 rotation;
rotation.initRotTrans(dom_value[3] * DEG_TO_RAD, LLVector3(dom_value[0], dom_value[1], dom_value[2]), LLVector3(0, 0, 0));
-
+
rotation *= mTransform;
mTransform = rotation;
}
-
+
domScale* scale = daeSafeCast<domScale>(element);
if (scale)
{
domFloat3 dom_value = scale->getValue();
-
+
LLMatrix4 scaling;
scaling.initScale(LLVector3(dom_value[0], dom_value[1], dom_value[2]));
-
+
scaling *= mTransform;
mTransform = scaling;
}
-
+
domMatrix* matrix = daeSafeCast<domMatrix>(element);
if (matrix)
{
domFloat4x4 dom_value = matrix->getValue();
-
+
LLMatrix4 matrix_transform;
-
+
for (int i = 0; i < 4; i++)
{
for(int j = 0; j < 4; j++)
@@ -1733,11 +1734,11 @@ void LLModelLoader::processElement(daeElement* element)
matrix_transform.mMatrix[i][j] = dom_value[i + j*4];
}
}
-
+
matrix_transform *= mTransform;
mTransform = matrix_transform;
}
-
+
domInstance_geometry* instance_geo = daeSafeCast<domInstance_geometry>(element);
if (instance_geo)
{
@@ -1751,32 +1752,32 @@ void LLModelLoader::processElement(daeElement* element)
if (model)
{
LLMatrix4 transformation = mTransform;
-
+
std::vector<LLImportMaterial> materials = getMaterials(model, instance_geo);
-
+
// adjust the transformation to compensate for mesh normalization
LLVector3 mesh_scale_vector;
LLVector3 mesh_translation_vector;
model->getNormalizedScaleTranslation(mesh_scale_vector, mesh_translation_vector);
-
+
LLMatrix4 mesh_translation;
mesh_translation.setTranslation(mesh_translation_vector);
mesh_translation *= transformation;
transformation = mesh_translation;
-
+
LLMatrix4 mesh_scale;
mesh_scale.initScale(mesh_scale_vector);
mesh_scale *= transformation;
transformation = mesh_scale;
-
+
mScene[transformation].push_back(LLModelInstance(model, transformation, materials));
-
- stretch_extents(model, transformation, mExtents[0], mExtents[1], mFirstTransform);
+
+ stretch_extents(model, transformation, mExtents[0], mExtents[1], mFirstTransform);
}
}
}
}
-
+
domInstance_node* instance_node = daeSafeCast<domInstance_node>(element);
if (instance_node)
{
@@ -1786,18 +1787,18 @@ void LLModelLoader::processElement(daeElement* element)
processElement(instance);
}
}
-
+
//process children
daeTArray< daeSmartRef<daeElement> > children = element->getChildren();
for (S32 i = 0; i < children.getCount(); i++)
{
processElement(children[i]);
}
-
+
domNode* node = daeSafeCast<domNode>(element);
if (node)
{ //this element was a node, restore transform before processiing siblings
- mTransform = saved_transform;
+ mTransform = saved_transform;
}
}
@@ -1807,26 +1808,26 @@ std::vector<LLImportMaterial> LLModelLoader::getMaterials(LLModel* model, domIns
for (int i = 0; i < model->mMaterialList.size(); i++)
{
LLImportMaterial import_material;
-
+
domInstance_material* instance_mat = NULL;
-
+
domBind_material::domTechnique_common* technique =
daeSafeCast<domBind_material::domTechnique_common>(instance_geo->getDescendant(daeElement::matchType(domBind_material::domTechnique_common::ID())));
-
+
if (technique)
{
daeTArray< daeSmartRef<domInstance_material> > inst_materials = technique->getChildrenByType<domInstance_material>();
for (int j = 0; j < inst_materials.getCount(); j++)
{
std::string symbol(inst_materials[j]->getSymbol());
-
+
if (symbol == model->mMaterialList[i]) // found the binding
{
instance_mat = inst_materials[j];
}
}
}
-
+
if (instance_mat)
{
domMaterial* material = daeSafeCast<domMaterial>(instance_mat->getTarget().getElement());
@@ -1849,10 +1850,10 @@ std::vector<LLImportMaterial> LLModelLoader::getMaterials(LLModel* model, domIns
}
}
}
-
+
materials.push_back(import_material);
}
-
+
return materials;
}
@@ -1860,7 +1861,7 @@ LLImportMaterial LLModelLoader::profileToMaterial(domProfile_COMMON* material)
{
LLImportMaterial mat;
mat.mFullbright = FALSE;
-
+
daeElement* diffuse = material->getDescendant("diffuse");
if (diffuse)
{
@@ -1878,7 +1879,7 @@ LLImportMaterial LLModelLoader::profileToMaterial(domProfile_COMMON* material)
if (init)
{
domFx_surface_init_from_common_Array init_from = init->getInit_from_array();
-
+
if (init_from.getCount() > i)
{
domImage* image = daeSafeCast<domImage>(init_from[i]->getValue().getElement());
@@ -1889,10 +1890,10 @@ LLImportMaterial LLModelLoader::profileToMaterial(domProfile_COMMON* material)
if (init)
{
std::string filename = cdom::uriToNativePath(init->getValue().str());
-
+
mat.mDiffuseMap = LLViewerTextureManager::getFetchedTextureFromUrl("file://" + filename, TRUE, LLViewerTexture::BOOST_PREVIEW);
mat.mDiffuseMap->setLoadedCallback(LLModelPreview::textureLoadedCallback, 0, TRUE, FALSE, this->mPreview, NULL, FALSE);
-
+
mat.mDiffuseMap->forceToSaveRawImage();
mat.mDiffuseMapFilename = filename;
mat.mDiffuseMapLabel = getElementLabel(material);
@@ -1903,7 +1904,7 @@ LLImportMaterial LLModelLoader::profileToMaterial(domProfile_COMMON* material)
}
}
}
-
+
domCommon_color_or_texture_type_complexType::domColor* color =
daeSafeCast<domCommon_color_or_texture_type_complexType::domColor>(diffuse->getDescendant("color"));
if (color)
@@ -1913,7 +1914,7 @@ LLImportMaterial LLModelLoader::profileToMaterial(domProfile_COMMON* material)
mat.mDiffuseColor = value;
}
}
-
+
daeElement* emission = material->getDescendant("emission");
if (emission)
{
@@ -1923,7 +1924,7 @@ LLImportMaterial LLModelLoader::profileToMaterial(domProfile_COMMON* material)
mat.mFullbright = TRUE;
}
}
-
+
return mat;
}
@@ -1936,13 +1937,13 @@ std::string LLModelLoader::getElementLabel(daeElement *element)
{
return name;
}
-
+
// if we have an ID attribute, use it
if (element->getID())
{
return std::string(element->getID());
}
-
+
// if we have a parent, use it
daeElement* parent = element->getParent();
if (parent)
@@ -1953,21 +1954,21 @@ std::string LLModelLoader::getElementLabel(daeElement *element)
{
return name;
}
-
+
// if parent has an ID, use it
if (parent->getID())
{
return std::string(parent->getID());
}
}
-
+
// try to use our type
daeString element_name = element->getElementName();
if (element_name)
{
return std::string(element_name);
}
-
+
// if all else fails, use "object"
return std::string("object");
}
@@ -1982,7 +1983,7 @@ LLColor4 LLModelLoader::getDaeColor(daeElement* element)
domFx_color_common domfx_color = color->getValue();
value = LLColor4(domfx_color[0], domfx_color[1], domfx_color[2], domfx_color[3]);
}
-
+
return value;
}
@@ -1990,7 +1991,7 @@ LLColor4 LLModelLoader::getDaeColor(daeElement* element)
// LLModelPreview
//-----------------------------------------------------------------------------
-LLModelPreview::LLModelPreview(S32 width, S32 height, LLFloater* fmp)
+LLModelPreview::LLModelPreview(S32 width, S32 height, LLFloater* fmp)
: LLViewerDynamicTexture(width, height, 3, ORDER_MIDDLE, FALSE), LLMutex(NULL)
{
mNeedsUpdate = TRUE;
@@ -2010,9 +2011,9 @@ LLModelPreview::LLModelPreview(S32 width, S32 height, LLFloater* fmp)
mBuildQueueMode = GLOD_QUEUE_GREEDY;
mBuildBorderMode = GLOD_BORDER_UNLOCK;
mBuildOperator = GLOD_OPERATOR_HALF_EDGE_COLLAPSE;
-
+
mFMP = fmp;
-
+
glodInit();
}
@@ -2023,7 +2024,7 @@ LLModelPreview::~LLModelPreview()
delete mModelLoader;
mModelLoader = NULL;
}
-
+
//*HACK : *TODO : turn this back on when we understand why this crashes
//glodShutdown();
}
@@ -2031,59 +2032,59 @@ LLModelPreview::~LLModelPreview()
U32 LLModelPreview::calcResourceCost()
{
assert_main_thread();
-
+
rebuildUploadData();
if ( mModelLoader->getLoadState() != LLModelLoader::ERROR_PARSING )
{
mFMP->childEnable("ok_btn");
}
-
+
U32 cost = 0;
std::set<LLModel*> accounted;
U32 num_points = 0;
U32 num_hulls = 0;
-
+
F32 debug_scale = mFMP->childGetValue("import_scale").asReal();
-
+
F32 streaming_cost = 0.f;
for (U32 i = 0; i < mUploadData.size(); ++i)
{
LLModelInstance& instance = mUploadData[i];
-
+
if (accounted.find(instance.mModel) == accounted.end())
{
accounted.insert(instance.mModel);
-
+
LLModel::convex_hull_decomposition& decomp =
instance.mLOD[LLModel::LOD_PHYSICS] ?
instance.mLOD[LLModel::LOD_PHYSICS]->mConvexHullDecomp :
instance.mModel->mConvexHullDecomp;
-
+
LLSD ret = LLModel::writeModel(
"",
instance.mLOD[4],
- instance.mLOD[3],
- instance.mLOD[2],
- instance.mLOD[1],
+ instance.mLOD[3],
+ instance.mLOD[2],
+ instance.mLOD[1],
instance.mLOD[0],
decomp,
mFMP->childGetValue("upload_skin").asBoolean(),
mFMP->childGetValue("upload_joints").asBoolean(),
TRUE);
cost += gMeshRepo.calcResourceCost(ret);
-
+
num_hulls += decomp.size();
for (U32 i = 0; i < decomp.size(); ++i)
{
num_points += decomp[i].size();
}
-
+
//calculate streaming cost
LLMatrix4 transformation = instance.mTransform;
-
+
LLVector3 position = LLVector3(0, 0, 0) * transformation;
-
+
LLVector3 x_transformed = LLVector3(1, 0, 0) * transformation - position;
LLVector3 y_transformed = LLVector3(0, 1, 0) * transformation - position;
LLVector3 z_transformed = LLVector3(0, 0, 1) * transformation - position;
@@ -2091,64 +2092,64 @@ U32 LLModelPreview::calcResourceCost()
F32 y_length = y_transformed.normalize();
F32 z_length = z_transformed.normalize();
LLVector3 scale = LLVector3(x_length, y_length, z_length);
-
+
F32 radius = scale.length()*debug_scale;
-
+
streaming_cost += LLMeshRepository::getStreamingCost(ret, radius);
}
}
-
+
//mFMP->childSetTextArg(info_name[LLModel::LOD_PHYSICS], "[HULLS]", llformat("%d",num_hulls));
- //mFMP->childSetTextArg(info_name[LLModel::LOD_PHYSICS], "[POINTS]", llformat("%d",num_points));
- mFMP->childSetTextArg("streaming cost", "[COST]", llformat("%.3f", streaming_cost));
+ //mFMP->childSetTextArg(info_name[LLModel::LOD_PHYSICS], "[POINTS]", llformat("%d",num_points));
+ mFMP->childSetTextArg("streaming cost", "[COST]", llformat("%.3f", streaming_cost));
F32 scale = mFMP->childGetValue("import_scale").asReal()*2.f;
mFMP->childSetTextArg("import_dimensions", "[X]", llformat("%.3f", mPreviewScale[0]*scale));
mFMP->childSetTextArg("import_dimensions", "[Y]", llformat("%.3f", mPreviewScale[1]*scale));
mFMP->childSetTextArg("import_dimensions", "[Z]", llformat("%.3f", mPreviewScale[2]*scale));
-
+
updateStatusMessages();
-
+
return cost;
}
void LLModelPreview::rebuildUploadData()
{
assert_main_thread();
-
+
mUploadData.clear();
mTextureSet.clear();
-
+
//fill uploaddata instance vectors from scene data
std::string requested_name = mFMP->getChild<LLUICtrl>("description_form")->getValue().asString();
-
+
LLSpinCtrl* scale_spinner = mFMP->getChild<LLSpinCtrl>("import_scale");
-
+
if (!scale_spinner)
{
llerrs << "floater_model_preview.xml MUST contain import_scale spinner." << llendl;
}
-
+
F32 scale = scale_spinner->getValue().asReal();
-
+
LLMatrix4 scale_mat;
scale_mat.initScale(LLVector3(scale, scale, scale));
-
+
F32 max_scale = 0.f;
-
+
if ( mBaseScene.size() > 0 )
{
mFMP->childEnable("ok_btn");
}
-
+
for (LLModelLoader::scene::iterator iter = mBaseScene.begin(); iter != mBaseScene.end(); ++iter)
{ //for each transform in scene
LLMatrix4 mat = iter->first;
-
+
// compute position
LLVector3 position = LLVector3(0, 0, 0) * mat;
-
+
// compute scale
LLVector3 x_transformed = LLVector3(1, 0, 0) * mat - position;
LLVector3 y_transformed = LLVector3(0, 1, 0) * mat - position;
@@ -2156,21 +2157,21 @@ void LLModelPreview::rebuildUploadData()
F32 x_length = x_transformed.normalize();
F32 y_length = y_transformed.normalize();
F32 z_length = z_transformed.normalize();
-
+
max_scale = llmax(llmax(llmax(max_scale, x_length), y_length), z_length);
-
+
mat *= scale_mat;
-
+
for (LLModelLoader::model_instance_list::iterator model_iter = iter->second.begin(); model_iter != iter->second.end(); ++model_iter)
{ //for each instance with said transform applied
LLModelInstance instance = *model_iter;
-
+
LLModel* base_model = instance.mModel;
if (base_model)
{
base_model->mRequestedLabel = requested_name;
}
-
+
S32 idx = 0;
for (idx = 0; idx < mBaseModel.size(); ++idx)
{ //find reference instance for this model
@@ -2179,7 +2180,7 @@ void LLModelPreview::rebuildUploadData()
break;
}
}
-
+
for (U32 i = 0; i < LLModel::NUM_LODS; i++)
{ //fill LOD slots based on reference model index
if (!mModel[i].empty())
@@ -2191,16 +2192,16 @@ void LLModelPreview::rebuildUploadData()
instance.mLOD[i] = NULL;
}
}
-
+
instance.mTransform = mat;
mUploadData.push_back(instance);
}
}
-
+
F32 max_import_scale = DEFAULT_MAX_PRIM_SCALE/max_scale;
-
+
scale_spinner->setMaxValue(max_import_scale);
-
+
if (max_import_scale < scale)
{
scale_spinner->setValue(max_import_scale);
@@ -2215,7 +2216,7 @@ void LLModelPreview::clearModel(S32 lod)
{
return;
}
-
+
mVertexBuffer[lod].clear();
mModel[lod].clear();
mScene[lod].clear();
@@ -2224,15 +2225,15 @@ void LLModelPreview::clearModel(S32 lod)
void LLModelPreview::loadModel(std::string filename, S32 lod)
{
assert_main_thread();
-
+
LLMutexLock lock(this);
-
+
if (mModelLoader)
{
delete mModelLoader;
mModelLoader = NULL;
}
-
+
if (filename.empty())
{
if (mBaseModel.empty())
@@ -2241,31 +2242,31 @@ void LLModelPreview::loadModel(std::string filename, S32 lod)
// if we don't have a base model to show for high LOD.
mFMP->closeFloater(false);
}
-
+
mLoading = false;
return;
}
-
+
mLODFile[lod] = filename;
if (lod == LLModel::LOD_HIGH)
{
clearGLODGroup();
}
-
+
mModelLoader = new LLModelLoader(filename, lod, this);
-
+
mModelLoader->start();
-
+
mFMP->childSetTextArg("status", "[STATUS]", mFMP->getString("status_reading_file"));
-
+
setPreviewLOD(lod);
if ( mModelLoader->getLoadState() == LLModelLoader::ERROR_PARSING )
{
mFMP->childDisable("ok_btn");
}
-
+
if (lod == mPreviewLOD)
{
mFMP->childSetText("lod_file", mLODFile[mPreviewLOD]);
@@ -2274,14 +2275,14 @@ void LLModelPreview::loadModel(std::string filename, S32 lod)
{
mFMP->childSetText("physics_file", mLODFile[lod]);
}
-
+
mFMP->openFloater();
}
void LLModelPreview::setPhysicsFromLOD(S32 lod)
{
assert_main_thread();
-
+
if (lod >= 0 && lod <= 3)
{
mModel[LLModel::LOD_PHYSICS] = mModel[lod];
@@ -2306,7 +2307,7 @@ void LLModelPreview::clearIncompatible(S32 lod)
mModel[i].clear();
mScene[i].clear();
mVertexBuffer[i].clear();
-
+
if (i == LLModel::LOD_HIGH)
{
mBaseModel = mModel[lod];
@@ -2345,19 +2346,19 @@ void LLModelPreview::loadModelCallback(S32 lod)
{
return;
}
-
+
mModel[lod] = mModelLoader->mModelList;
mScene[lod] = mModelLoader->mScene;
mVertexBuffer[lod].clear();
-
+
if (lod == LLModel::LOD_PHYSICS)
{
mPhysicsMesh.clear();
}
-
+
setPreviewLOD(lod);
-
-
+
+
if (lod == LLModel::LOD_HIGH)
{ //save a copy of the highest LOD for automatic LOD manipulation
if (mBaseModel.empty())
@@ -2371,16 +2372,16 @@ void LLModelPreview::loadModelCallback(S32 lod)
mBaseScene = mScene[lod];
mVertexBuffer[5].clear();
}
-
+
clearIncompatible(lod);
-
+
mDirty = true;
-
+
if (lod == LLModel::LOD_HIGH)
{
resetPreviewTarget();
}
-
+
mLoading = false;
refresh();
}
@@ -2395,71 +2396,71 @@ void LLModelPreview::resetPreviewTarget()
void LLModelPreview::generateNormals()
{
assert_main_thread();
-
+
S32 which_lod = mPreviewLOD;
-
-
+
+
if (which_lod > 4 || which_lod < 0 ||
mModel[which_lod].empty())
{
return;
}
-
+
F32 angle_cutoff = mFMP->childGetValue("crease_angle").asReal();
-
+
angle_cutoff *= DEG_TO_RAD;
-
+
if (which_lod == 3 && !mBaseModel.empty())
{
for (LLModelLoader::model_list::iterator iter = mBaseModel.begin(); iter != mBaseModel.end(); ++iter)
{
(*iter)->generateNormals(angle_cutoff);
}
-
+
mVertexBuffer[5].clear();
}
-
+
for (LLModelLoader::model_list::iterator iter = mModel[which_lod].begin(); iter != mModel[which_lod].end(); ++iter)
{
(*iter)->generateNormals(angle_cutoff);
}
-
+
mVertexBuffer[which_lod].clear();
refresh();
-
+
}
void LLModelPreview::consolidate()
{
std::map<LLImportMaterial, std::vector<LLModelInstance> > composite;
-
+
LLMatrix4 identity;
-
+
//bake out each node in current scene to composite
for (LLModelLoader::scene::iterator iter = mScene[mPreviewLOD].begin(); iter != mScene[mPreviewLOD].end(); ++iter)
{ //for each transform in current scene
LLMatrix4 mat = iter->first;
glh::matrix4f inv_trans = glh::matrix4f((F32*) mat.mMatrix).inverse().transpose();
LLMatrix4 norm_mat(inv_trans.m);
-
+
for (LLModelLoader::model_instance_list::iterator model_iter = iter->second.begin(); model_iter != iter->second.end(); ++model_iter)
{ //for each instance with that transform
LLModelInstance& source_instance = *model_iter;
LLModel* source = source_instance.mModel;
-
+
if (!validate_model(source))
{
llerrs << "Invalid model found!" << llendl;
}
-
+
for (S32 i = 0; i < source->getNumVolumeFaces(); ++i)
{ //for each face in instance
const LLVolumeFace& src_face = source->getVolumeFace(i);
LLImportMaterial& source_material = source_instance.mMaterial[i];
-
+
//get model in composite that is composite for this material
LLModel* model = NULL;
-
+
if (composite.find(source_material) != composite.end())
{
model = composite[source_material].rbegin()->mModel;
@@ -2468,7 +2469,7 @@ void LLModelPreview::consolidate()
model = NULL;
}
}
-
+
if (model == NULL)
{ //no model found, make new model
std::vector<LLImportMaterial> materials;
@@ -2480,106 +2481,106 @@ void LLModelPreview::consolidate()
model->setNumVolumeFaces(0);
composite[source_material].push_back(LLModelInstance(model, identity, materials));
}
-
+
model->appendFace(src_face, source->mMaterialList[i], mat, norm_mat);
}
}
}
-
-
+
+
//condense composite into as few LLModel instances as possible
LLModelLoader::model_list new_model;
std::vector<LLModelInstance> instance_list;
-
+
LLVolumeParams volume_params;
volume_params.setType(LL_PCODE_PROFILE_SQUARE, LL_PCODE_PATH_LINE);
-
+
std::vector<LLImportMaterial> empty_material;
LLModelInstance cur_instance(new LLModel(volume_params, 0.f), identity, empty_material);
cur_instance.mModel->setNumVolumeFaces(0);
-
+
BOOL first_transform = TRUE;
-
+
LLModelLoader::scene new_scene;
LLVector3 min,max;
-
+
for (std::map<LLImportMaterial, std::vector<LLModelInstance> >::iterator iter = composite.begin();
iter != composite.end();
++iter)
{
std::map<LLImportMaterial, std::vector<LLModelInstance> >::iterator next_iter = iter; ++next_iter;
-
- for (std::vector<LLModelInstance>::iterator instance_iter = iter->second.begin();
+
+ for (std::vector<LLModelInstance>::iterator instance_iter = iter->second.begin();
instance_iter != iter->second.end();
++instance_iter)
{
LLModel* source = instance_iter->mModel;
-
+
if (instance_iter->mMaterial.size() != 1)
{
llerrs << "WTF?" << llendl;
}
-
+
if (source->getNumVolumeFaces() != 1)
{
llerrs << "WTF?" << llendl;
}
-
+
if (source->mMaterialList.size() != 1)
{
llerrs << "WTF?" << llendl;
}
-
+
cur_instance.mModel->addFace(source->getVolumeFace(0));
cur_instance.mMaterial.push_back(instance_iter->mMaterial[0]);
cur_instance.mModel->mMaterialList.push_back(source->mMaterialList[0]);
-
+
BOOL last_model = FALSE;
-
+
std::vector<LLModelInstance>::iterator next_instance = instance_iter; ++next_instance;
-
+
if (next_iter == composite.end() &&
next_instance == iter->second.end())
{
last_model = TRUE;
}
-
+
if (last_model || cur_instance.mModel->getNumVolumeFaces() >= MAX_MODEL_FACES)
{
cur_instance.mModel->mLabel = source->mLabel;
-
+
cur_instance.mModel->optimizeVolumeFaces();
cur_instance.mModel->normalizeVolumeFaces();
-
+
if (!validate_model(cur_instance.mModel))
{
llerrs << "Invalid model detected." << llendl;
}
-
+
new_model.push_back(cur_instance.mModel);
-
+
LLMatrix4 transformation = LLMatrix4();
-
+
// adjust the transformation to compensate for mesh normalization
LLVector3 mesh_scale_vector;
LLVector3 mesh_translation_vector;
cur_instance.mModel->getNormalizedScaleTranslation(mesh_scale_vector, mesh_translation_vector);
-
+
LLMatrix4 mesh_translation;
mesh_translation.setTranslation(mesh_translation_vector);
mesh_translation *= transformation;
transformation = mesh_translation;
-
+
LLMatrix4 mesh_scale;
mesh_scale.initScale(mesh_scale_vector);
mesh_scale *= transformation;
transformation = mesh_scale;
-
+
cur_instance.mTransform = transformation;
-
+
new_scene[transformation].push_back(cur_instance);
stretch_extents(cur_instance.mModel, transformation, min, max, first_transform);
-
+
if (!last_model)
{
cur_instance = LLModelInstance(new LLModel(volume_params, 0.f), identity, empty_material);
@@ -2588,11 +2589,11 @@ void LLModelPreview::consolidate()
}
}
}
-
+
mScene[mPreviewLOD] = new_scene;
mModel[mPreviewLOD] = new_model;
mVertexBuffer[mPreviewLOD].clear();
-
+
if (mPreviewLOD == LLModel::LOD_HIGH)
{
mBaseScene = new_scene;
@@ -2600,13 +2601,13 @@ void LLModelPreview::consolidate()
clearGLODGroup();
mVertexBuffer[5].clear();
}
-
+
mPreviewTarget = (min+max)*0.5f;
mPreviewScale = (max-min)*0.5f;
setPreviewTarget(mPreviewScale.magVec()*2.f);
-
+
clearIncompatible(mPreviewLOD);
-
+
mResourceCost = calcResourceCost();
refresh();
}
@@ -2619,11 +2620,11 @@ void LLModelPreview::clearMaterials()
{ //for each instance with that transform
LLModelInstance& source_instance = *model_iter;
LLModel* source = source_instance.mModel;
-
+
for (S32 i = 0; i < source->getNumVolumeFaces(); ++i)
{ //for each face in instance
LLImportMaterial& source_material = source_instance.mMaterial[i];
-
+
//clear material info
source_material.mDiffuseColor = LLColor4(1,1,1,1);
source_material.mDiffuseMap = NULL;
@@ -2633,9 +2634,9 @@ void LLModelPreview::clearMaterials()
}
}
}
-
+
mVertexBuffer[mPreviewLOD].clear();
-
+
if (mPreviewLOD == LLModel::LOD_HIGH)
{
mBaseScene = mScene[mPreviewLOD];
@@ -2643,7 +2644,7 @@ void LLModelPreview::clearMaterials()
clearGLODGroup();
mVertexBuffer[5].clear();
}
-
+
mResourceCost = calcResourceCost();
refresh();
}
@@ -2669,21 +2670,21 @@ void LLModelPreview::genLODs(S32 which_lod, U32 decimation)
{
return;
}
-
+
if (which_lod == LLModel::LOD_PHYSICS)
{ //clear physics mesh map
mPhysicsMesh.clear();
}
-
+
LLVertexBuffer::unbind();
-
+
stop_gloderror();
static U32 cur_name = 1;
-
+
S32 limit = -1;
-
+
U32 triangle_count = 0;
-
+
for (LLModelLoader::model_list::iterator iter = mBaseModel.begin(); iter != mBaseModel.end(); ++iter)
{
LLModel* mdl = *iter;
@@ -2692,13 +2693,13 @@ void LLModelPreview::genLODs(S32 which_lod, U32 decimation)
triangle_count += mdl->getVolumeFace(i).mNumIndices/3;
}
}
-
+
U32 base_triangle_count = triangle_count;
-
+
U32 type_mask = LLVertexBuffer::MAP_VERTEX | LLVertexBuffer::MAP_NORMAL | LLVertexBuffer::MAP_TEXCOORD0;
-
+
U32 lod_mode = 0;
-
+
LLCtrlSelectionInterface* iface = mFMP->childGetSelectionInterface("lod_mode");
if (iface)
{
@@ -2706,7 +2707,7 @@ void LLModelPreview::genLODs(S32 which_lod, U32 decimation)
}
F32 lod_error_threshold = mFMP->childGetValue("lod_error_threshold").asReal();
-
+
if (lod_mode == 0)
{
lod_mode = GLOD_TRIANGLE_BUDGET;
@@ -2812,14 +2813,14 @@ void LLModelPreview::genLODs(S32 which_lod, U32 decimation)
for (LLModelLoader::model_list::iterator iter = mBaseModel.begin(); iter != mBaseModel.end(); ++iter)
{ //build GLOD objects for each model in base model list
LLModel* mdl = *iter;
-
+
if (mObject[mdl] != 0)
{
glodDeleteObject(mObject[mdl]);
}
mObject[mdl] = cur_name++;
-
+
glodNewObject(mObject[mdl], mGroup, GLOD_DISCRETE);
stop_gloderror();
@@ -2827,12 +2828,12 @@ void LLModelPreview::genLODs(S32 which_lod, U32 decimation)
{ //regenerate vertex buffer for skinned models to prevent animation feedback during LOD generation
mVertexBuffer[5].clear();
}
-
+
if (mVertexBuffer[5].empty())
{
genBuffers(5, false);
}
-
+
U32 tri_count = 0;
for (U32 i = 0; i < mVertexBuffer[5][mdl].size(); ++i)
{
@@ -2862,16 +2863,16 @@ void LLModelPreview::genLODs(S32 which_lod, U32 decimation)
stop_gloderror();
}
}
-
-
+
+
S32 start = LLModel::LOD_HIGH;
S32 end = 0;
-
+
if (which_lod != -1)
{
start = end = which_lod;
}
-
+
mMaxTriangleLimit = base_triangle_count;
for (S32 lod = start; lod >= end; --lod)
@@ -2887,58 +2888,58 @@ void LLModelPreview::genLODs(S32 which_lod, U32 decimation)
{
triangle_count = limit;
}
-
+
mModel[lod].clear();
mModel[lod].resize(mBaseModel.size());
mVertexBuffer[lod].clear();
-
+
U32 actual_tris = 0;
U32 actual_verts = 0;
U32 submeshes = 0;
-
+
glodGroupParameteri(mGroup, GLOD_ADAPT_MODE, lod_mode);
- stop_gloderror();
-
+ stop_gloderror();
+
glodGroupParameteri(mGroup, GLOD_ERROR_MODE, GLOD_OBJECT_SPACE_ERROR);
stop_gloderror();
-
+
glodGroupParameteri(mGroup, GLOD_MAX_TRIANGLES, triangle_count);
stop_gloderror();
-
+
glodGroupParameterf(mGroup, GLOD_OBJECT_SPACE_ERROR_THRESHOLD, lod_error_threshold);
stop_gloderror();
-
+
glodAdaptGroup(mGroup);
stop_gloderror();
for (U32 mdl_idx = 0; mdl_idx < mBaseModel.size(); ++mdl_idx)
- {
+ {
LLModel* base = mBaseModel[mdl_idx];
-
+
GLint patch_count = 0;
glodGetObjectParameteriv(mObject[base], GLOD_NUM_PATCHES, &patch_count);
stop_gloderror();
-
+
LLVolumeParams volume_params;
volume_params.setType(LL_PCODE_PROFILE_SQUARE, LL_PCODE_PATH_LINE);
mModel[lod][mdl_idx] = new LLModel(volume_params, 0.f);
-
+
GLint* sizes = new GLint[patch_count*2];
glodGetObjectParameteriv(mObject[base], GLOD_PATCH_SIZES, sizes);
stop_gloderror();
-
+
GLint* names = new GLint[patch_count];
glodGetObjectParameteriv(mObject[base], GLOD_PATCH_NAMES, names);
stop_gloderror();
-
+
mModel[lod][mdl_idx]->setNumVolumeFaces(patch_count);
-
+
LLModel* target_model = mModel[lod][mdl_idx];
-
+
for (GLint i = 0; i < patch_count; ++i)
{
LLPointer<LLVertexBuffer> buff = new LLVertexBuffer(type_mask, 0);
-
+
if (sizes[i*2+1] > 0 && sizes[i*2] > 0)
{
buff->allocateBuffer(sizes[i*2+1], sizes[i*2], true);
@@ -2952,30 +2953,30 @@ void LLModelPreview::genLODs(S32 which_lod, U32 decimation)
memset(buff->getMappedData(), 0, buff->getSize());
memset(buff->getIndicesPointer(), 0, buff->getIndicesSize());
}
-
+
buff->validateRange(0, buff->getNumVerts()-1, buff->getNumIndices(), 0);
-
+
LLStrider<LLVector3> pos;
LLStrider<LLVector3> norm;
LLStrider<LLVector2> tc;
LLStrider<U16> index;
-
+
buff->getVertexStrider(pos);
buff->getNormalStrider(norm);
buff->getTexCoord0Strider(tc);
buff->getIndexStrider(index);
-
+
target_model->setVolumeFaceData(names[i], pos, norm, tc, index, buff->getNumVerts(), buff->getNumIndices());
actual_tris += buff->getNumIndices()/3;
actual_verts += buff->getNumVerts();
++submeshes;
-
+
if (!validate_face(target_model->getVolumeFace(names[i])))
{
llerrs << "Invalid face generated during LOD generation." << llendl;
}
}
-
+
//blind copy skin weights and just take closest skin weight to point on
//decimated mesh for now (auto-generating LODs with skin weights is still a bit
//of an open problem).
@@ -2988,20 +2989,20 @@ void LLModelPreview::genLODs(S32 which_lod, U32 decimation)
target_model->mAlternateBindMatrix = base->mAlternateBindMatrix;
//copy material list
target_model->mMaterialList = base->mMaterialList;
-
+
if (!validate_model(target_model))
{
llerrs << "Invalid model generated when creating LODs" << llendl;
}
-
+
delete [] sizes;
delete [] names;
}
-
+
//rebuild scene based on mBaseScene
mScene[lod].clear();
mScene[lod] = mBaseScene;
-
+
for (U32 i = 0; i < mBaseModel.size(); ++i)
{
LLModel* mdl = mBaseModel[i];
@@ -3021,14 +3022,14 @@ void LLModelPreview::genLODs(S32 which_lod, U32 decimation)
}
}
}
-
+
mResourceCost = calcResourceCost();
-
+
/*if (which_lod == -1 && mScene[LLModel::LOD_PHYSICS].empty())
{ //build physics scene
mScene[LLModel::LOD_PHYSICS] = mScene[LLModel::LOD_LOW];
mModel[LLModel::LOD_PHYSICS] = mModel[LLModel::LOD_LOW];
-
+
for (U32 i = 1; i < mModel[LLModel::LOD_PHYSICS].size(); ++i)
{
mPhysicsQ.push(mModel[LLModel::LOD_PHYSICS][i]);
@@ -3039,47 +3040,47 @@ void LLModelPreview::genLODs(S32 which_lod, U32 decimation)
void LLModelPreview::updateStatusMessages()
{
assert_main_thread();
-
+
//triangle/vertex/submesh count for each mesh asset for each lod
std::vector<S32> tris[LLModel::NUM_LODS];
std::vector<S32> verts[LLModel::NUM_LODS];
std::vector<S32> submeshes[LLModel::NUM_LODS];
-
+
//total triangle/vertex/submesh count for each lod
S32 total_tris[LLModel::NUM_LODS];
S32 total_verts[LLModel::NUM_LODS];
S32 total_submeshes[LLModel::NUM_LODS];
-
+
for (S32 lod = 0; lod < LLModel::NUM_LODS; ++lod)
{
//initialize total for this lod to 0
total_tris[lod] = total_verts[lod] = total_submeshes[lod] = 0;
-
+
for (U32 i = 0; i < mModel[lod].size(); ++i)
{ //for each model in the lod
S32 cur_tris = 0;
S32 cur_verts = 0;
S32 cur_submeshes = mModel[lod][i]->getNumVolumeFaces();
-
+
for (S32 j = 0; j < cur_submeshes; ++j)
{ //for each submesh (face), add triangles and vertices to current total
const LLVolumeFace& face = mModel[lod][i]->getVolumeFace(j);
cur_tris += face.mNumIndices/3;
cur_verts += face.mNumVertices;
}
-
+
//add this model to the lod total
total_tris[lod] += cur_tris;
total_verts[lod] += cur_verts;
total_submeshes[lod] += cur_submeshes;
-
+
//store this model's counts to asset data
tris[lod].push_back(cur_tris);
verts[lod].push_back(cur_verts);
submeshes[lod].push_back(cur_submeshes);
}
}
-
+
if (mMaxTriangleLimit == 0)
{
mMaxTriangleLimit = total_tris[LLModel::LOD_HIGH];
@@ -3087,11 +3088,11 @@ void LLModelPreview::updateStatusMessages()
mFMP->childSetTextArg("submeshes_info", "[SUBMESHES]", llformat("%d", total_submeshes[LLModel::LOD_HIGH]));
-
+
std::string mesh_status_na = mFMP->getString("mesh_status_na");
-
+
S32 upload_status[LLModel::LOD_HIGH+1];
-
+
bool upload_ok = true;
for (S32 lod = 0; lod <= LLModel::LOD_HIGH; ++lod)
@@ -3127,9 +3128,9 @@ void LLModelPreview::updateStatusMessages()
mFMP->childSetText(lod_triangles_name[lod], mesh_status_na);
mFMP->childSetText(lod_vertices_name[lod], mesh_status_na);
}
-
+
const U32 lod_high = LLModel::LOD_HIGH;
-
+
if (lod != lod_high)
{
if (total_submeshes[lod] && total_submeshes[lod] != total_submeshes[lod_high])
@@ -3147,7 +3148,7 @@ void LLModelPreview::updateStatusMessages()
for (U32 i = 0; i < verts[lod].size(); ++i)
{
S32 max_verts = i < verts[lod+1].size() ? verts[lod+1][i] : 0;
-
+
if (max_verts > 0)
{
if (verts[lod][i] > max_verts)
@@ -3159,12 +3160,12 @@ void LLModelPreview::updateStatusMessages()
}
}
}
-
+
LLIconCtrl* icon = mFMP->getChild<LLIconCtrl>(lod_icon_name[lod]);
LLUIImagePtr img = LLUI::getUIImage(lod_status_image[upload_status[lod]]);
icon->setVisible(true);
icon->setImage(img);
-
+
if (upload_status[lod] >= 2)
{
upload_ok = false;
@@ -3177,9 +3178,9 @@ void LLModelPreview::updateStatusMessages()
icon->setImage(img);
}
}
-
+
bool errorStateFromLoader = mModelLoader->getLoadState() == LLModelLoader::ERROR_PARSING ? true : false;
-
+
if ( upload_ok && !errorStateFromLoader )
{
mFMP->childEnable("ok_btn");
@@ -3262,7 +3263,7 @@ void LLModelPreview::updateStatusMessages()
//bool use_hull = fmp->childGetValue("physics_use_hull").asBoolean();
//fmp->childSetEnabled("physics_optimize", !use_hull);
-
+
bool enable = phys_tris > 0 || phys_hulls > 0;
//enable = enable && !use_hull && fmp->childGetValue("physics_optimize").asBoolean();
@@ -3283,10 +3284,10 @@ void LLModelPreview::updateStatusMessages()
{
child->setEnabled(enable);
child = panel->findNextSibling(child);
- }
+ }
}
- const char* lod_controls[] =
+ const char* lod_controls[] =
{
"lod_mode",
"lod_triangle_limit",
@@ -3311,7 +3312,7 @@ void LLModelPreview::updateStatusMessages()
//enable/disable controls based on radio groups
if (mFMP->childGetValue("lod_from_file").asBoolean())
- {
+ {
for (U32 i = 0; i < num_file_controls; ++i)
{
mFMP->childEnable(file_controls[i]);
@@ -3322,7 +3323,7 @@ void LLModelPreview::updateStatusMessages()
mFMP->childDisable(lod_controls[i]);
}
-
+
}
else if (mFMP->childGetValue("lod_none").asBoolean())
{
@@ -3346,8 +3347,8 @@ void LLModelPreview::updateStatusMessages()
updateStatusMessages();
return;
}
-
-
+
+
}
else
{ // auto generate, also the default case for wizard which has no radio selection
@@ -3362,7 +3363,7 @@ void LLModelPreview::updateStatusMessages()
}
//if (threshold)
- {
+ {
U32 lod_mode = 0;
LLCtrlSelectionInterface* iface = mFMP->childGetSelectionInterface("lod_mode");
if (iface)
@@ -3406,7 +3407,7 @@ void LLModelPreview::updateStatusMessages()
}
void LLModelPreview::setPreviewTarget(F32 distance)
-{
+{
mCameraDistance = distance;
mCameraZoom = 1.f;
mCameraPitch = 0.f;
@@ -3427,9 +3428,9 @@ void LLModelPreview::genBuffers(S32 lod, bool include_skin_weights)
U32 tri_count = 0;
U32 vertex_count = 0;
U32 mesh_count = 0;
-
+
LLModelLoader::model_list* model = NULL;
-
+
if (lod < 0 || lod > 4)
{
model = &mBaseModel;
@@ -3439,16 +3440,16 @@ void LLModelPreview::genBuffers(S32 lod, bool include_skin_weights)
{
model = &(mModel[lod]);
}
-
+
if (!mVertexBuffer[lod].empty())
{
mVertexBuffer[lod].clear();
}
-
+
mVertexBuffer[lod].clear();
-
+
LLModelLoader::model_list::iterator base_iter = mBaseModel.begin();
-
+
for (LLModelLoader::model_list::iterator iter = model->begin(); iter != model->end(); ++iter)
{
LLModel* mdl = *iter;
@@ -3456,94 +3457,94 @@ void LLModelPreview::genBuffers(S32 lod, bool include_skin_weights)
{
continue;
}
-
+
LLModel* base_mdl = *base_iter;
base_iter++;
-
+
for (S32 i = 0; i < mdl->getNumVolumeFaces(); ++i)
{
const LLVolumeFace &vf = mdl->getVolumeFace(i);
U32 num_vertices = vf.mNumVertices;
U32 num_indices = vf.mNumIndices;
-
+
if (!num_vertices || ! num_indices)
{
continue;
}
-
+
LLVertexBuffer* vb = NULL;
-
+
bool skinned = include_skin_weights && !mdl->mSkinWeights.empty();
-
+
U32 mask = LLVertexBuffer::MAP_VERTEX | LLVertexBuffer::MAP_NORMAL | LLVertexBuffer::MAP_TEXCOORD0;
-
+
if (skinned)
{
mask |= LLVertexBuffer::MAP_WEIGHT4;
}
-
+
vb = new LLVertexBuffer(mask, 0);
-
+
vb->allocateBuffer(num_vertices, num_indices, TRUE);
-
+
LLStrider<LLVector3> vertex_strider;
LLStrider<LLVector3> normal_strider;
LLStrider<LLVector2> tc_strider;
LLStrider<U16> index_strider;
LLStrider<LLVector4> weights_strider;
-
+
vb->getVertexStrider(vertex_strider);
vb->getNormalStrider(normal_strider);
vb->getTexCoord0Strider(tc_strider);
vb->getIndexStrider(index_strider);
-
+
if (skinned)
{
vb->getWeight4Strider(weights_strider);
}
-
+
LLVector4a::memcpyNonAliased16((F32*) vertex_strider.get(), (F32*) vf.mPositions, num_vertices*4*sizeof(F32));
LLVector4a::memcpyNonAliased16((F32*) tc_strider.get(), (F32*) vf.mTexCoords, num_vertices*2*sizeof(F32));
LLVector4a::memcpyNonAliased16((F32*) normal_strider.get(), (F32*) vf.mNormals, num_vertices*4*sizeof(F32));
-
+
if (skinned)
{
for (U32 i = 0; i < num_vertices; i++)
{
//find closest weight to vf.mVertices[i].mPosition
LLVector3 pos(vf.mPositions[i].getF32ptr());
-
+
const LLModel::weight_list& weight_list = base_mdl->getJointInfluences(pos);
-
+
LLVector4 w(0,0,0,0);
if (weight_list.size() > 4)
{
llerrs << "WTF?" << llendl;
}
-
+
for (U32 i = 0; i < weight_list.size(); ++i)
{
F32 wght = llmin(weight_list[i].mWeight, 0.999999f);
F32 joint = (F32) weight_list[i].mJointIdx;
w.mV[i] = joint + wght;
}
-
+
*(weights_strider++) = w;
}
}
-
+
// build indices
for (U32 i = 0; i < num_indices; i++)
{
*(index_strider++) = vf.mIndices[i];
}
-
+
mVertexBuffer[lod][mdl].push_back(vb);
-
+
vertex_count += num_vertices;
tri_count += num_indices/3;
++mesh_count;
-
+
}
}
}
@@ -3574,10 +3575,10 @@ void LLModelPreview::update()
BOOL LLModelPreview::render()
{
assert_main_thread();
-
+
LLMutexLock lock(this);
mNeedsUpdate = FALSE;
-
+
bool edges = false;
bool joint_positions = false;
bool skin_weight = false;
@@ -3596,28 +3597,28 @@ BOOL LLModelPreview::render()
S32 width = getWidth();
S32 height = getHeight();
-
+
LLGLSUIDefault def;
LLGLDisable no_blend(GL_BLEND);
LLGLEnable cull(GL_CULL_FACE);
LLGLDepthTest depth(GL_TRUE);
LLGLDisable fog(GL_FOG);
-
+
{
//clear background to blue
glMatrixMode(GL_PROJECTION);
gGL.pushMatrix();
glLoadIdentity();
glOrtho(0.0f, width, 0.0f, height, -1.0f, 1.0f);
-
+
glMatrixMode(GL_MODELVIEW);
gGL.pushMatrix();
glLoadIdentity();
-
+
gGL.color4f(0.15f, 0.2f, 0.3f, 1.f);
-
+
gl_rect_2d_simple( width, height );
-
+
glMatrixMode(GL_PROJECTION);
gGL.popMatrix();
@@ -3628,7 +3629,7 @@ BOOL LLModelPreview::render()
bool has_skin_weights = false;
bool upload_skin = mFMP->childGetValue("upload_skin").asBoolean();
bool upload_joints = mFMP->childGetValue("upload_joints").asBoolean();
-
+
for (LLModelLoader::scene::iterator iter = mScene[mPreviewLOD].begin(); iter != mScene[mPreviewLOD].end(); ++iter)
{
for (LLModelLoader::model_instance_list::iterator model_iter = iter->second.begin(); model_iter != iter->second.end(); ++model_iter)
@@ -3662,79 +3663,79 @@ BOOL LLModelPreview::render()
}
skin_weight = false;
}
-
+
if (upload_skin && !has_skin_weights)
{ //can't upload skin weights if model has no skin weights
mFMP->childSetValue("upload_skin", false);
upload_skin = false;
}
-
+
if (!upload_skin && upload_joints)
{ //can't upload joints if not uploading skin weights
mFMP->childSetValue("upload_joints", false);
upload_joints = false;
}
-
+
mFMP->childSetEnabled("upload_joints", upload_skin);
-
+
F32 explode = mFMP->childGetValue("physics_explode").asReal();
-
+
glClear(GL_DEPTH_BUFFER_BIT);
-
+
LLRect preview_rect = mFMP->getChildView("preview_panel")->getRect();
F32 aspect = (F32) preview_rect.getWidth()/preview_rect.getHeight();
LLViewerCamera::getInstance()->setAspect(aspect);
-
+
LLViewerCamera::getInstance()->setView(LLViewerCamera::getInstance()->getDefaultFOV() / mCameraZoom);
-
+
LLVector3 offset = mCameraOffset;
LLVector3 target_pos = mPreviewTarget+offset;
-
+
F32 z_near = 0.001f;
F32 z_far = mCameraDistance+mPreviewScale.magVec()+mCameraOffset.magVec();
-
+
if (skin_weight)
{
target_pos = gAgentAvatarp->getPositionAgent();
z_near = 0.01f;
z_far = 1024.f;
mCameraDistance = 16.f;
-
+
//render avatar previews every frame
refresh();
}
-
+
glLoadIdentity();
gPipeline.enableLightsPreview();
- LLQuaternion camera_rot = LLQuaternion(mCameraPitch, LLVector3::y_axis) *
+ LLQuaternion camera_rot = LLQuaternion(mCameraPitch, LLVector3::y_axis) *
LLQuaternion(mCameraYaw, LLVector3::z_axis);
-
+
LLQuaternion av_rot = camera_rot;
LLViewerCamera::getInstance()->setOriginAndLookAt(
target_pos + ((LLVector3(mCameraDistance, 0.f, 0.f) + offset) * av_rot), // camera
LLVector3::z_axis, // up
target_pos); // point of interest
-
-
+
+
LLViewerCamera::getInstance()->setPerspective(FALSE, mOrigin.mX, mOrigin.mY, width, height, FALSE, z_near, z_far);
-
+
stop_glerror();
-
+
gGL.pushMatrix();
const F32 BRIGHTNESS = 0.9f;
gGL.color3f(BRIGHTNESS, BRIGHTNESS, BRIGHTNESS);
-
+
LLGLEnable normalize(GL_NORMALIZE);
-
+
if (!mBaseModel.empty() && mVertexBuffer[5].empty())
{
genBuffers(-1, skin_weight);
//genBuffers(3);
//genLODs();
}
-
+
if (!mModel[mPreviewLOD].empty())
{
bool regen = mVertexBuffer[mPreviewLOD].empty();
@@ -3752,31 +3753,31 @@ BOOL LLModelPreview::render()
{
genBuffers(mPreviewLOD, skin_weight);
}
-
+
if (!skin_weight)
{
for (LLMeshUploadThread::instance_list::iterator iter = mUploadData.begin(); iter != mUploadData.end(); ++iter)
{
LLModelInstance& instance = *iter;
-
+
LLModel* model = instance.mLOD[mPreviewLOD];
-
+
if (!model)
{
continue;
}
-
+
gGL.pushMatrix();
LLMatrix4 mat = instance.mTransform;
- glMultMatrixf((GLfloat*) mat.mMatrix);
-
+ glMultMatrixf((GLfloat*) mat.mMatrix);
+
for (U32 i = 0; i < mVertexBuffer[mPreviewLOD][model].size(); ++i)
{
LLVertexBuffer* buffer = mVertexBuffer[mPreviewLOD][model][i];
-
+
buffer->setBuffer(LLVertexBuffer::MAP_VERTEX | LLVertexBuffer::MAP_NORMAL | LLVertexBuffer::MAP_TEXCOORD0);
-
+
if (textures)
{
glColor4fv(instance.mMaterial[i].mDiffuseColor.mV);
@@ -3793,11 +3794,11 @@ BOOL LLModelPreview::render()
{
glColor4f(1,1,1,1);
}
-
+
buffer->drawRange(LLRender::TRIANGLES, 0, buffer->getNumVerts()-1, buffer->getNumIndices(), 0);
gGL.getTexUnit(0)->unbind(LLTexUnit::TT_TEXTURE);
glColor3f(0.4f, 0.4f, 0.4f);
-
+
if (edges)
{
glLineWidth(3.f);
@@ -3809,7 +3810,7 @@ BOOL LLModelPreview::render()
}
gGL.popMatrix();
}
-
+
if (physics)
{
glClear(GL_DEPTH_BUFFER_BIT);
@@ -3819,7 +3820,7 @@ BOOL LLModelPreview::render()
for (LLMeshUploadThread::instance_list::iterator iter = mUploadData.begin(); iter != mUploadData.end(); ++iter)
{
LLModelInstance& instance = *iter;
-
+
LLModel* model = instance.mLOD[LLModel::LOD_PHYSICS];
if (!model)
@@ -3830,17 +3831,17 @@ BOOL LLModelPreview::render()
gGL.pushMatrix();
LLMatrix4 mat = instance.mTransform;
- glMultMatrixf((GLfloat*) mat.mMatrix);
+ glMultMatrixf((GLfloat*) mat.mMatrix);
+
-
bool render_mesh = true;
LLPhysicsDecomp* decomp = gMeshRepo.mDecompThread;
if (decomp)
{
LLMutexLock(decomp->mMutex);
-
- std::map<LLPointer<LLModel>, std::vector<LLPointer<LLVertexBuffer> > >::iterator iter =
+
+ std::map<LLPointer<LLModel>, std::vector<LLPointer<LLVertexBuffer> > >::iterator iter =
mPhysicsMesh.find(model);
if (iter != mPhysicsMesh.end())
{ //render hull instead of mesh
@@ -3850,29 +3851,29 @@ BOOL LLModelPreview::render()
if (explode > 0.f)
{
gGL.pushMatrix();
-
+
LLVector3 offset = model->mHullCenter[i]-model->mCenterOfHullCenters;
offset *= explode;
-
+
gGL.translatef(offset.mV[0], offset.mV[1], offset.mV[2]);
}
-
+
static std::vector<LLColor4U> hull_colors;
-
+
if (i+1 >= hull_colors.size())
{
hull_colors.push_back(LLColor4U(rand()%128+127, rand()%128+127, rand()%128+127, 255));
}
-
+
LLVertexBuffer* buff = iter->second[i];
if (buff)
{
- buff->setBuffer(LLVertexBuffer::MAP_VERTEX | LLVertexBuffer::MAP_NORMAL);
-
+ buff->setBuffer(LLVertexBuffer::MAP_VERTEX | LLVertexBuffer::MAP_NORMAL);
+
glColor4ubv(hull_colors[i].mV);
buff->drawArrays(LLRender::TRIANGLES, 0, buff->getNumVerts());
}
-
+
if (explode > 0.f)
{
gGL.popMatrix();
@@ -3880,7 +3881,7 @@ BOOL LLModelPreview::render()
}
}
}
-
+
if (render_mesh)
{
if (mVertexBuffer[LLModel::LOD_PHYSICS].empty())
@@ -3892,15 +3893,15 @@ BOOL LLModelPreview::render()
LLVertexBuffer* buffer = mVertexBuffer[LLModel::LOD_PHYSICS][model][i];
buffer->setBuffer(LLVertexBuffer::MAP_VERTEX | LLVertexBuffer::MAP_NORMAL | LLVertexBuffer::MAP_TEXCOORD0);
-
+
buffer->drawRange(LLRender::TRIANGLES, 0, buffer->getNumVerts()-1, buffer->getNumIndices(), 0);
gGL.getTexUnit(0)->unbind(LLTexUnit::TT_TEXTURE);
glColor4f(0.4f, 0.4f, 0.0f, 0.4f);
-
+
buffer->drawRange(LLRender::TRIANGLES, 0, buffer->getNumVerts()-1, buffer->getNumIndices(), 0);
glColor3f(1.f, 1.f, 0.f);
-
+
glLineWidth(3.f);
glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
buffer->drawRange(LLRender::TRIANGLES, 0, buffer->getNumVerts()-1, buffer->getNumIndices(), 0);
@@ -3908,10 +3909,10 @@ BOOL LLModelPreview::render()
glLineWidth(1.f);
}
}
-
+
gGL.popMatrix();
}
-
+
gGL.setSceneBlendType(LLRender::BT_ALPHA);
}
}
@@ -3919,40 +3920,40 @@ BOOL LLModelPreview::render()
{
LLVOAvatarSelf* avatar = gAgentAvatarp;
target_pos = avatar->getPositionAgent();
-
+
LLViewerCamera::getInstance()->setOriginAndLookAt(
target_pos + ((LLVector3(mCameraDistance, 0.f, 0.f) + offset) * av_rot), // camera
LLVector3::z_axis, // up
target_pos); // point of interest
-
+
if (joint_positions)
{
avatar->renderCollisionVolumes();
}
-
+
for (LLModelLoader::scene::iterator iter = mScene[mPreviewLOD].begin(); iter != mScene[mPreviewLOD].end(); ++iter)
{
for (LLModelLoader::model_instance_list::iterator model_iter = iter->second.begin(); model_iter != iter->second.end(); ++model_iter)
{
LLModelInstance& instance = *model_iter;
LLModel* model = instance.mModel;
-
+
if (!model->mSkinWeights.empty())
{
for (U32 i = 0; i < mVertexBuffer[mPreviewLOD][model].size(); ++i)
{
LLVertexBuffer* buffer = mVertexBuffer[mPreviewLOD][model][i];
-
+
const LLVolumeFace& face = model->getVolumeFace(i);
-
+
LLStrider<LLVector3> position;
buffer->getVertexStrider(position);
-
+
LLStrider<LLVector4> weight;
buffer->getWeight4Strider(weight);
-
+
//quick 'n dirty software vertex skinning
-
+
//build matrix palette
LLMatrix4 mat[64];
for (U32 j = 0; j < model->mJointList.size(); ++j)
@@ -3964,55 +3965,55 @@ BOOL LLModelPreview::render()
mat[j] *= joint->getWorldMatrix();
}
}
-
+
for (U32 j = 0; j < buffer->getRequestedVerts(); ++j)
{
LLMatrix4 final_mat;
final_mat.mMatrix[0][0] = final_mat.mMatrix[1][1] = final_mat.mMatrix[2][2] = final_mat.mMatrix[3][3] = 0.f;
-
+
LLVector4 wght;
S32 idx[4];
-
+
F32 scale = 0.f;
for (U32 k = 0; k < 4; k++)
{
F32 w = weight[j].mV[k];
-
+
idx[k] = (S32) floorf(w);
wght.mV[k] = w - floorf(w);
scale += wght.mV[k];
}
-
- wght *= 1.f/scale;
-
+
+ wght *= 1.f/scale;
+
for (U32 k = 0; k < 4; k++)
{
F32* src = (F32*) mat[idx[k]].mMatrix;
F32* dst = (F32*) final_mat.mMatrix;
-
+
F32 w = wght.mV[k];
-
+
for (U32 l = 0; l < 16; l++)
{
dst[l] += src[l]*w;
}
}
-
+
//VECTORIZE THIS
LLVector3 v(face.mPositions[j].getF32ptr());
-
+
v = v * model->mBindShapeMatrix;
v = v * final_mat;
-
+
position[j] = v;
}
-
+
buffer->setBuffer(LLVertexBuffer::MAP_VERTEX | LLVertexBuffer::MAP_NORMAL | LLVertexBuffer::MAP_TEXCOORD0);
glColor4fv(instance.mMaterial[i].mDiffuseColor.mV);
gGL.getTexUnit(0)->unbind(LLTexUnit::TT_TEXTURE);
buffer->draw(LLRender::TRIANGLES, buffer->getNumIndices(), 0);
glColor3f(0.4f, 0.4f, 0.4f);
-
+
if (edges)
{
glLineWidth(3.f);
@@ -4027,9 +4028,9 @@ BOOL LLModelPreview::render()
}
}
}
-
+
gGL.popMatrix();
-
+
return TRUE;
}
@@ -4037,8 +4038,8 @@ BOOL LLModelPreview::render()
// refresh()
//-----------------------------------------------------------------------------
void LLModelPreview::refresh()
-{
- mNeedsUpdate = TRUE;
+{
+ mNeedsUpdate = TRUE;
}
//-----------------------------------------------------------------------------
@@ -4047,7 +4048,7 @@ void LLModelPreview::refresh()
void LLModelPreview::rotate(F32 yaw_radians, F32 pitch_radians)
{
mCameraYaw = mCameraYaw + yaw_radians;
-
+
mCameraPitch = llclamp(mCameraPitch + pitch_radians, F_PI_BY_TWO * -0.8f, F_PI_BY_TWO * 0.8f);
}
@@ -4057,7 +4058,7 @@ void LLModelPreview::rotate(F32 yaw_radians, F32 pitch_radians)
void LLModelPreview::zoom(F32 zoom_amt)
{
F32 new_zoom = mCameraZoom+zoom_amt;
-
+
mCameraZoom = llclamp(new_zoom, 1.f, 10.f);
}
@@ -4074,7 +4075,7 @@ void LLModelPreview::setPreviewLOD(S32 lod)
if (lod != mPreviewLOD)
{
mPreviewLOD = lod;
-
+
LLComboBox* combo_box = mFMP->getChild<LLComboBox>("preview_lod_combo");
combo_box->setCurrentByIndex((NUM_LOD-1)-mPreviewLOD); // combo box list of lods is in reverse order
mFMP->childSetTextArg("lod_table_footer", "[DETAIL]", mFMP->getString(lod_name[mPreviewLOD]));
@@ -4097,11 +4098,11 @@ void LLModelPreview::setPreviewLOD(S32 lod)
updateStatusMessages();
}
-//static
+//static
void LLFloaterModelPreview::onBrowseLOD(void* data)
{
assert_main_thread();
-
+
LLFloaterModelPreview* mp = (LLFloaterModelPreview*) data;
mp->loadModel(mp->mModelPreview->mPreviewLOD);
}
@@ -4110,26 +4111,26 @@ void LLFloaterModelPreview::onBrowseLOD(void* data)
void LLFloaterModelPreview::onUpload(void* user_data)
{
assert_main_thread();
-
+
LLFloaterModelPreview* mp = (LLFloaterModelPreview*) user_data;
mp->mModelPreview->rebuildUploadData();
-
- gMeshRepo.uploadModel(mp->mModelPreview->mUploadData, mp->mModelPreview->mPreviewScale,
+
+ gMeshRepo.uploadModel(mp->mModelPreview->mUploadData, mp->mModelPreview->mPreviewScale,
mp->childGetValue("upload_textures").asBoolean(), mp->childGetValue("upload_skin"), mp->childGetValue("upload_joints"));
-
+
mp->closeFloater(false);
}
-//static
+//static
void LLFloaterModelPreview::onClearMaterials(void* user_data)
{
LLFloaterModelPreview* mp = (LLFloaterModelPreview*) user_data;
mp->mModelPreview->clearMaterials();
}
-//static
+//static
void LLFloaterModelPreview::refresh(LLUICtrl* ctrl, void* user_data)
{
sInstance->mModelPreview->mDirty = true;
@@ -4155,15 +4156,15 @@ LLFloaterModelPreview::DecompRequest::DecompRequest(const std::string& stage, LL
mModel = mdl;
mDecompID = &mdl->mDecompID;
mParams = sInstance->mDecompParams;
-
+
//copy out positions and indices
if (mdl)
{
U16 index_offset = 0;
-
+
mPositions.clear();
mIndices.clear();
-
+
//queue up vertex positions and indices
for (S32 i = 0; i < mdl->getNumVolumeFaces(); ++i)
{
@@ -4172,17 +4173,17 @@ LLFloaterModelPreview::DecompRequest::DecompRequest(const std::string& stage, LL
{
continue;
}
-
+
for (U32 j = 0; j < face.mNumVertices; ++j)
{
mPositions.push_back(LLVector3(face.mPositions[j].getF32ptr()));
}
-
+
for (U32 j = 0; j < face.mNumIndices; ++j)
{
mIndices.push_back(face.mIndices[j]+index_offset);
}
-
+
index_offset += face.mNumVertices;
}
}
@@ -4208,16 +4209,16 @@ S32 LLFloaterModelPreview::DecompRequest::statusCallback(const char* status, S32
void LLFloaterModelPreview::DecompRequest::completed()
{ //called from the main thread
mModel->setConvexHullDecomposition(mHull);
-
- if (sInstance)
- {
+
+ if (sInstance)
+ {
if (sInstance->mModelPreview)
{
sInstance->mModelPreview->mPhysicsMesh[mModel] = mHullMesh;
sInstance->mModelPreview->mDirty = true;
LLFloaterModelPreview::sInstance->mModelPreview->refresh();
}
-
+
sInstance->mCurRequest.erase(this);
}
}