private static void CalcNodeBoundingBox(RSM.Node node, Mat4 _matrix) { var v = new Vector3(); var box = node.box; var nodes = node.model.nodes; var vertices = node.vertices; float x, y, z; //find position node.matrix = _matrix.Clone(); Mat4.Translate(node.matrix, node.matrix, node.pos); //dynamic or static model if (node.rotKeyframes.Count == 0) { Mat4.Rotate(node.matrix, node.matrix, node.rotAngle, node.rotAxis); } Mat4.Scale(node.matrix, node.matrix, node.scale); Mat4 matrix = node.matrix.Clone(); if (!node.isOnly) { Mat4.Translate(matrix, matrix, node.offset); } Mat4.Multiply(matrix, matrix, Mat4.FromMat3(node.mat3, null)); for (int i = 0, count = vertices.Count; i < count; i++) { x = vertices[i][0]; y = vertices[i][1]; z = vertices[i][2]; v[0] = matrix[0] * x + matrix[4] * y + matrix[8] * z + matrix[12]; v[1] = matrix[1] * x + matrix[5] * y + matrix[9] * z + matrix[13]; v[2] = matrix[2] * x + matrix[6] * y + matrix[10] * z + matrix[14]; for (int j = 0; j < 3; j++) { box.min[j] = Math.Min(v[j], box.min[j]); box.max[j] = Math.Max(v[j], box.max[j]); } } for (int i = 0; i < 3; i++) { box.offset[i] = (box.max[i] + box.min[i]) / 2.0f; box.range[i] = (box.max[i] - box.min[i]) / 2.0f; box.center[i] = box.min[i] + box.range[i]; } for (int i = 0, count = nodes.Length; i < count; i++) { if (string.Equals(nodes[i].parentName, node.name) && !string.Equals(node.name, node.parentName)) { nodes[i].parent = node; node.children.Add(nodes[i]); CalcNodeBoundingBox(nodes[i], node.matrix); } } }