Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merge branch 'skyrim-properties-2'

  • Loading branch information...
commit ce3910a28b053631da9fe9e72c99efb73d879cb7 2 parents afa7ef4 + c9b1bb4
@amorilia authored
2  docsys
@@ -1 +1 @@
-Subproject commit f5c139065bf518ab309ac8264cdee8b4a47be2ae
+Subproject commit f5f6c6aec8c484e5ce41f50e10b46f188bc110c8
View
3  gl/glnode.cpp
@@ -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();
View
35 importex/3ds.cpp
@@ -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" )
View
32 importex/obj.cpp
@@ -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" )
View
10 nifxml.cpp
@@ -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 ) ),
View
77 spells/blocks.cpp
@@ -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;
}
}
@@ -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 ) ) )
@@ -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" ) )
{
@@ -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 )
@@ -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
Please sign in to comment.
Something went wrong with that request. Please try again.