Skip to content

Commit

Permalink
Merge branch 'skyrim-properties-2'
Browse files Browse the repository at this point in the history
  • Loading branch information
amorilia committed Dec 10, 2011
2 parents afa7ef4 + c9b1bb4 commit ce3910a
Show file tree
Hide file tree
Showing 6 changed files with 116 additions and 43 deletions.
2 changes: 1 addition & 1 deletion docsys
Submodule docsys updated from f5c139 to f5f6c6
3 changes: 3 additions & 0 deletions gl/glnode.cpp
Expand Up @@ -580,6 +580,9 @@ void Node::update( const NifModel * nif, const QModelIndex & index )
foreach ( qint32 l, nif->getLinkArray( iBlock, "Properties" ) )
if ( Property * p = scene->getProperty( nif, nif->getBlock( l ) ) )
newProps.add( p );
foreach ( qint32 l, nif->getLinkArray( iBlock, "BS Properties" ) )
if ( Property * p = scene->getProperty( nif, nif->getBlock( l ) ) )
newProps.add( p );
properties = newProps;

children.clear();
Expand Down
35 changes: 22 additions & 13 deletions importex/3ds.cpp
Expand Up @@ -615,23 +615,32 @@ void import3ds( NifModel * nif, const QModelIndex & index )
addLink( nif, iRoot, "Children", nif->getBlockNumber( iShape ) );
}

if ( iMaterial.isValid() == false || objIndex != 0 )

// add material property, for non-Skyrim versions
if ( nif->getUserVersion() < 12 )
{
iMaterial = nif->insertNiBlock( "NiMaterialProperty" );
if ( iMaterial.isValid() == false || objIndex != 0 )
{
iMaterial = nif->insertNiBlock( "NiMaterialProperty" );
}
nif->set<QString>( iMaterial, "Name", mat->name );
nif->set<Color3>( iMaterial, "Ambient Color", mat->Ka );
nif->set<Color3>( iMaterial, "Diffuse Color", mat->Kd );
nif->set<Color3>( iMaterial, "Specular Color", mat->Ks );
nif->set<Color3>( iMaterial, "Emissive Color", Color3( 0, 0, 0 ) );
nif->set<float>( iMaterial, "Alpha", mat->alpha );
nif->set<float>( iMaterial, "Glossiness", mat->glossiness );

addLink( nif, iShape, "Properties", nif->getBlockNumber( iMaterial ) );
}
nif->set<QString>( iMaterial, "Name", mat->name );
nif->set<Color3>( iMaterial, "Ambient Color", mat->Ka );
nif->set<Color3>( iMaterial, "Diffuse Color", mat->Kd );
nif->set<Color3>( iMaterial, "Specular Color", mat->Ks );
nif->set<Color3>( iMaterial, "Emissive Color", Color3( 0, 0, 0 ) );
nif->set<float>( iMaterial, "Alpha", mat->alpha );
nif->set<float>( iMaterial, "Glossiness", mat->glossiness );

addLink( nif, iShape, "Properties", nif->getBlockNumber( iMaterial ) );


if ( !mat->map_Kd.isEmpty() )
{
if ( nif->getVersionNumber() >= 0x0303000D )
if ( nif -> getUserVersion() >= 12 )
{
// Skyrim, nothing here yet
}
else if ( nif->getVersionNumber() >= 0x0303000D )
{
//Newer versions use NiTexturingProperty and NiSourceTexture
if ( iTexProp.isValid() == false || objIndex != 0 || nif->itemType(iTexProp) != "NiTexturingProperty" )
Expand Down
32 changes: 20 additions & 12 deletions importex/obj.cpp
Expand Up @@ -689,23 +689,31 @@ void importObj( NifModel * nif, const QModelIndex & index )

ObjMaterial mtl = omaterials.value( it.key() );

if ( iMaterial.isValid() == false || first_tri_shape == false )
// add material property, for non-Skyrim versions
if ( nif->getUserVersion() < 12 )
{
iMaterial = nif->insertNiBlock( "NiMaterialProperty" );
if ( iMaterial.isValid() == false || first_tri_shape == false )
{
iMaterial = nif->insertNiBlock( "NiMaterialProperty" );
}
nif->set<QString>( iMaterial, "Name", it.key() );
nif->set<Color3>( iMaterial, "Ambient Color", mtl.Ka );
nif->set<Color3>( iMaterial, "Diffuse Color", mtl.Kd );
nif->set<Color3>( iMaterial, "Specular Color", mtl.Ks );
nif->set<Color3>( iMaterial, "Emissive Color", Color3( 0, 0, 0 ) );
nif->set<float>( iMaterial, "Alpha", mtl.d );
nif->set<float>( iMaterial, "Glossiness", mtl.Ns );

addLink( nif, iShape, "Properties", nif->getBlockNumber( iMaterial ) );
}
nif->set<QString>( iMaterial, "Name", it.key() );
nif->set<Color3>( iMaterial, "Ambient Color", mtl.Ka );
nif->set<Color3>( iMaterial, "Diffuse Color", mtl.Kd );
nif->set<Color3>( iMaterial, "Specular Color", mtl.Ks );
nif->set<Color3>( iMaterial, "Emissive Color", Color3( 0, 0, 0 ) );
nif->set<float>( iMaterial, "Alpha", mtl.d );
nif->set<float>( iMaterial, "Glossiness", mtl.Ns );

addLink( nif, iShape, "Properties", nif->getBlockNumber( iMaterial ) );

if ( ! mtl.map_Kd.isEmpty() )
{
if ( nif->getVersionNumber() >= 0x0303000D )
if ( nif -> getUserVersion() >= 12)
{
// Skyrim, nothing here yet
}
else if ( nif->getVersionNumber() >= 0x0303000D )
{
//Newer versions use NiTexturingProperty and NiSourceTexture
if ( iTexProp.isValid() == false || first_tri_shape == false || nif->itemType(iTexProp) != "NiTexturingProperty" )
Expand Down
10 changes: 3 additions & 7 deletions nifxml.cpp
Expand Up @@ -260,19 +260,15 @@ class NifXmlHandler : public QXmlDefaultHandler
err( "failed to locate alias " + nstype );
type = nstype;
}

if ( type == "KeyArray" ) type = "ns keyarray";
else if ( type == "VectorKeyArray" ) type = "ns keyvecarray";
else if ( type == "TypedVectorKeyArray" ) type = "ns keyvecarraytyp";
else if ( type == "RotationKeyArray" ) type = "ns keyrotarray";

QString name = list.value( "name" );
QString nsname = list.value( "nifskopename" );
if (!nsname.isEmpty()) name = nsname;


// now allocate
data = NifData(
name,
list.value( "name" ),
type,
list.value( "template" ),
NifValue( NifValue::type( type ) ),
Expand Down
77 changes: 67 additions & 10 deletions spells/blocks.cpp
Expand Up @@ -26,16 +26,48 @@
* @param array The name of the link array
* @param link A reference to the block to insert into the link array
*/
static void addLink( NifModel * nif, QModelIndex iParent, QString array, int link )
static bool addLink( NifModel * nif, QModelIndex iParent, QString array, int link )
{
QModelIndex iSize = nif->getIndex( iParent, QString( "Num %1" ).arg( array ) );
QModelIndex iArray = nif->getIndex( iParent, array );
if ( iSize.isValid() && iArray.isValid() )
if ( iSize.isValid() && (iSize.flags() & Qt::ItemIsEnabled) )
{
int numlinks = nif->get<int>( iSize );
nif->set<int>( iSize, numlinks + 1 );
nif->updateArray( iArray );
nif->setLink( iArray.child( numlinks, 0 ), link );
// size is valid: dynamically sized array?
if ( iArray.isValid() && ( iArray.flags() & Qt::ItemIsEnabled ) )
{
int numlinks = nif->get<int>( iSize );
nif->set<int>( iSize, numlinks + 1 );
nif->updateArray( iArray );
nif->setLink( iArray.child( numlinks, 0 ), link );
return true;
}
else
{
// no clue what this is, fail
return false;
}
}
else if ( iArray.isValid() && ( iArray.flags() & Qt::ItemIsEnabled ) )
{
// static array, find a empty entry and insert link there
NifItem * item = static_cast<NifItem*>( iArray.internalPointer() );
if ( nif->isArray( iArray ) && item )
{
for ( int c = 0; c < item->childCount(); c++ )
{
if ( item->child( c )->value().toLink() == -1 )
{
nif->setLink( iArray.child( c, 0), link );
return true;
}
}
}
// failed in some way, either array not valid or no empty entry found
return false;
}
else
{
return false;
}
}

Expand All @@ -61,6 +93,8 @@ static void delLink( NifModel * nif, QModelIndex iParent, QString array, int lin
}

// documented in blocks.h
// XXX at the moment, we don't care if this fails or not...
// XXX probably should return a bool?
void blockLink( NifModel * nif, const QModelIndex & index, const QModelIndex & iBlock )
{
if ( nif->isLink( index ) && nif->inherits( iBlock, nif->itemTmplt( index ) ) )
Expand All @@ -77,7 +111,15 @@ void blockLink( NifModel * nif, const QModelIndex & index, const QModelIndex & i
}
else if ( nif->inherits( index, "NiAVObject" ) && nif->inherits( iBlock, "NiProperty" ) )
{
addLink( nif, index, "Properties", nif->getBlockNumber( iBlock ) );
// Skyrim note: this will fail if "Properties" is not enabled
if ( !addLink( nif, index, "Properties", nif->getBlockNumber( iBlock ) ) )
{
// "Properties" was not enabled: try Skyrim style "BS Properties"
if ( nif->inherits( index, "NiGeometry" ) )
{
addLink( nif, index, "BS Properties", nif->getBlockNumber( iBlock ) );
}
}
}
else if ( nif->inherits( index, "NiAVObject" ) && nif->inherits( iBlock, "NiExtraData" ) )
{
Expand Down Expand Up @@ -221,7 +263,17 @@ class spAttachProperty : public Spell

bool isApplicable( const NifModel * nif, const QModelIndex & index )
{
return nif->itemType( index ) == "NiBlock" && nif->inherits( index, "NiAVObject" );
if ( nif->itemType( index ) != "NiBlock" ) return false;
if ( nif->getUserVersion() < 12 )
{
// not Skyrim
return nif->inherits( index, "NiAVObject" );
}
else
{
// Skyrim
return nif->inherits( index, "NiGeometry" );
}
}

QModelIndex cast( NifModel * nif, const QModelIndex & index )
Expand All @@ -239,8 +291,13 @@ class spAttachProperty : public Spell
{
QPersistentModelIndex iParent = index;
QModelIndex iProperty = nif->insertNiBlock( act->text(), nif->getBlockNumber( index ) + 1 );

addLink( nif, iParent, "Properties", nif->getBlockNumber( iProperty ) );
if ( !addLink( nif, iParent, "Properties", nif->getBlockNumber( iProperty ) ) ) {
// try Skyrim
if ( !addLink( nif, iParent, "BS Properties", nif->getBlockNumber( iProperty ) ) )
{
qWarning() << "failed to attach property block; perhaps the array is full?";
}
}
return iProperty;
}
else
Expand Down

0 comments on commit ce3910a

Please sign in to comment.