Skip to content

Commit

Permalink
automate data
Browse files Browse the repository at this point in the history
  • Loading branch information
JR-Morgan committed Oct 12, 2023
1 parent 7ffee63 commit 97a071c
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 28 deletions.
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM python:3.11-slim
FROM nytimes/blender:latest

RUN pip install poetry

Expand Down
17 changes: 14 additions & 3 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,26 @@ def automate_function(
automate_context: AutomationContext
) -> None:

account = automate_context.speckle_client.account
AccountStorage.SaveObject(account.id, JsonConvert.SerializeObject(account));
client = automate_context.speckle_client
PROJECT_ID = automate_context.automation_run_data.project_id
VERSION_ID = automate_context.automation_run_data.version_id
OBJECT_ID = client.commit.get(PROJECT_ID, VERSION_ID).referencedObject

DATA = f"""
TOKEN = '{client.account.token}'
SERVER_URL = '{client.account.serverInfo.url}'
PROJECT_ID = '{PROJECT_ID}'
OBJECT_ID = '{OBJECT_ID}'
"""

Path.write_text(Path("./automate_data.py"), DATA)

run(
[
'blender',
'"environment.blend"',
'--background',
'--python speckle_import.py',
'-f 10',
],
capture_output=True,
text=True,
Expand Down
47 changes: 23 additions & 24 deletions speckle_import.py
Original file line number Diff line number Diff line change
@@ -1,49 +1,48 @@
import bpy
import os
from bpy_speckle.properties.scene import SpeckleSceneSettings
from bpy_speckle.convert.to_native import _deep_conversion

from specklepy.api import operations
from specklepy.transports.server import ServerTransport
from automate_data import *




def take_screenshot():
bpy.ops.render.render(write_still = True)
print(f"We took a screenshot! saved at {bpy.context.scene.render.filepath}")

def set_output_path(commitId, cameraName):
#Get Output file directory
def set_filename(fileName):
"""Sets the output directory for rendered images"""
filepath = bpy.data.filepath
filename = os.path.basename(filepath)
directory = os.path.dirname(filepath)
if not filepath:
raise Exception("Blend file must be saved!")

bpy.context.scene.render.filepath = os.path.join(directory, "Screenshots", f"{commitId}.{cameraName}")
bpy.context.scene.render.filepath = os.path.join(directory, "Screenshots", fileName)


print(f"Starting Receive...")

remote_transport = ServerTransport(STREAMID, token=TOKEN, url=SERVER_URL)
commit_object = operations.receive(OBJECTID, remote_transport)

speckle: SpeckleSceneSettings = bpy.context.scene.speckle
converted_objects = {}
_deep_conversion(commit_object, converted_objects, True)


print("hello speckle screenshot tool!")
bpy.ops.speckle.users_load()
bpy.ops.speckle.receive_stream_objects()


print(f"We received the objects!")
all_cameras = [o for o in bpy.context.scene.objects if o.type == 'CAMERA']
total = len(all_cameras)

print(f"Starting rendering cameras... 0/{total}")



for ob in bpy.context.scene.objects:
if ob.type != 'CAMERA':
continue
for (i, ob) in enumerate(all_cameras):
#Set as active render cam
bpy.context.scene.camera = ob
commit = speckle.get_active_user().get_active_stream().get_active_branch().get_active_commit()
set_output_path(commit.id, ob.name)
take_screenshot()

#Render camera to output directory
set_filename(f"{ob.name}")
bpy.ops.render.render(write_still = True)
print(f"Render {i}/{total} complete! saved at {bpy.context.scene.render.filepath}")

print(f"All Done!")



0 comments on commit 97a071c

Please sign in to comment.