Exemplo n.º 1
0
        private void toolStripMenuItem2_Click(object sender, EventArgs e)
        {
            F_NGN lev = TabControl.GetLevel();

            if (lev != null)
            {
                ColorDialog cd = new ColorDialog {
                    FullOpen = true
                };
                if (cd.ShowDialog() == DialogResult.OK)
                {
                    foreach (Character chr in lev.characters)
                    {
                        foreach (Shape shape in chr.shapes)
                        {
                            for (int i = 0; i < shape.rawVertexShading.Count; i++)
                            {
                                shape.rawVertexShading[i] = cd.Color;
                                shape.rawVertexData[i]    = new Vector3();
                            }
                        }
                    }
                }
            }
        }
Exemplo n.º 2
0
        private void allShapesInSelectedLevelToolStripMenuItem_Click(object sender, EventArgs e)
        {
            List <F_NGN> lev = new List <F_NGN>();

            lev.Add(TabControl.GetLevel(tabControl1.SelectedIndex));
            Globals.gMMaterials.AddRange(F_NGN.GetMaterialsFromLevels(lev, toolStripComboBoxMatSel.SelectedIndex));
        }
Exemplo n.º 3
0
        private void generateNameMapToolStripMenuItem_Click(object sender, EventArgs e)
        {
            F_NGN         lev = TabControl.GetLevel();
            StringBuilder sb  = new StringBuilder();

            if (lev != null)
            {
                Geometry geom = lev.Geometries[0];
                for (int i = 0; i < geom.shapes.Count; i++)
                {
                    if (i < 3)
                    {
                        geom.shapes[i].name = "Buzz";
                    }
                    else if (i > 2 && i < 8)
                    {
                        geom.shapes[i].name = "OOB Token";
                    }
                    else
                    {
                        geom.shapes[i].name = "Geometry" + i;
                    }
                    sb.Append(i.ToString() + " : " + geom.shapes[i].name + "\n");
                }
            }
            Console.WriteLine(sb.ToString());
        }
        public void ImportShape(ref Shape shape, ref F_NGN NGN, string altname = "", bool isMultiMat = false)
        {
            dgvShapeData.ignoreCellValueChanged = true; //we arent gonna be saving any changes while loading, and this is a good idea, i think
            groupMaterialProperties.SuspendLayout();
            t2Control_TextureSelector1.SuspendLayout();
            if (!isMultiMat)
            {
                Shape[] sp = new Shape[1];
                sp[0]        = shape;
                loadedShapes = sp;
                loadedShape  = shape;
            }
            loadedNGN = NGN;

            fieldShapeName.Text       = (shape.name == "") ? (altname == "") ? "<Untitled>" : altname : shape.name;
            numericCharShapeID.Value  = shape.type;
            numericCharShapeID2.Value = shape.type2;

            if (loadedNGN.textures.Count > 0)
            {
                t2Control_TextureSelector1.Init(loadedNGN.textures);
            }
            groupMaterialProperties.Visible = false;
            comboMaterial.Items.Clear();
            if (shape.materials.Count > 0)
            {
                for (int i = 0; i < shape.materials.Count; i++)
                {
                    comboMaterial.Items.Add("Material " + i);
                }
                comboMaterial.SelectedIndex = 0;
            }

            dgvShapeData.Rows.Clear();
            comboPrimitive.Items.Clear();
            if (shape.rawPrimitives.Count > 0)
            {
                int i = 0;
                foreach (IPrimitive prim in shape.rawPrimitives)
                {
                    comboPrimitive.Items.Add((prim.PrimType == typeof(Prim) ? "Prim " : "Patch ") + i);
                    i++;
                }
                comboPrimitive.SelectedIndex = -1;
                comboPrimitive.SelectedIndex = 0;
            }
            groupMaterialProperties.ResumeLayout();
            t2Control_TextureSelector1.ResumeLayout();
            Application.DoEvents();
            UpdateShapeDataUI(true);
        }
Exemplo n.º 5
0
        private void findMaterialsThatUseTextureOfNameToolStripMenuItem_Click(object sender, EventArgs e)
        {
            F_NGN lev = TabControl.GetLevel();

            if (lev != null)
            {
                InputDialog   id         = new InputDialog();
                List <string> tlocations = new List <string>();
                if (id.ShowDialog() == DialogResult.OK)
                {
                    string inp      = id.input;
                    int    reltexid = lev.TexNameToGlobalID(inp);
                    foreach (Character chr in lev.characters)
                    {
                        foreach (Shape shape in chr.shapes)
                        {
                            for (int i = 0; i < shape.materials.Count; i++)
                            {
                                if (shape.materials[i].textureIndexRelative == reltexid)
                                {
                                    tlocations.Add(String.Format("Found Texture : {0} > {1} > Material {2}", chr.name, (shape.name == "") ? "<Shape" + i + ">" : shape.name, i));
                                }
                            }
                        }
                    }
                    foreach (Geometry geo in lev.Geometries)
                    {
                        for (int s = 0; s < geo.shapes.Count; s++)
                        {
                            Shape shape = geo.shapes[s];
                            for (int i = 0; i < shape.materials.Count; i++)
                            {
                                if (shape.materials[i].textureIndexRelative == reltexid)
                                {
                                    tlocations.Add(String.Format("Found Texture : {0} > {1} > Material {2}", geo.name, (shape.name == "")? "<Shape" + i + ">" : shape.name, i));
                                }
                            }
                        }
                    }
                    SessionManager.Report("Search for " + inp + " in level returned " + tlocations.Count + " results :\n" + string.Join("\n", tlocations));
                }
            }
        }
Exemplo n.º 6
0
        private void validateSaveToolStripMenuItem_Click(object sender, EventArgs e)
        {
            SaveFileDialog sfd = new SaveFileDialog();

            if (sfd.ShowDialog() == DialogResult.OK)
            {
                SessionManager.Report("Writing to save...", SessionManager.RType.DEBUG);
                SaveFile(TabControl.Tabs[tabControl1.SelectedIndex].File.FilePath);
            }
            F_NGN loadedNGN = (F_NGN)TabControl.Tabs[tabControl1.SelectedIndex].File;
            F_NGN validater = (F_NGN)FileProcessor.ProcessFile(TabControl.Tabs[tabControl1.SelectedIndex].File.FilePath);

            SessionManager.Report("Validating save file...", SessionManager.RType.DEBUG);
            for (int i = 0; i < loadedNGN.Schema.NGNFunctions.Count; i++)
            {
                bool val = loadedNGN.Schema.NGNFunctions[i].FunctionOffset == validater.Schema.NGNFunctions[i].FunctionOffset;
                SessionManager.Report(Enum.GetName(typeof(F_NGN.NGNFunction), loadedNGN.Schema.NGNFunctions[i].FunctionType) + ((val) ? " successfully validated" : " did not validate succesfully"), ((val) ? SessionManager.RType.DEBUG : SessionManager.RType.WARN));//, Color.DarkGreen);
            }
        }
Exemplo n.º 7
0
        /// <summary>Process and Return a file based on a file path. Returns <seealso cref="F_Base"/>, you MUST cast it yourself using the correct cast.</summary>
        /// <param name="path"></param>
        public static F_Base ProcessFile(string path)
        {
            string ext = Path.GetExtension(path).ToLower();
            F_Base file;

            if (ext == ".ngn")
            {
                file = new F_NGN().Import(path);
            }
            else if (ext == ".sav")
            {
                file = F_Save.ImportSave(path);
            }
            else
            {
                //throw new TypeInitializationException("None", null);
                file = null;
            }
            return(file);
        }
Exemplo n.º 8
0
        private void fromSelectedShapeInSelectedLevelToolStripMenuItem_Click(object sender, EventArgs e)
        {
            //agh this is gonna be rough, we need a handle to the editor in the selected tab, to access to both the char and geom selectors
            //unlike in the other func, we cannot use GetMaterialsFromLevels, as this is too specific :(
            //get ready...
            T2Control_NGNEditor editor = ((T2Control_NGNEditor)TabControl.Tabs[tabControl1.SelectedIndex].editor.main);
            F_NGN file = (F_NGN)TabControl.Tabs[tabControl1.SelectedIndex].File;

            if (toolStripComboBoxMatSel.SelectedIndex == 0 || toolStripComboBoxMatSel.SelectedIndex == 1)
            {
                for (int i = 0; i < editor.listCharShapes.SelectedItems.Count; i++)
                {
                    Globals.gMMaterials.AddRange(file.characters[editor.comboCharacters.SelectedIndex].shapes[editor.listCharShapes.SelectedIndices[i]].materials);
                }
            }
            if (toolStripComboBoxMatSel.SelectedIndex == 0 || toolStripComboBoxMatSel.SelectedIndex == 2)
            {
                for (int i = 0; i < editor.listGeomShapes.SelectedItems.Count; i++)
                {
                    Globals.gMMaterials.AddRange(file.Geometries[editor.comboGeometry.SelectedIndex].shapes[editor.listGeomShapes.SelectedIndices[i]].materials);
                }
            }
        }
Exemplo n.º 9
0
        public static F_Base CreateFile(FileTypes fileType, TabController tabController, string fileName = "")
        {
            F_Base file;

            if (fileType == FileTypes.NGN)
            {
                file = new F_NGN();
            }
            else if (fileType == FileTypes.Save)
            {
                file = new F_Save(true);
            }
            else
            {
                file = null;
                throw new TypeInitializationException("None", null);
            }
            if (fileName == "")
            {
                file.TempName = TabController.CalculateUntitledTabName(fileType, tabController);
            }
            return(file);
        }
Exemplo n.º 10
0
        private void setAllShadingToColorToolStripMenuItem_Click(object sender, EventArgs e)
        {
            F_NGN lev = TabControl.GetLevel();

            if (lev != null)
            {
                ColorDialog cd = new ColorDialog {
                    FullOpen = true
                };
                if (cd.ShowDialog() == DialogResult.OK)
                {
                    foreach (Geometry geom in lev.Geometries)
                    {
                        foreach (Shape shape in geom.shapes)
                        {
                            for (int i = 0; i < shape.rawVertexShading.Count; i++)
                            {
                                shape.rawVertexShading[i] = cd.Color;
                            }
                        }
                    }
                }
            }
        }
Exemplo n.º 11
0
 private void allOpenedLevelsToolStripMenuItem_Click(object sender, EventArgs e)
 {
     Globals.gMMaterials.AddRange(F_NGN.GetMaterialsFromLevels(TabControl.GetAllLevels(), toolStripComboBoxMatSel.SelectedIndex));
 }
Exemplo n.º 12
0
        //public Character ProcessOBJ2(string filepath) {
        //    ObjLoaderFactory OBJLF = new ObjLoaderFactory();
        //    var objl = OBJLF.Create();

        //    FileStream fs = new FileStream(filepath, System.IO.FileMode.Open);

        //    var Model = objl.Load(fs);
        //    fs.Close();


        //    //begin processing
        //    Character chr = new Character { name = Path.GetFileNameWithoutExtension(filepath) };
        //    int MajorOffset = 0;
        //    foreach (Group g in Model.Groups) {
        //        Shape shape = new Shape();
        //        shape.rawVertices = ConvertCJCVectorsToVector3((List<Vertex>)Model.Vertices);
        //        shape.textures.Add(Path.GetFileNameWithoutExtension(g.Material.DiffuseTextureMap));
        //        shape.name = g.Name;
        //        shape.type = 1;

        //        //we have all the vertices
        //        //now we parse them into primitives aka faces
        //        int VertexCount = 0;
        //        foreach (Face face in g.Faces) {
        //            Prim prim = new Prim();
        //            for (int i = 0;i < face._vertices.Count;i++) {
        //                prim.vertices.Add(i);
        //                VertexCount++;
        //            }
        //            shape.rawPrimitives.Add(prim);
        //        }

        //        foreach (Face face in g.Faces) {
        //            foreach (FaceVertex fv in face._vertices) {
        //                int v3df = (VertexCount - Math.Abs(fv.VertexIndex)) + MajorOffset;
        //                shape.rawVertices.Add(new Vector3(Model.Vertices[v3df].X, Model.Vertices[v3df].Y, Model.Vertices[v3df].Z));
        //                //shape.rawVertexTextureCoords.Add(new Vector2(Model.TextureCoords[v3df].X, Model.TextureCoords[v3df].Y));
        //            }
        //        }


        //        MajorOffset += VertexCount;
        //        chr.shapes.Add(shape);

        //    }
        //    return chr;
        //}

        public void ProcessOBJ(string filepath, bool imp_textures, bool imp_materials, bool imp_names, Vector3 imp_translation)
        {
            Obj obj = new Obj();

            obj.LoadObj(filepath);
            Mtl mat = new Mtl();

            mat.LoadMtl(obj.Mtl);

            //for (int i = 0;i < obj.FaceList.Count;i++) {
            //    Shape shape = new Shape();
            //    //shape.name = obj.GroupNames[i];
            //    shape.rawVertices = objptoshapes(obj, obj.FaceList[i]);
            //    importedCharacter.shapes.Add(new Shape());
            //}


            //a note from the Obj class, when we parse in the obj file, its entirely likely that the obj will have no groups or objects
            //this is a problem as this is so rudimentary that we rely on them existing to build our shape DB
            //the parser takes care of that for us, and regardless of whether or not the .OBJ file has a group or object,
            //a default object and group is made to store all the data in, so...yeah...
            //tl;dr, Objects[0].groups[0] will always exist regardless of whats imported.


            int vOffset      = 0;
            int vAccumulator = 0;

            for (int i = 0; i < obj.Objects.Count; i++)//for each shape...
            {
                Obj.obj o     = obj.Objects[i];
                Shape   shape = new Shape();
                shape.name = (!imp_names || o.name == null) ? "" : o.name;
                foreach (Vertex v in o.vertexList)
                {
                    shape.rawVertices.Add(new Vector3((float)v.X, (float)v.Y, (float)v.Z));
                    shape.rawVertexShading.Add((v.color == null) ? System.Drawing.Color.Black : F_NGN.VColorToColor(v.color.ToArrayFloat()));
                }
                Matrix4D GTMF = new Matrix4D();
                imp_translation.SetMatrix4DNegative(GTMF, imp_translation);
                Vector3.TransformPoints(GTMF, ref shape.rawVertices);
                foreach (TextureVertex t in o.textureList)
                {
                    shape.rawVertexTextureCoords.Add(new Vector3((float)t.X, (float)t.Y, 0.0f));
                }
                for (int j = 0; j < o.groups.Count; j++)//for each prim...
                {
                    Obj.gf g    = o.groups[j];
                    Prim   prim = new Prim();
                    if (g.faces[0].VertexIndexList.Count() == 4)
                    {
                        prim.type = 4;
                    }
                    else
                    {
                        prim.type = 1;
                    };
                    if (imp_materials)
                    {
                        ObjParser.Types.Material usemtl = GetUsemtl(g.materialName, mat);
                        Material material = new Material {
                            id  = (usemtl.Opacity == 1) ? 129 : 193,
                            RGB = usemtl.DiffuseReflectivity.ToArrayDouble().ToList()
                        };
                        if (imp_textures)
                        {
                            material.textureName = usemtl.DiffuseMap.Split('.')[0];
                        }
                        shape.AddMaterial(material);
                    }
                    for (int k = 0; k < g.faces.Count; k++) // for each face... (3/4 points thing this is whats actually the prim, its weird i know)
                    {
                        Face f = g.faces[k];
                        for (int l = 0; l < f.VertexIndexList.Length; l++)//for each vertex, of each face, of each primitive inside this root shape...
                        {
                            prim.vertices.Add((f.VertexIndexList[l] - 1) - vOffset);
                            vAccumulator++;
                        }
                    }
                    shape.rawPrimitives.Add(prim);
                }
                shape.rawVertexData = (List <Vector3>)XF.GenerateListData(1, shape.rawVertices.Count, new Vector3(0, 0, 0));
                shape.type          = 5;
                shape.type2         = 65535;
                importedCharacter.shapes.Add(shape);
                vOffset     += vAccumulator;
                vAccumulator = 0;
            }


            //for (int i = 0;i < obj.GroupFaces.Count;i++) {
            //    Shape shape = new Shape();
            //    shape.name = obj.GroupFaces[i].name;
            //    List<int> vertices = new List<int>();
            //    for (int j = 0;j < obj.GroupFaces[i].faces.Count;j++) {
            //        ObjParser.Types.Face face = obj.GroupFaces[i].faces[j];
            //        Prim prim = new Prim();
            //        prim.type = face.VertexIndexList.Count();
            //        for (int k = 0;k < face.VertexIndexList.Length;k++) {
            //            int v = Math.Abs(face.VertexIndexList[k]) - 1;
            //            prim.vertices.Add(v);
            //            vertices.Add(v);
            //        }
            //        shape.rawPrimitives.Add(prim);
            //    }
            //    for (int j = 0;j < vertices.Count;j++) {
            //        ObjParser.Types.Vertex vertex = obj.VertexList[vertices[j]];
            //        shape.rawVertices.Add(new Vector3((float)vertex.X, (float)vertex.Y, (float)vertex.Z));
            //    }
            //    shape.rawVertexData = (List<Vector3>)XF.GenerateListData(1, shape.rawVertices.Count, new Vector3(0, 0, 0));
            //    shape.rawVertexShading = (List<System.Drawing.Color>)XF.GenerateListData(1, shape.rawVertices.Count, System.Drawing.Color.FromArgb(255, 0, 0, 0));
            //    shape.rawVertexTextureCoords = (List<Vector3>)XF.GenerateListData(1, shape.rawVertices.Count, new Vector3(0, 0, 0));
            //    shape.type = 5;
            //    shape.type2 = 65535;
            //    importedCharacter.shapes.Add(shape);
            //}
        }