def generate_xinit()

in mujoco_worldgen/objs/obj.py [0:0]


    def generate_xinit(self):
        # MuJoCo uses center of geom as origin, while we use bottom corner
        if not self.placeable:
            return {}
        position = self.absolute_position
        position_xinit = {}
        # extracts names of three top level slide joints from
        # the body.
        for body in self.xml_dict["worldbody"]["body"]:
            for jnt in body.get("joint", []):
                if jnt["@type"] == "slide":
                    idx = get_axis_index(jnt["@axis"])
                    position_xinit[jnt["@name"]] = position[idx]
        # Some people add transforms which remove joints.
        # Only generate xinit terms for joints that remain
        xinit = {}
        for body in self.xml_dict["worldbody"]["body"]:
            for joint in body.get('joint', []):
                joint_name = joint.get('@name', '')
                if joint_name in position_xinit:
                    xinit[joint_name] = position_xinit[joint_name]

        if hasattr(self, "default_qpos") and self.default_qpos is not None:
            for joint, value in self.default_qpos.items():
                if not joint.startswith(self.name + ':'):
                    joint = self.name + ":" + joint
                xinit[joint] = value
        return xinit