Skip to content

Commit

Permalink
Merge pull request #2185 from cyberbotics/fix.uneven-terrain-size
Browse files Browse the repository at this point in the history
Fix UnevenTerrain Size
  • Loading branch information
DavidMansolino committed Sep 1, 2020
2 parents 67457b7 + cb03c91 commit de32005
Show file tree
Hide file tree
Showing 7 changed files with 29 additions and 29 deletions.
2 changes: 2 additions & 0 deletions docs/reference/changelog-r2020.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ Released on September 1st, 2020.
- Fixed crash when inserting an empty [PointSet](pointset.md) node ([#2182](https://github.com/cyberbotics/webots/pull/2182)).
- Fixed crash occurring when selecting a [Robot](robot.md) with mechanical closed-loop ([#2117](https://github.com/cyberbotics/webots/pull/2117)).
- Fixed various issues when an extern [Robot](robot.md) controller exits and then a new one connects to the same [Robot](robot.md) ([#2152](https://github.com/cyberbotics/webots/pull/2152)).
- Fixed size of the [UnevenTerrain](../guide/object-floors.md#uneventerrain) PROTO node ([#2185](https://github.com/cyberbotics/webots/pull/2185)).
- Fixed texture mapping of the [ElevationGrid](elevationgrid.md) node ([#2185](https://github.com/cyberbotics/webots/pull/2185)).
- macOS: Fixed crash of the `animated_skin` simulation ([#2141](https://github.com/cyberbotics/webots/pull/2141)).
- Remove scaling factor in matrix returned by [`wb_supervisor_node_get_orientation`](supervisor.md#wb_supervisor_node_get_orientation) ([#2112](https://github.com/cyberbotics/webots/pull/2112)).
- Fixed conversion of identity matrix to quaternion in ROS API ([#2112](https://github.com/cyberbotics/webots/pull/2112)).
Expand Down
14 changes: 12 additions & 2 deletions projects/objects/floors/protos/UnevenTerrain.proto
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,18 @@ PROTO UnevenTerrain [
local nOctave = fields.perlinNOctaves.value

local size = fields.size.value

local xDimension = fields.xDimension.value
if xDimension < 2 then
xDimension = fields.xDimension.defaultValue
io.stderr:write("'xDimension' should be at least equalt to 2.\n")
end

local zDimension = fields.zDimension.value
if zDimension < 2 then
zDimension = fields.zDimension.defaultValue
io.stderr:write("'zDimension' should be at least equalt to 2.\n")
end
}%
Solid {
translation IS translation
Expand All @@ -96,9 +106,9 @@ PROTO UnevenTerrain [
geometry ElevationGrid {
%{ if xDimension > 2 and zDimension > 2 then }%
xDimension IS xDimension
xSpacing %{= size.x / xDimension }%
xSpacing %{= size.x / (xDimension - 1) }%
zDimension IS zDimension
zSpacing %{= size.z / zDimension }%
zSpacing %{= size.z / (zDimension - 1) }%

height [
%{ for i=0, xDimension - 1 do }%
Expand Down
2 changes: 1 addition & 1 deletion projects/robots/micromagic/mantis/worlds/mantis.wbt
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,6 @@ UnevenTerrain {
perlinNOctaves 8
}
Mantis {
translation -24.12 61.31 -6.15
translation -24.12 61.42 -6.15
rotation 0 1 0 1.3
}
2 changes: 1 addition & 1 deletion projects/robots/sphero/bb8/worlds/bb-8.wbt
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ UnevenTerrain {
perlinNOctaves 6
}
BB-8 {
translation -16.19 36.5 -4.36
translation -16.19 36.68 -4.36
rotation 0 1 0 5.75959
headSlot [
Camera {
Expand Down
24 changes: 6 additions & 18 deletions projects/samples/demos/worlds/anaglyph.wbt
Original file line number Diff line number Diff line change
Expand Up @@ -26,16 +26,10 @@ DEF GROUND Solid {
translation -8 0 -8
children [
Shape {
appearance PBRAppearance {
baseColorMap ImageTexture {
url [
"textures/grass.jpg"
]
}
roughness 1
metalness 0
appearance Grass {
type "mossy"
textureTransform TextureTransform {
scale 10 10
scale 8.5 8.5
}
}
geometry ElevationGrid {
Expand All @@ -49,16 +43,10 @@ DEF GROUND Solid {
]
}
Shape {
appearance PBRAppearance {
baseColorMap ImageTexture {
url [
"textures/grass.jpg"
]
}
roughness 1
metalness 0
appearance Grass {
type "mossy"
textureTransform TextureTransform {
scale 50 50
scale 250 250
}
}
geometry Plane {
Expand Down
10 changes: 5 additions & 5 deletions src/webots/nodes/WbElevationGrid.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -482,15 +482,15 @@ bool WbElevationGrid::isAValidBoundingObject(bool checkOde, bool warning) const

bool WbElevationGrid::pickUVCoordinate(WbVector2 &uv, const WbRay &ray, int textureCoordSet) const {
WbVector3 localCollisionPoint;
double collisionDistance = computeLocalCollisionPoint(ray, localCollisionPoint);
const double collisionDistance = computeLocalCollisionPoint(ray, localCollisionPoint);
if (collisionDistance < 0)
return false;

double sizeX = scaledWidth();
double sizeZ = scaledDepth();
const double sizeX = scaledWidth();
const double sizeZ = scaledDepth();

double u = (double)localCollisionPoint.x() / sizeX;
double v = 1 - (double)localCollisionPoint.z() / sizeZ;
const double u = (double)localCollisionPoint.x() / sizeX;
const double v = (double)localCollisionPoint.z() / sizeZ;

// result
uv.setXy(u, v);
Expand Down
4 changes: 2 additions & 2 deletions src/wren/StaticMesh.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -623,8 +623,8 @@ namespace wren {
for (int zi = 0; zi < dimensionZ; ++zi) {
for (int xi = 0; xi < dimensionX; ++xi) {
mesh->addCoord(glm::vec3(spacingX * xi, heightData[dimensionX * zi + xi], spacingZ * zi));
mesh->addTexCoord(glm::vec2(du * xi, dv * (stepsZ - zi)));
mesh->addUnwrappedTexCoord(glm::vec2(du * xi, dv * (stepsZ - zi)));
mesh->addTexCoord(glm::vec2(du * xi, dv * zi));
mesh->addUnwrappedTexCoord(glm::vec2(du * xi, dv * zi));
}
}

Expand Down

0 comments on commit de32005

Please sign in to comment.