Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Convert 3D model to SceneJS JSON, including texture

Motive
I'm trying to create a small demo application using WebGL. I chose to use SceneJS, because it seemed an easy framework and would more than suffice for this purpose.

I have downloaded a couple of .blend models (Amy Rose, amongst others) and exported them as a Collada (.dae) file using Blender. Then I used scenejs-pycollada to convert them to a json model.

I just spent a couple of hours getting the scenejs-pycollada convertor to work. Apparently getting those Python dependencies to work in Windows isn't that easy if you've never used Python before. ;)

Problem
But now I'm stuck (again). My problem is that the models don't have any textures or materials.

I used the Seymour Plane Example of SceneJS. The model I converted is hardly visible. It is black and doesn't seem to respond to the lighting in the scene. If I load the plane and the model together, I can see the model is loaded, because its arms and legs are sticking out of the plane.

Now I followed a couple of tutorials that would let me export the texture as a PNG image. I then modified the texture file name in the JSON model to match the file name, but it doesn't help.

So I hope someone can help me to find a way to export Blender models (or other common 3D models) to the JSON format used by SceneJS, including the textures.

Any other method of loading models in SceneJS will do too, as long as it works.

If one 's got a link to free downloads of body/figure JSON models, that would help for now, but I rather learn how this works. :)

I'm using

  • Windows 7 Home Premium 64bit
  • Python 2.7 (Windows 32bit)
    I chose the 32 bit version, because of seemingly better support for libraries, and more available installers. At first I mixed up 32 and 64 bit and it caused me trouble, but now everything seems to work (except for the textures, that is).
  • Blender 2.59
  • SceneJS 0.8.0

My workflow
In Blender I export the models to Collada (*.dae) files, and then convert them to Raw JSON using scenejs-pycollada. This gives me a JSON file with two objects in it. The first seems to be the scene, the second the model. I keep the second and put it in a Javascript variable that is used in the code of the SceneJS example. The model ends with the properties , "type": "library", "parent": "Scene" which I need to remove from the code to make it load at all.

like image 448
GolezTrol Avatar asked Oct 09 '11 18:10

GolezTrol


1 Answers

I'm actually the author of scenejs-pycollada. Let me see if I can help you :)

I see you're using version 0.8 of SceneJS... Things have been rather in flux, so it might actually easiest to pull the 2.0 branch of SceneJS from github and scenejs-pycollada from my personal repo. I was basically targeting SceneJS 0.9 for the first release of scenejs-pycollada, but that version never got officially released. Also, in the long run you won't have to rewrite everything if you just switch over now...

The problematic windows compile is also a big thorn, I really wish the numpy devs would fix this up for you windows folk. Once SceneJS 2.0 is released I'll release an official version of scenejs-pycollada that comes packaged with all the necessary dependencies for windows.

So, feel free to comment on this answer or update your question. I'll try to keep an eye on it.

P.S. Alternatively, if you're really frustrated I actually have a second blender exporter at https://github.com/rehno-lindeque/Blender-WebGL-exporter, but I don't recommend using this one - it's very outdated. The only other scenejs collada exporter was deprecated a long time ago.

P.P.S. There's also and example and some test models in scenejs-pycollada itself. If you just want a quick model to play with, check out https://github.com/rehno-lindeque/scenejs-pycollada/tree/master/example although admittedly it's not the prettiest model ever.

P.P.P.S. Actually one of the reasons why the Amy Rose model wasn't working well for you is because scenejs-pycollada didn't support multiple materials yet. I'm quickly adding some support for this tonight.

like image 121
Rehno Lindeque Avatar answered Nov 16 '22 11:11

Rehno Lindeque