add -invtrans option for sketchup models

This commit is contained in:
rdb 2012-08-08 16:01:14 +00:00
parent 5ae679ccc9
commit 268acf45b9
6 changed files with 40 additions and 21 deletions

View File

@ -221,7 +221,7 @@ process_extra(const string semantic, const FCDExtra* extra) {
// Description: Applies the stuff to the given EggPrimitive. // Description: Applies the stuff to the given EggPrimitive.
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
void DaeMaterials:: void DaeMaterials::
apply_to(const string semantic, const PT(EggPrimitive) to) { apply_to_primitive(const string semantic, const PT(EggPrimitive) to) {
if (_materials.count(semantic) > 0) { if (_materials.count(semantic) > 0) {
to->set_material(_materials[semantic]->_egg_material); to->set_material(_materials[semantic]->_egg_material);
for (pvector<PT_EggTexture>::iterator it = _materials[semantic]->_egg_textures.begin(); it != _materials[semantic]->_egg_textures.end(); ++it) { for (pvector<PT_EggTexture>::iterator it = _materials[semantic]->_egg_textures.begin(); it != _materials[semantic]->_egg_textures.end(); ++it) {
@ -238,15 +238,25 @@ apply_to(const string semantic, const PT(EggPrimitive) to) {
// Description: Applies the colorblend stuff to the given EggGroup. // Description: Applies the colorblend stuff to the given EggGroup.
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
void DaeMaterials:: void DaeMaterials::
apply_to(const string semantic, const PT(EggGroup) to) { apply_to_group(const string semantic, const PT(EggGroup) to, bool invert_transparency) {
if (_materials.count(semantic) > 0) { if (_materials.count(semantic) > 0) {
PT(DaeBlendSettings) blend = _materials[semantic]->_blend; PT(DaeBlendSettings) blend = _materials[semantic]->_blend;
if (blend && blend->_enabled) { if (blend && blend->_enabled) {
to->set_blend_mode(EggGroup::BM_add); to->set_blend_mode(EggGroup::BM_add);
to->set_blend_color(blend->_color); to->set_blend_color(blend->_color);
if (invert_transparency) {
to->set_blend_operand_a(blend->_operand_b);
to->set_blend_operand_b(blend->_operand_a);
} else {
to->set_blend_operand_a(blend->_operand_a); to->set_blend_operand_a(blend->_operand_a);
to->set_blend_operand_b(blend->_operand_b); to->set_blend_operand_b(blend->_operand_b);
} }
} else if (blend && invert_transparency) {
to->set_blend_mode(EggGroup::BM_add);
to->set_blend_color(blend->_color);
to->set_blend_operand_a(blend->_operand_b);
to->set_blend_operand_b(blend->_operand_a);
}
} }
} }
@ -410,34 +420,30 @@ convert_blend(FCDEffectStandard::TransparencyMode mode, const LColor &transparen
// See if we can optimize out the color. // See if we can optimize out the color.
if (blend->_operand_a == EggGroup::BO_constant_color) { if (blend->_operand_a == EggGroup::BO_constant_color) {
if ((blend->_color[0] == 0) && (blend->_color[1] == 0) && (blend->_color[2] == 0) && (blend->_color[3] == 0)) { if (blend->_color == LColor::zero()) {
blend->_operand_a = EggGroup::BO_zero; blend->_operand_a = EggGroup::BO_zero;
} } else if (blend->_color == LColor(1, 1, 1, 1)) {
if ((blend->_color[0] == 1) && (blend->_color[1] == 1) && (blend->_color[2] == 1) && (blend->_color[3] == 1)) {
blend->_operand_a = EggGroup::BO_one; blend->_operand_a = EggGroup::BO_one;
} }
} }
if (blend->_operand_b == EggGroup::BO_constant_color) { if (blend->_operand_b == EggGroup::BO_constant_color) {
if ((blend->_color[0] == 0) && (blend->_color[1] == 0) && (blend->_color[2] == 0) && (blend->_color[3] == 0)) { if (blend->_color == LColor::zero()) {
blend->_operand_b = EggGroup::BO_zero; blend->_operand_b = EggGroup::BO_zero;
} } else if (blend->_color == LColor(1, 1, 1, 1)) {
if ((blend->_color[0] == 1) && (blend->_color[1] == 1) && (blend->_color[2] == 1) && (blend->_color[3] == 1)) {
blend->_operand_b = EggGroup::BO_one; blend->_operand_b = EggGroup::BO_one;
} }
} }
if (blend->_operand_a == EggGroup::BO_one_minus_constant_color) { if (blend->_operand_a == EggGroup::BO_one_minus_constant_color) {
if ((blend->_color[0] == 0) && (blend->_color[1] == 0) && (blend->_color[2] == 0) && (blend->_color[3] == 0)) { if (blend->_color == LColor::zero()) {
blend->_operand_a = EggGroup::BO_one; blend->_operand_a = EggGroup::BO_one;
} } else if (blend->_color == LColor(1, 1, 1, 1)) {
if ((blend->_color[0] == 1) && (blend->_color[1] == 1) && (blend->_color[2] == 1) && (blend->_color[3] == 1)) {
blend->_operand_a = EggGroup::BO_zero; blend->_operand_a = EggGroup::BO_zero;
} }
} }
if (blend->_operand_b == EggGroup::BO_one_minus_constant_color) { if (blend->_operand_b == EggGroup::BO_one_minus_constant_color) {
if ((blend->_color[0] == 0) && (blend->_color[1] == 0) && (blend->_color[2] == 0) && (blend->_color[3] == 0)) { if (blend->_color == LColor::zero()) {
blend->_operand_b = EggGroup::BO_one; blend->_operand_b = EggGroup::BO_one;
} } else if (blend->_color == LColor(1, 1, 1, 1)) {
if ((blend->_color[0] == 1) && (blend->_color[1] == 1) && (blend->_color[2] == 1) && (blend->_color[3] == 1)) {
blend->_operand_b = EggGroup::BO_zero; blend->_operand_b = EggGroup::BO_zero;
} }
} }

View File

@ -44,8 +44,8 @@ public:
virtual ~DaeMaterials() {}; virtual ~DaeMaterials() {};
void add_material_instance(const FCDMaterialInstance* instance); void add_material_instance(const FCDMaterialInstance* instance);
void apply_to(const string semantic, const PT(EggPrimitive) to); void apply_to_primitive(const string semantic, const PT(EggPrimitive) to);
void apply_to(const string semantic, const PT(EggGroup) to); void apply_to_group(const string semantic, const PT(EggGroup) to, bool invert_transparency=false);
const string get_uvset_name(const string semantic, FUDaeGeometryInput::Semantic input_semantic, int32 input_set); const string get_uvset_name(const string semantic, FUDaeGeometryInput::Semantic input_semantic, int32 input_set);
static EggTexture::TextureType convert_texture_type(const FCDEffectParameterSampler::SamplerType orig_type); static EggTexture::TextureType convert_texture_type(const FCDEffectParameterSampler::SamplerType orig_type);

View File

@ -60,6 +60,7 @@ DAEToEggConverter() {
_table = NULL; _table = NULL;
_frame_rate = -1; _frame_rate = -1;
_error_handler = NULL; _error_handler = NULL;
_invert_transparency = false;
} }
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
@ -356,7 +357,7 @@ void DAEToEggConverter::process_mesh(PT(EggGroup) parent, const FCDGeometryMesh*
primitive_holders[gr] = primitiveholder; primitive_holders[gr] = primitiveholder;
// Apply the per-group data of the materials, if we have it. // Apply the per-group data of the materials, if we have it.
if (materials != NULL) { if (materials != NULL) {
materials->apply_to(FROM_FSTRING(polygons->GetMaterialSemantic()), primitiveholder); materials->apply_to_group(FROM_FSTRING(polygons->GetMaterialSemantic()), primitiveholder, _invert_transparency);
} }
// Find the position sources // Find the position sources
const FCDGeometryPolygonsInput* pinput = polygons->FindInput(FUDaeGeometryInput::POSITION); const FCDGeometryPolygonsInput* pinput = polygons->FindInput(FUDaeGeometryInput::POSITION);
@ -492,7 +493,7 @@ void DAEToEggConverter::process_mesh(PT(EggGroup) parent, const FCDGeometryMesh*
if (primitive != NULL) { if (primitive != NULL) {
primitive_holders[gr]->add_child(primitive); primitive_holders[gr]->add_child(primitive);
if (materials != NULL) { if (materials != NULL) {
materials->apply_to(FROM_FSTRING(polygons->GetMaterialSemantic()), primitive); materials->apply_to_primitive(FROM_FSTRING(polygons->GetMaterialSemantic()), primitive);
} }
for (size_t ve = 0; ve < polygons->GetFaceVertexCount(fa); ++ve) { for (size_t ve = 0; ve < polygons->GetFaceVertexCount(fa); ++ve) {
assert(mesh_pool->has_vertex(ve + polygons->GetFaceVertexOffset() + offset)); assert(mesh_pool->has_vertex(ve + polygons->GetFaceVertexOffset() + offset));

View File

@ -55,8 +55,9 @@ public:
virtual bool convert_file(const Filename &filename); virtual bool convert_file(const Filename &filename);
private: bool _invert_transparency;
private:
PT(EggTable) _table; PT(EggTable) _table;
FCDocument* _document; FCDocument* _document;
FUErrorSimpleHandler* _error_handler; FUErrorSimpleHandler* _error_handler;

View File

@ -30,6 +30,13 @@ DAEToEgg():
add_normals_options(); add_normals_options();
add_transform_options(); add_transform_options();
add_option
("invtrans", "", false,
"Import the .dae file using inverted transparency. "
"This is useful when importing COLLADA files from some authoring tools "
"that export models with inverted transparency, such as Google SketchUp.",
&SomethingToEgg::dispatch_none, &_invert_transparency);
set_program_description set_program_description
("This program converts .dae files (COLLADA Digital Asset Exchange) to .egg."); ("This program converts .dae files (COLLADA Digital Asset Exchange) to .egg.");
@ -50,6 +57,7 @@ run() {
DAEToEggConverter converter; DAEToEggConverter converter;
converter.set_egg_data(_data); converter.set_egg_data(_data);
converter._allow_errors = _allow_errors; converter._allow_errors = _allow_errors;
converter._invert_transparency = _invert_transparency;
apply_parameters(converter); apply_parameters(converter);

View File

@ -30,6 +30,9 @@ public:
DAEToEgg(); DAEToEgg();
void run(); void run();
private:
bool _invert_transparency;
}; };
#endif #endif