Skip to content

Commit

Permalink
Merge pull request #22 from Baldrax/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
Baldrax authored May 6, 2023
2 parents 5fdb276 + a84a0e2 commit 89be8af
Show file tree
Hide file tree
Showing 30 changed files with 155 additions and 18 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ venv/
#ignore example ts_terrain
hip/examples/ts_terrain/

#ignore image caches
images/cache/

#ignore other files
.userconfigs
notes.md
Expand All @@ -20,3 +23,4 @@ notes.md
.OPdummydefs
.createtimes
.modtimes

Binary file added geo/ts_proxies/Cave_Floor_-_Rock_01_2x2.bgeo.sc
Binary file not shown.
Binary file added geo/ts_proxies/Cave_Floor_-_Rock_2_1x1.bgeo.sc
Binary file not shown.
Binary file added geo/ts_proxies/Desert_floor_01_1x1.bgeo.sc
Binary file not shown.
Binary file added geo/ts_proxies/Desert_floor_02_2x2.bgeo.sc
Binary file not shown.
Binary file added geo/ts_proxies/Desert_floor_03_1x1.bgeo.sc
Binary file not shown.
Binary file added geo/ts_proxies/Desert_floor_04_2x2.bgeo.sc
Binary file not shown.
Binary file added geo/ts_proxies/Desert_roof_01_1x1.bgeo.sc
Binary file not shown.
Binary file added geo/ts_proxies/Desert_roof_02_2x2.bgeo.sc
Binary file not shown.
Binary file added geo/ts_proxies/Lava_floor_1x1_ashes.bgeo.sc
Binary file not shown.
Binary file added geo/ts_proxies/Lava_floor_2x2_ashes.bgeo.sc
Binary file not shown.
Binary file added geo/ts_proxies/tempWater1x1.bgeo.sc
Binary file not shown.
Binary file added geo/ts_proxies/tempWater2x2.bgeo.sc
Binary file not shown.
Binary file modified hip/examples/biomes.hipnc
Binary file not shown.
Binary file added hip/examples/water_tile_examples.hipnc
Binary file not shown.
Binary file modified hip/proxies/terrain_proxies.hipnc
Binary file not shown.
Binary file modified otls/OBJ_TaleSpire_Biome.hdanc
Binary file not shown.
Binary file modified otls/OBJ_TaleSpire_Object.hdanc
Binary file not shown.
Binary file modified otls/OBJ_TaleSpire_Terrain.hdanc
Binary file not shown.
Binary file modified otls/SOP_TaleSpire_Copy.hdanc
Binary file not shown.
Binary file modified otls/SOP_TaleSpire_Export.hdanc
Binary file not shown.
Binary file added otls/SOP_TaleSpire_Fetch_Water.hdanc
Binary file not shown.
Binary file modified otls/SOP_TaleSpire_Scatter.hdanc
Binary file not shown.
Binary file added otls/SOP_TaleSpire_Set_Water_Level.hdanc
Binary file not shown.
Binary file modified otls/SOP_TaleSpire_Tiler.hdanc
Binary file not shown.
102 changes: 95 additions & 7 deletions scripts/python/htg/nodes/OBJ_TaleSpire_Shared_Data.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
import talespire.assets
import os
import htg.configs as ts_configs
from PIL import Image
from PIL import ImageChops


def build_ts_database(node):
Expand All @@ -16,23 +18,37 @@ def build_ts_database(node):
geo.addAttrib(hou.attribType.Point, 'm_Center', hou.Vector3([0, 0, 0]))
geo.addAttrib(hou.attribType.Point, 'm_Extent', hou.Vector3([0, 0, 0]))
geo.addArrayAttrib(hou.attribType.Point, 'Tags', hou.attribData.String)
geo.addAttrib(hou.attribType.Point, 'Folder', '')
geo.addAttrib(hou.attribType.Point, 'proxy_path', '')
geo.addAttrib(hou.attribType.Point, 'texture_path', '')
geo.addAttrib(hou.attribType.Point, 'IconAtlas', '')
geo.addAttrib(hou.attribType.Point, 'IconRegion', hou.Vector4([0, 0, 0, 0]))

cfg = ts_configs.Configs()
ts_basepath = cfg.get_config('talespire_directory')
if not os.path.isdir(ts_basepath):
hou.ui.displayMessage('ERROR: TaleSpire directory not found, check the settings on the TaleSpire Terrain Node!',
asset_dicts = talespire.assets.get_asset_dicts(ts_basepath)

if asset_dicts is None or len(asset_dicts) == 0:
hou.ui.displayMessage('ERROR: Unable to find TaleSpire asset definitions, check the talespire_directory in '
'the settings tab of the TaleSpire Terrain Node. TaleSpire must be installed on this '
'machine in order to use the toolset.',
details=ts_basepath, severity=hou.severityType.Error)
return None
index_dict_list = talespire.assets.get_assets(ts_basepath)

proxy_names = []
htg_basedir = hou.text.expandString('$HTG_BASEDIR')
for proxy_file in os.listdir(os.path.join(htg_basedir, 'geo', 'ts_proxies')):
proxy_names.append(proxy_file.split('.')[0])

seen_ids = []
for index_dict in index_dict_list:
for index_name in asset_dicts:
index_path = asset_dicts[index_name]['path']
index_dict = asset_dicts[index_name]['index']

icon_atlases = list()
for atlas_entry in index_dict['IconsAtlases']:
icon_atlases.append(atlas_entry['Path'])

for type in index_dict:
if type in ['Tiles', 'Props']:
for asset_dict in index_dict[type]:
Expand Down Expand Up @@ -62,6 +78,7 @@ def build_ts_database(node):
point.setAttribValue('IsDeprecated', asset_dict['IsDeprecated'])
point.setAttribValue('GroupTag', asset_dict['GroupTag'])
point.setAttribValue('Tags', asset_tags)
point.setAttribValue('Folder', asset_dict['Folder'])

m_Center = asset_dict['ColliderBoundsBound']['m_Center']
m_Extent = asset_dict['ColliderBoundsBound']['m_Extent']
Expand All @@ -71,15 +88,86 @@ def build_ts_database(node):

extent = (m_Extent['x'], m_Extent['y'], m_Extent['z'])
if extent in ((1.0, 0.25, 1.0), (0.5, 0.25, 0.5)):
isfloor = True
is_floor = True
else:
isfloor = False
is_floor = False

proxy_name = asset_name.replace(' ', '_').replace('/', '_').replace('(', '_').replace(')', '_')
if proxy_name in proxy_names:
point.setAttribValue('proxy_path',
'{}/geo/ts_proxies/{}.bgeo.sc'.format(htg_basedir, proxy_name))
elif isfloor and tag_name.strip() in ('1x1', '2x2'):
elif is_floor and tag_name.strip() in ('1x1', '2x2'):
point.setAttribValue('proxy_path',
'{}/geo/ts_proxies/Standin_floor_{}.bgeo.sc'.format(htg_basedir,
tag_name.strip()))
atlas_index = asset_dict['Icon']['AtlasIndex']
point.setAttribValue('IconAtlas', os.path.join(os.path.dirname(index_path), icon_atlases[atlas_index]))
atlas_region = asset_dict['Icon']['Region']
point.setAttribValue('IconRegion', hou.Vector4(
[atlas_region['x'],
atlas_region['y'],
atlas_region['width'],
atlas_region['height']
]))


def process_images(node, process_type='textures'):
geo = node.geometry()
img_dict = dict()

for point in geo.points():
icon_atlas = point.attribValue('IconAtlas')
icon_region = point.attribValue('IconRegion')
uuid = point.attribValue('Id')

if uuid == 'b83392b1-8833-43c9-a97f-2ac3df659e66' or True:
if icon_atlas not in img_dict:
img_dict[icon_atlas] = []

img_dict[icon_atlas].append({'uuid': uuid, 'region': icon_region})

for icon_atlas in img_dict:
task_list = img_dict[icon_atlas]
im = Image.open(icon_atlas)
x_size, y_size = im.size
print(icon_atlas)

for task_dict in task_list:
uuid = task_dict['uuid']
region = task_dict['region']
output_path = '{}/images/cache/{}/{}.png'.format(hou.text.expandString('$HTG_BASEDIR'), process_type, uuid)
left = (region[0])*x_size
right = left+region[2]*x_size
lower = (1-region[1])*y_size
upper = lower-region[3]*y_size
crop_area = (left, upper, right, lower)
print(output_path)
print(crop_area)
img = im.crop(crop_area)

if process_type == 'textures':
img = simple_texture(img)

img.save(output_path)


def simple_texture(image):
fg = image.convert('RGB')

ys = Image.new('RGBA', image.size, (0, 0, 0, 255))
xs01 = Image.new('RGBA', image.size, (0, 0, 0, 255))
xs02 = Image.new('RGBA', image.size, (0, 0, 0, 255))

ys.paste(fg, (0, 8), image)
ys.paste(fg, (0, -8), image)

xs01.paste(fg, (-8, 0), image)
xs02.paste(fg, (8, 0), image)

xs = ImageChops.lighter(xs01, xs02)

combo = ImageChops.lighter(ys, xs)

combo.paste(fg, (0, 0), image)

return combo
7 changes: 2 additions & 5 deletions scripts/python/htg/nodes/OBJ_TaleSpire_Terrain.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,8 @@ def write_config(parm=None):
cfg.set_config(cfg_name, parm.eval())

if cfg_name == 'talespire_directory':
if os.path.isdir(parm.eval()):
ts_data = ts_common.SharedData()
ts_data.cook_database_node()
else:
hou.ui.displayMessage('The Directory is not Valid. You must select a valid TaleSpire install directory.')
ts_data = ts_common.SharedData()
ts_data.cook_database_node()


def load_default_networks(node=None):
Expand Down
30 changes: 28 additions & 2 deletions scripts/python/htg/nodes/SOP_TaleSpire_Export.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@


def set_slab_range(node=None):
force_update(node)
si1_parm = node.parm('slabindex1')
si2_parm = node.parm('slabindex2')
slabs_node = hou.node(node.path()+'/NUM_SLABS')
Expand All @@ -22,6 +23,18 @@ def copy_slab_from_node(node=None):
htg.utils.copy_to_clipboard(slab.strip("b'`"))


def copy_slab(node=None):
slab_node = hou.node(node.path() + '/OUT')
force_update(node)
copy_slab_from_node(node=slab_node)


def force_update(node=None):
current_frame = hou.frame()
grid_node = hou.node(node.path() + '/grid_neg_Z')
grid_node.cook(force=True, frame_range=(current_frame, current_frame+1))


def get_js(geonode=None):
geo = geonode.geometry()
uuid_data = {}
Expand Down Expand Up @@ -67,10 +80,11 @@ def get_slab_with_pos(node=None):


def encode_slabs(node=None):
num_assets = 1 # Disabled while developing
force_update(node)
num_assets = asset_count(node)
do_export = True
if num_assets >= 1000000:
button_result = hou.ui.displayMessage('Warning: This map contains more that 1 Million assets.\n'
button_result = hou.ui.displayMessage('Warning: This export contains more that 1 Million assets.\n'
'TaleSpire will likely crash.\n'
'Are you sure you want to do this?',
buttons=('OK', 'Cancel'))
Expand All @@ -91,3 +105,15 @@ def encode_slabs(node=None):
slab_json.append(slab_pos)
htg.utils.copy_to_clipboard(json.dumps(slab_json))
slab_index_parm.set(og_index)


def asset_count(node=None):
try:
asset_node = hou.node(node.path() + '/INFO')
geo = asset_node.geometry()
points = geo.points()
num_assets = len(points)
except AttributeError:
num_assets = 0

return num_assets
20 changes: 20 additions & 0 deletions scripts/python/htg/nodes/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,26 @@ def ts_assets_menu():
pass


# What node am I in?
def inside_node(node, node_type=None):
found_node = None
work_node = node.parent()
while work_node:
work_node_type = work_node.type().nameComponents()[2]
if node_type == work_node_type:
found_node = work_node
break
work_node = work_node.parent()

return found_node


def inside_terrain_node(node):
"""Finds the terrain node that the given node is inside, returns None if not in a terrain node."""
return inside_node(node, 'TaleSpire_Terrain')



# Shared Data Node
def get_ts_database_node():
shared_data_node = SharedData()
Expand Down
10 changes: 6 additions & 4 deletions scripts/python/talespire/assets.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import os


def get_assets(ts_directory):
def get_asset_dicts(ts_directory):
ts_index_files = list()
taleweaver_dir = os.path.join(ts_directory, 'Taleweaver')

Expand All @@ -14,13 +14,15 @@ def get_assets(ts_directory):
if 'index.json' in files:
ts_index_files.append(os.path.join(root, 'index.json'))

index_dict_list = list()
asset_dicts = dict()

for ts_index_file in ts_index_files:
file = open(ts_index_file, 'r')
data = file.read()
file.close()

index_dict_list.append(json.loads(data))
index_dict = json.loads(data)
index_name = index_dict['Name']
asset_dicts[index_name] = {'path': ts_index_file, 'index': index_dict }

return index_dict_list
return asset_dicts

0 comments on commit 89be8af

Please sign in to comment.