style cleanup

This commit is contained in:
Campbell Barton 2012-06-12 22:05:33 +00:00
parent 46c95d37c6
commit 2e8a2f7668
28 changed files with 1293 additions and 1254 deletions

@ -161,13 +161,13 @@ struct MovieClip *BKE_object_movieclip_get(struct Scene *scene, struct Object *o
/* this function returns a superset of the scenes selection based on relationships */
typedef enum eObRelationTypes {
OB_REL_NONE = 0, /* just the selection as is */
OB_REL_PARENT = (1<<0), /* immediate parent */
OB_REL_PARENT_RECURSIVE = (1<<1), /* parents up to root of selection tree*/
OB_REL_CHILDREN = (1<<2), /* immediate children */
OB_REL_CHILDREN_RECURSIVE = (1<<3), /* All children */
OB_REL_MOD_ARMATURE = (1<<4), /* Armatures related to the selected objects */
OB_REL_SCENE_CAMERA = (1<<5), /* you might want the scene camera too even if unselected? */
OB_REL_NONE = 0, /* just the selection as is */
OB_REL_PARENT = (1 << 0), /* immediate parent */
OB_REL_PARENT_RECURSIVE = (1 << 1), /* parents up to root of selection tree*/
OB_REL_CHILDREN = (1 << 2), /* immediate children */
OB_REL_CHILDREN_RECURSIVE = (1 << 3), /* All children */
OB_REL_MOD_ARMATURE = (1 << 4), /* Armatures related to the selected objects */
OB_REL_SCENE_CAMERA = (1 << 5), /* you might want the scene camera too even if unselected? */
} eObRelationTypes;
typedef enum eObjectSet {

@ -3090,13 +3090,11 @@ static Object *obrel_armature_find(Object *ob)
ob_arm = ob->parent;
}
else {
ModifierData *mod = (ModifierData*)ob->modifiers.first;
while (mod) {
ModifierData *mod;
for (mod = (ModifierData *)ob->modifiers.first; mod; mod = mod->next) {
if (mod->type == eModifierType_Armature) {
ob_arm = ((ArmatureModifierData*)mod)->object;
ob_arm = ((ArmatureModifierData *)mod)->object;
}
mod = mod->next;
}
}
@ -3104,11 +3102,11 @@ static Object *obrel_armature_find(Object *ob)
}
static int obrel_is_recursive_child(Object *ob, Object *child) {
Object *ancestor = child->parent;
while (ancestor)
{
if(ancestor == ob) return TRUE;
ancestor = ancestor->parent;
Object *par;
for (par = child->parent; par; par = par->parent) {
if (par == ob) {
return TRUE;
}
}
return FALSE;
}
@ -3151,16 +3149,16 @@ struct LinkNode *BKE_object_relational_superset(struct Scene *scene, eObjectSet
obrel_list_add(&links, ob);
}
else {
if ( (objectSet == OB_SET_SELECTED && TESTBASELIB_BGMODE(((View3D *)NULL), scene, base))
|| (objectSet == OB_SET_VISIBLE && BASE_EDITABLE_BGMODE(((View3D *)NULL), scene, base))
) {
if ((objectSet == OB_SET_SELECTED && TESTBASELIB_BGMODE(((View3D *)NULL), scene, base)) ||
(objectSet == OB_SET_VISIBLE && BASE_EDITABLE_BGMODE(((View3D *)NULL), scene, base)))
{
Object *ob = base->object;
if (obrel_list_test(ob))
obrel_list_add(&links, ob);
/* parent relationship */
if (includeFilter & ( OB_REL_PARENT | OB_REL_PARENT_RECURSIVE )) {
if (includeFilter & (OB_REL_PARENT | OB_REL_PARENT_RECURSIVE)) {
Object *parent = ob->parent;
if (obrel_list_test(parent)) {
@ -3169,7 +3167,7 @@ struct LinkNode *BKE_object_relational_superset(struct Scene *scene, eObjectSet
/* recursive parent relationship */
if (includeFilter & OB_REL_PARENT_RECURSIVE) {
parent = parent->parent;
while (obrel_list_test(parent)){
while (obrel_list_test(parent)) {
obrel_list_add(&links, parent);
parent = parent->parent;
@ -3179,15 +3177,16 @@ struct LinkNode *BKE_object_relational_superset(struct Scene *scene, eObjectSet
}
/* child relationship */
if (includeFilter & ( OB_REL_CHILDREN | OB_REL_CHILDREN_RECURSIVE )) {
if (includeFilter & (OB_REL_CHILDREN | OB_REL_CHILDREN_RECURSIVE)) {
Base *local_base;
for (local_base = scene->base.first; local_base; local_base = local_base->next) {
if (BASE_EDITABLE_BGMODE(((View3D *)NULL), scene, local_base)) {
Object *child = local_base->object;
if (obrel_list_test(child)) {
if ((includeFilter & OB_REL_CHILDREN_RECURSIVE && obrel_is_recursive_child(ob,child))
|| (includeFilter & OB_REL_CHILDREN && child->parent && child->parent == ob )) {
if ((includeFilter & OB_REL_CHILDREN_RECURSIVE && obrel_is_recursive_child(ob, child)) ||
(includeFilter & OB_REL_CHILDREN && child->parent && child->parent == ob))
{
obrel_list_add(&links, child);
}
}
@ -3206,7 +3205,7 @@ struct LinkNode *BKE_object_relational_superset(struct Scene *scene, eObjectSet
}
}
} // end for
}
return links;
}

@ -28,7 +28,7 @@ template<class Functor>
void forEachObjectInExportSet(Scene *sce, Functor &f, LinkNode *export_set)
{
LinkNode *node;
for(node=export_set; node; node=node->next) {
for (node = export_set; node; node = node->next) {
Object *ob = (Object *)node->link;
f(ob);
}
@ -48,7 +48,7 @@ void AnimationExporter::exportAnimations(Scene *sce)
}
// called for each exported object
void AnimationExporter::operator() (Object *ob)
void AnimationExporter::operator()(Object *ob)
{
FCurve *fcu;
char *transformName;
@ -56,24 +56,24 @@ void AnimationExporter::operator() (Object *ob)
//Export transform animations
if (ob->adt && ob->adt->action) {
fcu = (FCurve*)ob->adt->action->curves.first;
fcu = (FCurve *)ob->adt->action->curves.first;
//transform matrix export for bones are temporarily disabled here.
if ( ob->type == OB_ARMATURE ) {
bArmature *arm = (bArmature*)ob->data;
for (Bone *bone = (Bone*)arm->bonebase.first; bone; bone = bone->next)
if (ob->type == OB_ARMATURE) {
bArmature *arm = (bArmature *)ob->data;
for (Bone *bone = (Bone *)arm->bonebase.first; bone; bone = bone->next)
write_bone_animation_matrix(ob, bone);
}
while (fcu) {
//for armature animations as objects
if ( ob->type == OB_ARMATURE )
if (ob->type == OB_ARMATURE)
transformName = fcu->rna_path;
else
transformName = extract_transform_name( fcu->rna_path );
transformName = extract_transform_name(fcu->rna_path);
if ((!strcmp(transformName, "location") || !strcmp(transformName, "scale")) ||
(!strcmp(transformName, "rotation_euler") && ob->rotmode == ROT_MODE_EUL)||
(!strcmp(transformName, "rotation_euler") && ob->rotmode == ROT_MODE_EUL) ||
(!strcmp(transformName, "rotation_quaternion")))
{
dae_animation(ob, fcu, transformName, false);
@ -84,12 +84,12 @@ void AnimationExporter::operator() (Object *ob)
}
//Export Lamp parameter animations
if ( (ob->type == OB_LAMP ) && ((Lamp*)ob ->data)->adt && ((Lamp*)ob ->data)->adt->action ) {
fcu = (FCurve*)(((Lamp*)ob ->data)->adt->action->curves.first);
if ( (ob->type == OB_LAMP) && ((Lamp *)ob->data)->adt && ((Lamp *)ob->data)->adt->action) {
fcu = (FCurve *)(((Lamp *)ob->data)->adt->action->curves.first);
while (fcu) {
transformName = extract_transform_name( fcu->rna_path );
transformName = extract_transform_name(fcu->rna_path);
if ((!strcmp(transformName, "color")) || (!strcmp(transformName, "spot_size"))||
if ((!strcmp(transformName, "color")) || (!strcmp(transformName, "spot_size")) ||
(!strcmp(transformName, "spot_blend")) || (!strcmp(transformName, "distance")))
{
dae_animation(ob, fcu, transformName, true);
@ -99,14 +99,14 @@ void AnimationExporter::operator() (Object *ob)
}
//Export Camera parameter animations
if ( (ob->type == OB_CAMERA ) && ((Camera*)ob ->data)->adt && ((Camera*)ob ->data)->adt->action ) {
fcu = (FCurve*)(((Camera*)ob ->data)->adt->action->curves.first);
if ( (ob->type == OB_CAMERA) && ((Camera *)ob->data)->adt && ((Camera *)ob->data)->adt->action) {
fcu = (FCurve *)(((Camera *)ob->data)->adt->action->curves.first);
while (fcu) {
transformName = extract_transform_name( fcu->rna_path );
transformName = extract_transform_name(fcu->rna_path);
if ((!strcmp(transformName, "lens"))||
(!strcmp(transformName, "ortho_scale"))||
(!strcmp(transformName, "clip_end"))||(!strcmp(transformName, "clip_start")))
if ((!strcmp(transformName, "lens")) ||
(!strcmp(transformName, "ortho_scale")) ||
(!strcmp(transformName, "clip_end")) || (!strcmp(transformName, "clip_start")))
{
dae_animation(ob, fcu, transformName, true);
}
@ -116,19 +116,19 @@ void AnimationExporter::operator() (Object *ob)
//Export Material parameter animations.
for (int a = 0; a < ob->totcol; a++) {
Material *ma = give_current_material(ob, a+1);
Material *ma = give_current_material(ob, a + 1);
if (!ma) continue;
if (ma->adt && ma->adt->action) {
/* isMatAnim = true; */
fcu = (FCurve*)ma->adt->action->curves.first;
fcu = (FCurve *)ma->adt->action->curves.first;
while (fcu) {
transformName = extract_transform_name( fcu->rna_path );
transformName = extract_transform_name(fcu->rna_path);
if ((!strcmp(transformName, "specular_hardness"))||(!strcmp(transformName, "specular_color")) ||
(!strcmp(transformName, "diffuse_color"))||(!strcmp(transformName, "alpha")) ||
(!strcmp(transformName, "ior")))
if ((!strcmp(transformName, "specular_hardness")) || (!strcmp(transformName, "specular_color")) ||
(!strcmp(transformName, "diffuse_color")) || (!strcmp(transformName, "alpha")) ||
(!strcmp(transformName, "ior")))
{
dae_animation(ob, fcu, transformName, true, ma );
dae_animation(ob, fcu, transformName, true, ma);
}
fcu = fcu->next;
}
@ -138,33 +138,33 @@ void AnimationExporter::operator() (Object *ob)
}
//euler sources from quternion sources
float * AnimationExporter::get_eul_source_for_quat(Object *ob )
float *AnimationExporter::get_eul_source_for_quat(Object *ob)
{
FCurve *fcu = (FCurve*)ob->adt->action->curves.first;
FCurve *fcu = (FCurve *)ob->adt->action->curves.first;
const int keys = fcu->totvert;
float *quat = (float*)MEM_callocN(sizeof(float) * fcu->totvert * 4, "quat output source values");
float *eul = (float*)MEM_callocN(sizeof(float) * fcu->totvert * 3, "quat output source values");
float *quat = (float *)MEM_callocN(sizeof(float) * fcu->totvert * 4, "quat output source values");
float *eul = (float *)MEM_callocN(sizeof(float) * fcu->totvert * 3, "quat output source values");
float temp_quat[4];
float temp_eul[3];
while (fcu) {
char * transformName = extract_transform_name( fcu->rna_path );
char *transformName = extract_transform_name(fcu->rna_path);
if ( !strcmp(transformName, "rotation_quaternion") ) {
for ( int i = 0 ; i < fcu->totvert ; i++) {
*(quat + ( i * 4 ) + fcu->array_index) = fcu->bezt[i].vec[1][1];
if (!strcmp(transformName, "rotation_quaternion") ) {
for (int i = 0; i < fcu->totvert; i++) {
*(quat + (i * 4) + fcu->array_index) = fcu->bezt[i].vec[1][1];
}
}
fcu = fcu->next;
}
for ( int i = 0 ; i < keys ; i++) {
for ( int j = 0;j<4;j++)
temp_quat[j] = quat[(i*4)+j];
for (int i = 0; i < keys; i++) {
for (int j = 0; j < 4; j++)
temp_quat[j] = quat[(i * 4) + j];
quat_to_eul(temp_eul, temp_quat);
for (int k = 0;k<3;k++)
eul[i*3 + k] = temp_eul[k];
for (int k = 0; k < 3; k++)
eul[i * 3 + k] = temp_eul[k];
}
MEM_freeN(quat);
@ -173,22 +173,22 @@ float * AnimationExporter::get_eul_source_for_quat(Object *ob )
}
//Get proper name for bones
std::string AnimationExporter::getObjectBoneName( Object* ob, const FCurve* fcu )
std::string AnimationExporter::getObjectBoneName(Object *ob, const FCurve *fcu)
{
//hard-way to derive the bone name from rna_path. Must find more compact method
std::string rna_path = std::string(fcu->rna_path);
char* boneName = strtok((char *)rna_path.c_str(), "\"");
char *boneName = strtok((char *)rna_path.c_str(), "\"");
boneName = strtok(NULL, "\"");
if ( boneName != NULL )
if (boneName != NULL)
return /*id_name(ob) + "_" +*/ std::string(boneName);
else
return id_name(ob);
}
//convert f-curves to animation curves and write
void AnimationExporter::dae_animation(Object* ob, FCurve *fcu, char* transformName, bool is_param, Material * ma )
void AnimationExporter::dae_animation(Object *ob, FCurve *fcu, char *transformName, bool is_param, Material *ma)
{
const char *axis_name = NULL;
char anim_id[200];
@ -196,15 +196,15 @@ void AnimationExporter::dae_animation(Object* ob, FCurve *fcu, char* transformNa
bool has_tangents = false;
bool quatRotation = false;
if ( !strcmp(transformName, "rotation_quaternion") ) {
if (!strcmp(transformName, "rotation_quaternion") ) {
fprintf(stderr, "quaternion rotation curves are not supported. rotation curve will not be exported\n");
quatRotation = true;
return;
}
//axis names for colors
else if ( !strcmp(transformName, "color")||!strcmp(transformName, "specular_color")||!strcmp(transformName, "diffuse_color")||
(!strcmp(transformName, "alpha")))
else if (!strcmp(transformName, "color") || !strcmp(transformName, "specular_color") || !strcmp(transformName, "diffuse_color") ||
(!strcmp(transformName, "alpha")))
{
const char *axis_names[] = {"R", "G", "B"};
if (fcu->array_index < 3)
@ -213,7 +213,7 @@ void AnimationExporter::dae_animation(Object* ob, FCurve *fcu, char* transformNa
//axis names for transforms
else if ((!strcmp(transformName, "location") || !strcmp(transformName, "scale")) ||
(!strcmp(transformName, "rotation_euler"))||(!strcmp(transformName, "rotation_quaternion")))
(!strcmp(transformName, "rotation_euler")) || (!strcmp(transformName, "rotation_quaternion")))
{
const char *axis_names[] = {"X", "Y", "Z"};
if (fcu->array_index < 3)
@ -229,16 +229,16 @@ void AnimationExporter::dae_animation(Object* ob, FCurve *fcu, char* transformNa
//Create anim Id
if (ob->type == OB_ARMATURE) {
ob_name = getObjectBoneName(ob, fcu);
BLI_snprintf(anim_id, sizeof(anim_id), "%s_%s.%s", (char*)translate_id(ob_name).c_str(),
transformName, axis_name);
BLI_snprintf(anim_id, sizeof(anim_id), "%s_%s.%s", (char *)translate_id(ob_name).c_str(),
transformName, axis_name);
}
else {
if (ma)
ob_name = id_name(ob) + "_material";
else
ob_name = id_name(ob);
BLI_snprintf(anim_id, sizeof(anim_id), "%s_%s_%s", (char*)translate_id(ob_name).c_str(),
fcu->rna_path, axis_name);
BLI_snprintf(anim_id, sizeof(anim_id), "%s_%s_%s", (char *)translate_id(ob_name).c_str(),
fcu->rna_path, axis_name);
}
openAnimation(anim_id, COLLADABU::Utils::EMPTY_STRING);
@ -252,16 +252,16 @@ void AnimationExporter::dae_animation(Object* ob, FCurve *fcu, char* transformNa
//quat rotations are skipped for now, because of complications with determining axis.
if (quatRotation) {
float *eul = get_eul_source_for_quat(ob);
float *eul_axis = (float*)MEM_callocN(sizeof(float) * fcu->totvert, "quat output source values");
for (int i = 0 ; i< fcu->totvert ; i++) {
eul_axis[i] = eul[i*3 + fcu->array_index];
float *eul_axis = (float *)MEM_callocN(sizeof(float) * fcu->totvert, "quat output source values");
for (int i = 0; i < fcu->totvert; i++) {
eul_axis[i] = eul[i * 3 + fcu->array_index];
}
output_id= create_source_from_array(COLLADASW::InputSemantic::OUTPUT, eul_axis, fcu->totvert, quatRotation, anim_id, axis_name);
output_id = create_source_from_array(COLLADASW::InputSemantic::OUTPUT, eul_axis, fcu->totvert, quatRotation, anim_id, axis_name);
MEM_freeN(eul);
MEM_freeN(eul_axis);
}
else {
output_id= create_source_from_fcurve(COLLADASW::InputSemantic::OUTPUT, fcu, anim_id, axis_name);
output_id = create_source_from_fcurve(COLLADASW::InputSemantic::OUTPUT, fcu, anim_id, axis_name);
}
// create interpolations source
std::string interpolation_id = create_interpolation_source(fcu, anim_id, axis_name, &has_tangents);
@ -296,21 +296,21 @@ void AnimationExporter::dae_animation(Object* ob, FCurve *fcu, char* transformNa
std::string target;
if ( !is_param )
if (!is_param)
target = translate_id(ob_name) +
"/" + get_transform_sid(fcu->rna_path, -1, axis_name, true);
else {
if ( ob->type == OB_LAMP )
if (ob->type == OB_LAMP)
target = get_light_id(ob) +
"/" + get_light_param_sid(fcu->rna_path, -1, axis_name, true);
if ( ob->type == OB_CAMERA )
if (ob->type == OB_CAMERA)
target = get_camera_id(ob) +
"/" + get_camera_param_sid(fcu->rna_path, -1, axis_name, true);
if ( ma )
if (ma)
target = translate_id(id_name(ma)) + "-effect" +
"/common/" /*profile common is only supported */ + get_transform_sid(fcu->rna_path, -1, axis_name, true);
"/common/" /*profile common is only supported */ + get_transform_sid(fcu->rna_path, -1, axis_name, true);
}
addChannel(COLLADABU::URI(empty, sampler_id), target);
@ -330,18 +330,18 @@ void AnimationExporter::write_bone_animation_matrix(Object *ob_arm, Bone *bone)
sample_and_write_bone_animation_matrix(ob_arm, bone);
for (Bone *child = (Bone*)bone->childbase.first; child; child = child->next)
for (Bone *child = (Bone *)bone->childbase.first; child; child = child->next)
write_bone_animation_matrix(ob_arm, child);
}
bool AnimationExporter::is_bone_deform_group(Bone * bone)
bool AnimationExporter::is_bone_deform_group(Bone *bone)
{
bool is_def;
//Check if current bone is deform
if ((bone->flag & BONE_NO_DEFORM) == 0 ) return true;
if ((bone->flag & BONE_NO_DEFORM) == 0) return true;
//Check child bones
else {
for (Bone *child = (Bone*)bone->childbase.first; child; child = child->next) {
for (Bone *child = (Bone *)bone->childbase.first; child; child = child->next) {
//loop through all the children until deform bone is found, and then return
is_def = is_bone_deform_group(child);
if (is_def) return true;
@ -353,16 +353,16 @@ bool AnimationExporter::is_bone_deform_group(Bone * bone)
void AnimationExporter::sample_and_write_bone_animation_matrix(Object *ob_arm, Bone *bone)
{
bArmature *arm = (bArmature*)ob_arm->data;
bArmature *arm = (bArmature *)ob_arm->data;
int flag = arm->flag;
std::vector<float> fra;
//char prefix[256];
FCurve* fcu = (FCurve*)ob_arm->adt->action->curves.first;
FCurve *fcu = (FCurve *)ob_arm->adt->action->curves.first;
while (fcu) {
std::string bone_name = getObjectBoneName(ob_arm, fcu);
int val = BLI_strcasecmp((char*)bone_name.c_str(), bone->name);
if (val==0) break;
int val = BLI_strcasecmp((char *)bone_name.c_str(), bone->name);
if (val == 0) break;
fcu = fcu->next;
}
@ -379,7 +379,7 @@ void AnimationExporter::sample_and_write_bone_animation_matrix(Object *ob_arm, B
}
if (fra.size()) {
dae_baked_animation(fra, ob_arm, bone );
dae_baked_animation(fra, ob_arm, bone);
}
if (flag & ARM_RESTPOS)
@ -396,8 +396,8 @@ void AnimationExporter::dae_baked_animation(std::vector<float> &fra, Object *ob_
if (!fra.size())
return;
BLI_snprintf(anim_id, sizeof(anim_id), "%s_%s_%s", (char*)translate_id(ob_name).c_str(),
(char*)translate_id(bone_name).c_str(), "pose_matrix");
BLI_snprintf(anim_id, sizeof(anim_id), "%s_%s_%s", (char *)translate_id(ob_name).c_str(),
(char *)translate_id(bone_name).c_str(), "pose_matrix");
openAnimation(anim_id, COLLADABU::Utils::EMPTY_STRING);
@ -406,7 +406,7 @@ void AnimationExporter::dae_baked_animation(std::vector<float> &fra, Object *ob_
// create output source
std::string output_id;
output_id = create_4x4_source( fra, ob_arm, bone, anim_id);
output_id = create_4x4_source(fra, ob_arm, bone, anim_id);
// create interpolations source
std::string interpolation_id = fake_interpolation_source(fra.size(), anim_id, "");
@ -444,15 +444,15 @@ void AnimationExporter::dae_bone_animation(std::vector<float> &fra, float *value
char rna_path[200];
BLI_snprintf(rna_path, sizeof(rna_path), "pose.bones[\"%s\"].%s", bone_name.c_str(),
tm_type == 0 ? "rotation_quaternion" : (tm_type == 1 ? "scale" : "location"));
tm_type == 0 ? "rotation_quaternion" : (tm_type == 1 ? "scale" : "location"));
if (axis > -1)
axis_name = axis_names[axis];
std::string transform_sid = get_transform_sid(NULL, tm_type, axis_name, false);
BLI_snprintf(anim_id, sizeof(anim_id), "%s_%s_%s", (char*)translate_id(ob_name).c_str(),
(char*)translate_id(bone_name).c_str(), (char*)transform_sid.c_str());
BLI_snprintf(anim_id, sizeof(anim_id), "%s_%s_%s", (char *)translate_id(ob_name).c_str(),
(char *)translate_id(bone_name).c_str(), (char *)transform_sid.c_str());
openAnimation(anim_id, COLLADABU::Utils::EMPTY_STRING);
@ -518,7 +518,7 @@ std::string AnimationExporter::get_semantic_suffix(COLLADASW::InputSemantic::Sem
}
void AnimationExporter::add_source_parameters(COLLADASW::SourceBase::ParameterNameList& param,
COLLADASW::InputSemantic::Semantics semantic, bool is_rot, const char *axis, bool transform)
COLLADASW::InputSemantic::Semantics semantic, bool is_rot, const char *axis, bool transform)
{
switch (semantic) {
case COLLADASW::InputSemantic::INPUT:
@ -533,14 +533,14 @@ void AnimationExporter::add_source_parameters(COLLADASW::SourceBase::ParameterNa
param.push_back(axis);
}
else
if ( transform ) {
param.push_back("TRANSFORM");
}
else { //assumes if axis isn't specified all axises are added
param.push_back("X");
param.push_back("Y");
param.push_back("Z");
}
if (transform) {
param.push_back("TRANSFORM");
}
else { //assumes if axis isn't specified all axises are added
param.push_back("X");
param.push_back("Y");
param.push_back("Z");
}
}
break;
case COLLADASW::InputSemantic::IN_TANGENT:
@ -706,7 +706,7 @@ std::string AnimationExporter::create_source_from_vector(COLLADASW::InputSemanti
//if (semantic == COLLADASW::InputSemantic::INPUT)
val = convert_time(val);
/*else if (is_rot)
val = convert_angle(val);*/
val = convert_angle(val);*/
source.appendValues(val);
}
@ -715,7 +715,7 @@ std::string AnimationExporter::create_source_from_vector(COLLADASW::InputSemanti
return source_id;
}
std::string AnimationExporter::create_4x4_source(std::vector<float> &frames, Object * ob_arm, Bone *bone, const std::string& anim_id)
std::string AnimationExporter::create_4x4_source(std::vector<float> &frames, Object *ob_arm, Bone *bone, const std::string& anim_id)
{
COLLADASW::InputSemantic::Semantics semantic = COLLADASW::InputSemantic::OUTPUT;
std::string source_id = anim_id + get_semantic_suffix(semantic);
@ -843,11 +843,11 @@ std::string AnimationExporter::create_interpolation_source(FCurve *fcu, const st
*has_tangents = false;
for (unsigned int i = 0; i < fcu->totvert; i++) {
if (fcu->bezt[i].ipo==BEZT_IPO_BEZ) {
if (fcu->bezt[i].ipo == BEZT_IPO_BEZ) {
source.appendValues(BEZIER_NAME);
*has_tangents = true;
}
else if (fcu->bezt[i].ipo==BEZT_IPO_CONST) {
else if (fcu->bezt[i].ipo == BEZT_IPO_CONST) {
source.appendValues(STEP_NAME);
}
else { // BEZT_IPO_LIN
@ -987,7 +987,7 @@ std::string AnimationExporter::get_camera_param_sid(char *rna_path, int tm_type,
std::string AnimationExporter::get_transform_sid(char *rna_path, int tm_type, const char *axis_name, bool append_axis)
{
std::string tm_name;
bool is_rotation =false;
bool is_rotation = false;
// when given rna_path, determine tm_type from it
if (rna_path) {
char *name = extract_transform_name(rna_path);
@ -1052,16 +1052,16 @@ std::string AnimationExporter::get_transform_sid(char *rna_path, int tm_type, co
if (is_rotation)
return tm_name + std::string(axis_name) + ".ANGLE";
else
if (axis_name[0])
return tm_name + "." + std::string(axis_name);
else
return tm_name;
if (axis_name[0])
return tm_name + "." + std::string(axis_name);
else
return tm_name;
}
return std::string("");
}
char* AnimationExporter::extract_transform_name(char *rna_path)
char *AnimationExporter::extract_transform_name(char *rna_path)
{
char *dot = strrchr(rna_path, '.');
return dot ? (dot + 1) : rna_path;
@ -1070,7 +1070,7 @@ char* AnimationExporter::extract_transform_name(char *rna_path)
//find keyframes of all the objects animations
void AnimationExporter::find_frames(Object *ob, std::vector<float> &fra)
{
FCurve *fcu= (FCurve*)ob->adt->action->curves.first;
FCurve *fcu = (FCurve *)ob->adt->action->curves.first;
for (; fcu; fcu = fcu->next) {
@ -1097,7 +1097,7 @@ void AnimationExporter::enable_fcurves(bAction *act, char *bone_name)
if (bone_name)
BLI_snprintf(prefix, sizeof(prefix), "pose.bones[\"%s\"]", bone_name);
for (fcu = (FCurve*)act->curves.first; fcu; fcu = fcu->next) {
for (fcu = (FCurve *)act->curves.first; fcu; fcu = fcu->next) {
if (bone_name) {
if (!strncmp(fcu->rna_path, prefix, strlen(prefix)))
fcu->flag &= ~FCURVE_DISABLED;
@ -1110,9 +1110,10 @@ void AnimationExporter::enable_fcurves(bAction *act, char *bone_name)
}
}
/* TODO - only check NodeLink objects that are exported */
bool AnimationExporter::hasAnimations(Scene *sce)
{
Base *base= (Base*) sce->base.first;
Base *base = (Base *) sce->base.first;
while (base) {
Object *ob = base->object;
@ -1120,26 +1121,26 @@ bool AnimationExporter::hasAnimations(Scene *sce)
FCurve *fcu = 0;
//Check for object transform animations
if (ob->adt && ob->adt->action)
fcu = (FCurve*)ob->adt->action->curves.first;
fcu = (FCurve *)ob->adt->action->curves.first;
//Check for Lamp parameter animations
else if ( (ob->type == OB_LAMP ) && ((Lamp*)ob ->data)->adt && ((Lamp*)ob ->data)->adt->action )
fcu = (FCurve*)(((Lamp*)ob ->data)->adt->action->curves.first);
else if ( (ob->type == OB_LAMP) && ((Lamp *)ob->data)->adt && ((Lamp *)ob->data)->adt->action)
fcu = (FCurve *)(((Lamp *)ob->data)->adt->action->curves.first);
//Check for Camera parameter animations
else if ( (ob->type == OB_CAMERA ) && ((Camera*)ob ->data)->adt && ((Camera*)ob ->data)->adt->action )
fcu = (FCurve*)(((Camera*)ob ->data)->adt->action->curves.first);
else if ( (ob->type == OB_CAMERA) && ((Camera *)ob->data)->adt && ((Camera *)ob->data)->adt->action)
fcu = (FCurve *)(((Camera *)ob->data)->adt->action->curves.first);
//Check Material Effect parameter animations.
for (int a = 0; a < ob->totcol; a++) {
Material *ma = give_current_material(ob, a+1);
Material *ma = give_current_material(ob, a + 1);
if (!ma) continue;
if (ma->adt && ma->adt->action) {
fcu = (FCurve*)ma->adt->action->curves.first;
fcu = (FCurve *)ma->adt->action->curves.first;
}
}
if ( fcu)
if (fcu)
return true;
base= base->next;
base = base->next;
}
return false;
}
@ -1152,12 +1153,12 @@ void AnimationExporter::find_rotation_frames(Object *ob, std::vector<float> &fra
else if (rotmode == ROT_MODE_QUAT)
find_frames(ob, fra, prefix, "rotation_quaternion");
/*else if (rotmode == ROT_MODE_AXISANGLE)
;*/
;*/
}
void AnimationExporter::find_frames(Object *ob, std::vector<float> &fra, const char *prefix, const char *tm_name)
{
FCurve *fcu= (FCurve*)ob->adt->action->curves.first;
FCurve *fcu = (FCurve *)ob->adt->action->curves.first;
for (; fcu; fcu = fcu->next) {
if (prefix && strncmp(prefix, fcu->rna_path, strlen(prefix)))
@ -1189,13 +1190,13 @@ void AnimationExporter::write_bone_animation(Object *ob_arm, Bone *bone)
for (int i = 0; i < 3; i++)
sample_and_write_bone_animation(ob_arm, bone, i);
for (Bone *child = (Bone*)bone->childbase.first; child; child = child->next)
for (Bone *child = (Bone *)bone->childbase.first; child; child = child->next)
write_bone_animation(ob_arm, child);
}
void AnimationExporter::sample_and_write_bone_animation(Object *ob_arm, Bone *bone, int transform_type)
{
bArmature *arm = (bArmature*)ob_arm->data;
bArmature *arm = (bArmature *)ob_arm->data;
int flag = arm->flag;
std::vector<float> fra;
char prefix[256];
@ -1227,12 +1228,12 @@ void AnimationExporter::sample_and_write_bone_animation(Object *ob_arm, Bone *bo
}
//v array will hold all values which will be exported.
if (fra.size()) {
float *values = (float*)MEM_callocN(sizeof(float) * 3 * fra.size(), "temp. anim frames");
float *values = (float *)MEM_callocN(sizeof(float) * 3 * fra.size(), "temp. anim frames");
sample_animation(values, fra, transform_type, bone, ob_arm, pchan);
if (transform_type == 0) {
// write x, y, z curves separately if it is rotation
float *axisValues = (float*)MEM_callocN(sizeof(float) * fra.size(), "temp. anim frames");
float *axisValues = (float *)MEM_callocN(sizeof(float) * fra.size(), "temp. anim frames");
for (int i = 0; i < 3; i++) {
for (unsigned int j = 0; j < fra.size(); j++)

File diff suppressed because it is too large Load Diff

@ -58,16 +58,17 @@ extern "C" {
// XXX exporter writes wrong data for shared armatures. A separate
// controller should be written for each armature-mesh binding how do
// we make controller ids then?
ArmatureExporter::ArmatureExporter(COLLADASW::StreamWriter *sw, const ExportSettings *export_settings) : COLLADASW::LibraryControllers(sw), export_settings(export_settings) {}
ArmatureExporter::ArmatureExporter(COLLADASW::StreamWriter *sw, const ExportSettings *export_settings) : COLLADASW::LibraryControllers(sw), export_settings(export_settings) {
}
// write bone nodes
void ArmatureExporter::add_armature_bones(Object *ob_arm, Scene* sce,
SceneExporter* se,
std::list<Object*>& child_objects)
void ArmatureExporter::add_armature_bones(Object *ob_arm, Scene *sce,
SceneExporter *se,
std::list<Object *>& child_objects)
{
// write bone nodes
bArmature *arm = (bArmature*)ob_arm->data;
for (Bone *bone = (Bone*)arm->bonebase.first; bone; bone = bone->next) {
bArmature *arm = (bArmature *)ob_arm->data;
for (Bone *bone = (Bone *)arm->bonebase.first; bone; bone = bone->next) {
// start from root bones
if (!bone->parent)
add_bone_node(bone, ob_arm, sce, se, child_objects);
@ -82,7 +83,7 @@ bool ArmatureExporter::is_skinned_mesh(Object *ob)
bool ArmatureExporter::add_instance_controller(Object *ob)
{
Object *ob_arm = bc_get_assigned_armature(ob);
bArmature *arm = (bArmature*)ob_arm->data;
bArmature *arm = (bArmature *)ob_arm->data;
const std::string& controller_id = get_controller_id(ob_arm, ob);
@ -94,7 +95,7 @@ bool ArmatureExporter::add_instance_controller(Object *ob)
// write root bone URLs
Bone *bone;
for (bone = (Bone*)arm->bonebase.first; bone; bone = bone->next) {
for (bone = (Bone *)arm->bonebase.first; bone; bone = bone->next) {
if (!bone->parent)
ins.addSkeleton(COLLADABU::URI(COLLADABU::Utils::EMPTY_STRING, get_joint_id(bone, ob_arm)));
}
@ -140,7 +141,7 @@ void ArmatureExporter::find_objects_using_armature(Object *ob_arm, std::vector<O
{
objects.clear();
Base *base= (Base*) sce->base.first;
Base *base = (Base *) sce->base.first;
while (base) {
Object *ob = base->object;
@ -148,7 +149,7 @@ void ArmatureExporter::find_objects_using_armature(Object *ob_arm, std::vector<O
objects.push_back(ob);
}
base= base->next;
base = base->next;
}
}
#endif
@ -159,9 +160,9 @@ std::string ArmatureExporter::get_joint_sid(Bone *bone, Object *ob_arm)
}
// parent_mat is armature-space
void ArmatureExporter::add_bone_node(Bone *bone, Object *ob_arm, Scene* sce,
SceneExporter* se,
std::list<Object*>& child_objects)
void ArmatureExporter::add_bone_node(Bone *bone, Object *ob_arm, Scene *sce,
SceneExporter *se,
std::list<Object *>& child_objects)
{
std::string node_id = get_joint_id(bone, ob_arm);
std::string node_name = std::string(bone->name);
@ -175,14 +176,14 @@ void ArmatureExporter::add_bone_node(Bone *bone, Object *ob_arm, Scene* sce,
node.setNodeSid(node_sid);
/*if ( bone->childbase.first == NULL || BLI_countlist(&(bone->childbase))>=2)
add_blender_leaf_bone( bone, ob_arm , node );
else{*/
add_blender_leaf_bone( bone, ob_arm , node );
else{*/
node.start();
add_bone_transform(ob_arm, bone, node);
// Write nodes of childobjects, remove written objects from list
std::list<Object*>::iterator i = child_objects.begin();
std::list<Object *>::iterator i = child_objects.begin();
while (i != child_objects.end()) {
if ((*i)->partype == PARBONE && (0 == strcmp((*i)->parsubstr, bone->name))) {
@ -219,29 +220,32 @@ void ArmatureExporter::add_bone_node(Bone *bone, Object *ob_arm, Scene* sce,
else i++;
}
for (Bone *child = (Bone*)bone->childbase.first; child; child = child->next) {
for (Bone *child = (Bone *)bone->childbase.first; child; child = child->next) {
add_bone_node(child, ob_arm, sce, se, child_objects);
}
node.end();
//}
}
/*void ArmatureExporter::add_blender_leaf_bone(Bone *bone, Object *ob_arm, COLLADASW::Node& node)
#if 0
void ArmatureExporter::add_blender_leaf_bone(Bone *bone, Object *ob_arm, COLLADASW::Node& node)
{
node.start();
add_bone_transform(ob_arm, bone, node);
node.addExtraTechniqueParameter("blender", "tip_x", bone->tail[0] );
node.addExtraTechniqueParameter("blender", "tip_y", bone->tail[1] );
node.addExtraTechniqueParameter("blender", "tip_z", bone->tail[2] );
node.addExtraTechniqueParameter("blender", "tip_x", bone->tail[0]);
node.addExtraTechniqueParameter("blender", "tip_y", bone->tail[1]);
node.addExtraTechniqueParameter("blender", "tip_z", bone->tail[2]);
for (Bone *child = (Bone*)bone->childbase.first; child; child = child->next) {
for (Bone *child = (Bone *)bone->childbase.first; child; child = child->next) {
add_bone_node(child, ob_arm, sce, se, child_objects);
}
node.end();
}*/
}
#endif
void ArmatureExporter::add_bone_transform(Object *ob_arm, Bone *bone, COLLADASW::Node& node)
{
bPoseChannel *pchan = BKE_pose_channel_find_name(ob_arm->pose, bone->name);
@ -292,7 +296,7 @@ std::string ArmatureExporter::get_controller_id(Object *ob_arm, Object *ob)
// ob should be of type OB_MESH
// both args are required
void ArmatureExporter::export_controller(Object* ob, Object *ob_arm)
void ArmatureExporter::export_controller(Object *ob, Object *ob_arm)
{
// joint names
// joint inverse bind matrices
@ -302,29 +306,29 @@ void ArmatureExporter::export_controller(Object* ob, Object *ob_arm)
// joint names: ob -> vertex group names
// vertex group weights: me->dvert -> groups -> index, weight
/*
me->dvert:
#if 0
me->dvert :
typedef struct MDeformVert {
struct MDeformWeight *dw;
int totweight;
int flag; // flag only in use for weightpaint now
int flag; // flag only in use for weightpaint now
} MDeformVert;
typedef struct MDeformWeight {
int def_nr;
float weight;
int def_nr;
float weight;
} MDeformWeight;
*/
#endif
bool use_instantiation = this->export_settings->use_object_instantiation;
Mesh *me;
if ( this->export_settings->apply_modifiers ) {
if (this->export_settings->apply_modifiers) {
me = bc_to_mesh_apply_modifiers(scene, ob);
}
else {
me = (Mesh*)ob->data;
me = (Mesh *)ob->data;
}
BKE_mesh_tessface_ensure(me);
@ -352,7 +356,7 @@ void ArmatureExporter::export_controller(Object* ob, Object *ob_arm)
std::vector<int> joint_index_by_def_index;
bDeformGroup *def;
for (def = (bDeformGroup*)ob->defbase.first, i = 0, j = 0; def; def = def->next, i++) {
for (def = (bDeformGroup *)ob->defbase.first, i = 0, j = 0; def; def = def->next, i++) {
if (is_bone_defgroup(ob_arm, def))
joint_index_by_def_index.push_back(j++);
else
@ -375,18 +379,20 @@ void ArmatureExporter::export_controller(Object* ob, Object *ob_arm)
}
if (sumw > 0.0f) {
float invsumw = 1.0f/sumw;
float invsumw = 1.0f / sumw;
vcounts.push_back(jw.size());
for (std::map<int, float>::iterator m = jw.begin(); m != jw.end(); ++m) {
joints.push_back((*m).first);
weights.push_back(invsumw*(*m).second);
weights.push_back(invsumw * (*m).second);
}
}
else {
vcounts.push_back(0);
/*vcounts.push_back(1);
#if 0
vcounts.push_back(1);
joints.push_back(-1);
weights.push_back(1.0f);*/
weights.push_back(1.0f);
#endif
}
}
}
@ -404,15 +410,15 @@ void ArmatureExporter::export_controller(Object* ob, Object *ob_arm)
}
void ArmatureExporter::add_joints_element(ListBase *defbase,
const std::string& joints_source_id, const std::string& inv_bind_mat_source_id)
const std::string& joints_source_id, const std::string& inv_bind_mat_source_id)
{
COLLADASW::JointsElement joints(mSW);
COLLADASW::InputList &input = joints.getInputList();
input.push_back(COLLADASW::Input(COLLADASW::InputSemantic::JOINT, // constant declared in COLLADASWInputList.h
COLLADASW::URI(COLLADABU::Utils::EMPTY_STRING, joints_source_id)));
COLLADASW::URI(COLLADABU::Utils::EMPTY_STRING, joints_source_id)));
input.push_back(COLLADASW::Input(COLLADASW::InputSemantic::BINDMATRIX,
COLLADASW::URI(COLLADABU::Utils::EMPTY_STRING, inv_bind_mat_source_id)));
COLLADASW::URI(COLLADABU::Utils::EMPTY_STRING, inv_bind_mat_source_id)));
joints.add();
}
@ -431,7 +437,7 @@ std::string ArmatureExporter::add_joints_source(Object *ob_arm, ListBase *defbas
int totjoint = 0;
bDeformGroup *def;
for (def = (bDeformGroup*)defbase->first; def; def = def->next) {
for (def = (bDeformGroup *)defbase->first; def; def = def->next) {
if (is_bone_defgroup(ob_arm, def))
totjoint++;
}
@ -447,7 +453,7 @@ std::string ArmatureExporter::add_joints_source(Object *ob_arm, ListBase *defbas
source.prepareToAppendValues();
for (def = (bDeformGroup*)defbase->first; def; def = def->next) {
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));
@ -463,7 +469,7 @@ std::string ArmatureExporter::add_inv_bind_mats_source(Object *ob_arm, ListBase
std::string source_id = controller_id + BIND_POSES_SOURCE_ID_SUFFIX;
int totjoint = 0;
for (bDeformGroup *def = (bDeformGroup*)defbase->first; def; def = def->next) {
for (bDeformGroup *def = (bDeformGroup *)defbase->first; def; def = def->next) {
if (is_bone_defgroup(ob_arm, def))
totjoint++;
}
@ -481,7 +487,7 @@ std::string ArmatureExporter::add_inv_bind_mats_source(Object *ob_arm, ListBase
source.prepareToAppendValues();
bPose *pose = ob_arm->pose;
bArmature *arm = (bArmature*)ob_arm->data;
bArmature *arm = (bArmature *)ob_arm->data;
int flag = arm->flag;
@ -491,7 +497,7 @@ std::string ArmatureExporter::add_inv_bind_mats_source(Object *ob_arm, ListBase
BKE_pose_where_is(scene, ob_arm);
}
for (bDeformGroup *def = (bDeformGroup*)defbase->first; def; def = def->next) {
for (bDeformGroup *def = (bDeformGroup *)defbase->first; def; def = def->next) {
if (is_bone_defgroup(ob_arm, def)) {
bPoseChannel *pchan = BKE_pose_channel_find_name(pose, def->name);
@ -530,13 +536,13 @@ std::string ArmatureExporter::add_inv_bind_mats_source(Object *ob_arm, ListBase
return source_id;
}
Bone *ArmatureExporter::get_bone_from_defgroup(Object *ob_arm, bDeformGroup* def)
Bone *ArmatureExporter::get_bone_from_defgroup(Object *ob_arm, bDeformGroup *def)
{
bPoseChannel *pchan = BKE_pose_channel_find_name(ob_arm->pose, def->name);
return pchan ? pchan->bone : NULL;
}
bool ArmatureExporter::is_bone_defgroup(Object *ob_arm, bDeformGroup* def)
bool ArmatureExporter::is_bone_defgroup(Object *ob_arm, bDeformGroup *def)
{
return get_bone_from_defgroup(ob_arm, def) != NULL;
}
@ -566,17 +572,17 @@ std::string ArmatureExporter::add_weights_source(Mesh *me, const std::string& co
}
void ArmatureExporter::add_vertex_weights_element(const std::string& weights_source_id, const std::string& joints_source_id,
const std::list<int>& vcounts,
const std::list<int>& joints)
const std::list<int>& vcounts,
const std::list<int>& joints)
{
COLLADASW::VertexWeightsElement weightselem(mSW);
COLLADASW::InputList &input = weightselem.getInputList();
int offset = 0;
input.push_back(COLLADASW::Input(COLLADASW::InputSemantic::JOINT, // constant declared in COLLADASWInputList.h
COLLADASW::URI(COLLADABU::Utils::EMPTY_STRING, joints_source_id), offset++));
COLLADASW::URI(COLLADABU::Utils::EMPTY_STRING, joints_source_id), offset++));
input.push_back(COLLADASW::Input(COLLADASW::InputSemantic::WEIGHT,
COLLADASW::URI(COLLADABU::Utils::EMPTY_STRING, weights_source_id), offset++));
COLLADASW::URI(COLLADABU::Utils::EMPTY_STRING, weights_source_id), offset++));
weightselem.setCount(vcounts.size());

@ -50,7 +50,8 @@ static const char *bc_get_joint_name(T *node)
}
ArmatureImporter::ArmatureImporter(UnitConverter *conv, MeshImporterBase *mesh, AnimationImporterBase *anim, Scene *sce) :
TransformReader(conv), scene(sce), empty(NULL), mesh_importer(mesh), anim_importer(anim) {}
TransformReader(conv), scene(sce), empty(NULL), mesh_importer(mesh), anim_importer(anim) {
}
ArmatureImporter::~ArmatureImporter()
{
@ -68,7 +69,7 @@ JointData *ArmatureImporter::get_joint_data(COLLADAFW::Node *node);
if (joint_id_to_joint_index_map.find(joint_id) == joint_id_to_joint_index_map.end()) {
fprintf(stderr, "Cannot find a joint index by joint id for %s.\n",
node->getOriginalId().c_str());
node->getOriginalId().c_str());
return NULL;
}
@ -77,12 +78,12 @@ JointData *ArmatureImporter::get_joint_data(COLLADAFW::Node *node);
return &joint_index_to_joint_info_map[joint_index];
}
#endif
void ArmatureImporter::create_unskinned_bone( COLLADAFW::Node *node, EditBone *parent, int totchild,
float parent_mat[][4], Object * ob_arm)
void ArmatureImporter::create_unskinned_bone(COLLADAFW::Node *node, EditBone *parent, int totchild,
float parent_mat[][4], Object *ob_arm)
{
std::vector<COLLADAFW::Node*>::iterator it;
std::vector<COLLADAFW::Node *>::iterator it;
it = std::find(finished_joints.begin(), finished_joints.end(), node);
if ( it != finished_joints.end()) return;
if (it != finished_joints.end()) return;
float mat[4][4];
float obmat[4][4];
@ -90,7 +91,7 @@ void ArmatureImporter::create_unskinned_bone( COLLADAFW::Node *node, EditBone *p
// object-space
get_node_mat(obmat, node, NULL, NULL);
EditBone *bone = ED_armature_edit_bone_add((bArmature*)ob_arm->data, (char*)bc_get_joint_name(node));
EditBone *bone = ED_armature_edit_bone_add((bArmature *)ob_arm->data, (char *)bc_get_joint_name(node));
totbone++;
if (parent) bone->parent = parent;
@ -107,9 +108,9 @@ void ArmatureImporter::create_unskinned_bone( COLLADAFW::Node *node, EditBone *p
}
float loc[3], size[3], rot[3][3];
mat4_to_loc_rot_size( loc, rot, size, obmat);
mat3_to_vec_roll(rot, NULL, &angle );
bone->roll=angle;
mat4_to_loc_rot_size(loc, rot, size, obmat);
mat3_to_vec_roll(rot, NULL, &angle);
bone->roll = angle;
// set head
copy_v3_v3(bone->head, mat[3]);
@ -142,7 +143,7 @@ void ArmatureImporter::create_unskinned_bone( COLLADAFW::Node *node, EditBone *p
COLLADAFW::NodePointerArray& children = node->getChildNodes();
for (unsigned int i = 0; i < children.getCount(); i++) {
create_unskinned_bone( children[i], bone, children.getCount(), mat, ob_arm);
create_unskinned_bone(children[i], bone, children.getCount(), mat, ob_arm);
}
// in second case it's not a leaf bone, but we handle it the same way
@ -155,12 +156,12 @@ void ArmatureImporter::create_unskinned_bone( COLLADAFW::Node *node, EditBone *p
}
void ArmatureImporter::create_bone(SkinInfo& skin, COLLADAFW::Node *node, EditBone *parent, int totchild,
float parent_mat[][4], bArmature *arm)
float parent_mat[][4], bArmature *arm)
{
//Checking if bone is already made.
std::vector<COLLADAFW::Node*>::iterator it;
std::vector<COLLADAFW::Node *>::iterator it;
it = std::find(finished_joints.begin(), finished_joints.end(), node);
if ( it != finished_joints.end()) return;
if (it != finished_joints.end()) return;
float joint_inv_bind_mat[4][4];
@ -169,7 +170,7 @@ void ArmatureImporter::create_bone(SkinInfo& skin, COLLADAFW::Node *node, EditBo
float mat[4][4];
// TODO rename from Node "name" attrs later
EditBone *bone = ED_armature_edit_bone_add(arm, (char*)bc_get_joint_name(node));
EditBone *bone = ED_armature_edit_bone_add(arm, (char *)bc_get_joint_name(node));
totbone++;
if (skin.get_joint_inv_bind_matrix(joint_inv_bind_mat, node)) {
@ -190,9 +191,9 @@ void ArmatureImporter::create_bone(SkinInfo& skin, COLLADAFW::Node *node, EditBo
copy_m4_m4(mat, obmat);
float loc[3], size[3], rot[3][3], angle;
mat4_to_loc_rot_size( loc, rot, size, obmat);
mat3_to_vec_roll(rot, NULL, &angle );
bone->roll=angle;
mat4_to_loc_rot_size(loc, rot, size, obmat);
mat3_to_vec_roll(rot, NULL, &angle);
bone->roll = angle;
}
@ -267,7 +268,7 @@ void ArmatureImporter::create_bone(SkinInfo& skin, COLLADAFW::Node *node, EditBo
finished_joints.push_back(node);
}
void ArmatureImporter::add_leaf_bone(float mat[][4], EditBone *bone, COLLADAFW::Node * node)
void ArmatureImporter::add_leaf_bone(float mat[][4], EditBone *bone, COLLADAFW::Node *node)
{
LeafBone leaf;
@ -337,7 +338,7 @@ void ArmatureImporter::set_euler_rotmode()
{
// just set rotmode = ROT_MODE_EUL on pose channel for each joint
std::map<COLLADAFW::UniqueId, COLLADAFW::Node*>::iterator it;
std::map<COLLADAFW::UniqueId, COLLADAFW::Node *>::iterator it;
for (it = joint_by_uid.begin(); it != joint_by_uid.end(); it++) {
@ -378,7 +379,7 @@ Object *ArmatureImporter::get_empty_for_leaves()
#if 0
Object *ArmatureImporter::find_armature(COLLADAFW::Node *node)
{
JointData* jd = get_joint_data(node);
JointData *jd = get_joint_data(node);
if (jd) return jd->ob_arm;
COLLADAFW::NodePointerArray& children = node->getChildNodes();
@ -408,10 +409,10 @@ ArmatureJoints& ArmatureImporter::get_armature_joints(Object *ob_arm)
#endif
void ArmatureImporter::create_armature_bones( )
{
std::vector<COLLADAFW::Node*>::iterator ri;
std::vector<COLLADAFW::Node *>::iterator ri;
//if there is an armature created for root_joint next root_joint
for (ri = root_joints.begin(); ri != root_joints.end(); ri++) {
if ( get_armature_for_joint(*ri) != NULL ) continue;
if (get_armature_for_joint(*ri) != NULL) continue;
//add armature object for current joint
//Object *ob_arm = bc_add_object(scene, OB_ARMATURE, NULL);
@ -428,9 +429,9 @@ void ArmatureImporter::create_armature_bones( )
// create unskinned bones
/*
TODO:
check if bones have already been created for a given joint
*/
* TODO:
* check if bones have already been created for a given joint
*/
leaf_bone_length = FLT_MAX;
create_unskinned_bone(*ri, NULL, (*ri)->getChildNodes().getCount(), NULL, ob_arm);
@ -442,10 +443,10 @@ void ArmatureImporter::create_armature_bones( )
ED_armature_from_edit(ob_arm);
set_pose(ob_arm, *ri, NULL, NULL );
set_pose(ob_arm, *ri, NULL, NULL);
ED_armature_edit_free(ob_arm);
DAG_id_tag_update(&ob_arm->id, OB_RECALC_OB|OB_RECALC_DATA);
DAG_id_tag_update(&ob_arm->id, OB_RECALC_OB | OB_RECALC_DATA);
}
@ -496,7 +497,7 @@ void ArmatureImporter::create_armature_bones(SkinInfo& skin)
SkinInfo *a = &skin;
Object *shared = NULL;
std::vector<COLLADAFW::Node*> skin_root_joints;
std::vector<COLLADAFW::Node *> skin_root_joints;
std::map<COLLADAFW::UniqueId, SkinInfo>::iterator it;
for (it = skin_by_data_uid.begin(); it != skin_by_data_uid.end(); it++) {
@ -508,7 +509,7 @@ void ArmatureImporter::create_armature_bones(SkinInfo& skin)
b->find_root_joints(root_joints, joint_by_uid, skin_root_joints);
std::vector<COLLADAFW::Node*>::iterator ri;
std::vector<COLLADAFW::Node *>::iterator ri;
for (ri = skin_root_joints.begin(); ri != skin_root_joints.end(); ri++) {
if (a->uses_joint_or_descendant(*ri)) {
shared = b->BKE_armature_from_object();
@ -523,7 +524,7 @@ void ArmatureImporter::create_armature_bones(SkinInfo& skin)
if (shared)
ob_arm = skin.set_armature(shared);
else
ob_arm = skin.create_armature(scene); //once for every armature
ob_arm = skin.create_armature(scene); //once for every armature
// enter armature edit mode
ED_armature_to_edit(ob_arm);
@ -538,9 +539,9 @@ void ArmatureImporter::create_armature_bones(SkinInfo& skin)
/*
TODO:
check if bones have already been created for a given joint
*/
*/
std::vector<COLLADAFW::Node*>::iterator ri;
std::vector<COLLADAFW::Node *>::iterator ri;
for (ri = root_joints.begin(); ri != root_joints.end(); ri++) {
// for shared armature check if bone tree is already created
if (shared && std::find(skin_root_joints.begin(), skin_root_joints.end(), *ri) != skin_root_joints.end())
@ -548,7 +549,7 @@ void ArmatureImporter::create_armature_bones(SkinInfo& skin)
// since root_joints may contain joints for multiple controllers, we need to filter
if (skin.uses_joint_or_descendant(*ri)) {
create_bone(skin, *ri, NULL, (*ri)->getChildNodes().getCount(), NULL, (bArmature*)ob_arm->data);
create_bone(skin, *ri, NULL, (*ri)->getChildNodes().getCount(), NULL, (bArmature *)ob_arm->data);
if (joint_parent_map.find((*ri)->getUniqueId()) != joint_parent_map.end() && !skin.get_parent())
skin.set_parent(joint_parent_map[(*ri)->getUniqueId()]);
@ -560,7 +561,7 @@ void ArmatureImporter::create_armature_bones(SkinInfo& skin)
// exit armature edit mode
ED_armature_from_edit(ob_arm);
ED_armature_edit_free(ob_arm);
DAG_id_tag_update(&ob_arm->id, OB_RECALC_OB|OB_RECALC_DATA);
DAG_id_tag_update(&ob_arm->id, OB_RECALC_OB | OB_RECALC_DATA);
// set_leaf_bone_shapes(ob_arm);
// set_euler_rotmode();
@ -571,9 +572,9 @@ void ArmatureImporter::create_armature_bones(SkinInfo& skin)
// is a child of a node (not joint), root should be true since
// this is where we build armature bones from
void ArmatureImporter::set_pose(Object * ob_arm, COLLADAFW::Node * root_node, const char *parentname, float parent_mat[][4])
void ArmatureImporter::set_pose(Object *ob_arm, COLLADAFW::Node *root_node, const char *parentname, float parent_mat[][4])
{
char * bone_name = (char *) bc_get_joint_name ( root_node);
char *bone_name = (char *) bc_get_joint_name(root_node);
float mat[4][4];
float obmat[4][4];
@ -584,7 +585,7 @@ void ArmatureImporter::set_pose(Object * ob_arm, COLLADAFW::Node * root_node, c
get_node_mat(obmat, root_node, NULL, NULL);
//if (*edbone)
bPoseChannel * pchan = BKE_pose_channel_find_name(ob_arm -> pose, bone_name);
bPoseChannel *pchan = BKE_pose_channel_find_name(ob_arm->pose, bone_name);
//else fprintf ( "",
// get world-space
@ -592,7 +593,7 @@ void ArmatureImporter::set_pose(Object * ob_arm, COLLADAFW::Node * root_node, c
mult_m4_m4m4(mat, parent_mat, obmat);
bPoseChannel *parchan = BKE_pose_channel_find_name(ob_arm->pose, parentname);
mult_m4_m4m4(pchan->pose_mat, parchan->pose_mat, mat );
mult_m4_m4m4(pchan->pose_mat, parchan->pose_mat, mat);
}
else {
@ -631,7 +632,7 @@ void ArmatureImporter::add_root_joint(COLLADAFW::Node *node)
{
// root_joints.push_back(node);
Object *ob_arm = find_armature(node);
if (ob_arm) {
if (ob_arm) {
get_armature_joints(ob_arm).root_joints.push_back(node);
}
#ifdef COLLADA_DEBUG
@ -694,7 +695,7 @@ void ArmatureImporter::link_armature(Object *ob_arm, const COLLADAFW::UniqueId&
}
#endif
bool ArmatureImporter::write_skin_controller_data(const COLLADAFW::SkinControllerData* data)
bool ArmatureImporter::write_skin_controller_data(const COLLADAFW::SkinControllerData *data)
{
// at this stage we get vertex influence info that should go into me->verts and ob->defbase
// there's no info to which object this should be long so we associate it with skin controller data UID
@ -719,14 +720,14 @@ bool ArmatureImporter::write_skin_controller_data(const COLLADAFW::SkinControlle
return true;
}
bool ArmatureImporter::write_controller(const COLLADAFW::Controller* controller)
bool ArmatureImporter::write_controller(const COLLADAFW::Controller *controller)
{
// - create and store armature object
const COLLADAFW::UniqueId& skin_id = controller->getUniqueId();
if (controller->getControllerType() == COLLADAFW::Controller::CONTROLLER_TYPE_SKIN) {
COLLADAFW::SkinController *co = (COLLADAFW::SkinController*)controller;
COLLADAFW::SkinController *co = (COLLADAFW::SkinController *)controller;
// to be able to find geom id by controller id
geom_uid_by_controller_uid[skin_id] = co->getSource();
@ -766,7 +767,7 @@ Object *ArmatureImporter::get_armature_for_joint(COLLADAFW::Node *node)
return skin.BKE_armature_from_object();
}
std::map<COLLADAFW::UniqueId, Object*>::iterator arm;
std::map<COLLADAFW::UniqueId, Object *>::iterator arm;
for (arm = unskinned_armature_map.begin(); arm != unskinned_armature_map.end(); arm++) {
if (arm->first == node->getUniqueId() )
return arm->second;
@ -799,6 +800,3 @@ bool ArmatureImporter::get_joint_bind_mat(float m[][4], COLLADAFW::Node *joint)
return found;
}

@ -37,13 +37,14 @@ extern "C" {
#include "collada_internal.h"
CamerasExporter::CamerasExporter(COLLADASW::StreamWriter *sw, const ExportSettings *export_settings): COLLADASW::LibraryCameras(sw), export_settings(export_settings) {}
CamerasExporter::CamerasExporter(COLLADASW::StreamWriter *sw, const ExportSettings *export_settings) : COLLADASW::LibraryCameras(sw), export_settings(export_settings) {
}
template<class Functor>
void forEachCameraObjectInExportSet(Scene *sce, Functor &f, LinkNode *export_set)
{
LinkNode *node;
for(node=export_set; node; node = node->next) {
for (node = export_set; node; node = node->next) {
Object *ob = (Object *)node->link;
if (ob->type == OB_CAMERA && ob->data) {
@ -63,32 +64,33 @@ void CamerasExporter::exportCameras(Scene *sce)
void CamerasExporter::operator()(Object *ob, Scene *sce)
{
// TODO: shiftx, shifty, YF_dofdist
Camera *cam = (Camera*)ob->data;
Camera *cam = (Camera *)ob->data;
std::string cam_id(get_camera_id(ob));
std::string cam_name(id_name(cam));
switch (cam->type) {
case CAM_PANO:
case CAM_PERSP: {
COLLADASW::PerspectiveOptic persp(mSW);
persp.setXFov(RAD2DEGF(focallength_to_fov(cam->lens, cam->sensor_x)), "xfov");
persp.setAspectRatio((float)(sce->r.xsch)/(float)(sce->r.ysch), false, "aspect_ratio");
persp.setZFar(cam->clipend, false, "zfar");
persp.setZNear(cam->clipsta, false, "znear");
COLLADASW::Camera ccam(mSW, &persp, cam_id, cam_name);
addCamera(ccam);
break;
case CAM_PANO:
case CAM_PERSP: {
COLLADASW::PerspectiveOptic persp(mSW);
persp.setXFov(RAD2DEGF(focallength_to_fov(cam->lens, cam->sensor_x)), "xfov");
persp.setAspectRatio((float)(sce->r.xsch) / (float)(sce->r.ysch), false, "aspect_ratio");
persp.setZFar(cam->clipend, false, "zfar");
persp.setZNear(cam->clipsta, false, "znear");
COLLADASW::Camera ccam(mSW, &persp, cam_id, cam_name);
addCamera(ccam);
break;
}
case CAM_ORTHO:
default:
{
COLLADASW::OrthographicOptic ortho(mSW);
ortho.setXMag(cam->ortho_scale, "xmag");
ortho.setAspectRatio((float)(sce->r.xsch) / (float)(sce->r.ysch), false, "aspect_ratio");
ortho.setZFar(cam->clipend, false, "zfar");
ortho.setZNear(cam->clipsta, false, "znear");
COLLADASW::Camera ccam(mSW, &ortho, cam_id, cam_name);
addCamera(ccam);
break;
}
}
case CAM_ORTHO:
default:
{
COLLADASW::OrthographicOptic ortho(mSW);
ortho.setXMag(cam->ortho_scale, "xmag");
ortho.setAspectRatio((float)(sce->r.xsch)/(float)(sce->r.ysch), false, "aspect_ratio");
ortho.setZFar(cam->clipend, false, "zfar");
ortho.setZNear(cam->clipsta, false, "znear");
COLLADASW::Camera ccam(mSW, &ortho, cam_id, cam_name);
addCamera(ccam);
break;
}}
}

@ -134,7 +134,7 @@ char *bc_CustomData_get_layer_name(const struct CustomData *data, int type, int
int layer_index = CustomData_get_layer_index(data, type);
if (layer_index < 0) return NULL;
return data->layers[layer_index+n].name;
return data->layers[layer_index + n].name;
}
char *bc_CustomData_get_active_layer_name(const CustomData *data, int type)
@ -146,7 +146,8 @@ char *bc_CustomData_get_active_layer_name(const CustomData *data, int type)
return data->layers[layer_index].name;
}
DocumentExporter::DocumentExporter(const ExportSettings *export_settings) : export_settings(export_settings) {}
DocumentExporter::DocumentExporter(const ExportSettings *export_settings) : export_settings(export_settings) {
}
// TODO: it would be better to instantiate animations rather than create a new one per object
// COLLADA allows this through multiple <channel>s in <animation>.
@ -160,7 +161,7 @@ void DocumentExporter::exportCurrentScene(Scene *sce)
clear_global_id_map();
COLLADABU::NativeString native_filename =
COLLADABU::NativeString(std::string(this->export_settings->filepath));
COLLADABU::NativeString(std::string(this->export_settings->filepath));
COLLADASW::StreamWriter sw(native_filename);
// open <collada>
@ -221,9 +222,9 @@ void DocumentExporter::exportCurrentScene(Scene *sce)
}
char version_buf[128];
#ifdef WITH_BUILDINFO
sprintf(version_buf, "Blender %d.%02d.%d r%s", BLENDER_VERSION/100, BLENDER_VERSION%100, BLENDER_SUBVERSION, build_rev);
sprintf(version_buf, "Blender %d.%02d.%d r%s", BLENDER_VERSION / 100, BLENDER_VERSION % 100, BLENDER_SUBVERSION, build_rev);
#else
sprintf(version_buf, "Blender %d.%02d.%d", BLENDER_VERSION/100, BLENDER_VERSION%100, BLENDER_SUBVERSION);
sprintf(version_buf, "Blender %d.%02d.%d", BLENDER_VERSION / 100, BLENDER_VERSION % 100, BLENDER_SUBVERSION);
#endif
asset.getContributor().mAuthoringTool = version_buf;
asset.add();
@ -276,7 +277,7 @@ void DocumentExporter::exportCurrentScene(Scene *sce)
// <scene>
std::string scene_name(translate_id(id_name(sce)));
COLLADASW::Scene scene(&sw, COLLADASW::URI(COLLADABU::Utils::EMPTY_STRING,
scene_name));
scene_name));
scene.add();
// close <Collada>
@ -284,14 +285,13 @@ void DocumentExporter::exportCurrentScene(Scene *sce)
}
void DocumentExporter::exportScenes(const char* filename)
void DocumentExporter::exportScenes(const char *filename)
{
}
/*
NOTES:
* AnimationExporter::sample_animation enables all curves on armature, this is undesirable for a user
* NOTES:
*
* AnimationExporter::sample_animation enables all curves on armature, this is undesirable for a user
*
*/

@ -88,8 +88,8 @@ extern "C" {
/*
COLLADA Importer limitations:
- no multiple scene import, all objects are added to active scene
COLLADA Importer limitations:
- no multiple scene import, all objects are added to active scene
*/
// #define COLLADA_DEBUG
@ -103,13 +103,14 @@ DocumentImporter::DocumentImporter(bContext *C, const char *filename) :
armature_importer(&unit_converter, &mesh_importer, &anim_importer, CTX_data_scene(C)),
mesh_importer(&unit_converter, &armature_importer, CTX_data_scene(C)),
anim_importer(&unit_converter, &armature_importer, CTX_data_scene(C))
{}
{
}
DocumentImporter::~DocumentImporter()
{
TagsMap::iterator etit;
etit = uid_tags_map.begin();
while (etit!=uid_tags_map.end()) {
while (etit != uid_tags_map.end()) {
delete etit->second;
etit++;
}
@ -171,11 +172,11 @@ void DocumentImporter::start()
void DocumentImporter::finish()
{
if (mImportStage!=General)
if (mImportStage != General)
return;
/** TODO Break up and put into 2-pass parsing of DAE */
std::vector<const COLLADAFW::VisualScene*>::iterator it;
std::vector<const COLLADAFW::VisualScene *>::iterator it;
for (it = vscenes.begin(); it != vscenes.end(); it++) {
PointerRNA sceneptr, unit_settings;
PropertyRNA *system, *scale;
@ -214,7 +215,7 @@ void DocumentImporter::finish()
armature_importer.fix_animation();
#endif
for (std::vector<const COLLADAFW::VisualScene*>::iterator it = vscenes.begin(); it != vscenes.end(); it++) {
for (std::vector<const COLLADAFW::VisualScene *>::iterator it = vscenes.begin(); it != vscenes.end(); it++) {
const COLLADAFW::NodePointerArray& roots = (*it)->getRootNodes();
for (unsigned int i = 0; i < roots.getCount(); i++)
@ -226,7 +227,7 @@ void DocumentImporter::finish()
fprintf(stderr, "got %d library nodes to free\n", (int)libnode_ob.size());
// free all library_nodes
std::vector<Object*>::iterator it;
std::vector<Object *>::iterator it;
for (it = libnode_ob.begin(); it != libnode_ob.end(); it++) {
Object *ob = *it;
@ -234,8 +235,8 @@ void DocumentImporter::finish()
if (base) {
BLI_remlink(&sce->base, base);
BKE_libblock_free_us(&G.main->object, base->object);
if (sce->basact==base)
sce->basact= NULL;
if (sce->basact == base)
sce->basact = NULL;
MEM_freeN(base);
}
}
@ -265,18 +266,20 @@ void DocumentImporter::translate_anim_recursive(COLLADAFW::Node *node, COLLADAFW
root_map[node->getUniqueId()] = root_map[par->getUniqueId()];
}
/*COLLADAFW::Transformation::TransformationType types[] = {
#if 0
COLLADAFW::Transformation::TransformationType types[] = {
COLLADAFW::Transformation::ROTATE,
COLLADAFW::Transformation::SCALE,
COLLADAFW::Transformation::TRANSLATE,
COLLADAFW::Transformation::MATRIX
};
Object *ob;*/
Object *ob;
#endif
unsigned int i;
//for (i = 0; i < 4; i++)
//ob =
// ob =
anim_importer.translate_Animations(node, root_map, object_map, FW_object_map);
COLLADAFW::NodePointerArray &children = node->getChildNodes();
@ -286,8 +289,8 @@ void DocumentImporter::translate_anim_recursive(COLLADAFW::Node *node, COLLADAFW
}
/** When this method is called, the writer must write the global document asset.
\return The writer should return true, if writing succeeded, false otherwise.*/
bool DocumentImporter::writeGlobalAsset ( const COLLADAFW::FileInfo* asset )
* \return The writer should return true, if writing succeeded, false otherwise.*/
bool DocumentImporter::writeGlobalAsset(const COLLADAFW::FileInfo *asset)
{
unit_converter.read_asset(asset);
@ -295,13 +298,13 @@ bool DocumentImporter::writeGlobalAsset ( const COLLADAFW::FileInfo* asset )
}
/** When this method is called, the writer must write the scene.
\return The writer should return true, if writing succeeded, false otherwise.*/
bool DocumentImporter::writeScene ( const COLLADAFW::Scene* scene )
* \return The writer should return true, if writing succeeded, false otherwise.*/
bool DocumentImporter::writeScene(const COLLADAFW::Scene *scene)
{
// XXX could store the scene id, but do nothing for now
return true;
}
Object* DocumentImporter::create_camera_object(COLLADAFW::InstanceCamera *camera, Scene *sce)
Object *DocumentImporter::create_camera_object(COLLADAFW::InstanceCamera *camera, Scene *sce)
{
const COLLADAFW::UniqueId& cam_uid = camera->getInstanciatedObjectId();
if (uid_camera_map.find(cam_uid) == uid_camera_map.end()) {
@ -311,7 +314,7 @@ Object* DocumentImporter::create_camera_object(COLLADAFW::InstanceCamera *camera
Object *ob = bc_add_object(sce, OB_CAMERA, NULL);
Camera *cam = uid_camera_map[cam_uid];
Camera *old_cam = (Camera*)ob->data;
Camera *old_cam = (Camera *)ob->data;
ob->data = cam;
old_cam->id.us--;
if (old_cam->id.us == 0)
@ -319,7 +322,7 @@ Object* DocumentImporter::create_camera_object(COLLADAFW::InstanceCamera *camera
return ob;
}
Object* DocumentImporter::create_lamp_object(COLLADAFW::InstanceLight *lamp, Scene *sce)
Object *DocumentImporter::create_lamp_object(COLLADAFW::InstanceLight *lamp, Scene *sce)
{
const COLLADAFW::UniqueId& lamp_uid = lamp->getInstanciatedObjectId();
if (uid_lamp_map.find(lamp_uid) == uid_lamp_map.end()) {
@ -329,7 +332,7 @@ Object* DocumentImporter::create_lamp_object(COLLADAFW::InstanceLight *lamp, Sce
Object *ob = bc_add_object(sce, OB_LAMP, NULL);
Lamp *la = uid_lamp_map[lamp_uid];
Lamp *old_lamp = (Lamp*)ob->data;
Lamp *old_lamp = (Lamp *)ob->data;
ob->data = la;
old_lamp->id.us--;
if (old_lamp->id.us == 0)
@ -337,12 +340,12 @@ Object* DocumentImporter::create_lamp_object(COLLADAFW::InstanceLight *lamp, Sce
return ob;
}
Object* DocumentImporter::create_instance_node(Object *source_ob, COLLADAFW::Node *source_node, COLLADAFW::Node *instance_node, Scene *sce, bool is_library_node)
Object *DocumentImporter::create_instance_node(Object *source_ob, COLLADAFW::Node *source_node, COLLADAFW::Node *instance_node, Scene *sce, bool is_library_node)
{
fprintf(stderr, "create <instance_node> under node id=%s from node id=%s\n", instance_node ? instance_node->getOriginalId().c_str() : NULL, source_node ? source_node->getOriginalId().c_str() : NULL);
Object *obn = BKE_object_copy(source_ob);
obn->recalc |= OB_RECALC_OB|OB_RECALC_DATA|OB_RECALC_TIME;
obn->recalc |= OB_RECALC_OB | OB_RECALC_DATA | OB_RECALC_TIME;
BKE_scene_base_add(sce, obn);
if (instance_node) {
@ -399,21 +402,21 @@ Object* DocumentImporter::create_instance_node(Object *source_ob, COLLADAFW::Nod
return obn;
}
void DocumentImporter::write_node (COLLADAFW::Node *node, COLLADAFW::Node *parent_node, Scene *sce, Object *par, bool is_library_node)
void DocumentImporter::write_node(COLLADAFW::Node *node, COLLADAFW::Node *parent_node, Scene *sce, Object *par, bool is_library_node)
{
Object *ob = NULL;
bool is_joint = node->getType() == COLLADAFW::Node::JOINT;
bool read_transform = true;
std::vector<Object*> * objects_done = new std::vector<Object *>();
std::vector<Object *> *objects_done = new std::vector<Object *>();
if (is_joint) {
if ( par ) {
Object * empty = par;
par = bc_add_object(sce, OB_ARMATURE, NULL);
bc_set_parent(par, empty->parent, mContext);
//remove empty : todo
object_map.insert(std::make_pair<COLLADAFW::UniqueId, Object *>(parent_node->getUniqueId(), par));
if (par) {
Object *empty = par;
par = bc_add_object(sce, OB_ARMATURE, NULL);
bc_set_parent(par, empty->parent, mContext);
//remove empty : todo
object_map.insert(std::make_pair<COLLADAFW::UniqueId, Object *>(parent_node->getUniqueId(), par));
}
armature_importer.add_joint(node, parent_node == NULL || parent_node->getType() != COLLADAFW::Node::JOINT, par, sce);
}
@ -434,7 +437,7 @@ void DocumentImporter::write_node (COLLADAFW::Node *node, COLLADAFW::Node *paren
// <instance_geometry>
while (geom_done < geom.getCount()) {
ob = mesh_importer.create_mesh_object(node, geom[geom_done], false, uid_material_map,
material_texture_mapping_map);
material_texture_mapping_map);
objects_done->push_back(ob);
++geom_done;
}
@ -449,7 +452,7 @@ void DocumentImporter::write_node (COLLADAFW::Node *node, COLLADAFW::Node *paren
++lamp_done;
}
while (controller_done < controller.getCount()) {
COLLADAFW::InstanceGeometry *geom = (COLLADAFW::InstanceGeometry*)controller[controller_done];
COLLADAFW::InstanceGeometry *geom = (COLLADAFW::InstanceGeometry *)controller[controller_done];
ob = mesh_importer.create_mesh_object(node, geom, true, uid_material_map, material_texture_mapping_map);
objects_done->push_back(ob);
++controller_done;
@ -487,7 +490,7 @@ void DocumentImporter::write_node (COLLADAFW::Node *node, COLLADAFW::Node *paren
for (std::vector<Object *>::iterator it = objects_done->begin(); it != objects_done->end(); ++it) {
ob = *it;
std::string nodename = node->getName().size() ? node->getName() : node->getOriginalId();
rename_id(&ob->id, (char*)nodename.c_str());
rename_id(&ob->id, (char *)nodename.c_str());
object_map.insert(std::make_pair<COLLADAFW::UniqueId, Object *>(node->getUniqueId(), ob));
node_map[node->getUniqueId()] = node;
@ -498,10 +501,10 @@ void DocumentImporter::write_node (COLLADAFW::Node *node, COLLADAFW::Node *paren
}
for (std::vector<Object *>::iterator it = objects_done->begin(); it != objects_done->end(); ++it) {
ob =*it;
ob = *it;
if (read_transform)
anim_importer.read_node_transform(node, ob); // overwrites location set earlier
anim_importer.read_node_transform(node, ob); // overwrites location set earlier
if (!is_joint) {
// if par was given make this object child of the previous
@ -517,10 +520,10 @@ void DocumentImporter::write_node (COLLADAFW::Node *node, COLLADAFW::Node *paren
}
/** When this method is called, the writer must write the entire visual scene.
\return The writer should return true, if writing succeeded, false otherwise.*/
bool DocumentImporter::writeVisualScene ( const COLLADAFW::VisualScene* visualScene )
* \return The writer should return true, if writing succeeded, false otherwise.*/
bool DocumentImporter::writeVisualScene(const COLLADAFW::VisualScene *visualScene)
{
if (mImportStage!=General)
if (mImportStage != General)
return true;
// this method called on post process after writeGeometry, writeMaterial, etc.
@ -539,11 +542,11 @@ bool DocumentImporter::writeVisualScene ( const COLLADAFW::VisualScene* visualSc
}
/** When this method is called, the writer must handle all nodes contained in the
library nodes.
\return The writer should return true, if writing succeeded, false otherwise.*/
bool DocumentImporter::writeLibraryNodes ( const COLLADAFW::LibraryNodes* libraryNodes )
* library nodes.
* \return The writer should return true, if writing succeeded, false otherwise.*/
bool DocumentImporter::writeLibraryNodes(const COLLADAFW::LibraryNodes *libraryNodes)
{
if (mImportStage!=General)
if (mImportStage != General)
return true;
Scene *sce = CTX_data_scene(mContext);
@ -558,24 +561,24 @@ bool DocumentImporter::writeLibraryNodes ( const COLLADAFW::LibraryNodes* librar
}
/** When this method is called, the writer must write the geometry.
\return The writer should return true, if writing succeeded, false otherwise.*/
bool DocumentImporter::writeGeometry ( const COLLADAFW::Geometry* geom )
* \return The writer should return true, if writing succeeded, false otherwise.*/
bool DocumentImporter::writeGeometry(const COLLADAFW::Geometry *geom)
{
if (mImportStage!=General)
if (mImportStage != General)
return true;
return mesh_importer.write_geometry(geom);
}
/** When this method is called, the writer must write the material.
\return The writer should return true, if writing succeeded, false otherwise.*/
bool DocumentImporter::writeMaterial( const COLLADAFW::Material* cmat )
* \return The writer should return true, if writing succeeded, false otherwise.*/
bool DocumentImporter::writeMaterial(const COLLADAFW::Material *cmat)
{
if (mImportStage!=General)
if (mImportStage != General)
return true;
const std::string& str_mat_id = cmat->getName().size() ? cmat->getName() : cmat->getOriginalId();
Material *ma = BKE_material_add((char*)str_mat_id.c_str());
Material *ma = BKE_material_add((char *)str_mat_id.c_str());
this->uid_effect_map[cmat->getInstantiatedEffect()] = ma;
this->uid_material_map[cmat->getUniqueId()] = ma;
@ -584,8 +587,8 @@ bool DocumentImporter::writeMaterial( const COLLADAFW::Material* cmat )
}
// create mtex, create texture, set texture image
MTex* DocumentImporter::create_texture(COLLADAFW::EffectCommon *ef, COLLADAFW::Texture &ctex, Material *ma,
int i, TexIndexTextureArrayMap &texindex_texarray_map)
MTex *DocumentImporter::create_texture(COLLADAFW::EffectCommon *ef, COLLADAFW::Texture &ctex, Material *ma,
int i, TexIndexTextureArrayMap &texindex_texarray_map)
{
COLLADAFW::SamplerPointerArray& samp_array = ef->getSamplerPointerArray();
COLLADAFW::Sampler *sampler = samp_array[ctex.getSamplerId()];
@ -735,32 +738,34 @@ void DocumentImporter::write_profile_COMMON(COLLADAFW::EffectCommon *ef, Materia
mtex->tex->imaflag |= TEX_USEALPHA;
i++;
ma->spectra = ma->alpha = 0;
ma->mode |= MA_ZTRANSP|MA_TRANSP;
ma->mode |= MA_ZTRANSP | MA_TRANSP;
}
}
// TRANSPARENT
// color
// if (ef->getOpacity().isColor()) {
// // XXX don't know what to do here
// }
// // texture
// else if (ef->getOpacity().isTexture()) {
// ctex = ef->getOpacity().getTexture();
// if (mtex != NULL) mtex->mapto &= MAP_ALPHA;
// else {
// mtex = create_texture(ef, ctex, ma, i, texindex_texarray_map);
// if (mtex != NULL) mtex->mapto = MAP_ALPHA;
// }
// }
#if 0
if (ef->getOpacity().isColor()) {
// XXX don't know what to do here
}
// texture
else if (ef->getOpacity().isTexture()) {
ctex = ef->getOpacity().getTexture();
if (mtex != NULL) mtex->mapto &= MAP_ALPHA;
else {
mtex = create_texture(ef, ctex, ma, i, texindex_texarray_map);
if (mtex != NULL) mtex->mapto = MAP_ALPHA;
}
}
#endif
material_texture_mapping_map[ma] = texindex_texarray_map;
}
/** When this method is called, the writer must write the effect.
\return The writer should return true, if writing succeeded, false otherwise.*/
* \return The writer should return true, if writing succeeded, false otherwise.*/
bool DocumentImporter::writeEffect( const COLLADAFW::Effect* effect )
bool DocumentImporter::writeEffect(const COLLADAFW::Effect *effect)
{
if (mImportStage!=General)
if (mImportStage != General)
return true;
const COLLADAFW::UniqueId& uid = effect->getUniqueId();
@ -771,9 +776,9 @@ bool DocumentImporter::writeEffect( const COLLADAFW::Effect* effect )
}
Material *ma = uid_effect_map[uid];
std::map<COLLADAFW::UniqueId, Material*>::iterator iter;
for (iter = uid_material_map.begin(); iter != uid_material_map.end() ; iter++ ) {
if ( iter->second == ma ) {
std::map<COLLADAFW::UniqueId, Material *>::iterator iter;
for (iter = uid_material_map.begin(); iter != uid_material_map.end(); iter++) {
if (iter->second == ma) {
this->FW_object_map[iter->first] = effect;
break;
}
@ -794,10 +799,10 @@ bool DocumentImporter::writeEffect( const COLLADAFW::Effect* effect )
/** When this method is called, the writer must write the camera.
\return The writer should return true, if writing succeeded, false otherwise.*/
bool DocumentImporter::writeCamera( const COLLADAFW::Camera* camera )
* \return The writer should return true, if writing succeeded, false otherwise.*/
bool DocumentImporter::writeCamera(const COLLADAFW::Camera *camera)
{
if (mImportStage!=General)
if (mImportStage != General)
return true;
Camera *cam = NULL;
@ -805,8 +810,8 @@ bool DocumentImporter::writeCamera( const COLLADAFW::Camera* camera )
cam_id = camera->getOriginalId();
cam_name = camera->getName();
if (cam_name.size()) cam = (Camera *)BKE_camera_add((char*)cam_name.c_str());
else cam = (Camera *)BKE_camera_add((char*)cam_id.c_str());
if (cam_name.size()) cam = (Camera *)BKE_camera_add((char *)cam_name.c_str());
else cam = (Camera *)BKE_camera_add((char *)cam_id.c_str());
if (!cam) {
fprintf(stderr, "Cannot create camera.\n");
@ -817,17 +822,17 @@ bool DocumentImporter::writeCamera( const COLLADAFW::Camera* camera )
COLLADAFW::Camera::CameraType type = camera->getCameraType();
switch (type) {
case COLLADAFW::Camera::ORTHOGRAPHIC:
case COLLADAFW::Camera::ORTHOGRAPHIC:
{
cam->type = CAM_ORTHO;
}
break;
case COLLADAFW::Camera::PERSPECTIVE:
case COLLADAFW::Camera::PERSPECTIVE:
{
cam->type = CAM_PERSP;
}
break;
case COLLADAFW::Camera::UNDEFINED_CAMERATYPE:
case COLLADAFW::Camera::UNDEFINED_CAMERATYPE:
{
fprintf(stderr, "Current camera type is not supported.\n");
cam->type = CAM_PERSP;
@ -836,35 +841,35 @@ bool DocumentImporter::writeCamera( const COLLADAFW::Camera* camera )
}
switch (camera->getDescriptionType()) {
case COLLADAFW::Camera::ASPECTRATIO_AND_Y:
case COLLADAFW::Camera::ASPECTRATIO_AND_Y:
{
switch (cam->type) {
case CAM_ORTHO:
{
double ymag = camera->getYMag().getValue();
double aspect = camera->getAspectRatio().getValue();
double xmag = aspect*ymag;
cam->ortho_scale = (float)xmag;
}
break;
{
double ymag = camera->getYMag().getValue();
double aspect = camera->getAspectRatio().getValue();
double xmag = aspect * ymag;
cam->ortho_scale = (float)xmag;
}
break;
case CAM_PERSP:
default:
{
double yfov = camera->getYFov().getValue();
double aspect = camera->getAspectRatio().getValue();
double xfov = aspect*yfov;
// xfov is in degrees, cam->lens is in millimiters
cam->lens = fov_to_focallength(DEG2RADF(xfov), cam->sensor_x);
}
break;
{
double yfov = camera->getYFov().getValue();
double aspect = camera->getAspectRatio().getValue();
double xfov = aspect * yfov;
// xfov is in degrees, cam->lens is in millimiters
cam->lens = fov_to_focallength(DEG2RADF(xfov), cam->sensor_x);
}
break;
}
}
break;
/* XXX correct way to do following four is probably to get also render
size and determine proper settings from that somehow */
case COLLADAFW::Camera::ASPECTRATIO_AND_X:
case COLLADAFW::Camera::SINGLE_X:
case COLLADAFW::Camera::X_AND_Y:
/* XXX correct way to do following four is probably to get also render
size and determine proper settings from that somehow */
case COLLADAFW::Camera::ASPECTRATIO_AND_X:
case COLLADAFW::Camera::SINGLE_X:
case COLLADAFW::Camera::X_AND_Y:
{
switch (cam->type) {
case CAM_ORTHO:
@ -872,16 +877,16 @@ bool DocumentImporter::writeCamera( const COLLADAFW::Camera* camera )
break;
case CAM_PERSP:
default:
{
double x = camera->getXFov().getValue();
// x is in degrees, cam->lens is in millimiters
cam->lens = fov_to_focallength(DEG2RADF(x), cam->sensor_x);
}
break;
{
double x = camera->getXFov().getValue();
// x is in degrees, cam->lens is in millimiters
cam->lens = fov_to_focallength(DEG2RADF(x), cam->sensor_x);
}
break;
}
}
break;
case COLLADAFW::Camera::SINGLE_Y:
case COLLADAFW::Camera::SINGLE_Y:
{
switch (cam->type) {
case CAM_ORTHO:
@ -889,18 +894,18 @@ bool DocumentImporter::writeCamera( const COLLADAFW::Camera* camera )
break;
case CAM_PERSP:
default:
{
{
double yfov = camera->getYFov().getValue();
// yfov is in degrees, cam->lens is in millimiters
cam->lens = fov_to_focallength(DEG2RADF(yfov), cam->sensor_x);
}
break;
}
break;
}
}
break;
case COLLADAFW::Camera::UNDEFINED:
// read nothing, use blender defaults.
break;
case COLLADAFW::Camera::UNDEFINED:
// read nothing, use blender defaults.
break;
}
this->uid_camera_map[camera->getUniqueId()] = cam;
@ -910,15 +915,15 @@ bool DocumentImporter::writeCamera( const COLLADAFW::Camera* camera )
}
/** When this method is called, the writer must write the image.
\return The writer should return true, if writing succeeded, false otherwise.*/
bool DocumentImporter::writeImage( const COLLADAFW::Image* image )
* \return The writer should return true, if writing succeeded, false otherwise.*/
bool DocumentImporter::writeImage(const COLLADAFW::Image *image)
{
if (mImportStage!=General)
if (mImportStage != General)
return true;
// XXX maybe it is necessary to check if the path is absolute or relative
const std::string& filepath = image->getImageURI().toNativePath();
const char *filename = (const char*)mFilename.c_str();
const char *filename = (const char *)mFilename.c_str();
char dir[FILE_MAX];
char full_path[FILE_MAX];
@ -935,10 +940,10 @@ bool DocumentImporter::writeImage( const COLLADAFW::Image* image )
}
/** When this method is called, the writer must write the light.
\return The writer should return true, if writing succeeded, false otherwise.*/
bool DocumentImporter::writeLight( const COLLADAFW::Light* light )
* \return The writer should return true, if writing succeeded, false otherwise.*/
bool DocumentImporter::writeLight(const COLLADAFW::Light *light)
{
if (mImportStage!=General)
if (mImportStage != General)
return true;
Lamp *lamp = NULL;
@ -952,8 +957,8 @@ bool DocumentImporter::writeLight( const COLLADAFW::Light* light )
la_id = light->getOriginalId();
la_name = light->getName();
if (la_name.size()) lamp = (Lamp*)BKE_lamp_add((char*)la_name.c_str());
else lamp = (Lamp*)BKE_lamp_add((char*)la_id.c_str());
if (la_name.size()) lamp = (Lamp *)BKE_lamp_add((char *)la_name.c_str());
else lamp = (Lamp *)BKE_lamp_add((char *)la_id.c_str());
if (!lamp) {
fprintf(stderr, "Cannot create lamp.\n");
@ -1036,12 +1041,12 @@ bool DocumentImporter::writeLight( const COLLADAFW::Light* light )
if (IS_EQ(linatt, 0.0f) && quadatt > 0.0f) {
att2 = quadatt;
d = sqrt(1.0f/quadatt);
d = sqrt(1.0f / quadatt);
}
// linear light
else if (IS_EQ(quadatt, 0.0f) && linatt > 0.0f) {
att1 = linatt;
d = (1.0f/linatt);
d = (1.0f / linatt);
}
else if (IS_EQ(constatt, 1.0f)) {
att1 = 1.0f;
@ -1051,7 +1056,7 @@ bool DocumentImporter::writeLight( const COLLADAFW::Light* light )
att1 = 1.0f;
}
d *= ( 1.0f / unit_converter.getLinearMeter());
d *= (1.0f / unit_converter.getLinearMeter());
lamp->energy = e;
lamp->dist = d;
@ -1059,47 +1064,47 @@ bool DocumentImporter::writeLight( const COLLADAFW::Light* light )
COLLADAFW::Light::LightType type = light->getLightType();
switch (type) {
case COLLADAFW::Light::AMBIENT_LIGHT:
{
lamp->type = LA_HEMI;
}
break;
{
lamp->type = LA_HEMI;
}
break;
case COLLADAFW::Light::SPOT_LIGHT:
{
lamp->type = LA_SPOT;
lamp->att1 = att1;
lamp->att2 = att2;
if (IS_EQ(att1, 0.0f) && att2 > 0)
lamp->falloff_type = LA_FALLOFF_INVSQUARE;
if (IS_EQ(att2, 0.0f) && att1 > 0)
lamp->falloff_type = LA_FALLOFF_INVLINEAR;
lamp->spotsize = light->getFallOffAngle().getValue();
lamp->spotblend = light->getFallOffExponent().getValue();
}
break;
{
lamp->type = LA_SPOT;
lamp->att1 = att1;
lamp->att2 = att2;
if (IS_EQ(att1, 0.0f) && att2 > 0)
lamp->falloff_type = LA_FALLOFF_INVSQUARE;
if (IS_EQ(att2, 0.0f) && att1 > 0)
lamp->falloff_type = LA_FALLOFF_INVLINEAR;
lamp->spotsize = light->getFallOffAngle().getValue();
lamp->spotblend = light->getFallOffExponent().getValue();
}
break;
case COLLADAFW::Light::DIRECTIONAL_LIGHT:
{
/* our sun is very strong, so pick a smaller energy level */
lamp->type = LA_SUN;
lamp->mode |= LA_NO_SPEC;
}
break;
{
/* our sun is very strong, so pick a smaller energy level */
lamp->type = LA_SUN;
lamp->mode |= LA_NO_SPEC;
}
break;
case COLLADAFW::Light::POINT_LIGHT:
{
lamp->type = LA_LOCAL;
lamp->att1 = att1;
lamp->att2 = att2;
if (IS_EQ(att1, 0.0f) && att2 > 0)
lamp->falloff_type = LA_FALLOFF_INVSQUARE;
if (IS_EQ(att2, 0.0f) && att1 > 0)
lamp->falloff_type = LA_FALLOFF_INVLINEAR;
}
break;
{
lamp->type = LA_LOCAL;
lamp->att1 = att1;
lamp->att2 = att2;
if (IS_EQ(att1, 0.0f) && att2 > 0)
lamp->falloff_type = LA_FALLOFF_INVSQUARE;
if (IS_EQ(att2, 0.0f) && att1 > 0)
lamp->falloff_type = LA_FALLOFF_INVLINEAR;
}
break;
case COLLADAFW::Light::UNDEFINED:
{
fprintf(stderr, "Current lamp type is not supported.\n");
lamp->type = LA_LOCAL;
}
break;
{
fprintf(stderr, "Current lamp type is not supported.\n");
lamp->type = LA_LOCAL;
}
break;
}
}
@ -1109,9 +1114,9 @@ bool DocumentImporter::writeLight( const COLLADAFW::Light* light )
}
// this function is called only for animations that pass COLLADAFW::validate
bool DocumentImporter::writeAnimation( const COLLADAFW::Animation* anim )
bool DocumentImporter::writeAnimation(const COLLADAFW::Animation *anim)
{
if (mImportStage!=General)
if (mImportStage != General)
return true;
// return true;
@ -1119,9 +1124,9 @@ bool DocumentImporter::writeAnimation( const COLLADAFW::Animation* anim )
}
// called on post-process stage after writeVisualScenes
bool DocumentImporter::writeAnimationList( const COLLADAFW::AnimationList* animationList )
bool DocumentImporter::writeAnimationList(const COLLADAFW::AnimationList *animationList)
{
if (mImportStage!=General)
if (mImportStage != General)
return true;
// return true;
@ -1129,40 +1134,40 @@ bool DocumentImporter::writeAnimationList( const COLLADAFW::AnimationList* anima
}
/** When this method is called, the writer must write the skin controller data.
\return The writer should return true, if writing succeeded, false otherwise.*/
bool DocumentImporter::writeSkinControllerData( const COLLADAFW::SkinControllerData* skin )
* \return The writer should return true, if writing succeeded, false otherwise.*/
bool DocumentImporter::writeSkinControllerData(const COLLADAFW::SkinControllerData *skin)
{
return armature_importer.write_skin_controller_data(skin);
}
// this is called on postprocess, before writeVisualScenes
bool DocumentImporter::writeController( const COLLADAFW::Controller* controller )
bool DocumentImporter::writeController(const COLLADAFW::Controller *controller)
{
if (mImportStage!=General)
if (mImportStage != General)
return true;
return armature_importer.write_controller(controller);
}
bool DocumentImporter::writeFormulas( const COLLADAFW::Formulas* formulas )
bool DocumentImporter::writeFormulas(const COLLADAFW::Formulas *formulas)
{
return true;
}
bool DocumentImporter::writeKinematicsScene( const COLLADAFW::KinematicsScene* kinematicsScene )
bool DocumentImporter::writeKinematicsScene(const COLLADAFW::KinematicsScene *kinematicsScene)
{
return true;
}
ExtraTags* DocumentImporter::getExtraTags(const COLLADAFW::UniqueId &uid)
ExtraTags *DocumentImporter::getExtraTags(const COLLADAFW::UniqueId &uid)
{
if (uid_tags_map.find(uid.toAscii())==uid_tags_map.end()) {
if (uid_tags_map.find(uid.toAscii()) == uid_tags_map.end()) {
return NULL;
}
return uid_tags_map[uid.toAscii()];
}
bool DocumentImporter::addExtraTags( const COLLADAFW::UniqueId &uid, ExtraTags *extra_tags)
bool DocumentImporter::addExtraTags(const COLLADAFW::UniqueId &uid, ExtraTags *extra_tags)
{
uid_tags_map[uid.toAscii()] = extra_tags;
return true;

@ -46,7 +46,7 @@
// OB_MESH is assumed
static std::string getActiveUVLayerName(Object *ob)
{
Mesh *me = (Mesh*)ob->data;
Mesh *me = (Mesh *)ob->data;
int num_layers = CustomData_number_of_layers(&me->fdata, CD_MTFACE);
if (num_layers)
@ -55,24 +55,25 @@ static std::string getActiveUVLayerName(Object *ob)
return "";
}
EffectsExporter::EffectsExporter(COLLADASW::StreamWriter *sw, const ExportSettings *export_settings) : COLLADASW::LibraryEffects(sw), export_settings(export_settings) {}
EffectsExporter::EffectsExporter(COLLADASW::StreamWriter *sw, const ExportSettings *export_settings) : COLLADASW::LibraryEffects(sw), export_settings(export_settings) {
}
bool EffectsExporter::hasEffects(Scene *sce)
{
Base *base = (Base *)sce->base.first;
while (base) {
Object *ob= base->object;
Object *ob = base->object;
int a;
for (a = 0; a < ob->totcol; a++) {
Material *ma = give_current_material(ob, a+1);
Material *ma = give_current_material(ob, a + 1);
// no material, but check all of the slots
if (!ma) continue;
return true;
}
base= base->next;
base = base->next;
}
return false;
}
@ -97,7 +98,7 @@ void EffectsExporter::writeBlinn(COLLADASW::EffectProfile &ep, Material *ma)
ep.setShininess(ma->har, false, "shininess");
// specular
cot = getcol(ma->specr, ma->specg, ma->specb, 1.0f);
ep.setSpecular(cot, false, "specular" );
ep.setSpecular(cot, false, "specular");
}
void EffectsExporter::writeLambert(COLLADASW::EffectProfile &ep, Material *ma)
@ -111,10 +112,10 @@ void EffectsExporter::writePhong(COLLADASW::EffectProfile &ep, Material *ma)
COLLADASW::ColorOrTexture cot;
ep.setShaderType(COLLADASW::EffectProfile::PHONG);
// shininess
ep.setShininess(ma->har, false, "shininess" );
ep.setShininess(ma->har, false, "shininess");
// specular
cot = getcol(ma->specr, ma->specg, ma->specb, 1.0f);
ep.setSpecular(cot, false, "specular" );
ep.setSpecular(cot, false, "specular");
}
void EffectsExporter::operator()(Material *ma, Object *ob)
@ -129,7 +130,7 @@ void EffectsExporter::operator()(Material *ma, Object *ob)
ep.setProfileType(COLLADASW::EffectProfile::COMMON);
ep.openProfile();
// set shader type - one of three blinn, phong or lambert
if (ma->spec>0.0f) {
if (ma->spec > 0.0f) {
if (ma->spec_shader == MA_SPEC_BLINN) {
writeBlinn(ep, ma);
}
@ -144,8 +145,8 @@ void EffectsExporter::operator()(Material *ma, Object *ob)
writeLambert(ep, ma);
}
else {
// \todo figure out handling of all spec+diff shader combos blender has, for now write phong
writePhong(ep, ma);
// \todo figure out handling of all spec+diff shader combos blender has, for now write phong
writePhong(ep, ma);
}
}
@ -168,7 +169,7 @@ void EffectsExporter::operator()(Material *ma, Object *ob)
}
// emission
cot=getcol(ma->emit, ma->emit, ma->emit, 1.0f);
cot = getcol(ma->emit, ma->emit, ma->emit, 1.0f);
ep.setEmission(cot, false, "emission");
// diffuse multiplied by diffuse intensity
@ -178,7 +179,7 @@ void EffectsExporter::operator()(Material *ma, Object *ob)
// ambient
/* ma->ambX is calculated only on render, so lets do it here manually and not rely on ma->ambX. */
if (this->scene->world)
cot = getcol(this->scene->world->ambr*ma->amb, this->scene->world->ambg*ma->amb, this->scene->world->ambb*ma->amb, 1.0f);
cot = getcol(this->scene->world->ambr * ma->amb, this->scene->world->ambg * ma->amb, this->scene->world->ambb * ma->amb, 1.0f);
else
cot = getcol(ma->amb, ma->amb, ma->amb, 1.0f);
@ -191,9 +192,9 @@ void EffectsExporter::operator()(Material *ma, Object *ob)
ep.setReflectivity(ma->ray_mirror);
}
// else {
// cot = getcol(ma->specr, ma->specg, ma->specb, 1.0f);
// ep.setReflective(cot);
// ep.setReflectivity(ma->spec);
// cot = getcol(ma->specr, ma->specg, ma->specb, 1.0f);
// ep.setReflective(cot);
// ep.setReflectivity(ma->spec);
// }
// specular
@ -229,7 +230,7 @@ void EffectsExporter::operator()(Material *ma, Object *ob)
if (im_samp_map.find(key) == im_samp_map.end()) {
// //<newparam> <surface> <init_from>
// COLLADASW::Surface surface(COLLADASW::Surface::SURFACE_TYPE_2D,
// key + COLLADASW::Surface::SURFACE_SID_SUFFIX);
// key + COLLADASW::Surface::SURFACE_SID_SUFFIX);
// COLLADASW::SurfaceInitOption sio(COLLADASW::SurfaceInitOption::INIT_FROM);
// sio.setImageReference(key);
// surface.setInitOption(sio);
@ -239,8 +240,8 @@ void EffectsExporter::operator()(Material *ma, Object *ob)
//<newparam> <sampler> <source>
COLLADASW::Sampler sampler(COLLADASW::Sampler::SAMPLER_TYPE_2D,
key + COLLADASW::Sampler::SAMPLER_SID_SUFFIX,
key + COLLADASW::Sampler::SURFACE_SID_SUFFIX);
key + COLLADASW::Sampler::SAMPLER_SID_SUFFIX,
key + COLLADASW::Sampler::SURFACE_SID_SUFFIX);
sampler.setImageId(key);
// copy values to arrays since they will live longer
samplers[a] = sampler;
@ -273,7 +274,7 @@ void EffectsExporter::operator()(Material *ma, Object *ob)
std::string key(id_name(ima));
key = translate_id(key);
int i = im_samp_map[key];
COLLADASW::Sampler *sampler = (COLLADASW::Sampler*)samp_surf[i][0];
COLLADASW::Sampler *sampler = (COLLADASW::Sampler *)samp_surf[i][0];
//COLLADASW::Surface *surface = (COLLADASW::Surface*)samp_surf[i][1];
std::string uvname = strlen(t->uvname) ? t->uvname : active_uv;
@ -320,7 +321,7 @@ void EffectsExporter::operator()(Material *ma, Object *ob)
ep.addProfileElements();
bool twoSided = false;
if (ob->type == OB_MESH && ob->data) {
Mesh *me = (Mesh*)ob->data;
Mesh *me = (Mesh *)ob->data;
if (me->flag & ME_TWOSIDED)
twoSided = true;
}
@ -335,9 +336,9 @@ void EffectsExporter::operator()(Material *ma, Object *ob)
}
COLLADASW::ColorOrTexture EffectsExporter::createTexture(Image *ima,
std::string& uv_layer_name,
COLLADASW::Sampler *sampler
/*COLLADASW::Surface *surface*/)
std::string& uv_layer_name,
COLLADASW::Sampler *sampler
/*COLLADASW::Surface *surface*/)
{
COLLADASW::Texture texture(translate_id(id_name(ima)));

@ -45,36 +45,36 @@ ErrorHandler::~ErrorHandler()
}
//--------------------------------------------------------------------
bool ErrorHandler::handleError( const COLLADASaxFWL::IError* error )
bool ErrorHandler::handleError(const COLLADASaxFWL::IError *error)
{
mError = true;
if ( error->getErrorClass() == COLLADASaxFWL::IError::ERROR_SAXPARSER ) {
COLLADASaxFWL::SaxParserError* saxParserError = (COLLADASaxFWL::SaxParserError*) error;
if (error->getErrorClass() == COLLADASaxFWL::IError::ERROR_SAXPARSER) {
COLLADASaxFWL::SaxParserError *saxParserError = (COLLADASaxFWL::SaxParserError *) error;
const GeneratedSaxParser::ParserError& parserError = saxParserError->getError();
// Workaround to avoid wrong error
if ( parserError.getErrorType() == GeneratedSaxParser::ParserError::ERROR_VALIDATION_MIN_OCCURS_UNMATCHED) {
if ( strcmp(parserError.getElement(), "effect") == 0 ) {
if (parserError.getErrorType() == GeneratedSaxParser::ParserError::ERROR_VALIDATION_MIN_OCCURS_UNMATCHED) {
if (strcmp(parserError.getElement(), "effect") == 0) {
mError = false;
}
}
if ( parserError.getErrorType() == GeneratedSaxParser::ParserError::ERROR_VALIDATION_SEQUENCE_PREVIOUS_SIBLING_NOT_PRESENT) {
if ( !((strcmp(parserError.getElement(), "extra") == 0) &&
(strcmp(parserError.getAdditionalText().c_str(), "sibling: fx_profile_abstract") == 0)))
if (parserError.getErrorType() == GeneratedSaxParser::ParserError::ERROR_VALIDATION_SEQUENCE_PREVIOUS_SIBLING_NOT_PRESENT) {
if (!((strcmp(parserError.getElement(), "extra") == 0) &&
(strcmp(parserError.getAdditionalText().c_str(), "sibling: fx_profile_abstract") == 0)))
{
mError = false;
}
}
if ( parserError.getErrorType() == GeneratedSaxParser::ParserError::ERROR_COULD_NOT_OPEN_FILE) {
if (parserError.getErrorType() == GeneratedSaxParser::ParserError::ERROR_COULD_NOT_OPEN_FILE) {
std::cout << "Couldn't open file" << std::endl;
}
std::cout << "Schema validation error: " << parserError.getErrorMessage() << std::endl;
}
else if ( error->getErrorClass() == COLLADASaxFWL::IError::ERROR_SAXFWL ) {
COLLADASaxFWL::SaxFWLError* saxFWLError = (COLLADASaxFWL::SaxFWLError*) error;
else if (error->getErrorClass() == COLLADASaxFWL::IError::ERROR_SAXFWL) {
COLLADASaxFWL::SaxFWLError *saxFWLError = (COLLADASaxFWL::SaxFWLError *) error;
std::cout << "Sax FWL Error: " << saxFWLError->getErrorMessage() << std::endl;
}
else {

@ -35,9 +35,10 @@ ExtraHandler::ExtraHandler(DocumentImporter *dimp, AnimationImporter *aimp) : cu
this->aimp = aimp;
}
ExtraHandler::~ExtraHandler() {}
ExtraHandler::~ExtraHandler() {
}
bool ExtraHandler::elementBegin( const char* elementName, const char** attributes)
bool ExtraHandler::elementBegin(const char *elementName, const char **attributes)
{
// \todo attribute handling for profile tags
currentElement = std::string(elementName);
@ -45,37 +46,38 @@ bool ExtraHandler::elementBegin( const char* elementName, const char** attribute
return true;
}
bool ExtraHandler::elementEnd(const char* elementName )
bool ExtraHandler::elementEnd(const char *elementName)
{
return true;
}
bool ExtraHandler::textData(const char* text, size_t textLength)
bool ExtraHandler::textData(const char *text, size_t textLength)
{
char buf[1024];
if (currentElement.length() == 0 || currentExtraTags == 0) return false;
BLI_snprintf(buf, textLength+1, "%s", text);
BLI_snprintf(buf, textLength + 1, "%s", text);
currentExtraTags->addTag(currentElement, std::string(buf));
return true;
}
bool ExtraHandler::parseElement (
const char* profileName,
const unsigned long& elementHash,
const COLLADAFW::UniqueId& uniqueId ) {
if (BLI_strcaseeq(profileName, "blender")) {
//printf("In parseElement for supported profile %s for id %s\n", profileName, uniqueId.toAscii().c_str());
currentUid = uniqueId;
ExtraTags *et = dimp->getExtraTags(uniqueId);
if (!et) {
et = new ExtraTags(std::string(profileName));
dimp->addExtraTags(uniqueId, et);
}
currentExtraTags = et;
return true;
bool ExtraHandler::parseElement(
const char *profileName,
const unsigned long& elementHash,
const COLLADAFW::UniqueId& uniqueId)
{
if (BLI_strcaseeq(profileName, "blender")) {
//printf("In parseElement for supported profile %s for id %s\n", profileName, uniqueId.toAscii().c_str());
currentUid = uniqueId;
ExtraTags *et = dimp->getExtraTags(uniqueId);
if (!et) {
et = new ExtraTags(std::string(profileName));
dimp->addExtraTags(uniqueId, et);
}
//printf("In parseElement for unsupported profile %s for id %s\n", profileName, uniqueId.toAscii().c_str());
return false;
currentExtraTags = et;
return true;
}
//printf("In parseElement for unsupported profile %s for id %s\n", profileName, uniqueId.toAscii().c_str());
return false;
}

@ -32,7 +32,7 @@
#include "ExtraTags.h"
ExtraTags::ExtraTags( std::string profile)
ExtraTags::ExtraTags(std::string profile)
{
this->profile = profile;
this->tags = std::map<std::string, std::string>();
@ -42,19 +42,19 @@ ExtraTags::~ExtraTags()
{
}
bool ExtraTags::isProfile( std::string profile)
bool ExtraTags::isProfile(std::string profile)
{
return this->profile == profile;
}
bool ExtraTags::addTag( std::string tag, std::string data)
bool ExtraTags::addTag(std::string tag, std::string data)
{
tags[tag] = data;
return true;
}
int ExtraTags::asInt( std::string tag, bool *ok)
int ExtraTags::asInt(std::string tag, bool *ok)
{
if (tags.find(tag) == tags.end()) {
*ok = false;
@ -64,7 +64,7 @@ int ExtraTags::asInt( std::string tag, bool *ok)
return atoi(tags[tag].c_str());
}
float ExtraTags::asFloat( std::string tag, bool *ok)
float ExtraTags::asFloat(std::string tag, bool *ok)
{
if (tags.find(tag) == tags.end()) {
*ok = false;
@ -74,7 +74,7 @@ float ExtraTags::asFloat( std::string tag, bool *ok)
return (float)atof(tags[tag].c_str());
}
std::string ExtraTags::asString( std::string tag, bool *ok)
std::string ExtraTags::asString(std::string tag, bool *ok)
{
if (tags.find(tag) == tags.end()) {
*ok = false;

@ -38,7 +38,7 @@
#include "DNA_meshdata_types.h"
extern "C" {
#include "BKE_DerivedMesh.h"
#include "BKE_DerivedMesh.h"
#include "BKE_main.h"
#include "BKE_global.h"
#include "BKE_library.h"
@ -52,7 +52,8 @@ extern "C" {
#include "collada_utils.h"
// TODO: optimize UV sets by making indexed list with duplicates removed
GeometryExporter::GeometryExporter(COLLADASW::StreamWriter *sw, const ExportSettings *export_settings) : COLLADASW::LibraryGeometries(sw), export_settings(export_settings) {}
GeometryExporter::GeometryExporter(COLLADASW::StreamWriter *sw, const ExportSettings *export_settings) : COLLADASW::LibraryGeometries(sw), export_settings(export_settings) {
}
void GeometryExporter::exportGeom(Scene *sce)
@ -76,11 +77,11 @@ void GeometryExporter::operator()(Object *ob)
bool use_instantiation = this->export_settings->use_object_instantiation;
Mesh *me;
if ( this->export_settings->apply_modifiers ) {
if (this->export_settings->apply_modifiers) {
me = bc_to_mesh_apply_modifiers(mScene, ob);
}
else {
me = (Mesh*)ob->data;
me = (Mesh *)ob->data;
}
BKE_mesh_tessface_ensure(me);
@ -90,8 +91,10 @@ void GeometryExporter::operator()(Object *ob)
// Skip if linked geometry was already exported from another reference
if (use_instantiation &&
exportedGeometry.find(geom_id) != exportedGeometry.end())
exportedGeometry.find(geom_id) != exportedGeometry.end())
{
return;
}
std::string geom_name = (use_instantiation) ? id_name(ob->data) : id_name(ob);
@ -132,7 +135,7 @@ void GeometryExporter::operator()(Object *ob)
// XXX slow
if (ob->totcol) {
for (int a = 0; a < ob->totcol; a++) {
for (int a = 0; a < ob->totcol; a++) {
createPolylist(a, has_uvs, has_color, ob, me, geom_id, norind);
}
}
@ -161,9 +164,9 @@ void GeometryExporter::operator()(Object *ob)
void GeometryExporter::createLooseEdgeList(Object *ob,
Mesh *me,
std::string& geom_id,
std::vector<Face>& norind)
Mesh *me,
std::string& geom_id,
std::vector<Face>& norind)
{
MEdge *medges = me->medge;
@ -204,8 +207,8 @@ void GeometryExporter::createLooseEdgeList(Object *ob,
for (index = 0; index < edges_in_linelist; index++)
{
lines.appendValues(edge_list[2*index+1]);
lines.appendValues(edge_list[2*index]);
lines.appendValues(edge_list[2 * index + 1]);
lines.appendValues(edge_list[2 * index]);
}
lines.finish();
}
@ -214,12 +217,12 @@ void GeometryExporter::createLooseEdgeList(Object *ob,
// powerful because it handles both cases when there is material and when there's not
void GeometryExporter::createPolylist(short material_index,
bool has_uvs,
bool has_color,
Object *ob,
Mesh *me,
std::string& geom_id,
std::vector<Face>& norind)
bool has_uvs,
bool has_color,
Object *ob,
Mesh *me,
std::string& geom_id,
std::vector<Face>& norind)
{
MFace *mfaces = me->mface;
int totfaces = me->totface;
@ -280,10 +283,10 @@ void GeometryExporter::createPolylist(short material_index,
for (i = 0; i < num_layers; i++) {
// char *name = CustomData_get_layer_name(&me->fdata, CD_MTFACE, i);
COLLADASW::Input input3(COLLADASW::InputSemantic::TEXCOORD,
makeUrl(makeTexcoordSourceId(geom_id, i)),
2, // offset always 2, this is only until we have optimized UV sets
i // set number equals UV map index
);
makeUrl(makeTexcoordSourceId(geom_id, i)),
2, // offset always 2, this is only until we have optimized UV sets
i // set number equals UV map index
);
til.push_back(input3);
}
@ -342,7 +345,7 @@ void GeometryExporter::createVertsSource(std::string geom_id, Mesh *me)
COLLADASW::FloatSourceF source(mSW);
source.setId(getIdBySemantics(geom_id, COLLADASW::InputSemantic::POSITION));
source.setArrayId(getIdBySemantics(geom_id, COLLADASW::InputSemantic::POSITION) +
ARRAY_ID_SUFFIX);
ARRAY_ID_SUFFIX);
source.setAccessorCount(totverts);
source.setAccessorStride(3);
COLLADASW::SourceBase::ParameterNameList &param = source.getParameterNameList();
@ -350,7 +353,7 @@ void GeometryExporter::createVertsSource(std::string geom_id, Mesh *me)
param.push_back("Y");
param.push_back("Z");
/*main function, it creates <source id = "">, <float_array id = ""
count = ""> */
count = ""> */
source.prepareToAppendValues();
//appends data to <float_array>
int i = 0;
@ -388,7 +391,7 @@ void GeometryExporter::createVertexColorSource(std::string geom_id, Mesh *me)
int index = CustomData_get_active_layer_index(&me->fdata, CD_MCOL);
MCol *mcol = (MCol*)me->fdata.layers[index].data;
MCol *mcol = (MCol *)me->fdata.layers[index].data;
MCol *c = mcol;
for (i = 0, f = me->mface; i < me->totface; i++, c += 4, f++)
@ -422,10 +425,10 @@ void GeometryExporter::createTexcoordsSource(std::string geom_id, Mesh *me)
for (i = 0; i < totfaces; i++) {
MFace *f = &mfaces[i];
if (f->v4 == 0) {
totuv+=3;
totuv += 3;
}
else {
totuv+=4;
totuv += 4;
}
}
@ -434,7 +437,7 @@ void GeometryExporter::createTexcoordsSource(std::string geom_id, Mesh *me)
// write <source> for each layer
// each <source> will get id like meshName + "map-channel-1"
for (int a = 0; a < num_layers; a++) {
MTFace *tface = (MTFace*)CustomData_get_layer_n(&me->fdata, CD_MTFACE, a);
MTFace *tface = (MTFace *)CustomData_get_layer_n(&me->fdata, CD_MTFACE, a);
// char *name = CustomData_get_layer_name(&me->fdata, CD_MTFACE, a);
COLLADASW::FloatSourceF source(mSW);
@ -455,7 +458,7 @@ void GeometryExporter::createTexcoordsSource(std::string geom_id, Mesh *me)
for (int j = 0; j < (f->v4 == 0 ? 3 : 4); j++) {
source.appendValues(tface[i].uv[j][0],
tface[i].uv[j][1]);
tface[i].uv[j][1]);
}
}
@ -475,7 +478,7 @@ void GeometryExporter::createNormalsSource(std::string geom_id, Mesh *me, std::v
COLLADASW::FloatSourceF source(mSW);
source.setId(getIdBySemantics(geom_id, COLLADASW::InputSemantic::NORMAL));
source.setArrayId(getIdBySemantics(geom_id, COLLADASW::InputSemantic::NORMAL) +
ARRAY_ID_SUFFIX);
ARRAY_ID_SUFFIX);
source.setAccessorCount((unsigned long)nor.size());
source.setAccessorStride(3);
COLLADASW::SourceBase::ParameterNameList &param = source.getParameterNameList();
@ -563,8 +566,9 @@ COLLADASW::URI GeometryExporter::makeUrl(std::string id)
return COLLADASW::URI(COLLADABU::Utils::EMPTY_STRING, id);
}
/* int GeometryExporter::getTriCount(MFace *faces, int totface) {
#if 0
int GeometryExporter::getTriCount(MFace *faces, int totface)
{
int i;
int tris = 0;
for (i = 0; i < totface; i++) {
@ -576,4 +580,5 @@ COLLADASW::URI GeometryExporter::makeUrl(std::string id)
}
return tris;
}*/
}
#endif

@ -42,17 +42,19 @@
#include "BLI_string.h"
ImagesExporter::ImagesExporter(COLLADASW::StreamWriter *sw, const ExportSettings *export_settings) : COLLADASW::LibraryImages(sw), export_settings(export_settings)
{}
{
}
/* TODO - shouldn't this use the objects LinkNode's ? */
bool ImagesExporter::hasImages(Scene *sce)
{
Base *base = (Base *)sce->base.first;
while (base) {
Object *ob= base->object;
Object *ob = base->object;
int a;
for (a = 0; a < ob->totcol; a++) {
Material *ma = give_current_material(ob, a+1);
Material *ma = give_current_material(ob, a + 1);
// no material, but check all of the slots
if (!ma) continue;
@ -63,7 +65,7 @@ bool ImagesExporter::hasImages(Scene *sce)
}
}
base= base->next;
base = base->next;
}
return false;
}

@ -43,8 +43,8 @@
void InstanceWriter::add_material_bindings(COLLADASW::BindMaterial& bind_material, Object *ob)
{
for (int a = 0; a < ob->totcol; a++) {
Material *ma = give_current_material(ob, a+1);
for (int a = 0; a < ob->totcol; a++) {
Material *ma = give_current_material(ob, a + 1);
COLLADASW::InstanceMaterialList& iml = bind_material.getInstanceMaterialList();
@ -56,7 +56,7 @@ void InstanceWriter::add_material_bindings(COLLADASW::BindMaterial& bind_materia
COLLADASW::InstanceMaterial im(ostr.str(), COLLADASW::URI(COLLADABU::Utils::EMPTY_STRING, matid));
// create <bind_vertex_input> for each uv map
Mesh *me = (Mesh*)ob->data;
Mesh *me = (Mesh *)ob->data;
int totlayer = CustomData_number_of_layers(&me->fdata, CD_MTFACE);
for (int b = 0; b < totlayer; b++) {

@ -39,7 +39,7 @@ template<class Functor>
void forEachLampObjectInExportSet(Scene *sce, Functor &f, LinkNode *export_set)
{
LinkNode *node;
for (node=export_set; node; node = node->next) {
for (node = export_set; node; node = node->next) {
Object *ob = (Object *)node->link;
if (ob->type == OB_LAMP && ob->data) {
@ -48,7 +48,8 @@ void forEachLampObjectInExportSet(Scene *sce, Functor &f, LinkNode *export_set)
}
}
LightsExporter::LightsExporter(COLLADASW::StreamWriter *sw, const ExportSettings *export_settings): COLLADASW::LibraryLights(sw), export_settings(export_settings) {}
LightsExporter::LightsExporter(COLLADASW::StreamWriter *sw, const ExportSettings *export_settings) : COLLADASW::LibraryLights(sw), export_settings(export_settings) {
}
void LightsExporter::exportLights(Scene *sce)
{
@ -61,7 +62,7 @@ void LightsExporter::exportLights(Scene *sce)
void LightsExporter::operator()(Object *ob)
{
Lamp *la = (Lamp*)ob->data;
Lamp *la = (Lamp *)ob->data;
std::string la_id(get_light_id(ob));
std::string la_name(id_name(la));
COLLADASW::Color col(la->r * la->energy, la->g * la->energy, la->b * la->energy);
@ -71,7 +72,7 @@ void LightsExporter::operator()(Object *ob)
constatt = 1.0f;
if (la->falloff_type==LA_FALLOFF_INVLINEAR) {
if (la->falloff_type == LA_FALLOFF_INVLINEAR) {
linatt = 1.0f / d;
quadatt = 0.0f;
}

@ -31,7 +31,8 @@
#include "COLLADABUUtils.h"
#include "collada_internal.h"
MaterialsExporter::MaterialsExporter(COLLADASW::StreamWriter *sw, const ExportSettings *export_settings): COLLADASW::LibraryMaterials(sw), export_settings(export_settings) {}
MaterialsExporter::MaterialsExporter(COLLADASW::StreamWriter *sw, const ExportSettings *export_settings) : COLLADASW::LibraryMaterials(sw), export_settings(export_settings) {
}
void MaterialsExporter::exportMaterials(Scene *sce)
{
@ -45,23 +46,23 @@ void MaterialsExporter::exportMaterials(Scene *sce)
}
}
/* TODO - shouldn't this use the scenes object LinkNode's ? */
bool MaterialsExporter::hasMaterials(Scene *sce)
{
Base *base = (Base *)sce->base.first;
while (base) {
Object *ob= base->object;
Object *ob = base->object;
int a;
for (a = 0; a < ob->totcol; a++) {
Material *ma = give_current_material(ob, a+1);
Material *ma = give_current_material(ob, a + 1);
// no material, but check all of the slots
if (!ma) continue;
return true;
}
base= base->next;
base = base->next;
}
return false;
}

@ -72,24 +72,24 @@ static const char *bc_get_dae_name(T *node)
static const char *bc_primTypeToStr(COLLADAFW::MeshPrimitive::PrimitiveType type)
{
switch (type) {
case COLLADAFW::MeshPrimitive::LINES:
return "LINES";
case COLLADAFW::MeshPrimitive::LINE_STRIPS:
return "LINESTRIPS";
case COLLADAFW::MeshPrimitive::POLYGONS:
return "POLYGONS";
case COLLADAFW::MeshPrimitive::POLYLIST:
return "POLYLIST";
case COLLADAFW::MeshPrimitive::TRIANGLES:
return "TRIANGLES";
case COLLADAFW::MeshPrimitive::TRIANGLE_FANS:
return "TRIANGLE_FANS";
case COLLADAFW::MeshPrimitive::TRIANGLE_STRIPS:
return "TRIANGLE_FANS";
case COLLADAFW::MeshPrimitive::POINTS:
return "POINTS";
case COLLADAFW::MeshPrimitive::UNDEFINED_PRIMITIVE_TYPE:
return "UNDEFINED_PRIMITIVE_TYPE";
case COLLADAFW::MeshPrimitive::LINES:
return "LINES";
case COLLADAFW::MeshPrimitive::LINE_STRIPS:
return "LINESTRIPS";
case COLLADAFW::MeshPrimitive::POLYGONS:
return "POLYGONS";
case COLLADAFW::MeshPrimitive::POLYLIST:
return "POLYLIST";
case COLLADAFW::MeshPrimitive::TRIANGLES:
return "TRIANGLES";
case COLLADAFW::MeshPrimitive::TRIANGLE_FANS:
return "TRIANGLE_FANS";
case COLLADAFW::MeshPrimitive::TRIANGLE_STRIPS:
return "TRIANGLE_FANS";
case COLLADAFW::MeshPrimitive::POINTS:
return "POINTS";
case COLLADAFW::MeshPrimitive::UNDEFINED_PRIMITIVE_TYPE:
return "UNDEFINED_PRIMITIVE_TYPE";
}
return "UNKNOWN";
}
@ -97,43 +97,44 @@ static const char *bc_primTypeToStr(COLLADAFW::MeshPrimitive::PrimitiveType type
static const char *bc_geomTypeToStr(COLLADAFW::Geometry::GeometryType type)
{
switch (type) {
case COLLADAFW::Geometry::GEO_TYPE_MESH:
return "MESH";
case COLLADAFW::Geometry::GEO_TYPE_SPLINE:
return "SPLINE";
case COLLADAFW::Geometry::GEO_TYPE_CONVEX_MESH:
return "CONVEX_MESH";
case COLLADAFW::Geometry::GEO_TYPE_UNKNOWN:
default:
return "UNKNOWN";
case COLLADAFW::Geometry::GEO_TYPE_MESH:
return "MESH";
case COLLADAFW::Geometry::GEO_TYPE_SPLINE:
return "SPLINE";
case COLLADAFW::Geometry::GEO_TYPE_CONVEX_MESH:
return "CONVEX_MESH";
case COLLADAFW::Geometry::GEO_TYPE_UNKNOWN:
default:
return "UNKNOWN";
}
}
UVDataWrapper::UVDataWrapper(COLLADAFW::MeshVertexData& vdata) : mVData(&vdata)
{}
{
}
#ifdef COLLADA_DEBUG
void WVDataWrapper::print()
{
fprintf(stderr, "UVs:\n");
switch (mVData->getType()) {
case COLLADAFW::MeshVertexData::DATA_TYPE_FLOAT:
case COLLADAFW::MeshVertexData::DATA_TYPE_FLOAT:
{
COLLADAFW::ArrayPrimitiveType<float>* values = mVData->getFloatValues();
COLLADAFW::ArrayPrimitiveType<float> *values = mVData->getFloatValues();
if (values->getCount()) {
for (int i = 0; i < values->getCount(); i += 2) {
fprintf(stderr, "%.1f, %.1f\n", (*values)[i], (*values)[i+1]);
fprintf(stderr, "%.1f, %.1f\n", (*values)[i], (*values)[i + 1]);
}
}
}
break;
case COLLADAFW::MeshVertexData::DATA_TYPE_DOUBLE:
case COLLADAFW::MeshVertexData::DATA_TYPE_DOUBLE:
{
COLLADAFW::ArrayPrimitiveType<double>* values = mVData->getDoubleValues();
COLLADAFW::ArrayPrimitiveType<double> *values = mVData->getDoubleValues();
if (values->getCount()) {
for (int i = 0; i < values->getCount(); i += 2) {
fprintf(stderr, "%.1f, %.1f\n", (float)(*values)[i], (float)(*values)[i+1]);
fprintf(stderr, "%.1f, %.1f\n", (float)(*values)[i], (float)(*values)[i + 1]);
}
}
}
@ -146,30 +147,30 @@ void WVDataWrapper::print()
void UVDataWrapper::getUV(int uv_index, float *uv)
{
int stride = mVData->getStride(0);
if (stride==0) stride = 2;
if (stride == 0) stride = 2;
switch (mVData->getType()) {
case COLLADAFW::MeshVertexData::DATA_TYPE_FLOAT:
case COLLADAFW::MeshVertexData::DATA_TYPE_FLOAT:
{
COLLADAFW::ArrayPrimitiveType<float>* values = mVData->getFloatValues();
COLLADAFW::ArrayPrimitiveType<float> *values = mVData->getFloatValues();
if (values->empty()) return;
uv[0] = (*values)[uv_index*stride];
uv[1] = (*values)[uv_index*stride + 1];
uv[0] = (*values)[uv_index * stride];
uv[1] = (*values)[uv_index * stride + 1];
}
break;
case COLLADAFW::MeshVertexData::DATA_TYPE_DOUBLE:
case COLLADAFW::MeshVertexData::DATA_TYPE_DOUBLE:
{
COLLADAFW::ArrayPrimitiveType<double>* values = mVData->getDoubleValues();
COLLADAFW::ArrayPrimitiveType<double> *values = mVData->getDoubleValues();
if (values->empty()) return;
uv[0] = (float)(*values)[uv_index*stride];
uv[1] = (float)(*values)[uv_index*stride + 1];
uv[0] = (float)(*values)[uv_index * stride];
uv[1] = (float)(*values)[uv_index * stride + 1];
}
break;
case COLLADAFW::MeshVertexData::DATA_TYPE_UNKNOWN:
default:
fprintf(stderr, "MeshImporter.getUV(): unknown data type\n");
case COLLADAFW::MeshVertexData::DATA_TYPE_UNKNOWN:
default:
fprintf(stderr, "MeshImporter.getUV(): unknown data type\n");
}
}
@ -198,7 +199,7 @@ void MeshImporter::rotate_face_indices(MFace *mface)
#endif
void MeshImporter::set_face_uv(MTFace *mtface, UVDataWrapper &uvs,
COLLADAFW::IndexList& index_list, unsigned int *tris_indices)
COLLADAFW::IndexList& index_list, unsigned int *tris_indices)
{
// per face vertex indices, this means for quad we have 4 indices, not 8
COLLADAFW::UIntValuesArray& indices = index_list.getIndices();
@ -209,7 +210,7 @@ void MeshImporter::set_face_uv(MTFace *mtface, UVDataWrapper &uvs,
}
void MeshImporter::set_face_uv(MTFace *mtface, UVDataWrapper &uvs,
COLLADAFW::IndexList& index_list, int index, bool quad)
COLLADAFW::IndexList& index_list, int index, bool quad)
{
// per face vertex indices, this means for quad we have 4 indices, not 8
COLLADAFW::UIntValuesArray& indices = index_list.getIndices();
@ -223,31 +224,31 @@ void MeshImporter::set_face_uv(MTFace *mtface, UVDataWrapper &uvs,
#ifdef COLLADA_DEBUG
if (quad) {
fprintf(stderr, "face uv:\n"
"((%d, %d, %d, %d))\n"
"((%.1f, %.1f), (%.1f, %.1f), (%.1f, %.1f), (%.1f, %.1f))\n",
"((%d, %d, %d, %d))\n"
"((%.1f, %.1f), (%.1f, %.1f), (%.1f, %.1f), (%.1f, %.1f))\n",
indices[index + 0],
indices[index + 1],
indices[index + 2],
indices[index + 3],
indices[index + 0],
indices[index + 1],
indices[index + 2],
indices[index + 3],
mtface->uv[0][0], mtface->uv[0][1],
mtface->uv[1][0], mtface->uv[1][1],
mtface->uv[2][0], mtface->uv[2][1],
mtface->uv[3][0], mtface->uv[3][1]);
mtface->uv[0][0], mtface->uv[0][1],
mtface->uv[1][0], mtface->uv[1][1],
mtface->uv[2][0], mtface->uv[2][1],
mtface->uv[3][0], mtface->uv[3][1]);
}
else {
fprintf(stderr, "face uv:\n"
"((%d, %d, %d))\n"
"((%.1f, %.1f), (%.1f, %.1f), (%.1f, %.1f))\n",
"((%d, %d, %d))\n"
"((%.1f, %.1f), (%.1f, %.1f), (%.1f, %.1f))\n",
indices[index + 0],
indices[index + 1],
indices[index + 2],
indices[index + 0],
indices[index + 1],
indices[index + 2],
mtface->uv[0][0], mtface->uv[0][1],
mtface->uv[1][0], mtface->uv[1][1],
mtface->uv[2][0], mtface->uv[2][1]);
mtface->uv[0][0], mtface->uv[0][1],
mtface->uv[1][0], mtface->uv[1][1],
mtface->uv[2][0], mtface->uv[2][1]);
}
#endif
}
@ -263,7 +264,7 @@ void MeshImporter::print_index_list(COLLADAFW::IndexList& index_list)
}
#endif
bool MeshImporter::is_nice_mesh(COLLADAFW::Mesh *mesh) // checks if mesh has supported primitive types: lines, polylist, triangles, triangle_fans
bool MeshImporter::is_nice_mesh(COLLADAFW::Mesh *mesh) // checks if mesh has supported primitive types: lines, polylist, triangles, triangle_fans
{
COLLADAFW::MeshPrimitiveArray& prim_arr = mesh->getMeshPrimitives();
@ -279,26 +280,26 @@ bool MeshImporter::is_nice_mesh(COLLADAFW::Mesh *mesh) // checks if mesh has sup
// OpenCollada passes POLYGONS type for <polylist>
if (type == COLLADAFW::MeshPrimitive::POLYLIST || type == COLLADAFW::MeshPrimitive::POLYGONS) {
COLLADAFW::Polygons *mpvc = (COLLADAFW::Polygons*)mp;
COLLADAFW::Polygons *mpvc = (COLLADAFW::Polygons *)mp;
COLLADAFW::Polygons::VertexCountArray& vca = mpvc->getGroupedVerticesVertexCountArray();
for (unsigned int j = 0; j < vca.getCount(); j++) {
int count = vca[j];
if (count < 3) {
fprintf(stderr, "Primitive %s in %s has at least one face with vertex count < 3\n",
type_str, name);
type_str, name);
return false;
}
}
}
else if ( type == COLLADAFW::MeshPrimitive::LINES )
else if (type == COLLADAFW::MeshPrimitive::LINES)
{
// TODO: Add Checker for line syntax here
}
else if (type != COLLADAFW::MeshPrimitive::TRIANGLES && type!= COLLADAFW::MeshPrimitive::TRIANGLE_FANS) {
else if (type != COLLADAFW::MeshPrimitive::TRIANGLES && type != COLLADAFW::MeshPrimitive::TRIANGLE_FANS) {
fprintf(stderr, "Primitive type %s is not supported.\n", type_str);
return false;
}
@ -317,10 +318,10 @@ void MeshImporter::read_vertices(COLLADAFW::Mesh *mesh, Mesh *me)
// vertices
COLLADAFW::MeshVertexData& pos = mesh->getPositions();
int stride = pos.getStride(0);
if (stride==0) stride = 3;
if (stride == 0) stride = 3;
me->totvert = mesh->getPositions().getFloatValues()->getCount() / stride;
me->mvert = (MVert*)CustomData_add_layer(&me->vdata, CD_MVERT, CD_CALLOC, NULL, me->totvert);
me->mvert = (MVert *)CustomData_add_layer(&me->vdata, CD_MVERT, CD_CALLOC, NULL, me->totvert);
MVert *mvert;
int i;
@ -339,12 +340,12 @@ int MeshImporter::triangulate_poly(unsigned int *indices, int totvert, MVert *ve
dispbase.first = dispbase.last = NULL;
dl = (DispList*)MEM_callocN(sizeof(DispList), "poly disp");
dl = (DispList *)MEM_callocN(sizeof(DispList), "poly disp");
dl->nr = totvert;
dl->type = DL_POLY;
dl->parts = 1;
dl->verts = vert = (float*)MEM_callocN(totvert * 3 * sizeof(float), "poly verts");
dl->index = (int*)MEM_callocN(sizeof(int) * 3 * totvert, "dl index");
dl->verts = vert = (float *)MEM_callocN(totvert * 3 * sizeof(float), "poly verts");
dl->index = (int *)MEM_callocN(sizeof(int) * 3 * totvert, "dl index");
BLI_addtail(&dispbase, dl);
@ -356,14 +357,14 @@ int MeshImporter::triangulate_poly(unsigned int *indices, int totvert, MVert *ve
BKE_displist_fill(&dispbase, &dispbase, 0);
int tottri = 0;
dl= (DispList*)dispbase.first;
dl = (DispList *)dispbase.first;
if (dl->type == DL_INDEX3) {
tottri = dl->parts;
int *index = dl->index;
for (i= 0; i < tottri; i++) {
int t[3]= {*index, *(index + 1), *(index + 2)};
for (i = 0; i < tottri; i++) {
int t[3] = {*index, *(index + 1), *(index + 2)};
std::sort(t, t + 3);
@ -394,9 +395,9 @@ int MeshImporter::count_new_tris(COLLADAFW::Mesh *mesh, Mesh *me)
unsigned int *indices = mp->getPositionIndices().getData();
if (type == COLLADAFW::MeshPrimitive::POLYLIST ||
type == COLLADAFW::MeshPrimitive::POLYGONS) {
COLLADAFW::Polygons *mpvc = (COLLADAFW::Polygons*)mp;
type == COLLADAFW::MeshPrimitive::POLYGONS)
{
COLLADAFW::Polygons *mpvc = (COLLADAFW::Polygons *)mp;
COLLADAFW::Polygons::VertexCountArray& vcounta = mpvc->getGroupedVerticesVertexCountArray();
for (unsigned int j = 0; j < prim_totface; j++) {
@ -433,8 +434,8 @@ bool MeshImporter::primitive_has_useable_normals(COLLADAFW::MeshPrimitive *mp) {
has_useable_normals = true;
else {
fprintf(stderr,
"Warning: Number of normals %d is different from the number of vertices %d, skipping normals\n",
normals_count, index_count );
"Warning: Number of normals %d is different from the number of vertices %d, skipping normals\n",
normals_count, index_count);
}
}
@ -496,7 +497,7 @@ void MeshImporter::allocate_face_data(COLLADAFW::Mesh *mesh, Mesh *me, int new_t
// allocate space for faces
if (total_facecount > 0) {
me->totface = total_facecount + new_tris;
me->mface = (MFace*)CustomData_add_layer(&me->fdata, CD_MFACE, CD_CALLOC, NULL, me->totface);
me->mface = (MFace *)CustomData_add_layer(&me->fdata, CD_MFACE, CD_CALLOC, NULL, me->totface);
}
}
@ -566,7 +567,7 @@ void MeshImporter::mesh_add_edges(Mesh *mesh, int len)
void MeshImporter::read_lines(COLLADAFW::Mesh *mesh, Mesh *me)
{
unsigned int loose_edge_count = get_loose_edge_count(mesh);
if(loose_edge_count > 0) {
if (loose_edge_count > 0) {
unsigned int face_edge_count = me->totedge;
unsigned int total_edge_count = loose_edge_count + face_edge_count;
@ -587,11 +588,11 @@ void MeshImporter::read_lines(COLLADAFW::Mesh *mesh, Mesh *me)
unsigned int *indices = mp->getPositionIndices().getData();
for (int i = 0; i < edge_count; i++, med++) {
med->bweight= 0;
med->crease = 0;
med->flag = 0;
med->v1 = indices[ 2*i ];
med->v2 = indices[ 2*i + 1];
med->bweight = 0;
med->crease = 0;
med->flag = 0;
med->v1 = indices[2 * i];
med->v2 = indices[2 * i + 1];
}
}
}
@ -630,7 +631,7 @@ void MeshImporter::read_faces(COLLADAFW::Mesh *mesh, Mesh *me, int new_tris) //T
}
// activate the first uv map
if (totuvset) me->mtface = (MTFace*)CustomData_get_layer_n(&me->fdata, CD_MTFACE, 0);
if (totuvset) me->mtface = (MTFace *)CustomData_get_layer_n(&me->fdata, CD_MTFACE, 0);
UVDataWrapper uvs(mesh->getUVCoords());
@ -669,11 +670,11 @@ void MeshImporter::read_faces(COLLADAFW::Mesh *mesh, Mesh *me, int new_tris) //T
#ifdef COLLADA_DEBUG
/*
fprintf(stderr, "Primitive %d:\n", i);
for (unsigned int j = 0; j < totuvset; j++) {
print_index_list(*index_list_array[j]);
}
*/
fprintf(stderr, "Primitive %d:\n", i);
for (unsigned int j = 0; j < totuvset; j++) {
print_index_list(*index_list_array[j]);
}
*/
#endif
if (type == COLLADAFW::MeshPrimitive::TRIANGLES) {
@ -686,14 +687,14 @@ void MeshImporter::read_faces(COLLADAFW::Mesh *mesh, Mesh *me, int new_tris) //T
for (unsigned int k = 0; k < totuvset; k++) {
if (!index_list_array.empty() && index_list_array[k]) {
// get mtface by face index and uv set index
MTFace *mtface = (MTFace*)CustomData_get_layer_n(&me->fdata, CD_MTFACE, k);
MTFace *mtface = (MTFace *)CustomData_get_layer_n(&me->fdata, CD_MTFACE, k);
set_face_uv(&mtface[face_index], uvs, k, *index_list_array[k], index, false);
}
}
#else
for (unsigned int k = 0; k < index_list_array.getCount(); k++) {
// get mtface by face index and uv set index
MTFace *mtface = (MTFace*)CustomData_get_layer_n(&me->fdata, CD_MTFACE, k);
MTFace *mtface = (MTFace *)CustomData_get_layer_n(&me->fdata, CD_MTFACE, k);
set_face_uv(&mtface[face_index], uvs, *index_list_array[k], index, false);
}
#endif
@ -725,24 +726,24 @@ void MeshImporter::read_faces(COLLADAFW::Mesh *mesh, Mesh *me, int new_tris) //T
for (unsigned int vertex_index = 0; vertex_index < vertex_count - 2; vertex_index++) {
// For each triangle store indeces of its 3 vertices
unsigned int triangle_vertex_indices[3]={first_vertex, indices[1], indices[2]};
unsigned int triangle_vertex_indices[3] = {first_vertex, indices[1], indices[2]};
set_face_indices(mface, triangle_vertex_indices, false);
test_index_face(mface, &me->fdata, face_index, 3);
if (mp_has_normals) { // vertex normals, same inplementation as for the triangles
// the same for vertces normals
unsigned int vertex_normal_indices[3]={first_normal, nind[1], nind[2]};
unsigned int vertex_normal_indices[3] = {first_normal, nind[1], nind[2]};
if (!flat_face(vertex_normal_indices, nor, 3))
mface->flag |= ME_SMOOTH;
nind++;
}
mface++; // same inplementation as for the triangles
indices++;
face_index++;
prim.totface++;
nind++;
}
mface++; // same inplementation as for the triangles
indices++;
face_index++;
prim.totface++;
}
// Moving cursor to the next triangle fan.
if (mp_has_normals)
nind += 2;
@ -751,7 +752,7 @@ void MeshImporter::read_faces(COLLADAFW::Mesh *mesh, Mesh *me, int new_tris) //T
}
}
else if (type == COLLADAFW::MeshPrimitive::POLYLIST || type == COLLADAFW::MeshPrimitive::POLYGONS) {
COLLADAFW::Polygons *mpvc = (COLLADAFW::Polygons*)mp;
COLLADAFW::Polygons *mpvc = (COLLADAFW::Polygons *)mp;
COLLADAFW::Polygons::VertexCountArray& vcounta = mpvc->getGroupedVerticesVertexCountArray();
for (unsigned int j = 0; j < prim_totface; j++) {
@ -769,14 +770,14 @@ void MeshImporter::read_faces(COLLADAFW::Mesh *mesh, Mesh *me, int new_tris) //T
for (unsigned int k = 0; k < totuvset; k++) {
if (!index_list_array.empty() && index_list_array[k]) {
// get mtface by face index and uv set index
MTFace *mtface = (MTFace*)CustomData_get_layer_n(&me->fdata, CD_MTFACE, k);
MTFace *mtface = (MTFace *)CustomData_get_layer_n(&me->fdata, CD_MTFACE, k);
set_face_uv(&mtface[face_index], uvs, k, *index_list_array[k], index, mface->v4 != 0);
}
}
#else
for (unsigned int k = 0; k < index_list_array.getCount(); k++) {
// get mtface by face index and uv set index
MTFace *mtface = (MTFace*)CustomData_get_layer_n(&me->fdata, CD_MTFACE, k);
MTFace *mtface = (MTFace *)CustomData_get_layer_n(&me->fdata, CD_MTFACE, k);
set_face_uv(&mtface[face_index], uvs, *index_list_array[k], index, vcount == 4);
}
#endif
@ -819,7 +820,7 @@ void MeshImporter::read_faces(COLLADAFW::Mesh *mesh, Mesh *me, int new_tris) //T
for (unsigned int l = 0; l < totuvset; l++) {
if (!index_list_array.empty() && index_list_array[l]) {
// get mtface by face index and uv set index
MTFace *mtface = (MTFace*)CustomData_get_layer_n(&me->fdata, CD_MTFACE, l);
MTFace *mtface = (MTFace *)CustomData_get_layer_n(&me->fdata, CD_MTFACE, l);
set_face_uv(&mtface[face_index], uvs, l, *index_list_array[l], uv_indices);
}
}
@ -828,7 +829,7 @@ void MeshImporter::read_faces(COLLADAFW::Mesh *mesh, Mesh *me, int new_tris) //T
int uvset_index = index_list_array[l]->getSetIndex();
// get mtface by face index and uv set index
MTFace *mtface = (MTFace*)CustomData_get_layer_n(&me->fdata, CD_MTFACE, uvset_index);
MTFace *mtface = (MTFace *)CustomData_get_layer_n(&me->fdata, CD_MTFACE, uvset_index);
set_face_uv(&mtface[face_index], uvs, *index_list_array[l], uv_indices);
}
#endif
@ -873,9 +874,9 @@ void MeshImporter::get_vector(float v[3], COLLADAFW::MeshVertexData& arr, int i,
i *= stride;
switch (arr.getType()) {
case COLLADAFW::MeshVertexData::DATA_TYPE_FLOAT:
case COLLADAFW::MeshVertexData::DATA_TYPE_FLOAT:
{
COLLADAFW::ArrayPrimitiveType<float>* values = arr.getFloatValues();
COLLADAFW::ArrayPrimitiveType<float> *values = arr.getFloatValues();
if (values->empty()) return;
v[0] = (*values)[i++];
@ -884,9 +885,9 @@ void MeshImporter::get_vector(float v[3], COLLADAFW::MeshVertexData& arr, int i,
}
break;
case COLLADAFW::MeshVertexData::DATA_TYPE_DOUBLE:
case COLLADAFW::MeshVertexData::DATA_TYPE_DOUBLE:
{
COLLADAFW::ArrayPrimitiveType<double>* values = arr.getDoubleValues();
COLLADAFW::ArrayPrimitiveType<double> *values = arr.getDoubleValues();
if (values->empty()) return;
v[0] = (float)(*values)[i++];
@ -894,8 +895,8 @@ void MeshImporter::get_vector(float v[3], COLLADAFW::MeshVertexData& arr, int i,
v[2] = (float)(*values)[i];
}
break;
default:
break;
default:
break;
}
}
@ -921,12 +922,13 @@ bool MeshImporter::flat_face(unsigned int *nind, COLLADAFW::MeshVertexData& nor,
return true;
}
MeshImporter::MeshImporter(UnitConverter *unitconv, ArmatureImporter *arm, Scene *sce) : unitconverter(unitconv), scene(sce), armature_importer(arm) {}
MeshImporter::MeshImporter(UnitConverter *unitconv, ArmatureImporter *arm, Scene *sce) : unitconverter(unitconv), scene(sce), armature_importer(arm) {
}
void MeshImporter::bmeshConversion()
{
for (std::map<COLLADAFW::UniqueId, Mesh*>::iterator m = uid_mesh_map.begin();
m != uid_mesh_map.end(); ++m)
for (std::map<COLLADAFW::UniqueId, Mesh *>::iterator m = uid_mesh_map.begin();
m != uid_mesh_map.end(); ++m)
{
if ((*m).second) {
Mesh *me = (*m).second;
@ -947,21 +949,21 @@ Object *MeshImporter::get_object_by_geom_uid(const COLLADAFW::UniqueId& geom_uid
}
MTex *MeshImporter::assign_textures_to_uvlayer(COLLADAFW::TextureCoordinateBinding &ctexture,
Mesh *me, TexIndexTextureArrayMap& texindex_texarray_map,
MTex *color_texture)
Mesh *me, TexIndexTextureArrayMap& texindex_texarray_map,
MTex *color_texture)
{
const COLLADAFW::TextureMapId texture_index = ctexture.getTextureMapId();
size_t setindex = ctexture.getSetIndex();
std::string uvname = ctexture.getSemantic();
if (setindex==-1) return NULL;
if (setindex == -1) return NULL;
const CustomData *data = &me->fdata;
int layer_index = CustomData_get_layer_index(data, CD_MTFACE);
if (layer_index == -1) return NULL;
CustomDataLayer *cdl = &data->layers[layer_index+setindex];
CustomDataLayer *cdl = &data->layers[layer_index + setindex];
/* set uvname to bind_vertex_input semantic */
BLI_strncpy(cdl->name, uvname.c_str(), sizeof(cdl->name));
@ -972,9 +974,9 @@ MTex *MeshImporter::assign_textures_to_uvlayer(COLLADAFW::TextureCoordinateBindi
return color_texture;
}
std::vector<MTex*> textures = texindex_texarray_map[texture_index];
std::vector<MTex *> textures = texindex_texarray_map[texture_index];
std::vector<MTex*>::iterator it;
std::vector<MTex *>::iterator it;
for (it = textures.begin(); it != textures.end(); it++) {
@ -989,12 +991,12 @@ MTex *MeshImporter::assign_textures_to_uvlayer(COLLADAFW::TextureCoordinateBindi
}
MTFace *MeshImporter::assign_material_to_geom(COLLADAFW::MaterialBinding cmaterial,
std::map<COLLADAFW::UniqueId, Material*>& uid_material_map,
Object *ob, const COLLADAFW::UniqueId *geom_uid,
MTex **color_texture, char *layername, MTFace *texture_face,
std::map<Material*, TexIndexTextureArrayMap>& material_texture_mapping_map, short mat_index)
std::map<COLLADAFW::UniqueId, Material *>& uid_material_map,
Object *ob, const COLLADAFW::UniqueId *geom_uid,
MTex **color_texture, char *layername, MTFace *texture_face,
std::map<Material *, TexIndexTextureArrayMap>& material_texture_mapping_map, short mat_index)
{
Mesh *me = (Mesh*)ob->data;
Mesh *me = (Mesh *)ob->data;
const COLLADAFW::UniqueId& ma_uid = cmaterial.getReferencedMaterial();
// do we know this material?
@ -1008,9 +1010,9 @@ MTFace *MeshImporter::assign_material_to_geom(COLLADAFW::MaterialBinding cmateri
// again. Make sure we don't overwrite them on the next occurrences, so keep list of
// what we already have handled.
std::multimap<COLLADAFW::UniqueId, COLLADAFW::UniqueId>::iterator it;
it=materials_mapped_to_geom.find(*geom_uid);
while (it!=materials_mapped_to_geom.end()) {
if (it->second == ma_uid && it->first == *geom_uid) return NULL; // do nothing if already found
it = materials_mapped_to_geom.find(*geom_uid);
while (it != materials_mapped_to_geom.end()) {
if (it->second == ma_uid && it->first == *geom_uid) return NULL; // do nothing if already found
it++;
}
// first time we get geom_uid, ma_uid pair. Save for later check.
@ -1020,22 +1022,22 @@ MTFace *MeshImporter::assign_material_to_geom(COLLADAFW::MaterialBinding cmateri
assign_material(ob, ma, ob->totcol + 1);
COLLADAFW::TextureCoordinateBindingArray& tex_array =
cmaterial.getTextureCoordinateBindingArray();
cmaterial.getTextureCoordinateBindingArray();
TexIndexTextureArrayMap texindex_texarray_map = material_texture_mapping_map[ma];
unsigned int i;
// loop through <bind_vertex_inputs>
for (i = 0; i < tex_array.getCount(); i++) {
*color_texture = assign_textures_to_uvlayer(tex_array[i], me, texindex_texarray_map,
*color_texture);
*color_texture);
}
// set texture face
if (*color_texture &&
strlen((*color_texture)->uvname) &&
strcmp(layername, (*color_texture)->uvname) != 0) {
texture_face = (MTFace*)CustomData_get_layer_named(&me->fdata, CD_MTFACE,
(*color_texture)->uvname);
strlen((*color_texture)->uvname) &&
strcmp(layername, (*color_texture)->uvname) != 0) {
texture_face = (MTFace *)CustomData_get_layer_named(&me->fdata, CD_MTFACE,
(*color_texture)->uvname);
strcpy(layername, (*color_texture)->uvname);
}
@ -1057,7 +1059,7 @@ MTFace *MeshImporter::assign_material_to_geom(COLLADAFW::MaterialBinding cmateri
mface->mat_nr = mat_index;
// bind texture images to faces
if (texture_face && (*color_texture)) {
texture_face->tpage = (Image*)(*color_texture)->tex->ima;
texture_face->tpage = (Image *)(*color_texture)->tex->ima;
texture_face++;
}
}
@ -1068,9 +1070,9 @@ MTFace *MeshImporter::assign_material_to_geom(COLLADAFW::MaterialBinding cmateri
}
Object *MeshImporter::create_mesh_object(COLLADAFW::Node *node, COLLADAFW::InstanceGeometry *geom,
bool isController,
std::map<COLLADAFW::UniqueId, Material*>& uid_material_map,
std::map<Material*, TexIndexTextureArrayMap>& material_texture_mapping_map)
bool isController,
std::map<COLLADAFW::UniqueId, Material *>& uid_material_map,
std::map<Material *, TexIndexTextureArrayMap>& material_texture_mapping_map)
{
const COLLADAFW::UniqueId *geom_uid = &geom->getInstanciatedObjectId();
@ -1097,7 +1099,7 @@ Object *MeshImporter::create_mesh_object(COLLADAFW::Node *node, COLLADAFW::Insta
// name Object
const std::string& id = node->getName().size() ? node->getName() : node->getOriginalId();
const char *name = (id.length())? id.c_str(): NULL;
const char *name = (id.length()) ? id.c_str() : NULL;
// add object
Object *ob = bc_add_object(scene, OB_MESH, name);
@ -1106,7 +1108,7 @@ Object *MeshImporter::create_mesh_object(COLLADAFW::Node *node, COLLADAFW::Insta
uid_object_map[*geom_uid] = ob;
// replace ob->data freeing the old one
Mesh *old_mesh = (Mesh*)ob->data;
Mesh *old_mesh = (Mesh *)ob->data;
set_mesh(ob, uid_mesh_map[*geom_uid]);
@ -1118,15 +1120,15 @@ Object *MeshImporter::create_mesh_object(COLLADAFW::Node *node, COLLADAFW::Insta
MTex *color_texture = NULL;
COLLADAFW::MaterialBindingArray& mat_array =
geom->getMaterialBindings();
geom->getMaterialBindings();
// loop through geom's materials
for (unsigned int i = 0; i < mat_array.getCount(); i++) {
for (unsigned int i = 0; i < mat_array.getCount(); i++) {
if (mat_array[i].getReferencedMaterial().isValid()) {
texture_face = assign_material_to_geom(mat_array[i], uid_material_map, ob, geom_uid,
&color_texture, layername, texture_face,
material_texture_mapping_map, i);
&color_texture, layername, texture_face,
material_texture_mapping_map, i);
}
else {
fprintf(stderr, "invalid referenced material for %s\n", mat_array[i].getName().c_str());
@ -1137,7 +1139,7 @@ Object *MeshImporter::create_mesh_object(COLLADAFW::Node *node, COLLADAFW::Insta
}
// create a mesh storing a pointer in a map so it can be retrieved later by geometry UID
bool MeshImporter::write_geometry(const COLLADAFW::Geometry* geom)
bool MeshImporter::write_geometry(const COLLADAFW::Geometry *geom)
{
// TODO: import also uvs, normals
// XXX what to do with normal indices?
@ -1150,7 +1152,7 @@ bool MeshImporter::write_geometry(const COLLADAFW::Geometry* geom)
return true;
}
COLLADAFW::Mesh *mesh = (COLLADAFW::Mesh*)geom;
COLLADAFW::Mesh *mesh = (COLLADAFW::Mesh *)geom;
if (!is_nice_mesh(mesh)) {
fprintf(stderr, "Ignoring mesh %s\n", bc_get_dae_name(mesh));
@ -1158,7 +1160,7 @@ bool MeshImporter::write_geometry(const COLLADAFW::Geometry* geom)
}
const std::string& str_geom_id = mesh->getName().size() ? mesh->getName() : mesh->getOriginalId();
Mesh *me = BKE_mesh_add((char*)str_geom_id.c_str());
Mesh *me = BKE_mesh_add((char *)str_geom_id.c_str());
me->id.us--; // is already 1 here, but will be set later in set_mesh
// store the Mesh pointer to link it later with an Object

@ -30,7 +30,8 @@
SceneExporter::SceneExporter(COLLADASW::StreamWriter *sw, ArmatureExporter *arm, const ExportSettings *export_settings)
: COLLADASW::LibraryVisualScenes(sw), arm_exporter(arm), export_settings(export_settings)
{}
{
}
void SceneExporter::exportScene(Scene *sce)
{
@ -48,14 +49,14 @@ void SceneExporter::exportHierarchy(Scene *sce)
std::vector<Object *> base_objects;
// Ensure all objects in the export_set are marked
for(node = this->export_settings->export_set; node; node = node->next) {
Object *ob = (Object*) node->link;
for (node = this->export_settings->export_set; node; node = node->next) {
Object *ob = (Object *) node->link;
ob->id.flag |= LIB_DOIT;
}
// Now find all exportable base ojects (highest in export hierarchy)
for(node = this->export_settings->export_set; node; node = node->next) {
Object *ob = (Object*) node->link;
for (node = this->export_settings->export_set; node; node = node->next) {
Object *ob = (Object *) node->link;
if (bc_is_base_node(this->export_settings->export_set, ob))
{
switch (ob->type) {
@ -71,7 +72,7 @@ void SceneExporter::exportHierarchy(Scene *sce)
}
// And now export the base objects:
for(int index=0; index < base_objects.size(); index++) {
for (int index = 0; index < base_objects.size(); index++) {
Object *ob = base_objects[index];
if (bc_is_marked(ob)) {
bc_remove_mark(ob);
@ -84,7 +85,7 @@ void SceneExporter::writeNodes(Object *ob, Scene *sce)
{
// Add associated armature first if available
Object *ob_arm = bc_get_assigned_armature(ob);
if(ob_arm != NULL && bc_is_marked(ob_arm)) {
if (ob_arm != NULL && bc_is_marked(ob_arm)) {
bc_remove_mark(ob_arm);
writeNodes(ob_arm, sce);
}
@ -97,10 +98,10 @@ void SceneExporter::writeNodes(Object *ob, Scene *sce)
colladaNode.start();
bool is_skinned_mesh = arm_exporter->is_skinned_mesh(ob);
std::list<Object*> child_objects;
std::list<Object *> child_objects;
// list child objects
LinkNode *node = this->export_settings->export_set ;
LinkNode *node = this->export_settings->export_set;
while (node) {
// cob - child object
Object *cob = (Object *)node->link;
@ -132,7 +133,7 @@ void SceneExporter::writeNodes(Object *ob, Scene *sce)
if (this->export_settings->include_armatures && is_skinned_mesh) {
instance_controller_created = arm_exporter->add_instance_controller(ob);
}
if (!instance_controller_created){
if (!instance_controller_created) {
COLLADASW::InstanceGeometry instGeom(mSW);
instGeom.setUrl(COLLADASW::URI(COLLADABU::Utils::EMPTY_STRING, get_geometry_id(ob, this->export_settings->use_object_instantiation)));
@ -165,7 +166,7 @@ void SceneExporter::writeNodes(Object *ob, Scene *sce)
GroupObject *go = NULL;
Group *gr = ob->dup_group;
/* printf("group detected '%s'\n", gr->id.name+2); */
for (go = (GroupObject*)(gr->gobject.first); go; go=go->next) {
for (go = (GroupObject *)(gr->gobject.first); go; go = go->next) {
printf("\t%s\n", go->ob->id.name);
}
}
@ -175,8 +176,8 @@ void SceneExporter::writeNodes(Object *ob, Scene *sce)
colladaNode.end();
}
for (std::list<Object*>::iterator i= child_objects.begin(); i != child_objects.end(); ++i) {
if(bc_is_marked(*i)) {
for (std::list<Object *>::iterator i = child_objects.begin(); i != child_objects.end(); ++i) {
if (bc_is_marked(*i)) {
bc_remove_mark(*i);
writeNodes(*i, sce);
}

@ -57,14 +57,15 @@ static const char *bc_get_joint_name(T *node)
// This is used to store data passed in write_controller_data.
// Arrays from COLLADAFW::SkinControllerData lose ownership, so do this class members
// so that arrays don't get freed until we free them explicitly.
SkinInfo::SkinInfo() {}
SkinInfo::SkinInfo() {
}
SkinInfo::SkinInfo(const SkinInfo& skin) : weights(skin.weights),
joint_data(skin.joint_data),
unit_converter(skin.unit_converter),
ob_arm(skin.ob_arm),
controller_uid(skin.controller_uid),
parent(skin.parent)
joint_data(skin.joint_data),
unit_converter(skin.unit_converter),
ob_arm(skin.ob_arm),
controller_uid(skin.controller_uid),
parent(skin.parent)
{
copy_m4_m4(bind_shape_matrix, (float (*)[4])skin.bind_shape_matrix);
@ -73,7 +74,8 @@ SkinInfo::SkinInfo(const SkinInfo& skin) : weights(skin.weights),
transfer_int_array_data_const(skin.joint_indices, joint_indices);
}
SkinInfo::SkinInfo(UnitConverter *conv) : unit_converter(conv), ob_arm(NULL), parent(NULL) {}
SkinInfo::SkinInfo(UnitConverter *conv) : unit_converter(conv), ob_arm(NULL), parent(NULL) {
}
// nobody owns the data after this, so it should be freed manually with releaseMemory
template <class T>
@ -87,21 +89,21 @@ void SkinInfo::transfer_array_data(T& src, T& dest)
// when src is const we cannot src.yieldOwnerShip, this is used by copy constructor
void SkinInfo::transfer_int_array_data_const(const COLLADAFW::IntValuesArray& src, COLLADAFW::IntValuesArray& dest)
{
dest.setData((int*)src.getData(), src.getCount());
dest.setData((int *)src.getData(), src.getCount());
dest.yieldOwnerShip();
}
void SkinInfo::transfer_uint_array_data_const(const COLLADAFW::UIntValuesArray& src, COLLADAFW::UIntValuesArray& dest)
{
dest.setData((unsigned int*)src.getData(), src.getCount());
dest.setData((unsigned int *)src.getData(), src.getCount());
dest.yieldOwnerShip();
}
void SkinInfo::borrow_skin_controller_data(const COLLADAFW::SkinControllerData* skin)
void SkinInfo::borrow_skin_controller_data(const COLLADAFW::SkinControllerData *skin)
{
transfer_array_data((COLLADAFW::UIntValuesArray&)skin->getJointsPerVertex(), joints_per_vertex);
transfer_array_data((COLLADAFW::UIntValuesArray&)skin->getWeightIndices(), weight_indices);
transfer_array_data((COLLADAFW::IntValuesArray&)skin->getJointIndices(), joint_indices);
transfer_array_data((COLLADAFW::UIntValuesArray &)skin->getJointsPerVertex(), joints_per_vertex);
transfer_array_data((COLLADAFW::UIntValuesArray &)skin->getWeightIndices(), weight_indices);
transfer_array_data((COLLADAFW::IntValuesArray &)skin->getJointIndices(), joint_indices);
// transfer_array_data(skin->getWeights(), weights);
// cannot transfer data for FloatOrDoubleArray, copy values manually
@ -130,7 +132,7 @@ void SkinInfo::add_joint(const COLLADABU::Math::Matrix4& matrix)
joint_data.push_back(jd);
}
void SkinInfo::set_controller(const COLLADAFW::SkinController* co)
void SkinInfo::set_controller(const COLLADAFW::SkinController *co)
{
controller_uid = co->getUniqueId();
@ -155,7 +157,7 @@ Object *SkinInfo::create_armature(Scene *scene)
return ob_arm;
}
Object* SkinInfo::set_armature(Object *ob_arm)
Object *SkinInfo::set_armature(Object *ob_arm)
{
if (this->ob_arm)
return this->ob_arm;
@ -211,8 +213,8 @@ bool SkinInfo::uses_joint_or_descendant(COLLADAFW::Node *node)
return false;
}
void SkinInfo::link_armature(bContext *C, Object *ob, std::map<COLLADAFW::UniqueId, COLLADAFW::Node*>& joint_by_uid,
TransformReader *tm)
void SkinInfo::link_armature(bContext *C, Object *ob, std::map<COLLADAFW::UniqueId, COLLADAFW::Node *>& joint_by_uid,
TransformReader *tm)
{
Main *bmain = CTX_data_main(C);
Scene *scene = CTX_data_scene(C);
@ -233,11 +235,11 @@ void SkinInfo::link_armature(bContext *C, Object *ob, std::map<COLLADAFW::Unique
BKE_object_workob_calc_parent(scene, ob, &workob);
invert_m4_m4(ob->parentinv, workob.obmat);
ob->recalc |= OB_RECALC_OB|OB_RECALC_DATA;
ob->recalc |= OB_RECALC_OB | OB_RECALC_DATA;
DAG_scene_sort(bmain, scene);
DAG_ids_flush_update(bmain, 0);
WM_event_add_notifier(C, NC_OBJECT|ND_TRANSFORM, NULL);
WM_event_add_notifier(C, NC_OBJECT | ND_TRANSFORM, NULL);
#endif
amd->deformflag = ARM_DEF_VGROUP;
@ -257,7 +259,7 @@ void SkinInfo::link_armature(bContext *C, Object *ob, std::map<COLLADAFW::Unique
name = bc_get_joint_name(joint_by_uid[(*it).joint_uid]);
}
ED_vgroup_add_name(ob, (char*)name);
ED_vgroup_add_name(ob, (char *)name);
}
// <vcount> - number of joints per vertex - joints_per_vertex
@ -274,12 +276,12 @@ void SkinInfo::link_armature(bContext *C, Object *ob, std::map<COLLADAFW::Unique
for (unsigned int vertex = 0, weight = 0; vertex < joints_per_vertex.getCount(); vertex++) {
unsigned int limit = weight + joints_per_vertex[vertex];
for ( ; weight < limit; weight++) {
for (; weight < limit; weight++) {
int joint = joint_indices[weight], joint_weight = weight_indices[weight];
// -1 means "weight towards the bind shape", we just don't assign it to any group
if (joint != -1) {
bDeformGroup *def = (bDeformGroup*)BLI_findlink(&ob->defbase, joint);
bDeformGroup *def = (bDeformGroup *)BLI_findlink(&ob->defbase, joint);
ED_vgroup_vert_add(ob, def, vertex, weights[joint_weight], WEIGHT_REPLACE);
}
@ -297,16 +299,16 @@ void SkinInfo::set_parent(Object *_parent)
parent = _parent;
}
Object* SkinInfo::get_parent()
Object *SkinInfo::get_parent()
{
return parent;
}
void SkinInfo::find_root_joints(const std::vector<COLLADAFW::Node*> &root_joints,
std::map<COLLADAFW::UniqueId, COLLADAFW::Node*>& joint_by_uid,
std::vector<COLLADAFW::Node*>& result)
void SkinInfo::find_root_joints(const std::vector<COLLADAFW::Node *> &root_joints,
std::map<COLLADAFW::UniqueId, COLLADAFW::Node *>& joint_by_uid,
std::vector<COLLADAFW::Node *>& result)
{
std::vector<COLLADAFW::Node*>::const_iterator it;
std::vector<COLLADAFW::Node *>::const_iterator it;
// for each root_joint
for (it = root_joints.begin(); it != root_joints.end(); it++) {
COLLADAFW::Node *root = *it;

@ -29,7 +29,8 @@
#include "TransformReader.h"
TransformReader::TransformReader(UnitConverter* conv) : unit_converter(conv) {}
TransformReader::TransformReader(UnitConverter *conv) : unit_converter(conv) {
}
void TransformReader::get_node_mat(float mat[][4], COLLADAFW::Node *node, std::map<COLLADAFW::UniqueId, Animation> *animation_map, Object *ob)
{
@ -43,7 +44,7 @@ void TransformReader::get_node_mat(float mat[][4], COLLADAFW::Node *node, std::m
COLLADAFW::Transformation *tm = node->getTransformations()[i];
COLLADAFW::Transformation::TransformationType type = tm->getTransformationType();
switch (type) {
switch (type) {
case COLLADAFW::Transformation::TRANSLATE:
dae_translate_to_mat4(tm, cur);
break;
@ -60,7 +61,7 @@ void TransformReader::get_node_mat(float mat[][4], COLLADAFW::Node *node, std::m
case COLLADAFW::Transformation::SKEW:
fprintf(stderr, "LOOKAT and SKEW transformations are not supported yet.\n");
break;
}
}
copy_m4_m4(copy, mat);
mult_m4_m4m4(mat, copy, cur);
@ -78,7 +79,7 @@ void TransformReader::get_node_mat(float mat[][4], COLLADAFW::Node *node, std::m
void TransformReader::dae_rotate_to_mat4(COLLADAFW::Transformation *tm, float m[][4])
{
COLLADAFW::Rotate *ro = (COLLADAFW::Rotate*)tm;
COLLADAFW::Rotate *ro = (COLLADAFW::Rotate *)tm;
COLLADABU::Math::Vector3& axis = ro->getRotationAxis();
const float angle = (float)DEG2RAD(ro->getRotationAngle());
const float ax[] = {axis[0], axis[1], axis[2]};
@ -90,7 +91,7 @@ void TransformReader::dae_rotate_to_mat4(COLLADAFW::Transformation *tm, float m[
void TransformReader::dae_translate_to_mat4(COLLADAFW::Transformation *tm, float m[][4])
{
COLLADAFW::Translate *tra = (COLLADAFW::Translate*)tm;
COLLADAFW::Translate *tra = (COLLADAFW::Translate *)tm;
COLLADABU::Math::Vector3& t = tra->getTranslation();
unit_m4(m);
@ -102,24 +103,24 @@ void TransformReader::dae_translate_to_mat4(COLLADAFW::Transformation *tm, float
void TransformReader::dae_scale_to_mat4(COLLADAFW::Transformation *tm, float m[][4])
{
COLLADABU::Math::Vector3& s = ((COLLADAFW::Scale*)tm)->getScale();
COLLADABU::Math::Vector3& s = ((COLLADAFW::Scale *)tm)->getScale();
float size[3] = {(float)s[0], (float)s[1], (float)s[2]};
size_to_mat4(m, size);
}
void TransformReader::dae_matrix_to_mat4(COLLADAFW::Transformation *tm, float m[][4])
{
unit_converter->dae_matrix_to_mat4_(m, ((COLLADAFW::Matrix*)tm)->getMatrix());
unit_converter->dae_matrix_to_mat4_(m, ((COLLADAFW::Matrix *)tm)->getMatrix());
}
void TransformReader::dae_translate_to_v3(COLLADAFW::Transformation *tm, float v[3])
{
dae_vector3_to_v3(((COLLADAFW::Translate*)tm)->getTranslation(), v);
dae_vector3_to_v3(((COLLADAFW::Translate *)tm)->getTranslation(), v);
}
void TransformReader::dae_scale_to_v3(COLLADAFW::Transformation *tm, float v[3])
{
dae_vector3_to_v3(((COLLADAFW::Scale*)tm)->getScale(), v);
dae_vector3_to_v3(((COLLADAFW::Scale *)tm)->getScale(), v);
}
void TransformReader::dae_vector3_to_v3(const COLLADABU::Math::Vector3 &v3, float v[3])

@ -47,11 +47,11 @@ void TransformWriter::add_node_transform(COLLADASW::Node& node, float mat[][4],
}
double dmat[4][4];
UnitConverter* converter = new UnitConverter();
UnitConverter *converter = new UnitConverter();
converter->mat4_to_dae_double(dmat, local);
TransformBase::decompose(local, loc, rot, NULL, scale);
if ( node.getType() == COLLADASW::Node::JOINT)
if (node.getType() == COLLADASW::Node::JOINT)
node.addMatrix("transform", dmat);
else
add_transform(node, loc, rot, scale);
@ -59,7 +59,7 @@ void TransformWriter::add_node_transform(COLLADASW::Node& node, float mat[][4],
void TransformWriter::add_node_transform_ob(COLLADASW::Node& node, Object *ob)
{
/*
#if 0
float rot[3], loc[3], scale[3];
if (ob->parent) {
@ -92,7 +92,7 @@ void TransformWriter::add_node_transform_ob(COLLADASW::Node& node, Object *ob)
}
add_transform(node, loc, rot, scale);
*/
#endif
/* Using parentinv should allow use of existing curves */
if (ob->parent) {
@ -124,9 +124,11 @@ void TransformWriter::add_node_transform_identity(COLLADASW::Node& node)
void TransformWriter::add_transform(COLLADASW::Node& node, float loc[3], float rot[3], float scale[3])
{
node.addTranslate("location", loc[0], loc[1], loc[2]);
/*node.addRotateZ("rotationZ", COLLADABU::Math::Utils::radToDegF(rot[2]));
#if 0
node.addRotateZ("rotationZ", COLLADABU::Math::Utils::radToDegF(rot[2]));
node.addRotateY("rotationY", COLLADABU::Math::Utils::radToDegF(rot[1]));
node.addRotateX("rotationX", COLLADABU::Math::Utils::radToDegF(rot[0]));*/
node.addRotateX("rotationX", COLLADABU::Math::Utils::radToDegF(rot[0]));
#endif
node.addRotateZ("rotationZ", RAD2DEGF(rot[2]));
node.addRotateY("rotationY", RAD2DEGF(rot[1]));
node.addRotateX("rotationX", RAD2DEGF(rot[0]));

@ -41,58 +41,60 @@ extern "C"
#include "BLI_fileops.h"
#include "BLI_path_util.h"
int collada_import(bContext *C, const char *filepath)
{
DocumentImporter imp (C, filepath);
if (imp.import()) return 1;
int collada_import(bContext *C, const char *filepath)
{
DocumentImporter imp(C, filepath);
if (imp.import()) return 1;
return 0;
}
int collada_export(
Scene *sce,
const char *filepath,
int selected,
int apply_modifiers,
int include_armatures,
int include_children,
int use_object_instantiation,
int second_life )
{
ExportSettings export_settings;
/* 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! */
export_settings.selected = selected != 0;
export_settings.apply_modifiers = apply_modifiers != 0;
export_settings.include_armatures = include_armatures != 0;
export_settings.include_children = include_children != 0;
export_settings.second_life = second_life != 0;
export_settings.use_object_instantiation = use_object_instantiation != 0;
export_settings.filepath = (char *)filepath;
int includeFilter = OB_REL_NONE;
if (export_settings.include_armatures) includeFilter |= OB_REL_MOD_ARMATURE;
if (export_settings.include_children) includeFilter |= OB_REL_CHILDREN_RECURSIVE;
eObjectSet objectSet = (export_settings.selected) ? OB_SET_SELECTED : OB_SET_ALL;
export_settings.export_set = BKE_object_relational_superset(sce, objectSet, (eObRelationTypes)includeFilter);
DocumentExporter exporter(&export_settings);
exporter.exportCurrentScene(sce);
BLI_linklist_free(export_settings.export_set, NULL);
return 1;
}
return 0;
}
int collada_export(
Scene *sce,
const char *filepath,
int selected,
int apply_modifiers,
int include_armatures,
int include_children,
int use_object_instantiation,
int second_life)
{
ExportSettings export_settings;
/* 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! */
export_settings.selected = selected != 0;
export_settings.apply_modifiers = apply_modifiers != 0;
export_settings.include_armatures = include_armatures != 0;
export_settings.include_children = include_children != 0;
export_settings.second_life = second_life != 0;
export_settings.use_object_instantiation = use_object_instantiation != 0;
export_settings.filepath = (char *)filepath;
int includeFilter = OB_REL_NONE;
if (export_settings.include_armatures) includeFilter |= OB_REL_MOD_ARMATURE;
if (export_settings.include_children) includeFilter |= OB_REL_CHILDREN_RECURSIVE;
eObjectSet objectSet = (export_settings.selected) ? OB_SET_SELECTED : OB_SET_ALL;
export_settings.export_set = BKE_object_relational_superset(sce, objectSet, (eObRelationTypes)includeFilter);
DocumentExporter exporter(&export_settings);
exporter.exportCurrentScene(sce);
BLI_linklist_free(export_settings.export_set, NULL);
return 1;
}
/* end extern C */
}

@ -31,9 +31,10 @@
#include "BLI_linklist.h"
UnitConverter::UnitConverter() : unit(), up_axis(COLLADAFW::FileInfo::Z_UP) {}
UnitConverter::UnitConverter() : unit(), up_axis(COLLADAFW::FileInfo::Z_UP) {
}
void UnitConverter::read_asset(const COLLADAFW::FileInfo* asset)
void UnitConverter::read_asset(const COLLADAFW::FileInfo *asset)
{
unit = asset->getUnit();
up_axis = asset->getUpAxisType();
@ -121,72 +122,74 @@ void TransformBase::decompose(float mat[][4], float *loc, float eul[3], float qu
* must obviously be removed too, otherwise they would be heavily misinterpreted.
*/
const unsigned char translate_start_name_map[256] = {
95, 95, 95, 95, 95, 95, 95, 95, 95,
95, 95, 95, 95, 95, 95, 95, 95,
95, 95, 95, 95, 95, 95, 95, 95,
95, 95, 95, 95, 95, 95, 95, 95,
95, 95, 95, 95, 95, 95, 95, 95,
95, 95, 95, 95, 95, 95, 95, 95,
95, 95, 95, 95, 95, 95, 95, 95,
95, 95, 95, 95, 95, 95, 95, 95,
65, 66, 67, 68, 69, 70, 71, 72,
73, 74, 75, 76, 77, 78, 79, 80,
81, 82, 83, 84, 85, 86, 87, 88,
89, 90, 95, 95, 95, 95, 95, 95,
97, 98, 99, 100, 101, 102, 103, 104,
105, 106, 107, 108, 109, 110, 111, 112,
113, 114, 115, 116, 117, 118, 119, 120,
121, 122, 95, 95, 95, 95, 95, 95,
95, 95, 95, 95, 95, 95, 95, 95,
95, 95, 95, 95, 95, 95, 95, 95,
95, 95, 95, 95, 95, 95, 95, 95,
95, 95, 95, 95, 95, 95, 95, 95,
95, 95, 95, 95, 95, 95, 95, 95,
95, 95, 95, 95, 95, 95, 95, 95,
95, 95, 95, 95, 95, 95, 95, 95,
95, 95, 95, 95, 95, 95, 95, 192,
193, 194, 195, 196, 197, 198, 199, 200,
201, 202, 203, 204, 205, 206, 207, 208,
209, 210, 211, 212, 213, 214, 95, 216,
217, 218, 219, 220, 221, 222, 223, 224,
225, 226, 227, 228, 229, 230, 231, 232,
233, 234, 235, 236, 237, 238, 239, 240,
241, 242, 243, 244, 245, 246, 95, 248,
249, 250, 251, 252, 253, 254, 255};
95, 95, 95, 95, 95, 95, 95, 95, 95,
95, 95, 95, 95, 95, 95, 95, 95,
95, 95, 95, 95, 95, 95, 95, 95,
95, 95, 95, 95, 95, 95, 95, 95,
95, 95, 95, 95, 95, 95, 95, 95,
95, 95, 95, 95, 95, 95, 95, 95,
95, 95, 95, 95, 95, 95, 95, 95,
95, 95, 95, 95, 95, 95, 95, 95,
65, 66, 67, 68, 69, 70, 71, 72,
73, 74, 75, 76, 77, 78, 79, 80,
81, 82, 83, 84, 85, 86, 87, 88,
89, 90, 95, 95, 95, 95, 95, 95,
97, 98, 99, 100, 101, 102, 103, 104,
105, 106, 107, 108, 109, 110, 111, 112,
113, 114, 115, 116, 117, 118, 119, 120,
121, 122, 95, 95, 95, 95, 95, 95,
95, 95, 95, 95, 95, 95, 95, 95,
95, 95, 95, 95, 95, 95, 95, 95,
95, 95, 95, 95, 95, 95, 95, 95,
95, 95, 95, 95, 95, 95, 95, 95,
95, 95, 95, 95, 95, 95, 95, 95,
95, 95, 95, 95, 95, 95, 95, 95,
95, 95, 95, 95, 95, 95, 95, 95,
95, 95, 95, 95, 95, 95, 95, 192,
193, 194, 195, 196, 197, 198, 199, 200,
201, 202, 203, 204, 205, 206, 207, 208,
209, 210, 211, 212, 213, 214, 95, 216,
217, 218, 219, 220, 221, 222, 223, 224,
225, 226, 227, 228, 229, 230, 231, 232,
233, 234, 235, 236, 237, 238, 239, 240,
241, 242, 243, 244, 245, 246, 95, 248,
249, 250, 251, 252, 253, 254, 255
};
const unsigned char translate_name_map[256] = {
95, 95, 95, 95, 95, 95, 95, 95, 95,
95, 95, 95, 95, 95, 95, 95, 95,
95, 95, 95, 95, 95, 95, 95, 95,
95, 95, 95, 95, 95, 95, 95, 95,
95, 95, 95, 95, 95, 95, 95, 95,
95, 95, 95, 95, 45, 95, 95, 48,
49, 50, 51, 52, 53, 54, 55, 56,
57, 95, 95, 95, 95, 95, 95, 95,
65, 66, 67, 68, 69, 70, 71, 72,
73, 74, 75, 76, 77, 78, 79, 80,
81, 82, 83, 84, 85, 86, 87, 88,
89, 90, 95, 95, 95, 95, 95, 95,
97, 98, 99, 100, 101, 102, 103, 104,
105, 106, 107, 108, 109, 110, 111, 112,
113, 114, 115, 116, 117, 118, 119, 120,
121, 122, 95, 95, 95, 95, 95, 95,
95, 95, 95, 95, 95, 95, 95, 95,
95, 95, 95, 95, 95, 95, 95, 95,
95, 95, 95, 95, 95, 95, 95, 95,
95, 95, 95, 95, 95, 95, 95, 95,
95, 95, 95, 95, 95, 95, 95, 95,
95, 95, 95, 95, 95, 95, 95, 95,
95, 95, 95, 95, 95, 95, 183, 95,
95, 95, 95, 95, 95, 95, 95, 192,
193, 194, 195, 196, 197, 198, 199, 200,
201, 202, 203, 204, 205, 206, 207, 208,
209, 210, 211, 212, 213, 214, 95, 216,
217, 218, 219, 220, 221, 222, 223, 224,
225, 226, 227, 228, 229, 230, 231, 232,
233, 234, 235, 236, 237, 238, 239, 240,
241, 242, 243, 244, 245, 246, 95, 248,
249, 250, 251, 252, 253, 254, 255};
95, 95, 95, 95, 95, 95, 95, 95, 95,
95, 95, 95, 95, 95, 95, 95, 95,
95, 95, 95, 95, 95, 95, 95, 95,
95, 95, 95, 95, 95, 95, 95, 95,
95, 95, 95, 95, 95, 95, 95, 95,
95, 95, 95, 95, 45, 95, 95, 48,
49, 50, 51, 52, 53, 54, 55, 56,
57, 95, 95, 95, 95, 95, 95, 95,
65, 66, 67, 68, 69, 70, 71, 72,
73, 74, 75, 76, 77, 78, 79, 80,
81, 82, 83, 84, 85, 86, 87, 88,
89, 90, 95, 95, 95, 95, 95, 95,
97, 98, 99, 100, 101, 102, 103, 104,
105, 106, 107, 108, 109, 110, 111, 112,
113, 114, 115, 116, 117, 118, 119, 120,
121, 122, 95, 95, 95, 95, 95, 95,
95, 95, 95, 95, 95, 95, 95, 95,
95, 95, 95, 95, 95, 95, 95, 95,
95, 95, 95, 95, 95, 95, 95, 95,
95, 95, 95, 95, 95, 95, 95, 95,
95, 95, 95, 95, 95, 95, 95, 95,
95, 95, 95, 95, 95, 95, 95, 95,
95, 95, 95, 95, 95, 95, 183, 95,
95, 95, 95, 95, 95, 95, 95, 192,
193, 194, 195, 196, 197, 198, 199, 200,
201, 202, 203, 204, 205, 206, 207, 208,
209, 210, 211, 212, 213, 214, 95, 216,
217, 218, 219, 220, 221, 222, 223, 224,
225, 226, 227, 228, 229, 230, 231, 232,
233, 234, 235, 236, 237, 238, 239, 240,
241, 242, 243, 244, 245, 246, 95, 248,
249, 250, 251, 252, 253, 254, 255
};
typedef std::map< std::string, std::vector<std::string> > map_string_list;
map_string_list global_id_map;
@ -205,7 +208,7 @@ std::string translate_id(const std::string &id)
std::string id_translated = id;
id_translated[0] = translate_start_name_map[(unsigned int)id_translated[0]];
for (unsigned int i=1; i < id_translated.size(); i++) {
for (unsigned int i = 1; i < id_translated.size(); i++) {
id_translated[i] = translate_name_map[(unsigned int)id_translated[i]];
}
// It's so much workload now, the if () should speed up things.
@ -215,7 +218,7 @@ std::string translate_id(const std::string &id)
if (iter != global_id_map.end()) {
unsigned int i = 0;
bool found = false;
for (i=0; i < iter->second.size(); i++) {
for (i = 0; i < iter->second.size(); i++) {
if (id == iter->second[i]) {
found = true;
break;
@ -223,9 +226,9 @@ std::string translate_id(const std::string &id)
}
bool convert = false;
if (found) {
if (i > 0) {
convert = true;
}
if (i > 0) {
convert = true;
}
}
else {
convert = true;
@ -244,7 +247,7 @@ std::string translate_id(const std::string &id)
std::string id_name(void *id)
{
return ((ID*)id)->name + 2;
return ((ID *)id)->name + 2;
}
std::string get_geometry_id(Object *ob)

@ -117,7 +117,7 @@ int bc_set_parent(Object *ob, Object *par, bContext *C, bool is_parent_space)
DAG_scene_sort(bmain, sce);
DAG_ids_flush_update(bmain, 0);
WM_event_add_notifier(C, NC_OBJECT|ND_TRANSFORM, NULL);
WM_event_add_notifier(C, NC_OBJECT | ND_TRANSFORM, NULL);
return true;
}
@ -126,9 +126,9 @@ Object *bc_add_object(Scene *scene, int type, const char *name)
{
Object *ob = BKE_object_add_only_object(type, name);
ob->data= BKE_object_obdata_add_from_type(type);
ob->lay= scene->lay;
ob->recalc |= OB_RECALC_OB|OB_RECALC_DATA|OB_RECALC_TIME;
ob->data = BKE_object_obdata_add_from_type(type);
ob->lay = scene->lay;
ob->recalc |= OB_RECALC_OB | OB_RECALC_DATA | OB_RECALC_TIME;
BKE_scene_base_select(scene, BKE_scene_base_add(scene, ob));
@ -154,13 +154,11 @@ Object *bc_get_assigned_armature(Object *ob)
ob_arm = ob->parent;
}
else {
ModifierData *mod = (ModifierData*)ob->modifiers.first;
while (mod) {
ModifierData *mod;
for (mod = (ModifierData *)ob->modifiers.first; mod; mod = mod->next) {
if (mod->type == eModifierType_Armature) {
ob_arm = ((ArmatureModifierData*)mod)->object;
ob_arm = ((ArmatureModifierData *)mod)->object;
}
mod = mod->next;
}
}

@ -87,17 +87,17 @@ static void rna_SceneRender_get_frame_path(RenderData *rd, int frame, char *name
static void rna_Scene_collada_export(
Scene *scene,
const char *filepath,
int selected,
int apply_modifiers,
int include_armatures,
int include_children,
int use_object_instantiation,
int second_life)
const char *filepath,
int selected,
int apply_modifiers,
int include_armatures,
int include_children,
int use_object_instantiation,
int second_life)
{
collada_export(scene, filepath, selected, apply_modifiers,
include_armatures, include_children,
use_object_instantiation, second_life);
include_armatures, include_children,
use_object_instantiation, second_life);
}
#endif

@ -591,7 +591,7 @@ void WM_operator_properties_alloc(PointerRNA **ptr, IDProperty **properties, con
void WM_operator_properties_sanitize(PointerRNA *ptr, const short no_context)
{
RNA_STRUCT_BEGIN (ptr, prop)
RNA_STRUCT_BEGIN(ptr, prop)
{
switch (RNA_property_type(prop)) {
case PROP_ENUM:
@ -625,7 +625,7 @@ void WM_operator_properties_reset(wmOperator *op)
PropertyRNA *iterprop;
iterprop = RNA_struct_iterator_property(op->type->srna);
RNA_PROP_BEGIN (op->ptr, itemptr, iterprop)
RNA_PROP_BEGIN(op->ptr, itemptr, iterprop)
{
PropertyRNA *prop = itemptr.data;
@ -1809,7 +1809,7 @@ static int wm_link_append_exec(bContext *C, wmOperator *op)
BLO_library_append_named_part_ex(C, mainl, &bh, name, idcode, flag);
}
else {
RNA_BEGIN (op->ptr, itemptr, "files")
RNA_BEGIN(op->ptr, itemptr, "files")
{
RNA_string_get(&itemptr, "name", name);
BLO_library_append_named_part_ex(C, mainl, &bh, name, idcode, flag);
@ -2163,10 +2163,10 @@ static int wm_collada_export_exec(bContext *C, wmOperator *op)
{
char filename[FILE_MAX];
int selected, second_life,
include_armatures,
apply_modifiers,
include_children,
use_object_instantiation;
int include_armatures,
int apply_modifiers,
int include_children,
int use_object_instantiation;
if (!RNA_struct_property_is_set(op->ptr, "filepath")) {
BKE_report(op->reports, RPT_ERROR, "No filename given");
@ -2187,14 +2187,14 @@ static int wm_collada_export_exec(bContext *C, wmOperator *op)
ED_object_exit_editmode(C, 0); /* 0 = does not exit editmode */
if (collada_export(
CTX_data_scene(C),
filename,
selected,
apply_modifiers,
include_armatures,
include_children,
use_object_instantiation,
second_life)) {
CTX_data_scene(C),
filename,
selected,
apply_modifiers,
include_armatures,
include_children,
use_object_instantiation,
second_life)) {
return OPERATOR_FINISHED;
}
else {
@ -2229,7 +2229,7 @@ static void WM_OT_collada_export(wmOperatorType *ot)
"Include all children even if not selected");
RNA_def_boolean(ot->srna, "use_object_instantiation", 1, "Use Object Instantiation",
"Instantiate multiple Objects from same Data");
"Instantiate multiple Objects from same Data");
RNA_def_boolean(ot->srna, "second_life", 0, "Export for Second Life",
"Compatibility mode for Second Life");
@ -2315,7 +2315,7 @@ static void WM_OT_console_toggle(wmOperatorType *ot)
{
/* XXX Have to mark these for xgettext, as under linux they do not exists...
* And even worth, have to give the context as text, as xgettext doesn't expand macros. :( */
ot->name = CTX_N_("Operator"/* BLF_I18NCONTEXT_OPERATOR_DEFAULT */, "Toggle System Console");
ot->name = CTX_N_("Operator" /* BLF_I18NCONTEXT_OPERATOR_DEFAULT */, "Toggle System Console");
ot->idname = "WM_OT_console_toggle";
ot->description = N_("Toggle System Console");
@ -2869,7 +2869,7 @@ int (*WM_gesture_lasso_path_to_array(bContext *UNUSED(C), wmOperator *op, int *m
static int gesture_lasso_exec(bContext *C, wmOperator *op)
{
RNA_BEGIN (op->ptr, itemptr, "path")
RNA_BEGIN(op->ptr, itemptr, "path")
{
float loc[2];
@ -3825,7 +3825,8 @@ static void gesture_circle_modal_keymap(wmKeyConfig *keyconf)
{GESTURE_MODAL_DESELECT, "DESELECT", 0, "DeSelect", ""},
{GESTURE_MODAL_NOP, "NOP", 0, "No Operation", ""},
{0, NULL, 0, NULL, NULL}};
{0, NULL, 0, NULL, NULL}
};
wmKeyMap *keymap = WM_modalkeymap_get(keyconf, "View3D Gesture Circle");
@ -3873,7 +3874,8 @@ static void gesture_straightline_modal_keymap(wmKeyConfig *keyconf)
{GESTURE_MODAL_CANCEL, "CANCEL", 0, "Cancel", ""},
{GESTURE_MODAL_SELECT, "SELECT", 0, "Select", ""},
{GESTURE_MODAL_BEGIN, "BEGIN", 0, "Begin", ""},
{0, NULL, 0, NULL, NULL}};
{0, NULL, 0, NULL, NULL}
};
wmKeyMap *keymap = WM_modalkeymap_get(keyconf, "Gesture Straight Line");
@ -3902,7 +3904,8 @@ static void gesture_border_modal_keymap(wmKeyConfig *keyconf)
{GESTURE_MODAL_SELECT, "SELECT", 0, "Select", ""},
{GESTURE_MODAL_DESELECT, "DESELECT", 0, "DeSelect", ""},
{GESTURE_MODAL_BEGIN, "BEGIN", 0, "Begin", ""},
{0, NULL, 0, NULL, NULL}};
{0, NULL, 0, NULL, NULL}
};
wmKeyMap *keymap = WM_modalkeymap_get(keyconf, "Gesture Border");
@ -3962,7 +3965,8 @@ static void gesture_zoom_border_modal_keymap(wmKeyConfig *keyconf)
{GESTURE_MODAL_IN, "IN", 0, "In", ""},
{GESTURE_MODAL_OUT, "OUT", 0, "Out", ""},
{GESTURE_MODAL_BEGIN, "BEGIN", 0, "Begin", ""},
{0, NULL, 0, NULL, NULL}};
{0, NULL, 0, NULL, NULL}
};
wmKeyMap *keymap = WM_modalkeymap_get(keyconf, "Gesture Zoom Border");