Changeset View
Changeset View
Standalone View
Standalone View
source/blender/collada/DocumentImporter.cpp
| Context not available. | |||||
| COLLADASaxFWL::Loader loader(&errorHandler); | COLLADASaxFWL::Loader loader(&errorHandler); | ||||
| COLLADAFW::Root root(&loader, this); | COLLADAFW::Root root(&loader, this); | ||||
| ExtraHandler *ehandler = new ExtraHandler(this, &(this->anim_importer)); | ExtraHandler *ehandler = new ExtraHandler(this, &(this->anim_importer)); | ||||
| loader.registerExtraDataCallbackHandler(ehandler); | loader.registerExtraDataCallbackHandler(ehandler); | ||||
| // deselect all to select new objects | // deselect all to select new objects | ||||
| Context not available. | |||||
| fprintf(stderr, "COLLADAFW::Root::loadDocument() returned false on 1st pass\n"); | fprintf(stderr, "COLLADAFW::Root::loadDocument() returned false on 1st pass\n"); | ||||
| return false; | return false; | ||||
| } | } | ||||
| if (errorHandler.hasError()) | if (errorHandler.hasError()) | ||||
| return false; | return false; | ||||
| /** TODO set up scene graph and such here */ | /** TODO set up scene graph and such here */ | ||||
| mImportStage = Controller; | mImportStage = Controller; | ||||
| COLLADASaxFWL::Loader loader2; | COLLADASaxFWL::Loader loader2; | ||||
| COLLADAFW::Root root2(&loader2, this); | COLLADAFW::Root root2(&loader2, this); | ||||
| if (!root2.loadDocument(encodedFilename)) { | if (!root2.loadDocument(encodedFilename)) { | ||||
| fprintf(stderr, "COLLADAFW::Root::loadDocument() returned false on 2nd pass\n"); | fprintf(stderr, "COLLADAFW::Root::loadDocument() returned false on 2nd pass\n"); | ||||
| return false; | return false; | ||||
| } | } | ||||
| delete ehandler; | delete ehandler; | ||||
| //XXX No longer needed (geometries are now created as bmesh) | //XXX No longer needed (geometries are now created as bmesh) | ||||
| Context not available. | |||||
| for (it = vscenes.begin(); it != vscenes.end(); it++) { | for (it = vscenes.begin(); it != vscenes.end(); it++) { | ||||
| PointerRNA sceneptr, unit_settings; | PointerRNA sceneptr, unit_settings; | ||||
| PropertyRNA *system, *scale; | PropertyRNA *system, *scale; | ||||
| // for scene unit settings: system, scale_length | // for scene unit settings: system, scale_length | ||||
| RNA_id_pointer_create(&sce->id, &sceneptr); | RNA_id_pointer_create(&sce->id, &sceneptr); | ||||
| Context not available. | |||||
| scale = RNA_struct_find_property(&unit_settings, "scale_length"); | scale = RNA_struct_find_property(&unit_settings, "scale_length"); | ||||
| if (this->import_settings->import_units) { | if (this->import_settings->import_units) { | ||||
| switch (unit_converter.isMetricSystem()) { | switch (unit_converter.isMetricSystem()) { | ||||
| case UnitConverter::Metric: | case UnitConverter::Metric: | ||||
| RNA_property_enum_set(&unit_settings, system, USER_UNIT_METRIC); | RNA_property_enum_set(&unit_settings, system, USER_UNIT_METRIC); | ||||
| Context not available. | |||||
| DAG_relations_tag_update(bmain); | DAG_relations_tag_update(bmain); | ||||
| } | } | ||||
| bc_match_scale(objects_to_scale, unit_converter, !this->import_settings->import_units); | bc_match_scale(objects_to_scale, unit_converter, !this->import_settings->import_units); | ||||
| } | } | ||||
| Context not available. | |||||
| short* type = 0; | short* type = 0; | ||||
| et->setData("type", type); | et->setData("type", type); | ||||
| BKE_constraint_add_for_object(ob, "Test_con", *type); | BKE_constraint_add_for_object(ob, "Test_con", *type); | ||||
| } | } | ||||
| } | } | ||||
| Context not available. | |||||
| root_objects->push_back(ob); | root_objects->push_back(ob); | ||||
| } | } | ||||
| } | } | ||||
| // XXX: if there're multiple instances, only one is stored | // XXX: if there're multiple instances, only one is stored | ||||
| if (!ob) return root_objects; | if (!ob) return root_objects; | ||||
| Context not available. | |||||
| { | { | ||||
| if (mImportStage != General) | if (mImportStage != General) | ||||
| return true; | return true; | ||||
| // this method called on post process after writeGeometry, writeMaterial, etc. | // this method called on post process after writeGeometry, writeMaterial, etc. | ||||
| // for each <node> in <visual_scene>: | // for each <node> in <visual_scene>: | ||||
| Context not available. | |||||
| // we link Objects with Meshes here | // we link Objects with Meshes here | ||||
| vscenes.push_back(visualScene); | vscenes.push_back(visualScene); | ||||
| return true; | return true; | ||||
| } | } | ||||
| /** When this method is called, the writer must handle all nodes contained in the | /** When this method is called, the writer must handle all nodes contained in the | ||||
| * library nodes. | * library nodes. | ||||
| * \return The writer should return true, if writing succeeded, false otherwise.*/ | * \return The writer should return true, if writing succeeded, false otherwise.*/ | ||||
| bool DocumentImporter::writeLibraryNodes(const COLLADAFW::LibraryNodes *libraryNodes) | bool DocumentImporter::writeLibraryNodes(const COLLADAFW::LibraryNodes *libraryNodes) | ||||
| { | { | ||||
| if (mImportStage != General) | if (mImportStage != General) | ||||
| return true; | return true; | ||||
| Scene *sce = CTX_data_scene(mContext); | Scene *sce = CTX_data_scene(mContext); | ||||
| const COLLADAFW::NodePointerArray& nodes = libraryNodes->getNodes(); | const COLLADAFW::NodePointerArray& nodes = libraryNodes->getNodes(); | ||||
| Context not available. | |||||
| { | { | ||||
| if (mImportStage != General) | if (mImportStage != General) | ||||
| return true; | return true; | ||||
| return mesh_importer.write_geometry(geom); | return mesh_importer.write_geometry(geom); | ||||
| } | } | ||||
| Context not available. | |||||
| { | { | ||||
| if (mImportStage != General) | if (mImportStage != General) | ||||
| return true; | return true; | ||||
| const std::string& str_mat_id = cmat->getName().size() ? cmat->getName() : cmat->getOriginalId(); | const std::string& str_mat_id = cmat->getName().size() ? cmat->getName() : cmat->getOriginalId(); | ||||
| Material *ma = BKE_material_add(G.main, (char *)str_mat_id.c_str()); | Material *ma = BKE_material_add(G.main, (char *)str_mat_id.c_str()); | ||||
| this->uid_effect_map[cmat->getInstantiatedEffect()] = ma; | this->uid_effect_map[cmat->getInstantiatedEffect()] = ma; | ||||
| this->uid_material_map[cmat->getUniqueId()] = ma; | this->uid_material_map[cmat->getUniqueId()] = ma; | ||||
| return true; | return true; | ||||
| } | } | ||||
| Context not available. | |||||
| { | { | ||||
| COLLADAFW::SamplerPointerArray& samp_array = ef->getSamplerPointerArray(); | COLLADAFW::SamplerPointerArray& samp_array = ef->getSamplerPointerArray(); | ||||
| COLLADAFW::Sampler *sampler = samp_array[ctex.getSamplerId()]; | COLLADAFW::Sampler *sampler = samp_array[ctex.getSamplerId()]; | ||||
| const COLLADAFW::UniqueId& ima_uid = sampler->getSourceImage(); | const COLLADAFW::UniqueId& ima_uid = sampler->getSourceImage(); | ||||
| if (uid_image_map.find(ima_uid) == uid_image_map.end()) { | if (uid_image_map.find(ima_uid) == uid_image_map.end()) { | ||||
| fprintf(stderr, "Couldn't find an image by UID.\n"); | fprintf(stderr, "Couldn't find an image by UID.\n"); | ||||
| return NULL; | return NULL; | ||||
| } | } | ||||
| ma->mtex[i] = add_mtex(); | ma->mtex[i] = add_mtex(); | ||||
| ma->mtex[i]->texco = TEXCO_UV; | ma->mtex[i]->texco = TEXCO_UV; | ||||
| ma->mtex[i]->tex = add_texture(G.main, "Texture"); | ma->mtex[i]->tex = add_texture(G.main, "Texture"); | ||||
| ma->mtex[i]->tex->type = TEX_IMAGE; | ma->mtex[i]->tex->type = TEX_IMAGE; | ||||
| ma->mtex[i]->tex->ima = uid_image_map[ima_uid]; | ma->mtex[i]->tex->ima = uid_image_map[ima_uid]; | ||||
| texindex_texarray_map[ctex.getTextureMapId()].push_back(ma->mtex[i]); | texindex_texarray_map[ctex.getTextureMapId()].push_back(ma->mtex[i]); | ||||
| return ma->mtex[i]; | return ma->mtex[i]; | ||||
| } | } | ||||
| void DocumentImporter::write_profile_COMMON(COLLADAFW::EffectCommon *ef, Material *ma) | void DocumentImporter::write_profile_COMMON(COLLADAFW::EffectCommon *ef, Material *ma) | ||||
| { | { | ||||
| COLLADAFW::EffectCommon::ShaderType shader = ef->getShaderType(); | COLLADAFW::EffectCommon::ShaderType shader = ef->getShaderType(); | ||||
| // blinn | // blinn | ||||
| if (shader == COLLADAFW::EffectCommon::SHADER_BLINN) { | if (shader == COLLADAFW::EffectCommon::SHADER_BLINN) { | ||||
| ma->spec_shader = MA_SPEC_BLINN; | ma->spec_shader = MA_SPEC_BLINN; | ||||
| Context not available. | |||||
| ma->ray_mirror = ef->getReflectivity().getFloatValue(); | ma->ray_mirror = ef->getReflectivity().getFloatValue(); | ||||
| // index of refraction | // index of refraction | ||||
| ma->ang = ef->getIndexOfRefraction().getFloatValue(); | ma->ang = ef->getIndexOfRefraction().getFloatValue(); | ||||
| int i = 0; | int i = 0; | ||||
| COLLADAFW::Color col; | COLLADAFW::Color col; | ||||
| MTex *mtex = NULL; | MTex *mtex = NULL; | ||||
| TexIndexTextureArrayMap texindex_texarray_map; | TexIndexTextureArrayMap texindex_texarray_map; | ||||
| // DIFFUSE | // DIFFUSE | ||||
| // color | // color | ||||
| if (ef->getDiffuse().isColor()) { | if (ef->getDiffuse().isColor()) { | ||||
| Context not available. | |||||
| } | } | ||||
| // texture | // texture | ||||
| else if (ef->getDiffuse().isTexture()) { | else if (ef->getDiffuse().isTexture()) { | ||||
| COLLADAFW::Texture ctex = ef->getDiffuse().getTexture(); | COLLADAFW::Texture ctex = ef->getDiffuse().getTexture(); | ||||
| mtex = create_texture(ef, ctex, ma, i, texindex_texarray_map); | mtex = create_texture(ef, ctex, ma, i, texindex_texarray_map); | ||||
| if (mtex != NULL) { | if (mtex != NULL) { | ||||
| mtex->mapto = MAP_COL; | mtex->mapto = MAP_COL; | ||||
| Context not available. | |||||
| } | } | ||||
| // texture | // texture | ||||
| else if (ef->getAmbient().isTexture()) { | else if (ef->getAmbient().isTexture()) { | ||||
| COLLADAFW::Texture ctex = ef->getAmbient().getTexture(); | COLLADAFW::Texture ctex = ef->getAmbient().getTexture(); | ||||
| mtex = create_texture(ef, ctex, ma, i, texindex_texarray_map); | mtex = create_texture(ef, ctex, ma, i, texindex_texarray_map); | ||||
| if (mtex != NULL) { | if (mtex != NULL) { | ||||
| mtex->mapto = MAP_AMB; | mtex->mapto = MAP_AMB; | ||||
| i++; | i++; | ||||
| } | } | ||||
| } | } | ||||
| Context not available. | |||||
| } | } | ||||
| // texture | // texture | ||||
| else if (ef->getSpecular().isTexture()) { | else if (ef->getSpecular().isTexture()) { | ||||
| COLLADAFW::Texture ctex = ef->getSpecular().getTexture(); | COLLADAFW::Texture ctex = ef->getSpecular().getTexture(); | ||||
| mtex = create_texture(ef, ctex, ma, i, texindex_texarray_map); | mtex = create_texture(ef, ctex, ma, i, texindex_texarray_map); | ||||
| if (mtex != NULL) { | if (mtex != NULL) { | ||||
| mtex->mapto = MAP_SPEC; | mtex->mapto = MAP_SPEC; | ||||
| i++; | i++; | ||||
| } | } | ||||
| } | } | ||||
| Context not available. | |||||
| } | } | ||||
| // texture | // texture | ||||
| else if (ef->getReflective().isTexture()) { | else if (ef->getReflective().isTexture()) { | ||||
| COLLADAFW::Texture ctex = ef->getReflective().getTexture(); | COLLADAFW::Texture ctex = ef->getReflective().getTexture(); | ||||
| mtex = create_texture(ef, ctex, ma, i, texindex_texarray_map); | mtex = create_texture(ef, ctex, ma, i, texindex_texarray_map); | ||||
| if (mtex != NULL) { | if (mtex != NULL) { | ||||
| mtex->mapto = MAP_REF; | mtex->mapto = MAP_COLMIR; | ||||
| i++; | i++; | ||||
| } | } | ||||
| } | } | ||||
| // EMISSION | // EMISSION | ||||
| // color | // color | ||||
| if (ef->getEmission().isColor()) { | if (ef->getEmission().isColor()) { | ||||
| // XXX there is no emission color in blender | // XXX blender only uses a single value to indicate emission, so just use the red | ||||
| // but I am not sure | col = ef->getEmission().getColor(); | ||||
| ma->emit = col.getRed(); | |||||
| } | } | ||||
| // texture | // texture | ||||
| else if (ef->getEmission().isTexture()) { | else if (ef->getEmission().isTexture()) { | ||||
| COLLADAFW::Texture ctex = ef->getEmission().getTexture(); | COLLADAFW::Texture ctex = ef->getEmission().getTexture(); | ||||
| mtex = create_texture(ef, ctex, ma, i, texindex_texarray_map); | mtex = create_texture(ef, ctex, ma, i, texindex_texarray_map); | ||||
| if (mtex != NULL) { | if (mtex != NULL) { | ||||
| mtex->mapto = MAP_EMIT; | mtex->mapto = MAP_EMIT; | ||||
| i++; | i++; | ||||
| } | } | ||||
| } | } | ||||
| if (ef->getOpacity().isTexture()) { | if (ef->getOpacity().isTexture()) { | ||||
| COLLADAFW::Texture ctex = ef->getOpacity().getTexture(); | COLLADAFW::Texture ctex = ef->getOpacity().getTexture(); | ||||
| mtex = create_texture(ef, ctex, ma, i, texindex_texarray_map); | mtex = create_texture(ef, ctex, ma, i, texindex_texarray_map); | ||||
| Context not available. | |||||
| { | { | ||||
| if (mImportStage != General) | if (mImportStage != General) | ||||
| return true; | return true; | ||||
| const COLLADAFW::UniqueId& uid = effect->getUniqueId(); | const COLLADAFW::UniqueId& uid = effect->getUniqueId(); | ||||
| if (uid_effect_map.find(uid) == uid_effect_map.end()) { | if (uid_effect_map.find(uid) == uid_effect_map.end()) { | ||||
| fprintf(stderr, "Couldn't find a material by UID.\n"); | fprintf(stderr, "Couldn't find a material by UID.\n"); | ||||
| return true; | return true; | ||||
| } | } | ||||
| Material *ma = uid_effect_map[uid]; | Material *ma = uid_effect_map[uid]; | ||||
| std::map<COLLADAFW::UniqueId, Material *>::iterator iter; | std::map<COLLADAFW::UniqueId, Material *>::iterator iter; | ||||
| for (iter = uid_material_map.begin(); iter != uid_material_map.end(); iter++) { | for (iter = uid_material_map.begin(); iter != uid_material_map.end(); iter++) { | ||||
| Context not available. | |||||
| COLLADAFW::EffectCommon *ef = common_efs[0]; | COLLADAFW::EffectCommon *ef = common_efs[0]; | ||||
| write_profile_COMMON(ef, ma); | write_profile_COMMON(ef, ma); | ||||
| this->FW_object_map[effect->getUniqueId()] = effect; | this->FW_object_map[effect->getUniqueId()] = effect; | ||||
| return true; | return true; | ||||
| } | } | ||||
| Context not available. | |||||
| { | { | ||||
| if (mImportStage != General) | if (mImportStage != General) | ||||
| return true; | return true; | ||||
| Camera *cam = NULL; | Camera *cam = NULL; | ||||
| std::string cam_id, cam_name; | std::string cam_id, cam_name; | ||||
| ExtraTags *et=getExtraTags(camera->getUniqueId()); | ExtraTags *et=getExtraTags(camera->getUniqueId()); | ||||
| cam_id = camera->getOriginalId(); | cam_id = camera->getOriginalId(); | ||||
| cam_name = camera->getName(); | cam_name = camera->getName(); | ||||
| if (cam_name.size()) cam = (Camera *)BKE_camera_add(G.main, (char *)cam_name.c_str()); | if (cam_name.size()) cam = (Camera *)BKE_camera_add(G.main, (char *)cam_name.c_str()); | ||||
| else cam = (Camera *)BKE_camera_add(G.main, (char *)cam_id.c_str()); | else cam = (Camera *)BKE_camera_add(G.main, (char *)cam_id.c_str()); | ||||
| if (!cam) { | if (!cam) { | ||||
| fprintf(stderr, "Cannot create camera.\n"); | fprintf(stderr, "Cannot create camera.\n"); | ||||
| return true; | return true; | ||||
| Context not available. | |||||
| } | } | ||||
| cam->clipsta = camera->getNearClippingPlane().getValue(); | cam->clipsta = camera->getNearClippingPlane().getValue(); | ||||
| cam->clipend = camera->getFarClippingPlane().getValue(); | cam->clipend = camera->getFarClippingPlane().getValue(); | ||||
| COLLADAFW::Camera::CameraType type = camera->getCameraType(); | COLLADAFW::Camera::CameraType type = camera->getCameraType(); | ||||
| switch (type) { | switch (type) { | ||||
| case COLLADAFW::Camera::ORTHOGRAPHIC: | case COLLADAFW::Camera::ORTHOGRAPHIC: | ||||
| Context not available. | |||||
| } | } | ||||
| break; | break; | ||||
| } | } | ||||
| switch (camera->getDescriptionType()) { | switch (camera->getDescriptionType()) { | ||||
| case COLLADAFW::Camera::ASPECTRATIO_AND_Y: | case COLLADAFW::Camera::ASPECTRATIO_AND_Y: | ||||
| { | { | ||||
| Context not available. | |||||
| // read nothing, use blender defaults. | // read nothing, use blender defaults. | ||||
| break; | break; | ||||
| } | } | ||||
| this->uid_camera_map[camera->getUniqueId()] = cam; | this->uid_camera_map[camera->getUniqueId()] = cam; | ||||
| this->FW_object_map[camera->getUniqueId()] = camera; | this->FW_object_map[camera->getUniqueId()] = camera; | ||||
| // XXX import camera options | // XXX import camera options | ||||
| Context not available. | |||||
| { | { | ||||
| if (mImportStage != General) | if (mImportStage != General) | ||||
| return true; | return true; | ||||
| const std::string& imagepath = image->getImageURI().toNativePath(); | const std::string& imagepath = image->getImageURI().toNativePath(); | ||||
| char dir[FILE_MAX]; | char dir[FILE_MAX]; | ||||
| Context not available. | |||||
| BLI_join_dirfile(absolute_path, sizeof(absolute_path), dir, imagepath.c_str()); | BLI_join_dirfile(absolute_path, sizeof(absolute_path), dir, imagepath.c_str()); | ||||
| if (BLI_exists(absolute_path)) { | if (BLI_exists(absolute_path)) { | ||||
| workpath = absolute_path; | workpath = absolute_path; | ||||
| } | } | ||||
| else { | else { | ||||
| // Maybe imagepath was already absolute ? | // Maybe imagepath was already absolute ? | ||||
| if (!BLI_exists(imagepath.c_str())) { | if (!BLI_exists(imagepath.c_str())) { | ||||
| Context not available. | |||||
| return true; | return true; | ||||
| } | } | ||||
| this->uid_image_map[image->getUniqueId()] = ima; | this->uid_image_map[image->getUniqueId()] = ima; | ||||
| return true; | return true; | ||||
| } | } | ||||
| Context not available. | |||||
| // assuming point light (const att = 1.0); | // assuming point light (const att = 1.0); | ||||
| att1 = 1.0f; | att1 = 1.0f; | ||||
| } | } | ||||
| d *= (1.0f / unit_converter.getLinearMeter()); | d *= (1.0f / unit_converter.getLinearMeter()); | ||||
| lamp->energy = e; | lamp->energy = e; | ||||
| Context not available. | |||||
| { | { | ||||
| if (mImportStage != General) | if (mImportStage != General) | ||||
| return true; | return true; | ||||
| // return true; | // return true; | ||||
| return anim_importer.write_animation(anim); | return anim_importer.write_animation(anim); | ||||
| } | } | ||||
| Context not available. | |||||
| { | { | ||||
| if (mImportStage != General) | if (mImportStage != General) | ||||
| return true; | return true; | ||||
| // return true; | // return true; | ||||
| return anim_importer.write_animation_list(animationList); | return anim_importer.write_animation_list(animationList); | ||||
| } | } | ||||
| Context not available. | |||||
| { | { | ||||
| if (mImportStage != General) | if (mImportStage != General) | ||||
| return true; | return true; | ||||
| return armature_importer.write_controller(controller); | return armature_importer.write_controller(controller); | ||||
| } | } | ||||
| Context not available. | |||||