mrdoob / three.js

JavaScript 3D Library.
https://threejs.org/
MIT License
102k stars 35.33k forks source link

How to use Blender export script? #143

Closed geoffreak closed 13 years ago

geoffreak commented 13 years ago

I have looked everywhere and tried to get the Blender export script working, but I seem to be completely unable to get the export to three.js functionality working. Everywhere I look refers to a certain blog post, but that website isn't functioning and hasn't for the past few days of me checking.

Has anyone successfully gotten the export scripts to work in Blender (under Mac OSX)?

alteredq commented 13 years ago

This blog post is very old, meanwhile exporter, format and loading changed a lot.

Current Blender exporter works with the Blender beta 2.56.0 and can be found here (or under corresponding location in your local repo clone):

https://github.com/mrdoob/three.js/tree/master/utils/exporters/blender

In order to get this working, you will need to copy Python scripts from Three.js repo to corresponding location in your Blender installation.

I don't know where Blender keeps its user data in OSX, but for example on Windows it is under c:/users/yourusername/Application Data/Blender Foundation/Blender.

Under this folder there should be directory structure as in Three.js repo 2.56\scripts\op (you should see other exporters there that came with Blender).

Now under this op folder you need to create io_mesh_threejs subfolder and copy there files from corresponding folder in Three.js repo.

When you reload Blender (or press F8), in File->Export menu you should have now Three.js (.js) option.

Don't use yet scene export option, it's not yet finished, but if you uncheck it, you can export single selected mesh.

This will generate model in ascii JSON format, which can be then loaded via THREE.JSONLoader.

Check Blender exporter or OBJ converter examples to see it in action (OBJ converter generates the same ascii JSON format as Blender exporter):

http://mrdoob.github.com/three.js/examples/webgl_geometry_blenderexport_colors.html

https://github.com/mrdoob/three.js/blob/master/examples/webgl_geometry_blenderexport_colors.html#L76

http://mrdoob.github.com/three.js/examples/webgl_objconvert_test.html

https://github.com/mrdoob/three.js/blob/master/examples/webgl_objconvert_test.html#L196

Relevant piece of code is here:

var loader = new THREE.JSONLoader();
loader.load( { model: "myModel.js", callback: function(geo) { createModel( geo ) } } );
geoffreak commented 13 years ago

When checking my Blender system information, I see the following:

Blender home dir:
  /Applications/blender/blender.app/Contents/MacOS/.blender

 Default dir for scripts:
  /Applications/blender/blender.app/Contents/MacOS/.blender/scripts

 Default "bpydata/" data dir for scripts:
  /Applications/blender/blender.app/Contents/MacOS/.blender/scripts/bpydata

 User defined dir for scripts:
   -- not found

 Data dir "bpydata/" inside user defined dir:
   -- not found

 Default config data "bpydata/config/" dir:
  /Applications/blender/blender.app/Contents/MacOS/.blender/scripts/bpydata/config

So I put the scripts import_threejs.py, export_threejs.py, and init.py into /Applications/blender/blender.app/Contents/MacOS/.blender/scripts Despite this, nothing appears on the export menu regardless if I quit out of Blender and relaunch it, or if I hit F8

alteredq commented 13 years ago

You need to find where in your OS Blender keeps its own native importers / exporters and copy Three.js files there to keep the same pattern.

Somewhere you should have folder structure like this:

autosave
config
plugins
scripts
    addons
    io
    keyingsets 
    modules
    op
        io_anim_bvh 
        io_mesh_ply
        io_mesh_threejs  <= create this folder
        io_scene_3ds 
        io_scene_fbx 
        io_scene_obj 
        io_scene_x3d 
        io_shape_mdd 
    presets
    templates
    ui

Also check Blender console for eventual error messages or loading modules reports.

Make sure you copy files to folder from the right version of Blender (must be 2.56a).

At least on Windows, each beta keeps its files in a different folder, all start with version number (so above the folder structure I posted, there are 2.54, 2.55, 2.56 folders, if you tried multiple betas).

geoffreak commented 13 years ago

Sorry for wasting your time alteredq. My issue was that my version of Blender wasn't the latest version. I thought I had downloaded the latest version just a couple of days ago, but I must have either not been launching the right version or I downloaded an old version.

For future reference to those who have this problem too, the scripts folder is inside the blender.app in the Contents/MacOS/ folder, then the folder structure is as listed in alteredq's post above.

ajullz commented 13 years ago

Hi there guys,

I tried to do what you explained, but with versions (2.56-beta, 2.56a-beta and 2.57b), all that I could find was: .../blender/2.56 (or2.57)/python/lib/ ... and there is a bunch of folders and python scripts but no folder named "op" or "scripts".

I made a new folder inside this lib folder named io_mesh_threejs and then copied the .py files -- import_threejs.py, export_threejs.py and init.py inside -- It did not work :(

Do I need to copy something else or did I just do the whole thing wrong? When I re-open blender and went to file-->export I didn't see the option -- Three.js (.js) -- with any of the versions. BTW, I'm using windows.

Thanks for the help xD Julio

TJKoury commented 13 years ago

Deprecated file format error...?

-TJ

mikaelgramont commented 13 years ago

I haven't tried 2.57 yet but you can still download 2.56b from the blender site, and I got it to work on Ubuntu. I placed the files inside the blender application directory, not the .blender user pref directory: ~/Apps/blender-2.56-beta-linux-glibc27-x86_64/2.56/scripts/op/io_mesh_threejs

where ~/Apps/blender-2.56-beta-linux-glibc27-x86_64 is the folder I uncompressed Blender to.

TJKoury commented 13 years ago

Thanks. I got it to work, my problem now is that the file it outputs is in the 'old' (pre-version 2) format, so I get the 'depricated file format' error. It's missing the vertices array, I think.

wezzy commented 13 years ago

Hi, i'm able to run the exporter on Mac. I've copied the folder https://github.com/mrdoob/three.js/tree/master/utils/exporters/blender/2.57/scripts/addons/io_mesh_threejs to /Applications/Blender/blender.app/Contents/MacOS/2.57/scripts/addons/io_mesh_threejs then opened Blender and under File -> User Preferences -> Add-Ons searched for three.js format and then checked the checkbok on the right of the line to activate the exporter.

georgik commented 13 years ago

Windows 7 and Blender 2.57: copy folder https://github.com/mrdoob/three.js/tree/master/utils/exporters/blender/2.57/scripts/addons/io_mesh_threejs

Start Blender, File -> User Preferences -> Add-Ons, search for Three.js, activate plugin.

ngons commented 13 years ago

@ JCAZ Just copy the folder labeled "scripts" and paste it under the subfolder called "2.57". The structure should look like this: C:\Program Files\Blender Foundation\Blender\2.57\scripts\addons\io_mesh_threejs

fernandoc1 commented 13 years ago

For Linux, I have created this tutorial:

https://docs.google.com/document/pub?id=1eobAyKH5ajO_JQC7L3TQx5EnTO3P65JxlZGGCV94Q8A

ajullz commented 13 years ago

oh hi there tha1bu1,

I hadn't seen your post sry and thanks for the help :) but I already had it working xD

mariakay commented 11 years ago

Hi! I was able to import now using three js but cant export. three.js option is listed but is inactive. What could have been the problem?

fromerolx commented 11 years ago

excuse my English, I have version 2.66 of blender, is that the problem?. I copy the files in the directory and do not see the option to export

http://k43.kn3.net/178096C1E.jpg 178096C1E 1

denisw commented 11 years ago

excuse my English, I have version 2.66 of blender, is that the problem?. I copy the files in the directory and do not see the option to export

Seems as if the exporter doesn't work with 2.66 yet. I have tried the same thing (on Ubuntu) and also couldn't see the exporter in the add-ons list, while the same thing worked with 2.63 (the version that in the repos of my Ubuntu 12.10 installation) without problems.

fromerolx commented 11 years ago

whether it was the version.

ghost commented 11 years ago

Try to search the list of plugins. Scroll down to the bottom of plugins list - in my case it was at the end. I have Ubunut 12.04 with Blender 2.66 and the latest exporter and everything works correctly.

fromerolx commented 11 years ago

should make a tutorial, but video

sohailiiui commented 11 years ago

i have 3d model created in blender now my task is to import and play that 3d human model in webgl using three.js any help plzzz

anothercoder2 commented 11 years ago

Has anyone been able to get the three.js import export addon for Blender (2.66 or 2.65) to work on Windows 7 or Windows Vista

I tried on two different computers.

On windows 7 I placed the files in (I have blender 2.65 on this machine) E:\blender-2.65-release-windows32\blender-2.65-release-windows32\2.65\scripts\addons\io_mesh_threejs

On Windows Vista where I have blender 2.66 I placed the files in C:\Users\USERNAME\AppData\Roaming\Blender Foundation\Blender\2.66\scripts\addons

I looked in the User Preferences and can not see the addon there. I also tried the filter etc.

Please help!

anothercoder2 commented 11 years ago

See the following error if I start blender from command line

fake_module: addon missing 'bl_info' gives bad performance!: 'C:\BlenderInstall \Blender2.66\2.66\scripts\addons\io_mesh_threejs**init**.py'

anothercoder2 commented 11 years ago

I figured out my problem. I had downloaded the files from github incorrectly and the python was enclosed in html tags. Have fixed that by making sure that the files only have python inside them. Now I can see the plugin and when I try to import a model I get the following error

File "C:\BlenderInstall\Blender2.66\2.66\scripts\addons\io_mesh_threejsinit.py", line 149, in execute

return io_mesh_threejs.import_threejs.load(self, context, **self.properties)

AttributeError: 'module' object has no attribute 'load'

location: :-1

location: :-1

WestLangley commented 11 years ago

As stated in the guidelines, help requests should be directed to stackoverflow. This board is for bugs and feature requests.