Ejemplo n.º 1
0
// parent_mat is armature-space
void ArmatureExporter::add_bone_node(Bone *bone, Object *ob_arm)
{
	std::string node_id = get_joint_id(bone, ob_arm);
	std::string node_name = std::string(bone->name);
	std::string node_sid = get_joint_sid(bone, ob_arm);

	COLLADASW::Node node(mSW);

	node.setType(COLLADASW::Node::JOINT);
	node.setNodeId(node_id);
	node.setNodeName(node_name);
	node.setNodeSid(node_sid);

	/*if ( bone->childbase.first == NULL || BLI_countlist(&(bone->childbase))>=2)
		add_blender_leaf_bone( bone, ob_arm , node );
	else{*/
	node.start();

	add_bone_transform(ob_arm, bone, node);

	for (Bone *child = (Bone*)bone->childbase.first; child; child = child->next) {
		add_bone_node(child, ob_arm);
	}
	node.end();
	//}
}
Ejemplo n.º 2
0
std::string ArmatureExporter::add_joints_source(Object *ob_arm, ListBase *defbase, const std::string& controller_id)
{
	std::string source_id = controller_id + JOINTS_SOURCE_ID_SUFFIX;

	int totjoint = 0;
	bDeformGroup *def;
	for (def = (bDeformGroup*)defbase->first; def; def = def->next) {
		if (is_bone_defgroup(ob_arm, def))
			totjoint++;
	}

	COLLADASW::NameSource source(mSW);
	source.setId(source_id);
	source.setArrayId(source_id + ARRAY_ID_SUFFIX);
	source.setAccessorCount(totjoint);
	source.setAccessorStride(1);
	
	COLLADASW::SourceBase::ParameterNameList &param = source.getParameterNameList();
	param.push_back("JOINT");

	source.prepareToAppendValues();

	for (def = (bDeformGroup*)defbase->first; def; def = def->next) {
		Bone *bone = get_bone_from_defgroup(ob_arm, def);
		if (bone)
			source.appendValues(get_joint_sid(bone, ob_arm));
	}

	source.finish();

	return source_id;
}
Ejemplo n.º 3
0
// parent_mat is armature-space
void ArmatureExporter::add_bone_node(Bone *bone,
                                     Object *ob_arm,
                                     SceneExporter *se,
                                     std::vector<Object *> &child_objects)
{
  if (can_export(bone)) {
    std::string node_id = translate_id(id_name(ob_arm) + "_" + bone->name);
    std::string node_name = std::string(bone->name);
    std::string node_sid = get_joint_sid(bone);

    COLLADASW::Node node(mSW);

    node.setType(COLLADASW::Node::JOINT);
    node.setNodeId(node_id);
    node.setNodeName(node_name);
    node.setNodeSid(node_sid);

    if (this->export_settings.get_use_blender_profile()) {
      if (!is_export_root(bone)) {
        if (bone->flag & BONE_CONNECTED) {
          node.addExtraTechniqueParameter("blender", "connect", true);
        }
      }
      std::string layers = BoneExtended::get_bone_layers(bone->layer);
      node.addExtraTechniqueParameter("blender", "layer", layers);

      bArmature *armature = (bArmature *)ob_arm->data;
      EditBone *ebone = bc_get_edit_bone(armature, bone->name);
      if (ebone && ebone->roll != 0) {
        node.addExtraTechniqueParameter("blender", "roll", ebone->roll);
      }
      if (bc_is_leaf_bone(bone)) {
        Vector head, tail;
        const BCMatrix &global_transform = this->export_settings.get_global_transform();
        if (this->export_settings.get_apply_global_orientation()) {
          bc_add_global_transform(head, bone->arm_head, global_transform);
          bc_add_global_transform(tail, bone->arm_tail, global_transform);
        }
        else {
          copy_v3_v3(head, bone->arm_head);
          copy_v3_v3(tail, bone->arm_tail);
        }
        node.addExtraTechniqueParameter("blender", "tip_x", tail[0] - head[0]);
        node.addExtraTechniqueParameter("blender", "tip_y", tail[1] - head[1]);
        node.addExtraTechniqueParameter("blender", "tip_z", tail[2] - head[2]);
      }
    }

    node.start();

    add_bone_transform(ob_arm, bone, node);

    // Write nodes of childobjects, remove written objects from list
    std::vector<Object *>::iterator iter = child_objects.begin();

    while (iter != child_objects.end()) {
      Object *ob = *iter;
      if (ob->partype == PARBONE && STREQ(ob->parsubstr, bone->name)) {
        float backup_parinv[4][4];
        copy_m4_m4(backup_parinv, ob->parentinv);

        // crude, temporary change to parentinv
        // so transform gets exported correctly.

        // Add bone tail- translation... don't know why
        // bone parenting is against the tail of a bone
        // and not it's head, seems arbitrary.
        ob->parentinv[3][1] += bone->length;

        // OPEN_SIM_COMPATIBILITY
        // TODO: when such objects are animated as
        // single matrix the tweak must be applied
        // to the result.
        if (export_settings.get_open_sim()) {
          // tweak objects parentinverse to match compatibility
          float temp[4][4];

          copy_m4_m4(temp, bone->arm_mat);
          temp[3][0] = temp[3][1] = temp[3][2] = 0.0f;

          mul_m4_m4m4(ob->parentinv, temp, ob->parentinv);
        }

        se->writeNode(ob);
        copy_m4_m4(ob->parentinv, backup_parinv);
        iter = child_objects.erase(iter);
      }
      else
        iter++;
    }

    for (Bone *child = (Bone *)bone->childbase.first; child; child = child->next) {
      add_bone_node(child, ob_arm, se, child_objects);
    }
    node.end();
  }
  else {
    for (Bone *child = (Bone *)bone->childbase.first; child; child = child->next) {
      add_bone_node(child, ob_arm, se, child_objects);
    }
  }
}