Scales and translates mesh to fit target bounding box (uniform or non-uniform).
Takes entity (mesh entity handle), x (target box center X), y (target box center Y - positive up), z (target box center Z), width (target box width), height (target box height), depth (target box depth), uniform (0=non-uniform stretch, 1=uniform scale preserving proportions).
Returns nothing.
3D Graphics
Parameters & Returns
Parameters
entityInt
xDouble
yDouble
zDouble
widthDouble
heightDouble
depthDouble
uniformInt
Returns
Void
Quick Summary
Scales and translates mesh to fit target bounding box (uniform or non-uniform).
Takes entity (mesh entity handle), x (target box center X), y (target box center Y - positive up), z (target box center Z), width (target box width), height (target box height), depth (target box depth), uniform (0=non-uniform stretch, 1=uniform scale preserving proportions).
Returns nothing.
Technical Exegesis...
Scales and translates mesh to fit target bounding box (uniform or non-uniform). Takes entity (mesh entity handle), x (target box center X), y (target box center Y - positive up), z (target box center Z), width (target box width), height (target box height), depth (target box depth), uniform (0=non-uniform stretch, 1=uniform scale preserving proportions). Returns nothing.
Scales and translates mesh to fit target bounding box (uniform or non-uniform). Takes entity (mesh entity handle), x (target box center X), y (target box center Y - positive up), z (target box center Z), width (target box width), height (target box height), depth (target box depth), uniform (0=non-uniform stretch, 1=uniform scale preserving proportions). Returns nothing. Validates entity and mesh exist, calls EnsureUniqueMesh for copy-on-write, calculates current mesh bounding box (min/max corners), computes scale factors (target size / current size), if uniform=1 uses smallest scale factor for all axes (preserves proportions), scales all vertices by factors, translates vertices to target center with Y-axis negation, recalculates bounding radius, handles locked meshes (sets needsGPUUpload, defers buffer rebuild), unlocked meshes immediately call RebuildGPUBuffersFromSurfaces. Permanent geometry modification.
This function resizes and repositions mesh to fit target dimensions. Use case: normalize imported models to standard size, fit meshes into specific spaces (rooms, containers, grids), procedural level generation (fit pieces together), scale normalization (meshes with wildly different sizes). Copy-on-write: calls EnsureUniqueMesh() before modification, creates independent copy if mesh shared. Bounding box calculation: iterates all vertices in all surfaces, finds min/max corners: min=XMFLOAT3(minX, minY, minZ), max=XMFLOAT3(maxX, maxY, maxZ), current size = max - min, current center = (min + max) / 2. Scale factor computation: scaleX = width / currentWidth, scaleY = height / currentHeight, scaleZ = depth / currentDepth. Uniform vs non-uniform: if uniform=0 (non-uniform), uses computed scaleX/Y/Z independently (stretches to fill box exactly, distorts proportions if aspect ratios differ). If uniform=1 (uniform), finds smallest scale factor: uniformScale = min(scaleX, scaleY, scaleZ), uses uniformScale for all axes (preserves proportions, mesh may not fill box completely on larger axes, no distortion). Scaling: for each vertex: vertex.position -= currentCenter (center at origin), vertex.position *= scale factors (resize), vertex.position += targetCenter with Y-negation (move to target position). Implementation details: Y-axis negation applied to target center: targetCenter = XMFLOAT3(x, -y, z), user +Y=up, internal -Y=up. Normals/tangents: NOT modified (scale is applied, but normals not renormalized, may cause lighting issues with non-uniform scale). UV coordinates: NOT modified. Bounding radius recalculation: after fitting, calculates max distance from new center: boundingRadius = max(distance(vertex, targetCenter)), affects frustum culling. Lock/unlock pattern: if mesh.locked==true, sets mesh.needsGPUUpload=true, defers GPU buffer update. If mesh.locked==false, immediately calls RebuildGPUBuffersFromSurfaces. Use cases: (1) Normalize model sizes (make all imported models same scale), (2) Fit into grid cells (procedural placement), (3) Resize to fit containers (inventory systems, storage), (4) Scale to match reference (replace placeholder with final asset), (5) Procedural generation (fit pieces into layouts). Common pattern: mesh=b3dLoadMesh("model.glb"), b3dFitMesh(mesh, 0, 0, 0, 2, 2, 2, 1) to fit in 2x2x2 cube at origin preserving proportions. Uniform scaling: b3dFitMesh(mesh, x, y, z, size, size, size, 1) fits in cube, preserves shape. Non-uniform scaling: b3dFitMesh(mesh, x, y, z, w, h, d, 0) stretches to fill box, may distort. Typical workflow: load mesh, measure with bounding box queries, b3dFitMesh to desired size, or b3dLockMesh, fit/modify, b3dUnlockMesh. Performance: O(N) where N=total vertex count (two passes: bounding box calculation, vertex transformation), locked mesh mode defers GPU upload, EnsureUniqueMesh may allocate/copy. Bounding box edge cases: empty mesh (no vertices) handled (no modification), single vertex mesh (min==max, zero size) may cause division by zero (check for zero dimensions in implementation). GPU upload: RebuildGPUBuffersFromSurfaces creates new vertex/index buffers, uploads to GPU. Coordinate space: operates in mesh local space, fitted mesh permanently resized/repositioned, subsequent entity transforms apply to fitted mesh. Hierarchy: mesh modification doesn't affect children. Validation: invalid entity/mesh handles silently ignored. Zero dimensions: target width/height/depth of 0 collapses mesh to plane/line/point (edge case). Negative dimensions: inverts mesh along that axis (mirrors), may break winding (use b3dFlipMesh to fix). Related: b3dScaleMesh scales without translating, b3dPositionMesh translates without scaling, b3dLockMesh/UnlockMesh for batching, EnsureUniqueMesh handles copy-on-write, RebuildGPUBuffersFromSurfaces uploads to GPU, b3dGetMeshBoundsMin/Max for querying bounds.