Skip to content

Commit

Permalink
Fix image rendering
Browse files Browse the repository at this point in the history
  • Loading branch information
pragma37 committed Nov 16, 2023
1 parent f7e8a92 commit f81a3c5
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 30 deletions.
20 changes: 0 additions & 20 deletions BlenderMalt/CBlenderMalt/CBlenderMalt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -152,23 +152,3 @@ EXPORT bool has_flat_polys(void* in_mesh, int polys_count)

return false;
}

struct RenderPass {
struct RenderPass *next, *prev;
int channels;
char name[64];
char chan_id[8];
float *rect;
int rectx, recty;

char fullname[64];
char view[64];
int view_id;

int pad;
};

EXPORT float* get_rect_ptr(void* render_pass_ptr)
{
return ((RenderPass*)render_pass_ptr)->rect;
}
4 changes: 0 additions & 4 deletions BlenderMalt/CBlenderMalt/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,3 @@
has_flat_polys = CBlenderMalt['has_flat_polys']
has_flat_polys.argtypes = [ctypes.c_void_p, ctypes.c_int]
has_flat_polys.restype = ctypes.c_bool

get_rect_ptr = CBlenderMalt['get_rect_ptr']
get_rect_ptr.argtypes = [ctypes.c_void_p]
get_rect_ptr.restype = ctypes.POINTER(ctypes.c_float)
5 changes: 3 additions & 2 deletions BlenderMalt/MaltRenderEngine.py
Original file line number Diff line number Diff line change
Expand Up @@ -275,8 +275,7 @@ def render(self, depsgraph):
if key == 'Combined': buffer_name = 'COLOR'
if key == 'Depth': buffer_name = 'DEPTH'
if buffer_name in buffers and hasattr(buffers[buffer_name], 'buffer'):
rect_ptr = CBlenderMalt.get_rect_ptr(value.as_pointer())
ctypes.memmove(rect_ptr, buffers[buffer_name].buffer(), size*4*value.channels)
value.rect = buffers[buffer_name].as_np_array((size , value.channels))

self.end_result(result)
# Delete the scene. Otherwise we get memory leaks.
Expand All @@ -287,7 +286,9 @@ def view_update(self, context, depsgraph):
self.request_new_frame = True
self.request_scene_update = True

print('------------UPDATE---------------')
for update in depsgraph.updates:
print(update.id, update.is_updated_transform, update.is_updated_geometry, update.is_updated_shading)
if update.is_updated_geometry:
if isinstance(update.id, bpy.types.Object):
MaltMeshes.unload_mesh(update.id)
Expand Down
11 changes: 7 additions & 4 deletions Malt/Utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ def size_in_bytes(self):
import ctypes
return ctypes.sizeof(self.ctype()) * len(self)

def as_array_interface(self):
def as_array_interface(self, shape=None):
import ctypes
type_map = {
ctypes.c_float : 'f',
Expand All @@ -120,12 +120,15 @@ def as_array_interface(self):
ctypes.c_bool : 'b',
}

if shape is None:
shape = (len(self),)

return Array_Interface(
ctypes.addressof(self.buffer()),
type_map[self.ctype()],
(len(self),)
shape
)

def as_np_array(self):
def as_np_array(self, shape=None):
import numpy as np
return np.array(self.as_array_interface(), copy=False)
return np.array(self.as_array_interface(shape), copy=False)

0 comments on commit f81a3c5

Please sign in to comment.