Newer
Older
Andrey Kleshchev
committed
3001
3002
3003
3004
3005
3006
3007
3008
3009
3010
3011
3012
3013
3014
3015
3016
3017
3018
3019
3020
3021
3022
3023
3024
3025
3026
3027
3028
3029
3030
3031
3032
3033
3034
3035
3036
3037
3038
3039
3040
3041
3042
3043
3044
3045
3046
3047
3048
3049
3050
3051
3052
3053
3054
3055
3056
3057
3058
3059
3060
3061
3062
3063
3064
return 0;
}
void LLModelPreview::addEmptyFace(LLModel* pTarget)
{
U32 type_mask = LLVertexBuffer::MAP_VERTEX | LLVertexBuffer::MAP_NORMAL | LLVertexBuffer::MAP_TEXCOORD0;
LLPointer<LLVertexBuffer> buff = new LLVertexBuffer(type_mask, 0);
buff->allocateBuffer(1, 3, true);
memset((U8*)buff->getMappedData(), 0, buff->getSize());
memset((U8*)buff->getIndicesPointer(), 0, buff->getIndicesSize());
buff->validateRange(0, buff->getNumVerts() - 1, buff->getNumIndices(), 0);
LLStrider<LLVector3> pos;
LLStrider<LLVector3> norm;
LLStrider<LLVector2> tc;
LLStrider<U16> index;
buff->getVertexStrider(pos);
if (type_mask & LLVertexBuffer::MAP_NORMAL)
{
buff->getNormalStrider(norm);
}
if (type_mask & LLVertexBuffer::MAP_TEXCOORD0)
{
buff->getTexCoord0Strider(tc);
}
buff->getIndexStrider(index);
//resize face array
int faceCnt = pTarget->getNumVolumeFaces();
pTarget->setNumVolumeFaces(faceCnt + 1);
pTarget->setVolumeFaceData(faceCnt + 1, pos, norm, tc, index, buff->getNumVerts(), buff->getNumIndices());
}
//-----------------------------------------------------------------------------
// render()
//-----------------------------------------------------------------------------
// Todo: we shouldn't be setting all those UI elements on render.
// Note: Render happens each frame with skinned avatars
BOOL LLModelPreview::render()
{
assert_main_thread();
LLMutexLock lock(this);
mNeedsUpdate = FALSE;
bool edges = mViewOption["show_edges"];
bool joint_overrides = mViewOption["show_joint_overrides"];
bool joint_positions = mViewOption["show_joint_positions"];
bool skin_weight = mViewOption["show_skin_weight"];
bool textures = mViewOption["show_textures"];
bool physics = mViewOption["show_physics"];
S32 width = getWidth();
S32 height = getHeight();
LLGLSUIDefault def; // GL_BLEND, GL_ALPHA_TEST, GL_CULL_FACE, depth test
LLGLDisable no_blend(GL_BLEND);
LLGLEnable cull(GL_CULL_FACE);
Andrey Kleshchev
committed
LLGLDepthTest depth(GL_FALSE); // SL-12781 disable z-buffer to render background color
LLGLDisable fog(GL_FOG);
{
gUIProgram.bind();
Andrey Kleshchev
committed
//clear background to grey
gGL.matrixMode(LLRender::MM_PROJECTION);
gGL.pushMatrix();
gGL.loadIdentity();
gGL.ortho(0.0f, width, 0.0f, height, -1.0f, 1.0f);
gGL.matrixMode(LLRender::MM_MODELVIEW);
gGL.pushMatrix();
gGL.loadIdentity();
gGL.color4fv(PREVIEW_CANVAS_COL.mV);
Andrey Kleshchev
committed
gl_rect_2d_simple(width, height);
gGL.matrixMode(LLRender::MM_PROJECTION);
gGL.popMatrix();
gGL.matrixMode(LLRender::MM_MODELVIEW);
gGL.popMatrix();
gUIProgram.unbind();
Andrey Kleshchev
committed
}
LLFloaterModelPreview* fmp = LLFloaterModelPreview::sInstance;
bool has_skin_weights = false;
bool upload_skin = mFMP->childGetValue("upload_skin").asBoolean();
bool upload_joints = mFMP->childGetValue("upload_joints").asBoolean();
if (upload_joints != mLastJointUpdate)
{
mLastJointUpdate = upload_joints;
if (fmp)
{
fmp->clearAvatarTab();
}
Andrey Kleshchev
committed
3106
3107
3108
3109
3110
3111
3112
3113
3114
3115
3116
3117
3118
3119
3120
3121
3122
3123
3124
3125
3126
3127
3128
}
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;
model->mPelvisOffset = mPelvisZOffset;
if (!model->mSkinWeights.empty())
{
has_skin_weights = true;
}
}
}
if (has_skin_weights && lodsReady())
{ //model has skin weights, enable view options for skin weights and joint positions
U32 flags = getLegacyRigFlags();
if (fmp)
{
if (flags == LEGACY_RIG_OK)
{
if (mFirstSkinUpdate)
{
// auto enable weight upload if weights are present
// (note: all these UI updates need to be somewhere that is not render)
fmp->childSetValue("upload_skin", true);
mFirstSkinUpdate = false;
Mnikolenko Productengine
committed
upload_skin = true;
skin_weight = true;
mViewOption["show_skin_weight"] = true;
Andrey Kleshchev
committed
fmp->enableViewOption("show_skin_weight");
fmp->setViewOptionEnabled("show_joint_overrides", skin_weight);
fmp->setViewOptionEnabled("show_joint_positions", skin_weight);
mFMP->childEnable("upload_skin");
mFMP->childSetValue("show_skin_weight", skin_weight);
Andrey Kleshchev
committed
3146
3147
3148
3149
3150
3151
3152
3153
3154
3155
3156
3157
3158
3159
3160
3161
3162
3163
3164
3165
3166
3167
3168
3169
3170
3171
3172
3173
3174
3175
3176
3177
3178
3179
3180
3181
3182
3183
3184
}
else if ((flags & LEGACY_RIG_FLAG_TOO_MANY_JOINTS) > 0)
{
mFMP->childSetVisible("skin_too_many_joints", true);
}
else if ((flags & LEGACY_RIG_FLAG_UNKNOWN_JOINT) > 0)
{
mFMP->childSetVisible("skin_unknown_joint", true);
}
}
}
else
{
mFMP->childDisable("upload_skin");
if (fmp)
{
mViewOption["show_skin_weight"] = false;
fmp->disableViewOption("show_skin_weight");
fmp->disableViewOption("show_joint_overrides");
fmp->disableViewOption("show_joint_positions");
skin_weight = false;
mFMP->childSetValue("show_skin_weight", false);
fmp->setViewOptionEnabled("show_skin_weight", skin_weight);
}
}
if (upload_skin && !has_skin_weights)
{ //can't upload skin weights if model has no skin weights
mFMP->childSetValue("upload_skin", false);
upload_skin = false;
}
if (!upload_skin && upload_joints)
{ //can't upload joints if not uploading skin weights
mFMP->childSetValue("upload_joints", false);
upload_joints = false;
}
Andrey Kleshchev
committed
{
if (upload_skin)
Andrey Kleshchev
committed
{
// will populate list of joints
fmp->updateAvatarTab(upload_joints);
Andrey Kleshchev
committed
}
else
{
fmp->clearAvatarTab();
}
}
if (upload_skin && upload_joints)
{
mFMP->childEnable("lock_scale_if_joint_position");
Andrey Kleshchev
committed
3201
3202
3203
3204
3205
3206
3207
3208
3209
3210
3211
3212
3213
3214
3215
3216
3217
3218
3219
3220
3221
3222
3223
3224
3225
3226
3227
3228
3229
3230
3231
3232
3233
3234
3235
3236
3237
3238
3239
3240
3241
3242
3243
}
else
{
mFMP->childDisable("lock_scale_if_joint_position");
mFMP->childSetValue("lock_scale_if_joint_position", false);
}
//Only enable joint offsets if it passed the earlier critiquing
if (isRigValidForJointPositionUpload())
{
mFMP->childSetEnabled("upload_joints", upload_skin);
}
F32 explode = mFMP->childGetValue("physics_explode").asReal();
LLGLDepthTest gls_depth(GL_TRUE); // SL-12781 re-enable z-buffer for 3D model preview
LLRect preview_rect;
preview_rect = mFMP->getChildView("preview_panel")->getRect();
F32 aspect = (F32)preview_rect.getWidth() / preview_rect.getHeight();
LLViewerCamera::getInstance()->setAspect(aspect);
LLViewerCamera::getInstance()->setView(LLViewerCamera::getInstance()->getDefaultFOV() / mCameraZoom);
LLVector3 offset = mCameraOffset;
LLVector3 target_pos = mPreviewTarget + offset;
F32 z_near = 0.001f;
F32 z_far = mCameraDistance*10.0f + mPreviewScale.magVec() + mCameraOffset.magVec();
if (skin_weight)
{
target_pos = getPreviewAvatar()->getPositionAgent() + offset;
z_near = 0.01f;
z_far = 1024.f;
//render avatar previews every frame
refresh();
}
gObjectPreviewProgram.bind();
Andrey Kleshchev
committed
3245
3246
3247
3248
3249
3250
3251
3252
3253
3254
3255
3256
3257
3258
3259
3260
3261
3262
3263
3264
3265
3266
gGL.loadIdentity();
gPipeline.enableLightsPreview();
LLQuaternion camera_rot = LLQuaternion(mCameraPitch, LLVector3::y_axis) *
LLQuaternion(mCameraYaw, LLVector3::z_axis);
LLQuaternion av_rot = camera_rot;
F32 camera_distance = skin_weight ? SKIN_WEIGHT_CAMERA_DISTANCE : mCameraDistance;
LLViewerCamera::getInstance()->setOriginAndLookAt(
target_pos + ((LLVector3(camera_distance, 0.f, 0.f) + offset) * av_rot), // camera
LLVector3::z_axis, // up
target_pos); // point of interest
z_near = llclamp(z_far * 0.001f, 0.001f, 0.1f);
LLViewerCamera::getInstance()->setPerspective(FALSE, mOrigin.mX, mOrigin.mY, width, height, FALSE, z_near, z_far);
stop_glerror();
gGL.pushMatrix();
gGL.color4fv(PREVIEW_EDGE_COL.mV);
Andrey Kleshchev
committed
3268
3269
3270
3271
3272
3273
3274
3275
3276
3277
3278
3279
3280
3281
3282
3283
3284
3285
3286
3287
3288
3289
3290
3291
3292
3293
3294
3295
3296
3297
3298
3299
3300
3301
3302
3303
const U32 type_mask = LLVertexBuffer::MAP_VERTEX | LLVertexBuffer::MAP_NORMAL | LLVertexBuffer::MAP_TEXCOORD0;
LLGLEnable normalize(GL_NORMALIZE);
if (!mBaseModel.empty() && mVertexBuffer[5].empty())
{
genBuffers(-1, skin_weight);
//genBuffers(3);
}
if (!mModel[mPreviewLOD].empty())
{
mFMP->childEnable("reset_btn");
bool regen = mVertexBuffer[mPreviewLOD].empty();
if (!regen)
{
const std::vector<LLPointer<LLVertexBuffer> >& vb_vec = mVertexBuffer[mPreviewLOD].begin()->second;
if (!vb_vec.empty())
{
const LLVertexBuffer* buff = vb_vec[0];
regen = buff->hasDataType(LLVertexBuffer::TYPE_WEIGHT4) != skin_weight;
}
else
{
LL_INFOS() << "Vertex Buffer[" << mPreviewLOD << "]" << " is EMPTY!!!" << LL_ENDL;
regen = TRUE;
}
}
if (regen)
{
genBuffers(mPreviewLOD, skin_weight);
}
if (physics && mVertexBuffer[LLModel::LOD_PHYSICS].empty())
{
genBuffers(LLModel::LOD_PHYSICS, false);
}
Andrey Kleshchev
committed
3309
3310
3311
3312
3313
3314
3315
3316
3317
3318
3319
3320
3321
3322
3323
3324
3325
3326
3327
3328
3329
3330
3331
3332
3333
3334
3335
3336
3337
3338
3339
3340
3341
3342
3343
3344
3345
3346
3347
3348
3349
3350
3351
3352
3353
3354
3355
if (!skin_weight)
{
for (LLMeshUploadThread::instance_list::iterator iter = mUploadData.begin(); iter != mUploadData.end(); ++iter)
{
LLModelInstance& instance = *iter;
LLModel* model = instance.mLOD[mPreviewLOD];
if (!model)
{
continue;
}
gGL.pushMatrix();
LLMatrix4 mat = instance.mTransform;
gGL.multMatrix((GLfloat*)mat.mMatrix);
U32 num_models = mVertexBuffer[mPreviewLOD][model].size();
for (U32 i = 0; i < num_models; ++i)
{
LLVertexBuffer* buffer = mVertexBuffer[mPreviewLOD][model][i];
buffer->setBuffer(type_mask & buffer->getTypeMask());
if (textures)
{
int materialCnt = instance.mModel->mMaterialList.size();
if (i < materialCnt)
{
const std::string& binding = instance.mModel->mMaterialList[i];
const LLImportMaterial& material = instance.mMaterial[binding];
gGL.diffuseColor4fv(material.mDiffuseColor.mV);
// Find the tex for this material, bind it, and add it to our set
//
LLViewerFetchedTexture* tex = bindMaterialDiffuseTexture(material);
if (tex)
{
mTextureSet.insert(tex);
}
}
}
else
{
gGL.diffuseColor4fv(PREVIEW_BASE_COL.mV);
Andrey Kleshchev
committed
}
buffer->drawRange(LLRender::TRIANGLES, 0, buffer->getNumVerts() - 1, buffer->getNumIndices(), 0);
gGL.getTexUnit(0)->unbind(LLTexUnit::TT_TEXTURE);
gGL.diffuseColor4fv(PREVIEW_EDGE_COL.mV);
Andrey Kleshchev
committed
if (edges)
{
glLineWidth(PREVIEW_EDGE_WIDTH);
Andrey Kleshchev
committed
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);
}
buffer->flush();
Andrey Kleshchev
committed
3371
3372
3373
3374
3375
3376
3377
3378
3379
3380
3381
3382
3383
3384
3385
3386
3387
3388
3389
3390
3391
3392
3393
3394
3395
3396
3397
3398
3399
3400
3401
3402
3403
3404
3405
3406
3407
3408
3409
3410
3411
3412
3413
3414
3415
3416
3417
3418
3419
3420
3421
3422
3423
3424
3425
3426
3427
3428
3429
3430
}
gGL.popMatrix();
}
if (physics)
{
glClear(GL_DEPTH_BUFFER_BIT);
for (U32 pass = 0; pass < 2; pass++)
{
if (pass == 0)
{ //depth only pass
gGL.setColorMask(false, false);
}
else
{
gGL.setColorMask(true, true);
}
//enable alpha blending on second pass but not first pass
LLGLState blend(GL_BLEND, pass);
gGL.blendFunc(LLRender::BF_SOURCE_ALPHA, LLRender::BF_ONE_MINUS_SOURCE_ALPHA);
for (LLMeshUploadThread::instance_list::iterator iter = mUploadData.begin(); iter != mUploadData.end(); ++iter)
{
LLModelInstance& instance = *iter;
LLModel* model = instance.mLOD[LLModel::LOD_PHYSICS];
if (!model)
{
continue;
}
gGL.pushMatrix();
LLMatrix4 mat = instance.mTransform;
gGL.multMatrix((GLfloat*)mat.mMatrix);
bool render_mesh = true;
LLPhysicsDecomp* decomp = gMeshRepo.mDecompThread;
if (decomp)
{
LLMutexLock(decomp->mMutex);
LLModel::Decomposition& physics = model->mPhysics;
if (!physics.mHull.empty())
{
render_mesh = false;
if (physics.mMesh.empty())
{ //build vertex buffer for physics mesh
gMeshRepo.buildPhysicsMesh(physics);
}
if (!physics.mMesh.empty())
{ //render hull instead of mesh
// SL-16993 physics.mMesh[i].mNormals were being used to light the exploded
// analyzed physics shape but the drawArrays() interface changed
// causing normal data <0,0,0> to be passed to the shader.
// The Phyics Preview shader uses plain vertex coloring so the physics hull is full lit.
// We could also use interface/ui shaders.
gObjectPreviewProgram.unbind();
gPhysicsPreviewProgram.bind();
Andrey Kleshchev
committed
for (U32 i = 0; i < physics.mMesh.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, 128));
}
gGL.diffuseColor4ubv(hull_colors[i].mV);
David Parks
committed
LLVertexBuffer::drawArrays(LLRender::TRIANGLES, physics.mMesh[i].mPositions);
Andrey Kleshchev
committed
if (explode > 0.f)
{
gGL.popMatrix();
}
}
gPhysicsPreviewProgram.unbind();
gObjectPreviewProgram.bind();
Andrey Kleshchev
committed
}
}
}
if (render_mesh)
{
U32 num_models = mVertexBuffer[LLModel::LOD_PHYSICS][model].size();
if (pass > 0){
for (U32 i = 0; i < num_models; ++i)
{
LLVertexBuffer* buffer = mVertexBuffer[LLModel::LOD_PHYSICS][model][i];
gGL.getTexUnit(0)->unbind(LLTexUnit::TT_TEXTURE);
gGL.diffuseColor4fv(PREVIEW_PSYH_FILL_COL.mV);
Andrey Kleshchev
committed
buffer->setBuffer(type_mask & buffer->getTypeMask());
buffer->drawRange(LLRender::TRIANGLES, 0, buffer->getNumVerts() - 1, buffer->getNumIndices(), 0);
gGL.diffuseColor4fv(PREVIEW_PSYH_EDGE_COL.mV);
glLineWidth(PREVIEW_PSYH_EDGE_WIDTH);
Andrey Kleshchev
committed
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);
buffer->flush();
Andrey Kleshchev
committed
}
}
}
gGL.popMatrix();
}
// only do this if mDegenerate was set in the preceding mesh checks [Check this if the ordering ever breaks]
if (mHasDegenerate)
Andrey Kleshchev
committed
{
glLineWidth(PREVIEW_DEG_EDGE_WIDTH);
glPointSize(PREVIEW_DEG_POINT_SIZE);
Andrey Kleshchev
committed
3507
3508
3509
3510
3511
3512
3513
3514
3515
3516
3517
3518
3519
3520
3521
3522
3523
3524
3525
3526
3527
3528
3529
3530
3531
3532
3533
3534
3535
3536
3537
3538
3539
3540
3541
3542
3543
3544
3545
3546
3547
3548
3549
3550
3551
3552
3553
gPipeline.enableLightsFullbright();
//show degenerate triangles
LLGLDepthTest depth(GL_TRUE, GL_TRUE, GL_ALWAYS);
LLGLDisable cull(GL_CULL_FACE);
gGL.diffuseColor4f(1.f, 0.f, 0.f, 1.f);
const LLVector4a scale(0.5f);
for (LLMeshUploadThread::instance_list::iterator iter = mUploadData.begin(); iter != mUploadData.end(); ++iter)
{
LLModelInstance& instance = *iter;
LLModel* model = instance.mLOD[LLModel::LOD_PHYSICS];
if (!model)
{
continue;
}
gGL.pushMatrix();
LLMatrix4 mat = instance.mTransform;
gGL.multMatrix((GLfloat*)mat.mMatrix);
LLPhysicsDecomp* decomp = gMeshRepo.mDecompThread;
if (decomp)
{
LLMutexLock(decomp->mMutex);
LLModel::Decomposition& physics = model->mPhysics;
if (physics.mHull.empty())
{
U32 num_models = mVertexBuffer[LLModel::LOD_PHYSICS][model].size();
for (U32 v = 0; v < num_models; ++v)
{
LLVertexBuffer* buffer = mVertexBuffer[LLModel::LOD_PHYSICS][model][v];
buffer->setBuffer(type_mask & buffer->getTypeMask());
LLStrider<LLVector3> pos_strider;
buffer->getVertexStrider(pos_strider, 0);
LLVector4a* pos = (LLVector4a*)pos_strider.get();
LLStrider<U16> idx;
buffer->getIndexStrider(idx, 0);
for (U32 i = 0; i < buffer->getNumIndices(); i += 3)
Andrey Kleshchev
committed
{
LLVector4a v1; v1.setMul(pos[*idx++], scale);
LLVector4a v2; v2.setMul(pos[*idx++], scale);
LLVector4a v3; v3.setMul(pos[*idx++], scale);
Andrey Kleshchev
committed
if (ll_is_degenerate(v1, v2, v3))
{
buffer->draw(LLRender::LINE_LOOP, 3, i);
buffer->draw(LLRender::POINTS, 3, i);
Andrey Kleshchev
committed
}
}
buffer->flush();
Andrey Kleshchev
committed
3568
3569
3570
3571
3572
3573
3574
3575
3576
3577
3578
3579
3580
3581
3582
3583
3584
3585
3586
3587
3588
3589
3590
3591
3592
3593
3594
3595
3596
3597
3598
3599
3600
3601
3602
3603
3604
3605
3606
}
}
}
gGL.popMatrix();
}
glLineWidth(1.f);
glPointSize(1.f);
gPipeline.enableLightsPreview();
gGL.setSceneBlendType(LLRender::BT_ALPHA);
}
}
}
}
else
{
target_pos = getPreviewAvatar()->getPositionAgent();
getPreviewAvatar()->clearAttachmentOverrides(); // removes pelvis fixup
LLUUID fake_mesh_id;
fake_mesh_id.generate();
getPreviewAvatar()->addPelvisFixup(mPelvisZOffset, fake_mesh_id);
bool pelvis_recalc = false;
LLViewerCamera::getInstance()->setOriginAndLookAt(
target_pos + ((LLVector3(camera_distance, 0.f, 0.f) + offset) * av_rot), // camera
LLVector3::z_axis, // up
target_pos); // point of interest
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())
{
const LLMeshSkinInfo *skin = &model->mSkinInfo;
LLSkinningUtil::initJointNums(&model->mSkinInfo, getPreviewAvatar());// inits skin->mJointNums if nessesary
U32 joint_count = LLSkinningUtil::getMeshJointCount(skin);
U32 bind_count = skin->mAlternateBindMatrix.size();
Andrey Kleshchev
committed
if (joint_overrides
&& bind_count > 0
&& joint_count == bind_count)
Andrey Kleshchev
committed
{
// mesh_id is used to determine which mesh gets to
// set the joint offset, in the event of a conflict. Since
// we don't know the mesh id yet, we can't guarantee that
// joint offsets will be applied with the same priority as
// in the uploaded model. If the file contains multiple
// meshes with conflicting joint offsets, preview may be
// incorrect.
LLUUID fake_mesh_id;
fake_mesh_id.generate();
for (U32 j = 0; j < joint_count; ++j)
Andrey Kleshchev
committed
{
LLJoint *joint = getPreviewAvatar()->getJoint(skin->mJointNums[j]);
if (joint)
{
const LLVector3& jointPos = LLVector3(skin->mAlternateBindMatrix[j].getTranslation());
Andrey Kleshchev
committed
3629
3630
3631
3632
3633
3634
3635
3636
3637
3638
3639
3640
3641
3642
3643
3644
3645
3646
3647
3648
3649
3650
3651
3652
3653
3654
3655
3656
3657
3658
3659
3660
3661
3662
3663
3664
3665
3666
3667
3668
3669
if (joint->aboveJointPosThreshold(jointPos))
{
bool override_changed;
joint->addAttachmentPosOverride(jointPos, fake_mesh_id, "model", override_changed);
if (override_changed)
{
//If joint is a pelvis then handle old/new pelvis to foot values
if (joint->getName() == "mPelvis")// or skin->mJointNames[j]
{
pelvis_recalc = true;
}
}
if (skin->mLockScaleIfJointPosition)
{
// Note that unlike positions, there's no threshold check here,
// just a lock at the default value.
joint->addAttachmentScaleOverride(joint->getDefaultScale(), fake_mesh_id, "model");
}
}
}
}
}
for (U32 i = 0, e = mVertexBuffer[mPreviewLOD][model].size(); i < e; ++i)
{
LLVertexBuffer* buffer = mVertexBuffer[mPreviewLOD][model][i];
const LLVolumeFace& face = model->getVolumeFace(i);
LLStrider<LLVector3> position;
buffer->getVertexStrider(position);
LLStrider<LLVector4> weight;
buffer->getWeight4Strider(weight);
//quick 'n dirty software vertex skinning
//build matrix palette
LLMatrix4a mat[LL_MAX_JOINTS_PER_MESH_OBJECT];
LLSkinningUtil::initSkinningMatrixPalette(mat, joint_count,
Andrey Kleshchev
committed
skin, getPreviewAvatar());
const LLMatrix4a& bind_shape_matrix = skin->mBindShapeMatrix;
Andrey Kleshchev
committed
3674
3675
3676
3677
3678
3679
3680
3681
3682
3683
3684
3685
3686
3687
3688
3689
3690
3691
3692
3693
3694
3695
3696
3697
3698
3699
3700
3701
3702
3703
3704
3705
3706
3707
3708
3709
3710
3711
3712
3713
U32 max_joints = LLSkinningUtil::getMaxJointCount();
for (U32 j = 0; j < buffer->getNumVerts(); ++j)
{
LLMatrix4a final_mat;
F32 *wptr = weight[j].mV;
LLSkinningUtil::getPerVertexSkinMatrix(wptr, mat, true, final_mat, max_joints);
//VECTORIZE THIS
LLVector4a& v = face.mPositions[j];
LLVector4a t;
LLVector4a dst;
bind_shape_matrix.affineTransform(v, t);
final_mat.affineTransform(t, dst);
position[j][0] = dst[0];
position[j][1] = dst[1];
position[j][2] = dst[2];
}
llassert(model->mMaterialList.size() > i);
const std::string& binding = instance.mModel->mMaterialList[i];
const LLImportMaterial& material = instance.mMaterial[binding];
buffer->setBuffer(type_mask & buffer->getTypeMask());
gGL.diffuseColor4fv(material.mDiffuseColor.mV);
gGL.getTexUnit(0)->unbind(LLTexUnit::TT_TEXTURE);
// Find the tex for this material, bind it, and add it to our set
//
LLViewerFetchedTexture* tex = bindMaterialDiffuseTexture(material);
if (tex)
{
mTextureSet.insert(tex);
}
buffer->draw(LLRender::TRIANGLES, buffer->getNumIndices(), 0);
if (edges)
{
gGL.diffuseColor4fv(PREVIEW_EDGE_COL.mV);
glLineWidth(PREVIEW_EDGE_WIDTH);
Andrey Kleshchev
committed
glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
buffer->draw(LLRender::TRIANGLES, buffer->getNumIndices(), 0);
glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
glLineWidth(1.f);
}
}
}
}
}
if (joint_positions)
{
LLGLSLShader* shader = LLGLSLShader::sCurBoundShaderPtr;
if (shader)
{
gDebugProgram.bind();
}
getPreviewAvatar()->renderCollisionVolumes();
Andrey Kleshchev
committed
if (fmp->mTabContainer->getCurrentPanelIndex() == fmp->mAvatarTabIndex)
{
getPreviewAvatar()->renderBones(fmp->mSelectedJointName);
}
else
{
getPreviewAvatar()->renderBones();
}
renderGroundPlane(mPelvisZOffset);
Andrey Kleshchev
committed
if (shader)
{
shader->bind();
}
}
if (pelvis_recalc)
{
// size/scale recalculation
getPreviewAvatar()->postPelvisSetRecalc();
}
}
}
gObjectPreviewProgram.unbind();
Andrey Kleshchev
committed
gGL.popMatrix();
return TRUE;
}
void LLModelPreview::renderGroundPlane(float z_offset)
{ // Not necesarilly general - beware - but it seems to meet the needs of LLModelPreview::render
gGL.diffuseColor3f( 1.0f, 0.0f, 1.0f );
gGL.begin(LLRender::LINES);
gGL.vertex3fv(mGroundPlane[0].mV);
gGL.vertex3fv(mGroundPlane[1].mV);
gGL.vertex3fv(mGroundPlane[1].mV);
gGL.vertex3fv(mGroundPlane[2].mV);
gGL.vertex3fv(mGroundPlane[2].mV);
gGL.vertex3fv(mGroundPlane[3].mV);
gGL.vertex3fv(mGroundPlane[3].mV);
gGL.vertex3fv(mGroundPlane[0].mV);
gGL.end();
}
Andrey Kleshchev
committed
3786
3787
3788
3789
3790
3791
3792
3793
3794
3795
3796
3797
3798
3799
3800
3801
3802
3803
3804
3805
3806
3807
3808
3809
3810
//-----------------------------------------------------------------------------
// refresh()
//-----------------------------------------------------------------------------
void LLModelPreview::refresh()
{
mNeedsUpdate = TRUE;
}
//-----------------------------------------------------------------------------
// rotate()
//-----------------------------------------------------------------------------
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);
}
//-----------------------------------------------------------------------------
// zoom()
//-----------------------------------------------------------------------------
void LLModelPreview::zoom(F32 zoom_amt)
{
F32 new_zoom = mCameraZoom + zoom_amt;
// TODO: stop clamping in render
mCameraZoom = llclamp(new_zoom, 1.f, PREVIEW_ZOOM_LIMIT);
Andrey Kleshchev
committed
3812
3813
3814
3815
3816
3817
3818
3819
3820
3821
3822
3823
3824
3825
3826
3827
3828
3829
3830
3831
3832
3833
3834
3835
3836
3837
3838
3839
3840
3841
3842
3843
3844
3845
3846
3847
3848
3849
3850
3851
3852
3853
3854
3855
3856
3857
3858
3859
3860
3861
3862
3863
3864
3865
3866
3867
3868
3869
3870
3871
3872
3873
3874
3875
3876
3877
3878
3879
3880
3881
3882
3883
3884
3885
3886
3887
3888
3889
3890
3891
3892
}
void LLModelPreview::pan(F32 right, F32 up)
{
bool skin_weight = mViewOption["show_skin_weight"];
F32 camera_distance = skin_weight ? SKIN_WEIGHT_CAMERA_DISTANCE : mCameraDistance;
mCameraOffset.mV[VY] = llclamp(mCameraOffset.mV[VY] + right * camera_distance / mCameraZoom, -1.f, 1.f);
mCameraOffset.mV[VZ] = llclamp(mCameraOffset.mV[VZ] + up * camera_distance / mCameraZoom, -1.f, 1.f);
}
void LLModelPreview::setPreviewLOD(S32 lod)
{
lod = llclamp(lod, 0, (S32)LLModel::LOD_HIGH);
if (lod != mPreviewLOD)
{
mPreviewLOD = lod;
LLComboBox* combo_box = mFMP->getChild<LLComboBox>("preview_lod_combo");
combo_box->setCurrentByIndex((NUM_LOD - 1) - mPreviewLOD); // combo box list of lods is in reverse order
mFMP->childSetValue("lod_file_" + lod_name[mPreviewLOD], mLODFile[mPreviewLOD]);
LLColor4 highlight_color = LLUIColorTable::instance().getColor("MeshImportTableHighlightColor");
LLColor4 normal_color = LLUIColorTable::instance().getColor("MeshImportTableNormalColor");
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);
}
LLFloaterModelPreview* fmp = (LLFloaterModelPreview*)mFMP;
if (fmp)
{
// make preview repopulate tab
fmp->clearAvatarTab();
}
}
refresh();
updateStatusMessages();
}
//static
void LLModelPreview::textureLoadedCallback(
BOOL success,
LLViewerFetchedTexture *src_vi,
LLImageRaw* src,
LLImageRaw* src_aux,
S32 discard_level,
BOOL final,
void* userdata)
{
LLModelPreview* preview = (LLModelPreview*)userdata;
preview->refresh();
if (final && preview->mModelLoader)
{
if (preview->mModelLoader->mNumOfFetchingTextures > 0)
{
preview->mModelLoader->mNumOfFetchingTextures--;
}
}
}
// static
bool LLModelPreview::lodQueryCallback()
{
// not the best solution, but model preview belongs to floater
// so it is an easy way to check that preview still exists.
LLFloaterModelPreview* fmp = LLFloaterModelPreview::sInstance;
if (fmp && fmp->mModelPreview)
{
LLModelPreview* preview = fmp->mModelPreview;
if (preview->mLodsQuery.size() > 0)
{
S32 lod = preview->mLodsQuery.back();
preview->mLodsQuery.pop_back();
preview->genMeshOptimizerLODs(lod, MESH_OPTIMIZER_AUTO);
Andrey Kleshchev
committed
if (preview->mLookUpLodFiles && (lod == LLModel::LOD_HIGH))
{
preview->lookupLODModelFiles(LLModel::LOD_HIGH);
}
Andrey Kleshchev
committed
// return false to continue cycle
return preview->mLodsQuery.empty();
Andrey Kleshchev
committed
}
}
// nothing to process
return true;
}
Andrey Kleshchev
committed
void LLModelPreview::onLODMeshOptimizerParamCommit(S32 requested_lod, bool enforce_tri_limit, S32 mode)
Andrey Kleshchev
committed
{
if (!mLODFrozen)
{
Andrey Kleshchev
committed
genMeshOptimizerLODs(requested_lod, mode, 3, enforce_tri_limit);
Andrey Kleshchev
committed
refresh();
Mnikolenko Productengine
committed
mDirty = true;