Some minor cleanup in the Blender/Psychopath communication code.
This commit is contained in:
parent
69ace90689
commit
d132e6a015
|
@ -77,7 +77,7 @@ class PsychopathRender(bpy.types.RenderEngine):
|
||||||
|
|
||||||
# Start Rendering!
|
# Start Rendering!
|
||||||
try:
|
try:
|
||||||
self._process = subprocess.Popen([psy_binary] + args, bufsize=1, stdin=subprocess.PIPE, stdout=subprocess.PIPE)
|
self._process = subprocess.Popen([psy_binary] + args, stdin=subprocess.PIPE, stdout=subprocess.PIPE)
|
||||||
except OSError:
|
except OSError:
|
||||||
# TODO, report api
|
# TODO, report api
|
||||||
print("Psychopath: could not execute '%s'" % psy_binary)
|
print("Psychopath: could not execute '%s'" % psy_binary)
|
||||||
|
@ -99,16 +99,16 @@ class PsychopathRender(bpy.types.RenderEngine):
|
||||||
height = bucket_info[3] - bucket_info[1]
|
height = bucket_info[3] - bucket_info[1]
|
||||||
|
|
||||||
# Decode pixel data
|
# Decode pixel data
|
||||||
pixels = [p for p in struct.iter_unpack("ffff", base64.b64decode(pixels_encoded))]
|
pixels_unpacked = [p for p in struct.iter_unpack("ffff", base64.b64decode(pixels_encoded))]
|
||||||
pixels_flipped = []
|
pixels = []
|
||||||
for i in range(height):
|
for i in range(height):
|
||||||
n = height - i - 1
|
n = height - i - 1
|
||||||
pixels_flipped += pixels[n*width:(n+1)*width]
|
pixels += pixels_unpacked[n*width:(n+1)*width]
|
||||||
|
|
||||||
# Write pixel data to render image
|
# Write pixel data to render image
|
||||||
result = self.begin_result(x, y, width, height)
|
result = self.begin_result(x, y, width, height)
|
||||||
lay = result.layers[0].passes["Combined"]
|
lay = result.layers[0].passes["Combined"]
|
||||||
lay.rect = pixels_flipped
|
lay.rect = pixels
|
||||||
self.end_result(result)
|
self.end_result(result)
|
||||||
|
|
||||||
def _render(self, depsgraph):
|
def _render(self, depsgraph):
|
||||||
|
|
|
@ -74,7 +74,6 @@ register_engine_with_panels(
|
||||||
"DATA_PT_mesh_attributes",
|
"DATA_PT_mesh_attributes",
|
||||||
"DATA_PT_normals",
|
"DATA_PT_normals",
|
||||||
"DATA_PT_remesh",
|
"DATA_PT_remesh",
|
||||||
"DATA_PT_sculpt_vertex_colors",
|
|
||||||
"DATA_PT_shape_keys",
|
"DATA_PT_shape_keys",
|
||||||
"DATA_PT_texture_space",
|
"DATA_PT_texture_space",
|
||||||
"DATA_PT_uv_texture",
|
"DATA_PT_uv_texture",
|
||||||
|
|
32
src/image.rs
32
src/image.rs
|
@ -235,25 +235,39 @@ impl<'a> Bucket<'a> {
|
||||||
/// encoding to base64. The fourth channel is alpha, and is set to 1.0 for
|
/// encoding to base64. The fourth channel is alpha, and is set to 1.0 for
|
||||||
/// all pixels.
|
/// all pixels.
|
||||||
pub fn rgba_base64<F>(&mut self, color_convert: F) -> String
|
pub fn rgba_base64<F>(&mut self, color_convert: F) -> String
|
||||||
|
where
|
||||||
|
F: Fn((f32, f32, f32)) -> (f32, f32, f32),
|
||||||
|
{
|
||||||
|
let data_u8 = self.rgba_raw(color_convert);
|
||||||
|
base64::encode(&data_u8)
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Returns the bucket's contents as a binary string.
|
||||||
|
///
|
||||||
|
/// The data is laid out as four-floats-per-pixel in scanline order.
|
||||||
|
/// The fourth channel is alpha, and is set to 1.0 for all pixels.
|
||||||
|
///
|
||||||
|
/// `color_convert` lets you do a colorspace conversion before base64
|
||||||
|
/// encoding if desired.
|
||||||
|
pub fn rgba_raw<F>(&mut self, color_convert: F) -> Vec<u8>
|
||||||
where
|
where
|
||||||
F: Fn((f32, f32, f32)) -> (f32, f32, f32),
|
F: Fn((f32, f32, f32)) -> (f32, f32, f32),
|
||||||
{
|
{
|
||||||
use std::slice;
|
use std::slice;
|
||||||
let mut data = Vec::with_capacity(
|
let mut data: Vec<u8> = Vec::with_capacity(
|
||||||
(4 * (self.max.0 - self.min.0) * (self.max.1 - self.min.1)) as usize,
|
std::mem::size_of::<f32>()
|
||||||
|
* (4 * (self.max.0 - self.min.0) * (self.max.1 - self.min.1)) as usize,
|
||||||
);
|
);
|
||||||
for y in self.min.1..self.max.1 {
|
for y in self.min.1..self.max.1 {
|
||||||
for x in self.min.0..self.max.0 {
|
for x in self.min.0..self.max.0 {
|
||||||
let color = color_convert(self.get(x, y).to_tuple());
|
let color = color_convert(self.get(x, y).to_tuple());
|
||||||
data.push(color.0);
|
data.extend_from_slice(&color.0.to_ne_bytes());
|
||||||
data.push(color.1);
|
data.extend_from_slice(&color.1.to_ne_bytes());
|
||||||
data.push(color.2);
|
data.extend_from_slice(&color.2.to_ne_bytes());
|
||||||
data.push(1.0);
|
data.extend_from_slice(&1.0f32.to_ne_bytes());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
let data_u8 =
|
data
|
||||||
unsafe { slice::from_raw_parts(&data[0] as *const f32 as *const u8, data.len() * 4) };
|
|
||||||
base64::encode(data_u8)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -293,16 +293,26 @@ impl<'a> Renderer<'a> {
|
||||||
let new_string = format!("{:.2}%", percentage_new);
|
let new_string = format!("{:.2}%", percentage_new);
|
||||||
|
|
||||||
if let Some(bucket_data) = base64_enc {
|
if let Some(bucket_data) = base64_enc {
|
||||||
|
let mut stdout = std::io::stdout().lock();
|
||||||
// If doing Blender output
|
// If doing Blender output
|
||||||
println!("DIV");
|
stdout.write_all(b"DIV\n").unwrap();
|
||||||
println!("{}", new_string);
|
stdout
|
||||||
println!(
|
.write_all(format!("{}\n", new_string).as_bytes())
|
||||||
"{} {} {} {}",
|
.unwrap();
|
||||||
bucket_min.0, bucket_min.1, bucket_max.0, bucket_max.1
|
stdout
|
||||||
);
|
.write_all(
|
||||||
println!("{}", bucket_data);
|
format!(
|
||||||
println!("BUCKET_END");
|
"{} {} {} {}\n",
|
||||||
println!("DIV");
|
bucket_min.0, bucket_min.1, bucket_max.0, bucket_max.1
|
||||||
|
)
|
||||||
|
.as_bytes(),
|
||||||
|
)
|
||||||
|
.unwrap();
|
||||||
|
stdout
|
||||||
|
.write_all(format!("{}\n", bucket_data).as_bytes())
|
||||||
|
.unwrap();
|
||||||
|
stdout.write_all(b"BUCKET_END\n").unwrap();
|
||||||
|
stdout.write_all(b"DIV\n").unwrap();
|
||||||
} else {
|
} else {
|
||||||
// If doing console output
|
// If doing console output
|
||||||
if new_string != old_string {
|
if new_string != old_string {
|
||||||
|
|
Loading…
Reference in New Issue
Block a user