Skip to content

HeightMap : Collision and Visual Aspect mismatch #1658

@ibrahiminfinite

Description

@ibrahiminfinite

Environment

Select the following information.

  • DART version: 6.13.0
  • OS name and version name(or number): Ubuntu 20.04
  • Compiler name and version number: gcc version 9.4.0 (Ubuntu 9.4.0-1ubuntu1~20.04)

Description

Collision Engine used : ODE

When creating a heightmap of a given size , the visual and collision aspects are not aligned as one would expect.
Below is an image with a HeightMapShape (blue) of width = depth = 2, and a BoxShape (Green) with width = depth = 2 and balls spaced at even distance dropped on them.(Gravity is enabled and the balls are in contact with the surface)
The BoxShape is translated by 1 unit in the -z direction

Expected behaviour would be ,visual and collision aspect of heightmap should be aligned.

image

image

The observed result is as seen, the visual aspect seem to be translated with respect to the collision aspect for the heightmap.

This is the code for my HeightMap

/*
  "heightmap" :
  {
    "origin" : [0.0, 0.0, 0.0],
    "width" : 2.0,
    "depth" : 2.0,
    "minZ" : 0.0,
    "maxZ" : 0.0,
    "scale" : 2.0
  }
*/


struct TerrainConfig
{
    Eigen::Vector3f terrain_origin;
    float tWidth;
    float tDepth;
    float minZ;
    float maxZ;
    float tScale;
};

dynamics::SkeletonPtr createHeightMap(TerrainConfig& tConfig)
{

    dynamics::SkeletonPtr terrainSkel = dynamics::Skeleton::create("terrain");

    dynamics::BodyNodePtr terrainBody
            = terrainSkel->createJointAndBodyNodePair<dynamics::WeldJoint>(nullptr)
                    .second;

    Eigen::Isometry3d tf_trans = Eigen::Isometry3d::Identity();
    tf_trans.translation() = Eigen::Vector3d{tConfig.terrain_origin[0],tConfig.terrain_origin[1],
                                             tConfig.terrain_origin[2]};
    terrainBody->getParentJoint()->setTransformFromParentBodyNode(tf_trans);

    auto terrainShape = std::make_shared<dynamics::HeightmapShape<float>>();
    std::vector<float> heights{} ;
    for(auto i=0; i < tConfig.tWidth * tConfig.tDepth ; i++)
    {
        heights.emplace_back(math::Random::uniform(tConfig.minZ, tConfig.maxZ));
    }
    std::cout<< "HEIGHTS " << heights.size();
    terrainShape->setHeightField(tConfig.tWidth, tConfig.tDepth, heights);
    terrainShape->setScale(Eigen::Vector3f(tConfig.tScale, tConfig.tScale, 1.0));


    terrainBody->createShapeNodeWith<
            dynamics::CollisionAspect,
            dynamics::DynamicsAspect,
            dynamics::VisualAspect>(terrainShape);

    return terrainSkel;

}

I am not sure if this is really a bug , or if it is just me doing something wrong here.
Would be great if someone with expertise on the matter could guide me with this.

Thanks in advance.

Metadata

Metadata

Assignees

No one assigned

    Labels

    help wantedIndicates wanting help on an issue or pull requesttype: bugIndicates an unexpected problem or unintended behavior

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions