From e8ef07c10541d33bfa22a7ac3a703cf972b7cf1c Mon Sep 17 00:00:00 2001
From: Tazpn <tazpn@users.sourceforge.net>
Date: Tue, 22 Aug 2006 03:36:42 +0000
Subject: [PATCH] 1. Change strippifcation to use the niflib version on
 objects. 2. commit fix for bug with transforms.

---
 MaxNifPlugins_Readme.txt     |   1 +
 NifCommon/niutils.h          |  12 ++++
 NifExport/Coll.cpp           |   7 +++
 NifExport/Mesh.cpp           | 111 ++++++-----------------------------
 NifExport/NifExport.rc       |  20 +++----
 NifFurniture/NifFurniture.rc |   8 +--
 NifImport/MaxNifImport.rc    |   8 +--
 NifProps/NifProps.rc         |   8 +--
 8 files changed, 60 insertions(+), 115 deletions(-)

diff --git a/MaxNifPlugins_Readme.txt b/MaxNifPlugins_Readme.txt
index 9573bf8..10c7a6b 100644
--- a/MaxNifPlugins_Readme.txt
+++ b/MaxNifPlugins_Readme.txt
@@ -32,6 +32,7 @@
     o Exporter
       - Replace the Tri Stripper with a new version.
         o The old version had some bugs which came when compiled with VS 2005.
+      - Fix issues with transforms on exporting with extra nodes and for collision meshes
         
       0.2
       -----
diff --git a/NifCommon/niutils.h b/NifCommon/niutils.h
index c4bc272..7d0d913 100644
--- a/NifCommon/niutils.h
+++ b/NifCommon/niutils.h
@@ -294,6 +294,18 @@ static inline Quat TOQUAT(const Niflib::QuaternionXYZW& q, bool inverse = false)
    return (inverse) ? qt.Inverse() : qt;
 }
 
+static inline Niflib::QuaternionXYZW TOQUATXYZW(const Niflib::Quaternion& q){
+   Niflib::QuaternionXYZW qt;
+   qt.x = q.x; qt.y = q.y; qt.z = q.z; qt.w = q.w;
+   return qt;
+}
+
+static inline Niflib::QuaternionXYZW TOQUATXYZW(const Quat& q){
+   Niflib::QuaternionXYZW qt;
+   qt.x = q.x; qt.y = q.y; qt.z = q.z; qt.w = q.w;
+   return qt;
+}
+
 static inline AngAxis TOANGAXIS(const Niflib::Quaternion& q, bool inverse = false){
    Quat qt(q.x, q.y, q.z, q.w);
    if (inverse) qt.Invert();
diff --git a/NifExport/Coll.cpp b/NifExport/Coll.cpp
index 5c8f30f..d52d332 100755
--- a/NifExport/Coll.cpp
+++ b/NifExport/Coll.cpp
@@ -284,6 +284,13 @@ Exporter::Result Exporter::exportCollision(NiNodeRef &parent, INode *node)
 		bhkRigidBodyRef body = makeCollisionBody(node);
 		body->SetShape(DynamicCast<bhkShape>(shape));
 
+      QuaternionXYZW q;
+      Vector3 trans;
+      TimeValue t = 0;
+      nodeTransform(q, trans, node, t, false);
+      body->SetRotation(q);
+      body->SetTranslation(trans / 7.0f);
+
 		bhkCollisionObjectRef co = DynamicCast<bhkCollisionObject>(CreateBlock("bhkCollisionObject"));
 		co->SetBody(DynamicCast<NiObject>(body));
       
diff --git a/NifExport/Mesh.cpp b/NifExport/Mesh.cpp
index 37a21b1..dba3ae8 100755
--- a/NifExport/Mesh.cpp
+++ b/NifExport/Mesh.cpp
@@ -81,13 +81,11 @@ Exporter::Result Exporter::exportMeshes(NiNodeRef &parent, INode *node)
             || os.obj->ClassID() == Class_ID(BONE_CLASS_ID,0)
             || os.obj->ClassID() == Class_ID(0x00009125,0) /* Biped Twist Helpers */
             )
-         )
-         newParent = makeNode(nodeParent, node, local);
-#ifdef USE_BIPED
-      else if (os.obj && os.obj->node->ClassID() == BIPED_CLASS_ID)
+            ) 
+      {
          newParent = makeNode(nodeParent, node, local);
-#endif
-      else
+      } 
+      else 
       {
          newParent = (mExportExtraNodes) ? makeNode(nodeParent, node, local) : nodeParent;
 
@@ -180,14 +178,12 @@ Exporter::Result Exporter::exportMesh(NiNodeRef &ninode, INode *node, TimeValue
 		}
       bool exportStrips = mTriStrips;
 
-      // Disable strips if exporting skin nodes, for now
-      //if (exportStrips && mExportSkin && GetSkin(node) != NULL)
-      //   exportStrips = false;
-
-
-      Matrix33 rot; Vector3 trans;
-      nodeTransform(rot, trans, node, t, local);
-      Matrix44 tm(trans, rot, 1.0f);
+      Matrix44 tm = Matrix44::IDENTITY;
+      if (!mExportExtraNodes) {
+         Matrix33 rot; Vector3 trans;
+         nodeTransform(rot, trans, node, t, local);
+         tm = Matrix44(trans, rot, 1.0f);
+      }
 
       TSTR basename = node->NodeName();
       TSTR format = (!basename.isNull() && grps.size() > 1) ? "%s:%d" : "%s";
@@ -223,23 +219,15 @@ NiTriBasedGeomRef Exporter::makeMesh(NiNodeRef &parent, Mtl *mtl, FaceGroup &grp
 	NiTriBasedGeomRef shape;
 	NiTriBasedGeomDataRef data;
 
-	if (exportStrips)
-	{
-		NiTriStripsRef stripsShape = CreateNiObject<NiTriStrips>();
-		shape = DynamicCast<NiTriBasedGeom>(stripsShape);
-		strippify(grp);
-		NiTriStripsDataRef stripData = makeTriStripsData(grp.strips);
-		data = DynamicCast<NiTriBasedGeomData>(stripData);
-
-	} else
-	{
-		NiTriShapeRef tris = CreateNiObject<NiTriShape>();
-		NiTriShapeDataRef triData = CreateNiObject<NiTriShapeData>();
-		data = DynamicCast<NiTriBasedGeomData>(triData);
-		shape = DynamicCast<NiTriBasedGeom>(tris);
-		triData->SetTriangles(grp.faces);
+	if (exportStrips) {
+      shape = new NiTriStrips();
+      data = new NiTriStripsData();
+	} else {
+      shape = new NiTriShape();
+      data = new NiTriShapeData();
 	}
 
+   data->SetTriangles(grp.faces);
 	data->SetVertices(grp.verts);
 	data->SetNormals(grp.vnorms);
 
@@ -370,12 +358,6 @@ struct SkinInstance : public Exporter::NiCallback
 {  
    typedef vector<SkinWeight> SkinWeightList;
    typedef vector<SkinWeightList> BoneWeightList;
-   typedef vector<float> WeightList;
-   typedef vector<ushort> BoneList;
-   typedef vector<ushort> Strip;
-   typedef vector<Strip> Strips;
-   typedef vector<Triangle> Triangles;
-
 
    Exporter *owner;
    // Common Data
@@ -385,15 +367,6 @@ struct SkinInstance : public Exporter::NiCallback
    // Bone to weight map
    BoneWeightList boneWeights;
 
-   // Partition
-   int nWeightsPerVertex;
-   vector<WeightList> vertexWeights;
-   BoneList boneMap;
-   vector<ushort> vertexMap;
-   Strips strips;
-   vector<BoneList> boneIndexList;
-   Triangles triangles;
-
    SkinInstance(Exporter *Owner) : owner(Owner) {}
    virtual ~SkinInstance() {}
    virtual Exporter::Result execute();
@@ -429,44 +402,21 @@ bool Exporter::makeSkin(NiTriBasedGeomRef shape, INode *node, FaceGroup &grp, Ti
    mPostExportCallbacks.push_back(si);
 
    si->shape = shape;
-   for (TriStrips::iterator strip = grp.strips.begin(); strip != grp.strips.end(); ++strip)
-      si->strips.push_back(*strip);
-
-   // Get number of weights per vertex
-   int nWeightsPerVertex = 4;
-   Interval ivalid;
-   IParamBlock2 *params = mod->GetParamBlockByID(2/*advanced*/);
-   params->GetValue(0x7/*bone_Limit*/, 0, nWeightsPerVertex, ivalid);
-   si->nWeightsPerVertex = nWeightsPerVertex;
 
    // Get bone references (may not actually exist in proper structure at this time)
    int totalBones = skin->GetNumBones();
    si->boneWeights.resize(totalBones);
    si->boneList.resize(totalBones);
-   si->boneMap.resize(totalBones);
    for (int i=0; i<totalBones; ++i) {
       string name = skin->GetBone(i)->GetName();
       si->boneList[i] = getNode(name);
-      si->boneMap[i] = i;
    }
 
    vector<int>& vidx = grp.vidx;
-   vector<Vector3>& verts = grp.verts;
    int nv = vidx.size();
-   si->vertexMap.resize(nv);
-   si->vertexWeights.resize(nv);
-   si->boneIndexList.resize(nv);
-
    for (int i=0; i<nv; ++i)
    {
-      SkinInstance::WeightList& vertexWeights = si->vertexWeights[i];
-      SkinInstance::BoneList& boneIndexList = si->boneIndexList[i];
-      vertexWeights.assign(nWeightsPerVertex, 0.0f);
-      boneIndexList.resize(nWeightsPerVertex, 0);
-      si->vertexMap[i] = i;
-
       int vi = vidx[i];
-      Vector3& vert = verts[i];
       int nbones = skinData->GetNumAssignedBones(vi);
       for (int j=0; j<nbones; ++j)
       {
@@ -477,9 +427,6 @@ bool Exporter::makeSkin(NiTriBasedGeomRef shape, INode *node, FaceGroup &grp, Ti
 
          SkinInstance::SkinWeightList& weights = si->boneWeights[boneIndex];
          weights.push_back(sw);
-
-         boneIndexList[j] = boneIndex;
-         vertexWeights[j] = sw.weight;
       }         
    }
    return true;
@@ -499,29 +446,7 @@ Exporter::Result SkinInstance::execute()
       else
          shape->SetBoneWeights(bone, emptyweights);
    }
-
-   NiSkinInstanceRef skin = shape->GetSkinInstance();
-   NiSkinPartitionRef partition = CreateNiObject<NiSkinPartition>();
-   partition->SetNumPartitions(1);
-   partition->SetWeightsPerVertex(0, nWeightsPerVertex);
-   partition->SetBoneMap(0, boneMap);
-   partition->SetNumVertices(0, ushort(vertexMap.size()) );
-   partition->SetVertexMap(0, vertexMap);
-   partition->EnableVertexWeights(0, true);
-   for (int i=0; i<vertexWeights.size(); ++i) {
-      partition->SetVertexWeights(0, i, vertexWeights[i]);
-   }
-   //partition->SetTriangles()
-   partition->SetStripCount(0, ushort(strips.size()) );
-   for (int i=0; i<strips.size(); ++i) {
-      partition->SetStrip(0, i, strips[i]);
-   }
-   partition->EnableVertexBoneIndices(0, true);
-   for (int i=0; i<boneIndexList.size(); ++i) {
-      partition->SetVertexBoneIndices(0, i, boneIndexList[i]);
-   }
-
-   skin->SetSkinPartition(partition);
+   shape->GenHardwareSkinInfo();
 
    return Exporter::Ok;
 }
diff --git a/NifExport/NifExport.rc b/NifExport/NifExport.rc
index ddfcbb2..aa2504b 100755
--- a/NifExport/NifExport.rc
+++ b/NifExport/NifExport.rc
@@ -89,12 +89,12 @@ BEGIN
     CONTROL         "&Lights",IDC_CHK_LIGHTS,"Button",BS_AUTOCHECKBOX | NOT WS_VISIBLE | WS_DISABLED | WS_TABSTOP,14,89,67,10
     GROUPBOX        "Behaviors:",IDC_STATIC,94,6,101,97
     CONTROL         "Generate &Strips",IDC_CHK_STRIPS,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,102,17,88,10
-    CONTROL         "&Remap Indices",IDC_CHK_REMAP,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,102,29,88,10
-    CONTROL         "Extra Nodes on Mesh",IDC_CHK_EXTRA,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,102,41,88,11
-    CONTROL         "Add User Prop Buffer",IDC_CHK_UPB,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,102,53,88,11
-    CONTROL         "Flatten Hierarchy",IDC_CHK_HIER,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,102,65,88,10
-    CONTROL         "Remove Extra Bones",IDC_CHK_REM_BONES,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,102,77,88,10
-    CONTROL         "Sort Nodes",IDC_CHK_SORTNODES,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,102,89,88,10
+    CONTROL         "&Remap Indices",IDC_CHK_REMAP,"Button",BS_AUTOCHECKBOX | NOT WS_VISIBLE | WS_DISABLED | WS_TABSTOP,102,89,88,10
+    CONTROL         "Extra Nodes on Mesh",IDC_CHK_EXTRA,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,102,28,88,11
+    CONTROL         "Add User Prop Buffer",IDC_CHK_UPB,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,102,40,88,11
+    CONTROL         "Flatten Hierarchy",IDC_CHK_HIER,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,102,52,88,10
+    CONTROL         "Remove Extra Bones",IDC_CHK_REM_BONES,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,102,64,88,10
+    CONTROL         "Sort Nodes",IDC_CHK_SORTNODES,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,102,76,88,10
     CONTROL         "",IDC_SPIN,"SpinnerControl",NOT WS_VISIBLE,193,7,7,10
     CONTROL         "",IDC_EDIT,"CustEdit",NOT WS_VISIBLE | WS_TABSTOP,194,18,6,10
     EDITTEXT        IDC_ED_WELDTHRESH,189,30,11,12,ES_AUTOHSCROLL | NOT WS_VISIBLE | WS_DISABLED
@@ -138,8 +138,8 @@ END
 //
 
 VS_VERSION_INFO VERSIONINFO
- FILEVERSION 0,2,1,0
- PRODUCTVERSION 0,2,1,0
+ FILEVERSION 0,2,2,0
+ PRODUCTVERSION 0,2,2,0
  FILEFLAGSMASK 0x17L
 #ifdef _DEBUG
  FILEFLAGS 0x1L
@@ -155,12 +155,12 @@ BEGIN
         BLOCK "040904b0"
         BEGIN
             VALUE "FileDescription", "3ds Max Nif Exporter"
-            VALUE "FileVersion", "0, 2, 1, 0"
+            VALUE "FileVersion", "0, 2, 2, 0"
             VALUE "InternalName", "NifExport.dle"
             VALUE "LegalCopyright", "Copyright (c) 2006, NIF File Format Library and Tools\r\nAll rights reserved."
             VALUE "OriginalFilename", "NifExport.dle"
             VALUE "ProductName", "3ds Max Nif Exporter"
-            VALUE "ProductVersion", "0, 2, 1, 0"
+            VALUE "ProductVersion", "0, 2, 2, 0"
         END
     END
     BLOCK "VarFileInfo"
diff --git a/NifFurniture/NifFurniture.rc b/NifFurniture/NifFurniture.rc
index ef6495d..84a94f0 100755
--- a/NifFurniture/NifFurniture.rc
+++ b/NifFurniture/NifFurniture.rc
@@ -107,8 +107,8 @@ END
 //
 
 VS_VERSION_INFO VERSIONINFO
- FILEVERSION 0,2,1,0
- PRODUCTVERSION 0,2,1,0
+ FILEVERSION 0,2,2,0
+ PRODUCTVERSION 0,2,2,0
  FILEFLAGSMASK 0x17L
 #ifdef _DEBUG
  FILEFLAGS 0x1L
@@ -124,12 +124,12 @@ BEGIN
         BLOCK "040904b0"
         BEGIN
             VALUE "FileDescription", "3ds Max Nif Furniture Plugin"
-            VALUE "FileVersion", "0, 2, 1, 0"
+            VALUE "FileVersion", "0, 2, 2, 0"
             VALUE "InternalName", "NifFurniture.dlu"
             VALUE "LegalCopyright", "Copyright (c) 2006, NIF File Format Library and Tools\r\nAll rights reserved."
             VALUE "OriginalFilename", "NifFurniture.dlu"
             VALUE "ProductName", "3ds Max Nif Furniture Plugin"
-            VALUE "ProductVersion", "0, 2, 1, 0"
+            VALUE "ProductVersion", "0, 2, 2, 0"
         END
     END
     BLOCK "VarFileInfo"
diff --git a/NifImport/MaxNifImport.rc b/NifImport/MaxNifImport.rc
index bbbac52..cdfac9b 100644
--- a/NifImport/MaxNifImport.rc
+++ b/NifImport/MaxNifImport.rc
@@ -108,8 +108,8 @@ END
 //
 
 VS_VERSION_INFO VERSIONINFO
- FILEVERSION 0,2,1,0
- PRODUCTVERSION 0,2,1,0
+ FILEVERSION 0,2,2,0
+ PRODUCTVERSION 0,2,2,0
  FILEFLAGSMASK 0x17L
 #ifdef _DEBUG
  FILEFLAGS 0x1L
@@ -125,12 +125,12 @@ BEGIN
         BLOCK "040904b0"
         BEGIN
             VALUE "FileDescription", "3ds Max Nif Importer"
-            VALUE "FileVersion", "0, 2, 1, 0"
+            VALUE "FileVersion", "0, 2, 2, 0"
             VALUE "InternalName", "MaxNifImport.dli"
             VALUE "LegalCopyright", "Copyright (c) 2006, NIF File Format Library and Tools\r\nAll rights reserved."
             VALUE "OriginalFilename", "MaxNifImport.dli"
             VALUE "ProductName", "3ds Max Nif Importer"
-            VALUE "ProductVersion", "0, 2, 1, 0"
+            VALUE "ProductVersion", "0, 2, 2, 0"
         END
     END
     BLOCK "VarFileInfo"
diff --git a/NifProps/NifProps.rc b/NifProps/NifProps.rc
index 38a094a..a31d730 100755
--- a/NifProps/NifProps.rc
+++ b/NifProps/NifProps.rc
@@ -342,8 +342,8 @@ END
 //
 
 VS_VERSION_INFO VERSIONINFO
- FILEVERSION 0,2,1,0
- PRODUCTVERSION 0,2,1,0
+ FILEVERSION 0,2,2,0
+ PRODUCTVERSION 0,2,2,0
  FILEFLAGSMASK 0x17L
 #ifdef _DEBUG
  FILEFLAGS 0x1L
@@ -359,12 +359,12 @@ BEGIN
         BLOCK "040904b0"
         BEGIN
             VALUE "FileDescription", "3ds Max Nif Reactor Properites Plugin"
-            VALUE "FileVersion", "0, 2, 1, 0"
+            VALUE "FileVersion", "0, 2, 2, 0"
             VALUE "InternalName", "NifProps.dlu"
             VALUE "LegalCopyright", "Copyright (c) 2006, NIF File Format Library and Tools\r\nAll rights reserved."
             VALUE "OriginalFilename", "NifProps.dlu"
             VALUE "ProductName", "3ds Max Nif Reactor Properites Plugin"
-            VALUE "ProductVersion", "0, 2, 1, 0"
+            VALUE "ProductVersion", "0, 2, 2, 0"
         END
     END
     BLOCK "VarFileInfo"
-- 
GitLab