Пример #1
0
        static void Main(string[] args)
        {
            var fact   = new ObjLoaderFactory();
            var loader = fact.Create();

            using (var fs = File.OpenRead(args[0]))
            {
                var res = loader.Load(fs);

                List <Vector3> verts   = new List <Vector3>();
                List <ushort>  indices = new List <ushort>();

                foreach (var vert in res.Vertices)
                {
                    verts.Add(new Vector3(vert.X, vert.Y, vert.Z));
                }
                foreach (var idx in res.Groups[0].Faces)
                {
                    indices.Add((ushort)(idx[0].VertexIndex - 1));
                    indices.Add((ushort)(idx[1].VertexIndex - 1));
                    indices.Add((ushort)(idx[2].VertexIndex - 1));
                }

                HKX2.Builders.hknpCollisionMeshBuilder colBuilder = new HKX2.Builders.hknpCollisionMeshBuilder();
                colBuilder.AddMesh(verts, indices);
                var root = colBuilder.CookCollision();

                using (FileStream s2 = File.Create(args[0] + ".hkx"))
                {
                    BinaryWriterEx bw = new BinaryWriterEx(false, s2);
                    var            s  = new HKX2.PackFileSerializer();
                    s.Serialize(root, bw);
                }
            }
        }
Пример #2
0
        static void Main(string[] args)
        {
            var hkxpath = args[0];

            using (FileStream stream = File.OpenRead(hkxpath))
            {
                BinaryReaderEx br   = new BinaryReaderEx(false, stream);
                var            des  = new HKX2.PackFileDeserializer();
                var            root = (hkRootLevelContainer)des.Deserialize(br);

                // Strip some stuff

                /*var v = (hknpPhysicsSceneData)root.m_namedVariants[0].m_variant;
                 * foreach (fsnpCustomParamCompressedMeshShape s in v.m_systemDatas[0].m_referencedObjects)
                 * {
                 *  var bvh = s.m_data.getMeshBVH();
                 *  s.m_triangleIndexToShapeKey = null;
                 *  s.m_pParam = null;
                 *  s.m_edgeWeldingMap.m_primaryKeyToIndex = null;
                 *  s.m_edgeWeldingMap.m_secondaryKeyMask = 0;
                 *  s.m_edgeWeldingMap.m_sencondaryKeyBits = 0;
                 *  s.m_edgeWeldingMap.m_valueAndSecondaryKeys = null;
                 *  s.m_quadIsFlat.m_storage.m_numBits = 0;
                 *  s.m_quadIsFlat.m_storage.m_words = null;
                 *  s.m_triangleIsInterior.m_storage.m_numBits = 0;
                 *  s.m_triangleIsInterior.m_storage.m_words = null;
                 *  s.m_numShapeKeyBits = 0;
                 *  s.m_data.m_meshTree.m_bitsPerKey = 0;
                 *  s.m_data.m_meshTree.m_maxKeyValue = 0;
                 *  s.m_data.m_meshTree.m_bitsPerKey = 0;
                 *  s.m_data.m_meshTree.m_numPrimitiveKeys = 0;
                 *  s.m_data.m_meshTree.m_domain.m_min.W = 1.0f;
                 *  s.m_data.m_meshTree.m_domain.m_max.W = 1.0f;
                 *  s.m_data.m_simdTree.m_nodes = null;
                 *  foreach (var sec in s.m_data.m_meshTree.m_sections)
                 *  {
                 *      sec.m_leafIndex = 0;
                 *      sec.m_flags = 0;
                 *      var sbvh = sec.getSectionBVH();
                 *  }
                 * }*/

                using (FileStream s2 = File.Create(args[1]))
                {
                    BinaryWriterEx bw = new BinaryWriterEx(false, s2);
                    var            s  = new HKX2.PackFileSerializer();
                    s.Serialize(root, bw);
                }
            }
        }
Пример #3
0
        public void OnGui(GameType game)
        {
            if (ImGui.Begin("Navmesh Build"))
            {
                if (game != GameType.DarkSoulsIII)
                {
                    ImGui.Text("Navmesh building only supported for DS3");
                    ImGui.End();
                    return;
                }

                var sel = _selection.GetSingleFilteredSelection <Entity>();
                if (sel != null && sel.RenderSceneMesh != null && sel.RenderSceneMesh is MeshRenderableProxy mrp &&
                    mrp.ResourceHandle != null && mrp.ResourceHandle is ResourceHandle <HavokCollisionResource> col)
                {
                    ImGui.LabelText("value", "lable");
                    ImGui.DragFloat("Cell size", ref Cellsize, 0.005f, 0.0f);
                    ImGui.DragFloat("Cell height", ref Cellheight, 0.005f, 0.0f);
                    ImGui.DragFloat("Slope Angle", ref SlopeAngle, 0.5f, 0.0f, 85.0f);
                    ImGui.DragFloat("Agent Height", ref AgentHeight, 0.005f, 0.0f);
                    ImGui.DragFloat("Agent Climb", ref AgentClimb, 0.005f, 0.0f);
                    ImGui.DragFloat("Agent Radius", ref AgentRadius, 0.005f, 0.0f);
                    ImGui.DragInt("Min Region Area", ref MinRegionArea, 1, 0);

                    if (ImGui.Button("Build Navmesh"))
                    {
                        var buildverts   = new List <Vector3>();
                        var buildindices = new List <int>();
                        int vbase        = 0;
                        foreach (var sm in col.Get().GPUMeshes)
                        {
                            buildverts.AddRange(sm.PickingVertices);
                            foreach (var i in sm.PickingIndices)
                            {
                                buildindices.Add(i + vbase);
                            }
                            vbase += sm.PickingVertices.Length;
                        }
                        //var sm = col.Resource.Get().GPUMeshes[0];
                        var bv = buildverts.ToArray();
                        //buildindices.Reverse();
                        var bi = buildindices.ToArray();

                        foreach (var i in bi)
                        {
                            var x = bv[i];
                        }


                        NavGen.SetNavmeshBuildParams(Cellsize, Cellheight, SlopeAngle, AgentHeight, AgentClimb, AgentRadius, MinRegionArea);

                        var p = new hkaiNavMeshBuilder.BuildParams();
                        p.Cellsize      = Cellsize;
                        p.Cellheight    = Cellheight;
                        p.SlopeAngle    = SlopeAngle;
                        p.AgentHeight   = AgentHeight;
                        p.AgentClimb    = AgentClimb;
                        p.AgentRadius   = AgentRadius;
                        p.MinRegionArea = MinRegionArea;

                        var builder = new hkaiNavMeshBuilder();
                        var built   = builder.BuildNavmesh(p, buildverts, buildindices);
                        BuildSuccess = (built != null);
                        DidBuild     = true;
                        if (BuildSuccess)
                        {
                            if (_previewMesh != null)
                            {
                                _previewMesh.Dispose();
                            }

                            var res = HavokNavmeshResource.ResourceFromNavmeshRoot(built);
                            _previewResource = ResourceHandle <HavokNavmeshResource> .TempHandleFromResource(res);

                            _previewMesh       = MeshRenderableProxy.MeshRenderableFromHavokNavmeshResource(_scene, _previewResource, true);
                            _previewMesh.World = mrp.World;

                            // Do a test save
                            var path = $@"{_locator.GameModDirectory}\navout\test.hkx";
                            using (FileStream s2 = File.Create(path))
                            {
                                BinaryWriterEx bw = new BinaryWriterEx(false, s2);
                                var            s  = new HKX2.PackFileSerializer();
                                s.Serialize(built, bw);
                            }

                            /*vcount = NavGen.GetMeshVertCount();
                             * icount = NavGen.GetMeshTriCount();
                             *
                             * if (icount > 0)
                             * {
                             *  // Make preview mesh
                             *  ushort[] verts = new ushort[vcount * 3];
                             *  ushort[] indices = new ushort[icount * 3 * 2];
                             *  NavGen.GetMeshVerts(verts);
                             *  NavGen.GetMeshTris(indices);
                             *
                             *  Vector3[] bounds = new Vector3[2];
                             *  NavGen.GetBoundingBox(bounds);
                             *
                             *  if (_previewMesh != null)
                             *  {
                             *      _previewMesh.UnregisterWithScene();
                             *      _previewMesh = null;
                             *  }
                             *
                             *  var nvm = new Scene.NvmRenderer(bounds[0], bounds[1], Cellsize, Cellheight, verts, indices);
                             *  _previewMesh = new Scene.Mesh(Scene, nvm.Bounds, nvm);
                             *  _previewMesh.Highlighted = true;
                             * }*/
                        }
                    }

                    if (DidBuild)
                    {
                        if (BuildSuccess)
                        {
                            ImGui.Text("Successfully built navmesh");
                            ImGui.Text($@"Vertex count: {vcount}");
                            ImGui.Text($@"Triangle count: {icount}");
                        }
                        else
                        {
                            ImGui.Text("Navmesh build failed");
                        }
                    }
                }
                else
                {
                    ImGui.Text("Select a single collision mesh to generate a navmesh");
                }
            }