Esempio n. 1
0
        /// <summary>
        /// Add a Shader to Scene, assigning it a scene specific ID.
        /// </summary>
        /// <param name="shader">The Shader to add to the Scene</param>
        /// <returns>Scene-specific ID for the Shader</returns>
        public uint AddShader(Shader shader)
        {
            var shader_in_scene_id = CSycles.scene_add_shader(Client.Id, Id, shader.Id);

            m_shader_in_scene_ids.Add(shader, shader_in_scene_id);
            return(shader_in_scene_id);
        }
Esempio n. 2
0
        /// <summary>
        /// Create a new scene with the given SceneParameters and Device
        /// </summary>
        /// <param name="client">The client from C[CS]ycles API</param>
        /// <param name="sceneParams">The SceneParameters to create scene with</param>
        /// <param name="device">The Device to create scene for</param>
        public Scene(Client client, SceneParameters sceneParams, Device device)
        {
            Client     = client;
            Id         = CSycles.scene_create(Client.Id, sceneParams.Id, device.Id);
            Background = new Background(this);
            Camera     = new Camera(this);
            Integrator = new Integrator(this);
            Film       = new Film(this);
            Device     = device;

            /* add simple wrappers for shadermanager created default shaders */
            var surface    = Shader.WrapDefaultSurfaceShader(client);
            var light      = Shader.WrapDefaultLightShader(client);
            var background = Shader.WrapDefaultBackgroundShader(client);
            var empty      = Shader.WrapDefaultEmptyShader(client);

            /* register the wrapped shaders with scene */
            m_shader_in_scene_ids.Add(surface, surface.Id);
            m_shader_in_scene_ids.Add(background, background.Id);
            m_shader_in_scene_ids.Add(light, light.Id);
            m_shader_in_scene_ids.Add(empty, empty.Id);

            DefaultSurface = surface;

            // set ourself to client as reference
            client.Scene = this;
        }
Esempio n. 3
0
        /// <summary>
        /// Clear the shader graph for this node, so it can be repopulated.
        /// </summary>
        public void Recreate()
        {
            CSycles.shader_new_graph(Client.Id, Id);

            m_nodes.Clear();

            Output = new OutputNode();
            AddNode(Output);
        }
Esempio n. 4
0
 /// <summary>
 /// Create a new shader for client.
 /// </summary>
 /// <param name="client">Client ID for C[CS]ycles API.</param>
 /// <param name="type">The type of shader to create</param>
 public Shader(Client client, ShaderType type)
 {
     Client = client;
     Type   = type;
     Id     = CSycles.create_shader(Client.Id);
     Output = new OutputNode();
     AddNode(Output);
     created_in_cycles = false;
     Verbose           = false;
 }
Esempio n. 5
0
 /// <summary>
 /// Make the actual connection between nodes.
 /// </summary>
 /// <param name="from"></param>
 /// <param name="fromout"></param>
 /// <param name="to"></param>
 /// <param name="toin"></param>
 private void Connect(ShaderNode from, string fromout, ShaderNode to, string toin)
 {
     if (m_nodes.Contains(from) && m_nodes.Contains(to))
     {
         CSycles.shader_connect_nodes(Client.Id, Id, from.Id, fromout, to.Id, toin);
     }
     else
     {
         throw new ArgumentException(String.Format("Cannot connect {0} to {1}", from, to));
     }
 }
Esempio n. 6
0
 /// <summary>
 /// Get the device with specified index
 /// </summary>
 /// <param name="idx"></param>
 /// <returns></returns>
 static public Device GetDevice(int idx)
 {
     return(new Device
     {
         Id = (uint)idx,
         Description = CSycles.device_decription(idx),
         Name = CSycles.DeviceId(idx),
         Num = CSycles.device_num(idx),
         Type = CSycles.device_type(idx),
         AdvancedShading = CSycles.device_advanced_shading(idx),
         DisplayDevice = CSycles.device_display_device(idx),
         PackImages = CSycles.device_pack_images(idx)
     });
 }
Esempio n. 7
0
        /// <summary>
        /// Add a ShaderNode to the shader. This will create the node in Cycles, set
        /// any values for sockets and direct members.
        /// </summary>
        /// <param name="node">ShaderNode to add</param>
        public void AddNode(ShaderNode node)
        {
            if (node is OutputNode)
            {
                node.Id = CSycles.OUTPUT_SHADERNODE_ID;
                m_nodes.Add(node);
                return;
            }

            if (created_in_cycles)
            {
                m_nodes.Add(node);
                return;
            }

            var nodeid = CSycles.add_shader_node(Client.Id, Id, node.Type);

            node.Id = nodeid;
            m_nodes.Add(node);
        }
Esempio n. 8
0
 /// <summary>
 /// Release lock.
 /// </summary>
 public void Unlock()
 {
     CSycles.scene_unlock(Client.Id, Id);
 }
Esempio n. 9
0
 /// <summary>
 /// True if any of the available devices is a CUDA device
 /// </summary>
 /// <returns></returns>
 static public bool CudaAvailable()
 {
     return(CSycles.number_cuda_devices() > 0);
 }
Esempio n. 10
0
 /// <summary>
 /// Tag the camera for update.
 /// </summary>
 public void Update()
 {
     CSycles.camera_update(Scene.Client.Id, Scene.Id);
 }
Esempio n. 11
0
 /// <summary>
 /// Compute auto view plane.
 /// </summary>
 public void ComputeAutoViewPlane()
 {
     CSycles.camera_compute_auto_viewplane(Scene.Client.Id, Scene.Id);
 }
Esempio n. 12
0
 /// <summary>
 /// Set view plane
 /// </summary>
 /// <param name="left"></param>
 /// <param name="right"></param>
 /// <param name="top"></param>
 /// <param name="bottom"></param>
 public void SetViewPlane(float left, float right, float top, float bottom)
 {
     CSycles.camera_set_viewplane(Scene.Client.Id, Scene.Id, left, right, top, bottom);
 }
Esempio n. 13
0
 /// <summary>
 /// Tag shader for device update
 /// </summary>
 public void Tag()
 {
     CSycles.scene_tag_shader(Client.Id, Client.Scene.Id, Id);
 }
Esempio n. 14
0
 /// <summary>
 /// Tag the film for update.
 /// </summary>
 public void Update()
 {
     CSycles.film_tag_update(Scene.Client.Id, Scene.Id);
 }
Esempio n. 15
0
        public void ReadNodeGraph(ref Shader shader, XmlReader xmlNode)
        {
            var nodes = new Dictionary <string, ShaderNode> {
                { "output", shader.Output }
            };

            while (xmlNode.Read())
            {
                ShaderNode shader_node = null;
                if (!xmlNode.IsStartElement())
                {
                    continue;
                }
                var nodename = xmlNode.GetAttribute("name");
                if (string.IsNullOrEmpty(nodename) && xmlNode.Name != "connect")
                {
                    continue;
                }

                if (string.IsNullOrEmpty(nodename))
                {
                    nodename = "";
                }

                switch (xmlNode.Name)
                {
                case "connect":
                    var fromstring = xmlNode.GetAttribute("from");
                    var tostring   = xmlNode.GetAttribute("to");
                    if (fromstring != null && tostring != null)
                    {
                        var from = fromstring.Split(' ');
                        var to   = tostring.Split(' ');

                        if (!nodes.ContainsKey(from[0]))
                        {
                            throw new KeyNotFoundException(string.Format("'from' node [{0}] not defined prior to connection.", from[0]));
                        }
                        var fromnode   = nodes[from[0]];
                        var fromsocket = fromnode.outputs.Socket(from[1]);

                        if (!nodes.ContainsKey(to[0]))
                        {
                            throw new KeyNotFoundException(string.Format("'to' node [{0}] not defined prior to connection.", to[0]));
                        }
                        var tonode   = nodes[to[0]];
                        var tosocket = tonode.inputs.Socket(to[1]);

                        fromsocket.Connect(tosocket);
                    }
                    break;

                default:
                    shader_node = CSycles.CreateShaderNode(xmlNode.Name, nodename);
                    break;
                }
                if (shader_node != null)
                {
                    shader_node.ParseXml(xmlNode);
                    nodes.Add(nodename, shader_node);
                    shader.AddNode(shader_node);
                }
            }

            shader.FinalizeGraph();
        }
Esempio n. 16
0
 /// <summary>
 /// Aqcuire lock on scene mutex blocking.
 /// </summary>
 public void Lock()
 {
     CSycles.scene_lock(Client.Id, Id);
 }
Esempio n. 17
0
 /// <summary>
 /// Try aqcuire lock on scene mutex non-blocking.
 /// </summary>
 /// <returns>True if lock was acquired, false otherwise</returns>
 public bool TryLock()
 {
     return(CSycles.scene_try_lock(Client.Id, Id));
 }
Esempio n. 18
0
        //public static uint scene_create(uint scene_params_id, uint deviceid)
        //public static uint scene_add_object(uint scene_id)
        //public static uint scene_add_mesh(uint scene_id, uint object_id, uint shader_id)
        //public static void scene_set_default_surface_shader(uint scene_id, uint shader_id)

        /// <summary>
        /// Reset the scene, forcing update and device update in Cycles.
        /// </summary>
        public void Reset()
        {
            CSycles.scene_reset(Client.Id, Id);
        }
Esempio n. 19
0
 /// <summary>
 /// Create session parameters using <c>Device</c>
 /// </summary>
 /// <param name="dev">The device to create session parameters for</param>
 public SessionParameters(Client client, Device dev)
 {
     Client  = client;
     _device = dev;
     Id      = CSycles.session_params_create(Client.Id, (uint)dev.Id);
 }
Esempio n. 20
0
 /// <summary>
 /// Set film filter type and width
 /// </summary>
 /// <param name="filterType">Box or Gaussian</param>
 /// <param name="filterWidth">for proper Box use 1.0f</param>
 public void SetFilter(FilterType filterType, float filterWidth)
 {
     CSycles.film_set_filter(Scene.Client.Id, Scene.Id, filterType, filterWidth);
 }