Nuke DM out of collada code.

Also, now use out-of-main temp copy of mesh for export, and fixed a
potential memleak (return without freeing temp copy of mesh, tsst).
This commit is contained in:
2018-06-24 18:40:52 +02:00
parent d0856d1d54
commit a59d7374ea
7 changed files with 23 additions and 29 deletions

View File

@@ -42,7 +42,6 @@ extern "C"
#include "BLI_listbase.h" #include "BLI_listbase.h"
#include "BLI_utildefines.h" #include "BLI_utildefines.h"
#include "BKE_DerivedMesh.h"
#include "BKE_fcurve.h" #include "BKE_fcurve.h"
#include "BKE_animsys.h" #include "BKE_animsys.h"
#include "BKE_scene.h" #include "BKE_scene.h"

View File

@@ -199,8 +199,11 @@ void ControllerExporter::export_skin_controller(Object *ob, Object *ob_arm)
bool use_instantiation = this->export_settings->use_object_instantiation; bool use_instantiation = this->export_settings->use_object_instantiation;
Mesh *me; Mesh *me;
if (((Mesh *)ob->data)->dvert == NULL) {
return;
}
me = bc_get_mesh_copy( me = bc_get_mesh_copy(
m_bmain,
depsgraph, depsgraph,
scene, scene,
ob, ob,
@@ -208,8 +211,6 @@ void ControllerExporter::export_skin_controller(Object *ob, Object *ob_arm)
this->export_settings->apply_modifiers, this->export_settings->apply_modifiers,
this->export_settings->triangulate); this->export_settings->triangulate);
if (!me->dvert) return;
std::string controller_name = id_name(ob_arm); std::string controller_name = id_name(ob_arm);
std::string controller_id = get_controller_id(ob_arm, ob); std::string controller_id = get_controller_id(ob_arm, ob);
@@ -293,7 +294,7 @@ void ControllerExporter::export_skin_controller(Object *ob, Object *ob_arm)
add_joints_element(&ob->defbase, joints_source_id, inv_bind_mat_source_id); add_joints_element(&ob->defbase, joints_source_id, inv_bind_mat_source_id);
add_vertex_weights_element(weights_source_id, joints_source_id, vcounts, joints); add_vertex_weights_element(weights_source_id, joints_source_id, vcounts, joints);
BKE_libblock_free_us(m_bmain, me); BKE_id_free(NULL, me);
closeSkin(); closeSkin();
closeController(); closeController();
@@ -305,7 +306,6 @@ void ControllerExporter::export_morph_controller(Object *ob, Key *key)
Mesh *me; Mesh *me;
me = bc_get_mesh_copy( me = bc_get_mesh_copy(
m_bmain,
depsgraph, depsgraph,
scene, scene,
ob, ob,
@@ -332,8 +332,7 @@ void ControllerExporter::export_morph_controller(Object *ob, Key *key)
COLLADASW::URI(COLLADABU::Utils::EMPTY_STRING, morph_weights_id))); COLLADASW::URI(COLLADABU::Utils::EMPTY_STRING, morph_weights_id)));
targets.add(); targets.add();
BKE_libblock_free_us(m_bmain, me); BKE_id_free(NULL, me);
//support for animations //support for animations
//can also try the base element and param alternative //can also try the base element and param alternative

View File

@@ -85,11 +85,11 @@ extern "C"
#include "BLI_listbase.h" #include "BLI_listbase.h"
#include "BLI_utildefines.h" #include "BLI_utildefines.h"
#include "BKE_DerivedMesh.h"
#include "BKE_action.h" // pose functions #include "BKE_action.h" // pose functions
#include "BKE_animsys.h" #include "BKE_animsys.h"
#include "BKE_armature.h" #include "BKE_armature.h"
#include "BKE_blender_version.h" #include "BKE_blender_version.h"
#include "BKE_customdata.h"
#include "BKE_fcurve.h" #include "BKE_fcurve.h"
#include "BKE_global.h" #include "BKE_global.h"
#include "BKE_image.h" #include "BKE_image.h"

View File

@@ -40,7 +40,6 @@
extern "C" { extern "C" {
#include "BLI_utildefines.h" #include "BLI_utildefines.h"
#include "BKE_DerivedMesh.h"
#include "BKE_main.h" #include "BKE_main.h"
#include "BKE_global.h" #include "BKE_global.h"
#include "BKE_library.h" #include "BKE_library.h"
@@ -72,14 +71,8 @@ void GeometryExporter::exportGeom(Main *bmain, struct Depsgraph *depsgraph, Scen
void GeometryExporter::operator()(Object *ob) void GeometryExporter::operator()(Object *ob)
{ {
// XXX don't use DerivedMesh, Mesh instead?
#if 0
DerivedMesh *dm = mesh_get_derived_final(mScene, ob, CD_MASK_BAREMESH);
#endif
bool use_instantiation = this->export_settings->use_object_instantiation; bool use_instantiation = this->export_settings->use_object_instantiation;
Mesh *me = bc_get_mesh_copy( Mesh *me = bc_get_mesh_copy(
m_bmain,
mDepsgraph, mDepsgraph,
mScene, mScene,
ob, ob,
@@ -170,8 +163,7 @@ void GeometryExporter::operator()(Object *ob)
} }
} }
BKE_libblock_free_us(m_bmain, me); BKE_id_free(NULL, me);
} }
void GeometryExporter::export_key_mesh(Object *ob, Mesh *me, KeyBlock *kb) void GeometryExporter::export_key_mesh(Object *ob, Mesh *me, KeyBlock *kb)

View File

@@ -48,7 +48,6 @@ extern "C" {
#include "DNA_modifier_types.h" #include "DNA_modifier_types.h"
#include "DNA_userdef_types.h" #include "DNA_userdef_types.h"
#include "BKE_DerivedMesh.h"
#include "BKE_fcurve.h" #include "BKE_fcurve.h"
#include "BKE_animsys.h" #include "BKE_animsys.h"
#include "BLI_path_util.h" #include "BLI_path_util.h"

View File

@@ -51,8 +51,8 @@ extern "C" {
#include "BKE_global.h" #include "BKE_global.h"
#include "BKE_layer.h" #include "BKE_layer.h"
#include "BKE_mesh.h" #include "BKE_mesh.h"
#include "BKE_mesh_runtime.h"
#include "BKE_scene.h" #include "BKE_scene.h"
#include "BKE_DerivedMesh.h"
#include "BKE_main.h" #include "BKE_main.h"
#include "ED_armature.h" #include "ED_armature.h"
@@ -160,13 +160,13 @@ Object *bc_add_object(Main *bmain, Scene *scene, ViewLayer *view_layer, int type
} }
Mesh *bc_get_mesh_copy( Mesh *bc_get_mesh_copy(
Main *bmain, Depsgraph *depsgraph, Scene *scene, Object *ob, BC_export_mesh_type export_mesh_type, bool apply_modifiers, bool triangulate) Depsgraph *depsgraph, Scene *scene, Object *ob, BC_export_mesh_type export_mesh_type, bool apply_modifiers, bool triangulate)
{ {
Mesh *tmpmesh;
CustomDataMask mask = CD_MASK_MESH; CustomDataMask mask = CD_MASK_MESH;
Mesh *mesh = (Mesh *)ob->data; Mesh *mesh = (Mesh *)ob->data;
DerivedMesh *dm = NULL; Mesh *tmpmesh = NULL;
if (apply_modifiers) { if (apply_modifiers) {
#if 0 /* Not supported by new system currently... */
switch (export_mesh_type) { switch (export_mesh_type) {
case BC_MESH_TYPE_VIEW: case BC_MESH_TYPE_VIEW:
{ {
@@ -179,14 +179,20 @@ Mesh *bc_get_mesh_copy(
break; break;
} }
} }
#else
tmpmesh = mesh_get_eval_final(depsgraph, scene, ob, mask);
#endif
} }
else { else {
dm = mesh_create_derived((Mesh *)ob->data, NULL); tmpmesh = mesh;
} }
tmpmesh = BKE_mesh_add(bmain, "ColladaMesh"); // name is not important here BKE_id_copy_ex(NULL, &tmpmesh->id, (ID **)&tmpmesh,
DM_to_mesh(dm, tmpmesh, ob, CD_MASK_MESH, true); LIB_ID_CREATE_NO_MAIN |
tmpmesh->flag = mesh->flag; LIB_ID_CREATE_NO_USER_REFCOUNT |
LIB_ID_CREATE_NO_DEG_TAG |
LIB_ID_COPY_NO_PREVIEW,
false);
if (triangulate) { if (triangulate) {
bc_triangulate_mesh(tmpmesh); bc_triangulate_mesh(tmpmesh);

View File

@@ -51,7 +51,6 @@ extern "C" {
#include "BKE_context.h" #include "BKE_context.h"
#include "BKE_object.h" #include "BKE_object.h"
#include "BKE_DerivedMesh.h"
#include "BKE_scene.h" #include "BKE_scene.h"
#include "BKE_idprop.h" #include "BKE_idprop.h"
} }
@@ -73,7 +72,7 @@ extern int bc_test_parent_loop(Object *par, Object *ob);
extern int bc_set_parent(Object *ob, Object *par, bContext *C, bool is_parent_space = true); extern int bc_set_parent(Object *ob, Object *par, bContext *C, bool is_parent_space = true);
extern Object *bc_add_object(Main *bmain, Scene *scene, ViewLayer *view_layer, int type, const char *name); extern Object *bc_add_object(Main *bmain, Scene *scene, ViewLayer *view_layer, int type, const char *name);
extern Mesh *bc_get_mesh_copy( extern Mesh *bc_get_mesh_copy(
Main *bmain, Depsgraph *depsgraph, Scene *scene, Object *ob, BC_export_mesh_type export_mesh_type, bool apply_modifiers, bool triangulate); Depsgraph *depsgraph, Scene *scene, Object *ob, BC_export_mesh_type export_mesh_type, bool apply_modifiers, bool triangulate);
extern Object *bc_get_assigned_armature(Object *ob); extern Object *bc_get_assigned_armature(Object *ob);
extern Object *bc_get_highest_selected_ancestor_or_self(LinkNode *export_set, Object *ob); extern Object *bc_get_highest_selected_ancestor_or_self(LinkNode *export_set, Object *ob);