Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Scene publishing support #255

Merged
merged 11 commits into from
Feb 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
90 changes: 90 additions & 0 deletions addons/io_hubs_addon/api.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
import requests


def create_room(endpoint, token=None, scene_name=None, scene_id=None):
payload = {}
if scene_id:
payload = {
"hub": {
"name": scene_name,
"scene_id": scene_id
}
}

headers = {}
if token:
headers = {
"content-type": "application/json",
"authorization": f'Bearer {token}'
}

import json
body = json.dumps(payload)

url = f'{endpoint}/api/v1/hubs'
resp = requests.post(url, body, headers=headers)

return resp.json()


def upload_media(endpoint, file):
resp = requests.post(f'{endpoint}/api/v1/media', files={'media': (
'glb', file, 'application/octet-stream')}, verify=False)
json = resp.json()
Exairnous marked this conversation as resolved.
Show resolved Hide resolved

if "error" in json:
raise Exception(f'Unknown error')

return {
"file_id": json.get("file_id"),
"access_token": json.get("meta").get("access_token")
}


def publish_scene(endpoint, token, scene_data, scene_id=None):
headers = {
"content-type": "application/json",
"authorization": f'Bearer {token}'
}

import json
body = json.dumps({"scene": scene_data})

url = f'{endpoint}/api/v1/scenes{"/" + scene_id if scene_id else ""}'
if scene_id:
resp = requests.put(url, body, headers=headers)
else:
resp = requests.post(url, body, headers=headers)

jsonFile = resp.json()
if "error" in jsonFile:
error = jsonFile.get("error")
if error == "invalid_token":
raise Exception("Authentication error")
else:
raise Exception(f'Unknown error: {error}')

return jsonFile


def get_projects(endpoint, token):
headers = {
"content-type": "application/json",
"authorization": f'Bearer {token}'
}

resp = requests.get(
f'{endpoint}/api/v1/scenes/projectless', headers=headers)

jsonFile = resp.json()
if "error" in jsonFile:
error = jsonFile.get("error")
if error == "invalid_token":
raise Exception("Authentication error")
else:
raise Exception(f'Unknown error: {error}')

if "scenes" not in jsonFile:
raise Exception(f'Projects request error')
scenes = jsonFile.get("scenes")
return scenes
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ def draw(self, context, layout, panel):
sub_row.enabled = False
add_link_indicator(sub_row, self.backgroundTexture)

row.context_pointer_set("hubs_component", self)
row.context_pointer_set("target", self)
row.context_pointer_set("host", context.scene)
op = row.operator("image.hubs_open_image", text='', icon='FILE_FOLDER')
op.target_property = "backgroundTexture"
Expand All @@ -112,7 +112,7 @@ def draw(self, context, layout, panel):
sub_row.enabled = False
add_link_indicator(sub_row, self.envMapTexture)

row.context_pointer_set("hubs_component", self)
row.context_pointer_set("target", self)
row.context_pointer_set("host", context.scene)
op = row.operator("image.hubs_open_image", text='', icon='FILE_FOLDER')
op.target_property = "envMapTexture"
Expand Down
6 changes: 3 additions & 3 deletions addons/io_hubs_addon/components/operators.py
Original file line number Diff line number Diff line change
Expand Up @@ -646,14 +646,14 @@ def execute(self, context):
self.report({'INFO'}, "Open image cancelled. No image selected.")
return {'CANCELLED'}

old_img = self.hubs_component[self.target_property]
old_img = getattr(self.target, self.target_property)

# Load/Reload the first image and assign it to the target property, then load the rest of the images if they're not already loaded. This mimics Blender's default open files behavior.
primary_filepath = os.path.join(dirname, self.files[0].name)
primary_img = bpy.data.images.load(
filepath=primary_filepath, check_existing=True)
primary_img.reload()
self.hubs_component[self.target_property] = primary_img
setattr(self.target, self.target_property, primary_img)

for f in self.files[1:]:
bpy.data.images.load(filepath=os.path.join(
Expand All @@ -665,7 +665,7 @@ def execute(self, context):

def invoke(self, context, event):
self.filepath = ""
self.hubs_component = context.hubs_component
self.target = context.target
context.window_manager.fileselect_add(self)
return {'RUNNING_MODAL'}

Expand Down
Loading
Loading