mirror of
https://github.com/cocos/cocos4.git
synced 2026-11-21 08:02:39 +08:00
Merge branch 'v3.7.0' into v3.7.1
This commit is contained in:
@@ -295,7 +295,11 @@ export class LODGroup extends Component {
|
||||
* @ 重置 LODs 为当前新设置的值。
|
||||
*/
|
||||
set LODs (valArray: readonly LOD[]) {
|
||||
if (valArray === this._LODs) return;
|
||||
if (valArray === this._LODs) {
|
||||
//_LODs maybe changed, we need to notify the scene to update.
|
||||
this._updateDataToScene();
|
||||
return;
|
||||
}
|
||||
this._LODs.length = 0;
|
||||
this.lodGroup.clearLODs();
|
||||
valArray.forEach((lod: LOD, index: number) => {
|
||||
@@ -303,6 +307,8 @@ export class LODGroup extends Component {
|
||||
this._LODs[index] = lod;
|
||||
lod.modelAddedCallback = this.onLodModelAddedCallback.bind(this);
|
||||
});
|
||||
//_LODs has been changed, we need to notify the scene to update.
|
||||
this._updateDataToScene();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -602,13 +608,13 @@ export class LODGroup extends Component {
|
||||
}
|
||||
|
||||
private _attachToScene () {
|
||||
if (!this.node.scene) { return; }
|
||||
|
||||
const renderScene = this._getRenderScene();
|
||||
if (this._lodGroup.scene) {
|
||||
this._detachFromScene();
|
||||
if (this.node && this.node.scene) {
|
||||
const renderScene = this._getRenderScene();
|
||||
if (this._lodGroup.scene) {
|
||||
this._detachFromScene();
|
||||
}
|
||||
renderScene.addLODGroup(this._lodGroup);
|
||||
}
|
||||
renderScene.addLODGroup(this._lodGroup);
|
||||
}
|
||||
|
||||
private _detachFromScene () {
|
||||
@@ -624,4 +630,9 @@ export class LODGroup extends Component {
|
||||
EditorExtends.Node.emit('change', node.uuid, node);
|
||||
}
|
||||
}
|
||||
|
||||
private _updateDataToScene () {
|
||||
this._detachFromScene();
|
||||
this._attachToScene();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -125,11 +125,11 @@ export class ReflectionProbe extends Component {
|
||||
*/
|
||||
@type(Enum(ProbeType))
|
||||
set probeType (value: number) {
|
||||
this.probe.probeType = value;
|
||||
if (value !== this._probeType) {
|
||||
const lastSize = this._size.clone();
|
||||
const lastSizeIsNoExist = Vec3.equals(this._lastSize, Vec3.ZERO);
|
||||
this._probeType = value;
|
||||
this.probe.probeType = value;
|
||||
|
||||
if (this._probeType === ProbeType.CUBE) {
|
||||
if (lastSizeIsNoExist) {
|
||||
|
||||
@@ -24,7 +24,7 @@
|
||||
|
||||
// @ts-check
|
||||
import { ccclass, override } from 'cc.decorator';
|
||||
import { EDITOR, ALIPAY, XIAOMI, JSB, TEST, BAIDU } from 'internal:constants';
|
||||
import { EDITOR, ALIPAY, XIAOMI, JSB, TEST, BAIDU, TAOBAO } from 'internal:constants';
|
||||
import { Device, Format, FormatFeatureBit, deviceManager } from '../../gfx';
|
||||
import { Asset } from './asset';
|
||||
import { PixelFormat } from './asset-enum';
|
||||
@@ -163,7 +163,7 @@ function fetchImageSource (imageSource: ImageSource) {
|
||||
|
||||
// 返回该图像源是否是平台提供的图像对象。
|
||||
function isNativeImage (imageSource: ImageSource): imageSource is (HTMLImageElement | HTMLCanvasElement | ImageBitmap) {
|
||||
if (ALIPAY || XIAOMI || BAIDU) {
|
||||
if (ALIPAY || TAOBAO || XIAOMI || BAIDU) {
|
||||
// We're unable to grab the constructors of Alipay native image or canvas object.
|
||||
return !('_data' in imageSource);
|
||||
}
|
||||
|
||||
@@ -478,7 +478,9 @@ function parseAttributes (constructor: Function, attributes: PropertyStash, clas
|
||||
if ('default' in attributes) {
|
||||
(attrs || initAttrs())[`${propertyNamePrefix}default`] = attributes.default;
|
||||
} else if (((EDITOR && !window.Build) || TEST) && warnOnNoDefault && !(attributes.get || attributes.set)) {
|
||||
warnID(3654, className, propertyName);
|
||||
// TODO: we close this warning for now:
|
||||
// issue: https://github.com/cocos/3d-tasks/issues/14887
|
||||
// warnID(3654, className, propertyName);
|
||||
}
|
||||
|
||||
const parseSimpleAttribute = (attributeName: keyof IAcceptableAttributes, expectType: string) => {
|
||||
|
||||
@@ -246,11 +246,15 @@ function setDefaultValue<T> (
|
||||
propertyStash: PropertyStash,
|
||||
classConstructor: new () => T,
|
||||
propertyKey: PropertyKey,
|
||||
descriptorOrInitializer: BabelPropertyDecoratorDescriptor | Initializer | undefined,
|
||||
descriptorOrInitializer: BabelPropertyDecoratorDescriptor | Initializer | undefined | null,
|
||||
) {
|
||||
if (descriptorOrInitializer) {
|
||||
if (descriptorOrInitializer !== undefined) {
|
||||
if (typeof descriptorOrInitializer === 'function') {
|
||||
propertyStash.default = getDefaultFromInitializer(descriptorOrInitializer);
|
||||
} else if (descriptorOrInitializer === null) {
|
||||
// some decorated properties we haven't specified default value, then the initializer should be null.
|
||||
// We fallback to the behavior of v3.6.3, where we don't specify default value automatically.
|
||||
// propertyStash.default = undefined;
|
||||
} else if (descriptorOrInitializer.initializer) {
|
||||
// In case of Babel, if an initializer is given for class field.
|
||||
// That initializer is passed to `descriptor.initializer`.
|
||||
@@ -259,6 +263,7 @@ function setDefaultValue<T> (
|
||||
} else {
|
||||
// In case of TypeScript, we can not directly capture the initializer.
|
||||
// We have to be hacking to extract the value.
|
||||
// We should fallback to TypeScript case only when `descriptorOrInitializer` is undefined.
|
||||
const actualDefaultValues = classStash.default || (classStash.default = extractActualDefaultValues(classConstructor));
|
||||
// eslint-disable-next-line no-prototype-builtins
|
||||
if ((actualDefaultValues as any).hasOwnProperty(propertyKey)) {
|
||||
|
||||
@@ -40,7 +40,9 @@ export type BabelPropertyDecoratorDescriptor = PropertyDescriptor & { initialize
|
||||
* 该签名同时兼容 TypeScript legacy 装饰器以及 Babel legacy 装饰器。
|
||||
* 第三个参数在 Babel 情况下,会传入 descriptor。对于一些被优化的引擎内部装饰器,会传入 initializer。
|
||||
*/
|
||||
export type LegacyPropertyDecorator = (target: Record<string, any>, propertyKey: string | symbol, descriptorOrInitializer?: BabelPropertyDecoratorDescriptor | Initializer) => void;
|
||||
export type LegacyPropertyDecorator = (
|
||||
target: Record<string, any>, propertyKey: string | symbol, descriptorOrInitializer?: BabelPropertyDecoratorDescriptor | Initializer | null,
|
||||
) => void;
|
||||
|
||||
/**
|
||||
* @en
|
||||
|
||||
@@ -35,9 +35,9 @@ import { IVec3Like, IQuatLike } from '../math/type-define';
|
||||
export class Capsule {
|
||||
/**
|
||||
* @en
|
||||
* Gets the type of the shape.
|
||||
* Gets the type of this Capsule, always returns `enums.SHAPE_CAPSULE`.
|
||||
* @zh
|
||||
* 获取形状的类型。
|
||||
* 获取此形状的类型,值固定为 `enums.SHAPE_CAPSULE`。
|
||||
*/
|
||||
get type () {
|
||||
return this._type;
|
||||
@@ -47,9 +47,9 @@ export class Capsule {
|
||||
|
||||
/**
|
||||
* @en
|
||||
* Capsule sphere radius.
|
||||
* The radius of the sphere in this capsule.
|
||||
* @zh
|
||||
* 胶囊体球部半径。
|
||||
* 胶囊体球部的半径。
|
||||
*/
|
||||
radius: number;
|
||||
|
||||
@@ -63,7 +63,7 @@ export class Capsule {
|
||||
|
||||
/**
|
||||
* @en
|
||||
* Local orientation of capsule [0,1,2] => [x,y,z].
|
||||
* The local orientation of this capsule [0,1,2] => [x,y,z].
|
||||
* @zh
|
||||
* 胶囊体的本地朝向,映射关系 [0,1,2] => [x,y,z]。
|
||||
*/
|
||||
@@ -95,6 +95,15 @@ export class Capsule {
|
||||
*/
|
||||
readonly ellipseCenter1: Vec3;
|
||||
|
||||
/**
|
||||
* @en
|
||||
* Constructs a Capsule instance.
|
||||
* @zh
|
||||
* 构造一个胶囊体实例。
|
||||
* @param radius @en The radius of the sphere in this capsule. @zh 胶囊体球部的半径。
|
||||
* @param halfHeight @en The distance between the center point of the capsule and the center of the sphere. @zh 胶囊体中心点和球部圆心的距离。
|
||||
* @param axis @en The local orientation of this capsule [0,1,2] => [x,y,z]. @zh 胶囊体的本地朝向,映射关系 [0,1,2] => [x,y,z]。
|
||||
*/
|
||||
constructor (radius = 0.5, halfHeight = 0.5, axis = 1) {
|
||||
this._type = enums.SHAPE_CAPSULE;
|
||||
this.radius = radius;
|
||||
@@ -111,9 +120,9 @@ export class Capsule {
|
||||
|
||||
/**
|
||||
* @en
|
||||
* Transform this capsule.
|
||||
* Transforms this capsule by a 4x4 matrix and RTS.
|
||||
* @zh
|
||||
* 变换此胶囊体。
|
||||
* 使用 4x4 矩阵和 RTS 变换此胶囊体。
|
||||
*/
|
||||
transform (m: Mat4, pos: IVec3Like, rot: IQuatLike, scale: IVec3Like, out: Capsule) {
|
||||
const ws = scale;
|
||||
@@ -130,6 +139,12 @@ export class Capsule {
|
||||
out.updateCache();
|
||||
}
|
||||
|
||||
/**
|
||||
* @en
|
||||
* Updates the cache.
|
||||
* @zh
|
||||
* 更新缓存。
|
||||
*/
|
||||
updateCache () {
|
||||
this.updateLocalCenter();
|
||||
Vec3.transformQuat(this.ellipseCenter0, this.ellipseCenter0, this.rotation);
|
||||
@@ -138,6 +153,12 @@ export class Capsule {
|
||||
this.ellipseCenter1.add(this.center);
|
||||
}
|
||||
|
||||
/**
|
||||
* @en
|
||||
* Updates the center points.
|
||||
* @zh
|
||||
* 更新中心点信息。
|
||||
*/
|
||||
updateLocalCenter () {
|
||||
const halfHeight = this.halfHeight;
|
||||
const axis = this.axis;
|
||||
|
||||
@@ -45,13 +45,12 @@ const _temp_v3 = new Vec3();
|
||||
* @en
|
||||
* Basic Geometry: frustum.
|
||||
* @zh
|
||||
* 基础几何 截头锥体。
|
||||
* 基础几何:视锥体。
|
||||
*/
|
||||
|
||||
export class Frustum {
|
||||
/**
|
||||
* @en
|
||||
* Create an orthogonal frustum.
|
||||
* Creates an orthogonal frustum.
|
||||
* @zh
|
||||
* 创建一个正交视锥体。
|
||||
* @param out @en The result orthogonal frustum. @zh 输出的正交视锥体。
|
||||
@@ -60,9 +59,9 @@ export class Frustum {
|
||||
* @param near @en The near plane of the frustum. @zh 正交视锥体的近平面值。
|
||||
* @param far @en The far plane of the frustum. @zh 正交视锥体的远平面值。
|
||||
* @param transform @en The transform matrix of the frustum. @zh 正交视锥体的变换矩阵。
|
||||
* @return @en The out object @zh 返回正交视锥体.
|
||||
* @returns @en The result frustum, same as the `out` parameter. @zh 存储结果的视锥体,与 `out` 参数为同一个对象。
|
||||
*/
|
||||
public static createOrtho = (() => (out: Frustum, width: number, height: number, near: number, far: number, transform: Mat4) => {
|
||||
public static createOrtho (out: Frustum, width: number, height: number, near: number, far: number, transform: Mat4) {
|
||||
const halfWidth = width / 2;
|
||||
const halfHeight = height / 2;
|
||||
Vec3.set(_temp_v3, halfWidth, halfHeight, -near);
|
||||
@@ -88,16 +87,16 @@ export class Frustum {
|
||||
Plane.fromPoints(out.planes[3], out.vertices[0], out.vertices[5], out.vertices[4]);
|
||||
Plane.fromPoints(out.planes[4], out.vertices[2], out.vertices[0], out.vertices[3]);
|
||||
Plane.fromPoints(out.planes[5], out.vertices[7], out.vertices[5], out.vertices[6]);
|
||||
})();
|
||||
}
|
||||
|
||||
/**
|
||||
* @en Create a frustum from an AABB box.
|
||||
* @zh 从 AABB 包围盒中创建一个视锥体。
|
||||
* @param out @en The result frustum @zh 输出的视锥体对象。
|
||||
* @param aabb @en The AABB bounding box of the frustum @zh AABB 包围盒。
|
||||
* @return @en The out object @zh 返回视锥体.
|
||||
* @en Creates a frustum from an AABB instance.
|
||||
* @zh 根据一个 AABB 实例创建一个视锥体。
|
||||
* @param out @en The result frustum. @zh 输出的视锥体对象。
|
||||
* @param aabb @en The AABB to create the result frustum. @zh 用于创建视锥体 AABB。
|
||||
* @returns @en The result frustum, same as the `out` parameter. @zh 存储结果的视锥体,与 `out` 参数为同一个对象。
|
||||
*/
|
||||
public static createFromAABB (out: Frustum, aabb: AABB | Readonly<AABB>) : Frustum {
|
||||
public static createFromAABB (out: Frustum, aabb: AABB | Readonly<AABB>): Frustum {
|
||||
const vec3_min = new Vec3(); const vec3_max = new Vec3();
|
||||
Vec3.subtract(vec3_min, aabb.center, aabb.halfExtents);
|
||||
Vec3.add(vec3_max, aabb.center, aabb.halfExtents);
|
||||
@@ -121,13 +120,13 @@ export class Frustum {
|
||||
}
|
||||
|
||||
/**
|
||||
* @en Calculate a split frustum.
|
||||
* @en Calculates a split frustum.
|
||||
* @zh 计算出一个分割的视锥体。
|
||||
* @param start @en The split start position @zh 分割开始位置
|
||||
* @param end @en The split end position @zh 分割末尾位置
|
||||
* @param aspect @en The aspect ratio of the camera @zh 相机视图的长宽比
|
||||
* @param fov @en Field of view of the camera @zh 相机的视角大小
|
||||
* @param m @en The transform matrix @zh 变换矩阵
|
||||
* @param start @en The split start position. @zh 分割开始位置。
|
||||
* @param end @en The split end position. @zh 分割末尾位置。
|
||||
* @param aspect @en The aspect ratio of the camera. @zh 相机视图的长宽比。
|
||||
* @param fov @en The field of view of the camera. @zh 相机的视角大小。
|
||||
* @param m @en The transform matrix. @zh 变换矩阵。
|
||||
*/
|
||||
public split (start: number, end: number, aspect: number, fov: number, m: Mat4) {
|
||||
// 0: cameraNear 1:cameraFar
|
||||
@@ -162,10 +161,10 @@ export class Frustum {
|
||||
|
||||
/**
|
||||
* @en
|
||||
* Create a new frustum.
|
||||
* Creates a new frustum.
|
||||
* @zh
|
||||
* 创建一个新的截锥体。
|
||||
* @return @en An empty frustum. @zh 一个空截椎体
|
||||
* 创建一个新的视椎体。
|
||||
* @returns @en An empty frustum. @zh 一个空视椎体。
|
||||
*/
|
||||
public static create (): Frustum {
|
||||
return new Frustum();
|
||||
@@ -173,11 +172,11 @@ export class Frustum {
|
||||
|
||||
/**
|
||||
* @en
|
||||
* Clone a frustum.
|
||||
* Clones a frustum.
|
||||
* @zh
|
||||
* 克隆一个截锥体。
|
||||
* @param f @en The frustum to clone from @zh 用于克隆的截锥体
|
||||
* @return @en The cloned frustum @zh 克隆出的新截锥体
|
||||
* 克隆一个视椎体。
|
||||
* @param f @en The frustum to clone from. @zh 用于克隆的视椎体。
|
||||
* @return @en The cloned frustum. @zh 克隆出的新视椎体。
|
||||
*/
|
||||
public static clone (f: Frustum): Frustum {
|
||||
return Frustum.copy(new Frustum(), f);
|
||||
@@ -185,12 +184,12 @@ export class Frustum {
|
||||
|
||||
/**
|
||||
* @en
|
||||
* Copy the values from one frustum to another.
|
||||
* Copies the values from one frustum to another.
|
||||
* @zh
|
||||
* 从一个视锥体拷贝到另一个视锥体。
|
||||
* @param out @en The result frustum @zh 用于存储拷贝数据的截锥体
|
||||
* @param f @en The frustum to copy from @zh 用于克隆的截锥体
|
||||
* @return @en The out object @zh 传入的 out 对象
|
||||
* @returns @en The result frustum, same as the `out` parameter. @zh 存储结果的视锥体,与 `out` 参数为同一个对象。
|
||||
*/
|
||||
public static copy (out: Frustum, f: Readonly<Frustum>): Frustum {
|
||||
out._type = f.type;
|
||||
@@ -205,7 +204,7 @@ export class Frustum {
|
||||
|
||||
/**
|
||||
* @en
|
||||
* Set whether to use accurate intersection testing function on this frustum.
|
||||
* Sets whether to use accurate intersection testing function on this frustum.
|
||||
* @zh
|
||||
* 设置是否在此截锥体上使用精确的相交测试函数。
|
||||
*/
|
||||
@@ -215,16 +214,29 @@ export class Frustum {
|
||||
|
||||
/**
|
||||
* @en
|
||||
* Gets the type of the shape.
|
||||
* Gets the type of the shape. The value may be `enums.SHAPE_FRUSTUM_ACCURATE` or `enums.SHAPE_FRUSTUM`.
|
||||
* @zh
|
||||
* 获取形状的类型。
|
||||
* 获取形状的类型。值可能为 `enums.SHAPE_FRUSTUM_ACCURATE` 或 `enums.SHAPE_FRUSTUM`。
|
||||
* @readonly
|
||||
*/
|
||||
get type () {
|
||||
return this._type;
|
||||
}
|
||||
|
||||
/**
|
||||
* @en
|
||||
* The 6 planes of the frustum.
|
||||
* @zh
|
||||
* 视椎体的 6 个面。
|
||||
*/
|
||||
public planes: Plane[];
|
||||
|
||||
/**
|
||||
* @en
|
||||
* The 8 vertices of the frustum.
|
||||
* @zh
|
||||
* 视椎体的 8 个顶点。
|
||||
*/
|
||||
public vertices: Vec3[];
|
||||
|
||||
protected _type: number;
|
||||
@@ -243,12 +255,12 @@ export class Frustum {
|
||||
|
||||
/**
|
||||
* @en
|
||||
* Update the frustum information according to the given transform matrix.
|
||||
* Updates the frustum information according to the given transform matrix.
|
||||
* Note that the resulting planes are not normalized under normal mode.
|
||||
* @zh
|
||||
* 根据给定的变换矩阵更新截锥体信息,注意得到的平面不是在标准模式下归一化的。
|
||||
* @param m @en The view-projection matrix @zh 视图投影矩阵
|
||||
* @param inv @en The inverse view-projection matrix @zh 视图投影逆矩阵
|
||||
* @param m @en The view-projection matrix. @zh 视图投影矩阵。
|
||||
* @param inv @en The inverse view-projection matrix. @zh 视图投影逆矩阵。
|
||||
*/
|
||||
public update (m: Mat4, inv: Mat4) {
|
||||
// RTR4, ch. 22.14.1, p. 983
|
||||
@@ -291,10 +303,10 @@ export class Frustum {
|
||||
|
||||
/**
|
||||
* @en
|
||||
* Transform this frustum.
|
||||
* Transforms this frustum.
|
||||
* @zh
|
||||
* 变换此视锥体。
|
||||
* @param mat @en The transform matrix @zh 变换矩阵
|
||||
* @param mat @en The transform matrix. @zh 变换矩阵。
|
||||
*/
|
||||
public transform (mat: Mat4) {
|
||||
if (this._type !== enums.SHAPE_FRUSTUM_ACCURATE) {
|
||||
@@ -307,8 +319,8 @@ export class Frustum {
|
||||
}
|
||||
|
||||
/**
|
||||
* @en Initialize the frustum
|
||||
* @zh 初始化视锥体
|
||||
* @en Makes the frustum empty, all vertices will be zero values.
|
||||
* @zh 置空此视锥体,所有顶点将被赋值为 0。
|
||||
*/
|
||||
public zero () {
|
||||
for (let i = 0; i < 8; i++) {
|
||||
@@ -318,8 +330,8 @@ export class Frustum {
|
||||
}
|
||||
|
||||
/**
|
||||
* @en Update all six planes of the frustum
|
||||
* @zh 更新视锥体的所有面数据
|
||||
* @en Updates all six planes of the frustum.
|
||||
* @zh 更新视锥体的所有面数据。
|
||||
*/
|
||||
public updatePlanes () {
|
||||
// left plane
|
||||
|
||||
@@ -45,9 +45,9 @@ import type { Mesh } from '../../3d';
|
||||
* ray-plane intersect detect.
|
||||
* @zh
|
||||
* 射线与平面的相交性检测。
|
||||
* @param ray @zh 射线 @en The ray to test
|
||||
* @param plane @zh 平面 @en The plane to test
|
||||
* @return @zh 0 或 非0 @en 0 or not 0, 0 indicates there is no intersection
|
||||
* @param ray @zh 要测试的射线。 @en The ray to test.
|
||||
* @param plane @zh 要测试的平面。 @en The plane to test.
|
||||
* @returns @zh 如果没有相交,返回 0 ,否则返回非 0。 @en zero if no intersection, otherwise returns a non-zero value.
|
||||
*/
|
||||
const rayPlane = (function () {
|
||||
const pt = new Vec3(0, 0, 0);
|
||||
@@ -68,10 +68,10 @@ const rayPlane = (function () {
|
||||
* ray-triangle intersect detect.
|
||||
* @zh
|
||||
* 射线与三角形的相交性检测。
|
||||
* @param ray @zh 射线 @en The ray to test
|
||||
* @param triangle @zh 三角形 @en The triangle to test
|
||||
* @param doubleSided @zh 三角形是否为双面 @en Indicates whether it is double sided
|
||||
* @return @zh 0 或 非0 @en 0 or not 0, 0 indicates there is no intersection
|
||||
* @param ray @zh 要测试的射线。 @en The ray to test.
|
||||
* @param triangle @zh 用来测试三角形。 @en The triangle to test.
|
||||
* @param doubleSided @zh 要测试的三角形是否为双面。 @en Indicates whether the triangle to test is double sided.
|
||||
* @returns @zh 0 或 非 0,0 表示没有相交。@en 0 or not 0, 0 indicates there is no intersection.
|
||||
*/
|
||||
const rayTriangle = (function () {
|
||||
const ab = new Vec3(0, 0, 0);
|
||||
@@ -108,9 +108,9 @@ const rayTriangle = (function () {
|
||||
* ray-sphere intersect detect.
|
||||
* @zh
|
||||
* 射线和球的相交性检测。
|
||||
* @param ray @zh 射线 @en The ray to test
|
||||
* @param sphere @zh 球 @en The sphere to test
|
||||
* @return @zh 0 或 非0 @en 0 or not 0, 0 indicates there is no intersection
|
||||
* @param ray @zh 要测试的射线。 @en The ray to test.
|
||||
* @param sphere @zh 要测试的球。 @en The sphere to test.
|
||||
* @returns @zh 如果没有相交,返回 0 ,否则返回非 0。 @en zero if no intersection, otherwise returns a non-zero value.
|
||||
*/
|
||||
const raySphere = (function () {
|
||||
const e = new Vec3(0, 0, 0);
|
||||
@@ -139,9 +139,9 @@ const raySphere = (function () {
|
||||
* ray-aabb intersect detect.
|
||||
* @zh
|
||||
* 射线和轴对齐包围盒的相交性检测。
|
||||
* @param ray @zh 射线 @en The ray to test
|
||||
* @param aabb @zh 轴对齐包围盒 @en The aabb to test
|
||||
* @return @zh 0 或 非0 @en 0 or not 0, 0 indicates there is no intersection
|
||||
* @param ray @zh 要测试的射线。 @en The ray to test.
|
||||
* @param aabb @zh 要测试的 AABB。 @en The aabb to test.
|
||||
* @returns @zh 如果没有相交,返回 0 ,否则返回非 0。 @en zero if no intersection, otherwise returns a non-zero value.
|
||||
*/
|
||||
const rayAABB = (function () {
|
||||
const min = new Vec3();
|
||||
@@ -172,10 +172,10 @@ function rayAABB2 (ray: Ray, min: IVec3Like, max: IVec3Like) {
|
||||
* @en
|
||||
* ray-obb intersect detect.
|
||||
* @zh
|
||||
* 射线和方向包围盒的相交性检测。
|
||||
* @param ray @zh 射线 @en The ray
|
||||
* @param obb @zh 方向包围盒 @en The obb to test
|
||||
* @return @zh 0 或非 0 @en 0 or not 0, 0 indicates there is no intersection
|
||||
* 射线和 OBB 的相交性检测。
|
||||
* @param ray @zh 要测试的射线。 @en The ray to test.
|
||||
* @param obb @zh 要测试的 OBB。 @en The OBB to test.
|
||||
* @returns @zh 如果没有相交,返回 0 ,否则返回非 0。 @en zero if no intersection, otherwise returns a non-zero value.
|
||||
*/
|
||||
const rayOBB = (function () {
|
||||
let center = new Vec3();
|
||||
@@ -253,9 +253,9 @@ const rayOBB = (function () {
|
||||
* ray-capsule intersect detect.
|
||||
* @zh
|
||||
* 射线和胶囊体的相交性检测。
|
||||
* @param ray @zh 射线 @en The ray to test
|
||||
* @param capsule @zh 胶囊体 @en The capsule to test
|
||||
* @return @zh 0 或非 0 @en 0 or not 0, 0 indicates there is no intersection
|
||||
* @param ray @zh 要测试的射线。 @en The ray to test.
|
||||
* @param capsule @zh 要测试的胶囊体。 @en The capsule to test.
|
||||
* @returns @zh 如果没有相交,返回 0 ,否则返回非 0。 @en zero if no intersection, otherwise returns a non-zero value.
|
||||
*/
|
||||
const rayCapsule = (function () {
|
||||
const v3_0 = new Vec3();
|
||||
@@ -339,9 +339,9 @@ const rayCapsule = (function () {
|
||||
* line-plane intersect detect.
|
||||
* @zh
|
||||
* 线段与平面的相交性检测。
|
||||
* @param line @zh 线段 @en The line to test
|
||||
* @param plane @zh 平面 @en The plane to test
|
||||
* @return @zh 0 或非 0 @en 0 or not 0, 0 indicates there is no intersection
|
||||
* @param line @zh 要测试的线段。 @en The line to test.
|
||||
* @param plane @zh 要测试的平面。 @en The plane to test.
|
||||
* @returns @zh 如果没有相交,返回 0 ,否则返回非 0。 @en zero if no intersection, otherwise returns a non-zero value.
|
||||
*/
|
||||
const linePlane = (function () {
|
||||
const ab = new Vec3(0, 0, 0);
|
||||
@@ -359,10 +359,10 @@ const linePlane = (function () {
|
||||
* line-triangle intersect detect.
|
||||
* @zh
|
||||
* 线段与三角形的相交性检测。
|
||||
* @param line @zh 线段 @en The line to test
|
||||
* @param triangle @zh 三角形 @en The triangle to test
|
||||
* @param outPt @zh 可选,相交点 @en Optional out param, indicates the intersection point
|
||||
* @return @zh 0 或非 0 @en 0 or not 0, 0 indicates there is no intersection
|
||||
* @param line @zh 线段 @en The line to test.
|
||||
* @param triangle @zh 三角形 @en The triangle to test.
|
||||
* @param outPt @zh 可选,相交点 @en Optional out param, indicates the intersection point.
|
||||
* @returns @zh 如果没有相交,返回 0 ,否则返回非 0。 @en zero if no intersection, otherwise returns a non-zero value.
|
||||
*/
|
||||
const lineTriangle = (function () {
|
||||
const ab = new Vec3(0, 0, 0);
|
||||
@@ -426,7 +426,7 @@ const r_t = new Ray();
|
||||
* 线段与轴对齐包围盒的相交性检测
|
||||
* @param line @zh 线段 @en The line to test
|
||||
* @param aabb @zh 轴对齐包围盒 @en The aabb to test
|
||||
* @return @zh 0 或非 0 @en 0 or not 0, 0 indicates there is no intersection
|
||||
* @returns @zh 如果没有相交,返回 0 ,否则返回非 0。 @en zero if no intersection, otherwise returns a non-zero value.no intersection
|
||||
*/
|
||||
function lineAABB (line: Line, aabb: AABB): number {
|
||||
r_t.o.set(line.s);
|
||||
@@ -445,10 +445,10 @@ function lineAABB (line: Line, aabb: AABB): number {
|
||||
* @en
|
||||
* line-obb intersect detect.
|
||||
* @zh
|
||||
* 线段与方向包围盒的相交性检测
|
||||
* @param line @zh 线段 @en The line to test
|
||||
* @param obb @zh 方向包围盒 @en The obb
|
||||
* @return @zh 0 或非 0 @en 0 or not 0, 0 indicates there is no intersection
|
||||
* 线段与OBB的相交性检测。
|
||||
* @param line @zh 线段 @en The line to test.
|
||||
* @param obb @zh OBB @en The OBB to test.
|
||||
* @returns @zh 如果没有相交,返回 0 ,否则返回非 0。 @en zero if no intersection, otherwise returns a non-zero value.no intersection
|
||||
*/
|
||||
function lineOBB (line: Line, obb: OBB): number {
|
||||
r_t.o.set(line.s);
|
||||
@@ -470,7 +470,7 @@ function lineOBB (line: Line, obb: OBB): number {
|
||||
* 线段与球的相交性检测
|
||||
* @param line @zh 线段 @en The line to test
|
||||
* @param sphere @zh 球 @en The sphere to test
|
||||
* @return @zh 0 或非 0 @en 0 or not 0, 0 indicates there is no intersection
|
||||
* @returns @zh 如果没有相交,返回 0 ,否则返回非 0。 @en zero if no intersection, otherwise returns a non-zero value.no intersection
|
||||
*/
|
||||
function lineSphere (line: Line, sphere: Sphere): number {
|
||||
r_t.o.set(line.s);
|
||||
@@ -492,7 +492,7 @@ function lineSphere (line: Line, sphere: Sphere): number {
|
||||
* 轴对齐包围盒和轴对齐包围盒的相交性检测。
|
||||
* @param aabb1 @zh 轴对齐包围盒1 @en aabb 1 to test
|
||||
* @param aabb2 @zh 轴对齐包围盒2 @en aabb 2 to test
|
||||
* @return @zh 0 或非 0 @en 0 or not 0, 0 indicates there is no intersection
|
||||
* @returns @zh 如果没有相交,返回 0 ,否则返回非 0。 @en zero if no intersection, otherwise returns a non-zero value.no intersection
|
||||
*/
|
||||
const aabbWithAABB = (function () {
|
||||
const aMin = new Vec3();
|
||||
@@ -570,10 +570,10 @@ function getInterval (vertices: any[] | Vec3[], axis: Vec3) {
|
||||
* @en
|
||||
* aabb-obb intersect detect.
|
||||
* @zh
|
||||
* 轴对齐包围盒和方向包围盒的相交性检测。
|
||||
* 轴对齐包围盒和OBB的相交性检测。
|
||||
* @param aabb @zh 轴对齐包围盒 @en The aabb to test
|
||||
* @param obb @zh 方向包围盒 @en The obb to test
|
||||
* @return @zh 0 或非 0 @en 0 or not 0, 0 indicates there is no intersection
|
||||
* @param obb @zh OBB @en The OBB to test
|
||||
* @returns @zh 如果没有相交,返回 0 ,否则返回非 0。 @en zero if no intersection, otherwise returns a non-zero value.no intersection
|
||||
*/
|
||||
const aabbWithOBB = (function () {
|
||||
const test = new Array(15);
|
||||
@@ -626,7 +626,7 @@ const aabbWithOBB = (function () {
|
||||
* 轴对齐包围盒和平面的相交性检测。
|
||||
* @param aabb @zh 轴对齐包围盒 @en The aabb to test
|
||||
* @param plane @zh 平面 @en The plane to test
|
||||
* @return @zh 检测结果, 包含为 -1, 不包含为 0, 相交为 1 @en Test result, inside(back) = -1, outside(front) = 0, intersect = 1
|
||||
* @returns @zh 检测结果, 包含为 -1, 不包含为 0, 相交为 1 @en Test result, inside(back) = -1, outside(front) = 0, intersect = 1
|
||||
*/
|
||||
const aabbPlane = function (aabb: AABB, plane: Plane): number {
|
||||
const r = aabb.halfExtents.x * Math.abs(plane.n.x)
|
||||
@@ -644,7 +644,7 @@ const aabbPlane = function (aabb: AABB, plane: Plane): number {
|
||||
* 轴对齐包围盒和锥台相交性检测,速度快,但有错误情况。
|
||||
* @param aabb @zh 轴对齐包围盒 @en The aabb to test
|
||||
* @param frustum @zh 锥台 @en The frustum to test
|
||||
* @return @zh 0 或非 0 @en 0 or not 0, 0 indicates there is no intersection
|
||||
* @returns @zh 如果没有相交,返回 0 ,否则返回非 0。 @en zero if no intersection, otherwise returns a non-zero value.no intersection
|
||||
*/
|
||||
const aabbFrustum = function (aabb: AABB, frustum: Readonly<Frustum>): number {
|
||||
for (let i = 0; i < frustum.planes.length; i++) {
|
||||
@@ -663,7 +663,7 @@ const aabbFrustum = function (aabb: AABB, frustum: Readonly<Frustum>): number {
|
||||
* 轴对齐包围盒和锥台的相交性检测。速度快,但是当锥台完全在aabb中时就会判断出错。
|
||||
* @param {AABB} aabb 轴对齐包围盒
|
||||
* @param {Frustum} frustum 锥台
|
||||
* @return {number} aabb completely inside the frustum = 1, otherwise = 0
|
||||
* @returns {number} aabb completely inside the frustum = 1, otherwise = 0
|
||||
*/
|
||||
const aabbFrustumCompletelyInside = function (aabb: AABB, frustum: Readonly<Frustum>): number {
|
||||
for (let i = 0; i < frustum.planes.length; i++) {
|
||||
@@ -683,7 +683,7 @@ const aabbFrustumCompletelyInside = function (aabb: AABB, frustum: Readonly<Frus
|
||||
* 轴对齐包围盒和锥台相交性检测,正确处理大多数错误情况。
|
||||
* @param aabb @zh 轴对齐包围盒 @en The aabb to test
|
||||
* @param frustum @zh 锥台 @en The frustum to test
|
||||
* @return @zh 0 或非 0 @en 0 or not 0, 0 indicates there is no intersection
|
||||
* @returns @zh 如果没有相交,返回 0 ,否则返回非 0。 @en zero if no intersection, otherwise returns a non-zero value.no intersection
|
||||
*/
|
||||
const aabbFrustumAccurate = (function () {
|
||||
const tmp = new Array(8);
|
||||
@@ -727,12 +727,12 @@ const aabbFrustumAccurate = (function () {
|
||||
|
||||
/**
|
||||
* @en
|
||||
* obb contains the point.
|
||||
* Checks whether the OBB contains the point.
|
||||
* @zh
|
||||
* 方向包围盒和点的相交性检测。
|
||||
* @param obb @zh 方向包围盒 @en The obb to test
|
||||
* @param point @zh 点 @en The point to test
|
||||
* @return @zh 布尔值 @en The value indicates if there is a intersection
|
||||
* OBB 和点的相交性检测。
|
||||
* @param obb @zh 参与测试的 OBB。 @en The OBB to test.
|
||||
* @param point @zh 参与测试的点。 @en The point to test.
|
||||
* @returns @zh 是否相交 @en The value indicates if there is an intersection.
|
||||
*/
|
||||
const obbPoint = (function () {
|
||||
const tmp = new Vec3(0, 0, 0); const m3 = new Mat3();
|
||||
@@ -748,10 +748,10 @@ const obbPoint = (function () {
|
||||
* @en
|
||||
* obb-plane intersect detect.
|
||||
* @zh
|
||||
* 方向包围盒和平面的相交性检测。
|
||||
* @param obb @zh 方向包围盒 @en The obb to test
|
||||
* OBB 和平面的相交性检测。
|
||||
* @param obb @zh OBB @en The OBB to test
|
||||
* @param plane @zh 平面 @en The plane to test
|
||||
* @return @zh 检测结果, 包含为 -1, 不包含为 0, 相交为 1 @en Test result, inside(back) = -1, outside(front) = 0, intersect = 1
|
||||
* @returns @zh 检测结果, 包含为 -1, 不包含为 0, 相交为 1 @en Test result, inside(back) = -1, outside(front) = 0, intersect = 1
|
||||
*/
|
||||
const obbPlane = (function () {
|
||||
const absDot = function (n: Vec3, x: number, y: number, z: number) {
|
||||
@@ -771,12 +771,12 @@ const obbPlane = (function () {
|
||||
|
||||
/**
|
||||
* @en
|
||||
* obb-frustum intersect, faster but has false positive corner cases.
|
||||
* OBB-frustum intersect, faster but has false positive corner cases.
|
||||
* @zh
|
||||
* 方向包围盒和锥台相交性检测,速度快,但有错误情况。
|
||||
* @param obb @zh 方向包围盒 @en The obb to test
|
||||
* @param frustum @zh 锥台 @en The frustum to test
|
||||
* @return @zh 0 或非 0 @en 0 or not 0, 0 indicates there is no intersection
|
||||
* OBB 和锥台相交性检测,速度快,但有错误情况。
|
||||
* @param obb @zh OBB @en The OBB to test.
|
||||
* @param frustum @zh 锥台 @en The frustum to test.
|
||||
* @returns @zh 如果没有相交,返回 0 ,否则返回非 0。 @en zero if no intersection, otherwise returns a non-zero value.
|
||||
*/
|
||||
const obbFrustum = function (obb: OBB, frustum: Frustum): number {
|
||||
for (let i = 0; i < frustum.planes.length; i++) {
|
||||
@@ -793,10 +793,10 @@ const obbFrustum = function (obb: OBB, frustum: Frustum): number {
|
||||
* @en
|
||||
* obb-frustum intersect, handles most of the false positives correctly.
|
||||
* @zh
|
||||
* 方向包围盒和锥台相交性检测,正确处理大多数错误情况。
|
||||
* @param obb @zh 方向包围盒 @en The obb to test
|
||||
* OBB 和锥台相交性检测,正确处理大多数错误情况。
|
||||
* @param obb @zh OBB @en The OBB to test
|
||||
* @param frustum @zh 锥台 @en The frustum to test
|
||||
* @return @zh 0 或非 0 @en 0 or not 0, 0 indicates there is no intersection
|
||||
* @returns @zh 如果没有相交,返回 0 ,否则返回非 0。 @en zero if no intersection, otherwise returns a non-zero value.no intersection
|
||||
*/
|
||||
const obbFrustumAccurate = (function () {
|
||||
const tmp = new Array(8);
|
||||
@@ -848,10 +848,10 @@ const obbFrustumAccurate = (function () {
|
||||
* @en
|
||||
* obb-obb intersect detect.
|
||||
* @zh
|
||||
* 方向包围盒和方向包围盒的相交性检测。
|
||||
* @param obb1 @zh 方向包围盒1 @en Obb 1 to test
|
||||
* @param obb2 @zh 方向包围盒2 @en Obb 2 to test
|
||||
* @return @zh 0 或非 0 @en 0 or not 0, 0 indicates there is no intersection
|
||||
* OBB 和OBB的相交性检测。
|
||||
* @param obb1 @zh OBB1 @en Obb 1 to test
|
||||
* @param obb2 @zh OBB2 @en Obb 2 to test
|
||||
* @returns @zh 如果没有相交,返回 0 ,否则返回非 0。 @en zero if no intersection, otherwise returns a non-zero value.no intersection
|
||||
*/
|
||||
const obbWithOBB = (function () {
|
||||
const test = new Array(15);
|
||||
@@ -898,12 +898,12 @@ const obbWithOBB = (function () {
|
||||
// https://github.com/diku-dk/bvh-tvcg18/blob/1fd3348c17bc8cf3da0b4ae60fdb8f2aa90a6ff0/FOUNDATION/GEOMETRY/GEOMETRY/include/overlap/geometry_overlap_obb_capsule.h
|
||||
/**
|
||||
* @en
|
||||
* obb-capsule intersect detect.
|
||||
* OBB-capsule intersect detect.
|
||||
* @zh
|
||||
* 方向包围盒和胶囊体的相交性检测。
|
||||
* @param obb @zh 方向包围盒 @en The obb to test
|
||||
* @param capsule @zh 胶囊体 @en The capsule to test
|
||||
* @return @zh 0 或非 0 @en 0 or not 0, 0 indicates there is no intersection
|
||||
* OBB 和胶囊体的相交性检测。
|
||||
* @param obb @zh OBB @en The OBB to test.
|
||||
* @param capsule @zh 胶囊体 @en The capsule to test.
|
||||
* @returns @zh 如果没有相交,返回 0 ,否则返回非 0。 @en zero if no intersection, otherwise returns a non-zero value.
|
||||
*/
|
||||
const obbCapsule = (function () {
|
||||
const sphere_0 = new Sphere();
|
||||
@@ -969,7 +969,7 @@ const obbCapsule = (function () {
|
||||
* 球与平面的相交性检测。
|
||||
* @param sphere @zh 球 @en The sphere to test
|
||||
* @param plane @zh 平面 @en The plane to test
|
||||
* @return @zh 检测结果, 包含为 -1, 不包含为 0, 相交为 1 @en Test result, inside(back) = -1, outside(front) = 0, intersect = 1
|
||||
* @returns @zh 检测结果, 包含为 -1, 不包含为 0, 相交为 1 @en Test result, inside(back) = -1, outside(front) = 0, intersect = 1
|
||||
*/
|
||||
const spherePlane = function (sphere: Sphere, plane: Plane): number {
|
||||
const dot = Vec3.dot(plane.n, sphere.center);
|
||||
@@ -985,7 +985,7 @@ const spherePlane = function (sphere: Sphere, plane: Plane): number {
|
||||
* 球和锥台的相交性检测,速度快,但有错误情况。
|
||||
* @param sphere @zh 球 @en The sphere to test
|
||||
* @param frustum @zh 锥台 @en The frustum to test
|
||||
* @return @zh 0 或非 0 @en 0 or not 0, 0 indicates there is no intersection
|
||||
* @returns @zh 如果没有相交,返回 0 ,否则返回非 0。 @en zero if no intersection, otherwise returns a non-zero value.no intersection
|
||||
*/
|
||||
const sphereFrustum = function (sphere: Sphere, frustum: Frustum): number {
|
||||
for (let i = 0; i < frustum.planes.length; i++) {
|
||||
@@ -1005,7 +1005,7 @@ const sphereFrustum = function (sphere: Sphere, frustum: Frustum): number {
|
||||
* 球和锥台的相交性检测,正确处理大多数错误情况。
|
||||
* @param sphere @zh 球 @en The sphere to test
|
||||
* @param frustum @zh 锥台 @en The frustum to test
|
||||
* @return @zh 0 或非 0 @en 0 or not 0, 0 indicates there is no intersection
|
||||
* @returns @zh 如果没有相交,返回 0 ,否则返回非 0。 @en zero if no intersection, otherwise returns a non-zero value.no intersection
|
||||
*/
|
||||
const sphereFrustumAccurate = (function () {
|
||||
const pt = new Vec3(0, 0, 0); const map = [1, -1, 1, -1, 1, -1];
|
||||
@@ -1038,7 +1038,7 @@ const sphereFrustumAccurate = (function () {
|
||||
* 球和球的相交性检测。
|
||||
* @param sphere0 @zh 球 0 @en The sphere A to test
|
||||
* @param sphere1 @zh 球 1 @en The sphere B to test
|
||||
* @return @zh 是否发生碰撞 @en true or false which indicates if there is a intersection
|
||||
* @returns @zh 是否发生碰撞 @en true or false which indicates if there is an intersection
|
||||
*/
|
||||
const sphereWithSphere = function (sphere0: Sphere, sphere1: Sphere): boolean {
|
||||
const r = sphere0.radius + sphere1.radius;
|
||||
@@ -1052,7 +1052,7 @@ const sphereWithSphere = function (sphere0: Sphere, sphere1: Sphere): boolean {
|
||||
* 球和轴对齐包围盒的相交性检测。
|
||||
* @param sphere @zh 球 @en The sphere to test
|
||||
* @param aabb @zh 轴对齐包围盒 @en The aabb to test
|
||||
* @return @zh 是否发生碰撞 @en true or false which indicates if there is a intersection
|
||||
* @returns @zh 是否发生碰撞 @en true or false which indicates if there is an intersection
|
||||
*/
|
||||
const sphereAABB = (function () {
|
||||
const pt = new Vec3();
|
||||
@@ -1064,12 +1064,12 @@ const sphereAABB = (function () {
|
||||
|
||||
/**
|
||||
* @en
|
||||
* sphere-obb intersect detect.
|
||||
* sphere-OBB intersect detect.
|
||||
* @zh
|
||||
* 球和方向包围盒的相交性检测。
|
||||
* @param sphere @zh 球 @en The sphere to test
|
||||
* @param obb @zh 方向包围盒 @en The obb to test
|
||||
* @return @zh 是否发生碰撞 @en true or false which indicates if there is a intersection
|
||||
* 球和 OBB 的相交性检测。
|
||||
* @param sphere @zh 参与测试的球。 @en The sphere to test.
|
||||
* @param obb @zh 参与测试的 OBB。 @en The OBB to test.
|
||||
* @returns @zh 是否发生碰撞。 @en true or false which indicates if there is an intersection.
|
||||
*/
|
||||
const sphereOBB = (function () {
|
||||
const pt = new Vec3();
|
||||
@@ -1084,9 +1084,9 @@ const sphereOBB = (function () {
|
||||
* sphere-capsule intersect detect.
|
||||
* @zh
|
||||
* 球和胶囊体的相交性检测。
|
||||
* @param sphere @zh 球 @en The sphere to test
|
||||
* @param capsule @zh 胶囊体 @en The capsule to test
|
||||
* @return @zh 是否发生碰撞 @en true or false which indicates if there is a intersection
|
||||
* @param sphere @zh 参与测试的球。 @en The sphere to test.
|
||||
* @param capsule @zh 参与测试的胶囊体。 @en The capsule to test.
|
||||
* @returns @zh 是否发生碰撞。 @en true or false which indicates if there is an intersection.
|
||||
*/
|
||||
const sphereCapsule = (function () {
|
||||
const v3_0 = new Vec3();
|
||||
@@ -1119,9 +1119,9 @@ const sphereCapsule = (function () {
|
||||
* capsule-capsule intersect detect.
|
||||
* @zh
|
||||
* 胶囊体和胶囊体的相交性检测。
|
||||
* @param capsuleA @zh 胶囊体 A @en The capsule A to test
|
||||
* @param capsuleB @zh 胶囊体 B @en The capsule B to test
|
||||
* @return @zh 是否发生碰撞 @en true or false which indicates if there is a intersection
|
||||
* @param capsuleA @zh 要测试的胶囊体 A。 @en The capsule A to test.
|
||||
* @param capsuleB @zh 要测试的胶囊体 B。 @en The capsule B to test.
|
||||
* @returns @zh 如果相交,返回 true,否则返回 false。 @en true if there is an intersection, otherwise returns false.
|
||||
*/
|
||||
const capsuleWithCapsule = (function () {
|
||||
const v3_0 = new Vec3();
|
||||
|
||||
+52
-52
@@ -29,21 +29,21 @@ import enums from './enums';
|
||||
* @en
|
||||
* Basic Geometry: Line.
|
||||
* @zh
|
||||
* 基础几何 line。
|
||||
* 基础几何:直线。
|
||||
*/
|
||||
export class Line {
|
||||
/**
|
||||
* @en
|
||||
* create a new line
|
||||
* Creates a new line.
|
||||
* @zh
|
||||
* 创建一个新的 line。
|
||||
* @param sx @en Start position x @zh 起点的 x 坐标。
|
||||
* @param sy @en Start position y @zh 起点的 y 坐标。
|
||||
* @param sz @en Start position z @zh 起点的 z 坐标。
|
||||
* @param ex @en End position x @zh 终点的 x 坐标。
|
||||
* @param ey @en End position y @zh 终点的 y 坐标。
|
||||
* @param ez @en End position z @zh 终点的 z 坐标。
|
||||
* @return
|
||||
* 创建一条新的直线。
|
||||
* @param sx @en The x coordinate of the start position. @zh 起点的 x 坐标。
|
||||
* @param sy @en The y coordinate of the start position. @zh 起点的 y 坐标。
|
||||
* @param sz @en The z coordinate of the start position. @zh 起点的 z 坐标。
|
||||
* @param ex @en The x coordinate of the end position. @zh 终点的 x 坐标。
|
||||
* @param ey @en The y coordinate of the end position. @zh 终点的 y 坐标。
|
||||
* @param ez @en the z coordinate of the end position. @zh 终点的 z 坐标。
|
||||
* @returns @en The created line. @zh 创建的直线。
|
||||
*/
|
||||
public static create (sx: number, sy: number, sz: number, ex: number, ey: number, ez: number) {
|
||||
return new Line(sx, sy, sz, ex, ey, ez);
|
||||
@@ -51,11 +51,11 @@ export class Line {
|
||||
|
||||
/**
|
||||
* @en
|
||||
* Creates a new Line initialized with values from an existing Line
|
||||
* Creates a new Line initialized with values from an existing Line.
|
||||
* @zh
|
||||
* 克隆一个新的 line。
|
||||
* @param a @en The line to clone from @zh 克隆的来源 Line 对象。
|
||||
* @return @en The new line cloned @zh 克隆出的新 Line 对象
|
||||
* 克隆一条新的直线。
|
||||
* @param a @en The line to clone from. @zh 克隆的来源 Line 对象。
|
||||
* @returns @en The cloned line. @zh 克隆出的新 Line 对象。
|
||||
*/
|
||||
public static clone (a: Line) {
|
||||
return new Line(
|
||||
@@ -66,12 +66,12 @@ export class Line {
|
||||
|
||||
/**
|
||||
* @en
|
||||
* Copy the values from one Line to another
|
||||
* Copies the values from one Line to another.
|
||||
* @zh
|
||||
* 复制一个线的值到另一个。
|
||||
* @param out @en The output line to store the copied data @zh 用来存储拷贝数据的 Line 对象
|
||||
* @param a @en The line to copy from @zh 从这个 Line 对象拷贝信息。
|
||||
* @return @en The out object @zh 会直接返回传入的 out 对象
|
||||
* 复制一条直线的值到另一条直线中。
|
||||
* @param out @en The output line to store the copied data. @zh 用来存储拷贝数据的 Line 对象。
|
||||
* @param a @en The line to copy from. @zh 从这个 Line 对象拷贝信息。
|
||||
* @returns @en The `out` parameter. @zh 传入的 `out` 对象。
|
||||
*/
|
||||
public static copy (out: Line, a: Line) {
|
||||
Vec3.copy(out.s, a.s);
|
||||
@@ -82,13 +82,13 @@ export class Line {
|
||||
|
||||
/**
|
||||
* @en
|
||||
* create a line from two points
|
||||
* Creates a line from two points.
|
||||
* @zh
|
||||
* 用两个点创建一个线。
|
||||
* @param out @en The output line @zh 接受新数据的 Line 对象
|
||||
* @param start @en The start point @zh 起点
|
||||
* @param end @en The end point @zh 终点
|
||||
* @return @en The out object @zh 会直接返回传入的 out 对象
|
||||
* 用两个点创建一条直线。
|
||||
* @param out @en The output line. @zh 接受新数据的 Line 对象。
|
||||
* @param start @en The start point. @zh 起点。
|
||||
* @param end @en The end point. @zh 终点。
|
||||
* @returns @en The `out` parameter. @zh 传入的 out 对象。
|
||||
*/
|
||||
public static fromPoints (out: Line, start: Vec3, end: Vec3) {
|
||||
Vec3.copy(out.s, start);
|
||||
@@ -98,17 +98,17 @@ export class Line {
|
||||
|
||||
/**
|
||||
* @en
|
||||
* Set the components of a Vec3 to the given values
|
||||
* Sets the start point and the end point of a line with the given values.
|
||||
* @zh
|
||||
* 将给定线的属性设置为给定值。
|
||||
* @param out @en The output line to set properties to @zh 接受新数据的 Line 对象
|
||||
* @param sx @en Start position x @zh 起点到 x 坐标
|
||||
* @param sy @en Start position y @zh 起点到 y 坐标
|
||||
* @param sz @en Start position z @zh 起点到 z 坐标
|
||||
* @param ex @en End position x @zh 终点到 x 坐标
|
||||
* @param ey @en End position y @zh 终点到 y 坐标
|
||||
* @param ez @en End position z @zh 终点到 z 坐标
|
||||
* @return @en The out object @zh 会直接返回传入的 out 对象
|
||||
* 将给定线段的起点和终点设置为给定值。
|
||||
* @param out @en The output line to set properties. to @zh 接受新数据的 Line 对象。
|
||||
* @param sx @en The x coordinate of the start position. @zh 起点的 x 坐标。
|
||||
* @param sy @en The y coordinate of the start position. @zh 起点的 y 坐标。
|
||||
* @param sz @en The z coordinate of the start position. @zh 起点的 z 坐标。
|
||||
* @param ex @en The x coordinate of the end position. @zh 终点的 x 坐标。
|
||||
* @param ey @en The y coordinate of the end position. @zh 终点的 y 坐标。
|
||||
* @param ez @en the z coordinate of the end position. @zh 终点的 z 坐标。
|
||||
* @returns @en The `out` parameter. @zh 传入的 `out` 对象。
|
||||
*/
|
||||
public static set (out: Line, sx: number, sy: number, sz: number, ex: number, ey: number, ez: number) {
|
||||
out.s.x = sx;
|
||||
@@ -122,30 +122,30 @@ export class Line {
|
||||
}
|
||||
|
||||
/**
|
||||
* @en Calculate the length of the given line
|
||||
* @en Calculates the length of the given line.
|
||||
* @zh 计算线的长度。
|
||||
* @param a @en The line @zh 用于计算长度的线段
|
||||
* @return @en The length of the given line @zh 线段的长度
|
||||
* @param a @en The line to calculate length. @zh 用于计算长度的线段。
|
||||
* @returns @en The length of the given line. @zh 线段的长度。
|
||||
*/
|
||||
public static len (a: Line) {
|
||||
return Vec3.distance(a.s, a.e);
|
||||
}
|
||||
|
||||
/**
|
||||
* @en Start point
|
||||
* @en The start point.
|
||||
* @zh 起点。
|
||||
*/
|
||||
public s: Vec3;
|
||||
|
||||
/**
|
||||
* @en End point
|
||||
* @en The end point.
|
||||
* @zh 终点。
|
||||
*/
|
||||
public e: Vec3;
|
||||
|
||||
/**
|
||||
* @en Gets the type of the shape.
|
||||
* @zh 获取形状的类型。
|
||||
* @en Gets the type of the shape. Always returns `enums.SHAPE_LINE`.
|
||||
* @zh 获取形状的类型,总是返回 `enums.SHAPE_LINE`。
|
||||
*/
|
||||
get type () {
|
||||
return this._type;
|
||||
@@ -154,14 +154,14 @@ export class Line {
|
||||
private readonly _type: number;
|
||||
|
||||
/**
|
||||
* @en Constructor of the line
|
||||
* @en Constructs a line.
|
||||
* @zh 构造一条线。
|
||||
* @param sx @en Start position x @zh 起点的 x 坐标
|
||||
* @param sy @en Start position y @zh 起点的 y 坐标
|
||||
* @param sz @en Start position z @zh 起点的 z 坐标
|
||||
* @param ex @en End position x @zh 终点的 x 坐标
|
||||
* @param ey @en End position y @zh 终点的 y 坐标
|
||||
* @param ez @en End position z @zh 终点的 z 坐标
|
||||
* @param sx @en The x coordinate of the start position. @zh 起点的 x 坐标。
|
||||
* @param sy @en The y coordinate of the start position. @zh 起点的 y 坐标。
|
||||
* @param sz @en The z coordinate of the start position. @zh 起点的 z 坐标。
|
||||
* @param ex @en The x coordinate of the end position. @zh 终点的 x 坐标。
|
||||
* @param ey @en The y coordinate of the end position. @zh 终点的 y 坐标。
|
||||
* @param ez @en the z coordinate of the end position. @zh 终点的 z 坐标。
|
||||
*/
|
||||
constructor (sx = 0, sy = 0, sz = 0, ex = 0, ey = 0, ez = -1) {
|
||||
this._type = enums.SHAPE_LINE;
|
||||
@@ -170,9 +170,9 @@ export class Line {
|
||||
}
|
||||
|
||||
/**
|
||||
* @en Calculate the length of the line
|
||||
* @zh 计算线的长度。
|
||||
* @return @en The length @zh 线段的长度
|
||||
* @en Calculates the length of the line.
|
||||
* @zh 计算线段的长度。
|
||||
* @returns @en The length of the line. @zh 线段的长度。
|
||||
*/
|
||||
public length () {
|
||||
return Vec3.distance(this.s, this.e);
|
||||
|
||||
+79
-59
@@ -39,33 +39,33 @@ const transform_extent_m3 = (out: Vec3, extent: Vec3, m3: Mat3) => {
|
||||
|
||||
/**
|
||||
* @en
|
||||
* Basic Geometry: directional bounding box.
|
||||
* Basic Geometry: Oriented bounding box.
|
||||
* @zh
|
||||
* 基础几何 方向包围盒。
|
||||
* 基础几何:方向包围盒。
|
||||
*/
|
||||
|
||||
export class OBB {
|
||||
/**
|
||||
* @en
|
||||
* create a new obb
|
||||
* Creates a new OBB instance
|
||||
* @zh
|
||||
* 创建一个新的 obb 实例。
|
||||
* 创建一个新的 OBB 实例。
|
||||
* @param cx @zh 形状的相对于原点的 X 坐标。 @en The x coordinate of origin.
|
||||
* @param cy @zh 形状的相对于原点的 Y 坐标。 @en The y coordinate of origin.
|
||||
* @param cz @zh 形状的相对于原点的 Z 坐标。 @en The z coordinate of origin.
|
||||
* @param hw @zh - obb 宽度的一半。 @en Half the width of the OBB.
|
||||
* @param hh @zh - obb 高度的一半。 @en Half the height of the OBB.
|
||||
* @param hl @zh - obb 长度的一半。 @en Half the length of the OBB.
|
||||
* @param ox_1 @zh 方向矩阵参数。 @en The x component of the one axis of the OBB.
|
||||
* @param ox_2 @zh 方向矩阵参数。 @en The x component of the second axis of the OBB.
|
||||
* @param ox_3 @zh 方向矩阵参数。 @en The x component of the third axis of the OBB.
|
||||
* @param oy_1 @zh 方向矩阵参数。 @en The y component of the one axis of the OBB.
|
||||
* @param oy_2 @zh 方向矩阵参数。 @en The y component of the second axis of the OBB.
|
||||
* @param oy_3 @zh 方向矩阵参数。 @en The y component of the third axis of the OBB.
|
||||
* @param oz_1 @zh 方向矩阵参数。 @en The z component of the one axis of the OBB.
|
||||
* @param oz_2 @zh 方向矩阵参数。 @en The z component of the second axis of the OBB.
|
||||
* @param oz_3 @zh 方向矩阵参数。 @en The z component of the third axis of the OBB.
|
||||
* @return @zh 返回一个 obb。 @en A new OBB.
|
||||
* @param hw @zh - OBB 宽度的一半。 @en Half the width of the OBB.
|
||||
* @param hh @zh - OBB 高度的一半。 @en Half the height of the OBB.
|
||||
* @param hl @zh - OBB 长度的一半。 @en Half the length of the OBB.
|
||||
* @param ox_1 @zh 方向矩阵参数,第 1 条轴的 x 分量。 @en The x component of the first axis of the OBB.
|
||||
* @param ox_2 @zh 方向矩阵参数,第 2 条轴的 x 分量。 @en The x component of the second axis of the OBB.
|
||||
* @param ox_3 @zh 方向矩阵参数,第 3 条轴的 x 分量。 @en The x component of the third axis of the OBB.
|
||||
* @param oy_1 @zh 方向矩阵参数,第 1 条轴的 y 分量。 @en The y component of the first axis of the OBB.
|
||||
* @param oy_2 @zh 方向矩阵参数,第 2 条轴的 y 分量。 @en The y component of the second axis of the OBB.
|
||||
* @param oy_3 @zh 方向矩阵参数,第 3 条轴的 y 分量。 @en The y component of the third axis of the OBB.
|
||||
* @param oz_1 @zh 方向矩阵参数,第 1 条轴的 z 分量。 @en The z component of the first axis of the OBB.
|
||||
* @param oz_2 @zh 方向矩阵参数,第 2 条轴的 z 分量。 @en The z component of the second axis of the OBB.
|
||||
* @param oz_3 @zh 方向矩阵参数,第 3 条轴的 z 分量。 @en The z component of the third axis of the OBB.
|
||||
* @returns @zh 返回新创建的 OBB 实例。 @en A new OBB instance.
|
||||
*/
|
||||
public static create (
|
||||
cx: number, cy: number, cz: number,
|
||||
@@ -79,11 +79,11 @@ export class OBB {
|
||||
|
||||
/**
|
||||
* @en
|
||||
* clone a new obb
|
||||
* Clones a new OBB instance.
|
||||
* @zh
|
||||
* 克隆一个 obb。
|
||||
* 克隆一个 OBB 实例。
|
||||
* @param a @zh 克隆的目标。 @en The input OBB.
|
||||
* @returns @zh The new OBB. @en 克隆出的新对象。
|
||||
* @returns @zh The cloned OBB instance. @en 克隆出的新对象。
|
||||
*/
|
||||
public static clone (a: OBB) {
|
||||
return new OBB(a.center.x, a.center.y, a.center.z,
|
||||
@@ -95,12 +95,12 @@ export class OBB {
|
||||
|
||||
/**
|
||||
* @en
|
||||
* copy the values from one obb to another
|
||||
* Copies the values from one OBB to another.
|
||||
* @zh
|
||||
* 将从一个 obb 的值复制到另一个 obb。
|
||||
* @param out @zh 接受操作的 obb。 @en The output OBB.
|
||||
* @param a @zh 被复制的 obb。 @en The input OBB.
|
||||
* @returns @zh out 接受操作的 obb。 @en The reference of the first parameter `out`.
|
||||
* 复制一个 OBB 的值到另一个 OBB 中。
|
||||
* @param out @zh 接受操作的 OBB。 @en The output OBB.
|
||||
* @param a @zh 被复制的 OBB。 @en The input OBB.
|
||||
* @returns @zh 接受操作的 OBB,与 `out` 参数相同。 @en The output OBB, same as the `out` parameter.
|
||||
*/
|
||||
public static copy (out: OBB, a: OBB): OBB {
|
||||
Vec3.copy(out.center, a.center);
|
||||
@@ -112,13 +112,13 @@ export class OBB {
|
||||
|
||||
/**
|
||||
* @en
|
||||
* create a new obb from two corner points
|
||||
* Creates a new OBB from two corner points.
|
||||
* @zh
|
||||
* 用两个点创建一个新的 obb。
|
||||
* @param out @zh - 接受操作的 obb。 @en The output OBB.
|
||||
* @param minPos @zh - obb 的最小点。 @en The minimum position of the AABB.
|
||||
* @param maxPos @zh - obb 的最大点。 @en The maximum position of the AABB.
|
||||
* @returns @zh {OBB} out 接受操作的 obb。 @en The reference of the first parameter `out`.
|
||||
* 用两个点创建一个新的 OBB。
|
||||
* @param out @zh - 接受操作的 OBB。 @en The output OBB.
|
||||
* @param minPos @zh - OBB 的最小点。 @en The minimum position of the AABB.
|
||||
* @param maxPos @zh - OBB 的最大点。 @en The maximum position of the AABB.
|
||||
* @returns @zh 接受操作的 OBB,与 `out` 参数相同。 @en The output OBB, same as the `out` parameter.
|
||||
*/
|
||||
public static fromPoints (out: OBB, minPos: Vec3, maxPos: Vec3): OBB {
|
||||
Vec3.multiplyScalar(out.center, Vec3.add(_v3_tmp, minPos, maxPos), 0.5);
|
||||
@@ -129,26 +129,26 @@ export class OBB {
|
||||
|
||||
/**
|
||||
* @en
|
||||
* Set the components of a obb to the given values
|
||||
* Sets the components of an OBB to the given values.
|
||||
* @zh
|
||||
* 将给定 obb 的属性设置为给定的值。
|
||||
* @param out @zh 目标 OBB @en The output OBB.
|
||||
* 将给定 OBB 的属性设置为给定的值。
|
||||
* @param out @zh 目标 OBB @en The output OBB instance.
|
||||
* @param cx @zh 形状的相对于原点的 X 坐标。 @en The x coordinate of origin.
|
||||
* @param cy @zh 形状的相对于原点的 Y 坐标。 @en The y coordinate of origin.
|
||||
* @param cz @zh 形状的相对于原点的 Z 坐标。 @en The z coordinate of origin.
|
||||
* @param hw @zh - obb 宽度的一半。 @en Half the width of the OBB.
|
||||
* @param hh @zh - obb 高度的一半。 @en Half the height of the OBB.
|
||||
* @param hl @zh - obb 长度的一半。 @en Half the length of the OBB.
|
||||
* @param ox_1 @zh 方向矩阵参数。 @en The x component of the one axis of the OBB.
|
||||
* @param ox_2 @zh 方向矩阵参数。 @en The x component of the second axis of the OBB.
|
||||
* @param ox_3 @zh 方向矩阵参数。 @en The x component of the third axis of the OBB.
|
||||
* @param oy_1 @zh 方向矩阵参数。 @en The y component of the one axis of the OBB.
|
||||
* @param oy_2 @zh 方向矩阵参数。 @en The y component of the second axis of the OBB.
|
||||
* @param oy_3 @zh 方向矩阵参数。 @en The y component of the third axis of the OBB.
|
||||
* @param oz_1 @zh 方向矩阵参数。 @en The z component of the one axis of the OBB.
|
||||
* @param oz_2 @zh 方向矩阵参数。 @en The z component of the second axis of the OBB.
|
||||
* @param oz_3 @zh 方向矩阵参数。 @en The z component of the third axis of the OBB.
|
||||
* @returns @zh out 接受操作的 OBB @en The reference of the first parameter `out`.
|
||||
* @param ox_1 @zh 方向矩阵参数,第 1 条轴的 x 分量。 @en The x component of the first axis of the OBB.
|
||||
* @param ox_2 @zh 方向矩阵参数,第 2 条轴的 x 分量。 @en The x component of the second axis of the OBB.
|
||||
* @param ox_3 @zh 方向矩阵参数,第 3 条轴的 x 分量。 @en The x component of the third axis of the OBB.
|
||||
* @param oy_1 @zh 方向矩阵参数,第 1 条轴的 y 分量。 @en The y component of the first axis of the OBB.
|
||||
* @param oy_2 @zh 方向矩阵参数,第 2 条轴的 y 分量。 @en The y component of the second axis of the OBB.
|
||||
* @param oy_3 @zh 方向矩阵参数,第 3 条轴的 y 分量。 @en The y component of the third axis of the OBB.
|
||||
* @param oz_1 @zh 方向矩阵参数,第 1 条轴的 z 分量。 @en The z component of the first axis of the OBB.
|
||||
* @param oz_2 @zh 方向矩阵参数,第 2 条轴的 z 分量。 @en The z component of the second axis of the OBB.
|
||||
* @param oz_3 @zh 方向矩阵参数,第 3 条轴的 z 分量。 @en The z component of the third axis of the OBB.
|
||||
* @returns @zh 接受操作的 OBB,与 `out` 参数相同。 @en The output OBB, same as the `out` parameter.
|
||||
*/
|
||||
public static set (
|
||||
out: OBB,
|
||||
@@ -166,7 +166,7 @@ export class OBB {
|
||||
|
||||
/**
|
||||
* @en
|
||||
* Center point of the OBB.
|
||||
* The center point of an OBB in local coordinate.
|
||||
* @zh
|
||||
* 本地坐标的中心点。
|
||||
*/
|
||||
@@ -190,9 +190,9 @@ export class OBB {
|
||||
|
||||
/**
|
||||
* @en
|
||||
* Gets the type of the shape.
|
||||
* Gets the type of the OBB. Always returns `enums.SHAPE_OBB`.
|
||||
* @zh
|
||||
* 获取形状的类型。
|
||||
* 获取形状的类型,固定返回 `enums.SHAPE_OBB`。
|
||||
*/
|
||||
get type () {
|
||||
return this._type;
|
||||
@@ -200,6 +200,23 @@ export class OBB {
|
||||
|
||||
protected readonly _type: number;
|
||||
|
||||
/**
|
||||
* @param cx @zh 形状的相对于原点的 X 坐标。 @en The x coordinate of origin.
|
||||
* @param cy @zh 形状的相对于原点的 Y 坐标。 @en The y coordinate of origin.
|
||||
* @param cz @zh 形状的相对于原点的 Z 坐标。 @en The z coordinate of origin.
|
||||
* @param hw @zh - OBB 宽度的一半。 @en Half the width of the OBB.
|
||||
* @param hh @zh - OBB 高度的一半。 @en Half the height of the OBB.
|
||||
* @param hl @zh - OBB 长度的一半。 @en Half the length of the OBB.
|
||||
* @param ox_1 @zh 方向矩阵参数,第 1 条轴的 x 分量。 @en The x component of the first axis of the OBB.
|
||||
* @param ox_2 @zh 方向矩阵参数,第 2 条轴的 x 分量。 @en The x component of the second axis of the OBB.
|
||||
* @param ox_3 @zh 方向矩阵参数,第 3 条轴的 x 分量。 @en The x component of the third axis of the OBB.
|
||||
* @param oy_1 @zh 方向矩阵参数,第 1 条轴的 y 分量。 @en The y component of the first axis of the OBB.
|
||||
* @param oy_2 @zh 方向矩阵参数,第 2 条轴的 y 分量。 @en The y component of the second axis of the OBB.
|
||||
* @param oy_3 @zh 方向矩阵参数,第 3 条轴的 y 分量。 @en The y component of the third axis of the OBB.
|
||||
* @param oz_1 @zh 方向矩阵参数,第 1 条轴的 z 分量。 @en The z component of the first axis of the OBB.
|
||||
* @param oz_2 @zh 方向矩阵参数,第 2 条轴的 z 分量。 @en The z component of the second axis of the OBB.
|
||||
* @param oz_3 @zh 方向矩阵参数,第 3 条轴的 z 分量。 @en The z component of the third axis of the OBB.
|
||||
*/
|
||||
constructor (cx = 0, cy = 0, cz = 0,
|
||||
hw = 1, hh = 1, hl = 1,
|
||||
ox_1 = 1, ox_2 = 0, ox_3 = 0,
|
||||
@@ -213,11 +230,11 @@ export class OBB {
|
||||
|
||||
/**
|
||||
* @en
|
||||
* Get the bounding points of this shape
|
||||
* Gets the bounding points of this OBB instance.
|
||||
* @zh
|
||||
* 获取 obb 的最小点和最大点。
|
||||
* @param minPos @zh 最小点。 @en The out minimum position of the OBB.
|
||||
* @param maxPos @zh 最大点。 @en The out maximum position of the OBB.
|
||||
* 获取此 OBB 的最小点和最大点。
|
||||
* @param minPos @zh 此 OBB 的最小点。 @en The out minimum position of the OBB.
|
||||
* @param maxPos @zh 此 OBB 的最大点。 @en The out maximum position of the OBB.
|
||||
*/
|
||||
public getBoundary (minPos: Vec3, maxPos: Vec3) {
|
||||
transform_extent_m3(_v3_tmp, this.halfExtents, this.orientation);
|
||||
@@ -227,14 +244,15 @@ export class OBB {
|
||||
|
||||
/**
|
||||
* @en
|
||||
* Transform this shape
|
||||
* Transforms this OBB and store the result to the `out` parameter.
|
||||
* @zh
|
||||
* 将 out 根据这个 obb 的数据进行变换。
|
||||
* 对当前 OBB 的数据进行变换,并存储结果到 `out` 参数中。
|
||||
* @param m @zh 变换的矩阵。 @en The transform matrix
|
||||
* @param pos @zh 变换的位置部分。 @en 3d-vector translation.
|
||||
* @param rot @zh 变换的旋转部分。 @en Quaternion rotation.
|
||||
* @param scale @zh 变换的缩放部分。 @en 3d-vector scale.
|
||||
* @param out @zh 变换的目标。 @en The output OBB.
|
||||
* @param out @zh 变换结果的目标 OBB。 @en The output OBB.
|
||||
* @note @zh 此方法不会修改当前 OBB 的数据。 @en This method will not modify the data of current OBB.
|
||||
*/
|
||||
public transform (m: Mat4, pos: Vec3, rot: Quat, scale: Vec3, out: OBB) {
|
||||
Vec3.transformMat4(out.center, this.center, m);
|
||||
@@ -245,12 +263,13 @@ export class OBB {
|
||||
|
||||
/**
|
||||
* @en
|
||||
* Transform by matrix and rotation.
|
||||
* Transforms this OBB by a 4x4 matrix and a quaternion.
|
||||
* @zh
|
||||
* 将 out 根据这个 obb 的数据进行变换。
|
||||
* 根据一个 4x4 矩阵和一个四元数变换此 OBB。
|
||||
* @param m @zh 变换的矩阵。 @en The transform matrix.
|
||||
* @param rot @zh 变换的旋转部分。 @en Quaternion rotation.
|
||||
* @param rot @zh 变换的旋转部分。 @en The quaternion for rotation.
|
||||
* @param out @zh 变换的目标。 @en The output OBB.
|
||||
* @note @zh 此方法不会修改当前 OBB 的数据。 @en This method will not modify the data of current OBB.
|
||||
*/
|
||||
public translateAndRotate (m: Mat4, rot: Quat, out: OBB) {
|
||||
Vec3.transformMat4(out.center, this.center, m);
|
||||
@@ -260,11 +279,12 @@ export class OBB {
|
||||
|
||||
/**
|
||||
* @en
|
||||
* Scale OBB by a 3d-vector.
|
||||
* Scales this OBB by a 3d-vector and store the result to the `out` parameter.
|
||||
* @zh
|
||||
* 将 out 根据这个 obb 的数据进行缩放。
|
||||
* 根据 3D 向量对此 OBB 的数据进行缩放并将结果存储在 out 参数中。
|
||||
* @param scale @zh 缩放值。 @en 3d-vector scale.
|
||||
* @param out @zh 缩放的目标。 @en The output OBB.
|
||||
* @note @zh 此方法不会修改当前 OBB 的数据。 @en This method will not modify the data of current OBB.
|
||||
*/
|
||||
public setScale (scale: Vec3, out: OBB) {
|
||||
Vec3.multiply(out.halfExtents, this.halfExtents, scale);
|
||||
|
||||
@@ -35,20 +35,20 @@ const temp_vec4 = legacyCC.v4();
|
||||
* @en
|
||||
* Basic Geometry: Plane.
|
||||
* @zh
|
||||
* 基础几何 Plane。
|
||||
* 基础几何:平面。
|
||||
*/
|
||||
|
||||
export class Plane {
|
||||
/**
|
||||
* @en
|
||||
* create a new plane
|
||||
* Creates a new plane.
|
||||
* @zh
|
||||
* 创建一个新的 plane。
|
||||
* @param nx @en The x component of normal vector. @zh 法向分量的 x 部分。
|
||||
* @param ny @en The y component of normal vector. @zh 法向分量的 y 部分。
|
||||
* @param nz @en The z component of normal vector. @zh 法向分量的 z 部分。
|
||||
* 创建一个新的平面。
|
||||
* @param nx @en The x component of normal vector. @zh 法向量的 x 部分。
|
||||
* @param ny @en The y component of normal vector. @zh 法向量的 y 部分。
|
||||
* @param nz @en The z component of normal vector. @zh 法向量的 z 部分。
|
||||
* @param d @en The distance between normal vector and the origin. @zh 与原点的距离。
|
||||
* @return
|
||||
* @returns @en The created plane object. @zh 新创建的平面。
|
||||
*/
|
||||
public static create (nx: number, ny: number, nz: number, d: number) {
|
||||
return new Plane(nx, ny, nz, d);
|
||||
@@ -56,11 +56,11 @@ export class Plane {
|
||||
|
||||
/**
|
||||
* @en
|
||||
* clone a new plane
|
||||
* Clones a new plane.
|
||||
* @zh
|
||||
* 克隆一个新的 plane。
|
||||
* @param p @en The Plane object to be cloned from. @zh 克隆的来源。
|
||||
* @return @en Cloned objects @zh 克隆出的对象。
|
||||
* 克隆一个新的平面。
|
||||
* @param p @en The Plane object to be cloned from. @zh 克隆的来源平面对象。
|
||||
* @returns @en The cloned Plane object @zh 克隆出的平面对象。
|
||||
*/
|
||||
public static clone (p: Plane) {
|
||||
return new Plane(p.n.x, p.n.y, p.n.z, p.d);
|
||||
@@ -68,12 +68,12 @@ export class Plane {
|
||||
|
||||
/**
|
||||
* @en
|
||||
* copy the values from one plane to another
|
||||
* Copies the values from one plane to another.
|
||||
* @zh
|
||||
* 复制一个平面的值到另一个。
|
||||
* @param out @en The object to be operated on. @zh 接受操作的对象。
|
||||
* @param p @en The source of replication. @zh 复制的来源。
|
||||
* @return @en The object to be operated on. @zh 接受操作的对象。
|
||||
* @returns @en The object to be operated on. @zh 接受操作的对象。
|
||||
*/
|
||||
public static copy (out: Plane, p: Plane) {
|
||||
Vec3.copy(out.n, p.n);
|
||||
@@ -84,14 +84,14 @@ export class Plane {
|
||||
|
||||
/**
|
||||
* @en
|
||||
* create a plane from three points
|
||||
* Creates a plane from three points
|
||||
* @zh
|
||||
* 用三个点创建一个平面。
|
||||
* @param out @en The object to be operated on. @zh 接受操作的对象。
|
||||
* @param a @en Point a. @zh 点 a。
|
||||
* @param b @en Point b. @zh 点 b。
|
||||
* @param c @en Point c. @zh 点 c。
|
||||
* @return out @en The object to be operated on. @zh 接受操作的对象。
|
||||
* @param out @en The Plane object to be operated on. @zh 接受操作的对象。
|
||||
* @param a @en The point a. @zh 点 a。
|
||||
* @param b @en The point b. @zh 点 b。
|
||||
* @param c @en The point c. @zh 点 c。
|
||||
* @returns @en The Plane object to be operated on, same as `out` parameter. @zh 接受操作的对象,与 `out` 相同。
|
||||
*/
|
||||
public static fromPoints (out: Plane, a: Vec3, b: Vec3, c: Vec3) {
|
||||
Vec3.subtract(v1, b, a);
|
||||
@@ -105,15 +105,15 @@ export class Plane {
|
||||
|
||||
/**
|
||||
* @en
|
||||
* Set the components of a plane to the given values
|
||||
* Sets the components of a plane to the given values.
|
||||
* @zh
|
||||
* 将给定平面的属性设置为给定值。
|
||||
* @param out @en The object to be operated on. @zh 接受操作的对象。
|
||||
* @param nx @en The x component of normal vector. @zh 法向分量的 x 部分。
|
||||
* @param ny @en The y component of normal vector. @zh 法向分量的 y 部分。
|
||||
* @param nz @en The z component of normal vector. @zh 法向分量的 z 部分。
|
||||
* @param out @en The Plane object to be operated on. @zh 接受操作的对象。
|
||||
* @param nx @en The x component of normal vector. @zh 法向量量的 x 部分。
|
||||
* @param ny @en The y component of normal vector. @zh 法向量的 y 部分。
|
||||
* @param nz @en The z component of normal vector. @zh 法向量的 z 部分。
|
||||
* @param d @en The distance between normal vector and the origin. @zh 与原点的距离。
|
||||
* @return out @en The object to be operated on. @zh 接受操作的对象。
|
||||
* @returns @en The object to be operated on, same as the `out` parameter. @zh 接受操作的对象,与 `out` 参数相同。
|
||||
*/
|
||||
public static set (out: Plane, nx: number, ny: number, nz: number, d: number) {
|
||||
out.n.x = nx;
|
||||
@@ -126,13 +126,13 @@ export class Plane {
|
||||
|
||||
/**
|
||||
* @en
|
||||
* create plane from normal and point
|
||||
* Creates plane from normal and point.
|
||||
* @zh
|
||||
* 用一条法线和一个点创建平面。
|
||||
* @param out @en The object to be operated on. @zh 接受操作的对象。
|
||||
* @param normal @en Normal of the plane. @zh 平面的法线。
|
||||
* @param normal @en The normal of the plane. @zh 平面的法线。
|
||||
* @param point @en A point in the plane. @zh 平面上的一点。
|
||||
* @return out @en The object to be operated on. @zh 接受操作的对象。
|
||||
* @returns @en The object to be operated on, same as the `out` parameter. @zh 接受操作的对象,与 `out` 参数相同。
|
||||
*/
|
||||
public static fromNormalAndPoint (out: Plane, normal: Vec3, point: Vec3) {
|
||||
Vec3.copy(out.n, normal);
|
||||
@@ -143,12 +143,12 @@ export class Plane {
|
||||
|
||||
/**
|
||||
* @en
|
||||
* normalize a plane
|
||||
* Normalizes a plane.
|
||||
* @zh
|
||||
* 归一化一个平面。
|
||||
* @param out @en The object to be operated on. @zh 接受操作的对象。
|
||||
* @param a @en Source data for the operation. @zh 操作的源数据。
|
||||
* @return out @en The object to be operated on. @zh 接受操作的对象。
|
||||
* @returns @en The object to be operated on, sames as the `out` parameter. @zh 接受操作的对象,与 `out` 相同。
|
||||
*/
|
||||
public static normalize (out: Plane, a: Plane) {
|
||||
const len = a.n.length();
|
||||
@@ -177,9 +177,9 @@ export class Plane {
|
||||
|
||||
/**
|
||||
* @en
|
||||
* Gets the type of the shape.
|
||||
* Gets the type of the Plane, its value is `enums.SHAPE_PLANE`.
|
||||
* @zh
|
||||
* 获取形状的类型。
|
||||
* 获取形状的类型,值为 `enums.SHAPE_PLANE`。
|
||||
*/
|
||||
get type () {
|
||||
return this._type;
|
||||
@@ -199,12 +199,12 @@ export class Plane {
|
||||
|
||||
/**
|
||||
* @en
|
||||
* Construct a plane.
|
||||
* Constructs a plane.
|
||||
* @zh
|
||||
* 构造一个平面。
|
||||
* @param nx @en The x component of normal vector. @zh 法向分量的 x 部分。
|
||||
* @param ny @en The y component of normal vector. @zh 法向分量的 y 部分。
|
||||
* @param nz @en The z component of normal vector. @zh 法向分量的 z 部分。
|
||||
* @param nx @en The x component of normal vector. @zh 法向量的 x 部分。
|
||||
* @param ny @en The y component of normal vector. @zh 法向量的 y 部分。
|
||||
* @param nz @en The z component of normal vector. @zh 法向量的 z 部分。
|
||||
* @param d @en The distance between normal vector and the origin. @zh 与原点的距离。
|
||||
*/
|
||||
constructor (nx = 0, ny = 1, nz = 0, d = 0) {
|
||||
@@ -215,10 +215,10 @@ export class Plane {
|
||||
|
||||
/**
|
||||
* @en
|
||||
* transform this plane.
|
||||
* Transforms this plane by a 4x4 matrix.
|
||||
* @zh
|
||||
* 变换一个平面。
|
||||
* @param mat
|
||||
* 使用一个 4x4 矩阵变换此平面。
|
||||
* @param mat @en The 4x4 matrix for transformation @zh 用于变换的 4x4 矩阵。
|
||||
*/
|
||||
public transform (mat: Mat4): void {
|
||||
Mat4.invert(temp_mat, mat);
|
||||
|
||||
+45
-45
@@ -28,24 +28,24 @@ import { IVec3Like } from '../math/type-define';
|
||||
|
||||
/**
|
||||
* @en
|
||||
* Basic Geometry: ray.
|
||||
* Basic Geometry: Ray.
|
||||
* @zh
|
||||
* 基础几何 射线。
|
||||
* 基础几何:射线。
|
||||
*/
|
||||
|
||||
export class Ray {
|
||||
/**
|
||||
* @en
|
||||
* create a new ray
|
||||
* Creates a new ray.
|
||||
* @zh
|
||||
* 创建一条射线。
|
||||
* @param {number} ox @en x component of start point @zh 起点的 x 部分。
|
||||
* @param {number} oy @en y component of start point @zh 起点的 y 部分。
|
||||
* @param {number} oz @en z component of start point @zh 起点的 z 部分。
|
||||
* @param {number} dx @en Point in the x direction @zh 方向的 x 部分。
|
||||
* @param {number} dy @en Point in the y direction @zh 方向的 y 部分。
|
||||
* @param {number} dz @en Point in the z direction @zh 方向的 z 部分。
|
||||
* @return {Ray} @en Ray object @zh 射线。
|
||||
* @param {number} ox @en The x component of start point. @zh 起点的 x 部分。
|
||||
* @param {number} oy @en The y component of start point. @zh 起点的 y 部分。
|
||||
* @param {number} oz @en The z component of start point. @zh 起点的 z 部分。
|
||||
* @param {number} dx @en The x component of direction point. @zh 方向的 x 部分。
|
||||
* @param {number} dy @en The y component of direction point. @zh 方向的 y 部分。
|
||||
* @param {number} dz @en The z component of direction point. @zh 方向的 z 部分。
|
||||
* @returns {Ray} @en The created ray object. @zh 新创建的射线。
|
||||
*/
|
||||
public static create (ox = 0, oy = 0, oz = 0, dx = 0, dy = 0, dz = 1): Ray {
|
||||
return new Ray(ox, oy, oz, dx, dy, dz);
|
||||
@@ -53,11 +53,11 @@ export class Ray {
|
||||
|
||||
/**
|
||||
* @en
|
||||
* Creates a new ray initialized with values from an existing ray
|
||||
* Creates a new ray initialized with the values from an existing ray.
|
||||
* @zh
|
||||
* 从一条射线克隆出一条新的射线。
|
||||
* @param {Ray} a @en The Ray object to be cloned from @zh 克隆的目标。
|
||||
* @return {Ray} @en Clone new ray object @zh 克隆出的新对象。
|
||||
* @param a @en The Ray object to be cloned from. @zh 克隆的目标。
|
||||
* @returns @en The cloned Ray object. @zh 克隆出的新对象。
|
||||
*/
|
||||
public static clone (a: Ray): Ray {
|
||||
return new Ray(
|
||||
@@ -68,12 +68,12 @@ export class Ray {
|
||||
|
||||
/**
|
||||
* @en
|
||||
* Copy the values from one ray to another
|
||||
* Copies the values from one ray to another.
|
||||
* @zh
|
||||
* 将从一个 ray 的值复制到另一个 ray。
|
||||
* @param {Ray} out @en The ray object to be modified @zh 接受操作的 ray。
|
||||
* @param {Ray} a @en The copied ray object @zh 被复制的 ray。
|
||||
* @return {Ray} @en Ray object @zh out 接受操作的 ray。
|
||||
* 复制一个 Ray 的值到另一个 Ray 中。
|
||||
* @param out @en The Ray object to copy to. @zh 接受操作的射线。
|
||||
* @param a @en The Ray object to copy from. @zh 被复制的射线。
|
||||
* @returns @en The Ray object to copy to, same as the `out` parameter. @zh 接受操作的射线,与 `out` 参数相同。
|
||||
*/
|
||||
public static copy (out: Ray, a: Ray): Ray {
|
||||
Vec3.copy(out.o, a.o);
|
||||
@@ -84,13 +84,13 @@ export class Ray {
|
||||
|
||||
/**
|
||||
* @en
|
||||
* create a ray from two points
|
||||
* Creates a ray from two points.
|
||||
* @zh
|
||||
* 用两个点创建一条射线。
|
||||
* @param {Ray} out @en The ray object to be modified @zh 接受操作的射线。
|
||||
* @param {Vec3} origin @en Starting point of the ray @zh 射线的起点。
|
||||
* @param {Vec3} target @en point on the ray @zh 射线上的一点。
|
||||
* @return {Ray} @en Ray object @zh out 接受操作的射线。
|
||||
* @param out @en The Ray object. @zh 接受操作的射线。
|
||||
* @param origin @en The start point of the ray. @zh 射线的起点。
|
||||
* @param target @en The target point on the ray. @zh 射线上的一点。
|
||||
* @returns @en The Ray object, same as the `out` parameter. @zh 接受操作的射线,与 `out` 参数相同。
|
||||
*/
|
||||
public static fromPoints (out: Ray, origin: Vec3, target: Vec3): Ray {
|
||||
Vec3.copy(out.o, origin);
|
||||
@@ -100,17 +100,17 @@ export class Ray {
|
||||
|
||||
/**
|
||||
* @en
|
||||
* Set the components of a ray to the given values
|
||||
* Sets the components of a ray to the given values.
|
||||
* @zh
|
||||
* 将给定射线的属性设置为给定的值。
|
||||
* @param {Ray} out @en The ray object to be modified @zh 接受操作的射线。
|
||||
* @param {number} ox @en x component of start point @zh 起点的 x 部分。
|
||||
* @param {number} oy @en y component of start point @zh 起点的 y 部分。
|
||||
* @param {number} oz @en z component of start point @zh 起点的 z 部分。
|
||||
* @param {number} dx @en Point in the x direction @zh 方向的 x 部分。
|
||||
* @param {number} dy @en Point in the y direction @zh 方向的 y 部分。
|
||||
* @param {number} dz @en Point in the z direction @zh 方向的 z 部分。
|
||||
* @return {Ray} @en Ray object @zh out 接受操作的射线。
|
||||
* @param out @en The Ray object to be modified @zh 接受操作的射线。
|
||||
* @param ox @en The x component of start point. @zh 起点的 x 部分。
|
||||
* @param oy @en The y component of start point. @zh 起点的 y 部分。
|
||||
* @param oz @en The z component of start point. @zh 起点的 z 部分。
|
||||
* @param dx @en The x component of direction point. @zh 方向的 x 部分。
|
||||
* @param dy @en The y component of direction point. @zh 方向的 y 部分。
|
||||
* @param dz @en The z component of direction point. @zh 方向的 z 部分。
|
||||
* @returns @en The Ray object, same as the `out` parameter. @zh 接受操作的射线,与 `out` 相同。
|
||||
*/
|
||||
public static set (out: Ray, ox: number, oy: number, oz: number, dx: number, dy: number, dz: number): Ray {
|
||||
out.o.x = ox;
|
||||
@@ -141,9 +141,9 @@ export class Ray {
|
||||
|
||||
/**
|
||||
* @en
|
||||
* Gets the type of the shape.
|
||||
* Gets the type of the ray, its value is `enums.SHAPE_RAY`.
|
||||
* @zh
|
||||
* 获取形状的类型。
|
||||
* 获取形状的类型,其值为`enums.SHAPE_RAY`。
|
||||
*/
|
||||
get type () {
|
||||
return this._type;
|
||||
@@ -153,15 +153,15 @@ export class Ray {
|
||||
|
||||
/**
|
||||
* @en
|
||||
* Construct a ray;
|
||||
* Constructs a ray.
|
||||
* @zh
|
||||
* 构造一条射线。
|
||||
* @param {number} ox @en x component of start point @zh 起点的 x 部分。
|
||||
* @param {number} oy @en y component of start point @zh 起点的 y 部分。
|
||||
* @param {number} oz @en z component of start point @zh 起点的 z 部分。
|
||||
* @param {number} dx @en Point in the x direction @zh 方向的 x 部分。
|
||||
* @param {number} dy @en Point in the y direction @zh 方向的 y 部分。
|
||||
* @param {number} dz @en Point in the z direction @zh 方向的 z 部分。
|
||||
* @param ox @en The x component of start point. @zh 起点的 x 部分。
|
||||
* @param oy @en The y component of start point. @zh 起点的 y 部分。
|
||||
* @param oz @en The z component of start point. @zh 起点的 z 部分。
|
||||
* @param dx @en The x component of direction point. @zh 方向的 x 部分。
|
||||
* @param dy @en The y component of direction point. @zh 方向的 y 部分。
|
||||
* @param dz @en The z component of direction point. @zh 方向的 z 部分。
|
||||
*/
|
||||
constructor (ox = 0, oy = 0, oz = 0,
|
||||
dx = 0, dy = 0, dz = -1) {
|
||||
@@ -172,11 +172,11 @@ export class Ray {
|
||||
|
||||
/**
|
||||
* @en
|
||||
* Compute a point with the distance between the origin.
|
||||
* Calculates a point on the ray with the specific distance from the origin point.
|
||||
* @zh
|
||||
* 根据给定距离计算出射线上的一点。
|
||||
* @param out @en Another point on the ray @zh 射线上的另一点。
|
||||
* @param distance @en Given distance @zh 给定距离。
|
||||
* 根据给定的距离计算出射线上的一点。
|
||||
* @param out @en Another point on the ray. @zh 射线上的另一点。
|
||||
* @param distance @en The given distance. @zh 给定的距离。
|
||||
*/
|
||||
public computeHit (out: IVec3Like, distance: number) {
|
||||
Vec3.normalize(out, this.d);
|
||||
|
||||
@@ -32,7 +32,7 @@ export enum ERaycastMode {
|
||||
|
||||
/**
|
||||
* @en
|
||||
* Detect and record all data.
|
||||
* Detects and records all data.
|
||||
* @zh
|
||||
* 检测并记录所有的数据。
|
||||
*/
|
||||
@@ -40,7 +40,7 @@ export enum ERaycastMode {
|
||||
|
||||
/**
|
||||
* @en
|
||||
* Detect all, but record only the most recent data.
|
||||
* Detects all data, but records only the most recent data.
|
||||
* @zh
|
||||
* 检测所有,但只记录最近的数据。
|
||||
*/
|
||||
@@ -156,7 +156,7 @@ export interface IRayMeshOptions extends IRaySubMeshOptions {
|
||||
|
||||
/**
|
||||
* @en
|
||||
* The optional param structure of the `rayModel`.
|
||||
* The optional parameter structure of the `rayModel`.
|
||||
* @zh
|
||||
* `rayModel`的可选参数结构。
|
||||
*/
|
||||
|
||||
@@ -36,20 +36,20 @@ function maxComponent (v: Vec3) { return Math.max(Math.max(v.x, v.y), v.z); }
|
||||
* @en
|
||||
* Basic Geometry: Sphere.
|
||||
* @zh
|
||||
* 基础几何 轴对齐球。
|
||||
* 基础几何:球。
|
||||
*/
|
||||
|
||||
export class Sphere {
|
||||
/**
|
||||
* @en
|
||||
* create a new sphere
|
||||
* Creates a new sphere instance.
|
||||
* @zh
|
||||
* 创建一个新的 sphere 实例。
|
||||
* @param cx @en X-Coordinate of center point relative to the origin. @zh 中心点的相对于原点的 X 坐标。
|
||||
* @param cy @en Y-Coordinate of center point relative to the origin. @zh 中心点的相对于原点的 Y 坐标。
|
||||
* @param cz @en Z-Coordinate of center point relative to the origin. @zh 中心点的相对于原点的 Z 坐标。
|
||||
* @param r @en Radius of the sphere. @zh 球体的半径
|
||||
* @return @en return a new sphere. @zh 返回一个 sphere。
|
||||
* 创建一个新的球实例。
|
||||
* @param cx @en The X-Coordinate of the center point relative to the origin. @zh 相对于原点的中心点的 X 坐标。
|
||||
* @param cy @en The Y-Coordinate of the center point relative to the origin. @zh 相对于原点的中心点的 Y 坐标。
|
||||
* @param cz @en The Z-Coordinate of the center point relative to the origin. @zh 相对于原点的中心点的 Z 坐标。
|
||||
* @param r @en The radius of the sphere. @zh 球体的半径
|
||||
* @returns @en A new sphere instance. @zh 一个新的球实例。
|
||||
*/
|
||||
public static create (cx: number, cy: number, cz: number, r: number): Sphere {
|
||||
return new Sphere(cx, cy, cz, r);
|
||||
@@ -57,11 +57,11 @@ export class Sphere {
|
||||
|
||||
/**
|
||||
* @en
|
||||
* clone a new sphere
|
||||
* Clones a sphere instance.
|
||||
* @zh
|
||||
* 克隆一个新的 sphere 实例。
|
||||
* 克隆一个新的球实例。
|
||||
* @param p @en The sphere object to clone from. @zh 克隆的目标。
|
||||
* @return @en The sphere object to clone to. @zh 克隆出的示例。
|
||||
* @returns @en The sphere object to clone to. @zh 克隆出的实例。
|
||||
*/
|
||||
public static clone (p: Sphere): Sphere {
|
||||
return new Sphere(p.center.x, p.center.y, p.center.z, p.radius);
|
||||
@@ -69,12 +69,12 @@ export class Sphere {
|
||||
|
||||
/**
|
||||
* @en
|
||||
* copy the values from one sphere to another
|
||||
* Copies the values from one sphere to another.
|
||||
* @zh
|
||||
* 将从一个 sphere 的值复制到另一个 sphere。
|
||||
* @param out @en The sphere object to copy to. @zh 接受操作的 sphere。
|
||||
* @param a @en The sphere object to copy from. @zh 被复制的 sphere。
|
||||
* @return @en The sphere object to copy to. @zh 接受操作的 sphere。
|
||||
* 复制一个球的值到另一个球中。
|
||||
* @param out @en The sphere object to copy to. @zh 接受操作的球实例。
|
||||
* @param a @en The sphere object to copy from. @zh 被复制的球实例。
|
||||
* @returns @en The sphere object to copy to. @zh 接受操作的球实例。
|
||||
*/
|
||||
public static copy (out: Sphere, p: Sphere): Sphere {
|
||||
Vec3.copy(out.center, p.center);
|
||||
@@ -85,13 +85,13 @@ export class Sphere {
|
||||
|
||||
/**
|
||||
* @en
|
||||
* create a new bounding sphere from two corner points
|
||||
* Creates a new sphere instance from two points.
|
||||
* @zh
|
||||
* 从两个点创建一个新的 sphere。
|
||||
* @param out - @en Sphere created from points. @zh 接受操作的 sphere。
|
||||
* @param minPos - @en Lower point of the sphere. @zh sphere 的较小点。
|
||||
* @param maxPos - @en Upper point of the sphere. @zh sphere 的较大点。
|
||||
* @returns @en The output sphere object to save the created sphere data. @zh 接受操作的 sphere。
|
||||
* 从两个点创建一个新的球实例。
|
||||
* @param out - @en The sphere created from the two points. @zh 接受操作的球实例。
|
||||
* @param minPos - @en The lower point of the sphere. @zh 球的较小点。
|
||||
* @param maxPos - @en The upper point of the sphere. @zh 球的较大点。
|
||||
* @returns @en The created sphere, same as the `out` parameter. @zh 接受操作的球实例,与 `out` 参数相同。
|
||||
*/
|
||||
public static fromPoints (out: Sphere, minPos: Vec3, maxPos: Vec3): Sphere {
|
||||
Vec3.multiplyScalar(out.center, Vec3.add(_v3_tmp, minPos, maxPos), 0.5);
|
||||
@@ -101,15 +101,15 @@ export class Sphere {
|
||||
|
||||
/**
|
||||
* @en
|
||||
* Set the components of a sphere to the given values
|
||||
* Sets the components of a sphere to the given values
|
||||
* @zh
|
||||
* 将球体的属性设置为给定的值。
|
||||
* @param out @en The sphere to set properties to. @zh 接受操作的 sphere。
|
||||
* @param cx @en X-Coordinate of center point relative to the origin. @zh 中心点的相对于原点的 X 坐标。
|
||||
* @param cy @en Y-Coordinate of center point relative to the origin. @zh 中心点的相对于原点的 Y 坐标。
|
||||
* @param cz @en Z-Coordinate of center point relative to the origin. @zh 中心点的相对于原点的 Z 坐标。
|
||||
* @param r @en Radius of the sphere. @zh 半径。
|
||||
* @return @en Sphere which the properties will be set to. @zh 接受操作的 sphere。
|
||||
* @param out @en The sphere to set values to. @zh 接受操作的球实例。
|
||||
* @param cx @en The X-Coordinate of the center point which relative to the origin. @zh 相对于原点的中心点的 X 坐标。
|
||||
* @param cy @en The Y-Coordinate of the center point which relative to the origin. @zh 相对于原点的中心点的 Y 坐标。
|
||||
* @param cz @en The Z-Coordinate of the center point which relative to the origin. @zh 相对于原点的中心点的 Z 坐标。
|
||||
* @param r @en The radius of the sphere. @zh 要设置的球的半径。
|
||||
* @returns @en The sphere to set values to, same as the `out` parameter. @zh 接受操作的实例,与 `out` 相同。
|
||||
* @function
|
||||
*/
|
||||
public static set (out: Sphere, cx: number, cy: number, cz: number, r: number): Sphere {
|
||||
@@ -125,7 +125,7 @@ export class Sphere {
|
||||
* @en
|
||||
* The center of this sphere.
|
||||
* @zh
|
||||
* 本地坐标的中心点。
|
||||
* 当前球在本地坐标中的中心点。
|
||||
*/
|
||||
protected _center: Vec3 = new Vec3(0, 0, 0);
|
||||
get center (): Vec3 {
|
||||
@@ -142,7 +142,7 @@ export class Sphere {
|
||||
* @en
|
||||
* The radius of this sphere.
|
||||
* @zh
|
||||
* 半径。
|
||||
* 当前球的半径。
|
||||
*/
|
||||
get radius (): number {
|
||||
return this._radius;
|
||||
@@ -154,9 +154,9 @@ export class Sphere {
|
||||
|
||||
/**
|
||||
* @en
|
||||
* Gets the type of the shape.
|
||||
* Gets the type of the shape, always returns `enums.SHAPE_SPHERE`.
|
||||
* @zh
|
||||
* 获取形状的类型。
|
||||
* 获取球的类型,固定返回 `enums.SHAPE_SPHERE`。
|
||||
*/
|
||||
get type () {
|
||||
return this._type;
|
||||
@@ -166,13 +166,13 @@ export class Sphere {
|
||||
|
||||
/**
|
||||
* @en
|
||||
* Construct a sphere.
|
||||
* Constructs a sphere instance.
|
||||
* @zh
|
||||
* 构造一个球。
|
||||
* @param cx @en The X-Coordinate of the sphere. @zh 该球的世界坐标的 X 坐标。
|
||||
* @param cy @en The Y-Coordinate of the sphere. @zh 该球的世界坐标的 Y 坐标。
|
||||
* @param cz @en The Z-Coordinate of the sphere. @zh 该球的世界坐标的 Z 坐标。
|
||||
* @param r @en The radius. @zh 半径。
|
||||
* @param r @en The radius of the sphere. @zh 球的半径。
|
||||
*/
|
||||
constructor (cx = 0, cy = 0, cz = 0, r = 1) {
|
||||
this._type = enums.SHAPE_SPHERE;
|
||||
@@ -185,9 +185,10 @@ export class Sphere {
|
||||
|
||||
/**
|
||||
* @en
|
||||
* Get a clone.
|
||||
* Clones a sphere instance.
|
||||
* @zh
|
||||
* 获得克隆。
|
||||
* 克隆一个球实例。
|
||||
* @returns @en The cloned sphere instance. @zh 克隆的球实例。
|
||||
*/
|
||||
public clone () {
|
||||
return Sphere.clone(this);
|
||||
@@ -195,9 +196,9 @@ export class Sphere {
|
||||
|
||||
/**
|
||||
* @en
|
||||
* Copy a sphere.
|
||||
* Copies the values from a sphere to the current sphere.
|
||||
* @zh
|
||||
* 拷贝对象。
|
||||
* 复制一个球的值到当前球实例中。
|
||||
* @param a @en The sphere to copy from. @zh 拷贝的目标。
|
||||
*/
|
||||
public copy (a: Sphere) {
|
||||
@@ -206,11 +207,11 @@ export class Sphere {
|
||||
|
||||
/**
|
||||
* @en
|
||||
* Get the bounding points of this shape
|
||||
* Gets the bounding points of this sphere.
|
||||
* @zh
|
||||
* 获取此形状的边界点。
|
||||
* @param minPos @en The point with maximum coordinates of the sphere. @zh 最小点。
|
||||
* @param maxPos @en The point with minimum coordinates of the sphere. @zh 最大点。
|
||||
* 获取此球体的边界点。
|
||||
* @param minPos @en The point with maximum coordinates of the sphere. @zh 当前球实例的最小点。
|
||||
* @param maxPos @en The point with minimum coordinates of the sphere. @zh 当前球实例的最大点。
|
||||
*/
|
||||
public getBoundary (minPos: Vec3, maxPos: Vec3) {
|
||||
Vec3.set(minPos, this.center.x - this.radius, this.center.y - this.radius, this.center.z - this.radius);
|
||||
@@ -219,13 +220,13 @@ export class Sphere {
|
||||
|
||||
/**
|
||||
* @en
|
||||
* Transform this shape
|
||||
* Transforms this sphere by a 4x4 matrix and RTS and stores to the `out` parameter.
|
||||
* @zh
|
||||
* 将 out 根据这个 sphere 的数据进行变换。
|
||||
* @param m @en The transform matrix. @zh 变换的矩阵。
|
||||
* @param pos @en The position. @zh 变换的位置部分。
|
||||
* @param rot @en The rotation. @zh 变换的旋转部分。
|
||||
* @param scale @en The scale. @zh 变换的缩放部分。
|
||||
* 用一个 4x4 矩阵和一组 RTS 变换此球体,并将结果存储在 `out` 参数中。
|
||||
* @param m @en The 4x4 transform matrix. @zh 4x4 变换矩阵。
|
||||
* @param pos @en The position part of the transform. @zh 变换的位置部分。
|
||||
* @param rot @en The rotation part of the transform. @zh 变换的旋转部分。
|
||||
* @param scale @en The scale part of the transform. @zh 变换的缩放部分。
|
||||
* @param out @en The sphere which the transform will be applied to. @zh 变换的目标。
|
||||
*/
|
||||
public transform (m: Mat4, pos: Vec3, rot: Quat, scale: Vec3, out: Sphere) {
|
||||
@@ -235,11 +236,11 @@ export class Sphere {
|
||||
|
||||
/**
|
||||
* @en
|
||||
* Translate and rotate this sphere.
|
||||
* Transforms this sphere by a 4x4 matrix and a quternion, stores the result to the `out` parameter.
|
||||
* @zh
|
||||
* 将 out 根据这个 sphere 的数据进行变换。
|
||||
* @param m @en The transform matrix. @zh 变换的矩阵。
|
||||
* @param rot @en The rotation. @zh 变换的旋转部分。
|
||||
* 使用一个 4x4 矩阵和一个四元数变换此球体,并将结果存储在 `out` 参数中。
|
||||
* @param m @en The 4x4 transform matrix. @zh 4x4 变换矩阵。
|
||||
* @param rot @en The rotation part of the transform. @zh 变换的旋转部分。
|
||||
* @param out @en The sphere which the transform will be applied to. @zh 变换的目标。
|
||||
*/
|
||||
public translateAndRotate (m: Mat4, rot: Quat, out: Sphere) {
|
||||
@@ -248,10 +249,10 @@ export class Sphere {
|
||||
|
||||
/**
|
||||
* @en
|
||||
* Scaling this sphere.
|
||||
* Scales this sphere and stores the result to the `out` parameter.
|
||||
* @zh
|
||||
* 将 out 根据这个 sphere 的数据进行缩放。
|
||||
* @param scale @en The scale. @zh 缩放值。
|
||||
* 对当前球实例进行缩放处理,并将结果存储在 `out` 参数中。
|
||||
* @param scale @en The scale value. @zh 缩放值。
|
||||
* @param out @en The sphere which the scale will be applied to. @zh 缩放的目标。
|
||||
*/
|
||||
public setScale (scale: Vec3, out: Sphere) {
|
||||
@@ -259,9 +260,9 @@ export class Sphere {
|
||||
}
|
||||
|
||||
/**
|
||||
* @en The point to be merged.
|
||||
* @zh 球跟点合并
|
||||
* @param point @en The point to be merged. @zh 点
|
||||
* @en Merges a point to this sphere.
|
||||
* @zh 合并一个点到当前球实例中。
|
||||
* @param point @en The point to be merged to this sphere. @zh 要合并到当前球实例的点。
|
||||
*/
|
||||
public mergePoint (point: Vec3) {
|
||||
// if sphere.radius Less than 0,
|
||||
@@ -284,9 +285,9 @@ export class Sphere {
|
||||
}
|
||||
|
||||
/**
|
||||
* @en The sphere and points to be merged.
|
||||
* @zh 球跟一系列点合并
|
||||
* @param points @en The point to be merged. @zh 一系列点
|
||||
* @en Merges some points to this sphere.
|
||||
* @zh 合并一些点到当前球实例中。
|
||||
* @param points @en The points to be merged to this sphere. @zh 要合并到当前球实例的点列表。
|
||||
*/
|
||||
public mergePoints (points: Vec3[]) {
|
||||
const length = points.length;
|
||||
@@ -301,9 +302,9 @@ export class Sphere {
|
||||
}
|
||||
|
||||
/**
|
||||
* @en The axis-aligned bounding box to be merged.
|
||||
* @zh 球跟立方体合并
|
||||
* @param a @en Cube. @zh 立方体
|
||||
* @en Merges a AABB to this sphere.
|
||||
* @zh 合并一个 AABB 到当前球实例中。
|
||||
* @param a @en The AABB instance to be merged to this sphere. @zh 要合并到当前球实例的 AABB 实例。
|
||||
*/
|
||||
public mergeAABB (a: AABB) {
|
||||
a.getBoundary(_min, _max);
|
||||
|
||||
@@ -29,12 +29,16 @@ import enums from './enums';
|
||||
|
||||
export enum SplineMode {
|
||||
/**
|
||||
* @en
|
||||
* Broken line:
|
||||
* Each knot is connected with a straight line from the beginning to the end to form a curve. At least two knots.
|
||||
* @zh
|
||||
* 每个结从头到尾用一条直线相连,形成一条曲线。 至少存在两个结点。
|
||||
*/
|
||||
LINEAR = 0,
|
||||
|
||||
/**
|
||||
* @en
|
||||
* Piecewise Bezier curve:
|
||||
* Every four knots form a curve. Total knots number must be a multiple of 4.
|
||||
* Each curve passes only the first and fourth knots, and does not pass through the middle two control knots.
|
||||
@@ -43,13 +47,29 @@ export enum SplineMode {
|
||||
* (1) Suppose the four knots of the previous curve are A, B, C, D
|
||||
* (2) The four knots of the next curve must be D, E, F, G
|
||||
* (3) C and E need to be symmetrical about D
|
||||
*
|
||||
* @zh
|
||||
* 分段贝塞尔曲线:
|
||||
* 每四个结形成一条曲线。 总节数必须是 4 的倍数。
|
||||
* 每条曲线只通过第一个和第四个结点,不通过中间两个控制结点。
|
||||
*
|
||||
* 如果你需要一条完整的连续曲线:
|
||||
* (1) 假设前面曲线的四个结点分别是 A, B, C, D
|
||||
* (2) 下一条曲线的四个结点必须是 D, E, F, G
|
||||
* (3) C 和 E 需要关于 D 对称
|
||||
*/
|
||||
BEZIER = 1,
|
||||
|
||||
/**
|
||||
* @en
|
||||
* Catmull Rom curve:
|
||||
* All knots(including start & end knots) form a whole continuous curve. At least two knots.
|
||||
* The whole curve passes through all knots.
|
||||
*
|
||||
* @zh
|
||||
* Catmull Rom 曲线:
|
||||
* 所有结点(包括起始结点和结束结点)形成一条完整的连续曲线。 至少存在两个结点。
|
||||
* 整条曲线穿过所有结点。
|
||||
*/
|
||||
CATMULL_ROM = 2
|
||||
}
|
||||
@@ -65,7 +85,7 @@ const _v3 = new Vec3();
|
||||
* @en
|
||||
* Basic Geometry: Spline.
|
||||
* @zh
|
||||
* 基础几何 Spline
|
||||
* 基础几何:Spline。
|
||||
*/
|
||||
|
||||
export class Spline {
|
||||
@@ -82,14 +102,40 @@ export class Spline {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @en
|
||||
* Creates a spline instance.
|
||||
* @zh
|
||||
* 创建一个 Spline 实例。
|
||||
* @param mode @en The mode to create the Spline instance. @zh 用于创建 Spline 实例的模式。
|
||||
* @param knots @en The knots to create the Spline instance. @zh 用于创建 Spline 实例的结点列表。
|
||||
* @returns @en The created Spline instance. @zh 创建出的 Spline 实例。
|
||||
*/
|
||||
public static create (mode: SplineMode, knots: Vec3[] = []) {
|
||||
return new Spline(mode, knots);
|
||||
}
|
||||
|
||||
/**
|
||||
* @en
|
||||
* Clones a Spline instance.
|
||||
* @zh
|
||||
* 克隆一个 Spline 实例。
|
||||
* @param s @en The Spline instance to be cloned. @zh 用于克隆的 Spline 实例。
|
||||
* @returns @en The cloned Spline instance. @zh 克隆出的 Spline 实例。
|
||||
*/
|
||||
public static clone (s: Spline) {
|
||||
return new Spline(s.mode, s.knots);
|
||||
}
|
||||
|
||||
/**
|
||||
* @en
|
||||
* Copies the values of a Spline instance to another.
|
||||
* @zh
|
||||
* 拷贝一个 Spline 实例的值到另一个中。
|
||||
* @param out @en The target Spline instance to copy to. @zh 拷贝目标 Spline 实例。
|
||||
* @param s @en The source Spline instance to copy from. @zh 拷贝源 Spline 实例。
|
||||
* @returns @en The target Spline instance to copy to, same as the `out` parameter. @zh 拷贝目标 Spline 实例,值与 `out` 参数相同。
|
||||
*/
|
||||
public static copy (out: Spline, s: Spline) {
|
||||
out._mode = s.mode;
|
||||
out._knots.length = 0;
|
||||
@@ -103,18 +149,44 @@ export class Spline {
|
||||
return out;
|
||||
}
|
||||
|
||||
/**
|
||||
* @en
|
||||
* Gets the type of this Spline instance, always returns `enums.SHAPE_SPLINE`.
|
||||
* @zh
|
||||
* 获取此 Spline 的类型,固定返回 `enums.SHAPE_SPLINE`
|
||||
*/
|
||||
get type () {
|
||||
return this._type;
|
||||
}
|
||||
|
||||
/**
|
||||
* @en
|
||||
* Gets the mode of this Spline instance.
|
||||
* @zh
|
||||
* 获取当前 Spline 实例的模式。
|
||||
*/
|
||||
get mode () {
|
||||
return this._mode;
|
||||
}
|
||||
|
||||
/**
|
||||
* @en
|
||||
* Gets all knots of this Spline instance.
|
||||
* @zh
|
||||
* 获取当前 Spline 实例的所有结点。
|
||||
*/
|
||||
get knots (): Readonly<Vec3[]> {
|
||||
return this._knots;
|
||||
}
|
||||
|
||||
/**
|
||||
* @en
|
||||
* Sets the mode and knots to this Spline instance.
|
||||
* @zh
|
||||
* 给当前 Spline 实例设置模式和结点。
|
||||
* @param mode @en The mode to be set to this Spline instance. @zh 要设置到当前 Spline 实例的模式。
|
||||
* @param knots @en The knots to be set to this spline instance. @zh 要设置到当前 Spline 实例的结点列表。
|
||||
*/
|
||||
public setModeAndKnots (mode: SplineMode, knots: Vec3[]) {
|
||||
this._mode = mode;
|
||||
this._knots.length = 0;
|
||||
@@ -124,18 +196,46 @@ export class Spline {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @en
|
||||
* Clears all knots of this Spline instance.
|
||||
* @zh
|
||||
* 清空当前 Spline 实例的所有结点。
|
||||
*/
|
||||
public clearKnots () {
|
||||
this._knots.length = 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* @en
|
||||
* Gets the knot count of this Spline instance.
|
||||
* @zh
|
||||
* 获取当前 Spline 实例的结点数量。
|
||||
* @returns @en The knot count of this Spline instance. @zh 当前 Spline 实例的结点数量。
|
||||
*/
|
||||
public getKnotCount () {
|
||||
return this._knots.length;
|
||||
}
|
||||
|
||||
/**
|
||||
* @en
|
||||
* Adds a knot to this Spline instance.
|
||||
* @zh
|
||||
* 给当前 Spline 实例添加一个结点。
|
||||
* @param knot @en The knot to add to this Spline instance. @zh 要添加到当前 Spline 实例的结点。
|
||||
*/
|
||||
public addKnot (knot: Vec3) {
|
||||
this._knots.push(new Vec3(knot));
|
||||
}
|
||||
|
||||
/**
|
||||
* @en
|
||||
* Inserts a knot to the specified position of this Spline instance.
|
||||
* @zh
|
||||
* 插入一个结点到当前 Spline 实例的指定位置。
|
||||
* @param index @en The position of this Spline instance to be inserted. @zh 要插入到此 Spline 实例的位置。
|
||||
* @param knot @en The knot to be inserted. @zh 要插入的结点。
|
||||
*/
|
||||
public insertKnot (index: number, knot: Vec3) {
|
||||
const item = new Vec3(knot);
|
||||
if (index >= this._knots.length) {
|
||||
@@ -146,34 +246,65 @@ export class Spline {
|
||||
this._knots.splice(index, 0, item);
|
||||
}
|
||||
|
||||
/**
|
||||
* @en
|
||||
* Removes a knot at the specified position of this Spline instance.
|
||||
* @zh
|
||||
* 移除当前 Spline 实例的指定位置的一个结点。
|
||||
* @param index
|
||||
*/
|
||||
public removeKnot (index: number) {
|
||||
assertIsTrue(index >= 0 && index < this._knots.length, 'Spline: invalid index');
|
||||
|
||||
this._knots.splice(index, 1);
|
||||
}
|
||||
|
||||
/**
|
||||
* @en
|
||||
* Sets a knot to the specified position of this Spline instance.
|
||||
* @zh
|
||||
* 为当前 Spline 实例的指定位置设置结点信息。
|
||||
* @param index @en The specified position of this Spline instance. @zh 要设置结点的指定位置。
|
||||
* @param knot @en The knot to be set to the specified position. @zh 要设置的结点。
|
||||
*/
|
||||
public setKnot (index: number, knot: Vec3) {
|
||||
assertIsTrue(index >= 0 && index < this._knots.length, 'Spline: invalid index');
|
||||
|
||||
this._knots[index].set(knot);
|
||||
}
|
||||
|
||||
/**
|
||||
* @en
|
||||
* Gets the knot of the specified position of this Spline instance.
|
||||
* @zh
|
||||
* 获取当前 Spline 实例指定位置的结点。
|
||||
* @param index @en The specified position of this Spline instance. @zh 要设置结点的指定位置。
|
||||
* @returns @en The knot of the specified position of this Spline instance. @zh 当前 Spline 实例指定位置的结点。
|
||||
*/
|
||||
public getKnot (index: number): Readonly<Vec3> {
|
||||
assertIsTrue(index >= 0 && index < this._knots.length, 'Spline: invalid index');
|
||||
|
||||
return this._knots[index];
|
||||
}
|
||||
|
||||
// get a point at t with repect to the `index` segment of curve or the whole curve.
|
||||
/**
|
||||
* @en
|
||||
* Gets a point at t with repect to the `index` segment of curve or the whole curve.
|
||||
* @zh
|
||||
* 获取 t 处相对于某段或整条曲线的点。
|
||||
* @param t @en The factor with a range of [0.0, 1.0]. @zh 0.0 到 1.0 的因子。
|
||||
* @param index @en The knot index of this Spline instance, default value is the whole curve. @zh 当前 Spline 实例的某个结点索引,默认值为整条曲线。
|
||||
* @returns @en The point matches the input `t` factor and `index`. @zh 满足输入 `t` 参数和 `index` 参数的点。
|
||||
*/
|
||||
public getPoint (t: number, index: number = SPLINE_WHOLE_INDEX) {
|
||||
t = clamp(t, 0.0, 1.0);
|
||||
|
||||
const segments = this.getSegments();
|
||||
if (segments == 0) {
|
||||
if (segments === 0) {
|
||||
return new Vec3(0.0, 0.0, 0.0);
|
||||
}
|
||||
|
||||
if (index == SPLINE_WHOLE_INDEX) {
|
||||
if (index === SPLINE_WHOLE_INDEX) {
|
||||
const deltaT = 1.0 / segments;
|
||||
|
||||
index = Math.floor(t / deltaT);
|
||||
@@ -199,13 +330,21 @@ export class Spline {
|
||||
}
|
||||
}
|
||||
|
||||
// get num points from 0 to 1 uniformly with repect to the `index` segment of curve or the whole curve
|
||||
/**
|
||||
* @en
|
||||
* Gets points from 0 to 1 uniformly with repect to the `index` segment of curve or the whole curve.
|
||||
* @zh
|
||||
* 获取相对与某段或整条曲线上的 n 个数量的点信息。
|
||||
* @param num @en The count of points needed. @zh 需要的点的数量。
|
||||
* @param index @en The knot index of this Spline instance, default value is the whole curve. @zh 当前 Spline 实例的某个结点索引,默认值为整条曲线。
|
||||
* @returns @en The points with `num` size at the `index` segment or the whole curve. @zh 曲线某段或者整条曲线上的 `num` 个点。
|
||||
*/
|
||||
public getPoints (num: number, index: number = SPLINE_WHOLE_INDEX): Vec3[] {
|
||||
if (num == 0) {
|
||||
if (num === 0) {
|
||||
return [];
|
||||
}
|
||||
|
||||
if (num == 1) {
|
||||
if (num === 1) {
|
||||
const point = this.getPoint(0.0, index);
|
||||
return [point];
|
||||
}
|
||||
|
||||
@@ -29,25 +29,25 @@ import enums from './enums';
|
||||
* @en
|
||||
* Basic Geometry: Triangle.
|
||||
* @zh
|
||||
* 基础几何 三角形。
|
||||
* 基础几何:三角形。
|
||||
*/
|
||||
|
||||
export class Triangle {
|
||||
/**
|
||||
* @en
|
||||
* create a new triangle
|
||||
* Creates a new triangle instance.
|
||||
* @zh
|
||||
* 创建一个新的 triangle。
|
||||
* @param {number} ax @en x component of point a @zh a 点的 x 部分。
|
||||
* @param {number} ay @en y component of point a @zh a 点的 y 部分。
|
||||
* @param {number} az @en z component of point a @zh a 点的 z 部分。
|
||||
* @param {number} bx @en x component of point b @zh b 点的 x 部分。
|
||||
* @param {number} by @en y component of point b @zh b 点的 y 部分。
|
||||
* @param {number} bz @en z component of point b @zh b 点的 z 部分。
|
||||
* @param {number} cx @en x component of point c @zh c 点的 x 部分。
|
||||
* @param {number} cy @en y component of point c @zh c 点的 y 部分。
|
||||
* @param {number} cz @en z component of point c @zh c 点的 z 部分。
|
||||
* @return {Triangle} @en A new triangle. @zh 一个新的 triangle。
|
||||
* 创建一个新的三角形。
|
||||
* @param {number} ax @en The x component of point a @zh a 点的 x 部分。
|
||||
* @param {number} ay @en The y component of point a @zh a 点的 y 部分。
|
||||
* @param {number} az @en The z component of point a @zh a 点的 z 部分。
|
||||
* @param {number} bx @en The x component of point b @zh b 点的 x 部分。
|
||||
* @param {number} by @en The y component of point b @zh b 点的 y 部分。
|
||||
* @param {number} bz @en The z component of point b @zh b 点的 z 部分。
|
||||
* @param {number} cx @en The x component of point c @zh c 点的 x 部分。
|
||||
* @param {number} cy @en The y component of point c @zh c 点的 y 部分。
|
||||
* @param {number} cz @en The z component of point c @zh c 点的 z 部分。
|
||||
* @returns {Triangle} @en The created Triangle instance. @zh 创建出的三角形实例。
|
||||
*/
|
||||
public static create (ax = 1, ay = 0, az = 0,
|
||||
bx = 0, by = 0, bz = 0,
|
||||
@@ -57,11 +57,11 @@ export class Triangle {
|
||||
|
||||
/**
|
||||
* @en
|
||||
* clone a new triangle
|
||||
* Clones a triangle instance.
|
||||
* @zh
|
||||
* 克隆一个新的 triangle。
|
||||
* @param {Triangle} @en Triangle object to be cloned from. @zh t 克隆的目标。
|
||||
* @return {Triangle} @en A new cloned Triangle object. @zh 克隆出的新对象。
|
||||
* 克隆一个新的三角形。
|
||||
* @param t @en The Triangle object to be cloned from. @zh 克隆的目标。
|
||||
* @returns @en The cloned triangle instance. @zh 克隆出的新对象。
|
||||
*/
|
||||
public static clone (t: Triangle): Triangle {
|
||||
return new Triangle(
|
||||
@@ -73,12 +73,12 @@ export class Triangle {
|
||||
|
||||
/**
|
||||
* @en
|
||||
* copy the values from one triangle to another
|
||||
* Copies the values from one triangle to another.
|
||||
* @zh
|
||||
* 将一个 triangle 的值复制到另一个 triangle。
|
||||
* @param {Triangle} out @en Target Triangle object to be copied to. @zh 接受操作的 triangle。
|
||||
* @param {Triangle} t @en A Triangle object to be copied from. @zh 被复制的 triangle。
|
||||
* @return {Triangle} @en The same as out. @zh out 接受操作的 triangle。
|
||||
* 复制一个三角形的值到另一个三角形中。
|
||||
* @param out @en The target Triangle object to be copied to. @zh 接受操作的三角形。
|
||||
* @param t @en A Triangle object to be copied from. @zh 被复制的三角形。
|
||||
* @returns @en The target Triangle object to be copied to, same as the `out` parameter. @zh 接受操作的三角形,与 `out` 参数相同。
|
||||
*/
|
||||
public static copy (out: Triangle, t: Triangle): Triangle {
|
||||
Vec3.copy(out.a, t.a);
|
||||
@@ -90,14 +90,14 @@ export class Triangle {
|
||||
|
||||
/**
|
||||
* @en
|
||||
* Create a triangle from three points
|
||||
* Creates a triangle instance from three points.
|
||||
* @zh
|
||||
* 用三个点创建一个 triangle。
|
||||
* @param {Triangle} out @en The Triangle object to be modified. @zh 接受操作的 triangle。
|
||||
* @param {Vec3} a @en The point value to set out.a. @zh a 点。
|
||||
* @param {Vec3} b @en The point value to set out.b. @zh b 点。
|
||||
* @param {Vec3} c @en The point value to set out.c. @zh c 点。
|
||||
* @return {Triangle} @en The same as out. @zh 接受操作的 triangle。
|
||||
* 用三个点创建一个三角形。
|
||||
* @param out @en The Triangle object to be modified. @zh 接受操作的三角形。
|
||||
* @param a @en The point value to set out.a. @zh a 点。
|
||||
* @param b @en The point value to set out.b. @zh b 点。
|
||||
* @param c @en The point value to set out.c. @zh c 点。
|
||||
* @returns @en The Triangle object to be modified, same as the `out` parameter. @zh 接受操作的三角形,与 `out` 参数相同。
|
||||
*/
|
||||
public static fromPoints (out: Triangle, a: Vec3, b: Vec3, c: Vec3): Triangle {
|
||||
Vec3.copy(out.a, a);
|
||||
@@ -108,21 +108,20 @@ export class Triangle {
|
||||
|
||||
/**
|
||||
* @en
|
||||
* Set the components of a triangle to the given values
|
||||
* Sets the components of a triangle to the given values.
|
||||
* @zh
|
||||
* 将给定三角形的属性设置为给定值。
|
||||
* @param {Triangle} out @en The Triangle object to be set. @zh 被修改的三角形。
|
||||
* @param {number} ax @en The value to set out.a.x. @zh a 点的 x 部分。
|
||||
* @param {number} ay @en The value to set out.a.y. @zh a 点的 y 部分。
|
||||
* @param {number} az @en The value to set out.a.z. @zh a 点的 z 部分。
|
||||
* @param {number} bx @en The value to set out.b.x. @zh b 点的 x 部分。
|
||||
* @param {number} by @en The value to set out.b.y. @zh b 点的 y 部分。
|
||||
* @param {number} bz @en The value to set out.b.z. @zh b 点的 z 部分。
|
||||
* @param {number} cx @en The value to set out.c.x. @zh c 点的 x 部分。
|
||||
* @param {number} cy @en The value to set out.c.y. @zh c 点的 y 部分。
|
||||
* @param {number} cz @en The value to set out.c.z. @zh c 点的 z 部分。
|
||||
* @return {Triangle} @en The same as out. @zh 传入的 out 对象。
|
||||
* @function
|
||||
* @param out @en The Triangle object to be set. @zh 接受操作的三角形。
|
||||
* @param ax @en The value to set out.a.x. @zh a 点的 x 部分。
|
||||
* @param ay @en The value to set out.a.y. @zh a 点的 y 部分。
|
||||
* @param az @en The value to set out.a.z. @zh a 点的 z 部分。
|
||||
* @param bx @en The value to set out.b.x. @zh b 点的 x 部分。
|
||||
* @param by @en The value to set out.b.y. @zh b 点的 y 部分。
|
||||
* @param bz @en The value to set out.b.z. @zh b 点的 z 部分。
|
||||
* @param cx @en The value to set out.c.x. @zh c 点的 x 部分。
|
||||
* @param cy @en The value to set out.c.y. @zh c 点的 y 部分。
|
||||
* @param cz @en The value to set out.c.z. @zh c 点的 z 部分。
|
||||
* @returns @en The Triangle object to be set, same as the `out` parameter. @zh 接受操作的三角形,与 `out` 参数相同。
|
||||
*/
|
||||
public static set (out: Triangle,
|
||||
ax: number, ay: number, az: number,
|
||||
@@ -169,9 +168,9 @@ export class Triangle {
|
||||
|
||||
/**
|
||||
* @en
|
||||
* Gets the type of the shape.
|
||||
* Gets the type of the triangle, always returns `enums.SHAPE_TRIANGLE`.
|
||||
* @zh
|
||||
* 获取形状的类型。
|
||||
* 获取此三角形的类型,固定返回 `enums.SHAPE_TRIANGLE`。
|
||||
*/
|
||||
get type () {
|
||||
return this._type;
|
||||
@@ -181,7 +180,7 @@ export class Triangle {
|
||||
|
||||
/**
|
||||
* @en
|
||||
* Construct a triangle.
|
||||
* Constructs a triangle.
|
||||
* @zh
|
||||
* 构造一个三角形。
|
||||
* @param {number} ax @en x component of point a. @zh a 点的 x 部分。
|
||||
|
||||
+6
-1
@@ -31,7 +31,7 @@ import { ConfigOrientation } from 'pal/screen-adapter';
|
||||
import assetManager, { IAssetManagerOptions } from '../asset/asset-manager/asset-manager';
|
||||
import { EventTarget, AsyncDelegate, sys, macro, VERSION, cclegacy, screen, Settings, settings, assert, garbageCollectionManager, DebugMode, warn, log, _resetDebugSetting } from '../core';
|
||||
import { input } from '../input';
|
||||
import { deviceManager } from '../gfx';
|
||||
import { deviceManager, LegacyRenderMode } from '../gfx';
|
||||
import { SplashScreen } from './splash-screen';
|
||||
import { RenderPipeline } from '../rendering';
|
||||
import { Layers, Node } from '../scene-graph';
|
||||
@@ -775,6 +775,11 @@ export class Game extends EventTarget {
|
||||
if (!cclegacy.rendering || !cclegacy.rendering.enableEffectImport) {
|
||||
return;
|
||||
}
|
||||
const renderMode = settings.querySettings(Settings.Category.RENDERING, 'renderMode');
|
||||
if (renderMode === LegacyRenderMode.HEADLESS) {
|
||||
cclegacy.rendering.init(deviceManager.gfxDevice, null);
|
||||
return;
|
||||
}
|
||||
const data = effectSettings.data;
|
||||
if (data === null) {
|
||||
console.error('Effect settings not found, effects will not be imported.');
|
||||
|
||||
@@ -1257,6 +1257,7 @@ export class UniformBlock {
|
||||
public name: string = '',
|
||||
public members: Uniform[] = [],
|
||||
public count: number = 0,
|
||||
public flattened: number = 0,
|
||||
) {}
|
||||
|
||||
public copy (info: Readonly<UniformBlock>) {
|
||||
@@ -1265,6 +1266,7 @@ export class UniformBlock {
|
||||
this.name = info.name;
|
||||
deepCopy(this.members, info.members, Uniform);
|
||||
this.count = info.count;
|
||||
this.flattened = info.flattened;
|
||||
return this;
|
||||
}
|
||||
}
|
||||
@@ -1278,6 +1280,7 @@ export class UniformSamplerTexture {
|
||||
public name: string = '',
|
||||
public type: Type = Type.UNKNOWN,
|
||||
public count: number = 0,
|
||||
public flattened: number = 0,
|
||||
) {}
|
||||
|
||||
public copy (info: Readonly<UniformSamplerTexture>) {
|
||||
@@ -1286,6 +1289,7 @@ export class UniformSamplerTexture {
|
||||
this.name = info.name;
|
||||
this.type = info.type;
|
||||
this.count = info.count;
|
||||
this.flattened = info.flattened;
|
||||
return this;
|
||||
}
|
||||
}
|
||||
@@ -1298,6 +1302,7 @@ export class UniformSampler {
|
||||
public binding: number = 0,
|
||||
public name: string = '',
|
||||
public count: number = 0,
|
||||
public flattened: number = 0,
|
||||
) {}
|
||||
|
||||
public copy (info: Readonly<UniformSampler>) {
|
||||
@@ -1305,6 +1310,7 @@ export class UniformSampler {
|
||||
this.binding = info.binding;
|
||||
this.name = info.name;
|
||||
this.count = info.count;
|
||||
this.flattened = info.flattened;
|
||||
return this;
|
||||
}
|
||||
}
|
||||
@@ -1318,6 +1324,7 @@ export class UniformTexture {
|
||||
public name: string = '',
|
||||
public type: Type = Type.UNKNOWN,
|
||||
public count: number = 0,
|
||||
public flattened: number = 0,
|
||||
) {}
|
||||
|
||||
public copy (info: Readonly<UniformTexture>) {
|
||||
@@ -1326,6 +1333,7 @@ export class UniformTexture {
|
||||
this.name = info.name;
|
||||
this.type = info.type;
|
||||
this.count = info.count;
|
||||
this.flattened = info.flattened;
|
||||
return this;
|
||||
}
|
||||
}
|
||||
@@ -1340,6 +1348,7 @@ export class UniformStorageImage {
|
||||
public type: Type = Type.UNKNOWN,
|
||||
public count: number = 0,
|
||||
public memoryAccess: MemoryAccess = MemoryAccessBit.READ_WRITE,
|
||||
public flattened: number = 0,
|
||||
) {}
|
||||
|
||||
public copy (info: Readonly<UniformStorageImage>) {
|
||||
@@ -1349,6 +1358,7 @@ export class UniformStorageImage {
|
||||
this.type = info.type;
|
||||
this.count = info.count;
|
||||
this.memoryAccess = info.memoryAccess;
|
||||
this.flattened = info.flattened;
|
||||
return this;
|
||||
}
|
||||
}
|
||||
@@ -1362,6 +1372,7 @@ export class UniformStorageBuffer {
|
||||
public name: string = '',
|
||||
public count: number = 0,
|
||||
public memoryAccess: MemoryAccess = MemoryAccessBit.READ_WRITE,
|
||||
public flattened: number = 0,
|
||||
) {}
|
||||
|
||||
public copy (info: Readonly<UniformStorageBuffer>) {
|
||||
@@ -1370,6 +1381,7 @@ export class UniformStorageBuffer {
|
||||
this.name = info.name;
|
||||
this.count = info.count;
|
||||
this.memoryAccess = info.memoryAccess;
|
||||
this.flattened = info.flattened;
|
||||
return this;
|
||||
}
|
||||
}
|
||||
@@ -1382,6 +1394,7 @@ export class UniformInputAttachment {
|
||||
public binding: number = 0,
|
||||
public name: string = '',
|
||||
public count: number = 0,
|
||||
public flattened: number = 0,
|
||||
) {}
|
||||
|
||||
public copy (info: Readonly<UniformInputAttachment>) {
|
||||
@@ -1389,6 +1402,7 @@ export class UniformInputAttachment {
|
||||
this.binding = info.binding;
|
||||
this.name = info.name;
|
||||
this.count = info.count;
|
||||
this.flattened = info.flattened;
|
||||
return this;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -585,14 +585,14 @@ export class BlendState {
|
||||
this._nativeObj = new gfx.BlendState();
|
||||
this._setTargets(targets);
|
||||
this.blendColor = blendColor;
|
||||
this.isA2c = isA2C;
|
||||
this.isA2C = isA2C;
|
||||
this.isIndepend = isIndepend;
|
||||
}
|
||||
|
||||
get isA2c (): boolean {
|
||||
get isA2C (): boolean {
|
||||
return this._isA2C;
|
||||
}
|
||||
set isA2c (val: boolean) {
|
||||
set isA2C (val: boolean) {
|
||||
this._isA2C = val;
|
||||
this._nativeObj.isA2C = val;
|
||||
}
|
||||
@@ -628,7 +628,7 @@ export class BlendState {
|
||||
}
|
||||
|
||||
public reset () {
|
||||
this.isA2c = false;
|
||||
this.isA2C = false;
|
||||
this.isIndepend = false;
|
||||
this.blendColor = new Color(0, 0, 0, 0);
|
||||
|
||||
|
||||
@@ -22,7 +22,7 @@
|
||||
THE SOFTWARE.
|
||||
*/
|
||||
|
||||
import { debug, error, errorID, CachedArray } from '../../core';
|
||||
import { debug, error, errorID, CachedArray, cclegacy } from '../../core';
|
||||
import { WebGLCommandAllocator } from './webgl-command-allocator';
|
||||
import { WebGLEXT } from './webgl-define';
|
||||
import { WebGLDevice } from './webgl-device';
|
||||
@@ -1460,26 +1460,40 @@ export function WebGLCmdFuncCreateShader (device: WebGLDevice, gpuShader: IWebGL
|
||||
const { bindingMappings } = device;
|
||||
const { texUnitCacheMap } = device.stateCache;
|
||||
|
||||
let flexibleSetBaseOffset = 0;
|
||||
for (let i = 0; i < gpuShader.blocks.length; ++i) {
|
||||
if (gpuShader.blocks[i].set === bindingMappings.flexibleSet) {
|
||||
flexibleSetBaseOffset++;
|
||||
if (!(cclegacy.rendering && cclegacy.rendering.enableEffectImport)) {
|
||||
let flexibleSetBaseOffset = 0;
|
||||
for (let i = 0; i < gpuShader.blocks.length; ++i) {
|
||||
if (gpuShader.blocks[i].set === bindingMappings.flexibleSet) {
|
||||
flexibleSetBaseOffset++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
let arrayOffset = 0;
|
||||
for (let i = 0; i < gpuShader.samplerTextures.length; ++i) {
|
||||
const sampler = gpuShader.samplerTextures[i];
|
||||
const glLoc = gl.getUniformLocation(gpuShader.glProgram, sampler.name);
|
||||
if (device.extensions.isLocationActive(glLoc)) {
|
||||
glActiveSamplers.push(gpuShader.glSamplerTextures[i]);
|
||||
glActiveSamplerLocations.push(glLoc);
|
||||
let arrayOffset = 0;
|
||||
for (let i = 0; i < gpuShader.samplerTextures.length; ++i) {
|
||||
const sampler = gpuShader.samplerTextures[i];
|
||||
const glLoc = gl.getUniformLocation(gpuShader.glProgram, sampler.name);
|
||||
if (device.extensions.isLocationActive(glLoc)) {
|
||||
glActiveSamplers.push(gpuShader.glSamplerTextures[i]);
|
||||
glActiveSamplerLocations.push(glLoc);
|
||||
}
|
||||
if (texUnitCacheMap[sampler.name] === undefined) {
|
||||
let binding = sampler.binding + bindingMappings.samplerTextureOffsets[sampler.set] + arrayOffset;
|
||||
if (sampler.set === bindingMappings.flexibleSet) { binding -= flexibleSetBaseOffset; }
|
||||
texUnitCacheMap[sampler.name] = binding % device.capabilities.maxTextureUnits;
|
||||
arrayOffset += sampler.count - 1;
|
||||
}
|
||||
}
|
||||
if (texUnitCacheMap[sampler.name] === undefined) {
|
||||
let binding = sampler.binding + bindingMappings.samplerTextureOffsets[sampler.set] + arrayOffset;
|
||||
if (sampler.set === bindingMappings.flexibleSet) { binding -= flexibleSetBaseOffset; }
|
||||
texUnitCacheMap[sampler.name] = binding % device.capabilities.maxTextureUnits;
|
||||
arrayOffset += sampler.count - 1;
|
||||
} else {
|
||||
for (let i = 0; i < gpuShader.samplerTextures.length; ++i) {
|
||||
const sampler = gpuShader.samplerTextures[i];
|
||||
const glLoc = gl.getUniformLocation(gpuShader.glProgram, sampler.name);
|
||||
if (device.extensions.isLocationActive(glLoc)) {
|
||||
glActiveSamplers.push(gpuShader.glSamplerTextures[i]);
|
||||
glActiveSamplerLocations.push(glLoc);
|
||||
}
|
||||
if (texUnitCacheMap[sampler.name] === undefined) {
|
||||
texUnitCacheMap[sampler.name] = sampler.flattened;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -46,7 +46,7 @@ import {
|
||||
IWebGL2GPUUniformSamplerTexture,
|
||||
IWebGL2GPURenderPass,
|
||||
} from './webgl2-gpu-objects';
|
||||
import { CachedArray, error, errorID, debug } from '../../core';
|
||||
import { CachedArray, error, errorID, debug, cclegacy } from '../../core';
|
||||
|
||||
const WebGLWraps: GLenum[] = [
|
||||
0x2901, // WebGLRenderingContext.REPEAT
|
||||
@@ -1614,6 +1614,8 @@ export function WebGL2CmdFuncCreateShader (device: WebGL2Device, gpuShader: IWeb
|
||||
|
||||
gpuShader.glProgram = glProgram;
|
||||
|
||||
const enableEffectImport = !!(cclegacy.rendering && cclegacy.rendering.enableEffectImport);
|
||||
|
||||
// link program
|
||||
for (let k = 0; k < gpuShader.gpuStages.length; k++) {
|
||||
const gpuStage = gpuShader.gpuStages[k];
|
||||
@@ -1704,7 +1706,10 @@ export function WebGL2CmdFuncCreateShader (device: WebGL2Device, gpuShader: IWeb
|
||||
// blockIdx = gl.getUniformBlockIndex(gpuShader.glProgram, blockName);
|
||||
blockIdx = b;
|
||||
blockSize = gl.getActiveUniformBlockParameter(gpuShader.glProgram, blockIdx, gl.UNIFORM_BLOCK_DATA_SIZE);
|
||||
const glBinding = block.binding + (device.bindingMappings.blockOffsets[block.set] || 0);
|
||||
|
||||
const glBinding = enableEffectImport
|
||||
? block.flattened
|
||||
: block.binding + (device.bindingMappings.blockOffsets[block.set] || 0);
|
||||
|
||||
gl.uniformBlockBinding(gpuShader.glProgram, blockIdx, glBinding);
|
||||
|
||||
@@ -1753,27 +1758,42 @@ export function WebGL2CmdFuncCreateShader (device: WebGL2Device, gpuShader: IWeb
|
||||
const glActiveSamplerLocations: WebGLUniformLocation[] = [];
|
||||
const texUnitCacheMap = device.stateCache.texUnitCacheMap;
|
||||
|
||||
let flexibleSetBaseOffset = 0;
|
||||
for (let i = 0; i < gpuShader.blocks.length; ++i) {
|
||||
if (gpuShader.blocks[i].set === device.bindingMappings.flexibleSet) {
|
||||
flexibleSetBaseOffset++;
|
||||
if (!enableEffectImport) {
|
||||
let flexibleSetBaseOffset = 0;
|
||||
for (let i = 0; i < gpuShader.blocks.length; ++i) {
|
||||
if (gpuShader.blocks[i].set === device.bindingMappings.flexibleSet) {
|
||||
flexibleSetBaseOffset++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
let arrayOffset = 0;
|
||||
for (let i = 0; i < gpuShader.samplerTextures.length; ++i) {
|
||||
const sampler = gpuShader.samplerTextures[i];
|
||||
const glLoc = gl.getUniformLocation(gpuShader.glProgram, sampler.name);
|
||||
// wEcHAT just returns { id: -1 } for non-existing names /eyerolling
|
||||
if (glLoc && (glLoc as any).id !== -1) {
|
||||
glActiveSamplers.push(gpuShader.glSamplerTextures[i]);
|
||||
glActiveSamplerLocations.push(glLoc);
|
||||
let arrayOffset = 0;
|
||||
for (let i = 0; i < gpuShader.samplerTextures.length; ++i) {
|
||||
const sampler = gpuShader.samplerTextures[i];
|
||||
const glLoc = gl.getUniformLocation(gpuShader.glProgram, sampler.name);
|
||||
// wEcHAT just returns { id: -1 } for non-existing names /eyerolling
|
||||
if (glLoc && (glLoc as any).id !== -1) {
|
||||
glActiveSamplers.push(gpuShader.glSamplerTextures[i]);
|
||||
glActiveSamplerLocations.push(glLoc);
|
||||
}
|
||||
if (texUnitCacheMap[sampler.name] === undefined) {
|
||||
let binding = sampler.binding + device.bindingMappings.samplerTextureOffsets[sampler.set] + arrayOffset;
|
||||
if (sampler.set === device.bindingMappings.flexibleSet) { binding -= flexibleSetBaseOffset; }
|
||||
texUnitCacheMap[sampler.name] = binding % device.capabilities.maxTextureUnits;
|
||||
arrayOffset += sampler.count - 1;
|
||||
}
|
||||
}
|
||||
if (texUnitCacheMap[sampler.name] === undefined) {
|
||||
let binding = sampler.binding + device.bindingMappings.samplerTextureOffsets[sampler.set] + arrayOffset;
|
||||
if (sampler.set === device.bindingMappings.flexibleSet) { binding -= flexibleSetBaseOffset; }
|
||||
texUnitCacheMap[sampler.name] = binding % device.capabilities.maxTextureUnits;
|
||||
arrayOffset += sampler.count - 1;
|
||||
} else {
|
||||
for (let i = 0; i < gpuShader.samplerTextures.length; ++i) {
|
||||
const sampler = gpuShader.samplerTextures[i];
|
||||
const glLoc = gl.getUniformLocation(gpuShader.glProgram, sampler.name);
|
||||
// wEcHAT just returns { id: -1 } for non-existing names /eyerolling
|
||||
if (glLoc && (glLoc as any).id !== -1) {
|
||||
glActiveSamplers.push(gpuShader.glSamplerTextures[i]);
|
||||
glActiveSamplerLocations.push(glLoc);
|
||||
}
|
||||
if (texUnitCacheMap[sampler.name] === undefined) {
|
||||
texUnitCacheMap[sampler.name] = sampler.flattened % device.capabilities.maxTextureUnits;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -22,6 +22,7 @@
|
||||
THE SOFTWARE.
|
||||
*/
|
||||
|
||||
import { systemInfo } from 'pal/system-info';
|
||||
import { DescriptorSet } from '../base/descriptor-set';
|
||||
import { DescriptorSetLayout } from '../base/descriptor-set-layout';
|
||||
import { PipelineLayout } from '../base/pipeline-layout';
|
||||
@@ -61,10 +62,11 @@ import { WebGL2CmdFuncCopyTextureToBuffers, WebGL2CmdFuncCopyBuffersToTexture, W
|
||||
import { GeneralBarrier } from '../base/states/general-barrier';
|
||||
import { TextureBarrier } from '../base/states/texture-barrier';
|
||||
import { BufferBarrier } from '../base/states/buffer-barrier';
|
||||
import { debug } from '../../core';
|
||||
import { debug, sys } from '../../core';
|
||||
import { Swapchain } from '../base/swapchain';
|
||||
import { IWebGL2Extensions, WebGL2DeviceManager } from './webgl2-define';
|
||||
import { IWebGL2BindingMapping } from './webgl2-gpu-objects';
|
||||
import { BrowserType, OS } from '../../../pal/system-info/enum-type';
|
||||
|
||||
export class WebGL2Device extends Device {
|
||||
get gl () {
|
||||
@@ -146,6 +148,13 @@ export class WebGL2Device extends Device {
|
||||
|
||||
this._caps.maxVertexAttributes = gl.getParameter(gl.MAX_VERTEX_ATTRIBS);
|
||||
this._caps.maxVertexUniformVectors = gl.getParameter(gl.MAX_VERTEX_UNIFORM_VECTORS);
|
||||
// WECHAT browser in IOS implementation of WebGL2 exist bugs.
|
||||
// iOS15.5 or higher 15.x version the max valid vertex uniform vectors is 256.
|
||||
// iOS16.0 or higher 16.x version the max valid vertex uniform vectors is 520?
|
||||
// So limit wechat browser in IOS using vertex uniform vectors no more than 256.
|
||||
if (systemInfo.os === OS.IOS && sys.browserType === BrowserType.WECHAT) {
|
||||
this._caps.maxVertexUniformVectors = 256;
|
||||
}
|
||||
this._caps.maxFragmentUniformVectors = gl.getParameter(gl.MAX_FRAGMENT_UNIFORM_VECTORS);
|
||||
this._caps.maxTextureUnits = gl.getParameter(gl.MAX_TEXTURE_IMAGE_UNITS);
|
||||
this._caps.maxVertexTextureUnits = gl.getParameter(gl.MAX_VERTEX_TEXTURE_IMAGE_UNITS);
|
||||
|
||||
@@ -27,14 +27,15 @@ import { BufferInfo, Buffer, BufferUsageBit, ClearFlagBit, Color, DescriptorSet,
|
||||
import { Camera, CSMLevel, DirectionalLight, Light, LightType, ReflectionProbe, ShadowType, SKYBOX_FLAG, SpotLight } from '../../render-scene/scene';
|
||||
import { supportsR32FloatTexture } from '../define';
|
||||
import { Pipeline } from './pipeline';
|
||||
import { AccessType, AttachmentType, ComputeView, LightInfo, QueueHint, RasterView, ResourceResidency, SceneFlags } from './types';
|
||||
import { Vec4, macro, geometry, toRadian, cclegacy } from '../../core';
|
||||
import { AccessType, AttachmentType, ComputeView, LightInfo, QueueHint, RasterView, ResourceResidency, SceneFlags, UpdateFrequency } from './types';
|
||||
import { Vec4, macro, geometry, toRadian, cclegacy, assert } from '../../core';
|
||||
import { Material } from '../../asset/assets';
|
||||
import { SRGBToLinear } from '../pipeline-funcs';
|
||||
import { RenderWindow } from '../../render-scene/core/render-window';
|
||||
import { RenderData } from './render-graph';
|
||||
import { WebPipeline } from './web-pipeline';
|
||||
import { DescriptorSetData } from './layout-graph';
|
||||
import { legacyCC } from '../../core/global-exports';
|
||||
|
||||
// Anti-aliasing type, other types will be gradually added in the future
|
||||
export enum AntiAliasing {
|
||||
@@ -315,7 +316,7 @@ export function buildBloomPass (camera: Camera,
|
||||
}
|
||||
ppl.updateRenderTarget(bloomPassPrefilterRTName, width, height);
|
||||
ppl.updateDepthStencil(bloomPassPrefilterDSName, width, height);
|
||||
const bloomPrefilterPass = ppl.addRasterPass(width, height, 'Bloom_Prefilter');
|
||||
const bloomPrefilterPass = ppl.addRasterPass(width, height, 'bloom-prefilter');
|
||||
bloomPrefilterPass.name = `CameraBloomPrefilterPass${cameraID}`;
|
||||
bloomPrefilterPass.setViewport(new Viewport(area.x, area.y, width, height));
|
||||
if (ppl.containsResource(inputRT)) {
|
||||
@@ -347,7 +348,7 @@ export function buildBloomPass (camera: Camera,
|
||||
}
|
||||
ppl.updateRenderTarget(bloomPassDownSampleRTName, width, height);
|
||||
ppl.updateDepthStencil(bloomPassDownSampleDSName, width, height);
|
||||
const bloomDownSamplePass = ppl.addRasterPass(width, height, `Bloom_Downsample${i}`);
|
||||
const bloomDownSamplePass = ppl.addRasterPass(width, height, `bloom-downsample${i}`);
|
||||
bloomDownSamplePass.name = `CameraBloomDownSamplePass${cameraID}${i}`;
|
||||
bloomDownSamplePass.setViewport(new Viewport(area.x, area.y, width, height));
|
||||
const computeView = new ComputeView();
|
||||
@@ -382,7 +383,7 @@ export function buildBloomPass (camera: Camera,
|
||||
}
|
||||
ppl.updateRenderTarget(bloomPassUpSampleRTName, width, height);
|
||||
ppl.updateDepthStencil(bloomPassUpSampleDSName, width, height);
|
||||
const bloomUpSamplePass = ppl.addRasterPass(width, height, `Bloom_Upsample${i}`);
|
||||
const bloomUpSamplePass = ppl.addRasterPass(width, height, `bloom-upsample${i}`);
|
||||
bloomUpSamplePass.name = `CameraBloomUpSamplePass${cameraID}${bloomData.iterations - 1 - i}`;
|
||||
bloomUpSamplePass.setViewport(new Viewport(area.x, area.y, width, height));
|
||||
const computeView = new ComputeView();
|
||||
@@ -416,7 +417,7 @@ export function buildBloomPass (camera: Camera,
|
||||
}
|
||||
ppl.updateRenderTarget(bloomPassCombineRTName, width, height);
|
||||
ppl.updateDepthStencil(bloomPassCombineDSName, width, height);
|
||||
const bloomCombinePass = ppl.addRasterPass(width, height, 'Bloom_Combine');
|
||||
const bloomCombinePass = ppl.addRasterPass(width, height, 'bloom-combine');
|
||||
bloomCombinePass.name = `CameraBloomCombinePass${cameraID}`;
|
||||
bloomCombinePass.setViewport(new Viewport(area.x, area.y, width, height));
|
||||
const computeViewOut = new ComputeView();
|
||||
@@ -486,7 +487,7 @@ export function buildPostprocessPass (camera: Camera,
|
||||
}
|
||||
ppl.updateRenderWindow(postprocessPassRTName, camera.window);
|
||||
ppl.updateDepthStencil(postprocessPassDS, width, height);
|
||||
const postprocessPass = ppl.addRasterPass(width, height, 'Postprocess');
|
||||
const postprocessPass = ppl.addRasterPass(width, height, 'post-process');
|
||||
postprocessPass.name = `CameraPostprocessPass${cameraID}`;
|
||||
postprocessPass.setViewport(new Viewport(area.x, area.y, area.width, area.height));
|
||||
if (ppl.containsResource(inputTex)) {
|
||||
@@ -777,7 +778,7 @@ export function buildGBufferPass (camera: Camera,
|
||||
ppl.updateRenderTarget(gBufferPassEmissive, width, height);
|
||||
ppl.updateDepthStencil(gBufferPassDSName, width, height);
|
||||
// gbuffer pass
|
||||
const gBufferPass = ppl.addRasterPass(width, height, 'Geometry');
|
||||
const gBufferPass = ppl.addRasterPass(width, height, 'default');
|
||||
gBufferPass.name = `CameraGBufferPass${cameraID}`;
|
||||
gBufferPass.setViewport(new Viewport(area.x, area.y, area.width, area.height));
|
||||
const rtColor = new Color(0, 0, 0, 0);
|
||||
@@ -866,7 +867,7 @@ export function buildLightingPass (camera: Camera, ppl: Pipeline, gBuffer: GBuff
|
||||
ppl.updateRenderTarget(deferredLightingPassRTName, width, height);
|
||||
ppl.updateDepthStencil(deferredLightingPassDS, width, height);
|
||||
// lighting pass
|
||||
const lightingPass = ppl.addRasterPass(width, height, 'Lighting');
|
||||
const lightingPass = ppl.addRasterPass(width, height, 'deferred-lighting');
|
||||
lightingPass.name = `CameraLightingPass${cameraID}`;
|
||||
lightingPass.setViewport(new Viewport(area.x, area.y, width, height));
|
||||
for (const dirShadowName of cameraInfo.mainLightShadowNames) {
|
||||
@@ -1106,11 +1107,11 @@ function bindDescValue (desc: DescriptorSet, binding: number, value) {
|
||||
}
|
||||
}
|
||||
|
||||
function bindGlobalDesc (pipeline: Pipeline, binding: number, value) {
|
||||
bindDescValue(pipeline.descriptorSet, binding, value);
|
||||
function bindGlobalDesc (desc: DescriptorSet, binding: number, value) {
|
||||
bindDescValue(desc, binding, value);
|
||||
}
|
||||
|
||||
function getDescBinding (descId, descData: DescriptorSetData): number {
|
||||
export function getDescBinding (descId, descData: DescriptorSetData): number {
|
||||
const layoutData = descData;
|
||||
// find descriptor binding
|
||||
for (const block of layoutData.descriptorSetLayoutData.descriptorBlocks) {
|
||||
@@ -1147,15 +1148,17 @@ export function getDescBindingFromName (bindingName: string) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
function applyGlobalDescBinding (pipeline: Pipeline, data: RenderData, isUpdate = false) {
|
||||
function applyGlobalDescBinding (data: RenderData, layout: string, isUpdate = false) {
|
||||
const constants = data.constants;
|
||||
const samplers = data.samplers;
|
||||
const textures = data.textures;
|
||||
const device = cclegacy.director.root.device;
|
||||
const currPip = pipeline as WebPipeline;
|
||||
const descriptorSetData = getDescriptorSetDataFromLayout(layout)!;
|
||||
const descriptorSet = descriptorSetData.descriptorSet!;
|
||||
for (const [key, value] of constants) {
|
||||
const bindId = getDescBinding(key, currPip.globalDescriptorSetData);
|
||||
let buffer = pipeline.descriptorSet.getBuffer(bindId);
|
||||
const bindId = getDescBinding(key, descriptorSetData);
|
||||
if (bindId === -1) { continue; }
|
||||
let buffer = descriptorSet.getBuffer(bindId);
|
||||
let haveBuff = true;
|
||||
if (!buffer && !isUpdate) {
|
||||
buffer = device.createBuffer(new BufferInfo(BufferUsageBit.UNIFORM | BufferUsageBit.TRANSFER_DST,
|
||||
@@ -1165,28 +1168,74 @@ function applyGlobalDescBinding (pipeline: Pipeline, data: RenderData, isUpdate
|
||||
haveBuff = false;
|
||||
}
|
||||
if (isUpdate) buffer.update(new Float32Array(value));
|
||||
if (!haveBuff) bindGlobalDesc(pipeline, bindId, buffer);
|
||||
if (!haveBuff) bindGlobalDesc(descriptorSet, bindId, buffer);
|
||||
}
|
||||
for (const [key, value] of textures) {
|
||||
const bindId = getDescBinding(key, currPip.globalDescriptorSetData);
|
||||
const tex = pipeline.descriptorSet.getTexture(bindId);
|
||||
const bindId = getDescBinding(key, descriptorSetData);
|
||||
if (bindId === -1) { continue; }
|
||||
const tex = descriptorSet.getTexture(bindId);
|
||||
if (!tex || isUpdate) {
|
||||
bindGlobalDesc(pipeline, bindId, value);
|
||||
bindGlobalDesc(descriptorSet, bindId, value);
|
||||
}
|
||||
}
|
||||
for (const [key, value] of samplers) {
|
||||
const bindId = getDescBinding(key, currPip.globalDescriptorSetData);
|
||||
const sampler = pipeline.descriptorSet.getSampler(bindId);
|
||||
const bindId = getDescBinding(key, descriptorSetData);
|
||||
if (bindId === -1) { continue; }
|
||||
const sampler = descriptorSet.getSampler(bindId);
|
||||
if (!sampler || isUpdate) {
|
||||
bindGlobalDesc(pipeline, bindId, value);
|
||||
bindGlobalDesc(descriptorSet, bindId, value);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export function initGlobalDescBinding (pipeline: Pipeline, data: RenderData) {
|
||||
applyGlobalDescBinding(pipeline, data);
|
||||
const layouts: Map<string, DescriptorSetData> = new Map();
|
||||
export function getDescriptorSetDataFromLayout (layoutName: string) {
|
||||
const descLayout = layouts.get(layoutName);
|
||||
if (descLayout) {
|
||||
return descLayout;
|
||||
}
|
||||
const webPip = cclegacy.director.root.pipeline as WebPipeline;
|
||||
const stageId = webPip.layoutGraph.locateChild(webPip.layoutGraph.nullVertex(), layoutName);
|
||||
assert(stageId !== 0xFFFFFFFF);
|
||||
const layout = webPip.layoutGraph.getLayout(stageId);
|
||||
const layoutData = layout.descriptorSets.get(UpdateFrequency.PER_PASS);
|
||||
layouts.set(layoutName, layoutData!);
|
||||
return layoutData;
|
||||
}
|
||||
|
||||
export function updateGlobalDescBinding (pipeline: Pipeline, data: RenderData) {
|
||||
applyGlobalDescBinding(pipeline, data, true);
|
||||
export function initGlobalDescBinding (data: RenderData, layoutName = 'default') {
|
||||
applyGlobalDescBinding(data, layoutName);
|
||||
}
|
||||
|
||||
export function updateGlobalDescBinding (data: RenderData, layoutName = 'default') {
|
||||
applyGlobalDescBinding(data, layoutName, true);
|
||||
}
|
||||
|
||||
export function mergeSrcToTargetDesc (fromDesc, toDesc, isForce = false) {
|
||||
fromDesc.update();
|
||||
const fromGpuDesc = fromDesc.gpuDescriptorSet;
|
||||
const toGpuDesc = toDesc.gpuDescriptorSet;
|
||||
const extResId: number[] = [];
|
||||
if (isForce) {
|
||||
toGpuDesc.gpuDescriptors = fromGpuDesc.gpuDescriptors;
|
||||
toGpuDesc.descriptorIndices = fromGpuDesc.descriptorIndices;
|
||||
return extResId;
|
||||
}
|
||||
for (let i = 0; i < toGpuDesc.gpuDescriptors.length; i++) {
|
||||
const fromRes = fromGpuDesc.gpuDescriptors[i];
|
||||
if (!fromRes) continue;
|
||||
const currRes = toGpuDesc.gpuDescriptors[i];
|
||||
if (!currRes.gpuBuffer && fromRes.gpuBuffer) {
|
||||
currRes.gpuBuffer = fromRes.gpuBuffer;
|
||||
extResId.push(i);
|
||||
} else if ('gpuTextureView' in currRes && !currRes.gpuTextureView) {
|
||||
currRes.gpuTextureView = fromRes.gpuTextureView;
|
||||
currRes.gpuSampler = fromRes.gpuSampler;
|
||||
extResId.push(i);
|
||||
} else if ('gpuTexture' in currRes && !currRes.gpuTexture) {
|
||||
currRes.gpuTexture = fromRes.gpuTexture;
|
||||
currRes.gpuSampler = fromRes.gpuSampler;
|
||||
extResId.push(i);
|
||||
}
|
||||
}
|
||||
return extResId;
|
||||
}
|
||||
|
||||
@@ -88,7 +88,7 @@ enum BloomStage {
|
||||
}
|
||||
|
||||
function buildBloomDownSample (lg, idx: number) {
|
||||
const bloomDownsampleID = lg.addRenderStage(`Bloom_Downsample${idx}`, BloomStage.DOWNSAMPLE);
|
||||
const bloomDownsampleID = lg.addRenderStage(`bloom-downsample${idx}`, BloomStage.DOWNSAMPLE);
|
||||
lg.addRenderPhase('Queue', bloomDownsampleID);
|
||||
const bloomDownsampleDescriptors = lg.layoutGraph.getDescriptors(bloomDownsampleID);
|
||||
|
||||
@@ -113,7 +113,7 @@ function buildBloomDownSample (lg, idx: number) {
|
||||
}
|
||||
|
||||
function buildBloomUpSample (lg, idx: number) {
|
||||
const bloomUpsampleID = lg.addRenderStage(`Bloom_Upsample${idx}`, BloomStage.UPSAMPLE);
|
||||
const bloomUpsampleID = lg.addRenderStage(`bloom-upsample${idx}`, BloomStage.UPSAMPLE);
|
||||
lg.addRenderPhase('Queue', bloomUpsampleID);
|
||||
const bloomUpsampleDescriptors = lg.layoutGraph.getDescriptors(bloomUpsampleID);
|
||||
|
||||
@@ -143,7 +143,7 @@ export function buildForwardLayout (ppl: Pipeline) {
|
||||
const defaultID = lg.addGlobal('default', true, true, true, true, true, true, true, true);
|
||||
lg.mergeDescriptors(defaultID);
|
||||
// 1.=== Bloom prefilter ===
|
||||
const bloomPrefilterID = lg.addRenderStage('Bloom_Prefilter', BloomStage.PREFILTER);
|
||||
const bloomPrefilterID = lg.addRenderStage('bloom-prefilter', BloomStage.PREFILTER);
|
||||
lg.addRenderPhase('Queue', bloomPrefilterID);
|
||||
const bloomPrefilterDescriptors = lg.layoutGraph.getDescriptors(bloomPrefilterID);
|
||||
// unifom
|
||||
@@ -172,7 +172,7 @@ export function buildForwardLayout (ppl: Pipeline) {
|
||||
buildBloomUpSample(lg, 0);
|
||||
buildBloomUpSample(lg, 1);
|
||||
// 4.=== Bloom combine ===
|
||||
const bloomCombineSampleID = lg.addRenderStage('Bloom_Combine', BloomStage.COMBINE);
|
||||
const bloomCombineSampleID = lg.addRenderStage('bloom-combine', BloomStage.COMBINE);
|
||||
lg.addRenderPhase('Queue', bloomCombineSampleID);
|
||||
const bloomCombineSampleDescriptors = lg.layoutGraph.getDescriptors(bloomCombineSampleID);
|
||||
|
||||
@@ -201,7 +201,7 @@ export function buildForwardLayout (ppl: Pipeline) {
|
||||
lg.merge(bloomCombineSampleDescriptors);
|
||||
lg.mergeDescriptors(bloomCombineSampleID);
|
||||
// 5.=== Postprocess ===
|
||||
const postPassID = lg.addRenderStage('Postprocess', DeferredStage.POST);
|
||||
const postPassID = lg.addRenderStage('post-process', DeferredStage.POST);
|
||||
const postDescriptors = lg.layoutGraph.getDescriptors(postPassID);
|
||||
const postPassBlock = lg.getLayoutBlock(UpdateFrequency.PER_PASS,
|
||||
ParameterType.TABLE,
|
||||
@@ -266,8 +266,8 @@ export function buildDeferredLayout (ppl: Pipeline) {
|
||||
const defaultID = lg.addGlobal('default', true, true, true, true, true, true, true, true);
|
||||
lg.mergeDescriptors(defaultID);
|
||||
const geometryPassID = lg.addRenderStage('Geometry', DeferredStage.GEOMETRY);
|
||||
const lightingPassID = lg.addRenderStage('Lighting', DeferredStage.LIGHTING);
|
||||
const postPassID = lg.addRenderStage('Postprocess', DeferredStage.POST);
|
||||
const lightingPassID = lg.addRenderStage('deferred-lighting', DeferredStage.LIGHTING);
|
||||
const postPassID = lg.addRenderStage('post-process', DeferredStage.POST);
|
||||
|
||||
const geometryQueueID = lg.addRenderPhase('Queue', geometryPassID);
|
||||
const lightingQueueID = lg.addRenderPhase('Queue', lightingPassID);
|
||||
|
||||
@@ -62,7 +62,7 @@ import { renderProfiler } from '../pipeline-funcs';
|
||||
import { PlanarShadowQueue } from '../planar-shadow-queue';
|
||||
import { DefaultVisitor, depthFirstSearch, ReferenceGraphView } from './graph';
|
||||
import { VectorGraphColorMap } from './effect';
|
||||
import { getDescBindingFromName, getRenderArea, updateGlobalDescBinding } from './define';
|
||||
import { getDescBindingFromName, getDescriptorSetDataFromLayout, getRenderArea, mergeSrcToTargetDesc, updateGlobalDescBinding } from './define';
|
||||
import { RenderReflectionProbeQueue } from '../render-reflection-probe-queue';
|
||||
import { ReflectionProbeManager } from '../reflection-probe-manager';
|
||||
|
||||
@@ -233,7 +233,7 @@ class BlitDesc {
|
||||
inputAssemblerData.quadIA = quadIA;
|
||||
return inputAssemblerData;
|
||||
}
|
||||
createSreenQuad () {
|
||||
createScreenQuad () {
|
||||
if (!this._screenQuad) {
|
||||
this._screenQuad = this._createQuadInputAssembler();
|
||||
}
|
||||
@@ -409,7 +409,7 @@ class DeviceRenderQueue {
|
||||
return;
|
||||
}
|
||||
this._blitDesc = new BlitDesc(blit, this);
|
||||
this._blitDesc.createSreenQuad();
|
||||
this._blitDesc.createScreenQuad();
|
||||
this._blitDesc.createStageDescriptor();
|
||||
}
|
||||
addSceneTask (scene: GraphScene): void {
|
||||
@@ -478,11 +478,13 @@ class RenderPassLayoutInfo {
|
||||
this._stage = lg.getRenderStage(layoutId);
|
||||
this._context = context;
|
||||
this._layout = lg.getLayout(layoutId);
|
||||
const layoutData = this._layout.descriptorSets.get(UpdateFrequency.PER_PASS);
|
||||
const layoutData = this._layout.descriptorSets.get(UpdateFrequency.PER_PASS);
|
||||
const globalDesc = context.pipeline.descriptorSet;
|
||||
if (layoutData) {
|
||||
// find resource
|
||||
const deviceTex = context.deviceTextures.get(this._inputName);
|
||||
const gfxTex = deviceTex?.texture;
|
||||
const layoutDesc = layoutData.descriptorSet!;
|
||||
if (!gfxTex) {
|
||||
throw Error(`Could not find texture with resource name ${this._inputName}`);
|
||||
}
|
||||
@@ -495,11 +497,19 @@ class RenderPassLayoutInfo {
|
||||
// find descriptor binding
|
||||
for (const block of layoutData.descriptorSetLayoutData.descriptorBlocks) {
|
||||
for (let i = 0; i !== block.descriptors.length; ++i) {
|
||||
// const buffer = layoutDesc.getBuffer(block.offset + i);
|
||||
// const texture = layoutDesc.getTexture(block.offset + i);
|
||||
if (descriptorID === block.descriptors[i].descriptorID) {
|
||||
layoutData.descriptorSet!.bindTexture(block.offset + i, gfxTex);
|
||||
layoutData.descriptorSet!.bindSampler(block.offset + i, context.device.getSampler(samplerInfo));
|
||||
if (!this._descriptorSet) this._descriptorSet = layoutData.descriptorSet;
|
||||
layoutDesc.bindTexture(block.offset + i, gfxTex);
|
||||
layoutDesc.bindSampler(block.offset + i, context.device.getSampler(samplerInfo));
|
||||
if (!this._descriptorSet) this._descriptorSet = layoutDesc;
|
||||
continue;
|
||||
}
|
||||
// if (!buffer && !texture) {
|
||||
// layoutDesc.bindBuffer(block.offset + i, globalDesc.getBuffer(block.offset + i));
|
||||
// layoutDesc.bindTexture(block.offset + i, globalDesc.getTexture(block.offset + i));
|
||||
// layoutDesc.bindSampler(block.offset + i, globalDesc.getSampler(block.offset + i));
|
||||
// }
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -538,7 +548,6 @@ class DeviceRenderPass {
|
||||
protected _viewport: Viewport | null = null;
|
||||
private _rasterInfo: RasterPassInfo;
|
||||
private _layout: RenderPassLayoutInfo | null = null;
|
||||
public submitMap: Map<Camera, SubmitInfo> = new Map<Camera, SubmitInfo>();
|
||||
constructor (context: ExecutorContext, passInfo: RasterPassInfo) {
|
||||
this._context = context;
|
||||
this._rasterInfo = passInfo;
|
||||
@@ -749,7 +758,7 @@ class DeviceRenderPass {
|
||||
}
|
||||
|
||||
private _clear () {
|
||||
for (const [cam, info] of this.submitMap) {
|
||||
for (const [cam, info] of this.context.submitMap) {
|
||||
info.additiveLight?.clear();
|
||||
const it = info.instances.values(); let res = it.next();
|
||||
while (!res.done) {
|
||||
@@ -763,7 +772,7 @@ class DeviceRenderPass {
|
||||
|
||||
postPass () {
|
||||
this._clear();
|
||||
this.submitMap.clear();
|
||||
// this.submitMap.clear();
|
||||
for (const queue of this._deviceQueues) {
|
||||
queue.postRecord();
|
||||
}
|
||||
@@ -865,8 +874,8 @@ class DevicePreSceneTask extends WebSceneTask {
|
||||
return;
|
||||
}
|
||||
const devicePass = this._currentQueue.devicePass;
|
||||
const submitMap = devicePass.submitMap;
|
||||
const context = devicePass.context;
|
||||
const submitMap = context.submitMap;
|
||||
if (submitMap.has(this.camera)) {
|
||||
this._submitInfo = submitMap.get(this.camera)!;
|
||||
} else {
|
||||
@@ -1027,8 +1036,9 @@ class DevicePreSceneTask extends WebSceneTask {
|
||||
}
|
||||
|
||||
protected _updateGlobal (context: ExecutorContext, data: RenderData) {
|
||||
updateGlobalDescBinding(context.pipeline, data);
|
||||
context.pipeline.descriptorSet.update();
|
||||
const devicePass = this._currentQueue.devicePass;
|
||||
updateGlobalDescBinding(data, isEnableEffect() ? context.renderGraph.getLayout(devicePass.rasterPassInfo.id) : 'default');
|
||||
if (!isEnableEffect()) context.pipeline.descriptorSet.update();
|
||||
}
|
||||
|
||||
protected _setMainLightShadowTex (context: ExecutorContext, data: RenderData) {
|
||||
@@ -1059,6 +1069,11 @@ class DevicePreSceneTask extends WebSceneTask {
|
||||
const queueRenderData = context.renderGraph.getData(queueId)!;
|
||||
this._setMainLightShadowTex(context, queueRenderData);
|
||||
this._updateGlobal(context, queueRenderData);
|
||||
if (isEnableEffect()) {
|
||||
const layoutName = context.renderGraph.getLayout(rasterId);
|
||||
const descSetData = getDescriptorSetDataFromLayout(layoutName);
|
||||
mergeSrcToTargetDesc(descSetData!.descriptorSet, context.pipeline.descriptorSet, true);
|
||||
}
|
||||
}
|
||||
|
||||
public submit () {
|
||||
@@ -1090,7 +1105,7 @@ class DeviceSceneTask extends WebSceneTask {
|
||||
get graphScene () { return this._graphScene; }
|
||||
public start () {}
|
||||
protected _recordRenderList (isTransparent: boolean) {
|
||||
const submitMap = this._currentQueue.devicePass.submitMap;
|
||||
const submitMap = this._currentQueue.devicePass.context.submitMap;
|
||||
const renderList = isTransparent ? submitMap.get(this.camera!)!.transparentList : submitMap.get(this.camera!)!.opaqueList;
|
||||
for (let i = 0; i < renderList.length; ++i) {
|
||||
const { subModel, passIdx } = renderList[i];
|
||||
@@ -1110,7 +1125,7 @@ class DeviceSceneTask extends WebSceneTask {
|
||||
this._recordRenderList(false);
|
||||
}
|
||||
protected _recordInstences () {
|
||||
const submitMap = this._currentQueue.devicePass.submitMap;
|
||||
const submitMap = this._currentQueue.devicePass.context.submitMap;
|
||||
const it = submitMap.get(this.camera!)!.renderInstanceQueue.length === 0
|
||||
? submitMap.get(this.camera!)!.instances.values()
|
||||
: submitMap.get(this.camera!)!.renderInstanceQueue.values();
|
||||
@@ -1140,7 +1155,7 @@ class DeviceSceneTask extends WebSceneTask {
|
||||
}
|
||||
}
|
||||
protected _recordBatches () {
|
||||
const submitMap = this._currentQueue.devicePass.submitMap;
|
||||
const submitMap = this._currentQueue.devicePass.context.submitMap;
|
||||
const it = submitMap.get(this.camera!)!.batches.values(); let res = it.next();
|
||||
while (!res.done) {
|
||||
let boundPSO = false;
|
||||
@@ -1195,13 +1210,13 @@ class DeviceSceneTask extends WebSceneTask {
|
||||
}
|
||||
protected _recordShadowMap () {
|
||||
const context = this._currentQueue.devicePass.context;
|
||||
const submitMap = this._currentQueue.devicePass.submitMap;
|
||||
const submitMap = context.submitMap;
|
||||
submitMap.get(this.camera!)?.shadowMap?.recordCommandBuffer(context.device,
|
||||
this._renderPass, context.commandBuffer);
|
||||
}
|
||||
protected _recordReflectionProbe () {
|
||||
const context = this._currentQueue.devicePass.context;
|
||||
const submitMap = this._currentQueue.devicePass.submitMap;
|
||||
const submitMap = context.submitMap;
|
||||
submitMap.get(this.camera!)?.reflectionProbe?.recordCommandBuffer(context.device,
|
||||
this._renderPass, context.commandBuffer);
|
||||
}
|
||||
@@ -1211,28 +1226,6 @@ class DeviceSceneTask extends WebSceneTask {
|
||||
&& this.graphScene.scene
|
||||
&& this.graphScene.scene.flags & SceneFlags.SHADOW_CASTER;
|
||||
}
|
||||
private _mergeMatToBlitDesc (fromDesc, toDesc) {
|
||||
fromDesc.update();
|
||||
const fromGpuDesc = fromDesc.gpuDescriptorSet;
|
||||
const toGpuDesc = toDesc.gpuDescriptorSet;
|
||||
const extResId: number[] = [];
|
||||
for (let i = 0; i < toGpuDesc.gpuDescriptors.length; i++) {
|
||||
const currRes = toGpuDesc.gpuDescriptors[i];
|
||||
if (!currRes.gpuBuffer && fromGpuDesc.gpuDescriptors[i].gpuBuffer) {
|
||||
currRes.gpuBuffer = fromGpuDesc.gpuDescriptors[i].gpuBuffer;
|
||||
extResId.push(i);
|
||||
} else if ('gpuTextureView' in currRes && !currRes.gpuTextureView) {
|
||||
currRes.gpuTextureView = fromGpuDesc.gpuDescriptors[i].gpuTextureView;
|
||||
currRes.gpuSampler = fromGpuDesc.gpuDescriptors[i].gpuSampler;
|
||||
extResId.push(i);
|
||||
} else if ('gpuTexture' in currRes && !currRes.gpuTexture) {
|
||||
currRes.gpuTexture = fromGpuDesc.gpuDescriptors[i].gpuTexture;
|
||||
currRes.gpuSampler = fromGpuDesc.gpuDescriptors[i].gpuSampler;
|
||||
extResId.push(i);
|
||||
}
|
||||
}
|
||||
return extResId;
|
||||
}
|
||||
|
||||
private _clearExtBlitDesc (desc, extResId: number[]) {
|
||||
const toGpuDesc = desc.gpuDescriptorSet;
|
||||
@@ -1259,6 +1252,7 @@ class DeviceSceneTask extends WebSceneTask {
|
||||
const shader = pass.getShaderVariant();
|
||||
const devicePass = this._currentQueue.devicePass;
|
||||
const screenIa: any = this._currentQueue.blitDesc!.screenQuad!.quadIA;
|
||||
const globalDesc = devicePass.context.pipeline.descriptorSet;
|
||||
let pso;
|
||||
if (pass !== null && shader !== null && screenIa !== null) {
|
||||
pso = PipelineStateManager.getOrCreatePipelineState(devicePass.context.device, pass, shader,
|
||||
@@ -1268,20 +1262,21 @@ class DeviceSceneTask extends WebSceneTask {
|
||||
this.visitor.bindPipelineState(pso);
|
||||
const layoutStage = devicePass.renderLayout;
|
||||
const layoutDesc = layoutStage!.descriptorSet!;
|
||||
const extResId: number[] = this._mergeMatToBlitDesc(pass.descriptorSet, layoutDesc);
|
||||
// TODO: It will be changed to global later
|
||||
this.visitor.bindDescriptorSet(SetIndex.MATERIAL, layoutDesc);
|
||||
const extResId: number[] = isEnableEffect() ? [] : mergeSrcToTargetDesc(pass.descriptorSet, layoutDesc);
|
||||
// if (isEnableEffect()) this.visitor.bindDescriptorSet(SetIndex.GLOBAL, layoutDesc);
|
||||
this.visitor.bindDescriptorSet(SetIndex.MATERIAL, isEnableEffect() ? pass.descriptorSet : layoutDesc);
|
||||
this.visitor.bindDescriptorSet(SetIndex.LOCAL, this._currentQueue.blitDesc!.stageDesc!);
|
||||
this.visitor.bindInputAssembler(screenIa);
|
||||
this.visitor.draw(screenIa);
|
||||
// The desc data obtained from the outside should be cleaned up so that the data can be modified
|
||||
this._clearExtBlitDesc(layoutDesc, extResId);
|
||||
// if (isEnableEffect()) this.visitor.bindDescriptorSet(SetIndex.GLOBAL, globalDesc);
|
||||
}
|
||||
}
|
||||
private _recordAdditiveLights () {
|
||||
const devicePass = this._currentQueue.devicePass;
|
||||
const submitMap = devicePass.submitMap;
|
||||
const context = devicePass.context;
|
||||
const submitMap = context.submitMap;
|
||||
submitMap.get(this.camera!)?.additiveLight?.recordCommandBuffer(context.device,
|
||||
this._renderPass,
|
||||
devicePass.context.commandBuffer);
|
||||
@@ -1289,8 +1284,8 @@ class DeviceSceneTask extends WebSceneTask {
|
||||
|
||||
private _recordPlanarShadows () {
|
||||
const devicePass = this._currentQueue.devicePass;
|
||||
const submitMap = devicePass.submitMap;
|
||||
const context = devicePass.context;
|
||||
const submitMap = context.submitMap;
|
||||
submitMap.get(this.camera!)?.planarQueue?.recordCommandBuffer(context.device,
|
||||
this._renderPass,
|
||||
devicePass.context.commandBuffer);
|
||||
@@ -1394,6 +1389,7 @@ class ExecutorContext {
|
||||
readonly height: number;
|
||||
readonly additiveLight: RenderAdditiveLightQueue;
|
||||
readonly shadowMapBatched: RenderShadowMapBatchedQueue;
|
||||
readonly submitMap: Map<Camera, SubmitInfo> = new Map<Camera, SubmitInfo>();
|
||||
renderGraph: RenderGraph;
|
||||
}
|
||||
class ResourceVisitor implements ResourceGraphVisitor {
|
||||
@@ -1450,6 +1446,7 @@ export class Executor {
|
||||
|
||||
execute (rg: RenderGraph) {
|
||||
this._context.renderGraph = rg;
|
||||
this._context.submitMap.clear();
|
||||
const cmdBuff = this._context.commandBuffer;
|
||||
cmdBuff.begin();
|
||||
const visitor = new RenderVisitor(this._context);
|
||||
@@ -1512,13 +1509,24 @@ class PreRenderVisitor extends BaseRenderVisitor implements RenderGraphVisitor {
|
||||
raster (pass: RasterPass) {
|
||||
if (!this.rg.getValid(this.passID)) return;
|
||||
const devicePasses = this.context.devicePasses;
|
||||
const passHash = stringify(pass);
|
||||
this.currPass = devicePasses.get(passHash);
|
||||
if (!this.currPass) {
|
||||
this.currPass = new DeviceRenderPass(this.context, new RasterPassInfo(this.passID, pass));
|
||||
devicePasses.set(passHash, this.currPass);
|
||||
if (pass.versionName === '') {
|
||||
const passHash = stringify(pass);
|
||||
this.currPass = devicePasses.get(passHash);
|
||||
if (!this.currPass) {
|
||||
this.currPass = new DeviceRenderPass(this.context, new RasterPassInfo(this.passID, pass));
|
||||
devicePasses.set(passHash, this.currPass);
|
||||
} else {
|
||||
this.currPass.resetResource(this.passID, pass);
|
||||
}
|
||||
} else {
|
||||
this.currPass.resetResource(this.passID, pass);
|
||||
const passHash = pass.versionName;
|
||||
this.currPass = devicePasses.get(passHash);
|
||||
if (!this.currPass || this.currPass.version !== pass.version) {
|
||||
this.currPass = new DeviceRenderPass(this.context, new RasterPassInfo(this.passID, pass));
|
||||
devicePasses.set(passHash, this.currPass);
|
||||
} else {
|
||||
this.currPass.resetResource(this.passID, pass);
|
||||
}
|
||||
}
|
||||
}
|
||||
compute (value: ComputePass) {}
|
||||
@@ -1570,7 +1578,9 @@ class PostRenderVisitor extends BaseRenderVisitor implements RenderGraphVisitor
|
||||
}
|
||||
raster (pass: RasterPass) {
|
||||
const devicePasses = this.context.devicePasses;
|
||||
const passHash = stringify(pass);
|
||||
const passHash = pass.versionName === ''
|
||||
? stringify(pass)
|
||||
: pass.versionName;
|
||||
const currPass = devicePasses.get(passHash);
|
||||
if (!currPass) return;
|
||||
this.currPass = currPass;
|
||||
|
||||
@@ -250,7 +250,7 @@ export interface IncidenceGraph extends Graph {
|
||||
export interface BidirectionalGraph extends IncidenceGraph {
|
||||
inEdges (v: vertex_descriptor): in_edge_iterator;
|
||||
inDegree (v: vertex_descriptor): number;
|
||||
degree (v: vertex_descriptor) : number;
|
||||
degree (v: vertex_descriptor): number;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------
|
||||
@@ -424,7 +424,7 @@ export interface AddressableGraph extends ParentGraph {
|
||||
addressable (absPath: string): boolean;
|
||||
locate (absPath: string): vertex_descriptor | null;
|
||||
locateRelative (path: string, start?: vertex_descriptor | null): vertex_descriptor | null;
|
||||
path (v: vertex_descriptor) : string;
|
||||
path (v: vertex_descriptor): string;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------
|
||||
|
||||
@@ -76,8 +76,12 @@ function addCustomBuiltinPipelines (map: Map<string, PipelineBuilder>) {
|
||||
|
||||
addCustomBuiltinPipelines(customPipelineBuilderMap);
|
||||
|
||||
export function init (device: Device, arrayBuffer: ArrayBuffer) {
|
||||
_renderModule = render.Factory.init(device, arrayBuffer);
|
||||
export function init (device: Device, arrayBuffer: ArrayBuffer | null) {
|
||||
if (arrayBuffer) {
|
||||
_renderModule = render.Factory.init(device, arrayBuffer);
|
||||
} else {
|
||||
_renderModule = render.Factory.init(device, new ArrayBuffer(0));
|
||||
}
|
||||
}
|
||||
|
||||
export function destroy () {
|
||||
|
||||
@@ -45,7 +45,7 @@ export * from './types';
|
||||
export * from './pipeline';
|
||||
export * from './archive';
|
||||
|
||||
export const enableEffectImport = false;
|
||||
export const enableEffectImport = !EDITOR;
|
||||
export const programLib: ProgramLibrary = new WebProgramLibrary(defaultLayoutGraph);
|
||||
|
||||
export function createCustomPipeline (): Pipeline {
|
||||
@@ -54,6 +54,7 @@ export function createCustomPipeline (): Pipeline {
|
||||
const ppl = new WebPipeline(layoutGraph);
|
||||
const pplName = macro.CUSTOM_PIPELINE_NAME;
|
||||
ppl.setCustomPipelineName(pplName);
|
||||
(programLib as WebProgramLibrary).pipeline = ppl;
|
||||
|
||||
if (!enableEffectImport) {
|
||||
if (pplName === 'Deferred') {
|
||||
@@ -90,9 +91,11 @@ function addCustomBuiltinPipelines (map: Map<string, PipelineBuilder>) {
|
||||
|
||||
addCustomBuiltinPipelines(customPipelineBuilderMap);
|
||||
|
||||
export function init (device: Device, arrayBuffer: ArrayBuffer) {
|
||||
const readBinaryData = new BinaryInputArchive(arrayBuffer);
|
||||
loadLayoutGraphData(readBinaryData, defaultLayoutGraph);
|
||||
export function init (device: Device, arrayBuffer: ArrayBuffer | null) {
|
||||
if (arrayBuffer) {
|
||||
const readBinaryData = new BinaryInputArchive(arrayBuffer);
|
||||
loadLayoutGraphData(readBinaryData, defaultLayoutGraph);
|
||||
}
|
||||
initializeLayoutGraphData(device, defaultLayoutGraph);
|
||||
}
|
||||
|
||||
|
||||
@@ -1142,6 +1142,12 @@ class LayoutGraphBuilder2 implements LayoutGraphBuilder {
|
||||
dstBlock.descriptors.push(data);
|
||||
}
|
||||
layout.capacity += block.capacity;
|
||||
if (index.descriptorType === DescriptorTypeOrder.UNIFORM_BUFFER
|
||||
|| index.descriptorType === DescriptorTypeOrder.DYNAMIC_UNIFORM_BUFFER) {
|
||||
layout.uniformBlockCapacity += block.capacity;
|
||||
} else {
|
||||
layout.samplerTextureCapacity += block.capacity;
|
||||
}
|
||||
}
|
||||
addUniformBlock (nodeID: number, index: DescriptorBlockIndex, name: string, uniformBlock: UniformBlock): void {
|
||||
const g: LayoutGraphData = this.lg;
|
||||
@@ -1165,6 +1171,12 @@ class LayoutGraphBuilder2 implements LayoutGraphBuilder {
|
||||
dstBlock.offset = layout.capacity;
|
||||
layout.descriptorBlocks.push(dstBlock);
|
||||
layout.capacity += block.capacity;
|
||||
if (index.descriptorType === DescriptorTypeOrder.UNIFORM_BUFFER
|
||||
|| index.descriptorType === DescriptorTypeOrder.DYNAMIC_UNIFORM_BUFFER) {
|
||||
layout.uniformBlockCapacity += block.capacity;
|
||||
} else {
|
||||
layout.samplerTextureCapacity += block.capacity;
|
||||
}
|
||||
}
|
||||
compile (): number {
|
||||
// console.debug(this.print());
|
||||
@@ -1322,6 +1334,13 @@ export function makeDescriptorSetLayoutData (lg: LayoutGraphData,
|
||||
}
|
||||
// increate total capacity
|
||||
capacity += block.capacity;
|
||||
data.capacity += block.capacity;
|
||||
if (index.descriptorType === DescriptorTypeOrder.UNIFORM_BUFFER
|
||||
|| index.descriptorType === DescriptorTypeOrder.DYNAMIC_UNIFORM_BUFFER) {
|
||||
data.uniformBlockCapacity += block.capacity;
|
||||
} else {
|
||||
data.samplerTextureCapacity += block.capacity;
|
||||
}
|
||||
data.descriptorBlocks.push(block);
|
||||
}
|
||||
return data;
|
||||
|
||||
@@ -619,6 +619,8 @@ export class DescriptorSetLayoutData {
|
||||
}
|
||||
slot: number;
|
||||
capacity: number;
|
||||
uniformBlockCapacity = 0;
|
||||
samplerTextureCapacity = 0;
|
||||
readonly descriptorBlocks: DescriptorBlockData[];
|
||||
readonly uniformBlocks: Map<number, UniformBlock>;
|
||||
readonly bindingMap: Map<number, number>;
|
||||
@@ -1418,6 +1420,8 @@ export function loadDescriptorBlockData (ar: InputArchive, v: DescriptorBlockDat
|
||||
export function saveDescriptorSetLayoutData (ar: OutputArchive, v: DescriptorSetLayoutData) {
|
||||
ar.writeNumber(v.slot);
|
||||
ar.writeNumber(v.capacity);
|
||||
ar.writeNumber(v.uniformBlockCapacity);
|
||||
ar.writeNumber(v.samplerTextureCapacity);
|
||||
ar.writeNumber(v.descriptorBlocks.length); // DescriptorBlockData[]
|
||||
for (const v1 of v.descriptorBlocks) {
|
||||
saveDescriptorBlockData(ar, v1);
|
||||
@@ -1437,6 +1441,8 @@ export function saveDescriptorSetLayoutData (ar: OutputArchive, v: DescriptorSet
|
||||
export function loadDescriptorSetLayoutData (ar: InputArchive, v: DescriptorSetLayoutData) {
|
||||
v.slot = ar.readNumber();
|
||||
v.capacity = ar.readNumber();
|
||||
v.uniformBlockCapacity = ar.readNumber();
|
||||
v.samplerTextureCapacity = ar.readNumber();
|
||||
let sz = 0;
|
||||
sz = ar.readNumber(); // DescriptorBlockData[]
|
||||
v.descriptorBlocks.length = sz;
|
||||
|
||||
@@ -103,6 +103,7 @@ export interface RasterPassBuilder extends Setter {
|
||||
addQueue (hint: QueueHint): RasterQueueBuilder;
|
||||
addQueue (/*QueueHint.NONE*/): RasterQueueBuilder;
|
||||
setViewport (viewport: Viewport): void;
|
||||
setVersion (name: string, version: number): void;
|
||||
}
|
||||
|
||||
export interface ComputeQueueBuilder extends Setter {
|
||||
|
||||
@@ -1024,6 +1024,8 @@ export class RasterPass {
|
||||
width = 0;
|
||||
height = 0;
|
||||
readonly viewport: Viewport = new Viewport();
|
||||
versionName = '';
|
||||
version = 0;
|
||||
}
|
||||
|
||||
export class ComputePass {
|
||||
|
||||
@@ -24,7 +24,7 @@
|
||||
|
||||
/* eslint-disable max-len */
|
||||
import { systemInfo } from 'pal/system-info';
|
||||
import { Color, Buffer, DescriptorSetLayout, Device, Feature, Format, FormatFeatureBit, Sampler, Swapchain, Texture, ClearFlagBit, DescriptorSet, deviceManager, Viewport, API, CommandBuffer, Type, SamplerInfo, Filter, Address } from '../../gfx';
|
||||
import { Color, Buffer, DescriptorSetLayout, Device, Feature, Format, FormatFeatureBit, Sampler, Swapchain, Texture, ClearFlagBit, DescriptorSet, deviceManager, Viewport, API, CommandBuffer, Type, SamplerInfo, Filter, Address, DescriptorSetInfo } from '../../gfx';
|
||||
import { Mat4, Quat, toRadian, Vec2, Vec3, Vec4, assert, macro, cclegacy } from '../../core';
|
||||
import { ComputeView, CopyPair, LightInfo, LightingMode, MovePair, QueueHint, RasterView, ResourceDimension, ResourceFlags, ResourceResidency, SceneFlags, UpdateFrequency } from './types';
|
||||
import { Blit, ClearView, ComputePass, CopyPass, Dispatch, ManagedResource, MovePass, RasterPass, RenderData, RenderGraph, RenderGraphComponent, RenderGraphValue, RenderQueue, RenderSwapchain, ResourceDesc, ResourceGraph, ResourceGraphValue, ResourceStates, ResourceTraits, SceneData } from './render-graph';
|
||||
@@ -37,7 +37,7 @@ import { Executor } from './executor';
|
||||
import { RenderWindow } from '../../render-scene/core/render-window';
|
||||
import { MacroRecord, RenderScene } from '../../render-scene';
|
||||
import { GlobalDSManager } from '../global-descriptor-set-manager';
|
||||
import { supportsR32FloatTexture, UBOSkinning } from '../define';
|
||||
import { isEnableEffect, supportsR32FloatTexture, UBOSkinning } from '../define';
|
||||
import { OS } from '../../../pal/system-info/enum-type';
|
||||
import { Compiler } from './compiler';
|
||||
import { PipelineUBO } from '../pipeline-ubo';
|
||||
@@ -51,7 +51,7 @@ import { CustomPipelineBuilder } from './custom-pipeline';
|
||||
import { decideProfilerCamera } from '../pipeline-funcs';
|
||||
import { DebugViewCompositeType } from '../debug-view';
|
||||
import { getUBOTypeCount } from './utils';
|
||||
import { initGlobalDescBinding } from './define';
|
||||
import { getDescBinding, initGlobalDescBinding } from './define';
|
||||
|
||||
export class WebSetter {
|
||||
constructor (data: RenderData, lg: LayoutGraphData) {
|
||||
@@ -85,6 +85,7 @@ export class WebSetter {
|
||||
|
||||
protected _getUniformOffset (name: string, type: Type, idx = 0) {
|
||||
const currBlock = this._getCurrUniformBlock();
|
||||
if (!currBlock) return -1;
|
||||
let offset = 0;
|
||||
const typeCount = getUBOTypeCount(type);
|
||||
for (const uniform of currBlock.members) {
|
||||
@@ -110,7 +111,22 @@ export class WebSetter {
|
||||
const ppl = this._lg.getLayout(nodeId);
|
||||
const layout = ppl.descriptorSets.get(UpdateFrequency.PER_PASS)!.descriptorSetLayoutData;
|
||||
const nameID: number = this._lg.attributeIndex.get(block)!;
|
||||
return layout.uniformBlocks.get(nameID)!;
|
||||
return layout.uniformBlocks.get(nameID);
|
||||
}
|
||||
|
||||
protected _getCurrDescriptorBlock (block: string) {
|
||||
const nodeId = this._lg.locateChild(0xFFFFFFFF, this._currStage);
|
||||
const ppl = this._lg.getLayout(nodeId);
|
||||
const layout = ppl.descriptorSets.get(UpdateFrequency.PER_PASS)!.descriptorSetLayoutData;
|
||||
const nameID: number = this._lg.attributeIndex.get(block)!;
|
||||
for (const block of layout.descriptorBlocks) {
|
||||
for (let i = 0; i !== block.descriptors.length; ++i) {
|
||||
if (nameID === block.descriptors[i].descriptorID) {
|
||||
return block.offset + i;
|
||||
}
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
setCurrConstant (block: string, stage = 'default') {
|
||||
@@ -119,10 +135,12 @@ export class WebSetter {
|
||||
const nameID: number = this._lg.attributeIndex.get(block)!;
|
||||
this._currCount = 0;
|
||||
const currBlock = this._getCurrUniformBlock();
|
||||
if (!currBlock) return false;
|
||||
for (const uniform of currBlock.members) {
|
||||
this._currCount += getUBOTypeCount(uniform.type) * uniform.count;
|
||||
}
|
||||
this._currConstant = this._data.constants.get(nameID)!;
|
||||
return true;
|
||||
}
|
||||
|
||||
getCurrConstant () {
|
||||
@@ -135,6 +153,7 @@ export class WebSetter {
|
||||
const num = this._lg.attributeIndex.get(block)!;
|
||||
this._currCount = 0;
|
||||
const currBlock = this._getCurrUniformBlock();
|
||||
if (!currBlock) return false;
|
||||
for (const uniform of currBlock.members) {
|
||||
this._currCount += getUBOTypeCount(uniform.type) * uniform.count;
|
||||
}
|
||||
@@ -144,6 +163,7 @@ export class WebSetter {
|
||||
this._data.constants.set(num, value);
|
||||
}
|
||||
this.setCurrConstant(block);
|
||||
return true;
|
||||
}
|
||||
public setMat4 (name: string, mat: Mat4, idx = 0): void {
|
||||
this._applyCurrConstantBuffer(name, mat, Type.MAT4, idx);
|
||||
@@ -165,12 +185,18 @@ export class WebSetter {
|
||||
}
|
||||
public setBuffer (name: string, buffer: Buffer): void {}
|
||||
public setTexture (name: string, texture: Texture): void {
|
||||
if (this._getCurrDescriptorBlock(name) === -1) {
|
||||
return;
|
||||
}
|
||||
const num = this._lg.attributeIndex.get(name)!;
|
||||
this._data.textures.set(num, texture);
|
||||
}
|
||||
public setReadWriteBuffer (name: string, buffer: Buffer): void {}
|
||||
public setReadWriteTexture (name: string, texture: Texture): void {}
|
||||
public setSampler (name: string, sampler: Sampler): void {
|
||||
if (this._getCurrDescriptorBlock(name) === -1) {
|
||||
return;
|
||||
}
|
||||
const num = this._lg.attributeIndex.get(name)!;
|
||||
this._data.samplers.set(num, sampler);
|
||||
}
|
||||
@@ -186,7 +212,8 @@ export class WebSetter {
|
||||
|
||||
function setShadowUBOLightView (setter: WebSetter,
|
||||
light: Light,
|
||||
level: number) {
|
||||
level: number,
|
||||
layout = 'default') {
|
||||
const director = cclegacy.director;
|
||||
const pipeline = director.root.pipeline;
|
||||
const device = pipeline.device;
|
||||
@@ -196,9 +223,9 @@ function setShadowUBOLightView (setter: WebSetter,
|
||||
const packing = supportsR32FloatTexture(device) ? 0.0 : 1.0;
|
||||
const cap = pipeline.device.capabilities;
|
||||
const _vec4ShadowInfo = new Vec4();
|
||||
setter.addConstant('CCCSM');
|
||||
setter.addConstant('CCCSM', layout);
|
||||
// ShadowMap
|
||||
setter.addConstant('CCShadow');
|
||||
if (!setter.addConstant('CCShadow', layout)) return;
|
||||
switch (light.type) {
|
||||
case LightType.DIRECTIONAL: {
|
||||
const mainLight = light as DirectionalLight;
|
||||
@@ -299,7 +326,7 @@ function getPCFRadius (shadowInfo: Shadows, mainLight: DirectionalLight): number
|
||||
return 0.0;
|
||||
}
|
||||
|
||||
function setShadowUBOView (setter: WebSetter, camera: Camera) {
|
||||
function setShadowUBOView (setter: WebSetter, camera: Camera, layout = 'default') {
|
||||
const director = cclegacy.director;
|
||||
const pipeline = director.root.pipeline;
|
||||
const device = pipeline.device;
|
||||
@@ -310,89 +337,99 @@ function setShadowUBOView (setter: WebSetter, camera: Camera) {
|
||||
const csmSupported = sceneData.csmSupported;
|
||||
const packing = supportsR32FloatTexture(device) ? 0.0 : 1.0;
|
||||
const _vec4ShadowInfo = new Vec4();
|
||||
setter.addConstant('CCShadow');
|
||||
setter.addConstant('CCCSM');
|
||||
const hasCCShadow = setter.addConstant('CCShadow', layout);
|
||||
const hasCCCSM = setter.addConstant('CCCSM', layout);
|
||||
if (mainLight && shadowInfo.enabled) {
|
||||
if (shadowInfo.type === ShadowType.ShadowMap) {
|
||||
if (mainLight.shadowEnabled) {
|
||||
if (mainLight.shadowFixedArea || mainLight.csmLevel === CSMLevel.LEVEL_1 || !csmSupported) {
|
||||
setter.setCurrConstant('CCShadow');
|
||||
const matShadowView = csmLayers.specialLayer.matShadowView;
|
||||
const matShadowProj = csmLayers.specialLayer.matShadowProj;
|
||||
const matShadowViewProj = csmLayers.specialLayer.matShadowViewProj;
|
||||
const near = mainLight.shadowNear;
|
||||
const far = mainLight.shadowFar;
|
||||
if (hasCCShadow) {
|
||||
setter.setCurrConstant('CCShadow', layout);
|
||||
const matShadowView = csmLayers.specialLayer.matShadowView;
|
||||
const matShadowProj = csmLayers.specialLayer.matShadowProj;
|
||||
const matShadowViewProj = csmLayers.specialLayer.matShadowViewProj;
|
||||
const near = mainLight.shadowNear;
|
||||
const far = mainLight.shadowFar;
|
||||
|
||||
setter.setMat4('cc_matLightView', matShadowView);
|
||||
setter.setVec4('cc_shadowProjDepthInfo', new Vec4(matShadowProj.m10, matShadowProj.m14,
|
||||
matShadowProj.m11, matShadowProj.m15));
|
||||
setter.setMat4('cc_matLightView', matShadowView);
|
||||
setter.setVec4('cc_shadowProjDepthInfo', new Vec4(matShadowProj.m10, matShadowProj.m14,
|
||||
matShadowProj.m11, matShadowProj.m15));
|
||||
|
||||
setter.setVec4('cc_shadowProjInfo', new Vec4(matShadowProj.m00, matShadowProj.m05,
|
||||
1.0 / matShadowProj.m00, 1.0 / matShadowProj.m05));
|
||||
setter.setMat4('cc_matLightViewProj', matShadowViewProj);
|
||||
_vec4ShadowInfo.set(near, far, 0, 1.0 - mainLight.shadowSaturation);
|
||||
setter.setVec4('cc_shadowNFLSInfo', _vec4ShadowInfo);
|
||||
_vec4ShadowInfo.set(0.0, packing, mainLight.shadowNormalBias, 0);
|
||||
setter.setVec4('cc_shadowLPNNInfo', _vec4ShadowInfo);
|
||||
} else {
|
||||
const layerThreshold = getPCFRadius(shadowInfo, mainLight);
|
||||
setter.setCurrConstant('CCCSM');
|
||||
for (let i = 0; i < mainLight.csmLevel; i++) {
|
||||
const matShadowView = csmLayers.layers[i].matShadowView;
|
||||
_vec4ShadowInfo.set(matShadowView.m00, matShadowView.m04, matShadowView.m08, layerThreshold);
|
||||
setter.setVec4('cc_csmViewDir0', _vec4ShadowInfo, i);
|
||||
_vec4ShadowInfo.set(matShadowView.m01, matShadowView.m05, matShadowView.m09, 0.0);
|
||||
setter.setVec4('cc_csmViewDir1', _vec4ShadowInfo, i);
|
||||
_vec4ShadowInfo.set(matShadowView.m02, matShadowView.m06, matShadowView.m10, 0.0);
|
||||
setter.setVec4('cc_csmViewDir2', _vec4ShadowInfo, i);
|
||||
|
||||
const csmAtlas = csmLayers.layers[i].csmAtlas;
|
||||
setter.setVec4('cc_csmAtlas', csmAtlas, i);
|
||||
|
||||
setter.setFloat('cc_csmSplitsInfo', csmLayers.layers[i].splitCameraFar / mainLight.shadowDistance, i);
|
||||
const matShadowViewProj = csmLayers.layers[i].matShadowViewProj;
|
||||
setter.setMat4('cc_matCSMViewProj', matShadowViewProj, i);
|
||||
|
||||
const matShadowProj = csmLayers.layers[i].matShadowProj;
|
||||
setter.setVec4('cc_csmProjDepthInfo', new Vec4(matShadowProj.m10,
|
||||
matShadowProj.m14, matShadowProj.m11, matShadowProj.m15), i);
|
||||
|
||||
setter.setVec4('cc_csmProjInfo', new Vec4(matShadowProj.m00,
|
||||
matShadowProj.m05, 1.0 / matShadowProj.m00, 1.0 / matShadowProj.m05), i);
|
||||
setter.setVec4('cc_shadowProjInfo', new Vec4(matShadowProj.m00, matShadowProj.m05,
|
||||
1.0 / matShadowProj.m00, 1.0 / matShadowProj.m05));
|
||||
setter.setMat4('cc_matLightViewProj', matShadowViewProj);
|
||||
_vec4ShadowInfo.set(near, far, 0, 1.0 - mainLight.shadowSaturation);
|
||||
setter.setVec4('cc_shadowNFLSInfo', _vec4ShadowInfo);
|
||||
_vec4ShadowInfo.set(0.0, packing, mainLight.shadowNormalBias, 0);
|
||||
setter.setVec4('cc_shadowLPNNInfo', _vec4ShadowInfo);
|
||||
}
|
||||
} else {
|
||||
if (hasCCCSM) {
|
||||
const layerThreshold = getPCFRadius(shadowInfo, mainLight);
|
||||
setter.setCurrConstant('CCCSM', layout);
|
||||
for (let i = 0; i < mainLight.csmLevel; i++) {
|
||||
const matShadowView = csmLayers.layers[i].matShadowView;
|
||||
_vec4ShadowInfo.set(matShadowView.m00, matShadowView.m04, matShadowView.m08, layerThreshold);
|
||||
setter.setVec4('cc_csmViewDir0', _vec4ShadowInfo, i);
|
||||
_vec4ShadowInfo.set(matShadowView.m01, matShadowView.m05, matShadowView.m09, 0.0);
|
||||
setter.setVec4('cc_csmViewDir1', _vec4ShadowInfo, i);
|
||||
_vec4ShadowInfo.set(matShadowView.m02, matShadowView.m06, matShadowView.m10, 0.0);
|
||||
setter.setVec4('cc_csmViewDir2', _vec4ShadowInfo, i);
|
||||
|
||||
const csmAtlas = csmLayers.layers[i].csmAtlas;
|
||||
setter.setVec4('cc_csmAtlas', csmAtlas, i);
|
||||
|
||||
setter.setFloat('cc_csmSplitsInfo', csmLayers.layers[i].splitCameraFar / mainLight.shadowDistance, i);
|
||||
const matShadowViewProj = csmLayers.layers[i].matShadowViewProj;
|
||||
setter.setMat4('cc_matCSMViewProj', matShadowViewProj, i);
|
||||
|
||||
const matShadowProj = csmLayers.layers[i].matShadowProj;
|
||||
setter.setVec4('cc_csmProjDepthInfo', new Vec4(matShadowProj.m10,
|
||||
matShadowProj.m14, matShadowProj.m11, matShadowProj.m15), i);
|
||||
|
||||
setter.setVec4('cc_csmProjInfo', new Vec4(matShadowProj.m00,
|
||||
matShadowProj.m05, 1.0 / matShadowProj.m00, 1.0 / matShadowProj.m05), i);
|
||||
}
|
||||
}
|
||||
if (hasCCShadow) {
|
||||
setter.setCurrConstant('CCShadow', layout);
|
||||
_vec4ShadowInfo.set(0, 0, 0, 1.0 - mainLight.shadowSaturation);
|
||||
setter.setVec4('cc_shadowNFLSInfo', _vec4ShadowInfo);
|
||||
_vec4ShadowInfo.set(0.0, packing, mainLight.shadowNormalBias, mainLight.csmLevel);
|
||||
setter.setVec4('cc_shadowLPNNInfo', _vec4ShadowInfo);
|
||||
}
|
||||
setter.setCurrConstant('CCShadow');
|
||||
_vec4ShadowInfo.set(0, 0, 0, 1.0 - mainLight.shadowSaturation);
|
||||
setter.setVec4('cc_shadowNFLSInfo', _vec4ShadowInfo);
|
||||
_vec4ShadowInfo.set(0.0, packing, mainLight.shadowNormalBias, mainLight.csmLevel);
|
||||
setter.setVec4('cc_shadowLPNNInfo', _vec4ShadowInfo);
|
||||
}
|
||||
setter.setCurrConstant('CCShadow');
|
||||
_vec4ShadowInfo.set(shadowInfo.size.x, shadowInfo.size.y, mainLight.shadowPcf, mainLight.shadowBias);
|
||||
setter.setVec4('cc_shadowWHPBInfo', _vec4ShadowInfo);
|
||||
if (hasCCShadow) {
|
||||
setter.setCurrConstant('CCShadow', layout);
|
||||
_vec4ShadowInfo.set(shadowInfo.size.x, shadowInfo.size.y, mainLight.shadowPcf, mainLight.shadowBias);
|
||||
setter.setVec4('cc_shadowWHPBInfo', _vec4ShadowInfo);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
setter.setCurrConstant('CCShadow');
|
||||
} else if (hasCCShadow) {
|
||||
setter.setCurrConstant('CCShadow', layout);
|
||||
const _tempVec3 = new Vec3();
|
||||
Vec3.normalize(_tempVec3, shadowInfo.normal);
|
||||
setter.setVec4('cc_planarNDInfo', new Vec4(_tempVec3.x, _tempVec3.y, _tempVec3.z, -shadowInfo.distance));
|
||||
}
|
||||
setter.setCurrConstant('CCShadow');
|
||||
setter.setColor('cc_shadowColor', shadowInfo.shadowColor);
|
||||
if (hasCCShadow) {
|
||||
setter.setCurrConstant('CCShadow', layout);
|
||||
setter.setColor('cc_shadowColor', shadowInfo.shadowColor);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function setCameraUBOValues (setter: WebSetter,
|
||||
camera: Readonly<Camera>, cfg: Readonly<PipelineSceneData>,
|
||||
scene: Readonly<RenderScene>) {
|
||||
scene: Readonly<RenderScene>,
|
||||
layoutName = 'default') {
|
||||
const director = cclegacy.director;
|
||||
const root = director.root;
|
||||
const pipeline = root.pipeline as WebPipeline;
|
||||
const layoutGraph = pipeline.layoutGraph;
|
||||
const shadowInfo = cfg.shadows;
|
||||
const skybox = cfg.skybox;
|
||||
const shadingScale = cfg.shadingScale;
|
||||
// Camera
|
||||
setter.addConstant('CCCamera');
|
||||
if (!setter.addConstant('CCCamera', layoutName)) return;
|
||||
setter.setMat4('cc_matView', camera.matView);
|
||||
setter.setMat4('cc_matViewInv', camera.node.worldMatrix);
|
||||
setter.setMat4('cc_matProj', camera.matProj);
|
||||
@@ -445,7 +482,7 @@ function setCameraUBOValues (setter: WebSetter,
|
||||
setter.setVec4('cc_viewPort', new Vec4(camera.viewport.x, camera.viewport.y, shadingScale * camera.window.width * camera.viewport.z, shadingScale * camera.window.height * camera.viewport.w));
|
||||
}
|
||||
|
||||
function setTextureUBOView (setter: WebSetter, camera: Camera, cfg: Readonly<PipelineSceneData>) {
|
||||
function setTextureUBOView (setter: WebSetter, camera: Camera, cfg: Readonly<PipelineSceneData>, layout = 'default') {
|
||||
const skybox = cfg.skybox;
|
||||
const director = cclegacy.director;
|
||||
const root = director.root;
|
||||
@@ -510,21 +547,30 @@ export class WebRasterQueueBuilder extends WebSetter implements RasterQueueBuild
|
||||
set name (name: string) {
|
||||
this._renderGraph.setName(this._vertID, name);
|
||||
}
|
||||
|
||||
getLayoutName () {
|
||||
const parId = this._renderGraph.getParent(this._vertID);
|
||||
const layoutName = isEnableEffect() ? this._renderGraph.getLayout(parId) : 'default';
|
||||
return layoutName;
|
||||
}
|
||||
|
||||
addSceneOfCamera (camera: Camera, light: LightInfo, sceneFlags = SceneFlags.NONE, name = 'Camera'): void {
|
||||
const sceneData = new SceneData(name, sceneFlags, light);
|
||||
sceneData.camera = camera;
|
||||
this._renderGraph.addVertex<RenderGraphValue.Scene>(
|
||||
RenderGraphValue.Scene, sceneData, name, '', new RenderData(), false, this._vertID,
|
||||
);
|
||||
const layoutName = this.getLayoutName();
|
||||
setCameraUBOValues(this, camera, this._pipeline,
|
||||
camera.scene ? camera.scene : cclegacy.director.getScene().renderScene);
|
||||
camera.scene ? camera.scene : cclegacy.director.getScene().renderScene,
|
||||
layoutName);
|
||||
if (sceneFlags & SceneFlags.SHADOW_CASTER) {
|
||||
setShadowUBOLightView(this, light.light!, light.level);
|
||||
setShadowUBOLightView(this, light.light!, light.level, layoutName);
|
||||
} else {
|
||||
setShadowUBOView(this, camera);
|
||||
setShadowUBOView(this, camera, layoutName);
|
||||
}
|
||||
setTextureUBOView(this, camera, this._pipeline);
|
||||
initGlobalDescBinding(cclegacy.director.root.pipeline, this._data);
|
||||
initGlobalDescBinding(this._data, layoutName);
|
||||
}
|
||||
addScene (sceneName: string, sceneFlags = SceneFlags.NONE): void {
|
||||
const sceneData = new SceneData(sceneName, sceneFlags);
|
||||
@@ -543,15 +589,16 @@ export class WebRasterQueueBuilder extends WebSetter implements RasterQueueBuild
|
||||
RenderGraphValue.Blit, new Blit(material, passID, sceneFlags, camera),
|
||||
'CameraQuad', '', new RenderData(), false, this._vertID,
|
||||
);
|
||||
const layoutName = this.getLayoutName();
|
||||
setCameraUBOValues(this, camera, this._pipeline,
|
||||
camera.scene ? camera.scene : cclegacy.director.getScene().renderScene);
|
||||
camera.scene ? camera.scene : cclegacy.director.getScene().renderScene, layoutName);
|
||||
if (sceneFlags & SceneFlags.SHADOW_CASTER) {
|
||||
// setShadowUBOLightView(this, light.light!, light.level);
|
||||
} else {
|
||||
setShadowUBOView(this, camera);
|
||||
setShadowUBOView(this, camera, layoutName);
|
||||
}
|
||||
setTextureUBOView(this, camera, this._pipeline);
|
||||
initGlobalDescBinding(cclegacy.director.root.pipeline, this._data);
|
||||
initGlobalDescBinding(this._data, layoutName);
|
||||
}
|
||||
clearRenderTarget (name: string, color: Color = new Color()) {
|
||||
this._renderGraph.addVertex<RenderGraphValue.Clear>(
|
||||
@@ -585,6 +632,10 @@ export class WebRasterPassBuilder extends WebSetter implements RasterPassBuilder
|
||||
);
|
||||
this._layoutID = layoutGraph.locateChild(layoutGraph.nullVertex(), layoutName);
|
||||
}
|
||||
setVersion (name: string, version: number): void {
|
||||
this._pass.versionName = name;
|
||||
this._pass.version = version;
|
||||
}
|
||||
get name () {
|
||||
return this._renderGraph.getName(this._vertID);
|
||||
}
|
||||
@@ -868,7 +919,8 @@ export class WebPipeline implements Pipeline {
|
||||
this._globalDSManager = new GlobalDSManager(this._device);
|
||||
this._globalDescSetData = this.getGlobalDescriptorSetData()!;
|
||||
this._globalDescriptorSetLayout = this._globalDescSetData.descriptorSetLayout;
|
||||
this._globalDescriptorSet = this._globalDescSetData.descriptorSet!;
|
||||
this._globalDescriptorSet = isEnableEffect() ? this._device.createDescriptorSet(new DescriptorSetInfo(this._globalDescriptorSetLayout!))
|
||||
: this._globalDescSetData.descriptorSet;
|
||||
this._globalDSManager.globalDescriptorSet = this.globalDescriptorSet;
|
||||
this.setMacroBool('CC_USE_HDR', this._pipelineSceneData.isHDR);
|
||||
this._generateConstantMacros(false);
|
||||
@@ -1148,8 +1200,8 @@ export class WebPipeline implements Pipeline {
|
||||
RenderGraphValue.Raster, pass, name, layoutName, data, false,
|
||||
);
|
||||
const result = new WebRasterPassBuilder(data, this._renderGraph!, this._layoutGraph, vertID, pass, this._pipelineSceneData);
|
||||
this._updateRasterPassConstants(result, width, height);
|
||||
initGlobalDescBinding(cclegacy.director.root.pipeline, data);
|
||||
this._updateRasterPassConstants(result, width, height, isEnableEffect() ? layoutName : 'default');
|
||||
initGlobalDescBinding(data, layoutName);
|
||||
return result;
|
||||
}
|
||||
public getDescriptorSetLayout (shaderName: string, freq: UpdateFrequency): DescriptorSetLayout {
|
||||
@@ -1169,7 +1221,7 @@ export class WebPipeline implements Pipeline {
|
||||
return this._layoutGraph;
|
||||
}
|
||||
|
||||
protected _updateRasterPassConstants (setter: WebSetter, width: number, height: number) {
|
||||
protected _updateRasterPassConstants (setter: WebSetter, width: number, height: number, layoutName = 'default') {
|
||||
const director = cclegacy.director;
|
||||
const root = director.root;
|
||||
const shadingWidth = width;
|
||||
@@ -1177,7 +1229,7 @@ export class WebPipeline implements Pipeline {
|
||||
const pipeline = root.pipeline as WebPipeline;
|
||||
const layoutGraph = pipeline.layoutGraph;
|
||||
// Global
|
||||
setter.addConstant('CCGlobal');
|
||||
if (!setter.addConstant('CCGlobal', layoutName)) return;
|
||||
setter.setVec4('cc_time', new Vec4(root.cumulativeTime, root.frameTime, director.getTotalFrames()));
|
||||
setter.setVec4('cc_screenSize', new Vec4(shadingWidth, shadingHeight, 1.0 / shadingWidth, 1.0 / shadingHeight));
|
||||
setter.setVec4('cc_nativeSize', new Vec4(shadingWidth, shadingHeight, 1.0 / shadingWidth, 1.0 / shadingHeight));
|
||||
|
||||
@@ -24,17 +24,18 @@
|
||||
|
||||
/* eslint-disable max-len */
|
||||
import { EffectAsset } from '../../asset/assets';
|
||||
import { Attribute, DescriptorSetLayout, DESCRIPTOR_BUFFER_TYPE, DESCRIPTOR_SAMPLER_TYPE, Device, MemoryAccessBit, PipelineLayout, PipelineLayoutInfo, Shader, ShaderInfo, ShaderStage, ShaderStageFlagBit, Type, Uniform, UniformBlock, UniformInputAttachment, UniformSampler, UniformSamplerTexture, UniformStorageBuffer, UniformStorageImage, UniformTexture } from '../../gfx';
|
||||
import { Attribute, DescriptorSetLayout, DescriptorType, DESCRIPTOR_BUFFER_TYPE, DESCRIPTOR_SAMPLER_TYPE, Device, MemoryAccessBit, PipelineLayout, PipelineLayoutInfo, Shader, ShaderInfo, ShaderStage, ShaderStageFlagBit, Type, Uniform, UniformBlock, UniformInputAttachment, UniformSampler, UniformSamplerTexture, UniformStorageBuffer, UniformStorageImage, UniformTexture } from '../../gfx';
|
||||
import { genHandles, getActiveAttributes, getCombinationDefines, getShaderInstanceName, getSize, getVariantKey, populateMacros, prepareDefines } from '../../render-scene/core/program-utils';
|
||||
import { getDeviceShaderVersion, MacroRecord } from '../../render-scene';
|
||||
import { IProgramInfo } from '../../render-scene/core/program-lib';
|
||||
import { DescriptorBlockData, DescriptorData, DescriptorSetData, DescriptorSetLayoutData, LayoutGraphData, LayoutGraphDataValue, PipelineLayoutData, RenderPhaseData, ShaderProgramData } from './layout-graph';
|
||||
import { ProgramLibrary, ProgramProxy } from './private';
|
||||
import { DescriptorTypeOrder, UpdateFrequency } from './types';
|
||||
import { ProgramGroup, ProgramHost, ProgramInfo } from './web-types';
|
||||
import { ProgramGroup, ProgramInfo } from './web-types';
|
||||
import { getCustomPassID, getCustomPhaseID, getOrCreateDescriptorSetLayout, getEmptyDescriptorSetLayout, getEmptyPipelineLayout, initializeDescriptorSetLayoutInfo, makeDescriptorSetLayoutData, getDescriptorSetLayout, getOrCreateDescriptorID, getDescriptorTypeOrder, getProgramID, getDescriptorNameID, getDescriptorName, INVALID_ID } from './layout-graph-utils';
|
||||
import { assert } from '../../core/platform/debug';
|
||||
import { IDescriptorSetLayoutInfo, localDescriptorSetLayout } from '../define';
|
||||
import { PipelineRuntime } from './pipeline';
|
||||
|
||||
const _setIndex = [2, 1, 3, 0];
|
||||
|
||||
@@ -339,6 +340,116 @@ function populateLocalShaderInfo (
|
||||
}
|
||||
}
|
||||
|
||||
function getIDescriptorSetLayoutInfoUniformBlockCapacity (info: IDescriptorSetLayoutInfo): number {
|
||||
let capacity = 0;
|
||||
for (const binding of info.bindings) {
|
||||
if (binding.descriptorType === DescriptorType.UNIFORM_BUFFER
|
||||
|| binding.descriptorType === DescriptorType.DYNAMIC_UNIFORM_BUFFER) {
|
||||
capacity += binding.count;
|
||||
}
|
||||
}
|
||||
return capacity;
|
||||
}
|
||||
|
||||
function getIDescriptorSetLayoutInfoSamplerTextureCapacity (info: IDescriptorSetLayoutInfo): number {
|
||||
let capacity = 0;
|
||||
for (const binding of info.bindings) {
|
||||
if (binding.descriptorType !== DescriptorType.UNIFORM_BUFFER
|
||||
&& binding.descriptorType !== DescriptorType.DYNAMIC_UNIFORM_BUFFER) {
|
||||
capacity += binding.count;
|
||||
}
|
||||
}
|
||||
return capacity;
|
||||
}
|
||||
|
||||
function setFlattenedUniformBlockBinding (setOffsets: number[],
|
||||
descriptors: UniformBlock[]) {
|
||||
for (const d of descriptors) {
|
||||
d.flattened = setOffsets[d.set] + d.binding;
|
||||
}
|
||||
}
|
||||
|
||||
function setFlattenedSamplerTextureBinding (setOffsets: number[],
|
||||
uniformBlockCapacities: number[],
|
||||
descriptors: UniformSamplerTexture[]
|
||||
| UniformSampler[]
|
||||
| UniformTexture[]
|
||||
| UniformStorageBuffer[]
|
||||
| UniformStorageImage[]
|
||||
| UniformInputAttachment[]) {
|
||||
for (const d of descriptors) {
|
||||
d.flattened = setOffsets[d.set] + d.binding - uniformBlockCapacities[d.set];
|
||||
}
|
||||
}
|
||||
|
||||
function calculateFlattenedBinding (
|
||||
descriptorSets: (DescriptorSetLayoutData | null)[],
|
||||
fixedInstanceDescriptorSetLayout: IDescriptorSetLayoutInfo | null,
|
||||
shaderInfo: ShaderInfo,
|
||||
) {
|
||||
// Descriptors of UniformBlock starts from 0, and Descriptors of SamplerTexture starts from the end of UniformBlock.
|
||||
const uniformBlockCapacities = new Array(4);
|
||||
{
|
||||
const passCapacity = descriptorSets[UpdateFrequency.PER_PASS]?.uniformBlockCapacity || 0;
|
||||
const phaseCapacity = descriptorSets[UpdateFrequency.PER_PHASE]?.uniformBlockCapacity || 0;
|
||||
const batchCapacity = descriptorSets[UpdateFrequency.PER_BATCH]?.uniformBlockCapacity || 0; // dynamic size
|
||||
const instanceCapacity = fixedInstanceDescriptorSetLayout
|
||||
? getIDescriptorSetLayoutInfoUniformBlockCapacity(fixedInstanceDescriptorSetLayout)
|
||||
: (descriptorSets[UpdateFrequency.PER_INSTANCE]?.uniformBlockCapacity || 0);
|
||||
|
||||
// update uniform block capacities
|
||||
uniformBlockCapacities[_setIndex[UpdateFrequency.PER_PASS]] = passCapacity;
|
||||
uniformBlockCapacities[_setIndex[UpdateFrequency.PER_PHASE]] = phaseCapacity;
|
||||
uniformBlockCapacities[_setIndex[UpdateFrequency.PER_BATCH]] = batchCapacity;
|
||||
uniformBlockCapacities[_setIndex[UpdateFrequency.PER_INSTANCE]] = instanceCapacity;
|
||||
|
||||
// calculate uniform block offsets
|
||||
const passOffset = 0;
|
||||
const phaseOffset = passOffset + passCapacity;
|
||||
const instanceOffset = phaseOffset + phaseCapacity;
|
||||
const batchOffset = instanceOffset + instanceCapacity;
|
||||
|
||||
// save uniform block offsets by set index
|
||||
const uniformBlockOffsets = new Array(4);
|
||||
uniformBlockOffsets[_setIndex[UpdateFrequency.PER_PASS]] = passOffset;
|
||||
uniformBlockOffsets[_setIndex[UpdateFrequency.PER_PHASE]] = phaseOffset;
|
||||
uniformBlockOffsets[_setIndex[UpdateFrequency.PER_BATCH]] = batchOffset;
|
||||
uniformBlockOffsets[_setIndex[UpdateFrequency.PER_INSTANCE]] = instanceOffset;
|
||||
|
||||
// update flattened uniform block binding
|
||||
setFlattenedUniformBlockBinding(uniformBlockOffsets, shaderInfo.blocks);
|
||||
}
|
||||
{
|
||||
// calculate sampler texture capacities
|
||||
const passCapacity = descriptorSets[UpdateFrequency.PER_PASS]?.samplerTextureCapacity || 0;
|
||||
const phaseCapacity = descriptorSets[UpdateFrequency.PER_PHASE]?.samplerTextureCapacity || 0;
|
||||
// const batchCapacity = descriptorSets[UpdateFrequency.PER_BATCH]?.capacity || 0; // dynamic size
|
||||
const instanceCapacity = fixedInstanceDescriptorSetLayout
|
||||
? getIDescriptorSetLayoutInfoSamplerTextureCapacity(fixedInstanceDescriptorSetLayout)
|
||||
: (descriptorSets[UpdateFrequency.PER_INSTANCE]?.samplerTextureCapacity || 0);
|
||||
|
||||
// calculate sampler texture offsets
|
||||
const passOffset = 0;
|
||||
const phaseOffset = passOffset + passCapacity;
|
||||
const instanceOffset = phaseOffset + phaseCapacity;
|
||||
const batchOffset = instanceOffset + instanceCapacity;
|
||||
|
||||
// save sampler texture offsets by set index
|
||||
const samplerTextureOffsets = new Array(4);
|
||||
samplerTextureOffsets[_setIndex[UpdateFrequency.PER_PASS]] = passOffset;
|
||||
samplerTextureOffsets[_setIndex[UpdateFrequency.PER_PHASE]] = phaseOffset;
|
||||
samplerTextureOffsets[_setIndex[UpdateFrequency.PER_BATCH]] = batchOffset;
|
||||
samplerTextureOffsets[_setIndex[UpdateFrequency.PER_INSTANCE]] = instanceOffset;
|
||||
|
||||
// update flattened sampler texture binding
|
||||
setFlattenedSamplerTextureBinding(samplerTextureOffsets, uniformBlockCapacities, shaderInfo.samplerTextures);
|
||||
setFlattenedSamplerTextureBinding(samplerTextureOffsets, uniformBlockCapacities, shaderInfo.samplers);
|
||||
setFlattenedSamplerTextureBinding(samplerTextureOffsets, uniformBlockCapacities, shaderInfo.textures);
|
||||
setFlattenedSamplerTextureBinding(samplerTextureOffsets, uniformBlockCapacities, shaderInfo.buffers);
|
||||
setFlattenedSamplerTextureBinding(samplerTextureOffsets, uniformBlockCapacities, shaderInfo.images);
|
||||
}
|
||||
}
|
||||
|
||||
// make gfx.ShaderInfo
|
||||
function makeShaderInfo (
|
||||
lg: LayoutGraphData,
|
||||
@@ -348,11 +459,14 @@ function makeShaderInfo (
|
||||
programData: ShaderProgramData | null,
|
||||
fixedLocal: boolean,
|
||||
): [ShaderInfo, Array<number>] {
|
||||
const descriptorSets: Array<DescriptorSetLayoutData | null> = [null, null, null, null];
|
||||
let fixedInstanceDescriptorSetLayout: IDescriptorSetLayoutInfo | null = null;
|
||||
const shaderInfo = new ShaderInfo();
|
||||
const blockSizes = new Array<number>();
|
||||
{ // pass
|
||||
const passLayout = passLayouts.descriptorSets.get(UpdateFrequency.PER_PASS);
|
||||
if (passLayout) {
|
||||
descriptorSets[UpdateFrequency.PER_PASS] = passLayout.descriptorSetLayoutData;
|
||||
populateMergedShaderInfo(lg.valueNames, passLayout.descriptorSetLayoutData,
|
||||
_setIndex[UpdateFrequency.PER_PASS], shaderInfo, blockSizes);
|
||||
}
|
||||
@@ -360,6 +474,7 @@ function makeShaderInfo (
|
||||
{ // phase
|
||||
const phaseLayout = phaseLayouts.descriptorSets.get(UpdateFrequency.PER_PHASE);
|
||||
if (phaseLayout) {
|
||||
descriptorSets[UpdateFrequency.PER_PHASE] = phaseLayout.descriptorSetLayoutData;
|
||||
populateMergedShaderInfo(lg.valueNames, phaseLayout.descriptorSetLayoutData,
|
||||
_setIndex[UpdateFrequency.PER_PHASE], shaderInfo, blockSizes);
|
||||
}
|
||||
@@ -369,12 +484,14 @@ function makeShaderInfo (
|
||||
if (programData) {
|
||||
const perBatch = programData.layout.descriptorSets.get(UpdateFrequency.PER_BATCH);
|
||||
if (perBatch) {
|
||||
descriptorSets[UpdateFrequency.PER_BATCH] = perBatch.descriptorSetLayoutData;
|
||||
populateMergedShaderInfo(lg.valueNames, perBatch.descriptorSetLayoutData,
|
||||
_setIndex[UpdateFrequency.PER_BATCH], shaderInfo, blockSizes);
|
||||
}
|
||||
} else {
|
||||
const batchLayout = phaseLayouts.descriptorSets.get(UpdateFrequency.PER_BATCH);
|
||||
if (batchLayout) {
|
||||
descriptorSets[UpdateFrequency.PER_BATCH] = batchLayout.descriptorSetLayoutData;
|
||||
populateGroupedShaderInfo(batchLayout.descriptorSetLayoutData,
|
||||
batchInfo, _setIndex[UpdateFrequency.PER_BATCH],
|
||||
shaderInfo, blockSizes);
|
||||
@@ -385,10 +502,12 @@ function makeShaderInfo (
|
||||
const instanceInfo = srcShaderInfo.descriptors[UpdateFrequency.PER_INSTANCE];
|
||||
if (programData) {
|
||||
if (fixedLocal) {
|
||||
fixedInstanceDescriptorSetLayout = localDescriptorSetLayout;
|
||||
populateLocalShaderInfo(instanceInfo, localDescriptorSetLayout, shaderInfo, blockSizes);
|
||||
} else {
|
||||
const perInstance = programData.layout.descriptorSets.get(UpdateFrequency.PER_INSTANCE);
|
||||
if (perInstance) {
|
||||
descriptorSets[UpdateFrequency.PER_INSTANCE] = perInstance.descriptorSetLayoutData;
|
||||
populateMergedShaderInfo(lg.valueNames, perInstance.descriptorSetLayoutData,
|
||||
_setIndex[UpdateFrequency.PER_INSTANCE], shaderInfo, blockSizes);
|
||||
}
|
||||
@@ -396,28 +515,27 @@ function makeShaderInfo (
|
||||
} else {
|
||||
const instanceLayout = phaseLayouts.descriptorSets.get(UpdateFrequency.PER_INSTANCE);
|
||||
if (instanceLayout) {
|
||||
descriptorSets[UpdateFrequency.PER_INSTANCE] = instanceLayout.descriptorSetLayoutData;
|
||||
populateGroupedShaderInfo(instanceLayout.descriptorSetLayoutData,
|
||||
instanceInfo, _setIndex[UpdateFrequency.PER_INSTANCE],
|
||||
shaderInfo, blockSizes);
|
||||
}
|
||||
}
|
||||
}
|
||||
calculateFlattenedBinding(descriptorSets, fixedInstanceDescriptorSetLayout, shaderInfo);
|
||||
shaderInfo.stages.push(new ShaderStage(ShaderStageFlagBit.VERTEX, ''));
|
||||
shaderInfo.stages.push(new ShaderStage(ShaderStageFlagBit.FRAGMENT, ''));
|
||||
return [shaderInfo, blockSizes];
|
||||
}
|
||||
|
||||
class WebProgramProxy implements ProgramProxy {
|
||||
constructor (host: ProgramHost) {
|
||||
this.host = host;
|
||||
constructor (shader: Shader) {
|
||||
this.shader = shader;
|
||||
}
|
||||
get name (): string {
|
||||
return this.host.program.name;
|
||||
return this.shader.name;
|
||||
}
|
||||
get shader (): Shader {
|
||||
return this.host.program;
|
||||
}
|
||||
host: ProgramHost;
|
||||
readonly shader: Shader;
|
||||
}
|
||||
|
||||
// find name and type from local descriptor set info
|
||||
@@ -723,6 +841,7 @@ export class WebProgramLibrary implements ProgramLibrary {
|
||||
}
|
||||
// get program variant
|
||||
getProgramVariant (device: Device, phaseID: number, name: string, defines: MacroRecord, key: string | null = null): ProgramProxy | null {
|
||||
Object.assign(defines, this.pipeline?.macros);
|
||||
assert(phaseID !== INVALID_ID);
|
||||
// get phase
|
||||
const group = this.phases.get(phaseID);
|
||||
@@ -742,10 +861,10 @@ export class WebProgramLibrary implements ProgramLibrary {
|
||||
}
|
||||
|
||||
// try get program
|
||||
const programHosts = group.programHosts;
|
||||
const programHosts = group.programProxies;
|
||||
const programHost = programHosts.get(key);
|
||||
if (programHost !== undefined) {
|
||||
return new WebProgramProxy(programHost);
|
||||
return programHost;
|
||||
}
|
||||
|
||||
// prepare variant
|
||||
@@ -772,11 +891,11 @@ export class WebProgramLibrary implements ProgramLibrary {
|
||||
const shader = device.createShader(shaderInfo);
|
||||
|
||||
// create program host and register
|
||||
const host = new ProgramHost(shader);
|
||||
const host = new WebProgramProxy(shader);
|
||||
programHosts.set(key, host);
|
||||
|
||||
// create
|
||||
return new WebProgramProxy(host);
|
||||
return host;
|
||||
}
|
||||
// get material descriptor set layout
|
||||
getMaterialDescriptorSetLayout (device: Device, phaseID: number, programName: string): DescriptorSetLayout {
|
||||
@@ -882,8 +1001,9 @@ export class WebProgramLibrary implements ProgramLibrary {
|
||||
getDescriptorName (nameID: number): string {
|
||||
return getDescriptorName(this.layoutGraph, nameID);
|
||||
}
|
||||
layoutGraph: LayoutGraphData;
|
||||
readonly layoutGraph: LayoutGraphData;
|
||||
readonly phases: Map<number, ProgramGroup> = new Map<number, ProgramGroup>();
|
||||
mergeHighFrequency = false;
|
||||
fixedLocal = true;
|
||||
pipeline: PipelineRuntime | null = null;
|
||||
}
|
||||
|
||||
@@ -28,7 +28,8 @@
|
||||
* ========================= !DO NOT CHANGE THE FOLLOWING SECTION MANUALLY! =========================
|
||||
*/
|
||||
/* eslint-disable max-len */
|
||||
import { Attribute, Shader, ShaderInfo } from '../../gfx';
|
||||
import { Attribute, ShaderInfo } from '../../gfx';
|
||||
import { ProgramProxy } from './private';
|
||||
import { IProgramInfo } from '../../render-scene/core/program-lib';
|
||||
|
||||
export class ProgramInfo {
|
||||
@@ -52,14 +53,7 @@ export class ProgramInfo {
|
||||
readonly handleMap: Record<string, number>;
|
||||
}
|
||||
|
||||
export class ProgramHost {
|
||||
constructor (program: Shader) {
|
||||
this.program = program;
|
||||
}
|
||||
/*refcount*/ program: Shader;
|
||||
}
|
||||
|
||||
export class ProgramGroup {
|
||||
readonly programInfos: Map<string, ProgramInfo> = new Map<string, ProgramInfo>();
|
||||
readonly programHosts: Map<string, ProgramHost> = new Map<string, ProgramHost>();
|
||||
readonly programProxies: Map<string, ProgramProxy> = new Map<string, ProgramProxy>();
|
||||
}
|
||||
|
||||
+66
-102
@@ -54,6 +54,24 @@ export const ReflectionProbeFlow = nr.ReflectionProbeFlow;
|
||||
export const ReflectionProbeStage = nr.ReflectionProbeStage;
|
||||
export { PipelineEventType } from './pipeline-event';
|
||||
|
||||
interface IRenderFlowInfo {
|
||||
name: string;
|
||||
priority: number;
|
||||
stages: any[];
|
||||
tag: number;
|
||||
}
|
||||
|
||||
interface IRenderPipelineInfo {
|
||||
flows: any[];
|
||||
tag: number;
|
||||
}
|
||||
interface IRenderStageInfo {
|
||||
name: string;
|
||||
priority: number;
|
||||
tag: number;
|
||||
renderQueues: RenderQueueDesc[];
|
||||
}
|
||||
|
||||
let getOrCreatePipelineState = nr.PipelineStateManager.getOrCreatePipelineState;
|
||||
nr.PipelineStateManager.getOrCreatePipelineState = function (device, pass, shader, renderPass, ia) {
|
||||
return getOrCreatePipelineState(pass, shader, renderPass, ia); //cjh TODO: remove hacking. c++ API doesn't access device argument.
|
||||
@@ -70,7 +88,7 @@ forwardPipelineProto.init = function () {
|
||||
for (let i = 0; i < this._flows.length; i++) {
|
||||
this._flows[i].init(this);
|
||||
}
|
||||
const info = new nr.RenderPipelineInfo(this._tag, this._flows);
|
||||
const info: IRenderPipelineInfo = { tag: this._tag, flows: this._flows };
|
||||
this.initialize(info);
|
||||
};
|
||||
|
||||
@@ -81,7 +99,7 @@ forwardPipelineProto.onLoaded = function () {
|
||||
for (let i = 0; i < this._flows.length; i++) {
|
||||
this._flows[i].init(this);
|
||||
}
|
||||
const info = new nr.RenderPipelineInfo(this._tag, this._flows);
|
||||
const info: IRenderPipelineInfo = { tag: this._tag, flows: this._flows };
|
||||
this.initialize(info);
|
||||
}
|
||||
|
||||
@@ -96,7 +114,7 @@ forwardFlowProto.init = function (pipeline) {
|
||||
for (let i = 0; i < this._stages.length; i++) {
|
||||
this._stages[i].init(pipeline);
|
||||
}
|
||||
const info = new nr.RenderFlowInfo(this._name, this._priority, this._tag, this._stages);
|
||||
const info: IRenderFlowInfo = { name: this._name, priority: this._priority, tag: this._tag, stages: this._stages };
|
||||
this.initialize(info);
|
||||
}
|
||||
|
||||
@@ -111,7 +129,7 @@ shadowFlowProto.init = function (pipeline) {
|
||||
for (let i = 0; i < this._stages.length; i++) {
|
||||
this._stages[i].init(pipeline);
|
||||
}
|
||||
const info = new nr.RenderFlowInfo(this._name, this._priority, this._tag, this._stages);
|
||||
const info: IRenderFlowInfo = { name: this._name, priority: this._priority, tag: this._tag, stages: this._stages };
|
||||
this.initialize(info);
|
||||
}
|
||||
|
||||
@@ -126,7 +144,7 @@ reflectionProbeFlowProto.init = function (pipeline) {
|
||||
for (let i = 0; i < this._stages.length; i++) {
|
||||
this._stages[i].init(pipeline);
|
||||
}
|
||||
const info = new nr.RenderFlowInfo(this._name, this._priority, this._tag, this._stages);
|
||||
const info: IRenderFlowInfo = { name: this._name, priority: this._priority, tag: this._tag, stages: this._stages };
|
||||
this.initialize(info);
|
||||
}
|
||||
|
||||
@@ -143,7 +161,7 @@ forwardStageProto.init = function (pipeline) {
|
||||
// @ts-ignore
|
||||
queues.push(this.renderQueues[i].init());
|
||||
}
|
||||
const info = new nr.RenderStageInfo(this._name, this._priority, this._tag, queues);
|
||||
const info: IRenderStageInfo = { name: this._name, priority: this._priority, tag: this._tag, renderQueues: queues };
|
||||
this.initialize(info);
|
||||
}
|
||||
|
||||
@@ -167,7 +185,7 @@ reflectionProbeStage.init = function (pipeline) {
|
||||
// @ts-ignore
|
||||
queues.push(this.renderQueues[i].init());
|
||||
}
|
||||
const info = new nr.RenderStageInfo(this._name, this._priority, this._tag, queues);
|
||||
const info: IRenderStageInfo = { name: this._name, priority: this._priority, tag: this._tag, renderQueues: queues };
|
||||
this.initialize(info);
|
||||
}
|
||||
|
||||
@@ -179,7 +197,7 @@ export enum RenderQueueSortMode {
|
||||
ccenum(RenderQueueSortMode);
|
||||
|
||||
shadowStageProto.init = function (pipeline) {
|
||||
const info = new nr.RenderStageInfo(this._name, this._priority, this._tag, []);
|
||||
const info: IRenderStageInfo = { name: this._name, priority: this._priority, tag: this._tag, renderQueues: [] };
|
||||
this.initialize(info);
|
||||
}
|
||||
|
||||
@@ -232,7 +250,7 @@ deferredPipelineProto.onLoaded = function () {
|
||||
for (let i = 0; i < this._flows.length; i++) {
|
||||
this._flows[i].init(this);
|
||||
}
|
||||
let info = new nr.RenderPipelineInfo(this._tag, this._flows);
|
||||
let info = { tag: this._tag, flows: this._flows };
|
||||
this.initialize(info);
|
||||
}
|
||||
|
||||
@@ -247,7 +265,7 @@ mainFlowProto.init = function (pipeline) {
|
||||
for (let i = 0; i < this._stages.length; i++) {
|
||||
this._stages[i].init(pipeline);
|
||||
}
|
||||
let info = new nr.RenderFlowInfo(this._name, this._priority, this._tag, this._stages);
|
||||
const info: IRenderFlowInfo = { name: this._name, priority: this._priority, tag: this._tag, stages: this._stages };
|
||||
this.initialize(info);
|
||||
}
|
||||
|
||||
@@ -264,7 +282,7 @@ gbufferStageProto.init = function (pipeline) {
|
||||
// @ts-ignore
|
||||
queues.push(this.renderQueues[i].init());
|
||||
}
|
||||
let info = new nr.RenderStageInfo(this._name, this._priority, this._tag, queues);
|
||||
const info: IRenderStageInfo = { name: this._name, priority: this._priority, tag: this._tag, renderQueues: queues };
|
||||
this.initialize(info);
|
||||
}
|
||||
|
||||
@@ -284,7 +302,7 @@ lightingStageProto.init = function (pipeline) {
|
||||
queues.push(this.renderQueues[i].init());
|
||||
}
|
||||
pipeline.pipelineSceneData.deferredLightingMaterial = this._deferredMaterial;
|
||||
let info = new nr.RenderStageInfo(this._name, this._priority, this._tag, queues);
|
||||
const info: IRenderStageInfo = { name: this._name, priority: this._priority, tag: this._tag, renderQueues: queues };
|
||||
this.initialize(info);
|
||||
}
|
||||
|
||||
@@ -303,7 +321,7 @@ bloomStageProto.init = function (pipeline) {
|
||||
queues.push(this.renderQueues[i].init());
|
||||
}
|
||||
pipeline.pipelineSceneData.bloomMaterial = this._bloomMaterial;
|
||||
let info = new nr.RenderStageInfo(this._name, this._priority, this._tag, queues);
|
||||
const info: IRenderStageInfo = { name: this._name, priority: this._priority, tag: this._tag, renderQueues: queues };
|
||||
this.initialize(info);
|
||||
}
|
||||
|
||||
@@ -322,8 +340,7 @@ postProcessStageProto.init = function (pipeline) {
|
||||
queues.push(this.renderQueues[i].init());
|
||||
}
|
||||
pipeline.pipelineSceneData.postProcessMaterial = this._postProcessMaterial;
|
||||
let info =
|
||||
new nr.RenderStageInfo(this._name, this._priority, this._tag, queues);
|
||||
const info: IRenderStageInfo = { name: this._name, priority: this._priority, tag: this._tag, renderQueues: queues };
|
||||
this.initialize(info);
|
||||
}
|
||||
|
||||
@@ -344,34 +361,30 @@ class RenderTextureConfig {
|
||||
}
|
||||
|
||||
|
||||
function proxyArrayAttribute(proto: any, attr: string) {
|
||||
const underlyingAttr = `_udl_${attr}`;
|
||||
const underlyingPropt = Object.getOwnPropertyDescriptor(proto, attr);
|
||||
if (!underlyingPropt) {
|
||||
console.error(`Attribute ${attr} is not defined in function ${proto.constructor.name}`);
|
||||
return;
|
||||
function proxyArrayAttributeImpl(proto: any, attr: string) {
|
||||
const proxyTarget = `_${attr}_target`;
|
||||
let arrayProxy = (self, targetArrayAttr: string) => {
|
||||
return new Proxy(self[targetArrayAttr], {
|
||||
get(targetArray, prop, receiver) {
|
||||
return Reflect.get(targetArray, prop, receiver);
|
||||
},
|
||||
set(targetArray, prop, receiver) {
|
||||
const ret = Reflect.set(targetArray, prop, receiver);
|
||||
self[targetArrayAttr] = targetArray;
|
||||
return ret;
|
||||
}
|
||||
});
|
||||
}
|
||||
Object.defineProperty(proto, underlyingAttr, underlyingPropt!);
|
||||
|
||||
Object.defineProperty(proto, attr, {
|
||||
configurable: true,
|
||||
enumerable: true,
|
||||
get: function () {
|
||||
const self = this;
|
||||
return new Proxy(this[underlyingAttr], {
|
||||
get(target, prop, receiver) {
|
||||
// console.log('GET: ' + String(prop) );
|
||||
return Reflect.get(target, prop, receiver);
|
||||
},
|
||||
set(target, prop, receiver) {
|
||||
// console.log('SET: ' + String(prop) );
|
||||
const ret = Reflect.set(target, prop, receiver);
|
||||
self[underlyingAttr] = target;
|
||||
return ret;
|
||||
}
|
||||
});
|
||||
this[proxyTarget] ||= [];
|
||||
return arrayProxy(this, proxyTarget);
|
||||
},
|
||||
set: function (v) {
|
||||
this[underlyingAttr] = v;
|
||||
this[proxyTarget] = v;
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -381,56 +394,10 @@ function declType(proto: any, attrType: any, attr: string, dft: () => any) {
|
||||
}
|
||||
|
||||
|
||||
function declArrayPropetry(proto: any, attr: string) {
|
||||
const udKey = `__arr_${attr}`;
|
||||
Object.defineProperty(proto, attr, {
|
||||
configurable: true,
|
||||
enumerable: true,
|
||||
get() {
|
||||
if (!this[udKey]) {
|
||||
this[udKey] = [];
|
||||
}
|
||||
return this[udKey];
|
||||
},
|
||||
set(v: any) {
|
||||
if (!this[udKey]) {
|
||||
this[udKey] = [];
|
||||
}
|
||||
this[udKey] = v;
|
||||
}
|
||||
});
|
||||
}
|
||||
function declObjectPropetry(proto: any, attr: string, dftValue: any) {
|
||||
const udKey = `__obj_${attr}`;
|
||||
Object.defineProperty(proto, attr, {
|
||||
configurable: true,
|
||||
enumerable: true,
|
||||
get() {
|
||||
if (this[udKey] === undefined) {
|
||||
this[udKey] = dftValue;
|
||||
}
|
||||
return this[udKey];
|
||||
},
|
||||
set(v: any) {
|
||||
if (this[udKey] === undefined) {
|
||||
this[udKey] = dftValue;
|
||||
}
|
||||
this[udKey] = v;
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
declArrayPropetry(DeferredPipeline.prototype, 'renderTextures');
|
||||
declArrayPropetry(ForwardPipeline.prototype, 'renderTextures');
|
||||
declArrayPropetry(GbufferStage.prototype, 'renderQueues');
|
||||
declArrayPropetry(LightingStage.prototype, 'renderQueues');
|
||||
declArrayPropetry(PostProcessStage.prototype, 'renderQueues');
|
||||
declArrayPropetry(ForwardStage.prototype, 'renderQueues');
|
||||
|
||||
declObjectPropetry(LightingStage.prototype, '_deferredMaterial', null);
|
||||
declObjectPropetry(BloomStage.prototype, '_bloomMaterial', null);
|
||||
declObjectPropetry(PostProcessStage.prototype, '_postProcessMaterial', null);
|
||||
let proxyArrayAttribute = proxyArrayAttributeImpl;
|
||||
|
||||
editable(RenderStage.prototype, '_name', () => '');
|
||||
editable(RenderStage.prototype, '_tag', () => 0);
|
||||
@@ -461,30 +428,25 @@ serializable(RenderPipeline.prototype, '_flows', () => []);
|
||||
|
||||
editable(DeferredPipeline.prototype, 'renderTextures', () => []);
|
||||
declType(DeferredPipeline.prototype, [RenderTextureConfig], "renderTextures", () => []);
|
||||
proxyArrayAttribute(DeferredPipeline.prototype, 'renderTextures');
|
||||
serializable(DeferredPipeline.prototype, 'renderTextures', () => []);
|
||||
editable(DeferredPipeline.prototype, 'renderTextures', () => []);
|
||||
|
||||
|
||||
editable(ForwardPipeline.prototype, 'renderTextures', () => []);
|
||||
declType(ForwardPipeline.prototype, [RenderTextureConfig], "renderTextures", () => []);
|
||||
proxyArrayAttribute(ForwardPipeline.prototype, 'renderTextures');
|
||||
serializable(ForwardPipeline.prototype, 'renderTextures', () => []);
|
||||
|
||||
declType(GbufferStage.prototype, [RenderQueueDesc], 'renderQueues', () => []);
|
||||
proxyArrayAttribute(GbufferStage.prototype, 'renderQueues');
|
||||
serializable(GbufferStage.prototype, 'renderQueues', () => []);
|
||||
editable(GbufferStage.prototype, 'renderQueues', () => []);
|
||||
|
||||
// serializable(RenderQueueDesc.prototype, 'isTransparent', () => false);
|
||||
// editable(RenderQueueDesc.prototype, 'isTransparent', () => false);
|
||||
// editable(RenderQueueDesc.prototype, 'sortMode', () => false);
|
||||
// editable(RenderQueueDesc.prototype, 'stages', () => []);
|
||||
|
||||
editable(LightingStage.prototype, '_deferredMaterial', () => null);
|
||||
declType(LightingStage.prototype, jsb.Material, '_deferredMaterial', () => null);
|
||||
declType(LightingStage.prototype, [RenderQueueDesc], 'renderQueues', () => []);
|
||||
proxyArrayAttribute(LightingStage.prototype, 'renderQueues');
|
||||
serializable(LightingStage.prototype, '_deferredMaterial', () => null);
|
||||
serializable(LightingStage.prototype, 'renderQueue', () => []);
|
||||
editable(LightingStage.prototype, 'renderQueue', () => []);
|
||||
|
||||
editable(BloomStage.prototype, '_bloomMaterial', () => null);
|
||||
declType(BloomStage.prototype, jsb.Material, '_bloomMaterial', () => []);
|
||||
@@ -492,31 +454,33 @@ serializable(BloomStage.prototype, '_bloomMaterial', () => null);
|
||||
|
||||
|
||||
declType(PostProcessStage.prototype, [RenderQueueDesc], 'renderQueues', () => []);
|
||||
proxyArrayAttribute(PostProcessStage.prototype, 'renderQueues');
|
||||
editable(PostProcessStage.prototype, '_postProcessMaterial', () => null);
|
||||
declType(PostProcessStage.prototype, jsb.Material, '_postProcessMaterial', () => null);
|
||||
serializable(PostProcessStage.prototype, 'renderQueues', () => []);
|
||||
editable(PostProcessStage.prototype, 'renderQueues', () => []);
|
||||
serializable(PostProcessStage.prototype, '_postProcessMaterial', () => null);
|
||||
|
||||
declType(ForwardStage.prototype, [RenderQueueDesc], 'renderQueues', () => []);
|
||||
proxyArrayAttribute(ForwardStage.prototype, 'renderQueues');
|
||||
serializable(ForwardStage.prototype, 'renderQueues', () => []);
|
||||
editable(ForwardStage.prototype, 'renderQueues', () => []);
|
||||
|
||||
//-------------------- register types --------------------
|
||||
ccclass('cc.RenderPipeline')(RenderPipeline);
|
||||
ccclass('RenderQueueDesc')(RenderQueueDesc);
|
||||
ccclass('RenderStage')(RenderStage)
|
||||
ccclass('RenderFlow')(RenderFlow)
|
||||
ccclass('ForwardPipeline')(ForwardPipeline);
|
||||
ccclass('DeferredPipeline')(DeferredPipeline);
|
||||
ccclass('MainFlow')(MainFlow);
|
||||
ccclass('ForwardFlow')(ForwardFlow);
|
||||
ccclass('ShadowFlow')(ShadowFlow);
|
||||
ccclass('ReflectionProbeStage')(ReflectionProbeStage);
|
||||
ccclass('GbufferStage')(GbufferStage);
|
||||
ccclass('LightingStage')(LightingStage);
|
||||
ccclass('BloomStage')(BloomStage);
|
||||
ccclass('PostProcessStage')(PostProcessStage);
|
||||
ccclass('ForwardStage')(ForwardStage);
|
||||
ccclass('ShadowStage')(ShadowStage);
|
||||
ccclass('RenderQueueDesc')(RenderQueueDesc);
|
||||
|
||||
ccclass('RenderFlow')(RenderFlow)
|
||||
ccclass('MainFlow')(MainFlow);
|
||||
ccclass('ForwardFlow')(ForwardFlow);
|
||||
ccclass('ShadowFlow')(ShadowFlow);
|
||||
ccclass('ReflectionProbeFlow')(ReflectionProbeFlow);
|
||||
ccclass('ReflectionProbeStage')(ReflectionProbeStage);
|
||||
|
||||
ccclass('cc.RenderPipeline')(RenderPipeline);
|
||||
ccclass('ForwardPipeline')(ForwardPipeline);
|
||||
ccclass('DeferredPipeline')(DeferredPipeline);
|
||||
@@ -88,34 +88,37 @@ export function shadowCulling (camera: Camera, sceneData: PipelineSceneData, lay
|
||||
dirShadowObjects.length = 0;
|
||||
const visibility = camera.visibility;
|
||||
|
||||
csmLayerObjects.array.forEach((obj, index) => {
|
||||
for (let i = csmLayerObjects.length - 1; i >= 0; i--) {
|
||||
const obj = csmLayerObjects.array[i];
|
||||
if (!obj) {
|
||||
return;
|
||||
csmLayerObjects.fastRemove(i);
|
||||
continue;
|
||||
}
|
||||
const model = obj.model;
|
||||
if (!model || !model.enabled || !model.node) {
|
||||
return;
|
||||
csmLayerObjects.fastRemove(i);
|
||||
continue;
|
||||
}
|
||||
if (((visibility & model.node.layer) !== model.node.layer) && !(visibility & model.visFlags)) {
|
||||
return;
|
||||
if (((visibility & model.node.layer) !== model.node.layer) && (!(visibility & model.visFlags))) {
|
||||
csmLayerObjects.fastRemove(i);
|
||||
continue;
|
||||
}
|
||||
if (!model.worldBounds || !model.castShadow) {
|
||||
return;
|
||||
csmLayerObjects.fastRemove(i);
|
||||
continue;
|
||||
}
|
||||
|
||||
// frustum culling
|
||||
const accurate = geometry.intersect.aabbFrustum(model.worldBounds, dirLightFrustum);
|
||||
if (!accurate) {
|
||||
return;
|
||||
continue;
|
||||
}
|
||||
dirShadowObjects.push(obj);
|
||||
if (layer.level < mainLight.csmLevel) {
|
||||
if (mainLight.csmOptimizationMode === CSMOptimizationMode.RemoveDuplicates
|
||||
&& geometry.intersect.aabbFrustumCompletelyInside(model.worldBounds, dirLightFrustum)) {
|
||||
csmLayerObjects.fastRemove(index);
|
||||
csmLayerObjects.fastRemove(i);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
export function sceneCulling (pipeline: RenderPipeline, camera: Camera) {
|
||||
|
||||
+13
-10
@@ -33,7 +33,7 @@ import { DirectionalLight } from './render-scene/scene/directional-light';
|
||||
import { SphereLight } from './render-scene/scene/sphere-light';
|
||||
import { SpotLight } from './render-scene/scene/spot-light';
|
||||
import { RenderWindow, IRenderWindowInfo } from './render-scene/core/render-window';
|
||||
import { ColorAttachment, DepthStencilAttachment, RenderPassInfo, StoreOp, Device, Swapchain, Feature, deviceManager } from './gfx';
|
||||
import { ColorAttachment, DepthStencilAttachment, RenderPassInfo, StoreOp, Device, Swapchain, Feature, deviceManager, LegacyRenderMode } from './gfx';
|
||||
import { Pipeline, PipelineRuntime } from './rendering/custom/pipeline';
|
||||
import { Batcher2D } from './2d/renderer/batcher-2d';
|
||||
import { IPipelineEvent } from './rendering/pipeline-event';
|
||||
@@ -397,16 +397,19 @@ export class Root {
|
||||
this._usesCustomPipeline = false;
|
||||
}
|
||||
|
||||
if (!this._pipeline.activate(this._mainWindow!.swapchain)) {
|
||||
if (isCreateDefaultPipeline) {
|
||||
this._pipeline.destroy();
|
||||
}
|
||||
this._classicPipeline = null;
|
||||
this._customPipeline = null;
|
||||
this._pipeline = null;
|
||||
this._pipelineEvent = null;
|
||||
const renderMode = settings.querySettings(Settings.Category.RENDERING, 'renderMode');
|
||||
if (renderMode !== LegacyRenderMode.HEADLESS || this._classicPipeline) {
|
||||
if (!this._pipeline.activate(this._mainWindow!.swapchain)) {
|
||||
if (isCreateDefaultPipeline) {
|
||||
this._pipeline.destroy();
|
||||
}
|
||||
this._classicPipeline = null;
|
||||
this._customPipeline = null;
|
||||
this._pipeline = null;
|
||||
this._pipelineEvent = null;
|
||||
|
||||
return false;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
//-----------------------------------------------
|
||||
|
||||
@@ -33,6 +33,18 @@ const Destroying = CCObject.Flags.Destroying;
|
||||
const IS_PREVIEW = !!legacyCC.GAME_VIEW;
|
||||
|
||||
export function nodePolyfill (Node) {
|
||||
if ((EDITOR && !IS_PREVIEW) || TEST) {
|
||||
Node.prototype._onPreDestroy = function () {
|
||||
const destroyByParent: boolean = this._onPreDestroyBase();
|
||||
if (!destroyByParent) {
|
||||
// ensure this node can reattach to scene by undo system
|
||||
// (simulate some destruct logic to make undo system work correctly)
|
||||
this._parent = null;
|
||||
}
|
||||
return destroyByParent;
|
||||
};
|
||||
}
|
||||
|
||||
if (EDITOR || TEST) {
|
||||
Node.prototype._checkMultipleComp = function (ctor) {
|
||||
const existing = this.getComponent(ctor._disallowMultiple);
|
||||
@@ -71,8 +83,6 @@ export function nodePolyfill (Node) {
|
||||
}
|
||||
return dependant;
|
||||
};
|
||||
}
|
||||
if ((EDITOR && !IS_PREVIEW) || TEST) {
|
||||
/**
|
||||
* This api should only used by undo system
|
||||
* @method _addComponentAt
|
||||
@@ -133,21 +143,8 @@ export function nodePolyfill (Node) {
|
||||
legacyCC.director._nodeActivator.activateNode(this, shouldActiveNow);
|
||||
}
|
||||
};
|
||||
|
||||
Node.prototype._onPreDestroy = function () {
|
||||
const destroyByParent: boolean = this._onPreDestroyBase();
|
||||
if (!destroyByParent) {
|
||||
// ensure this node can reattach to scene by undo system
|
||||
// (simulate some destruct logic to make undo system work correctly)
|
||||
this._parent = null;
|
||||
}
|
||||
return destroyByParent;
|
||||
};
|
||||
|
||||
Node.prototype._onRestoreBase = Node.prototype.onRestore;
|
||||
}
|
||||
|
||||
if ((EDITOR && !IS_PREVIEW) || TEST) {
|
||||
Node.prototype._registerIfAttached = function (register) {
|
||||
if (!this._id) {
|
||||
console.warn(`Node(${this && this.name}}) is invalid or its data is corrupted.`);
|
||||
|
||||
@@ -432,8 +432,10 @@ export function expandNestedPrefabInstanceNode (node: Node) {
|
||||
prefabInfo.nestedPrefabInstanceRoots.forEach((instanceNode: Node) => {
|
||||
expandPrefabInstanceNode(instanceNode);
|
||||
// when expanding the prefab,it's children will be change,so need to apply after expanded
|
||||
// @ts-expect-error private member access
|
||||
applyNodeAndComponentId(instanceNode, instanceNode._prefab?.instance?.fileId);
|
||||
if (!EDITOR) {
|
||||
// @ts-expect-error private member access
|
||||
applyNodeAndComponentId(instanceNode, instanceNode._prefab?.instance?.fileId);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,27 +1,3 @@
|
||||
/****************************************************************************
|
||||
Copyright (c) 2022-2023 Xiamen Yaji Software Co., Ltd.
|
||||
|
||||
https://www.cocos.com/
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights to
|
||||
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
|
||||
of the Software, and to permit persons to whom the Software is furnished to do so,
|
||||
subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
|
||||
Spine Runtimes License Agreement
|
||||
Last updated May 1, 2019. Replaces all prior versions.
|
||||
|
||||
|
||||
@@ -5,38 +5,86 @@ CCEffect %{
|
||||
- passes:
|
||||
- vert: bloom-vs
|
||||
frag: prefilter-fs
|
||||
phase: bloom-prefilter
|
||||
pass: bloom-prefilter
|
||||
depthStencilState:
|
||||
depthTest: false
|
||||
depthWrite: false
|
||||
# Supports up to MAX_BLOOM_FILTER_PASS_NUM upsample/downsample passes
|
||||
- &downsample
|
||||
vert: bloom-vs
|
||||
frag: downsample-fs
|
||||
phase: bloom-downsample
|
||||
depthStencilState:
|
||||
depthTest: false
|
||||
depthWrite: false
|
||||
- *downsample
|
||||
- *downsample
|
||||
- *downsample
|
||||
- *downsample
|
||||
- *downsample
|
||||
- &upsample
|
||||
vert: bloom-vs
|
||||
frag: upsample-fs
|
||||
phase: bloom-upsample
|
||||
depthStencilState:
|
||||
depthTest: false
|
||||
depthWrite: false
|
||||
- *upsample
|
||||
- *upsample
|
||||
- *upsample
|
||||
- *upsample
|
||||
- *upsample
|
||||
- vert: bloom-vs
|
||||
frag: downsample-fs
|
||||
pass: bloom-downsample0
|
||||
depthStencilState:
|
||||
depthTest: false
|
||||
depthWrite: false
|
||||
- vert: bloom-vs
|
||||
frag: downsample-fs
|
||||
pass: bloom-downsample1
|
||||
depthStencilState:
|
||||
depthTest: false
|
||||
depthWrite: false
|
||||
- vert: bloom-vs
|
||||
frag: downsample-fs
|
||||
pass: bloom-downsample2
|
||||
depthStencilState:
|
||||
depthTest: false
|
||||
depthWrite: false
|
||||
- vert: bloom-vs
|
||||
frag: downsample-fs
|
||||
pass: bloom-downsample3
|
||||
depthStencilState:
|
||||
depthTest: false
|
||||
depthWrite: false
|
||||
- vert: bloom-vs
|
||||
frag: downsample-fs
|
||||
pass: bloom-downsample4
|
||||
depthStencilState:
|
||||
depthTest: false
|
||||
depthWrite: false
|
||||
- vert: bloom-vs
|
||||
frag: downsample-fs
|
||||
pass: bloom-downsample5
|
||||
depthStencilState:
|
||||
depthTest: false
|
||||
depthWrite: false
|
||||
- vert: bloom-vs
|
||||
frag: upsample-fs
|
||||
pass: bloom-upsample0
|
||||
depthStencilState:
|
||||
depthTest: false
|
||||
depthWrite: false
|
||||
- vert: bloom-vs
|
||||
frag: upsample-fs
|
||||
pass: bloom-upsample1
|
||||
depthStencilState:
|
||||
depthTest: false
|
||||
depthWrite: false
|
||||
- vert: bloom-vs
|
||||
frag: upsample-fs
|
||||
pass: bloom-upsample2
|
||||
depthStencilState:
|
||||
depthTest: false
|
||||
depthWrite: false
|
||||
- vert: bloom-vs
|
||||
frag: upsample-fs
|
||||
pass: bloom-upsample3
|
||||
depthStencilState:
|
||||
depthTest: false
|
||||
depthWrite: false
|
||||
- vert: bloom-vs
|
||||
frag: upsample-fs
|
||||
pass: bloom-upsample4
|
||||
depthStencilState:
|
||||
depthTest: false
|
||||
depthWrite: false
|
||||
- vert: bloom-vs
|
||||
frag: upsample-fs
|
||||
pass: bloom-upsample5
|
||||
depthStencilState:
|
||||
depthTest: false
|
||||
depthWrite: false
|
||||
- vert: bloom-vs
|
||||
frag: combine-fs
|
||||
phase: bloom-combine
|
||||
pass: bloom-combine
|
||||
depthStencilState:
|
||||
depthTest: false
|
||||
depthWrite: false
|
||||
@@ -70,6 +118,7 @@ CCProgram prefilter-fs %{
|
||||
uniform BloomUBO {
|
||||
mediump vec4 texSize;
|
||||
};
|
||||
#pragma rate outputResultMap pass
|
||||
uniform sampler2D outputResultMap;
|
||||
|
||||
layout(location = 0) out vec4 fragColor;
|
||||
@@ -98,6 +147,7 @@ CCProgram downsample-fs %{
|
||||
uniform BloomUBO {
|
||||
mediump vec4 texSize;
|
||||
};
|
||||
#pragma rate bloomTexture pass
|
||||
uniform sampler2D bloomTexture;
|
||||
|
||||
layout(location = 0) out vec4 fragColor;
|
||||
@@ -140,6 +190,7 @@ CCProgram upsample-fs %{
|
||||
uniform BloomUBO {
|
||||
mediump vec4 texSize;
|
||||
};
|
||||
#pragma rate bloomTexture pass
|
||||
uniform sampler2D bloomTexture;
|
||||
|
||||
layout(location = 0) out vec4 fragColor;
|
||||
@@ -182,7 +233,9 @@ CCProgram combine-fs %{
|
||||
uniform BloomUBO {
|
||||
mediump vec4 texSize;
|
||||
};
|
||||
#pragma rate outputResultMap pass
|
||||
uniform sampler2D outputResultMap;
|
||||
#pragma rate bloomTexture pass
|
||||
uniform sampler2D bloomTexture;
|
||||
|
||||
layout(location = 0) out vec4 fragColor;
|
||||
|
||||
@@ -5,7 +5,7 @@ CCEffect %{
|
||||
- passes:
|
||||
- vert: lighting-vs
|
||||
frag: lighting-fs
|
||||
phase: deferred-lighting
|
||||
pass: deferred-lighting
|
||||
depthStencilState:
|
||||
depthFunc: greater
|
||||
depthTest: true
|
||||
@@ -60,9 +60,13 @@ CCProgram lighting-fs %{
|
||||
layout(binding = 3) uniform sampler2D depth_stencil;
|
||||
#endif
|
||||
#else
|
||||
#pragma rate gbuffer_albedoMap pass
|
||||
layout(binding = 0) uniform sampler2D gbuffer_albedoMap;
|
||||
#pragma rate gbuffer_normalMap pass
|
||||
layout(binding = 1) uniform sampler2D gbuffer_normalMap;
|
||||
#pragma rate gbuffer_emissiveMap pass
|
||||
layout(binding = 2) uniform sampler2D gbuffer_emissiveMap;
|
||||
#pragma rate depth_stencil pass
|
||||
layout(binding = 3) uniform sampler2D depth_stencil;
|
||||
#endif
|
||||
|
||||
|
||||
@@ -5,6 +5,7 @@ CCEffect %{
|
||||
passes:
|
||||
- vert: fxaa-vs:vert
|
||||
frag: fxaa-edge-fs:frag
|
||||
pass: fxaa
|
||||
depthStencilState:
|
||||
depthTest: false
|
||||
depthWrite: false
|
||||
@@ -40,6 +41,7 @@ CCProgram fxaa-edge-fs %{
|
||||
};
|
||||
|
||||
in vec2 v_uv;
|
||||
#pragma rate sceneColorMap pass
|
||||
uniform sampler2D sceneColorMap;
|
||||
|
||||
vec4 frag () {
|
||||
@@ -56,6 +58,7 @@ CCProgram copy-fs %{
|
||||
};
|
||||
|
||||
in vec2 v_uv;
|
||||
#pragma rate sceneColorMap pass
|
||||
uniform sampler2D sceneColorMap;
|
||||
|
||||
vec4 frag () {
|
||||
|
||||
@@ -5,7 +5,7 @@ CCEffect %{
|
||||
- passes:
|
||||
- vert: post-process-vs
|
||||
frag: post-process-fs
|
||||
phase: post-process
|
||||
pass: post-process
|
||||
depthStencilState:
|
||||
depthTest: false
|
||||
depthWrite: false
|
||||
@@ -44,6 +44,7 @@ CCProgram post-process-fs %{
|
||||
#include <post-process/anti-aliasing>
|
||||
in vec2 v_uv;
|
||||
|
||||
#pragma rate outputResultMap pass
|
||||
layout(binding = 0) uniform sampler2D outputResultMap;
|
||||
|
||||
layout(location = 0) out vec4 fragColor;
|
||||
|
||||
@@ -32,7 +32,7 @@ exports.template = /* html */`
|
||||
<ui-label slot="label" value="i18n:ENGINE.assets.fbx.promoteSingleRootNode.name" tooltip="i18n:ENGINE.assets.fbx.promoteSingleRootNode.title"></ui-label>
|
||||
<ui-checkbox slot="content" class="promoteSingleRootNode-checkbox"></ui-checkbox>
|
||||
</ui-prop>
|
||||
<ui-prop>
|
||||
<ui-prop hidden>
|
||||
<ui-label slot="label" value="i18n:ENGINE.assets.fbx.generateLightmapUVNode.name" tooltip="i18n:ENGINE.assets.fbx.generateLightmapUVNode.title"></ui-label>
|
||||
<ui-checkbox slot="content" class="generateLightmapUVNode-checkbox"></ui-checkbox>
|
||||
</ui-prop>
|
||||
|
||||
@@ -1372,6 +1372,7 @@ cocos_source_files(
|
||||
cocos/renderer/pipeline/custom/RenderInterfaceFwd.h
|
||||
cocos/renderer/pipeline/custom/RenderInterfaceTypes.cpp
|
||||
cocos/renderer/pipeline/custom/RenderInterfaceTypes.h
|
||||
cocos/renderer/pipeline/custom/RenderingModule.h
|
||||
)
|
||||
|
||||
if (USE_GEOMETRY_RENDERER)
|
||||
|
||||
@@ -8653,6 +8653,40 @@ static bool js_cc_gfx_UniformBlock_count_get(se::State& s)
|
||||
}
|
||||
SE_BIND_PROP_GET(js_cc_gfx_UniformBlock_count_get)
|
||||
|
||||
static bool js_cc_gfx_UniformBlock_flattened_set(se::State& s)
|
||||
{
|
||||
CC_UNUSED bool ok = true;
|
||||
const auto& args = s.args();
|
||||
size_t argc = args.size();
|
||||
cc::gfx::UniformBlock *arg1 = (cc::gfx::UniformBlock *) NULL ;
|
||||
|
||||
arg1 = SE_THIS_OBJECT<cc::gfx::UniformBlock>(s);
|
||||
if (nullptr == arg1) return true;
|
||||
|
||||
ok &= sevalue_to_native(args[0], &arg1->flattened, s.thisObject());
|
||||
SE_PRECONDITION2(ok, false, "Error processing arguments");
|
||||
|
||||
|
||||
|
||||
return true;
|
||||
}
|
||||
SE_BIND_PROP_SET(js_cc_gfx_UniformBlock_flattened_set)
|
||||
|
||||
static bool js_cc_gfx_UniformBlock_flattened_get(se::State& s)
|
||||
{
|
||||
CC_UNUSED bool ok = true;
|
||||
cc::gfx::UniformBlock *arg1 = (cc::gfx::UniformBlock *) NULL ;
|
||||
|
||||
arg1 = SE_THIS_OBJECT<cc::gfx::UniformBlock>(s);
|
||||
if (nullptr == arg1) return true;
|
||||
|
||||
ok &= nativevalue_to_se(arg1->flattened, s.rval(), s.thisObject());
|
||||
|
||||
|
||||
return true;
|
||||
}
|
||||
SE_BIND_PROP_GET(js_cc_gfx_UniformBlock_flattened_get)
|
||||
|
||||
static bool js_cc_gfx_UniformBlock_copy(se::State& s)
|
||||
{
|
||||
CC_UNUSED bool ok = true;
|
||||
@@ -8750,6 +8784,12 @@ bool sevalue_to_native(const se::Value &from, cc::gfx::UniformBlock * to, se::Ob
|
||||
}
|
||||
|
||||
|
||||
json->getProperty("flattened", &field, true);
|
||||
if (!field.isNullOrUndefined()) {
|
||||
ok &= sevalue_to_native(field, &(to->flattened), ctx);
|
||||
}
|
||||
|
||||
|
||||
return ok;
|
||||
}
|
||||
|
||||
@@ -8763,6 +8803,7 @@ bool js_register_cc_gfx_UniformBlock(se::Object* obj) {
|
||||
cls->defineProperty("name", _SE(js_cc_gfx_UniformBlock_name_get), _SE(js_cc_gfx_UniformBlock_name_set));
|
||||
cls->defineProperty("members", _SE(js_cc_gfx_UniformBlock_members_get), _SE(js_cc_gfx_UniformBlock_members_set));
|
||||
cls->defineProperty("count", _SE(js_cc_gfx_UniformBlock_count_get), _SE(js_cc_gfx_UniformBlock_count_set));
|
||||
cls->defineProperty("flattened", _SE(js_cc_gfx_UniformBlock_flattened_get), _SE(js_cc_gfx_UniformBlock_flattened_set));
|
||||
|
||||
cls->defineFunction("copy", _SE(js_cc_gfx_UniformBlock_copy));
|
||||
|
||||
@@ -8962,6 +9003,40 @@ static bool js_cc_gfx_UniformSamplerTexture_count_get(se::State& s)
|
||||
}
|
||||
SE_BIND_PROP_GET(js_cc_gfx_UniformSamplerTexture_count_get)
|
||||
|
||||
static bool js_cc_gfx_UniformSamplerTexture_flattened_set(se::State& s)
|
||||
{
|
||||
CC_UNUSED bool ok = true;
|
||||
const auto& args = s.args();
|
||||
size_t argc = args.size();
|
||||
cc::gfx::UniformSamplerTexture *arg1 = (cc::gfx::UniformSamplerTexture *) NULL ;
|
||||
|
||||
arg1 = SE_THIS_OBJECT<cc::gfx::UniformSamplerTexture>(s);
|
||||
if (nullptr == arg1) return true;
|
||||
|
||||
ok &= sevalue_to_native(args[0], &arg1->flattened, s.thisObject());
|
||||
SE_PRECONDITION2(ok, false, "Error processing arguments");
|
||||
|
||||
|
||||
|
||||
return true;
|
||||
}
|
||||
SE_BIND_PROP_SET(js_cc_gfx_UniformSamplerTexture_flattened_set)
|
||||
|
||||
static bool js_cc_gfx_UniformSamplerTexture_flattened_get(se::State& s)
|
||||
{
|
||||
CC_UNUSED bool ok = true;
|
||||
cc::gfx::UniformSamplerTexture *arg1 = (cc::gfx::UniformSamplerTexture *) NULL ;
|
||||
|
||||
arg1 = SE_THIS_OBJECT<cc::gfx::UniformSamplerTexture>(s);
|
||||
if (nullptr == arg1) return true;
|
||||
|
||||
ok &= nativevalue_to_se(arg1->flattened, s.rval(), s.thisObject());
|
||||
|
||||
|
||||
return true;
|
||||
}
|
||||
SE_BIND_PROP_GET(js_cc_gfx_UniformSamplerTexture_flattened_get)
|
||||
|
||||
static bool js_cc_gfx_UniformSamplerTexture_copy(se::State& s)
|
||||
{
|
||||
CC_UNUSED bool ok = true;
|
||||
@@ -9059,6 +9134,12 @@ bool sevalue_to_native(const se::Value &from, cc::gfx::UniformSamplerTexture * t
|
||||
}
|
||||
|
||||
|
||||
json->getProperty("flattened", &field, true);
|
||||
if (!field.isNullOrUndefined()) {
|
||||
ok &= sevalue_to_native(field, &(to->flattened), ctx);
|
||||
}
|
||||
|
||||
|
||||
return ok;
|
||||
}
|
||||
|
||||
@@ -9072,6 +9153,7 @@ bool js_register_cc_gfx_UniformSamplerTexture(se::Object* obj) {
|
||||
cls->defineProperty("name", _SE(js_cc_gfx_UniformSamplerTexture_name_get), _SE(js_cc_gfx_UniformSamplerTexture_name_set));
|
||||
cls->defineProperty("type", _SE(js_cc_gfx_UniformSamplerTexture_type_get), _SE(js_cc_gfx_UniformSamplerTexture_type_set));
|
||||
cls->defineProperty("count", _SE(js_cc_gfx_UniformSamplerTexture_count_get), _SE(js_cc_gfx_UniformSamplerTexture_count_set));
|
||||
cls->defineProperty("flattened", _SE(js_cc_gfx_UniformSamplerTexture_flattened_get), _SE(js_cc_gfx_UniformSamplerTexture_flattened_set));
|
||||
|
||||
cls->defineFunction("copy", _SE(js_cc_gfx_UniformSamplerTexture_copy));
|
||||
|
||||
@@ -9234,6 +9316,40 @@ static bool js_cc_gfx_UniformSampler_count_get(se::State& s)
|
||||
}
|
||||
SE_BIND_PROP_GET(js_cc_gfx_UniformSampler_count_get)
|
||||
|
||||
static bool js_cc_gfx_UniformSampler_flattened_set(se::State& s)
|
||||
{
|
||||
CC_UNUSED bool ok = true;
|
||||
const auto& args = s.args();
|
||||
size_t argc = args.size();
|
||||
cc::gfx::UniformSampler *arg1 = (cc::gfx::UniformSampler *) NULL ;
|
||||
|
||||
arg1 = SE_THIS_OBJECT<cc::gfx::UniformSampler>(s);
|
||||
if (nullptr == arg1) return true;
|
||||
|
||||
ok &= sevalue_to_native(args[0], &arg1->flattened, s.thisObject());
|
||||
SE_PRECONDITION2(ok, false, "Error processing arguments");
|
||||
|
||||
|
||||
|
||||
return true;
|
||||
}
|
||||
SE_BIND_PROP_SET(js_cc_gfx_UniformSampler_flattened_set)
|
||||
|
||||
static bool js_cc_gfx_UniformSampler_flattened_get(se::State& s)
|
||||
{
|
||||
CC_UNUSED bool ok = true;
|
||||
cc::gfx::UniformSampler *arg1 = (cc::gfx::UniformSampler *) NULL ;
|
||||
|
||||
arg1 = SE_THIS_OBJECT<cc::gfx::UniformSampler>(s);
|
||||
if (nullptr == arg1) return true;
|
||||
|
||||
ok &= nativevalue_to_se(arg1->flattened, s.rval(), s.thisObject());
|
||||
|
||||
|
||||
return true;
|
||||
}
|
||||
SE_BIND_PROP_GET(js_cc_gfx_UniformSampler_flattened_get)
|
||||
|
||||
static bool js_cc_gfx_UniformSampler_copy(se::State& s)
|
||||
{
|
||||
CC_UNUSED bool ok = true;
|
||||
@@ -9325,6 +9441,12 @@ bool sevalue_to_native(const se::Value &from, cc::gfx::UniformSampler * to, se::
|
||||
}
|
||||
|
||||
|
||||
json->getProperty("flattened", &field, true);
|
||||
if (!field.isNullOrUndefined()) {
|
||||
ok &= sevalue_to_native(field, &(to->flattened), ctx);
|
||||
}
|
||||
|
||||
|
||||
return ok;
|
||||
}
|
||||
|
||||
@@ -9337,6 +9459,7 @@ bool js_register_cc_gfx_UniformSampler(se::Object* obj) {
|
||||
cls->defineProperty("binding", _SE(js_cc_gfx_UniformSampler_binding_get), _SE(js_cc_gfx_UniformSampler_binding_set));
|
||||
cls->defineProperty("name", _SE(js_cc_gfx_UniformSampler_name_get), _SE(js_cc_gfx_UniformSampler_name_set));
|
||||
cls->defineProperty("count", _SE(js_cc_gfx_UniformSampler_count_get), _SE(js_cc_gfx_UniformSampler_count_set));
|
||||
cls->defineProperty("flattened", _SE(js_cc_gfx_UniformSampler_flattened_get), _SE(js_cc_gfx_UniformSampler_flattened_set));
|
||||
|
||||
cls->defineFunction("copy", _SE(js_cc_gfx_UniformSampler_copy));
|
||||
|
||||
@@ -9536,6 +9659,40 @@ static bool js_cc_gfx_UniformTexture_count_get(se::State& s)
|
||||
}
|
||||
SE_BIND_PROP_GET(js_cc_gfx_UniformTexture_count_get)
|
||||
|
||||
static bool js_cc_gfx_UniformTexture_flattened_set(se::State& s)
|
||||
{
|
||||
CC_UNUSED bool ok = true;
|
||||
const auto& args = s.args();
|
||||
size_t argc = args.size();
|
||||
cc::gfx::UniformTexture *arg1 = (cc::gfx::UniformTexture *) NULL ;
|
||||
|
||||
arg1 = SE_THIS_OBJECT<cc::gfx::UniformTexture>(s);
|
||||
if (nullptr == arg1) return true;
|
||||
|
||||
ok &= sevalue_to_native(args[0], &arg1->flattened, s.thisObject());
|
||||
SE_PRECONDITION2(ok, false, "Error processing arguments");
|
||||
|
||||
|
||||
|
||||
return true;
|
||||
}
|
||||
SE_BIND_PROP_SET(js_cc_gfx_UniformTexture_flattened_set)
|
||||
|
||||
static bool js_cc_gfx_UniformTexture_flattened_get(se::State& s)
|
||||
{
|
||||
CC_UNUSED bool ok = true;
|
||||
cc::gfx::UniformTexture *arg1 = (cc::gfx::UniformTexture *) NULL ;
|
||||
|
||||
arg1 = SE_THIS_OBJECT<cc::gfx::UniformTexture>(s);
|
||||
if (nullptr == arg1) return true;
|
||||
|
||||
ok &= nativevalue_to_se(arg1->flattened, s.rval(), s.thisObject());
|
||||
|
||||
|
||||
return true;
|
||||
}
|
||||
SE_BIND_PROP_GET(js_cc_gfx_UniformTexture_flattened_get)
|
||||
|
||||
static bool js_cc_gfx_UniformTexture_copy(se::State& s)
|
||||
{
|
||||
CC_UNUSED bool ok = true;
|
||||
@@ -9633,6 +9790,12 @@ bool sevalue_to_native(const se::Value &from, cc::gfx::UniformTexture * to, se::
|
||||
}
|
||||
|
||||
|
||||
json->getProperty("flattened", &field, true);
|
||||
if (!field.isNullOrUndefined()) {
|
||||
ok &= sevalue_to_native(field, &(to->flattened), ctx);
|
||||
}
|
||||
|
||||
|
||||
return ok;
|
||||
}
|
||||
|
||||
@@ -9646,6 +9809,7 @@ bool js_register_cc_gfx_UniformTexture(se::Object* obj) {
|
||||
cls->defineProperty("name", _SE(js_cc_gfx_UniformTexture_name_get), _SE(js_cc_gfx_UniformTexture_name_set));
|
||||
cls->defineProperty("type", _SE(js_cc_gfx_UniformTexture_type_get), _SE(js_cc_gfx_UniformTexture_type_set));
|
||||
cls->defineProperty("count", _SE(js_cc_gfx_UniformTexture_count_get), _SE(js_cc_gfx_UniformTexture_count_set));
|
||||
cls->defineProperty("flattened", _SE(js_cc_gfx_UniformTexture_flattened_get), _SE(js_cc_gfx_UniformTexture_flattened_set));
|
||||
|
||||
cls->defineFunction("copy", _SE(js_cc_gfx_UniformTexture_copy));
|
||||
|
||||
@@ -9882,6 +10046,40 @@ static bool js_cc_gfx_UniformStorageImage_memoryAccess_get(se::State& s)
|
||||
}
|
||||
SE_BIND_PROP_GET(js_cc_gfx_UniformStorageImage_memoryAccess_get)
|
||||
|
||||
static bool js_cc_gfx_UniformStorageImage_flattened_set(se::State& s)
|
||||
{
|
||||
CC_UNUSED bool ok = true;
|
||||
const auto& args = s.args();
|
||||
size_t argc = args.size();
|
||||
cc::gfx::UniformStorageImage *arg1 = (cc::gfx::UniformStorageImage *) NULL ;
|
||||
|
||||
arg1 = SE_THIS_OBJECT<cc::gfx::UniformStorageImage>(s);
|
||||
if (nullptr == arg1) return true;
|
||||
|
||||
ok &= sevalue_to_native(args[0], &arg1->flattened, s.thisObject());
|
||||
SE_PRECONDITION2(ok, false, "Error processing arguments");
|
||||
|
||||
|
||||
|
||||
return true;
|
||||
}
|
||||
SE_BIND_PROP_SET(js_cc_gfx_UniformStorageImage_flattened_set)
|
||||
|
||||
static bool js_cc_gfx_UniformStorageImage_flattened_get(se::State& s)
|
||||
{
|
||||
CC_UNUSED bool ok = true;
|
||||
cc::gfx::UniformStorageImage *arg1 = (cc::gfx::UniformStorageImage *) NULL ;
|
||||
|
||||
arg1 = SE_THIS_OBJECT<cc::gfx::UniformStorageImage>(s);
|
||||
if (nullptr == arg1) return true;
|
||||
|
||||
ok &= nativevalue_to_se(arg1->flattened, s.rval(), s.thisObject());
|
||||
|
||||
|
||||
return true;
|
||||
}
|
||||
SE_BIND_PROP_GET(js_cc_gfx_UniformStorageImage_flattened_get)
|
||||
|
||||
static bool js_cc_gfx_UniformStorageImage_copy(se::State& s)
|
||||
{
|
||||
CC_UNUSED bool ok = true;
|
||||
@@ -9985,6 +10183,12 @@ bool sevalue_to_native(const se::Value &from, cc::gfx::UniformStorageImage * to,
|
||||
}
|
||||
|
||||
|
||||
json->getProperty("flattened", &field, true);
|
||||
if (!field.isNullOrUndefined()) {
|
||||
ok &= sevalue_to_native(field, &(to->flattened), ctx);
|
||||
}
|
||||
|
||||
|
||||
return ok;
|
||||
}
|
||||
|
||||
@@ -9999,6 +10203,7 @@ bool js_register_cc_gfx_UniformStorageImage(se::Object* obj) {
|
||||
cls->defineProperty("type", _SE(js_cc_gfx_UniformStorageImage_type_get), _SE(js_cc_gfx_UniformStorageImage_type_set));
|
||||
cls->defineProperty("count", _SE(js_cc_gfx_UniformStorageImage_count_get), _SE(js_cc_gfx_UniformStorageImage_count_set));
|
||||
cls->defineProperty("memoryAccess", _SE(js_cc_gfx_UniformStorageImage_memoryAccess_get), _SE(js_cc_gfx_UniformStorageImage_memoryAccess_set));
|
||||
cls->defineProperty("flattened", _SE(js_cc_gfx_UniformStorageImage_flattened_get), _SE(js_cc_gfx_UniformStorageImage_flattened_set));
|
||||
|
||||
cls->defineFunction("copy", _SE(js_cc_gfx_UniformStorageImage_copy));
|
||||
|
||||
@@ -10198,6 +10403,40 @@ static bool js_cc_gfx_UniformStorageBuffer_memoryAccess_get(se::State& s)
|
||||
}
|
||||
SE_BIND_PROP_GET(js_cc_gfx_UniformStorageBuffer_memoryAccess_get)
|
||||
|
||||
static bool js_cc_gfx_UniformStorageBuffer_flattened_set(se::State& s)
|
||||
{
|
||||
CC_UNUSED bool ok = true;
|
||||
const auto& args = s.args();
|
||||
size_t argc = args.size();
|
||||
cc::gfx::UniformStorageBuffer *arg1 = (cc::gfx::UniformStorageBuffer *) NULL ;
|
||||
|
||||
arg1 = SE_THIS_OBJECT<cc::gfx::UniformStorageBuffer>(s);
|
||||
if (nullptr == arg1) return true;
|
||||
|
||||
ok &= sevalue_to_native(args[0], &arg1->flattened, s.thisObject());
|
||||
SE_PRECONDITION2(ok, false, "Error processing arguments");
|
||||
|
||||
|
||||
|
||||
return true;
|
||||
}
|
||||
SE_BIND_PROP_SET(js_cc_gfx_UniformStorageBuffer_flattened_set)
|
||||
|
||||
static bool js_cc_gfx_UniformStorageBuffer_flattened_get(se::State& s)
|
||||
{
|
||||
CC_UNUSED bool ok = true;
|
||||
cc::gfx::UniformStorageBuffer *arg1 = (cc::gfx::UniformStorageBuffer *) NULL ;
|
||||
|
||||
arg1 = SE_THIS_OBJECT<cc::gfx::UniformStorageBuffer>(s);
|
||||
if (nullptr == arg1) return true;
|
||||
|
||||
ok &= nativevalue_to_se(arg1->flattened, s.rval(), s.thisObject());
|
||||
|
||||
|
||||
return true;
|
||||
}
|
||||
SE_BIND_PROP_GET(js_cc_gfx_UniformStorageBuffer_flattened_get)
|
||||
|
||||
static bool js_cc_gfx_UniformStorageBuffer_copy(se::State& s)
|
||||
{
|
||||
CC_UNUSED bool ok = true;
|
||||
@@ -10295,6 +10534,12 @@ bool sevalue_to_native(const se::Value &from, cc::gfx::UniformStorageBuffer * to
|
||||
}
|
||||
|
||||
|
||||
json->getProperty("flattened", &field, true);
|
||||
if (!field.isNullOrUndefined()) {
|
||||
ok &= sevalue_to_native(field, &(to->flattened), ctx);
|
||||
}
|
||||
|
||||
|
||||
return ok;
|
||||
}
|
||||
|
||||
@@ -10308,6 +10553,7 @@ bool js_register_cc_gfx_UniformStorageBuffer(se::Object* obj) {
|
||||
cls->defineProperty("name", _SE(js_cc_gfx_UniformStorageBuffer_name_get), _SE(js_cc_gfx_UniformStorageBuffer_name_set));
|
||||
cls->defineProperty("count", _SE(js_cc_gfx_UniformStorageBuffer_count_get), _SE(js_cc_gfx_UniformStorageBuffer_count_set));
|
||||
cls->defineProperty("memoryAccess", _SE(js_cc_gfx_UniformStorageBuffer_memoryAccess_get), _SE(js_cc_gfx_UniformStorageBuffer_memoryAccess_set));
|
||||
cls->defineProperty("flattened", _SE(js_cc_gfx_UniformStorageBuffer_flattened_get), _SE(js_cc_gfx_UniformStorageBuffer_flattened_set));
|
||||
|
||||
cls->defineFunction("copy", _SE(js_cc_gfx_UniformStorageBuffer_copy));
|
||||
|
||||
@@ -10470,6 +10716,40 @@ static bool js_cc_gfx_UniformInputAttachment_count_get(se::State& s)
|
||||
}
|
||||
SE_BIND_PROP_GET(js_cc_gfx_UniformInputAttachment_count_get)
|
||||
|
||||
static bool js_cc_gfx_UniformInputAttachment_flattened_set(se::State& s)
|
||||
{
|
||||
CC_UNUSED bool ok = true;
|
||||
const auto& args = s.args();
|
||||
size_t argc = args.size();
|
||||
cc::gfx::UniformInputAttachment *arg1 = (cc::gfx::UniformInputAttachment *) NULL ;
|
||||
|
||||
arg1 = SE_THIS_OBJECT<cc::gfx::UniformInputAttachment>(s);
|
||||
if (nullptr == arg1) return true;
|
||||
|
||||
ok &= sevalue_to_native(args[0], &arg1->flattened, s.thisObject());
|
||||
SE_PRECONDITION2(ok, false, "Error processing arguments");
|
||||
|
||||
|
||||
|
||||
return true;
|
||||
}
|
||||
SE_BIND_PROP_SET(js_cc_gfx_UniformInputAttachment_flattened_set)
|
||||
|
||||
static bool js_cc_gfx_UniformInputAttachment_flattened_get(se::State& s)
|
||||
{
|
||||
CC_UNUSED bool ok = true;
|
||||
cc::gfx::UniformInputAttachment *arg1 = (cc::gfx::UniformInputAttachment *) NULL ;
|
||||
|
||||
arg1 = SE_THIS_OBJECT<cc::gfx::UniformInputAttachment>(s);
|
||||
if (nullptr == arg1) return true;
|
||||
|
||||
ok &= nativevalue_to_se(arg1->flattened, s.rval(), s.thisObject());
|
||||
|
||||
|
||||
return true;
|
||||
}
|
||||
SE_BIND_PROP_GET(js_cc_gfx_UniformInputAttachment_flattened_get)
|
||||
|
||||
static bool js_cc_gfx_UniformInputAttachment_copy(se::State& s)
|
||||
{
|
||||
CC_UNUSED bool ok = true;
|
||||
@@ -10561,6 +10841,12 @@ bool sevalue_to_native(const se::Value &from, cc::gfx::UniformInputAttachment *
|
||||
}
|
||||
|
||||
|
||||
json->getProperty("flattened", &field, true);
|
||||
if (!field.isNullOrUndefined()) {
|
||||
ok &= sevalue_to_native(field, &(to->flattened), ctx);
|
||||
}
|
||||
|
||||
|
||||
return ok;
|
||||
}
|
||||
|
||||
@@ -10573,6 +10859,7 @@ bool js_register_cc_gfx_UniformInputAttachment(se::Object* obj) {
|
||||
cls->defineProperty("binding", _SE(js_cc_gfx_UniformInputAttachment_binding_get), _SE(js_cc_gfx_UniformInputAttachment_binding_set));
|
||||
cls->defineProperty("name", _SE(js_cc_gfx_UniformInputAttachment_name_get), _SE(js_cc_gfx_UniformInputAttachment_name_set));
|
||||
cls->defineProperty("count", _SE(js_cc_gfx_UniformInputAttachment_count_get), _SE(js_cc_gfx_UniformInputAttachment_count_set));
|
||||
cls->defineProperty("flattened", _SE(js_cc_gfx_UniformInputAttachment_flattened_get), _SE(js_cc_gfx_UniformInputAttachment_flattened_set));
|
||||
|
||||
cls->defineFunction("copy", _SE(js_cc_gfx_UniformInputAttachment_copy));
|
||||
|
||||
|
||||
@@ -1742,6 +1742,38 @@ static bool js_cc_render_RasterPassBuilder_setViewport(se::State& s)
|
||||
}
|
||||
SE_BIND_FUNC(js_cc_render_RasterPassBuilder_setViewport)
|
||||
|
||||
static bool js_cc_render_RasterPassBuilder_setVersion(se::State& s)
|
||||
{
|
||||
CC_UNUSED bool ok = true;
|
||||
const auto& args = s.args();
|
||||
size_t argc = args.size();
|
||||
cc::render::RasterPassBuilder *arg1 = (cc::render::RasterPassBuilder *) NULL ;
|
||||
ccstd::string *arg2 = 0 ;
|
||||
uint64_t arg3 ;
|
||||
ccstd::string temp2 ;
|
||||
|
||||
if(argc != 2) {
|
||||
SE_REPORT_ERROR("wrong number of arguments: %d, was expecting %d", (int)argc, 2);
|
||||
return false;
|
||||
}
|
||||
arg1 = SE_THIS_OBJECT<cc::render::RasterPassBuilder>(s);
|
||||
if (nullptr == arg1) return true;
|
||||
|
||||
ok &= sevalue_to_native(args[0], &temp2, s.thisObject());
|
||||
SE_PRECONDITION2(ok, false, "Error processing arguments");
|
||||
arg2 = &temp2;
|
||||
|
||||
|
||||
ok &= sevalue_to_native(args[1], &arg3, s.thisObject());
|
||||
SE_PRECONDITION2(ok, false, "Error processing arguments");
|
||||
|
||||
(arg1)->setVersion((ccstd::string const &)*arg2,arg3);
|
||||
|
||||
|
||||
return true;
|
||||
}
|
||||
SE_BIND_FUNC(js_cc_render_RasterPassBuilder_setVersion)
|
||||
|
||||
static bool js_cc_render_RasterPassBuilder_addQueue__SWIG_1(se::State& s)
|
||||
{
|
||||
CC_UNUSED bool ok = true;
|
||||
@@ -1799,6 +1831,7 @@ bool js_register_cc_render_RasterPassBuilder(se::Object* obj) {
|
||||
cls->defineFunction("addRasterView", _SE(js_cc_render_RasterPassBuilder_addRasterView));
|
||||
cls->defineFunction("addComputeView", _SE(js_cc_render_RasterPassBuilder_addComputeView));
|
||||
cls->defineFunction("setViewport", _SE(js_cc_render_RasterPassBuilder_setViewport));
|
||||
cls->defineFunction("setVersion", _SE(js_cc_render_RasterPassBuilder_setVersion));
|
||||
cls->defineFunction("addQueue", _SE(js_cc_render_RasterPassBuilder_addQueue));
|
||||
|
||||
|
||||
|
||||
@@ -150,6 +150,13 @@ void Object::cleanup() {
|
||||
SE_ASSERT(NativePtrToObjectMap::size() == 0, "NativePtrToObjectMap should be empty!");
|
||||
}
|
||||
|
||||
Object *Object::createProxyTarget(se::Object *proxy) {
|
||||
SE_ASSERT(proxy->isProxy(), "parameter is not a Proxy object");
|
||||
v8::Local<v8::Object> jsobj = proxy->getProxyTarget().As<v8::Object>();
|
||||
Object *obj = Object::_createJSObject(nullptr, jsobj);
|
||||
return obj;
|
||||
}
|
||||
|
||||
Object *Object::createPlainObject() {
|
||||
v8::Local<v8::Object> jsobj = v8::Object::New(__isolate);
|
||||
Object *obj = _createJSObject(nullptr, jsobj);
|
||||
@@ -564,6 +571,17 @@ bool Object::isTypedArray() const {
|
||||
return const_cast<Object *>(this)->_obj.handle(__isolate)->IsTypedArray();
|
||||
}
|
||||
|
||||
bool Object::isProxy() const {
|
||||
return const_cast<Object *>(this)->_obj.handle(__isolate)->IsProxy();
|
||||
}
|
||||
|
||||
v8::Local<v8::Value> Object::getProxyTarget() const {
|
||||
v8::Local<v8::Value> value = const_cast<Object *>(this)->_obj.handle(__isolate);
|
||||
CC_ASSERTF(value->IsProxy(), "Object is not a Proxy");
|
||||
v8::Proxy *proxy = v8::Proxy::Cast(*value);
|
||||
return proxy->GetTarget();
|
||||
}
|
||||
|
||||
Object::TypedArrayType Object::getTypedArrayType() const {
|
||||
v8::Local<v8::Value> value = const_cast<Object *>(this)->_obj.handle(__isolate);
|
||||
TypedArrayType ret = TypedArrayType::NONE;
|
||||
@@ -794,8 +812,7 @@ bool Object::getArrayLength(uint32_t *length) const {
|
||||
CC_ASSERT(isArray());
|
||||
CC_ASSERT_NOT_NULL(length);
|
||||
auto *thiz = const_cast<Object *>(this);
|
||||
|
||||
v8::Local<v8::Array> v8Arr = v8::Local<v8::Array>::Cast(thiz->_obj.handle(__isolate));
|
||||
auto v8Arr = v8::Local<v8::Array>::Cast(thiz->_obj.handle(__isolate));
|
||||
*length = v8Arr->Length();
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -177,6 +177,13 @@ public:
|
||||
*/
|
||||
static Object *createObjectWithConstructor(se::Object *constructor, const ValueArray &args);
|
||||
|
||||
/**
|
||||
* Gets the Proxy Target object
|
||||
* @param proxy The JavaScript Proxy object.
|
||||
* @return The target JavaScript object of the parameter.
|
||||
*/
|
||||
static Object *createProxyTarget(se::Object *proxy);
|
||||
|
||||
/**
|
||||
* @brief Gets a se::Object from an existing native object pointer.
|
||||
* @param[in] ptr The native object pointer associated with the se::Object
|
||||
@@ -314,6 +321,11 @@ public:
|
||||
*/
|
||||
bool isTypedArray() const;
|
||||
|
||||
/** @brief Tests whether an object is a proxy object.
|
||||
* @return true if object is a proxy object, otherwise false.
|
||||
*/
|
||||
bool isProxy() const;
|
||||
|
||||
/**
|
||||
* @brief Gets the type of a typed array object.
|
||||
* @return The type of a typed array object.
|
||||
@@ -656,6 +668,7 @@ private:
|
||||
~Object() override;
|
||||
|
||||
bool init(Class *cls, v8::Local<v8::Object> obj);
|
||||
v8::Local<v8::Value> getProxyTarget() const;
|
||||
|
||||
Class *_cls{nullptr};
|
||||
ObjectWrap _obj;
|
||||
|
||||
@@ -200,12 +200,20 @@ typename std::enable_if<std::is_pointer<T>::value && std::is_class<typename std:
|
||||
seval_to_std_vector(const se::Value &v, ccstd::vector<T> *ret) { // NOLINT(readability-identifier-naming)
|
||||
CC_ASSERT_NOT_NULL(ret);
|
||||
CC_ASSERT(v.isObject());
|
||||
se::Object *obj = v.toObject();
|
||||
CC_ASSERT(obj->isArray());
|
||||
se::Object *arrayObj= v.toObject();
|
||||
se::Object *tempArray = nullptr;
|
||||
if(arrayObj->isArray()) {
|
||||
tempArray = arrayObj;
|
||||
tempArray->incRef();
|
||||
}else {
|
||||
tempArray = se::Object::createProxyTarget(arrayObj);
|
||||
}
|
||||
se::HandleObject array(tempArray);
|
||||
CC_ASSERT(array->isArray());
|
||||
|
||||
bool ok = true;
|
||||
uint32_t len = 0;
|
||||
ok = obj->getArrayLength(&len);
|
||||
ok = array->getArrayLength(&len);
|
||||
if (!ok) {
|
||||
ret->clear();
|
||||
return false;
|
||||
@@ -215,7 +223,7 @@ seval_to_std_vector(const se::Value &v, ccstd::vector<T> *ret) { // NOLINT(reada
|
||||
|
||||
se::Value tmp;
|
||||
for (uint32_t i = 0; i < len; ++i) {
|
||||
ok = obj->getArrayElement(i, &tmp);
|
||||
ok = array->getArrayElement(i, &tmp);
|
||||
if (!ok) {
|
||||
ret->clear();
|
||||
return false;
|
||||
@@ -240,12 +248,20 @@ typename std::enable_if<!std::is_pointer<T>::value, bool>::type
|
||||
seval_to_std_vector(const se::Value &v, ccstd::vector<T> *ret) { // NOLINT(readability-identifier-naming)
|
||||
CC_ASSERT_NOT_NULL(ret);
|
||||
CC_ASSERT(v.isObject());
|
||||
se::Object *obj = v.toObject();
|
||||
CC_ASSERT(obj->isArray());
|
||||
se::Object *arrayObj= v.toObject();
|
||||
se::Object *tempArray = nullptr;
|
||||
if(arrayObj->isArray()) {
|
||||
tempArray = arrayObj;
|
||||
tempArray->incRef();
|
||||
}else {
|
||||
tempArray = se::Object::createProxyTarget(arrayObj);
|
||||
}
|
||||
se::HandleObject array(tempArray);
|
||||
CC_ASSERT(array->isArray());
|
||||
|
||||
bool ok = true;
|
||||
uint32_t len = 0;
|
||||
ok = obj->getArrayLength(&len);
|
||||
ok = array->getArrayLength(&len);
|
||||
if (!ok) {
|
||||
ret->clear();
|
||||
return false;
|
||||
@@ -255,7 +271,7 @@ seval_to_std_vector(const se::Value &v, ccstd::vector<T> *ret) { // NOLINT(reada
|
||||
|
||||
se::Value tmp;
|
||||
for (uint32_t i = 0; i < len; ++i) {
|
||||
ok = obj->getArrayElement(i, &tmp);
|
||||
ok = array->getArrayElement(i, &tmp);
|
||||
if (!ok) {
|
||||
ret->clear();
|
||||
return false;
|
||||
@@ -709,8 +725,16 @@ bool sevalue_to_native(const se::Value &from, ccstd::vector<T> *to, se::Object *
|
||||
}
|
||||
|
||||
CC_ASSERT(from.toObject());
|
||||
se::Object *array = from.toObject();
|
||||
|
||||
se::Object *arrayObj= from.toObject();
|
||||
se::Object *tempArray = nullptr;
|
||||
if(arrayObj->isArray()) {
|
||||
tempArray = arrayObj;
|
||||
tempArray->incRef();
|
||||
}else {
|
||||
tempArray = se::Object::createProxyTarget(arrayObj);
|
||||
}
|
||||
se::HandleObject array(tempArray);
|
||||
|
||||
if (array->isArray()) {
|
||||
uint32_t len = 0;
|
||||
array->getArrayLength(&len);
|
||||
|
||||
@@ -648,7 +648,7 @@ int aabbFrustum(const AABB &aabb, const Frustum &frustum) {
|
||||
int aabbFrustumCompletelyInside(const AABB &aabb, const Frustum &frustum) {
|
||||
for (const auto &plane : frustum.planes) {
|
||||
// frustum plane normal points to the inside
|
||||
if (aabbPlane(aabb, *plane) == 0) {
|
||||
if (aabbPlane(aabb, *plane) != 0) {
|
||||
return 0;
|
||||
}
|
||||
} // completely inside
|
||||
|
||||
@@ -266,7 +266,7 @@ void Engine::tick() {
|
||||
|
||||
// iOS/macOS use its own fps limitation algorithm.
|
||||
// Windows for Editor should not sleep,because Editor call tick function synchronously
|
||||
#if (CC_PLATFORM == CC_PLATFORM_ANDROID || (CC_PLATFORM == CC_PLATFORM_WINDOWS && !defined(CC_EDITOR)) || CC_PLATFORM == CC_PLATFORM_OHOS) || (defined(CC_SERVER_MODE) && (CC_PLATFORM == CC_PLATFORM_MAC_OSX))
|
||||
#if (CC_PLATFORM == CC_PLATFORM_ANDROID || (CC_PLATFORM == CC_PLATFORM_WINDOWS && !CC_EDITOR) || CC_PLATFORM == CC_PLATFORM_OHOS) || (defined(CC_SERVER_MODE) && (CC_PLATFORM == CC_PLATFORM_MAC_OSX))
|
||||
if (dtNS < static_cast<double>(_prefererredNanosecondsPerFrame)) {
|
||||
CC_PROFILE(EngineSleep);
|
||||
std::this_thread::sleep_for(
|
||||
|
||||
@@ -37,47 +37,6 @@ namespace cc {
|
||||
|
||||
namespace {
|
||||
|
||||
ccstd::string mapDefine(const IDefineInfo &info, const ccstd::optional<MacroRecord::mapped_type> &def) {
|
||||
if (info.type == "boolean") {
|
||||
return def.has_value() ? (macroRecordAsBool(def.value()) ? "1" : "0") : "0";
|
||||
}
|
||||
if (info.type == "string") {
|
||||
return def.has_value() ? macroRecordAsString(def.value()) : info.options.value()[0];
|
||||
}
|
||||
if (info.type == "number") {
|
||||
return def.has_value() ? macroRecordAsString(def.value()) : std::to_string(info.range.value()[0]);
|
||||
}
|
||||
CC_LOG_WARNING("unknown define type '%s', name: %s", info.type.c_str(), info.name.c_str());
|
||||
return "-1"; // should neven happen
|
||||
}
|
||||
|
||||
ccstd::vector<IMacroInfo> prepareDefines(const MacroRecord &records, const ccstd::vector<IDefineRecord> &defList) {
|
||||
ccstd::vector<IMacroInfo> macros{};
|
||||
for (const auto &tmp : defList) {
|
||||
const auto &name = tmp.name;
|
||||
auto it = records.find(name);
|
||||
auto value = mapDefine(tmp, it == records.end() ? ccstd::nullopt : ccstd::optional<MacroValue>(it->second));
|
||||
bool isDefault = it == records.end() || (ccstd::holds_alternative<ccstd::string>(it->second) && ccstd::get<ccstd::string>(it->second) == "0");
|
||||
macros.emplace_back();
|
||||
auto &info = macros.back();
|
||||
info.name = name;
|
||||
info.value = value;
|
||||
info.isDefault = isDefault;
|
||||
}
|
||||
return macros;
|
||||
}
|
||||
|
||||
ccstd::string getShaderInstanceName(const ccstd::string &name, const ccstd::vector<IMacroInfo> ¯os) {
|
||||
std::stringstream ret;
|
||||
ret << name;
|
||||
for (const auto &cur : macros) {
|
||||
if (!cur.isDefault) {
|
||||
ret << "|" << cur.name << cur.value;
|
||||
}
|
||||
}
|
||||
return ret.str();
|
||||
}
|
||||
|
||||
void insertBuiltinBindings(const IProgramInfo &tmpl, ITemplateInfo &tmplInfo, const pipeline::DescriptorSetLayoutInfos &source,
|
||||
const ccstd::string &type, ccstd::vector<gfx::DescriptorSetLayoutBinding> *outBindings) {
|
||||
CC_ASSERT(type == "locals" || type == "globals");
|
||||
@@ -144,32 +103,6 @@ int32_t getSize(const IBlockInfo &block) {
|
||||
return s;
|
||||
}
|
||||
|
||||
bool dependencyCheck(const ccstd::vector<ccstd::string> &dependencies, const MacroRecord &defines) {
|
||||
for (const auto &d : dependencies) { // NOLINT(readability-use-anyofallof)
|
||||
if (d[0] == '!') { // negative dependency
|
||||
if (defines.find(d.substr(1)) != defines.end()) {
|
||||
return false;
|
||||
}
|
||||
} else if (defines.count(d) == 0 ? true : !macroRecordAsBool(defines.at(d))) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
ccstd::vector<gfx::Attribute> getActiveAttributes(const IProgramInfo &tmpl, const ITemplateInfo &tmplInfo, const MacroRecord &defines) {
|
||||
ccstd::vector<gfx::Attribute> out{};
|
||||
const auto &attributes = tmpl.attributes;
|
||||
const auto &gfxAttributes = tmplInfo.gfxAttributes;
|
||||
for (auto i = 0; i < attributes.size(); i++) {
|
||||
if (!dependencyCheck(attributes[i].defines, defines)) {
|
||||
continue;
|
||||
}
|
||||
out.emplace_back(gfxAttributes[i]);
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
const char *getDeviceShaderVersion(const gfx::Device *device) {
|
||||
@@ -540,7 +473,7 @@ gfx::Shader *ProgramLib::getGFXShader(gfx::Device *device, const ccstd::string &
|
||||
tmplInfo.pipelineLayout = device->createPipelineLayout(gfx::PipelineLayoutInfo{tmplInfo.setLayouts.get()});
|
||||
}
|
||||
|
||||
ccstd::vector<IMacroInfo> macroArray = prepareDefines(defines, tmpl.defines);
|
||||
ccstd::vector<IMacroInfo> macroArray = render::prepareDefines(defines, tmpl.defines);
|
||||
std::stringstream ss;
|
||||
ss << std::endl;
|
||||
for (const auto &m : macroArray) {
|
||||
@@ -559,9 +492,9 @@ gfx::Shader *ProgramLib::getGFXShader(gfx::Device *device, const ccstd::string &
|
||||
tmplInfo.shaderInfo.stages[1].source = prefix + src->frag;
|
||||
|
||||
// strip out the active attributes only, instancing depend on this
|
||||
tmplInfo.shaderInfo.attributes = getActiveAttributes(tmpl, tmplInfo, defines);
|
||||
tmplInfo.shaderInfo.attributes = render::getActiveAttributes(tmpl, tmplInfo.gfxAttributes, defines);
|
||||
|
||||
tmplInfo.shaderInfo.name = getShaderInstanceName(name, macroArray);
|
||||
tmplInfo.shaderInfo.name = render::getShaderInstanceName(name, macroArray);
|
||||
|
||||
auto *shader = device->createShader(tmplInfo.shaderInfo);
|
||||
_cache[key] = shader;
|
||||
|
||||
@@ -163,6 +163,91 @@ ccstd::string getVariantKey(const IProgramInfo &tmpl, const MacroRecord &defines
|
||||
return ret;
|
||||
}
|
||||
|
||||
namespace {
|
||||
|
||||
ccstd::string mapDefine(const IDefineInfo &info, const ccstd::optional<MacroRecord::mapped_type> &def) {
|
||||
if (info.type == "boolean") {
|
||||
return def.has_value() ? (macroRecordAsBool(def.value()) ? "1" : "0") : "0";
|
||||
}
|
||||
if (info.type == "string") {
|
||||
return def.has_value() ? macroRecordAsString(def.value()) : info.options.value()[0];
|
||||
}
|
||||
if (info.type == "number") {
|
||||
return def.has_value() ? macroRecordAsString(def.value()) : std::to_string(info.range.value()[0]);
|
||||
}
|
||||
CC_LOG_WARNING("unknown define type '%s', name: %s", info.type.c_str(), info.name.c_str());
|
||||
return "-1"; // should neven happen
|
||||
}
|
||||
|
||||
bool dependencyCheck(const ccstd::vector<ccstd::string> &dependencies, const MacroRecord &defines) {
|
||||
for (const auto &d : dependencies) { // NOLINT(readability-use-anyofallof)
|
||||
if (d[0] == '!') { // negative dependency
|
||||
if (defines.find(d.substr(1)) != defines.end()) {
|
||||
return false;
|
||||
}
|
||||
} else if (defines.count(d) == 0 ? true : !macroRecordAsBool(defines.at(d))) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
template <class Vector>
|
||||
ccstd::vector<gfx::Attribute> getActiveAttributesImpl(
|
||||
const IProgramInfo &tmpl,
|
||||
const Vector &gfxAttributes, const MacroRecord &defines) {
|
||||
ccstd::vector<gfx::Attribute> out{};
|
||||
const auto &attributes = tmpl.attributes;
|
||||
for (auto i = 0; i < attributes.size(); i++) {
|
||||
if (!dependencyCheck(attributes[i].defines, defines)) {
|
||||
continue;
|
||||
}
|
||||
out.emplace_back(gfxAttributes[i]);
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
ccstd::vector<IMacroInfo> prepareDefines(const MacroRecord &records, const ccstd::vector<IDefineRecord> &defList) {
|
||||
ccstd::vector<IMacroInfo> macros{};
|
||||
for (const auto &tmp : defList) {
|
||||
const auto &name = tmp.name;
|
||||
auto it = records.find(name);
|
||||
auto value = mapDefine(tmp, it == records.end() ? ccstd::nullopt : ccstd::optional<MacroValue>(it->second));
|
||||
bool isDefault = it == records.end() || (ccstd::holds_alternative<ccstd::string>(it->second) && ccstd::get<ccstd::string>(it->second) == "0");
|
||||
macros.emplace_back();
|
||||
auto &info = macros.back();
|
||||
info.name = name;
|
||||
info.value = value;
|
||||
info.isDefault = isDefault;
|
||||
}
|
||||
return macros;
|
||||
}
|
||||
|
||||
ccstd::vector<gfx::Attribute> getActiveAttributes(
|
||||
const IProgramInfo &tmpl,
|
||||
const ccstd::vector<gfx::Attribute> &gfxAttributes, const MacroRecord &defines) {
|
||||
return getActiveAttributesImpl(tmpl, gfxAttributes, defines);
|
||||
}
|
||||
|
||||
ccstd::vector<gfx::Attribute> getActiveAttributes(
|
||||
const IProgramInfo &tmpl,
|
||||
const ccstd::pmr::vector<gfx::Attribute> &gfxAttributes, const MacroRecord &defines) {
|
||||
return getActiveAttributesImpl(tmpl, gfxAttributes, defines);
|
||||
}
|
||||
|
||||
ccstd::string getShaderInstanceName(const ccstd::string &name, const ccstd::vector<IMacroInfo> ¯os) {
|
||||
std::stringstream ret;
|
||||
ret << name;
|
||||
for (const auto &cur : macros) {
|
||||
if (!cur.isDefault) {
|
||||
ret << "|" << cur.name << cur.value;
|
||||
}
|
||||
}
|
||||
return ret.str();
|
||||
}
|
||||
|
||||
} // namespace render
|
||||
|
||||
} // namespace cc
|
||||
|
||||
@@ -34,6 +34,19 @@ void populateMacros(IProgramInfo& tmpl);
|
||||
ccstd::unordered_map<ccstd::string, uint32_t> genHandles(const IProgramInfo& tmpl);
|
||||
ccstd::unordered_map<ccstd::string, uint32_t> genHandles(const gfx::ShaderInfo& tmpl);
|
||||
ccstd::string getVariantKey(const IProgramInfo& tmpl, const MacroRecord& defines);
|
||||
ccstd::vector<IMacroInfo> prepareDefines(
|
||||
const MacroRecord& records, const ccstd::vector<IDefineRecord>& defList);
|
||||
|
||||
ccstd::vector<gfx::Attribute> getActiveAttributes(
|
||||
const IProgramInfo& tmpl,
|
||||
const ccstd::vector<gfx::Attribute>& gfxAttributes, const MacroRecord& defines);
|
||||
|
||||
ccstd::vector<gfx::Attribute> getActiveAttributes(
|
||||
const IProgramInfo& tmpl,
|
||||
const ccstd::pmr::vector<gfx::Attribute>& gfxAttributes, const MacroRecord& defines);
|
||||
|
||||
ccstd::string getShaderInstanceName(
|
||||
const ccstd::string& name, const ccstd::vector<IMacroInfo>& macros);
|
||||
|
||||
} // namespace render
|
||||
|
||||
|
||||
@@ -1117,6 +1117,7 @@ struct UniformBlock {
|
||||
ccstd::string name;
|
||||
UniformList members;
|
||||
uint32_t count{0};
|
||||
uint32_t flattened{0};
|
||||
|
||||
EXPOSE_COPY_FN(UniformBlock)
|
||||
};
|
||||
@@ -1129,6 +1130,7 @@ struct UniformSamplerTexture {
|
||||
ccstd::string name;
|
||||
Type type{Type::UNKNOWN};
|
||||
uint32_t count{0};
|
||||
uint32_t flattened{0};
|
||||
|
||||
EXPOSE_COPY_FN(UniformSamplerTexture)
|
||||
};
|
||||
@@ -1140,6 +1142,7 @@ struct UniformSampler {
|
||||
uint32_t binding{0};
|
||||
ccstd::string name;
|
||||
uint32_t count{0};
|
||||
uint32_t flattened{0};
|
||||
|
||||
EXPOSE_COPY_FN(UniformSampler)
|
||||
};
|
||||
@@ -1152,6 +1155,7 @@ struct UniformTexture {
|
||||
ccstd::string name;
|
||||
Type type{Type::UNKNOWN};
|
||||
uint32_t count{0};
|
||||
uint32_t flattened{0};
|
||||
|
||||
EXPOSE_COPY_FN(UniformTexture)
|
||||
};
|
||||
@@ -1165,6 +1169,7 @@ struct UniformStorageImage {
|
||||
Type type{Type::UNKNOWN};
|
||||
uint32_t count{0};
|
||||
MemoryAccess memoryAccess{MemoryAccessBit::READ_WRITE};
|
||||
uint32_t flattened{0};
|
||||
|
||||
EXPOSE_COPY_FN(UniformStorageImage)
|
||||
};
|
||||
@@ -1177,6 +1182,7 @@ struct UniformStorageBuffer {
|
||||
ccstd::string name;
|
||||
uint32_t count{0};
|
||||
MemoryAccess memoryAccess{MemoryAccessBit::READ_WRITE};
|
||||
uint32_t flattened{0};
|
||||
|
||||
EXPOSE_COPY_FN(UniformStorageBuffer)
|
||||
};
|
||||
@@ -1188,6 +1194,7 @@ struct UniformInputAttachment {
|
||||
uint32_t binding{0};
|
||||
ccstd::string name;
|
||||
uint32_t count{0};
|
||||
uint32_t flattened{0};
|
||||
|
||||
EXPOSE_COPY_FN(UniformInputAttachment)
|
||||
};
|
||||
|
||||
@@ -105,31 +105,40 @@ void shadowCulling(const RenderPipeline *pipeline, const scene::Camera *camera,
|
||||
|
||||
layer->clearShadowObjects();
|
||||
|
||||
for (size_t i = 0; i < csmLayers->getLayerObjects().size(); ++i) {
|
||||
const auto *model = csmLayers->getLayerObjects()[i].model;
|
||||
if (csmLayers->getLayerObjects().empty()) return;
|
||||
|
||||
for (auto it = csmLayers->getLayerObjects().begin(); it != csmLayers->getLayerObjects().end();) {
|
||||
const auto *model = it->model;
|
||||
if (!model || !model->isEnabled() || !model->getNode()) {
|
||||
it = csmLayers->getLayerObjects().erase(it);
|
||||
continue;
|
||||
}
|
||||
const auto *node = model->getNode();
|
||||
if (((visibility & node->getLayer()) != node->getLayer()) && !(visibility & static_cast<uint32_t>(model->getVisFlags()))) {
|
||||
it = csmLayers->getLayerObjects().erase(it);
|
||||
continue;
|
||||
}
|
||||
if (!model->getWorldBounds() || !model->isCastShadow()) {
|
||||
it = csmLayers->getLayerObjects().erase(it);
|
||||
continue;
|
||||
}
|
||||
|
||||
// frustum culling
|
||||
const bool accurate = model->getWorldBounds()->aabbFrustum(layer->getValidFrustum());
|
||||
if (!accurate) {
|
||||
++it;
|
||||
continue;
|
||||
}
|
||||
layer->addShadowObject(genRenderObject(model, camera));
|
||||
if (layer->getLevel() < static_cast<uint32_t>(mainLight->getCSMLevel())) {
|
||||
if (mainLight->getCSMOptimizationMode() == scene::CSMOptimizationMode::REMOVE_DUPLICATES &&
|
||||
aabbFrustumCompletelyInside(*model->getWorldBounds(), layer->getValidFrustum())) {
|
||||
csmLayers->getLayerObjects().erase(csmLayers->getLayerObjects().begin() + static_cast<uint32_t>(i));
|
||||
i--;
|
||||
it = csmLayers->getLayerObjects().erase(it);
|
||||
} else {
|
||||
++it;
|
||||
}
|
||||
} else {
|
||||
++it;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -199,6 +199,8 @@ inline void load(InputArchive& ar, DescriptorBlockData& v) {
|
||||
inline void save(OutputArchive& ar, const DescriptorSetLayoutData& v) {
|
||||
save(ar, v.slot);
|
||||
save(ar, v.capacity);
|
||||
save(ar, v.uniformBlockCapacity);
|
||||
save(ar, v.samplerTextureCapacity);
|
||||
save(ar, v.descriptorBlocks);
|
||||
save(ar, v.uniformBlocks);
|
||||
save(ar, v.bindingMap);
|
||||
@@ -207,6 +209,8 @@ inline void save(OutputArchive& ar, const DescriptorSetLayoutData& v) {
|
||||
inline void load(InputArchive& ar, DescriptorSetLayoutData& v) {
|
||||
load(ar, v.slot);
|
||||
load(ar, v.capacity);
|
||||
load(ar, v.uniformBlockCapacity);
|
||||
load(ar, v.samplerTextureCapacity);
|
||||
load(ar, v.descriptorBlocks);
|
||||
load(ar, v.uniformBlocks);
|
||||
load(ar, v.bindingMap);
|
||||
|
||||
@@ -146,6 +146,8 @@ DescriptorSetLayoutData::DescriptorSetLayoutData(uint32_t slotIn, uint32_t capac
|
||||
DescriptorSetLayoutData::DescriptorSetLayoutData(DescriptorSetLayoutData&& rhs, const allocator_type& alloc)
|
||||
: slot(rhs.slot),
|
||||
capacity(rhs.capacity),
|
||||
uniformBlockCapacity(rhs.uniformBlockCapacity),
|
||||
samplerTextureCapacity(rhs.samplerTextureCapacity),
|
||||
descriptorBlocks(std::move(rhs.descriptorBlocks), alloc),
|
||||
uniformBlocks(std::move(rhs.uniformBlocks), alloc),
|
||||
bindingMap(std::move(rhs.bindingMap), alloc) {}
|
||||
|
||||
@@ -365,6 +365,8 @@ struct DescriptorSetLayoutData {
|
||||
|
||||
uint32_t slot{0xFFFFFFFF};
|
||||
uint32_t capacity{0};
|
||||
uint32_t uniformBlockCapacity{0};
|
||||
uint32_t samplerTextureCapacity{0};
|
||||
ccstd::pmr::vector<DescriptorBlockData> descriptorBlocks;
|
||||
ccstd::pmr::unordered_map<NameLocalID, gfx::UniformBlock> uniformBlocks;
|
||||
PmrFlatMap<NameLocalID, uint32_t> bindingMap;
|
||||
|
||||
@@ -28,6 +28,7 @@
|
||||
#include "LayoutGraphSerialization.h"
|
||||
#include "NativePipelineTypes.h"
|
||||
#include "RenderInterfaceTypes.h"
|
||||
#include "RenderingModule.h"
|
||||
#include "details/GslUtils.h"
|
||||
#include "pipeline/custom/LayoutGraphTypes.h"
|
||||
#include "pipeline/custom/details/Pmr.h"
|
||||
@@ -70,6 +71,13 @@ Pipeline* Factory::createPipeline() {
|
||||
return ccnew NativePipeline(boost::container::pmr::get_default_resource());
|
||||
}
|
||||
|
||||
ProgramLibrary* getProgramLibrary() {
|
||||
if (!sRenderingModule) {
|
||||
return nullptr;
|
||||
}
|
||||
return sRenderingModule->programLibrary.get();
|
||||
}
|
||||
|
||||
} // namespace render
|
||||
|
||||
} // namespace cc
|
||||
|
||||
@@ -30,16 +30,14 @@
|
||||
// clang-format off
|
||||
#pragma once
|
||||
#include "cocos/base/std/variant.h"
|
||||
#include "cocos/renderer/core/ProgramLib.h"
|
||||
#include "cocos/renderer/pipeline/custom/LayoutGraphFwd.h"
|
||||
#include "cocos/renderer/pipeline/custom/RenderInterfaceFwd.h"
|
||||
#include "cocos/renderer/pipeline/custom/PrivateFwd.h"
|
||||
|
||||
namespace cc {
|
||||
|
||||
namespace render {
|
||||
|
||||
struct ProgramInfo;
|
||||
struct ProgramHost;
|
||||
struct ProgramGroup;
|
||||
|
||||
} // namespace render
|
||||
|
||||
@@ -32,7 +32,6 @@
|
||||
#include "cocos/base/std/variant.h"
|
||||
#include "cocos/renderer/pipeline/InstancedBuffer.h"
|
||||
#include "cocos/renderer/pipeline/custom/NativeFwd.h"
|
||||
#include "cocos/renderer/pipeline/custom/PrivateFwd.h"
|
||||
#include "cocos/renderer/pipeline/custom/RenderGraphFwd.h"
|
||||
|
||||
namespace cc {
|
||||
|
||||
@@ -38,7 +38,6 @@
|
||||
#include "cocos/renderer/pipeline/InstancedBuffer.h"
|
||||
#include "cocos/renderer/pipeline/custom/NativePipelineFwd.h"
|
||||
#include "cocos/renderer/pipeline/custom/NativeTypes.h"
|
||||
#include "cocos/renderer/pipeline/custom/PrivateTypes.h"
|
||||
#include "cocos/renderer/pipeline/custom/RenderGraphTypes.h"
|
||||
#include "cocos/renderer/pipeline/custom/details/Map.h"
|
||||
#include "cocos/renderer/pipeline/custom/details/Set.h"
|
||||
@@ -131,6 +130,7 @@ public:
|
||||
void addComputeView(const ccstd::string &name, const ComputeView &view) override;
|
||||
RasterQueueBuilder *addQueue(QueueHint hint) override;
|
||||
void setViewport(const gfx::Viewport &viewport) override;
|
||||
void setVersion(const ccstd::string &name, uint64_t version) override;
|
||||
|
||||
RenderGraph* renderGraph{nullptr};
|
||||
const LayoutGraphData* layoutGraph{nullptr};
|
||||
@@ -525,13 +525,13 @@ public:
|
||||
|
||||
void addEffect(EffectAsset *effectAsset) override;
|
||||
void precompileEffect(gfx::Device *device, EffectAsset *effectAsset) override;
|
||||
ccstd::string getKey(uint32_t phaseID, const ccstd::pmr::string &programName, const MacroRecord &defines) const override;
|
||||
const gfx::PipelineLayout &getPipelineLayout(gfx::Device *device, uint32_t phaseID, const ccstd::pmr::string &programName) override;
|
||||
ccstd::string getKey(uint32_t phaseID, const ccstd::string &programName, const MacroRecord &defines) const override;
|
||||
IntrusivePtr<gfx::PipelineLayout> getPipelineLayout(gfx::Device *device, uint32_t phaseID, const ccstd::string &programName) override;
|
||||
const gfx::DescriptorSetLayout &getMaterialDescriptorSetLayout(gfx::Device *device, uint32_t phaseID, const ccstd::pmr::string &programName) override;
|
||||
const gfx::DescriptorSetLayout &getLocalDescriptorSetLayout(gfx::Device *device, uint32_t phaseID, const ccstd::pmr::string &programName) override;
|
||||
const IProgramInfo &getProgramInfo(uint32_t phaseID, const ccstd::pmr::string &programName) const override;
|
||||
const gfx::ShaderInfo &getShaderInfo(uint32_t phaseID, const ccstd::pmr::string &programName) const override;
|
||||
ProgramProxy *getProgramVariant(gfx::Device *device, uint32_t phaseID, const ccstd::string &name, const MacroRecord &defines, const ccstd::pmr::string *key) const override;
|
||||
ProgramProxy *getProgramVariant(gfx::Device *device, uint32_t phaseID, const ccstd::string &name, MacroRecord &defines, const ccstd::pmr::string *key) override;
|
||||
const ccstd::pmr::vector<unsigned> &getBlockSizes(uint32_t phaseID, const ccstd::pmr::string &programName) const override;
|
||||
const Record<ccstd::string, uint32_t> &getHandleMap(uint32_t phaseID, const ccstd::pmr::string &programName) const override;
|
||||
uint32_t getProgramID(uint32_t phaseID, const ccstd::pmr::string &programName) override;
|
||||
@@ -548,6 +548,7 @@ public:
|
||||
bool fixedLocal{true};
|
||||
IntrusivePtr<gfx::DescriptorSetLayout> emptyDescriptorSetLayout;
|
||||
IntrusivePtr<gfx::PipelineLayout> emptyPipelineLayout;
|
||||
PipelineRuntime* pipeline{nullptr};
|
||||
};
|
||||
|
||||
class NativeRenderingModule final : public RenderingModule {
|
||||
|
||||
@@ -31,6 +31,7 @@
|
||||
#include "NativePipelineTypes.h"
|
||||
#include "ProgramLib.h"
|
||||
#include "ProgramUtils.h"
|
||||
#include "base/Ptr.h"
|
||||
#include "cocos/base/Log.h"
|
||||
#include "cocos/core/assets/EffectAsset.h"
|
||||
#include "cocos/renderer/core/ProgramUtils.h"
|
||||
@@ -39,7 +40,10 @@
|
||||
#include "cocos/renderer/pipeline/custom/LayoutGraphGraphs.h"
|
||||
#include "cocos/renderer/pipeline/custom/LayoutGraphTypes.h"
|
||||
#include "gfx-base/GFXDescriptorSetLayout.h"
|
||||
#include "gfx-base/GFXShader.h"
|
||||
#include "pipeline/custom/NativePipelineFwd.h"
|
||||
#include "pipeline/custom/PrivateTypes.h"
|
||||
#include "pipeline/custom/RenderCommonTypes.h"
|
||||
#include "pipeline/custom/details/GslUtils.h"
|
||||
|
||||
namespace cc {
|
||||
@@ -556,6 +560,137 @@ void populateLocalShaderInfo(
|
||||
}
|
||||
}
|
||||
|
||||
uint32_t getIDescriptorSetLayoutInfoUniformBlockCapacity(const pipeline::DescriptorSetLayoutInfos &info) {
|
||||
uint32_t capacity = 0;
|
||||
for (const auto &binding : info.bindings) {
|
||||
if (binding.descriptorType == gfx::DescriptorType::UNIFORM_BUFFER ||
|
||||
binding.descriptorType == gfx::DescriptorType::DYNAMIC_UNIFORM_BUFFER) {
|
||||
capacity += binding.count;
|
||||
}
|
||||
}
|
||||
return capacity;
|
||||
}
|
||||
|
||||
uint32_t getIDescriptorSetLayoutInfoSamplerTextureCapacity(const pipeline::DescriptorSetLayoutInfos &info) {
|
||||
uint32_t capacity = 0;
|
||||
for (const auto &binding : info.bindings) {
|
||||
if (binding.descriptorType != gfx::DescriptorType::UNIFORM_BUFFER &&
|
||||
binding.descriptorType != gfx::DescriptorType::DYNAMIC_UNIFORM_BUFFER) {
|
||||
capacity += binding.count;
|
||||
}
|
||||
}
|
||||
return capacity;
|
||||
}
|
||||
|
||||
void setFlattenedUniformBlockBinding(
|
||||
const std::array<uint32_t, 4> &setOffsets,
|
||||
ccstd::vector<gfx::UniformBlock> &descriptors) {
|
||||
for (auto &d : descriptors) {
|
||||
d.flattened = setOffsets[d.set] + d.binding;
|
||||
}
|
||||
}
|
||||
|
||||
template <class Desc>
|
||||
void setFlattenedSamplerTextureBinding(
|
||||
const std::array<uint32_t, 4> &setOffsets,
|
||||
const std::array<uint32_t, 4> &uniformBlockCapacities,
|
||||
ccstd::vector<Desc> &descriptors) {
|
||||
for (auto &d : descriptors) {
|
||||
d.flattened = setOffsets[d.set] + d.binding - uniformBlockCapacities[d.set];
|
||||
}
|
||||
}
|
||||
|
||||
void calculateFlattenedBinding(
|
||||
const std::array<const DescriptorSetLayoutData *, 4> &descriptorSets,
|
||||
const pipeline::DescriptorSetLayoutInfos *fixedInstanceDescriptorSetLayout,
|
||||
gfx::ShaderInfo &shaderInfo) {
|
||||
// Descriptors of UniformBlock starts from 0, and Descriptors of SamplerTexture starts from the end of UniformBlock.
|
||||
std::array<uint32_t, 4> uniformBlockCapacities{};
|
||||
{
|
||||
const auto passCapacity =
|
||||
descriptorSets[static_cast<size_t>(UpdateFrequency::PER_PASS)]
|
||||
? descriptorSets[static_cast<size_t>(UpdateFrequency::PER_PASS)]->uniformBlockCapacity
|
||||
: 0;
|
||||
const auto phaseCapacity =
|
||||
descriptorSets[static_cast<size_t>(UpdateFrequency::PER_PHASE)]
|
||||
? descriptorSets[static_cast<size_t>(UpdateFrequency::PER_PHASE)]->uniformBlockCapacity
|
||||
: 0;
|
||||
const auto batchCapacity =
|
||||
descriptorSets[static_cast<size_t>(UpdateFrequency::PER_BATCH)]
|
||||
? descriptorSets[static_cast<size_t>(UpdateFrequency::PER_BATCH)]->uniformBlockCapacity
|
||||
: 0;
|
||||
const auto instanceCapacity =
|
||||
fixedInstanceDescriptorSetLayout
|
||||
? getIDescriptorSetLayoutInfoUniformBlockCapacity(*fixedInstanceDescriptorSetLayout)
|
||||
: (descriptorSets[static_cast<size_t>(UpdateFrequency::PER_INSTANCE)]
|
||||
? descriptorSets[static_cast<size_t>(UpdateFrequency::PER_INSTANCE)]->uniformBlockCapacity
|
||||
: 0);
|
||||
|
||||
// update uniform block capacities
|
||||
uniformBlockCapacities[setIndex(UpdateFrequency::PER_PASS)] = passCapacity;
|
||||
uniformBlockCapacities[setIndex(UpdateFrequency::PER_PHASE)] = phaseCapacity;
|
||||
uniformBlockCapacities[setIndex(UpdateFrequency::PER_BATCH)] = batchCapacity;
|
||||
uniformBlockCapacities[setIndex(UpdateFrequency::PER_INSTANCE)] = instanceCapacity;
|
||||
|
||||
// calculate uniform block offsets
|
||||
const auto passOffset = 0;
|
||||
const auto phaseOffset = passOffset + passCapacity;
|
||||
const auto instanceOffset = phaseOffset + phaseCapacity;
|
||||
const auto batchOffset = instanceOffset + instanceCapacity;
|
||||
|
||||
// save uniform block offsets by set index
|
||||
std::array<uint32_t, 4> uniformBlockOffsets{};
|
||||
uniformBlockOffsets[setIndex(UpdateFrequency::PER_PASS)] = passOffset;
|
||||
uniformBlockOffsets[setIndex(UpdateFrequency::PER_PHASE)] = phaseOffset;
|
||||
uniformBlockOffsets[setIndex(UpdateFrequency::PER_BATCH)] = batchOffset;
|
||||
uniformBlockOffsets[setIndex(UpdateFrequency::PER_INSTANCE)] = instanceOffset;
|
||||
|
||||
// update flattened uniform block binding
|
||||
setFlattenedUniformBlockBinding(uniformBlockOffsets, shaderInfo.blocks);
|
||||
}
|
||||
{
|
||||
// calculate sampler texture capacities
|
||||
const auto passCapacity =
|
||||
descriptorSets[static_cast<size_t>(UpdateFrequency::PER_PASS)]
|
||||
? descriptorSets[static_cast<size_t>(UpdateFrequency::PER_PASS)]->samplerTextureCapacity
|
||||
: 0;
|
||||
const auto phaseCapacity =
|
||||
descriptorSets[static_cast<size_t>(UpdateFrequency::PER_PHASE)]
|
||||
? descriptorSets[static_cast<size_t>(UpdateFrequency::PER_PHASE)]->samplerTextureCapacity
|
||||
: 0;
|
||||
const auto batchCapacity =
|
||||
descriptorSets[static_cast<size_t>(UpdateFrequency::PER_BATCH)]
|
||||
? descriptorSets[static_cast<size_t>(UpdateFrequency::PER_BATCH)]->samplerTextureCapacity
|
||||
: 0;
|
||||
const auto instanceCapacity =
|
||||
fixedInstanceDescriptorSetLayout
|
||||
? getIDescriptorSetLayoutInfoSamplerTextureCapacity(*fixedInstanceDescriptorSetLayout)
|
||||
: (descriptorSets[static_cast<size_t>(UpdateFrequency::PER_INSTANCE)]
|
||||
? descriptorSets[static_cast<size_t>(UpdateFrequency::PER_INSTANCE)]->samplerTextureCapacity
|
||||
: 0);
|
||||
|
||||
// calculate sampler texture offsets
|
||||
const auto passOffset = 0;
|
||||
const auto phaseOffset = passOffset + passCapacity;
|
||||
const auto instanceOffset = phaseOffset + phaseCapacity;
|
||||
const auto batchOffset = instanceOffset + instanceCapacity;
|
||||
|
||||
// save sampler texture offsets by set index
|
||||
std::array<uint32_t, 4> samplerTextureOffsets{};
|
||||
samplerTextureOffsets[setIndex(UpdateFrequency::PER_PASS)] = passOffset;
|
||||
samplerTextureOffsets[setIndex(UpdateFrequency::PER_PHASE)] = phaseOffset;
|
||||
samplerTextureOffsets[setIndex(UpdateFrequency::PER_BATCH)] = batchOffset;
|
||||
samplerTextureOffsets[setIndex(UpdateFrequency::PER_INSTANCE)] = instanceOffset;
|
||||
|
||||
// update flattened sampler texture binding
|
||||
setFlattenedSamplerTextureBinding(samplerTextureOffsets, uniformBlockCapacities, shaderInfo.samplerTextures);
|
||||
setFlattenedSamplerTextureBinding(samplerTextureOffsets, uniformBlockCapacities, shaderInfo.samplers);
|
||||
setFlattenedSamplerTextureBinding(samplerTextureOffsets, uniformBlockCapacities, shaderInfo.textures);
|
||||
setFlattenedSamplerTextureBinding(samplerTextureOffsets, uniformBlockCapacities, shaderInfo.buffers);
|
||||
setFlattenedSamplerTextureBinding(samplerTextureOffsets, uniformBlockCapacities, shaderInfo.images);
|
||||
}
|
||||
}
|
||||
|
||||
void makeShaderInfo(
|
||||
LayoutGraphData &lg,
|
||||
const PipelineLayoutData &passLayouts, // NOLINT(bugprone-easily-swappable-parameters)
|
||||
@@ -565,9 +700,12 @@ void makeShaderInfo(
|
||||
bool fixedLocal,
|
||||
gfx::ShaderInfo &shaderInfo,
|
||||
ccstd::pmr::vector<uint32_t> &blockSizes) {
|
||||
std::array<const DescriptorSetLayoutData *, 4> descriptorSets{};
|
||||
const pipeline::DescriptorSetLayoutInfos *fixedInstanceDescriptorSetLayout = nullptr;
|
||||
{ // pass
|
||||
auto iter = passLayouts.descriptorSets.find(UpdateFrequency::PER_PASS);
|
||||
if (iter != passLayouts.descriptorSets.end()) {
|
||||
descriptorSets[static_cast<size_t>(UpdateFrequency::PER_PASS)] = &iter->second.descriptorSetLayoutData;
|
||||
populateMergedShaderInfo(
|
||||
lg.valueNames, iter->second.descriptorSetLayoutData,
|
||||
setIndex(UpdateFrequency::PER_PASS),
|
||||
@@ -577,6 +715,7 @@ void makeShaderInfo(
|
||||
{ // phase
|
||||
auto iter = phaseLayouts.descriptorSets.find(UpdateFrequency::PER_PHASE);
|
||||
if (iter != passLayouts.descriptorSets.end()) {
|
||||
descriptorSets[static_cast<size_t>(UpdateFrequency::PER_PHASE)] = &iter->second.descriptorSetLayoutData;
|
||||
populateMergedShaderInfo(
|
||||
lg.valueNames, iter->second.descriptorSetLayoutData,
|
||||
setIndex(UpdateFrequency::PER_PHASE),
|
||||
@@ -589,6 +728,7 @@ void makeShaderInfo(
|
||||
if (programData) {
|
||||
auto iter = programData->layout.descriptorSets.find(UpdateFrequency::PER_BATCH);
|
||||
if (iter != programData->layout.descriptorSets.end()) {
|
||||
descriptorSets[static_cast<size_t>(UpdateFrequency::PER_BATCH)] = &iter->second.descriptorSetLayoutData;
|
||||
populateMergedShaderInfo(
|
||||
lg.valueNames, iter->second.descriptorSetLayoutData,
|
||||
setIndex(UpdateFrequency::PER_BATCH),
|
||||
@@ -597,6 +737,7 @@ void makeShaderInfo(
|
||||
} else {
|
||||
auto iter = phaseLayouts.descriptorSets.find(UpdateFrequency::PER_BATCH);
|
||||
if (iter != phaseLayouts.descriptorSets.end()) {
|
||||
descriptorSets[static_cast<size_t>(UpdateFrequency::PER_BATCH)] = &iter->second.descriptorSetLayoutData;
|
||||
populateGroupedShaderInfo(
|
||||
iter->second.descriptorSetLayoutData,
|
||||
batchInfo, setIndex(UpdateFrequency::PER_BATCH),
|
||||
@@ -609,6 +750,7 @@ void makeShaderInfo(
|
||||
static_cast<uint32_t>(UpdateFrequency::PER_INSTANCE));
|
||||
if (programData) {
|
||||
if (fixedLocal) {
|
||||
fixedInstanceDescriptorSetLayout = &pipeline::localDescriptorSetLayout;
|
||||
populateLocalShaderInfo(
|
||||
instanceInfo,
|
||||
pipeline::localDescriptorSetLayout, shaderInfo, blockSizes);
|
||||
@@ -616,6 +758,7 @@ void makeShaderInfo(
|
||||
auto iter = programData->layout.descriptorSets.find(
|
||||
UpdateFrequency::PER_INSTANCE);
|
||||
if (iter != programData->layout.descriptorSets.end()) {
|
||||
descriptorSets[static_cast<size_t>(UpdateFrequency::PER_INSTANCE)] = &iter->second.descriptorSetLayoutData;
|
||||
populateMergedShaderInfo(
|
||||
lg.valueNames, iter->second.descriptorSetLayoutData,
|
||||
setIndex(UpdateFrequency::PER_INSTANCE),
|
||||
@@ -625,6 +768,7 @@ void makeShaderInfo(
|
||||
} else {
|
||||
auto iter = phaseLayouts.descriptorSets.find(UpdateFrequency::PER_INSTANCE);
|
||||
if (iter != phaseLayouts.descriptorSets.end()) {
|
||||
descriptorSets[static_cast<size_t>(UpdateFrequency::PER_INSTANCE)] = &iter->second.descriptorSetLayoutData;
|
||||
populateGroupedShaderInfo(
|
||||
iter->second.descriptorSetLayoutData,
|
||||
instanceInfo, setIndex(UpdateFrequency::PER_INSTANCE),
|
||||
@@ -632,6 +776,9 @@ void makeShaderInfo(
|
||||
}
|
||||
}
|
||||
}
|
||||
calculateFlattenedBinding(descriptorSets, fixedInstanceDescriptorSetLayout, shaderInfo);
|
||||
shaderInfo.stages.emplace_back(gfx::ShaderStage{gfx::ShaderStageFlagBit::VERTEX, ""});
|
||||
shaderInfo.stages.emplace_back(gfx::ShaderStage{gfx::ShaderStageFlagBit::FRAGMENT, ""});
|
||||
}
|
||||
|
||||
// overwrite IProgramInfo using gfx.ShaderInfo
|
||||
@@ -691,10 +838,10 @@ gfx::DescriptorSetLayout *getDescriptorSetLayout(
|
||||
gfx::DescriptorSetLayout *getProgramDescriptorSetLayout(
|
||||
gfx::Device *device,
|
||||
LayoutGraphData &lg, uint32_t phaseID,
|
||||
const ccstd::pmr::string &programName, UpdateFrequency rate) {
|
||||
const ccstd::string &programName, UpdateFrequency rate) {
|
||||
CC_EXPECTS(rate < UpdateFrequency::PER_PHASE);
|
||||
auto &phase = get(RenderPhaseTag{}, phaseID, lg);
|
||||
const auto iter = phase.shaderIndex.find(programName);
|
||||
const auto iter = phase.shaderIndex.find(std::string_view{programName});
|
||||
if (iter == phase.shaderIndex.end()) {
|
||||
return nullptr;
|
||||
}
|
||||
@@ -807,9 +954,10 @@ void NativeProgramLibrary::addEffect(EffectAsset *effectAssetIn) {
|
||||
// programs
|
||||
auto iter = this->phases.find(phaseID);
|
||||
if (iter == this->phases.end()) {
|
||||
iter = this->phases.emplace(std::piecewise_construct,
|
||||
std::forward_as_tuple(phaseID),
|
||||
std::forward_as_tuple())
|
||||
iter = this->phases.emplace(
|
||||
std::piecewise_construct,
|
||||
std::forward_as_tuple(phaseID),
|
||||
std::forward_as_tuple())
|
||||
.first;
|
||||
}
|
||||
auto &phasePrograms = iter->second.programInfos;
|
||||
@@ -870,7 +1018,7 @@ void NativeProgramLibrary::precompileEffect(gfx::Device *device, EffectAsset *ef
|
||||
}
|
||||
|
||||
ccstd::string NativeProgramLibrary::getKey(
|
||||
uint32_t phaseID, const ccstd::pmr::string &programName,
|
||||
uint32_t phaseID, const ccstd::string &programName,
|
||||
const MacroRecord &defines) const {
|
||||
auto iter = phases.find(phaseID);
|
||||
if (iter == phases.end()) {
|
||||
@@ -878,7 +1026,7 @@ ccstd::string NativeProgramLibrary::getKey(
|
||||
return "";
|
||||
}
|
||||
const auto &phase = iter->second;
|
||||
auto iter2 = phase.programInfos.find(programName);
|
||||
auto iter2 = phase.programInfos.find(std::string_view{programName});
|
||||
if (iter2 == phase.programInfos.end()) {
|
||||
CC_LOG_ERROR("program not found");
|
||||
return "";
|
||||
@@ -887,29 +1035,29 @@ ccstd::string NativeProgramLibrary::getKey(
|
||||
return getVariantKey(info.programInfo, defines);
|
||||
}
|
||||
|
||||
const gfx::PipelineLayout &NativeProgramLibrary::getPipelineLayout(
|
||||
gfx::Device *device, uint32_t phaseID, const ccstd::pmr::string &programName) {
|
||||
IntrusivePtr<gfx::PipelineLayout> NativeProgramLibrary::getPipelineLayout(
|
||||
gfx::Device *device, uint32_t phaseID, const ccstd::string &programName) {
|
||||
if (mergeHighFrequency) {
|
||||
CC_EXPECTS(phaseID != LayoutGraphData::null_vertex());
|
||||
const auto &layout = get(RenderPhaseTag{}, phaseID, layoutGraph);
|
||||
return *layout.pipelineLayout;
|
||||
return layout.pipelineLayout;
|
||||
}
|
||||
auto &lg = layoutGraph;
|
||||
auto &phase = get(RenderPhaseTag{}, phaseID, lg);
|
||||
const auto iter = phase.shaderIndex.find(programName);
|
||||
const auto iter = phase.shaderIndex.find(std::string_view{programName});
|
||||
if (iter == phase.shaderIndex.end()) {
|
||||
return *emptyPipelineLayout;
|
||||
return emptyPipelineLayout;
|
||||
}
|
||||
const auto programID = iter->second;
|
||||
auto &programData = phase.shaderPrograms.at(programID);
|
||||
if (programData.pipelineLayout) {
|
||||
return *programData.pipelineLayout;
|
||||
return programData.pipelineLayout;
|
||||
}
|
||||
|
||||
// get pass
|
||||
const auto passID = parent(phaseID, lg);
|
||||
if (passID == LayoutGraphData::null_vertex()) {
|
||||
return *emptyPipelineLayout;
|
||||
return emptyPipelineLayout;
|
||||
}
|
||||
// create pipeline layout
|
||||
gfx::PipelineLayoutInfo info{};
|
||||
@@ -932,7 +1080,7 @@ const gfx::PipelineLayout &NativeProgramLibrary::getPipelineLayout(
|
||||
info.setLayouts.emplace_back(instanceSet);
|
||||
}
|
||||
programData.pipelineLayout = device->createPipelineLayout(info);
|
||||
return *programData.pipelineLayout;
|
||||
return programData.pipelineLayout;
|
||||
}
|
||||
|
||||
const gfx::DescriptorSetLayout &NativeProgramLibrary::getMaterialDescriptorSetLayout(
|
||||
@@ -973,19 +1121,25 @@ const gfx::ShaderInfo &NativeProgramLibrary::getShaderInfo(
|
||||
|
||||
ProgramProxy *NativeProgramLibrary::getProgramVariant(
|
||||
gfx::Device *device, uint32_t phaseID, const ccstd::string &name,
|
||||
const MacroRecord &defines, const ccstd::pmr::string *key0) const {
|
||||
MacroRecord &defines, const ccstd::pmr::string *key0) {
|
||||
if (pipeline) {
|
||||
for (const auto &it : pipeline->getMacros()) {
|
||||
defines[it.first] = it.second;
|
||||
}
|
||||
}
|
||||
|
||||
auto iter = phases.find(phaseID);
|
||||
if (iter == phases.end()) {
|
||||
CC_LOG_ERROR("phase not found");
|
||||
return nullptr;
|
||||
}
|
||||
const auto &phase = iter->second;
|
||||
auto &phase = iter->second;
|
||||
auto iter2 = phase.programInfos.find(std::string_view{name});
|
||||
if (iter2 == phase.programInfos.end()) {
|
||||
CC_LOG_ERROR("program not found");
|
||||
return nullptr;
|
||||
}
|
||||
const auto &info = iter2->second;
|
||||
auto &info = iter2->second;
|
||||
|
||||
const auto &programInfo = info.programInfo;
|
||||
|
||||
@@ -999,48 +1153,83 @@ ProgramProxy *NativeProgramLibrary::getProgramVariant(
|
||||
key = *key0;
|
||||
}
|
||||
|
||||
auto iter3 = phase.programHosts.find(key);
|
||||
if (iter3 != phase.programHosts.end()) {
|
||||
return new NativeProgramProxy(iter3->second.program);
|
||||
auto iter3 = phase.programProxies.find(key);
|
||||
if (iter3 != phase.programProxies.end()) {
|
||||
return iter3->second.get();
|
||||
}
|
||||
|
||||
std::ignore = device;
|
||||
std::ignore = phaseID;
|
||||
std::ignore = name;
|
||||
std::ignore = defines;
|
||||
std::ignore = key;
|
||||
return nullptr;
|
||||
// prepare defines
|
||||
ccstd::vector<IMacroInfo> macroArray = render::prepareDefines(defines, programInfo.defines);
|
||||
std::stringstream ss;
|
||||
ss << std::endl;
|
||||
for (const auto &m : macroArray) {
|
||||
ss << "#define " << m.name << " " << m.value << std::endl;
|
||||
}
|
||||
auto prefix = pipeline->getConstantMacros() + programInfo.constantMacros + ss.str();
|
||||
|
||||
const IShaderSource *src = &programInfo.glsl3;
|
||||
const auto *deviceShaderVersion = getDeviceShaderVersion(device);
|
||||
if (deviceShaderVersion) {
|
||||
src = programInfo.getSource(deviceShaderVersion);
|
||||
} else {
|
||||
CC_LOG_ERROR("Invalid GFX API!");
|
||||
}
|
||||
info.shaderInfo.stages[0].source = prefix + src->vert;
|
||||
info.shaderInfo.stages[1].source = prefix + src->frag;
|
||||
|
||||
// strip out the active attributes only, instancing depend on this
|
||||
info.shaderInfo.attributes = getActiveAttributes(programInfo, info.attributes, defines);
|
||||
|
||||
info.shaderInfo.name = getShaderInstanceName(name, macroArray);
|
||||
|
||||
IntrusivePtr<gfx::Shader> shader = device->createShader(info.shaderInfo);
|
||||
auto res = phase.programProxies.emplace(
|
||||
key,
|
||||
IntrusivePtr<ProgramProxy>(new NativeProgramProxy(std::move(shader))));
|
||||
CC_ENSURES(res.second);
|
||||
|
||||
return res.first->second.get();
|
||||
}
|
||||
|
||||
const ccstd::pmr::vector<unsigned> &NativeProgramLibrary::getBlockSizes(
|
||||
uint32_t phaseID, const ccstd::pmr::string &programName) const {
|
||||
std::ignore = phaseID;
|
||||
std::ignore = programName;
|
||||
throw std::runtime_error("not implemented");
|
||||
CC_EXPECTS(phaseID != LayoutGraphData::null_vertex());
|
||||
const auto &group = phases.at(phaseID);
|
||||
const auto &info = group.programInfos.at(programName);
|
||||
return info.blockSizes;
|
||||
}
|
||||
|
||||
const Record<ccstd::string, uint32_t> &NativeProgramLibrary::getHandleMap(
|
||||
uint32_t phaseID, const ccstd::pmr::string &programName) const {
|
||||
std::ignore = phaseID;
|
||||
std::ignore = programName;
|
||||
throw std::runtime_error("not implemented");
|
||||
CC_EXPECTS(phaseID != LayoutGraphData::null_vertex());
|
||||
const auto &group = phases.at(phaseID);
|
||||
const auto &info = group.programInfos.at(programName);
|
||||
return info.handleMap;
|
||||
}
|
||||
|
||||
uint32_t NativeProgramLibrary::getProgramID(
|
||||
uint32_t phaseID, const ccstd::pmr::string &programName) {
|
||||
std::ignore = phaseID;
|
||||
std::ignore = programName;
|
||||
throw std::runtime_error("not implemented");
|
||||
CC_EXPECTS(phaseID != LayoutGraphData::null_vertex());
|
||||
const auto &phase = get(RenderPhaseTag{}, phaseID, layoutGraph);
|
||||
auto iter = phase.shaderIndex.find(programName);
|
||||
if (iter == phase.shaderIndex.end()) {
|
||||
CC_LOG_ERROR("program not found");
|
||||
return LayoutGraphData::null_vertex();
|
||||
}
|
||||
return iter->second;
|
||||
}
|
||||
|
||||
uint32_t NativeProgramLibrary::getDescriptorNameID(const ccstd::pmr::string &name) {
|
||||
std::ignore = name;
|
||||
return 0xFFFFFFFF;
|
||||
const auto iter = layoutGraph.attributeIndex.find(name);
|
||||
if (iter == layoutGraph.attributeIndex.end()) {
|
||||
CC_LOG_ERROR("descriptor name not found");
|
||||
return 0xFFFFFFFF;
|
||||
}
|
||||
return iter->second.value;
|
||||
}
|
||||
|
||||
const ccstd::pmr::string &NativeProgramLibrary::getDescriptorName(uint32_t nameID) {
|
||||
std::ignore = nameID;
|
||||
throw std::runtime_error("not implemented");
|
||||
return layoutGraph.valueNames.at(static_cast<size_t>(nameID));
|
||||
}
|
||||
|
||||
} // namespace render
|
||||
|
||||
@@ -382,6 +382,10 @@ void NativeRasterPassBuilder::setSampler(const ccstd::string &name, gfx::Sampler
|
||||
addSampler(*layoutGraph, name, sampler, data);
|
||||
}
|
||||
|
||||
void NativeRasterPassBuilder::setVersion(const ccstd::string &name, uint64_t version) {
|
||||
// noop
|
||||
}
|
||||
|
||||
// NativeComputeQueue
|
||||
ccstd::string NativeComputeQueueBuilder::getName() const {
|
||||
return std::string(get(RenderGraph::Name, *renderGraph, queueID));
|
||||
|
||||
@@ -61,15 +61,15 @@ ProgramInfo::ProgramInfo(ProgramInfo const& rhs, const allocator_type& alloc)
|
||||
|
||||
ProgramGroup::ProgramGroup(const allocator_type& alloc) noexcept
|
||||
: programInfos(alloc),
|
||||
programHosts(alloc) {}
|
||||
programProxies(alloc) {}
|
||||
|
||||
ProgramGroup::ProgramGroup(ProgramGroup&& rhs, const allocator_type& alloc)
|
||||
: programInfos(std::move(rhs.programInfos), alloc),
|
||||
programHosts(std::move(rhs.programHosts), alloc) {}
|
||||
programProxies(std::move(rhs.programProxies), alloc) {}
|
||||
|
||||
ProgramGroup::ProgramGroup(ProgramGroup const& rhs, const allocator_type& alloc)
|
||||
: programInfos(rhs.programInfos, alloc),
|
||||
programHosts(rhs.programHosts, alloc) {}
|
||||
programProxies(rhs.programProxies, alloc) {}
|
||||
|
||||
} // namespace render
|
||||
|
||||
|
||||
@@ -1,18 +1,17 @@
|
||||
/****************************************************************************
|
||||
Copyright (c) 2021-2022 Xiamen Yaji Software Co., Ltd.
|
||||
Copyright (c) 2021-2023 Xiamen Yaji Software Co., Ltd.
|
||||
|
||||
http://www.cocos.com
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated engine source code (the "Software"), a limited,
|
||||
worldwide, royalty-free, non-assignable, revocable and non-exclusive license
|
||||
to use Cocos Creator solely to develop games on your target platforms. You shall
|
||||
not use Cocos Creator software for developing other software or tools that's
|
||||
used for developing games. You are not granted to publish, distribute,
|
||||
sublicense, and/or sell copies of Cocos Creator.
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights to
|
||||
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
|
||||
of the Software, and to permit persons to whom the Software is furnished to do so,
|
||||
subject to the following conditions:
|
||||
|
||||
The software or tools in this License Agreement are licensed, not sold.
|
||||
Xiamen Yaji Software Co., Ltd. reserves all rights not expressly granted to you.
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
@@ -30,15 +29,13 @@
|
||||
*/
|
||||
// clang-format off
|
||||
#pragma once
|
||||
#include "cocos/base/Ptr.h"
|
||||
#include "cocos/base/std/container/string.h"
|
||||
#include "cocos/base/std/hash/hash.h"
|
||||
#include "cocos/renderer/core/ProgramLib.h"
|
||||
#include "cocos/renderer/gfx-base/GFXRenderPass.h"
|
||||
#include "cocos/renderer/pipeline/GlobalDescriptorSetManager.h"
|
||||
#include "cocos/renderer/pipeline/custom/LayoutGraphTypes.h"
|
||||
#include "cocos/renderer/pipeline/custom/NativeFwd.h"
|
||||
#include "cocos/renderer/pipeline/custom/RenderInterfaceTypes.h"
|
||||
#include "cocos/renderer/pipeline/custom/PrivateTypes.h"
|
||||
#include "cocos/renderer/pipeline/custom/details/Map.h"
|
||||
|
||||
namespace cc {
|
||||
@@ -68,14 +65,6 @@ struct ProgramInfo {
|
||||
Record<ccstd::string, uint32_t> handleMap;
|
||||
};
|
||||
|
||||
struct ProgramHost {
|
||||
ProgramHost() = default;
|
||||
ProgramHost(IntrusivePtr<gfx::Shader> programIn) noexcept // NOLINT
|
||||
: program(std::move(programIn)) {}
|
||||
|
||||
IntrusivePtr<gfx::Shader> program;
|
||||
};
|
||||
|
||||
struct ProgramGroup {
|
||||
using allocator_type = boost::container::pmr::polymorphic_allocator<char>;
|
||||
allocator_type get_allocator() const noexcept { // NOLINT
|
||||
@@ -92,7 +81,7 @@ struct ProgramGroup {
|
||||
ProgramGroup& operator=(ProgramGroup const& rhs) = default;
|
||||
|
||||
PmrFlatMap<ccstd::pmr::string, ProgramInfo> programInfos;
|
||||
PmrFlatMap<ccstd::pmr::string, ProgramHost> programHosts;
|
||||
PmrFlatMap<ccstd::pmr::string, IntrusivePtr<ProgramProxy>> programProxies;
|
||||
};
|
||||
|
||||
} // namespace render
|
||||
|
||||
@@ -62,19 +62,19 @@ public:
|
||||
|
||||
virtual void addEffect(EffectAsset *effectAsset) = 0;
|
||||
virtual void precompileEffect(gfx::Device *device, EffectAsset *effectAsset) = 0;
|
||||
virtual ccstd::string getKey(uint32_t phaseID, const ccstd::pmr::string &programName, const MacroRecord &defines) const = 0;
|
||||
virtual const gfx::PipelineLayout &getPipelineLayout(gfx::Device *device, uint32_t phaseID, const ccstd::pmr::string &programName) = 0;
|
||||
virtual ccstd::string getKey(uint32_t phaseID, const ccstd::string &programName, const MacroRecord &defines) const = 0;
|
||||
virtual IntrusivePtr<gfx::PipelineLayout> getPipelineLayout(gfx::Device *device, uint32_t phaseID, const ccstd::string &programName) = 0;
|
||||
virtual const gfx::DescriptorSetLayout &getMaterialDescriptorSetLayout(gfx::Device *device, uint32_t phaseID, const ccstd::pmr::string &programName) = 0;
|
||||
virtual const gfx::DescriptorSetLayout &getLocalDescriptorSetLayout(gfx::Device *device, uint32_t phaseID, const ccstd::pmr::string &programName) = 0;
|
||||
virtual const IProgramInfo &getProgramInfo(uint32_t phaseID, const ccstd::pmr::string &programName) const = 0;
|
||||
virtual const gfx::ShaderInfo &getShaderInfo(uint32_t phaseID, const ccstd::pmr::string &programName) const = 0;
|
||||
virtual ProgramProxy *getProgramVariant(gfx::Device *device, uint32_t phaseID, const ccstd::string &name, const MacroRecord &defines, const ccstd::pmr::string *key) const = 0;
|
||||
virtual ProgramProxy *getProgramVariant(gfx::Device *device, uint32_t phaseID, const ccstd::string &name, MacroRecord &defines, const ccstd::pmr::string *key) = 0;
|
||||
virtual const ccstd::pmr::vector<unsigned> &getBlockSizes(uint32_t phaseID, const ccstd::pmr::string &programName) const = 0;
|
||||
virtual const Record<ccstd::string, uint32_t> &getHandleMap(uint32_t phaseID, const ccstd::pmr::string &programName) const = 0;
|
||||
virtual uint32_t getProgramID(uint32_t phaseID, const ccstd::pmr::string &programName) = 0;
|
||||
virtual uint32_t getDescriptorNameID(const ccstd::pmr::string &name) = 0;
|
||||
virtual const ccstd::pmr::string &getDescriptorName(uint32_t nameID) = 0;
|
||||
ProgramProxy *getProgramVariant(gfx::Device *device, uint32_t phaseID, const ccstd::string &name, const MacroRecord &defines) const {
|
||||
ProgramProxy *getProgramVariant(gfx::Device *device, uint32_t phaseID, const ccstd::string &name, MacroRecord &defines) {
|
||||
return getProgramVariant(device, phaseID, name, defines, nullptr);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -159,7 +159,8 @@ SubpassGraph::Vertex::Vertex(Vertex const& rhs, const allocator_type& alloc)
|
||||
RasterPass::RasterPass(const allocator_type& alloc) noexcept
|
||||
: rasterViews(alloc),
|
||||
computeViews(alloc),
|
||||
subpassGraph(alloc) {}
|
||||
subpassGraph(alloc),
|
||||
versionName(alloc) {}
|
||||
|
||||
RasterPass::RasterPass(RasterPass&& rhs, const allocator_type& alloc)
|
||||
: rasterViews(std::move(rhs.rasterViews), alloc),
|
||||
@@ -167,7 +168,9 @@ RasterPass::RasterPass(RasterPass&& rhs, const allocator_type& alloc)
|
||||
subpassGraph(std::move(rhs.subpassGraph), alloc),
|
||||
width(rhs.width),
|
||||
height(rhs.height),
|
||||
viewport(rhs.viewport) {}
|
||||
viewport(rhs.viewport),
|
||||
versionName(std::move(rhs.versionName), alloc),
|
||||
version(rhs.version) {}
|
||||
|
||||
RasterPass::RasterPass(RasterPass const& rhs, const allocator_type& alloc)
|
||||
: rasterViews(rhs.rasterViews, alloc),
|
||||
@@ -175,7 +178,9 @@ RasterPass::RasterPass(RasterPass const& rhs, const allocator_type& alloc)
|
||||
subpassGraph(rhs.subpassGraph, alloc),
|
||||
width(rhs.width),
|
||||
height(rhs.height),
|
||||
viewport(rhs.viewport) {}
|
||||
viewport(rhs.viewport),
|
||||
versionName(rhs.versionName, alloc),
|
||||
version(rhs.version) {}
|
||||
|
||||
ComputePass::ComputePass(const allocator_type& alloc) noexcept
|
||||
: computeViews(alloc) {}
|
||||
|
||||
@@ -467,11 +467,13 @@ struct RasterPass {
|
||||
uint32_t width{0};
|
||||
uint32_t height{0};
|
||||
gfx::Viewport viewport;
|
||||
ccstd::pmr::string versionName;
|
||||
uint64_t version{0};
|
||||
};
|
||||
|
||||
inline bool operator==(const RasterPass& lhs, const RasterPass& rhs) noexcept {
|
||||
return std::forward_as_tuple(lhs.rasterViews, lhs.computeViews, lhs.subpassGraph, lhs.width, lhs.height) ==
|
||||
std::forward_as_tuple(rhs.rasterViews, rhs.computeViews, rhs.subpassGraph, rhs.width, rhs.height);
|
||||
return std::forward_as_tuple(lhs.rasterViews, lhs.computeViews, lhs.subpassGraph, lhs.width, lhs.height, lhs.versionName, lhs.version) ==
|
||||
std::forward_as_tuple(rhs.rasterViews, rhs.computeViews, rhs.subpassGraph, rhs.width, rhs.height, rhs.versionName, rhs.version);
|
||||
}
|
||||
|
||||
inline bool operator!=(const RasterPass& lhs, const RasterPass& rhs) noexcept {
|
||||
@@ -937,6 +939,8 @@ inline hash_t hash<cc::render::RasterPass>::operator()(const cc::render::RasterP
|
||||
hash_combine(seed, val.subpassGraph);
|
||||
hash_combine(seed, val.width);
|
||||
hash_combine(seed, val.height);
|
||||
hash_combine(seed, val.versionName);
|
||||
hash_combine(seed, val.version);
|
||||
return seed;
|
||||
}
|
||||
|
||||
|
||||
@@ -172,6 +172,7 @@ public:
|
||||
virtual void addComputeView(const ccstd::string &name, const ComputeView &view) = 0;
|
||||
virtual RasterQueueBuilder *addQueue(QueueHint hint) = 0;
|
||||
virtual void setViewport(const gfx::Viewport &viewport) = 0;
|
||||
virtual void setVersion(const ccstd::string &name, uint64_t version) = 0;
|
||||
RasterQueueBuilder *addQueue() {
|
||||
return addQueue(QueueHint::NONE);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,36 @@
|
||||
/****************************************************************************
|
||||
Copyright (c) 2021-2023 Xiamen Yaji Software Co., Ltd.
|
||||
|
||||
http://www.cocos.com
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights to
|
||||
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
|
||||
of the Software, and to permit persons to whom the Software is furnished to do so,
|
||||
subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
|
||||
#pragma once
|
||||
#include "cocos/renderer/pipeline/custom/PrivateTypes.h"
|
||||
|
||||
namespace cc {
|
||||
|
||||
namespace render {
|
||||
|
||||
ProgramLibrary* getProgramLibrary();
|
||||
|
||||
} // namespace render
|
||||
|
||||
} // namespace cc
|
||||
@@ -73,9 +73,9 @@ float LODGroup::getScreenUsagePercentage(const Camera *camera) const {
|
||||
|
||||
float LODGroup::distanceToScreenUsagePercentage(const Camera *camera, float distance, float size) {
|
||||
if (camera->getProjectionType() == CameraProjection::PERSPECTIVE) {
|
||||
return static_cast<float>((size * camera->getMatProj().m[5]) / (distance * 2.0)); // note: matProj.m11 is 1 / tan(fov / 2.0)
|
||||
return static_cast<float>((size * fabs(camera->getMatProj().m[5])) / (distance * 2.0)); // note: matProj.m11 is 1 / tan(fov / 2.0)
|
||||
}
|
||||
return static_cast<float>(size * camera->getMatProj().m[5] * 0.5);
|
||||
return static_cast<float>(size * fabs(camera->getMatProj().m[5]) * 0.5);
|
||||
}
|
||||
|
||||
float LODGroup::getWorldSpaceSize() const {
|
||||
|
||||
@@ -25,6 +25,7 @@
|
||||
#include "scene/Pass.h"
|
||||
#include "base/std/hash/hash.h"
|
||||
#include "cocos/bindings/jswrapper/SeApi.h"
|
||||
#include "cocos/renderer/pipeline/custom/RenderingModule.h"
|
||||
#include "core/Root.h"
|
||||
#include "core/assets/TextureBase.h"
|
||||
#include "core/builtin/BuiltinResMgr.h"
|
||||
@@ -134,8 +135,15 @@ ccstd::hash_t Pass::getPassHash(Pass *pass) {
|
||||
ccstd::hash_combine(hashValue, serializeDepthStencilState(pass->_depthStencilState));
|
||||
ccstd::hash_combine(hashValue, serializeRasterizerState(pass->_rs));
|
||||
|
||||
const ccstd::string &shaderKey = ProgramLib::getInstance()->getKey(pass->getProgram(), pass->getDefines());
|
||||
ccstd::hash_range(hashValue, shaderKey.begin(), shaderKey.end());
|
||||
const auto *programLib = render::getProgramLibrary();
|
||||
if (programLib) {
|
||||
const auto &shaderKey = programLib->getKey(pass->_phaseID, pass->getProgram(), pass->getDefines());
|
||||
ccstd::hash_combine(hashValue, pass->_phaseID);
|
||||
ccstd::hash_range(hashValue, shaderKey.begin(), shaderKey.end());
|
||||
} else {
|
||||
const ccstd::string &shaderKey = ProgramLib::getInstance()->getKey(pass->getProgram(), pass->getDefines());
|
||||
ccstd::hash_range(hashValue, shaderKey.begin(), shaderKey.end());
|
||||
}
|
||||
|
||||
return hashValue;
|
||||
}
|
||||
@@ -433,13 +441,25 @@ bool Pass::tryCompile() {
|
||||
}
|
||||
|
||||
syncBatchingScheme();
|
||||
auto *shader = ProgramLib::getInstance()->getGFXShader(_device, _programName, _defines, _root->getPipeline());
|
||||
if (!shader) {
|
||||
CC_LOG_WARNING("create shader %s failed", _programName.c_str());
|
||||
return false;
|
||||
auto *programLib = render::getProgramLibrary();
|
||||
if (programLib) {
|
||||
auto *shaderProxy = programLib->getProgramVariant(_device, _phaseID, _programName, _defines);
|
||||
if (!shaderProxy) {
|
||||
CC_LOG_WARNING("create shader %s failed", _programName.c_str());
|
||||
return false;
|
||||
}
|
||||
_shader = shaderProxy->getShader();
|
||||
_pipelineLayout = programLib->getPipelineLayout(_device, _phaseID, _programName);
|
||||
} else {
|
||||
auto *shader = ProgramLib::getInstance()->getGFXShader(_device, _programName, _defines, _root->getPipeline());
|
||||
if (!shader) {
|
||||
CC_LOG_WARNING("create shader %s failed", _programName.c_str());
|
||||
return false;
|
||||
}
|
||||
_shader = shader;
|
||||
_pipelineLayout = ProgramLib::getInstance()->getTemplateInfo(_programName)->pipelineLayout;
|
||||
}
|
||||
_shader = shader;
|
||||
_pipelineLayout = ProgramLib::getInstance()->getTemplateInfo(_programName)->pipelineLayout;
|
||||
|
||||
_hash = Pass::getPassHash(this);
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -276,10 +276,10 @@ public:
|
||||
inline const ccstd::vector<IBlockRef> &getBlocks() const { return _blocks; }
|
||||
inline ArrayBuffer *getRootBlock() { return _rootBlock; }
|
||||
inline bool isRootBufferDirty() const { return _rootBufferDirty; }
|
||||
//NOTE: _setRootBufferDirty must contain a _ prefix to make bindings-generator work correctly.
|
||||
// In ts engine, Pass has rootBufferDirty getter and without setter, but it contains a protected function named _setRootBufferDirty.
|
||||
// If we remove _ prefix in C++, bindings-generator doesn't support to bind rootBufferDirty property as getter and ignore to bind setRootBufferDirty as setter at the same time.
|
||||
// So let's keep the _ prefix temporarily.
|
||||
// NOTE: _setRootBufferDirty must contain a _ prefix to make bindings-generator work correctly.
|
||||
// In ts engine, Pass has rootBufferDirty getter and without setter, but it contains a protected function named _setRootBufferDirty.
|
||||
// If we remove _ prefix in C++, bindings-generator doesn't support to bind rootBufferDirty property as getter and ignore to bind setRootBufferDirty as setter at the same time.
|
||||
// So let's keep the _ prefix temporarily.
|
||||
inline void _setRootBufferDirty(bool val) { _rootBufferDirty = val; } // NOLINT(readability-identifier-naming)
|
||||
// states
|
||||
inline pipeline::RenderPriority getPriority() const { return _priority; }
|
||||
@@ -335,6 +335,8 @@ protected:
|
||||
pipeline::RenderPriority _priority{pipeline::RenderPriority::DEFAULT};
|
||||
pipeline::RenderPassStage _stage{pipeline::RenderPassStage::DEFAULT};
|
||||
uint32_t _phase{0};
|
||||
uint32_t _passID{0xFFFFFFFF};
|
||||
uint32_t _phaseID{0xFFFFFFFF};
|
||||
ccstd::string _phaseString;
|
||||
gfx::PrimitiveMode _primitive{gfx::PrimitiveMode::TRIANGLE_LIST};
|
||||
BatchingSchemes _batchingScheme{BatchingSchemes::NONE};
|
||||
|
||||
@@ -3,6 +3,6 @@
|
||||
"type": "github",
|
||||
"owner": "cocos-creator",
|
||||
"name": "engine-native-external",
|
||||
"checkout": "v3.7.0-6"
|
||||
"checkout": "v3.7.0-7"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -161,8 +161,13 @@ async function removeDir (dirPath) {
|
||||
}
|
||||
await cleanOldRal();
|
||||
await removeDir(repositoryPath);
|
||||
let exitCode = await runCommand('git clone git@github.com:yangws/runtime-web-adapter.git', __dirname);
|
||||
if (exitCode !== 0) {
|
||||
try {
|
||||
let exitCode = await runCommand('git clone git@github.com:yangws/runtime-web-adapter.git', __dirname);
|
||||
if (exitCode !== 0) {
|
||||
await removeDir(repositoryPath);
|
||||
await runCommand('git clone https://github.com/yangws/runtime-web-adapter', __dirname);
|
||||
}
|
||||
} catch (e) {
|
||||
await removeDir(repositoryPath);
|
||||
await runCommand('git clone https://github.com/yangws/runtime-web-adapter', __dirname);
|
||||
}
|
||||
|
||||
@@ -43,7 +43,8 @@ describe('ccclass warnings', () => {
|
||||
warnID.mockClear();
|
||||
};
|
||||
|
||||
test('Warn on no default value specified', () => {
|
||||
// TODO
|
||||
test.skip('Warn on no default value specified', () => {
|
||||
clearWarnID();
|
||||
{ @ccclass class _ { @float p; } }
|
||||
expect(warnID).toHaveBeenCalledTimes(1);
|
||||
|
||||
@@ -11,44 +11,38 @@ import {
|
||||
} from '../../cocos/core/data/decorators';
|
||||
import { CCClass } from '../../cocos/core/data/class';
|
||||
import { property } from '../../cocos/core/data/decorators/property';
|
||||
import { getClassByName, unregisterClass } from '../../cocos/core/utils/js-typed';
|
||||
import { LegacyPropertyDecorator } from '../../cocos/core/data/decorators/utils';
|
||||
|
||||
describe('Decorators signature', () => {
|
||||
test('Decorators signature', () => {
|
||||
class Foo {}
|
||||
|
||||
property(Foo, 'field1', function initializer () {
|
||||
property(Foo.prototype, 'field1', function initializer () {
|
||||
return 1;
|
||||
});
|
||||
property(Foo, 'field2', {
|
||||
property(Foo.prototype, 'field2', {
|
||||
initializer() {
|
||||
return 2;
|
||||
},
|
||||
});
|
||||
property(Foo, 'property', { value: 1 });
|
||||
property(Foo, 'getset', {
|
||||
property(Foo.prototype, 'property', { value: 1 });
|
||||
property(Foo.prototype, 'getset', {
|
||||
get() {
|
||||
return 3;
|
||||
},
|
||||
set(v) {},
|
||||
});
|
||||
expect(Foo.constructor['__ccclassCache__']).toMatchInlineSnapshot(`
|
||||
Object {
|
||||
"proto": Object {
|
||||
"properties": Object {
|
||||
"field1": Object {
|
||||
"default": 1,
|
||||
},
|
||||
"field2": Object {
|
||||
"default": 2,
|
||||
},
|
||||
"getset": Object {
|
||||
"get": [Function],
|
||||
"set": [Function],
|
||||
},
|
||||
"property": Object {},
|
||||
},
|
||||
},
|
||||
}
|
||||
`);
|
||||
ccclass('Foo')(Foo);
|
||||
expect(Foo['__attrs__']).toMatchObject({
|
||||
field1$_$default: 1,
|
||||
field2$_$default: 2,
|
||||
getset$_$hasGetter: true,
|
||||
getset$_$hasSetter: true,
|
||||
getset$_$serializable: false,
|
||||
});
|
||||
expect(Foo['__props__']).toMatchObject(['field1', 'field2', 'property', 'getset']);
|
||||
|
||||
unregisterClass(Foo);
|
||||
});
|
||||
|
||||
describe(`Decorators`, () => {
|
||||
@@ -272,3 +266,51 @@ describe(`Decorators`, () => {
|
||||
expect(CCClass.Attr.attr(Tooltip, 'boo').tooltip).toBe('i18n:ENGINE.model.shadow_normal_bias');
|
||||
});
|
||||
});
|
||||
|
||||
describe('Decorated property test', () => {
|
||||
afterEach(() => {
|
||||
const cls = getClassByName('A');
|
||||
unregisterClass(cls);
|
||||
});
|
||||
|
||||
const t = (descriptorOrInitializer?: Parameters<LegacyPropertyDecorator>[2]) => {
|
||||
class A {
|
||||
test: number;
|
||||
}
|
||||
property(A.prototype, 'test', descriptorOrInitializer);
|
||||
ccclass('A')(A);
|
||||
return CCClass.Attr.attr(A, 'test');
|
||||
};
|
||||
|
||||
test('property without default value', () => {
|
||||
// Simulate `class A { @property test; }`(in babel case)
|
||||
expect(t(null)).toMatchObject({});
|
||||
});
|
||||
|
||||
test('property with default value null', () => {
|
||||
// Simulate `class A { @property test = null; }`(in babel case)
|
||||
expect(t(() => null)).toMatchObject({
|
||||
default: null,
|
||||
});
|
||||
});
|
||||
|
||||
test('property with property descriptor', () => {
|
||||
// Simulate `class A { @property test = null; }`(in babel case)
|
||||
expect(t({
|
||||
configurable: true,
|
||||
enumerable: true,
|
||||
value: 1,
|
||||
writable: true,
|
||||
initializer () { return null; }
|
||||
})).toMatchObject({
|
||||
default: null,
|
||||
});
|
||||
});
|
||||
|
||||
test('property in TSC compiler', () => {
|
||||
// Simulate `class A { @property test; }`(in tsc case)
|
||||
expect(t()).toMatchObject({
|
||||
default: undefined,
|
||||
});
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user