/// <summary> /// 根据每个节点的组件信息调用SofaPhysicsAPI,对于mechanicalObject和olgModel组件,动态创建unity相关渲染组件 /// </summary> /// <param name="node"></param> private void SofaErgodicComponents(Transform node) { if (node.name != "root") { SofaPhysicsAPI.AddChildNode(ToChar(node.parent.name), ToChar(node.name)); } Component[] allComponents; allComponents = node.gameObject.GetComponents <Component>(); foreach (Component com in allComponents) { switch (com.GetType().Name) { case "Sofa_DefaultPipeline": Sofa_DefaultPipeline defaultPipeline = node.gameObject.GetComponent <Sofa_DefaultPipeline>(); SofaPhysicsAPI.AddDefaultPipeline(ToChar(node.name), ToChar(defaultPipeline.componentName)); break; case "Sofa_BruteForceDetection": Sofa_BruteForceDetection bruteForceDetection = node.gameObject.GetComponent <Sofa_BruteForceDetection>(); SofaPhysicsAPI.AddBruteForceDetection(ToChar(node.name), ToChar(bruteForceDetection.componentName)); break; case "Sofa_DefaultContactManager": Sofa_DefaultContactManager defaultContactManager = node.gameObject.GetComponent <Sofa_DefaultContactManager>(); SofaPhysicsAPI.AddDefaultContactManager(ToChar(node.name), ToChar(defaultContactManager.componentName)); break; case "Sofa_DiscreteIntersection": Sofa_DiscreteIntersection discreteIntersection = node.gameObject.GetComponent <Sofa_DiscreteIntersection>(); SofaPhysicsAPI.AddDiscreteIntersection(ToChar(node.name), ToChar(discreteIntersection.componentName)); break; case "Sofa_EulerImplicSolver": Sofa_EulerImplicSolver eulerImplicSolver = node.gameObject.GetComponent <Sofa_EulerImplicSolver>(); SofaPhysicsAPI.AddEulerImplicSolver(ToChar(node.name), ToChar(eulerImplicSolver.componentName), eulerImplicSolver.rayleighStiffness, eulerImplicSolver.rayleighMass); break; case "Sofa_CGLinearSolver": Sofa_CGLinearSolver cGLinearSolver = node.gameObject.GetComponent <Sofa_CGLinearSolver>(); SofaPhysicsAPI.AddCGLinearSolver(ToChar(node.name), ToChar(cGLinearSolver.componentName), cGLinearSolver.iterations, cGLinearSolver.tolerance, cGLinearSolver.threshold); break; case "Sofa_MeshGmshLoader": Sofa_MeshGmshLoader meshGmshLoader = node.gameObject.GetComponent <Sofa_MeshGmshLoader>(); SofaPhysicsAPI.AddMeshGmshLoader(ToChar(node.name), ToChar(meshGmshLoader.componentName), ToChar(meshGmshLoader.filePath)); break; case "Sofa_TetrahedronSetTopologyContainer": Sofa_TetrahedronSetTopologyContainer tetrahedronSetTopologyContainer = node.gameObject.GetComponent <Sofa_TetrahedronSetTopologyContainer>(); SofaPhysicsAPI.AddTetrahedronSetTopologyContainer(ToChar(node.name), ToChar(tetrahedronSetTopologyContainer.componentName), ToChar(tetrahedronSetTopologyContainer.srcPath), ToChar(tetrahedronSetTopologyContainer.srcName)); break; case "Sofa_MechanicalObject": Sofa_MechanicalObject mechanicalObject = node.gameObject.GetComponent <Sofa_MechanicalObject>(); SofaPhysicsAPI.AddMechanicalObjectSrcPath(ToChar(node.name), ToChar(mechanicalObject.componentName), ToChar(mechanicalObject.srcPath), ToChar(mechanicalObject.srcName)); UnityMechanicalObjectInfoInit(node, mechanicalObject.componentName, mechanicalObject.triangleMat, mechanicalObject.quadMat, mechanicalObject.tetrahedraMat); break; case "Sofa_TetrahedronSetGeometryAlgorithms": Sofa_TetrahedronSetGeometryAlgorithms tetrahedronSetGeometryAlgorithms = node.gameObject.GetComponent <Sofa_TetrahedronSetGeometryAlgorithms>(); SofaPhysicsAPI.AddTetrahedronSetGeometryAlgorithms(ToChar(node.name), ToChar(tetrahedronSetGeometryAlgorithms.componentName)); break; case "Sofa_TetrahedronSetTopologyModifier": Sofa_TetrahedronSetTopologyModifier tetrahedronSetTopologyModifier = node.gameObject.GetComponent <Sofa_TetrahedronSetTopologyModifier>(); SofaPhysicsAPI.AddTetrahedronSetTopologyModifier(ToChar(node.name), ToChar(tetrahedronSetTopologyModifier.componentName)); break; case "Sofa_TetrahedronSetTopologyAlgorithms": Sofa_TetrahedronSetTopologyAlgorithms tetrahedronSetTopologyAlgorithms = node.gameObject.GetComponent <Sofa_TetrahedronSetTopologyAlgorithms>(); SofaPhysicsAPI.AddTetrahedronSetTopologyAlgorithms(ToChar(node.name), ToChar(tetrahedronSetTopologyAlgorithms.componentName)); break; case "Sofa_DiagonalMass": Sofa_DiagonalMass diagonalMass = node.gameObject.GetComponent <Sofa_DiagonalMass>(); SofaPhysicsAPI.AddDiagonalMass(ToChar(node.name), ToChar(diagonalMass.componentName), diagonalMass.massDensity); break; case "Sofa_TetrahedralCorotationalFEMForceField": Sofa_TetrahedralCorotationalFEMForceField tetrahedralCorotationalFEMForceField = node.gameObject.GetComponent <Sofa_TetrahedralCorotationalFEMForceField>(); SofaPhysicsAPI.AddTetrahedralCorotationalFEMForceField(ToChar(node.name), ToChar(tetrahedralCorotationalFEMForceField.componentName), ToChar(tetrahedralCorotationalFEMForceField.method), tetrahedralCorotationalFEMForceField.poissonRatio, tetrahedralCorotationalFEMForceField.youngModulus, tetrahedralCorotationalFEMForceField.computeGlobalMatrix); break; case "Sofa_FixedConstraint": Sofa_FixedConstraint fixedConstraint = node.gameObject.GetComponent <Sofa_FixedConstraint>(); SofaPhysicsAPI.AddFixedConstraint(ToChar(node.name), ToChar(fixedConstraint.componentName), fixedConstraint.indices, fixedConstraint.indices.Length); break; case "Sofa_OglModel": Sofa_OglModel oglModel = node.gameObject.GetComponent <Sofa_OglModel>(); SofaPhysicsAPI.AddOglModel(ToChar(node.name), ToChar(oglModel.componentName), ToChar(oglModel.fileMesh)); UnityMeshInfoInit(node, oglModel.componentName, oglModel.mat); break; case "Sofa_BarycentricMapping": Sofa_BarycentricMapping baryCentricMapping = node.gameObject.GetComponent <Sofa_BarycentricMapping>(); SofaPhysicsAPI.AddBarycentricMapping(ToChar(node.name), ToChar(baryCentricMapping.componentName), ToChar(baryCentricMapping.input), ToChar(baryCentricMapping.output)); break; default: break; } } }