public SubModel(DatDigger.Sections.Model.ModelChunk model, Cache.VarEquip varEquip) : base() { this.model = model; this.varEquip = varEquip; this.meshes = new List<Mesh>(); }
public Pgrp(DatDigger.Sections.Model.PgrpChunk pgrp, IndexList idxList, int numVertices) : base() { this.pgrp = pgrp; this.idxList = idxList; this.numVertices = numVertices; this.numTriangles = pgrp.Triangles.Length; this.Name = pgrp.PgrpName; }
public Mesh(DatDigger.Sections.Model.MeshChunk mesh, Cache.VarEquip varEquip) : base() { this.mesh = mesh; this.varEquip = varEquip; }
public void LoadBones(DatDigger.Sections.Skeleton.SkeletonSection skeleton) { if (IsLoaded) { throw new InvalidOperationException("AnimatedSkeleton already populated"); } this.skeleton = skeleton; this.Bones = new Bone[skeleton.Bones.Count]; Dictionary<int, Bone> boneIdMap = new Dictionary<int, Bone>(); SpuBinary spuBinary = this.mtbSection.FindChild<SpuBinary>(); for (var i = 0; i < this.Bones.Length; i++) { Bone thisBone = new Bone(); thisBone.Id = i; this.Bones[i] = thisBone; AnimatedBoneNode aniBoneNode = spuBinary.FindChild<AnimatedBoneNode>(x => x.Bone.BoneId == i); AnimatedBone aniBone = (aniBoneNode == null) ? null : aniBoneNode.Bone; Vector3 translation; Vector3 scale; Quaternion rotation; if (aniBone != null) { translation = new Vector3(); scale = new Vector3(); translation.X = (aniBone.TranslationX == null) ? skeleton.Bones[i].Translation.X : aniBone.TranslationX.GetValue(0); translation.Y = (aniBone.TranslationY == null) ? skeleton.Bones[i].Translation.Y : aniBone.TranslationY.GetValue(0); translation.Z = (aniBone.TranslationZ == null) ? skeleton.Bones[i].Translation.Z : aniBone.TranslationZ.GetValue(0); scale.X = (aniBone.ScaleX == null) ? skeleton.Bones[i].Scale.X : aniBone.ScaleX.GetValue(0); scale.Y = (aniBone.ScaleY == null) ? skeleton.Bones[i].Scale.Y : aniBone.ScaleY.GetValue(0); scale.Z = (aniBone.ScaleZ == null) ? skeleton.Bones[i].Scale.Z : aniBone.ScaleZ.GetValue(0); rotation = (aniBone.RotationCurve == null) ? skeleton.Bones[i].Rotation : aniBone.RotationCurve.GetValue(0); } else { translation = skeleton.Bones[i].Translation; scale = skeleton.Bones[i].Scale; rotation = skeleton.Bones[i].Rotation; } boneNameMap[skeleton.Bones[i].Name] = thisBone; boneIdMap[skeleton.Bones[i].BoneIndex] = thisBone; int parentBoneIndex = skeleton.Bones[i].ParentBoneIndex; if (parentBoneIndex >= 0) { Bone parent = boneIdMap[parentBoneIndex]; thisBone.ParentId = parent.Id; // Transform our translation by our parent's rotation quaternion and add to our parent translation Vector4 transformedPos = Vector3.Transform(translation, parent.Orientation); thisBone.Position.X = transformedPos.X + parent.Position.X; thisBone.Position.Y = transformedPos.Y + parent.Position.Y; thisBone.Position.Z = transformedPos.Z + parent.Position.Z; // Rotate our baseframe orientation by our parent joint's rotation quaternion thisBone.Orientation = rotation * parent.Orientation; // Order is important thisBone.Orientation = Quaternion.Normalize(thisBone.Orientation); thisBone.Scale = Vector3.Modulate(scale, parent.Scale); } else { thisBone.ParentId = -1; thisBone.Orientation = rotation; thisBone.Position = translation; thisBone.Scale = scale; } } this.IsLoaded = true; }
public void LoadBones(DatDigger.Sections.Skeleton.SkeletonSection skeleton) { if (IsLoaded) { throw new InvalidOperationException("SkeletalFrame already populated"); } this.Bones = new Bone[skeleton.Bones.Count]; Dictionary<int, Bone> boneIdMap = new Dictionary<int, Bone>(); for (var i = 0; i < this.Bones.Length; i++) { Bone thisBone = new Bone(); thisBone.Id = i; this.Bones[i] = thisBone; boneNameMap[skeleton.Bones[i].Name] = thisBone; boneIdMap[skeleton.Bones[i].BoneIndex] = thisBone; int parentBoneIndex = skeleton.Bones[i].ParentBoneIndex; if (parentBoneIndex >= 0) { Bone parent = boneIdMap[skeleton.Bones[i].ParentBoneIndex]; thisBone.ParentId = parent.Id; // Transform our translation by our parent's rotation quaternion and add to our parent translation Vector4 transformedPos = Vector3.Transform(skeleton.Bones[i].Translation, parent.Orientation); thisBone.Position.X = transformedPos.X + parent.Position.X; thisBone.Position.Y = transformedPos.Y + parent.Position.Y; thisBone.Position.Z = transformedPos.Z + parent.Position.Z; // Rotate our baseframe orientation by our parent joint's rotation quaternion thisBone.Orientation = skeleton.Bones[i].Rotation * parent.Orientation; // Order is important //thisBone.Orientation = parent.Orientation * skeleton.Bones[i].Rotation; // Order is important thisBone.Orientation = Quaternion.Normalize(thisBone.Orientation); thisBone.Scale = Vector3.Modulate(skeleton.Bones[i].Scale, parent.Scale); } else if (parentBoneIndex == -1) { thisBone.ParentId = -1; thisBone.Orientation = skeleton.Bones[i].Rotation; thisBone.Position = skeleton.Bones[i].Translation; thisBone.Scale = skeleton.Bones[i].Scale; } else { // Parent bone is a bone in the main skeleton int parentIdx = parentBoneIndex ^ Int32.MinValue; // Unset the MSB Bone parent = this.extendingFrame.Bones[parentIdx]; thisBone.ParentId = parentBoneIndex; // Transform our translation by our parent's rotation quaternion and add to our parent translation Vector4 transformedPos = Vector3.Transform(skeleton.Bones[i].Translation, parent.Orientation); thisBone.Position.X = transformedPos.X + parent.Position.X; thisBone.Position.Y = transformedPos.Y + parent.Position.Y; thisBone.Position.Z = transformedPos.Z + parent.Position.Z; // Rotate our baseframe orientation by our parent joint's rotation quaternion thisBone.Orientation = skeleton.Bones[i].Rotation * parent.Orientation; // Order is important //thisBone.Orientation = parent.Orientation * skeleton.Bones[i].Rotation; // Order is important thisBone.Orientation = Quaternion.Normalize(thisBone.Orientation); thisBone.Scale = Vector3.Modulate(skeleton.Bones[i].Scale, parent.Scale); } if (this.baseFrame == this) { thisBone.CalculateJointMatrix(); } } this.IsLoaded = true; }