| 163 | } |
| 164 | |
| 165 | void parseNode(Mesh *mesh, const vrmllib::node *n, Matrix4 m) |
| 166 | { |
| 167 | if (const Transform *tr = dynamic_cast<const Transform *>(n)) { |
| 168 | // TODO: handle center, scaleOrientation |
| 169 | |
| 170 | Matrix4 trans; |
| 171 | trans.makeTrans(vec(tr->translation)); |
| 172 | |
| 173 | Matrix4 scale = Matrix4::IDENTITY; |
| 174 | scale[0][0] = tr->scale.x; |
| 175 | scale[1][1] = tr->scale.y; |
| 176 | scale[2][2] = tr->scale.z; |
| 177 | |
| 178 | Matrix3 rot3; |
| 179 | rot3.FromAxisAngle(vec(tr->rotation.vector), tr->rotation.radians); |
| 180 | Matrix4 rot = Matrix4::IDENTITY; |
| 181 | rot = rot3; |
| 182 | |
| 183 | m = m * transMat(tr->translation) * transMat(tr->center) |
| 184 | * rotMat(tr->rotation) * rotMat(tr->scaleOrientation) * scaleMat(tr->scale) |
| 185 | * rotMat(tr->scaleOrientation, true) * transMat(tr->center, true); |
| 186 | } |
| 187 | |
| 188 | if (const grouping_node *gn = dynamic_cast<const grouping_node *>(n)) { |
| 189 | for (std::vector<vrmllib::node *>::const_iterator |
| 190 | i=gn->children.begin(), e=gn->children.end(); i!=e; ++i) |
| 191 | parseNode(mesh, *i, m); |
| 192 | |
| 193 | } else if (const Shape *sh = dynamic_cast<const Shape *>(n)) |
| 194 | parseShape(mesh, sh, m); |
| 195 | } |
| 196 | |
| 197 | void parseShape(Mesh *mesh, const Shape *sh, Matrix4 mat) |
| 198 | { |