示例#1
0
bool Renderer::ConditionSingle::eval( const NifModel * nif, const QList<QModelIndex> & iBlocks ) const
{
	QModelIndex iLeft = getIndex( nif, iBlocks, left );
	if ( ! iLeft.isValid() )
		return invert;
	if ( comp == NONE )
		return ! invert;
	NifValue val = nif->getValue( iLeft );
	if ( val.isString() )
		return compare( val.toString(), right ) ^ invert;
	else if ( val.isCount() )
		return compare( val.toCount(), right.toUInt(NULL, 0) ) ^ invert;
	else if ( val.isFloat() )
		return compare( val.toFloat(), (float) right.toDouble() ) ^ invert;
	else if ( val.isFileVersion() )
		return compare( val.toFileVersion(), right.toUInt(NULL, 0) ) ^ invert;
	
	return false;
}
示例#2
0
void ValueEdit::setValue( const NifValue & v )
{
    typ = v.type();

    if ( edit )
    {
        // segfaults with Qt 4.5:
        //delete edit;
        edit = 0;
        resize( this->baseSize() );
    }

    switch ( typ )
    {
    case NifValue::tByte:
    {
        QSpinBox * be = new QSpinBox( this );
        be->setFrame(false);
        be->setRange( 0, 0xff );
        be->setValue( v.toCount() );
        edit = be;
    }
    break;
    case NifValue::tWord:
    case NifValue::tFlags:
    {
        QSpinBox * we = new QSpinBox( this );
        we->setFrame(false);
        we->setRange( 0, 0xffff );
        we->setValue( v.toCount() );
        edit = we;
    }
    break;
    case NifValue::tShort:
    {
        QSpinBox * we = new QSpinBox( this );
        we->setFrame(false);
        we->setRange( SHRT_MIN, SHRT_MAX );
        we->setValue( (short)v.toCount() );
        edit = we;
    }
    break;
    case NifValue::tInt:
    {
        QSpinBox * ie = new QSpinBox( this );
        ie->setFrame(false);
        ie->setRange( INT_MIN, INT_MAX );
        ie->setValue( (int)v.toCount() );
        edit = ie;
    }
    break;
    case NifValue::tStringIndex:
    {
        QSpinBox * ie = new QSpinBox( this );
        ie->setFrame(false);
        ie->setRange( -1, INT_MAX );
        ie->setValue( (int)v.toCount() );
        edit = ie;
    }
    break;
    case NifValue::tUInt:
    {
        QSpinBox * ie = new UIntSpinBox( this );
        ie->setFrame(false);
        ie->setValue( v.toCount() );
        edit = ie;
    }
    break;
    case NifValue::tLink:
    case NifValue::tUpLink:
    {
        QLineEdit * le = new QLineEdit( this );
        int tmp = v.toLink();
        if ( tmp > 0 ) {
            le->setText( QString::number(tmp) );
        }
        edit = le;
    }
    break;
    case NifValue::tFloat:
    {
        FloatEdit * fe = new FloatEdit( this );
        /*
        fe->setFrame(false);
        fe->setRange( -1e10, +1e10 );
        fe->setDecimals( 4 );
        */
        fe->setValue( v.toFloat() );
        edit = fe;
    }
    break;

    case NifValue::tText:
    case NifValue::tSizedString:
    {
        TextEdit * te = new TextEdit( v.toString(), this );
        te->resize( size() );
        connect( te, SIGNAL( sigResized(QResizeEvent *) ), this, SLOT( childResized(QResizeEvent *) ) );
        edit = te;
    }
    break;
    case NifValue::tLineString:
    case NifValue::tShortString:
    case NifValue::tChar8String:
    {
        QLineEdit * le = new QLineEdit( this );
        le->setText( v.toString() );
        edit = le;
    }
    break;
    //case NifValue::tText:
    //{
    //	TextEdit * te = new TextEdit( v.toString(), this );
    //	te->setMinimumSize( width(), height() );
    //	te->setBaseSize( width(), height() * 5);
    //	edit = te;
    //}	break;
    case NifValue::tColor4:
    {
        ColorEdit * ce = new ColorEdit( this );
        ce->setColor4( v.get<Color4>() );
        edit = ce;
    }
    break;
    case NifValue::tColor3:
    {
        ColorEdit * ce = new ColorEdit( this );
        ce->setColor3( v.get<Color3>() );
        edit = ce;
    }
    break;
    case NifValue::tVector4:
    {
        VectorEdit * ve = new VectorEdit( this );
        ve->setVector4( v.get<Vector4>() );
        edit = ve;
    }
    break;
    case NifValue::tVector3:
    {
        VectorEdit * ve = new VectorEdit( this );
        ve->setVector3( v.get<Vector3>() );
        edit = ve;
    }
    break;
    case NifValue::tVector2:
    {
        VectorEdit * ve = new VectorEdit( this );
        ve->setVector2( v.get<Vector2>() );
        edit = ve;
    }
    break;
    case NifValue::tMatrix:
    {
        RotationEdit * re = new RotationEdit( this );
        re->setMatrix( v.get<Matrix>() );
        edit = re;
    }
    break;
    case NifValue::tQuat:
    case NifValue::tQuatXYZW:
    {
        RotationEdit * re = new RotationEdit( this );
        re->setQuat( v.get<Quat>() );
        edit = re;
    }
    break;
    case NifValue::tTriangle:
    {
        TriangleEdit * te = new TriangleEdit( this );
        te->setTriangle( v.get<Triangle>() );
        edit = te;
    }
    break;
    case NifValue::tString:
    {
        if (/*???*/false)
        {
            QSpinBox * ie = new UIntSpinBox( this );
            ie->setFrame(false);
            ie->setValue( v.toCount() );
            edit = ie;
        }
        else
        {
            QLineEdit * le = new QLineEdit( this );
            le->setText( v.toString() );
            edit = le;
        }
    }
    break;
    case NifValue::tFilePath:
    {
        if (/*???*/false)
        {
            QSpinBox * ie = new UIntSpinBox( this );
            ie->setFrame(false);
            ie->setValue( v.toCount() );
            edit = ie;
        }
        else
        {
            QLineEdit * le = new QLineEdit( this );
            le->setText( v.toString() );
            edit = le;
        }
    }
    break;
    default:
        edit = 0;
        break;
    }

    resizeEditor();

    setFocusProxy( edit );
}
示例#3
0
void Mesh::transform()
{
	const NifModel * nif = static_cast<const NifModel *>( iBlock.model() );
	if ( ! nif || ! iBlock.isValid() )
	{
		clear();
		return;
	}
	
	if ( upData )
	{
		upData = false;
		
		// update for NiMesh
		if ( nif->checkVersion( 0x14050000, 0 ) && nif->inherits( iBlock, "NiMesh" ) )
		{
#ifndef QT_NO_DEBUG
			// do stuff
			qWarning() << "Entering NiMesh decoding...";
			// mesh primitive type
			QString meshPrimitiveType = NifValue::enumOptionName( "MeshPrimitiveType", nif->get<uint>( iData, "Primitive Type" ) );
			qWarning() << "Mesh uses" << meshPrimitiveType;
			for ( int i = 0; i < nif->rowCount( iData ); i ++ )
			{
				// each data reference is to a single data stream
				quint32 stream = nif->getLink( iData.child( i, 0 ), "Stream" );
				qWarning() << "Data stream: " << stream;
				// can have multiple submeshes, unsure of exact meaning
				ushort numSubmeshes = nif->get<ushort>( iData.child( i, 0 ), "Num Submeshes" );
				qWarning() << "Submeshes: " << numSubmeshes;
				QPersistentModelIndex submeshMap = nif->getIndex( iData.child( i, 0 ), "Submesh To Region Map" );
				for ( int j = 0; j < numSubmeshes; j++ )
				{
					qWarning() << "Submesh" << j << "maps to region" << nif->get<ushort>( submeshMap.child( j, 0 ) );
				}
				// each stream can have multiple components, and each has a starting index
				QMap<uint, QString> componentIndexMap;
				int numComponents = nif->get<int>( iData.child( i, 0 ), "Num Components" );
				qWarning() << "Components: " << numComponents;
				// semantics determine the usage
				QPersistentModelIndex componentSemantics = nif->getIndex( iData.child( i, 0 ), "Component Semantics" );
				for( int j = 0; j < numComponents; j++ )
				{
					QString name = nif->get<QString>( componentSemantics.child( j, 0 ), "Name" );
					uint index = nif->get<uint>( componentSemantics.child( j, 0 ), "Index" );
					qWarning() << "Component" << name << "at position" << index << "of component" << j << "in stream" << stream;
					componentIndexMap.insert( j, QString( "%1 %2").arg( name ).arg( index ) );
				}
				
				// now the data stream itself...
				QPersistentModelIndex dataStream = nif->getBlock( stream );
				QByteArray streamData = nif->get<QByteArray>( nif->getIndex( dataStream, "Data" ).child( 0, 0 ) );
				QBuffer streamBuffer( &streamData );
				streamBuffer.open( QIODevice::ReadOnly );
				// probably won't use this
				QDataStream streamReader( &streamData, QIODevice::ReadOnly );
				// we should probably check the header here, but we expect things to be little endian
				streamReader.setByteOrder( QDataStream::LittleEndian );
				// each region exists within the data stream at the specified index
				quint32 numRegions = nif->get<quint32>( dataStream, "Num Regions");
				QPersistentModelIndex regions = nif->getIndex( dataStream, "Regions" );
				quint32 totalIndices = 0;
				if ( regions.isValid() )
				{
					qWarning() << numRegions << " regions in this stream";
					for( quint32 j = 0; j < numRegions; j++ )
					{
						qWarning() << "Start index: " << nif->get<quint32>( regions.child( j, 0 ), "Start Index" );
						qWarning() << "Num indices: " << nif->get<quint32>( regions.child( j, 0 ), "Num Indices" );
						totalIndices += nif->get<quint32>( regions.child( j, 0 ), "Num Indices" );
					}
					qWarning() << totalIndices << "total indices in" << numRegions << "regions";
				}
				uint numStreamComponents = nif->get<uint>( dataStream, "Num Components" );
				qWarning() << "Stream has" << numStreamComponents << "components";
				QPersistentModelIndex streamComponents = nif->getIndex( dataStream, "Component Formats" );
				// stream components are interleaved, so we need to know their type before we read them
				QList<uint> typeList;
				for( uint j = 0; j < numStreamComponents; j++ )
				{
					uint compFormat = nif->get<uint>( streamComponents.child( j, 0 ) );
					QString compName = NifValue::enumOptionName( "ComponentFormat", compFormat );
					qWarning() << "Component format is" << compName;
					qWarning() << "Stored as a" << compName.split( "_" )[1];
					typeList.append( compFormat - 1 );
					
					// this can probably wait until we're reading the stream values
					QString compNameIndex = componentIndexMap.value( j );
					QString compType = compNameIndex.split( " " )[0];
					uint startIndex = compNameIndex.split( " " )[1].toUInt();
					qWarning() << "Component" << j << "contains" << compType << "starting at index" << startIndex;

					// try and sort out texcoords here...
					if( compType == "TEXCOORD" )
					{
						QVector<Vector2> tempCoords;
						coords.append( tempCoords );
						qWarning() << "Assigning coordinate set" << startIndex;
					}

				}	
				
				// for each component
				// get the length
				// get the underlying type (will probably need OpenEXR to deal with float16 types)
				// read that type in, k times, where k is the length of the vector
				// start index will not be 0 if eg. multiple UV maps, but hopefully we don't have multiple components
				
				for( uint j = 0; j < totalIndices; j++ )
				{
					for( uint k = 0; k < numStreamComponents; k++ )
					{
						int typeLength = ( ( typeList[k] & 0x000F0000 ) >> 0x10 );
						int typeSize = ( ( typeList[k] & 0x00000F00 ) >> 0x08 );
						qWarning() << "Reading" << typeLength << "values" << typeSize << "bytes";

						NifIStream tempInput( new NifModel, &streamBuffer );
						QList<NifValue> values;
						NifValue tempValue;
						// if we had the right types, we could read in Vector etc. and not have the mess below
						switch( ( typeList[k] & 0x00000FF0 ) >> 0x04 )
						{
							case 0x10:
								tempValue.changeType( NifValue::tByte );
								break;
							case 0x21:
								tempValue.changeType( NifValue::tShort );
								break;
							case 0x42:
								tempValue.changeType( NifValue::tInt );
								break;
							case 0x43:
								tempValue.changeType( NifValue::tFloat );
								break;
						}
						for( int l = 0; l < typeLength; l++ )
						{
							tempInput.read( tempValue );
							values.append( tempValue );
							qWarning() << tempValue.toString();
						}
						QString compType = componentIndexMap.value( k ).split( " " )[0];
						qWarning() << "Will store this value in" << compType;
						// the mess begins...
						if( NifValue::enumOptionName( "ComponentFormat", (typeList[k] + 1 ) ) == "F_FLOAT32_3" )
						{
							Vector3 tempVect3( values[0].toFloat(), values[1].toFloat(), values[2].toFloat() );
							if( compType == "POSITION" )
							{
								verts.append( tempVect3 );
							}
							else if( compType == "NORMAL" )
							{
								norms.append( tempVect3 );
							}
						}
						else if( compType == "INDEX" )
						{
							indices.append( values[0].toCount() );
						}
						else if( compType == "TEXCOORD" )
						{
							Vector2 tempVect2( values[0].toFloat(), values[1].toFloat() );
							quint32 coordSet = componentIndexMap.value( k ).split( " " )[1].toUInt();
							qWarning() << "Need to append" << tempVect2 << "to texcoords" << coordSet;
							QVector<Vector2> currentSet = coords[coordSet];
							currentSet.append( tempVect2 );
							coords[coordSet] = currentSet;
						}
					}
				}

				// build triangles, strips etc.
				if( meshPrimitiveType == "MESH_PRIMITIVE_TRIANGLES" )
				{
					for( int k = 0; k < indices.size(); )
					{
						Triangle tempTri( indices[k], indices[k+1], indices[k+2] );
						qWarning() << "Inserting triangle" << tempTri;
						triangles.append( tempTri );
						k = k+3;
					}
				}
			}
#endif
		}
		else
		{