public void AddDummyPoly(FLVER.Dummy dmy) { lock (_lock_everything_monkaS) { var di = new DummyPolyInfo(dmy, MODEL.Skeleton); DummyPoly.Add(di); if (!_dummyPolyByRefID.ContainsKey(dmy.ReferenceID)) { _dummyPolyByRefID.Add(dmy.ReferenceID, new List <DummyPolyInfo>()); } if (!_dummyPolyByRefID[dmy.ReferenceID].Contains(di)) { _dummyPolyByRefID[dmy.ReferenceID].Add(di); } if (!_dummyPolyByBoneID.ContainsKey(dmy.AttachBoneIndex)) { _dummyPolyByBoneID.Add(dmy.AttachBoneIndex, new List <DummyPolyInfo>()); } if (!_dummyPolyByBoneID[dmy.AttachBoneIndex].Contains(di)) { _dummyPolyByBoneID[dmy.AttachBoneIndex].Add(di); } } }
public DummyPolyInfo(FLVER.Dummy dmy, NewAnimSkeleton_FLVER skeleton) { dummy = dmy; ReferenceID = dmy.ReferenceID; ReferenceMatrix = Matrix.CreateWorld( Vector3.Zero, Vector3.Normalize(new Vector3(dmy.Forward.X, dmy.Forward.Y, dmy.Forward.Z)), dmy.UseUpwardVector ? Vector3.Normalize(new Vector3(dmy.Upward.X, dmy.Upward.Y, dmy.Upward.Z)) : Vector3.Up) * Matrix.CreateTranslation(new Vector3(dmy.Position.X, dmy.Position.Y, dmy.Position.Z)) * (dmy.ParentBoneIndex >= 0 ? skeleton.FlverSkeleton[dmy.ParentBoneIndex].ReferenceMatrix : Matrix.Identity); AttachMatrix = Matrix.Identity; ArrowPrimitive = new DbgPrimWireArrow("DummyPoly Spawns", Transform.Default, Color.White) { //Wireframe = true, //BackfaceCulling = true, //DisableLighting = true, Category = DbgPrimCategory.DummyPolySpawnArrow, OverrideColor = Color.Cyan, }; }
public DummyPolyInfo(FLVER.Dummy dmy, NewAnimSkeleton skeleton) { ReferenceID = dmy.ReferenceID; FollowBoneIndex = dmy.AttachBoneIndex; ReferenceMatrix = Matrix.CreateWorld( Vector3.Zero, Vector3.Normalize(new Vector3(dmy.Forward.X, dmy.Forward.Y, dmy.Forward.Z)), dmy.UseUpwardVector ? Vector3.Normalize(new Vector3(dmy.Upward.X, dmy.Upward.Y, dmy.Upward.Z)) : Vector3.Up) * Matrix.CreateTranslation(new Vector3(dmy.Position.X, dmy.Position.Y, dmy.Position.Z)) * (dmy.ParentBoneIndex >= 0 ? skeleton.FlverSkeleton[dmy.ParentBoneIndex].ReferenceMatrix : Matrix.Identity); CurrentMatrix = ReferenceMatrix; ArrowPrimitive = new DbgPrimWireArrow("DummyPoly Spawns", Transform.Default, Color.White) { //Wireframe = true, //BackfaceCulling = true, //DisableLighting = true, Category = DbgPrimCategory.DummyPolySpawnArrow, OverrideColor = Color.Cyan, }; SpawnPrinter.Font = DBG.DEBUG_FONT_SMALL; SpawnPrinter.FullyOutlined = true; }
public static FLVERMetaskeleton GenerateFlverMetaskeletonFromRootNode( Node rootNode, Matrix4x4 rootNodeAbsoluteMatrix, float importScale) { var bonesAssimp = new List <Node>(); var skel = new FLVERMetaskeleton(); var dummyAttachBoneNames = new List <string>(); NMatrix matrixScale = NMatrix.CreateScale(importScale, importScale, importScale); // Returns index of bone in master bone list if boneNode is a bone. // Returns -1 if boneNode is a DummyPoly (denoted with a node name starting with "DUMMY_POLY"). int AddBone(Node boneNode, Node parentBoneNode, Matrix4x4 parentAbsoluteMatrix) { short parentBoneIndex = (short)(bonesAssimp.IndexOf(parentBoneNode)); var thisBoneMatrix = boneNode.Transform; var thisNodeAbsoluteMatrix = thisBoneMatrix * parentAbsoluteMatrix; var boneTrans = FLVERBoneTransform.FromMatrix4x4( (parentBoneIndex == -1 ? thisNodeAbsoluteMatrix : thisBoneMatrix), true); if (boneNode.Name.StartsWith("DUMMY_POLY")) { // TODO thisNodeAbsoluteMatrix.Decompose(out Vector3D dummyScale, out Quaternion dummyQuat, out Vector3D dummyTranslation); var dmy = new FLVER.Dummy(); dmy.ParentBoneIndex = parentBoneIndex; dmy.Position = dummyTranslation.ToNumerics(); // Format: "DUMMY_POLY|<RefID>|<AttachBoneName>" // Example: "DUMMY_POLY|220|Spine1" string[] dummyNameParts = boneNode.Name.Split('|'); //ErrorTODO: TryParse dmy.ReferenceID = short.Parse(dummyNameParts[1].Trim()); if (dummyNameParts.Length == 3) { dummyAttachBoneNames.Add(dummyNameParts[2]); } else { dummyAttachBoneNames.Add(null); } //NOTE: Maybe this should be specifiable? I forget what the point of false is here. dmy.UseUpwardVector = true; var sceneRotation = NMatrix.CreateRotationX(boneTrans.Rotation.X) * NMatrix.CreateRotationZ(boneTrans.Rotation.Z) * NMatrix.CreateRotationY(boneTrans.Rotation.Y); dmy.Upward = NVector3.Transform(new NVector3(0, 1, 0), sceneRotation); //TODO: Check if forward vector3 should be 1 or -1; dmy.Forward = NVector3.Transform(new NVector3(0, 0, 1), sceneRotation); skel.DummyPoly.Add(dmy); return(-1); } else { bonesAssimp.Add(boneNode); int thisBoneIndex = bonesAssimp.Count - 1; var flverBone = new FLVER.Bone(); if (parentBoneNode != null) { flverBone.ParentIndex = parentBoneIndex; } flverBone.Name = boneNode.Name; flverBone.BoundingBoxMin = new NVector3(float.MaxValue, float.MaxValue, float.MaxValue); flverBone.BoundingBoxMax = new NVector3(float.MinValue, float.MinValue, float.MinValue); flverBone.Translation = boneTrans.Translation * importScale; flverBone.Rotation = boneTrans.Rotation; flverBone.Scale = boneTrans.Scale; skel.Bones.Add(flverBone); List <int> childBoneIndices = new List <int>(); foreach (var c in boneNode.Children) { int cIndex = AddBone(c, boneNode, thisNodeAbsoluteMatrix); //cIndex will be -1 if the child node was a DummyPoly instead of a bone. if (cIndex >= 0) { childBoneIndices.Add(cIndex); } } if (childBoneIndices.Count > 0) { flverBone.ChildIndex = (short)childBoneIndices[0]; for (int i = 0; i < childBoneIndices.Count; i++) { var thisChildBone = skel.Bones[childBoneIndices[i]]; if (i == 0) { thisChildBone.PreviousSiblingIndex = -1; } else { thisChildBone.PreviousSiblingIndex = (short)(childBoneIndices[i - 1]); } if (i == childBoneIndices.Count - 1) { thisChildBone.NextSiblingIndex = -1; } else { thisChildBone.NextSiblingIndex = (short)(childBoneIndices[i + 1]); } } } return(thisBoneIndex); } } //if (rootNode.Children == null) // throw new InvalidDataException("Assimp scene has no heirarchy."); var root = rootNode; //var master = root.Children[0]; //foreach (var c in root.Children) //{ // AddBone(c, null, root.Transform * rootNodeAbsoluteMatrix); //} AddBone(root, null, rootNodeAbsoluteMatrix); // Apply parent bone transforms to DummyPoly foreach (var d in skel.DummyPoly) { if (d.ParentBoneIndex >= 0) { var parentMat = skel.Bones[d.ParentBoneIndex].GetAbsoluteNMatrix(skel.Bones); d.Position = NVector3.Transform(d.Position, parentMat); d.Upward = NVector3.TransformNormal(d.Upward, parentMat); d.Forward = NVector3.TransformNormal(d.Forward, parentMat); } } return(skel); }