| 1590 | } |
| 1591 | |
| 1592 | Ref<SceneGraph::Node> XMLLoader::loadMultiTransformNode(const Ref<XML>& xml) |
| 1593 | { |
| 1594 | /* parse number of time steps to use for instanced geometry */ |
| 1595 | int time_steps = 1; |
| 1596 | std::string str_time_steps = xml->parm("time_steps"); |
| 1597 | if (str_time_steps != "") time_steps = max(1,std::stoi(str_time_steps)); |
| 1598 | |
| 1599 | bool quaternion = false; |
| 1600 | avector<AffineSpace3ff> space; |
| 1601 | avector<avector<AffineSpace3ff>> spaces(time_steps); |
| 1602 | size_t j = 0; |
| 1603 | for (size_t i=0; i<time_steps; i++) { |
| 1604 | if (xml->children[i]->name == "AffineSpaceArray") { |
| 1605 | spaces[j++] = loadAffineSpace3faArray(xml->children[i]); |
| 1606 | } |
| 1607 | else if (xml->children[i]->name == "QuaternionArray") { |
| 1608 | spaces[j++] = loadQuaternionArray(xml->children[i]); |
| 1609 | quaternion = true; |
| 1610 | } |
| 1611 | else { |
| 1612 | THROW_RUNTIME_ERROR(xml->loc.str()+": unknown transformation representation"); |
| 1613 | } |
| 1614 | } |
| 1615 | assert(j == time_steps); |
| 1616 | |
| 1617 | if (xml->size() == time_steps+1) { |
| 1618 | auto node = new SceneGraph::MultiTransformNode(spaces,loadNode(xml->children[time_steps])); |
| 1619 | for (size_t i = 0; i < node->spaces.size(); ++i) { |
| 1620 | node->spaces[i].quaternion = quaternion; |
| 1621 | } |
| 1622 | return node; |
| 1623 | } |
| 1624 | |
| 1625 | Ref<SceneGraph::GroupNode> group = new SceneGraph::GroupNode; |
| 1626 | for (size_t i=time_steps; i<xml->size(); i++) |
| 1627 | group->add(loadNode(xml->children[i])); |
| 1628 | |
| 1629 | auto node = new SceneGraph::MultiTransformNode(spaces,group.dynamicCast<SceneGraph::Node>()); |
| 1630 | for (size_t i = 0; i < node->spaces.size(); ++i) { |
| 1631 | node->spaces[i].quaternion = quaternion; |
| 1632 | } |
| 1633 | return node; |
| 1634 | } |
| 1635 | |
| 1636 | Ref<SceneGraph::Node> XMLLoader::loadTransform2Node(const Ref<XML>& xml) |
| 1637 | { |