Skip to content

Commit

Permalink
some tweaks
Browse files Browse the repository at this point in the history
  • Loading branch information
m4444x committed Aug 26, 2006
1 parent 973cffb commit e680d66
Show file tree
Hide file tree
Showing 12 changed files with 298 additions and 103 deletions.
8 changes: 8 additions & 0 deletions basemodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,14 @@ QString BaseModel::itemType( const QModelIndex & index ) const
return item->type();
}

QString BaseModel::itemTmplt( const QModelIndex & index ) const
{
NifItem * item = static_cast<NifItem*>( index.internalPointer() );
if ( ! ( index.isValid() && item && index.model() == this ) ) return QString();
return item->temp();
}


NifValue BaseModel::getValue( const QModelIndex & index ) const
{
NifItem * item = static_cast<NifItem*>( index.internalPointer() );
Expand Down
1 change: 1 addition & 0 deletions basemodel.h
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ Q_OBJECT
quint32 itemVer1( const QModelIndex & index ) const;
quint32 itemVer2( const QModelIndex & index ) const;
QString itemText( const QModelIndex & index ) const;
QString itemTmplt( const QModelIndex & index ) const;

// find a branch by name
QModelIndex getIndex( const QModelIndex & parent, const QString & name ) const;
Expand Down
101 changes: 62 additions & 39 deletions gl/glnode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,46 @@ class TransformController : public Controller
QPointer<TransformInterpolator> interpolator;
};

class KeyframeController : public Controller
{
public:
KeyframeController( Node * node, const QModelIndex & index )
: Controller( index ), target( node ), lTrans( 0 ), lRotate( 0 ), lScale( 0 ) {}

void update( float time )
{
if ( ! ( flags.controller.active && target ) )
return;

time = ctrlTime( time );

interpolate( target->local.rotation, iRotations, time, lRotate );
interpolate( target->local.translation, iTranslations, time, lTrans );
interpolate( target->local.scale, iScales, time, lScale );
}

bool update( const NifModel * nif, const QModelIndex & index )
{
if ( Controller::update( nif, index ) )
{
iTranslations = nif->getIndex( iData, "Translations" );
iRotations = nif->getIndex( iData, "Rotations" );
if ( ! iRotations.isValid() )
iRotations = iData;
iScales = nif->getIndex( iData, "Scales" );
return true;
}
return false;
}

protected:
QPointer<Node> target;

QPersistentModelIndex iTranslations, iRotations, iScales;

int lTrans, lRotate, lScale;
};

class VisibilityController : public Controller
{
public:
Expand Down Expand Up @@ -285,15 +325,8 @@ void Node::update( const NifModel * nif, const QModelIndex & index )
if ( iBlock == index || ! index.isValid() )
{
PropertyList newProps;
QModelIndex iProperties = nif->getIndex( iBlock, "Properties" );
if ( iProperties.isValid() )
{
for ( int p = 0; p < nif->rowCount( iProperties ); p++ )
{
QModelIndex iProp = nif->getBlock( nif->getLink( iProperties.child( p, 0 ) ) );
newProps.add( scene->getProperty( nif, iProp ) );
}
}
foreach ( qint32 l, nif->getLinkArray( iBlock, "Properties" ) )
newProps.add( scene->getProperty( nif, nif->getBlock( l ) ) );
properties = newProps;

children.clear();
Expand Down Expand Up @@ -330,12 +363,18 @@ void Node::makeParent( Node * newParent )
void Node::setController( const NifModel * nif, const QModelIndex & iController )
{
QString cname = nif->itemName( iController );
if ( cname == "NiKeyframeController" || cname == "NiTransformController" )
if ( cname == "NiTransformController" )
{
Controller * ctrl = new TransformController( this, iController );
ctrl->update( nif, iController );
controllers.append( ctrl );
}
else if ( cname == "NiKeyframeController" )
{
Controller * ctrl = new KeyframeController( this, iController );
ctrl->update( nif, iController );
controllers.append( ctrl );
}
else if ( cname == "NiVisController" )
{
Controller * ctrl = new VisibilityController( this, iController );
Expand Down Expand Up @@ -542,6 +581,15 @@ void drawHvkShape( const NifModel * nif, const QModelIndex & iShape, QStack<QMod
glLoadName( nif->getBlockNumber( iShape ) );
drawSphere( Vector3(), nif->get<float>( iShape, "Radius" ) );
}
else if ( name == "bhkMultiSphereShape" )
{
glLoadName( nif->getBlockNumber( iShape ) );
QModelIndex iSpheres = nif->getIndex( iShape, "Spheres" );
for ( int r = 0; r < nif->rowCount( iSpheres ); r++ )
{
drawSphere( nif->get<Vector3>( iSpheres.child( r, 0 ), "Center" ), nif->get<float>( iSpheres.child( r, 0 ), "Radius" ) );
}
}
else if ( name == "bhkBoxShape" )
{
glLoadName( nif->getBlockNumber( iShape ) );
Expand Down Expand Up @@ -782,10 +830,9 @@ void Node::drawHavok()

glPopMatrix();

QModelIndex iConstraints = nif->getIndex( iBody, "Constraints" );
for ( int r = 0; r < nif->rowCount( iConstraints ); r++ )
foreach ( qint32 l, nif->getLinkArray( iBody, "Constraints" ) )
{
QModelIndex iConstraint = nif->getBlock( nif->getLink( iConstraints.child( r, 0 ) ) );
QModelIndex iConstraint = nif->getBlock( l );
if ( nif->inherits( iConstraint, "AbhkConstraint" ) )
drawHvkConstraint( nif, iConstraint, scene );
}
Expand Down Expand Up @@ -847,32 +894,8 @@ void drawFurnitureMarker( const NifModel *nif, const QModelIndex &iPosition )
qDebug() << "Unknown furniture marker " << ref1 << "!";
return;
}

float roll;
switch ( orient )
{
case 1570:
roll = -90 / 180.0f * M_PI;
break;
case 3141:
roll = M_PI;
break;

case 4712:
roll = 90.0f / 180.0f * M_PI;
break;

case 0:
case 6283:
roll = 0;
break;

default:
qDebug() << "Unknown orientation " << orient << "!";
roll = 0;
break;
}


float roll = float( orient ) / 6284.0 * 2.0 * (-M_PI);

glLoadName( ( nif->getBlockNumber( iPosition )&0x0ffff ) |
( (iPosition.row()&0x0ffff ) << 16) );
Expand Down
1 change: 1 addition & 0 deletions gl/glnode.h
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ class Node : public Controllable

NodeFlags flags;

friend class KeyframeController;
friend class TransformController;
friend class VisibilityController;
friend class NodeList;
Expand Down
18 changes: 4 additions & 14 deletions kfmmodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -99,20 +99,11 @@ void KfmModel::clear()
* array functions
*/

inline QString inBrakets( const QString & x )
inline QString parentPrefix( const QString & x )
{
for ( int c = 0; c < x.length(); c++ )
if ( ! x[c].isNumber() )
return QString( "(%1)" ).arg( x );
return x;
}

inline QString removeBrakets( QString x )
{
while ( x.startsWith( "(" ) )
x = x.right( x.length() - 1 );
while ( x.endsWith( ")" ) )
x = x.left( x.length() - 1 );
return QString( "../" ) + x;
return x;
}

Expand All @@ -131,7 +122,7 @@ bool KfmModel::updateArrayItem( NifItem * array, bool fast )
int rows = array->childCount();
if ( d1 > rows )
{
NifData data( array->name(), array->type(), array->temp(), NifValue( NifValue::type( array->type() ) ), inBrakets( array->arg() ), inBrakets( array->arr2() ), QString(), QString(), 0, 0 );
NifData data( array->name(), array->type(), array->temp(), NifValue( NifValue::type( array->type() ) ), parentPrefix( array->arg() ), parentPrefix( array->arr2() ), QString(), QString(), 0, 0 );

if ( ! fast ) beginInsertRows( createIndex( array->row(), 0, array ), rows, d1-1 );
array->prepareInsert( d1 - rows );
Expand Down Expand Up @@ -163,15 +154,14 @@ void KfmModel::insertType( NifItem * parent, const NifData & data, int at )
return;
}

QReadLocker lck( &XMLlock );
NifBlock * compound = compounds.value( data.type() );
if ( compound )
{
NifItem * branch = insertBranch( parent, data, at );
branch->prepareInsert( compound->types.count() );
if ( ! data.arg().isEmpty() || ! data.temp().isEmpty() )
{
QString arg = inBrakets( data.arg() );
QString arg = parentPrefix( data.arg() );
QString tmp = data.temp();
if ( tmp == "TEMPLATE" )
{
Expand Down
7 changes: 3 additions & 4 deletions kfmmodel.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,9 @@ Q_OBJECT
// call this once on startup to load the XML descriptions
static bool loadXML();

// when creating kfmmodels from outside the main thread better protect them with a QReadLocker
static QReadWriteLock XMLlock;

// clear model data
void clear();

Expand Down Expand Up @@ -100,8 +103,6 @@ Q_OBJECT
NifItem * kfmroot;

// XML structures
static QReadWriteLock XMLlock;

static QList<quint32> supportedVersions;

static QHash<QString,NifBlock*> compounds;
Expand All @@ -114,13 +115,11 @@ Q_OBJECT

inline bool KfmModel::isCompound( const QString & name )
{
QReadLocker lck( &XMLlock );
return compounds.contains( name );
}

inline bool KfmModel::isVersionSupported( quint32 v )
{
QReadLocker lck( &XMLlock );
return supportedVersions.contains( v );
}

Expand Down
Loading

0 comments on commit e680d66

Please sign in to comment.