mirror of
https://github.com/panda3d/panda3d.git
synced 2025-10-01 01:07:51 -04:00
add -invtrans option for sketchup models
This commit is contained in:
parent
5ae679ccc9
commit
268acf45b9
@ -221,7 +221,7 @@ process_extra(const string semantic, const FCDExtra* extra) {
|
||||
// Description: Applies the stuff to the given EggPrimitive.
|
||||
////////////////////////////////////////////////////////////////////
|
||||
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) {
|
||||
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) {
|
||||
@ -238,14 +238,24 @@ apply_to(const string semantic, const PT(EggPrimitive) to) {
|
||||
// Description: Applies the colorblend stuff to the given EggGroup.
|
||||
////////////////////////////////////////////////////////////////////
|
||||
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) {
|
||||
PT(DaeBlendSettings) blend = _materials[semantic]->_blend;
|
||||
if (blend && blend->_enabled) {
|
||||
to->set_blend_mode(EggGroup::BM_add);
|
||||
to->set_blend_color(blend->_color);
|
||||
to->set_blend_operand_a(blend->_operand_a);
|
||||
to->set_blend_operand_b(blend->_operand_b);
|
||||
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_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.
|
||||
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;
|
||||
}
|
||||
if ((blend->_color[0] == 1) && (blend->_color[1] == 1) && (blend->_color[2] == 1) && (blend->_color[3] == 1)) {
|
||||
} else if (blend->_color == LColor(1, 1, 1, 1)) {
|
||||
blend->_operand_a = EggGroup::BO_one;
|
||||
}
|
||||
}
|
||||
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;
|
||||
}
|
||||
if ((blend->_color[0] == 1) && (blend->_color[1] == 1) && (blend->_color[2] == 1) && (blend->_color[3] == 1)) {
|
||||
} else if (blend->_color == LColor(1, 1, 1, 1)) {
|
||||
blend->_operand_b = EggGroup::BO_one;
|
||||
}
|
||||
}
|
||||
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;
|
||||
}
|
||||
if ((blend->_color[0] == 1) && (blend->_color[1] == 1) && (blend->_color[2] == 1) && (blend->_color[3] == 1)) {
|
||||
} else if (blend->_color == LColor(1, 1, 1, 1)) {
|
||||
blend->_operand_a = EggGroup::BO_zero;
|
||||
}
|
||||
}
|
||||
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;
|
||||
}
|
||||
if ((blend->_color[0] == 1) && (blend->_color[1] == 1) && (blend->_color[2] == 1) && (blend->_color[3] == 1)) {
|
||||
} else if (blend->_color == LColor(1, 1, 1, 1)) {
|
||||
blend->_operand_b = EggGroup::BO_zero;
|
||||
}
|
||||
}
|
||||
|
@ -44,8 +44,8 @@ public:
|
||||
virtual ~DaeMaterials() {};
|
||||
|
||||
void add_material_instance(const FCDMaterialInstance* instance);
|
||||
void apply_to(const string semantic, const PT(EggPrimitive) to);
|
||||
void apply_to(const string semantic, const PT(EggGroup) to);
|
||||
void apply_to_primitive(const string semantic, const PT(EggPrimitive) 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);
|
||||
|
||||
static EggTexture::TextureType convert_texture_type(const FCDEffectParameterSampler::SamplerType orig_type);
|
||||
|
@ -60,6 +60,7 @@ DAEToEggConverter() {
|
||||
_table = NULL;
|
||||
_frame_rate = -1;
|
||||
_error_handler = NULL;
|
||||
_invert_transparency = false;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
@ -356,7 +357,7 @@ void DAEToEggConverter::process_mesh(PT(EggGroup) parent, const FCDGeometryMesh*
|
||||
primitive_holders[gr] = primitiveholder;
|
||||
// Apply the per-group data of the materials, if we have it.
|
||||
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
|
||||
const FCDGeometryPolygonsInput* pinput = polygons->FindInput(FUDaeGeometryInput::POSITION);
|
||||
@ -492,7 +493,7 @@ void DAEToEggConverter::process_mesh(PT(EggGroup) parent, const FCDGeometryMesh*
|
||||
if (primitive != NULL) {
|
||||
primitive_holders[gr]->add_child(primitive);
|
||||
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) {
|
||||
assert(mesh_pool->has_vertex(ve + polygons->GetFaceVertexOffset() + offset));
|
||||
|
@ -55,8 +55,9 @@ public:
|
||||
|
||||
virtual bool convert_file(const Filename &filename);
|
||||
|
||||
bool _invert_transparency;
|
||||
|
||||
private:
|
||||
|
||||
PT(EggTable) _table;
|
||||
FCDocument* _document;
|
||||
FUErrorSimpleHandler* _error_handler;
|
||||
|
@ -30,6 +30,13 @@ DAEToEgg():
|
||||
add_normals_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
|
||||
("This program converts .dae files (COLLADA Digital Asset Exchange) to .egg.");
|
||||
|
||||
@ -50,6 +57,7 @@ run() {
|
||||
DAEToEggConverter converter;
|
||||
converter.set_egg_data(_data);
|
||||
converter._allow_errors = _allow_errors;
|
||||
converter._invert_transparency = _invert_transparency;
|
||||
|
||||
apply_parameters(converter);
|
||||
|
||||
|
@ -30,6 +30,9 @@ public:
|
||||
DAEToEgg();
|
||||
|
||||
void run();
|
||||
|
||||
private:
|
||||
bool _invert_transparency;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
Loading…
x
Reference in New Issue
Block a user