Skip to content
Snippets Groups Projects
Commit 30108872 authored by Tazpn's avatar Tazpn
Browse files

Fix major issue with skin transforms. Add ability to not import bones.

parent 2fe85421
No related branches found
No related tags found
No related merge requests found
...@@ -105,7 +105,8 @@ bool NifImporter::ImportMesh(ImpNode *node, TriObject *o, NiTriBasedGeomRef triG ...@@ -105,7 +105,8 @@ bool NifImporter::ImportMesh(ImpNode *node, TriObject *o, NiTriBasedGeomRef triG
{ {
Mesh& mesh = o->GetMesh(); Mesh& mesh = o->GetMesh();
node->SetTransform(0,TOMATRIX3(triGeom->GetLocalTransform())); Matrix44 baseTM = (importBones) ? triGeom->GetLocalTransform() : triGeom->GetWorldTransform();
node->SetTransform(0,TOMATRIX3(baseTM));
// Vertex info // Vertex info
{ {
...@@ -311,39 +312,32 @@ bool NifImporter::ImportSkin(ImpNode *node, NiTriBasedGeomRef triGeom) ...@@ -311,39 +312,32 @@ bool NifImporter::ImportSkin(ImpNode *node, NiTriBasedGeomRef triGeom)
if (ISkin *skin = (ISkin *) skinMod->GetInterface(I_SKIN)){ if (ISkin *skin = (ISkin *) skinMod->GetInterface(I_SKIN)){
ISkinImportData* iskinImport = (ISkinImportData*) skinMod->GetInterface(I_SKINIMPORTDATA); ISkinImportData* iskinImport = (ISkinImportData*) skinMod->GetInterface(I_SKINIMPORTDATA);
Matrix3 m3; Matrix3 m3(TRUE);
if (applyOverallTransformToSkinAndBones) { if (applyOverallTransformToSkinAndBones) {
Matrix3 initNodeTM, initObjTM;
initNodeTM.IdentityMatrix(), initObjTM.IdentityMatrix();
skin->GetSkinInitTM(tnode, initNodeTM, false);
skin->GetSkinInitTM(tnode, initObjTM, true);
m3 = TOMATRIX3(data->GetOverallTransform()); m3 = TOMATRIX3(data->GetOverallTransform());
iskinImport->SetSkinTm(tnode, initNodeTM * m3, initObjTM * m3); Matrix3 im3 = Inverse(m3);
iskinImport->SetSkinTm(tnode, im3, im3); // ???
} }
// Create Bone List // Create Bone List
Tab<INode*> bones; Tab<INode*> bones;
int i=0; for (size_t i=0; i<nifBones.size(); ++i){
for (vector<NiNodeRef>::iterator itr = nifBones.begin(), end = nifBones.end(); itr != end; ++itr, ++i){ NiNodeRef bone = nifBones[i];
string name = (*itr)->GetName(); Matrix3 b3 = TOMATRIX3(data->GetBoneTransform(i));
Matrix3 ib3 = Inverse(b3);
string name = bone->GetName();
if (INode *boneRef = gi->GetINodeByName(name.c_str())) { if (INode *boneRef = gi->GetINodeByName(name.c_str())) {
bones.Append(1, &boneRef); bones.Append(1, &boneRef);
iskinImport->AddBoneEx(boneRef, TRUE); iskinImport->AddBoneEx(boneRef, TRUE);
// Set Bone Transform // Set Bone Transform
if (applyOverallTransformToSkinAndBones) { if (applyOverallTransformToSkinAndBones) {
Matrix3 initNodeTM, initBoneTM; iskinImport->SetBoneTm(boneRef, ib3, ib3);
initNodeTM.IdentityMatrix(), initBoneTM.IdentityMatrix();
skin->GetBoneInitTM(boneRef, initNodeTM, false);
skin->GetBoneInitTM(boneRef, initBoneTM, true);
iskinImport->SetBoneTm(boneRef, initNodeTM * m3, initBoneTM * m3);
} }
} }
} }
ObjectState os = tnode->EvalWorldState(0); ObjectState os = tnode->EvalWorldState(0);
// Need to trigger ModifyObject in BonesDefMod prior to adding vertices or nothing is added
GetCOREInterface()->ForceCompleteRedraw();
// Need to get a list of bones and weights for each vertex. // Need to get a list of bones and weights for each vertex.
vector<VertexHolder> vertexHolders; vector<VertexHolder> vertexHolders;
vertexHolders.resize(m.numVerts); vertexHolders.resize(m.numVerts);
...@@ -372,6 +366,11 @@ bool NifImporter::ImportSkin(ImpNode *node, NiTriBasedGeomRef triGeom) ...@@ -372,6 +366,11 @@ bool NifImporter::ImportSkin(ImpNode *node, NiTriBasedGeomRef triGeom)
add = add; add = add;
} }
} }
// This is a kludge to get skin transforms to update and avoid jumping around after modifying the transforms.
// Initially they show up incorrectly but magically fix up if you go to the modifier roll up.
// There is still an outstanding issue with skeleton and GetObjectTMBeforeWSM.
skinMod->DisableModInViews();
skinMod->EnableModInViews();
} }
return ok; return ok;
} }
...@@ -33,6 +33,8 @@ RemoveIllegalFaces=1 ...@@ -33,6 +33,8 @@ RemoveIllegalFaces=1
EnableSkinSupport=1 EnableSkinSupport=1
[BipedImport] [BipedImport]
; Top level bone import setting. Default:1
ImportBones=1
; Biped Height. Default: 131.90 ; Biped Height. Default: 131.90
BipedHeight=131.90 BipedHeight=131.90
; Biped initial rotation. Default: 90.0 ; Biped initial rotation. Default: 90.0
...@@ -71,7 +73,7 @@ RequireMultipleKeys=1 ...@@ -71,7 +73,7 @@ RequireMultipleKeys=1
; Replace TCB Rotation with Bezier (workaround for unexpected behavior with TCB rotations) ; Replace TCB Rotation with Bezier (workaround for unexpected behavior with TCB rotations)
ReplaceTCBRotationWithBezier=1 ReplaceTCBRotationWithBezier=1
; Apply the overall transform to skin and bones. Default: 0 ; Apply the overall transform to skin and bones. Default: 0
ApplyOverallTransformToSkinAndBones=0 ApplyOverallTransformToSkinAndBones=1
; [Applications] ; [Applications]
; RootPaths - Semicolon separated list of base directories to use when determining which app the imported file is from ; RootPaths - Semicolon separated list of base directories to use when determining which app the imported file is from
...@@ -99,7 +101,6 @@ TextureRootPaths=${RootPath};${TextureRootPath} ...@@ -99,7 +101,6 @@ TextureRootPaths=${RootPath};${TextureRootPath}
TextureExtensions=.dds; TextureExtensions=.dds;
TextureSearchPaths=${RootPath}\Textures;${TextureRootPath}\Textures\Characters;${TextureRootPath}\Textures\Armor TextureSearchPaths=${RootPath}\Textures;${TextureRootPath}\Textures\Characters;${TextureRootPath}\Textures\Armor
GoToSkeletonBindPosition=1 GoToSkeletonBindPosition=1
ApplyOverallTransformToSkinAndBones=0
[Morrowind] [Morrowind]
InstallPath=[HKLM\SOFTWARE\Bethesda Softworks\Morrowind]=@"Installed Path" InstallPath=[HKLM\SOFTWARE\Bethesda Softworks\Morrowind]=@"Installed Path"
...@@ -110,7 +111,6 @@ TextureRootPaths=${RootPath}\Textures;${ExtractFolder}\Textures ...@@ -110,7 +111,6 @@ TextureRootPaths=${RootPath}\Textures;${ExtractFolder}\Textures
TextureExtensions=.tga; TextureExtensions=.tga;
TextureSearchPaths=${RootPath}\Textures TextureSearchPaths=${RootPath}\Textures
GoToSkeletonBindPosition=1 GoToSkeletonBindPosition=1
ApplyOverallTransformToSkinAndBones=1
[Civ4] [Civ4]
InstallPath=[HKEY_LOCAL_MACHINE\SOFTWARE\Firaxis Games\Sid Meier's Civilization 4]=@"INSTALLDIR" InstallPath=[HKEY_LOCAL_MACHINE\SOFTWARE\Firaxis Games\Sid Meier's Civilization 4]=@"INSTALLDIR"
...@@ -122,7 +122,6 @@ TextureExtensions=.dds;.bmp ...@@ -122,7 +122,6 @@ TextureExtensions=.dds;.bmp
TextureSearchPaths= TextureSearchPaths=
GoToSkeletonBindPosition=1 GoToSkeletonBindPosition=1
DummyNodeMatches=MD;Bip;Bip??;* NonAccum;Effect*;Sound*;Dummy* DummyNodeMatches=MD;Bip;Bip??;* NonAccum;Effect*;Sound*;Dummy*
ApplyOverallTransformToSkinAndBones=0
[DAoC] [DAoC]
Isles_InstallPath=[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\Dark Age of Camelot - Shrouded Isles_is1]=@"InstallLocation" Isles_InstallPath=[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\Dark Age of Camelot - Shrouded Isles_is1]=@"InstallLocation"
...@@ -133,4 +132,4 @@ TextureRootPaths=$(ExtractFolder) ...@@ -133,4 +132,4 @@ TextureRootPaths=$(ExtractFolder)
TextureExtensions=.dds;.bmp;.tga TextureExtensions=.dds;.bmp;.tga
TextureSearchPaths= TextureSearchPaths=
GoToSkeletonBindPosition=1 GoToSkeletonBindPosition=1
ApplyOverallTransformToSkinAndBones=1
...@@ -62,7 +62,7 @@ void NifImporter::Initialize() ...@@ -62,7 +62,7 @@ void NifImporter::Initialize()
{ {
// Apply post processing checks after reading blocks // Apply post processing checks after reading blocks
if (isValid()){ if (isValid()){
if (goToSkeletonBindPosition && !nodes.empty()) if (goToSkeletonBindPosition && !nodes.empty() && importBones)
GoToSkeletonBindPosition(nodes); GoToSkeletonBindPosition(nodes);
// Only support biped if CreateNewBiped can be found. // Only support biped if CreateNewBiped can be found.
...@@ -124,6 +124,7 @@ void NifImporter::LoadIniSettings() ...@@ -124,6 +124,7 @@ void NifImporter::LoadIniSettings()
flipUVTextures = GetIniValue<bool>(NifImportSection, "FlipUVTextures", true); flipUVTextures = GetIniValue<bool>(NifImportSection, "FlipUVTextures", true);
enableSkinSupport = GetIniValue<bool>(NifImportSection, "EnableSkinSupport", true); enableSkinSupport = GetIniValue<bool>(NifImportSection, "EnableSkinSupport", true);
importBones = GetIniValue<bool>(BipedImportSection, "ImportBones", true);
bipedHeight = GetIniValue<float>(BipedImportSection, "BipedHeight", 131.90f); bipedHeight = GetIniValue<float>(BipedImportSection, "BipedHeight", 131.90f);
bipedAngle = GetIniValue<float>(BipedImportSection, "BipedAngle", 90.0f); bipedAngle = GetIniValue<float>(BipedImportSection, "BipedAngle", 90.0f);
bipedAnkleAttach = GetIniValue<float>(BipedImportSection, "BipedAnkleAttach", 0.2f); bipedAnkleAttach = GetIniValue<float>(BipedImportSection, "BipedAnkleAttach", 0.2f);
...@@ -192,7 +193,7 @@ bool NifImporter::DoImport() ...@@ -192,7 +193,7 @@ bool NifImporter::DoImport()
else else
{ {
vector<string> importedBones; vector<string> importedBones;
if (importSkeleton) if (importSkeleton && importBones)
{ {
if (browseForSkeleton) if (browseForSkeleton)
{ {
...@@ -239,15 +240,17 @@ bool NifImporter::DoImport() ...@@ -239,15 +240,17 @@ bool NifImporter::DoImport()
} }
} }
} }
} else if (hasSkeleton && useBiped) { } else if (hasSkeleton && useBiped && importBones) {
ImportBipeds(nodes); ImportBipeds(nodes);
} }
if (isValid()) { if (isValid()) {
if (strmatch(rootNode->GetName(), "Scene Root")) if (importBones) {
ImportBones(DynamicCast<NiNode>(rootNode->GetChildren())); if (strmatch(rootNode->GetName(), "Scene Root"))
else ImportBones(DynamicCast<NiNode>(rootNode->GetChildren()));
ImportBones(rootNode); else
ImportBones(rootNode);
}
ok = ImportMeshes(rootNode); ok = ImportMeshes(rootNode);
......
...@@ -30,6 +30,7 @@ public: ...@@ -30,6 +30,7 @@ public:
bool goToSkeletonBindPosition; bool goToSkeletonBindPosition;
// Biped/Bones related settings // Biped/Bones related settings
bool importBones;
string skeleton; string skeleton;
float bipedHeight; float bipedHeight;
string skeletonCheck; string skeletonCheck;
......
...@@ -494,3 +494,37 @@ void FindImages(NameValueCollection& images, const string& rootPath, const strin ...@@ -494,3 +494,37 @@ void FindImages(NameValueCollection& images, const string& rootPath, const strin
} }
// Debugger Trace Window Utilities
TSTR PrintMatrix3(Matrix3& m)
{
Point3 pt = m.GetTrans();
float y,p,r;
m.GetYawPitchRoll(&y,&p,&r);
return FormatText("Matrix3: [%g,%g,%g] <%g,%g,%g>\n"
,pt.x, pt.y, pt.z
,TODEG(y), TODEG(p), TODEG(r)
);
}
void DumpMatrix3(Matrix3& m)
{
OutputDebugString(PrintMatrix3(m));
}
TSTR PrintMatrix44(Matrix44& m)
{
Vector3 p; Matrix33 rot; float sc;
m.Decompose(p, rot, sc);
Quaternion q = rot.AsQuaternion();
Float3 f = q.AsEulerYawPitchRoll();
return FormatText("Matrix3: [%g,%g,%g] <%g,%g,%g> (%g)\n"
,p.x, p.y, p.z
,TODEG(f[0]), TODEG(f[1]), TODEG(f[2])
,sc
);
}
void DumpMatrix44(Matrix44& m)
{
OutputDebugString(PrintMatrix44(m));
}
\ No newline at end of file
...@@ -303,4 +303,7 @@ inline Niflib::Ref<U> SelectFirstObjectOfType( list<Niflib::Ref<T> > const & obj ...@@ -303,4 +303,7 @@ inline Niflib::Ref<U> SelectFirstObjectOfType( list<Niflib::Ref<T> > const & obj
return Niflib::Ref<U>(); return Niflib::Ref<U>();
} }
TSTR PrintMatrix3(Matrix3& m);
TSTR PrintMatrix44(Niflib::Matrix44& m);
#endif // _NIUTILS_H_ #endif // _NIUTILS_H_
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment