Auto-generate 3D mesh from convex OBJ if dim=3 in flex.

This requires the user to explicitly specify an origin.

PiperOrigin-RevId: 712483526
Change-Id: Ie316a5eccb676bb918d4bb746795019145c10f5b
This commit is contained in:
Alessio Quaglino
2025-01-06 04:34:49 -08:00
committed by Copybara-Service
parent 65048d6b8f
commit ee6f4837f3
8 changed files with 747 additions and 22 deletions
+7
View File
@@ -3632,6 +3632,13 @@ saving the XML:
These attributes are directly passed through to the automatically-generated :ref:`flex<deformable-flex>` object and
have the same meaning.
.. _body-flexcomp-origin:
:at:`origin`: :at-val:`real(3), "0 0 0"`
The origin of the flexcomp. Used for generating a volumetric mesh from an OBJ surface mesh. Each surface triangle is
connected to the origin to create a tetrahedron, so the resulting volumetric mesh is guaranteed to be well-formed
only for convex shapes.
.. _flexcomp-contact:
:el-prefix:`flexcomp/` |-| **contact** (*)
+2
View File
@@ -445,6 +445,8 @@
| | | +-----------------------------------------------------------------+-----------------------------------------------------------------+-----------------------------------------------------------------+-----------------------------------------------------------------+ |
| | | | :ref:`axisangle<body-flexcomp-axisangle>` | :ref:`xyaxes<body-flexcomp-xyaxes>` | :ref:`zaxis<body-flexcomp-zaxis>` | :ref:`euler<body-flexcomp-euler>` | |
| | | +-----------------------------------------------------------------+-----------------------------------------------------------------+-----------------------------------------------------------------+-----------------------------------------------------------------+ |
| | | | :ref:`origin<body-flexcomp-origin>` | | | | |
| | | +-----------------------------------------------------------------+-----------------------------------------------------------------+-----------------------------------------------------------------+-----------------------------------------------------------------+ |
+------------------------------------+----+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| |_2| flexcomp |br| |_2| |L| | | .. table:: |
| :ref:`edge | ? | :class: mjcf-attributes |
+617
View File
@@ -0,0 +1,617 @@
####
#
# OBJ File Generated by Meshlab
#
####
# Object cap.obj
#
# Vertices: 217
# Faces: 384
#
####
v -0.00000000 0.00000000 0.07411810
v 0.09659259 0.00000000 -0.00000001
v 0.04829629 0.08365163 0.00000001
v -0.04829629 0.08365163 0.00000001
v -0.09659259 0.00000000 -0.00000001
v -0.04829629 -0.08365163 0.00000001
v 0.04829629 -0.08365163 0.00000001
v 0.05341240 -0.00000000 0.05865872
v 0.08365164 0.04829629 -0.00000001
v 0.02670619 0.04625649 0.05865872
v 0.00000000 0.09659259 -0.00000001
v -0.02670619 0.04625649 0.05865872
v -0.08365164 0.04829629 -0.00000001
v -0.05341240 0.00000000 0.05865872
v -0.08365164 -0.04829629 -0.00000001
v -0.02670619 -0.04625649 0.05865872
v 0.00000000 -0.09659259 -0.00000001
v 0.02670619 -0.04625649 0.05865872
v 0.08365164 -0.04829629 -0.00000001
v 0.06724097 0.02381060 0.04420168
v 0.05424107 0.04632709 0.04420168
v 0.04028573 0.02325897 0.06263974
v 0.01299990 0.07013769 0.04420167
v -0.01299990 0.07013769 0.04420168
v -0.00000000 0.04651795 0.06263975
v -0.05424108 0.04632709 0.04420166
v -0.06724098 0.02381060 0.04420166
v -0.04028573 0.02325897 0.06263974
v -0.06724097 -0.02381060 0.04420168
v -0.05424107 -0.04632709 0.04420168
v -0.04028573 -0.02325897 0.06263974
v -0.01299990 -0.07013769 0.04420167
v 0.01299990 -0.07013769 0.04420168
v 0.00000000 -0.04651795 0.06263975
v 0.05424108 -0.04632709 0.04420166
v 0.06724098 -0.02381060 0.04420166
v 0.04028573 -0.02325897 0.06263974
v 0.02678733 -0.00000000 0.07046351
v 0.01339367 0.02319851 0.07046351
v 0.07868688 -0.00000000 0.03583015
v 0.09330128 0.02500000 -0.00000001
v 0.06830128 0.06830128 -0.00000004
v 0.03934343 0.06814483 0.03583015
v -0.01339367 0.02319851 0.07046351
v 0.02500000 0.09330128 -0.00000001
v -0.02500000 0.09330128 -0.00000001
v -0.03934344 0.06814483 0.03583015
v -0.02678734 0.00000000 0.07046351
v -0.06830128 0.06830128 -0.00000004
v -0.09330128 0.02500000 -0.00000001
v -0.07868689 0.00000000 0.03583013
v -0.01339367 -0.02319851 0.07046351
v -0.09330128 -0.02500000 -0.00000001
v -0.06830128 -0.06830128 -0.00000004
v -0.03934343 -0.06814483 0.03583015
v 0.01339367 -0.02319851 0.07046351
v -0.02500000 -0.09330128 -0.00000001
v 0.02500000 -0.09330128 -0.00000001
v 0.03934344 -0.06814483 0.03583015
v 0.06830128 -0.06830128 -0.00000004
v 0.09330128 -0.02500000 -0.00000001
v 0.06102579 0.03523326 0.04507211
v 0.04719808 0.03485627 0.05509577
v 0.05378547 0.02344661 0.05509576
v -0.00000000 0.07046651 0.04507211
v -0.00658737 0.05830287 0.05509577
v 0.00658736 0.05830287 0.05509577
v -0.06102579 0.03523326 0.04507211
v -0.05378547 0.02344662 0.05509576
v -0.04719809 0.03485627 0.05509576
v -0.06102579 -0.03523326 0.04507211
v -0.04719808 -0.03485627 0.05509577
v -0.05378547 -0.02344661 0.05509576
v 0.00000000 -0.07046651 0.04507211
v 0.00658737 -0.05830287 0.05509577
v -0.00658736 -0.05830287 0.05509577
v 0.06102579 -0.03523326 0.04507211
v 0.05378547 -0.02344662 0.05509576
v 0.04719809 -0.03485627 0.05509576
v 0.03349884 0.01162469 0.06762048
v 0.02681670 0.02319850 0.06762048
v 0.02009635 0.01160263 0.07138842
v 0.08512369 0.01233582 0.02512579
v 0.08049080 0.02435185 0.02823111
v 0.07300231 0.01205527 0.04138871
v 0.06133472 0.05753115 0.02823112
v 0.05324498 0.06755137 0.02512579
v 0.04694132 0.05719421 0.04138872
v 0.00668214 0.03482319 0.06762048
v -0.00668214 0.03482319 0.06762048
v -0.00000000 0.02320527 0.07138842
v 0.03187871 0.07988720 0.02512577
v 0.01915608 0.08188300 0.02823112
v 0.02606098 0.06924948 0.04138871
v -0.01915608 0.08188300 0.02823112
v -0.03187871 0.07988719 0.02512579
v -0.02606099 0.06924949 0.04138871
v -0.02681670 0.02319850 0.06762048
v -0.03349884 0.01162470 0.06762048
v -0.02009636 0.01160263 0.07138842
v -0.05324498 0.06755137 0.02512577
v -0.06133472 0.05753115 0.02823112
v -0.04694132 0.05719422 0.04138871
v -0.08049081 0.02435185 0.02823111
v -0.08512370 0.01233582 0.02512577
v -0.07300231 0.01205527 0.04138870
v -0.03349884 -0.01162469 0.06762048
v -0.02681670 -0.02319850 0.06762048
v -0.02009635 -0.01160263 0.07138842
v -0.08512370 -0.01233582 0.02512577
v -0.08049080 -0.02435185 0.02823111
v -0.07300231 -0.01205527 0.04138871
v -0.06133472 -0.05753115 0.02823112
v -0.05324498 -0.06755137 0.02512579
v -0.04694132 -0.05719421 0.04138872
v -0.00668214 -0.03482319 0.06762048
v 0.00668214 -0.03482319 0.06762048
v 0.00000000 -0.02320527 0.07138842
v -0.03187871 -0.07988720 0.02512577
v -0.01915608 -0.08188300 0.02823112
v -0.02606098 -0.06924948 0.04138871
v 0.01915608 -0.08188300 0.02823112
v 0.03187871 -0.07988719 0.02512579
v 0.02606099 -0.06924949 0.04138871
v 0.02681670 -0.02319850 0.06762048
v 0.03349884 -0.01162470 0.06762048
v 0.02009636 -0.01160263 0.07138842
v 0.05324498 -0.06755137 0.02512577
v 0.06133472 -0.05753115 0.02823112
v 0.04694132 -0.05719422 0.04138871
v 0.08049081 -0.02435185 0.02823111
v 0.08512369 -0.01233582 0.02512579
v 0.07300231 -0.01205527 0.04138871
v 0.06011157 0.01183397 0.05315326
v 0.04687075 0.01169339 0.06167607
v 0.07504904 0.03594581 0.02957566
v 0.06865450 0.04702147 0.02957566
v 0.04030430 0.04614115 0.05315326
v 0.03356215 0.03474456 0.06167607
v 0.01980726 0.05797512 0.05315328
v 0.01330860 0.04643795 0.06167607
v 0.00639453 0.08296728 0.02957566
v -0.00639453 0.08296728 0.02957566
v -0.01980726 0.05797513 0.05315326
v -0.01330860 0.04643795 0.06167607
v -0.04030430 0.04614115 0.05315326
v -0.03356215 0.03474456 0.06167607
v -0.06865451 0.04702147 0.02957564
v -0.07504904 0.03594581 0.02957565
v -0.06011157 0.01183397 0.05315326
v -0.04687076 0.01169339 0.06167606
v -0.06011157 -0.01183397 0.05315326
v -0.04687075 -0.01169339 0.06167607
v -0.07504904 -0.03594581 0.02957566
v -0.06865450 -0.04702147 0.02957566
v -0.04030430 -0.04614115 0.05315326
v -0.03356215 -0.03474456 0.06167607
v -0.01980726 -0.05797512 0.05315328
v -0.01330860 -0.04643795 0.06167607
v -0.00639453 -0.08296728 0.02957566
v 0.00639453 -0.08296728 0.02957566
v 0.01980726 -0.05797513 0.05315326
v 0.01330860 -0.04643795 0.06167607
v 0.04030430 -0.04614115 0.05315326
v 0.03356215 -0.03474456 0.06167607
v 0.06865451 -0.04702147 0.02957564
v 0.07504904 -0.03594581 0.02957565
v 0.06011157 -0.01183397 0.05315326
v 0.04687075 -0.01169339 0.06167607
v 0.01339461 -0.00000000 0.07321696
v 0.00669730 0.01160007 0.07321696
v 0.04015301 -0.00000000 0.06570269
v 0.02007650 0.03477353 0.06570269
v 0.06638318 -0.00000000 0.04890629
v 0.08950821 -0.00000000 0.01870825
v 0.09576622 0.01260786 -0.00000001
v 0.08923991 0.03696438 -0.00000001
v 0.03319159 0.05748951 0.04890630
v 0.07663205 0.05880184 -0.00000001
v 0.05880184 0.07663205 -0.00000001
v 0.04475410 0.07751638 0.01870825
v -0.00669731 0.01160007 0.07321696
v -0.02007651 0.03477353 0.06570269
v 0.03696438 0.08923991 -0.00000001
v 0.01260786 0.09576622 -0.00000001
v -0.03319159 0.05748951 0.04890630
v -0.01260786 0.09576622 -0.00000001
v -0.03696438 0.08923991 -0.00000001
v -0.04475411 0.07751638 0.01870823
v -0.01339461 0.00000000 0.07321696
v -0.04015301 0.00000000 0.06570269
v -0.05880184 0.07663205 -0.00000001
v -0.07663205 0.05880184 -0.00000001
v -0.06638319 0.00000000 0.04890629
v -0.08923991 0.03696438 -0.00000001
v -0.09576622 0.01260786 -0.00000001
v -0.08950821 0.00000000 0.01870823
v -0.00669730 -0.01160007 0.07321696
v -0.02007650 -0.03477353 0.06570269
v -0.09576622 -0.01260786 -0.00000001
v -0.08923991 -0.03696438 -0.00000001
v -0.03319159 -0.05748951 0.04890630
v -0.07663205 -0.05880184 -0.00000001
v -0.05880184 -0.07663205 -0.00000001
v -0.04475410 -0.07751638 0.01870825
v 0.00669731 -0.01160007 0.07321696
v 0.02007651 -0.03477353 0.06570269
v -0.03696438 -0.08923991 -0.00000001
v -0.01260786 -0.09576622 -0.00000001
v 0.03319159 -0.05748951 0.04890630
v 0.01260786 -0.09576622 -0.00000001
v 0.03696438 -0.08923991 -0.00000001
v 0.04475411 -0.07751638 0.01870823
v 0.05880184 -0.07663205 -0.00000001
v 0.07663205 -0.05880184 -0.00000001
v 0.08923991 -0.03696438 -0.00000001
v 0.09576622 -0.01260786 -0.00000001
# 217 vertices, 0 vertices normals
f 62 63 64
f 65 66 67
f 68 69 70
f 71 72 73
f 74 75 76
f 77 78 79
f 80 81 82
f 83 84 85
f 86 87 88
f 89 90 91
f 92 93 94
f 95 96 97
f 98 99 100
f 101 102 103
f 104 105 106
f 107 108 109
f 110 111 112
f 113 114 115
f 116 117 118
f 119 120 121
f 122 123 124
f 125 126 127
f 128 129 130
f 131 132 133
f 134 64 135
f 136 137 62
f 63 138 139
f 140 67 141
f 142 143 65
f 66 144 145
f 146 70 147
f 148 149 68
f 69 150 151
f 152 73 153
f 154 155 71
f 72 156 157
f 158 76 159
f 160 161 74
f 75 162 163
f 164 79 165
f 166 167 77
f 78 168 169
f 170 82 171
f 172 135 80
f 81 139 173
f 174 85 134
f 175 176 83
f 84 177 136
f 138 88 178
f 137 179 86
f 87 180 181
f 171 91 182
f 173 141 89
f 90 145 183
f 178 94 140
f 181 184 92
f 93 185 142
f 144 97 186
f 143 187 95
f 96 188 189
f 182 100 190
f 183 147 98
f 99 151 191
f 186 103 146
f 189 192 101
f 102 193 148
f 150 106 194
f 149 195 104
f 105 196 197
f 190 109 198
f 191 153 107
f 108 157 199
f 194 112 152
f 197 200 110
f 111 201 154
f 156 115 202
f 155 203 113
f 114 204 205
f 198 118 206
f 199 159 116
f 117 163 207
f 202 121 158
f 205 208 119
f 120 209 160
f 162 124 210
f 161 211 122
f 123 212 213
f 206 127 170
f 207 165 125
f 126 169 172
f 210 130 164
f 213 214 128
f 129 215 166
f 168 133 174
f 167 216 131
f 132 217 175
f 20 62 64
f 62 21 63
f 64 63 22
f 23 65 67
f 65 24 66
f 67 66 25
f 26 68 70
f 68 27 69
f 70 69 28
f 29 71 73
f 71 30 72
f 73 72 31
f 32 74 76
f 74 33 75
f 76 75 34
f 35 77 79
f 77 36 78
f 79 78 37
f 38 80 82
f 80 22 81
f 82 81 39
f 40 83 85
f 83 41 84
f 85 84 20
f 21 86 88
f 86 42 87
f 88 87 43
f 39 89 91
f 89 25 90
f 91 90 44
f 43 92 94
f 92 45 93
f 94 93 23
f 24 95 97
f 95 46 96
f 97 96 47
f 44 98 100
f 98 28 99
f 100 99 48
f 47 101 103
f 101 49 102
f 103 102 26
f 27 104 106
f 104 50 105
f 106 105 51
f 48 107 109
f 107 31 108
f 109 108 52
f 51 110 112
f 110 53 111
f 112 111 29
f 30 113 115
f 113 54 114
f 115 114 55
f 52 116 118
f 116 34 117
f 118 117 56
f 55 119 121
f 119 57 120
f 121 120 32
f 33 122 124
f 122 58 123
f 124 123 59
f 56 125 127
f 125 37 126
f 127 126 38
f 59 128 130
f 128 60 129
f 130 129 35
f 36 131 133
f 131 61 132
f 133 132 40
f 8 134 135
f 134 20 64
f 135 64 22
f 20 136 62
f 136 9 137
f 62 137 21
f 22 63 139
f 63 21 138
f 139 138 10
f 10 140 141
f 140 23 67
f 141 67 25
f 23 142 65
f 142 11 143
f 65 143 24
f 25 66 145
f 66 24 144
f 145 144 12
f 12 146 147
f 146 26 70
f 147 70 28
f 26 148 68
f 148 13 149
f 68 149 27
f 28 69 151
f 69 27 150
f 151 150 14
f 14 152 153
f 152 29 73
f 153 73 31
f 29 154 71
f 154 15 155
f 71 155 30
f 31 72 157
f 72 30 156
f 157 156 16
f 16 158 159
f 158 32 76
f 159 76 34
f 32 160 74
f 160 17 161
f 74 161 33
f 34 75 163
f 75 33 162
f 163 162 18
f 18 164 165
f 164 35 79
f 165 79 37
f 35 166 77
f 166 19 167
f 77 167 36
f 37 78 169
f 78 36 168
f 169 168 8
f 1 170 171
f 170 38 82
f 171 82 39
f 38 172 80
f 172 8 135
f 80 135 22
f 39 81 173
f 81 22 139
f 173 139 10
f 8 174 134
f 174 40 85
f 134 85 20
f 40 175 83
f 175 2 176
f 83 176 41
f 20 84 136
f 84 41 177
f 136 177 9
f 10 138 178
f 138 21 88
f 178 88 43
f 21 137 86
f 137 9 179
f 86 179 42
f 43 87 181
f 87 42 180
f 181 180 3
f 1 171 182
f 171 39 91
f 182 91 44
f 39 173 89
f 173 10 141
f 89 141 25
f 44 90 183
f 90 25 145
f 183 145 12
f 10 178 140
f 178 43 94
f 140 94 23
f 43 181 92
f 181 3 184
f 92 184 45
f 23 93 142
f 93 45 185
f 142 185 11
f 12 144 186
f 144 24 97
f 186 97 47
f 24 143 95
f 143 11 187
f 95 187 46
f 47 96 189
f 96 46 188
f 189 188 4
f 1 182 190
f 182 44 100
f 190 100 48
f 44 183 98
f 183 12 147
f 98 147 28
f 48 99 191
f 99 28 151
f 191 151 14
f 12 186 146
f 186 47 103
f 146 103 26
f 47 189 101
f 189 4 192
f 101 192 49
f 26 102 148
f 102 49 193
f 148 193 13
f 14 150 194
f 150 27 106
f 194 106 51
f 27 149 104
f 149 13 195
f 104 195 50
f 51 105 197
f 105 50 196
f 197 196 5
f 1 190 198
f 190 48 109
f 198 109 52
f 48 191 107
f 191 14 153
f 107 153 31
f 52 108 199
f 108 31 157
f 199 157 16
f 14 194 152
f 194 51 112
f 152 112 29
f 51 197 110
f 197 5 200
f 110 200 53
f 29 111 154
f 111 53 201
f 154 201 15
f 16 156 202
f 156 30 115
f 202 115 55
f 30 155 113
f 155 15 203
f 113 203 54
f 55 114 205
f 114 54 204
f 205 204 6
f 1 198 206
f 198 52 118
f 206 118 56
f 52 199 116
f 199 16 159
f 116 159 34
f 56 117 207
f 117 34 163
f 207 163 18
f 16 202 158
f 202 55 121
f 158 121 32
f 55 205 119
f 205 6 208
f 119 208 57
f 32 120 160
f 120 57 209
f 160 209 17
f 18 162 210
f 162 33 124
f 210 124 59
f 33 161 122
f 161 17 211
f 122 211 58
f 59 123 213
f 123 58 212
f 213 212 7
f 1 206 170
f 206 56 127
f 170 127 38
f 56 207 125
f 207 18 165
f 125 165 37
f 38 126 172
f 126 37 169
f 172 169 8
f 18 210 164
f 210 59 130
f 164 130 35
f 59 213 128
f 213 7 214
f 128 214 60
f 35 129 166
f 129 60 215
f 166 215 19
f 8 168 174
f 168 36 133
f 174 133 40
f 36 167 131
f 167 19 216
f 131 216 61
f 40 132 175
f 132 61 217
f 175 217 2
# 384 faces, 0 coords texture
# End of File
+66
View File
@@ -0,0 +1,66 @@
<!-- Copyright 2024 DeepMind Technologies Limited
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<mujoco model="Gripper">
<include file="scene.xml"/>
<option cone="elliptic" impratio="10" integrator="implicitfast"/>
<worldbody>
<body name="hand" pos="0 0 .37">
<joint name="lift" type="slide" range="0 1"/>
<geom type="box" size=".2 .1 .05" rgba=".2 .2 .2 1"/>
<body name="right_gripper">
<joint name="right" type="slide" axis="-1 0 0"/>
<geom type="box" size=".02 .1 .15" pos=".18 0 -.2" rgba=".2 .2 .2 1"/>
<flexcomp type="mesh" file="cap.obj" pos=".16 0 -.25" dim="3" euler="0 -90 0"
origin="0 0 0" radius=".001" rgba="0 .7 .7 1" mass=".5" name="left">
<edge equality="true"/>
<contact selfcollide="none" internal="false" contype="2" conaffinity="2"/>
<pin id="0 2 3 4 5 6 7 9 11 13 15 17 19 41 45 46 50 53 57 58 61 176 177 179 180 184 185
187 188 192 193 195 196 200 201 203 204 208 209 211 212 214 215 216 217"/>
</flexcomp>
</body>
<body name="left_gripper">
<joint name="left" type="slide" axis="1 0 0"/>
<geom type="box" size=".02 .1 .15" pos="-.18 0 -.2" rgba=".2 .2 .2 1"/>
<flexcomp type="mesh" file="cap.obj" pos="-.16 0 -.25" dim="3" euler="0 90 0"
origin="0 0 0" radius=".001" rgba="0 .7 .7 1" mass=".5" name="right">
<edge equality="true"/>
<contact selfcollide="none" internal="false" contype="2" conaffinity="2"/>
<pin id="0 2 3 4 5 6 7 9 11 13 15 17 19 41 45 46 50 53 57 58 61 176 177 179 180 184 185
187 188 192 193 195 196 200 201 203 204 208 209 211 212 214 215 216 217"/>
</flexcomp>
</body>
</body>
</worldbody>
<equality>
<joint joint1="right" joint2="left"/>
</equality>
<tendon>
<fixed name="grasp">
<joint joint="right" coef="1"/>
<joint joint="left" coef="1"/>
</fixed>
</tendon>
<actuator>
<position name="lift" joint="lift" kp="600" dampratio="1" ctrlrange="0 1"/>
<position name="grasp" tendon="grasp" kp="200" dampratio="1" ctrlrange="0 1"/>
</actuator>
</mujoco>
+32 -5
View File
@@ -940,8 +940,8 @@ bool mjCFlexcomp::MakeMesh(mjCModel* model, char* error, int error_sz) {
}
// check dim
if (def.spec.flex->dim != 2) {
return comperr(error, "Flex dim must be 2 in for mesh", error_sz);
if (def.spec.flex->dim < 2) {
return comperr(error, "Flex dim must be at least 2 for mesh", error_sz);
}
// load resource
@@ -990,15 +990,42 @@ bool mjCFlexcomp::MakeMesh(mjCModel* model, char* error, int error_sz) {
mesh.RemoveRepeated();
}
// copy faces
element = mesh.Face();
// copy vertices, convert from float to double
point = vector<double> (mesh.nvert()*3);
for (int i=0; i < mesh.nvert()*3; i++) {
point[i] = (double) mesh.Vert(i);
}
// copy faces or create 3D mesh
if (def.spec.flex->dim == 2) {
element = mesh.Face();
} else {
point.insert(point.begin() + 0, origin[0]);
point.insert(point.begin() + 1, origin[1]);
point.insert(point.begin() + 2, origin[2]);
for (int i=0; i < mesh.Face().size(); i+=3) {
// only add tetrahedra with positive volume
int tet[3] = {mesh.Face()[i+0]+1,
mesh.Face()[i+1]+1,
mesh.Face()[i+2]+1};
double edge1[3], edge2[3], edge3[3];
for (int i=0; i < 3; i++) {
edge1[i] = point[3*tet[0]+i] - origin[i];
edge2[i] = point[3*tet[1]+i] - origin[i];
edge3[i] = point[3*tet[2]+i] - origin[i];
}
double normal[3];
mjuu_crossvec(normal, edge1, edge2);
if (mjuu_dot3(normal, edge3) < mjMINVAL) {
continue;
}
element.push_back(0);
element.push_back(tet[0]);
element.push_back(tet[1]);
element.push_back(tet[2]);
}
}
return true;
}
+1
View File
@@ -68,6 +68,7 @@ class mjCFlexcomp {
int count[3]; // grid count in each dimension
double spacing[3]; // spacing between grid elements
double scale[3]; // scaling for mesh and direct
double origin[3]; // origin for generating a 3D mesh from a convex 2D mesh
double mass; // total mass of auto-generated bodies
double inertiabox; // size of inertia box for each body
bool equality; // create edge equality constraint
+6 -2
View File
@@ -311,10 +311,10 @@ const char* MJCF[nMJCF][mjXATTRNUM] = {
{"config", "*", "2", "key", "value"},
{">"},
{">"},
{"flexcomp", "*", "24", "name", "type", "group", "dim",
{"flexcomp", "*", "25", "name", "type", "group", "dim",
"count", "spacing", "radius", "rigid", "mass", "inertiabox",
"scale", "file", "point", "element", "texcoord", "material", "rgba",
"flatskin", "pos", "quat", "axisangle", "xyaxes", "zaxis", "euler"},
"flatskin", "pos", "quat", "axisangle", "xyaxes", "zaxis", "euler", "origin"},
{"<"},
{"edge", "?", "5", "equality", "solref", "solimp", "stiffness", "damping"},
{"elasticity", "?", "4", "young", "poisson", "damping", "thickness"},
@@ -2643,6 +2643,10 @@ void mjXReader::OneFlexcomp(XMLElement* elem, mjsBody* body, const mjVFS* vfs) {
ReadAttrInt(elem, "dim", &dflex.dim);
ReadAttr(elem, "radius", 1, &dflex.radius, text);
ReadAttrInt(elem, "group", &dflex.group);
if (!ReadAttr(elem, "origin", 3, fcomp.origin, text) &&
fcomp.type == mjFCOMPTYPE_MESH && dflex.dim == 3) {
throw mjXError(elem, "origin must be specified for mesh flexcomps if dim=3");
}
// pose
ReadAttr(elem, "pos", 3, fcomp.pos, text);
+16 -15
View File
@@ -231,21 +231,22 @@ mjtNum CompareModel(const mjModel* m1, const mjModel* m2,
#undef X
if (maxdif > 0) return maxdif;
// compare arrays, apart from bvh-related ones, as those are sensitive to
// numerical differences when meshes are perfectly symmetric.
#define X(type, name, nr, nc) \
if (strncmp(#name, "bvh_", 4)) { \
for (int r = 0; r < m1->nr; r++) { \
for (int c = 0; c < nc; c++) { \
dif = Compare(m1->name[r * nc + c], m2->name[r * nc + c]); \
if (dif > maxdif) { \
maxdif = dif; \
field = #name; \
field += " row: " + std::to_string(r); \
field += " col: " + std::to_string(c); \
} \
} \
} \
// compare arrays, apart from bvh-related ones (which includes flex_vert0), as
// those are sensitive to numerical differences when meshes are perfectly
// symmetric.
#define X(type, name, nr, nc) \
if (strncmp(#name, "bvh_", 4) && strncmp(#name, "flex_vert0", 4)) { \
for (int r = 0; r < m1->nr; r++) { \
for (int c = 0; c < nc; c++) { \
dif = Compare(m1->name[r * nc + c], m2->name[r * nc + c]); \
if (dif > maxdif) { \
maxdif = dif; \
field = #name; \
field += " row: " + std::to_string(r); \
field += " col: " + std::to_string(c); \
} \
} \
} \
} // NOLINT
MJMODEL_POINTERS
#undef X