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?
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.
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
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
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With