added a maya2egg option to round uvs from 1/1000th precision to 1/100th precision, it called -round-uvs

This commit is contained in:
Asad M. Zaman 2006-11-11 01:11:22 +00:00
parent 9fb8d43cf5
commit c0d11f9c97
4 changed files with 42 additions and 4 deletions

View File

@ -97,6 +97,7 @@ MayaToEggConverter(const string &program_name) :
_respect_maya_double_sided = maya_default_double_sided;
_always_show_vertex_color = maya_default_vertex_color;
_keep_all_uvsets = false;
_round_uvs = false;
_transform_type = TT_model;
}
@ -120,6 +121,7 @@ MayaToEggConverter(const MayaToEggConverter &copy) :
_respect_maya_double_sided(copy._respect_maya_double_sided),
_always_show_vertex_color(copy._always_show_vertex_color),
_keep_all_uvsets(copy._keep_all_uvsets),
_round_uvs(copy._round_uvs),
_transform_type(copy._transform_type)
{
}
@ -779,6 +781,10 @@ bool MayaToEggConverter::
convert_hierarchy(EggGroupNode *egg_root) {
int num_nodes = _tree.get_num_nodes();
if (_round_uvs) {
mayaegg_cat.info() << "will round up uv coordinates" << endl;
}
_tree.clear_egg(get_egg_data(), egg_root, NULL, NULL);
for (int i = 0; i < num_nodes; i++) {
MayaNodeDesc *node = _tree.get_node(i);
@ -1675,6 +1681,20 @@ find_uv_link(string match) {
}
return "not found";
}
////////////////////////////////////////////////////////////////////
// Function: MayaShader::round uvs
// Access: Private
// Description: given uvsets, round them up or down
////////////////////////////////////////////////////////////////////
int MayaToEggConverter::
round(double value) {
if (value < 0)
return -(floor(-value + 0.5));
// or as an alternate use:
// return ceil ( value - 0.5);
else
return floor( value + 0.5);
}
/*
////////////////////////////////////////////////////////////////////
// Function: MayaToEggConverter::store_tex_names
@ -2020,9 +2040,17 @@ make_polyset(MayaNodeDesc *node_desc, const MDagPath &dag_path,
if (!status) {
status.perror("MItMeshPolygon::getUV");
} else {
// apply upto 1/1000th precision
uvs[0] = (double)((long)(uvs[0]*1000))/1000.0;
uvs[1] = (double)((long)(uvs[1]*1000))/1000.0;
if (_round_uvs) {
// apply upto 1/1000th precision, but round up
uvs[0] = (long)(uvs[0]*1000);
uvs[1] = (long)(uvs[1]*1000);
//cout << "before rounding uvs[0]: " << uvs[0] << endl;
//cout << "before rounding uvs[1]: " << uvs[1] << endl;
uvs[0] = (double)(round((double)uvs[0]/10.0)*10.0)/1000.0;
uvs[1] = (double)(round((double)uvs[1]/10.0)*10.0)/1000.0;
//cout << "after rounding uvs[0]: " << uvs[0] << endl;
//cout << "after rounding uvs[1]: " << uvs[1] << endl;
}
vert.set_uv(colordef_uv_name, TexCoordd(uvs[0], uvs[1]));
}
}

View File

@ -155,7 +155,8 @@ private:
bool reparent_decals(EggGroupNode *egg_parent);
string find_uv_link(string match);
// string find_uv_link_2(string match, const MObjectArray &textures);
int round(double value);
string _program_name;
@ -182,6 +183,7 @@ public:
bool _respect_maya_double_sided;
bool _always_show_vertex_color;
bool _keep_all_uvsets;
bool _round_uvs;
enum TransformType {
TT_invalid,

View File

@ -83,6 +83,12 @@ MayaToEgg() :
"to be referenced by any textures.",
&MayaToEgg::dispatch_none, &_keep_all_uvsets);
add_option
("round-uvs", "", 0,
"round up uv coordinates to the nearest 1/100th. i.e. -0.001 becomes"
"0.0; 0.444 becomes 0.44; 0.778 becomes 0.78.",
&MayaToEgg::dispatch_none, &_round_uvs);
add_option
("trans", "type", 0,
"Specifies which transforms in the Maya file should be converted to "
@ -182,6 +188,7 @@ run() {
converter._respect_maya_double_sided = _respect_maya_double_sided;
converter._always_show_vertex_color = !_suppress_vertex_color;
converter._keep_all_uvsets = _keep_all_uvsets;
converter._round_uvs = _round_uvs;
converter._transform_type = _transform_type;
vector_string::const_iterator si;

View File

@ -42,6 +42,7 @@ protected:
bool _respect_maya_double_sided;
bool _suppress_vertex_color;
bool _keep_all_uvsets;
bool _round_uvs;
MayaToEggConverter::TransformType _transform_type;
vector_string _subroots;
vector_string _subsets;