Import model from 3dStudioMax into THREE.js
Asked Answered
F

5

13

I know that THREE.js has importers from various 3d graphics formats.

Is there an importer suitable to display a model created in 3dStudioMax? And if there is not one, is there a way to convert a 3dStudioMax model in something that can be imported in THREE.js?

Filide answered 28/10, 2011 at 15:1 Comment(1)
By the way, this would be an excellent question for the proposed 3d stackexchange at area51.stackexchange.com/proposals/5022/….Rakel
R
6

Below is a MAXScript script that will convert a selected object's mesh into JSON. At the time of this post, it was available in the SVN of the 3ds Max developer community at Google code hosting.

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
Rakel answered 30/10, 2011 at 13:7 Comment(0)
D
18

You have two options:

1) Use ThreeJSExporter.ms but take into account that is no longer mantained:

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

2) (Recommended) Use OBJ exporter option in 3DS Max. Then use convert_obj_three.py script available here:

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

More detailed info in my issue on Three.js's Github:

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

Disfeature answered 23/12, 2011 at 9:11 Comment(0)
R
6

Below is a MAXScript script that will convert a selected object's mesh into JSON. At the time of this post, it was available in the SVN of the 3ds Max developer community at Google code hosting.

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
Rakel answered 30/10, 2011 at 13:7 Comment(0)
F
2

I haven't used three.js in a while, but I know it imports OBJ which 3dsmax can easily export and there is a python script that converts an .obj to a three.js .json mesh.

I noticed that in the latest revision there is a MaxScript Exporter straight to the json format, so start with that. It should generate a .js file based on the selected mesh, but can't access a PC at the moment to test.

Fortune answered 29/10, 2011 at 17:36 Comment(0)
I
1

You can save max file using 3ds file format. Open 3ds model with the A3dsViewer. Click Export to the HTML5 in the toolbar and you will be able to preview the model in the browser.

Illdefined answered 23/12, 2013 at 8:28 Comment(0)
M
0

Now in 2018, we do have glTF and a very nice exporter for 3ds max, developed and actively maintained by the babylon community:

enter image description here

Description and how to install is extensively described here:

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

The gltf models can then easily be used in three.js, see some examples:

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

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

Enjoy!

Merodach answered 28/11, 2018 at 22:16 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.