ulf.schroeter Posted February 2, 2011 Posted February 2, 2011 Problem Current implementation of MeshFileDAE does not support COLLADA unit tag. This is bad as cool and free Google SketchUp7/8 modelling software ALWAYS exports COLLADA format with "inch" unit, even when modelling metrics are set to e.g. "meter". Google SketchUp modelled unit cube with 1 [m] edge length will be scaled by factor 39,37 (1[inch] = 0.0254[m]) on import with UNIGINE ResourceEditor tool for mesh conversion <COLLADA xmlns="http://www.collada.org/2005/11/COLLADASchema" version="1.4.1"> <asset> <contributor> <authoring_tool>Google SketchUp 8.0.4811</authoring_tool> </contributor> <unit meter="0.02539999969303608" name="inch" /> <up_axis>Z_UP</up_axis> </asset> ... Proposal Following lines of code in MeshFile.cpp will add generic COLLADA unit support class MeshFileDAE : public MeshFile { ... int up_axis; 1 float unit_scale; // meter unit conversion scale ... }; void MeshFileDAE::parse_asset(const Xml *xml) { for(int i = 0; i < xml->getNumChilds(); i++) { ... if(name == "up_axis") { ... } 2 else if(name == "unit") { 3 unit_scale = x->getFloatArg("meter"); 4 if( unit_scale == 0.0f ) 5 unit_scale = 1.0f; // reset to default in case of parsing error 6 } } } void MeshFileDAE::parse_node(const Xml *xml,const mat4 &t) { ... if(name == "matrix") { mat4 m; x->getFloatArrayData(m,16); 7 m.m30 *= unit_scale; m.m31 *= unit_scale; m.m32 *= unit_scale; transform = transform * transpose(m); } ... else if(name == "translate") { vec3 t; x->getFloatArrayData(t,3); 8 t *= unit_scale; transform = transform * translate(t.x,t.y,t.z); } ... } void MeshFileDAE::parse_primitive(const Xml *xml,Surface &surface) { ... for(int i = 0; i < xml->getNumChilds(); i++) { ... // vertices for(int j = 0; j < indices.size(); j += stride) { Mesh::Vertex v; ... ... 9 v.xyz *= unit_scale; // convert to COLLADA default unit meter vertex.append(v); } .... } } UnitCube.dae.txt
Recommended Posts