예제 #1
0
        /// <summary>
        /// Generates the maps for the supplied PQS configuration and returns them as encoded PNG bytes
        /// </summary>
        public async Task <EncodedTextureData> GenerateMapsEncoded(NodeTree pqsConfig)
        {
            // I am going to use files for the communication, because I am not sure how the pip handles large data
            String configPath = Path.GetTempFileName();

            File.WriteAllText(configPath, pqsConfig.ToString());

            // Start a new channel
            String channel = Guid.NewGuid().ToString();
            await _server.SendMessage("GENERATE-MAPS-ENCODED", channel);

            await _server.SendMessage(channel, configPath);

            // Does the application return any errors?
            String error = await _server.ReadMessage(channel + "-ERR");

            if (error != "NONE")
            {
                throw new Exception(error);
            }

            // Request the paths to the exported maps
            String color = await _server.ReadMessage(channel);

            String height = await _server.ReadMessage(channel);

            String normal = await _server.ReadMessage(channel);

            // Load the maps and return them
            return(new EncodedTextureData
            {
                Color = new DestructableFileStream(File.OpenRead(color), color),
                Height = new DestructableFileStream(File.OpenRead(height), height),
                Normal = new DestructableFileStream(File.OpenRead(normal), normal)
            });
        }
예제 #2
0
        /// <summary>
        /// Generates the maps for the supplied PQS configuration and returns them as raw color arrays
        /// </summary>
        public async Task <RawTextureData> GenerateMapsRaw(NodeTree pqsConfig)
        {
            // I am going to use files for the communication, because I am not sure how the pip handles large data
            String configPath = Path.GetTempFileName();

            File.WriteAllText(configPath, pqsConfig.ToString());

            // Start a new channel
            String channel = Guid.NewGuid().ToString();
            await _server.SendMessage("GENERATE-MAPS-RAW", channel);

            await _server.SendMessage(channel, configPath);

            // Does the application return any errors?
            String error = await _server.ReadMessage(channel + "-ERR");

            if (error != "NONE")
            {
                throw new Exception(error);
            }

            // Request the paths to the exported maps
            String color = await _server.ReadMessage(channel);

            String height = await _server.ReadMessage(channel);

            String normal = await _server.ReadMessage(channel);

            String size = await _server.ReadMessage(channel);

            RawTextureData data = new RawTextureData();

            Int32.TryParse(size, out Int32 texWidth);
            Int32 texHeight = texWidth / 2;

            // Create the color arrays
            data.Color  = new Color[texWidth, texHeight];
            data.Height = new Color[texWidth, texHeight];
            data.Normal = new Color[texWidth, texHeight];

            // Load the maps
            FileStream colorData  = File.OpenRead(color);
            FileStream heightData = File.OpenRead(height);
            FileStream normalData = File.OpenRead(normal);

            // Load the colormap
            Byte[] buffer = new Byte[16];
            for (Int32 y = 0; y < texHeight; y++)
            {
                for (Int32 x = 0; x < texWidth; x++)
                {
                    // Color
                    await colorData.ReadAsync(buffer, 0, 16);

                    Color c = new Color();
                    c.r = BitConverter.ToSingle(buffer, 0);
                    c.g = BitConverter.ToSingle(buffer, 4);
                    c.b = BitConverter.ToSingle(buffer, 8);
                    c.a = BitConverter.ToSingle(buffer, 12);
                    data.Color[x, y] = c;

                    // Height
                    await heightData.ReadAsync(buffer, 0, 16);

                    c   = new Color();
                    c.r = BitConverter.ToSingle(buffer, 0);
                    c.g = BitConverter.ToSingle(buffer, 4);
                    c.b = BitConverter.ToSingle(buffer, 8);
                    c.a = BitConverter.ToSingle(buffer, 12);
                    data.Height[x, y] = c;

                    // Normal
                    await normalData.ReadAsync(buffer, 0, 16);

                    c   = new Color();
                    c.r = BitConverter.ToSingle(buffer, 0);
                    c.g = BitConverter.ToSingle(buffer, 4);
                    c.b = BitConverter.ToSingle(buffer, 8);
                    c.a = BitConverter.ToSingle(buffer, 12);
                    data.Normal[x, y] = c;
                }
            }

            // Unload the maps
            colorData.Close();
            colorData.Dispose();
            heightData.Close();
            heightData.Dispose();
            normalData.Close();
            normalData.Dispose();

            // Return the maps
            return(data);
        }
예제 #3
0
 /// <summary>
 /// Add a subnode to the node
 /// </summary>
 public void SetNode(String name, NodeTree node)
 {
     _nodes.Add(new KeyValuePair <String, NodeTree>(name, node));
 }