我是cocos3d的新手,我读过一些关于将3D模型加载到cocos3d中的信息。据我所知,在cocos3d中添加3D模型的原生方法是通过转换器将从Blender或3DsMax获得的模型转换为POD格式。是不是看起来有点难?在我的应用程序中,我可以很容易地做到这一点,因为我只有很少的模型,但是假设我正在编写一个有成百上千个模型的大型游戏,我应该这样做吗?转换我拥有的每一个模型?这是一个很好的实践吗?
谢谢!
发布于 2013-02-07 15:45:22
好吧,也许这个答案会对某些人有用。我已经写了一些脚本来自动从我的3d设计师那里获得3d模型(他们正在使用Blender)。第一个是将.blend文件导出为.dae,它是用Python语言编写的,文件应该存在于一个目录中(参见下一个脚本中的参数列表):
import os
import sys
import glob
import bpy
if len(sys.argv) != 7:
print("Must provide input and output path")
else:
for infile in glob.glob(os.path.join(sys.argv[5], '*.blend')):
bpy.ops.object.select_all(action='SELECT')
bpy.ops.object.delete()
bpy.ops.wm.open_mainfile(filepath=infile)
bpy.ops.object.select_all(action='SELECT')
bpy.ops.object.transform_apply(location=True,rotation=True,scale=True)
outfilename = os.path.splitext(os.path.split(infile)[1])[0] + ".dae"
bpy.ops.wm.collada_export(filepath=os.path.join(sys.argv[6], outfilename),apply_modifiers=True,include_armatures=True,deform_bones_only=True,include_uv_textures=True,include_material_textures=True,active_uv_only=True)第二个是使用Collada2Pod将这些.dae文件导出到.pod,这是Perl:
#!/usr/bin/perl
my $dir = '/Users/nikita/Develop/model_convertor/dae_models/';
my $out_dir = '/Users/nikita/Develop/model_convertor/pod_models/';
my $collada = '/Users/nikita/Develop/model_convertor/Collada2POD/MacOS_x86_32/Collada2POD';
opendir(DIR, $dir) or die $!;
while (my $file = readdir(DIR)) {
next if ($file !~ m/\.dae/);
$out_file = $file;
$out_file =~ s/dae/pod/g;
$command = "$collada -i=$dir$file -o=$out_dir$out_file";
system($command);
}使用示例:
/Applications/blender.app/Contents/MacOS/blender --background --python /Users/nikita/Develop/model_convertor/exporter.py -- /Users/nikita/Develop/model_convertor/catalog /Users/nikita/Develop/model_convertor/dae_models
perl /Users/nikita/Develop/model_convertor/convertor.pl其中第一个命令是"/path/to/blender --background --python /path/to/ first /script -- /path/to/blend/files /path/to/dae/files“。第二个命令是简单地执行perl脚本。很抱歉在第二个脚本中硬编码常量变量:)希望这对某些人有用。
更新:我已经在第一个脚本中添加了transform_apply函数,因为没有应用转换的模型存在问题,这会导致输出中出现错误
https://stackoverflow.com/questions/11147481
复制相似问题