Exemplo n.º 1
0
        public virtual void PrepareScene()
        {
            if (!Nodes.OfType<Camera>().Any())
                throw new Exception("No camera in scene");

            Camera = Nodes.OfType<Camera>().First();
            Camera.PrepareCamera();

            Lights = Nodes.OfType<Light>().ToList();
            Geomertries = new List<Geomertry>();

            foreach (Texture texture in Textures)
            {
                texture.PrepareTexture();
            }

            foreach (var geometry in Nodes.OfType<MeshGeometry>())
            {
                foreach (Triangle triangle in geometry.Triangles)
                {
                    triangle.Transform = geometry.Scale*geometry.Rotation*geometry.Translation;
                    triangle.Prepare();

                    Geomertries.Add(triangle);
                }
            }

            if (UseOptimisation && Geomertries.Any())
            {
                BuildTree();
            }
        }
Exemplo n.º 2
0
        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;
                        }
                }
            }
        }
Exemplo n.º 3
0
        private void ReadCameraInfo(Camera camera, string url)
        {
            XElement instanceElement = _document.XPathSelectElement(string.Format("//c:library_cameras/c:camera[@id='{0}']", url), _nsMgr);
            XElement cameraElement = instanceElement.XPathSelectElement("c:optics/c:technique_common/c:perspective", _nsMgr);

            camera.Fov = cameraElement.Element(Ns + "xfov").Value.ToFloat();
        }