سؤال

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?

هل كانت مفيدة؟

المحلول

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

نصائح أخرى

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

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.

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!

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top