Esempio n. 1
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);
        }