Пример #1
0
        private static string Serialize(Scene scene, double scale)
        {
            var vertices = new StringBuilder();
            var faces = new StringBuilder();
            var indexesBase = 1;

            for (var surfaceIndex = 0; surfaceIndex < scene.Surfaces.Count; surfaceIndex++)
            {
                var figure = scene.Surfaces[surfaceIndex];
                foreach (var point in figure.Points)
                {
                    vertices.AppendLine(
                        string.Format(
                            CultureInfo.InvariantCulture,
                            "v {0} {1} 0.0",
                            -point.X * scale,
                            -point.Y * scale));
                }

                faces.AppendLine($"g {surfaceIndex}");
                faces.AppendLine($"f {string.Join(" ", Enumerable.Range(indexesBase, figure.Points.Count))}");
                indexesBase += figure.Points.Count;
            }

            return vertices.ToString() + faces;
        }
Пример #2
0
        public void Export(Scene scene, double scale = 1.0)
        {
            var answer = _saveDialog.ShowDialog();
            if (answer.HasValue && answer.Value)
            {

                File.WriteAllText(_saveDialog.FileName, Serialize(scene, scale));
            }
        }
Пример #3
0
        private void SetState(Scene scene)
        {
            if (_scene == scene)
            {
                return;
            }

            _scene = scene;

            for (int i = 0; i < _scene.Surfaces.Count; i++)
            {
                if (i >= _shapes.Count)
                {
                    _shapes.Add(new Surface());
                }

                _shapes[i].SetState(_scene.Surfaces[i]);
            }

            while (_shapes.Count > _scene.Surfaces.Count)
            {
                _shapes.RemoveAt(_shapes.Count - 1);
            }
        }