Jump to content

Is there any way to convert .fbx/.dae/.stl like 3D formats to .babylon grammatically.


Ravi
 Share

Recommended Posts

Is there any way to convert .fbx/.dae/.stl like 3D formats to .babylon grammatically. I am using Angular 4 and NodeJS as programming languages.

I want to remove the dependancy of 3D software like 3D Max/Blender for exporting 3D model to .babylon format.

Appreciate your help!

Link to comment
Share on other sites

I've just done something similar for 3ds files, which while not removing a dependency on blender,  makes it really easy to batch convert models using the babylonjs blender exporter. I'm sure other formats could be converted using a similar method.

import os
import bpy
import sys

# see https://blender.stackexchange.com/questions/46990/how-to-completely-remove-all-loaded-data-from-blender?noredirect=1&lq=1
# make sure scene is empty
bpy.ops.wm.read_homefile(use_empty=True)

path_to_3ds = sys.argv[5]

file_list = sorted(os.listdir(path_to_3ds))

autodesk_list = [item for item in file_list if item.endswith('.3ds')]

for item in autodesk_list:
    bpy.ops.wm.addon_enable(module="babylon-js")
    path_to_files = os.path.join(path_to_3ds, item)
    bpy.ops.import_scene.autodesk_3ds(filepath = path_to_files)

    bpy.ops.bjs.main(filepath= os.path.join(path_to_3ds, item.replace("3ds", "babylon")))
    # bpy.ops.export_scene.obj(filepath= os.path.join(path_to_3ds, item.replace("3ds", "obj")))

    bpy.ops.wm.read_homefile(use_empty=True)

And then call this using:

"$BLENDER_LOCATION" --background --python ./convert.py -- "$PATH_TO_MODELS"

Some fixing up afterwards (due to 3ds models not having a diffuse colour, and a few other things) is done using sed  on the .babylon files after this, but what (if anything) needs fixing would depend on the input format.

For the models I've been converting, it's been taking less than a second for each one.

Link to comment
Share on other sites

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.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...