public void LoadModel(string modelid)
        {
            AssetDescription asset;
            AssetDescription assettex;

            Scene.RenderFilter filt = Scene.RenderFilter.All;
            var job = ResourceManager.CreateNewJob($@"Loading mesh");

            if (modelid.StartsWith("c"))
            {
                asset    = AssetLocator.GetChrModel(modelid);
                assettex = AssetLocator.GetChrTextures(modelid);
            }
            else if (modelid.StartsWith("o"))
            {
                asset    = AssetLocator.GetObjModel(modelid);
                assettex = AssetLocator.GetNullAsset();
            }
            else
            {
                asset    = AssetLocator.GetNullAsset();
                assettex = AssetLocator.GetNullAsset();
            }

            var res = ResourceManager.GetResource <Resource.FlverResource>(asset.AssetVirtualPath);

            if (_renderMesh != null)
            {
                //RenderScene.RemoveObject(_renderMesh);
            }
            _renderMesh = MeshRenderableProxy.MeshRenderableFromFlverResource(RenderScene, res);
            //_renderMesh.DrawFilter = filt;
            _renderMesh.World = Matrix4x4.Identity;
            _flverhandle      = res;
            _currentModel     = modelid;
            if (!res.IsLoaded || res.AccessLevel != AccessLevel.AccessFull)
            {
                if (asset.AssetArchiveVirtualPath != null)
                {
                    job.AddLoadArchiveTask(asset.AssetArchiveVirtualPath, AccessLevel.AccessFull, false, Resource.ResourceManager.ResourceType.Flver);
                }
                else if (asset.AssetVirtualPath != null)
                {
                    job.AddLoadFileTask(asset.AssetVirtualPath, AccessLevel.AccessFull);
                }
                if (assettex.AssetArchiveVirtualPath != null)
                {
                    job.AddLoadArchiveTask(assettex.AssetArchiveVirtualPath, AccessLevel.AccessGPUOptimizedOnly, false, Resource.ResourceManager.ResourceType.Texture);
                }
                else if (assettex.AssetVirtualPath != null)
                {
                    job.AddLoadFileTask(assettex.AssetVirtualPath, AccessLevel.AccessGPUOptimizedOnly);
                }
                _loadingTask = job.StartJobAsync();
            }
        }
예제 #2
0
        public void LoadFlver(FLVER2 flver, MeshRenderableProxy proxy)
        {
            var meshesNode = new NamedEntity(this, null, "Meshes");

            Objects.Add(meshesNode);
            RootObject.AddChild(meshesNode);
            for (int i = 0; i < flver.Meshes.Count; i++)
            {
                var meshnode = new NamedEntity(this, flver.Meshes[i], $@"mesh_{i}");
                if (proxy.Submeshes.Count > 0)
                {
                    meshnode.RenderSceneMesh = proxy.Submeshes[i];
                    proxy.Submeshes[i].SetSelectable(meshnode);
                }
                Objects.Add(meshnode);
                meshesNode.AddChild(meshnode);
            }

            var materialsNode = new NamedEntity(this, null, "Materials");

            Objects.Add(materialsNode);
            RootObject.AddChild(materialsNode);
            for (int i = 0; i < flver.Materials.Count; i++)
            {
                var matnode = new Entity(this, flver.Materials[i]);
                Objects.Add(matnode);
                materialsNode.AddChild(matnode);
            }

            var layoutsNode = new NamedEntity(this, null, "Layouts");

            Objects.Add(layoutsNode);
            RootObject.AddChild(layoutsNode);
            for (int i = 0; i < flver.BufferLayouts.Count; i++)
            {
                var laynode = new NamedEntity(this, flver.BufferLayouts[i], $@"layout_{i}");
                Objects.Add(laynode);
                layoutsNode.AddChild(laynode);
            }

            var bonesNode = new NamedEntity(this, null, "Bones");

            Objects.Add(bonesNode);
            RootObject.AddChild(bonesNode);
            var boneEntList = new List <TransformableNamedEntity>();

            for (int i = 0; i < flver.Bones.Count; i++)
            {
                var bonenode = new TransformableNamedEntity(this, flver.Bones[i], flver.Bones[i].Name);
                bonenode.RenderSceneMesh = Universe.GetBoneDrawable(this, bonenode);
                Objects.Add(bonenode);
                boneEntList.Add(bonenode);
            }
            for (int i = 0; i < flver.Bones.Count; i++)
            {
                if (flver.Bones[i].ParentIndex == -1)
                {
                    bonesNode.AddChild(boneEntList[i]);
                }
                else
                {
                    boneEntList[flver.Bones[i].ParentIndex].AddChild(boneEntList[i]);
                }
            }

            // Add dummy polys attached to bones
            var dmysNode = new NamedEntity(this, null, "DummyPolys");

            Objects.Add(dmysNode);
            RootObject.AddChild(dmysNode);
            for (int i = 0; i < flver.Dummies.Count; i++)
            {
                var dmynode = new TransformableNamedEntity(this, flver.Dummies[i], $@"dmy_{i}");
                dmynode.RenderSceneMesh = Universe.GetDummyPolyDrawable(this, dmynode);
                Objects.Add(dmynode);
                dmysNode.AddChild(dmynode);
            }
        }
예제 #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");
                }
            }