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

Simpler Json Format #1272

Merged
merged 10 commits into from
Sep 2, 2021
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
525 changes: 321 additions & 204 deletions libs/yocto/yocto_sceneio.cpp

Large diffs are not rendered by default.

27 changes: 18 additions & 9 deletions scripts/scene.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,18 +22,19 @@
"cameras": {
"description": "Scene cameras",
"type": "object",
"additionalProperties": {
"items": {
"description": "Camera",
"type": "object",
"properties": {
"name": {
"description": "Name",
"type": "string"
},
"frame": {
"description": "Frame",
"type": "array",
"items": {
"type": "array",
"items": {
"type": "number"
}
"type": "number"
}
},
"lens": {
Expand Down Expand Up @@ -61,11 +62,15 @@
},
"environments": {
"description": "Scene environments",
"type": "object",
"additionalProperties": {
"type": "array",
"items": {
"description": "Environment",
"type": "object",
"properties": {
"name": {
"description": "Name",
"type": "string"
},
"frame": {
"description": "Frame",
"type": "array",
Expand All @@ -89,11 +94,15 @@
},
"materials": {
"description": "Scene materials",
"type": "object",
"additionalProperties": {
"type": "array",
"items": {
"description": "Object",
"type": "object",
"properties": {
"name": {
"description": "Name",
"type": "string"
},
"emission": {
"description": "Emission",
"type": "array",
Expand Down
File renamed without changes.
47 changes: 47 additions & 0 deletions scripts/upgrade-scenes-42.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
#! /usr/bin/env python3 -B

import json, argparse
from typing import OrderedDict

def upgrade(filename, remove_names):
with open(filename) as f:
scene = json.load(f, object_pairs_hook=OrderedDict)
if scene['asset']['version'] == "4.2": return
if scene['asset']['version'] != "4.1": return
shape_map = { name: id for id, name in enumerate(scene['shapes'].keys()) } if 'shapes' in scene else {}
texture_map = { name: id for id, name in enumerate(scene['textures'].keys()) } if 'textures' in scene else {}
material_map = { name: id for id, name in enumerate(scene['materials'].keys()) } if 'materials' in scene else {}
nscene = OrderedDict()
nscene['asset'] = scene['asset']
nscene['asset']['version'] = "4.2"
for groupname in ['cameras', 'environments', 'textures', 'materials', 'shapes', 'subdivs', 'instances']:
if groupname not in scene: continue
nscene[groupname] = []
for name, item in scene[groupname].items():
nitem = OrderedDict()
nscene[groupname].append(nitem)
if not remove_names: nitem['name'] = name
if groupname in ['textures', 'shapes']:
nitem['uri'] = groupname + "/" + item
else:
nitem.update(item)
for key, value in nitem.items():
if key.endswith('_tex'): nitem[key] = texture_map[value]
if key == 'shape': nitem[key] = shape_map[value]
if key == 'material': nitem[key] = material_map[value]
if key == 'frame' and isinstance(value[0], list):
nitem[key] = value[0] + value[1] + value[2] + value[3]
if 'datafile' in nitem:
nitem['uri'] = item['datafile']
del item['datafile']
with open(filename, 'w') as f:
json.dump(nscene, f, indent=2)

parser = argparse.ArgumentParser(description='Upgrades scene.')
parser.add_argument('scenes', type=str, nargs='+')
parser.add_argument('--remove-names', action='store_true', default=False)
args = parser.parse_args()

for filename in args.scenes:
print(filename)
upgrade(filename, args.remove_names)
Loading