MaxScript和Deep Exploration结合使用,导出模型到ArcGIS

MaxScript可以帮我们批量操作3dsMax中的模型数据。这里几种操作给出样例:

1. 批量单个导出建筑模型块块为obj:

for obj in geometry do
(
	select obj
	rootpath = "F://data//tongji//newnewnew//objs//"
	filepathname = rootpath + getFilenameFile (obj.name)+".obj"
	obj_index = 1
	while doesFileExist filepathname == true do -- 防止小模块重名,重名的模块在后面增加数字
	(
		filepathname = rootpath + getFilenameFile (obj.name) + (obj_index as String) +".obj"
		obj_index = obj_index + 1
	)
	exportFile (filepathname) #noPrompt selectedOnly:true
)

2. 批量导出一级子节点的模块为obj(有些建筑物是多个模块成组,我们需要把整个建筑物作为一条记录导出):

function TraversalChildNode parentNode=
(
    for childnode in parentNode.children do
    (
		-- ExportObj childnode
		print childnode.name
		ExportObj childnode
		--for childrennode in childnode.children do
		--(
			--print childrennode.name
		--)
    )
)
       
function TraversalScene =
(
    TraversalChildNode rootNode
)

function ExportObj obj = 
(
	select obj
	exportFile ("F://data//tongji//newnewnew//objs//" + getFilenameFile (obj.name)+".obj") #noPrompt selectedOnly:true
)

TraversalScene()

然后,因为Deep Exploration转换模型每次都只能25个。所以我们把这些obj,通过python脚本分组,存成每25个obj+mtl一个文件夹,用Deep来转。其中tga复制到每个小文件夹里面。

# coding=utf-8
import os
import shutil
import math

root_path = r'F:\data\tongji\newnewnew' # input: \objs   output: \obj_3ds\0
name_list = []
tga_list = []
for filename in os.listdir(root_path + r'\objs'):
    num = filename.rfind('.')
    left_part = filename[:num]
    right_part = filename[num:]
    if  right_part == ".obj":
        print(left_part)
        name_list.append(left_part)
    elif right_part == ".tga":
        tga_list.append(left_part)

group_num = int(math.ceil(len(name_list) / 25.0))
tga_num = len(tga_list)

for i in range(0, group_num):
    path = root_path + r"\obj_3ds\0" + str(i)
    if not os.path.exists(path):
        os.mkdir(path)
    for j in range(0, 25):
        index = i * 25 + j
        obj_name = root_path + r'\objs\\' + name_list[index] + r".obj"
        mtl_name = root_path + r'\objs\\' + name_list[index] + r".mtl"
        new_obj_name = path + r'\\' + name_list[index] + r".obj"
        new_mtl_name = path + r'\\' + name_list[index] + r".mtl"
        if not os.path.exists(new_obj_name):
            shutil.copyfile(obj_name, new_obj_name)
        if not os.path.exists(new_mtl_name):
            shutil.copyfile(mtl_name, new_mtl_name)
    # add .tga
    for j in range(tga_num):
        tga_name = root_path + r'\objs\\' + tga_list[j] + r".tga"
        new_tga_name = path + r'\\' + tga_list[j] + r".tga"
        if not os.path.exists(new_tga_name):
            shutil.copyfile(tga_name, new_tga_name)

然后对每个小文件夹批量转换操作转3ds。这里转3ds时,deep会把贴图文件和3ds放在同一个文件夹。有时候贴图文件会重名,导致贴的图不对。这里我的同时似乎找到了一种相对巧妙的办法,我就不知道啦。

最后用ArcScene的导入3d模型工具就好了。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值