예제 #1
0
 public ElementRotation(ElementRotation rotation)
 {
     _axis     = rotation._axis;
     _angle    = rotation._angle;
     _origin   = new Vector3(rotation._origin.X, rotation._origin.Y, rotation._origin.Z);
     _rescale  = rotation._rescale;
     _treeNode = new TreeNodeRotation(this);
 }
예제 #2
0
 public JsonElement()
 {
     From     = Vector3.Zero;
     To       = Vector3.Zero;
     Shade    = true;
     Faces    = new List <JsonFace>();
     Rotation = new ElementRotation();
     Name     = "Element";
 }
예제 #3
0
        public Box(JsonElement element, Model parentModel)
        {
            _from              = element.From;
            _to                = element.To;
            _shade             = element.Shade;
            _rotation          = element.Rotation;
            _rotation.Changed += new OnRotationChangedHandler(OnLooksChanged);
            _name              = element.Name;
            _parentModel       = parentModel;

            _faces = new List <CubeFace>();
            for (int i = 0; i < element.Faces.Count; i++)
            {
                _faces.Add(new CubeFace(element.Faces[i], _from, _to, this));
            }
            AddMissingFaces();
            HookFaceEvents();
            _treeNode  = new TreeNodeElement(this);
            IsSelected = _treeNode.IsSelected;
            _treeNode.UpdateValues();
        }
예제 #4
0
        public Box(Vector3 from, Vector3 to, ElementRotation rotation, string textureName, string name, Model parentModel)
        {
            _from              = from;
            _to                = to;
            _shade             = true;
            _rotation          = rotation;
            _rotation.Changed += new OnRotationChangedHandler(OnLooksChanged);
            _name              = name;
            _parentModel       = parentModel;

            _faces = new List <CubeFace>
            {
                new CubeFace(from, to, FaceOrientation.up, new Vector4(0, 0, 16, 16), textureName, true, this),
                new CubeFace(from, to, FaceOrientation.down, new Vector4(0, 0, 16, 16), textureName, true, this),
                new CubeFace(from, to, FaceOrientation.north, new Vector4(0, 0, 16, 16), textureName, true, this),
                new CubeFace(from, to, FaceOrientation.south, new Vector4(0, 0, 16, 16), textureName, true, this),
                new CubeFace(from, to, FaceOrientation.east, new Vector4(0, 0, 16, 16), textureName, true, this),
                new CubeFace(from, to, FaceOrientation.west, new Vector4(0, 0, 16, 16), textureName, true, this)
            };
            HookFaceEvents();
            _treeNode  = new TreeNodeElement(this);
            IsSelected = _treeNode.IsSelected;
            _treeNode.UpdateValues();
        }
예제 #5
0
        private int ParseElements()
        {
            int    dataEnd = _fileText.LastIndexOf("]");
            string value   = _fileText.Substring(_readIndex, dataEnd - _readIndex);

            JsonElement element = new JsonElement();
            bool        done    = false;

            while (!done)
            {
                int    nameIndex  = value.IndexOf("\"") + 1;
                int    nameLenght = value.IndexOf("\"", nameIndex) - nameIndex;
                string name       = value.Substring(nameIndex, nameLenght);
                value = value.Substring(value.IndexOf(":") + 1);

                if (name == "__comment")
                {
                    int    commentIndex  = value.IndexOf("\"") + 1;
                    int    commentLenght = value.IndexOf("\"", commentIndex) - commentIndex;
                    string comment       = value.Substring(commentIndex, commentLenght);

                    element.Name = comment;
                    value        = value.Substring(commentIndex + commentLenght + 1);
                }
                if (name == "from")
                {
                    value = value.Substring(value.IndexOf("[") + 1);
                    double x = System.Xml.XmlConvert.ToDouble(value.Substring(0, value.IndexOf(",")));

                    value = value.Substring(value.IndexOf(",") + 1);
                    double y = System.Xml.XmlConvert.ToDouble(value.Substring(0, value.IndexOf(",")));

                    value = value.Substring(value.IndexOf(",") + 1);
                    double z = System.Xml.XmlConvert.ToDouble(value.Substring(0, value.IndexOf("]")));

                    element.From = new Vector3((float)x, (float)y, (float)z);

                    value = value.Substring(value.IndexOf("]") + 1);
                }
                if (name == "to")
                {
                    value = value.Substring(value.IndexOf("[") + 1);
                    double x = System.Xml.XmlConvert.ToDouble(value.Substring(0, value.IndexOf(",")));

                    value = value.Substring(value.IndexOf(",") + 1);
                    double y = System.Xml.XmlConvert.ToDouble(value.Substring(0, value.IndexOf(",")));

                    value = value.Substring(value.IndexOf(",") + 1);
                    double z = System.Xml.XmlConvert.ToDouble(value.Substring(0, value.IndexOf("]")));

                    element.To = new Vector3((float)x, (float)y, (float)z);

                    value = value.Substring(value.IndexOf("]") + 1);
                }

                if (name == "shade")
                {
                    int boolEnd;
                    int nextComma      = value.IndexOf(",");
                    int nextCloseBrack = value.IndexOf("}");
                    if (nextComma < 0 || nextComma > nextCloseBrack)
                    {
                        boolEnd = nextCloseBrack;
                    }
                    else
                    {
                        boolEnd = nextComma;
                    }

                    string boolString = value.Substring(0, boolEnd);

                    if (value.Contains("false"))
                    {
                        element.Shade = false;
                    }
                    else if (value.Contains("true"))
                    {
                        element.Shade = true;
                    }

                    value = value.Substring(boolEnd + 1);
                }
                #region Faces

                if (name == "faces")
                {
                    /////todo
                    bool facesDone = false;
                    while (!facesDone)
                    {
                        JsonFace face = new JsonFace();
                        face.Visible = true;
                        int    faceNameIndex  = value.IndexOf("\"") + 1;
                        int    faceNameLenght = value.IndexOf("\"", faceNameIndex) - faceNameIndex;
                        string faceName       = value.Substring(faceNameIndex, faceNameLenght);
                        value = value.Substring(value.IndexOf(":") + 1);

                        if (faceName == "north")
                        {
                            face.Orientation = FaceOrientation.north;
                        }
                        if (faceName == "south")
                        {
                            face.Orientation = FaceOrientation.south;
                        }
                        if (faceName == "up")
                        {
                            face.Orientation = FaceOrientation.up;
                        }
                        if (faceName == "down")
                        {
                            face.Orientation = FaceOrientation.down;
                        }
                        if (faceName == "east")
                        {
                            face.Orientation = FaceOrientation.east;
                        }
                        if (faceName == "west")
                        {
                            face.Orientation = FaceOrientation.west;
                        }


                        bool   parasDone = false;
                        string faceData  = value.Substring(0, value.IndexOf("}"));
                        while (!parasDone)
                        {
                            int    parNameIndex  = faceData.IndexOf("\"") + 1;
                            int    parNameLenght = faceData.IndexOf("\"", parNameIndex) - parNameIndex;
                            string parName       = faceData.Substring(parNameIndex, parNameLenght);
                            faceData = faceData.Substring(faceData.IndexOf(":") + 1);
                            int nextComma = faceData.IndexOf(",");
                            if (parName == "uv")
                            {
                                faceData = faceData.Substring(faceData.IndexOf("[") + 1);
                                double x1 = System.Xml.XmlConvert.ToDouble(faceData.Substring(0, faceData.IndexOf(",")));

                                faceData = faceData.Substring(faceData.IndexOf(",") + 1);
                                double y1 = System.Xml.XmlConvert.ToDouble(faceData.Substring(0, faceData.IndexOf(",")));

                                faceData = faceData.Substring(faceData.IndexOf(",") + 1);
                                double x2 = System.Xml.XmlConvert.ToDouble(faceData.Substring(0, faceData.IndexOf(",")));

                                faceData = faceData.Substring(faceData.IndexOf(",") + 1);
                                double y2 = System.Xml.XmlConvert.ToDouble(faceData.Substring(0, faceData.IndexOf("]")));

                                face.UV = new Vector4((float)x1, (float)y1, (float)x2, (float)y2);
                            }
                            if (parName == "texture")
                            {
                                int    texNameIndex  = faceData.IndexOf("\"") + 1;
                                int    texNameLenght = faceData.IndexOf("\"", texNameIndex) - texNameIndex;
                                string texName       = faceData.Substring(texNameIndex, texNameLenght);
                                face.TextureName = texName;
                            }
                            if (parName == "rotation")
                            {
                                if (nextComma < 0)
                                {
                                    face.Rotation = Convert.ToInt32(faceData);
                                }
                                else
                                {
                                    face.Rotation = Convert.ToInt32(faceData.Substring(0, nextComma));
                                }
                            }
                            if (parName == "tintindex")
                            {
                                if (nextComma < 0)
                                {
                                    face.TintIndex = Convert.ToInt32(faceData);
                                }
                                else
                                {
                                    face.TintIndex = Convert.ToInt32(faceData.Substring(0, nextComma));
                                }
                            }
                            if (parName == "cullface")
                            {
                                int    cullFaceIndex  = faceData.IndexOf("\"") + 1;
                                int    cullFaceLenght = faceData.IndexOf("\"", cullFaceIndex) - cullFaceIndex;
                                string cullFaceName   = faceData.Substring(cullFaceIndex, cullFaceLenght);

                                if (cullFaceName == "down")
                                {
                                    face.CullFace = CullFace.down;
                                }
                                if (cullFaceName == "up")
                                {
                                    face.CullFace = CullFace.up;
                                }
                                if (cullFaceName == "north")
                                {
                                    face.CullFace = CullFace.north;
                                }
                                if (cullFaceName == "south")
                                {
                                    face.CullFace = CullFace.south;
                                }
                                if (cullFaceName == "west")
                                {
                                    face.CullFace = CullFace.west;
                                }
                                if (cullFaceName == "east")
                                {
                                    face.CullFace = CullFace.east;
                                }
                            }

                            nextComma = faceData.IndexOf(",");
                            if (nextComma < 0)
                            {
                                parasDone = true;
                            }
                            else
                            {
                                faceData = faceData.Substring(nextComma + 1);
                            }
                        }
                        element.Faces.Add(face);
                        value = value.Substring(value.IndexOf("}") + 1);

                        int commaindex      = value.IndexOf(",");
                        int closeBrackindex = value.IndexOf("}");
                        if (commaindex < 0 || commaindex > closeBrackindex)
                        {
                            value     = value.Substring(value.IndexOf("}") + 1);
                            facesDone = true;
                        }
                    }
                }
                #endregion Faces
                #region Rotation
                if (name == "rotation")
                {
                    ElementRotation rotation = new ElementRotation();
                    string          rotData  = value.Substring(0, value.IndexOf("}"));

                    bool parasDone = false;
                    while (!parasDone)
                    {
                        int    parameterNameIndex  = rotData.IndexOf("\"") + 1;
                        int    parameterNameLenght = rotData.IndexOf("\"", parameterNameIndex) - parameterNameIndex;
                        string parameterName       = rotData.Substring(parameterNameIndex, parameterNameLenght);
                        rotData = rotData.Substring(rotData.IndexOf(":") + 1);
                        int nextComma = rotData.IndexOf(",");

                        if (parameterName == "origin")
                        {
                            rotData = rotData.Substring(rotData.IndexOf("[") + 1);
                            double x = System.Xml.XmlConvert.ToDouble(rotData.Substring(0, rotData.IndexOf(",")));

                            rotData = rotData.Substring(rotData.IndexOf(",") + 1);
                            double y = System.Xml.XmlConvert.ToDouble(rotData.Substring(0, rotData.IndexOf(",")));

                            rotData = rotData.Substring(rotData.IndexOf(",") + 1);
                            double z = System.Xml.XmlConvert.ToDouble(rotData.Substring(0, rotData.IndexOf("]")));

                            rotation.Origin = new Vector3((float)x, (float)y, (float)z);
                        }
                        if (parameterName == "axis")
                        {
                            int    axIndex  = rotData.IndexOf("\"") + 1;
                            int    axLenght = rotData.IndexOf("\"", axIndex) - axIndex;
                            string axName   = rotData.Substring(axIndex, axLenght);

                            if (axName == "x")
                            {
                                rotation.Axis = Axis.x;
                            }
                            if (axName == "y")
                            {
                                rotation.Axis = Axis.y;
                            }
                            if (axName == "z")
                            {
                                rotation.Axis = Axis.z;
                            }
                        }
                        if (parameterName == "angle")
                        {
                            if (nextComma < 0)
                            {
                                rotation.Angle = (float)System.Xml.XmlConvert.ToDouble(rotData);
                            }
                            else
                            {
                                rotation.Angle = (float)System.Xml.XmlConvert.ToDouble(rotData.Substring(0, nextComma));
                            }
                        }
                        if (parameterName == "rescale")
                        {
                            string boolScale;
                            if (nextComma >= 0)
                            {
                                boolScale = rotData.Substring(0, nextComma);
                            }
                            else
                            {
                                boolScale = rotData;
                            }

                            if (boolScale.Contains("true"))
                            {
                                rotation.Rescale = true;
                            }
                            if (boolScale.Contains("false"))
                            {
                                rotation.Rescale = false;
                            }
                        }
                        nextComma = rotData.IndexOf(",");
                        if (nextComma < 0)
                        {
                            parasDone = true;
                        }
                        else
                        {
                            rotData = rotData.Substring(nextComma + 1);
                        }
                    }
                    element.Rotation = rotation;
                    value            = value.Substring(value.IndexOf("}") + 1);
                }
                #endregion Rotation

                int commaIndex      = value.IndexOf(",");
                int closeBrackIndex = value.IndexOf("}");
                if (commaIndex > closeBrackIndex)
                {
                    _jsonModel.Elements.Add(element);
                    element = new JsonElement();
                }
                if (commaIndex < 0)
                {
                    _jsonModel.Elements.Add(element);
                    done = true;
                }
            }
            _readIndex = dataEnd + 1;
            return(1);
        }