| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2009, Google Inc. | 2 * Copyright 2009, Google Inc. |
| 3 * All rights reserved. | 3 * All rights reserved. |
| 4 * | 4 * |
| 5 * Redistribution and use in source and binary forms, with or without | 5 * Redistribution and use in source and binary forms, with or without |
| 6 * modification, are permitted provided that the following conditions are | 6 * modification, are permitted provided that the following conditions are |
| 7 * met: | 7 * met: |
| 8 * | 8 * |
| 9 * * Redistributions of source code must retain the above copyright | 9 * * Redistributions of source code must retain the above copyright |
| 10 * notice, this list of conditions and the following disclaimer. | 10 * notice, this list of conditions and the following disclaimer. |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 59 #define COLLADA_NAMESPACE_SEPARATOR "." | 59 #define COLLADA_NAMESPACE_SEPARATOR "." |
| 60 | 60 |
| 61 // Macro to provide a uniform prefix for all string constants created by | 61 // Macro to provide a uniform prefix for all string constants created by |
| 62 // COLLADA. | 62 // COLLADA. |
| 63 #define COLLADA_STRING_CONSTANT(value) \ | 63 #define COLLADA_STRING_CONSTANT(value) \ |
| 64 (COLLADA_NAMESPACE COLLADA_NAMESPACE_SEPARATOR value) | 64 (COLLADA_NAMESPACE COLLADA_NAMESPACE_SEPARATOR value) |
| 65 | 65 |
| 66 | 66 |
| 67 namespace o3d { | 67 namespace o3d { |
| 68 | 68 |
| 69 const char* Collada::kLightingTypeParamName = |
| 70 COLLADA_STRING_CONSTANT("lightingType"); |
| 71 |
| 72 const char* Collada::kLightingTypeConstant = "constant"; |
| 73 const char* Collada::kLightingTypePhong = "phong"; |
| 74 const char* Collada::kLightingTypeBlinn = "blinn"; |
| 75 const char* Collada::kLightingTypeLambert = "lambert"; |
| 76 const char* Collada::kLightingTypeUnknown = "unknown"; |
| 77 |
| 78 const char* Collada::kMaterialParamNameEmissive = "emissive"; |
| 79 const char* Collada::kMaterialParamNameAmbient = "ambient"; |
| 80 const char* Collada::kMaterialParamNameDiffuse = "diffuse"; |
| 81 const char* Collada::kMaterialParamNameSpecular = "specular"; |
| 82 const char* Collada::kMaterialParamNameShininess = "shininess"; |
| 83 const char* Collada::kMaterialParamNameSpecularFactor = "specularFactor"; |
| 84 const char* Collada::kMaterialParamNameEmissiveSampler = "emissiveSampler"; |
| 85 const char* Collada::kMaterialParamNameAmbientSampler = "ambientSampler"; |
| 86 const char* Collada::kMaterialParamNameDiffuseSampler = "diffuseSampler"; |
| 87 const char* Collada::kMaterialParamNameSpecularSampler = "specularSampler"; |
| 88 const char* Collada::kMaterialParamNameBumpSampler = "bumpSampler"; |
| 89 |
| 69 class TranslationMap : public FCDGeometryIndexTranslationMap { | 90 class TranslationMap : public FCDGeometryIndexTranslationMap { |
| 70 }; | 91 }; |
| 71 | 92 |
| 72 namespace { | 93 namespace { |
| 73 | 94 |
| 74 Vector3 FMVector3ToVector3(const FMVector3& fmvector3) { | 95 Vector3 FMVector3ToVector3(const FMVector3& fmvector3) { |
| 75 return Vector3(fmvector3.x, fmvector3.y, fmvector3.z); | 96 return Vector3(fmvector3.x, fmvector3.y, fmvector3.z); |
| 76 } | 97 } |
| 77 | 98 |
| 78 Vector4 FMVector4ToVector4(const FMVector4& fmvector4) { | 99 Vector4 FMVector4ToVector4(const FMVector4& fmvector4) { |
| (...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 206 file_util::AbsolutePath(&base_path_); | 227 file_util::AbsolutePath(&base_path_); |
| 207 | 228 |
| 208 bool status = false; | 229 bool status = false; |
| 209 if (ZipArchive::IsZipFile(FilePathToUTF8(filename))) { | 230 if (ZipArchive::IsZipFile(FilePathToUTF8(filename))) { |
| 210 status = ImportZIP(filename, parent, animation_input); | 231 status = ImportZIP(filename, parent, animation_input); |
| 211 } else { | 232 } else { |
| 212 status = ImportDAE(filename, parent, animation_input); | 233 status = ImportDAE(filename, parent, animation_input); |
| 213 } | 234 } |
| 214 | 235 |
| 215 if (!status) { | 236 if (!status) { |
| 216 // TODO: this could probably be the original URI instead of some | 237 // TODO(o3d): this could probably be the original URI instead of some |
| 217 // filename in the temp folder. | 238 // filename in the temp folder. |
| 218 O3D_ERROR(service_locator_) << "Unable to import: " | 239 O3D_ERROR(service_locator_) << "Unable to import: " |
| 219 << FilePathToUTF8(filename).c_str(); | 240 << FilePathToUTF8(filename).c_str(); |
| 220 } | 241 } |
| 221 | 242 |
| 222 return status; | 243 return status; |
| 223 } | 244 } |
| 224 | 245 |
| 225 // Imports the given ZIP file into the given client. | 246 // Imports the given ZIP file into the given client. |
| 226 // Parameters: see Import() above. | 247 // Parameters: see Import() above. |
| (...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 334 Vector3 up_axis = options_.up_axis; | 355 Vector3 up_axis = options_.up_axis; |
| 335 FMVector3 up(up_axis.getX(), up_axis.getY(), up_axis.getZ()); | 356 FMVector3 up(up_axis.getX(), up_axis.getY(), up_axis.getZ()); |
| 336 // Transform the document to the given up vector | 357 // Transform the document to the given up vector |
| 337 | 358 |
| 338 FCDocumentTools::StandardizeUpAxisAndLength(doc, up); | 359 FCDocumentTools::StandardizeUpAxisAndLength(doc, up); |
| 339 | 360 |
| 340 // Import all the textures in the file. Even if they are not used by | 361 // Import all the textures in the file. Even if they are not used by |
| 341 // materials or models the user put them in the file and might need them | 362 // materials or models the user put them in the file and might need them |
| 342 // at runtime. | 363 // at runtime. |
| 343 // | 364 // |
| 344 // TODO: Add option to skip this step if user just wants what's | 365 // TODO(o3d): Add option to skip this step if user just wants what's |
| 345 // actually used by models. The rest of the code already deals with this. | 366 // actually used by models. The rest of the code already deals with this. |
| 346 FCDImageLibrary* image_library = doc->GetImageLibrary(); | 367 FCDImageLibrary* image_library = doc->GetImageLibrary(); |
| 347 for (uint32 i = 0; i < image_library->GetEntityCount(); i++) { | 368 for (uint32 i = 0; i < image_library->GetEntityCount(); i++) { |
| 348 FCDEntity* entity = image_library->GetEntity(i); | 369 FCDEntity* entity = image_library->GetEntity(i); |
| 349 LOG_ASSERT(entity); | 370 LOG_ASSERT(entity); |
| 350 LOG_ASSERT(entity->GetType() == FCDEntity::IMAGE); | 371 LOG_ASSERT(entity->GetType() == FCDEntity::IMAGE); |
| 351 FCDImage* image = down_cast<FCDImage*>(entity); | 372 FCDImage* image = down_cast<FCDImage*>(entity); |
| 352 BuildTextureFromImage(image); | 373 BuildTextureFromImage(image); |
| 353 } | 374 } |
| 354 | 375 |
| 355 // Import all the materials in the file. Even if they are not used by | 376 // Import all the materials in the file. Even if they are not used by |
| 356 // models the user put them in the file and might need them at runtime. | 377 // models the user put them in the file and might need them at runtime. |
| 357 // | 378 // |
| 358 // TODO: Add option to skip this step if user just wants what's | 379 // TODO(o3d): Add option to skip this step if user just wants what's |
| 359 // actually used by models. The rest of the code already deals with this. | 380 // actually used by models. The rest of the code already deals with this. |
| 360 FCDMaterialLibrary* material_library = doc->GetMaterialLibrary(); | 381 FCDMaterialLibrary* material_library = doc->GetMaterialLibrary(); |
| 361 for (uint32 i = 0; i < material_library->GetEntityCount(); i++) { | 382 for (uint32 i = 0; i < material_library->GetEntityCount(); i++) { |
| 362 FCDEntity* entity = material_library->GetEntity(i); | 383 FCDEntity* entity = material_library->GetEntity(i); |
| 363 LOG_ASSERT(entity); | 384 LOG_ASSERT(entity); |
| 364 LOG_ASSERT(entity->GetType() == FCDEntity::MATERIAL); | 385 LOG_ASSERT(entity->GetType() == FCDEntity::MATERIAL); |
| 365 FCDMaterial* collada_material = down_cast<FCDMaterial*>(entity); | 386 FCDMaterial* collada_material = down_cast<FCDMaterial*>(entity); |
| 366 BuildMaterial(doc, collada_material); | 387 BuildMaterial(doc, collada_material); |
| 367 } | 388 } |
| 368 | 389 |
| (...skipping 431 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 800 } | 821 } |
| 801 | 822 |
| 802 Transform* transform = node_instance->transform(); | 823 Transform* transform = node_instance->transform(); |
| 803 for (size_t i = 0; i < node->GetInstanceCount(); ++i) { | 824 for (size_t i = 0; i < node->GetInstanceCount(); ++i) { |
| 804 FCDEntityInstance* instance = node->GetInstance(i); | 825 FCDEntityInstance* instance = node->GetInstance(i); |
| 805 FCDCamera* camera(NULL); | 826 FCDCamera* camera(NULL); |
| 806 FCDGeometryInstance* geom_instance(NULL); | 827 FCDGeometryInstance* geom_instance(NULL); |
| 807 | 828 |
| 808 LOG_ASSERT(instance != 0); | 829 LOG_ASSERT(instance != 0); |
| 809 // Import each node based on what kind of entity it is | 830 // Import each node based on what kind of entity it is |
| 810 // TODO: add more entity types as they are supported | 831 // TODO(o3d): add more entity types as they are supported |
| 811 switch (instance->GetEntityType()) { | 832 switch (instance->GetEntityType()) { |
| 812 case FCDEntity::CAMERA: | 833 case FCDEntity::CAMERA: |
| 813 // camera entity | 834 // camera entity |
| 814 camera = down_cast<FCDCamera*>(instance->GetEntity()); | 835 camera = down_cast<FCDCamera*>(instance->GetEntity()); |
| 815 BuildCamera(doc, camera, transform, node); | 836 BuildCamera(doc, camera, transform, node); |
| 816 break; | 837 break; |
| 817 case FCDEntity::GEOMETRY: { | 838 case FCDEntity::GEOMETRY: { |
| 818 // geometry entity | 839 // geometry entity |
| 819 geom_instance = static_cast<FCDGeometryInstance*>(instance); | 840 geom_instance = static_cast<FCDGeometryInstance*>(instance); |
| 820 Shape* shape = GetShape(doc, geom_instance); | 841 Shape* shape = GetShape(doc, geom_instance); |
| (...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1014 transform->CreateParam<ParamFloat3>( | 1035 transform->CreateParam<ParamFloat3>( |
| 1015 COLLADA_STRING_CONSTANT("upVector")); | 1036 COLLADA_STRING_CONSTANT("upVector")); |
| 1016 Vector4 world_up = parent_world * Vector4(up.x, up.y, up.z, 0.0f); | 1037 Vector4 world_up = parent_world * Vector4(up.x, up.y, up.z, 0.0f); |
| 1017 param_up_vector->set_value(Float3(world_up.getX(), | 1038 param_up_vector->set_value(Float3(world_up.getX(), |
| 1018 world_up.getY(), | 1039 world_up.getY(), |
| 1019 world_up.getZ())); | 1040 world_up.getZ())); |
| 1020 | 1041 |
| 1021 break; | 1042 break; |
| 1022 } | 1043 } |
| 1023 } | 1044 } |
| 1024 | |
| 1025 } | 1045 } |
| 1026 | 1046 |
| 1027 Shape* Collada::GetShape(FCDocument* doc, | 1047 Shape* Collada::GetShape(FCDocument* doc, |
| 1028 FCDGeometryInstance* geom_instance) { | 1048 FCDGeometryInstance* geom_instance) { |
| 1029 Shape* shape = NULL; | 1049 Shape* shape = NULL; |
| 1030 FCDGeometry* geom = static_cast<FCDGeometry*>(geom_instance->GetEntity()); | 1050 FCDGeometry* geom = static_cast<FCDGeometry*>(geom_instance->GetEntity()); |
| 1031 if (geom) { | 1051 if (geom) { |
| 1032 fm::string geom_id = geom->GetDaeId(); | 1052 fm::string geom_id = geom->GetDaeId(); |
| 1033 shape = shapes_[geom_id.c_str()]; | 1053 shape = shapes_[geom_id.c_str()]; |
| 1034 if (!shape) { | 1054 if (!shape) { |
| (...skipping 206 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1241 // mesh. | 1261 // mesh. |
| 1242 primitive->set_stream_bank(stream_bank); | 1262 primitive->set_stream_bank(stream_bank); |
| 1243 } | 1263 } |
| 1244 } | 1264 } |
| 1245 return shape; | 1265 return shape; |
| 1246 } | 1266 } |
| 1247 | 1267 |
| 1248 Shape* Collada::BuildSkinnedShape(FCDocument* doc, | 1268 Shape* Collada::BuildSkinnedShape(FCDocument* doc, |
| 1249 FCDControllerInstance* instance, | 1269 FCDControllerInstance* instance, |
| 1250 NodeInstance *parent_node_instance) { | 1270 NodeInstance *parent_node_instance) { |
| 1251 // TODO: Handle chained controllers. Morph->Skin->... | 1271 // TODO(o3d): Handle chained controllers. Morph->Skin->... |
| 1252 Shape* shape = NULL; | 1272 Shape* shape = NULL; |
| 1253 LOG_ASSERT(doc && instance); | 1273 LOG_ASSERT(doc && instance); |
| 1254 FCDController* controller = | 1274 FCDController* controller = |
| 1255 static_cast<FCDController*>(instance->GetEntity()); | 1275 static_cast<FCDController*>(instance->GetEntity()); |
| 1256 if (controller && controller->IsSkin()) { | 1276 if (controller && controller->IsSkin()) { |
| 1257 FCDSkinController* skin_controller = controller->GetSkinController(); | 1277 FCDSkinController* skin_controller = controller->GetSkinController(); |
| 1258 TranslationMap translationMap; | 1278 TranslationMap translationMap; |
| 1259 shape = BuildShape(doc, | 1279 shape = BuildShape(doc, |
| 1260 instance, | 1280 instance, |
| 1261 controller->GetBaseGeometry(), | 1281 controller->GetBaseGeometry(), |
| (...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1453 case Stream::NORMAL: | 1473 case Stream::NORMAL: |
| 1454 case Stream::BINORMAL: | 1474 case Stream::BINORMAL: |
| 1455 case Stream::TANGENT: { | 1475 case Stream::TANGENT: { |
| 1456 copied = true; | 1476 copied = true; |
| 1457 unsigned num_source_components = field.num_components(); | 1477 unsigned num_source_components = field.num_components(); |
| 1458 Field* new_field = new_fields[ii]; | 1478 Field* new_field = new_fields[ii]; |
| 1459 | 1479 |
| 1460 std::vector<float> data(num_vertices * num_source_components); | 1480 std::vector<float> data(num_vertices * num_source_components); |
| 1461 field.GetAsFloats(0, &data[0], num_source_components, | 1481 field.GetAsFloats(0, &data[0], num_source_components, |
| 1462 num_vertices); | 1482 num_vertices); |
| 1463 // TODO: Remove this matrix multiply. I don't think it is | 1483 // TODO(o3d): Remove this matrix multiply. I don't think it is |
| 1464 // needed. | 1484 // needed. |
| 1465 for (unsigned vv = 0; vv < num_vertices; ++vv) { | 1485 for (unsigned vv = 0; vv < num_vertices; ++vv) { |
| 1466 float* values = &data[vv * num_source_components]; | 1486 float* values = &data[vv * num_source_components]; |
| 1467 switch (field.num_components()) { | 1487 switch (field.num_components()) { |
| 1468 case 3: { | 1488 case 3: { |
| 1469 if (source_stream.semantic() == Stream::POSITION) { | 1489 if (source_stream.semantic() == Stream::POSITION) { |
| 1470 Vector4 result(matrix * Point3(values[0], | 1490 Vector4 result(matrix * Point3(values[0], |
| 1471 values[1], | 1491 values[1], |
| 1472 values[2])); | 1492 values[2])); |
| 1473 values[0] = result.getElem(0); | 1493 values[0] = result.getElem(0); |
| (...skipping 204 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1678 | 1698 |
| 1679 // Set the texture on the sampler. | 1699 // Set the texture on the sampler. |
| 1680 if (tex) { | 1700 if (tex) { |
| 1681 o3d_sampler->set_texture(tex); | 1701 o3d_sampler->set_texture(tex); |
| 1682 rc = true; | 1702 rc = true; |
| 1683 } | 1703 } |
| 1684 } | 1704 } |
| 1685 SetSamplerStates(sampler, o3d_sampler); | 1705 SetSamplerStates(sampler, o3d_sampler); |
| 1686 } | 1706 } |
| 1687 } else if (type == FCDEffectParameter::SURFACE) { | 1707 } else if (type == FCDEffectParameter::SURFACE) { |
| 1688 // TODO: This code is here to handle the NV_import profile | 1708 // TODO(o3d): This code is here to handle the NV_import profile |
| 1689 // exported by Max's DirectX Shader materials, which references | 1709 // exported by Max's DirectX Shader materials, which references |
| 1690 // only references texture params (not samplers). Once we move | 1710 // only references texture params (not samplers). Once we move |
| 1691 // completely to using samplers and add sampler blocks to our | 1711 // completely to using samplers and add sampler blocks to our |
| 1692 // collada file then we should eliminate this codepath. | 1712 // collada file then we should eliminate this codepath. |
| 1693 | 1713 |
| 1694 FCDEffectParameterSurface* surface = | 1714 FCDEffectParameterSurface* surface = |
| 1695 static_cast<FCDEffectParameterSurface*>(fc_param); | 1715 static_cast<FCDEffectParameterSurface*>(fc_param); |
| 1696 | 1716 |
| 1697 Texture* tex = BuildTexture(surface); | 1717 Texture* tex = BuildTexture(surface); |
| 1698 if (tex) { | 1718 if (tex) { |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1733 COLLADA_STRING_CONSTANT("substituteForMissingOrBadMaterial")); | 1753 COLLADA_STRING_CONSTANT("substituteForMissingOrBadMaterial")); |
| 1734 dummy_material_->set_effect(GetDummyEffect()); | 1754 dummy_material_->set_effect(GetDummyEffect()); |
| 1735 } | 1755 } |
| 1736 return dummy_material_; | 1756 return dummy_material_; |
| 1737 } | 1757 } |
| 1738 | 1758 |
| 1739 static const char* GetLightingType(FCDEffectStandard* std_profile) { | 1759 static const char* GetLightingType(FCDEffectStandard* std_profile) { |
| 1740 FCDEffectStandard::LightingType type = std_profile->GetLightingType(); | 1760 FCDEffectStandard::LightingType type = std_profile->GetLightingType(); |
| 1741 switch (type) { | 1761 switch (type) { |
| 1742 case FCDEffectStandard::CONSTANT: | 1762 case FCDEffectStandard::CONSTANT: |
| 1743 return "constant"; | 1763 return Collada::kLightingTypeConstant; |
| 1744 case FCDEffectStandard::PHONG: | 1764 case FCDEffectStandard::PHONG: |
| 1745 return "phong"; | 1765 return Collada::kLightingTypePhong; |
| 1746 case FCDEffectStandard::BLINN: | 1766 case FCDEffectStandard::BLINN: |
| 1747 return "blinn"; | 1767 return Collada::kLightingTypeBlinn; |
| 1748 case FCDEffectStandard::LAMBERT: | 1768 case FCDEffectStandard::LAMBERT: |
| 1749 return "lambert"; | 1769 return Collada::kLightingTypeLambert; |
| 1750 default: | 1770 default: |
| 1751 return "unknown"; | 1771 return Collada::kLightingTypeUnknown; |
| 1752 } | 1772 } |
| 1753 } | 1773 } |
| 1754 | 1774 |
| 1755 static FCDEffectProfileFX* FindProfileFX(FCDEffect* effect) { | 1775 static FCDEffectProfileFX* FindProfileFX(FCDEffect* effect) { |
| 1756 FCDEffectProfile* profile = effect->FindProfile(FUDaeProfileType::HLSL); | 1776 FCDEffectProfile* profile = effect->FindProfile(FUDaeProfileType::HLSL); |
| 1757 if (!profile) { | 1777 if (!profile) { |
| 1758 profile = effect->FindProfile(FUDaeProfileType::CG); | 1778 profile = effect->FindProfile(FUDaeProfileType::CG); |
| 1759 if (!profile) { | 1779 if (!profile) { |
| 1760 return NULL; | 1780 return NULL; |
| 1761 } | 1781 } |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1800 AddRenderState(pass->GetRenderState(i), state); | 1820 AddRenderState(pass->GetRenderState(i), state); |
| 1801 } | 1821 } |
| 1802 material->set_state(state); | 1822 material->set_state(state); |
| 1803 } | 1823 } |
| 1804 } | 1824 } |
| 1805 } else { | 1825 } else { |
| 1806 FCDEffectStandard* std_profile = static_cast<FCDEffectStandard *>( | 1826 FCDEffectStandard* std_profile = static_cast<FCDEffectStandard *>( |
| 1807 collada_effect->FindProfile(FUDaeProfileType::COMMON)); | 1827 collada_effect->FindProfile(FUDaeProfileType::COMMON)); |
| 1808 if (std_profile) { | 1828 if (std_profile) { |
| 1809 ParamString* type_tag = material->CreateParam<ParamString>( | 1829 ParamString* type_tag = material->CreateParam<ParamString>( |
| 1810 COLLADA_STRING_CONSTANT("lightingType")); | 1830 kLightingTypeParamName); |
| 1811 type_tag->set_value(GetLightingType(std_profile)); | 1831 type_tag->set_value(GetLightingType(std_profile)); |
| 1812 } | 1832 } |
| 1813 } | 1833 } |
| 1814 materials_[material_id.c_str()] = material; | 1834 materials_[material_id.c_str()] = material; |
| 1815 } | 1835 } |
| 1816 return material; | 1836 return material; |
| 1817 } | 1837 } |
| 1818 | 1838 |
| 1819 Effect* Collada::GetEffect(FCDocument* doc, FCDEffect* collada_effect) { | 1839 Effect* Collada::GetEffect(FCDocument* doc, FCDEffect* collada_effect) { |
| 1820 Effect* effect = NULL; | 1840 Effect* effect = NULL; |
| (...skipping 10 matching lines...) Expand all Loading... |
| 1831 // (Cg/HLSL) effect is present, it will be used and a programmable | 1851 // (Cg/HLSL) effect is present, it will be used and a programmable |
| 1832 // Effect generated. If not, an attempt is made to use one of the fixed- | 1852 // Effect generated. If not, an attempt is made to use one of the fixed- |
| 1833 // function profiles if present (eg., Constant, Lambert). | 1853 // function profiles if present (eg., Constant, Lambert). |
| 1834 // Parameters: | 1854 // Parameters: |
| 1835 // doc: The FCollada document from which to import nodes. | 1855 // doc: The FCollada document from which to import nodes. |
| 1836 // collada_effect: The COLLADA effect from which shaders will be taken. | 1856 // collada_effect: The COLLADA effect from which shaders will be taken. |
| 1837 // Returns: | 1857 // Returns: |
| 1838 // the newly-created effect, or NULL or error. | 1858 // the newly-created effect, or NULL or error. |
| 1839 Effect* Collada::BuildEffect(FCDocument* doc, FCDEffect* collada_effect) { | 1859 Effect* Collada::BuildEffect(FCDocument* doc, FCDEffect* collada_effect) { |
| 1840 if (!doc || !collada_effect) return NULL; | 1860 if (!doc || !collada_effect) return NULL; |
| 1841 // TODO: Remove all of this to be replaced by parsing Collada-FX | 1861 // TODO(o3d): Remove all of this to be replaced by parsing Collada-FX |
| 1842 // and profile_O3D only. | 1862 // and profile_O3D only. |
| 1843 Effect* effect = NULL; | 1863 Effect* effect = NULL; |
| 1844 FCDEffectProfileFX* profile_fx = FindProfileFX(collada_effect); | 1864 FCDEffectProfileFX* profile_fx = FindProfileFX(collada_effect); |
| 1845 if (profile_fx) { | 1865 if (profile_fx) { |
| 1846 if (profile_fx->GetCodeCount() > 0) { | 1866 if (profile_fx->GetCodeCount() > 0) { |
| 1847 FCDEffectCode* code = profile_fx->GetCode(0); | 1867 FCDEffectCode* code = profile_fx->GetCode(0); |
| 1848 String effect_string; | 1868 String effect_string; |
| 1849 FilePath file_path; | 1869 FilePath file_path; |
| 1850 if (code->GetType() == FCDEffectCode::CODE) { | 1870 if (code->GetType() == FCDEffectCode::CODE) { |
| 1851 fstring code_string = code->GetCode(); | 1871 fstring code_string = code->GetCode(); |
| (...skipping 18 matching lines...) Expand all Loading... |
| 1870 if (effect_data) { | 1890 if (effect_data) { |
| 1871 effect_string = effect_data; | 1891 effect_string = effect_data; |
| 1872 free(effect_data); | 1892 free(effect_data); |
| 1873 } else { | 1893 } else { |
| 1874 O3D_ERROR(service_locator_) | 1894 O3D_ERROR(service_locator_) |
| 1875 << "Unable to read effect data for effect '" | 1895 << "Unable to read effect data for effect '" |
| 1876 << FilePathToUTF8(file_path) << "'"; | 1896 << FilePathToUTF8(file_path) << "'"; |
| 1877 return NULL; | 1897 return NULL; |
| 1878 } | 1898 } |
| 1879 } else { | 1899 } else { |
| 1880 file_util::ReadFileToString(file_path, &effect_string); | 1900 FilePath temp_path = file_path; |
| 1901 GetRelativePathIfPossible(base_path_, temp_path, &temp_path); |
| 1902 file_util::ReadFileToString(temp_path, &effect_string); |
| 1881 } | 1903 } |
| 1882 } | 1904 } |
| 1883 String collada_effect_name = WideToUTF8( | 1905 String collada_effect_name = WideToUTF8( |
| 1884 collada_effect->GetName().c_str()); | 1906 collada_effect->GetName().c_str()); |
| 1885 effect = pack_->Create<Effect>(); | 1907 effect = pack_->Create<Effect>(); |
| 1886 effect->set_name(collada_effect_name); | 1908 effect->set_name(collada_effect_name); |
| 1887 | 1909 |
| 1888 ParamString* param = effect->CreateParam<ParamString>( | 1910 ParamString* param = effect->CreateParam<ParamString>( |
| 1889 O3D_STRING_CONSTANT("uri")); | 1911 O3D_STRING_CONSTANT("uri")); |
| 1890 DCHECK(param != NULL); | 1912 DCHECK(param != NULL); |
| (...skipping 642 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2533 bool allow_none) { | 2555 bool allow_none) { |
| 2534 switch (filter_function) { | 2556 switch (filter_function) { |
| 2535 case FUDaeTextureFilterFunction::NEAREST: | 2557 case FUDaeTextureFilterFunction::NEAREST: |
| 2536 case FUDaeTextureFilterFunction::NEAREST_MIPMAP_NEAREST: | 2558 case FUDaeTextureFilterFunction::NEAREST_MIPMAP_NEAREST: |
| 2537 case FUDaeTextureFilterFunction::NEAREST_MIPMAP_LINEAR: | 2559 case FUDaeTextureFilterFunction::NEAREST_MIPMAP_LINEAR: |
| 2538 return Sampler::POINT; | 2560 return Sampler::POINT; |
| 2539 case FUDaeTextureFilterFunction::LINEAR: | 2561 case FUDaeTextureFilterFunction::LINEAR: |
| 2540 case FUDaeTextureFilterFunction::LINEAR_MIPMAP_NEAREST: | 2562 case FUDaeTextureFilterFunction::LINEAR_MIPMAP_NEAREST: |
| 2541 case FUDaeTextureFilterFunction::LINEAR_MIPMAP_LINEAR: | 2563 case FUDaeTextureFilterFunction::LINEAR_MIPMAP_LINEAR: |
| 2542 return Sampler::LINEAR; | 2564 return Sampler::LINEAR; |
| 2543 // TODO: Once FCollada supports COLLADA v1.5, turn this on: | 2565 // TODO(o3d): Once FCollada supports COLLADA v1.5, turn this on: |
| 2544 // case FUDaeTextureFilterFunction::ANISOTROPIC: | 2566 // case FUDaeTextureFilterFunction::ANISOTROPIC: |
| 2545 // return Sampler::ANISOTROPIC; | 2567 // return Sampler::ANISOTROPIC; |
| 2546 case FUDaeTextureFilterFunction::NONE: | 2568 case FUDaeTextureFilterFunction::NONE: |
| 2547 return allow_none ? Sampler::NONE : Sampler::LINEAR; | 2569 return allow_none ? Sampler::NONE : Sampler::LINEAR; |
| 2548 default: | 2570 default: |
| 2549 return Sampler::LINEAR; | 2571 return Sampler::LINEAR; |
| 2550 } | 2572 } |
| 2551 } | 2573 } |
| 2552 | 2574 |
| 2553 | 2575 |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2586 wrap_t = FUDaeTextureWrapMode::CLAMP; | 2608 wrap_t = FUDaeTextureWrapMode::CLAMP; |
| 2587 } | 2609 } |
| 2588 | 2610 |
| 2589 FUDaeTextureFilterFunction::FilterFunction min_filter = | 2611 FUDaeTextureFilterFunction::FilterFunction min_filter = |
| 2590 effect_sampler->GetMinFilter(); | 2612 effect_sampler->GetMinFilter(); |
| 2591 FUDaeTextureFilterFunction::FilterFunction mag_filter = | 2613 FUDaeTextureFilterFunction::FilterFunction mag_filter = |
| 2592 effect_sampler->GetMagFilter(); | 2614 effect_sampler->GetMagFilter(); |
| 2593 | 2615 |
| 2594 FUDaeTextureFilterFunction::FilterFunction mip_filter = | 2616 FUDaeTextureFilterFunction::FilterFunction mip_filter = |
| 2595 effect_sampler->GetMipFilter(); | 2617 effect_sampler->GetMipFilter(); |
| 2596 // TODO: Once FCollada supports COLLADA v1.5, turn this on: | 2618 // TODO(o3d): Once FCollada supports COLLADA v1.5, turn this on: |
| 2597 // int max_anisotropy = effect_sampler->GetMaxAnisotropy(); | 2619 // int max_anisotropy = effect_sampler->GetMaxAnisotropy(); |
| 2598 | 2620 |
| 2599 o3d_sampler->set_address_mode_u(ConvertSamplerAddressMode(wrap_s)); | 2621 o3d_sampler->set_address_mode_u(ConvertSamplerAddressMode(wrap_s)); |
| 2600 o3d_sampler->set_address_mode_v(ConvertSamplerAddressMode(wrap_t)); | 2622 o3d_sampler->set_address_mode_v(ConvertSamplerAddressMode(wrap_t)); |
| 2601 | 2623 |
| 2602 // The Collada spec allows for both DX-style and GL-style specification | 2624 // The Collada spec allows for both DX-style and GL-style specification |
| 2603 // of texture filtering modes. In DX-style, Min, Mag and Mip filters | 2625 // of texture filtering modes. In DX-style, Min, Mag and Mip filters |
| 2604 // are specified separately, and may be Linear, Point or None. | 2626 // are specified separately, and may be Linear, Point or None. |
| 2605 // In GL-style, only Min and Mag are specified, with the Mip filter | 2627 // In GL-style, only Min and Mag are specified, with the Mip filter |
| 2606 // encoded as a combo setting in the Min filter. E.g., | 2628 // encoded as a combo setting in the Min filter. E.g., |
| (...skipping 13 matching lines...) Expand all Loading... |
| 2620 | 2642 |
| 2621 // If the mip filter is set to "UNKNOWN", we assume it's a GL-style | 2643 // If the mip filter is set to "UNKNOWN", we assume it's a GL-style |
| 2622 // mode, and use the 2nd part of the Min filter for the mip type. Otherwise, | 2644 // mode, and use the 2nd part of the Min filter for the mip type. Otherwise, |
| 2623 // we use the first part. | 2645 // we use the first part. |
| 2624 if (mip_filter == FUDaeTextureFilterFunction::UNKNOWN) { | 2646 if (mip_filter == FUDaeTextureFilterFunction::UNKNOWN) { |
| 2625 o3d_sampler->set_mip_filter(ConvertMipmapFilter(min_filter)); | 2647 o3d_sampler->set_mip_filter(ConvertMipmapFilter(min_filter)); |
| 2626 } else { | 2648 } else { |
| 2627 o3d_sampler->set_mip_filter(ConvertFilterType(mip_filter, true)); | 2649 o3d_sampler->set_mip_filter(ConvertFilterType(mip_filter, true)); |
| 2628 } | 2650 } |
| 2629 | 2651 |
| 2630 // TODO: Once FCollada supports COLLADA v1.5, turn this on: | 2652 // TODO(o3d): Once FCollada supports COLLADA v1.5, turn this on: |
| 2631 // o3d_sampler->set_max_anisotropy(max_anisotropy); | 2653 // o3d_sampler->set_max_anisotropy(max_anisotropy); |
| 2632 } | 2654 } |
| 2633 | 2655 |
| 2634 // Sets the value of a Param on the given ParamObject from an FCollada | 2656 // Sets the value of a Param on the given ParamObject from an FCollada |
| 2635 // standard-profile effect parameter. If the FCollada parameter | 2657 // standard-profile effect parameter. If the FCollada parameter |
| 2636 // contains a texture, the sampler_param_name and channel is used to set | 2658 // contains a texture, the sampler_param_name and channel is used to set |
| 2637 // a Sampler Param in o3d from the surface. If not, the | 2659 // a Sampler Param in o3d from the surface. If not, the |
| 2638 // color_param_name is used to create set a vector Param value. | 2660 // color_param_name is used to create set a vector Param value. |
| 2639 // Parameters: | 2661 // Parameters: |
| 2640 // effect_standard: The fixed-function FCollada effect from which | 2662 // effect_standard: The fixed-function FCollada effect from which |
| (...skipping 16 matching lines...) Expand all Loading... |
| 2657 FCDEffectParameterSampler* sampler = texture->GetSampler(); | 2679 FCDEffectParameterSampler* sampler = texture->GetSampler(); |
| 2658 SetParamFromFCEffectParam(param_object, sampler_param_name, sampler); | 2680 SetParamFromFCEffectParam(param_object, sampler_param_name, sampler); |
| 2659 } else if (color_param) { | 2681 } else if (color_param) { |
| 2660 SetParamFromFCEffectParam(param_object, color_param_name, color_param); | 2682 SetParamFromFCEffectParam(param_object, color_param_name, color_param); |
| 2661 } | 2683 } |
| 2662 } | 2684 } |
| 2663 | 2685 |
| 2664 // Sets the values of a ParamObject parameters from a given FCollada material | 2686 // Sets the values of a ParamObject parameters from a given FCollada material |
| 2665 // node. If a corresponding ParamObject parameter is not found, the FCollada | 2687 // node. If a corresponding ParamObject parameter is not found, the FCollada |
| 2666 // parameter is ignored. | 2688 // parameter is ignored. |
| 2667 // TODO: Should we ignore params not found? Maybe the user wants those for | 2689 // TODO(o3d): Should we ignore params not found? Maybe the user wants those for |
| 2668 // things other than rendering. | 2690 // things other than rendering. |
| 2669 // Parameters: | 2691 // Parameters: |
| 2670 // material: The FCollada material node from which to retrieve values. | 2692 // material: The FCollada material node from which to retrieve values. |
| 2671 // param_object: The ParamObject on which parameters will be set. | 2693 // param_object: The ParamObject on which parameters will be set. |
| 2672 void Collada::SetParamsFromMaterial(FCDMaterial* material, | 2694 void Collada::SetParamsFromMaterial(FCDMaterial* material, |
| 2673 ParamObject* param_object) { | 2695 ParamObject* param_object) { |
| 2674 size_t pcount = material->GetEffectParameterCount(); | 2696 size_t pcount = material->GetEffectParameterCount(); |
| 2675 // TODO: This test (for determining if we used the | 2697 // TODO(o3d): This test (for determining if we used the |
| 2676 // programmable profile or the fixed-func profile) is not very robust. | 2698 // programmable profile or the fixed-func profile) is not very robust. |
| 2677 // Remove this once the Material changes are in. | 2699 // Remove this once the Material changes are in. |
| 2678 if (pcount > 0) { | 2700 if (pcount > 0) { |
| 2679 for (size_t i = 0; i < pcount; ++i) { | 2701 for (size_t i = 0; i < pcount; ++i) { |
| 2680 FCDEffectParameter* p = material->GetEffectParameter(i); | 2702 FCDEffectParameter* p = material->GetEffectParameter(i); |
| 2681 LOG_ASSERT(p); | 2703 LOG_ASSERT(p); |
| 2682 String param_name(p->GetReference()); | 2704 String param_name(p->GetReference()); |
| 2683 // Check for an effect binding | 2705 // Check for an effect binding |
| 2684 FCDEffect* effect = material->GetEffect(); | 2706 FCDEffect* effect = material->GetEffect(); |
| 2685 FCDEffectProfileFX* profile_fx = FindProfileFX(material->GetEffect()); | 2707 FCDEffectProfileFX* profile_fx = FindProfileFX(material->GetEffect()); |
| (...skipping 14 matching lines...) Expand all Loading... |
| 2700 } | 2722 } |
| 2701 SetParamFromFCEffectParam(param_object, param_name, p); | 2723 SetParamFromFCEffectParam(param_object, param_name, p); |
| 2702 } | 2724 } |
| 2703 } else { | 2725 } else { |
| 2704 FCDEffect* effect = material->GetEffect(); | 2726 FCDEffect* effect = material->GetEffect(); |
| 2705 FCDEffectStandard* effect_standard; | 2727 FCDEffectStandard* effect_standard; |
| 2706 if (effect && (effect_standard = static_cast<FCDEffectStandard *>( | 2728 if (effect && (effect_standard = static_cast<FCDEffectStandard *>( |
| 2707 effect->FindProfile(FUDaeProfileType::COMMON))) != NULL) { | 2729 effect->FindProfile(FUDaeProfileType::COMMON))) != NULL) { |
| 2708 SetParamFromStandardEffectParam(effect_standard, | 2730 SetParamFromStandardEffectParam(effect_standard, |
| 2709 param_object, | 2731 param_object, |
| 2710 "emissive", | 2732 kMaterialParamNameEmissive, |
| 2711 "emissiveSampler", | 2733 kMaterialParamNameEmissiveSampler, |
| 2712 effect_standard->GetEmissionColorParam(), | 2734 effect_standard->GetEmissionColorParam(), |
| 2713 FUDaeTextureChannel::EMISSION); | 2735 FUDaeTextureChannel::EMISSION); |
| 2714 SetParamFromStandardEffectParam(effect_standard, | 2736 SetParamFromStandardEffectParam(effect_standard, |
| 2715 param_object, | 2737 param_object, |
| 2716 "ambient", | 2738 kMaterialParamNameAmbient, |
| 2717 "ambientSampler", | 2739 kMaterialParamNameAmbientSampler, |
| 2718 effect_standard->GetAmbientColorParam(), | 2740 effect_standard->GetAmbientColorParam(), |
| 2719 FUDaeTextureChannel::AMBIENT); | 2741 FUDaeTextureChannel::AMBIENT); |
| 2720 SetParamFromStandardEffectParam(effect_standard, | 2742 SetParamFromStandardEffectParam(effect_standard, |
| 2721 param_object, | 2743 param_object, |
| 2722 "diffuse", | 2744 kMaterialParamNameDiffuse, |
| 2723 "diffuseSampler", | 2745 kMaterialParamNameDiffuseSampler, |
| 2724 effect_standard->GetDiffuseColorParam(), | 2746 effect_standard->GetDiffuseColorParam(), |
| 2725 FUDaeTextureChannel::DIFFUSE); | 2747 FUDaeTextureChannel::DIFFUSE); |
| 2726 SetParamFromStandardEffectParam(effect_standard, | 2748 SetParamFromStandardEffectParam(effect_standard, |
| 2727 param_object, | 2749 param_object, |
| 2728 "specular", | 2750 kMaterialParamNameSpecular, |
| 2729 "specularSampler", | 2751 kMaterialParamNameSpecularSampler, |
| 2730 effect_standard->GetSpecularColorParam(), | 2752 effect_standard->GetSpecularColorParam(), |
| 2731 FUDaeTextureChannel::SPECULAR); | 2753 FUDaeTextureChannel::SPECULAR); |
| 2732 SetParamFromStandardEffectParam(effect_standard, | 2754 SetParamFromStandardEffectParam(effect_standard, |
| 2733 param_object, | 2755 param_object, |
| 2734 NULL, | 2756 NULL, |
| 2735 "bumpSampler", | 2757 kMaterialParamNameBumpSampler, |
| 2736 NULL, | 2758 NULL, |
| 2737 FUDaeTextureChannel::BUMP); | 2759 FUDaeTextureChannel::BUMP); |
| 2738 SetParamFromFCEffectParam(param_object, | 2760 SetParamFromFCEffectParam(param_object, |
| 2739 "shininess", | 2761 kMaterialParamNameShininess, |
| 2740 effect_standard->GetShininessParam()); | 2762 effect_standard->GetShininessParam()); |
| 2741 SetParamFromFCEffectParam(param_object, | 2763 SetParamFromFCEffectParam(param_object, |
| 2742 "specularFactor", | 2764 kMaterialParamNameSpecularFactor, |
| 2743 effect_standard->GetSpecularFactorParam()); | 2765 effect_standard->GetSpecularFactorParam()); |
| 2744 } | 2766 } |
| 2745 } | 2767 } |
| 2746 } | 2768 } |
| 2747 } // namespace o3d | 2769 } // namespace o3d |
| OLD | NEW |