예제 #1
0
        public string[] GetBodyNames()
        {
            string[] ModNames = new string[Mdl.BodyPartCount];

            for (int i = 0; i < ModNames.Length; i++)
            {
                ModNames[i] = Mdl.GetBodyPartName(i);
            }

            return(ModNames);
        }
예제 #2
0
        private JToken GetIndex(IResourceProvider provider, string filePath, string mapName = null)
        {
            StudioModelFile mdl;

            using (var mdlStream = provider.OpenFile(filePath))
            {
                mdl = new StudioModelFile(mdlStream);
            }

            var parts = new JArray();

            for (var bodyPartIndex = 0; bodyPartIndex < mdl.BodyPartCount; ++bodyPartIndex)
            {
                var models = new JArray();

                var modelIndex = 0;
                foreach (var model in mdl.GetModels(bodyPartIndex))
                {
                    var meshes = new JArray();

                    foreach (var mesh in mdl.GetMeshes(model.MeshIndex, model.NumMeshes))
                    {
                        meshes.Add(new JObject
                        {
                            { "material", mesh.Material },
                            { "center", mesh.Center.ToJson() }
                        });
                    }

                    var meshDataAction = mapName == null?nameof(GetVpkMeshData) : nameof(GetPakMeshData);

                    models.Add(new JObject
                    {
                        { "name", model.Name },
                        { "radius", model.BoundingRadius },
                        {
                            "meshDataUrl", GetActionUrl(meshDataAction,
                                                        ResourcePath(filePath),
                                                        Replace("mapName", mapName),
                                                        Replace("bodyPart", bodyPartIndex),
                                                        Replace("model", modelIndex),
                                                        Replace("lod", 0))
                        },
                        { "meshes", meshes }
                    });

                    ++modelIndex;
                }

                parts.Add(new JObject
                {
                    { "name", mdl.GetBodyPartName(bodyPartIndex) },
                    { "models", models }
                });
            }

            var materials = new JArray();

            for (var i = 0; i < mdl.NumTextures; ++i)
            {
                var vmtPath = provider is ValveBspFile.PakFileLump
                    ? mdl.GetMaterialName(i, provider, Resources)
                    : mdl.GetMaterialName(i, provider);

                if (!vmtPath.Contains("/"))
                {
                    var mdlDir = Path.GetDirectoryName(filePath);
                    vmtPath = Path.Combine(mdlDir, vmtPath).Replace('\\', '/');
                }

                var vmt = mapName == null
                    ? VmtUtils.OpenVmt(vmtPath)
                    : VmtUtils.OpenVmt(BspController.GetBspFile(Request, mapName), vmtPath);

                materials.Add(vmt == null ? null : VmtUtils.SerializeVmt(Request, vmt, vmtPath));
            }

            return(new JObject
            {
                { "materials", materials },
                { "bodyParts", parts }
            });
        }