Small performance improvement: Parse body once during replicate.
PiperOrigin-RevId: 657227162 Change-Id: I5b60c25ab4634a44ed0474fdbf22e676bcb8f6d7
This commit is contained in:
committed by
Copybara-Service
parent
a29f67c850
commit
6928e09f36
@@ -3497,12 +3497,16 @@ void mjXReader::Body(XMLElement* section, mjsBody* pbody, mjsFrame* frame,
|
|||||||
double pos[3] = {0, 0, 0};
|
double pos[3] = {0, 0, 0};
|
||||||
double quat[4] = {1, 0, 0, 0};
|
double quat[4] = {1, 0, 0, 0};
|
||||||
|
|
||||||
for (int i = 0; i < count; i++) {
|
// parent frame that will be used to attach the subtree
|
||||||
// create parent frame
|
mjsFrame* pframe = mjs_addFrame(subtree, frame);
|
||||||
mjsFrame* pframe = mjs_addFrame(subtree, frame);
|
mjs_setDefault(pframe->element, childdef ? childdef : def);
|
||||||
mjs_setString(pframe->info, ("line = " + std::to_string(elem->GetLineNum())).c_str());
|
mjs_setString(pframe->info, ("line = " + std::to_string(elem->GetLineNum())).c_str());
|
||||||
mjs_setDefault(pframe->element, childdef ? childdef : def);
|
|
||||||
|
|
||||||
|
// parse subtree
|
||||||
|
Body(elem, subtree, pframe, vfs);
|
||||||
|
|
||||||
|
// update pframe and attach
|
||||||
|
for (int i = 0; i < count; i++) {
|
||||||
// accumulate rotation
|
// accumulate rotation
|
||||||
mjuu_setvec(pframe->pos, pos[0], pos[1], pos[2]);
|
mjuu_setvec(pframe->pos, pos[0], pos[1], pos[2]);
|
||||||
mjuu_frameaccum(pos, quat, offset, rotation);
|
mjuu_frameaccum(pos, quat, offset, rotation);
|
||||||
@@ -3518,9 +3522,6 @@ void mjXReader::Body(XMLElement* section, mjsBody* pbody, mjsFrame* frame,
|
|||||||
std::string suffix = separator;
|
std::string suffix = separator;
|
||||||
UpdateString(suffix, count, i);
|
UpdateString(suffix, count, i);
|
||||||
|
|
||||||
// process subtree
|
|
||||||
Body(elem, subtree, pframe, vfs);
|
|
||||||
|
|
||||||
// attach to parent
|
// attach to parent
|
||||||
if (mjs_attachFrame(pbody, pframe, /*prefix=*/"", suffix.c_str()) != 0) {
|
if (mjs_attachFrame(pbody, pframe, /*prefix=*/"", suffix.c_str()) != 0) {
|
||||||
throw mjXError(elem, mjs_getError(spec));
|
throw mjXError(elem, mjs_getError(spec));
|
||||||
|
|||||||
Reference in New Issue
Block a user