for (bone = (Bone *)arm->bonebase.first; bone; bone = bone->next) {
write_bone_URLs(ins, ob_arm, bone);
}
-
+
InstanceWriter::add_material_bindings(ins.getBindMaterial(), ob, this->export_settings->active_uv_only);
ins.add();
Object *ob_arm = bc_get_assigned_armature(ob);
Key *key = BKE_key_from_object(ob);
- if (ob_arm)
+ if (ob_arm) {
export_skin_controller(ob, ob_arm);
- if(key){
+ }
+ if (key) {
export_morph_controller(ob, key);
}
}
bool use_instantiation = this->export_settings->use_object_instantiation;
Mesh *me;
- if (this->export_settings->apply_modifiers)
- me = bc_to_mesh_apply_modifiers(scene, ob, this->export_settings->export_mesh_type);
- else
- me = (Mesh *)ob->data;
+ me = bc_get_mesh_copy(scene,
+ ob,
+ this->export_settings->export_mesh_type,
+ this->export_settings->apply_modifiers,
+ this->export_settings->triangulate);
- BKE_mesh_tessface_ensure(me);
-
if (!me->dvert) return;
std::string controller_name = id_name(ob_arm);
joint_index_by_def_index.push_back(-1);
}
+ int oob_counter = 0;
for (i = 0; i < me->totvert; i++) {
MDeformVert *vert = &me->dvert[i];
std::map<int, float> jw;
float sumw = 0.0f;
for (j = 0; j < vert->totweight; j++) {
- int joint_index = joint_index_by_def_index[vert->dw[j].def_nr];
- if (joint_index != -1 && vert->dw[j].weight > 0.0f) {
- jw[joint_index] += vert->dw[j].weight;
- sumw += vert->dw[j].weight;
+ int idx = vert->dw[j].def_nr;
+ if (idx >= joint_index_by_def_index.size()) {
+ // XXX: Maybe better find out where and
+ // why the Out Of Bound indexes get created ?
+ oob_counter += 1;
+ }
+ else {
+ if (idx >= 0) {
+ int joint_index = joint_index_by_def_index[idx];
+ if (joint_index != -1 && vert->dw[j].weight > 0.0f) {
+ jw[joint_index] += vert->dw[j].weight;
+ sumw += vert->dw[j].weight;
+ }
+ }
}
}
#endif
}
}
+
+ if (oob_counter > 0) {
+ fprintf(stderr, "Ignored %d Vertex weigths which use index to non existing VGroup %ld.\n", oob_counter, joint_index_by_def_index.size());
+ }
}
std::string weights_source_id = add_weights_source(me, controller_id, weights);
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);
- if (this->export_settings->apply_modifiers)
- {
- BKE_libblock_free_us(&(G.main->mesh), me);
- }
+ BKE_libblock_free_us(&(G.main->mesh), me);
+
closeSkin();
closeController();
}
bool use_instantiation = this->export_settings->use_object_instantiation;
Mesh *me;
- if (this->export_settings->apply_modifiers) {
- me = bc_to_mesh_apply_modifiers(scene, ob, this->export_settings->export_mesh_type);
- }
- else {
- me = (Mesh *)ob->data;
- }
- BKE_mesh_tessface_ensure(me);
+ me = bc_get_mesh_copy(scene,
+ ob,
+ this->export_settings->export_mesh_type,
+ this->export_settings->apply_modifiers,
+ this->export_settings->triangulate);
std::string controller_name = id_name(ob) + "-morph";
std::string controller_id = get_controller_id(key, ob);
openMorph(controller_id, controller_name,
COLLADABU::URI(COLLADABU::Utils::EMPTY_STRING, get_geometry_id(ob, use_instantiation)));
-
+
std::string targets_id = add_morph_targets(key, ob);
std::string morph_weights_id = add_morph_weights(key, ob);
COLLADASW::URI(COLLADABU::Utils::EMPTY_STRING, morph_weights_id)));
targets.add();
- if (this->export_settings->apply_modifiers)
- {
- BKE_libblock_free_us(&(G.main->mesh), me);
- }
-
+ BKE_libblock_free_us(&(G.main->mesh), me);
+
+
//support for animations
//can also try the base element and param alternative
add_weight_extras(key);
source.setArrayId(source_id + ARRAY_ID_SUFFIX);
source.setAccessorCount(key->totkey - 1);
source.setAccessorStride(1);
-
+
COLLADASW::SourceBase::ParameterNameList ¶m = source.getParameterNameList();
param.push_back("IDREF");
source.prepareToAppendValues();
- KeyBlock * kb = (KeyBlock*)key->block.first;
+ KeyBlock *kb = (KeyBlock *)key->block.first;
//skip the basis
kb = kb->next;
for (; kb; kb = kb->next) {
source.setArrayId(source_id + ARRAY_ID_SUFFIX);
source.setAccessorCount(key->totkey - 1);
source.setAccessorStride(1);
-
+
COLLADASW::SourceBase::ParameterNameList ¶m = source.getParameterNameList();
param.push_back("MORPH_WEIGHT");
source.prepareToAppendValues();
- KeyBlock * kb = (KeyBlock*)key->block.first;
+ KeyBlock *kb = (KeyBlock *)key->block.first;
//skip the basis
kb = kb->next;
for (; kb; kb = kb->next) {
}
//Added to implemente support for animations.
-void ControllerExporter::add_weight_extras(Key *key){
+void ControllerExporter::add_weight_extras(Key *key)
+{
// can also try the base element and param alternative
COLLADASW::BaseExtraTechnique extra;
- KeyBlock * kb = (KeyBlock*)key->block.first;
+ KeyBlock * kb = (KeyBlock *)key->block.first;
//skip the basis
kb = kb->next;
for (; kb; kb = kb->next) {
- float weight = kb->curval;
+ // XXX why is the weight not used here and set to 0.0?
+ // float weight = kb->curval;
extra.addExtraTechniqueParameter ("KHR", "morph_weights" , 0.000, "MORPH_WEIGHT_TO_TARGET");
}
}