public static void LoadMsbRegionsDS3andBB(string mapName, MSB64.MSBVersion version) { var cylinder = new DbgPrimWireCylinder( location: Transform.Default, range: 1.0f, height: 1, numSegments: 12, color: Color.Cyan); var sphere = new DbgPrimWireSphere(Transform.Default, 1f, 12, 12, Color.Red); var circle = new DbgPrimWireSphere(Transform.Default, 1f, 12, 12, Color.Fuchsia); var point = new DbgPrimWireSphere(Transform.Default, 0.25f, 4, 4, Color.Lime); var box = new DbgPrimWireBox(Transform.Default, Vector3.One, Color.Yellow); var msb = MSB64.Read(GetInterrootPath($@"map\MapStudio\{mapName}.msb.dcx"), version); foreach (var msbBox in msb.Regions.Boxes) { var newBox = box.Instantiate(msbBox.Name, new Transform(msbBox.Position.X, msbBox.Position.Y, msbBox.Position.Z, MathHelper.ToRadians(msbBox.Rotation.X), MathHelper.ToRadians(msbBox.Rotation.Y), MathHelper.ToRadians(msbBox.Rotation.Z), msbBox.Length, msbBox.Height, msbBox.Width)); DBG.AddPrimitive(newBox); } foreach (var msbSphere in msb.Regions.Spheres) { var newSphere = sphere.Instantiate(msbSphere.Name, new Transform(msbSphere.Position.X, msbSphere.Position.Y, msbSphere.Position.Z, MathHelper.ToRadians(msbSphere.Rotation.X), MathHelper.ToRadians(msbSphere.Rotation.Y), MathHelper.ToRadians(msbSphere.Rotation.Z), msbSphere.Radius, msbSphere.Radius, msbSphere.Radius)); DBG.AddPrimitive(newSphere); } foreach (var msbCylinder in msb.Regions.Cylinders) { var newCylinder = cylinder.Instantiate(msbCylinder.Name, new Transform(msbCylinder.Position.X, msbCylinder.Position.Y, msbCylinder.Position.Z, MathHelper.ToRadians(msbCylinder.Rotation.X), MathHelper.ToRadians(msbCylinder.Rotation.Y), MathHelper.ToRadians(msbCylinder.Rotation.Z), msbCylinder.Radius, msbCylinder.Height, msbCylinder.Radius)); DBG.AddPrimitive(newCylinder); } foreach (var msbPoint in msb.Regions.Points) { var newPoint = point.Instantiate(msbPoint.Name, new Transform(msbPoint.Position.X, msbPoint.Position.Y, msbPoint.Position.Z, MathHelper.ToRadians(msbPoint.Rotation.X), MathHelper.ToRadians(msbPoint.Rotation.Y), MathHelper.ToRadians(msbPoint.Rotation.Z))); } // I think circles are probably just beta spheres kek foreach (var msbCircle in msb.Regions.Circles) { var newCircle = circle.Instantiate(msbCircle.Name, new Transform(msbCircle.Position.X, msbCircle.Position.Y, msbCircle.Position.Z, MathHelper.ToRadians(msbCircle.Rotation.X), MathHelper.ToRadians(msbCircle.Rotation.Y), MathHelper.ToRadians(msbCircle.Rotation.Z), msbCircle.Radius, msbCircle.Radius, msbCircle.Radius)); DBG.AddPrimitive(newCircle); } }
private static void DebugBVHDraw(HKX.BVHNode node, DbgPrimWireBox shapeProto) { if (node.IsTerminal) { var box = shapeProto.Instantiate("", new Transform(new Vector3((node.Max.X + node.Min.X) / 2.0f, (node.Max.Y + node.Min.Y) / 2.0f, (node.Max.Z + node.Min.Z) / 2.0f), new Vector3(0, 0, 0), new Vector3(node.Max.X - node.Min.X, node.Max.Y - node.Min.Y, node.Max.Z - node.Min.Z))); DBG.AddPrimitive(box); } if (!node.IsTerminal) { DebugBVHDraw(node.Left, shapeProto); DebugBVHDraw(node.Right, shapeProto); } }
public FlverBoneInfo(NewAnimSkeleton_HKX.HkxBoneInfo copyFromHkx, List <NewAnimSkeleton_HKX.HkxBoneInfo> hkxBoneList, List <FlverBoneInfo> flverBoneList) { ApplyHkxBoneProperties(copyFromHkx, hkxBoneList, flverBoneList); BoundingBoxPrim = new DbgPrimWireBox(Transform.Default, Vector3.One * -0.01f, Vector3.One * 0.01f, DBG.COLOR_FLVER_BONE_BBOX) { Category = DbgPrimCategory.FlverBoneBoundingBox, }; //SpawnPrinter.AppendLine(Name, DBG.COLOR_FLVER_BONE); }
public FlverBoneInfo(FLVER.Bone bone, List <FLVER.Bone> boneList) { Matrix GetBoneMatrix(SoulsFormats.FLVER.Bone b) { SoulsFormats.FLVER.Bone parentBone = b; var result = Matrix.Identity; do { result *= Matrix.CreateScale(parentBone.Scale.X, parentBone.Scale.Y, parentBone.Scale.Z); result *= Matrix.CreateRotationX(parentBone.Rotation.X); result *= Matrix.CreateRotationZ(parentBone.Rotation.Z); result *= Matrix.CreateRotationY(parentBone.Rotation.Y); result *= Matrix.CreateTranslation(parentBone.Translation.X, parentBone.Translation.Y, parentBone.Translation.Z); if (parentBone.ParentIndex >= 0) { parentBone = boneList[parentBone.ParentIndex]; } else { parentBone = null; } }while (parentBone != null); return(result); } ReferenceMatrix = GetBoneMatrix(bone); Name = bone.Name; if (bone.Unk3C == 0) { BonePrim = new DbgPrimWireBone(bone.Name, new Transform(ReferenceMatrix), DBG.COLOR_FLVER_BONE) { Category = DbgPrimCategory.FlverBone, }; BoundingBoxPrim = new DbgPrimWireBox(Transform.Default, new Vector3(bone.BoundingBoxMin.X, bone.BoundingBoxMin.Y, bone.BoundingBoxMin.Z), new Vector3(bone.BoundingBoxMax.X, bone.BoundingBoxMax.Y, bone.BoundingBoxMax.Z), DBG.COLOR_FLVER_BONE_BBOX) { Category = DbgPrimCategory.FlverBoneBoundingBox, }; } }
public static void LoadMsbRegionsDS1(string mapName) { var cylinder = new DbgPrimWireCylinder( location: Transform.Default, range: 1.0f, height: 1, numSegments: 12, color: Color.Cyan); var sphere = new DbgPrimWireSphere(Transform.Default, 1f, 12, 12, Color.Red); var point = new DbgPrimWireSphere(Transform.Default, 0.25f, 4, 4, Color.Lime); var box = new DbgPrimWireBox(Transform.Default, Vector3.One, Color.Yellow); var msb = DataFile.LoadFromFile <MSB>(InterrootLoader.GetInterrootPath($@"map\MapStudio\{mapName}.msb")); foreach (var msbBox in msb.Regions.Boxes) { var newBox = box.Instantiate(msbBox.Name, new Transform(msbBox.PosX, msbBox.PosY, msbBox.PosZ, MathHelper.ToRadians(msbBox.RotX), MathHelper.ToRadians(msbBox.RotY), MathHelper.ToRadians(msbBox.RotZ), msbBox.WidthX, msbBox.HeightY, msbBox.DepthZ)); DBG.AddPrimitive(newBox); } foreach (var msbSphere in msb.Regions.Spheres) { var newSphere = sphere.Instantiate(msbSphere.Name, new Transform(msbSphere.PosX, msbSphere.PosY, msbSphere.PosZ, MathHelper.ToRadians(msbSphere.RotX), MathHelper.ToRadians(msbSphere.RotY), MathHelper.ToRadians(msbSphere.RotZ), msbSphere.Radius, msbSphere.Radius, msbSphere.Radius)); DBG.AddPrimitive(newSphere); } foreach (var msbCylinder in msb.Regions.Cylinders) { var newCylinder = cylinder.Instantiate(msbCylinder.Name, new Transform(msbCylinder.PosX, msbCylinder.PosY, msbCylinder.PosZ, MathHelper.ToRadians(msbCylinder.RotX), MathHelper.ToRadians(msbCylinder.RotY), MathHelper.ToRadians(msbCylinder.RotZ), msbCylinder.Radius, msbCylinder.Height, msbCylinder.Radius)); DBG.AddPrimitive(newCylinder); } foreach (var msbPoint in msb.Regions.Points) { var newPoint = point.Instantiate(msbPoint.Name, new Transform(msbPoint.PosX, msbPoint.PosY, msbPoint.PosZ, MathHelper.ToRadians(msbPoint.RotX), MathHelper.ToRadians(msbPoint.RotY), MathHelper.ToRadians(msbPoint.RotZ))); } }
public FlverBoneInfo(FLVER.Bone bone, List <FLVER.Bone> boneList) { ParentIndex = bone.ParentIndex; if (GlobalBonePrim == null) { GlobalBonePrim = new DbgPrimWireBone("(BONE)", new Transform(Matrix.Identity), DBG.COLOR_FLVER_BONE) { Category = DbgPrimCategory.FlverBone, }; } Matrix GetBoneMatrix(SoulsFormats.FLVER.Bone b, bool saveParentBone) { SoulsFormats.FLVER.Bone parentBone = b; var result = Matrix.Identity; bool isTopBone = true; do { result *= Matrix.CreateScale(parentBone.Scale.X, parentBone.Scale.Y, parentBone.Scale.Z); result *= Matrix.CreateRotationX(parentBone.Rotation.X); result *= Matrix.CreateRotationZ(parentBone.Rotation.Z); result *= Matrix.CreateRotationY(parentBone.Rotation.Y); result *= Matrix.CreateTranslation(parentBone.Translation.X, parentBone.Translation.Y, parentBone.Translation.Z); if (parentBone.ParentIndex >= 0) { parentBone = boneList[parentBone.ParentIndex]; } else { parentBone = null; } isTopBone = false; if (saveParentBone && isTopBone) { ParentReferenceMatrix = GetBoneMatrix(parentBone, saveParentBone: false); } }while (parentBone != null); return(result); } ReferenceMatrix = GetBoneMatrix(bone, saveParentBone: true); Name = bone.Name; //SpawnPrinter.AppendLine(Name, DBG.COLOR_FLVER_BONE); if (bone.Unk3C == 0) { var nubBone = boneList.Where(bn => bn.Name == bone.Name + "Nub").FirstOrDefault(); if (nubBone != null) { var nubMat = Matrix.Identity; nubMat *= Matrix.CreateScale(nubBone.Scale.X, nubBone.Scale.Y, nubBone.Scale.Z); nubMat *= Matrix.CreateRotationX(nubBone.Rotation.X); nubMat *= Matrix.CreateRotationZ(nubBone.Rotation.Z); nubMat *= Matrix.CreateRotationY(nubBone.Rotation.Y); nubMat *= Matrix.CreateTranslation(nubBone.Translation.X, nubBone.Translation.Y, nubBone.Translation.Z); NubReferenceMatrix = nubMat; } } IsNub = bone.Unk3C != 0; BoundingBoxPrim = new DbgPrimWireBox(Transform.Default, new Vector3(bone.BoundingBoxMin.X, bone.BoundingBoxMin.Y, bone.BoundingBoxMin.Z), new Vector3(bone.BoundingBoxMax.X, bone.BoundingBoxMax.Y, bone.BoundingBoxMax.Z), DBG.COLOR_FLVER_BONE_BBOX) { Category = DbgPrimCategory.FlverBoneBoundingBox, }; }
static void TestMCP_MGC(string mapName) { if (InterrootLoader.Type != InterrootLoader.InterrootType.InterrootDS1) { return; } //GFX.ModelDrawer.AddMap(mapName, false); var box = new DbgPrimWireBox(Transform.Default, Vector3.One, Color.Red); var mcp = DataFile.LoadFromFile <MCP>(InterrootLoader.GetInterrootPath($@"map\{mapName}\{mapName}.mcp")); int bi = 0; foreach (var mcpBox in mcp.Boxes) { var min = new Vector3(mcpBox.MinX, mcpBox.MinY, mcpBox.MinZ); var max = new Vector3(mcpBox.MaxX, mcpBox.MaxY, mcpBox.MaxZ); var size = max - min; var center = min + (size / 2f); DBG.AddPrimitive(box.Instantiate($"Box [{(bi++)}]", new Transform(center.X, center.Y, center.Z, 0, 0, 0, size.X, size.Y, size.Z))); } var sphere = new DbgPrimWireSphere(Transform.Default, 0.35f, 32, 32, Color.Cyan); var mcg = DataFile.LoadFromFile <MCG>(InterrootLoader.GetInterrootPath($@"map\{mapName}\{mapName}.mcg")); var lines = new DbgPrimWire(); List <Vector3> startPoints = new List <Vector3>(); List <Vector3> endPoints = new List <Vector3>(); for (int i = 0; i < mcg.Paths.Count; i++) { var pointsThatReferenceThisShit = mcg.Points.Where(x => x.NearbyPathIndices.Contains(i)).ToList(); startPoints.Add(new Vector3(pointsThatReferenceThisShit[0].PosX, pointsThatReferenceThisShit[0].PosY, pointsThatReferenceThisShit[0].PosZ)); endPoints.Add(new Vector3(pointsThatReferenceThisShit[1].PosX, pointsThatReferenceThisShit[1].PosY, pointsThatReferenceThisShit[1].PosZ)); } void AddPath(int pathIndex, Color col) => lines.AddLine(startPoints[pathIndex], endPoints[pathIndex], col); void AddPathString(int pathIndex, string str, Color col) { var position = (startPoints[pathIndex] + endPoints[pathIndex]) / 2.0f; lines.AddDbgLabel(position, 5f, str, col); } //for (int i = 0; i < mcg.Paths.Count; i++) //{ // AddPath(i, Color.Cyan); // AddPathString(i, mcg.Paths[i].GetDebugReport(), Color.Cyan); // //foreach (var edgeIndex in mcg.Edges[i].OtherEdgeIndicesA) // //{ // // AddEdge(edgeIndex, Color.Cyan); // //} // //foreach (var edgeIndex in mcg.Edges[i].OtherEdgeIndicesB) // //{ // // AddEdge(edgeIndex, Color.Yellow); // //} // //break; //} float getPathLength(int pathIndex) { var start = startPoints[pathIndex]; var end = endPoints[pathIndex]; return((start - end).Length()); } void addPointDbg(int pointIndex) { DBG.AddPrimitive(sphere.Instantiate($"Point [{pointIndex}]", new Transform(new Vector3(mcg.Points[pointIndex].PosX, mcg.Points[pointIndex].PosY, mcg.Points[pointIndex].PosZ), Vector3.Zero))); int pidx = 0; foreach (var adjPointIndex in mcg.Points[pointIndex].NearbyPointIndices) { DBG.AddPrimitive(sphere.Instantiate($"INDEX IN POINT'S LIST:{pidx++}, Point Near [{adjPointIndex}]", new Transform(new Vector3(mcg.Points[adjPointIndex].PosX, mcg.Points[adjPointIndex].PosY, mcg.Points[adjPointIndex].PosZ), Vector3.Zero))); } pidx = 0; foreach (var path in mcg.Points[pointIndex].NearbyPathIndices) { AddPath(path, Color.Cyan); AddPathString(path, $"PATH INDEX IN POINT'S LIST:{pidx++}\n{mcg.Paths[path].GetDebugReport()}\nPATH LENGTH: {getPathLength(path)}", Color.Cyan); } } //addPointDbg(0); //addPointDbg(1); //addPointDbg(2); for (int i = 0; i < mcg.Points.Count; i++) { addPointDbg(i); } DBG.AddPrimitive(lines); Console.WriteLine("TEST"); }
// Used for collision rendering public FlverSubmeshRenderer(Model parent, HKX colhkx, HKX.FSNPCustomParamCompressedMeshShape meshdata) { Parent = parent; var coldata = meshdata.GetMeshShapeData(); var tree = coldata.getMeshBVH(); var box = new DbgPrimWireBox(Transform.Default, Vector3.One, Color.Cyan); if (tree != null) { //DebugBVHDraw(tree, box); } var vertices = new VertexPositionColorNormalTangentTexture[coldata.SmallVertices.Size + coldata.LargeVertices.Size]; /*for (int i = 0; i < coldata.SmallVertices.Size; i++) * { * var vert = coldata.SmallVertices.GetArrayData().Elements[i].Decompress(coldata.BoundingBoxMin, coldata.BoundingBoxMax); * vertices[i] = new VertexPositionColorNormalTangentTexture(); * vertices[i].Position = new Vector3(vert.X, vert.Y, vert.Z); * }*/ var largebase = coldata.SmallVertices.Size; for (int i = 0; i < coldata.LargeVertices.Size; i++) { var vert = coldata.LargeVertices.GetArrayData().Elements[i].Decompress(coldata.BoundingBoxMin, coldata.BoundingBoxMax); vertices[i + largebase] = new VertexPositionColorNormalTangentTexture(); vertices[i + largebase].Position = new Vector3(vert.X, vert.Y, vert.Z); } MeshFacesets = new List <FlverSubmeshRendererFaceSet>(); int ch = 0; foreach (var chunk in coldata.Chunks.GetArrayData().Elements) { /*if (ch != 1) * { * ch++; * continue; * } * ch++;*/ /*var tree2 = chunk.getChunkBVH(); * if (tree2 != null) * { * DebugBVHDraw(tree2, box); * }*/ List <ushort> indices = new List <ushort>(); for (int i = 0; i < chunk.ByteIndicesLength; i++) { var tri = coldata.MeshIndices.GetArrayData().Elements[i + chunk.ByteIndicesIndex]; if (tri.Idx2 == tri.Idx3 && tri.Idx1 != tri.Idx2) { if (tri.Idx0 < chunk.VertexIndicesLength) { ushort index = (ushort)((uint)tri.Idx0 + chunk.SmallVerticesBase); indices.Add(index); var vert = coldata.SmallVertices.GetArrayData().Elements[index].Decompress(chunk.SmallVertexScale, chunk.SmallVertexOffset); vertices[index] = new VertexPositionColorNormalTangentTexture(); vertices[index].Position = new Vector3(vert.X, vert.Y, vert.Z); } else { indices.Add((ushort)(coldata.VertexIndices.GetArrayData().Elements[tri.Idx0 + chunk.VertexIndicesIndex - chunk.VertexIndicesLength].data + largebase)); } if (tri.Idx1 < chunk.VertexIndicesLength) { ushort index = (ushort)((uint)tri.Idx1 + chunk.SmallVerticesBase); indices.Add(index); var vert = coldata.SmallVertices.GetArrayData().Elements[index].Decompress(chunk.SmallVertexScale, chunk.SmallVertexOffset); vertices[index] = new VertexPositionColorNormalTangentTexture(); vertices[index].Position = new Vector3(vert.X, vert.Y, vert.Z); } else { indices.Add((ushort)(coldata.VertexIndices.GetArrayData().Elements[tri.Idx1 + chunk.VertexIndicesIndex - chunk.VertexIndicesLength].data + largebase)); } if (tri.Idx2 < chunk.VertexIndicesLength) { ushort index = (ushort)((uint)tri.Idx2 + chunk.SmallVerticesBase); indices.Add(index); var vert = coldata.SmallVertices.GetArrayData().Elements[index].Decompress(chunk.SmallVertexScale, chunk.SmallVertexOffset); vertices[index] = new VertexPositionColorNormalTangentTexture(); vertices[index].Position = new Vector3(vert.X, vert.Y, vert.Z); } else { indices.Add((ushort)(coldata.VertexIndices.GetArrayData().Elements[tri.Idx2 + chunk.VertexIndicesIndex - chunk.VertexIndicesLength].data + largebase)); } } } if (indices.Count > 0) { var newFaceSet = new FlverSubmeshRendererFaceSet() { BackfaceCulling = false, IsTriangleStrip = false, IndexBuffer = new IndexBuffer( GFX.Device, IndexElementSize.SixteenBits, indices.Count, BufferUsage.WriteOnly), IndexCount = indices.Count, }; newFaceSet.IndexBuffer.SetData(indices.Select(x => (ushort)x).ToArray()); MeshFacesets.Add(newFaceSet); } } Bounds = BoundingBox.CreateFromPoints(vertices.Select(x => x.Position)); VertBuffer = new VertexBuffer(GFX.Device, typeof(VertexPositionColorNormalTangentTexture), vertices.Length, BufferUsage.WriteOnly); VertBuffer.SetData(vertices); VertBufferBinding = new VertexBufferBinding(VertBuffer, 0, 0); }