I am building a browser game with three.js
and I want to load a model from Maya 2013 into my scene. I have exported the model as an obj file.
我正在使用three.js构建一个浏览器游戏,我想将Maya 2013中的模型加载到我的场景中。我已将模型导出为obj文件。
Now I need to know how to convert it into an JS file for the three.js
-loader.
现在我需要知道如何将它转换为three.js-loader的JS文件。
This is my loader so far:
到目前为止这是我的装载机:
var jsonLoader = new THREE.JSONLoader();
jsonLoader.load( "models/model.js", addModelToScene );
Thanks in advance
提前致谢
6 个解决方案
#1
11
If you don't want to use blender, mrdoob(made threejs) has a simple python script to convert obj to json. Just run --this script-- in terminal like so:
如果你不想使用blender,mrdoob(made threejs)有一个简单的python脚本将obj转换为json。只需在终端中运行 - 这个脚本 - 如下:
python convert_obj_three.py -i infile.obj -o outfile.js
#2
10
Use Blender.
使用Blender。
搅拌机3D
Then install this addon:
然后安装这个插件:
Three.js出口商
#3
5
Thats a pretty late reply. I have written a converter to read obj files and convert to ThreeJS supported JSON format: https://github.com/theMaxscriptGuy/Windows_Programs/tree/master/Obj_To_ThreeJS
那是一个很晚的回复。我编写了一个转换器来读取obj文件并转换为ThreeJS支持的JSON格式:https://github.com/theMaxscriptGuy/Windows_Programs/tree/master/Obj_To_ThreeJS
Download all the files as zip and run converter.exe...
将所有文件下载为zip并运行converter.exe ...
#4
5
Note: the python converter script has been updated to a js based tool https://github.com/mrdoob/three.js/tree/dev/utils/converters
注意:python转换器脚本已更新为基于js的工具https://github.com/mrdoob/three.js/tree/dev/utils/converters
Usage:
用法:
node obj2three.js model.obj
node obj2three.js model.obj
#5
2
When exporting 3ds max models to three.js using the [convert_obj_three.py][1]
script, a little degree of automation can be achieved with the following command in cmd promt:
使用[convert_obj_three.py] [1]脚本将3ds max模型导出为three.js时,可以使用cmd promt中的以下命令实现一定程度的自动化:
cd C:\Python27 &
python convert_obj_three.py -i _obj\chromeBand.obj -o _json\chromeBand.js &
python convert_obj_three.py -i _obj\controlPanelCover.obj -o _json\controlPanelCover.js
I wrote a 3ds max script that will print the phyton script command for multiple models and also a json with the models relative urls and coordinates. The json is useful for placing multiple models at the correct position in scene.
我写了一个3ds max脚本,它将打印多个模型的phyton脚本命令,还有一个带有模型相对URL和坐标的json。 json对于将多个模型放置在场景中的正确位置非常有用。
(
local inputPath = "D:\Archive\Work\_Dev\_Convert\Obj\\"
local outputPath = "C:\Server\htdocs\viewer\assets\models\my-project\\"
local jsonPath = "assets/models/my-project/"
local myListEntry = "\n"
for o in selection do
(
myListEntry +=
"\"" + o.name + "\": {\n" +
"\t\"url\": \"" + jsonPath + o.name + ".js\",\n" +
"\t\"position\": {\n" +
"\t\t\"x\": \"" + o.position.x as string + "\",\n" +
"\t\t\"y\": \"" + o.position.z as string + "\",\n" +
"\t\t\"z\": \"" + (o.position.y * -1) as string + "\"\n" +
"\t}\n" +
"},\n"
)
myListEntry += "\n\n\n=== Run this using cmd promt: ===\n"
myListEntry += "cd C:\Python27 &\n"
for o in selection do
(
myListEntry += "python D:\Archive\Work\_Dev\_Convert\convert_obj_three.py -i " +
inputPath + o.name + ".obj -o " +
outputPath + o.name + ".js & \n"
)
myListEntry += "exit \n"
print myListEntry
actionMan.executeAction 0 "40472"
)
- Create a new txt file, rename it to
coordinates.mcr
and drag and drop the file into the 3ds max window. It will automatically open MaxScript Listener window and print the results. Copy paste the python command in cmd. Use the printed json to batch load your models in your project. - 创建一个新的txt文件,将其重命名为coordinates.mcr并将文件拖放到3ds max窗口中。它将自动打开MaxScript Listener窗口并打印结果。复制粘贴cmd中的python命令。使用打印的json在项目中批量加载模型。
- Also, scripts can be assigned to buttons in 3dsMax toolbars, for fast access.
- 此外,脚本可以分配给3dsMax工具栏中的按钮,以便快速访问。
- The above script could use further tweaking. Not the best solution but at least it speeds up things, hopefuly.
- 上面的脚本可以使用进一步的调整。不是最好的解决方案,但至少它可以加快速度。
- Use Jos Balcaen's script for exporting obj files in batch (3ds Max)
- 使用Jos Balcaen的脚本批量导出obj文件(3ds Max)
Edit:
编辑:
After experimenting a bit with the script I have made a setup that allows me to export my models (counting more than 20) in under 1 minute from 3ds max to open browser tab. Of course, you may need to adjust the json output to your liking. Hope you will find this useful.
在对脚本进行了一些实验后,我进行了一个设置,允许我在不到1分钟的时间内从3ds max导出我的模型(计数超过20)到打开浏览器选项卡。当然,您可能需要根据自己的喜好调整json输出。希望你会发现这很有用。
#6
1
Create a Python file named conversion.py
with the following content: click here to see it.
使用以下内容创建名为conversion.py的Python文件:单击此处查看。
And then run this command in your Terminal:
然后在终端中运行此命令:
python conversion.py -i file.obj -o file.js
#1
11
If you don't want to use blender, mrdoob(made threejs) has a simple python script to convert obj to json. Just run --this script-- in terminal like so:
如果你不想使用blender,mrdoob(made threejs)有一个简单的python脚本将obj转换为json。只需在终端中运行 - 这个脚本 - 如下:
python convert_obj_three.py -i infile.obj -o outfile.js
#2
10
Use Blender.
使用Blender。
搅拌机3D
Then install this addon:
然后安装这个插件:
Three.js出口商
#3
5
Thats a pretty late reply. I have written a converter to read obj files and convert to ThreeJS supported JSON format: https://github.com/theMaxscriptGuy/Windows_Programs/tree/master/Obj_To_ThreeJS
那是一个很晚的回复。我编写了一个转换器来读取obj文件并转换为ThreeJS支持的JSON格式:https://github.com/theMaxscriptGuy/Windows_Programs/tree/master/Obj_To_ThreeJS
Download all the files as zip and run converter.exe...
将所有文件下载为zip并运行converter.exe ...
#4
5
Note: the python converter script has been updated to a js based tool https://github.com/mrdoob/three.js/tree/dev/utils/converters
注意:python转换器脚本已更新为基于js的工具https://github.com/mrdoob/three.js/tree/dev/utils/converters
Usage:
用法:
node obj2three.js model.obj
node obj2three.js model.obj
#5
2
When exporting 3ds max models to three.js using the [convert_obj_three.py][1]
script, a little degree of automation can be achieved with the following command in cmd promt:
使用[convert_obj_three.py] [1]脚本将3ds max模型导出为three.js时,可以使用cmd promt中的以下命令实现一定程度的自动化:
cd C:\Python27 &
python convert_obj_three.py -i _obj\chromeBand.obj -o _json\chromeBand.js &
python convert_obj_three.py -i _obj\controlPanelCover.obj -o _json\controlPanelCover.js
I wrote a 3ds max script that will print the phyton script command for multiple models and also a json with the models relative urls and coordinates. The json is useful for placing multiple models at the correct position in scene.
我写了一个3ds max脚本,它将打印多个模型的phyton脚本命令,还有一个带有模型相对URL和坐标的json。 json对于将多个模型放置在场景中的正确位置非常有用。
(
local inputPath = "D:\Archive\Work\_Dev\_Convert\Obj\\"
local outputPath = "C:\Server\htdocs\viewer\assets\models\my-project\\"
local jsonPath = "assets/models/my-project/"
local myListEntry = "\n"
for o in selection do
(
myListEntry +=
"\"" + o.name + "\": {\n" +
"\t\"url\": \"" + jsonPath + o.name + ".js\",\n" +
"\t\"position\": {\n" +
"\t\t\"x\": \"" + o.position.x as string + "\",\n" +
"\t\t\"y\": \"" + o.position.z as string + "\",\n" +
"\t\t\"z\": \"" + (o.position.y * -1) as string + "\"\n" +
"\t}\n" +
"},\n"
)
myListEntry += "\n\n\n=== Run this using cmd promt: ===\n"
myListEntry += "cd C:\Python27 &\n"
for o in selection do
(
myListEntry += "python D:\Archive\Work\_Dev\_Convert\convert_obj_three.py -i " +
inputPath + o.name + ".obj -o " +
outputPath + o.name + ".js & \n"
)
myListEntry += "exit \n"
print myListEntry
actionMan.executeAction 0 "40472"
)
- Create a new txt file, rename it to
coordinates.mcr
and drag and drop the file into the 3ds max window. It will automatically open MaxScript Listener window and print the results. Copy paste the python command in cmd. Use the printed json to batch load your models in your project. - 创建一个新的txt文件,将其重命名为coordinates.mcr并将文件拖放到3ds max窗口中。它将自动打开MaxScript Listener窗口并打印结果。复制粘贴cmd中的python命令。使用打印的json在项目中批量加载模型。
- Also, scripts can be assigned to buttons in 3dsMax toolbars, for fast access.
- 此外,脚本可以分配给3dsMax工具栏中的按钮,以便快速访问。
- The above script could use further tweaking. Not the best solution but at least it speeds up things, hopefuly.
- 上面的脚本可以使用进一步的调整。不是最好的解决方案,但至少它可以加快速度。
- Use Jos Balcaen's script for exporting obj files in batch (3ds Max)
- 使用Jos Balcaen的脚本批量导出obj文件(3ds Max)
Edit:
编辑:
After experimenting a bit with the script I have made a setup that allows me to export my models (counting more than 20) in under 1 minute from 3ds max to open browser tab. Of course, you may need to adjust the json output to your liking. Hope you will find this useful.
在对脚本进行了一些实验后,我进行了一个设置,允许我在不到1分钟的时间内从3ds max导出我的模型(计数超过20)到打开浏览器选项卡。当然,您可能需要根据自己的喜好调整json输出。希望你会发现这很有用。
#6
1
Create a Python file named conversion.py
with the following content: click here to see it.
使用以下内容创建名为conversion.py的Python文件:单击此处查看。
And then run this command in your Terminal:
然后在终端中运行此命令:
python conversion.py -i file.obj -o file.js