Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Import model from 3dStudioMax into THREE.js

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?

like image 377
Andrea Avatar asked Oct 28 '11 15:10

Andrea


People also ask

What file types does three Js support?

three. js provides loaders for many other popular formats like FBX, Collada or OBJ as well. Nevertheless, you should always try to establish a glTF based workflow in your projects first.


4 Answers

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

like image 182
Roger Avatar answered Oct 03 '22 03:10

Roger


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
like image 34
cdiggins Avatar answered Oct 03 '22 01:10

cdiggins


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.

like image 30
George Profenza Avatar answered Oct 03 '22 01:10

George Profenza


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.

like image 35
Slider Avatar answered Oct 03 '22 02:10

Slider