greyday Posted August 16, 2017 Share Posted August 16, 2017 I'm working on a project that was previously using Cinema4D to export to Unity, then we were exporting to JSON from Unity. Very laborious and too many pieces. A friend of mine suggested we might be able to by pass the middle man... use Houdini through and through and export to JSON. The animation is quite simple.. we'll actually be using the data to move an object with a motor in it. We animate in 3D and export the data to a physical object. Is there a way to do this with Houdini using some sort of JSON export capabilities or could we use Python somehow? Thanks for any advice. I'm looking for options really. Quote Link to comment Share on other sites More sharing options...
f1480187 Posted August 17, 2017 Share Posted August 17, 2017 (edited) As long as you have scripting access to the values you need, there is no problem to dump it as JSON using Python. JSON is a very generic format, it can contain anything. You need to be more specific about data you want to export. Here is starting point: json_example.hipnc Edited August 17, 2017 by f1480187 Quote Link to comment Share on other sites More sharing options...
j00ey Posted August 20, 2017 Share Posted August 20, 2017 I've just been working on an exporter to write out geometry descriptions and animation data for a realtime renderer and found it was quite manageable using python, the thing that can get tricky to get right is the formatting - square brackets, curly brackets, commas etc. This site might come in very handy for checking your output : jsonlint.com Quote Link to comment Share on other sites More sharing options...
greyday Posted August 22, 2017 Author Share Posted August 22, 2017 Thanks everyone. I'm pretty new to the whole thing. Basically what I want to be able to do is animate a 3D object in Houdini (basic things like rotations and translation) export those values to JSON. Then the JSON file is read in to an external program that will move the physical robot in the same way I've animated it in Houdini. What should I read to be able to understand what f1480187 or even j00ey mentions? Quote Link to comment Share on other sites More sharing options...
j00ey Posted August 22, 2017 Share Posted August 22, 2017 It depends on what the software you're reading it back in with wants. I was writing it out for a custom renderer so the developer gave me a template to use as a guide and I matched that, filling in the data from geometry attributes and transforms etc. I guess if you just want translation, rotation etc you can use worldTransformAtTime() to get the transformation matrix at a given frame, then use extractTranslates(), extractRotates() to get the values for each frame [or time step] that you want to sample. Check how the reader expects your JSON to be formatted and match that - eg [if my memory serves] I had to write the point positions as one long array of comma separated values that the reader parses in groups of 3 [x, y, and z], so that meant looping through the points, getting the positions, stripping off the brackets, appending to the array then putting square brackets around the array. The site I posted last time was very useful for checking I hadn't missed a comma or bracket somewhere. If you have experience with python I think it should be fairly straightforward, if not [like me] use the docs... Quote Link to comment Share on other sites More sharing options...
j00ey Posted August 22, 2017 Share Posted August 22, 2017 I made you a basic file to start you off - I'm not very advanced in python myself so don't take this as the proper way to do something, it's just a way... If you open a python shell and click on the 'Print JSON' button, you should get some JSON printed out. Look in the python module of the asset to see how it's set up. basic_json.hip Quote Link to comment Share on other sites More sharing options...
f1480187 Posted August 22, 2017 Share Posted August 22, 2017 (edited) @greyday, show a simple example JSON readable by external program. The task is simple, but requires to know Python and HOM. The problem of different coordinate systems will also be raised, probably. If you are ready to spend couple of weeks, you can learn Python tutorial (at least, parts 3 through 6), then learn basics of json module (dumping simple dicts and lists on disk). I linked Python 3 pages and Houdini uses Python 2. There won't be any difference in this case, and it is reasonable to learn Python by most recent docs, IMO. Feel free to switch versions at the top bar of the Python site. Then read HOM introduction, find way to access animation values you need. Finally, combine everything in the final project. HOM will be the most tricky: docs are unfriendly. But you can ask here. @j00ey, try json module instead of manual formatting: data = { 'time': time, 'objects': [] } for obj in objs: t, r = get_wt(obj, time) obj_data = { 'name': hou.node(obj).name(), 'translate': list(t), 'rotate': list(r) } data['objects'].append(obj_data) print json.dumps(data, indent=4, sort_keys=True) Edited August 22, 2017 by f1480187 1 Quote Link to comment Share on other sites More sharing options...
j00ey Posted August 22, 2017 Share Posted August 22, 2017 Thanks very much for the tip, I will look at that. Quote Link to comment Share on other sites More sharing options...
j00ey Posted August 23, 2017 Share Posted August 23, 2017 @f1480187's method is indeed much cleaner. Here's an updated file in case it's useful. basic_json01.hip 1 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.