从3dStudioMax导入模型到THREE.js

13

我知道THREE.js有来自各种3D图形格式的导入器。

是否有一种适合显示在三维工作室Max中创建的模型的导入器?如果没有,是否有一种将3D Studio Max模型转换为可以在THREE.js中导入的格式的方法?


顺便说一下,这将是一个非常适合在http://area51.stackexchange.com/proposals/5022/3d-graphics-modeling-applications上提问的问题。 - cdiggins
5个回答

18

6
以下是一个 MAXScript 脚本,可以将选定对象的网格转换为 JSON 格式。在此帖子发布时,它可在 Google 代码托管的 3ds Max 开发者社区 的 SVN 中获取。
tmesh = snapshotAsMesh selection[1]
out_file = createfile "$scripts\\output.json

num_faces = tmesh.numfaces
num_verts = tmesh.numverts 

fn PrintPoint pt = (
 format "%, %, %, " pt.x pt.y pt.z to:out_file
)   

fn PrintPointUV pt = (
 format "%, %, " pt.x pt.y to:out_file
)   

fn PrintPointInt pt = (
    x = int(pt.x) - 1
    y = int(pt.y) - 1
    z = int(pt.z) - 1
    format "%, %, %, " x y z to:out_file
)   

format "{\n" to:out_file

-- Vertex Positions 
-- format "    \"vertexPositions\" : [" to:out_file
format "    positions : [" to:out_file
for i = 1 to num_verts do
(
 vert = getVert tmesh i
 PrintPoint vert
)
format "],\n" to:out_file

-- Vertex Normals
-- format "    \"vertexNormals\" : [" to:out_file
format "    normals : [" to:out_file
for i = 1 to num_verts do
(
  vert = getNormal tmesh i
  PrintPoint vert
)
format "],\n" to:out_file

-- Vertex Texture Coordinates 
-- format "    \"vertexTextureCoords\" : [" to:out_file
format "    uv : [" to:out_file
for i = 1 to num_faces do
(
    -- Iterate over faces 
    tvface = getTVFace tmesh i
    for j = 1 to 3 do (
        -- Get a specific texture vertex
        tvert = getTVert tmesh tvface[j]        
        PrintPointUV tvert
    )
)
format "],\n" to:out_file

-- Face Indexes
-- format "    \"indices\" : [" to:out_file
format "    indices : [" to:out_file
for f = 1 to num_faces do
(
   face = getFace tmesh f
   PrintPointInt face
)
format "],\n" to:out_file

format "}" to:out_file

close out_file
delete tmesh
edit out_name

2

我有一段时间没有使用three.js了,但是我知道它可以导入OBJ格式的文件,而3dsmax可以轻松地导出该格式,并且有一个Python脚本可以将.obj转换为three.js的.json网格。

我注意到在最新版本中,有一个MaxScript Exporter直接导出json格式,所以从那里开始。它应该会生成一个基于所选网格的.js文件,但目前无法访问PC进行测试。


1
你可以使用3ds文件格式来保存最大文件。使用A3dsViewer打开3ds模型。在工具栏中点击导出到HTML5,就可以在浏览器中预览模型。

0

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接