Skip to content

Commit

Permalink
Make Model::deleteBoneJoint, etc, return true on success
Browse files Browse the repository at this point in the history
  • Loading branch information
zturtleman committed Jul 21, 2019
1 parent 6148a65 commit 7c20fc2
Show file tree
Hide file tree
Showing 5 changed files with 121 additions and 93 deletions.
170 changes: 91 additions & 79 deletions src/libmm3d/model.cc
Original file line number Diff line number Diff line change
Expand Up @@ -834,47 +834,48 @@ bool Model::getTriangleVertices( unsigned triangleNum, unsigned & vert1, unsigne
}
}

void Model::deleteVertex( unsigned vertexNum )
bool Model::deleteVertex( unsigned vertexNum )
{
LOG_PROFILE();
if ( m_animationMode )
{
return;
return false;
}
if ( m_frameAnims.size() > 0 && !m_forceAddOrDelete)
{
displayFrameAnimPrimitiveError();
return;
return false;
}

if ( vertexNum >= m_vertices.size() )
{
return;
return false;
}

MU_DeleteVertex * undo = new MU_DeleteVertex();
undo->deleteVertex( vertexNum, m_vertices[vertexNum] );
sendUndo( undo );

removeVertex( vertexNum );
return true;
}

void Model::deleteTriangle( unsigned triangleNum )
bool Model::deleteTriangle( unsigned triangleNum )
{
LOG_PROFILE();
if ( m_animationMode )
{
return;
return false;
}
if ( m_frameAnims.size() > 0 && !m_forceAddOrDelete)
{
displayFrameAnimPrimitiveError();
return;
return false;
}

if ( triangleNum >= m_triangles.size() )
{
return;
return false;
}

// remove it from any groups
Expand All @@ -889,125 +890,136 @@ void Model::deleteTriangle( unsigned triangleNum )
sendUndo( undo );

removeTriangle( triangleNum );
return true;
}

void Model::deleteBoneJoint( unsigned joint )
bool Model::deleteBoneJoint( unsigned joint )
{
if ( joint < m_joints.size() )
if ( joint >= m_joints.size() )
{
unsigned count = m_joints.size();
return false;
}

// Break out early if this is a root joint and it has a child
if ( m_joints[joint]->m_parent < 0 )
unsigned count = m_joints.size();

// Break out early if this is a root joint and it has a child
if ( m_joints[joint]->m_parent < 0 )
{
for ( unsigned j = 0; j < count; j++ )
{
for ( unsigned j = 0; j < count; j++ )
if ( j != joint )
{
if ( j != joint )
if ( m_joints[j]->m_parent == (int) joint )
{
if ( m_joints[j]->m_parent == (int) joint )
{
model_status( this, StatusError, STATUSTIME_LONG, transll( QT_TRANSLATE_NOOP( "LowLevel", "Cannot delete root joint" )).c_str() );
return;
}
model_status( this, StatusError, STATUSTIME_LONG, transll( QT_TRANSLATE_NOOP( "LowLevel", "Cannot delete root joint" )).c_str() );
return false;
}
}
}
}

for ( unsigned v = 0; v < m_vertices.size(); v++ )
{
removeVertexInfluence( v, joint );
}
for ( unsigned v = 0; v < m_vertices.size(); v++ )
{
removeVertexInfluence( v, joint );
}

for ( unsigned p = 0; p < m_points.size(); p++ )
{
removePointInfluence( p, joint );
}
for ( unsigned p = 0; p < m_points.size(); p++ )
{
removePointInfluence( p, joint );
}

Matrix m;
int parent = joint;
do
{
parent = m_joints[ parent ]->m_parent;
} while ( parent >= 0 && m_joints[ parent ]->m_selected );
Matrix m;
int parent = joint;
do
{
parent = m_joints[ parent ]->m_parent;
} while ( parent >= 0 && m_joints[ parent ]->m_selected );

if ( parent >= 0 )
{
m = m_joints[ m_joints[joint]->m_parent ]->m_absolute.getInverse();
}
if ( parent >= 0 )
{
m = m_joints[ m_joints[joint]->m_parent ]->m_absolute.getInverse();
}

for ( unsigned j = 0; j < m_joints.size(); j++ )
for ( unsigned j = 0; j < m_joints.size(); j++ )
{
if ( m_joints[j]->m_parent == (int) joint )
{
if ( m_joints[j]->m_parent == (int) joint )
{
setBoneJointParent( j, m_joints[joint]->m_parent );
setBoneJointParent( j, m_joints[joint]->m_parent );

m_joints[j]->m_absolute = m_joints[j]->m_absolute * m;
double rot[3];
double trans[3];
m_joints[j]->m_absolute = m_joints[j]->m_absolute * m;
double rot[3];
double trans[3];

m_joints[j]->m_absolute.getRotation( rot );
m_joints[j]->m_absolute.getTranslation( trans );
m_joints[j]->m_absolute.getRotation( rot );
m_joints[j]->m_absolute.getTranslation( trans );

setBoneJointRotation( j, rot );
setBoneJointTranslation( j, trans );
}
setBoneJointRotation( j, rot );
setBoneJointTranslation( j, trans );
}
}

Joint * ptr = m_joints[joint];
removeBoneJoint( joint );
m_validJoints = false;
Joint * ptr = m_joints[joint];
removeBoneJoint( joint );
m_validJoints = false;

MU_DeleteBoneJoint * undo = new MU_DeleteBoneJoint();
undo->deleteBoneJoint( joint, ptr );
sendUndo( undo );
MU_DeleteBoneJoint * undo = new MU_DeleteBoneJoint();
undo->deleteBoneJoint( joint, ptr );
sendUndo( undo );

log_debug( "parent was %d\n", parent );
log_debug( "parent was %d\n", parent );

setupJoints();
}
setupJoints();

return true;
}

void Model::deletePoint( unsigned point )
bool Model::deletePoint( unsigned point )
{
if ( m_animationMode )
{
return;
return false;
}
if ( m_frameAnims.size() > 0 && !m_forceAddOrDelete)
{
displayFrameAnimPrimitiveError();
return;
return false;
}

if ( point < m_points.size() )
if ( point >= m_points.size() )
{
Point * ptr = m_points[point];
removePoint( point );
return false;
}

MU_DeletePoint * undo = new MU_DeletePoint();
undo->deletePoint( point, ptr );
sendUndo( undo );
Point * ptr = m_points[point];
removePoint( point );

setupJoints();
}
MU_DeletePoint * undo = new MU_DeletePoint();
undo->deletePoint( point, ptr );
sendUndo( undo );

setupJoints();
return true;
}

void Model::deleteProjection( unsigned proj )
bool Model::deleteProjection( unsigned proj )
{
if ( m_animationMode )
{
return;
return false;
}

if ( proj < m_projections.size() )
if ( proj >= m_projections.size() )
{
TextureProjection * ptr = m_projections[ proj ];
removeProjection( proj );

MU_DeleteProjection * undo = new MU_DeleteProjection();
undo->deleteProjection( proj, ptr );
sendUndo( undo );
return false;
}

TextureProjection * ptr = m_projections[ proj ];
removeProjection( proj );

MU_DeleteProjection * undo = new MU_DeleteProjection();
undo->deleteProjection( proj, ptr );
sendUndo( undo );
return true;
}

void Model::deleteOrphanedVertices()
Expand Down
16 changes: 8 additions & 8 deletions src/libmm3d/model.h
Original file line number Diff line number Diff line change
Expand Up @@ -1127,7 +1127,7 @@ class Model

// Common animation properties
int addAnimation( AnimationModeE mode, const char * name );
void deleteAnimation( AnimationModeE mode, unsigned index );
bool deleteAnimation( AnimationModeE mode, unsigned index );

unsigned getAnimCount( AnimationModeE m ) const;

Expand Down Expand Up @@ -1255,8 +1255,8 @@ class Model
int addVertex( double x, double y, double z );
int addTriangle( unsigned vert1, unsigned vert2, unsigned vert3 );

void deleteVertex( unsigned vertex );
void deleteTriangle( unsigned triangle );
bool deleteVertex( unsigned vertex );
bool deleteTriangle( unsigned triangle );

// No undo on this one
void setVertexFree( unsigned v, bool o );
Expand Down Expand Up @@ -1335,8 +1335,8 @@ class Model

bool setGroupTextureId( unsigned groupNumber, int textureId );

void deleteGroup( unsigned group );
void deleteTexture( unsigned texture );
bool deleteGroup( unsigned group );
bool deleteTexture( unsigned texture );

const char * getGroupName( unsigned groupNum ) const;
bool setGroupName( unsigned groupNum, const char * groupName );
Expand Down Expand Up @@ -1409,7 +1409,7 @@ class Model
double xrot, double yrot, double zrot,
int parent = -1 );

void deleteBoneJoint( unsigned joint );
bool deleteBoneJoint( unsigned joint );

const char * getBoneJointName( unsigned joint ) const;
int getBoneJointParent( unsigned joint ) const;
Expand Down Expand Up @@ -1491,7 +1491,7 @@ class Model
double xrot, double yrot, double zrot,
int boneId = -1 );

void deletePoint( unsigned point );
bool deletePoint( unsigned point );

int getPointByName( const char * name ) const;

Expand All @@ -1516,7 +1516,7 @@ class Model
// ------------------------------------------------------------------

int addProjection( const char * name, int type, double x, double y, double z );
void deleteProjection( unsigned proj );
bool deleteProjection( unsigned proj );

const char * getProjectionName( unsigned proj ) const;

Expand Down
6 changes: 5 additions & 1 deletion src/libmm3d/model_anim.cc
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ int Model::addAnimation( AnimationModeE m, const char * name )
return num;
}

void Model::deleteAnimation( AnimationModeE m, unsigned index )
bool Model::deleteAnimation( AnimationModeE m, unsigned index )
{
LOG_PROFILE();

Expand All @@ -106,6 +106,7 @@ void Model::deleteAnimation( AnimationModeE m, unsigned index )
sendUndo( undo );

removeSkelAnim( index );
return true;
}
break;
case ANIMMODE_FRAME:
Expand All @@ -116,11 +117,14 @@ void Model::deleteAnimation( AnimationModeE m, unsigned index )
sendUndo( undo );

removeFrameAnim( index );
return true;
}
break;
default:
break;
}

return false;
}

bool Model::setAnimName( AnimationModeE m, unsigned anim, const char * name )
Expand Down
13 changes: 10 additions & 3 deletions src/libmm3d/model_group.cc
Original file line number Diff line number Diff line change
Expand Up @@ -68,24 +68,31 @@ int Model::addGroup( const char * name )
}
}

void Model::deleteGroup( unsigned groupNum )
bool Model::deleteGroup( unsigned groupNum )
{
LOG_PROFILE();
if ( m_animationMode )
{
return;
return false;
}
if ( m_frameAnims.size() > 0 && !m_forceAddOrDelete)
{
displayFrameAnimPrimitiveError();
return;
return false;
}

if ( groupNum >= m_groups.size() )
{
return false;
}

MU_DeleteGroup * undo = new MU_DeleteGroup();
undo->deleteGroup( groupNum, m_groups[ groupNum ] );
sendUndo( undo );

removeGroup( groupNum );

return true;
}

bool Model::setGroupSmooth( unsigned groupNum, uint8_t smooth )
Expand Down
Loading

0 comments on commit 7c20fc2

Please sign in to comment.