LandscapeEditorDrawSystem::eErrorType LandscapeEditorDrawSystem::Init() { if (!heightmapProxy) { Heightmap* heightmap = baseLandscape->GetHeightmap(); if (heightmap == NULL || heightmap->Size() == 0) { return LANDSCAPE_EDITOR_SYSTEM_HEIGHTMAP_ABSENT; } heightmapProxy = new HeightmapProxy(baseLandscape->GetHeightmap()->Clone(NULL)); } if (!customColorsProxy) { customColorsProxy = new CustomColorsProxy((int32)GetTextureSize(Landscape::TEXTURE_TILE_FULL)); } if (!visibilityToolProxy) { visibilityToolProxy = new VisibilityToolProxy((int32)GetTextureSize(Landscape::TEXTURE_TILE_FULL)); } if (!rulerToolProxy) { rulerToolProxy = new RulerToolProxy((int32)GetTextureSize(Landscape::TEXTURE_TILE_FULL)); } return LANDSCAPE_EDITOR_SYSTEM_NO_ERRORS; }
float32 LandscapeEditorDrawSystem::GetHeightAtPoint(const Vector2& point) { Heightmap *heightmap = GetHeightmapProxy(); int32 x = (int32)point.x; int32 y = (int32)point.y; DVASSERT_MSG((x >= 0 && x < heightmap->Size()) && (y >= 0 && y < heightmap->Size()), "Point must be in heightmap coordinates"); int32 index = x + y * heightmap->Size(); float32 height = heightmap->Data()[index]; float32 maxHeight = GetLandscapeMaxHeight(); height *= maxHeight; height /= Heightmap::MAX_VALUE; return height; }
void LandscapeEditorHeightmap::UpdateHeightmap(const Rect &updatedRect) { Heightmap *heightmap = landscapesController->GetCurrentHeightmap(); Rect clippedRect; clippedRect.x = (float32)Clamp((int32)updatedRect.x, 0, heightmap->Size()-1); clippedRect.y = (float32)Clamp((int32)updatedRect.y, 0, heightmap->Size()-1); clippedRect.dx = Clamp((updatedRect.x + updatedRect.dx), 0.f, (float32)heightmap->Size() - 1.f) - clippedRect.x; clippedRect.dy = Clamp((updatedRect.y + updatedRect.dy), 0.f, (float32)heightmap->Size() - 1.f) - clippedRect.y; if(heightmapNode) { heightmapNode->UpdateHeightmapRect(clippedRect); } landscapesController->HeghtWasChanged(clippedRect); }
bool SceneValidator::ValidateHeightmapPathname(const FilePath &pathForValidation, Set<String> &errorsLog) { DVASSERT_MSG(!pathForChecking.IsEmpty(), "Need to set pathname for DataSource folder"); bool pathIsCorrect = IsPathCorrectForProject(pathForValidation); if(pathIsCorrect) { String::size_type posPng = pathForValidation.GetAbsolutePathname().find(".png"); String::size_type posHeightmap = pathForValidation.GetAbsolutePathname().find(Heightmap::FileExtension()); pathIsCorrect = ((String::npos != posPng) || (String::npos != posHeightmap)); if(!pathIsCorrect) { errorsLog.insert(Format("Heightmap path %s is wrong", pathForValidation.GetAbsolutePathname().c_str())); return false; } Heightmap *heightmap = new Heightmap(); if(String::npos != posPng) { Image *image = CreateTopLevelImage(pathForValidation); pathIsCorrect = heightmap->BuildFromImage(image); SafeRelease(image); } else { pathIsCorrect = heightmap->Load(pathForValidation); } if(!pathIsCorrect) { SafeRelease(heightmap); errorsLog.insert(Format("Can't load Heightmap from path %s", pathForValidation.GetAbsolutePathname().c_str())); return false; } pathIsCorrect = IsPowerOf2(heightmap->Size() - 1); if(!pathIsCorrect) { errorsLog.insert(Format("Heightmap %s has wrong size", pathForValidation.GetAbsolutePathname().c_str())); } SafeRelease(heightmap); return pathIsCorrect; } else { errorsLog.insert(Format("Path %s is incorrect for project %s", pathForValidation.GetAbsolutePathname().c_str(), pathForChecking.GetAbsolutePathname().c_str())); } return pathIsCorrect; }
float32 LandscapeEditorHeightmap::GetDropperHeight() { Vector3 landSize; AABBox3 transformedBox; workingLandscape->GetBoundingBox().GetTransformedBox(*workingLandscape->GetWorldTransformPtr(), transformedBox); landSize = transformedBox.max - transformedBox.min; Heightmap *heightmap = landscapesController->GetCurrentHeightmap(); int32 index = (int32)(landscapePoint.x + landscapePoint.y * heightmap->Size()); float32 height = heightmap->Data()[index]; float32 maxHeight = landSize.z; return (height / Heightmap::MAX_VALUE * maxHeight); }
void LandscapeEditorHeightmap::TextureDidChanged(const String &forKey) { if("property.landscape.texture.heightmap" == forKey) { savedPath = workingLandscape->GetHeightmapPathname(); Heightmap *heightmap = landscapesController->GetCurrentHeightmap(); landscapeSize = heightmap->Size(); CreateHeightmapUndo(); } else if("property.landscape.texture.tilemask" == forKey) { CreateTilemaskImage(); } }
void LandscapeEditorHeightmap::ShowAction() { prevToolSize = 0.f; SceneData *activeScene = SceneDataManager::Instance()->SceneGetActive(); landscapesController = activeScene->GetLandscapesController(); landscapesController->CreateEditorLandscape(); SafeRetain(landscapesController); savedPath = workingLandscape->GetHeightmapPathname(); Heightmap *heightmap = landscapesController->GetCurrentHeightmap(); landscapeSize = heightmap->Size(); landscapesController->CursorEnable(); CreateTilemaskImage(); }