From 36595961655010309c63c835f45f555bfea97240 Mon Sep 17 00:00:00 2001
From: Tazpn <tazpn@users.sourceforge.net>
Date: Sat, 24 Jun 2006 20:02:35 +0000
Subject: [PATCH] 1. Add an enable/disable skin flag. 2. Fix bug with matrix
 inversion missing. 3. Use Point3(0,0,0) instead of Point3()

---
 NifImport/DllEntry.cpp        |  1 +
 NifImport/MaxNifImport.cpp    | 21 ++++++++++++++-------
 NifImport/MaxNifImport.vcproj | 12 ++++++++++--
 NifImport/MaxNifTools.ini     |  2 ++
 4 files changed, 27 insertions(+), 9 deletions(-)

diff --git a/NifImport/DllEntry.cpp b/NifImport/DllEntry.cpp
index 97160e9..436e5af 100644
--- a/NifImport/DllEntry.cpp
+++ b/NifImport/DllEntry.cpp
@@ -10,6 +10,7 @@
 
  *>	Copyright (c) 2006, All Rights Reserved.
  **********************************************************************/
+#include "stdafx.h"
 #include "MaxNifImport.h"
 
 extern ClassDesc2* GetMaxNifImportDesc();
diff --git a/NifImport/MaxNifImport.cpp b/NifImport/MaxNifImport.cpp
index 9c7022f..5486090 100644
--- a/NifImport/MaxNifImport.cpp
+++ b/NifImport/MaxNifImport.cpp
@@ -93,6 +93,7 @@ public:
    bool enableAutoSmooth;
    float autoSmoothAngle;
    bool flipUVTextures;
+   bool enableSkinSupport;
 
    // Biped/Bones related settings
    string skeleton;
@@ -465,6 +466,7 @@ void NifImporter::LoadIniSettings()
    enableAutoSmooth = GetIniValue<bool>(NifImportSection, "EnableAutoSmooth", true);
    autoSmoothAngle = GetIniValue<float>(NifImportSection, "AutoSmoothAngle", 30.0f);
    flipUVTextures = GetIniValue<bool>(NifImportSection, "FlipUVTextures", true);
+   enableSkinSupport = GetIniValue<bool>(NifImportSection, "EnableSkinSupport", true);
 
    skeleton = (appSettings != NULL) ? appSettings->Skeleton : "";
 
@@ -611,7 +613,7 @@ void NifImporter::AlignBiped(IBipMaster* master, NiNodeRef block)
       Matrix3 m3 = node->GetNodeTM(TimeValue(), NULL); // local translation m
       master->SetBipedPos(Point3(pos.x, pos.y, pos.z), 0, node, TRUE);
 
-      Matrix3 m(rot.rows[0].data, rot.rows[1].data, rot.rows[2].data, Point3());
+      Matrix3 m(rot.rows[0].data, rot.rows[1].data, rot.rows[2].data, Point3(0,0,0));
       Matrix3 im = Inverse(m);
 
       Point3 p; Quat q; Point3 s;
@@ -644,7 +646,7 @@ void NifImporter::PositionBiped(IBipMaster* master, NiNodeRef block, bool Recurs
       Matrix3 m3 = node->GetNodeTM(TimeValue(), NULL); // local translation m
       master->SetBipedPos(Point3(pos.x, pos.y, pos.z), 0, node, TRUE);
 
-      Matrix3 m(rot.rows[0].data, rot.rows[1].data, rot.rows[2].data, Point3());
+      Matrix3 m(rot.rows[0].data, rot.rows[1].data, rot.rows[2].data, Point3(0,0,0));
       Matrix3 im = Inverse(m);
       Point3 p; Quat q; Point3 s;
       DecomposeMatrix(im, p, q, s);
@@ -679,7 +681,7 @@ void NifImporter::RotateBiped(IBipMaster* master, NiNodeRef block, bool Recurse)
       Matrix3 m3 = node->GetNodeTM(TimeValue(), NULL); // local translation m
       master->SetBipedPos(Point3(pos.x, pos.y, pos.z), 0, node, TRUE);
 
-      Matrix3 m(rot.rows[0].data, rot.rows[1].data, rot.rows[2].data, Point3());
+      Matrix3 m(rot.rows[0].data, rot.rows[1].data, rot.rows[2].data, Point3(0,0,0));
       Matrix3 im = Inverse(m);
 
       Point3 p; Quat q; Point3 s;
@@ -715,7 +717,7 @@ void NifImporter::ScaleBiped(IBipMaster* master, NiNodeRef block, bool Recurse)
       Matrix3 m3 = node->GetNodeTM(TimeValue(), NULL); // local translation m
       master->SetBipedPos(Point3(pos.x, pos.y, pos.z), 0, node, TRUE);
 
-      Matrix3 m(rot.rows[0].data, rot.rows[1].data, rot.rows[2].data, Point3());
+      Matrix3 m(rot.rows[0].data, rot.rows[1].data, rot.rows[2].data, Point3(0,0,0));
       Matrix3 im = Inverse(m);
 
       Point3 p; Quat q; Point3 s;
@@ -956,7 +958,8 @@ bool NifImporter::ImportTransform(ImpNode *node, NiAVObjectRef avObject)
    wt.Decompose(pos, rot, scale);
    Point3 p(pos.x, pos.y, pos.z);
 
-   Matrix3 m(rot.rows[0].data, rot.rows[1].data, rot.rows[2].data, Point3());
+   Matrix3 m(rot.rows[0].data, rot.rows[1].data, rot.rows[2].data, Point3(0,0,0));
+   m.Invert();
    m.SetTrans(p);
    node->SetTransform(0,m);   
    return true;
@@ -1067,7 +1070,9 @@ bool NifImporter::ImportMesh(NiTriShapeRef triShape)
       vector<Triangle> v = triShapeData->GetTriangles();
       SetTrangles(mesh, v, hasTexture);
    }
-   ImportSkin(node, triShape);
+   if (enableSkinSupport)
+      ImportSkin(node, triShape);
+
    i->AddNodeToScene(node);   
 
    if (enableAutoSmooth){
@@ -1107,7 +1112,9 @@ bool NifImporter::ImportMesh(NiTriStripsRef triStrips)
       vector<Triangle> v = triStripsData->GetTriangles();
       SetTrangles(mesh, v, hasTexture);
    }
-   ImportSkin(node, triStrips);
+   if (enableSkinSupport)
+      ImportSkin(node, triStrips);
+
    i->AddNodeToScene(node);   
 
    // apply autosmooth after object creation for it to take hold
diff --git a/NifImport/MaxNifImport.vcproj b/NifImport/MaxNifImport.vcproj
index 02ae21c..c118c76 100644
--- a/NifImport/MaxNifImport.vcproj
+++ b/NifImport/MaxNifImport.vcproj
@@ -54,7 +54,7 @@
 				RuntimeLibrary="0"
 				EnableFunctionLevelLinking="true"
 				ForceConformanceInForLoopScope="false"
-				UsePrecompiledHeader="0"
+				UsePrecompiledHeader="2"
 				PrecompiledHeaderFile=".\Release\MaxNifImport.pch"
 				AssemblerListingLocation=".\Release\"
 				ObjectFile=".\Release\"
@@ -154,7 +154,7 @@
 				ExceptionHandling="2"
 				RuntimeLibrary="1"
 				ForceConformanceInForLoopScope="false"
-				UsePrecompiledHeader="0"
+				UsePrecompiledHeader="2"
 				PrecompiledHeaderFile=".\Debug\MaxNifImport.pch"
 				AssemblerListingLocation=".\Debug\"
 				ObjectFile=".\Debug\"
@@ -236,6 +236,14 @@
 			<File
 				RelativePath=".\stdafx.cpp"
 				>
+				<FileConfiguration
+					Name="Release|Win32"
+					>
+					<Tool
+						Name="VCCLCompilerTool"
+						UsePrecompiledHeader="1"
+					/>
+				</FileConfiguration>
 				<FileConfiguration
 					Name="Debug|Win32"
 					>
diff --git a/NifImport/MaxNifTools.ini b/NifImport/MaxNifTools.ini
index 71bd9d8..f452380 100644
--- a/NifImport/MaxNifTools.ini
+++ b/NifImport/MaxNifTools.ini
@@ -30,6 +30,8 @@ AutoSmoothAngle=30.0
 ; Remove Double/Illegal faces on meshes on import
 RemoveDoubleFaces=1
 RemoveIllegalFaces=1
+; EnableSkinSupport attempt to skin the mesh if bones are available
+EnableSkinSupport=1
 
 [BipedImport]
 ; Biped Height. Default: 131.90
-- 
GitLab