Make blender addon persistent and restore gpu processing for non-blender rendering

pull/54/head
James Ball 2022-04-30 10:18:32 +01:00
rodzic 934954f4d5
commit 3efaa0ce88
3 zmienionych plików z 26 dodań i 20 usunięć

Wyświetl plik

@ -1,7 +1,7 @@
bl_info = {
"name": "osci-render",
"author": "James Ball",
"version": (1, 0, 0),
"version": (1, 0, 2),
"blender": (3, 1, 2),
"location": "View3D",
"description": "Addon to send gpencil frames over to osci-render",
@ -14,6 +14,7 @@ import bpy
import bmesh
import socket
import json
from bpy.app.handlers import persistent
HOST = "localhost"
PORT = 51677
@ -82,8 +83,8 @@ def append_matrix(object_info, obj):
return object_info
@persistent
def send_scene_to_osci_render(scene):
col = bpy.context.scene.collection["osci_render"]
engine_info = {"objects": []}
if sock is not None:
@ -120,9 +121,9 @@ def register():
def unregister():
bpy.app.handlers.frame_change_pre.clear()
bpy.app.handlers.depsgraph_update_post.clear()
for operation in operations.reverse():
bpy.app.handlers.frame_change_pre.remove(send_scene_to_osci_render)
bpy.app.handlers.depsgraph_update_post.remove(send_scene_to_osci_render)
for operation in reversed(operations):
bpy.utils.unregister_class(operation)

Wyświetl plik

@ -6,7 +6,7 @@
<groupId>sh.ball</groupId>
<artifactId>osci-render</artifactId>
<version>1.21.1</version>
<version>1.22.0</version>
<name>osci-render</name>

Wyświetl plik

@ -95,7 +95,9 @@ public class CameraDrawKernel extends Kernel {
this.cameraPosY = 0;
this.cameraPosZ = 0;
return executeKernel();
this.hideEdges = 0;
return executeKernel(true);
}
public List<Shape> draw(Camera camera, WorldObject object) {
@ -123,24 +125,27 @@ public class CameraDrawKernel extends Kernel {
this.cameraPosZ = (float) cameraPos.z;
this.focalLength = (float) camera.getFocalLength();
hideEdges = object.edgesHidden() ? 1 : 0;
return executeKernel();
this.hideEdges = object.edgesHidden() ? 1 : 0;
return executeKernel(false);
}
private List<Shape> executeKernel() {
int maxGroupSize = 256;
try {
maxGroupSize = getKernelMaxWorkGroupSize(getTargetDevice());
} catch (QueryFailedException e) {
e.printStackTrace();
}
private List<Shape> executeKernel(boolean cpu) {
if (cpu) {
for (int i = 0; i < vertices.length / 3; i++) {
processVertex(i);
}
} else {
int maxGroupSize = 256;
try {
maxGroupSize = getKernelMaxWorkGroupSize(getTargetDevice());
} catch (QueryFailedException e) {
e.printStackTrace();
}
for (int i = 0; i < vertices.length / 3; i++) {
processVertex(i);
execute(Range.create(roundUp(vertices.length / 3, maxGroupSize), maxGroupSize));
}
//execute(Range.create(roundUp(vertices.length / 3, maxGroupSize), maxGroupSize));
List<Shape> linesList = new ArrayList<>();
for (int i = 0; i < vertices.length / 3; i++) {