Esempio n. 1
0
        public Scene LoadScene(string fileName)
        {
            _scene = new SimpleScene();
            _scene.Camera = new TargetedCamera();

            _material = new Material();

            _transforms = new Stack<Matrix>();
            _transforms.Push(Matrix.Identity);

            StreamReader reader = new StreamReader(fileName);

            while (!reader.EndOfStream)
            {
                string line = reader.ReadLine().Trim();

                if (string.IsNullOrEmpty(line) || line.StartsWith("#"))
                {
                    continue;
                }

                ProcessLine(line.Split(' ').Where(t => !string.IsNullOrEmpty(t)).ToArray());
            }

            return _scene;
        }
        private void LoadScene()
        {
            XElement sceneElement = _document.XPathSelectElement("//c:library_visual_scenes/c:visual_scene", _nsMgr);

            _scene = new Scene
                     	{
                     		Id = sceneElement.Attribute("id").Value,
                     		Name = sceneElement.Attribute("name").Value
                     	};

            foreach (var nodeElement in sceneElement.Elements(Ns + "node"))
            {
                XElement instanceElement = nodeElement.XPathSelectElement("*[contains(local-name(),'instance_')]", _nsMgr);
                string instanceType = instanceElement.Name.LocalName;
                string instanceUrl = instanceElement.Attribute("url").Value.Substring(1);

                switch (instanceType)
                {
                    case "instance_camera":
                        {
                            Camera camera = new Camera();

                            ReadNodeInfo(camera, nodeElement);
                            ReadNodeTransform(camera, nodeElement);
                            ReadCameraInfo(camera, instanceUrl);
                            _scene.Nodes.Add(camera);
                            break;
                        }
                    case "instance_light":
                        {
                            Light light = ReadLight(instanceUrl);

                            ReadNodeInfo(light, nodeElement);
                            ReadNodeTransform(light, nodeElement);
                            _scene.Nodes.Add(light);
                            break;
                        }
                    case "instance_geometry":
                        {
                            MeshGeometry mesh = new MeshGeometry();

                            ReadNodeInfo(mesh, nodeElement);
                            ReadNodeTransform(mesh, nodeElement);
                            ReadMesh(mesh, instanceUrl);
                            _scene.Nodes.Add(mesh);
                            break;
                        }
                }
            }
        }
Esempio n. 3
0
 public RayTracer(Scene scene)
 {
     _scene = scene;
 }