Skip to content

Commit

Permalink
glwidgets: Make the 'Compare with mesh' object static, even while liv…
Browse files Browse the repository at this point in the history
…e-transformed during the roto-translate tool operation; we want to keep it unaffected, only moving the collision itself and having this static for reference. Suggested by @Dalion on Discord.

By the time renderBrfItem() was called, it was already too late, as the glMultMatrixf() call had already happened, and it we did a glPopMatrix() inside it we would need to push an identical one afterwards with the same (i==lastSelected) || applyExtraMatrixToAll logic anyway, and we didn't have access to the selected index to see if were the last one. So, instead of duplicating and countering the logic, move the comparison mesh drawing one level up, the function uses a C++ template anyway, so there are multiple copies for each BRF asset type, and this one would only work for BrfBody ones (collisions). Make it simpler.

Dalion
 —
Yesterday at 10:27 PM
@Swyter just found two potential further improvements to openbrf:
1) on collision tab, when you have compare with mesh checkbox ticked and try to rescale it, the mesh is rescaled too, which makes it difficult to adjust the size. When you confirm the changes the mesh size resets anyway so I'm not sure why it would be affected at all, looks like a bug
2) it would be great to introduce a position shift copying from one mesh to another. Like here I have to select both balls and move the centered one with apply to last selected object only to put it on the same spot. Would be faster to select shifted one - edit - copy, select centered one - edit - paste position
  • Loading branch information
Swyter committed May 1, 2024
1 parent be41797 commit 300aa55
Showing 1 changed file with 30 additions and 20 deletions.
50 changes: 30 additions & 20 deletions glwidgets.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -774,26 +774,6 @@ void GLWidget::enableMaterial(const BrfMaterial &m){
}

void GLWidget::renderBrfItem(const BrfBody& b){
if (useComparisonMesh) {
std::vector<BrfMesh> &v(data->mesh);
for (unsigned int i=0; i<v.size(); i++) {
BrfMesh &m( v[i] );
if ( m.IsNamedAsBody(b.name) && (m.IsNamedAsLOD()==0)) renderMesh(m,0);
}

int si = data->Find(b.name,SKELETON);

if (si>=0) {
if (selRefSkin>=0) {
for (unsigned int i=0; i<reference->mesh.size(); i++)
if (reference->mesh[i].name[4]==char('A'+selRefSkin))
renderMesh(reference->mesh[i],0); // skin!
} else {
renderSkeleton(data->skeleton[si]); // naked bones
}
}

}

renderBody(b);
}
Expand Down Expand Up @@ -2621,6 +2601,36 @@ void GLWidget::renderSelected(const std::vector<BrfType>& v){
for (int i:inViewport[vi].items)
if ( !hideLods || (lodOf(v[i])<=inViewport[vi].bestLod) ) { // don't draw
glPushMatrix();

/* swy: this code which draws the 'Compare with mesh' matching mesh before the collision was originally inside the BrfBody
variant of GLWidget::renderBrfItem(), but had to be moved out because the glMultMatrixf(extraMatrix) after this
meant that the comparison mesh would also get live transformed during the roto-translate tool operation,
and we want to keep it unaffected; only moving the collision itself and having this for reference.
PS: this mesh also needs to get drawn first/before for the see-through effect of the capsules to work */
if (useComparisonMesh && v[i].tokenIndex() == BODY) {
const BrfType &b = v[i];

std::vector<BrfMesh> &v(data->mesh);
for (unsigned int j=0; j<v.size(); j++) {
BrfMesh &m( v[j] );
if ( m.IsNamedAsBody(b.name) && (m.IsNamedAsLOD()==0)) renderMesh(m,0);
}

int si = data->Find(b.name,SKELETON);

if (si>=0) {
if (selRefSkin>=0) {
for (unsigned int i=0; i<reference->mesh.size(); i++)
if (reference->mesh[i].name[4]==char('A'+selRefSkin))
renderMesh(reference->mesh[i],0); // skin!
} else {
renderSkeleton(data->skeleton[si]); // naked bones
}
}

}

if ( (i==lastSelected) || applyExtraMatrixToAll ) glMultMatrixf(extraMatrix);
renderBrfItem(v[i]);

Expand Down

0 comments on commit 300aa55

Please sign in to comment.