From 8c0326a49c94583fc50eff481408c59654fdee6f Mon Sep 17 00:00:00 2001 From: Chris Robinson Date: Sat, 2 Mar 2013 18:30:28 -0800 Subject: [PATCH] Handle NiZBufferProperty --- components/nifogre/ogre_nif_loader.cpp | 33 +++++++++++++++++++------- 1 file changed, 24 insertions(+), 9 deletions(-) diff --git a/components/nifogre/ogre_nif_loader.cpp b/components/nifogre/ogre_nif_loader.cpp index 1d0d31961..1ea911a77 100644 --- a/components/nifogre/ogre_nif_loader.cpp +++ b/components/nifogre/ogre_nif_loader.cpp @@ -553,7 +553,8 @@ static Ogre::String getMaterial(const Nif::NiTriShape *shape, const Ogre::String const Nif::NiTexturingProperty *texprop, const Nif::NiMaterialProperty *matprop, const Nif::NiAlphaProperty *alphaprop, - const Nif::NiVertexColorProperty *vertprop) + const Nif::NiVertexColorProperty *vertprop, + const Nif::NiZBufferProperty *zprop) { Ogre::MaterialManager &matMgr = Ogre::MaterialManager::getSingleton(); Ogre::MaterialPtr material = matMgr.getByName(name); @@ -570,6 +571,7 @@ static Ogre::String getMaterial(const Nif::NiTriShape *shape, const Ogre::String int alphaTest = 0; int vertMode = 2; //int lightMode = 1; + int depthFlags = 3; Ogre::String texName; bool vertexColour = (shape->data->colors.size() != 0); @@ -628,6 +630,12 @@ static Ogre::String getMaterial(const Nif::NiTriShape *shape, const Ogre::String //lightMode = vertprop->data.lightmode; } + if(zprop) + { + depthFlags = zprop->flags; + // Depth function??? + } + // Material if(matprop) { @@ -731,8 +739,11 @@ static Ogre::String getMaterial(const Nif::NiTriShape *shape, const Ogre::String instance->setProperty("alpha_rejection", sh::makeProperty(new sh::StringValue(reject))); } - instance->setProperty("transparent_sorting", sh::makeProperty(new sh::StringValue(((alphaFlags>>13)&1) ? - "off" : "on"))); + instance->setProperty("transparent_sorting", sh::makeProperty(new sh::BooleanValue(!((alphaFlags>>13)&1)))); + + instance->setProperty("depth_check", sh::makeProperty(new sh::BooleanValue(depthFlags&1))); + instance->setProperty("depth_write", sh::makeProperty(new sh::BooleanValue((depthFlags>>1)&1))); + // depth_func??? sh::Factory::getInstance()._ensureMaterial(matname, "Default"); return matname; @@ -769,7 +780,8 @@ class NIFMeshLoader : Ogre::ManualResourceLoader const Nif::NiTexturingProperty *texprop, const Nif::NiMaterialProperty *matprop, const Nif::NiAlphaProperty *alphaprop, - const Nif::NiVertexColorProperty *vertprop) + const Nif::NiVertexColorProperty *vertprop, + const Nif::NiZBufferProperty *zprop) { Ogre::SkeletonPtr skel; const Nif::NiTriShapeData *data = shape->data.getPtr(); @@ -969,7 +981,7 @@ class NIFMeshLoader : Ogre::ManualResourceLoader std::string matname = NIFMaterialLoader::getMaterial(shape, mName, mGroup, texprop, matprop, alphaprop, - vertprop); + vertprop, zprop); if(matname.length() > 0) sub->setMaterialName(matname); } @@ -978,7 +990,8 @@ class NIFMeshLoader : Ogre::ManualResourceLoader const Nif::NiTexturingProperty *texprop=NULL, const Nif::NiMaterialProperty *matprop=NULL, const Nif::NiAlphaProperty *alphaprop=NULL, - const Nif::NiVertexColorProperty *vertprop=NULL) + const Nif::NiVertexColorProperty *vertprop=NULL, + const Nif::NiZBufferProperty *zprop=NULL) { // Scan the property list for material information const Nif::PropertyList &proplist = node->props; @@ -997,25 +1010,27 @@ class NIFMeshLoader : Ogre::ManualResourceLoader alphaprop = static_cast(pr); else if(pr->recType == Nif::RC_NiVertexColorProperty) vertprop = static_cast(pr); + else if(pr->recType == Nif::RC_NiZBufferProperty) + zprop = static_cast(pr); else warn("Unhandled property type: "+pr->recName); } if(node->recType == Nif::RC_NiTriShape && mShapeIndex == node->recIndex) { - handleNiTriShape(mesh, dynamic_cast(node), texprop, matprop, alphaprop, vertprop); + handleNiTriShape(mesh, dynamic_cast(node), texprop, matprop, alphaprop, vertprop, zprop); return true; } const Nif::NiNode *ninode = dynamic_cast(node); if(ninode) { - Nif::NodeList const &children = ninode->children; + const Nif::NodeList &children = ninode->children; for(size_t i = 0;i < children.length();i++) { if(!children[i].empty()) { - if(findTriShape(mesh, children[i].getPtr(), texprop, matprop, alphaprop, vertprop)) + if(findTriShape(mesh, children[i].getPtr(), texprop, matprop, alphaprop, vertprop, zprop)) return true; } }