【问题标题】:Import model from 3dStudioMax into THREE.js将模型从 3dStudioMax 导入 THREE.js
【发布时间】:2011-12-17 09:05:07
【问题描述】:

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

是否有适合显示在 3dStudioMax 中创建的模型的导入器?如果没有,有没有办法将 3dStudioMax 模型转换为可以在 THREE.js 中导入的东西?

【问题讨论】:

标签: 3d three.js 3dsmax


【解决方案1】:

我有一段时间没用过three.js,但我知道它会导入3dsmax 可以轻松导出的OBJ,并且有一个python 脚本可以将.obj 转换为three.js .json 网格。

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

【讨论】:

    【解决方案2】:

    下面是一个 MAXScript 脚本,它将选定对象的网格转换为 JSON。在撰写本文时,它在 Google 代码托管的3ds Max developer community 的 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
    

    【讨论】:

      【解决方案3】:

      你有两个选择:

      1) 使用 ThreeJSExporter.ms 但考虑到不再维护:

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

      2) (推荐) 在 3DS Max 中使用 OBJ 导出器选项。然后使用此处提供的 convert_obj_three.py 脚本:

      https://github.com/mrdoob/three.js/blob/master/utils/converters/obj/convert_obj_three.py

      更多详细信息请参阅我在 Three.js 的 Github 上的问题:

      https://github.com/mrdoob/three.js/issues/893

      【讨论】:

        【解决方案4】:

        您可以使用 3ds 文件格式保存 max 文件。打开 3ds 模型 与A3dsViewer。单击工具栏中的导出到 HTML5,然后 您将能够在浏览器中预览模型。

        【讨论】:

          【解决方案5】:

          现在在 2018 年,我们确实有 glTF 和一个非常好的 3ds max 导出器,由巴比伦社区开发和积极维护:

          此处详细描述了说明和安装方法:

          https://doc.babylonjs.com/resources/3dsmax_to_gltf

          gltf 模型可以很容易地在 three.js 中使用,请看一些示例:

          https://threejs.org/examples/webgl_loader_gltf.html

          https://threejs.org/examples/#misc_exporter_gltf

          享受吧!

          【讨论】:

            猜你喜欢
            • 2017-03-09
            • 2014-05-29
            • 1970-01-01
            • 1970-01-01
            • 2019-03-07
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            相关资源
            最近更新 更多