コード例 #1
0
ファイル: ItemAll.cs プロジェクト: dethunter12/DevPack
        private void MakeLCModels(string SMCFile)
        {
            int num  = -1;
            int ID   = this.GetIDFromList();
            int num2 = ItemList.FindIndex((ItemContainer p) => p.ItemID.Equals(ID));

            if (num2 != -1)
            {
                int arg_42_0 = ItemList[num2].JobFlag;
                num = ItemList[num2].Position;
            }
            try
            {
                List <smcMesh> list = SMCReader.ReadFile(SMCFile);
                for (int i = 0; i < list.Count <smcMesh>(); i++)
                {
                    bool flag = (num != 0 || !list[i].FileName.Contains("_hair_000")) && (num != 1 || !list[i].FileName.Contains("_bu_000")) && (num != 3 || !list[i].FileName.Contains("_bd_000")) && (num != 5 || !list[i].FileName.Contains("_hn_000")) && (num != 6 || !list[i].FileName.Contains("_ft_000"));
                    if (flag && LCMeshReader.ReadFile(list[i].FileName))
                    {
                        tMeshContainer pMesh = LCMeshReader.pMesh;
                        for (int j = 0; j < pMesh.Objects.Count <tMeshObject>(); j++)
                        {
                            int     toVert    = (int)pMesh.Objects[j].ToVert;
                            uint    arg_16B_0 = pMesh.Objects[j].FaceCount;
                            short[] faces     = pMesh.Objects[j].GetFaces();
                            CustomVertex.PositionNormalTextured[] array = new CustomVertex.PositionNormalTextured[toVert];
                            int num3 = (int)pMesh.Objects[j].FromVert;
                            int k    = 0;
                            while ((long)k < (long)((ulong)pMesh.Objects[j].ToVert))
                            {
                                array[k].Position = new Vector3(pMesh.Vertices[num3].X, pMesh.Vertices[num3].Y, pMesh.Vertices[num3].Z);
                                array[k].Normal   = new Vector3(pMesh.Normals[num3].X, pMesh.Normals[num3].Y, pMesh.Normals[num3].Z);
                                try
                                {
                                    array[k].Texture = new Vector2(pMesh.UVMaps[0].Coords[num3].U, pMesh.UVMaps[0].Coords[num3].V);
                                }
                                catch
                                {
                                    array[k].Texture = new Vector2(0f, 0f);
                                }
                                num3++;
                                k++;
                            }
                            new VertexBuffer(this.device, array.Count <CustomVertex.PositionNormalTextured>() * 32, Usage.None, VertexFormat.Position | VertexFormat.Texture1 | VertexFormat.Normal, Pool.Default);
                            Mesh       mesh = new Mesh(this.device, faces.Count <short>() / 3, array.Count <CustomVertex.PositionNormalTextured>(), MeshFlags.Managed, VertexFormat.Position | VertexFormat.Texture1 | VertexFormat.Normal);
                            DataStream dataStream2;
                            DataStream dataStream = dataStream2 = mesh.VertexBuffer.Lock(0, array.Count <CustomVertex.PositionNormalTextured>() * 32, LockFlags.None);
                            try
                            {
                                dataStream.WriteRange <CustomVertex.PositionNormalTextured>(array);
                                mesh.VertexBuffer.Unlock();
                            }
                            finally
                            {
                                if (dataStream2 != null)
                                {
                                    ((IDisposable)dataStream2).Dispose();
                                }
                            }
                            DataStream dataStream3;
                            dataStream = (dataStream3 = mesh.IndexBuffer.Lock(0, faces.Count <short>() * 2, LockFlags.None));
                            try
                            {
                                dataStream.WriteRange <short>(faces);
                                mesh.IndexBuffer.Unlock();
                            }
                            finally
                            {
                                if (dataStream3 != null)
                                {
                                    ((IDisposable)dataStream3).Dispose();
                                }
                            }
                            if (pMesh.Weights.Count <tMeshJointWeights>() != 0)
                            {
                                string[]       array2 = new string[pMesh.Weights.Count <tMeshJointWeights>()];
                                List <int>[]   array3 = new List <int> [pMesh.Weights.Count <tMeshJointWeights>()];
                                List <float>[] array4 = new List <float> [pMesh.Weights.Count <tMeshJointWeights>()];
                                for (int l = 0; l < pMesh.Weights.Count <tMeshJointWeights>(); l++)
                                {
                                    array2[l] = this.Enc.GetString(pMesh.Weights[l].JointName);
                                    array3[l] = new List <int>();
                                    array4[l] = new List <float>();
                                    for (int m = 0; m < pMesh.Weights[l].WeightsMap.Count <tMeshWeightsMap>(); m++)
                                    {
                                        array3[l].Add(pMesh.Weights[l].WeightsMap[m].Index);
                                        array4[l].Add(pMesh.Weights[l].WeightsMap[m].Weight);
                                    }
                                }
                                mesh.SkinInfo = new SkinInfo(array.Count <CustomVertex.PositionNormalTextured>(), VertexFormat.Position | VertexFormat.Texture1 | VertexFormat.Normal, (int)pMesh.HeaderInfo.JointCount);
                                for (k = 0; k < array3.Count <List <int> >(); k++)
                                {
                                    mesh.SkinInfo.SetBoneName(k, array2[k]);
                                    mesh.SkinInfo.SetBoneInfluence(k, array3[k].ToArray(), array4[k].ToArray());
                                }
                            }
                            mesh.GenerateAdjacency(0.5f);
                            mesh.ComputeNormals();
                            Texture texture = null;
                            string  objName = this.Enc.GetString(pMesh.Objects[j].Textures[0].InternalName);
                            int     num4    = list[i].Object.FindIndex((smcObject x) => x.Name.Equals(objName));
                            if (num4 != -1)
                            {
                                texture = this.GetTextureFromFile(list[i].Object[num4].Texture);
                            }
                            this.models.Add(new tMesh(mesh, texture));
                        }
                    }
                }
            }
            catch
            {
            }
            this.zoom = 4f;
        }