private void ExportModels(List <object> meshes)
        {
            string[]   fileNames = new string[meshes.Count];
            Vector3[]  filePos   = new Vector3[meshes.Count];
            Matrix33[] rotPos    = new Matrix33[meshes.Count];

            CustomEDD frameEDD = new CustomEDD();

            frameEDD.Entries = new List <CustomEDD.Entry>();

            Parallel.For(0, meshes.Count, i =>
            {
                CustomEDD.Entry entry        = new CustomEDD.Entry();
                FrameObjectSingleMesh mesh   = (meshes[i] as FrameObjectSingleMesh);
                FrameGeometry geom           = SceneData.FrameResource.FrameGeometries[mesh.Refs["Mesh"]];
                FrameMaterial mat            = SceneData.FrameResource.FrameMaterials[mesh.Refs["Material"]];
                IndexBuffer[] indexBuffers   = new IndexBuffer[geom.LOD.Length];
                VertexBuffer[] vertexBuffers = new VertexBuffer[geom.LOD.Length];

                //we need to retrieve buffers first.
                for (int c = 0; c != geom.LOD.Length; c++)
                {
                    indexBuffers[c]  = SceneData.IndexBufferPool.GetBuffer(geom.LOD[c].IndexBufferRef.uHash);
                    vertexBuffers[c] = SceneData.VertexBufferPool.GetBuffer(geom.LOD[c].VertexBufferRef.uHash);
                }

                Model newModel = new Model(mesh, indexBuffers, vertexBuffers, geom, mat);

                //if (mesh.ParentIndex1.Index != -1)
                //{
                //    FrameObjectBase parent = (SceneData.FrameResource.EntireFrame[mesh.ParentIndex1.Index] as FrameObjectBase);
                //    filePos[i] = RetrieveParent1Position(mesh);
                //}

                //if (((mesh.ParentIndex1.Index != -1)) && ((mesh.ParentIndex1.Index == mesh.ParentIndex2.Index)))
                //{
                //    FrameObjectFrame frame = SceneData.FrameResource.EntireFrame[mesh.ParentIndex1.Index] as FrameObjectFrame;
                //    if (frame.Item != null)
                //    {
                //        filePos[i] = frame.Item.Position;
                //    }
                //}

                entry.LodCount = newModel.ModelStructure.Lods.Length;
                entry.LODNames = new string[entry.LodCount];

                for (int c = 0; c != newModel.ModelStructure.Lods.Length; c++)
                {
                    newModel.ModelStructure.ExportToM2T(ToolkitSettings.ExportPath + "\\");
                    switch (ToolkitSettings.Format)
                    {
                    case 0:
                        newModel.ModelStructure.ExportToFbx(ToolkitSettings.ExportPath + "\\", false);
                        break;

                    case 1:
                        newModel.ModelStructure.ExportToFbx(ToolkitSettings.ExportPath + "\\", true);
                        break;

                    case 2:
                        newModel.ModelStructure.ExportToM2T(ToolkitSettings.ExportPath + "\\");
                        break;

                    default:
                        Log.WriteLine("Error! Unknown value set for ToolkitSettings.Format!", LoggingTypes.ERROR);
                        break;
                    }
                    Console.WriteLine(newModel.FrameMesh.Name.String);
                    if (newModel.FrameMesh.Name.String == "")
                    {
                        entry.LODNames[c] = newModel.FrameGeometry.LOD[c].VertexBufferRef.String;
                    }
                    else
                    {
                        entry.LODNames[c] = newModel.FrameMesh.Name.String;
                    }
                }
                entry.Position = mesh.Matrix.Position;
                entry.Rotation = mesh.Matrix.Rotation;

                frameEDD.Entries.Add(entry);
            });
            frameEDD.EntryCount = frameEDD.Entries.Count;
            using (BinaryWriter writer = new BinaryWriter(File.Create(ToolkitSettings.ExportPath + "\\" + "frame.edd")))
            {
                frameEDD.WriteToFile(writer);
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Insert all collisions into the editor.
        /// </summary>
        public void LoadInCollision()
        {
            treeView1.Nodes.Clear();
            for (int i = 0; i != SceneData.Collisions.NXSData.Count; i++)
            {
                Collision.NXSStruct nxsData = SceneData.Collisions.NXSData.ElementAt(i).Value;

                TreeNode node = new TreeNode(nxsData.Hash.ToString());
                node.Tag  = nxsData;
                node.Name = nxsData.Hash.ToString();


                M2TStructure model = new M2TStructure();
                model.Lods    = new Lod[1];
                model.Lods[0] = new Lod();

                ;
                model.Lods[0].Vertices = new Vertex[nxsData.Data.Vertices.Length];

                for (int x = 0; x != model.Lods[0].Vertices.Length; x++)
                {
                    model.Lods[0].Vertices[x]          = new Vertex();
                    model.Lods[0].Vertices[x].Position = nxsData.Data.Vertices[x];
                }

                List <CollisionMaterials> typeList = new List <CollisionMaterials>();
                List <List <Short3> >     values   = new List <List <Short3> >();

                for (int x = 0; x != nxsData.Data.Materials.Length; x++)
                {
                    CollisionMaterials[] mats = nxsData.Data.Materials;
                    Int3[] triangles          = nxsData.Data.Triangles;

                    if (!typeList.Contains(mats[x]))
                    {
                        typeList.Add(mats[x]);
                        values.Add(new List <Short3>());
                        values[typeList.Count - 1].Add(new Short3(triangles[x]));
                    }
                    else
                    {
                        for (int y = 0; y != typeList.Count; y++)
                        {
                            if (typeList[y] == mats[x])
                            {
                                values[y].Add(new Short3(triangles[x]));
                            }
                        }
                    }
                }

                model.Lods[0].Parts = new ModelPart[typeList.Count];

                for (int x = 0; x != typeList.Count; x++)
                {
                    model.Lods[0].Parts[x]          = new ModelPart();
                    model.Lods[0].Parts[x].Indices  = values[x].ToArray();
                    model.Lods[0].Parts[x].Material = typeList[x].ToString();
                }

                model.ExportCollisionToM2T(node.Name);
                treeView1.Nodes.Add(node);
            }

            CustomEDD frame = new CustomEDD();

            for (int i = 0; i != SceneData.Collisions.Placements.Count; i++)
            {
                Collision.Placement data  = SceneData.Collisions.Placements[i];
                CustomEDD.Entry     entry = new CustomEDD.Entry();

                entry.LodCount    = 1;
                entry.LODNames    = new string[1];
                entry.LODNames[0] = data.Hash.ToString();
                entry.Position    = data.Position;
                entry.Rotation    = new Matrix33();

                for (int x = 0; x != treeView1.Nodes.Count; x++)
                {
                    if (data.Hash.ToString() == treeView1.Nodes[x].Name)
                    {
                        TreeNode node = new TreeNode(treeView1.Nodes[x].Nodes.Count + 1.ToString());
                        node.Tag  = data;
                        node.Name = treeView1.Nodes[x].Nodes.Count + 1.ToString();

                        treeView1.Nodes[x].Nodes.Add(node);
                    }
                }
                frame.Entries.Add(entry);
            }
            frame.EntryCount = frame.Entries.Count;
            using (BinaryWriter writer = new BinaryWriter(File.Create("collisions/frame.edd")))
            {
                frame.WriteToFile(writer);
            }
        }