Resizing Building Meshes at Runtime Without Distortions
In procedural city builders and sandbox construction games, the ability to stretch a building mesh to fit a specific plot is a core mechanic. However, a standard transform scale operation leads to visual distortion: windows become wide rectangles, bricks stretch into thin lines, and architectural details lose their proportions. To achieve Consistent Scaling, developers must move beyond basic transforms and utilize techniques like 9-Slicing for 3D or World-Space UV Triplanar Mapping. This guide explains how to maintain structural integrity while modifying mesh dimensions during live gameplay.
Table of Content
- Purpose of Distortion-Free Scaling
- Common Use Cases
- Step by Step Implementation
- Best Results for Architectural Fidelity
- FAQ
- Disclaimer
Purpose
The primary purpose of this technique is to preserve the Texel Density and Geometric Aspect Ratio of an asset. When a building is resized, we want the repeating elements (like windows or siding) to tile or add new instances rather than stretching the existing polygons. By decoupling the mesh's logical bounds from its vertex positions, we allow for "rubber-band" style building tools that feel professional and grounded in the game world's reality.
Use Case
Distortion-free resizing is essential for:
- Procedural Architecture: Creating skyscrapers of varying heights using a single "base" module.
- Dynamic Base Building: Allowing players to drag walls to custom lengths in survival or strategy games.
- Level Design Tools: Enabling designers to quickly block out environments with "stretchable" assets that maintain their texture scale.
- Modding Frameworks: Providing flexible assets that players can resize to fit custom map layouts.
Step by Step
Implement World-Space UV Mapping
Standard UVs are "pinned" to the vertices. To prevent texture stretching, use a World-Space UV Shader. This calculates the texture coordinates based on the pixel's position in the game world rather than its position on the mesh. As the building grows, the texture simply "unveils" more of itself at the same scale.
Set Up 3D 9-Slicing (The Box Method)
Divide your building mesh into nine regions: four corners, four edges, and one center.
- Corners: Stay at a scale of 1:1 and only move as the building expands.
- Edges: Scale only on one axis (width or height).
- Center: Scales on both axes to fill the gap.
Use Procedural Mesh Generation
For complex buildings, use a script to "instantiate" middle sections. Instead of scaling a single mesh, the script calculates how many window "modules" fit into the new length and adds them dynamically to a single combined mesh at runtime.
Update Colliders Dynamically
Ensure your BoxCollider or MeshCollider bounds are updated in the same frame as the mesh resize to prevent players from walking through "phantom" walls.
Best Results
| Technique | Visual Quality | Performance Cost |
|---|---|---|
| Triplanar Mapping | Excellent (No stretching) | Moderate (Shader overhead) |
| Modular Instancing | Perfect (Geometric detail) | High (Draw call management) |
| Vertex Shifting | Good (Fast resizing) | Low (Efficient) |
FAQ
Will this work with curved buildings?
Resizing curves is more complex. You typically need to use a Spline-Based Mesh Deformer, which calculates the extrusion along a path rather than a simple box volume.
Why is my texture still blurry?
If you aren't using World-Space UVs, you must update the Texture Tiling (Tiling/Offset) in your material via script to match the new scale factor of the mesh.
Can I do this in real-time without lag?
Yes. Vertex shifting is very performant. Avoid rebuilding the entire mesh data every frame; instead, manipulate the transform.localScale of child modules or use a shader to move vertices.
Disclaimer
Runtime mesh manipulation can lead to significant performance overhead if not properly optimized (e.g., failing to batch draw calls for modular sections). These techniques assume a basic understanding of Shader Graph (Unity) or Material Editor (Unreal) and C# or C++ scripting within your chosen game engine.
Tags: ProceduralMesh, GameDevTips, MeshScaling, TechnicalArt
