------------------------------------------------------------------------------
| 799 | |
| 800 | //------------------------------------------------------------------------------ |
| 801 | bool vtkGLTFDocumentLoaderInternals::LoadNode( |
| 802 | const nlohmann::json& root, vtkGLTFDocumentLoader::Node& node) |
| 803 | { |
| 804 | node.Camera = -1; |
| 805 | vtkGLTFUtils::GetIntValue(root, "camera", node.Camera); |
| 806 | |
| 807 | node.Children.clear(); |
| 808 | vtkGLTFUtils::GetIntArray(root, "children", node.Children); |
| 809 | |
| 810 | node.Skin = -1; |
| 811 | vtkGLTFUtils::GetIntValue(root, "skin", node.Skin); |
| 812 | |
| 813 | node.Mesh = -1; |
| 814 | vtkGLTFUtils::GetIntValue(root, "mesh", node.Mesh); |
| 815 | |
| 816 | // Load matrix value |
| 817 | std::vector<double> matrixValues; |
| 818 | node.Matrix = vtkSmartPointer<vtkMatrix4x4>::New(); |
| 819 | node.Matrix->Identity(); |
| 820 | |
| 821 | // A node can define either a 'matrix' property, or any of the three 'rotation', 'translation' and |
| 822 | // 'scale' properties, not both. |
| 823 | if (vtkGLTFUtils::GetDoubleArray(root, "matrix", matrixValues)) |
| 824 | { |
| 825 | // If the node has defined a skin, it can't define 'matrix' |
| 826 | if (node.Skin >= 0) |
| 827 | { |
| 828 | vtkErrorWithObjectMacro(this->Self, "Invalid node.matrix value with node.skin defined."); |
| 829 | return false; |
| 830 | } |
| 831 | if (matrixValues.size() == |
| 832 | vtkGLTFDocumentLoader::GetNumberOfComponentsForType( |
| 833 | vtkGLTFDocumentLoader::AccessorType::MAT4)) |
| 834 | { |
| 835 | node.Matrix->DeepCopy(matrixValues.data()); |
| 836 | node.Matrix->Transpose(); |
| 837 | node.TRSLoaded = false; |
| 838 | } |
| 839 | } |
| 840 | else |
| 841 | { |
| 842 | // Load translation, rotation and scale values |
| 843 | if (vtkGLTFUtils::GetFloatArray(root, "scale", node.InitialScale)) |
| 844 | { |
| 845 | if (node.InitialScale.size() != |
| 846 | vtkGLTFDocumentLoader::GetNumberOfComponentsForType( |
| 847 | vtkGLTFDocumentLoader::AccessorType::VEC3)) |
| 848 | { |
| 849 | vtkWarningWithObjectMacro( |
| 850 | this->Self, "Invalid node.scale array size. Using default scale for node " << node.Name); |
| 851 | node.InitialScale.clear(); |
| 852 | } |
| 853 | } |
| 854 | if (node.InitialScale.empty()) |
| 855 | { |
| 856 | // Default values |
| 857 | node.InitialScale.insert(node.InitialScale.end(), { 1, 1, 1 }); |
| 858 | } |
no test coverage detected