Question

I'm new to cocos3d and I've read some information about loading 3d-models into cocos3d. The native way to add 3d-models in cocos3d is, as I understood, to convert models got from Blender or from 3DsMax into POD format via convertors. Is not it seemed a bit difficult? In my app I can easily do this as I've got few models, but assume I'm writing a big game with hundreds or thousands models, should I do the same? Convert every model I have? Is it a good practice?

Thanks!

Was it helpful?

Solution

ok, maybe this answer will be useful to someone. I've written few scripts to automate getting 3d models from my 3d designers (they are using Blender). The first one is to export .blend files as .dae, it is written on Python, files should exist in one directory (see argument list in next scripts):

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)

the second one is to export these .dae files to .pod with Collada2Pod, this is 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);
}

usage example:

/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

where the first command is "/path/to/blender --background --python /path/to/first/script -- /path/to/blend/files /path/to/dae/files". The second command is simply perl script execute. Sorry for hard coding constant variables in the second script :) Hope that would be useful to someone.

Update: I've added transform_apply function into first script, since there were problems with models without applied transforms, which caused wrong ones in output

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top