我知道THREE.js有来自各种3D图形格式的导入器。
是否有一种适合显示在三维工作室Max中创建的模型的导入器?如果没有,是否有一种将3D Studio Max模型转换为可以在THREE.js中导入的格式的方法?
您有两个选择:
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上发布的问题:
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
我有一段时间没有使用three.js了,但是我知道它可以导入OBJ格式的文件,而3dsmax可以轻松地导出该格式,并且有一个Python脚本可以将.obj转换为three.js的.json网格。
我注意到在最新版本中,有一个MaxScript Exporter直接导出json格式,所以从那里开始。它应该会生成一个基于所选网格的.js文件,但目前无法访问PC进行测试。
现在是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
享受吧!