Skip to content

Commit

Permalink
Merge branch 'v3.8.6' into v3.8.6-gfx
Browse files Browse the repository at this point in the history
  • Loading branch information
star-e committed Feb 7, 2025
2 parents 5fadf35 + f937802 commit 61b7d99
Show file tree
Hide file tree
Showing 20 changed files with 291 additions and 222 deletions.
13 changes: 8 additions & 5 deletions cocos/2d/assets/sprite-frame.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@ const INSET_BOTTOM = 3;
const temp_vec3 = v3();
const temp_matrix = mat4();

const vec3TransformMat4 = Vec3.transformMat4;
const vec3ToArray = Vec3.toArray;

enum MeshType {
RECT = 0,
POLYGON = 1, // Todo: Polygon mode need add
Expand Down Expand Up @@ -1214,7 +1217,7 @@ export class SpriteFrame extends Asset {
const posArray = [];
for (let i = 0; i < this.vertices.rawPosition.length; i++) {
const pos = this.vertices.rawPosition[i];
Vec3.toArray(posArray, pos, 3 * i);
vec3ToArray(posArray, pos, 3 * i);
}
vertices = {
rawPosition: posArray,
Expand Down Expand Up @@ -1532,11 +1535,11 @@ export class SpriteFrame extends Asset {

for (let i = 0; i < vertices.rawPosition.length; i++) {
const pos = vertices.rawPosition[i];
Vec3.transformMat4(temp_vec3, pos, temp_matrix);
Vec3.toArray(vertices.positions, temp_vec3, 3 * i);
vec3TransformMat4(temp_vec3, pos, temp_matrix);
vec3ToArray(vertices.positions, temp_vec3, 3 * i);
}
Vec3.transformMat4(this._minPos, vertices.minPos, temp_matrix);
Vec3.transformMat4(this._maxPos, vertices.maxPos, temp_matrix);
vec3TransformMat4(this._minPos, vertices.minPos, temp_matrix);
vec3TransformMat4(this._maxPos, vertices.maxPos, temp_matrix);
}

protected _createMesh (): void {
Expand Down
11 changes: 6 additions & 5 deletions cocos/asset/asset-manager/builtin-res-mgr.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,13 @@ export class BuiltinResMgr {
const resources = this._resources;
const len = 2;
const numChannels = 4;
const byteLength = len * len * numChannels;

const blackValueView = new Uint8Array(len * len * numChannels);
const emptyValueView = new Uint8Array(len * len * numChannels);
const greyValueView = new Uint8Array(len * len * numChannels);
const whiteValueView = new Uint8Array(len * len * numChannels);
const normalValueView = new Uint8Array(len * len * numChannels);
const blackValueView = new Uint8Array(byteLength);
const emptyValueView = new Uint8Array(byteLength);
const greyValueView = new Uint8Array(byteLength);
const whiteValueView = new Uint8Array(byteLength);
const normalValueView = new Uint8Array(byteLength);

let offset = 0;
for (let i = 0; i < len * len; i++) {
Expand Down
2 changes: 1 addition & 1 deletion cocos/asset/asset-manager/depend-util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ export class DependUtil {
*
*/
public getDepsRecursively (uuid: string): string[] {
const exclude = Object.create(null);
const exclude: Record<string, any> = Object.create(null);
const depends = [];
this._descend(uuid, exclude, depends);
return depends;
Expand Down
2 changes: 1 addition & 1 deletion cocos/asset/assets/material.jsb.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ interface IMaterialInfo {
states?: PassOverrides | PassOverrides[];
}

type MaterialPropertyFull = MaterialProperty | TextureBase | Texture | null;
export type MaterialPropertyFull = MaterialProperty | TextureBase | Texture | null;

declare const jsb: any;
const matProto: any = jsb.Material.prototype;
Expand Down
6 changes: 3 additions & 3 deletions cocos/asset/assets/material.ts
Original file line number Diff line number Diff line change
Expand Up @@ -495,9 +495,9 @@ export class Material extends Asset {
pass.resetUniform(name);
}
} else if (Array.isArray(val)) {
for (let i = 0; i < val.length; i++) {
this._bindTexture(pass, handle, val[i], i);
}
val.forEach((v, i) => {
this._bindTexture(pass, handle, v, i);
});
} else if (val) {
this._bindTexture(pass, handle, val);
} else {
Expand Down
8 changes: 5 additions & 3 deletions cocos/core/geometry/aabb.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,13 @@ const _v3_tmp3 = new Vec3();
const _v3_tmp4 = new Vec3();
const _m3_tmp = new Mat3();

const mathAbs = Math.abs;

// https://zeuxcg.org/2010/10/17/aabb-from-obb-with-component-wise-abs/
const transform_extent_m4 = (out: Vec3, extent: Vec3, m4: Mat4 | Readonly<Mat4>): void => {
_m3_tmp.m00 = Math.abs(m4.m00); _m3_tmp.m01 = Math.abs(m4.m01); _m3_tmp.m02 = Math.abs(m4.m02);
_m3_tmp.m03 = Math.abs(m4.m04); _m3_tmp.m04 = Math.abs(m4.m05); _m3_tmp.m05 = Math.abs(m4.m06);
_m3_tmp.m06 = Math.abs(m4.m08); _m3_tmp.m07 = Math.abs(m4.m09); _m3_tmp.m08 = Math.abs(m4.m10);
_m3_tmp.m00 = mathAbs(m4.m00); _m3_tmp.m01 = mathAbs(m4.m01); _m3_tmp.m02 = mathAbs(m4.m02);
_m3_tmp.m03 = mathAbs(m4.m04); _m3_tmp.m04 = mathAbs(m4.m05); _m3_tmp.m05 = mathAbs(m4.m06);
_m3_tmp.m06 = mathAbs(m4.m08); _m3_tmp.m07 = mathAbs(m4.m09); _m3_tmp.m08 = mathAbs(m4.m10);
Vec3.transformMat3(out, extent, _m3_tmp);
};

Expand Down
8 changes: 5 additions & 3 deletions cocos/core/geometry/obb.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,13 @@ const _v3_tmp = new Vec3();
const _v3_tmp2 = new Vec3();
const _m3_tmp = new Mat3();

const mathAbs = Math.abs;

// https://zeuxcg.org/2010/10/17/aabb-from-obb-with-component-wise-abs/
const transform_extent_m3 = (out: Vec3, extent: Vec3, m3: Mat3): void => {
_m3_tmp.m00 = Math.abs(m3.m00); _m3_tmp.m01 = Math.abs(m3.m01); _m3_tmp.m02 = Math.abs(m3.m02);
_m3_tmp.m03 = Math.abs(m3.m03); _m3_tmp.m04 = Math.abs(m3.m04); _m3_tmp.m05 = Math.abs(m3.m05);
_m3_tmp.m06 = Math.abs(m3.m06); _m3_tmp.m07 = Math.abs(m3.m07); _m3_tmp.m08 = Math.abs(m3.m08);
_m3_tmp.m00 = mathAbs(m3.m00); _m3_tmp.m01 = mathAbs(m3.m01); _m3_tmp.m02 = mathAbs(m3.m02);
_m3_tmp.m03 = mathAbs(m3.m03); _m3_tmp.m04 = mathAbs(m3.m04); _m3_tmp.m05 = mathAbs(m3.m05);
_m3_tmp.m06 = mathAbs(m3.m06); _m3_tmp.m07 = mathAbs(m3.m07); _m3_tmp.m08 = mathAbs(m3.m08);
Vec3.transformMat3(out, extent, _m3_tmp);
};

Expand Down
64 changes: 33 additions & 31 deletions cocos/core/geometry/spline.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,14 @@
THE SOFTWARE.
*/

import { JSB } from 'internal:constants';
import { clamp, Vec3 } from '../math';
import { clamp, v3, Vec3 } from '../math';
import { assertID, warnID } from '../platform/debug';
import { ShapeType } from './enums';
import { assertsArrayIndex } from '../data/utils/asserts';

const vec3MultiplyScalar = Vec3.multiplyScalar;
const vec3Add = Vec3.add;

export enum SplineMode {
/**
* @en
Expand Down Expand Up @@ -77,10 +79,10 @@ export enum SplineMode {

const SPLINE_WHOLE_INDEX = 0xffffffff;

const _v0 = new Vec3();
const _v1 = new Vec3();
const _v2 = new Vec3();
const _v3 = new Vec3();
const _v0 = v3();
const _v1 = v3();
const _v2 = v3();
const _v3 = v3();

/**
* @en
Expand All @@ -99,7 +101,7 @@ export class Spline {
this._mode = mode;

for (let i = 0; i < knots.length; i++) {
this._knots[i] = new Vec3(knots[i]);
this._knots[i] = v3(knots[i]);
}
}

Expand Down Expand Up @@ -144,7 +146,7 @@ export class Spline {
const knots = s.knots;
const length = knots.length;
for (let i = 0; i < length; i++) {
out._knots[i] = new Vec3(knots[i]);
out._knots[i] = v3(knots[i]);
}

return out;
Expand Down Expand Up @@ -193,7 +195,7 @@ export class Spline {
this._knots.length = 0;

for (let i = 0; i < knots.length; i++) {
this._knots[i] = new Vec3(knots[i]);
this._knots[i] = v3(knots[i]);
}
}

Expand Down Expand Up @@ -226,7 +228,7 @@ export class Spline {
* @param knot @en The knot to add to this Spline instance. @zh 要添加到当前 Spline 实例的结点。
*/
public addKnot (knot: Vec3): void {
this._knots.push(new Vec3(knot));
this._knots.push(v3(knot));
}

/**
Expand All @@ -238,7 +240,7 @@ export class Spline {
* @param knot @en The knot to be inserted. @zh 要插入的结点。
*/
public insertKnot (index: number, knot: Vec3): void {
const item = new Vec3(knot);
const item = v3(knot);
if (index >= this._knots.length) {
this._knots.push(item);
return;
Expand Down Expand Up @@ -302,7 +304,7 @@ export class Spline {

const segments = this.getSegments();
if (segments === 0) {
return new Vec3();
return v3();
}

if (index === SPLINE_WHOLE_INDEX) {
Expand All @@ -315,7 +317,7 @@ export class Spline {
const knots = this._knots;

if (index >= segments) {
return new Vec3(knots[knots.length - 1]);
return v3(knots[knots.length - 1]);
}

switch (this._mode) {
Expand All @@ -331,7 +333,7 @@ export class Spline {
return Spline.calcCatmullRom(v0, knots[index], knots[index + 1], v3, t);
}
default:
return new Vec3();
return v3();
}
}

Expand Down Expand Up @@ -394,37 +396,37 @@ export class Spline {

private static calcLinear (v0: Vec3, v1: Vec3, t: number): Vec3 {
const result = new Vec3();
Vec3.multiplyScalar(_v0, v0, (1.0 - t));
Vec3.multiplyScalar(_v1, v1, t);
Vec3.add(result, _v0, _v1);
vec3MultiplyScalar(_v0, v0, (1.0 - t));
vec3MultiplyScalar(_v1, v1, t);
vec3Add(result, _v0, _v1);

return result;
}

private static calcBezier (v0: Vec3, v1: Vec3, v2: Vec3, v3: Vec3, t: number): Vec3 {
const result = new Vec3();
const s = 1.0 - t;
Vec3.multiplyScalar(_v0, v0, s * s * s);
Vec3.multiplyScalar(_v1, v1, 3.0 * t * s * s);
Vec3.multiplyScalar(_v2, v2, 3.0 * t * t * s);
Vec3.multiplyScalar(_v3, v3, t * t * t);
Vec3.add(_v0, _v0, _v1);
Vec3.add(_v2, _v2, _v3);
Vec3.add(result, _v0, _v2);
vec3MultiplyScalar(_v0, v0, s * s * s);
vec3MultiplyScalar(_v1, v1, 3.0 * t * s * s);
vec3MultiplyScalar(_v2, v2, 3.0 * t * t * s);
vec3MultiplyScalar(_v3, v3, t * t * t);
vec3Add(_v0, _v0, _v1);
vec3Add(_v2, _v2, _v3);
vec3Add(result, _v0, _v2);

return result;
}
private static calcCatmullRom (v0: Vec3, v1: Vec3, v2: Vec3, v3: Vec3, t: number): Vec3 {
const result = new Vec3();
const t2 = t * t;
const t3 = t2 * t;
Vec3.multiplyScalar(_v0, v0, -0.5 * t3 + t2 - 0.5 * t);
Vec3.multiplyScalar(_v1, v1, 1.5 * t3 - 2.5 * t2 + 1.0);
Vec3.multiplyScalar(_v2, v2, -1.5 * t3 + 2.0 * t2 + 0.5 * t);
Vec3.multiplyScalar(_v3, v3, 0.5 * t3 - 0.5 * t2);
Vec3.add(_v0, _v0, _v1);
Vec3.add(_v2, _v2, _v3);
Vec3.add(result, _v0, _v2);
vec3MultiplyScalar(_v0, v0, -0.5 * t3 + t2 - 0.5 * t);
vec3MultiplyScalar(_v1, v1, 1.5 * t3 - 2.5 * t2 + 1.0);
vec3MultiplyScalar(_v2, v2, -1.5 * t3 + 2.0 * t2 + 0.5 * t);
vec3MultiplyScalar(_v3, v3, 0.5 * t3 - 0.5 * t2);
vec3Add(_v0, _v0, _v1);
vec3Add(_v2, _v2, _v3);
vec3Add(result, _v0, _v2);

return result;
}
Expand Down
12 changes: 7 additions & 5 deletions cocos/core/math/mat4.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,16 @@ import { EPSILON } from './utils';
import { Vec3 } from './vec3';
import { legacyCC } from '../global-exports';

const objectFreeze = Object.freeze;

/**
* @engineInternal
*/
export const preTransforms = Object.freeze([
Object.freeze([1, 0, 0, 1]), // SurfaceTransform.IDENTITY
Object.freeze([0, 1, -1, 0]), // SurfaceTransform.ROTATE_90
Object.freeze([-1, 0, 0, -1]), // SurfaceTransform.ROTATE_180
Object.freeze([0, -1, 1, 0]), // SurfaceTransform.ROTATE_270
export const preTransforms = objectFreeze([
objectFreeze([1, 0, 0, 1]), // SurfaceTransform.IDENTITY
objectFreeze([0, 1, -1, 0]), // SurfaceTransform.ROTATE_90
objectFreeze([-1, 0, 0, -1]), // SurfaceTransform.ROTATE_180
objectFreeze([0, -1, 1, 0]), // SurfaceTransform.ROTATE_270
]);

/**
Expand Down
Loading

0 comments on commit 61b7d99

Please sign in to comment.