From d26a124b6960dd40d99030df7ebe80f1c7528ffc Mon Sep 17 00:00:00 2001 From: Amorilia <amorilia@users.sourceforge.net> Date: Sun, 27 Nov 2005 06:51:20 +0000 Subject: [PATCH] More Python wrapper fixes and upgrades. --- NIF_Blocks.cpp | 11 +++++++ NIF_Blocks.h | 2 ++ NIF_IO.cpp | 10 ++++-- nif_attrs.h | 4 +++ nif_math.cpp | 16 +++++----- niflib.h | 86 ++++++++++++++++++++++++++++++++++++++++++++------ pyniflib.i | 1 + 7 files changed, 111 insertions(+), 19 deletions(-) diff --git a/NIF_Blocks.cpp b/NIF_Blocks.cpp index 192c02de..68140635 100644 --- a/NIF_Blocks.cpp +++ b/NIF_Blocks.cpp @@ -823,6 +823,17 @@ void AShapeData::SetUVSet( int index, const vector<UVCoord> & in ) { uv_sets[index] = in; } +void AShapeData::AppendVertex( Vector3 v, bool hasn, Vector3 n, bool hasvc, Color vc, bool hasuv, UVCoord uv ) { + vertices.push_back(v); + if (hasn) normals.push_back(n); + if (hasvc) colors.push_back(vc); + if (hasuv) uv_sets[0].push_back(uv); // one UV set assumed; TODO: support for multiple UV sets +} + +void NiTriShapeData::AppendTriangle( Triangle t ) { + triangles.push_back(t); +} + /*********************************************************** * AParticlesData methods **********************************************************/ diff --git a/NIF_Blocks.h b/NIF_Blocks.h index 3968c025..6efd3aeb 100644 --- a/NIF_Blocks.h +++ b/NIF_Blocks.h @@ -568,6 +568,7 @@ public: void SetNormals( const vector<Vector3> & in ); void SetColors( const vector<Color> & in ); void SetUVSet( int index, const vector<UVCoord> & in ); + void AppendVertex( Vector3 v, bool hasn, Vector3 n, bool hasvc, Color vc, bool hasuv, UVCoord uv ); protected: vector<Vector3> vertices; vector<Vector3> normals; @@ -665,6 +666,7 @@ public: vector<Triangle> GetTriangles() { return triangles; } //Setters void SetTriangles( const vector<Triangle> & in ); + void AppendTriangle( Triangle t ); private: vector<Triangle> triangles; diff --git a/NIF_IO.cpp b/NIF_IO.cpp index 56046600..ae0235c6 100644 --- a/NIF_IO.cpp +++ b/NIF_IO.cpp @@ -300,10 +300,16 @@ void WriteString( string val, ofstream& out ) { void WriteBool( bool val, ofstream& out, unsigned int version ) { if ( version < 0x04010001 ) { //Bools are stored as integers before version 4.1.0.1 - WriteUInt(int(val), out ); + if (val) + WriteUInt( 0xFFFFFFFF, out ); // NifTexture workaround + else + WriteUInt( 0, out ); } else { //And as bytes from 4.1.0.1 on - WriteByte(byte(val), out ); + if (val) + WriteByte( 1, out ); + else + WriteByte( 0, out ); } } diff --git a/nif_attrs.h b/nif_attrs.h index 2bc7aa18..1ddf192a 100644 --- a/nif_attrs.h +++ b/nif_attrs.h @@ -583,6 +583,10 @@ public: bool HasLinks() { return true; } + int asInt() const { + return links.size(); + } + list<blk_ref> asLinkList() const { list<blk_ref> out; diff --git a/nif_math.cpp b/nif_math.cpp index 41a5948a..3eb496f8 100644 --- a/nif_math.cpp +++ b/nif_math.cpp @@ -143,29 +143,29 @@ float DetMatrix33( Matrix33 & m ) { } float DetMatrix44( Matrix44 & m ) { - Matrix33 sub1 = { + Matrix33 sub1( m[1][1], m[1][2], m[1][3], m[2][1], m[2][2], m[2][3], m[3][1], m[3][2], m[3][3] - }; + ); - Matrix33 sub2 = { + Matrix33 sub2( m[1][0], m[1][2], m[1][3], m[2][0], m[2][2], m[2][3], m[3][0], m[3][2], m[3][3] - }; + ); - Matrix33 sub3 = { + Matrix33 sub3( m[1][0], m[1][1], m[1][3], m[2][0], m[2][1], m[2][3], m[3][0], m[3][1], m[3][3] - }; + ); - Matrix33 sub4 = { + Matrix33 sub4( m[1][0], m[1][1], m[1][2], m[2][0], m[2][1], m[2][2], m[3][0], m[3][1], m[3][2] - }; + ); return m[0][0] * DetMatrix33( sub1 ) - m[0][1] * DetMatrix33( sub2 ) diff --git a/niflib.h b/niflib.h index 0778ff45..3d79a4ba 100644 --- a/niflib.h +++ b/niflib.h @@ -147,6 +147,8 @@ ITriStripsData * QueryTriStripsData ( blk_ref & block ); struct UVCoord { float u, v; + UVCoord() : u(0.0), v(0.0) {} + UVCoord(float _u, float _v) : u(_u), v(_v) {} void Set(float u, float v) { this->u = u; this->v = v; @@ -164,11 +166,27 @@ struct Triangle { struct Vector3 { float x, y, z; + Vector3() : x(0.0), y(0.0), z(0.0) {} + Vector3(float _x, float _y, float _z) : x(_x), y(_y), z(_z) {} void Set(float x, float y, float z) { this->x = x; this->y = y; this->z = z; } + Vector3 __mul__(float a) { + Vector3 result(*this); + result.x *= a; + result.y *= a; + result.z *= a; + return result; + } + Vector3 __div__(float a) { + Vector3 result(*this); + result.x /= a; + result.y /= a; + result.z /= a; + return result; + } }; struct Float2 { @@ -227,10 +245,25 @@ struct Float3 { float operator[](int n) const { return data[n]; } + Float3() { + data[0] = 0.0; + data[1] = 0.0; + data[2] = 0.0; + } + Float3( float f1, float f2, float f3 ) { + data[0] = f1; + data[1] = f2; + data[2] = f3; + } + Float3( Float3 const & f3 ) { + data[0] = f3.data[0]; + data[1] = f3.data[1]; + data[2] = f3.data[2]; + } void Set( float f1, float f2, float f3 ) { data[0] = f1; data[1] = f2; - data[3] = f3; + data[2] = f3; } //Python Operator Overloads float __getitem__(int n) { @@ -244,10 +277,10 @@ struct Float3 { data[n] = value; } Float3 __mul__(float value) { - Float3 result; - result.data[0] = data[0] * value; - result.data[1] = data[1] * value; - result.data[2] = data[2] * value; + Float3 result(*this); + result.data[0] *= value; + result.data[1] *= value; + result.data[2] *= value; return result; } }; @@ -260,6 +293,20 @@ struct Matrix33 { const Float3 & operator[](int n) const { return rows[n]; } + Matrix33() { + rows[0][0] = 1.0; rows[0][1] = 0.0; rows[0][2] = 0.0; + rows[1][0] = 0.0; rows[1][1] = 1.0; rows[1][2] = 0.0; + rows[2][0] = 0.0; rows[2][1] = 0.0; rows[2][2] = 1.0; + } + Matrix33( + float m11, float m12, float m13, + float m21, float m22, float m23, + float m31, float m32, float m33 + ) { + rows[0][0] = m11; rows[0][1] = m12; rows[0][2] = m13; + rows[1][0] = m21; rows[1][1] = m22; rows[1][2] = m23; + rows[2][0] = m31; rows[2][1] = m32; rows[2][2] = m33; + } void Set( float m11, float m12, float m13, float m21, float m22, float m23, @@ -340,11 +387,30 @@ struct Matrix44 { struct Color { float r, g, b, a; - void Set(float r, float g, float b) { + Color() : r(1.0), g(1.0), b(1.0), a(1.0) {} + Color(float _r, float _g, float _b, float _a = 1.0) : r(_r), g(_g), b(_b), a(_a) {} + void Set(float r, float g, float b, float a = 1.0) { this->r = r; this->g = g; this->b = b; - } + this->a = a; + } + Color __mul__(float q) { + Color result(*this); + result.r *= q; + result.g *= q; + result.b *= q; + result.a *= q; + return result; + }; + Color __div__(float q) { + Color result(*this); + result.r /= q; + result.g /= q; + result.b /= q; + result.a /= q; + return result; + }; }; struct Quaternion { @@ -484,9 +550,9 @@ public: virtual void SetNormals( const vector<Vector3> & in ) = 0; virtual void SetColors( const vector<Color> & in ) = 0; virtual void SetUVSet( int index, const vector<UVCoord> & in ) = 0; + virtual void AppendVertex( Vector3 v, bool hasn, Vector3 n, bool hasvc, Color vc, bool hasuv, UVCoord uv ) = 0; }; - class ITriShapeData { public: ITriShapeData() {} @@ -501,6 +567,7 @@ public: virtual vector<Triangle> GetTriangles() = 0; //Setters virtual void SetTriangles( const vector<Triangle> & in ) = 0; + virtual void AppendTriangle( Triangle t ) = 0; }; class ITriStripsData { @@ -1044,6 +1111,7 @@ struct ConditionalInt { }; struct Texture { + Texture() : isUsed(0), clampMode(WRAP_S_WRAP_T), filterMode(FILTER_TRILERP), textureSet(0), PS2_L(0), PS2_K(0xFFB5), unknownShort(0x0101) {} bool isUsed; TexClampMode clampMode; TexFilterMode filterMode; @@ -1059,7 +1127,7 @@ struct Texture { //Bitmap block - only exists if this texture is in the bitmap slot float bmLumaOffset; float bmLumaScale; - Matrix22 bmMatrix; + Matrix22 bmMatrix; }; struct TextureSource { diff --git a/pyniflib.i b/pyniflib.i index 58314b75..731b1ba4 100644 --- a/pyniflib.i +++ b/pyniflib.i @@ -92,4 +92,5 @@ template <class T> struct Key; %ignore Matrix33::operator[](int n) const; %ignore Matrix44::operator[](int n); %ignore Matrix44::operator[](int n) const; +%ignore blk_ref::operator[](string index); %include "niflib.h" -- GitLab