diff options
author | gman@google.com <gman@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-06-29 22:54:27 +0000 |
---|---|---|
committer | gman@google.com <gman@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-06-29 22:54:27 +0000 |
commit | af892b45dc366dd19c98f2bd030ed87b9152468c (patch) | |
tree | 0b75bc06109c3fabbbd239f161282aa71ddcff6a /o3d/converter | |
parent | 41bc40e3bbfb9426a8f48cd155bbf695f016d52d (diff) | |
download | chromium_src-af892b45dc366dd19c98f2bd030ed87b9152468c.zip chromium_src-af892b45dc366dd19c98f2bd030ed87b9152468c.tar.gz chromium_src-af892b45dc366dd19c98f2bd030ed87b9152468c.tar.bz2 |
Updates the o3dConverter to turn on filtering by default
because the collada exporters often set it to NONE or POINT.
Also make it change any collada standard Material
that is used by a Primitive with no normals to use
"constant" shading. This should make sketchup stuff
work.
Review URL: http://codereview.chromium.org/147192
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@19545 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'o3d/converter')
-rw-r--r-- | o3d/converter/cross/converter.cc | 72 | ||||
-rw-r--r-- | o3d/converter/cross/converter.h | 12 | ||||
-rw-r--r-- | o3d/converter/cross/converter_main.cc | 21 |
3 files changed, 101 insertions, 4 deletions
diff --git a/o3d/converter/cross/converter.cc b/o3d/converter/cross/converter.cc index 981b129..6f50787 100644 --- a/o3d/converter/cross/converter.cc +++ b/o3d/converter/cross/converter.cc @@ -132,6 +132,78 @@ bool Convert(const FilePath& in_filename, pack->RemoveObject(param_object); } + // Mark all Samplers to use tri-linear filtering + if (!options.keep_filters) { + std::vector<Sampler*> samplers = pack->GetByClass<Sampler>(); + for (unsigned ii = 0; ii < samplers.size(); ++ii) { + Sampler* sampler = samplers[ii]; + sampler->set_mag_filter(Sampler::LINEAR); + sampler->set_min_filter(Sampler::LINEAR); + sampler->set_mip_filter(Sampler::LINEAR); + } + } + + // Mark all Materials that are on Primitives that have no normals as constant. + if (!options.keep_materials) { + std::vector<Primitive*> primitives = pack->GetByClass<Primitive>(); + for (unsigned ii = 0; ii < primitives.size(); ++ii) { + Primitive* primitive = primitives[ii]; + StreamBank* stream_bank = primitive->stream_bank(); + if (stream_bank && !stream_bank->GetVertexStream(Stream::NORMAL, 0)) { + Material* material = primitive->material(); + if (material) { + ParamString* lighting_param = material->GetParam<ParamString>( + Collada::kLightingTypeParamName); + if (lighting_param) { + // If the lighting type is lambert, blinn, or phong + // copy the diffuse color to the emissive since that's most likely + // what the user wants to see. + if (lighting_param->value().compare( + Collada::kLightingTypeLambert) == 0 || + lighting_param->value().compare( + Collada::kLightingTypeBlinn) == 0 || + lighting_param->value().compare( + Collada::kLightingTypePhong) == 0) { + // There's 4 cases: (to bad they are not the same names) + // 1) Diffuse -> Emissive + // 2) DiffuseSampler -> Emissive + // 3) Diffuse -> EmissiveSampler + // 4) DiffuseSampler -> EmissiveSampler + ParamFloat4* diffuse_param = material->GetParam<ParamFloat4>( + Collada::kMaterialParamNameDiffuse); + ParamFloat4* emissive_param = material->GetParam<ParamFloat4>( + Collada::kMaterialParamNameEmissive); + ParamSampler* diffuse_sampler_param = + material->GetParam<ParamSampler>( + Collada::kMaterialParamNameDiffuseSampler); + ParamSampler* emissive_sampler_param = + material->GetParam<ParamSampler>( + Collada::kMaterialParamNameEmissive); + Param* source_param = diffuse_param ? + static_cast<Param*>(diffuse_param) : + static_cast<Param*>(diffuse_sampler_param); + Param* destination_param = emissive_param ? + static_cast<Param*>(emissive_param) : + static_cast<Param*>(emissive_sampler_param); + if (!source_param->IsA(destination_param->GetClass())) { + // The params do not match type so we need to make the emissive + // Param the same as the diffuse Param. + material->RemoveParam(destination_param); + destination_param = material->CreateParamByClass( + diffuse_param ? Collada::kMaterialParamNameEmissive : + Collada::kMaterialParamNameEmissiveSampler, + source_param->GetClass()); + DCHECK(destination_param); + } + destination_param->CopyDataFromParam(source_param); + } + lighting_param->set_value(Collada::kLightingTypeConstant); + } + } + } + } + } + // Attempt to open the output file. FILE* out_file = file_util::OpenFile(out_filename, "wb"); if (out_file == NULL) { diff --git a/o3d/converter/cross/converter.h b/o3d/converter/cross/converter.h index 1524493..dd0141c 100644 --- a/o3d/converter/cross/converter.h +++ b/o3d/converter/cross/converter.h @@ -50,7 +50,10 @@ struct Options { : base_path(FilePath::kCurrentDirectory), condition(true), up_axis(0, 0, 0), - pretty_print(false) {} + pretty_print(false), + keep_filters(false), + keep_materials(false) { + } // The path to the "base" of the model path, from which all paths // are made relative. Defaults to the current directory. @@ -68,6 +71,13 @@ struct Options { // pretty-printed (formatted with spaces and newlines) or just // emitted as one huge one-line string. Defaults to false. bool pretty_print; + + // Tells the converter not to set all filters to tri-linear. + bool keep_filters; + + // Tells the converter not to change materials to constant if they are used by + // a mesh that has no normals. + bool keep_materials; }; // Converts the given file for use in O3D. This is done by diff --git a/o3d/converter/cross/converter_main.cc b/o3d/converter/cross/converter_main.cc index 85cc594..650e0b7 100644 --- a/o3d/converter/cross/converter_main.cc +++ b/o3d/converter/cross/converter_main.cc @@ -80,9 +80,24 @@ int CrossMain(int argc, char**argv) { in_filename = o3d::WideToFilePath(values[0]); out_filename = o3d::WideToFilePath(values[1]); } else { - std::cerr << "Usage: " << argv[0] - << " [--no-condition] [--base-path=<path>] [--up-axis=x,y,z]" - << " [--pretty-print] <infile.dae> [ <outfile> ]\n"; + std::cerr << "Usage: " << argv[0] + << " [ options ] <infile.dae> [ <outfile> ]\n"; + std::cerr + << "--no-condition\n" + << " Stops the converter from conditioning shaders.\n" + << "--base-path=<path>\n" + << " Sets the base path for finding textures and other external\n" + << " files.\n" + << "--up-axis=x,y,z\n" + << " Converts the file to have this up axis.\n" + << "--pretty-print\n" + << " Makes the exported JSON easier to read.\n" + << "--keep-filters\n" + << " Stops the converter from forcing all texture samplers to use\n" + << " tri-linear filtering.\n" + << "--keep-materials\n" + << " Stops the converter from changing materials to <constant> if\n" + << " they are used by a mesh that has no normals.\n"; return EXIT_FAILURE; } |