Esempio n. 1
0
        public TournamentDef Clone()
        {
            TournamentDef clone = ObjUtils.DeepClone <TournamentDef>(this);

            clone.Logger = this.Logger;
            return(clone);
        }
Esempio n. 2
0
        /// <summary>
        /// Delete every unused material the obj file
        /// </summary>
        /// <param name="objData">Data parsed from the obj file</param>
        /// <param name="mtlData">Data parsed from the mtl file</param>
        public static bool DeleteUnusedMaterials(ObjData objData, MtlData mtlData)
        {
            if (mtlData == null)
            {
                return(false);
            }

            // Dictionary that associate every material to a list of groups
            Dictionary <string, List <int> > dictMaterialGroups = ObjUtils.GetDictMaterialGroups(objData);

            // Dictionary that associate every material of the mtl file to their index
            Dictionary <string, int> dictMaterialIndex = MtlUtils.GetDictMaterialIndex(mtlData);

            List <MaterialMtl> newMaterialsList = new List <MaterialMtl>();

            foreach (KeyValuePair <string, List <int> > keyValue in dictMaterialGroups)
            {
                if (dictMaterialIndex.TryGetValue(keyValue.Key, out int index)) // We get the index of the material
                {
                    MaterialMtl materialMtl = mtlData.MaterialsList[index];
                    newMaterialsList.Add(materialMtl);
                }
            }

            // Every material that wasnt used in a group was not added to the list
            mtlData.MaterialsList = newMaterialsList;
            return(true);
        }
Esempio n. 3
0
        public void DumpComparison(TextWriter writer, GameEngineDefCeres other, bool differentOnly = true)
        {
            writer.WriteLine("\r\n-----------------------------------------------------------------------");
            writer.WriteLine("Evaluator 1     : " + EvaluatorDef);
            writer.WriteLine("Evaluator 2     : " + other.EvaluatorDef);
            writer.WriteLine("Time Manager 1  : " + (OverrideTimeManager == null ? "(default)" : OverrideTimeManager));
            writer.WriteLine("Time Manager 2  : " + (other.OverrideTimeManager == null ? "(default)" : other.OverrideTimeManager));
            writer.WriteLine("Postprocessor 1 : " + (ParamsSearchExecutionPostprocessor == null ? "(none)" : "Present"));
            writer.WriteLine("Postprocessor 2 : " + (other.ParamsSearchExecutionPostprocessor == null ? "(none)" : "Present"));
            writer.WriteLine();

            writer.WriteLine("ENGINE 1 Options Modifications from Default");

            writer.Write(ObjUtils.FieldValuesDumpString <ParamsSelect>(SelectParams, new ParamsSelect(), differentOnly));
            writer.Write(ObjUtils.FieldValuesDumpString <ParamsSearch>(SearchParams, new ParamsSearch(), differentOnly));
            //      ParamsDump.DumpTimeManagerDifference(false, null, OverrideTimeManager);
            writer.Write(ObjUtils.FieldValuesDumpString <ParamsSearchExecution>(SearchParams.Execution, new ParamsSearchExecution(), differentOnly));


            writer.WriteLine("\r\n-----------------------------------------------------------------------");
            writer.WriteLine("ENGINE 2 Options Modifications from Engine 1");

            writer.Write(ObjUtils.FieldValuesDumpString <ParamsSelect>(other.SelectParams, SelectParams, differentOnly));
            writer.Write(ObjUtils.FieldValuesDumpString <ParamsSearch>(other.SearchParams, SearchParams, differentOnly));
            //      ParamsDump.DumpTimeManagerDifference(differentOnly, OverrideTimeManager, other.OverrideTimeManager);
            writer.Write(ObjUtils.FieldValuesDumpString <ParamsSearchExecution>(SearchParams.Execution, other.SearchParams.Execution, differentOnly));
            writer.WriteLine();
        }
Esempio n. 4
0
    void Awake()
    {
//#if !UNITY_EDITOR
//        this.enabled = false;
//        return;
//#endif
        canvas      = GameObject.FindGameObjectWithTag("demo").GetComponent <Canvas>();
        logText     = ObjUtils.FindChild <Text>(canvas.transform, "LogTxt");
        atlasBtn    = ObjUtils.FindChild <Button>(canvas.transform, "atlasBtn");
        sceneBtn    = ObjUtils.FindChild <Button>(canvas.transform, "sceneBtn");
        sourceBtn   = ObjUtils.FindChild <Button>(canvas.transform, "sourceBtn");
        configBtn   = ObjUtils.FindChild <Button>(canvas.transform, "configBtn");
        uiBtn       = ObjUtils.FindChild <Button>(canvas.transform, "uiBtn");
        modelBtn    = ObjUtils.FindChild <Button>(canvas.transform, "modelBtn");
        eventBtn    = ObjUtils.FindChild <Button>(canvas.transform, "eventBtn");
        wwwImageBtn = ObjUtils.FindChild <Button>(canvas.transform, "wwwImageBtn");
        cameraBtn   = ObjUtils.FindChild <Button>(canvas.transform, "cameraBtn");

        logText.text = "";
        logBuilder   = new StringBuilder();

        atlasBtn.onClick.AddListener(AtlasTest);
        sceneBtn.onClick.AddListener(() => { StartCoroutine(SceneTest()); });
        sourceBtn.onClick.AddListener(SourceTest);
        configBtn.onClick.AddListener(ConfigTest);
        uiBtn.onClick.AddListener(UITest);
        modelBtn.onClick.AddListener(ModelTest);
        eventBtn.onClick.AddListener(EventTest);


        wwwImageBtn.onClick.AddListener(() => {
            Image img = wwwImageBtn.GetComponentInChildren <Image>();
            WWWEngine.SetGameAsyncImage(img, "http://u3d-model.oss-cn-beijing.aliyuncs.com/model/Res/Ver3/testimg.jpg");
        });
    }
Esempio n. 5
0
        private void WritePlayerModel()
        {
            if (_settings.Character == Character.LinkMM)
            {
                return;
            }

            int characterIndex = (int)_settings.Character;

            using (var b = new BinaryReader(File.Open($"{Values.ObjsDirectory}link-{characterIndex}", FileMode.Open)))
            {
                var obj = new byte[b.BaseStream.Length];
                b.Read(obj, 0, obj.Length);

                ResourceUtils.ApplyHack($"{Values.ModsDirectory}fix-link-{characterIndex}");
                ObjUtils.InsertObj(obj, 0x11);
            }

            if (_settings.Character == Character.Kafei)
            {
                using (var b = new BinaryReader(File.Open($"{Values.ObjsDirectory}kafei", FileMode.Open)))
                {
                    var obj = new byte[b.BaseStream.Length];
                    b.Read(obj, 0, obj.Length);

                    ObjUtils.InsertObj(obj, 0x1C);
                    ResourceUtils.ApplyHack(Values.ModsDirectory + "fix-kafei");
                }
            }
        }
Esempio n. 6
0
        /// <summary>
        /// Rename every material from the obj and mtl to make them unique after the merge
        /// </summary>
        /// <param name="objData"></param>
        /// <param name="mtlData"></param>
        /// <param name="indexMaterial"></param>
        private static void SetUniqueMaterialsNames(ObjData objData, MtlData mtlData, IntWrapper indexMaterial)
        {
            // Dictionary that associate every material to a list of groups
            Dictionary <string, List <int> > dictMaterialGroups = ObjUtils.GetDictMaterialGroups(objData);

            if (mtlData == null) // Need to rename the Materials in obj only
            {
                foreach (KeyValuePair <string, List <int> > keyValue in dictMaterialGroups)
                {
                    SetUniqueMaterialsName(objData, keyValue.Value, indexMaterial);
                    indexMaterial.Value++;
                }
            }
            else // Need to rename the Materials in both obj and mtl
            {
                // Dictionary that associate every material of the mtl file to their index
                Dictionary <string, int> dictMaterialIndex = MtlUtils.GetDictMaterialIndex(mtlData);

                foreach (KeyValuePair <string, List <int> > keyValue in dictMaterialGroups)
                {
                    SetUniqueMaterialsName(objData, keyValue.Value, indexMaterial);

                    if (dictMaterialIndex.TryGetValue(keyValue.Key, out int index)) // We get the index of the material
                    {
                        MaterialMtl materialMtl = mtlData.MaterialsList[index];
                        if (materialMtl.NewMtl != null)
                        {
                            materialMtl.NewMtl = GenericUtils.MergeIndexStr(indexMaterial.Value, materialMtl.NewMtl);
                        }
                    }
                    indexMaterial.Value++;
                }
            }
        }
Esempio n. 7
0
 public static void ReadEnemyList()
 {
     EnemyList = new List<Enemy>();
     string[] lines = Properties.Resources.ENEMIES.Split(new[] { "\r\n", "\r", "\n" }, StringSplitOptions.None);
     int i = 0;
     while (i < lines.Length)
     {
         if (lines[i].StartsWith("-"))
         {
             i++;
             continue;
         }
         Enemy e = new Enemy();
         e.Actor = Convert.ToInt32(lines[i], 16);
         e.Object = Convert.ToInt32(lines[i + 1], 16);
         e.ObjectSize = ObjUtils.GetObjSize(e.Object);
         string[] varlist = lines[i + 2].Split(',');
         for (int j = 0; j <  varlist.Length; j++)
         {
             e.Variables.Add(Convert.ToInt32(varlist[j], 16));
         }
         e.Type = Convert.ToInt32(lines[i + 3], 16);
         e.Stationary = Convert.ToInt32(lines[i + 4], 16);
         if (lines[i + 5] != "")
         {
             string[] selist = lines[i + 5].Split(',');
             for (int j = 0; j < selist.Length; j++)
             {
                 e.SceneExclude.Add(Convert.ToInt32(selist[j], 16));
             }
         }
         EnemyList.Add(e);
         i += 6;
     }
 }
    /// <summary>
    /// 停止特定的音效
    /// </summary>
    /// <param name="audioname"></param>
    public void SoundStop(string audioname)
    {
        GameObject obj = ObjUtils.FindChild(this.transform, "audioname").gameObject;

        if (obj != null)
        {
            Destroy(obj);
        }
    }
Esempio n. 9
0
        /// <summary>
        /// Patch object data for new color values.
        /// </summary>
        public void PatchObjects()
        {
            var playerActor = RomData.MMFileList[38];

            PatchHumanEnergyColors(ObjUtils.GetObjectData(1));
            PatchDekuEnergyColors(playerActor.Data);
            PatchGoronEnergyColors(ObjUtils.GetObjectData(0x14C));
            PatchZoraEnergyColors(ObjUtils.GetObjectData(0x14D));
            PatchFierceDeityEnergyColors(playerActor.Data);
        }
Esempio n. 10
0
    /// <summary>
    /// 查找子物体 返回Transform
    /// </summary>
    public Transform FindChild(string goName)
    {
        if (mFrame == null || string.IsNullOrEmpty(goName))
        {
            return(null);
        }

        Transform go = ObjUtils.FindChild(mFrame.transform, goName);

        return(go);
    }
Esempio n. 11
0
        /// <summary>
        /// Return one object from the obj file
        /// </summary>
        /// <param name="listKeysValues"></param>
        /// <param name="allVertices"></param>
        /// <param name="startIndex"></param>
        /// <param name="endIndex"></param>
        /// <returns></returns>
        private static ObjectObj ObjectData(List <Tuple <string, string> > listKeysValues, AllVerticesDataObj allVertices,
                                            int startIndex, int endIndex)
        {
            LocalIndexesObj indexesObj = new LocalIndexesObj();
            ObjectObj       objectObj  = new ObjectObj();
            int             i          = startIndex;

            while (i < endIndex)
            {
                Tuple <string, string> keyValue = listKeysValues[i];
                if (keyValue != null)
                {
                    string key   = keyValue.Item1;
                    string value = keyValue.Item2.TrimEnd('\0').Trim(); // Remove the null character and any blank space
                    if (ObjUtils.IsVertData(key))                       // f
                    {
                        VerticeData(value, objectObj, allVertices, indexesObj);
                    }
                    else // Other key (o, g, s, usemtl)
                    {
                        switch (key)
                        {
                        case "usemtl":
                            objectObj.MaterialName = value;
                            break;

                        case "o":
                            objectObj.ObjectName = value;
                            break;

                        case "g":
                            objectObj.GroupName = value;
                            break;

                        case "s":
                            if (value != "off")
                            {
                                if (Int32.TryParse(value, out int s))
                                {
                                    objectObj.Smooth = s;
                                }
                            }
                            break;

                        default:
                            break;
                        }
                    }
                }
                i++;
            }
            return(objectObj);
        }
Esempio n. 12
0
 /// <summary>
 /// Constructor.
 /// </summary>
 public GameEngineDefCeres(string id, NNEvaluatorDef evaluatorDef, ParamsSearch searchParams = null,
                           ParamsSearchExecutionModifier paramsSearchExecutionPostprocessor  = null,
                           ParamsSelect selectParams = null, IManagerGameLimit overrideTimeManager = null)
     : base(id)
 {
     // Make a defensive clone of the EvaluatorDef so it will definitely not be shared.
     EvaluatorDef = ObjUtils.DeepClone(evaluatorDef);
     SearchParams = searchParams ?? new ParamsSearch();
     ParamsSearchExecutionPostprocessor = paramsSearchExecutionPostprocessor;
     SelectParams        = selectParams ?? new ParamsSelect();
     OverrideTimeManager = overrideTimeManager;
 }
Esempio n. 13
0
    /// <summary>
    /// 查找子物体(递归查找)  where T : UnityEngine.Object
    /// </summary>
    public T FindChild <T>(Transform parent, string goName) where T : UnityEngine.Object
    {
        T go = null;

        if (mFrame == null || string.IsNullOrEmpty(goName))
        {
            return(null);
        }
        if (parent != null)
        {
            go = ObjUtils.FindChild <T>(parent, goName);
        }
        else
        {
            go = ObjUtils.FindChild <T>(mFrame.transform, goName);
        }
        return(go);
    }
Esempio n. 14
0
        /// <summary>
        /// Constructor.
        /// </summary>
        /// <param name="id"></param>
        /// <param name="evaluatorDef"></param>
        /// <param name="forceDisableSmartPruning"></param>
        /// <param name="searchParamsEmulate"></param>
        /// <param name="selectParamsEmulate"></param>
        /// <param name="overrideEXE"></param>
        /// <param name="extraCommandLineArgs"></param>
        public GameEngineDefLC0(string id,
                                NNEvaluatorDef evaluatorDef,
                                bool forceDisableSmartPruning,
                                ParamsSearch searchParamsEmulate = null,
                                ParamsSelect selectParamsEmulate = null,
                                string overrideEXE          = null,
                                string extraCommandLineArgs = null)
            : base(id)
        {
            if ((SearchParamsEmulate == null) != (SelectParamsEmulate == null))
            {
                throw new ArgumentException("SearchParamsEmulate and SelectParamsEmulate must be both provided or not");
            }

            // Verify compatability of evaluator for LC0
            if (evaluatorDef == null)
            {
                throw new ArgumentNullException(nameof(evaluatorDef));
            }
            if (evaluatorDef.Nets.Length != 1)
            {
                throw new Exception("Exactly one network must be specified for use with LC0.");
            }
            if (evaluatorDef.Nets[0].Net.Type != NNEvaluatorType.LC0Library)
            {
                throw new Exception("Network Type must be LC0Library");
            }
            if (evaluatorDef.NetCombo != NNEvaluatorNetComboType.Single)
            {
                throw new Exception("Network Type must be Single");
            }

            ID = id;

            // Make a defensive clone of the EvaluatorDef so it will definitely not be shared.
            EvaluatorDef = ObjUtils.DeepClone(evaluatorDef);

            ForceDisableSmartPruning = forceDisableSmartPruning;

            SearchParamsEmulate  = searchParamsEmulate;
            SelectParamsEmulate  = selectParamsEmulate;
            OverrideEXE          = overrideEXE;
            ExtraCommandLineArgs = extraCommandLineArgs;
        }
Esempio n. 15
0
    /**
     * 添加到父级
     */
    public void addToParent()
    {
        if (_myParent == null || this.Frame == null)
        {
            return;
        }
        Transform transform = ObjUtils.FindChild(_myParent.transform, "Camera");

        //Transform transform = _myParent.transform;
        if (transform == null)
        {
            Debug.Log(" Camera == null");
        }
        this.Frame.transform.SetParent(transform);
        this.Frame.GetComponent <RectTransform>().offsetMax = Vector3.zero;
        this.Frame.GetComponent <RectTransform>().offsetMin = Vector3.zero;
        this.Frame.transform.localScale    = Vector3.one;
        this.Frame.transform.localPosition = Vector3.zero;
    }
Esempio n. 16
0
        private Character DeterminePlayerModel()
        {
            var data = ObjUtils.GetObjectData(0x11);

            if (data[0x107] == 0x05)
            {
                return(Character.LinkMM);
            }
            if (data[0x107] == 0x07)
            {
                return(Character.LinkOOT);
            }
            if (data[0xC6] == 0x02)
            {
                return(Character.AdultLink);
            }
            if (data[0xC5] == 0x15)
            {
                return(Character.Kafei);
            }
            throw new InvalidOperationException("Unable to determine player's model.");
        }
Esempio n. 17
0
        private void WriteTunicColor()
        {
            Color t = _settings.TunicColor;

            byte[] color = { t.R, t.G, t.B };

            var otherTunics = ResourceUtils.GetAddresses(Values.AddrsDirectory + "tunic-forms");

            TunicUtils.UpdateFormTunics(otherTunics, _settings.TunicColor);

            var playerModel    = DeterminePlayerModel();
            var characterIndex = (int)playerModel;
            var locations      = ResourceUtils.GetAddresses($"{Values.AddrsDirectory}tunic-{characterIndex}");
            var objectIndex    = playerModel == Character.Kafei ? 0x1C : 0x11;
            var objectData     = ObjUtils.GetObjectData(objectIndex);

            for (int j = 0; j < locations.Count; j++)
            {
                ReadWriteUtils.WriteFileAddr(locations[j], color, objectData);
            }
            ObjUtils.InsertObj(objectData, objectIndex);
        }
Esempio n. 18
0
        /// <summary>
        /// Create the obj and mtl files with the given data
        /// </summary>
        /// <param name="wrlData">Data parsed from the wrl file</param>
        /// <param name="objFilename">Output file</param>
        /// <returns></returns>
        public static bool WriteObj(WrlData wrlData, string objFilename)
        {
            // objFilename has the .obj extension
            string directory   = System.IO.Path.GetDirectoryName(objFilename);
            string noExtension = System.IO.Path.GetFileNameWithoutExtension(objFilename);
            string mtlRelative = $"{noExtension}.mtl";
            string mtlFilename = System.IO.Path.Combine(directory, mtlRelative);

            List <string> mtlLines = new List <string>(); // To store the lines to append to the mtl file

            try
            {
                using (StreamWriter obj = new StreamWriter(objFilename))
                {
                    // mtllib, o, v, vt, g, usemtl, s, f

                    obj.WriteLine(GenericUtils.GetCreditsFile());
                    obj.WriteLine(ObjUtils.GetNewMtlLib(mtlRelative));

                    int i_coordIndex    = 0;
                    int i_texCoordIndex = 0;

                    int index = 0;

                    foreach (Transform transform in wrlData.TransformsList)
                    {
                        foreach (Shape shape in transform.ShapesList)
                        {
                            string groupName    = "";
                            string urlTexture   = null;
                            string diffuseColor = null;

                            if (shape.Appearance != null)
                            {
                                if (shape.Appearance.Material != null)
                                {
                                    if (shape.Appearance.Material.DiffuseColor != null)
                                    {
                                        diffuseColor = shape.Appearance.Material.DiffuseColor.ToString();
                                    }
                                }

                                if (shape.Appearance.Texture != null)
                                {
                                    urlTexture = shape.Appearance.Texture.Url;
                                    if (urlTexture != null)
                                    {
                                        groupName = ObjUtils.GetGroupName(index, urlTexture);
                                    }
                                    else
                                    {
                                        groupName = ObjUtils.GetGroupName(index);
                                    }
                                }
                                else
                                {
                                    groupName = ObjUtils.GetGroupName(index);
                                }
                            }

                            mtlLines.Add(MtlUtils.GetMtlData(groupName, urlTexture, diffuseColor));

                            obj.WriteLine(ObjUtils.GetNewObject(groupName)); // o


                            int sizeCoord = 0; int sizeTexCoord = 0;

                            if (shape.Geometry != null)
                            {
                                if (shape.Geometry.Coord != null)
                                {
                                    sizeCoord = shape.Geometry.Coord.PointsList.Count;
                                    foreach (Point point in shape.Geometry.Coord.PointsList)
                                    {
                                        obj.WriteLine(ObjUtils.GetNewCoord(point.ToString())); // v
                                    }
                                }

                                if (shape.Geometry.TexCoord != null)
                                {
                                    sizeTexCoord = shape.Geometry.TexCoord.UVList.Count;
                                    foreach (UVCoordinates uv in shape.Geometry.TexCoord.UVList)
                                    {
                                        obj.WriteLine(ObjUtils.GetNewTexCoord(uv.ToString())); // vt
                                    }
                                }
                            }

                            obj.WriteLine(ObjUtils.GetNewGroup(groupName));  // g
                            obj.WriteLine(ObjUtils.GetNewUseMtl(groupName)); // usemtl
                            obj.WriteLine(ObjUtils.GetNewSmoothGroup());     // s

                            if (shape.Geometry != null)
                            {
                                CoordIndexesWrl coordIndexes    = shape.Geometry.CoordIndexes;
                                CoordIndexesWrl texCoordIndexes = shape.Geometry.TexCoordIndexes;

                                if (coordIndexes != null)
                                {
                                    List <CoordIndexWrl> coordIndexesList = coordIndexes.IndexesList;
                                    if (texCoordIndexes != null)
                                    {
                                        List <CoordIndexWrl> texCoordIndexesList = texCoordIndexes.IndexesList;
                                        for (int i = 0; i < coordIndexesList.Count; i++)
                                        {
                                            string strIndexesF = GetIndexesF(coordIndexesList[i], texCoordIndexesList[i], i_coordIndex, i_texCoordIndex);
                                            obj.WriteLine(ObjUtils.GetNewF(strIndexesF)); // f
                                        }
                                    }
                                    else
                                    {
                                        foreach (CoordIndexWrl coordIndex in coordIndexesList)
                                        {
                                            string strIndexesF = GetIndexesF(coordIndex, i_coordIndex);
                                            obj.WriteLine(ObjUtils.GetNewF(strIndexesF)); // f
                                        }
                                    }
                                }
                            }
                            i_coordIndex    += sizeCoord;
                            i_texCoordIndex += sizeTexCoord;
                            index++;
                        }
                    }
                }
            }
            catch
            {
                return(false);
            }
            return(MtlExporter.WriteMtl(mtlLines, mtlFilename)); // Create the mtl file
        }
Esempio n. 19
0
        /// <summary>
        /// Dump two sets of parameters, optionally showing only differences.
        /// </summary>
        public static void DumpParams(TextWriter writer, bool differentOnly,
                                      GameEngineUCISpec externalEngine1Spec, GameEngineUCISpec externalEngine2Spec,
                                      NNEvaluatorDef evaluatorDef1, NNEvaluatorDef evaluatorDef2,
                                      SearchLimit searchLimit1, SearchLimit searchLimit2,
                                      ParamsSelect selectParams1, ParamsSelect selectParams2,
                                      ParamsSearch searchParams1, ParamsSearch searchParams2,
                                      IManagerGameLimit timeManager1, IManagerGameLimit timeManager2,
                                      ParamsSearchExecution paramsSearchExecution1,
                                      ParamsSearchExecution paramsSearchExecution2)
        {
            writer.WriteLine("\r\n-----------------------------------------------------------------------");
            writer.WriteLine("ENGINE 1 Options Modifications from Default");

            if (evaluatorDef1 != null)
            {
                writer.WriteLine("Ceres Evaluator : " + evaluatorDef1.ToString());
            }
            else
            {
                writer.Write("External UCI : " + externalEngine1Spec);
            }

            writer.Write(ObjUtils.FieldValuesDumpString <SearchLimit>(searchLimit1, SearchLimit.NodesPerMove(1), differentOnly));
            //      writer.Write(ObjUtils.FieldValuesDumpString<NNEvaluatorDef>(Def.NNEvaluators1.EvaluatorDef, new ParamsNN(), differentOnly));
            writer.Write(ObjUtils.FieldValuesDumpString <ParamsSelect>(selectParams1, new ParamsSelect(), differentOnly));
            writer.Write(ObjUtils.FieldValuesDumpString <ParamsSearch>(searchParams1, new ParamsSearch(), differentOnly));
            DumpTimeManagerDifference(true, null, timeManager1);
            writer.Write(ObjUtils.FieldValuesDumpString <ParamsSearchExecution>(paramsSearchExecution1, new ParamsSearchExecution(), differentOnly));

            writer.WriteLine("\r\n-----------------------------------------------------------------------");
            writer.WriteLine("ENGINE 2 Options Modifications from Engine 1");
            bool evaluatorsDifferent = false;

            bool eval2TypeDifferent = (evaluatorDef1 == null) != (evaluatorDef2 == null);

            if (eval2TypeDifferent)
            {
                evaluatorsDifferent = true;
            }
            else
            {
                if (evaluatorDef1 != null)
                {
                    evaluatorsDifferent = evaluatorDef1.ToString() != evaluatorDef2.ToString();
                }
                else
                {
                    evaluatorsDifferent = externalEngine1Spec.ToString() != externalEngine2Spec.ToString();
                }
            }
            if (!differentOnly || evaluatorsDifferent)
            {
                if (evaluatorDef1 != null && evaluatorDef2 != null)
                {
                    writer.WriteLine("Ceres Evaluator : " + evaluatorDef2.ToString());
                }
                else
                {
                    writer.Write("External UCI : " + externalEngine2Spec);
                }
            }

            if (searchLimit2 != null)
            {
                writer.Write(ObjUtils.FieldValuesDumpString <SearchLimit>(searchLimit2, searchLimit1, differentOnly));
                //      writer.Write(ObjUtils.FieldValuesDumpString<NNEvaluatorDef>(Def.NNEvaluators1.EvaluatorDef, Def.NNEvaluators2.EvaluatorDef, differentOnly));
                writer.Write(ObjUtils.FieldValuesDumpString <ParamsSelect>(selectParams2, selectParams1, differentOnly));
                writer.Write(ObjUtils.FieldValuesDumpString <ParamsSearch>(searchParams2, searchParams1, differentOnly));
                DumpTimeManagerDifference(differentOnly, timeManager1, timeManager2);
                writer.Write(ObjUtils.FieldValuesDumpString <ParamsSearchExecution>(paramsSearchExecution2, paramsSearchExecution1, differentOnly));
            }
        }
Esempio n. 20
0
        /// <summary>
        /// Merge together groups that share a texture
        /// </summary>
        /// <param name="objData">Data parsed from the obj file</param>
        /// <param name="mtlData">Data parsed from the mtl file</param>
        public static bool MergeGroups(ObjData objData, MtlData mtlData)
        {
            if (mtlData == null)
            {
                return(false);
            }

            var tupleTextureMaterials = MtlUtils.GetTupleDictTextureMaterials(mtlData);

            // Dictionary that associate every texture to a list of materials
            Dictionary <string, List <int> > dictTextureMaterials = tupleTextureMaterials.Item1;

            // List of materials without any texture
            List <int> untexturedMaterials = tupleTextureMaterials.Item2;

            // Dictionary that associate every material to a list of groups
            Dictionary <string, List <int> > dictMaterialGroups = ObjUtils.GetDictMaterialGroups(objData);

            // Dictionary that associate every texture to a list of groups
            Dictionary <string, List <int> > dictTextureGroups = ObjUtils.GetDictTextureGroups(objData, mtlData,
                                                                                               dictTextureMaterials, dictMaterialGroups);

            List <ObjectObj>   newObjectsList   = new List <ObjectObj>();
            List <MaterialMtl> newMaterialsList = new List <MaterialMtl>();

            foreach (KeyValuePair <string, List <int> > keyValue in dictTextureGroups) // Textured groups
            {
                // Merge the groups
                ObjectObj objectObj = MergeObjects(objData, keyValue.Key, keyValue.Value);
                newObjectsList.Add(objectObj);

                if (dictTextureMaterials.TryGetValue(keyValue.Key, out List <int> materials))
                {
                    if (materials != null)
                    {
                        // Merge the materials
                        MaterialMtl materialMtl = MergeMaterials(mtlData, keyValue.Key, materials);
                        newMaterialsList.Add(materialMtl);
                    }
                }
            }

            foreach (int materialId in untexturedMaterials) // The untextured materials
            {
                MaterialMtl materialMtl = mtlData.MaterialsList[materialId];
                newMaterialsList.Add(materialMtl); // Insert material in the list
                if (dictMaterialGroups.TryGetValue(materialMtl.NewMtl, out List <int> groups))
                {
                    if (groups != null)
                    {
                        foreach (int groupId in groups)
                        {
                            ObjectObj objectObj = objData.ObjectsList[groupId];
                            newObjectsList.Add(objectObj); // Insert the object in the list
                        }
                    }
                }
            }
            objData.ObjectsList   = newObjectsList;
            mtlData.MaterialsList = newMaterialsList;
            return(true);
        }
Esempio n. 21
0
        /// <summary>
        /// Delete all groups that use textures from a given list (compare the textures)
        /// </summary>
        /// <param name="objData">Data parsed from the obj file</param>
        /// <param name="mtlData">Data parsed from the mtl file</param>
        /// <param name="listFileName">List of textures that should be matched</param>
        public static bool DeleteMatchingGroups(ObjData objData, MtlData mtlData, List <string> listFileName)
        {
            if (mtlData == null)
            {
                return(false);
            }

            List <BitmapStoreData> imgList = BitmapStoreData.GetListBitmapStoreData(listFileName);

            var tupleTextureMaterials = MtlUtils.GetTupleDictTextureMaterials(mtlData);

            // Dictionary that associate every texture to a list of materials
            Dictionary <string, List <int> > dictTextureMaterials = tupleTextureMaterials.Item1;
            // List of materials without any texture
            List <int> untexturedMaterials = tupleTextureMaterials.Item2;

            // Dictionary that associate every material to a list of groups
            Dictionary <string, List <int> > dictMaterialGroups = ObjUtils.GetDictMaterialGroups(objData);

            // Dictionary that associate every texture to a list of groups
            Dictionary <string, List <int> > dictTextureGroups = ObjUtils.GetDictTextureGroups(objData, mtlData,
                                                                                               dictTextureMaterials, dictMaterialGroups);

            List <ObjectObj>   newObjectsList   = new List <ObjectObj>();
            List <MaterialMtl> newMaterialsList = new List <MaterialMtl>();

            string srcDir = System.IO.Path.GetDirectoryName(mtlData.FilePath);

            foreach (KeyValuePair <string, List <int> > keyValue in dictTextureGroups)
            {
                List <int> groups = keyValue.Value;
                if (groups != null)
                {
                    if (groups.Count >= 1) // Should always be the case
                    {
                        string texturePath = keyValue.Key;

                        if (!System.IO.Path.IsPathRooted(texturePath)) // Not an absolute path
                        {
                            texturePath = System.IO.Path.Combine(srcDir, texturePath);
                        }

                        System.Drawing.Bitmap img = ImageUtilsShared.CreateBitmap(texturePath);
                        if (img != null)
                        {
                            BitmapStoreData bmpData = new BitmapStoreData(img);
                            if (bmpData.BData != null)
                            {
                                if (!ImageUtilsShared.SamePictures(imgList, bmpData)) // Not the same image
                                {
                                    // We can keep all these groups and materials

                                    foreach (int groupId in groups)
                                    {
                                        ObjectObj objectObj = objData.ObjectsList[groupId];
                                        newObjectsList.Add(objectObj); // Insert the object in the list
                                    }

                                    if (dictTextureMaterials.TryGetValue(keyValue.Key, out List <int> materials))
                                    {
                                        if (materials != null)
                                        {
                                            foreach (int materialId in materials)
                                            {
                                                MaterialMtl materialMtl = mtlData.MaterialsList[materialId];
                                                newMaterialsList.Add(materialMtl); // Insert the material in the list
                                            }
                                        }
                                    }
                                }
                                bmpData.UnlockBits();
                            }
                        }
                    }
                }
            }

            foreach (int materialId in untexturedMaterials) // The untextured materials
            {
                MaterialMtl materialMtl = mtlData.MaterialsList[materialId];
                newMaterialsList.Add(materialMtl); // Insert material in the list
                if (dictMaterialGroups.TryGetValue(materialMtl.NewMtl, out List <int> groups))
                {
                    if (groups != null)
                    {
                        foreach (int groupId in groups)
                        {
                            ObjectObj objectObj = objData.ObjectsList[groupId];
                            newObjectsList.Add(objectObj); // Insert the object in the list
                        }
                    }
                }
            }
            BitmapStoreData.BitmapDataUnlock(imgList);

            objData.ObjectsList   = newObjectsList;
            mtlData.MaterialsList = newMaterialsList;
            return(true);
        }
Esempio n. 22
0
        /// <summary>
        /// Create the obj and mtl files with the given data
        /// </summary>
        /// <param name="objData">Data parsed from the obj file</param>
        /// <param name="mtlData">Data parsed from the mtl file</param>
        /// <param name="objFilename">Output path</param>
        /// <param name="makeMtl">Create a mtl file</param>
        /// <param name="useExistingMtl">Use the mtlData to create the mtl file</param>
        /// <returns></returns>
        public static bool WriteObj(ObjData objData, MtlData mtlData, string objFilename, bool makeMtl, bool useExistingMtl)
        {
            // objFilename has the .obj extension
            string directory   = System.IO.Path.GetDirectoryName(objFilename);
            string noExtension = System.IO.Path.GetFileNameWithoutExtension(objFilename);
            string mtlRelative = string.Format("{0}.mtl", noExtension);
            string mtlFilename = System.IO.Path.Combine(directory, mtlRelative);

            List <string> mtlLines = new List <string>(); // To store the lines to append to the mtl file

            try
            {
                using (StreamWriter obj = new StreamWriter(objFilename))
                {
                    // mtllib, o, v, vt, g, usemtl, s, f

                    obj.WriteLine(GenericUtils.GetCreditsFile());
                    if (makeMtl)
                    {
                        obj.WriteLine(ObjUtils.GetNewMtlLib(mtlRelative));
                    }

                    LocalIndexesObj indexesObj = new LocalIndexesObj();

                    foreach (ObjectObj objectObj in objData.ObjectsList)
                    {
                        if (objectObj.ObjectName != null)
                        {
                            obj.WriteLine(ObjUtils.GetNewObject(objectObj.ObjectName)); // o
                        }
                        foreach (Point p in objectObj.VerticesList)
                        {
                            obj.WriteLine(ObjUtils.GetNewCoord(p.ToString())); // v
                        }
                        foreach (UVCoordinates uv in objectObj.UVsList)
                        {
                            obj.WriteLine(ObjUtils.GetNewTexCoord(uv.ToString())); // vt
                        }
                        foreach (Vector v in objectObj.NormalsList)
                        {
                            obj.WriteLine(ObjUtils.GetNewVertNormal(v.ToString())); // vn
                        }
                        if (objectObj.GroupName != null)
                        {
                            obj.WriteLine(ObjUtils.GetNewGroup(objectObj.GroupName)); // g
                        }
                        if (objectObj.MaterialName != null)
                        {
                            obj.WriteLine(ObjUtils.GetNewUseMtl(objectObj.MaterialName)); // usemtl
                            // Store lines in the mtl array to append to the file later
                            mtlLines.Add(MtlUtils.GetMtlData(objectObj.MaterialName, objectObj.TextureName));
                        }

                        if (objectObj.Smooth == -1)
                        {
                            obj.WriteLine(ObjUtils.GetNewSmoothGroup()); // s
                        }
                        else
                        {
                            obj.WriteLine(ObjUtils.GetNewSmoothGroup(objectObj.Smooth)); // s
                        }
                        foreach (VertIndexesObj vertIndexes in objectObj.VertIndexesList)
                        {
                            obj.WriteLine(ObjUtils.GetNewF(GetDataF(vertIndexes, indexesObj))); // f
                        }
                        indexesObj.vIndex  += objectObj.VerticesList.Count;
                        indexesObj.vtIndex += objectObj.UVsList.Count;
                        indexesObj.vnIndex += objectObj.NormalsList.Count;
                    }
                }
            }
            catch
            {
                return(false);
            }

            if (makeMtl)                               // If we dont delete materials
            {
                if (useExistingMtl && mtlData != null) // Use the parsed mtl
                {
                    return(MtlExporter.WriteMtl(mtlData, mtlFilename));
                }
                else // Create a mtl from the data obtained in the obj
                {
                    return(MtlExporter.WriteMtl(mtlLines, mtlFilename));
                }
            }

            return(true);
        }
        /**
         * Creates and initializes OpenGL resources needed for rendering the model.
         *
         * @param context Context for loading the shader and below-named model and texture assets.
         * @param objAssetName  Name of the OBJ file containing the model geometry.
         * @param diffuseTextureAssetName  Name of the PNG file containing the diffuse texture map.
         */
        public void CreateOnGlThread(Context context, string objAssetName, string diffuseTextureAssetName)
        {
            // Read the texture.
            var textureBitmap = BitmapFactory.DecodeStream(context.Assets.Open(diffuseTextureAssetName));

            GLES20.GlActiveTexture(GLES20.GlTexture0);
            GLES20.GlGenTextures(mTextures.Length, mTextures, 0);
            GLES20.GlBindTexture(GLES20.GlTexture2d, mTextures[0]);

            GLES20.GlTexParameteri(GLES20.GlTexture2d,
                                   GLES20.GlTextureMinFilter, GLES20.GlLinearMipmapLinear);
            GLES20.GlTexParameteri(GLES20.GlTexture2d,
                                   GLES20.GlTextureMagFilter, GLES20.GlLinear);
            GLUtils.TexImage2D(GLES20.GlTexture2d, 0, textureBitmap, 0);
            GLES20.GlGenerateMipmap(GLES20.GlTexture2d);
            GLES20.GlBindTexture(GLES20.GlTexture2d, 0);

            textureBitmap.Recycle();

            ShaderUtil.CheckGLError(TAG, "Texture loading");

            // Read the obj file.
            var objInputStream = context.Assets.Open(objAssetName);
            var obj            = ObjReader.Read(objInputStream);

            // Prepare the Obj so that its structure is suitable for
            // rendering with OpenGL:
            // 1. Triangulate it
            // 2. Make sure that texture coordinates are not ambiguous
            // 3. Make sure that normals are not ambiguous
            // 4. Convert it to single-indexed data
            obj = ObjUtils.ConvertToRenderable(obj);

            // OpenGL does not use Java arrays. ByteBuffers are used instead to provide data in a format
            // that OpenGL understands.

            // Obtain the data from the OBJ, as direct buffers:
            IntBuffer   wideIndices = ObjData.GetFaceVertexIndices(obj, 3);
            FloatBuffer vertices    = ObjData.GetVertices(obj);
            FloatBuffer texCoords   = ObjData.GetTexCoords(obj, 2);
            FloatBuffer normals     = ObjData.GetNormals(obj);

            // Convert int indices to shorts for GL ES 2.0 compatibility
            ShortBuffer indices = ByteBuffer.AllocateDirect(2 * wideIndices.Limit())
                                  .Order(ByteOrder.NativeOrder()).AsShortBuffer();

            while (wideIndices.HasRemaining)
            {
                indices.Put((short)wideIndices.Get());
            }
            indices.Rewind();

            var buffers = new int[2];

            GLES20.GlGenBuffers(2, buffers, 0);
            mVertexBufferId = buffers[0];
            mIndexBufferId  = buffers[1];

            // Load vertex buffer
            mVerticesBaseAddress  = 0;
            mTexCoordsBaseAddress = mVerticesBaseAddress + 4 * vertices.Limit();
            mNormalsBaseAddress   = mTexCoordsBaseAddress + 4 * texCoords.Limit();
            int totalBytes = mNormalsBaseAddress + 4 * normals.Limit();

            GLES20.GlBindBuffer(GLES20.GlArrayBuffer, mVertexBufferId);
            GLES20.GlBufferData(GLES20.GlArrayBuffer, totalBytes, null, GLES20.GlStaticDraw);
            GLES20.GlBufferSubData(
                GLES20.GlArrayBuffer, mVerticesBaseAddress, 4 * vertices.Limit(), vertices);
            GLES20.GlBufferSubData(
                GLES20.GlArrayBuffer, mTexCoordsBaseAddress, 4 * texCoords.Limit(), texCoords);
            GLES20.GlBufferSubData(
                GLES20.GlArrayBuffer, mNormalsBaseAddress, 4 * normals.Limit(), normals);
            GLES20.GlBindBuffer(GLES20.GlArrayBuffer, 0);

            // Load index buffer
            GLES20.GlBindBuffer(GLES20.GlElementArrayBuffer, mIndexBufferId);
            mIndexCount = indices.Limit();
            GLES20.GlBufferData(
                GLES20.GlElementArrayBuffer, 2 * mIndexCount, indices, GLES20.GlStaticDraw);
            GLES20.GlBindBuffer(GLES20.GlElementArrayBuffer, 0);

            ShaderUtil.CheckGLError(TAG, "OBJ buffer load");

            int vertexShader = ShaderUtil.LoadGLShader(TAG, context,
                                                       GLES20.GlVertexShader, Resource.Raw.object_vertex);
            int fragmentShader = ShaderUtil.LoadGLShader(TAG, context,
                                                         GLES20.GlFragmentShader, Resource.Raw.object_fragment);

            mProgram = GLES20.GlCreateProgram();
            GLES20.GlAttachShader(mProgram, vertexShader);
            GLES20.GlAttachShader(mProgram, fragmentShader);
            GLES20.GlLinkProgram(mProgram);
            GLES20.GlUseProgram(mProgram);

            ShaderUtil.CheckGLError(TAG, "Program creation");

            mModelViewUniform           = GLES20.GlGetUniformLocation(mProgram, "u_ModelView");
            mModelViewProjectionUniform =
                GLES20.GlGetUniformLocation(mProgram, "u_ModelViewProjection");

            mPositionAttribute = GLES20.GlGetAttribLocation(mProgram, "a_Position");
            mNormalAttribute   = GLES20.GlGetAttribLocation(mProgram, "a_Normal");
            mTexCoordAttribute = GLES20.GlGetAttribLocation(mProgram, "a_TexCoord");

            mTextureUniform = GLES20.GlGetUniformLocation(mProgram, "u_Texture");

            mLightingParametersUniform = GLES20.GlGetUniformLocation(mProgram, "u_LightingParameters");
            mMaterialParametersUniform = GLES20.GlGetUniformLocation(mProgram, "u_MaterialParameters");

            ShaderUtil.CheckGLError(TAG, "Program parameters");

            Android.Opengl.Matrix.SetIdentityM(mModelMatrix, 0);
        }
Esempio n. 24
0
        /// <summary>
        /// Store the f, v, vt and vn lines into the object
        /// </summary>
        /// <param name="value"></param>
        /// <param name="objectObj"></param>
        /// <param name="allVertices"></param>
        /// <param name="indexesObj"></param>
        private static void VerticeData(string value, ObjectObj objectObj, AllVerticesDataObj allVertices, LocalIndexesObj indexesObj)
        {
            VertIndexesObj vertIndexes = new VertIndexesObj();

            foreach (string indexes in ObjUtils.SplitVertData(value))
            {
                VertIndexObj vertIndex = new VertIndexObj();

                string[] indexList = ObjUtils.SplitIndexes(indexes);

                int length = indexList.Length;

                for (int i = 0; i < length; i++)
                {
                    int index = 0;
                    if (indexList[i] != "")                                 // the vt line can be empty
                    {
                        if (Int32.TryParse(indexList[i], out int tmpIndex)) // Get the index
                        {
                            index = tmpIndex;
                        }
                    }

                    if (i == 0) // v
                    {
                        if (index != 0)
                        {
                            vertIndex.V = indexesObj.vIndex;
                            string vLine = allVertices.GetVIndex(index - 1); // Obj index start at 1
                            if (vLine != null)
                            {
                                objectObj.VerticesList.Add(new Point(vLine));
                                indexesObj.vIndex++;
                            }
                        }
                    }
                    else if (i == 1) // vt
                    {
                        if (index != 0)
                        {
                            vertIndex.Vt = indexesObj.vtIndex;
                            string vtLine = allVertices.GetVtIndex(index - 1); // Obj index start at 1
                            if (vtLine != null)
                            {
                                objectObj.UVsList.Add(new UVCoordinates(vtLine));
                                indexesObj.vtIndex++;
                            }
                        }
                    }
                    else if (i == 2) // vn
                    {
                        if (index != 0)
                        {
                            vertIndex.Vn = indexesObj.vnIndex;
                            string vnLine = allVertices.GetVnIndex(index - 1); // Obj index start at 1
                            if (vnLine != null)
                            {
                                objectObj.NormalsList.Add(new Vector(vnLine));
                                indexesObj.vnIndex++;
                            }
                        }
                    }
                }
                vertIndexes.VertIndexList.Add(vertIndex);
            }
            objectObj.VertIndexesList.Add(vertIndexes);
        }