From 32fdb545c79413dd94fa0d14a68141c135f6706c Mon Sep 17 00:00:00 2001 From: Alecu100 <lui_alecu@yahoo.co.uk> Date: Mon, 30 Jan 2012 17:08:16 +0200 Subject: [PATCH] updated complex shape to gather bethesda specific properties from the nigeometry node --- include/MatTexCollection.h | 9 ++++++--- src/ComplexShape.cpp | 13 ++++++++++++- src/MatTexCollection.cpp | 30 +++++++++++++++++++++++------- 3 files changed, 41 insertions(+), 11 deletions(-) diff --git a/include/MatTexCollection.h b/include/MatTexCollection.h index 5acc47e7..d6efd2ff 100644 --- a/include/MatTexCollection.h +++ b/include/MatTexCollection.h @@ -30,6 +30,7 @@ class NiMaterialProperty; class NiTexturingProperty; class NiTextureProperty; class NiMultiTextureProperty; +class NiStencilProperty; class NiSourceTexture; class NiImage; @@ -148,7 +149,7 @@ public: * \return The index of the material that matches the specified properties, * or NO_MATERIAL if no match is found. */ - NIFLIB_API unsigned int GetMaterialIndex( NiMaterialProperty * mat, NiTexturingProperty * texing, NiTextureProperty * tex, NiMultiTextureProperty * multi, NiSpecularProperty * spec, NiAlphaProperty * alpha ); + NIFLIB_API unsigned int GetMaterialIndex( NiMaterialProperty * mat, NiTexturingProperty * texing, NiTextureProperty * tex, NiMultiTextureProperty * multi, NiSpecularProperty * spec, NiAlphaProperty * alpha, NiStencilProperty * stencil ); /* * Retrieves the material index of the material that matches the given list @@ -158,7 +159,7 @@ public: * or NO_MATERIAL if no match is found. */ NIFLIB_API unsigned int GetMaterialIndex( const vector< Ref<NiProperty> > & properties ); - + /* * Creates a new material and adds it to the end of the array of materials * contained in this collection. The type of material data that will @@ -330,7 +331,7 @@ private: friend class MatTexCollection; /*! NIFLIB_HIDDEN function. For internal use only. */ - NIFLIB_HIDDEN MaterialWrapper( NiMaterialProperty * mat, NiTexturingProperty * texing, NiTextureProperty * tex, NiMultiTextureProperty * multi, NiSpecularProperty * spec, NiAlphaProperty * alpha, MatTexCollection * creator ); + NIFLIB_HIDDEN MaterialWrapper( NiMaterialProperty * mat, NiTexturingProperty * texing, NiTextureProperty * tex, NiMultiTextureProperty * multi, NiSpecularProperty * spec, NiAlphaProperty * alpha, NiStencilProperty * stencil, MatTexCollection * creator ); /*! The NiMaterialProperty that this object wraps, if any. */ Ref<NiMaterialProperty> mat_prop; @@ -344,6 +345,8 @@ private: Ref<NiSpecularProperty> spec_prop; /*! The NiAlphaProperty that this object wraps, if any. */ Ref<NiAlphaProperty> alpha_prop; + /*! The NiStencilProperty that this object wraps if any */ + Ref<NiStencilProperty> stencil_prop; /*! A pointer back to the MatTexCollection that created this wrapper */ MatTexCollection * _creator; }; diff --git a/src/ComplexShape.cpp b/src/ComplexShape.cpp index d9fefd3d..a119e791 100644 --- a/src/ComplexShape.cpp +++ b/src/ComplexShape.cpp @@ -226,8 +226,19 @@ void ComplexShape::Merge( NiAVObject * root ) { unsigned int prop_group_index = 0; for ( vector<NiTriBasedGeomRef>::iterator geom = shapes.begin(); geom != shapes.end(); ++geom ) { + vector<NiPropertyRef> current_property_group = (*geom)->GetProperties(); + + //Special code to handle the Bethesda Skyrim properties + array<2, NiPropertyRef> bs_properties = (*geom)->getBsProperties(); + if(bs_properties[0] != NULL) { + current_property_group.push_back(bs_properties[0]); + } + if(bs_properties[1] != NULL) { + current_property_group.push_back(bs_properties[1]); + } + //Get properties of this shape - propGroups[prop_group_index] = (*geom)->GetProperties(); + propGroups[prop_group_index] = current_property_group; NiTriBasedGeomDataRef geomData = DynamicCast<NiTriBasedGeomData>( (*geom)->GetData() ); diff --git a/src/MatTexCollection.cpp b/src/MatTexCollection.cpp index a8ae354d..27cff1ad 100644 --- a/src/MatTexCollection.cpp +++ b/src/MatTexCollection.cpp @@ -13,6 +13,7 @@ All rights reserved. Please see niflib.h for license. */ #include "../include/obj/NiAlphaProperty.h" #include "../include/obj/NiSourceTexture.h" #include "../include/obj/NiImage.h" +#include "../include/obj/NiStencilProperty.h" namespace Niflib { @@ -41,9 +42,10 @@ void MatTexCollection::GatherMaterials( NiAVObject * scene_root ) { NiPropertyRef multi = scene_root->GetPropertyByType( NiMultiTextureProperty::TYPE ); NiPropertyRef spec = scene_root->GetPropertyByType( NiSpecularProperty::TYPE ); NiPropertyRef alpha = scene_root->GetPropertyByType( NiAlphaProperty::TYPE ); + NiPropertyRef stencil = scene_root->GetPropertyByType( NiStencilProperty::TYPE); //Make sure at least one isn't NULL - if ( mat != NULL || texing != NULL || tex != NULL || multi != NULL ) { + if ( mat != NULL || texing != NULL || tex != NULL || multi != NULL || stencil != NULL) { //One isn't NULL, so create a new Material NiMaterialPropertyRef matC = DynamicCast<NiMaterialProperty>(mat); @@ -52,6 +54,7 @@ void MatTexCollection::GatherMaterials( NiAVObject * scene_root ) { NiMultiTexturePropertyRef multiC = DynamicCast<NiMultiTextureProperty>(multi); NiSpecularPropertyRef specC = DynamicCast<NiSpecularProperty>(spec); NiAlphaPropertyRef alphaC = DynamicCast<NiAlphaProperty>(alpha); + NiStencilPropertyRef stencilC = DynamicCast<NiStencilProperty>(stencil); //First, check if the material's textures have been found yet @@ -82,7 +85,7 @@ void MatTexCollection::GatherMaterials( NiAVObject * scene_root ) { //TODO: Implement this for NiMultiTextureProperty as well - materials.push_back( MaterialWrapper( matC, texingC, texC, multiC, specC, alphaC, this ) ); + materials.push_back( MaterialWrapper( matC, texingC, texC, multiC, specC, alphaC, stencilC, this ) ); } } //Done with this branch, so return. @@ -137,14 +140,15 @@ unsigned int MatTexCollection::GetMaterialIndex( NiAVObject * obj ) { return GetMaterialIndex( properties ); } -unsigned int MatTexCollection::GetMaterialIndex( NiMaterialProperty * mat, NiTexturingProperty * texing, NiTextureProperty * tex, NiMultiTextureProperty * multi, NiSpecularProperty * spec, NiAlphaProperty * alpha ) { +unsigned int MatTexCollection::GetMaterialIndex( NiMaterialProperty * mat, NiTexturingProperty * texing, NiTextureProperty * tex, NiMultiTextureProperty * multi, NiSpecularProperty * spec, NiAlphaProperty * alpha, NiStencilProperty * stencil ) { for( size_t i = 0; i < materials.size(); ++i ) { if ( materials[i].mat_prop == mat && materials[i].texing_prop == texing && materials[i].tex_prop == tex && materials[i].multi_prop == multi && materials[i].spec_prop == spec && - materials[i].alpha_prop == alpha ) { + materials[i].alpha_prop == alpha && + materials[i].stencil_prop == stencil) { //Match found, return its index return i; } @@ -186,6 +190,7 @@ unsigned int MatTexCollection::GetMaterialIndex( const vector< Ref<NiProperty> > NiMultiTexturePropertyRef multi = NULL; NiSpecularPropertyRef spec = NULL; NiAlphaPropertyRef alpha = NULL; + NiStencilPropertyRef stencil = NULL; for ( unsigned i = 0; i < properties.size(); ++i ) { if ( properties[i] == NULL ) { @@ -203,11 +208,13 @@ unsigned int MatTexCollection::GetMaterialIndex( const vector< Ref<NiProperty> > spec = DynamicCast<NiSpecularProperty>( properties[i] ); } else if ( properties[i]->IsDerivedType( NiAlphaProperty::TYPE ) ) { alpha = DynamicCast<NiAlphaProperty>( properties[i] ); + } else if ( properties[i]->IsDerivedType( NiStencilProperty::TYPE )) { + stencil = DynamicCast<NiStencilProperty>( properties[i] ); } } //Do the search - return GetMaterialIndex( mat, texing, tex, multi, spec, alpha ); + return GetMaterialIndex( mat, texing, tex, multi, spec, alpha, stencil ); } unsigned int MatTexCollection::CreateTexture( unsigned int version ) { @@ -241,6 +248,7 @@ unsigned int MatTexCollection::CreateMaterial( bool color, bool texture, bool mu NiMultiTexturePropertyRef multi = NULL; NiSpecularPropertyRef spec = NULL; NiAlphaPropertyRef alpha = NULL; + NiStencilPropertyRef stencil = NULL; if ( color == true ) { mat = new NiMaterialProperty; @@ -268,7 +276,7 @@ unsigned int MatTexCollection::CreateMaterial( bool color, bool texture, bool mu } //Create Material and add it to the array - materials.push_back( MaterialWrapper( mat, texing, tex, multi, spec, alpha, this ) ); + materials.push_back( MaterialWrapper( mat, texing, tex, multi, spec, alpha, stencil, this ) ); //Return the index of the newly created material return materials.size() - 1; @@ -276,13 +284,14 @@ unsigned int MatTexCollection::CreateMaterial( bool color, bool texture, bool mu //MaterialWrapper////////////////////////////////////////////////////////////// -MaterialWrapper::MaterialWrapper( NiMaterialProperty * mat, NiTexturingProperty * texing, NiTextureProperty * tex, NiMultiTextureProperty * multi, NiSpecularProperty * spec, NiAlphaProperty * alpha, MatTexCollection * creator ) { +MaterialWrapper::MaterialWrapper( NiMaterialProperty * mat, NiTexturingProperty * texing, NiTextureProperty * tex, NiMultiTextureProperty * multi, NiSpecularProperty * spec, NiAlphaProperty * alpha, NiStencilProperty * stencil, MatTexCollection * creator ) { mat_prop = mat; texing_prop = texing; tex_prop = tex; multi_prop = multi; spec_prop = spec; alpha_prop = alpha; + stencil_prop = stencil; _creator = creator; } @@ -308,6 +317,9 @@ void MaterialWrapper::ApplyToObject( NiAVObject * target ) { if ( alpha_prop != NULL ) { target->AddProperty( alpha_prop ); } + if ( stencil_prop != NULL) { + target->AddProperty( stencil_prop ); + } } vector< Ref<NiProperty> > MaterialWrapper::GetProperties() { @@ -338,6 +350,10 @@ vector< Ref<NiProperty> > MaterialWrapper::GetProperties() { prop = StaticCast<NiProperty>(alpha_prop); properties.push_back(prop); } + if( stencil_prop != NULL ) { + prop = StaticCast<NiProperty>(stencil_prop); + properties.push_back(prop); + } return properties; } -- GitLab