Implementation of scaling factor of objects into an AMF file.

https://github.com/prusa3d/Slic3r/issues/7
This commit is contained in:
bubnikv 2017-03-06 17:35:38 +01:00
parent c23c0ee7d2
commit 8a42c0ad9f

View file

@ -99,11 +99,12 @@ struct AMFParserContext
NODE_TYPE_DELTAX, // amf/constellation/instance/deltax NODE_TYPE_DELTAX, // amf/constellation/instance/deltax
NODE_TYPE_DELTAY, // amf/constellation/instance/deltay NODE_TYPE_DELTAY, // amf/constellation/instance/deltay
NODE_TYPE_RZ, // amf/constellation/instance/rz NODE_TYPE_RZ, // amf/constellation/instance/rz
NODE_TYPE_SCALE, // amf/constellation/instance/scale
NODE_TYPE_METADATA, // anywhere under amf/*/metadata NODE_TYPE_METADATA, // anywhere under amf/*/metadata
}; };
struct Instance { struct Instance {
Instance() : deltax_set(false), deltay_set(false), rz_set(false) {} Instance() : deltax_set(false), deltay_set(false), rz_set(false), scale_set(false) {}
// Shift in the X axis. // Shift in the X axis.
float deltax; float deltax;
bool deltax_set; bool deltax_set;
@ -113,6 +114,9 @@ struct AMFParserContext
// Rotation around the Z axis. // Rotation around the Z axis.
float rz; float rz;
bool rz_set; bool rz_set;
// Scaling factor
float scale;
bool scale_set;
}; };
struct Object { struct Object {
@ -222,6 +226,8 @@ void AMFParserContext::startElement(const char *name, const char **atts)
node_type_new = NODE_TYPE_DELTAY; node_type_new = NODE_TYPE_DELTAY;
else if (strcmp(name, "rz") == 0) else if (strcmp(name, "rz") == 0)
node_type_new = NODE_TYPE_RZ; node_type_new = NODE_TYPE_RZ;
else if (strcmp(name, "scale") == 0)
node_type_new = NODE_TYPE_SCALE;
} }
break; break;
case 4: case 4:
@ -278,7 +284,7 @@ void AMFParserContext::characters(const XML_Char *s, int len)
{ {
switch (m_path.size()) { switch (m_path.size()) {
case 4: case 4:
if (m_path.back() == NODE_TYPE_DELTAX || m_path.back() == NODE_TYPE_DELTAY || m_path.back() == NODE_TYPE_RZ) if (m_path.back() == NODE_TYPE_DELTAX || m_path.back() == NODE_TYPE_DELTAY || m_path.back() == NODE_TYPE_RZ || m_path.back() == NODE_TYPE_SCALE)
m_value[0].append(s, len); m_value[0].append(s, len);
break; break;
case 6: case 6:
@ -324,6 +330,12 @@ void AMFParserContext::endElement(const char *name)
m_instance->rz_set = true; m_instance->rz_set = true;
m_value[0].clear(); m_value[0].clear();
break; break;
case NODE_TYPE_SCALE:
assert(m_instance);
m_instance->scale = float(atof(m_value[0].c_str()));
m_instance->scale_set = true;
m_value[0].clear();
break;
// Object vertices: // Object vertices:
case NODE_TYPE_VERTEX: case NODE_TYPE_VERTEX:
@ -451,6 +463,7 @@ void AMFParserContext::endDocument()
mi->offset.x = instance.deltax; mi->offset.x = instance.deltax;
mi->offset.y = instance.deltay; mi->offset.y = instance.deltay;
mi->rotation = instance.rz_set ? instance.rz : 0.f; mi->rotation = instance.rz_set ? instance.rz : 0.f;
mi->scaling_factor = instance.scale_set ? instance.scale : 1.f;
} }
} }
} }
@ -596,11 +609,13 @@ bool store_amf(const char *path, Model *model)
" <deltax>%lf</deltax>\n" " <deltax>%lf</deltax>\n"
" <deltay>%lf</deltay>\n" " <deltay>%lf</deltay>\n"
" <rz>%lf</rz>\n" " <rz>%lf</rz>\n"
" <scale>%lf</scale>\n"
" </instance>\n", " </instance>\n",
object_id, object_id,
instance->offset.x, instance->offset.x,
instance->offset.y, instance->offset.y,
instance->rotation); instance->rotation,
instance->scaling_factor);
//FIXME missing instance->scaling_factor //FIXME missing instance->scaling_factor
instances.append(buf); instances.append(buf);
} }