diff --git a/src/user/CMakeLists.txt b/src/user/CMakeLists.txt index 5aa8981c..73c2050e 100644 --- a/src/user/CMakeLists.txt +++ b/src/user/CMakeLists.txt @@ -21,7 +21,7 @@ set(MUJOCO_USER_SRCS user_composite.h user_flexcomp.cc user_flexcomp.h - user_init.cc + user_init.c user_mesh.cc user_model.cc user_model.h diff --git a/src/user/user_api.h b/src/user/user_api.h index 59ec6d26..e23a5cb2 100644 --- a/src/user/user_api.h +++ b/src/user/user_api.h @@ -15,6 +15,7 @@ #ifndef MUJOCO_SRC_USER_USER_API_H_ #define MUJOCO_SRC_USER_USER_API_H_ +#include #include #include #include @@ -26,6 +27,8 @@ extern "C" { #endif +#define mjNAN NAN // used to mark undefined fields + //---------------------------------- handles to internal objects ----------------------------------- @@ -144,7 +147,7 @@ typedef struct _mjSpec { // model specification mjString modelfiledir; // path to model file // other - bool hasImplicitPluginElem; // already encountered an implicit plugin sensor/actuator + mjtByte hasImplicitPluginElem; // already encountered an implicit plugin sensor/actuator } mjSpec; @@ -747,7 +750,7 @@ typedef struct _mjsDefault { // default specification //---------------------------------- Top-level spec manipulation ----------------------------------- // Create spec. -MJAPI mjSpec* mjs_createSpec(); +MJAPI mjSpec* mjs_createSpec(void); // Compile spec to model. MJAPI mjModel* mjs_compile(mjSpec* s, const mjVFS* vfs); @@ -977,80 +980,80 @@ MJAPI const char* mjs_fullInertia(double quat[4], double inertia[3], const doubl //---------------------------------- Initialization ----------------------------------------------- -// Default model attributes. -MJAPI void mjs_defaultSpec(mjSpec& model); +// Default spec attributes. +MJAPI void mjs_defaultSpec(mjSpec* spec); // Default orientation attributes. -MJAPI void mjs_defaultOrientation(mjsOrientation& orient); +MJAPI void mjs_defaultOrientation(mjsOrientation* orient); // Default body attributes. -MJAPI void mjs_defaultBody(mjsBody& body); +MJAPI void mjs_defaultBody(mjsBody* body); // Default frame attributes. -MJAPI void mjs_defaultFrame(mjsFrame& frame); +MJAPI void mjs_defaultFrame(mjsFrame* frame); // Default joint attributes. -MJAPI void mjs_defaultJoint(mjsJoint& joint); +MJAPI void mjs_defaultJoint(mjsJoint* joint); // Default geom attributes. -MJAPI void mjs_defaultGeom(mjsGeom& geom); +MJAPI void mjs_defaultGeom(mjsGeom* geom); // Default site attributes. -MJAPI void mjs_defaultSite(mjsSite& site); +MJAPI void mjs_defaultSite(mjsSite* site); // Default camera attributes. -MJAPI void mjs_defaultCamera(mjsCamera& camera); +MJAPI void mjs_defaultCamera(mjsCamera* camera); // Default light attributes. -MJAPI void mjs_defaultLight(mjsLight& light); +MJAPI void mjs_defaultLight(mjsLight* light); // Default flex attributes. -MJAPI void mjs_defaultFlex(mjsFlex& flex); +MJAPI void mjs_defaultFlex(mjsFlex* flex); // Default mesh attributes. -MJAPI void mjs_defaultMesh(mjsMesh& mesh); +MJAPI void mjs_defaultMesh(mjsMesh* mesh); // Default height field attributes. -MJAPI void mjs_defaultHField(mjsHField& hfield); +MJAPI void mjs_defaultHField(mjsHField* hfield); // Default skin attributes. -MJAPI void mjs_defaultSkin(mjsSkin& skin); +MJAPI void mjs_defaultSkin(mjsSkin* skin); // Default texture attributes. -MJAPI void mjs_defaultTexture(mjsTexture& texture); +MJAPI void mjs_defaultTexture(mjsTexture* texture); // Default material attributes. -MJAPI void mjs_defaultMaterial(mjsMaterial& material); +MJAPI void mjs_defaultMaterial(mjsMaterial* material); // Default pair attributes. -MJAPI void mjs_defaultPair(mjsPair& pair); +MJAPI void mjs_defaultPair(mjsPair* pair); // Default equality attributes. -MJAPI void mjs_defaultEquality(mjsEquality& equality); +MJAPI void mjs_defaultEquality(mjsEquality* equality); // Default tendon attributes. -MJAPI void mjs_defaultTendon(mjsTendon& tendon); +MJAPI void mjs_defaultTendon(mjsTendon* tendon); // Default actuator attributes. -MJAPI void mjs_defaultActuator(mjsActuator& actuator); +MJAPI void mjs_defaultActuator(mjsActuator* actuator); // Default sensor attributes. -MJAPI void mjs_defaultSensor(mjsSensor& sensor); +MJAPI void mjs_defaultSensor(mjsSensor* sensor); // Default numeric attributes. -MJAPI void mjs_defaultNumeric(mjsNumeric& numeric); +MJAPI void mjs_defaultNumeric(mjsNumeric* numeric); // Default text attributes. -MJAPI void mjs_defaultText(mjsText& text); +MJAPI void mjs_defaultText(mjsText* text); // Default tuple attributes. -MJAPI void mjs_defaultTuple(mjsTuple& tuple); +MJAPI void mjs_defaultTuple(mjsTuple* tuple); // Default keyframe attributes. -MJAPI void mjs_defaultKey(mjsKey& key); +MJAPI void mjs_defaultKey(mjsKey* key); // Default plugin attributes. -MJAPI void mjs_defaultPlugin(mjsPlugin& plugin); +MJAPI void mjs_defaultPlugin(mjsPlugin* plugin); //---------------------------------- Compiler cache ------------------------------------------------ @@ -1061,7 +1064,7 @@ typedef struct _mjCache* mjCache; MJAPI void mj_setCacheSize(mjCache cache, size_t size); // Get internal global cache context. -MJAPI mjCache mj_globalCache(); +MJAPI mjCache mj_globalCache(void); #ifdef __cplusplus } diff --git a/src/user/user_composite.cc b/src/user/user_composite.cc index 3a813b11..21c3cb6d 100644 --- a/src/user/user_composite.cc +++ b/src/user/user_composite.cc @@ -66,7 +66,7 @@ mjCComposite::mjCComposite(void) { mj_defaultSolRefImp(solrefsmooth, solimpsmooth); // plugin variables - mjs_defaultPlugin(plugin); + mjs_defaultPlugin(&plugin); plugin_name = ""; plugin_instance_name = ""; plugin.name = (mjString)&plugin_name; diff --git a/src/user/user_flexcomp.cc b/src/user/user_flexcomp.cc index a01f9a42..c319e1ab 100644 --- a/src/user/user_flexcomp.cc +++ b/src/user/user_flexcomp.cc @@ -87,8 +87,8 @@ mjCFlexcomp::mjCFlexcomp(void) { rigid = false; centered = false; - mjs_defaultPlugin(plugin); - mjs_defaultOrientation(alt); + mjs_defaultPlugin(&plugin); + mjs_defaultOrientation(&alt); plugin_name = ""; plugin_instance_name = ""; plugin.name = (mjString)&plugin_name; diff --git a/src/user/user_init.c b/src/user/user_init.c new file mode 100644 index 00000000..02f8b8fa --- /dev/null +++ b/src/user/user_init.c @@ -0,0 +1,404 @@ +// 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. + +#include +#include +#include +#include "engine/engine_io.h" +#include "user/user_api.h" + + + +// default model attributes +void mjs_defaultSpec(mjSpec* spec) { + memset(spec, 0, sizeof(mjSpec)); + + // default statistics + spec->stat.meaninertia = mjNAN; + spec->stat.meanmass = mjNAN; + spec->stat.meansize = mjNAN; + spec->stat.extent = mjNAN; + spec->stat.center[0] = mjNAN; + + // compiler settings + spec->autolimits = 1; + spec->settotalmass = -1; + spec->degree = 1; + spec->euler[0] = 'x'; + spec->euler[1] = 'y'; + spec->euler[2] = 'z'; + spec->convexhull = 1; + spec->usethread = 1; + spec->inertiafromgeom = mjINERTIAFROMGEOM_AUTO; + spec->inertiagrouprange[1] = mjNGROUP-1; + mj_defaultLROpt(&spec->LRopt); + + // engine data + mj_defaultOption(&spec->option); + mj_defaultVisual(&spec->visual); + spec->memory = -1; + spec->njmax = -1; + spec->nconmax = -1; + spec->nstack = -1; + + // user fields + spec->nuser_body = -1; + spec->nuser_jnt = -1; + spec->nuser_geom = -1; + spec->nuser_site = -1; + spec->nuser_cam = -1; + spec->nuser_tendon = -1; + spec->nuser_actuator = -1; + spec->nuser_sensor = -1; +} + + + +// default orientation attributes +void mjs_defaultOrientation(mjsOrientation* orient) { + memset(orient, 0, sizeof(mjsOrientation)); +} + + + +// default body attributes +void mjs_defaultBody(mjsBody* body) { + memset(body, 0, sizeof(mjsBody)); + + // body frame + body->pos[0] = mjNAN; + body->quat[0] = 1; + + // inertial frame + body->ipos[0] = mjNAN; + body->iquat[0] = 1; + body->fullinertia[0] = mjNAN; +} + + + +// default frame attributes +void mjs_defaultFrame(mjsFrame* frame) { + memset(frame, 0, sizeof(mjsFrame)); + frame->quat[0] = 1; +} + + + +// default joint attributes +void mjs_defaultJoint(mjsJoint* joint) { + memset(joint, 0, sizeof(mjsJoint)); + joint->type = mjJNT_HINGE; + joint->axis[2] = 1; + joint->limited = mjLIMITED_AUTO; + joint->actfrclimited = mjLIMITED_AUTO; + mj_defaultSolRefImp(joint->solref_limit, joint->solimp_limit); + mj_defaultSolRefImp(joint->solref_friction, joint->solimp_friction); + joint->urdfeffort = -1; +} + + + +// default geom attributes +void mjs_defaultGeom(mjsGeom* geom) { + memset(geom, 0, sizeof(mjsGeom)); + + // type + geom->type = mjGEOM_SPHERE; + + // frame + geom->quat[0] = 1; + geom->fromto[0] = mjNAN; + + // contact-related + geom->contype = 1; + geom->conaffinity = 1; + geom->condim = 3; + geom->friction[0] = 1; + geom->friction[1] = 0.005; + geom->friction[2] = 0.0001; + geom->solmix = 1.0; + mj_defaultSolRefImp(geom->solref, geom->solimp); + + // inertia-related + geom->mass = mjNAN; + geom->density = 1000; // water density (1000 Kg / m^3) + geom->typeinertia = mjINERTIA_VOLUME; + + // color + geom->rgba[0] = geom->rgba[1] = geom->rgba[2] = 0.5f; + geom->rgba[3] = 1.0f; + + // fluid forces + geom->fluid_coefs[0] = 0.5; // blunt drag + geom->fluid_coefs[1] = 0.25; // slender drag + geom->fluid_coefs[2] = 1.5; // angular drag + geom->fluid_coefs[3] = 1.0; // kutta lift + geom->fluid_coefs[4] = 1.0; // magnus lift + + // other + geom->fitscale = 1; +} + + + +// default site attributes +void mjs_defaultSite(mjsSite* site) { + memset(site, 0, sizeof(mjsSite)); + + // type + site->type = mjGEOM_SPHERE; + + // frame + site->quat[0] = 1; + site->size[0] = site->size[1] = site->size[2] = 0.005; + site->fromto[0] = mjNAN; + + // color + site->rgba[0] = site->rgba[1] = site->rgba[2] = 0.5f; + site->rgba[3] = 1.0f; +} + + + +// default cam attributes +void mjs_defaultCamera(mjsCamera* cam) { + memset(cam, 0, sizeof(mjsCamera)); + + // mode + cam->mode = mjCAMLIGHT_FIXED; + + // extrinsics + cam->quat[0] = 1; + + // intrinsics + cam->fovy = 45; + cam->ipd = 0.068; + cam->resolution[0] = cam->resolution[1] = 1; +} + + + +// default light attributes +void mjs_defaultLight(mjsLight* light) { + memset(light, 0, sizeof(mjsLight)); + + // mode + light->mode = mjCAMLIGHT_FIXED; + + // extrinsics + light->dir[2] = -1; + + // intrinsics + light->castshadow = 1; + light->bulbradius = 0.02; + light->active = 1; + light->attenuation[0] = 1; + light->cutoff = 45; + light->exponent = 10; + light->diffuse[0] = light->diffuse[1] = light->diffuse[2] = 0.7; + light->specular[0] = light->specular[1] = light->specular[2] = 0.3; +} + + + +// default flex attributes +void mjs_defaultFlex(mjsFlex* flex) { + memset(flex, 0, sizeof(mjsFlex)); + + // set contact defaults + flex->contype = 1; + flex->conaffinity = 1; + flex->condim = 3; + flex->friction[0] = 1; + flex->friction[1] = 0.005; + flex->friction[2] = 0.0001; + flex->solmix = 1.0; + mj_defaultSolRefImp(flex->solref, flex->solimp); + + // set other defaults + flex->dim = 2; + flex->radius = 0.005; + flex->internal = 1; + flex->selfcollide = mjFLEXSELF_AUTO; + flex->activelayers = 1; + flex->rgba[0] = flex->rgba[1] = flex->rgba[2] = 0.5f; + flex->rgba[3] = 1.0f; +} + + + +// default mesh attributes +void mjs_defaultMesh(mjsMesh* mesh) { + memset(mesh, 0, sizeof(mjsMesh)); + mesh->refquat[0] = 1; + mesh->scale[0] = mesh->scale[1] = mesh->scale[2] = 1; +} + + + +// default height field attributes +void mjs_defaultHField(mjsHField* hfield) { + memset(hfield, 0, sizeof(mjsHField)); +} + + + +// default skin attributes +void mjs_defaultSkin(mjsSkin* skin) { + memset(skin, 0, sizeof(mjsSkin)); + skin->rgba[0] = skin->rgba[1] = skin->rgba[2] = 0.5f; + skin->rgba[3] = 1.0f; +} + + + +// default texture attributes +void mjs_defaultTexture(mjsTexture* texture) { + memset(texture, 0, sizeof(mjsTexture)); + texture->type = mjTEXTURE_CUBE; + texture->rgb1[0] = texture->rgb1[1] = texture->rgb1[2] = 0.8; + texture->rgb2[0] = texture->rgb2[1] = texture->rgb2[2] = 0.5; + texture->random = 0.01; + texture->gridsize[0] = texture->gridsize[1] = 1; + char defaultlayout[sizeof(texture->gridlayout)] = "............"; + strncpy(texture->gridlayout, defaultlayout, sizeof(texture->gridlayout)); +} + + + +// default material attributes +void mjs_defaultMaterial(mjsMaterial* material) { + memset(material, 0, sizeof(mjsMaterial)); + material->texrepeat[0] = material->texrepeat[1] = 1; + material->specular = 0.5; + material->shininess = 0.5; + material->metallic = 1.; + material->roughness = 1.0; + material->rgba[0] = material->rgba[1] = material->rgba[2] = material->rgba[3] = 1; +} + + + +// default pair attributes +void mjs_defaultPair(mjsPair* pair) { + memset(pair, 0, sizeof(mjsPair)); + pair->condim = 3; + mj_defaultSolRefImp(pair->solref, pair->solimp); + pair->friction[0] = 1; + pair->friction[1] = 1; + pair->friction[2] = 0.005; + pair->friction[3] = 0.0001; + pair->friction[4] = 0.0001; +} + + + +// default equality attributes +void mjs_defaultEquality(mjsEquality* equality) { + memset(equality, 0, sizeof(mjsEquality)); + equality->type = mjEQ_CONNECT; + equality->active = 1; + mj_defaultSolRefImp(equality->solref, equality->solimp); + equality->data[1] = 1; + equality->data[10] = 1; // torque:force ratio +} + + + +// default tendon attributes +void mjs_defaultTendon(mjsTendon* tendon) { + memset(tendon, 0, sizeof(mjsTendon)); + tendon->limited = mjLIMITED_AUTO; + tendon->springlength[0] = tendon->springlength[1] = -1; + mj_defaultSolRefImp(tendon->solref_limit, tendon->solimp_limit); + mj_defaultSolRefImp(tendon->solref_friction, tendon->solimp_friction); + tendon->width = 0.003; + tendon->rgba[0] = tendon->rgba[1] = tendon->rgba[2] = 0.5f; + tendon->rgba[3] = 1.0f; +} + + + +// default actuator attributes +void mjs_defaultActuator(mjsActuator* actuator) { + memset(actuator, 0, sizeof(mjsActuator)); + + // gain, bias + actuator->gaintype = mjGAIN_FIXED; + actuator->gainprm[0] = 1; + actuator->biastype = mjBIAS_NONE; + + // activation state + actuator->dyntype = mjDYN_NONE; + actuator->dynprm[0] = 1; + actuator->actdim = -1; + + // transmission + actuator->trntype = mjTRN_UNDEFINED; + actuator->gear[0] = 1; + + // input/output clamping + actuator->ctrllimited = mjLIMITED_AUTO; + actuator->forcelimited = mjLIMITED_AUTO; + actuator->actlimited = mjLIMITED_AUTO; +} + + + +// default sensor attributes +void mjs_defaultSensor(mjsSensor* sensor) { + memset(sensor, 0, sizeof(mjsSensor)); + + sensor->type = mjSENS_TOUCH; + sensor->datatype = mjDATATYPE_REAL; + sensor->needstage = mjSTAGE_ACC; +} + + + +// Default numeric attributes. +void mjs_defaultNumeric(mjsNumeric* numeric) { + memset(numeric, 0, sizeof(mjsNumeric)); +} + + + +// Default text attributes. +void mjs_defaultText(mjsText* text) { + memset(text, 0, sizeof(mjsText)); +} + + + +// Default tuple attributes. +void mjs_defaultTuple(mjsTuple* tuple) { + memset(tuple, 0, sizeof(mjsTuple)); +} + + + +// Default keyframe attributes. +void mjs_defaultKey(mjsKey* key) { + memset(key, 0, sizeof(mjsKey)); +} + + + +// default plugin attributes +void mjs_defaultPlugin(mjsPlugin* plugin) { + memset(plugin, 0, sizeof(mjsPlugin)); + plugin->plugin_slot = -1; +} + diff --git a/src/user/user_init.cc b/src/user/user_init.cc deleted file mode 100644 index 73ab11b4..00000000 --- a/src/user/user_init.cc +++ /dev/null @@ -1,425 +0,0 @@ -// 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. - -#include -#include -#include -#include "cc/array_safety.h" -#include "user/user_api.h" -#include "user/user_util.h" - - - -// default model attributes -void mjs_defaultSpec(mjSpec& model) { - memset(&model, 0, sizeof(mjSpec)); - - // default statistics - model.stat.meaninertia = mjNAN; - model.stat.meanmass = mjNAN; - model.stat.meansize = mjNAN; - model.stat.extent = mjNAN; - model.stat.center[0] = mjNAN; - - // compiler settings - model.autolimits = true; - model.boundmass = 0; - model.boundinertia = 0; - model.settotalmass = -1; - model.balanceinertia = false; - model.strippath = false; - model.fitaabb = false; - model.degree = true; - model.euler[0] = 'x'; - model.euler[1] = 'y'; - model.euler[2] = 'z'; - model.discardvisual = false; - model.convexhull = true; - model.usethread = true; - model.fusestatic = false; - model.inertiafromgeom = mjINERTIAFROMGEOM_AUTO; - model.inertiagrouprange[0] = 0; - model.inertiagrouprange[1] = mjNGROUP-1; - model.exactmeshinertia = false; - mj_defaultLROpt(&model.LRopt); - - // engine data - mj_defaultOption(&model.option); - mj_defaultVisual(&model.visual); - model.memory = -1; - model.nemax = 0; - model.njmax = -1; - model.nconmax = -1; - model.nstack = -1; - model.nuserdata = 0; - model.nuser_body = -1; - model.nuser_jnt = -1; - model.nuser_geom = -1; - model.nuser_site = -1; - model.nuser_cam = -1; - model.nuser_tendon = -1; - model.nuser_actuator = -1; - model.nuser_sensor = -1; -} - - - -// default orientation attributes -void mjs_defaultOrientation(mjsOrientation& orient) { - memset(&orient, 0, sizeof(mjsOrientation)); -} - - - -// default body attributes -void mjs_defaultBody(mjsBody& body) { - memset(&body, 0, sizeof(mjsBody)); - - // body frame - body.pos[0] = mjNAN; - body.quat[0] = 1; - mjs_defaultOrientation(body.alt); - - // inertial frame - body.ipos[0] = mjNAN; - body.iquat[0] = 1; - mjs_defaultOrientation(body.ialt); - body.fullinertia[0] = mjNAN; -} - - - -// default frame attributes -void mjs_defaultFrame(mjsFrame& frame) { - memset(&frame, 0, sizeof(mjsFrame)); - mju_zero3(frame.pos); - mjuu_setvec(frame.quat, 1, 0, 0, 0); - mjs_defaultOrientation(frame.alt); -} - - - -// default joint attributes -void mjs_defaultJoint(mjsJoint& joint) { - memset(&joint, 0, sizeof(mjsJoint)); - - joint.type = mjJNT_HINGE; - joint.axis[2] = 1; - joint.limited = mjLIMITED_AUTO; - joint.actfrclimited = mjLIMITED_AUTO; - mj_defaultSolRefImp(joint.solref_limit, joint.solimp_limit); - mj_defaultSolRefImp(joint.solref_friction, joint.solimp_friction); - joint.urdfeffort = -1; -} - - - -// default geom attributes -void mjs_defaultGeom(mjsGeom& geom) { - memset(&geom, 0, sizeof(mjsGeom)); - - // type - geom.type = mjGEOM_SPHERE; - - // frame - geom.quat[0] = 1; - geom.fromto[0] = mjNAN; - mjs_defaultOrientation(geom.alt); - - // contact-related - geom.contype = 1; - geom.conaffinity = 1; - geom.condim = 3; - geom.friction[0] = 1; - geom.friction[1] = 0.005; - geom.friction[2] = 0.0001; - geom.solmix = 1.0; - mj_defaultSolRefImp(geom.solref, geom.solimp); - - // inertia-related - geom.mass = mjNAN; - geom.density = 1000; // water density (1000 Kg / m^3) - geom.typeinertia = mjINERTIA_VOLUME; - - // color - geom.rgba[0] = geom.rgba[1] = geom.rgba[2] = 0.5f; - geom.rgba[3] = 1.0f; - - // fluid forces - geom.fluid_coefs[0] = 0.5; // blunt drag - geom.fluid_coefs[1] = 0.25; // slender drag - geom.fluid_coefs[2] = 1.5; // angular drag - geom.fluid_coefs[3] = 1.0; // kutta lift - geom.fluid_coefs[4] = 1.0; // magnus lift - - // other - geom.fitscale = 1; -} - - - -// default site attributes -void mjs_defaultSite(mjsSite& site) { - // set everything to 0 / false / NULL - memset(&site, 0, sizeof(mjsSite)); - - // type - site.type = mjGEOM_SPHERE; - - // frame - site.quat[0] = 1; - site.size[0] = site.size[1] = site.size[2] = 0.005; - site.fromto[0] = mjNAN; - mjs_defaultOrientation(site.alt); - - // color - site.rgba[0] = site.rgba[1] = site.rgba[2] = 0.5f; - site.rgba[3] = 1.0f; -} - - - -// default cam attributes -void mjs_defaultCamera(mjsCamera& cam) { - memset(&cam, 0, sizeof(mjsCamera)); - - // type - cam.mode = mjCAMLIGHT_FIXED; - - // extrinsics - cam.quat[0] = 1; - mjs_defaultOrientation(cam.alt); - - // intrinsics - cam.fovy = 45; - cam.ipd = 0.068; - cam.resolution[0] = cam.resolution[1] = 1; -} - - - -// default light attributes -void mjs_defaultLight(mjsLight& light) { - memset(&light, 0, sizeof(mjsLight)); - - // mode - light.mode = mjCAMLIGHT_FIXED; - - // intrinsics - light.castshadow = 1; - light.bulbradius = 0.02; - light.active = 1; - light.dir[2] = -1; - light.attenuation[0] = 1; - light.cutoff = 45; - light.exponent = 10; - light.diffuse[0] = light.diffuse[1] = light.diffuse[2] = 0.7; - light.specular[0] = light.specular[1] = light.specular[2] = 0.3; -} - - - -// default flex attributes -void mjs_defaultFlex(mjsFlex& flex) { - memset(&flex, 0, sizeof(mjsFlex)); - - // set contact defaults - flex.contype = 1; - flex.conaffinity = 1; - flex.condim = 3; - mjuu_setvec(flex.friction, 1, 0.005, 0.0001); - flex.solmix = 1.0; - mj_defaultSolRefImp(flex.solref, flex.solimp); - - // set other defaults - flex.dim = 2; - flex.radius = 0.005; - flex.internal = true; - flex.selfcollide = mjFLEXSELF_AUTO; - flex.activelayers = 1; - flex.rgba[0] = flex.rgba[1] = flex.rgba[2] = 0.5f; - flex.rgba[3] = 1.0f; -} - - - -// default mesh attributes -void mjs_defaultMesh(mjsMesh& mesh) { - memset(&mesh, 0, sizeof(mjsMesh)); - mjuu_setvec(mesh.refpos, 0, 0, 0); - mjuu_setvec(mesh.refquat, 1, 0, 0, 0); - mjuu_setvec(mesh.scale, 1, 1, 1); - mesh.smoothnormal = false; -} - - - -// default height field attributes -void mjs_defaultHField(mjsHField& hfield) { - memset(&hfield, 0, sizeof(mjsHField)); -} - - - -// default skin attributes -void mjs_defaultSkin(mjsSkin& skin) { - memset(&skin, 0, sizeof(mjsSkin)); - skin.rgba[0] = skin.rgba[1] = skin.rgba[2] = 0.5f; - skin.rgba[3] = 1.0f; - skin.inflate = 0; - skin.group = 0; -} - - - -// default texture attributes -void mjs_defaultTexture(mjsTexture& texture) { - memset(&texture, 0, sizeof(mjsTexture)); - texture.type = mjTEXTURE_CUBE; - mjuu_setvec(texture.rgb1, 0.8, 0.8, 0.8); - mjuu_setvec(texture.rgb2, 0.5, 0.5, 0.5); - mjuu_setvec(texture.markrgb, 0, 0, 0); - texture.random = 0.01; - texture.gridsize[0] = texture.gridsize[1] = 1; - mujoco::util::strcpy_arr(texture.gridlayout, "............"); -} - - - -// default material attributes -void mjs_defaultMaterial(mjsMaterial& material) { - memset(&material, 0, sizeof(mjsMaterial)); - material.texuniform = false; - material.texrepeat[0] = material.texrepeat[1] = 1; - material.emission = 0; - material.specular = 0.5; - material.shininess = 0.5; - material.reflectance = 0; - material.metallic = 1.0; - material.roughness = 1.0; - material.rgba[0] = material.rgba[1] = material.rgba[2] = material.rgba[3] = 1; -} - - - -// default pair attributes -void mjs_defaultPair(mjsPair& pair) { - memset(&pair, 0, sizeof(mjsPair)); - pair.condim = 3; - mj_defaultSolRefImp(pair.solref, pair.solimp); - pair.friction[0] = 1; - pair.friction[1] = 1; - pair.friction[2] = 0.005; - pair.friction[3] = 0.0001; - pair.friction[4] = 0.0001; -} - - - -// default equality attributes -void mjs_defaultEquality(mjsEquality& equality) { - memset(&equality, 0, sizeof(mjsEquality)); - equality.type = mjEQ_CONNECT; - equality.active = 1; - mj_defaultSolRefImp(equality.solref, equality.solimp); - equality.data[1] = 1; - equality.data[10] = 1; // torque:force ratio -} - - - -// default tendon attributes -void mjs_defaultTendon(mjsTendon& tendon) { - memset(&tendon, 0, sizeof(mjsTendon)); - tendon.limited = mjLIMITED_AUTO; - tendon.springlength[0] = tendon.springlength[1] = -1; - mj_defaultSolRefImp(tendon.solref_limit, tendon.solimp_limit); - mj_defaultSolRefImp(tendon.solref_friction, tendon.solimp_friction); - tendon.width = 0.003; - tendon.rgba[0] = tendon.rgba[1] = tendon.rgba[2] = 0.5f; - tendon.rgba[3] = 1.0f; -} - - - -// default actuator attributes -void mjs_defaultActuator(mjsActuator& actuator) { - memset(&actuator, 0, sizeof(mjsActuator)); - - // gain, bias - actuator.gaintype = mjGAIN_FIXED; - actuator.gainprm[0] = 1; - actuator.biastype = mjBIAS_NONE; - - // activation state - actuator.dyntype = mjDYN_NONE; - actuator.dynprm[0] = 1; - actuator.actdim = -1; - - // transmission - actuator.trntype = mjTRN_UNDEFINED; - actuator.gear[0] = 1; - - // input/output clamping - actuator.ctrllimited = mjLIMITED_AUTO; - actuator.forcelimited = mjLIMITED_AUTO; - actuator.actlimited = mjLIMITED_AUTO; -} - - - -// default sensor attributes -void mjs_defaultSensor(mjsSensor& sensor) { - memset(&sensor, 0, sizeof(mjsSensor)); - sensor.type = mjSENS_TOUCH; - sensor.datatype = mjDATATYPE_REAL; - sensor.needstage = mjSTAGE_ACC; -} - - - -// Default numeric attributes. -void mjs_defaultNumeric(mjsNumeric& numeric) { - memset(&numeric, 0, sizeof(mjsNumeric)); -} - - - -// Default text attributes. -void mjs_defaultText(mjsText& text) { - memset(&text, 0, sizeof(mjsText)); -} - - - -// Default tuple attributes. -void mjs_defaultTuple(mjsTuple& tuple) { - memset(&tuple, 0, sizeof(mjsTuple)); -} - - - -// Default keyframe attributes. -void mjs_defaultKey(mjsKey& key) { - memset(&key, 0, sizeof(mjsKey)); -} - - - -// default plugin attributes -void mjs_defaultPlugin(mjsPlugin& plugin) { - memset(&plugin, 0, sizeof(mjsPlugin)); - plugin.plugin_slot = -1; -} - diff --git a/src/user/user_mesh.cc b/src/user/user_mesh.cc index ed2f7d72..00103c73 100644 --- a/src/user/user_mesh.cc +++ b/src/user/user_mesh.cc @@ -131,7 +131,7 @@ static void ReadFromBuffer(T* dst, const char* src) { //------------------ class mjCMesh implementation -------------------------------------------------- mjCMesh::mjCMesh(mjCModel* _model, mjCDef* _def) { - mjs_defaultMesh(spec); + mjs_defaultMesh(&spec); elemtype = mjOBJ_MESH; // clear internal variables @@ -2059,7 +2059,7 @@ void mjCMesh::MakeCenter(void) { // constructor mjCSkin::mjCSkin(mjCModel* _model) { - mjs_defaultSkin(spec); + mjs_defaultSkin(&spec); elemtype = mjOBJ_SKIN; // set model pointer @@ -2484,7 +2484,7 @@ constexpr int eledge[3][6][2] = {{{ 0, 1}, {-1, -1}, {-1, -1}, // constructor mjCFlex::mjCFlex(mjCModel* _model) { - mjs_defaultFlex(spec); + mjs_defaultFlex(&spec); elemtype = mjOBJ_FLEX; // set model diff --git a/src/user/user_model.cc b/src/user/user_model.cc index 6c1e547c..e8a3791e 100644 --- a/src/user/user_model.cc +++ b/src/user/user_model.cc @@ -83,7 +83,7 @@ static void copyvec(T1* dest, T2* src, int n) { // constructor mjCModel::mjCModel() { - mjs_defaultSpec(spec); + mjs_defaultSpec(&spec); elemtype = mjOBJ_UNKNOWN; spec_comment_.clear(); spec_modelfiledir_.clear(); diff --git a/src/user/user_objects.cc b/src/user/user_objects.cc index 35db7cbd..636b4921 100644 --- a/src/user/user_objects.cc +++ b/src/user/user_objects.cc @@ -474,18 +474,18 @@ mjCDef::mjCDef(void) { name.clear(); parentid = -1; childid.clear(); - mjs_defaultJoint(joint.spec); - mjs_defaultGeom(geom.spec); - mjs_defaultSite(site.spec); - mjs_defaultCamera(camera.spec); - mjs_defaultLight(light.spec); - mjs_defaultFlex(flex.spec); - mjs_defaultMesh(mesh.spec); - mjs_defaultMaterial(material.spec); - mjs_defaultPair(pair.spec); - mjs_defaultEquality(equality.spec); - mjs_defaultTendon(tendon.spec); - mjs_defaultActuator(actuator.spec); + mjs_defaultJoint(&joint.spec); + mjs_defaultGeom(&geom.spec); + mjs_defaultSite(&site.spec); + mjs_defaultCamera(&camera.spec); + mjs_defaultLight(&light.spec); + mjs_defaultFlex(&flex.spec); + mjs_defaultMesh(&mesh.spec); + mjs_defaultMaterial(&material.spec); + mjs_defaultPair(&pair.spec); + mjs_defaultEquality(&equality.spec); + mjs_defaultTendon(&tendon.spec); + mjs_defaultActuator(&actuator.spec); // make sure all the pointers are local PointToLocal(); @@ -675,7 +675,7 @@ mjCBody::mjCBody(mjCModel* _model) { // set model pointer model = _model; - mjs_defaultBody(spec); + mjs_defaultBody(&spec); elemtype = mjOBJ_BODY; parentid = -1; weldid = -1; @@ -1451,7 +1451,7 @@ void mjCBody::Compile(void) { // initialize frame mjCFrame::mjCFrame(mjCModel* _model, mjCFrame* _frame) { - mjs_defaultFrame(spec); + mjs_defaultFrame(&spec); elemtype = mjOBJ_FRAME; compiled = false; model = _model; @@ -1568,7 +1568,7 @@ void mjCFrame::Compile() { // initialize default joint mjCJoint::mjCJoint(mjCModel* _model, mjCDef* _def) { - mjs_defaultJoint(spec); + mjs_defaultJoint(&spec); elemtype = mjOBJ_JOINT; // clear internal variables @@ -1758,7 +1758,7 @@ int mjCJoint::Compile(void) { // initialize default geom mjCGeom::mjCGeom(mjCModel* _model, mjCDef* _def) { - mjs_defaultGeom(spec); + mjs_defaultGeom(&spec); elemtype = mjOBJ_GEOM; mass_ = 0; @@ -2405,7 +2405,7 @@ void mjCGeom::Compile(void) { // initialize default site mjCSite::mjCSite(mjCModel* _model, mjCDef* _def) { - mjs_defaultSite(spec); + mjs_defaultSite(&spec); elemtype = mjOBJ_SITE; // clear internal variables @@ -2558,7 +2558,7 @@ void mjCSite::Compile(void) { // initialize defaults mjCCamera::mjCCamera(mjCModel* _model, mjCDef* _def) { - mjs_defaultCamera(spec); + mjs_defaultCamera(&spec); elemtype = mjOBJ_CAMERA; // clear private variables @@ -2712,7 +2712,7 @@ void mjCCamera::Compile(void) { // initialize defaults mjCLight::mjCLight(mjCModel* _model, mjCDef* _def) { - mjs_defaultLight(spec); + mjs_defaultLight(&spec); elemtype = mjOBJ_LIGHT; // clear private variables @@ -2815,7 +2815,7 @@ void mjCLight::Compile(void) { // constructor mjCHField::mjCHField(mjCModel* _model) { - mjs_defaultHField(spec); + mjs_defaultHField(&spec); elemtype = mjOBJ_HFIELD; // set model pointer @@ -3066,7 +3066,7 @@ void mjCHField::Compile(const mjVFS* vfs) { // initialize defaults mjCTexture::mjCTexture(mjCModel* _model) { - mjs_defaultTexture(spec); + mjs_defaultTexture(&spec); elemtype = mjOBJ_TEXTURE; // set model pointer @@ -3797,7 +3797,7 @@ void mjCTexture::Compile(const mjVFS* vfs) { // initialize defaults mjCMaterial::mjCMaterial(mjCModel* _model, mjCDef* _def) { - mjs_defaultMaterial(spec); + mjs_defaultMaterial(&spec); elemtype = mjOBJ_MATERIAL; // clear internal @@ -3880,7 +3880,7 @@ void mjCMaterial::Compile(void) { // constructor mjCPair::mjCPair(mjCModel* _model, mjCDef* _def) { - mjs_defaultPair(spec); + mjs_defaultPair(&spec); elemtype = mjOBJ_PAIR; // set defaults @@ -4245,7 +4245,7 @@ void mjCBodyPair::Compile(void) { // initialize default constraint mjCEquality::mjCEquality(mjCModel* _model, mjCDef* _def) { - mjs_defaultEquality(spec); + mjs_defaultEquality(&spec); elemtype = mjOBJ_EQUALITY; // clear internal variables @@ -4406,7 +4406,7 @@ void mjCEquality::Compile(void) { // constructor mjCTendon::mjCTendon(mjCModel* _model, mjCDef* _def) { - mjs_defaultTendon(spec); + mjs_defaultTendon(&spec); elemtype = mjOBJ_TENDON; // clear internal variables @@ -4883,7 +4883,7 @@ void mjCWrap::ResolveReferences(const mjCModel* m) { // initialize defaults mjCActuator::mjCActuator(mjCModel* _model, mjCDef* _def) { - mjs_defaultActuator(spec); + mjs_defaultActuator(&spec); elemtype = mjOBJ_ACTUATOR; // clear private variables @@ -5226,7 +5226,7 @@ void mjCActuator::Compile(void) { // initialize defaults mjCSensor::mjCSensor(mjCModel* _model) { - mjs_defaultSensor(spec); + mjs_defaultSensor(&spec); elemtype = mjOBJ_SENSOR; // set model @@ -5708,7 +5708,7 @@ void mjCSensor::Compile(void) { // constructor mjCNumeric::mjCNumeric(mjCModel* _model) { - mjs_defaultNumeric(spec); + mjs_defaultNumeric(&spec); elemtype = mjOBJ_NUMERIC; // set model pointer @@ -5797,7 +5797,7 @@ void mjCNumeric::Compile(void) { // constructor mjCText::mjCText(mjCModel* _model) { - mjs_defaultText(spec); + mjs_defaultText(&spec); elemtype = mjOBJ_TEXT; // set model pointer @@ -5874,7 +5874,7 @@ void mjCText::Compile(void) { // constructor mjCTuple::mjCTuple(mjCModel* _model) { - mjs_defaultTuple(spec); + mjs_defaultTuple(&spec); elemtype = mjOBJ_TUPLE; // set model pointer @@ -6007,7 +6007,7 @@ void mjCTuple::Compile(void) { // constructor mjCKey::mjCKey(mjCModel* _model) { - mjs_defaultKey(spec); + mjs_defaultKey(&spec); elemtype = mjOBJ_KEY; // set model pointer @@ -6191,7 +6191,7 @@ mjCPlugin::mjCPlugin(mjCModel* _model) { instance_name.clear(); // public interface - mjs_defaultPlugin(spec); + mjs_defaultPlugin(&spec); elemtype = mjOBJ_PLUGIN; spec.name = (mjString)&name; spec.instance_name = (mjString)&instance_name; diff --git a/src/user/user_util.cc b/src/user/user_util.cc index 35e5568d..a2a91ee9 100644 --- a/src/user/user_util.cc +++ b/src/user/user_util.cc @@ -33,10 +33,6 @@ using std::string; using std::numeric_limits; -// set value of NAN here; needs -const double mjNAN = numeric_limits::quiet_NaN(); - - // check if numeric variable is defined bool mjuu_defined(const double num) { return !isnan(num); diff --git a/src/user/user_util.h b/src/user/user_util.h index 2cede571..29ff5dd8 100644 --- a/src/user/user_util.h +++ b/src/user/user_util.h @@ -20,7 +20,6 @@ #include -extern const double mjNAN; // used to mark undefined fields const double mjEPS = 1E-14; // minimum value in various calculations const double mjMINMASS = 1E-6; // minimum mass allowed diff --git a/src/xml/xml_native_reader.cc b/src/xml/xml_native_reader.cc index 1c742a45..1a12d3d8 100644 --- a/src/xml/xml_native_reader.cc +++ b/src/xml/xml_native_reader.cc @@ -3394,7 +3394,7 @@ void mjXReader::Body(XMLElement* section, mjsBody* pbody, mjsFrame* frame) { // store rotation difference mjsOrientation alt; - mjs_defaultOrientation(alt); + mjs_defaultOrientation(&alt); alt.type = mjORIENTATION_EULER; mjuu_copyvec(alt.euler, euler, 3); double rotation[4] = {1, 0, 0, 0}; diff --git a/src/xml/xml_urdf.cc b/src/xml/xml_urdf.cc index 30739848..e7d281ce 100644 --- a/src/xml/xml_urdf.cc +++ b/src/xml/xml_urdf.cc @@ -633,7 +633,7 @@ void mjXURDF::Origin(XMLElement* origin_elem, double* pos, double* quat) { // orientation mjsOrientation alt; - mjs_defaultOrientation(alt); + mjs_defaultOrientation(&alt); if (ReadAttr(temp, "rpy", 3, alt.euler, text)) { alt.type = mjORIENTATION_EULER; mjs_resolveOrientation(quat, 0, "XYZ", &alt);