From c9a42f85eb9e47401ece70be03579f6fc49faa2a Mon Sep 17 00:00:00 2001 From: Nicolay Korslund Date: Wed, 6 Jan 2010 16:22:34 +0100 Subject: [PATCH] Added NiSourceTexture, NiTexturingProperty --- nif/data.h | 86 ++++++++++++++++++++++++++++++ nif/nif_file.cpp | 6 ++- nif/nif_file.h | 5 ++ nif/property.h | 134 +++++++++++++++++++++++++++++++++++++++++++++++ nif/record_ptr.h | 4 ++ 5 files changed, 234 insertions(+), 1 deletion(-) create mode 100644 nif/data.h create mode 100644 nif/property.h diff --git a/nif/data.h b/nif/data.h new file mode 100644 index 0000000000..867473203f --- /dev/null +++ b/nif/data.h @@ -0,0 +1,86 @@ +/* + OpenMW - The completely unofficial reimplementation of Morrowind + Copyright (C) 2008-2010 Nicolay Korslund + Email: < korslund@gmail.com > + WWW: http://openmw.sourceforge.net/ + + This file (data.h) is part of the OpenMW package. + + OpenMW is distributed as free software: you can redistribute it + and/or modify it under the terms of the GNU General Public License + version 3, as published by the Free Software Foundation. + + This program is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + General Public License for more details. + + You should have received a copy of the GNU General Public License + version 3 along with this program. If not, see + http://www.gnu.org/licenses/ . + + */ + +#ifndef _NIF_DATA_H_ +#define _NIF_DATA_H_ + +#include "controlled.h" + +namespace Nif +{ + +struct NiSourceTexture : Named +{ + // Is this an external (references a separate texture file) or + // internal (data is inside the nif itself) texture? + bool external; + + SString filename; // In case of external textures + NiPixelDataPtr data; // In case of internal textures + + /* Pixel layout + 0 - Palettised + 1 - High color 16 + 2 - True color 32 + 3 - Compressed + 4 - Bumpmap + 5 - Default */ + int pixel; + + /* Mipmap format + 0 - no + 1 - yes + 2 - default */ + int mipmap; + + /* Alpha + 0 - none + 1 - binary + 2 - smooth + 3 - default (use material alpha, or multiply material with texture if present) + */ + int alpha; + + void read(NIFFile *nif) + { + Named::read(nif); + + external = nif->getByte(); + + if(external) filename = nif->getString(); + else + { + nif->getByte(); // always 1 + data.read(nif); + } + + pixel = nif->getInt(); + mipmap = nif->getInt(); + alpha = nif->getInt(); + + nif->getByte(); // always 1 + } +}; + +} // Namespace +#endif diff --git a/nif/nif_file.cpp b/nif/nif_file.cpp index 624abd7b62..477c2a1833 100644 --- a/nif/nif_file.cpp +++ b/nif/nif_file.cpp @@ -28,6 +28,8 @@ #include "extra.h" #include "controlled.h" #include "node.h" +#include "property.h" +#include "data.h" #include using namespace std; @@ -53,7 +55,7 @@ void NIFFile::parse() { SString rec = getString(); - cout << endl << i << ": " << rec.toString() << endl; + cout << i << ": " << rec.toString() << endl; Record *r; @@ -62,6 +64,8 @@ void NIFFile::parse() // node names. if(rec == "NiNode") r = new NiNode; else if(rec == "NiTriShape") r = new NiTriShape; + else if(rec == "NiTexturingProperty") r = new NiTexturingProperty; + else if(rec == "NiSourceTexture") r = new NiSourceTexture; else break; r->read(this); diff --git a/nif/nif_file.h b/nif/nif_file.h index 2d6dc594c0..229fae138b 100644 --- a/nif/nif_file.h +++ b/nif/nif_file.h @@ -108,10 +108,14 @@ class NIFFile ****************************************************/ + void skip(size_t size) { inp->getPtr(size); } + template const X* getPtr() { return (const X*)inp->getPtr(sizeof(X)); } template X getType() { return *getPtr(); } unsigned short getUshort() { return getType(); } int getInt() { return getType(); } + float getFloat() { return getType(); } + char getByte() { return getType(); } template SliceArray getArray() @@ -125,6 +129,7 @@ class NIFFile const Vector *getVector() { return getPtr(); } const Matrix *getMatrix() { return getPtr(); } const Transformation *getTrafo() { return getPtr(); } + const Vector4 *getVector4() { return getPtr(); } // For fixed-size strings where you already know the size const char *getString(int size) diff --git a/nif/property.h b/nif/property.h new file mode 100644 index 0000000000..d717dc600a --- /dev/null +++ b/nif/property.h @@ -0,0 +1,134 @@ +/* + OpenMW - The completely unofficial reimplementation of Morrowind + Copyright (C) 2008-2010 Nicolay Korslund + Email: < korslund@gmail.com > + WWW: http://openmw.sourceforge.net/ + + This file (property.h) is part of the OpenMW package. + + OpenMW is distributed as free software: you can redistribute it + and/or modify it under the terms of the GNU General Public License + version 3, as published by the Free Software Foundation. + + This program is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + General Public License for more details. + + You should have received a copy of the GNU General Public License + version 3 along with this program. If not, see + http://www.gnu.org/licenses/ . + + */ + +#ifndef _NIF_PROPERTY_H_ +#define _NIF_PROPERTY_H_ + +#include "controlled.h" + +namespace Nif +{ + +struct Property : Named +{ + // The meaning of these depends on the actual property type. + int flags; + + void read(NIFFile *nif) + { + Named::read(nif); + flags = nif->getUshort(); + } +}; + +struct NiTexturingProperty : Property +{ + // A sub-texture + struct Texture + { + /* Clamp mode + 0 - clampS clampT + 1 - clampS wrapT + 2 - wrapS clampT + 3 - wrapS wrapT + */ + + /* Filter: + 0 - nearest + 1 - bilinear + 2 - trilinear + 3, 4, 5 - who knows + */ + bool inUse; + NiSourceTexturePtr texture; + + int clamp, set, filter; + short unknown2; + + void read(NIFFile *nif) + { + inUse = nif->getInt(); + if(!inUse) return; + + texture.read(nif); + clamp = nif->getInt(); + filter = nif->getInt(); + set = nif->getInt(); + + // I have no idea, but I think these are actually two + // PS2-specific shorts (ps2L and ps2K), followed by an unknown + // short. + nif->skip(6); + } + }; + + /* Apply mode: + 0 - replace + 1 - decal + 2 - modulate + 3 - hilight // These two are for PS2 only? + 4 - hilight2 + */ + int apply; + + /* + * The textures in this list are as follows: + * + * 0 - Base texture + * 1 - Dark texture + * 2 - Detail texture + * 3 - Gloss texture (never used?) + * 4 - Glow texture + * 5 - Bump map texture + * 6 - Decal texture + */ + Texture textures[7]; + + void read(NIFFile *nif) + { + Property::read(nif); + apply = nif->getInt(); + + // Unknown, always 7. Probably the number of textures to read + // below + nif->getInt(); + + textures[0].read(nif); // Base + textures[1].read(nif); // Dark + textures[2].read(nif); // Detail + textures[3].read(nif); // Gloss (never present) + textures[4].read(nif); // Glow + textures[5].read(nif); // Bump map + if(textures[5].inUse) + { + // Ignore these at the moment + float lumaScale = nif->getFloat(); + float lumaOffset = nif->getFloat(); + const Vector4 *lumaMatrix = nif->getVector4(); + } + textures[6].read(nif); // Decal + } +}; + +} // Namespace +#endif diff --git a/nif/record_ptr.h b/nif/record_ptr.h index 1d7f2295ea..9f33ab36d9 100644 --- a/nif/record_ptr.h +++ b/nif/record_ptr.h @@ -127,14 +127,18 @@ class Node; class Extra; class Property; class Controller; +class NiPixelData; class NiTriShapeData; class NiSkinInstance; +class NiSourceTexture; typedef RecordPtrT NodePtr; typedef RecordPtrT ExtraPtr; typedef RecordPtrT ControllerPtr; +typedef RecordPtrT NiPixelDataPtr; typedef RecordPtrT NiTriShapeDataPtr; typedef RecordPtrT NiSkinInstancePtr; +typedef RecordPtrT NiSourceTexturePtr; typedef RecordListT NodeList; typedef RecordListT PropertyList;