Exemple #1
0
	int collada_export(Scene *sce, const char *filepath, int selected, int apply_modifiers, int second_life)
	{
		ExportSettings export_settings;
		
		export_settings.selected        = selected != 0;
		export_settings.apply_modifiers = apply_modifiers != 0;
		export_settings.second_life     = second_life != 0;
		export_settings.filepath        = (char *)filepath;

		/* annoying, collada crashes if file cant be created! [#27162] */
		if (!BLI_exists(filepath)) {
			BLI_make_existing_file(filepath); /* makes the dir if its not there */
			if (BLI_file_touch(filepath) == 0) {
				return 0;
			}
		}
		/* end! */

		DocumentExporter exporter(&export_settings);
		exporter.exportCurrentScene(sce);

		return 1;
	}
Exemple #2
0
/* function used for WM_OT_save_mainfile too */
static int wm_collada_export_exec(bContext *C, wmOperator *op)
{
    char filepath[FILE_MAX];
    int apply_modifiers;
    int export_mesh_type;
    int selected;
    int include_children;
    int include_armatures;
    int include_shapekeys;
    int deform_bones_only;

    int include_uv_textures;
    int include_material_textures;
    int use_texture_copies;
    int active_uv_only;

    int triangulate;
    int use_object_instantiation;
    int sort_by_name;
    int export_transformation_type;
    int open_sim;

    int export_count;

    if (!RNA_struct_property_is_set(op->ptr, "filepath")) {
        BKE_report(op->reports, RPT_ERROR, "No filename given");
        return OPERATOR_CANCELLED;
    }

    RNA_string_get(op->ptr, "filepath", filepath);
    BLI_ensure_extension(filepath, sizeof(filepath), ".dae");


    /* Avoid File write exceptions in Collada */
    if (!BLI_exists(filepath)) {
        BLI_make_existing_file(filepath);
        if (!BLI_file_touch(filepath)) {
            BKE_report(op->reports, RPT_ERROR, "Can't create export file");
            fprintf(stdout, "Collada export: Can not create: %s\n", filepath);
            return OPERATOR_CANCELLED;
        }
    }
    else if (!BLI_file_is_writable(filepath)) {
        BKE_report(op->reports, RPT_ERROR, "Can't overwrite export file");
        fprintf(stdout, "Collada export: Can not modify: %s\n", filepath);
        return OPERATOR_CANCELLED;
    }

    /* Now the exporter can create and write the export file */

    /* Options panel */
    apply_modifiers          = RNA_boolean_get(op->ptr, "apply_modifiers");
    export_mesh_type         = RNA_enum_get(op->ptr,    "export_mesh_type_selection");
    selected                 = RNA_boolean_get(op->ptr, "selected");
    include_children         = RNA_boolean_get(op->ptr, "include_children");
    include_armatures        = RNA_boolean_get(op->ptr, "include_armatures");
    include_shapekeys        = RNA_boolean_get(op->ptr, "include_shapekeys");
    deform_bones_only        = RNA_boolean_get(op->ptr, "deform_bones_only");

    include_uv_textures      = RNA_boolean_get(op->ptr, "include_uv_textures");
    include_material_textures = RNA_boolean_get(op->ptr, "include_material_textures");
    use_texture_copies       = RNA_boolean_get(op->ptr, "use_texture_copies");
    active_uv_only           = RNA_boolean_get(op->ptr, "active_uv_only");

    triangulate                = RNA_boolean_get(op->ptr, "triangulate");
    use_object_instantiation   = RNA_boolean_get(op->ptr, "use_object_instantiation");
    sort_by_name               = RNA_boolean_get(op->ptr, "sort_by_name");
    export_transformation_type = RNA_enum_get(op->ptr,    "export_transformation_type_selection");
    open_sim                   = RNA_boolean_get(op->ptr, "open_sim");

    /* get editmode results */
    ED_object_editmode_load(CTX_data_edit_object(C));


    export_count = collada_export(CTX_data_scene(C),
                                  filepath,
                                  apply_modifiers,
                                  export_mesh_type,
                                  selected,
                                  include_children,
                                  include_armatures,
                                  include_shapekeys,
                                  deform_bones_only,

                                  active_uv_only,
                                  include_uv_textures,
                                  include_material_textures,
                                  use_texture_copies,

                                  triangulate,
                                  use_object_instantiation,
                                  sort_by_name,
                                  export_transformation_type,
                                  open_sim);

    if (export_count == 0) {
        BKE_report(op->reports, RPT_WARNING, "Export file is empty");
        return OPERATOR_CANCELLED;
    }
    else {
        char buff[100];
        sprintf(buff, "Exported %d Objects", export_count);
        BKE_report(op->reports, RPT_INFO, buff);
        return OPERATOR_FINISHED;
    }
}