matthiasvegh / Chunkymator

A json generator for Chunky
GNU General Public License v2.0
5 stars 2 forks source link

TypeError(repr(o) + " is not JSON serializable") #2

Closed martijnrondeel closed 10 years ago

martijnrondeel commented 10 years ago

Getting this error when using Chunkymator to generate files from 5 .json points:

Traceback (most recent call last):
  File "C:\Users\Martijn\Downloads\morph.py", line 172, in <module>
    main()
  File "C:\Users\Martijn\Downloads\morph.py", line 167, in main
    c.saveToFile(name);
  File "C:\Users\Martijn\Downloads\cvf.py", line 69, in saveToFile
    json.dump(self.inputJson, f)
  File "C:\Users\Martijn\Anaconda\lib\json\__init__.py", line 189, in dump
    for chunk in iterable:
  File "C:\Users\Martijn\Anaconda\lib\json\encoder.py", line 434, in _iterencode

    for chunk in _iterencode_dict(o, _current_indent_level):
  File "C:\Users\Martijn\Anaconda\lib\json\encoder.py", line 408, in _iterencode
_dict
    for chunk in chunks:
  File "C:\Users\Martijn\Anaconda\lib\json\encoder.py", line 408, in _iterencode
_dict
    for chunk in chunks:
  File "C:\Users\Martijn\Anaconda\lib\json\encoder.py", line 408, in _iterencode
_dict
    for chunk in chunks:
  File "C:\Users\Martijn\Anaconda\lib\json\encoder.py", line 442, in _iterencode

    o = _default(o)
  File "C:\Users\Martijn\Anaconda\lib\json\encoder.py", line 184, in default
    raise TypeError(repr(o) + " is not JSON serializable")
TypeError: array(62.64230753861712) is not JSON serializable
matthiasvegh commented 10 years ago

Hm, I haven't tried the scripts on windows, can you attach the jsons in question?

martijnrondeel commented 10 years ago

Compressed the files into a .zip: http://www.mediafire.com/download/msykpcmn5hokt47/z1.zip There are 5 .json files (z1, z2 etc.).

matthiasvegh commented 10 years ago

Okay, I tried to run the script on linux, and things seemed to work fine, so I'll have to try on windows next. Bear with me. While I'm doing that, can you tell me what python version you are using? I'm also not familiar with Anaconda, so I'm not sure if there are any relevant changes to look for in there.

martijnrondeel commented 10 years ago

I am using Python 2.7.8. Anaconda is basically a package for windows that comes with PIP and alot of other packages installed.

martijnrondeel commented 10 years ago

Don't worry about getting it to work with windows too much, I have managed to get it working on Debian. However, it generates .json files, shouldn't it generate .cvf files?

matthiasvegh commented 10 years ago

Not to my knowledge, no, Chunky uses .jsons as input, as does the command line renderer. If you're already on debian, fire up a python prompt:

NumberOfFramesGenerated=<someNumber>
for i in range(NumberOfFramesGenerated):
    subprocess.call(["java", "-jar", "/path/to/ChunkyLauncher.jar", "-render", "interpolated-"+str(i), "-scene-dir /path/you/specified/as/output/directory", "-target 50"])

Replace 50 with whatever you see fit, but it will take a while whatever you set it to. Update: I see the documentation still states .cvfs will be generated, let me just fix that.

martijnrondeel commented 10 years ago

I am using this script to render:

#!/bin/bash
for i in seq 0 1001; do
    echo "rendering:" $i
    java -jar ChunkyLauncher.jar -render interpolated-$i
done

However, because the scene was made on a Windows machine in every interpolated-$i.json file there is this line:

"world": {
"path": "C:\\Users\\Martijn\\AppData\\Roaming\\.minecraft\\saves\\Project_Zombie",
"dimension": 0
 }

I have the world save now downloaded to my debian machine, but that'd mean I will have to change that path line in 1001 files hehe. Any idea how I could solve this?

matthiasvegh commented 10 years ago

Yes I encountered that issue once, when I too edited scenes on Windows. I think this would be a valuable feature to have, a command line switch to change the paths, but for the time being, edit the input jsons by hand, and rerun Chunkymator on them. (You'd still have to some jsons, but not 1001 of them) Alternatively, you could use sed, but I wouldn't want to have to escape all those backslashes.

Update: Actually, scratch the last. The last json is duplicated and then manipulated. So if you only change the file path in the last input json, that should be used in all the outputs.

martijnrondeel commented 10 years ago

Alright, managed to get it all working :+1: Thanks for the help! I'll post the result in /r/Chunky once it's done (probably takes a few days hehe).

matthiasvegh commented 10 years ago

I'd actually try running it at a low target (~5) and see if it is working first. I'm still hammering out some camera angle issues.

martijnrondeel commented 10 years ago

Will try that now.

martijnrondeel commented 10 years ago

Ok running 1001 renders now at 3 SPP each, when that is done, what'd be a good program/script to turn them into a video file?

matthiasvegh commented 10 years ago

I use:

ffmpeg -f image2 -i interpolated-%d-5.png -r 25 test.avi

Replace 5 with your target SPP. But ffmpeg seems to be such a moving target, I have no idea if these switches will make sense on your platform. In any event, I'm using ffmpeg 0.10.12

matthiasvegh commented 10 years ago

I've just pushed a new version, if you have any camera issues, try using the new version. (44c0eb592463cb39417e66c38ce09cfa1ab65dab) You can also turn the images into a video before all of them are completed, so you should have a good inkling on whether the frames rendered are okay.

martijnrondeel commented 10 years ago

Works really nice so far: http://youtu.be/hufDXy2pgT8

I'm wondering, is the sun interpolated too? Because that'd make even cooler videos. And which java params would you recommend to use (if any) with Chunky?

matthiasvegh commented 10 years ago

I started work on that, but I haven't finished it. I'll try to have that done today, but I'd appreciate it if you could test it.

matthiasvegh commented 10 years ago

I've got what seems to be working on branch sun (28e2f0e08579a89c9add514be9c17a08e1ccab5a). Give it a go when you can. Of course, if all the inputs specify the same sun position, nothing interesting will happen. So try to have the sun moving across the sky between frames.

martijnrondeel commented 10 years ago

I'll test that now!

martijnrondeel commented 10 years ago

Ok first thing I tried was having a scene with no movement except the sun that goes from the front of the building to the back (like a 360). This doesn't work because the program expects that there is movement/doesn't see the sun as correct movement.

Will try one now with movement and sun movement.

matthiasvegh commented 10 years ago

The reason you can't have just a sunset (appealing as that would be) is that the length of the video is calculated from the distance traveled.

martijnrondeel commented 10 years ago

It seems like there are still camera issues. This is the first waypoint for the animation, it's meant to look like this: ss 2014-07-08 at 01 55 21

But it gets rendered like this: interpolated-0-6

matthiasvegh commented 10 years ago

And is this from the latest on Sun branch?

martijnrondeel commented 10 years ago

Yes

matthiasvegh commented 10 years ago

I'll run some more tests tonight, to see what the hell is going wrong. Is the sun moving as expected?

martijnrondeel commented 10 years ago

Wasn't able to see that because the render was off, but I'll try make one now where it should be displayed.

martijnrondeel commented 10 years ago

Whatever I do, the render keeps oriented like this:

interpolated-0-4

Instead of being aimed at the ship. Here are the .json files: http://www.mediafire.com/download/96iankcdn55a2z8/x4.zip

matthiasvegh commented 10 years ago

Well as a testcase, you could approach the ship from the other side. But if you're up for it, take a look at https://github.com/matthiasvegh/Chunkymator/blob/master/morph.py#L38. Whatever the solution is, the problem is located there. So try -pi/2, +- pi, removing it altogether, I'm really not sure. I'll be playing with it today, but if you manage to fix it before I do, you're more than welcome to send a PR.

matthiasvegh commented 10 years ago

One thing before I do my analysis, the current behavior is to always for the camera to always look in the direction of travel. Can you check if this is what is happening?

martijnrondeel commented 10 years ago

Ahh, I set the render up to always stay focused on the ship and just move sideways. If it looks into the direction of travel that explains why the ship isn't in the render.

matthiasvegh commented 10 years ago

I previously interpolated the camera angle as any other parameter, but the oscillations were quite unsightly, so this approach seemed to make more sense, but if you would like to be able to strafe like this, open up an issue for it, and I'll see if I can add a switch for it.

martijnrondeel commented 10 years ago

Alright I'll do that.