Add .clang-format to user/, format user_composite

PiperOrigin-RevId: 958225464
Change-Id: Iad7eb52dbecf7585f98375c90863ca707c494590
This commit is contained in:
Yuval Tassa
2026-08-03 01:21:09 -07:00
committed by Copybara-Service
parent 4278c7b0cd
commit 760477f406
2 changed files with 253 additions and 241 deletions
+28
View File
@@ -0,0 +1,28 @@
---
BasedOnStyle: Google
Language: Cpp
ColumnLimit: 100
IncludeBlocks: Preserve
AlignArrayOfStructures: Left
AlignConsecutiveAssignments:
Enabled: true
AlignCompound: true
PadOperators: true
AlignConsecutiveDeclarations:
Enabled: true
AlignConsecutiveShortCaseStatements:
Enabled: true
AlignEscapedNewlines: LeftWithLastLine
AlignTrailingComments:
Kind: Always
OverEmptyLines: 2
AllowAllArgumentsOnNextLine: false
AllowShortBlocksOnASingleLine: Always
AllowShortFunctionsOnASingleLine: Inline
BreakBinaryOperations: RespectPrecedence
BinPackArguments: false
BinPackParameters: OnePerLine
IndentPPDirectives: None
MaxEmptyLinesToKeep: 2
SortIncludes: false
...
+27 -43
View File
@@ -44,7 +44,6 @@ static bool comperr(char* error, const char* msg, int error_sz) {
} }
// constructor // constructor
mjCComposite::mjCComposite(void) { mjCComposite::mjCComposite(void) {
// common properties // common properties
@@ -77,16 +76,13 @@ mjCComposite::mjCComposite(void) {
skingroup = 0; skingroup = 0;
// clear add flags // clear add flags
for (int i=0; i < mjNCOMPKINDS; i++) { for (int i = 0; i < mjNCOMPKINDS; i++) { add[i] = false; }
add[i] = false;
}
// clear internal // clear internal
dim = 0; dim = 0;
} }
// create the array of default joint options, append new elements only for particles type // create the array of default joint options, append new elements only for particles type
bool mjCComposite::AddDefaultJoint(char* error, int error_sz) { bool mjCComposite::AddDefaultJoint(char* error, int error_sz) {
for (int i = 0; i < mjNCOMPKINDS; i++) { for (int i = 0; i < mjNCOMPKINDS; i++) {
@@ -103,7 +99,6 @@ bool mjCComposite::AddDefaultJoint(char* error, int error_sz) {
} }
// set defaults, after reading top-level info and skin // set defaults, after reading top-level info and skin
void mjCComposite::SetDefault(void) { void mjCComposite::SetDefault(void) {
// set all default groups to 3 // set all default groups to 3
@@ -126,16 +121,13 @@ void mjCComposite::SetDefault(void) {
} }
// make composite object // make composite object
bool mjCComposite::Make(mjSpec* spec, mjsBody* body, char* error, int error_sz) { bool mjCComposite::Make(mjSpec* spec, mjsBody* body, char* error, int error_sz) {
mjCModel* model = (mjCModel*)spec->element; mjCModel* model = (mjCModel*)spec->element;
// check counts // check counts
for (int i = 0; i < 3; i++) { for (int i = 0; i < 3; i++) {
if (count[i] < 1) { if (count[i] < 1) { return comperr(error, "Positive counts expected in composite", error_sz); }
return comperr(error, "Positive counts expected in composite", error_sz);
}
} }
// check cable sizes are nonzero if vertices are not prescribed // check cable sizes are nonzero if vertices are not prescribed
@@ -159,9 +151,7 @@ bool mjCComposite::Make(mjSpec* spec, mjsBody* body, char* error, int error_sz)
first = true; first = true;
} else { } else {
dim++; dim++;
if (first) { if (first) { return comperr(error, "Singleton counts must come last", error_sz); }
return comperr(error, "Singleton counts must come last", error_sz);
}
} }
} }
@@ -239,12 +229,9 @@ bool mjCComposite::Make(mjSpec* spec, mjsBody* body, char* error, int error_sz)
} }
bool mjCComposite::MakeCable(mjCModel* model, mjsBody* body, char* error, int error_sz) { bool mjCComposite::MakeCable(mjCModel* model, mjsBody* body, char* error, int error_sz) {
// check dim // check dim
if (dim != 1) { if (dim != 1) { return comperr(error, "Cable must be one-dimensional", error_sz); }
return comperr(error, "Cable must be one-dimensional", error_sz);
}
// check geom type // check geom type
if (def[0].spec.geom->type != mjGEOM_CYLINDER && if (def[0].spec.geom->type != mjGEOM_CYLINDER &&
@@ -313,9 +300,8 @@ bool mjCComposite::MakeCable(mjCModel* model, mjsBody* body, char* error, int er
} }
mjsBody* mjCComposite::AddCableBody(
mjsBody* mjCComposite::AddCableBody(mjCModel* model, mjsBody* body, int ix, mjCModel* model, mjsBody* body, int ix, double normal[3], double prev_quat[4]) {
double normal[3], double prev_quat[4]) {
char txt_geom[100], txt_site[100], txt_slide[100]; char txt_geom[100], txt_site[100], txt_slide[100];
char this_body[100], next_body[100], this_joint[100]; char this_body[100], next_body[100], this_joint[100];
double dquat[4], this_quat[4]; double dquat[4], this_quat[4];
@@ -328,17 +314,20 @@ mjsBody* mjCComposite::AddCableBody(mjCModel* model, mjsBody* body, int ix,
// compute edge and tangent vectors // compute edge and tangent vectors
double edge[3], tprev[3], tnext[3], length_prev = 0; double edge[3], tprev[3], tnext[3], length_prev = 0;
mjuu_setvec(edge, uservert[3*(ix+1)+0]-uservert[3*ix+0], mjuu_setvec(edge,
uservert[3 * (ix + 1) + 0] - uservert[3 * ix + 0],
uservert[3 * (ix + 1) + 1] - uservert[3 * ix + 1], uservert[3 * (ix + 1) + 1] - uservert[3 * ix + 1],
uservert[3 * (ix + 1) + 2] - uservert[3 * ix + 2]); uservert[3 * (ix + 1) + 2] - uservert[3 * ix + 2]);
if (!first) { if (!first) {
mjuu_setvec(tprev, uservert[3*ix+0]-uservert[3*(ix-1)+0], mjuu_setvec(tprev,
uservert[3 * ix + 0] - uservert[3 * (ix - 1) + 0],
uservert[3 * ix + 1] - uservert[3 * (ix - 1) + 1], uservert[3 * ix + 1] - uservert[3 * (ix - 1) + 1],
uservert[3 * ix + 2] - uservert[3 * (ix - 1) + 2]); uservert[3 * ix + 2] - uservert[3 * (ix - 1) + 2]);
length_prev = mjuu_normvec(tprev, 3); length_prev = mjuu_normvec(tprev, 3);
} }
if (!last) { if (!last) {
mjuu_setvec(tnext, uservert[3*(ix+2)+0]-uservert[3*(ix+1)+0], mjuu_setvec(tnext,
uservert[3 * (ix + 2) + 0] - uservert[3 * (ix + 1) + 0],
uservert[3 * (ix + 2) + 1] - uservert[3 * (ix + 1) + 1], uservert[3 * (ix + 2) + 1] - uservert[3 * (ix + 1) + 1],
uservert[3 * (ix + 2) + 2] - uservert[3 * (ix + 1) + 2]); uservert[3 * (ix + 2) + 2] - uservert[3 * (ix + 1) + 2]);
mjuu_normvec(tnext, 3); mjuu_normvec(tnext, 3);
@@ -374,13 +363,12 @@ mjsBody* mjCComposite::AddCableBody(mjCModel* model, mjsBody* body, int ix,
body = mjs_addBody(body, 0); body = mjs_addBody(body, 0);
mjs_setName(body->element, this_body); mjs_setName(body->element, this_body);
if (first) { if (first) {
mjuu_setvec(body->pos, offset[0]+uservert[3*ix], mjuu_setvec(body->pos,
offset[0] + uservert[3 * ix],
offset[1] + uservert[3 * ix + 1], offset[1] + uservert[3 * ix + 1],
offset[2] + uservert[3 * ix + 2]); offset[2] + uservert[3 * ix + 2]);
mjuu_copyvec(body->quat, this_quat, 4); mjuu_copyvec(body->quat, this_quat, 4);
if (frame) { if (frame) { mjs_setFrame(body->element, frame); }
mjs_setFrame(body->element, frame);
}
} else { } else {
mjuu_setvec(body->pos, length_prev, 0, 0); mjuu_setvec(body->pos, length_prev, 0, 0);
double negquat[4] = {prev_quat[0], -prev_quat[1], -prev_quat[2], -prev_quat[3]}; double negquat[4] = {prev_quat[0], -prev_quat[1], -prev_quat[2], -prev_quat[3]};
@@ -392,8 +380,7 @@ mjsBody* mjCComposite::AddCableBody(mjCModel* model, mjsBody* body, int ix,
mjsGeom* geom = mjs_addGeom(body, &def[0].spec); mjsGeom* geom = mjs_addGeom(body, &def[0].spec);
mjs_setDefault(geom->element, mjs_getDefault(body->element)); mjs_setDefault(geom->element, mjs_getDefault(body->element));
mjs_setName(geom->element, txt_geom); mjs_setName(geom->element, txt_geom);
if (def[0].spec.geom->type == mjGEOM_CYLINDER || if (def[0].spec.geom->type == mjGEOM_CYLINDER || def[0].spec.geom->type == mjGEOM_CAPSULE) {
def[0].spec.geom->type == mjGEOM_CAPSULE) {
mjuu_zerovec(geom->fromto, 6); mjuu_zerovec(geom->fromto, 6);
geom->fromto[3] = length; geom->fromto[3] = length;
} else if (def[0].spec.geom->type == mjGEOM_BOX) { } else if (def[0].spec.geom->type == mjGEOM_BOX) {
@@ -445,7 +432,6 @@ mjsBody* mjCComposite::AddCableBody(mjCModel* model, mjsBody* body, int ix,
} }
// copy local vectors to skin // copy local vectors to skin
void mjCComposite::CopyIntoSkin(mjsSkin* skin) { void mjCComposite::CopyIntoSkin(mjsSkin* skin) {
mjs_setInt(skin->face, face.data(), face.size()); mjs_setInt(skin->face, face.data(), face.size());
@@ -471,7 +457,6 @@ void mjCComposite::CopyIntoSkin(mjsSkin* skin) {
} }
// add skin to 2D // add skin to 2D
void mjCComposite::MakeSkin2(mjCModel* model, mjtNum inflate) { void mjCComposite::MakeSkin2(mjCModel* model, mjtNum inflate) {
char txt[100]; char txt[100];
@@ -567,7 +552,6 @@ void mjCComposite::MakeSkin2(mjCModel* model, mjtNum inflate) {
} }
// add bones to 1D // add bones to 1D
void mjCComposite::MakeCableBones(mjCModel* model, mjsSkin* skin) { void mjCComposite::MakeCableBones(mjCModel* model, mjsSkin* skin) {
char this_body[100]; char this_body[100];
@@ -591,15 +575,19 @@ void mjCComposite::MakeCableBones(mjCModel* model, mjsSkin* skin) {
bindpos.push_back((ix == count[0] - 1) ? -2 * def[0].spec.geom->size[0] : 0); bindpos.push_back((ix == count[0] - 1) ? -2 * def[0].spec.geom->size[0] : 0);
bindpos.push_back(-def[0].spec.geom->size[1]); bindpos.push_back(-def[0].spec.geom->size[1]);
bindpos.push_back(0); bindpos.push_back(0);
bindquat.push_back(1); bindquat.push_back(0); bindquat.push_back(1);
bindquat.push_back(0); bindquat.push_back(0); bindquat.push_back(0);
bindquat.push_back(0);
bindquat.push_back(0);
} else { } else {
mjs_appendString(skin->bodyname, this_body); mjs_appendString(skin->bodyname, this_body);
bindpos.push_back((ix == count[0] - 1) ? -2 * def[0].spec.geom->size[0] : 0); bindpos.push_back((ix == count[0] - 1) ? -2 * def[0].spec.geom->size[0] : 0);
bindpos.push_back(def[0].spec.geom->size[1]); bindpos.push_back(def[0].spec.geom->size[1]);
bindpos.push_back(0); bindpos.push_back(0);
bindquat.push_back(1); bindquat.push_back(0); bindquat.push_back(1);
bindquat.push_back(0); bindquat.push_back(0); bindquat.push_back(0);
bindquat.push_back(0);
bindquat.push_back(0);
} }
// create vertid and vertweight // create vertid and vertweight
@@ -610,7 +598,6 @@ void mjCComposite::MakeCableBones(mjCModel* model, mjsSkin* skin) {
} }
void mjCComposite::MakeCableBonesSubgrid(mjCModel* model, mjsSkin* skin) { void mjCComposite::MakeCableBonesSubgrid(mjCModel* model, mjsSkin* skin) {
// populate bones // populate bones
for (int ix = 0; ix < count[0]; ix++) { for (int ix = 0; ix < count[0]; ix++) {
@@ -654,8 +641,8 @@ void mjCComposite::MakeCableBonesSubgrid(mjCModel* model, mjsSkin* skin) {
} }
//------------------------------------- subgrid matrices //------------------------------------- subgrid matrices
// clang-format off
// C = W * [f; f_x; f_y; f_xy] // C = W * [f; f_x; f_y; f_xy]
static const mjtNum subW[16*16] = { static const mjtNum subW[16*16] = {
@@ -883,7 +870,7 @@ static const mjtNum subD22[] = {
9, -1, 6, -1, 5, 1, 10, 1, -1, 9, -1, 6, -1, 5, 1, 10, 1, -1,
9, -0.5, 2, -0.5, 1, 0.5, 10, 0.5, -1 9, -0.5, 2, -0.5, 1, 0.5, 10, 0.5, -1
}; };
// clang-format on
// add skin to 2D, with subgrid // add skin to 2D, with subgrid
void mjCComposite::MakeSkin2Subgrid(mjCModel* model, mjtNum inflate) { void mjCComposite::MakeSkin2Subgrid(mjCModel* model, mjtNum inflate) {
@@ -1063,9 +1050,7 @@ void mjCComposite::MakeSkin2Subgrid(mjCModel* model, mjtNum inflate) {
int boneid[16]; int boneid[16];
int cnt = 0; int cnt = 0;
for (int dx = -1; dx < 3; dx++) { for (int dx = -1; dx < 3; dx++) {
for (int dy=-1; dy < 3; dy++) { for (int dy = -1; dy < 3; dy++) { boneid[cnt++] = (ix + dx) * count[1] + (iy + dy); }
boneid[cnt++] = (ix+dx)*count[1] + (iy+dy);
}
} }
// process subgrid, top-rigth owns last index // process subgrid, top-rigth owns last index
@@ -1100,4 +1085,3 @@ void mjCComposite::MakeSkin2Subgrid(mjCModel* model, mjtNum inflate) {
mju_free(Weight); mju_free(Weight);
mju_free(D); mju_free(D);
} }