UE4渲染用到的Bounds

博客介绍了使用Actor边界进行可见性测试的相关内容。每个Actor的边界由球体和盒子两部分组成,可在视口可视化其边界。还说明了编辑Actor边界的方法,如设置Bounds Scale等,同时指出增加边界可能影响性能和阴影质量,相机视角渲染会根据Bounds检测裁剪剔除。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

官方介绍:

Testing Visibility with an Actor's Bounds

Each Actor placed in a Level has a set of bounds using a box and a sphere that is used for various things in the Engine. One of those being specifically to test whether an it is visible or not. The bounds of an Actor is made up of two parts: a sphere and a box. The bounding sphere is used for fast collision detection with a simple distance test, and, more often than not, it's greater in size than the object it contains. On the other hand, the bounding box is a closer match to the shape of the object and provides more accurate results. 

Visualize bounds of Actors in the Level Viewport by selecting Show > Advanced > Bounds. Alternatively, in the Skeletal Mesh Editor you can select Character > Bounds and in the Static Mesh Editor, select Bounds in the main toolbar.

 

ActorBounds.png

An Actor with its bounds (sphere and box) displayed.

 

Each Static Mesh and Skeletal Mesh has its own bounding box and sphere that automatically scales to the size of the geometry when imported, or when scaled or rotated in the viewport.

 

You can edit an Actor's bounds using the following ways:

  • By setting the Bounds Scale from its Details panel when it's selected in a Level or in a Blueprint. The Bounds Scale uniformly scales the bounds of an Actor, acting as a multiplier of the original scale values.

    PerActorBoundsSettingsDetailsPanel.png

    Click image for full size.

  • By opening the Static Mesh or Skeletal Mesh Editors to apply non-uniform scaling for Positive Bounds Extension and Negative Bounds Extensions using the Details panel. 
    ActorEditorBoundsExtension.png

Increasing an Actor's bounds can potentially impact performance and shadow quality by keeping the Actor from be culled sooner than it would otherwise have been. 

 

源码解释:

/** 
     * Scales the bounds of the object.
     * This is useful when using World Position Offset to animate the vertices of the object outside of its bounds. 
     * Warning: Increasing the bounds of an object will reduce performance and shadow quality!
     * Currently only used by StaticMeshComponent and SkeletalMeshComponent.
     */
    UPROPERTY(EditAnywhere, AdvancedDisplay, Category=Rendering, meta=(UIMin = "1", UIMax = "10.0"))
    float BoundsScale;

 

使用:

玩家快速走过,相机视角可看到某物体,可以适当增加BoundsScale,但是降低性能。相机视角渲染,会根据Bounds检测是否渲染裁剪剔除。

### 实现 `react-draggable` 中动态设置 `bounds` 为了实现在 `react-draggable` 组件中动态更新边界 (`bounds`) 的效果,可以利用 React 的状态管理机制来控制 `bounds` 属性的变化。下面是一个具体的例子展示如何通过父组件的状态变化影响子组件中的 `bounds` 参数。 #### 使用 `useState` 和 `useEffect` 来处理动态 `bounds` ```jsx import React, { useState, useEffect, useRef } from 'react'; import Draggable from 'react-draggable'; const DynamicBoundsExample = () => { const [containerSize, setContainerSize] = useState({ width: 400, height: 400 }); const boundsRef = useRef(null); // 模拟容器大小改变事件 useEffect(() => { let timeoutId; // 定期更改容器尺寸作为模拟场景 timeoutId = setTimeout(() => { setContainerSize({ width: Math.floor(Math.random() * (800 - 300 + 1)) + 300, height: Math.floor(Math.random() * (600 - 200 + 1)) + 200 }); }, 5000); return () => clearTimeout(timeoutId); }); return ( <div> <p>当前容器宽度:{containerSize.width}px</p> <p>当前容器高度:{containerSize.height}px</p> {/* 设置带有边界的可拖拽区域 */} <div ref={boundsRef} style={{ width: `${containerSize.width}px`, height: `${containerStyle.height}px`, border: 'solid 1px #ccc', position: 'relative' }} > <Draggable bounds={boundsRef}> <div className="draggable-box" style={{ width: '100px', height: '100px', backgroundColor: '#f00', textAlign: 'center', lineHeight: '100px', color: '#fff' }}> Drag Me Around! </div> </Draggable> </div> </div> ); }; export default DynamicBoundsExample; ``` 在这个案例里,每当定时器触发时会随机调整外部包裹层(`boundsRef`)的宽高属性,并且这些新的尺寸会被传递给 `<Draggable>` 组件内的 `bounds` 属性,从而实现了动态设定拖拽范围的效果[^4]。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值