mirror of
https://github.com/cocos/cocos4.git
synced 2026-11-20 15:42:39 +08:00
fix camera id (#17857)
This commit is contained in:
@@ -399,6 +399,8 @@ export const SKYBOX_FLAG = SkyBoxFlagValue.VALUE;
|
||||
|
||||
const correctionMatrices: Mat4[] = [];
|
||||
|
||||
let _cameraCount = 0;
|
||||
|
||||
/**
|
||||
* @en The render camera representation in the render scene, it's managed by [[Camera]]
|
||||
* @zh 渲染场景中的相机对象,由项目层的 [[Camera]] 管理。
|
||||
@@ -799,6 +801,11 @@ export class Camera {
|
||||
return this._matViewProjInv$;
|
||||
}
|
||||
|
||||
/** @engineInternal */
|
||||
get cameraId (): number {
|
||||
return this._cameraId$;
|
||||
}
|
||||
|
||||
/**
|
||||
* @en Whether the camera is fixed size or matching the window size.
|
||||
* @zh 相机是固定尺寸还是跟随屏幕尺寸
|
||||
@@ -862,6 +869,7 @@ export class Camera {
|
||||
private _cameraType$: CameraType = CameraType.DEFAULT;
|
||||
private _trackingType$: TrackingType = TrackingType.NO_TRACKING;
|
||||
private _usage$: CameraUsage = CameraUsage.GAME;
|
||||
private _cameraId$ = _cameraCount++;
|
||||
|
||||
constructor (device: Device) {
|
||||
this._device$ = device;
|
||||
|
||||
@@ -120,13 +120,8 @@ export function validPunctualLightsCulling (pipeline: BasicPipeline, camera: Cam
|
||||
sceneData.validPunctualLights = validPunctualLights;
|
||||
}
|
||||
|
||||
const _cameras: Camera[] = [];
|
||||
|
||||
export function getCameraUniqueID (camera: Camera): number {
|
||||
if (!_cameras.includes(camera)) {
|
||||
_cameras.push(camera);
|
||||
}
|
||||
return _cameras.indexOf(camera);
|
||||
return camera.cameraId;
|
||||
}
|
||||
|
||||
export function getLoadOpOfClearFlag (clearFlag: ClearFlagBit, attachment: AttachmentType): LoadOp {
|
||||
|
||||
@@ -57,6 +57,8 @@ constexpr ccstd::array<ccstd::array<float, 4>, 4> PRE_TRANSFORMS = {{
|
||||
{{0, -1, 1, 0}} // SurfaceTransform.ROTATE_270
|
||||
}};
|
||||
|
||||
std::atomic<uint32_t> sCameraId{0};
|
||||
|
||||
} // namespace
|
||||
|
||||
const ccstd::vector<float> Camera::FSTOPS{1.8F, 2.0F, 2.2F, 2.5F, 2.8F, 3.2F, 3.5F, 4.0F, 4.5F, 5.0F, 5.6F, 6.3F, 7.1F, 8.0F, 9.0F, 10.0F, 11.0F, 13.0F, 14.0F, 16.0F, 18.0F, 20.0F, 22.0F};
|
||||
@@ -65,7 +67,8 @@ const ccstd::vector<float> Camera::SHUTTERS{1.0F, 1.0F / 2.0F, 1.0F / 4.0F, 1.0F
|
||||
const ccstd::vector<float> Camera::ISOS{100.0F, 200.0F, 400.0F, 800.0F};
|
||||
|
||||
Camera::Camera(gfx::Device *device)
|
||||
: _device(device) {
|
||||
: _device(device)
|
||||
, _cameraId(sCameraId++) {
|
||||
_apertureValue = Camera::FSTOPS.at(static_cast<int>(_aperture));
|
||||
_shutterValue = Camera::SHUTTERS.at(static_cast<int>(_shutter));
|
||||
_isoValue = Camera::ISOS[static_cast<int>(_iso)];
|
||||
|
||||
@@ -181,6 +181,7 @@ public:
|
||||
void syncCameraEditor(const Camera *camera);
|
||||
void update(bool forceUpdate = false); // for lazy eval situations like the in-editor preview
|
||||
void changeTargetWindow(RenderWindow *window);
|
||||
uint32_t getCameraId() const noexcept { return _cameraId; }
|
||||
|
||||
/**
|
||||
* transform a screen position (in oriented space) to a world space ray
|
||||
@@ -419,6 +420,7 @@ private:
|
||||
CameraType _cameraType{CameraType::DEFAULT};
|
||||
TrackingType _trackingType{TrackingType::NO_TRACKING};
|
||||
CameraUsage _usage{CameraUsage::GAME};
|
||||
uint32_t _cameraId{0};
|
||||
|
||||
#if CC_USE_GEOMETRY_RENDERER
|
||||
IntrusivePtr<pipeline::GeometryRenderer> _geometryRenderer;
|
||||
|
||||
@@ -452,6 +452,7 @@ using namespace cc;
|
||||
%attribute(cc::scene::Camera, cc::scene::CameraUsage, cameraUsage, getCameraUsage, setCameraUsage);
|
||||
%attribute(cc::scene::Camera, cc::scene::TrackingType, trackingType, getTrackingType, setTrackingType);
|
||||
%attribute(cc::scene::Camera, cc::scene::CameraType, cameraType, getCameraType, setCameraType);
|
||||
%attribute(cc::scene::Camera, uint32_t, cameraId, getCameraId);
|
||||
|
||||
%attribute(cc::scene::RenderScene, ccstd::string&, name, getName);
|
||||
%attribute(cc::scene::RenderScene, ccstd::vector<cc::IntrusivePtr<cc::scene::Camera>>&, cameras, getCameras);
|
||||
|
||||
Reference in New Issue
Block a user