So, we have seen how to create a generic point cloud export to a JSON file, lets now take a look at how to import that same point cloud, back into Houdini, to create a full data loop.
Our goal is to export data out of Houdini and then to import back in so we can modify it and export it again. This is a key element to your game dev pipelines on larger game development projects. In this video we are going to look at how to take in a JSON file and read in attributes in a generic way, so we can recreate the point cloud that was exported out. This is great for any sort of point cloud you are making when instancing objects in your game levels.
Code:
node = hou.pwd()
geo = node.geometry()
# Add code to modify contents of geo.
# Use drop down menu to select examples.
import os
import json
parent = node.parent()
path = parent.parm('json_file').eval()
data = {}
with open(path) as f:
data = json.load(f)
pathAttrib = geo.addAttrib(hou.attribType.Point, "path", "")
rotAttrib = geo.addAttrib(hou.attribType.Point, "rot", [0.0,0.0,0.0])
for point in data['points']:
pos = point['pos']
path = point['path']
rot = point['rot']
position = hou.Vector3(float(pos[0]), float(pos[1]), float(pos[2]))
rotation = hou.Vector3(float(rot[0]), float(rot[1]), float(rot[2]))
newpnt = geo.createPoint()
newpnt.setPosition(position)
newpnt.setAttribValue(pathAttrib, path)
newpnt.setAttribValue(rotAttrib, rotation)
Thanks so much!
Kenny
Indie-Pixel
Comments