我想通过regex从代码中提取4x4矩阵数据,以便在python中使用它进行进一步处理。
数据的名称(空间中某个点的3D位置的矩阵)与名称应与之关联的变换数据位于不同的行中。如果我理解正确,你可以使用组(...)。
name 'Point\d'
为我想要捕捉的3D点创建匹配。如何将变换数据链接到关联点。
(?<=transform).+
匹配我想要的转换数据
问题:这两个信息都在不同的行中。您可以运行匹配的2个不同的正则表达式,然后通过组合match1(name)和match1(transform)将它们组合在一起,但如果匹配不总是以优雅的方式对齐,那么这可能会导致问题。
以下是应处理的示例文本:
scenegraph {
name 'Root'
visible 1
transform 1.000000000e+00 0.000000000e+00 0.000000000e+00 0.000000000e+00 0.000000000e+00 1.000000000e+00 0.000000000e+00 0.000000000e+00 0.000000000e+00 0.000000000e+00 1.000000000e+00 0.000000000e+00 0.000000000e+00 0.000000000e+00 0.000000000e+00 1.000000000e+00
geometry 0
children 2 [
scenegraph {
name 'Point1'
visible 1
transform 8.133591413e-01 0.000000000e+00 0.000000000e+00 0.000000000e+00 0.000000000e+00 8.133591413e-01 0.000000000e+00 0.000000000e+00 0.000000000e+00 0.000000000e+00 8.133591413e-01 0.000000000e+00 9.277027100e-02 6.371318848e+03 4.141105652e+02 1.000000000e+00
geometry {
vertices 1 4294967295 0
edges 0
faces 0
vertex_attrs 2 [
attribute {
name 'align_2d'
type 'vec2'
startTime 1.03900000000000000e+03
initialVals 1 [
-
]
keys 2 [
1.03900000000000000e+03 0 1.408942139e+03 7.712362671e+02
1.08900000000000000e+03 0 8.704575806e+02 9.245101929e+02
]
}
attribute {
name 'pts_3d'
type 'vec3'
startTime 0.00000000000000000e+00
initialVals 1 [
+ 0.000000000e+00 0.000000000e+00 0.000000000e+00
]
keys 0 [
]
}
]
edge_attrs 0 [
]
face_attrs 0 [
]
selected 1
}
children 0 [
]
}
scenegraph {
name 'Point2'
visible 1
transform 3.526667595e+00 0.000000000e+00 0.000000000e+00 0.000000000e+00 0.000000000e+00 3.526667595e+00 0.000000000e+00 0.000000000e+00 0.000000000e+00 0.000000000e+00 3.526667595e+00 0.000000000e+00 -4.233531475e+00 6.362593262e+03 4.306122437e+02 1.000000000e+00
geometry {
vertices 1 4294967295 0
edges 0
faces 0
vertex_attrs 2 [
attribute {
name 'align_2d'
type 'vec2'
startTime 1.04500000000000000e+03
initialVals 1 [
-
]
keys 2 [
1.04500000000000000e+03 0 4.777643433e+02 1.594472809e+02
1.05300000000000000e+03 0 1.969290161e+02 -1.577421112e+02
]
}