Material Hardness Animation Import Complete.
authorSukhitha Prabhath Jayathilake <pr.jayathilake@gmail.com>
Sat, 23 Jul 2011 20:49:26 +0000 (20:49 +0000)
committerSukhitha Prabhath Jayathilake <pr.jayathilake@gmail.com>
Sat, 23 Jul 2011 20:49:26 +0000 (20:49 +0000)
source/blender/collada/AnimationImporter.cpp
source/blender/collada/DocumentImporter.cpp
source/blender/collada/DocumentImporter.h

index e6c35b3ffb717f5b3b8f93aee987298fa8573f99..eaf6835420e0e50d09e722e029d4db39a608b631 100644 (file)
@@ -906,32 +906,29 @@ void AnimationImporter::translate_Animations_NEW ( COLLADAFW::Node * node ,
 
                }
        }
-               if ( animType->material != 0){
-                        Material *ma = give_current_material(ob, 1);
-                        if (!ma->adt || !ma->adt->action) act = verify_adt_action((ID*)&ma->id, 1);
-                                       else act = ma->adt->action;
-       
-                       ListBase *AnimCurves = &(act->curves);
-                       
-                       const COLLADAFW::InstanceGeometryPointerArray& nodeGeoms = node->getInstanceGeometries();
-                       for (unsigned int i = 0; i < nodeGeoms.getCount(); i++) {
-                               const COLLADAFW::MaterialBindingArray& matBinds = nodeGeoms[i]->getMaterialBindings();
-                               for (unsigned int j = 0; j < matBinds.getCount(); j++) {
-                                       const COLLADAFW::Material *mat = (COLLADAFW::Material *) FW_object_map[matBinds[j].getReferencedMaterial()];
-                                       const COLLADAFW::Effect *ef = (COLLADAFW::Effect *) FW_object_map[mat->getInstantiatedEffect()];
-                                       COLLADAFW::CommonEffectPointerArray commonEffects  =  ef->getCommonEffects();
-                                       for (unsigned int k = 0; k < commonEffects.getCount(); k++) {
-                                               COLLADAFW::EffectCommon *efc = commonEffects[k];
-                                               if((animType->material & MATERIAL_SHININESS) != 0){
-                                                       const COLLADAFW::FloatOrParam *shin = &(efc->getShininess());
-                                                       const COLLADAFW::UniqueId& listid =  shin->getAnimationList();
-                                                       Assign_float_animations( listid, AnimCurves , "specular_hardness" );
-                                               }
-                                       }
-                               }       
-                       }
-               }
+       if ( animType->material != 0){
+                Material *ma = give_current_material(ob, 1);
+                if (!ma->adt || !ma->adt->action) act = verify_adt_action((ID*)&ma->id, 1);
+                               else act = ma->adt->action;
+
+               ListBase *AnimCurves = &(act->curves);
                
+               const COLLADAFW::InstanceGeometryPointerArray& nodeGeoms = node->getInstanceGeometries();
+               for (unsigned int i = 0; i < nodeGeoms.getCount(); i++) {
+                       const COLLADAFW::MaterialBindingArray& matBinds = nodeGeoms[i]->getMaterialBindings();
+                       for (unsigned int j = 0; j < matBinds.getCount(); j++) {
+                               const COLLADAFW::UniqueId & matuid = matBinds[j].getReferencedMaterial();
+                               const COLLADAFW::Effect *ef = (COLLADAFW::Effect *) (FW_object_map[matuid]);
+                               const COLLADAFW::CommonEffectPointerArray& commonEffects  =  ef->getCommonEffects();
+                               COLLADAFW::EffectCommon *efc = commonEffects[0];
+                               if((animType->material & MATERIAL_SHININESS) != 0){
+                                       const COLLADAFW::FloatOrParam *shin = &(efc->getShininess());
+                                       const COLLADAFW::UniqueId& listid =  shin->getAnimationList();
+                                       Assign_float_animations( listid, AnimCurves , "specular_hardness" );
+                               }
+                       }
+               }       
+       }
 }
 
 
@@ -940,11 +937,6 @@ AnimationImporter::AnimMix* AnimationImporter::get_animation_type ( const COLLAD
                                                                                        std::map<COLLADAFW::UniqueId, const COLLADAFW::Object*> FW_object_map) 
 {
        AnimMix *types = new AnimMix();
-       //types->transform = INANIMATE ;
-       //types->light = INANIMATE;
-       //types->camera = INANIMATE;
-       //types->material = INANIMATE;
-       //types->texture = INANIMATE;
        
        const COLLADAFW::TransformationPointerArray& nodeTransforms = node->getTransformations();
        
@@ -999,15 +991,12 @@ AnimationImporter::AnimMix* AnimationImporter::get_animation_type ( const COLLAD
        for (unsigned int i = 0; i < nodeGeoms.getCount(); i++) {
                const COLLADAFW::MaterialBindingArray& matBinds = nodeGeoms[i]->getMaterialBindings();
                for (unsigned int j = 0; j < matBinds.getCount(); j++) {
-                       const COLLADAFW::Material *mat = (COLLADAFW::Material *) FW_object_map[matBinds[j].getReferencedMaterial()];
-                       const COLLADAFW::Effect *ef = (COLLADAFW::Effect *) FW_object_map[mat->getInstantiatedEffect()];
-                   COLLADAFW::CommonEffectPointerArray commonEffects  =  ef->getCommonEffects();
-                       for (unsigned int k = 0; k < commonEffects.getCount(); k++) {
-                               COLLADAFW::EffectCommon *efc = commonEffects[k];
-                               types->material =  setAnimType(&(efc->getShininess()),(types->material), MATERIAL_SHININESS);
-                       }
+                       const COLLADAFW::UniqueId & matuid = matBinds[j].getReferencedMaterial();
+                       const COLLADAFW::Effect *ef = (COLLADAFW::Effect *) (FW_object_map[matuid]);
+                       const COLLADAFW::CommonEffectPointerArray& commonEffects  =  ef->getCommonEffects();
+                       COLLADAFW::EffectCommon *efc = commonEffects[0];
+                       types->material =  setAnimType(&(efc->getShininess()),(types->material), MATERIAL_SHININESS);
                }
-               
        }
        return types;
 }
index 2ff791eb91d506afce1e733d02d2f7506f80d2ec..d4eeb594922c40545342798587fda3affb1e4f9b 100644 (file)
@@ -537,7 +537,10 @@ bool DocumentImporter::writeMaterial( const COLLADAFW::Material* cmat )
        
        this->uid_effect_map[cmat->getInstantiatedEffect()] = ma;
        this->uid_material_map[cmat->getUniqueId()] = ma;
-       this->FW_object_map[cmat->getUniqueId()] = cmat;
+       this->matUidforEffect = &(cmat->getUniqueId());
+       /*COLLADAFW::Material * matCopy = new COLLADAFW::Material(&cmat);
+       this->FW_object_map[cmat->getUniqueId()] = matCopy;
+       *///matForEff = cmat;
        return true;
 }
 
@@ -722,13 +725,21 @@ bool DocumentImporter::writeEffect( const COLLADAFW::Effect* effect )
                return true;
        
        const COLLADAFW::UniqueId& uid = effect->getUniqueId();
+       
        if (uid_effect_map.find(uid) == uid_effect_map.end()) {
                fprintf(stderr, "Couldn't find a material by UID.\n");
                return true;
        }
        
        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 ) {
+                       this->FW_object_map[iter->first] = effect;
+                       break;
+               }
+       }
        COLLADAFW::CommonEffectPointerArray common_efs = effect->getCommonEffects();
        if (common_efs.getCount() < 1) {
                fprintf(stderr, "Couldn't find <profile_COMMON>.\n");
@@ -739,6 +750,7 @@ bool DocumentImporter::writeEffect( const COLLADAFW::Effect* effect )
        COLLADAFW::EffectCommon *ef = common_efs[0];
        write_profile_COMMON(ef, ma);
        this->FW_object_map[effect->getUniqueId()] = effect;
+               
        return true;
 }
 
index ce7a64a600dee12d7be3f71dbf4a770a351f2e60..8af0996885bc404c7021a3fb3975f633834b3926 100644 (file)
@@ -38,6 +38,8 @@
 #include "COLLADAFWController.h"
 #include "COLLADAFWMorphController.h"
 #include "COLLADAFWSkinController.h"
+#include "COLLADAFWEffectCommon.h"
+
 
 #include "BKE_object.h"
 
@@ -155,9 +157,12 @@ private:
        std::map<COLLADAFW::UniqueId, COLLADAFW::Node*> node_map;
        std::vector<const COLLADAFW::VisualScene*> vscenes;
        std::vector<Object*> libnode_ob;
+       
+       const COLLADAFW::UniqueId *matUidforEffect;
 
        std::map<COLLADAFW::UniqueId, COLLADAFW::Node*> root_map; // find root joint by child joint uid, for bone tree evaluation during resampling
        std::map<COLLADAFW::UniqueId, const COLLADAFW::Object*> FW_object_map;
+
 };
 
 #endif