diff options
Diffstat (limited to 'indra/newview/llfloatermodelpreview.cpp')
-rw-r--r-- | indra/newview/llfloatermodelpreview.cpp | 2485 |
1 files changed, 1262 insertions, 1223 deletions
diff --git a/indra/newview/llfloatermodelpreview.cpp b/indra/newview/llfloatermodelpreview.cpp index 73707ad2f1..85cc205dab 100644 --- a/indra/newview/llfloatermodelpreview.cpp +++ b/indra/newview/llfloatermodelpreview.cpp @@ -105,28 +105,54 @@ const S32 PREVIEW_TEXTURE_HEIGHT = 300; void drawBoxOutline(const LLVector3& pos, const LLVector3& size); -std::string limit_name[] = -{ - "lowest limit", - "low limit", - "medium limit", - "high limit", - "physics limit", - "I went off the end of the limit_name array. Me so smart." +std::string lod_name[] = +{ + "lowest", + "low", + "medium", + "high", + "I went off the end of the lod_name array. Me so smart." +}; + +std::string lod_triangles_name[] = +{ + "lowest_triangles", + "low_triangles", + "medium_triangles", + "high_triangles", + "I went off the end of the lod_triangles_name array. Me so smart." }; -std::string info_name[] = +std::string lod_vertices_name[] = { - "lowest info", - "low info", - "medium info", - "high info", - "physics info", + "lowest_vertices", + "low_vertices", + "medium_vertices", + "high_vertices", + "I went off the end of the lod_vertices_name array. Me so smart." +}; + +std::string lod_status_name[] = +{ + "lowest_status", + "low_status", + "medium_status", + "high_status", + "I went off the end of the lod_status_name array. Me so smart." +}; - "I went off the end of the info_name array. Me so smart." +std::string lod_label_name[] = +{ + "lowest_label", + "low_label", + "medium_label", + "high_label", + "I went off the end of the lod_label_name array. Me so smart." }; + + bool validate_face(const LLVolumeFace& face) { for (U32 i = 0; i < face.mNumIndices; ++i) @@ -137,7 +163,7 @@ bool validate_face(const LLVolumeFace& face) return false; } } - + return true; } @@ -156,62 +182,48 @@ 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; } -LLPhysicsDecompFloater::LLPhysicsDecompFloater(LLSD& key) -: LLFloater(key) -{ - -} - -LLPhysicsDecompFloater::~LLPhysicsDecompFloater() -{ - if (LLFloaterModelPreview::sInstance && LLFloaterModelPreview::sInstance->mDecompFloater) - { - LLFloaterModelPreview::sInstance->mDecompFloater = NULL; - } -} - class LLMeshFilePicker : public LLFilePickerThread { public: LLFloaterModelPreview* mFMP; S32 mLOD; - + LLMeshFilePicker(LLFloaterModelPreview* fmp, S32 lod) - : LLFilePickerThread(LLFilePicker::FFLOAD_COLLADA) + : LLFilePickerThread(LLFilePicker::FFLOAD_COLLADA) { mFMP = fmp; mLOD = lod; } - + virtual void notify(const std::string& filename) { mFMP->mModelPreview->loadModel(mFile, mLOD); @@ -223,14 +235,13 @@ public: // LLFloaterModelPreview() //----------------------------------------------------------------------------- LLFloaterModelPreview::LLFloaterModelPreview(const LLSD& key) : - LLFloater(key) +LLFloater(key) { sInstance = this; mLastMouseX = 0; mLastMouseY = 0; mGLName = 0; mLoading = FALSE; - mDecompFloater = NULL; } //----------------------------------------------------------------------------- @@ -242,76 +253,74 @@ BOOL LLFloaterModelPreview::postBuild() { return FALSE; } - - childSetCommitCallback("high detail combo", onHighLODCommit, this); - childSetCommitCallback("medium detail combo", onMediumLODCommit, this); - childSetCommitCallback("low detail combo", onLowLODCommit, this); - childSetCommitCallback("lowest detail combo", onLowestLODCommit, this); - childSetCommitCallback("physics detail combo", onPhysicsLODCommit, this); - - - childSetCommitCallback("high limit", onHighLimitCommit, this); - childSetCommitCallback("medium limit", onMediumLimitCommit, this); - childSetCommitCallback("low limit", onLowLimitCommit, this); - childSetCommitCallback("lowest limit", onLowestLimitCommit, this); - childSetCommitCallback("physics limit", onPhysicsLimitCommit, this); - - childSetCommitCallback("smooth normals", onSmoothNormalsCommit, this); - + + childSetAction("lod_browse", onBrowseLOD, this); + childSetCommitCallback("lod_triangle_limit", onTriangleLimitCommit, this); + + childSetCommitCallback("crease_angle", onGenerateNormalsCommit, this); + childSetCommitCallback("generate_normals", onGenerateNormalsCommit, this); + childSetCommitCallback("show edges", onShowEdgesCommit, this); - childSetCommitCallback("auto fill", onAutoFillCommit, this); - + childSetCommitCallback("lod_generate", onAutoFillCommit, this); + childSetTextArg("status", "[STATUS]", getString("status_idle")); - - for (S32 lod = 0; lod < LLModel::NUM_LODS; ++lod) - { - if (lod == LLModel::LOD_PHYSICS) - { - childSetTextArg(info_name[lod], "[TRIANGLES]", std::string("0")); - childSetTextArg(info_name[lod], "[HULLS]", std::string("0")); - childSetTextArg(info_name[lod], "[POINTS]", std::string("0")); - } - else - { - childSetTextArg(info_name[lod], "[TRIANGLES]", std::string("0")); - childSetTextArg(info_name[lod], "[VERTICES]", std::string("0")); - childSetTextArg(info_name[lod], "[SUBMESHES]", std::string("0")); - std::string msg = getString("required"); - childSetTextArg(info_name[lod], "[MESSAGE]", msg); - } - - childSetVisible(limit_name[lod], FALSE); - } - + //childSetLabelArg("ok_btn", "[AMOUNT]", llformat("%d",sUploadAmount)); childSetAction("ok_btn", onUpload, this); - + childSetAction("consolidate", onConsolidate, this); - childSetAction("scrub materials", onScrubMaterials, this); - - childSetAction("decompose_btn", onDecompose, this); - + 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("debug scale", onDebugScaleCommit, this); - + childSetCommitCallback("lod_file_or_limit", refresh, this); + childSetCommitCallback("physics_load_radio", refresh, this); + childDisable("upload_skin"); childDisable("upload_joints"); + + initDecompControls(); + + LLView* preview_panel = getChild<LLView>("preview_panel"); - const U32 width = 512; - const U32 height = 512; - - mPreviewRect.set(getRect().getWidth()-PREVIEW_HPAD-width, - PREVIEW_HPAD+height, - getRect().getWidth()-PREVIEW_HPAD, - PREVIEW_HPAD); - + 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++) + { + LLTextBox* text = getChild<LLTextBox>(lod_label_name[i]); + if (text) + { + text->setMouseDownCallback(boost::bind(&LLModelPreview::setPreviewLOD, mModelPreview, i)); + } + + text = getChild<LLTextBox>(lod_triangles_name[i]); + if (text) + { + text->setMouseDownCallback(boost::bind(&LLModelPreview::setPreviewLOD, mModelPreview, i)); + } + + text = getChild<LLTextBox>(lod_vertices_name[i]); + if (text) + { + text->setMouseDownCallback(boost::bind(&LLModelPreview::setPreviewLOD, mModelPreview, i)); + } + + text = getChild<LLTextBox>(lod_status_name[i]); + if (text) + { + text->setMouseDownCallback(boost::bind(&LLModelPreview::setPreviewLOD, mModelPreview, i)); + } + } + return TRUE; } @@ -321,7 +330,7 @@ BOOL LLFloaterModelPreview::postBuild() LLFloaterModelPreview::~LLFloaterModelPreview() { sInstance = NULL; - + if ( mModelPreview->containsRiggedAsset() ) { gAgentAvatarp->resetJointPositions(); @@ -333,71 +342,13 @@ LLFloaterModelPreview::~LLFloaterModelPreview() { LLImageGL::deleteTextures(1, &mGLName ); } - - if (mDecompFloater) - { - mDecompFloater->closeFloater(); - mDecompFloater = NULL; - } } void LLFloaterModelPreview::loadModel(S32 lod) { mLoading = TRUE; - - (new LLMeshFilePicker(this, lod))->getFile(); -} - -void LLFloaterModelPreview::setLODMode(S32 lod, S32 mode) -{ - if (mode == 0) - { - if (lod != LLModel::LOD_PHYSICS) - { - for (S32 i = lod; i >= 0; i--) - { - mModelPreview->clearModel(i); - } - } - else - { - mModelPreview->clearModel(lod); - } - - mModelPreview->refresh(); - mModelPreview->calcResourceCost(); - } - else if (mode == 1) - { - loadModel(lod); - } - else if (mode != mModelPreview->mLODMode[lod]) - { - mModelPreview->mLODMode[lod] = mode; - mModelPreview->genLODs(lod); - } - - mModelPreview->setPreviewLOD(lod); - - LLSpinCtrl* lim = getChild<LLSpinCtrl>(limit_name[lod], TRUE); - - if (mode == 2) //triangle count - { - U32 tri_count = 0; - for (LLModelLoader::model_list::iterator iter = mModelPreview->mBaseModel.begin(); - iter != mModelPreview->mBaseModel.end(); ++iter) - { - tri_count += (*iter)->getNumTriangles(); - } - - lim->setMaxValue(tri_count); - lim->setVisible(TRUE); - } - else - { - lim->setVisible(FALSE); - } + (new LLMeshFilePicker(this, lod))->getFile(); } void LLFloaterModelPreview::setLimit(S32 lod, S32 limit) @@ -411,7 +362,7 @@ void LLFloaterModelPreview::setLimit(S32 lod, S32 limit) } //static -void LLFloaterModelPreview::onDebugScaleCommit(LLUICtrl*,void* userdata) +void LLFloaterModelPreview::onImportScaleCommit(LLUICtrl*,void* userdata) { LLFloaterModelPreview *fp =(LLFloaterModelPreview *)userdata; @@ -419,8 +370,9 @@ void LLFloaterModelPreview::onDebugScaleCommit(LLUICtrl*,void* userdata) { return; } - + fp->mModelPreview->calcResourceCost(); + fp->mModelPreview->refresh(); } //static @@ -432,7 +384,7 @@ void LLFloaterModelPreview::onUploadJointsCommit(LLUICtrl*,void* userdata) { return; } - + fp->mModelPreview->refresh(); } @@ -445,12 +397,12 @@ void LLFloaterModelPreview::onUploadSkinCommit(LLUICtrl*,void* userdata) { return; } - + fp->mModelPreview->refresh(); fp->mModelPreview->resetPreviewTarget(); fp->mModelPreview->clearBuffers(); } - + //static void LLFloaterModelPreview::onPreviewLODCommit(LLUICtrl* ctrl, void* userdata) { @@ -460,9 +412,9 @@ void LLFloaterModelPreview::onPreviewLODCommit(LLUICtrl* ctrl, void* userdata) { return; } - + S32 which_mode = 0; - + LLCtrlSelectionInterface* iface = fp->childGetSelectionInterface("preview_lod_combo"); if (iface) { @@ -472,68 +424,6 @@ void LLFloaterModelPreview::onPreviewLODCommit(LLUICtrl* ctrl, void* userdata) } //static -void LLFloaterModelPreview::setLODMode(S32 lod, void* userdata) -{ - LLFloaterModelPreview *fp =(LLFloaterModelPreview *)userdata; - - if (!fp->mModelPreview) - { - return; - } - - S32 which_mode = 0; - - std::string combo_name[] = - { - "lowest detail combo", - "low detail combo", - "medium detail combo", - "high detail combo", - "physics detail combo", - - "I went off the end of the combo_name array. Me so smart." - }; - - LLCtrlSelectionInterface* iface = fp->childGetSelectionInterface(combo_name[lod]); - if (iface) - { - which_mode = iface->getFirstSelectedIndex(); - } - - fp->setLODMode(lod, which_mode); -} - -//static -void LLFloaterModelPreview::onHighLODCommit(LLUICtrl* ctrl, void* userdata) -{ - LLFloaterModelPreview::setLODMode(3, userdata); -} - -//static -void LLFloaterModelPreview::onMediumLODCommit(LLUICtrl* ctrl, void* userdata) -{ - LLFloaterModelPreview::setLODMode(2, userdata); -} - -//static -void LLFloaterModelPreview::onLowLODCommit(LLUICtrl* ctrl, void* userdata) -{ - LLFloaterModelPreview::setLODMode(1, userdata); -} - -//static -void LLFloaterModelPreview::onLowestLODCommit(LLUICtrl* ctrl, void* userdata) -{ - LLFloaterModelPreview::setLODMode(0, userdata); -} - -//static -void LLFloaterModelPreview::onPhysicsLODCommit(LLUICtrl* ctrl, void* userdata) -{ - LLFloaterModelPreview::setLODMode(4, userdata); -} - -//static void LLFloaterModelPreview::setLimit(S32 lod, void* userdata) { LLFloaterModelPreview *fp =(LLFloaterModelPreview *)userdata; @@ -542,56 +432,34 @@ void LLFloaterModelPreview::setLimit(S32 lod, void* userdata) { return; } - - S32 limit = fp->childGetValue(limit_name[lod]).asInteger(); - + + S32 limit = fp->childGetValue("lod_triangle_limit").asInteger(); + fp->setLimit(lod, limit); } //static -void LLFloaterModelPreview::onHighLimitCommit(LLUICtrl* ctrl, void* userdata) -{ - LLFloaterModelPreview::setLimit(3, userdata); -} - -//static -void LLFloaterModelPreview::onMediumLimitCommit(LLUICtrl* ctrl, void* userdata) -{ - LLFloaterModelPreview::setLimit(2, userdata); -} - -//static -void LLFloaterModelPreview::onLowLimitCommit(LLUICtrl* ctrl, void* userdata) +void LLFloaterModelPreview::onTriangleLimitCommit(LLUICtrl* ctrl, void* userdata) { - LLFloaterModelPreview::setLimit(1, userdata); -} - -//static -void LLFloaterModelPreview::onLowestLimitCommit(LLUICtrl* ctrl, void* userdata) -{ - LLFloaterModelPreview::setLimit(0, userdata); -} + LLFloaterModelPreview* fp = (LLFloaterModelPreview*) userdata; -//static -void LLFloaterModelPreview::onPhysicsLimitCommit(LLUICtrl* ctrl, void* userdata) -{ - LLFloaterModelPreview::setLimit(4, userdata); + LLFloaterModelPreview::setLimit(fp->mModelPreview->mPreviewLOD, userdata); } //static -void LLFloaterModelPreview::onSmoothNormalsCommit(LLUICtrl* ctrl, void* userdata) +void LLFloaterModelPreview::onGenerateNormalsCommit(LLUICtrl* ctrl, void* userdata) { LLFloaterModelPreview* fp = (LLFloaterModelPreview*) userdata; - - fp->mModelPreview->smoothNormals(); + + fp->mModelPreview->generateNormals(); } //static void LLFloaterModelPreview::onShowEdgesCommit(LLUICtrl* ctrl, void* userdata) { LLFloaterModelPreview* fp = (LLFloaterModelPreview*) userdata; - + fp->mModelPreview->refresh(); } @@ -599,7 +467,7 @@ void LLFloaterModelPreview::onShowEdgesCommit(LLUICtrl* ctrl, void* userdata) void LLFloaterModelPreview::onExplodeCommit(LLUICtrl* ctrl, void* userdata) { LLFloaterModelPreview* fp = LLFloaterModelPreview::sInstance; - + fp->mModelPreview->refresh(); } @@ -607,7 +475,7 @@ void LLFloaterModelPreview::onExplodeCommit(LLUICtrl* ctrl, void* userdata) void LLFloaterModelPreview::onAutoFillCommit(LLUICtrl* ctrl, void* userdata) { LLFloaterModelPreview* fp = (LLFloaterModelPreview*) userdata; - + fp->mModelPreview->genLODs(); } @@ -619,7 +487,7 @@ void LLFloaterModelPreview::draw() { LLFloater::draw(); LLRect r = getRect(); - + mModelPreview->update(); if (!mLoading) @@ -627,24 +495,16 @@ void LLFloaterModelPreview::draw() childSetTextArg("status", "[STATUS]", getString("status_idle")); } - childSetTextArg("description_label", "[PRIM_COST]", llformat("%d", mModelPreview->mResourceCost)); + childSetTextArg("prim_cost", "[PRIM_COST]", llformat("%d", mModelPreview->mResourceCost)); childSetTextArg("description_label", "[TEXTURES]", llformat("%d", mModelPreview->mTextureSet.size())); - - if (mDecompFloater) + + if (mCurRequest.notNull()) { - if (mCurRequest.notNull()) - { - mDecompFloater->childSetText("status", mCurRequest->mStatusMessage); - } - else - { - const std::string idle("Idle."); - mDecompFloater->childSetText("status", idle); - } + childSetTextArg("status", "[STATUS]", mCurRequest->mStatusMessage); } - + U32 resource_cost = mModelPreview->mResourceCost*10; - + if (childGetValue("upload_textures").asBoolean()) { resource_cost += mModelPreview->mTextureSet.size()*10; @@ -655,9 +515,19 @@ void LLFloaterModelPreview::draw() if (mModelPreview) { gGL.color3f(1.f, 1.f, 1.f); - + gGL.getTexUnit(0)->bind(mModelPreview); + + LLView* preview_panel = getChild<LLView>("preview_panel"); + + LLRect rect = preview_panel->getRect(); + if (rect != mPreviewRect) + { + mModelPreview->refresh(); + mPreviewRect = preview_panel->getRect(); + } + gGL.begin( LLRender::QUADS ); { gGL.texCoord2f(0.f, 1.f); @@ -670,7 +540,7 @@ void LLFloaterModelPreview::draw() gGL.vertex2i(mPreviewRect.mRight, mPreviewRect.mTop); } gGL.end(); - + gGL.getTexUnit(0)->unbind(LLTexUnit::TT_TEXTURE); } } @@ -689,7 +559,7 @@ BOOL LLFloaterModelPreview::handleMouseDown(S32 x, S32 y, MASK mask) mLastMouseY = y; return TRUE; } - + return LLFloater::handleMouseDown(x, y, mask); } @@ -709,7 +579,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) @@ -726,20 +596,20 @@ BOOL LLFloaterModelPreview::handleHover (S32 x, S32 y, MASK mask) } 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); @@ -756,7 +626,7 @@ BOOL LLFloaterModelPreview::handleHover (S32 x, S32 y, MASK mask) { gViewerWindow->setCursor(UI_CURSOR_TOOLZOOMIN); } - + return TRUE; } @@ -770,7 +640,7 @@ BOOL LLFloaterModelPreview::handleScrollWheel(S32 x, S32 y, S32 clicks) mModelPreview->zoom((F32)clicks * -0.2f); mModelPreview->refresh(); } - + return TRUE; } @@ -782,7 +652,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; @@ -796,7 +666,7 @@ void LLFloaterModelPreview::onPhysicsStageExecute(LLUICtrl* ctrl, void* data) LLCDStageData* stage = (LLCDStageData*) data; LLModel* mdl = NULL; - + if (sInstance) { if (sInstance->mCurRequest.notNull()) @@ -804,16 +674,13 @@ void LLFloaterModelPreview::onPhysicsStageExecute(LLUICtrl* ctrl, void* data) llinfos << "Decomposition request still pending." << llendl; return; } - + if (sInstance->mModelPreview) { - if (sInstance->mDecompFloater) + S32 idx = sInstance->childGetValue("physics_layer").asInteger(); + if (idx >= 0 && idx < sInstance->mModelPreview->mModel[LLModel::LOD_PHYSICS].size()) { - S32 idx = sInstance->mDecompFloater->childGetValue("model").asInteger(); - if (idx >= 0 && idx < sInstance->mModelPreview->mModel[LLModel::LOD_PHYSICS].size()) - { - mdl = sInstance->mModelPreview->mModel[LLModel::LOD_PHYSICS][idx]; - } + mdl = sInstance->mModelPreview->mModel[LLModel::LOD_PHYSICS][idx]; } } } @@ -823,8 +690,61 @@ void LLFloaterModelPreview::onPhysicsStageExecute(LLUICtrl* ctrl, void* data) sInstance->mCurRequest = new DecompRequest(stage->mName, mdl); gMeshRepo.mDecompThread->submitRequest(sInstance->mCurRequest); } + + const std::string decompose("Decompose"); + + if (decompose == stage->mName) + { //hide decompose panel and show simplify panel + sInstance->childSetVisible("physics step 2", false); + sInstance->childSetVisible("physics step 3", true); + } +} + +//static +void LLFloaterModelPreview::onPhysicsOptimize(LLUICtrl* ctrl, void *data) +{ + //hide step 1 panel and show step 2 panel + info + sInstance->childSetVisible("physics step 1", false); + sInstance->childSetVisible("physics step 2", true); + sInstance->childSetVisible("physics info", true); +} + +//static +void LLFloaterModelPreview::onPhysicsBrowse(LLUICtrl* ctrl, void* userdata) +{ + sInstance->loadModel(LLModel::LOD_PHYSICS); } +//static +void LLFloaterModelPreview::onPhysicsUseLOD(LLUICtrl* ctrl, void* userdata) +{ + S32 which_mode = 3; + LLCtrlSelectionInterface* iface = sInstance->childGetSelectionInterface("physics_lod_combo"); + if (iface) + { + which_mode = iface->getFirstSelectedIndex(); + } + + sInstance->mModelPreview->setPhysicsFromLOD(which_mode); +} + +//static +void LLFloaterModelPreview::onPhysicsDecomposeBack(LLUICtrl* ctrl, void* userdata) +{ + //hide step 2 panel and info and show step 1 panel + sInstance->childSetVisible("physics step 1", true); + sInstance->childSetVisible("physics step 2", false); + sInstance->childSetVisible("physics info", false); +} + +//static +void LLFloaterModelPreview::onPhysicsSimplifyBack(LLUICtrl* ctrl, void* userdata) +{ + //hide step 3 panel and show step 2 panel + sInstance->childSetVisible("physics step 3", false); + sInstance->childSetVisible("physics step 2", true); +} + //static void LLFloaterModelPreview::onPhysicsStageCancel(LLUICtrl* ctrl, void*data) { @@ -833,266 +753,135 @@ void LLFloaterModelPreview::onPhysicsStageCancel(LLUICtrl* ctrl, void*data) sInstance->mCurRequest->mContinue = 0; } } - -void LLFloaterModelPreview::showDecompFloater() + +void LLFloaterModelPreview::initDecompControls() { - if (!mDecompFloater) + LLSD key; + + childSetCommitCallback("cancel_btn", onPhysicsStageCancel, NULL); + childSetCommitCallback("physics_lod_combo", onPhysicsUseLOD, NULL); + childSetCommitCallback("physics_browse", onPhysicsBrowse, NULL); + childSetCommitCallback("physics_optimize", onPhysicsOptimize, NULL); + childSetCommitCallback("decompose_back", onPhysicsDecomposeBack, NULL); + childSetCommitCallback("simplify_back", onPhysicsSimplifyBack, NULL); + childSetCommitCallback("physics_layer", refresh, NULL); + + static const LLCDStageData* stage = NULL; + static S32 stage_count = 0; + + if (!stage && LLConvexDecomposition::getInstance() != NULL) { - LLSD key; - mDecompFloater = new LLPhysicsDecompFloater(key); - - S32 left = 20; - S32 right = 320; - - S32 cur_y = 30; - - { - //add status text - LLTextBox::Params p; - p.name("status"); - p.rect(LLRect(left, cur_y, right-80, cur_y-20)); - mDecompFloater->addChild(LLUICtrlFactory::create<LLTextBox>(p)); - } - - - { //add cancel button - LLButton::Params p; - p.name("Cancel"); - p.label("Cancel"); - p.rect(LLRect(right-80, cur_y, right, cur_y-20)); - LLButton* button = LLUICtrlFactory::create<LLButton>(p); - button->setCommitCallback(onPhysicsStageCancel, NULL); - mDecompFloater->addChild(button); - } - - cur_y += 30; - - - 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) + 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(¶m); + } + + for (S32 j = stage_count-1; j >= 0; --j) + { + LLButton* button = getChild<LLButton>(stage[j].mName); + if (button) { - param_count = LLConvexDecomposition::getInstance()->getParameters(¶m); + button->setCommitCallback(onPhysicsStageExecute, (void*) &stage[j]); } - for (S32 j = stage_count-1; j >= 0; --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) { - LLButton::Params p; - p.name(stage[j].mName); - p.label(stage[j].mName); - p.rect(LLRect(left, cur_y, right, cur_y-20)); - LLButton* button = LLUICtrlFactory::create<LLButton>(p); - button->setCommitCallback(onPhysicsStageExecute, (void*) &stage[j]); - mDecompFloater->addChild(button); - gMeshRepo.mDecompThread->mStageID[stage[j].mName] = j; - cur_y += 30; - // 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) { - 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) + 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) { - mDecompParams[param[i].mName] = LLSD(param[i].mDefault.mFloat); - llinfos << "Type: float, Default: " << param[i].mDefault.mFloat << llendl; - - LLSliderCtrl::Params p; - p.name(name); - p.label(name); - p.rect(LLRect(left, cur_y, right, cur_y-20)); - p.min_value(param[i].mDetails.mRange.mLow.mFloat); - p.max_value(param[i].mDetails.mRange.mHigh.mFloat); - p.increment(param[i].mDetails.mRange.mDelta.mFloat); - p.tool_tip(description); - p.decimal_digits(3); - p.initial_value(param[i].mDefault.mFloat); - LLSliderCtrl* slider = LLUICtrlFactory::create<LLSliderCtrl>(p); + slider->setMinValue(param[i].mDetails.mRange.mLow.mFloat); + slider->setMaxValue(param[i].mDetails.mRange.mHigh.mFloat); + slider->setIncrement(param[i].mDetails.mRange.mDelta.mFloat); + slider->setValue(param[i].mDefault.mFloat); slider->setCommitCallback(onPhysicsParamCommit, (void*) ¶m[i]); - mDecompFloater->addChild(slider); - cur_y += 30; } - else if (param[i].mType == LLCDParam::LLCD_INTEGER) + } + else if (param[i].mType == LLCDParam::LLCD_INTEGER) + { + 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) { - mDecompParams[param[i].mName] = LLSD(param[i].mDefault.mIntOrEnumValue); - llinfos << "Type: integer, Default: " << param[i].mDefault.mIntOrEnumValue << llendl; - LLSliderCtrl::Params p; - p.name(name); - p.label(name); - p.rect(LLRect(left, cur_y, right, cur_y-20)); - p.min_value(param[i].mDetails.mRange.mLow.mIntOrEnumValue); - p.max_value(param[i].mDetails.mRange.mHigh.mIntOrEnumValue); - p.increment(param[i].mDetails.mRange.mDelta.mIntOrEnumValue); - p.tool_tip(description); - p.initial_value(param[i].mDefault.mIntOrEnumValue); - LLSliderCtrl* slider = LLUICtrlFactory::create<LLSliderCtrl>(p); + slider->setMinValue(param[i].mDetails.mRange.mLow.mIntOrEnumValue); + slider->setMaxValue(param[i].mDetails.mRange.mHigh.mIntOrEnumValue); + slider->setIncrement(param[i].mDetails.mRange.mDelta.mIntOrEnumValue); + slider->setValue(param[i].mDefault.mIntOrEnumValue); slider->setCommitCallback(onPhysicsParamCommit, (void*) ¶m[i]); - mDecompFloater->addChild(slider); - cur_y += 30; } - else if (param[i].mType == LLCDParam::LLCD_BOOLEAN) + } + else if (param[i].mType == LLCDParam::LLCD_BOOLEAN) + { + 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) { - mDecompParams[param[i].mName] = LLSD(param[i].mDefault.mBool); - llinfos << "Type: boolean, Default: " << (param[i].mDefault.mBool ? "True" : "False") << llendl; - - LLCheckBoxCtrl::Params p; - p.rect(LLRect(left, cur_y, right, cur_y-20)); - p.name(name); - p.label(name); - p.initial_value(param[i].mDefault.mBool); - p.tool_tip(description); - LLCheckBoxCtrl* check_box = LLUICtrlFactory::create<LLCheckBoxCtrl>(p); + check_box->setValue(param[i].mDefault.mBool); check_box->setCommitCallback(onPhysicsParamCommit, (void*) ¶m[i]); - mDecompFloater->addChild(check_box); - cur_y += 30; } - else if (param[i].mType == LLCDParam::LLCD_ENUM) - { - S32 cur_x = left; - mDecompParams[param[i].mName] = LLSD(param[i].mDefault.mIntOrEnumValue); - llinfos << "Type: enum, Default: " << param[i].mDefault.mIntOrEnumValue << llendl; - - { //add label - LLTextBox::Params p; - const LLFontGL* font = (LLFontGL*) p.font(); - - p.rect(LLRect(left, cur_y, left+font->getWidth(name), cur_y-20)); - p.name(name); - p.label(name); - p.initial_value(name); - LLTextBox* text_box = LLUICtrlFactory::create<LLTextBox>(p); - mDecompFloater->addChild(text_box); - cur_x += text_box->getRect().getWidth(); - } - - { //add combo_box - LLComboBox::Params p; - p.rect(LLRect(cur_x, cur_y, right-right/4, cur_y-20)); - p.name(name); - p.label(name); - p.tool_tip(description); - - llinfos << "Accepted values: " << llendl; - LLComboBox* combo_box = LLUICtrlFactory::create<LLComboBox>(p); - for (S32 k = 0; k < param[i].mDetails.mEnumValues.mNumEnums; ++k) - { - 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, - LLSD::Integer(param[i].mDetails.mEnumValues.mEnumsArray[k].mValue)); - } - combo_box->setValue(param[i].mDefault.mIntOrEnumValue); - combo_box->setCommitCallback(onPhysicsParamCommit, (void*) ¶m[i]); - mDecompFloater->addChild(combo_box); - cur_y += 30; - - } - - llinfos << "----" << llendl; - } - llinfos << "-----------------------------" << llendl; } - } - - cur_y += 30; - //explode slider - { - LLSliderCtrl::Params p; - p.initial_value(0); - p.min_value(0); - p.max_value(1); - p.decimal_digits(2); - p.increment(0.05f); - p.label("Explode"); - p.name("explode"); - p.rect(LLRect(left, cur_y, right, cur_y-20)); - LLSliderCtrl* slider = LLUICtrlFactory::create<LLSliderCtrl>(p); - - mDecompFloater->addChild(slider); - cur_y += 30; - } - - //mesh render checkbox - { - LLCheckBoxCtrl::Params p; - p.label("Mesh: "); - p.name("render_mesh"); - p.rect(LLRect(left, cur_y, right/4, cur_y-20)); - LLCheckBoxCtrl* check = LLUICtrlFactory::create<LLCheckBoxCtrl>(p); - check->setValue(true); - mDecompFloater->addChild(check); - } - - //hull render checkbox - { - LLCheckBoxCtrl::Params p; - p.label("Hull: "); - p.name("render_hull"); - p.rect(LLRect(right/4, cur_y, right/2, cur_y-20)); - LLCheckBoxCtrl* check = LLUICtrlFactory::create<LLCheckBoxCtrl>(p); - check->setValue(true); - mDecompFloater->addChild(check); - } - - { //submesh combo box label - LLTextBox::Params p; - p.label("Model"); - p.name("model label"); - p.rect(LLRect(right/2, cur_y, right-right/3, cur_y-20)); - LLTextBox* text_box = LLUICtrlFactory::create<LLTextBox>(p); - text_box->setValue("Model"); - mDecompFloater->addChild(text_box); - } - - { - //add submesh combo box - LLComboBox::Params p; - p.rect(LLRect(right-right/2+p.font()->getWidth("Model"), cur_y, right, cur_y-20)); - p.name("model"); - LLComboBox* combo_box = LLUICtrlFactory::create<LLComboBox>(p); - for (S32 i = 0; i < mModelPreview->mBaseModel.size(); ++i) + else if (param[i].mType == LLCDParam::LLCD_ENUM) { - LLModel* mdl = mModelPreview->mBaseModel[i]; - combo_box->add(mdl->mLabel, i); + 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 + // << " - " << param[i].mDetails.mEnumValues.mEnumsArray[k].mName << llendl; + + 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*) ¶m[i]); + } + + //llinfos << "----" << llendl; } - combo_box->setValue(0); - mDecompFloater->addChild(combo_box); - cur_y += 30; + //llinfos << "-----------------------------" << llendl; } - - mDecompFloater->childSetCommitCallback("model", LLFloaterModelPreview::refresh, LLFloaterModelPreview::sInstance); - mDecompFloater->childSetCommitCallback("render_mesh", LLFloaterModelPreview::refresh, LLFloaterModelPreview::sInstance); - mDecompFloater->childSetCommitCallback("render_hull", LLFloaterModelPreview::refresh, LLFloaterModelPreview::sInstance); - - mDecompFloater->setRect(LLRect(10, cur_y+20, right+20, 10)); } - - mDecompFloater->childSetCommitCallback("explode", LLFloaterModelPreview::onExplodeCommit, this); - - mDecompFloater->openFloater(); + + childSetCommitCallback("physics_layer", LLFloaterModelPreview::refresh, LLFloaterModelPreview::sInstance); + childSetCommitCallback("physics_explode", LLFloaterModelPreview::onExplodeCommit, this); + childSetCommitCallback("show physics", LLFloaterModelPreview::refresh, this); } //----------------------------------------------------------------------------- @@ -1136,7 +925,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"; @@ -1163,8 +952,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"; @@ -1200,7 +989,7 @@ 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); @@ -1211,15 +1000,15 @@ void stretch_extents(LLModel* model, LLMatrix4a& mat, LLVector4a& min, LLVector4 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); if (first_transform) @@ -1239,11 +1028,11 @@ 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()); @@ -1254,32 +1043,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(); @@ -1287,14 +1076,14 @@ 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()))); - + daeSafeCast<domAsset::domUp_axis>(root->getDescendant(daeElement::matchType(domAsset::domUp_axis::ID()))); + if (up_axis) { up = up_axis->getValue(); @@ -1308,20 +1097,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); @@ -1329,13 +1118,13 @@ 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()); @@ -1351,7 +1140,7 @@ 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); @@ -1359,13 +1148,13 @@ void LLModelLoader::run() 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); - + domSkin::domBind_shape_matrix* bind_mat = skin->getBind_shape_matrix(); - + if (bind_mat) { //get bind shape matrix domFloat4x4& dom_value = bind_mat->getValue(); @@ -1377,28 +1166,14 @@ void LLModelLoader::run() model->mBindShapeMatrix.mMatrix[i][j] = dom_value[i + j*4]; } } - + LLMatrix4 trans = normalized_transformation; trans *= model->mBindShapeMatrix; model->mBindShapeMatrix = trans; - + } - - /*{ - LLMatrix4 rotation; - if (up == UPAXISTYPE_X_UP) - { - rotation.initRotation(0.0f, 90.0f * DEG_TO_RAD, 0.0f); - } - else if (up == UPAXISTYPE_Z_UP) - { - rotation.initRotation(90.0f * DEG_TO_RAD, 90.0f * DEG_TO_RAD, 0.0f); - } - - rotation *= model->mBindShapeMatrix; - model->mBindShapeMatrix = rotation; - }*/ - + + //The joint transfom map that we'll populate below std::map<std::string,LLMatrix4> jointTransforms; jointTransforms.clear(); @@ -1406,9 +1181,41 @@ void LLModelLoader::run() //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 ); - if ( pSkeleton ) - { + bool missingSkeletonOrScene = false; + + //If no skeleton, do a breadth-first search to get at specific joints + if ( !pSkeleton ) + { + daeElement* pScene = root->getDescendant("visual_scene"); + if ( !pScene ) + { + llwarns<<"No visual scene - unable to parse bone offsets "<<llendl; + missingSkeletonOrScene = true; + } + else + { + //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) + { + domNode* pNode = daeSafeCast<domNode>(children[i]); + if ( isNodeAJoint( pNode ) ) + { + processJointNode( pNode, jointTransforms ); + } + } + } + } + else + //Has Skeleton + { //Get the root node of the skeleton daeElement* pSkeletonRootNode = pSkeleton->getValue().getElement(); if ( pSkeletonRootNode ) @@ -1416,7 +1223,7 @@ void LLModelLoader::run() //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(); - bool missingID = false; + //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 ) { @@ -1426,89 +1233,94 @@ void LLModelLoader::run() //llwarns<<"Joint "<< str <<llendl; //Setup the resolver - daeSIDResolver resolver( pSkeletonRootNode, str ); - - //Look for the joint - domNode* pJoint = daeSafeCast<domNode>(resolver.getElement()); - if ( pJoint ) - { + 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 + + //Translation via SID if ( pTranslate ) { - domFloat3 jointTrans = pTranslate->getValue(); - LLVector3 singleJointTranslation( jointTrans[0], jointTrans[1], jointTrans[2] ); - workingTransform.setTranslation( singleJointTranslation ); + extractTranslation( pTranslate, workingTransform ); } else { - missingID = true; - llwarns<< "No translation sid!" << llendl; + //Translation via child from element + daeElement* pTranslateElement = getChildFromElement( pJoint, "translate" ); + if ( pTranslateElement && pTranslateElement->typeID() != domTranslate::ID() ) + { + llwarns<< "The found element is not a translate node" <<llendl; + missingSkeletonOrScene = true; + } + else + { + extractTranslationViaElement( pTranslateElement, workingTransform ); + } } - //Store the joint transform w/respect to it's name. - jointTransforms[(*jointIt).second.c_str()] = workingTransform; - } - else - { - missingID = true; - llwarns<< "Missing joint." << llendl; - } + //Store the joint transform w/respect to it's name. + jointTransforms[(*jointIt).second.c_str()] = workingTransform; + } } //If anything failed in regards to extracting the skeleton, joints or translation id, //mention it - if ( missingID ) + if ( missingSkeletonOrScene ) { llwarns<< "Partial jointmap found in asset - did you mean to just have a partial map?" << llendl; } - - //Set the joint translations on the avatar - //The joints are reset in the dtor - jointIt = mJointMap.begin(); - for ( int i=0; i<jointCnt; ++i, ++jointIt ) - { - 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() ); - } - else - { - //Most likely an error in the asset. - llwarns<<"Tried to apply joint position from .dae, but it did not exist in the avatar rig." << llendl; - } - } - } - } - else - { - llwarns<<"No root node in this skeleton" << llendl; - } - } - else - { - llwarns<<"No skeleton in this asset" << llendl; + }//got skeleton? } + if ( !missingSkeletonOrScene ) + { + //Set the joint translations on the avatar + //The joints are reset in the dtor + const int jointCnt = mJointMap.size(); + std::map<std::string, std::string> :: const_iterator jointIt = mJointMap.begin(); + for ( int i=0; i<jointCnt; ++i, ++jointIt ) + { + 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() ); + } + else + { + //Most likely an error in the asset. + llwarns<<"Tried to apply joint position from .dae, but it did not exist in the avatar rig." << llendl; + } + //Reposition the avatars pelvis (avPos+offset) + if ( lookingForJoint == "mPelvis" ) + { + const LLVector3& pos = gAgentAvatarp->getCharacterPosition(); + gAgentAvatarp->setPelvisOffset( true, 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(); @@ -1517,13 +1329,13 @@ void LLModelLoader::run() if (source) { - + domName_array* names_source = source->getName_array(); if (names_source) { domListOfNames &names = names_source->getValue(); - + for (size_t j = 0; j < names.getCount(); ++j) { std::string name(names.get(j)); @@ -1541,7 +1353,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()); @@ -1566,11 +1378,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++) @@ -1578,14 +1390,14 @@ 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. @@ -1636,10 +1448,10 @@ void LLModelLoader::run() } 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); } } @@ -1647,7 +1459,7 @@ void LLModelLoader::run() } } } - + //grab skin weights array domSkin::domVertex_weights* weights = skin->getVertex_weights(); if (weights) @@ -1665,44 +1477,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)); } - + //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) @@ -1720,7 +1532,7 @@ void LLModelLoader::run() wght[i].mWeight *= scale; } } - + model->mSkinWeights[model->mPosition[vc_idx]] = wght; } @@ -1738,67 +1550,153 @@ void LLModelLoader::run() } } } - + daeElement* scene = root->getDescendant("visual_scene"); if (!scene) { llwarns << "document has no visual_scene" << llendl; return; } - + processElement(scene); - + mPreview->loadModelCallback(mLod); } } +bool LLModelLoader::isNodeAJoint( domNode* pNode ) +{ + if ( mJointMap.find( pNode->getName() ) != mJointMap.end() ) + { + return true; + } + + return false; +} + +void LLModelLoader::extractTranslation( domTranslate* pTranslate, LLMatrix4& transform ) +{ + domFloat3 jointTrans = pTranslate->getValue(); + LLVector3 singleJointTranslation( jointTrans[0], jointTrans[1], jointTrans[2] ); + transform.setTranslation( singleJointTranslation ); +} + +void LLModelLoader::extractTranslationViaElement( daeElement* pTranslateElement, LLMatrix4& transform ) +{ + domTranslate* pTranslateChild = dynamic_cast<domTranslate*>( pTranslateElement ); + domFloat3 translateChild = pTranslateChild->getValue(); + LLVector3 singleJointTranslation( translateChild[0], translateChild[1], translateChild[2] ); + transform.setTranslation( singleJointTranslation ); +} + +void LLModelLoader::processJointNode( domNode* pNode, std::map<std::string,LLMatrix4>& jointTransforms ) +{ + //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" ); + domTranslate* pTranslate = daeSafeCast<domTranslate>( jointResolver.getElement() ); + + //Translation via SID was successful + if ( pTranslate ) + { + extractTranslation( pTranslate, workingTransform ); + } + else + { + //Translation via child from element + daeElement* pTranslateElement = getChildFromElement( pNode, "translate" ); + if ( !pTranslateElement || pTranslateElement->typeID() != domTranslate::ID() ) + { + 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; + + //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; +} + 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++) @@ -1810,7 +1708,7 @@ void LLModelLoader::processElement(daeElement* element) matrix_transform *= mTransform; mTransform = matrix_transform; } - + domInstance_geometry* instance_geo = daeSafeCast<domInstance_geometry>(element); if (instance_geo) { @@ -1824,14 +1722,14 @@ 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; @@ -1843,13 +1741,13 @@ void LLModelLoader::processElement(daeElement* element) transformation = mesh_scale; mScene[transformation].push_back(LLModelInstance(model, transformation, materials)); - + stretch_extents(model, transformation, mExtents[0], mExtents[1], mFirstTransform); } } } } - + domInstance_node* instance_node = daeSafeCast<domInstance_node>(element); if (instance_node) { @@ -1859,14 +1757,14 @@ 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 @@ -1880,40 +1778,40 @@ 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()))); - + 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()); if (material) { domInstance_effect* instance_effect = - daeSafeCast<domInstance_effect>(material->getDescendant(daeElement::matchType(domInstance_effect::ID()))); + daeSafeCast<domInstance_effect>(material->getDescendant(daeElement::matchType(domInstance_effect::ID()))); if (instance_effect) { domEffect* effect = daeSafeCast<domEffect>(instance_effect->getUrl().getElement()); if (effect) { domProfile_COMMON* profile = - daeSafeCast<domProfile_COMMON>(effect->getDescendant(daeElement::matchType(domProfile_COMMON::ID()))); + daeSafeCast<domProfile_COMMON>(effect->getDescendant(daeElement::matchType(domProfile_COMMON::ID()))); if (profile) { import_material = profileToMaterial(profile); @@ -1925,7 +1823,7 @@ std::vector<LLImportMaterial> LLModelLoader::getMaterials(LLModel* model, domIns materials.push_back(import_material); } - + return materials; } @@ -1933,12 +1831,12 @@ LLImportMaterial LLModelLoader::profileToMaterial(domProfile_COMMON* material) { LLImportMaterial mat; mat.mFullbright = FALSE; - + daeElement* diffuse = material->getDescendant("diffuse"); if (diffuse) { domCommon_color_or_texture_type_complexType::domTexture* texture = - daeSafeCast<domCommon_color_or_texture_type_complexType::domTexture>(diffuse->getDescendant("texture")); + daeSafeCast<domCommon_color_or_texture_type_complexType::domTexture>(diffuse->getDescendant("texture")); if (texture) { domCommon_newparam_type_Array newparams = material->getNewparam_array(); @@ -1962,10 +1860,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); @@ -1978,7 +1876,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")); + daeSafeCast<domCommon_color_or_texture_type_complexType::domColor>(diffuse->getDescendant("color")); if (color) { domFx_color_common domfx_color = color->getValue(); @@ -1986,7 +1884,7 @@ LLImportMaterial LLModelLoader::profileToMaterial(domProfile_COMMON* material) mat.mDiffuseColor = value; } } - + daeElement* emission = material->getDescendant("emission"); if (emission) { @@ -1996,7 +1894,7 @@ LLImportMaterial LLModelLoader::profileToMaterial(domProfile_COMMON* material) mat.mFullbright = TRUE; } } - + return mat; } @@ -2009,13 +1907,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) @@ -2026,21 +1924,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"); } @@ -2049,13 +1947,13 @@ LLColor4 LLModelLoader::getDaeColor(daeElement* element) { LLColor4 value; domCommon_color_or_texture_type_complexType::domColor* color = - daeSafeCast<domCommon_color_or_texture_type_complexType::domColor>(element->getDescendant("color")); + daeSafeCast<domCommon_color_or_texture_type_complexType::domColor>(element->getDescendant("color")); if (color) { domFx_color_common domfx_color = color->getValue(); value = LLColor4(domfx_color[0], domfx_color[1], domfx_color[2], domfx_color[3]); } - + return value; } @@ -2072,20 +1970,17 @@ LLModelPreview::LLModelPreview(S32 width, S32 height, LLFloaterModelPreview* fmp mCameraPitch = 0.f; mCameraZoom = 1.f; mTextureName = 0; - mPreviewLOD = 3; + mPreviewLOD = 0; mModelLoader = NULL; mDirty = false; - + for (U32 i = 0; i < LLModel::NUM_LODS; i++) { - mLODMode[i] = 1; mLimit[i] = 0; } - - mLODMode[0] = 0; - + mFMP = fmp; - + glodInit(); } @@ -2096,7 +1991,7 @@ LLModelPreview::~LLModelPreview() delete mModelLoader; mModelLoader = NULL; } - + //*HACK : *TODO : turn this back on when we understand why this crashes //glodShutdown(); } @@ -2104,40 +1999,39 @@ LLModelPreview::~LLModelPreview() U32 LLModelPreview::calcResourceCost() { rebuildUploadData(); - + U32 cost = 0; std::set<LLModel*> accounted; U32 num_points = 0; U32 num_hulls = 0; - - F32 debug_scale = mFMP->childGetValue("debug scale").asReal(); - + + 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; - + 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[0], - decomp, - mFMP->childGetValue("upload_skin").asBoolean(), - mFMP->childGetValue("upload_joints").asBoolean(), - TRUE); + "", + instance.mLOD[4], + 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(); @@ -2145,12 +2039,12 @@ U32 LLModelPreview::calcResourceCost() { 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; @@ -2158,21 +2052,21 @@ 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(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)); - F32 scale = mFMP->childGetValue("debug scale").asReal()*2.f; - mFMP->childSetTextArg("dimensions", "[X]", llformat("%.3f", mPreviewScale[0]*scale)); - mFMP->childSetTextArg("dimensions", "[Y]", llformat("%.3f", mPreviewScale[1]*scale)); - mFMP->childSetTextArg("dimensions", "[Z]", llformat("%.3f", mPreviewScale[2]*scale)); - + 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; @@ -2182,30 +2076,30 @@ void LLModelPreview::rebuildUploadData() { mUploadData.clear(); mTextureSet.clear(); - + //fill uploaddata instance vectors from scene data - - LLSpinCtrl* scale_spinner = mFMP->getChild<LLSpinCtrl>("debug scale"); - + + LLSpinCtrl* scale_spinner = mFMP->getChild<LLSpinCtrl>("import_scale"); + if (!scale_spinner) { - llerrs << "floater_model_preview.xml MUST contain debug scale spinner." << llendl; + 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; - + 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; @@ -2217,13 +2111,13 @@ void LLModelPreview::rebuildUploadData() 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; - + S32 idx = 0; for (idx = 0; idx < mBaseModel.size(); ++idx) { //find reference instance for this model @@ -2232,7 +2126,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()) @@ -2244,20 +2138,35 @@ 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); } + + //refill "layer" combo in physics panel + LLComboBox* combo_box = mFMP->getChild<LLComboBox>("physics_layer"); + if (combo_box) + { + S32 current = combo_box->getCurrentIndex(); + combo_box->removeall(); + + for (S32 i = 0; i < mBaseModel.size(); ++i) + { + LLModel* mdl = mBaseModel[i]; + combo_box->add(mdl->mLabel, i); + } + combo_box->setCurrentByIndex(current); + } } @@ -2267,7 +2176,7 @@ void LLModelPreview::clearModel(S32 lod) { return; } - + mVertexBuffer[lod].clear(); mModel[lod].clear(); mScene[lod].clear(); @@ -2282,7 +2191,7 @@ void LLModelPreview::loadModel(std::string filename, S32 lod) delete mModelLoader; mModelLoader = NULL; } - + if (filename.empty()) { if (mBaseModel.empty()) @@ -2291,10 +2200,12 @@ void LLModelPreview::loadModel(std::string filename, S32 lod) // if we don't have a base model to show for high LOD. mFMP->closeFloater(false); } - + mFMP->mLoading = false; return; } + + mLODFile[lod] = filename; if (lod == 3 && !mGroup.empty()) { @@ -2303,32 +2214,51 @@ void LLModelPreview::loadModel(std::string filename, S32 lod) glodDeleteGroup(iter->second); stop_gloderror(); } - + for (std::map<LLPointer<LLModel>, U32>::iterator iter = mObject.begin(); iter != mObject.end(); ++iter) { glodDeleteObject(iter->second); stop_gloderror(); } - + mGroup.clear(); mObject.clear(); } - + mModelLoader = new LLModelLoader(filename, lod, this); - + mModelLoader->start(); - + mFMP->childSetTextArg("status", "[STATUS]", mFMP->getString("status_reading_file")); + + setPreviewLOD(lod); - if (mFMP->childGetValue("description_form").asString().empty()) + if (lod == mPreviewLOD) { - std::string name = gDirUtilp->getBaseFileName(filename, true); - mFMP->childSetValue("description_form", name); + mFMP->childSetText("lod_file", mLODFile[mPreviewLOD]); } - + else if (lod == LLModel::LOD_PHYSICS) + { + mFMP->childSetText("physics_file", mLODFile[lod]); + } + mFMP->openFloater(); } +void LLModelPreview::setPhysicsFromLOD(S32 lod) +{ + if (lod >= 0 && lod <= 3) + { + mModel[LLModel::LOD_PHYSICS] = mModel[lod]; + mScene[LLModel::LOD_PHYSICS] = mScene[lod]; + mLODFile[LLModel::LOD_PHYSICS].clear(); + mFMP->childSetText("physics_file", mLODFile[LLModel::LOD_PHYSICS]); + mVertexBuffer[LLModel::LOD_PHYSICS].clear(); + rebuildUploadData(); + refresh(); + } +} + void LLModelPreview::clearIncompatible(S32 lod) { for (U32 i = 0; i <= LLModel::LOD_HIGH; i++) @@ -2340,7 +2270,7 @@ void LLModelPreview::clearIncompatible(S32 lod) mModel[i].clear(); mScene[i].clear(); mVertexBuffer[i].clear(); - + if (i == LLModel::LOD_HIGH) { mBaseModel = mModel[lod]; @@ -2359,7 +2289,7 @@ void LLModelPreview::loadModelCallback(S32 lod) { return; } - + mModel[lod] = mModelLoader->mModelList; mScene[lod] = mModelLoader->mScene; mVertexBuffer[lod].clear(); @@ -2368,7 +2298,7 @@ void LLModelPreview::loadModelCallback(S32 lod) { mPhysicsMesh.clear(); } - + setPreviewLOD(lod); @@ -2379,12 +2309,15 @@ void LLModelPreview::loadModelCallback(S32 lod) mVertexBuffer[5].clear(); //mModel[lod] = NULL; } - + clearIncompatible(lod); - + mDirty = true; - resetPreviewTarget(); + if (lod == LLModel::LOD_HIGH) + { + resetPreviewTarget(); + } mFMP->mLoading = FALSE; refresh(); @@ -2397,54 +2330,54 @@ void LLModelPreview::resetPreviewTarget() setPreviewTarget(mPreviewScale.magVec()*2.f); } -void LLModelPreview::smoothNormals() +void LLModelPreview::generateNormals() { S32 which_lod = mPreviewLOD; - - + + if (which_lod > 4 || which_lod < 0 || mModel[which_lod].empty()) { return; } - - F32 angle_cutoff = mFMP->childGetValue("edge threshold").asReal(); - + + 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)->smoothNormals(angle_cutoff); + (*iter)->generateNormals(angle_cutoff); } - + mVertexBuffer[5].clear(); } - + for (LLModelLoader::model_list::iterator iter = mModel[which_lod].begin(); iter != mModel[which_lod].end(); ++iter) { - (*iter)->smoothNormals(angle_cutoff); + (*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; @@ -2454,15 +2387,15 @@ void LLModelPreview::consolidate() { 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; @@ -2471,7 +2404,7 @@ void LLModelPreview::consolidate() model = NULL; } } - + if (model == NULL) { //no model found, make new model std::vector<LLImportMaterial> materials; @@ -2483,91 +2416,91 @@ 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) + 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(); - instance_iter != iter->second.end(); - ++instance_iter) + 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; @@ -2577,12 +2510,12 @@ void LLModelPreview::consolidate() 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); @@ -2591,29 +2524,29 @@ void LLModelPreview::consolidate() } } } - + mScene[mPreviewLOD] = new_scene; mModel[mPreviewLOD] = new_model; mVertexBuffer[mPreviewLOD].clear(); - + if (mPreviewLOD == LLModel::LOD_HIGH) { mBaseScene = new_scene; mBaseModel = new_model; mVertexBuffer[5].clear(); } - + mPreviewTarget = (min+max)*0.5f; mPreviewScale = (max-min)*0.5f; setPreviewTarget(mPreviewScale.magVec()*2.f); - + clearIncompatible(mPreviewLOD); - + mResourceCost = calcResourceCost(); refresh(); } -void LLModelPreview::scrubMaterials() +void LLModelPreview::clearMaterials() { for (LLModelLoader::scene::iterator iter = mScene[mPreviewLOD].begin(); iter != mScene[mPreviewLOD].end(); ++iter) { //for each transform in current scene @@ -2625,7 +2558,7 @@ void LLModelPreview::scrubMaterials() 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; @@ -2635,17 +2568,16 @@ void LLModelPreview::scrubMaterials() } } } - - + mVertexBuffer[mPreviewLOD].clear(); - + if (mPreviewLOD == LLModel::LOD_HIGH) { mBaseScene = mScene[mPreviewLOD]; mBaseModel = mModel[mPreviewLOD]; mVertexBuffer[5].clear(); } - + mResourceCost = calcResourceCost(); refresh(); } @@ -2671,26 +2603,26 @@ void LLModelPreview::genLODs(S32 which_lod) { 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; - + if (which_lod != -1) { limit = mLimit[which_lod]; } - + U32 triangle_count = 0; - + for (LLModelLoader::model_list::iterator iter = mBaseModel.begin(); iter != mBaseModel.end(); ++iter) { LLModel* mdl = *iter; @@ -2699,11 +2631,11 @@ void LLModelPreview::genLODs(S32 which_lod) 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; - + if (mGroup[mBaseModel[0]] == 0) { //clear LOD maps mGroup.clear(); @@ -2711,7 +2643,7 @@ void LLModelPreview::genLODs(S32 which_lod) mPercentage.clear(); mPatch.clear(); } - + 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; @@ -2719,32 +2651,32 @@ void LLModelPreview::genLODs(S32 which_lod) { mGroup[mdl] = cur_name++; mObject[mdl] = cur_name++; - + glodNewGroup(mGroup[mdl]); stop_gloderror(); - + glodGroupParameteri(mGroup[mdl], GLOD_ADAPT_MODE, GLOD_TRIANGLE_BUDGET); stop_gloderror(); - + glodGroupParameteri(mGroup[mdl], GLOD_ERROR_MODE, GLOD_OBJECT_SPACE_ERROR); stop_gloderror(); - + glodGroupParameterf(mGroup[mdl], GLOD_OBJECT_SPACE_ERROR_THRESHOLD, 0.025f); stop_gloderror(); - + glodNewObject(mObject[mdl], mGroup[mdl], GLOD_DISCRETE); stop_gloderror(); - + if (iter == mBaseModel.begin() && !mdl->mSkinWeights.empty()) { //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) { @@ -2757,10 +2689,10 @@ void LLModelPreview::genLODs(S32 which_lod) tri_count += num_indices/3; stop_gloderror(); } - + //store what percentage of total model (in terms of triangle count) this model makes up mPercentage[mdl] = (F32) tri_count / (F32) base_triangle_count; - + //build glodobject glodBuildObject(mObject[mdl]); if (stop_gloderror()) @@ -2769,18 +2701,18 @@ void LLModelPreview::genLODs(S32 which_lod) stop_gloderror(); glodDeleteObject(mObject[mdl]); stop_gloderror(); - + mGroup[mdl] = 0; mObject[mdl] = 0; - + if (which_lod == -1) { mModel[LLModel::LOD_HIGH] = mBaseModel; } - + return; } - + } //generating LODs for all entries, or this entry has a triangle budget @@ -2790,35 +2722,19 @@ void LLModelPreview::genLODs(S32 which_lod) glodGroupParameterf(mGroup[mdl], GLOD_OBJECT_SPACE_ERROR_THRESHOLD, 0.025f); stop_gloderror(); } - - + + S32 start = LLModel::LOD_HIGH; S32 end = 0; - + if (which_lod != -1) { start = end = which_lod; } + LLSpinCtrl* lim = mFMP->getChild<LLSpinCtrl>("lod_triangle_limit", TRUE); + lim->setMaxValue(base_triangle_count); - std::string combo_name[] = - { - "lowest detail combo", - "low detail combo", - "medium detail combo", - "high detail combo", - "physics detail combo" - }; - - std::string limit_name[] = - { - "lowest limit", - "low limit", - "medium limit", - "high limit", - "physics limit" - }; - for (S32 lod = start; lod >= end; --lod) { if (which_lod == -1) @@ -2832,59 +2748,52 @@ void LLModelPreview::genLODs(S32 which_lod) { triangle_count = limit; } - - LLComboBox* combo_box = mFMP->findChild<LLComboBox>(combo_name[lod]); - combo_box->setCurrentByIndex(2); - - LLSpinCtrl* lim = mFMP->getChild<LLSpinCtrl>(limit_name[lod], TRUE); - lim->setMaxValue(base_triangle_count); - lim->setVisible(true); - + mModel[lod].clear(); mModel[lod].resize(mBaseModel.size()); mVertexBuffer[lod].clear(); - + U32 actual_tris = 0; U32 actual_verts = 0; U32 submeshes = 0; - + for (U32 mdl_idx = 0; mdl_idx < mBaseModel.size(); ++mdl_idx) { LLModel* base = mBaseModel[mdl_idx]; - + U32 target_count = U32(mPercentage[base]*triangle_count); - + if (target_count < 4) { target_count = 4; } - + glodGroupParameteri(mGroup[base], GLOD_MAX_TRIANGLES, target_count); stop_gloderror(); - + glodAdaptGroup(mGroup[base]); stop_gloderror(); - + 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); @@ -2904,29 +2813,29 @@ void LLModelPreview::genLODs(S32 which_lod) } 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). @@ -2939,20 +2848,20 @@ void LLModelPreview::genLODs(S32 which_lod) 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]; @@ -2972,19 +2881,19 @@ void LLModelPreview::genLODs(S32 which_lod) } } } - + 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]); - } - }*/ + { //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]); + } + }*/ } void LLModelPreview::updateStatusMessages() @@ -2998,30 +2907,30 @@ void LLModelPreview::updateStatusMessages() 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); @@ -3029,61 +2938,165 @@ void LLModelPreview::updateStatusMessages() } } - - std::string upload_message; - - mFMP->childSetTextArg(info_name[LLModel::LOD_PHYSICS], "[TRIANGLES]", llformat("%d", total_tris[LLModel::LOD_PHYSICS])); - + mFMP->childSetTextArg("submeshes_info", "[SUBMESHES]", llformat("%d", total_submeshes[LLModel::LOD_HIGH])); + + std::string mesh_status_good = mFMP->getString("mesh_status_good"); + std::string mesh_status_bad = mFMP->getString("mesh_status_bad"); + std::string mesh_status_na = mFMP->getString("mesh_status_na"); + std::string mesh_status_none = mFMP->getString("mesh_status_none"); + + bool upload_ok = true; + for (S32 lod = 0; lod <= LLModel::LOD_HIGH; ++lod) { - mFMP->childSetTextArg(info_name[lod], "[TRIANGLES]", llformat("%d", total_tris[lod])); - mFMP->childSetTextArg(info_name[lod], "[VERTICES]", llformat("%d", total_verts[lod])); - mFMP->childSetTextArg(info_name[lod], "[SUBMESHES]", llformat("%d", total_submeshes[lod])); - - std::string message = "good"; + if (total_tris[lod] > 0) + { + mFMP->childSetText(lod_triangles_name[lod], llformat("%d", total_tris[lod])); + mFMP->childSetText(lod_vertices_name[lod], llformat("%d", total_verts[lod])); + } + else + { + mFMP->childSetText(lod_triangles_name[lod], mesh_status_na); + mFMP->childSetText(lod_vertices_name[lod], mesh_status_na); + } + + + std::string message = mesh_status_good; const U32 lod_high = LLModel::LOD_HIGH; - + if (lod != lod_high) { if (total_submeshes[lod] && total_submeshes[lod] != total_submeshes[lod_high]) - { - message = "mesh_mismatch"; - upload_message = "bad_lod"; + { //number of submeshes is different + message = mesh_status_bad; + upload_ok = false; } else if (!tris[lod].empty() && tris[lod].size() != tris[lod_high].size()) - { - message = "model_mismatch"; - upload_message = "bad_lod"; + { //number of meshes is different + message = mesh_status_bad; + upload_ok = false; } else if (!verts[lod].empty()) { for (U32 i = 0; i < verts[lod].size(); ++i) { - S32 max_verts = verts[lod+1][i]; - + S32 max_verts = i < verts[lod+1].size() ? verts[lod+1][i] : 0; + if (verts[lod][i] > max_verts) - { - message = "too_heavy"; - upload_message = "bad_lod"; + { //too many vertices in this lod + message = mesh_status_bad; + upload_ok = false; } } } + else + { //no mesh + message = mesh_status_none; + } } - - mFMP->childSetTextArg(info_name[lod], "[MESSAGE]", mFMP->getString(message)); + + mFMP->childSetText(lod_status_name[lod], message); } - - if (upload_message.empty()) + + if (upload_ok) { - mFMP->childSetTextArg("upload_message", "[MESSAGE]", std::string("")); mFMP->childEnable("ok_btn"); } else { - mFMP->childSetTextArg("upload_message", "[MESSAGE]", mFMP->getString(upload_message)); mFMP->childDisable("ok_btn"); } + + //add up physics triangles etc + S32 start = 0; + S32 end = mModel[LLModel::LOD_PHYSICS].size(); + + S32 idx = mFMP->childGetValue("physics_layer").asInteger(); + + if (idx >= 0 && idx < mModel[LLModel::LOD_PHYSICS].size()) + { + start = idx; + end = idx+1; + } + + S32 phys_tris = 0; + S32 phys_hulls = 0; + S32 phys_points = 0; + + for (S32 i = start; i < end; ++i) + { //add up hulls and points and triangles for selected mesh(es) + LLModel* model = mModel[LLModel::LOD_PHYSICS][i]; + S32 cur_submeshes = model->getNumVolumeFaces(); + + LLModel::convex_hull_decomposition& decomp = model->mConvexHullDecomp; + + if (!decomp.empty()) + { + phys_hulls += decomp.size(); + for (U32 i = 0; i < decomp.size(); ++i) + { + phys_points += decomp[i].size(); + } + } + else + { //choose physics shape OR decomposition, can't use both + for (S32 j = 0; j < cur_submeshes; ++j) + { //for each submesh (face), add triangles and vertices to current total + const LLVolumeFace& face = model->getVolumeFace(j); + phys_tris += face.mNumIndices/3; + } + } + } + + if (phys_tris > 0) + { + mFMP->childSetTextArg("physics_triangles", "[TRIANGLES]", llformat("%d", phys_tris)); + } + else + { + mFMP->childSetTextArg("physics_triangles", "[TRIANGLES]", mesh_status_na); + } + + if (phys_hulls > 0) + { + mFMP->childSetTextArg("physics_hulls", "[HULLS]", llformat("%d", phys_hulls)); + mFMP->childSetTextArg("physics_points", "[POINTS]", llformat("%d", phys_points)); + } + else + { + mFMP->childSetTextArg("physics_hulls", "[HULLS]", mesh_status_na); + mFMP->childSetTextArg("physics_points", "[POINTS]", mesh_status_na); + } + + //enable/disable controls based on radio groups + if (mFMP->childGetValue("lod_from_file").asBoolean()) + { + mFMP->childDisable("lod_triangle_limit"); + mFMP->childDisable("lod_generate"); + mFMP->childEnable("lod_file"); + mFMP->childEnable("lod_browse"); + } + else + { + mFMP->childEnable("lod_triangle_limit"); + mFMP->childEnable("lod_generate"); + mFMP->childDisable("lod_file"); + mFMP->childDisable("lod_browse"); + } + + if (mFMP->childGetValue("physics_load_from_file").asBoolean()) + { + mFMP->childDisable("physics_lod_combo"); + mFMP->childEnable("physics_file"); + mFMP->childEnable("physics_browse"); + } + else + { + mFMP->childEnable("physics_lod_combo"); + mFMP->childDisable("physics_file"); + mFMP->childDisable("physics_browse"); + } } void LLModelPreview::setPreviewTarget(F32 distance) @@ -3108,9 +3121,9 @@ void LLModelPreview::genBuffers(S32 lod, bool avatar_preview) U32 tri_count = 0; U32 vertex_count = 0; U32 mesh_count = 0; - + LLModelLoader::model_list* model = NULL; - + if (lod < 0 || lod > 4) { model = &mBaseModel; @@ -3120,16 +3133,16 @@ void LLModelPreview::genBuffers(S32 lod, bool avatar_preview) { 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; @@ -3137,47 +3150,47 @@ void LLModelPreview::genBuffers(S32 lod, bool avatar_preview) { 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 = avatar_preview && !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); @@ -3186,22 +3199,22 @@ void LLModelPreview::genBuffers(S32 lod, bool avatar_preview) 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); @@ -3212,19 +3225,19 @@ void LLModelPreview::genBuffers(S32 lod, bool avatar_preview) *(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; - + } } } @@ -3235,6 +3248,7 @@ void LLModelPreview::update() { mDirty = false; mResourceCost = calcResourceCost(); + refresh(); } } @@ -3245,33 +3259,42 @@ BOOL LLModelPreview::render() { LLMutexLock lock(this); mNeedsUpdate = FALSE; - + 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(); - 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_MODELVIEW); + gGL.popMatrix(); + } bool avatar_preview = 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) @@ -3284,19 +3307,19 @@ BOOL LLModelPreview::render() } } } - + if (upload_skin && !avatar_preview) { mFMP->childSetValue("upload_skin", false); upload_skin = false; } - + if (!upload_skin && upload_joints) { mFMP->childSetValue("upload_joints", false); upload_joints = false; } - + if (!avatar_preview) { mFMP->childDisable("upload_skin"); @@ -3305,7 +3328,7 @@ BOOL LLModelPreview::render() { mFMP->childEnable("upload_skin"); } - + if (!upload_skin) { mFMP->childDisable("upload_joints"); @@ -3314,156 +3337,248 @@ BOOL LLModelPreview::render() { mFMP->childEnable("upload_joints"); } - + avatar_preview = avatar_preview && upload_skin; - - + + mFMP->childSetEnabled("consolidate", !avatar_preview); - F32 explode = mFMP->mDecompFloater ? mFMP->mDecompFloater->childGetValue("explode").asReal() : 0.f; - - glMatrixMode(GL_PROJECTION); - gGL.popMatrix(); - - glMatrixMode(GL_MODELVIEW); - gGL.popMatrix(); - + F32 explode = mFMP->childGetValue("physics_explode").asReal(); + glClear(GL_DEPTH_BUFFER_BIT); + + F32 aspect = (F32) mFMP->mPreviewRect.getWidth()/mFMP->mPreviewRect.getHeight(); - LLViewerCamera::getInstance()->setAspect((F32) width / height ); + LLViewerCamera::getInstance()->setAspect(aspect); LLViewerCamera::getInstance()->setView(LLViewerCamera::getInstance()->getDefaultFOV() / mCameraZoom); - - LLVector3 target_pos = mPreviewTarget; + LLVector3 offset = mCameraOffset; - - F32 z_near = llmax(mCameraDistance-mPreviewScale.magVec(), 0.001f); - F32 z_far = mCameraDistance+mPreviewScale.magVec(); - + LLVector3 target_pos = mPreviewTarget+offset; + + F32 z_near = 0.001f; + F32 z_far = mCameraDistance+mPreviewScale.magVec()+mCameraOffset.magVec(); + if (avatar_preview) { target_pos = gAgentAvatarp->getPositionAgent(); z_near = 0.01f; z_far = 1024.f; mCameraDistance = 16.f; - + //render avatar previews every frame refresh(); } - + LLQuaternion camera_rot = LLQuaternion(mCameraPitch, LLVector3::y_axis) * - LLQuaternion(mCameraYaw, LLVector3::z_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 - + 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(); - + gPipeline.enableLightsAvatar(); - + gGL.pushMatrix(); const F32 BRIGHTNESS = 0.9f; gGL.color3f(BRIGHTNESS, BRIGHTNESS, BRIGHTNESS); LLGLEnable normalize(GL_NORMALIZE); - + if (!mBaseModel.empty() && mVertexBuffer[5].empty()) { genBuffers(-1, avatar_preview); //genBuffers(3); //genLODs(); } - - bool physics = (mPreviewLOD == LLModel::LOD_PHYSICS); - - S32 physics_idx = -1; - - bool render_mesh = true; - bool render_hull = false; - - if (physics && mFMP->mDecompFloater) - { - physics_idx = mFMP->mDecompFloater->childGetValue("model").asInteger(); - render_mesh = mFMP->mDecompFloater->childGetValue("render_mesh").asBoolean(); - render_hull = mFMP->mDecompFloater->childGetValue("render_hull").asBoolean(); - } - + + bool physics = mFMP->childGetValue("show physics").asBoolean(); + S32 physics_idx = mFMP->childGetValue("physics_layer").asInteger(); + if (!mModel[mPreviewLOD].empty()) { if (mVertexBuffer[mPreviewLOD].empty()) { genBuffers(mPreviewLOD, avatar_preview); } - + if (!avatar_preview) { - //for (LLModelLoader::scene::iterator iter = mScene[mPreviewLOD].begin(); iter != mScene[mPreviewLOD].end(); ++iter) 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); + + glColor4fv(instance.mMaterial[i].mDiffuseColor.mV); + if (i < instance.mMaterial.size() && instance.mMaterial[i].mDiffuseMap.notNull()) + { + gGL.getTexUnit(0)->bind(instance.mMaterial[i].mDiffuseMap, true); + if (instance.mMaterial[i].mDiffuseMap->getDiscardLevel() > -1) + { + mTextureSet.insert(instance.mMaterial[i].mDiffuseMap); + } + } + + 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 (mFMP->childGetValue("show edges").asBoolean()) + { + glLineWidth(3.f); + glPolygonMode(GL_FRONT_AND_BACK, GL_LINE); + buffer->drawRange(LLRender::TRIANGLES, 0, buffer->getNumVerts()-1, buffer->getNumIndices(), 0); + glPolygonMode(GL_FRONT_AND_BACK, GL_FILL); + glLineWidth(1.f); + } + } + gGL.popMatrix(); + } + + if (physics) + { + glClear(GL_DEPTH_BUFFER_BIT); + LLGLEnable blend(GL_BLEND); + gGL.blendFunc(LLRender::BF_ONE, LLRender::BF_ZERO); + + LLModel* physics_model = NULL; - //for (LLModelLoader::model_instance_list::iterator model_iter = iter->second.begin(); model_iter != iter->second.end(); ++model_iter) + if (physics_idx >= 0 && physics_idx < mModel[LLModel::LOD_PHYSICS].size() ) + { + physics_model = mModel[LLModel::LOD_PHYSICS][physics_idx]; + } + + for (LLMeshUploadThread::instance_list::iterator iter = mUploadData.begin(); iter != mUploadData.end(); ++iter) { - //LLModelInstance& instance = *model_iter; - LLModel* model = instance.mLOD[mPreviewLOD]; + LLModelInstance& instance = *iter; + + LLModel* model = instance.mLOD[LLModel::LOD_PHYSICS]; if (!model) { continue; } - //if (instance.mTransform != mat) - //{ - // llerrs << "WTF?" << llendl; - //} + gGL.pushMatrix(); + LLMatrix4 mat = instance.mTransform; - if (render_mesh) + glMultMatrixf((GLfloat*) mat.mMatrix); + + + bool render_mesh = true; + + LLPhysicsDecomp* decomp = gMeshRepo.mDecompThread; + if (decomp) { - for (U32 i = 0; i < mVertexBuffer[mPreviewLOD][model].size(); ++i) + LLMutexLock(decomp->mMutex); + + std::map<LLPointer<LLModel>, std::vector<LLPointer<LLVertexBuffer> > >::iterator iter = + mPhysicsMesh.find(model); + if (iter != mPhysicsMesh.end()) { - LLVertexBuffer* buffer = mVertexBuffer[mPreviewLOD][model][i]; - - buffer->setBuffer(LLVertexBuffer::MAP_VERTEX | LLVertexBuffer::MAP_NORMAL | LLVertexBuffer::MAP_TEXCOORD0); - if (physics) + render_mesh = false; + for (U32 i = 0; i < iter->second.size(); ++i) { - if (physics_idx > -1 && model == mModel[mPreviewLOD][physics_idx]) + if (explode > 0.f) { - glColor4f(1,0,0,1); + gGL.pushMatrix(); + + LLVector3 offset = model->mHullCenter[i]-model->mCenterOfHullCenters; + offset *= explode; + + gGL.translatef(offset.mV[0], offset.mV[1], offset.mV[2]); } - else + + static std::vector<LLColor4U> hull_colors; + + if (i+1 >= hull_colors.size()) { - glColor4f(0.75f, 0.75f, 0.75f, 1.f); + hull_colors.push_back(LLColor4U(rand()%128+127, rand()%128+127, rand()%128+127, 255)); } - } - else - { - glColor4fv(instance.mMaterial[i].mDiffuseColor.mV); - if (i < instance.mMaterial.size() && instance.mMaterial[i].mDiffuseMap.notNull()) + + LLVertexBuffer* buff = iter->second[i]; + if (buff) { - gGL.getTexUnit(0)->bind(instance.mMaterial[i].mDiffuseMap, true); - if (instance.mMaterial[i].mDiffuseMap->getDiscardLevel() > -1) + buff->setBuffer(LLVertexBuffer::MAP_VERTEX | LLVertexBuffer::MAP_NORMAL); + + glColor4ubv(hull_colors[i].mV); + buff->drawArrays(LLRender::TRIANGLES, 0, buff->getNumVerts()); + + if (mFMP->childGetValue("show edges").asBoolean()) { - mTextureSet.insert(instance.mMaterial[i].mDiffuseMap); - } + glPolygonMode(GL_FRONT_AND_BACK, GL_LINE); + glLineWidth(3.f); + glColor4ub(hull_colors[i].mV[0]/2, hull_colors[i].mV[1]/2, hull_colors[i].mV[2]/2, 255); + buff->drawArrays(LLRender::TRIANGLES, 0, buff->getNumVerts()); + glPolygonMode(GL_FRONT_AND_BACK, GL_FILL); + glLineWidth(1.f); + } + } + + if (explode > 0.f) + { + gGL.popMatrix(); } } + } + } + + if (render_mesh) + { + if (mVertexBuffer[LLModel::LOD_PHYSICS].empty()) + { + genBuffers(LLModel::LOD_PHYSICS, false); + } + for (U32 i = 0; i < mVertexBuffer[LLModel::LOD_PHYSICS][model].size(); ++i) + { + LLVertexBuffer* buffer = mVertexBuffer[LLModel::LOD_PHYSICS][model][i]; + buffer->setBuffer(LLVertexBuffer::MAP_VERTEX | LLVertexBuffer::MAP_NORMAL | LLVertexBuffer::MAP_TEXCOORD0); + + glColor4fv(instance.mMaterial[i].mDiffuseColor.mV); + if (i < instance.mMaterial.size() && instance.mMaterial[i].mDiffuseMap.notNull()) + { + gGL.getTexUnit(0)->bind(instance.mMaterial[i].mDiffuseMap, true); + if (instance.mMaterial[i].mDiffuseMap->getDiscardLevel() > -1) + { + mTextureSet.insert(instance.mMaterial[i].mDiffuseMap); + } + } + 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 (mFMP->childGetValue("show edges").asBoolean()) + if (mFMP->childGetValue("show edges").asBoolean() || model == physics_model) { + if (model == physics_model) + { + 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); @@ -3472,104 +3587,40 @@ BOOL LLModelPreview::render() } } } - - if (render_hull) - { - LLPhysicsDecomp* decomp = gMeshRepo.mDecompThread; - if (decomp) - { - LLMutexLock(decomp->mMutex); - - std::map<LLPointer<LLModel>, std::vector<LLPointer<LLVertexBuffer> > >::iterator iter = - mPhysicsMesh.find(model); - if (iter != mPhysicsMesh.end()) - { - for (U32 i = 0; i < iter->second.size(); ++i) - { - 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); - - glColor4ubv(hull_colors[i].mV); - buff->drawArrays(LLRender::TRIANGLES, 0, buff->getNumVerts()); - - if (mFMP->childGetValue("show edges").asBoolean()) - { - glPolygonMode(GL_FRONT_AND_BACK, GL_LINE); - glLineWidth(3.f); - glColor4ub(hull_colors[i].mV[0]/2, hull_colors[i].mV[1]/2, hull_colors[i].mV[2]/2, 255); - buff->drawArrays(LLRender::TRIANGLES, 0, buff->getNumVerts()); - glPolygonMode(GL_FRONT_AND_BACK, GL_FILL); - glLineWidth(1.f); - } - } - - if (explode > 0.f) - { - gGL.popMatrix(); - } - } - } - } - - //mFMP->childSetTextArg(info_name[LLModel::LOD_PHYSICS], "[HULLS]", llformat("%d",decomp->mHulls.size())); - //mFMP->childSetTextArg(info_name[LLModel::LOD_PHYSICS], "[POINTS]", llformat("%d",decomp->mTotalPoints)); - } + + gGL.popMatrix(); } - - gGL.popMatrix(); - } - - if (physics) - { - mPreviewLOD = LLModel::LOD_PHYSICS; + + gGL.setSceneBlendType(LLRender::BT_ALPHA); } } else { 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 - + target_pos + ((LLVector3(mCameraDistance, 0.f, 0.f) + offset) * av_rot), // camera + LLVector3::z_axis, // up + target_pos); // point of interest + 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); @@ -3577,7 +3628,7 @@ BOOL LLModelPreview::render() buffer->getWeight4Strider(weight); //quick 'n dirty software vertex skinning - + //build matrix palette LLMatrix4 mat[64]; for (U32 j = 0; j < model->mJointList.size(); ++j) @@ -3589,55 +3640,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; - + 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 (mFMP->childGetValue("show edges").asBoolean()) { glLineWidth(3.f); @@ -3652,9 +3703,9 @@ BOOL LLModelPreview::render() } } } - + gGL.popMatrix(); - + return TRUE; } @@ -3672,7 +3723,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); } @@ -3682,7 +3733,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); } @@ -3694,53 +3745,50 @@ void LLModelPreview::pan(F32 right, F32 up) void LLModelPreview::setPreviewLOD(S32 lod) { - mPreviewLOD = llclamp(lod, 0, 4); - refresh(); -} + lod = llclamp(lod, 0, (S32) LLModel::LOD_HIGH); -//static -void LLFloaterModelPreview::onBrowseHighLOD(void* data) -{ - LLFloaterModelPreview* mp = (LLFloaterModelPreview*) data; - mp->loadModel(3); -} + if (lod != mPreviewLOD) + { + mPreviewLOD = lod; + + LLComboBox* combo_box = mFMP->getChild<LLComboBox>("preview_lod_combo"); + combo_box->setCurrentByIndex(mPreviewLOD); + mFMP->childSetTextArg("lod_table_footer", "[DETAIL]", mFMP->getString(lod_name[mPreviewLOD])); + mFMP->childSetText("lod_file", mLODFile[mPreviewLOD]); -//static -void LLFloaterModelPreview::onBrowseMediumLOD(void* data) -{ - LLFloaterModelPreview* mp = (LLFloaterModelPreview*) data; - mp->loadModel(2); -} + LLColor4 highlight_color = LLUIColorTable::instance().getColor("MeshImportTableHighlightColor"); + LLColor4 normal_color = LLUIColorTable::instance().getColor("MeshImportTableNormalColor"); -//static -void LLFloaterModelPreview::onBrowseLowLOD(void* data) -{ - LLFloaterModelPreview* mp = (LLFloaterModelPreview*) data; - mp->loadModel(1); + for (S32 i = 0; i <= LLModel::LOD_HIGH; ++i) + { + const LLColor4& color = (i == lod) ? highlight_color : normal_color; + + mFMP->childSetColor(lod_status_name[i], color); + mFMP->childSetColor(lod_label_name[i], color); + mFMP->childSetColor(lod_triangles_name[i], color); + mFMP->childSetColor(lod_vertices_name[i], color); + } + } + refresh(); } //static -void LLFloaterModelPreview::onBrowseLowestLOD(void* data) +void LLFloaterModelPreview::onBrowseLOD(void* data) { LLFloaterModelPreview* mp = (LLFloaterModelPreview*) data; - mp->loadModel(0); + mp->loadModel(mp->mModelPreview->mPreviewLOD); } //static void LLFloaterModelPreview::onUpload(void* user_data) { LLFloaterModelPreview* mp = (LLFloaterModelPreview*) user_data; - - if (mp->mDecompFloater) - { - mp->mDecompFloater->closeFloater(); - } - + mp->mModelPreview->rebuildUploadData(); - + gMeshRepo.uploadModel(mp->mModelPreview->mUploadData, mp->mModelPreview->mPreviewScale, - mp->childGetValue("upload_textures").asBoolean(), mp->childGetValue("upload_skin"), mp->childGetValue("upload_joints")); - + mp->childGetValue("upload_textures").asBoolean(), mp->childGetValue("upload_skin"), mp->childGetValue("upload_joints")); + mp->closeFloater(false); } @@ -3752,24 +3800,16 @@ void LLFloaterModelPreview::onConsolidate(void* user_data) } //static -void LLFloaterModelPreview::onScrubMaterials(void* user_data) +void LLFloaterModelPreview::onClearMaterials(void* user_data) { LLFloaterModelPreview* mp = (LLFloaterModelPreview*) user_data; - mp->mModelPreview->scrubMaterials(); -} - -//static -void LLFloaterModelPreview::onDecompose(void* user_data) -{ - LLFloaterModelPreview* mp = (LLFloaterModelPreview*) user_data; - mp->showDecompFloater(); + mp->mModelPreview->clearMaterials(); } //static void LLFloaterModelPreview::refresh(LLUICtrl* ctrl, void* user_data) { - LLFloaterModelPreview* mp = (LLFloaterModelPreview*) user_data; - mp->mModelPreview->refresh(); + sInstance->mModelPreview->mDirty = true; } void LLFloaterModelPreview::updateResourceCost() @@ -3791,15 +3831,15 @@ LLFloaterModelPreview::DecompRequest::DecompRequest(const std::string& stage, LL mContinue = 1; mModel = mdl; 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) { @@ -3808,17 +3848,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; } } @@ -3847,4 +3887,3 @@ void LLFloaterModelPreview::DecompRequest::completed() } } - |